Skip to content

Commit

Permalink
Do not add empty IP address of an interface to the route table
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
guvenc committed Feb 8, 2024
1 parent 026e215 commit 60f425f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/grpc/dp_async_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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";

Expand Down
17 changes: 11 additions & 6 deletions src/grpc/dp_grpc_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down
4 changes: 4 additions & 0 deletions test/test_zzz_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 60f425f

Please sign in to comment.