From 2b716b186fdfe0a40d6ddb9e43c795bb05d1ca10 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Fri, 22 Oct 2021 09:53:44 -0500 Subject: tap: handle null namespace and bridge correctly Type: fix In tap_create_if(), if args->host_namespace or args->host_bridge are null because no values were set for those, the virtio_if_t entry in virtio_main.interfaces ends up getting populated with values of "(nil)" in net_ns or host_bridge, respectively. Check whether args->host_namespace and args->host_bridge are null before trying to set the corresponding fields on virtio_if_t. Change-Id: I8e1e66a6d7b246e7c66fece406d116ffb1312c64 Signed-off-by: Matthew Smith --- src/vnet/devices/tap/tap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vnet/devices/tap/tap.c b/src/vnet/devices/tap/tap.c index 2cca1fb7771..2d075f9e0fc 100644 --- a/src/vnet/devices/tap/tap.c +++ b/src/vnet/devices/tap/tap.c @@ -625,10 +625,12 @@ tap_create_if (vlib_main_t * vm, tap_create_if_args_t * args) ethernet_mac_address_generate (args->mac_addr.bytes); clib_memcpy (vif->mac_addr, args->mac_addr.bytes, 6); - vif->host_bridge = format (0, "%s%c", args->host_bridge, 0); + if (args->host_bridge) + vif->host_bridge = format (0, "%s%c", args->host_bridge, 0); } vif->host_if_name = format (0, "%s%c", host_if_name, 0); - vif->net_ns = format (0, "%s%c", args->host_namespace, 0); + if (args->host_namespace) + vif->net_ns = format (0, "%s%c", args->host_namespace, 0); vif->host_mtu_size = args->host_mtu_size; vif->tap_flags = args->tap_flags; clib_memcpy (vif->host_mac_addr, args->host_mac_addr.bytes, 6); -- cgit 1.2.3-korg