tap: handle null namespace and bridge correctly 09/34209/2
authorMatthew Smith <mgsmith@netgate.com>
Fri, 22 Oct 2021 14:53:44 +0000 (09:53 -0500)
committerDamjan Marion <dmarion@me.com>
Thu, 28 Oct 2021 11:00:57 +0000 (11:00 +0000)
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 <mgsmith@netgate.com>
src/vnet/devices/tap/tap.c

index 2cca1fb..2d075f9 100644 (file)
@@ -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);