From b9c3e544c48e76dd01aa32e9b1f5cd4c1ad8532c Mon Sep 17 00:00:00 2001 From: Yan Ka Chiu Date: Thu, 30 Jun 2022 10:29:45 -0700 Subject: [PATCH] bhyve virtio-net: Allow backend type to be explicitly specified. Surrently virtio-net uses the prefix of the backing interface to choose the backend. This patch adds an additional option "type" to choose the backend type explicitly. This allows greater flexibility for end users to manage bhyve specific resources (such as by naming the tap interfaces to more descriptive names). The option "type" is optional. When it is not presented, the backend is derived from the name of the backend interface. For example, the line `-s 3,virtio-net,bsdvm0,type=tap` will create a virtio-net device for the guest using the tap interface "bsdvm0". Adding a new "type" option preserves the current legacy format in which the first value after virtio-net names an instance of a backend. Note that tap interfaces not following the pattern "tap*" will not be created on demand via devfs cloning but must be created explicitly. Reviewed by: vmaffione, jhb Differential Revision: https://reviews.freebsd.org/D35143 --- usr.sbin/bhyve/net_backends.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/usr.sbin/bhyve/net_backends.c b/usr.sbin/bhyve/net_backends.c index ca4c96b10239..9fcc33216bad 100644 --- a/usr.sbin/bhyve/net_backends.c +++ b/usr.sbin/bhyve/net_backends.c @@ -980,7 +980,7 @@ netbe_init(struct net_backend **ret, nvlist_t *nvl, net_be_rxeof_t cb, void *param) { struct net_backend **pbe, *nbe, *tbe = NULL; - const char *value; + const char *value, *type; char *devname; int err; @@ -990,12 +990,20 @@ netbe_init(struct net_backend **ret, nvlist_t *nvl, net_be_rxeof_t cb, } devname = strdup(value); + /* + * Use the type given by configuration if exists; otherwise + * use the prefix of the backend as the type. + */ + type = get_config_value_node(nvl, "type"); + if (type == NULL) + type = devname; + /* * Find the network backend that matches the user-provided * device name. net_backend_set is built using a linker set. */ SET_FOREACH(pbe, net_backend_set) { - if (strncmp(devname, (*pbe)->prefix, + if (strncmp(type, (*pbe)->prefix, strlen((*pbe)->prefix)) == 0) { tbe = *pbe; assert(tbe->init != NULL);