From 60f425f9df432daed845f83b896c7a5dd1fab23c Mon Sep 17 00:00:00 2001 From: Guvenc Gulce Date: Wed, 7 Feb 2024 19:14:22 +0100 Subject: [PATCH] Do not add empty IP address of an interface to the route table After introducing IPv6 support, it is a valid case that an interface has an ipv4 and no ipv6 address or vice versa but it can not have empty ipv4 and ipv6 addresses. So reflect these constraints to the code. Signed-off-by: Guvenc Gulce --- src/grpc/dp_async_grpc.cpp | 6 ++++-- src/grpc/dp_grpc_impl.c | 17 +++++++++++------ test/test_zzz_grpc.py | 4 ++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/grpc/dp_async_grpc.cpp b/src/grpc/dp_async_grpc.cpp index 917aaf032..13cd8d590 100644 --- a/src/grpc/dp_async_grpc.cpp +++ b/src/grpc/dp_async_grpc.cpp @@ -233,6 +233,10 @@ const char* CreateInterfaceCall::FillRequest(struct dpgrpc_request* request) request->add_iface.vni = request_.vni(); if (!GrpcConv::StrToIpv4(request_.ipv4_config().primary_address(), &request->add_iface.ip4_addr)) return "Invalid ipv4_config.primary_address"; + if (!GrpcConv::StrToIpv6(request_.ipv6_config().primary_address(), request->add_iface.ip6_addr)) + return "Invalid ipv6_config.primary_address"; + if (request->add_iface.ip4_addr == 0 && dp_is_ipv6_addr_zero(request->add_iface.ip6_addr)) + return "Invalid ipv4_config.primary_address and ipv6_config.primary_address combination"; if (!request_.pxe_config().next_server().empty()) { DPGRPC_LOG_INFO("Setting PXE", DP_LOG_IFACE(request_.interface_id().c_str()), @@ -245,8 +249,6 @@ const char* CreateInterfaceCall::FillRequest(struct dpgrpc_request* request) } if (SNPRINTF_FAILED(request->add_iface.pci_name, request_.device_name())) return "Invalid device_name"; - if (!GrpcConv::StrToIpv6(request_.ipv6_config().primary_address(), request->add_iface.ip6_addr)) - return "Invalid ipv6_config.primary_address"; if (SNPRINTF_FAILED(request->add_iface.iface_id, request_.interface_id())) return "Invalid interface_id"; diff --git a/src/grpc/dp_grpc_impl.c b/src/grpc/dp_grpc_impl.c index 6fff95681..094ddd98f 100644 --- a/src/grpc/dp_grpc_impl.c +++ b/src/grpc/dp_grpc_impl.c @@ -491,12 +491,17 @@ static int dp_process_create_interface(struct dp_grpc_responder *responder) rte_memcpy(port->iface.cfg.pxe_str, request->pxe_str, sizeof(port->iface.cfg.pxe_str)); port->iface.cfg.pxe_ip = request->ip4_pxe_addr; - ret = dp_add_route(port, request->vni, 0, request->ip4_addr, NULL, 32); - if (DP_FAILED(ret)) - goto iface_err; - ret = dp_add_route6(port, request->vni, 0, request->ip6_addr, NULL, 128); - if (DP_FAILED(ret)) - goto route_err; + /* Do not install routes for an empty(zero) IP, as zero ip is just a marker for showing the disabled IPv4/IPv6 machinery */ + if (request->ip4_addr != 0) { + ret = dp_add_route(port, request->vni, 0, request->ip4_addr, NULL, 32); + if (DP_FAILED(ret)) + goto iface_err; + } + if (!dp_is_ipv6_addr_zero(request->ip6_addr)) { + ret = dp_add_route6(port, request->vni, 0, request->ip6_addr, NULL, 128); + if (DP_FAILED(ret)) + goto route_err; + } if (!port->is_pf) if (DP_FAILED(dp_port_meter_config(port, request->total_flow_rate_cap, request->public_flow_rate_cap))) { diff --git a/test/test_zzz_grpc.py b/test/test_zzz_grpc.py index 1e1c59742..36342e23b 100644 --- a/test/test_zzz_grpc.py +++ b/test/test_zzz_grpc.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 from helpers import * +import pytest def test_grpc_addinterface_already_exists(prepare_ifaces, grpc_client): # Try to add using an existing vm identifier @@ -10,6 +11,9 @@ def test_grpc_addinterface_already_exists(prepare_ifaces, grpc_client): def test_grpc_addinterface_bad_interface(prepare_ifaces, grpc_client): # Try to add without specifying PCI address or using a bad one grpc_client.expect_error(201).addinterface("new_vm", "invalid", VM2.vni, VM2.ip, VM2.ipv6) + # Try to add with zero IPs + with pytest.raises(RuntimeError, match="Grpc client failed"): + grpc_client.addinterface(VM4.name, VM4.pci, VM4.vni, "0.0.0.0", "::") def test_grpc_getmachine_single(prepare_ifaces, grpc_client): # Try to get a single existing interface(machine)