From nobody Fri Nov 19 00:02:48 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F0916188FA53; Fri, 19 Nov 2021 00:02:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HwH160803z4vwL; Fri, 19 Nov 2021 00:02:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 096BB1E2D6; Fri, 19 Nov 2021 00:02:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AJ02mfL072734; Fri, 19 Nov 2021 00:02:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AJ02meM072733; Fri, 19 Nov 2021 00:02:48 GMT (envelope-from git) Date: Fri, 19 Nov 2021 00:02:48 GMT Message-Id: <202111190002.1AJ02meM072733@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: f74147e26999 - stable/13 - bhyve: net_backends, automatically IFF_UP tap devices List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f74147e26999838e03a522bf59ea33bef470d356 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=f74147e26999838e03a522bf59ea33bef470d356 commit f74147e26999838e03a522bf59ea33bef470d356 Author: Bjoern A. Zeeb AuthorDate: 2021-07-28 22:53:25 +0000 Commit: Bjoern A. Zeeb CommitDate: 2021-11-19 00:01:27 +0000 bhyve: net_backends, automatically IFF_UP tap devices If you want communications with the outside world and tell bhyve to create an interfaces then it should be usable as well. Rather than relying on the sysctl net.link.tap.up_on_open automatically try to IFF_UP the opened tap device. (cherry picked from commit 56be282bc999cc05dcd1ccb163b108d54f3ff448) --- usr.sbin/bhyve/net_backends.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/usr.sbin/bhyve/net_backends.c b/usr.sbin/bhyve/net_backends.c index 30c26aea458b..cb1730fc77df 100644 --- a/usr.sbin/bhyve/net_backends.c +++ b/usr.sbin/bhyve/net_backends.c @@ -46,6 +46,9 @@ __FBSDID("$FreeBSD$"); #include #include +#if defined(INET6) || defined(INET) +#include +#endif #include #include #define NETMAP_WITH_LIBS @@ -179,6 +182,17 @@ SET_DECLARE(net_backend_set, struct net_backend); * The tap backend */ +#if defined(INET6) || defined(INET) +const int pf_list[] = { +#if defined(INET6) + PF_INET6, +#endif +#if defined(INET) + PF_INET, +#endif +}; +#endif + struct tap_priv { struct mevent *mevp; /* @@ -211,6 +225,10 @@ tap_init(struct net_backend *be, const char *devname, struct tap_priv *priv = (struct tap_priv *)be->opaque; char tbuf[80]; int opt = 1; +#if defined(INET6) || defined(INET) + struct ifreq ifrq; + int i, s; +#endif #ifndef WITHOUT_CAPSICUM cap_rights_t rights; #endif @@ -238,6 +256,39 @@ tap_init(struct net_backend *be, const char *devname, goto error; } +#if defined(INET6) || defined(INET) + /* + * Try to UP the interface rather than relying on + * net.link.tap.up_on_open. + */ + bzero(&ifrq, sizeof(ifrq)); + if (ioctl(be->fd, TAPGIFNAME, &ifrq) < 0) { + WPRINTF(("Could not get interface name")); + goto error; + } + + s = -1; + for (i = 0; s == -1 && i < nitems(pf_list); i++) + s = socket(pf_list[i], SOCK_DGRAM, 0); + if (s == -1) { + WPRINTF(("Could open socket")); + goto error; + } + + if (ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) { + (void)close(s); + WPRINTF(("Could not get interface flags")); + goto error; + } + ifrq.ifr_flags |= IFF_UP; + if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) { + (void)close(s); + WPRINTF(("Could not set interface flags")); + goto error; + } + (void)close(s); +#endif + #ifndef WITHOUT_CAPSICUM cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE); if (caph_rights_limit(be->fd, &rights) == -1)