summaryrefslogtreecommitdiffstats
path: root/net/tap.c
diff options
context:
space:
mode:
authorPeter Maydell2021-04-08 17:45:31 +0200
committerPeter Maydell2021-04-08 17:45:31 +0200
commitce69aa92d71e13db9c3702a8e8305e8d2463aeb8 (patch)
treedb523c9f40dd1e69e3f0a829d20eb36898c25597 /net/tap.c
parentMerge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20210407b'... (diff)
parenttap-win32: correctly recycle buffers (diff)
downloadqemu-ce69aa92d71e13db9c3702a8e8305e8d2463aeb8.tar.gz
qemu-ce69aa92d71e13db9c3702a8e8305e8d2463aeb8.tar.xz
qemu-ce69aa92d71e13db9c3702a8e8305e8d2463aeb8.zip
Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging
# gpg: Signature made Thu 08 Apr 2021 10:34:24 BST # gpg: using RSA key EF04965B398D6211 # gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <jasowang@redhat.com>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 215D 46F4 8246 689E C77F 3562 EF04 965B 398D 6211 * remotes/jasowang/tags/net-pull-request: tap-win32: correctly recycle buffers Revert "qapi: net: Add query-netdev command" Revert "tests: Add tests for query-netdev command" Revert "net: Move NetClientState.info_str to dynamic allocations" Revert "hmp: Use QAPI NetdevInfo in hmp_info_network" Revert "net: Do not fill legacy info_str for backends" Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'net/tap.c')
-rw-r--r--net/tap.c107
1 files changed, 13 insertions, 94 deletions
diff --git a/net/tap.c b/net/tap.c
index d6d8456188..dd42ac6134 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -600,7 +600,6 @@ int net_init_bridge(const Netdev *netdev, const char *name,
const char *helper, *br;
TAPState *s;
int fd, vnet_hdr;
- NetdevBridgeOptions *stored;
assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
bridge = &netdev->u.bridge;
@@ -620,20 +619,8 @@ int net_init_bridge(const Netdev *netdev, const char *name,
}
s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
- /* Store startup parameters */
- s->nc.stored_config = g_new0(NetdevInfo, 1);
- s->nc.stored_config->type = NET_BACKEND_BRIDGE;
- stored = &s->nc.stored_config->u.bridge;
-
- if (br) {
- stored->has_br = true;
- stored->br = g_strdup(br);
- }
-
- if (helper) {
- stored->has_helper = true;
- stored->helper = g_strdup(helper);
- }
+ snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
+ br);
return 0;
}
@@ -679,13 +666,11 @@ static void net_init_tap_one(const NetdevTapOptions *tap, 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, NetdevInfo **common_stored,
- Error **errp)
+ int vnet_hdr, int fd, Error **errp)
{
Error *err = NULL;
TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
int vhostfd;
- NetdevTapOptions *stored;
tap_set_sndbuf(s->fd, tap, &err);
if (err) {
@@ -693,59 +678,15 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
return;
}
- /* Store startup parameters */
- if (!*common_stored) {
- *common_stored = g_new0(NetdevInfo, 1);
- (*common_stored)->type = NET_BACKEND_TAP;
- s->nc.stored_config = *common_stored;
- }
- stored = &(*common_stored)->u.tap;
-
- if (tap->has_sndbuf && !stored->has_sndbuf) {
- stored->has_sndbuf = true;
- stored->sndbuf = tap->sndbuf;
- }
-
- if (vnet_hdr && !stored->has_vnet_hdr) {
- stored->has_vnet_hdr = true;
- stored->vnet_hdr = true;
- }
-
if (tap->has_fd || tap->has_fds) {
- if (!stored->has_fds) {
- stored->has_fds = true;
- stored->fds = g_strdup_printf("%d", fd);
- } else {
- char *tmp_s = stored->fds;
- stored->fds = g_strdup_printf("%s:%d", stored->fds, fd);
- g_free(tmp_s);
- }
+ snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
} else if (tap->has_helper) {
- if (!stored->has_helper) {
- stored->has_helper = true;
- stored->helper = g_strdup(tap->helper);
- }
-
- if (!stored->has_br) {
- stored->has_br = true;
- stored->br = tap->has_br ? g_strdup(tap->br) :
- g_strdup(DEFAULT_BRIDGE_INTERFACE);
- }
+ snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s",
+ tap->helper);
} else {
- if (ifname && !stored->has_ifname) {
- stored->has_ifname = true;
- stored->ifname = g_strdup(ifname);
- }
-
- if (script && !stored->has_script) {
- stored->has_script = true;
- stored->script = g_strdup(script);
- }
-
- if (downscript && !stored->has_downscript) {
- stored->has_downscript = true;
- stored->downscript = g_strdup(downscript);
- }
+ snprintf(s->nc.info_str, sizeof(s->nc.info_str),
+ "ifname=%s,script=%s,downscript=%s", ifname, script,
+ downscript);
if (strcmp(downscript, "no") != 0) {
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
@@ -758,20 +699,9 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
vhostfdname || (tap->has_vhostforce && tap->vhostforce)) {
VhostNetOptions options;
- stored->has_vhost = true;
- stored->vhost = true;
-
- if (tap->has_vhostforce && tap->vhostforce) {
- stored->has_vhostforce = true;
- stored->vhostforce = true;
- }
-
options.backend_type = VHOST_BACKEND_TYPE_KERNEL;
options.net_backend = &s->nc;
if (tap->has_poll_us) {
- stored->has_poll_us = true;
- stored->poll_us = tap->poll_us;
-
options.busyloop_timeout = tap->poll_us;
} else {
options.busyloop_timeout = 0;
@@ -811,15 +741,6 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
}
options.opaque = (void *)(uintptr_t)vhostfd;
- if (!stored->has_vhostfds) {
- stored->has_vhostfds = true;
- stored->vhostfds = g_strdup_printf("%d", vhostfd);
- } else {
- char *tmp_s = stored->vhostfds;
- stored->vhostfds = g_strdup_printf("%s:%d", stored->fds, vhostfd);
- g_free(tmp_s);
- }
-
s->vhost_net = vhost_net_init(&options);
if (!s->vhost_net) {
if (tap->has_vhostforce && tap->vhostforce) {
@@ -872,7 +793,6 @@ int net_init_tap(const Netdev *netdev, const char *name,
const char *vhostfdname;
char ifname[128];
int ret = 0;
- NetdevInfo *common_stored = NULL; /* will store configuration */
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
tap = &netdev->u.tap;
@@ -919,7 +839,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
net_init_tap_one(tap, peer, "tap", name, NULL,
script, downscript,
- vhostfdname, vnet_hdr, fd, &common_stored, &err);
+ vhostfdname, vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
close(fd);
@@ -982,7 +902,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
net_init_tap_one(tap, peer, "tap", name, ifname,
script, downscript,
tap->has_vhostfds ? vhost_fds[i] : NULL,
- vnet_hdr, fd, &common_stored, &err);
+ vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
ret = -1;
@@ -1025,7 +945,7 @@ free_fail:
net_init_tap_one(tap, peer, "bridge", name, ifname,
script, downscript, vhostfdname,
- vnet_hdr, fd, &common_stored, &err);
+ vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
close(fd);
@@ -1071,8 +991,7 @@ free_fail:
net_init_tap_one(tap, peer, "tap", name, ifname,
i >= 1 ? "no" : script,
i >= 1 ? "no" : downscript,
- vhostfdname, vnet_hdr, fd,
- &common_stored, &err);
+ vhostfdname, vnet_hdr, fd, &err);
if (err) {
error_propagate(errp, err);
close(fd);