Use net_init_tap_one() in net_init_bridge() to be able in further
commits use net_init_bridge for "bridge" case of init_tap, as it has
the same first part, but requires tap-related things in
net_init_tap_one.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Tested-by: Lei Yang <leiyang@redhat.com>
---
net/tap.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/net/tap.c b/net/tap.c
index 7dc8f52831..01f9277211 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -88,6 +88,12 @@ static void launch_script(const char *setup_script, const char *ifname,
static void tap_send(void *opaque);
static void tap_writable(void *opaque);
+static int net_init_tap_one(const Netdev *netdev, NetClientState *peer,
+ const char *model, const char *name,
+ const char *ifname, const char *script,
+ const char *downscript, const char *vhostfdname,
+ int vnet_hdr, int fd, Error **errp);
+
static void tap_update_fd_handler(TAPState *s)
{
qemu_set_fd_handler(s->fd,
@@ -614,8 +620,7 @@ int net_init_bridge(const Netdev *netdev, const char *name,
{
const NetdevBridgeOptions *bridge;
const char *helper, *br;
- TAPState *s;
- int fd, vnet_hdr;
+ int fd, vnet_hdr, ret;
assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
bridge = &netdev->u.bridge;
@@ -635,9 +640,14 @@ int net_init_bridge(const Netdev *netdev, const char *name,
close(fd);
return -1;
}
- s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
- qemu_set_info_str(&s->nc, "helper=%s,br=%s", helper, br);
+ ret = net_init_tap_one(netdev, peer, "bridge", name,
+ NULL, NULL, NULL,
+ NULL, vnet_hdr, fd, errp);
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
return 0;
}
@@ -685,11 +695,19 @@ static int net_init_tap_one(const Netdev *netdev, NetClientState *peer,
const char *downscript, const char *vhostfdname,
int vnet_hdr, int fd, Error **errp)
{
- const NetdevTapOptions *tap = &netdev->u.tap;
+ const NetdevTapOptions *tap;
TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
int vhostfd;
+ if (netdev->type == NET_CLIENT_DRIVER_BRIDGE) {
+ const NetdevBridgeOptions *bridge = &netdev->u.bridge;
+ qemu_set_info_str(&s->nc, "helper=%s,br=%s",
+ bridge->helper, bridge->br);
+ return 0;
+ }
+
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
+ tap = &netdev->u.tap;
if (tap_set_sndbuf(s->fd, tap, errp) < 0) {
goto failed;
--
2.48.1