From nobody Sat Oct 25 23:41:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516147017549278.17001507280906; Tue, 16 Jan 2018 15:56:57 -0800 (PST) Received: from localhost ([::1]:47488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebb64-0003MF-4P for importer@patchew.org; Tue, 16 Jan 2018 18:56:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebb51-0002w4-1n for qemu-devel@nongnu.org; Tue, 16 Jan 2018 18:55:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebb4w-0004OU-TY for qemu-devel@nongnu.org; Tue, 16 Jan 2018 18:55:47 -0500 Received: from devhost2.servers.provps.com ([208.82.112.163]:43840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebb4w-0004Nt-Kj for qemu-devel@nongnu.org; Tue, 16 Jan 2018 18:55:42 -0500 Received: by devhost2.servers.provps.com (Postfix, from userid 0) id 9EEB83205B6; Tue, 16 Jan 2018 15:18:27 -0800 (PST) From: Shaun Reitan To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:18:24 -0800 Message-Id: <20180116231824.27114-1-shaun.reitan@ndchost.com> X-Mailer: git-send-email 2.9.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 208.82.112.163 Subject: [Qemu-devel] [PATCH] Add ability to provide ifname when using netdev bridge or tap helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shaun Reitan , Jason Wang , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch replaces the patch I sent yesturday. This one fixes a bug in my original code as well as corrects a few styling issues. Hopfully this one comes out correct! Sorry for the inconvienece. =20 When currently using -netdev bridge or -netdev tap with a helper you are unable to set an ifname. This patch adds that ability so that you can now specify an ifname. Signed-off-by: Shaun Reitan --- net/tap.c | 33 ++++++++++++++++++++++++--------- qapi/net.json | 1 + qemu-bridge-helper.c | 11 +++++++++-- qemu-options.hx | 2 +- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/net/tap.c b/net/tap.c index 979e622..c4f3bb0 100644 --- a/net/tap.c +++ b/net/tap.c @@ -472,7 +472,7 @@ static int recv_fd(int c) } =20 static int net_bridge_run_helper(const char *helper, const char *bridge, - Error **errp) + const char *ifname, Error **errp) { sigset_t oldmask, mask; int pid, status; @@ -499,7 +499,9 @@ static int net_bridge_run_helper(const char *helper, co= nst char *bridge, int open_max =3D sysconf(_SC_OPEN_MAX), i; char fd_buf[6+10]; char br_buf[6+IFNAMSIZ] =3D {0}; - char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15]; + char ifname_buf[10 + IFNAMSIZ]; + char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + + sizeof(ifname_buf) + 16]; =20 for (i =3D 3; i < open_max; i++) { if (i !=3D sv[1]) { @@ -516,8 +518,13 @@ static int net_bridge_run_helper(const char *helper, c= onst char *bridge, snprintf(br_buf, sizeof(br_buf), "%s%s", "--br=3D", bridge= ); } =20 - snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s", - helper, "--use-vnet", fd_buf, br_buf); + if (strstr(helper, "--ifname=3D") =3D=3D NULL && ifname !=3D N= ULL) { + snprintf(ifname_buf, sizeof(ifname_buf), "%s%s", "--ifname= =3D", + ifname); + } + + snprintf(helper_cmd, sizeof(helper_cmd), "%s %s %s %s %s", + helper, "--use-vnet", fd_buf, br_buf, ifname_buf); =20 parg =3D args; *parg++ =3D (char *)"sh"; @@ -536,6 +543,13 @@ static int net_bridge_run_helper(const char *helper, c= onst char *bridge, *parg++ =3D (char *)"--use-vnet"; *parg++ =3D fd_buf; *parg++ =3D br_buf; + + if (ifname !=3D NULL) { + snprintf(ifname_buf, sizeof(ifname_buf), "%s%s", "--ifname= =3D", + ifname); + *parg++ =3D ifname_buf; + } + *parg++ =3D NULL; =20 execv(helper, args); @@ -586,7 +600,7 @@ int net_init_bridge(const Netdev *netdev, const char *n= ame, helper =3D bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER; br =3D bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERF= ACE; =20 - fd =3D net_bridge_run_helper(helper, br, errp); + fd =3D net_bridge_run_helper(helper, br, bridge->ifname, errp); if (fd =3D=3D -1) { return -1; } @@ -854,16 +868,17 @@ free_fail: g_free(vhost_fds); return -1; } else if (tap->has_helper) { - if (tap->has_ifname || tap->has_script || tap->has_downscript || - tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "queues=3D, and vhostfds=3D are invalid with helper= =3D"); + if (tap->has_script || tap->has_downscript || tap->has_vnet_hdr || + tap->has_queues || tap->has_vhostfds) { + error_setg(errp, "script=3D, downscript=3D, vnet_hdr=3D, queue= s=3D, and " + "vhostfds=3D are invalid with helper=3D"); return -1; } =20 fd =3D net_bridge_run_helper(tap->helper, tap->has_br ? tap->br : DEFAULT_BRIDGE_INTERFACE, + tap->ifname, errp); if (fd =3D=3D -1) { return -1; diff --git a/qapi/net.json b/qapi/net.json index 4beff5d..5b5b281 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -402,6 +402,7 @@ { 'struct': 'NetdevBridgeOptions', 'data': { '*br': 'str', + '*ifname': 'str', '*helper': 'str' } } =20 ## diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 5396fbf..7b01cd5 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -57,7 +57,7 @@ typedef QSIMPLEQ_HEAD(ACLList, ACLRule) ACLList; static void usage(void) { fprintf(stderr, - "Usage: qemu-bridge-helper [--use-vnet] --br=3Dbridge --fd=3Du= nixfd\n"); + "Usage: qemu-bridge-helper [--use-vnet] --br=3Dbridge --fd=3Du= nixfd [--ifname=3Dname]\n"); } =20 static int parse_acl_file(const char *filename, ACLList *acl_list) @@ -223,6 +223,7 @@ int main(int argc, char **argv) int use_vnet =3D 0; int mtu; const char *bridge =3D NULL; + const char *ifname =3D NULL; char iface[IFNAMSIZ]; int index; ACLRule *acl_rule; @@ -249,6 +250,8 @@ int main(int argc, char **argv) bridge =3D &argv[index][5]; } else if (strncmp(argv[index], "--fd=3D", 5) =3D=3D 0) { unixfd =3D atoi(&argv[index][5]); + } else if (strncmp(argv[index], "--ifname=3D", 9) =3D=3D 0) { + ifname =3D &argv[index][9]; } else { usage(); return EXIT_FAILURE; @@ -320,7 +323,11 @@ int main(int argc, char **argv) =20 /* request a tap device, disable PI, and add vnet header support if * requested and it's available. */ - prep_ifreq(&ifr, "tap%d"); + if (ifname =3D=3D NULL) { + prep_ifreq(&ifr, "tap%d"); + } else { + prep_ifreq(&ifr, ifname); + } ifr.ifr_flags =3D IFF_TAP|IFF_NO_PI; if (use_vnet && has_vnet_hdr(fd)) { ifr.ifr_flags |=3D IFF_VNET_HDR; diff --git a/qemu-options.hx b/qemu-options.hx index 678181c..81cbc3c 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1961,7 +1961,7 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, " use 'queues=3Dn' to specify the number of queues to b= e created for multiqueue TAP\n" " use 'poll-us=3Dn' to speciy the maximum number of mic= roseconds that could be\n" " spent on busy polling for vhost net\n" - "-netdev bridge,id=3Dstr[,br=3Dbridge][,helper=3Dhelper]\n" + "-netdev bridge,id=3Dstr[,br=3Dbridge][,helper=3Dhelper][,ifname=3Dnam= e]\n" " configure a host TAP network backend with ID 'str' th= at is\n" " connected to a bridge (default=3D" DEFAULT_BRIDGE_INT= ERFACE ")\n" " using the program 'helper (default=3D" DEFAULT_BRIDGE= _HELPER ")\n" --=20 2.9.5