1
The following changes since commit 6632f6ff96f0537fc34cdc00c760656fc62e23c5:
1
The following changes since commit df722e33d5da26ea8604500ca8f509245a0ea524:
2
2
3
Merge remote-tracking branch 'remotes/famz/tags/block-and-testing-pull-request' into staging (2017-07-17 11:46:36 +0100)
3
Merge tag 'bsd-user-arm-pull-request' of gitlab.com:bsdimp/qemu into staging (2022-01-08 09:37:59 -0800)
4
4
5
are available in the git repository at:
5
are available in the git repository at:
6
6
7
https://github.com/jasowang/qemu.git tags/net-pull-request
7
https://github.com/jasowang/qemu.git tags/net-pull-request
8
8
9
for you to fetch changes up to 189ae6bb5ce1f5a322f8691d00fe942ba43dd601:
9
for you to fetch changes up to 5136cc6d3b8b74f4fa572f0874656947a401330e:
10
10
11
virtio-net: fix offload ctrl endian (2017-07-17 20:13:56 +0800)
11
net/vmnet: update MAINTAINERS list (2022-01-10 11:30:55 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
14
15
- fix virtio-net ctrl offload endian
15
----------------------------------------------------------------
16
- vnet header support for variou COLO netfilters and compare thread
16
Peter Foley (2):
17
net/tap: Set return code on failure
18
net: Fix uninitialized data usage
17
19
18
----------------------------------------------------------------
20
Philippe Mathieu-Daudé (1):
19
Jason Wang (1):
21
hw/net/vmxnet3: Log guest-triggerable errors using LOG_GUEST_ERROR
20
virtio-net: fix offload ctrl endian
21
22
22
Michal Privoznik (1):
23
Rao Lei (1):
23
virtion-net: Prefer is_power_of_2()
24
net/filter: Optimize filter_send to coroutine
24
25
25
Zhang Chen (12):
26
Vladislav Yaroshchuk (7):
26
net: Add vnet_hdr_len arguments in NetClientState
27
net/vmnet: add vmnet dependency and customizable option
27
net/net.c: Add vnet_hdr support in SocketReadState
28
net/vmnet: add vmnet backends to qapi/net
28
net/filter-mirror.c: Introduce parameter for filter_send()
29
net/vmnet: implement shared mode (vmnet-shared)
29
net/filter-mirror.c: Make filter mirror support vnet support.
30
net/vmnet: implement host mode (vmnet-host)
30
net/filter-mirror.c: Add new option to enable vnet support for filter-redirector
31
net/vmnet: implement bridged mode (vmnet-bridged)
31
net/colo.c: Make vnet_hdr_len as packet property
32
net/vmnet: update qemu-options.hx
32
net/colo-compare.c: Introduce parameter for compare_chr_send()
33
net/vmnet: update MAINTAINERS list
33
net/colo-compare.c: Make colo-compare support vnet_hdr_len
34
net/colo.c: Add vnet packet parse feature in colo-proxy
35
net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare
36
net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len
37
docs/colo-proxy.txt: Update colo-proxy usage of net driver with vnet_header
38
34
39
docs/colo-proxy.txt | 26 ++++++++++++++++
35
Zhang Chen (2):
40
hw/net/virtio-net.c | 4 ++-
36
net/colo-compare.c: Optimize compare order for performance
41
include/net/net.h | 10 ++++--
37
net/colo-compare.c: Update the default value comments
42
net/colo-compare.c | 84 ++++++++++++++++++++++++++++++++++++++++++---------
38
43
net/colo.c | 9 +++---
39
MAINTAINERS | 5 +
44
net/colo.h | 4 ++-
40
hw/net/vmxnet3.c | 4 +-
45
net/filter-mirror.c | 75 +++++++++++++++++++++++++++++++++++++++++----
41
meson.build | 4 +
46
net/filter-rewriter.c | 37 ++++++++++++++++++++++-
42
meson_options.txt | 2 +
47
net/net.c | 37 ++++++++++++++++++++---
43
net/clients.h | 11 ++
48
net/socket.c | 8 ++---
44
net/colo-compare.c | 28 ++--
49
qemu-options.hx | 19 ++++++------
45
net/filter-mirror.c | 66 +++++++--
50
11 files changed, 265 insertions(+), 48 deletions(-)
46
net/meson.build | 7 +
47
net/net.c | 10 ++
48
net/tap-linux.c | 1 +
49
net/tap.c | 1 +
50
net/vmnet-bridged.m | 111 ++++++++++++++
51
net/vmnet-common.m | 330 ++++++++++++++++++++++++++++++++++++++++++
52
net/vmnet-host.c | 105 ++++++++++++++
53
net/vmnet-shared.c | 91 ++++++++++++
54
net/vmnet_int.h | 48 ++++++
55
qapi/net.json | 132 ++++++++++++++++-
56
qemu-options.hx | 25 ++++
57
scripts/meson-buildoptions.sh | 3 +
58
19 files changed, 954 insertions(+), 30 deletions(-)
59
create mode 100644 net/vmnet-bridged.m
60
create mode 100644 net/vmnet-common.m
61
create mode 100644 net/vmnet-host.c
62
create mode 100644 net/vmnet-shared.c
63
create mode 100644 net/vmnet_int.h
51
64
52
65
66
diff view generated by jsdifflib
Deleted patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
1
3
Add vnet_hdr_len arguments in NetClientState
4
that make other module get real vnet_hdr_len easily.
5
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
9
include/net/net.h | 1 +
10
net/net.c | 1 +
11
2 files changed, 2 insertions(+)
12
13
diff --git a/include/net/net.h b/include/net/net.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/net/net.h
16
+++ b/include/net/net.h
17
@@ -XXX,XX +XXX,XX @@ struct NetClientState {
18
unsigned int queue_index;
19
unsigned rxfilter_notify_enabled:1;
20
int vring_enable;
21
+ int vnet_hdr_len;
22
QTAILQ_HEAD(NetFilterHead, NetFilterState) filters;
23
};
24
25
diff --git a/net/net.c b/net/net.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/net/net.c
28
+++ b/net/net.c
29
@@ -XXX,XX +XXX,XX @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len)
30
return;
31
}
32
33
+ nc->vnet_hdr_len = len;
34
nc->info->set_vnet_hdr_len(nc, len);
35
}
36
37
--
38
2.7.4
39
40
diff view generated by jsdifflib
1
Spec said offloads should be le64, so use virtio_ldq_p() to guarantee
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
valid endian.
3
2
4
Fixes: 644c98587d4c ("virtio-net: dynamic network offloads configuration")
3
The "Interrupt Cause" register (VMXNET3_REG_ICR) is read-only.
5
Cc: qemu-stable@nongnu.org
4
Write accesses are ignored. Log them with as LOG_GUEST_ERROR
6
Cc: Dmitry Fleytman <dfleytma@redhat.com>
5
instead of aborting:
6
7
[R +0.239743] writeq 0xe0002031 0x46291a5a55460800
8
ERROR:hw/net/vmxnet3.c:1819:vmxnet3_io_bar1_write: code should not be reached
9
Thread 1 "qemu-system-i38" received signal SIGABRT, Aborted.
10
(gdb) bt
11
#3 0x74c397d3 in __GI_abort () at abort.c:79
12
#4 0x76d3cd4c in g_assertion_message (domain=<optimized out>, file=<optimized out>, line=<optimized out>, func=<optimized out>, message=<optimized out>) at ../glib/gtestutils.c:3223
13
#5 0x76d9d45f in g_assertion_message_expr
14
(domain=0x0, file=0x59fc2e53 "hw/net/vmxnet3.c", line=1819, func=0x59fc11e0 <__func__.vmxnet3_io_bar1_write> "vmxnet3_io_bar1_write", expr=<optimized out>)
15
at ../glib/gtestutils.c:3249
16
#6 0x57e80a3a in vmxnet3_io_bar1_write (opaque=0x62814100, addr=56, val=70, size=4) at hw/net/vmxnet3.c:1819
17
#7 0x58c2d894 in memory_region_write_accessor (mr=0x62816b90, addr=56, value=0x7fff9450, size=4, shift=0, mask=4294967295, attrs=...) at softmmu/memory.c:492
18
#8 0x58c2d1d2 in access_with_adjusted_size (addr=56, value=0x7fff9450, size=1, access_size_min=4, access_size_max=4, access_fn=
19
0x58c2d290 <memory_region_write_accessor>, mr=0x62816b90, attrs=...) at softmmu/memory.c:554
20
#9 0x58c2bae7 in memory_region_dispatch_write (mr=0x62816b90, addr=56, data=70, op=MO_8, attrs=...) at softmmu/memory.c:1504
21
#10 0x58bfd034 in flatview_write_continue (fv=0x606000181700, addr=0xe0002038, attrs=..., ptr=0x7fffb9e0, len=1, addr1=56, l=1, mr=0x62816b90)
22
at softmmu/physmem.c:2782
23
#11 0x58beba00 in flatview_write (fv=0x606000181700, addr=0xe0002031, attrs=..., buf=0x7fffb9e0, len=8) at softmmu/physmem.c:2822
24
#12 0x58beb589 in address_space_write (as=0x608000015f20, addr=0xe0002031, attrs=..., buf=0x7fffb9e0, len=8) at softmmu/physmem.c:2914
25
26
Reported-by: Dike <dike199774@qq.com>
27
Reported-by: Duhao <504224090@qq.com>
28
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2032932
29
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
30
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
31
---
9
hw/net/virtio-net.c | 2 ++
32
hw/net/vmxnet3.c | 4 +++-
10
1 file changed, 2 insertions(+)
33
1 file changed, 3 insertions(+), 1 deletion(-)
11
34
12
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
35
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
13
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/net/virtio-net.c
37
--- a/hw/net/vmxnet3.c
15
+++ b/hw/net/virtio-net.c
38
+++ b/hw/net/vmxnet3.c
16
@@ -XXX,XX +XXX,XX @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
39
@@ -XXX,XX +XXX,XX @@ vmxnet3_io_bar1_write(void *opaque,
17
if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) {
40
case VMXNET3_REG_ICR:
18
uint64_t supported_offloads;
41
VMW_CBPRN("Write BAR1 [VMXNET3_REG_ICR] = %" PRIx64 ", size %d",
19
42
val, size);
20
+ offloads = virtio_ldq_p(vdev, &offloads);
43
- g_assert_not_reached();
21
+
44
+ qemu_log_mask(LOG_GUEST_ERROR,
22
if (!n->has_vnet_hdr) {
45
+ "%s: write to read-only register VMXNET3_REG_ICR\n",
23
return VIRTIO_NET_ERR;
46
+ TYPE_VMXNET3);
24
}
47
break;
48
49
/* Event Cause Register */
25
--
50
--
26
2.7.4
51
2.7.4
27
52
28
53
diff view generated by jsdifflib
1
From: Michal Privoznik <mprivozn@redhat.com>
1
From: Peter Foley <pefoley@google.com>
2
2
3
We have a function that checks if given number is power of two.
3
Match the other error handling in this function.
4
We should prefer it instead of expanding the check on our own.
5
4
6
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5
Fixes: e7b347d0bf6 ("net: detect errors from probing vnet hdr flag for TAP devices")
6
7
Reviewed-by: Patrick Venture <venture@google.com>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Peter Foley <pefoley@google.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
11
---
9
hw/net/virtio-net.c | 2 +-
12
net/tap.c | 1 +
10
1 file changed, 1 insertion(+), 1 deletion(-)
13
1 file changed, 1 insertion(+)
11
14
12
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
15
diff --git a/net/tap.c b/net/tap.c
13
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/net/virtio-net.c
17
--- a/net/tap.c
15
+++ b/hw/net/virtio-net.c
18
+++ b/net/tap.c
16
@@ -XXX,XX +XXX,XX @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
19
@@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name,
17
*/
20
if (i == 0) {
18
if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE ||
21
vnet_hdr = tap_probe_vnet_hdr(fd, errp);
19
n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE ||
22
if (vnet_hdr < 0) {
20
- (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) {
23
+ ret = -1;
21
+ !is_power_of_2(n->net_conf.rx_queue_size)) {
24
goto free_fail;
22
error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), "
25
}
23
"must be a power of 2 between %d and %d.",
26
} else if (vnet_hdr != tap_probe_vnet_hdr(fd, NULL)) {
24
n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE,
25
--
27
--
26
2.7.4
28
2.7.4
27
29
28
30
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Peter Foley <pefoley@google.com>
2
2
3
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
3
e.g.
4
1109 15:16:20.151506 Uninitialized bytes in ioctl_common_pre at offset 0 inside [0x7ffc516af9b8, 4)
5
1109 15:16:20.151659 ==588974==WARNING: MemorySanitizer: use-of-uninitialized-value
6
1109 15:16:20.312923 #0 0x5639b88acb21 in tap_probe_vnet_hdr_len third_party/qemu/net/tap-linux.c:183:9
7
1109 15:16:20.312952 #1 0x5639b88afd66 in net_tap_fd_init third_party/qemu/net/tap.c:409:9
8
1109 15:16:20.312954 #2 0x5639b88b2d1b in net_init_tap_one third_party/qemu/net/tap.c:681:19
9
1109 15:16:20.312956 #3 0x5639b88b16a8 in net_init_tap third_party/qemu/net/tap.c:912:13
10
1109 15:16:20.312957 #4 0x5639b8890175 in net_client_init1 third_party/qemu/net/net.c:1110:9
11
1109 15:16:20.312958 #5 0x5639b888f912 in net_client_init third_party/qemu/net/net.c:1208:15
12
1109 15:16:20.312960 #6 0x5639b8894aa5 in net_param_nic third_party/qemu/net/net.c:1588:11
13
1109 15:16:20.312961 #7 0x5639b900cd18 in qemu_opts_foreach third_party/qemu/util/qemu-option.c:1135:14
14
1109 15:16:20.312962 #8 0x5639b889393c in net_init_clients third_party/qemu/net/net.c:1612:9
15
1109 15:16:20.312964 #9 0x5639b717aaf3 in qemu_create_late_backends third_party/qemu/softmmu/vl.c:1962:5
16
1109 15:16:20.312965 #10 0x5639b717aaf3 in qemu_init third_party/qemu/softmmu/vl.c:3694:5
17
1109 15:16:20.312967 #11 0x5639b71083b8 in main third_party/qemu/softmmu/main.c:49:5
18
1109 15:16:20.312968 #12 0x7f464de1d8d2 in __libc_start_main (/usr/grte/v5/lib64/libc.so.6+0x628d2)
19
1109 15:16:20.312969 #13 0x5639b6bbd389 in _start /usr/grte/v5/debug-src/src/csu/../sysdeps/x86_64/start.S:120
20
1109 15:16:20.312970
21
1109 15:16:20.312975 Uninitialized value was stored to memory at
22
1109 15:16:20.313393 #0 0x5639b88acbee in tap_probe_vnet_hdr_len third_party/qemu/net/tap-linux.c
23
1109 15:16:20.313396 #1 0x5639b88afd66 in net_tap_fd_init third_party/qemu/net/tap.c:409:9
24
1109 15:16:20.313398 #2 0x5639b88b2d1b in net_init_tap_one third_party/qemu/net/tap.c:681:19
25
1109 15:16:20.313399 #3 0x5639b88b16a8 in net_init_tap third_party/qemu/net/tap.c:912:13
26
1109 15:16:20.313400 #4 0x5639b8890175 in net_client_init1 third_party/qemu/net/net.c:1110:9
27
1109 15:16:20.313401 #5 0x5639b888f912 in net_client_init third_party/qemu/net/net.c:1208:15
28
1109 15:16:20.313403 #6 0x5639b8894aa5 in net_param_nic third_party/qemu/net/net.c:1588:11
29
1109 15:16:20.313404 #7 0x5639b900cd18 in qemu_opts_foreach third_party/qemu/util/qemu-option.c:1135:14
30
1109 15:16:20.313405 #8 0x5639b889393c in net_init_clients third_party/qemu/net/net.c:1612:9
31
1109 15:16:20.313407 #9 0x5639b717aaf3 in qemu_create_late_backends third_party/qemu/softmmu/vl.c:1962:5
32
1109 15:16:20.313408 #10 0x5639b717aaf3 in qemu_init third_party/qemu/softmmu/vl.c:3694:5
33
1109 15:16:20.313409 #11 0x5639b71083b8 in main third_party/qemu/softmmu/main.c:49:5
34
1109 15:16:20.313410 #12 0x7f464de1d8d2 in __libc_start_main (/usr/grte/v5/lib64/libc.so.6+0x628d2)
35
1109 15:16:20.313412 #13 0x5639b6bbd389 in _start /usr/grte/v5/debug-src/src/csu/../sysdeps/x86_64/start.S:120
36
1109 15:16:20.313413
37
1109 15:16:20.313417 Uninitialized value was stored to memory at
38
1109 15:16:20.313791 #0 0x5639b88affbd in net_tap_fd_init third_party/qemu/net/tap.c:400:26
39
1109 15:16:20.313826 #1 0x5639b88b2d1b in net_init_tap_one third_party/qemu/net/tap.c:681:19
40
1109 15:16:20.313829 #2 0x5639b88b16a8 in net_init_tap third_party/qemu/net/tap.c:912:13
41
1109 15:16:20.313831 #3 0x5639b8890175 in net_client_init1 third_party/qemu/net/net.c:1110:9
42
1109 15:16:20.313836 #4 0x5639b888f912 in net_client_init third_party/qemu/net/net.c:1208:15
43
1109 15:16:20.313838 #5 0x5639b8894aa5 in net_param_nic third_party/qemu/net/net.c:1588:11
44
1109 15:16:20.313839 #6 0x5639b900cd18 in qemu_opts_foreach third_party/qemu/util/qemu-option.c:1135:14
45
1109 15:16:20.313841 #7 0x5639b889393c in net_init_clients third_party/qemu/net/net.c:1612:9
46
1109 15:16:20.313843 #8 0x5639b717aaf3 in qemu_create_late_backends third_party/qemu/softmmu/vl.c:1962:5
47
1109 15:16:20.313844 #9 0x5639b717aaf3 in qemu_init third_party/qemu/softmmu/vl.c:3694:5
48
1109 15:16:20.313845 #10 0x5639b71083b8 in main third_party/qemu/softmmu/main.c:49:5
49
1109 15:16:20.313846 #11 0x7f464de1d8d2 in __libc_start_main (/usr/grte/v5/lib64/libc.so.6+0x628d2)
50
1109 15:16:20.313847 #12 0x5639b6bbd389 in _start /usr/grte/v5/debug-src/src/csu/../sysdeps/x86_64/start.S:120
51
1109 15:16:20.313849
52
1109 15:16:20.313851 Uninitialized value was created by an allocation of 'ifr' in the stack frame of function 'tap_probe_vnet_hdr'
53
1109 15:16:20.313855 #0 0x5639b88ac680 in tap_probe_vnet_hdr third_party/qemu/net/tap-linux.c:151
54
1109 15:16:20.313856
55
1109 15:16:20.313878 SUMMARY: MemorySanitizer: use-of-uninitialized-value third_party/qemu/net/tap-linux.c:183:9 in tap_probe_vnet_hdr_len
56
57
Fixes: dc69004c7d8 ("net: move tap_probe_vnet_hdr() to tap-linux.c")
58
Reviewed-by: Hao Wu <wuhaotsh@google.com>
59
Reviewed-by: Patrick Venture <venture@google.com>
60
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
61
Signed-off-by: Peter Foley <pefoley@google.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
62
Signed-off-by: Jason Wang <jasowang@redhat.com>
5
---
63
---
6
docs/colo-proxy.txt | 26 ++++++++++++++++++++++++++
64
net/tap-linux.c | 1 +
7
1 file changed, 26 insertions(+)
65
1 file changed, 1 insertion(+)
8
66
9
diff --git a/docs/colo-proxy.txt b/docs/colo-proxy.txt
67
diff --git a/net/tap-linux.c b/net/tap-linux.c
10
index XXXXXXX..XXXXXXX 100644
68
index XXXXXXX..XXXXXXX 100644
11
--- a/docs/colo-proxy.txt
69
--- a/net/tap-linux.c
12
+++ b/docs/colo-proxy.txt
70
+++ b/net/tap-linux.c
13
@@ -XXX,XX +XXX,XX @@ Secondary(ip:3.3.3.8):
71
@@ -XXX,XX +XXX,XX @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
14
-chardev socket,id=red1,host=3.3.3.3,port=9004
72
int tap_probe_vnet_hdr(int fd, Error **errp)
15
-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0
73
{
16
-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1
74
struct ifreq ifr;
17
+-object filter-rewriter,id=f3,netdev=hn0,queue=all
75
+ memset(&ifr, 0, sizeof(ifr));
18
+
76
19
+If you want to use virtio-net-pci or other driver with vnet_header:
77
if (ioctl(fd, TUNGETIFF, &ifr) != 0) {
20
+
78
/* TUNGETIFF is available since kernel v2.6.27 */
21
+Primary(ip:3.3.3.3):
22
+-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown
23
+-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66
24
+-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait
25
+-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait
26
+-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait
27
+-chardev socket,id=compare0-0,host=3.3.3.3,port=9001
28
+-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait
29
+-chardev socket,id=compare_out0,host=3.3.3.3,port=9005
30
+-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support
31
+-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out,vnet_hdr_support
32
+-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0,vnet_hdr_support
33
+-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support
34
+
35
+Secondary(ip:3.3.3.8):
36
+-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown
37
+-device e1000,netdev=hn0,mac=52:a4:00:12:78:66
38
+-chardev socket,id=red0,host=3.3.3.3,port=9003
39
+-chardev socket,id=red1,host=3.3.3.3,port=9004
40
+-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0,vnet_hdr_support
41
+-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1,vnet_hdr_support
42
+-object filter-rewriter,id=f3,netdev=hn0,queue=all,vnet_hdr_support
43
44
Note:
45
a.COLO-proxy must work with COLO-frame and Block-replication.
46
--
79
--
47
2.7.4
80
2.7.4
48
81
49
82
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Zhang Chen <chen.zhang@intel.com>
2
2
3
We add the vnet_hdr_support option for colo-compare, default is disabled.
3
COLO-compare use the glib function g_queue_find_custom to dump
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
4
another VM's networking packet to compare. But this function always
5
You can use it for example:
5
start find from the queue->head(here is the newest packet), It will
6
-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support
6
reduce the success rate of comparison. So this patch reversed
7
the order of the queues for performance.
7
8
8
COLO-compare can get vnet header length from filter,
9
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
9
Add vnet_hdr_len to struct packet and output packet with
10
Reported-by: leirao <lei.rao@intel.com>
10
the vnet_hdr_len.
11
12
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
12
---
15
net/colo-compare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++-------
13
net/colo-compare.c | 26 +++++++++++++-------------
16
qemu-options.hx | 4 ++--
14
1 file changed, 13 insertions(+), 13 deletions(-)
17
2 files changed, 55 insertions(+), 9 deletions(-)
18
15
19
diff --git a/net/colo-compare.c b/net/colo-compare.c
16
diff --git a/net/colo-compare.c b/net/colo-compare.c
20
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
21
--- a/net/colo-compare.c
18
--- a/net/colo-compare.c
22
+++ b/net/colo-compare.c
19
+++ b/net/colo-compare.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct CompareState {
20
@@ -XXX,XX +XXX,XX @@ static void colo_compare_inconsistency_notify(CompareState *s)
24
CharBackend chr_out;
21
/* Use restricted to colo_insert_packet() */
25
SocketReadState pri_rs;
26
SocketReadState sec_rs;
27
+ bool vnet_hdr;
28
29
/* connection list: the connections belonged to this NIC could be found
30
* in this list.
31
@@ -XXX,XX +XXX,XX @@ enum {
32
33
static int compare_chr_send(CompareState *s,
34
const uint8_t *buf,
35
- uint32_t size);
36
+ uint32_t size,
37
+ uint32_t vnet_hdr_len);
38
39
static gint seq_sorter(Packet *a, Packet *b, gpointer data)
22
static gint seq_sorter(Packet *a, Packet *b, gpointer data)
40
{
23
{
41
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
24
- return a->tcp_seq - b->tcp_seq;
42
}
25
+ return b->tcp_seq - a->tcp_seq;
43
44
if (result) {
45
- ret = compare_chr_send(s, pkt->data, pkt->size);
46
+ ret = compare_chr_send(s,
47
+ pkt->data,
48
+ pkt->size,
49
+ pkt->vnet_hdr_len);
50
if (ret < 0) {
51
error_report("colo_send_primary_packet failed");
52
}
53
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
54
55
static int compare_chr_send(CompareState *s,
56
const uint8_t *buf,
57
- uint32_t size)
58
+ uint32_t size,
59
+ uint32_t vnet_hdr_len)
60
{
61
int ret = 0;
62
uint32_t len = htonl(size);
63
@@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CompareState *s,
64
goto err;
65
}
66
67
+ if (s->vnet_hdr) {
68
+ /*
69
+ * We send vnet header len make other module(like filter-redirector)
70
+ * know how to parse net packet correctly.
71
+ */
72
+ len = htonl(vnet_hdr_len);
73
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
74
+ if (ret != sizeof(len)) {
75
+ goto err;
76
+ }
77
+ }
78
+
79
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
80
if (ret != size) {
81
goto err;
82
@@ -XXX,XX +XXX,XX @@ static void compare_set_outdev(Object *obj, const char *value, Error **errp)
83
s->outdev = g_strdup(value);
84
}
26
}
85
27
86
+static bool compare_get_vnet_hdr(Object *obj, Error **errp)
28
static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
87
+{
29
@@ -XXX,XX +XXX,XX @@ pri:
88
+ CompareState *s = COLO_COMPARE(obj);
30
if (g_queue_is_empty(&conn->primary_list)) {
89
+
90
+ return s->vnet_hdr;
91
+}
92
+
93
+static void compare_set_vnet_hdr(Object *obj,
94
+ bool value,
95
+ Error **errp)
96
+{
97
+ CompareState *s = COLO_COMPARE(obj);
98
+
99
+ s->vnet_hdr = value;
100
+}
101
+
102
static void compare_pri_rs_finalize(SocketReadState *pri_rs)
103
{
104
CompareState *s = container_of(pri_rs, CompareState, pri_rs);
105
106
if (packet_enqueue(s, PRIMARY_IN)) {
107
trace_colo_compare_main("primary: unsupported packet in");
108
- compare_chr_send(s, pri_rs->buf, pri_rs->packet_len);
109
+ compare_chr_send(s,
110
+ pri_rs->buf,
111
+ pri_rs->packet_len,
112
+ pri_rs->vnet_hdr_len);
113
} else {
114
/* compare connection */
115
g_queue_foreach(&s->conn_list, colo_compare_connection, s);
116
@@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
117
return;
31
return;
118
}
32
}
119
33
- ppkt = g_queue_pop_head(&conn->primary_list);
120
- net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false);
34
+ ppkt = g_queue_pop_tail(&conn->primary_list);
121
- net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false);
35
sec:
122
+ net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);
36
if (g_queue_is_empty(&conn->secondary_list)) {
123
+ net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);
37
- g_queue_push_head(&conn->primary_list, ppkt);
124
38
+ g_queue_push_tail(&conn->primary_list, ppkt);
125
g_queue_init(&s->conn_list);
39
return;
126
40
}
41
- spkt = g_queue_pop_head(&conn->secondary_list);
42
+ spkt = g_queue_pop_tail(&conn->secondary_list);
43
44
if (ppkt->tcp_seq == ppkt->seq_end) {
45
colo_release_primary_pkt(s, ppkt);
46
@@ -XXX,XX +XXX,XX @@ sec:
47
}
48
}
49
if (!ppkt) {
50
- g_queue_push_head(&conn->secondary_list, spkt);
51
+ g_queue_push_tail(&conn->secondary_list, spkt);
52
goto pri;
53
}
54
}
55
@@ -XXX,XX +XXX,XX @@ sec:
56
if (mark == COLO_COMPARE_FREE_PRIMARY) {
57
conn->compare_seq = ppkt->seq_end;
58
colo_release_primary_pkt(s, ppkt);
59
- g_queue_push_head(&conn->secondary_list, spkt);
60
+ g_queue_push_tail(&conn->secondary_list, spkt);
61
goto pri;
62
} else if (mark == COLO_COMPARE_FREE_SECONDARY) {
63
conn->compare_seq = spkt->seq_end;
64
@@ -XXX,XX +XXX,XX @@ sec:
65
goto pri;
66
}
67
} else {
68
- g_queue_push_head(&conn->primary_list, ppkt);
69
- g_queue_push_head(&conn->secondary_list, spkt);
70
+ g_queue_push_tail(&conn->primary_list, ppkt);
71
+ g_queue_push_tail(&conn->secondary_list, spkt);
72
73
#ifdef DEBUG_COLO_PACKETS
74
qemu_hexdump(stderr, "colo-compare ppkt", ppkt->data, ppkt->size);
75
@@ -XXX,XX +XXX,XX @@ static void colo_compare_packet(CompareState *s, Connection *conn,
76
77
while (!g_queue_is_empty(&conn->primary_list) &&
78
!g_queue_is_empty(&conn->secondary_list)) {
79
- pkt = g_queue_pop_head(&conn->primary_list);
80
+ pkt = g_queue_pop_tail(&conn->primary_list);
81
result = g_queue_find_custom(&conn->secondary_list,
82
pkt, (GCompareFunc)HandlePacket);
83
84
@@ -XXX,XX +XXX,XX @@ static void colo_compare_packet(CompareState *s, Connection *conn,
85
* timeout, it will trigger a checkpoint request.
86
*/
87
trace_colo_compare_main("packet different");
88
- g_queue_push_head(&conn->primary_list, pkt);
89
+ g_queue_push_tail(&conn->primary_list, pkt);
90
91
colo_compare_inconsistency_notify(s);
92
break;
93
@@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CompareState *s,
94
entry->buf = g_malloc(size);
95
memcpy(entry->buf, buf, size);
96
}
97
- g_queue_push_head(&sendco->send_list, entry);
98
+ g_queue_push_tail(&sendco->send_list, entry);
99
100
if (sendco->done) {
101
sendco->co = qemu_coroutine_create(_compare_chr_send, sendco);
127
@@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data)
102
@@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data)
103
Packet *pkt = NULL;
128
104
129
while (!g_queue_is_empty(&conn->primary_list)) {
105
while (!g_queue_is_empty(&conn->primary_list)) {
130
pkt = g_queue_pop_head(&conn->primary_list);
106
- pkt = g_queue_pop_head(&conn->primary_list);
131
- compare_chr_send(s, pkt->data, pkt->size);
107
+ pkt = g_queue_pop_tail(&conn->primary_list);
132
+ compare_chr_send(s,
108
compare_chr_send(s,
133
+ pkt->data,
109
pkt->data,
134
+ pkt->size,
110
pkt->size,
135
+ pkt->vnet_hdr_len);
111
@@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data)
112
packet_destroy_partial(pkt, NULL);
113
}
114
while (!g_queue_is_empty(&conn->secondary_list)) {
115
- pkt = g_queue_pop_head(&conn->secondary_list);
116
+ pkt = g_queue_pop_tail(&conn->secondary_list);
136
packet_destroy(pkt, NULL);
117
packet_destroy(pkt, NULL);
137
}
118
}
138
while (!g_queue_is_empty(&conn->secondary_list)) {
139
@@ -XXX,XX +XXX,XX @@ static void colo_compare_class_init(ObjectClass *oc, void *data)
140
141
static void colo_compare_init(Object *obj)
142
{
143
+ CompareState *s = COLO_COMPARE(obj);
144
+
145
object_property_add_str(obj, "primary_in",
146
compare_get_pri_indev, compare_set_pri_indev,
147
NULL);
148
@@ -XXX,XX +XXX,XX @@ static void colo_compare_init(Object *obj)
149
object_property_add_str(obj, "outdev",
150
compare_get_outdev, compare_set_outdev,
151
NULL);
152
+
153
+ s->vnet_hdr = false;
154
+ object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
155
+ compare_set_vnet_hdr, NULL);
156
}
119
}
157
158
static void colo_compare_finalize(Object *obj)
159
diff --git a/qemu-options.hx b/qemu-options.hx
160
index XXXXXXX..XXXXXXX 100644
161
--- a/qemu-options.hx
162
+++ b/qemu-options.hx
163
@@ -XXX,XX +XXX,XX @@ Dump the network traffic on netdev @var{dev} to the file specified by
164
The file format is libpcap, so it can be analyzed with tools such as tcpdump
165
or Wireshark.
166
167
-@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},
168
-outdev=@var{chardevid}
169
+@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},outdev=@var{chardevid}[,vnet_hdr_support]
170
171
Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with
172
secondary packet. If the packets are same, we will output primary
173
packet to outdev@var{chardevid}, else we will notify colo-frame
174
do checkpoint and send primary packet to outdev@var{chardevid}.
175
+if it has the vnet_hdr_support flag, colo compare will send/recv packet with vnet_hdr_len.
176
177
we must use it with the help of filter-mirror and filter-redirector.
178
179
--
120
--
180
2.7.4
121
2.7.4
181
122
182
123
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Zhang Chen <chen.zhang@intel.com>
2
2
3
COLO-Proxy just focus on packet payload, so we skip vnet header.
3
Make the comments consistent with the REGULAR_PACKET_CHECK_MS.
4
4
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
5
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
7
---
8
net/colo-compare.c | 8 ++++++--
8
net/colo-compare.c | 2 +-
9
1 file changed, 6 insertions(+), 2 deletions(-)
9
1 file changed, 1 insertion(+), 1 deletion(-)
10
10
11
diff --git a/net/colo-compare.c b/net/colo-compare.c
11
diff --git a/net/colo-compare.c b/net/colo-compare.c
12
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
13
--- a/net/colo-compare.c
13
--- a/net/colo-compare.c
14
+++ b/net/colo-compare.c
14
+++ b/net/colo-compare.c
15
@@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset)
15
@@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
16
sec_ip_src, sec_ip_dst);
17
}
16
}
18
17
19
+ offset = ppkt->vnet_hdr_len + offset;
18
if (!s->expired_scan_cycle) {
20
+
19
- /* Set default value to 3000 MS */
21
if (ppkt->size == spkt->size) {
20
+ /* Set default value to 1000 MS */
22
- return memcmp(ppkt->data + offset, spkt->data + offset,
21
s->expired_scan_cycle = REGULAR_PACKET_CHECK_MS;
23
+ return memcmp(ppkt->data + offset,
22
}
24
+ spkt->data + offset,
23
25
spkt->size - offset);
26
} else {
27
trace_colo_compare_main("Net packet size are not the same");
28
@@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
29
*/
30
if (ptcp->th_off > 5) {
31
ptrdiff_t tcp_offset;
32
+
33
tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data
34
- + (ptcp->th_off * 4);
35
+ + (ptcp->th_off * 4) - ppkt->vnet_hdr_len;
36
res = colo_packet_compare_common(ppkt, spkt, tcp_offset);
37
} else if (ptcp->th_sum == stcp->th_sum) {
38
res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN);
39
--
24
--
40
2.7.4
25
2.7.4
41
26
42
27
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Rao Lei <lei.rao@intel.com>
2
2
3
This patch change the filter_send() parameter from CharBackend to MirrorState,
3
This patch is to improve the logic of QEMU main thread sleep code in
4
we can get more information like vnet_hdr(We use it to support packet with vnet_header).
4
qemu_chr_write_buffer() where it can be blocked and can't run other
5
coroutines during COLO IO stress test.
5
6
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Our approach is to put filter_send() in a coroutine. In this way,
8
filter_send() will call qemu_coroutine_yield() in qemu_co_sleep_ns(),
9
so that it can be scheduled out and QEMU main thread has opportunity to
10
run other tasks.
11
12
Signed-off-by: Lei Rao <lei.rao@intel.com>
13
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
14
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
15
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
16
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
17
---
9
net/filter-mirror.c | 10 +++++-----
18
net/filter-mirror.c | 66 ++++++++++++++++++++++++++++++++++++++++++-----------
10
1 file changed, 5 insertions(+), 5 deletions(-)
19
1 file changed, 53 insertions(+), 13 deletions(-)
11
20
12
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
21
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
13
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
14
--- a/net/filter-mirror.c
23
--- a/net/filter-mirror.c
15
+++ b/net/filter-mirror.c
24
+++ b/net/filter-mirror.c
16
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorState {
25
@@ -XXX,XX +XXX,XX @@
17
SocketReadState rs;
26
#include "chardev/char-fe.h"
18
} MirrorState;
27
#include "qemu/iov.h"
19
28
#include "qemu/sockets.h"
20
-static int filter_send(CharBackend *chr_out,
29
+#include "block/aio-wait.h"
21
+static int filter_send(MirrorState *s,
30
22
const struct iovec *iov,
31
#define TYPE_FILTER_MIRROR "filter-mirror"
23
int iovcnt)
32
typedef struct MirrorState MirrorState;
33
@@ -XXX,XX +XXX,XX @@ struct MirrorState {
34
bool vnet_hdr;
35
};
36
37
-static int filter_send(MirrorState *s,
38
- const struct iovec *iov,
39
- int iovcnt)
40
+typedef struct FilterSendCo {
41
+ MirrorState *s;
42
+ char *buf;
43
+ ssize_t size;
44
+ bool done;
45
+ int ret;
46
+} FilterSendCo;
47
+
48
+static int _filter_send(MirrorState *s,
49
+ char *buf,
50
+ ssize_t size)
24
{
51
{
25
@@ -XXX,XX +XXX,XX @@ static int filter_send(CharBackend *chr_out,
52
NetFilterState *nf = NETFILTER(s);
53
int ret = 0;
54
- ssize_t size = 0;
55
uint32_t len = 0;
56
- char *buf;
57
-
58
- size = iov_size(iov, iovcnt);
59
- if (!size) {
60
- return 0;
61
- }
62
63
len = htonl(size);
64
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
65
@@ -XXX,XX +XXX,XX @@ static int filter_send(MirrorState *s,
66
}
26
}
67
}
27
68
28
len = htonl(size);
69
- buf = g_malloc(size);
29
- ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)&len, sizeof(len));
70
- iov_to_buf(iov, iovcnt, 0, buf, size);
30
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
71
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
31
if (ret != sizeof(len)) {
72
- g_free(buf);
73
if (ret != size) {
32
goto err;
74
goto err;
33
}
75
}
34
76
@@ -XXX,XX +XXX,XX @@ err:
35
buf = g_malloc(size);
77
return ret < 0 ? ret : -EIO;
36
iov_to_buf(iov, iovcnt, 0, buf, size);
78
}
37
- ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)buf, size);
79
38
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
80
+static void coroutine_fn filter_send_co(void *opaque)
39
g_free(buf);
81
+{
40
if (ret != size) {
82
+ FilterSendCo *data = opaque;
41
goto err;
83
+
42
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
84
+ data->ret = _filter_send(data->s, data->buf, data->size);
43
MirrorState *s = FILTER_MIRROR(nf);
85
+ data->done = true;
44
int ret;
86
+ g_free(data->buf);
45
87
+ aio_wait_kick();
46
- ret = filter_send(&s->chr_out, iov, iovcnt);
88
+}
47
+ ret = filter_send(s, iov, iovcnt);
89
+
48
if (ret) {
90
+static int filter_send(MirrorState *s,
49
error_report("filter mirror send failed(%s)", strerror(-ret));
91
+ const struct iovec *iov,
50
}
92
+ int iovcnt)
51
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf,
93
+{
52
int ret;
94
+ ssize_t size = iov_size(iov, iovcnt);
53
95
+ char *buf = NULL;
54
if (qemu_chr_fe_backend_connected(&s->chr_out)) {
96
+
55
- ret = filter_send(&s->chr_out, iov, iovcnt);
97
+ if (!size) {
56
+ ret = filter_send(s, iov, iovcnt);
98
+ return 0;
57
if (ret) {
99
+ }
58
error_report("filter redirector send failed(%s)", strerror(-ret));
100
+
59
}
101
+ buf = g_malloc(size);
102
+ iov_to_buf(iov, iovcnt, 0, buf, size);
103
+
104
+ FilterSendCo data = {
105
+ .s = s,
106
+ .size = size,
107
+ .buf = buf,
108
+ .ret = 0,
109
+ };
110
+
111
+ Coroutine *co = qemu_coroutine_create(filter_send_co, &data);
112
+ qemu_coroutine_enter(co);
113
+
114
+ while (!data.done) {
115
+ aio_poll(qemu_get_aio_context(), true);
116
+ }
117
+
118
+ return data.ret;
119
+}
120
+
121
static void redirector_to_filter(NetFilterState *nf,
122
const uint8_t *buf,
123
int len)
60
--
124
--
61
2.7.4
125
2.7.4
62
126
63
127
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
Make colo-compare and filter-rewriter can parse vnet packet.
3
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
4
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
5
---
8
net/colo.c | 6 +++---
6
meson.build | 4 ++++
9
1 file changed, 3 insertions(+), 3 deletions(-)
7
meson_options.txt | 2 ++
8
scripts/meson-buildoptions.sh | 3 +++
9
3 files changed, 9 insertions(+)
10
10
11
diff --git a/net/colo.c b/net/colo.c
11
diff --git a/meson.build b/meson.build
12
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
13
--- a/net/colo.c
13
--- a/meson.build
14
+++ b/net/colo.c
14
+++ b/meson.build
15
@@ -XXX,XX +XXX,XX @@ int parse_packet_early(Packet *pkt)
15
@@ -XXX,XX +XXX,XX @@ if cocoa.found() and get_option('gtk').enabled()
16
{
16
error('Cocoa and GTK+ cannot be enabled at the same time')
17
int network_length;
17
endif
18
static const uint8_t vlan[] = {0x81, 0x00};
18
19
- uint8_t *data = pkt->data;
19
+vmnet = dependency('appleframeworks', modules: 'vmnet', required: get_option('vmnet'))
20
+ uint8_t *data = pkt->data + pkt->vnet_hdr_len;
20
+
21
uint16_t l3_proto;
21
seccomp = not_found
22
ssize_t l2hdr_len = eth_get_l2_hdr_length(data);
22
if not get_option('seccomp').auto() or have_system or have_tools
23
23
seccomp = dependency('libseccomp', version: '>=2.3.0',
24
- if (pkt->size < ETH_HLEN) {
24
@@ -XXX,XX +XXX,XX @@ config_host_data.set('CONFIG_SECCOMP', seccomp.found())
25
+ if (pkt->size < ETH_HLEN + pkt->vnet_hdr_len) {
25
config_host_data.set('CONFIG_SNAPPY', snappy.found())
26
trace_colo_proxy_main("pkt->size < ETH_HLEN");
26
config_host_data.set('CONFIG_USB_LIBUSB', libusb.found())
27
return 1;
27
config_host_data.set('CONFIG_VDE', vde.found())
28
}
28
+config_host_data.set('CONFIG_VMNET', vmnet.found())
29
@@ -XXX,XX +XXX,XX @@ int parse_packet_early(Packet *pkt)
29
config_host_data.set('CONFIG_VHOST_USER_BLK_SERVER', have_vhost_user_blk_server)
30
}
30
config_host_data.set('CONFIG_VNC', vnc.found())
31
31
config_host_data.set('CONFIG_VNC_JPEG', jpeg.found())
32
network_length = pkt->ip->ip_hl * 4;
32
@@ -XXX,XX +XXX,XX @@ endif
33
- if (pkt->size < l2hdr_len + network_length) {
33
summary_info += {'JACK support': jack}
34
+ if (pkt->size < l2hdr_len + network_length + pkt->vnet_hdr_len) {
34
summary_info += {'brlapi support': brlapi}
35
trace_colo_proxy_main("pkt->size < network_header + network_length");
35
summary_info += {'vde support': vde}
36
return 1;
36
+summary_info += {'vmnet.framework support': vmnet}
37
}
37
summary_info += {'netmap support': have_netmap}
38
summary_info += {'l2tpv3 support': have_l2tpv3}
39
summary_info += {'Linux AIO support': libaio}
40
diff --git a/meson_options.txt b/meson_options.txt
41
index XXXXXXX..XXXXXXX 100644
42
--- a/meson_options.txt
43
+++ b/meson_options.txt
44
@@ -XXX,XX +XXX,XX @@ option('netmap', type : 'feature', value : 'auto',
45
description: 'netmap network backend support')
46
option('vde', type : 'feature', value : 'auto',
47
description: 'vde network backend support')
48
+option('vmnet', type : 'feature', value : 'auto',
49
+ description: 'vmnet.framework network backend support')
50
option('virglrenderer', type : 'feature', value : 'auto',
51
description: 'virgl rendering support')
52
option('vnc', type : 'feature', value : 'auto',
53
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
54
index XXXXXXX..XXXXXXX 100644
55
--- a/scripts/meson-buildoptions.sh
56
+++ b/scripts/meson-buildoptions.sh
57
@@ -XXX,XX +XXX,XX @@ meson_options_help() {
58
printf "%s\n" ' u2f U2F emulation support'
59
printf "%s\n" ' usb-redir libusbredir support'
60
printf "%s\n" ' vde vde network backend support'
61
+ printf "%s\n" ' vmnet vmnet.framework network backend support'
62
printf "%s\n" ' vhost-user-blk-server'
63
printf "%s\n" ' build vhost-user-blk server'
64
printf "%s\n" ' virglrenderer virgl rendering support'
65
@@ -XXX,XX +XXX,XX @@ _meson_option_parse() {
66
--disable-usb-redir) printf "%s" -Dusb_redir=disabled ;;
67
--enable-vde) printf "%s" -Dvde=enabled ;;
68
--disable-vde) printf "%s" -Dvde=disabled ;;
69
+ --enable-vmnet) printf "%s" -Dvmnet=enabled ;;
70
+ --disable-vmnet) printf "%s" -Dvmnet=disabled ;;
71
--enable-vhost-user-blk-server) printf "%s" -Dvhost_user_blk_server=enabled ;;
72
--disable-vhost-user-blk-server) printf "%s" -Dvhost_user_blk_server=disabled ;;
73
--enable-virglrenderer) printf "%s" -Dvirglrenderer=enabled ;;
38
--
74
--
39
2.7.4
75
2.7.4
40
76
41
77
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
We add a flag to decide whether net_fill_rstate() need read
3
The vmnet framework is an API for virtual machines to read and write
4
the vnet_hdr_len or not.
4
packets.
5
5
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
The API allows a Guest OS interface to be in host mode or shared
7
Suggested-by: Jason Wang <jasowang@redhat.com>
7
mode. Interfaces in host mode can communicate with the native host
8
system and other interfaces running in host mode. In shared mode, the
9
network interface can send and receive packets to the Internet, the
10
native host, and other interfaces running in sharing mode.
11
12
Create separate netdevs for each vmnet operating mode:
13
14
- vmnet-host
15
- vmnet-shared
16
- vmnet-bridged
17
18
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
19
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
---
20
---
10
include/net/net.h | 9 +++++++--
21
net/clients.h | 11 +++++
11
net/colo-compare.c | 4 ++--
22
net/meson.build | 7 +++
12
net/filter-mirror.c | 2 +-
23
net/net.c | 10 ++++
13
net/net.c | 36 ++++++++++++++++++++++++++++++++----
24
net/vmnet-bridged.m | 25 ++++++++++
14
net/socket.c | 8 ++++----
25
net/vmnet-common.m | 19 ++++++++
15
5 files changed, 46 insertions(+), 13 deletions(-)
26
net/vmnet-host.c | 24 ++++++++++
16
27
net/vmnet-shared.c | 25 ++++++++++
17
diff --git a/include/net/net.h b/include/net/net.h
28
net/vmnet_int.h | 25 ++++++++++
29
qapi/net.json | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++-
30
9 files changed, 276 insertions(+), 2 deletions(-)
31
create mode 100644 net/vmnet-bridged.m
32
create mode 100644 net/vmnet-common.m
33
create mode 100644 net/vmnet-host.c
34
create mode 100644 net/vmnet-shared.c
35
create mode 100644 net/vmnet_int.h
36
37
diff --git a/net/clients.h b/net/clients.h
18
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX 100644
19
--- a/include/net/net.h
39
--- a/net/clients.h
20
+++ b/include/net/net.h
40
+++ b/net/clients.h
21
@@ -XXX,XX +XXX,XX @@ typedef struct NICState {
41
@@ -XXX,XX +XXX,XX @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
22
} NICState;
42
23
43
int net_init_vhost_vdpa(const Netdev *netdev, const char *name,
24
struct SocketReadState {
44
NetClientState *peer, Error **errp);
25
- int state; /* 0 = getting length, 1 = getting data */
45
+#ifdef CONFIG_VMNET
26
+ /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
46
+int net_init_vmnet_host(const Netdev *netdev, const char *name,
27
+ int state;
47
+ NetClientState *peer, Error **errp);
28
+ /* This flag decide whether to read the vnet_hdr_len field */
48
+
29
+ bool vnet_hdr;
49
+int net_init_vmnet_shared(const Netdev *netdev, const char *name,
30
uint32_t index;
50
+ NetClientState *peer, Error **errp);
31
uint32_t packet_len;
51
+
32
+ uint32_t vnet_hdr_len;
52
+int net_init_vmnet_bridged(const Netdev *netdev, const char *name,
33
uint8_t buf[NET_BUFSIZE];
53
+ NetClientState *peer, Error **errp);
34
SocketReadStateFinalize *finalize;
54
+#endif /* CONFIG_VMNET */
35
};
55
+
36
@@ -XXX,XX +XXX,XX @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender,
56
#endif /* QEMU_NET_CLIENTS_H */
37
void print_net_client(Monitor *mon, NetClientState *nc);
57
diff --git a/net/meson.build b/net/meson.build
38
void hmp_info_network(Monitor *mon, const QDict *qdict);
39
void net_socket_rs_init(SocketReadState *rs,
40
- SocketReadStateFinalize *finalize);
41
+ SocketReadStateFinalize *finalize,
42
+ bool vnet_hdr);
43
44
/* NIC info */
45
46
diff --git a/net/colo-compare.c b/net/colo-compare.c
47
index XXXXXXX..XXXXXXX 100644
58
index XXXXXXX..XXXXXXX 100644
48
--- a/net/colo-compare.c
59
--- a/net/meson.build
49
+++ b/net/colo-compare.c
60
+++ b/net/meson.build
50
@@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
61
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files(tap_posix))
51
return;
62
softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('tap-win32.c'))
52
}
63
softmmu_ss.add(when: 'CONFIG_VHOST_NET_VDPA', if_true: files('vhost-vdpa.c'))
53
64
54
- net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize);
65
+vmnet_files = files(
55
- net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize);
66
+ 'vmnet-common.m',
56
+ net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false);
67
+ 'vmnet-bridged.m',
57
+ net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false);
68
+ 'vmnet-host.c',
58
69
+ 'vmnet-shared.c'
59
g_queue_init(&s->conn_list);
70
+)
60
71
+softmmu_ss.add(when: vmnet, if_true: vmnet_files)
61
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
72
subdir('can')
62
index XXXXXXX..XXXXXXX 100644
63
--- a/net/filter-mirror.c
64
+++ b/net/filter-mirror.c
65
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp)
66
}
67
}
68
69
- net_socket_rs_init(&s->rs, redirector_rs_finalize);
70
+ net_socket_rs_init(&s->rs, redirector_rs_finalize, false);
71
72
if (s->indev) {
73
chr = qemu_chr_find(s->indev);
74
diff --git a/net/net.c b/net/net.c
73
diff --git a/net/net.c b/net/net.c
75
index XXXXXXX..XXXXXXX 100644
74
index XXXXXXX..XXXXXXX 100644
76
--- a/net/net.c
75
--- a/net/net.c
77
+++ b/net/net.c
76
+++ b/net/net.c
78
@@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_net_opts = {
77
@@ -XXX,XX +XXX,XX @@ static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
78
#ifdef CONFIG_L2TPV3
79
[NET_CLIENT_DRIVER_L2TPV3] = net_init_l2tpv3,
80
#endif
81
+#ifdef CONFIG_VMNET
82
+ [NET_CLIENT_DRIVER_VMNET_HOST] = net_init_vmnet_host,
83
+ [NET_CLIENT_DRIVER_VMNET_SHARED] = net_init_vmnet_shared,
84
+ [NET_CLIENT_DRIVER_VMNET_BRIDGED] = net_init_vmnet_bridged,
85
+#endif /* CONFIG_VMNET */
79
};
86
};
80
87
81
void net_socket_rs_init(SocketReadState *rs,
88
82
- SocketReadStateFinalize *finalize)
89
@@ -XXX,XX +XXX,XX @@ void show_netdevs(void)
83
+ SocketReadStateFinalize *finalize,
90
#ifdef CONFIG_VHOST_VDPA
84
+ bool vnet_hdr)
91
"vhost-vdpa",
85
{
92
#endif
86
rs->state = 0;
93
+#ifdef CONFIG_VMNET
87
+ rs->vnet_hdr = vnet_hdr;
94
+ "vmnet-host",
88
rs->index = 0;
95
+ "vmnet-shared",
89
rs->packet_len = 0;
96
+ "vmnet-bridged",
90
+ rs->vnet_hdr_len = 0;
97
+#endif
91
memset(rs->buf, 0, sizeof(rs->buf));
98
};
92
rs->finalize = finalize;
99
93
}
100
qemu_printf("Available netdev backend types:\n");
94
@@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
101
diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m
95
unsigned int l;
102
new file mode 100644
96
103
index XXXXXXX..XXXXXXX
97
while (size > 0) {
104
--- /dev/null
98
- /* reassemble a packet from the network */
105
+++ b/net/vmnet-bridged.m
99
- switch (rs->state) { /* 0 = getting length, 1 = getting data */
106
@@ -XXX,XX +XXX,XX @@
100
+ /* Reassemble a packet from the network.
107
+/*
101
+ * 0 = getting length.
108
+ * vmnet-bridged.m
102
+ * 1 = getting vnet header length.
109
+ *
103
+ * 2 = getting data.
110
+ * Copyright(c) 2021 Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
104
+ */
111
+ *
105
+ switch (rs->state) {
112
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
106
case 0:
113
+ * See the COPYING file in the top-level directory.
107
l = 4 - rs->index;
114
+ *
108
if (l > size) {
115
+ */
109
@@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
116
+
110
/* got length */
117
+#include "qemu/osdep.h"
111
rs->packet_len = ntohl(*(uint32_t *)rs->buf);
118
+#include "qapi/qapi-types-net.h"
112
rs->index = 0;
119
+#include "vmnet_int.h"
113
- rs->state = 1;
120
+#include "clients.h"
114
+ if (rs->vnet_hdr) {
121
+#include "qemu/error-report.h"
115
+ rs->state = 1;
122
+#include "qapi/error.h"
116
+ } else {
123
+
117
+ rs->state = 2;
124
+#include <vmnet/vmnet.h>
118
+ rs->vnet_hdr_len = 0;
125
+
119
+ }
126
+int net_init_vmnet_bridged(const Netdev *netdev, const char *name,
120
}
127
+ NetClientState *peer, Error **errp)
121
break;
128
+{
122
case 1:
129
+ error_setg(errp, "vmnet-bridged is not implemented yet");
123
+ l = 4 - rs->index;
130
+ return -1;
124
+ if (l > size) {
131
+}
125
+ l = size;
132
diff --git a/net/vmnet-common.m b/net/vmnet-common.m
126
+ }
133
new file mode 100644
127
+ memcpy(rs->buf + rs->index, buf, l);
134
index XXXXXXX..XXXXXXX
128
+ buf += l;
135
--- /dev/null
129
+ size -= l;
136
+++ b/net/vmnet-common.m
130
+ rs->index += l;
137
@@ -XXX,XX +XXX,XX @@
131
+ if (rs->index == 4) {
138
+/*
132
+ /* got vnet header length */
139
+ * vmnet-common.m - network client wrapper for Apple vmnet.framework
133
+ rs->vnet_hdr_len = ntohl(*(uint32_t *)rs->buf);
140
+ *
134
+ rs->index = 0;
141
+ * Copyright(c) 2021 Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
135
+ rs->state = 2;
142
+ * Copyright(c) 2021 Phillip Tennen <phillip@axleos.com>
136
+ }
143
+ *
137
+ break;
144
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
138
+ case 2:
145
+ * See the COPYING file in the top-level directory.
139
l = rs->packet_len - rs->index;
146
+ *
140
if (l > size) {
147
+ */
141
l = size;
148
+
142
diff --git a/net/socket.c b/net/socket.c
149
+#include "qemu/osdep.h"
150
+#include "qapi/qapi-types-net.h"
151
+#include "vmnet_int.h"
152
+#include "clients.h"
153
+#include "qemu/error-report.h"
154
+#include "qapi/error.h"
155
+
156
+#include <vmnet/vmnet.h>
157
diff --git a/net/vmnet-host.c b/net/vmnet-host.c
158
new file mode 100644
159
index XXXXXXX..XXXXXXX
160
--- /dev/null
161
+++ b/net/vmnet-host.c
162
@@ -XXX,XX +XXX,XX @@
163
+/*
164
+ * vmnet-host.c
165
+ *
166
+ * Copyright(c) 2021 Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
167
+ *
168
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
169
+ * See the COPYING file in the top-level directory.
170
+ *
171
+ */
172
+
173
+#include "qemu/osdep.h"
174
+#include "qapi/qapi-types-net.h"
175
+#include "vmnet_int.h"
176
+#include "clients.h"
177
+#include "qemu/error-report.h"
178
+#include "qapi/error.h"
179
+
180
+#include <vmnet/vmnet.h>
181
+
182
+int net_init_vmnet_host(const Netdev *netdev, const char *name,
183
+ NetClientState *peer, Error **errp) {
184
+ error_setg(errp, "vmnet-host is not implemented yet");
185
+ return -1;
186
+}
187
diff --git a/net/vmnet-shared.c b/net/vmnet-shared.c
188
new file mode 100644
189
index XXXXXXX..XXXXXXX
190
--- /dev/null
191
+++ b/net/vmnet-shared.c
192
@@ -XXX,XX +XXX,XX @@
193
+/*
194
+ * vmnet-shared.c
195
+ *
196
+ * Copyright(c) 2021 Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
197
+ *
198
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
199
+ * See the COPYING file in the top-level directory.
200
+ *
201
+ */
202
+
203
+#include "qemu/osdep.h"
204
+#include "qapi/qapi-types-net.h"
205
+#include "vmnet_int.h"
206
+#include "clients.h"
207
+#include "qemu/error-report.h"
208
+#include "qapi/error.h"
209
+
210
+#include <vmnet/vmnet.h>
211
+
212
+int net_init_vmnet_shared(const Netdev *netdev, const char *name,
213
+ NetClientState *peer, Error **errp)
214
+{
215
+ error_setg(errp, "vmnet-shared is not implemented yet");
216
+ return -1;
217
+}
218
diff --git a/net/vmnet_int.h b/net/vmnet_int.h
219
new file mode 100644
220
index XXXXXXX..XXXXXXX
221
--- /dev/null
222
+++ b/net/vmnet_int.h
223
@@ -XXX,XX +XXX,XX @@
224
+/*
225
+ * vmnet_int.h
226
+ *
227
+ * Copyright(c) 2021 Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
228
+ *
229
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
230
+ * See the COPYING file in the top-level directory.
231
+ *
232
+ */
233
+#ifndef VMNET_INT_H
234
+#define VMNET_INT_H
235
+
236
+#include "qemu/osdep.h"
237
+#include "vmnet_int.h"
238
+#include "clients.h"
239
+
240
+#include <vmnet/vmnet.h>
241
+
242
+typedef struct VmnetCommonState {
243
+ NetClientState nc;
244
+
245
+} VmnetCommonState;
246
+
247
+
248
+#endif /* VMNET_INT_H */
249
diff --git a/qapi/net.json b/qapi/net.json
143
index XXXXXXX..XXXXXXX 100644
250
index XXXXXXX..XXXXXXX 100644
144
--- a/net/socket.c
251
--- a/qapi/net.json
145
+++ b/net/socket.c
252
+++ b/qapi/net.json
146
@@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque)
253
@@ -XXX,XX +XXX,XX @@
147
closesocket(s->fd);
254
'*queues': 'int' } }
148
255
149
s->fd = -1;
256
##
150
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
257
+# @NetdevVmnetHostOptions:
151
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
258
+#
152
s->nc.link_down = true;
259
+# vmnet (host mode) network backend.
153
memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
260
+#
154
261
+# Allows the vmnet interface to communicate with other vmnet
155
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
262
+# interfaces that are in host mode and also with the host.
156
s->fd = fd;
263
+#
157
s->listen_fd = -1;
264
+# @start-address: The starting IPv4 address to use for the interface.
158
s->send_fn = net_socket_send_dgram;
265
+# Must be in the private IP range (RFC 1918). Must be
159
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
266
+# specified along with @end-address and @subnet-mask.
160
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
267
+# This address is used as the gateway address. The
161
net_socket_read_poll(s, true);
268
+# subsequent address up to and including end-address are
162
269
+# placed in the DHCP pool.
163
/* mcast: save bound address as dst */
270
+#
164
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
271
+# @end-address: The DHCP IPv4 range end address to use for the
165
272
+# interface. Must be in the private IP range (RFC 1918).
166
s->fd = fd;
273
+# Must be specified along with @start-address and
167
s->listen_fd = -1;
274
+# @subnet-mask.
168
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
275
+#
169
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
276
+# @subnet-mask: The IPv4 subnet mask to use on the interface. Must
170
277
+# be specified along with @start-address and @subnet-mask.
171
/* Disable Nagle algorithm on TCP sockets to reduce latency */
278
+#
172
socket_set_nodelay(fd);
279
+# @isolated: Enable isolation for this interface. Interface isolation
173
@@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer,
280
+# ensures that vmnet interface is not able to communicate
174
s->fd = -1;
281
+# with any other vmnet interfaces. Only communication with
175
s->listen_fd = fd;
282
+# host is allowed.
176
s->nc.link_down = true;
283
+#
177
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
284
+# @net-uuid: The identifier (UUID) to uniquely identify the isolated
178
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
285
+# network vmnet interface should be added to. If
179
286
+# set, no DHCP service is provided for this interface and
180
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
287
+# network communication is allowed only with other interfaces
181
return 0;
288
+# added to this network identified by the UUID.
289
+#
290
+# Since: 7.0
291
+##
292
+{ 'struct': 'NetdevVmnetHostOptions',
293
+ 'data': {
294
+ '*start-address': 'str',
295
+ '*end-address': 'str',
296
+ '*subnet-mask': 'str',
297
+ '*isolated': 'bool',
298
+ '*net-uuid': 'str' },
299
+ 'if': 'CONFIG_VMNET' }
300
+
301
+##
302
+# @NetdevVmnetSharedOptions:
303
+#
304
+# vmnet (shared mode) network backend.
305
+#
306
+# Allows traffic originating from the vmnet interface to reach the
307
+# Internet through a network address translator (NAT).
308
+# The vmnet interface can communicate with the host and with
309
+# other shared mode interfaces on the same subnet. If no DHCP
310
+# settings, subnet mask and IPv6 prefix specified, the interface can
311
+# communicate with any of other interfaces in shared mode.
312
+#
313
+# @start-address: The starting IPv4 address to use for the interface.
314
+# Must be in the private IP range (RFC 1918). Must be
315
+# specified along with @end-address and @subnet-mask.
316
+# This address is used as the gateway address. The
317
+# subsequent address up to and including end-address are
318
+# placed in the DHCP pool.
319
+#
320
+# @end-address: The DHCP IPv4 range end address to use for the
321
+# interface. Must be in the private IP range (RFC 1918).
322
+# Must be specified along with @start-address and @subnet-mask.
323
+#
324
+# @subnet-mask: The IPv4 subnet mask to use on the interface. Must
325
+# be specified along with @start-address and @subnet-mask.
326
+#
327
+# @isolated: Enable isolation for this interface. Interface isolation
328
+# ensures that vmnet interface is not able to communicate
329
+# with any other vmnet interfaces. Only communication with
330
+# host is allowed.
331
+#
332
+# @nat66-prefix: The IPv6 prefix to use into guest network. Must be a
333
+# unique local address i.e. start with fd00::/8 and have
334
+# length of 64.
335
+#
336
+# Since: 7.0
337
+##
338
+{ 'struct': 'NetdevVmnetSharedOptions',
339
+ 'data': {
340
+ '*start-address': 'str',
341
+ '*end-address': 'str',
342
+ '*subnet-mask': 'str',
343
+ '*isolated': 'bool',
344
+ '*nat66-prefix': 'str' },
345
+ 'if': 'CONFIG_VMNET' }
346
+
347
+##
348
+# @NetdevVmnetBridgedOptions:
349
+#
350
+# vmnet (bridged mode) network backend.
351
+#
352
+# Bridges the vmnet interface with a physical network interface.
353
+#
354
+# @ifname: The name of the physical interface to be bridged.
355
+#
356
+# @isolated: Enable isolation for this interface. Interface isolation
357
+# ensures that vmnet interface is not able to communicate
358
+# with any other vmnet interfaces. Only communication with
359
+# host is allowed.
360
+#
361
+# Since: 7.0
362
+##
363
+{ 'struct': 'NetdevVmnetBridgedOptions',
364
+ 'data': {
365
+ 'ifname': 'str',
366
+ '*isolated': 'str' },
367
+ 'if': 'CONFIG_VMNET' }
368
+
369
+##
370
# @NetClientDriver:
371
#
372
# Available netdev drivers.
373
@@ -XXX,XX +XXX,XX @@
374
# Since: 2.7
375
#
376
# @vhost-vdpa since 5.1
377
+# @vmnet-host since 7.0
378
+# @vmnet-shared since 7.0
379
+# @vmnet-bridged since 7.0
380
##
381
{ 'enum': 'NetClientDriver',
382
'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde',
383
- 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa' ] }
384
+ 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa',
385
+ { 'name': 'vmnet-host', 'if': 'CONFIG_VMNET' },
386
+ { 'name': 'vmnet-shared', 'if': 'CONFIG_VMNET' },
387
+ { 'name': 'vmnet-bridged', 'if': 'CONFIG_VMNET' }] }
388
389
##
390
# @Netdev:
391
@@ -XXX,XX +XXX,XX @@
392
# Since: 1.2
393
#
394
# 'l2tpv3' - since 2.1
395
+# 'vmnet-host' - since 7.0
396
+# 'vmnet-shared' - since 7.0
397
+# 'vmnet-bridged' - since 7.0
398
##
399
{ 'union': 'Netdev',
400
'base': { 'id': 'str', 'type': 'NetClientDriver' },
401
@@ -XXX,XX +XXX,XX @@
402
'hubport': 'NetdevHubPortOptions',
403
'netmap': 'NetdevNetmapOptions',
404
'vhost-user': 'NetdevVhostUserOptions',
405
- 'vhost-vdpa': 'NetdevVhostVDPAOptions' } }
406
+ 'vhost-vdpa': 'NetdevVhostVDPAOptions',
407
+ 'vmnet-host': { 'type': 'NetdevVmnetHostOptions',
408
+ 'if': 'CONFIG_VMNET' },
409
+ 'vmnet-shared': { 'type': 'NetdevVmnetSharedOptions',
410
+ 'if': 'CONFIG_VMNET' },
411
+ 'vmnet-bridged': { 'type': 'NetdevVmnetBridgedOptions',
412
+ 'if': 'CONFIG_VMNET' } } }
413
414
##
415
# @RxState:
182
--
416
--
183
2.7.4
417
2.7.4
184
418
185
419
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
This patch change the compare_chr_send() parameter from CharBackend to CompareState,
3
Interaction with vmnet.framework in different modes
4
we can get more information like vnet_hdr(We use it to support packet with vnet_header).
4
differs only on configuration stage, so we can create
5
5
common `send`, `receive`, etc. procedures and reuse them.
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
7
vmnet.framework supports iov, but writing more than
8
one iov into vmnet interface fails with
9
'VMNET_INVALID_ARGUMENT'. Collecting provided iovs into
10
one and passing it to vmnet works fine. That's the
11
reason why receive_iov() left unimplemented. But it still
12
works with good enough performance having .receive()
13
implemented only.
14
15
Also, there is no way to unsubscribe from vmnet packages
16
receiving except registering and unregistering event
17
callback or simply drop packages just ignoring and
18
not processing them when related flag is set. Here we do
19
using the second way.
20
21
Signed-off-by: Phillip Tennen <phillip@axleos.com>
22
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
23
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
24
---
9
net/colo-compare.c | 14 +++++++-------
25
net/vmnet-common.m | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++
10
1 file changed, 7 insertions(+), 7 deletions(-)
26
net/vmnet-shared.c | 74 ++++++++++++-
11
27
net/vmnet_int.h | 23 ++++
12
diff --git a/net/colo-compare.c b/net/colo-compare.c
28
3 files changed, 404 insertions(+), 4 deletions(-)
29
30
diff --git a/net/vmnet-common.m b/net/vmnet-common.m
13
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
14
--- a/net/colo-compare.c
32
--- a/net/vmnet-common.m
15
+++ b/net/colo-compare.c
33
+++ b/net/vmnet-common.m
16
@@ -XXX,XX +XXX,XX @@ enum {
34
@@ -XXX,XX +XXX,XX @@
17
SECONDARY_IN,
35
*/
18
};
36
19
37
#include "qemu/osdep.h"
20
-static int compare_chr_send(CharBackend *out,
38
+#include "qemu/main-loop.h"
21
+static int compare_chr_send(CompareState *s,
39
+#include "qemu/log.h"
22
const uint8_t *buf,
40
#include "qapi/qapi-types-net.h"
23
uint32_t size);
41
#include "vmnet_int.h"
24
42
#include "clients.h"
25
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
43
@@ -XXX,XX +XXX,XX @@
26
}
44
#include "qapi/error.h"
27
45
28
if (result) {
46
#include <vmnet/vmnet.h>
29
- ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size);
47
+#include <dispatch/dispatch.h>
30
+ ret = compare_chr_send(s, pkt->data, pkt->size);
48
+
31
if (ret < 0) {
49
+#ifdef DEBUG
32
error_report("colo_send_primary_packet failed");
50
+#define D(x) x
33
}
51
+#define D_LOG(...) qemu_log(__VA_ARGS__)
34
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
52
+#else
35
}
53
+#define D(x) do { } while (0)
54
+#define D_LOG(...) do { } while (0)
55
+#endif
56
+
57
+typedef struct vmpktdesc vmpktdesc_t;
58
+typedef struct iovec iovec_t;
59
+
60
+static void vmnet_set_send_enabled(VmnetCommonState *s, bool enable)
61
+{
62
+ s->send_enabled = enable;
63
+}
64
+
65
+
66
+static void vmnet_send_completed(NetClientState *nc, ssize_t len)
67
+{
68
+ VmnetCommonState *s = DO_UPCAST(VmnetCommonState, nc, nc);
69
+ vmnet_set_send_enabled(s, true);
70
+}
71
+
72
+
73
+static void vmnet_send(NetClientState *nc,
74
+ interface_event_t event_id,
75
+ xpc_object_t event)
76
+{
77
+ assert(event_id == VMNET_INTERFACE_PACKETS_AVAILABLE);
78
+
79
+ VmnetCommonState *s;
80
+ uint64_t packets_available;
81
+
82
+ struct iovec *iov;
83
+ struct vmpktdesc *packets;
84
+ int pkt_cnt;
85
+ int i;
86
+
87
+ vmnet_return_t if_status;
88
+ ssize_t size;
89
+
90
+ s = DO_UPCAST(VmnetCommonState, nc, nc);
91
+
92
+ packets_available = xpc_dictionary_get_uint64(
93
+ event,
94
+ vmnet_estimated_packets_available_key
95
+ );
96
+
97
+ pkt_cnt = (packets_available < VMNET_PACKETS_LIMIT) ?
98
+ packets_available :
99
+ VMNET_PACKETS_LIMIT;
100
+
101
+
102
+ iov = s->iov_buf;
103
+ packets = s->packets_buf;
104
+
105
+ for (i = 0; i < pkt_cnt; ++i) {
106
+ packets[i].vm_pkt_size = s->max_packet_size;
107
+ packets[i].vm_pkt_iovcnt = 1;
108
+ packets[i].vm_flags = 0;
109
+ }
110
+
111
+ if_status = vmnet_read(s->vmnet_if, packets, &pkt_cnt);
112
+ if (if_status != VMNET_SUCCESS) {
113
+ error_printf("vmnet: read failed: %s\n",
114
+ vmnet_status_map_str(if_status));
115
+ }
116
+ qemu_mutex_lock_iothread();
117
+ for (i = 0; i < pkt_cnt; ++i) {
118
+ size = qemu_send_packet_async(nc,
119
+ iov[i].iov_base,
120
+ packets[i].vm_pkt_size,
121
+ vmnet_send_completed);
122
+ if (size == 0) {
123
+ vmnet_set_send_enabled(s, false);
124
+ } else if (size < 0) {
125
+ break;
126
+ }
127
+ }
128
+ qemu_mutex_unlock_iothread();
129
+
130
+}
131
+
132
+
133
+static void vmnet_register_event_callback(VmnetCommonState *s)
134
+{
135
+ dispatch_queue_t avail_pkt_q = dispatch_queue_create(
136
+ "org.qemu.vmnet.if_queue",
137
+ DISPATCH_QUEUE_SERIAL
138
+ );
139
+
140
+ vmnet_interface_set_event_callback(
141
+ s->vmnet_if,
142
+ VMNET_INTERFACE_PACKETS_AVAILABLE,
143
+ avail_pkt_q,
144
+ ^(interface_event_t event_id, xpc_object_t event) {
145
+ if (s->send_enabled) {
146
+ vmnet_send(&s->nc, event_id, event);
147
+ }
148
+ });
149
+}
150
+
151
+
152
+static void vmnet_bufs_init(VmnetCommonState *s)
153
+{
154
+ int i;
155
+ struct vmpktdesc *packets;
156
+ struct iovec *iov;
157
+
158
+ packets = s->packets_buf;
159
+ iov = s->iov_buf;
160
+
161
+ for (i = 0; i < VMNET_PACKETS_LIMIT; ++i) {
162
+ iov[i].iov_len = s->max_packet_size;
163
+ iov[i].iov_base = g_malloc0(iov[i].iov_len);
164
+ packets[i].vm_pkt_iov = iov + i;
165
+ }
166
+}
167
+
168
+
169
+const char *vmnet_status_map_str(vmnet_return_t status)
170
+{
171
+ switch (status) {
172
+ case VMNET_SUCCESS:
173
+ return "success";
174
+ case VMNET_FAILURE:
175
+ return "general failure";
176
+ case VMNET_MEM_FAILURE:
177
+ return "memory allocation failure";
178
+ case VMNET_INVALID_ARGUMENT:
179
+ return "invalid argument specified";
180
+ case VMNET_SETUP_INCOMPLETE:
181
+ return "interface setup is not complete";
182
+ case VMNET_INVALID_ACCESS:
183
+ return "invalid access, permission denied";
184
+ case VMNET_PACKET_TOO_BIG:
185
+ return "packet size is larger than MTU";
186
+ case VMNET_BUFFER_EXHAUSTED:
187
+ return "buffers exhausted in kernel";
188
+ case VMNET_TOO_MANY_PACKETS:
189
+ return "packet count exceeds limit";
190
+ case VMNET_SHARING_SERVICE_BUSY:
191
+ return "conflict, sharing service is in use";
192
+ default:
193
+ return "unknown vmnet error";
194
+ }
195
+}
196
+
197
+
198
+int vmnet_if_create(NetClientState *nc,
199
+ xpc_object_t if_desc,
200
+ Error **errp,
201
+ void (*completion_callback)(xpc_object_t interface_param))
202
+{
203
+ VmnetCommonState *s;
204
+
205
+ dispatch_queue_t if_create_q;
206
+ dispatch_semaphore_t if_created_sem;
207
+
208
+ __block vmnet_return_t if_status;
209
+
210
+ if_create_q = dispatch_queue_create("org.qemu.vmnet.create",
211
+ DISPATCH_QUEUE_SERIAL);
212
+ if_created_sem = dispatch_semaphore_create(0);
213
+
214
+ xpc_dictionary_set_bool(
215
+ if_desc,
216
+ vmnet_allocate_mac_address_key,
217
+ false
218
+ );
219
+
220
+ D(D_LOG("vmnet.start.interface_desc:\n");
221
+ xpc_dictionary_apply(if_desc,
222
+ ^bool(const char *k, xpc_object_t v) {
223
+ char *desc = xpc_copy_description(v);
224
+ D_LOG(" %s=%s\n", k, desc);
225
+ free(desc);
226
+ return true;
227
+ }));
228
+
229
+ s = DO_UPCAST(VmnetCommonState, nc, nc);
230
+ s->vmnet_if = vmnet_start_interface(
231
+ if_desc,
232
+ if_create_q,
233
+ ^(vmnet_return_t status, xpc_object_t interface_param) {
234
+ if_status = status;
235
+ if (status != VMNET_SUCCESS || !interface_param) {
236
+ dispatch_semaphore_signal(if_created_sem);
237
+ return;
238
+ }
239
+
240
+ D(D_LOG("vmnet.start.interface_param:\n");
241
+ xpc_dictionary_apply(interface_param,
242
+ ^bool(const char *k, xpc_object_t v) {
243
+ char *desc = xpc_copy_description(v);
244
+ D_LOG(" %s=%s\n", k, desc);
245
+ free(desc);
246
+ return true;
247
+ }));
248
+
249
+ s->mtu = xpc_dictionary_get_uint64(
250
+ interface_param,
251
+ vmnet_mtu_key);
252
+ s->max_packet_size = xpc_dictionary_get_uint64(
253
+ interface_param,
254
+ vmnet_max_packet_size_key);
255
+
256
+ if (completion_callback) {
257
+ completion_callback(interface_param);
258
+ }
259
+ dispatch_semaphore_signal(if_created_sem);
260
+ });
261
+
262
+ if (s->vmnet_if == NULL) {
263
+ error_setg(errp, "unable to create interface with requested params");
264
+ return -1;
265
+ }
266
+
267
+ dispatch_semaphore_wait(if_created_sem, DISPATCH_TIME_FOREVER);
268
+ dispatch_release(if_create_q);
269
+
270
+ if (if_status != VMNET_SUCCESS) {
271
+ error_setg(errp,
272
+ "cannot create vmnet interface: %s",
273
+ vmnet_status_map_str(if_status));
274
+ return -1;
275
+ }
276
+
277
+ vmnet_register_event_callback(s);
278
+ vmnet_bufs_init(s);
279
+ vmnet_set_send_enabled(s, true);
280
+
281
+ return 0;
282
+}
283
+
284
+
285
+ssize_t vmnet_receive_common(NetClientState *nc,
286
+ const uint8_t *buf,
287
+ size_t size)
288
+{
289
+ VmnetCommonState *s;
290
+ vmpktdesc_t packet;
291
+ iovec_t iov;
292
+ int pkt_cnt;
293
+ vmnet_return_t if_status;
294
+
295
+ s = DO_UPCAST(VmnetCommonState, nc, nc);
296
+
297
+ if (size > s->max_packet_size) {
298
+ warn_report("vmnet: packet is too big, %zu > %llu\n",
299
+ packet.vm_pkt_size,
300
+ s->max_packet_size);
301
+ return -1;
302
+ }
303
+
304
+ iov.iov_base = (char *) buf;
305
+ iov.iov_len = size;
306
+
307
+ packet.vm_pkt_iovcnt = 1;
308
+ packet.vm_flags = 0;
309
+ packet.vm_pkt_size = size;
310
+ packet.vm_pkt_iov = &iov;
311
+
312
+ pkt_cnt = 1;
313
+ if_status = vmnet_write(s->vmnet_if, &packet, &pkt_cnt);
314
+
315
+ if (if_status != VMNET_SUCCESS) {
316
+ error_report("vmnet: write error: %s\n",
317
+ vmnet_status_map_str(if_status));
318
+ }
319
+
320
+ if (if_status == VMNET_SUCCESS && pkt_cnt) {
321
+ return size;
322
+ }
323
+ return 0;
324
+}
325
+
326
+
327
+void vmnet_cleanup_common(NetClientState *nc)
328
+{
329
+ VmnetCommonState *s;
330
+ dispatch_queue_t if_destroy_q;
331
+
332
+ s = DO_UPCAST(VmnetCommonState, nc, nc);
333
+
334
+ qemu_purge_queued_packets(nc);
335
+ vmnet_set_send_enabled(s, false);
336
+
337
+ if (s->vmnet_if == NULL) {
338
+ return;
339
+ }
340
+
341
+ if_destroy_q = dispatch_queue_create(
342
+ "org.qemu.vmnet.destroy",
343
+ DISPATCH_QUEUE_SERIAL
344
+ );
345
+
346
+ vmnet_stop_interface(
347
+ s->vmnet_if,
348
+ if_destroy_q,
349
+ ^(vmnet_return_t status) {
350
+ });
351
+
352
+ for (int i = 0; i < VMNET_PACKETS_LIMIT; ++i) {
353
+ g_free(s->iov_buf[i].iov_base);
354
+ }
355
+}
356
diff --git a/net/vmnet-shared.c b/net/vmnet-shared.c
357
index XXXXXXX..XXXXXXX 100644
358
--- a/net/vmnet-shared.c
359
+++ b/net/vmnet-shared.c
360
@@ -XXX,XX +XXX,XX @@
361
362
#include "qemu/osdep.h"
363
#include "qapi/qapi-types-net.h"
364
+#include "qapi/error.h"
365
#include "vmnet_int.h"
366
#include "clients.h"
367
-#include "qemu/error-report.h"
368
-#include "qapi/error.h"
369
370
#include <vmnet/vmnet.h>
371
372
+typedef struct VmnetSharedState {
373
+ VmnetCommonState cs;
374
+} VmnetSharedState;
375
+
376
+
377
+static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp)
378
+{
379
+ const NetdevVmnetSharedOptions *options = &(netdev->u.vmnet_shared);
380
+ xpc_object_t if_desc = xpc_dictionary_create(NULL, NULL, 0);
381
+
382
+ xpc_dictionary_set_uint64(
383
+ if_desc,
384
+ vmnet_operation_mode_key,
385
+ VMNET_SHARED_MODE
386
+ );
387
+
388
+ xpc_dictionary_set_bool(
389
+ if_desc,
390
+ vmnet_enable_isolation_key,
391
+ options->isolated
392
+ );
393
+
394
+ if (options->has_nat66_prefix) {
395
+ xpc_dictionary_set_string(if_desc,
396
+ vmnet_nat66_prefix_key,
397
+ options->nat66_prefix);
398
+ }
399
+
400
+ if (options->has_start_address ||
401
+ options->has_end_address ||
402
+ options->has_subnet_mask) {
403
+
404
+ if (options->has_start_address &&
405
+ options->has_end_address &&
406
+ options->has_subnet_mask) {
407
+
408
+ xpc_dictionary_set_string(if_desc,
409
+ vmnet_start_address_key,
410
+ options->start_address);
411
+ xpc_dictionary_set_string(if_desc,
412
+ vmnet_end_address_key,
413
+ options->end_address);
414
+ xpc_dictionary_set_string(if_desc,
415
+ vmnet_subnet_mask_key,
416
+ options->subnet_mask);
417
+ } else {
418
+ error_setg(
419
+ errp,
420
+ "'start-address', 'end-address', 'subnet_mask' "
421
+ "should be provided together"
422
+ );
423
+ }
424
+ }
425
+
426
+ return if_desc;
427
+}
428
+
429
+static NetClientInfo net_vmnet_shared_info = {
430
+ .type = NET_CLIENT_DRIVER_VMNET_SHARED,
431
+ .size = sizeof(VmnetSharedState),
432
+ .receive = vmnet_receive_common,
433
+ .cleanup = vmnet_cleanup_common,
434
+};
435
+
436
int net_init_vmnet_shared(const Netdev *netdev, const char *name,
437
NetClientState *peer, Error **errp)
438
{
439
- error_setg(errp, "vmnet-shared is not implemented yet");
440
- return -1;
441
+ NetClientState *nc = qemu_new_net_client(&net_vmnet_shared_info,
442
+ peer, "vmnet-shared", name);
443
+ xpc_object_t if_desc = create_if_desc(netdev, errp);
444
+
445
+ return vmnet_if_create(nc, if_desc, errp, NULL);
36
}
446
}
37
447
diff --git a/net/vmnet_int.h b/net/vmnet_int.h
38
-static int compare_chr_send(CharBackend *out,
448
index XXXXXXX..XXXXXXX 100644
39
+static int compare_chr_send(CompareState *s,
449
--- a/net/vmnet_int.h
40
const uint8_t *buf,
450
+++ b/net/vmnet_int.h
41
uint32_t size)
451
@@ -XXX,XX +XXX,XX @@
42
{
452
43
@@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CharBackend *out,
453
#include <vmnet/vmnet.h>
44
return 0;
454
45
}
455
+#define VMNET_PACKETS_LIMIT 50
46
456
+
47
- ret = qemu_chr_fe_write_all(out, (uint8_t *)&len, sizeof(len));
457
typedef struct VmnetCommonState {
48
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
458
NetClientState nc;
49
if (ret != sizeof(len)) {
459
+ interface_ref vmnet_if;
50
goto err;
460
+
51
}
461
+ bool send_enabled;
52
462
+
53
- ret = qemu_chr_fe_write_all(out, (uint8_t *)buf, size);
463
+ uint64_t mtu;
54
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
464
+ uint64_t max_packet_size;
55
if (ret != size) {
465
+
56
goto err;
466
+ struct vmpktdesc packets_buf[VMNET_PACKETS_LIMIT];
57
}
467
+ struct iovec iov_buf[VMNET_PACKETS_LIMIT];
58
@@ -XXX,XX +XXX,XX @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs)
468
59
469
} VmnetCommonState;
60
if (packet_enqueue(s, PRIMARY_IN)) {
470
61
trace_colo_compare_main("primary: unsupported packet in");
471
+const char *vmnet_status_map_str(vmnet_return_t status);
62
- compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len);
472
+
63
+ compare_chr_send(s, pri_rs->buf, pri_rs->packet_len);
473
+int vmnet_if_create(NetClientState *nc,
64
} else {
474
+ xpc_object_t if_desc,
65
/* compare connection */
475
+ Error **errp,
66
g_queue_foreach(&s->conn_list, colo_compare_connection, s);
476
+ void (*completion_callback)(xpc_object_t interface_param));
67
@@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data)
477
+
68
478
+ssize_t vmnet_receive_common(NetClientState *nc,
69
while (!g_queue_is_empty(&conn->primary_list)) {
479
+ const uint8_t *buf,
70
pkt = g_queue_pop_head(&conn->primary_list);
480
+ size_t size);
71
- compare_chr_send(&s->chr_out, pkt->data, pkt->size);
481
+
72
+ compare_chr_send(s, pkt->data, pkt->size);
482
+void vmnet_cleanup_common(NetClientState *nc);
73
packet_destroy(pkt, NULL);
483
74
}
484
#endif /* VMNET_INT_H */
75
while (!g_queue_is_empty(&conn->secondary_list)) {
76
--
485
--
77
2.7.4
486
2.7.4
78
487
79
488
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
We add the vnet_hdr_support option for filter-mirror, default is disabled.
3
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
5
You can use it for example:
6
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support
7
8
If it has vnet_hdr_support flag, we will change the sending packet format from
9
struct {int size; const uint8_t buf[];} to {int size; int vnet_hdr_len; const uint8_t buf[];}.
10
make other module(like colo-compare) know how to parse net packet correctly.
11
12
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
5
---
15
net/filter-mirror.c | 42 +++++++++++++++++++++++++++++++++++++++++-
6
net/vmnet-host.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
16
qemu-options.hx | 5 ++---
7
1 file changed, 87 insertions(+), 6 deletions(-)
17
2 files changed, 43 insertions(+), 4 deletions(-)
18
8
19
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
9
diff --git a/net/vmnet-host.c b/net/vmnet-host.c
20
index XXXXXXX..XXXXXXX 100644
10
index XXXXXXX..XXXXXXX 100644
21
--- a/net/filter-mirror.c
11
--- a/net/vmnet-host.c
22
+++ b/net/filter-mirror.c
12
+++ b/net/vmnet-host.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorState {
13
@@ -XXX,XX +XXX,XX @@
24
CharBackend chr_in;
14
*/
25
CharBackend chr_out;
15
26
SocketReadState rs;
16
#include "qemu/osdep.h"
27
+ bool vnet_hdr;
17
+#include "qemu/uuid.h"
28
} MirrorState;
18
#include "qapi/qapi-types-net.h"
29
19
-#include "vmnet_int.h"
30
static int filter_send(MirrorState *s,
20
-#include "clients.h"
31
const struct iovec *iov,
21
-#include "qemu/error-report.h"
32
int iovcnt)
22
#include "qapi/error.h"
33
{
23
+#include "clients.h"
34
+ NetFilterState *nf = NETFILTER(s);
24
+#include "vmnet_int.h"
35
int ret = 0;
25
36
ssize_t size = 0;
26
#include <vmnet/vmnet.h>
37
uint32_t len = 0;
27
38
@@ -XXX,XX +XXX,XX @@ static int filter_send(MirrorState *s,
28
+typedef struct VmnetHostState {
39
goto err;
29
+ VmnetCommonState cs;
40
}
30
+ QemuUUID network_uuid;
41
31
+} VmnetHostState;
42
+ if (s->vnet_hdr) {
43
+ /*
44
+ * If vnet_hdr = on, we send vnet header len to make other
45
+ * module(like colo-compare) know how to parse net
46
+ * packet correctly.
47
+ */
48
+ ssize_t vnet_hdr_len;
49
+
32
+
50
+ vnet_hdr_len = nf->netdev->vnet_hdr_len;
33
+static xpc_object_t create_if_desc(const Netdev *netdev,
34
+ NetClientState *nc,
35
+ Error **errp)
36
+{
37
+ const NetdevVmnetHostOptions *options = &(netdev->u.vmnet_host);
38
+ VmnetCommonState *cs = DO_UPCAST(VmnetCommonState, nc, nc);
39
+ VmnetHostState *hs = DO_UPCAST(VmnetHostState, cs, cs);
51
+
40
+
52
+ len = htonl(vnet_hdr_len);
41
+ xpc_object_t if_desc = xpc_dictionary_create(NULL, NULL, 0);
53
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
42
+
54
+ if (ret != sizeof(len)) {
43
+ xpc_dictionary_set_uint64(
55
+ goto err;
44
+ if_desc,
45
+ vmnet_operation_mode_key,
46
+ VMNET_HOST_MODE
47
+ );
48
+
49
+ xpc_dictionary_set_bool(
50
+ if_desc,
51
+ vmnet_enable_isolation_key,
52
+ options->isolated
53
+ );
54
+
55
+ if (options->has_net_uuid) {
56
+ if (qemu_uuid_parse(options->net_uuid, &hs->network_uuid) < 0) {
57
+ error_setg(errp, "Invalid UUID provided in 'net-uuid'");
58
+ }
59
+
60
+ xpc_dictionary_set_uuid(
61
+ if_desc,
62
+ vmnet_network_identifier_key,
63
+ hs->network_uuid.data
64
+ );
65
+ }
66
+
67
+ if (options->has_start_address ||
68
+ options->has_end_address ||
69
+ options->has_subnet_mask) {
70
+
71
+ if (options->has_start_address &&
72
+ options->has_end_address &&
73
+ options->has_subnet_mask) {
74
+
75
+ xpc_dictionary_set_string(if_desc,
76
+ vmnet_start_address_key,
77
+ options->start_address);
78
+ xpc_dictionary_set_string(if_desc,
79
+ vmnet_end_address_key,
80
+ options->end_address);
81
+ xpc_dictionary_set_string(if_desc,
82
+ vmnet_subnet_mask_key,
83
+ options->subnet_mask);
84
+ } else {
85
+ error_setg(
86
+ errp,
87
+ "'start-address', 'end-address', 'subnet_mask' "
88
+ "should be provided together"
89
+ );
56
+ }
90
+ }
57
+ }
91
+ }
58
+
92
+
59
buf = g_malloc(size);
93
+ return if_desc;
60
iov_to_buf(iov, iovcnt, 0, buf, size);
61
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
62
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp)
63
}
64
}
65
66
- net_socket_rs_init(&s->rs, redirector_rs_finalize, false);
67
+ net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr);
68
69
if (s->indev) {
70
chr = qemu_chr_find(s->indev);
71
@@ -XXX,XX +XXX,XX @@ static void filter_mirror_set_outdev(Object *obj,
72
}
73
}
74
75
+static bool filter_mirror_get_vnet_hdr(Object *obj, Error **errp)
76
+{
77
+ MirrorState *s = FILTER_MIRROR(obj);
78
+
79
+ return s->vnet_hdr;
80
+}
94
+}
81
+
95
+
82
+static void filter_mirror_set_vnet_hdr(Object *obj, bool value, Error **errp)
96
+static NetClientInfo net_vmnet_host_info = {
97
+ .type = NET_CLIENT_DRIVER_VMNET_HOST,
98
+ .size = sizeof(VmnetHostState),
99
+ .receive = vmnet_receive_common,
100
+ .cleanup = vmnet_cleanup_common,
101
+};
102
+
103
int net_init_vmnet_host(const Netdev *netdev, const char *name,
104
- NetClientState *peer, Error **errp) {
105
- error_setg(errp, "vmnet-host is not implemented yet");
106
- return -1;
107
+ NetClientState *peer, Error **errp)
83
+{
108
+{
84
+ MirrorState *s = FILTER_MIRROR(obj);
109
+ NetClientState *nc;
110
+ xpc_object_t if_desc;
85
+
111
+
86
+ s->vnet_hdr = value;
112
+ nc = qemu_new_net_client(&net_vmnet_host_info,
87
+}
113
+ peer, "vmnet-host", name);
88
+
114
+ if_desc = create_if_desc(netdev, nc, errp);
89
static char *filter_redirector_get_outdev(Object *obj, Error **errp)
115
+ return vmnet_if_create(nc, if_desc, errp, NULL);
90
{
91
MirrorState *s = FILTER_REDIRECTOR(obj);
92
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj,
93
94
static void filter_mirror_init(Object *obj)
95
{
96
+ MirrorState *s = FILTER_MIRROR(obj);
97
+
98
object_property_add_str(obj, "outdev", filter_mirror_get_outdev,
99
filter_mirror_set_outdev, NULL);
100
+
101
+ s->vnet_hdr = false;
102
+ object_property_add_bool(obj, "vnet_hdr_support",
103
+ filter_mirror_get_vnet_hdr,
104
+ filter_mirror_set_vnet_hdr, NULL);
105
}
116
}
106
107
static void filter_redirector_init(Object *obj)
108
diff --git a/qemu-options.hx b/qemu-options.hx
109
index XXXXXXX..XXXXXXX 100644
110
--- a/qemu-options.hx
111
+++ b/qemu-options.hx
112
@@ -XXX,XX +XXX,XX @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter.
113
@option{tx}: the filter is attached to the transmit queue of the netdev,
114
where it will receive packets sent by the netdev.
115
116
-@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
117
+@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support]
118
119
-filter-mirror on netdev @var{netdevid},mirror net packet to chardev
120
-@var{chardevid}
121
+filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len.
122
123
@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},
124
outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
125
--
117
--
126
2.7.4
118
2.7.4
127
119
128
120
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
We add the vnet_hdr_support option for filter-redirector, default is disabled.
3
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
4
If you use virtio-net-pci net driver or other driver needs vnet_hdr, please enable it.
5
Because colo-compare or other modules needs the vnet_hdr_len to parse
6
packet, we add this new option send the len to others.
7
You can use it for example:
8
-object filter-redirector,id=r0,netdev=hn0,queue=tx,outdev=red0,vnet_hdr_support
9
10
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
5
---
13
net/filter-mirror.c | 23 +++++++++++++++++++++++
6
net/vmnet-bridged.m | 98 +++++++++++++++++++++++++++++++++++++++++++++++++----
14
qemu-options.hx | 6 +++---
7
1 file changed, 92 insertions(+), 6 deletions(-)
15
2 files changed, 26 insertions(+), 3 deletions(-)
16
8
17
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
9
diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m
18
index XXXXXXX..XXXXXXX 100644
10
index XXXXXXX..XXXXXXX 100644
19
--- a/net/filter-mirror.c
11
--- a/net/vmnet-bridged.m
20
+++ b/net/filter-mirror.c
12
+++ b/net/vmnet-bridged.m
21
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj,
13
@@ -XXX,XX +XXX,XX @@
22
s->outdev = g_strdup(value);
14
23
}
15
#include "qemu/osdep.h"
24
16
#include "qapi/qapi-types-net.h"
25
+static bool filter_redirector_get_vnet_hdr(Object *obj, Error **errp)
17
-#include "vmnet_int.h"
18
-#include "clients.h"
19
-#include "qemu/error-report.h"
20
#include "qapi/error.h"
21
+#include "clients.h"
22
+#include "vmnet_int.h"
23
24
#include <vmnet/vmnet.h>
25
26
+typedef struct VmnetBridgedState {
27
+ VmnetCommonState cs;
28
+} VmnetBridgedState;
29
+
30
+static bool validate_ifname(const char *ifname)
26
+{
31
+{
27
+ MirrorState *s = FILTER_REDIRECTOR(obj);
32
+ xpc_object_t shared_if_list = vmnet_copy_shared_interface_list();
33
+ __block bool match = false;
28
+
34
+
29
+ return s->vnet_hdr;
35
+ xpc_array_apply(
36
+ shared_if_list,
37
+ ^bool(size_t index, xpc_object_t value) {
38
+ if (strcmp(xpc_string_get_string_ptr(value), ifname) == 0) {
39
+ match = true;
40
+ return false;
41
+ }
42
+ return true;
43
+ });
44
+
45
+ return match;
30
+}
46
+}
31
+
47
+
32
+static void filter_redirector_set_vnet_hdr(Object *obj,
48
+static const char *get_valid_ifnames(void)
33
+ bool value,
34
+ Error **errp)
35
+{
49
+{
36
+ MirrorState *s = FILTER_REDIRECTOR(obj);
50
+ xpc_object_t shared_if_list = vmnet_copy_shared_interface_list();
51
+ __block char *if_list = NULL;
37
+
52
+
38
+ s->vnet_hdr = value;
53
+ xpc_array_apply(
54
+ shared_if_list,
55
+ ^bool(size_t index, xpc_object_t value) {
56
+ if_list = g_strconcat(xpc_string_get_string_ptr(value),
57
+ " ",
58
+ if_list,
59
+ NULL);
60
+ return true;
61
+ });
62
+
63
+ if (if_list) {
64
+ return if_list;
65
+ }
66
+ return "[no interfaces]";
39
+}
67
+}
40
+
68
+
41
static void filter_mirror_init(Object *obj)
69
+static xpc_object_t create_if_desc(const Netdev *netdev, Error **errp)
70
+{
71
+ const NetdevVmnetBridgedOptions *options = &(netdev->u.vmnet_bridged);
72
+ xpc_object_t if_desc = xpc_dictionary_create(NULL, NULL, 0);
73
+
74
+ xpc_dictionary_set_uint64(
75
+ if_desc,
76
+ vmnet_operation_mode_key,
77
+ VMNET_BRIDGED_MODE
78
+ );
79
+
80
+ xpc_dictionary_set_bool(
81
+ if_desc,
82
+ vmnet_enable_isolation_key,
83
+ options->isolated
84
+ );
85
+
86
+ if (validate_ifname(options->ifname)) {
87
+ xpc_dictionary_set_string(if_desc,
88
+ vmnet_shared_interface_name_key,
89
+ options->ifname);
90
+ } else {
91
+ return NULL;
92
+ }
93
+ return if_desc;
94
+}
95
+
96
+static NetClientInfo net_vmnet_bridged_info = {
97
+ .type = NET_CLIENT_DRIVER_VMNET_BRIDGED,
98
+ .size = sizeof(VmnetBridgedState),
99
+ .receive = vmnet_receive_common,
100
+ .cleanup = vmnet_cleanup_common,
101
+};
102
+
103
int net_init_vmnet_bridged(const Netdev *netdev, const char *name,
104
NetClientState *peer, Error **errp)
42
{
105
{
43
MirrorState *s = FILTER_MIRROR(obj);
106
- error_setg(errp, "vmnet-bridged is not implemented yet");
44
@@ -XXX,XX +XXX,XX @@ static void filter_mirror_init(Object *obj)
107
- return -1;
45
108
-}
46
static void filter_redirector_init(Object *obj)
109
+ NetClientState *nc = qemu_new_net_client(&net_vmnet_bridged_info,
47
{
110
+ peer, "vmnet-bridged", name);
48
+ MirrorState *s = FILTER_REDIRECTOR(obj);
111
+ xpc_object_t if_desc = create_if_desc(netdev, errp);;
49
+
112
+
50
object_property_add_str(obj, "indev", filter_redirector_get_indev,
113
+ if (!if_desc) {
51
filter_redirector_set_indev, NULL);
114
+ error_setg(errp,
52
object_property_add_str(obj, "outdev", filter_redirector_get_outdev,
115
+ "unsupported ifname, should be one of: %s",
53
filter_redirector_set_outdev, NULL);
116
+ get_valid_ifnames());
117
+ return -1;
118
+ }
54
+
119
+
55
+ s->vnet_hdr = false;
120
+ return vmnet_if_create(nc, if_desc, errp, NULL);
56
+ object_property_add_bool(obj, "vnet_hdr_support",
121
+}
57
+ filter_redirector_get_vnet_hdr,
122
\ No newline at end of file
58
+ filter_redirector_set_vnet_hdr, NULL);
59
}
60
61
static void filter_mirror_fini(Object *obj)
62
diff --git a/qemu-options.hx b/qemu-options.hx
63
index XXXXXXX..XXXXXXX 100644
64
--- a/qemu-options.hx
65
+++ b/qemu-options.hx
66
@@ -XXX,XX +XXX,XX @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter.
67
68
filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len.
69
70
-@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},
71
-outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
72
+@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support]
73
74
filter-redirector on netdev @var{netdevid},redirect filter's net packet to chardev
75
-@var{chardevid},and redirect indev's packet to filter.
76
+@var{chardevid},and redirect indev's packet to filter.if it has the vnet_hdr_support flag,
77
+filter-redirector will redirect packet with vnet_hdr_len.
78
Create a filter-redirector we need to differ outdev id from indev id, id can not
79
be the same. we can just use indev or outdev, but at least one of indev or outdev
80
need to be specified.
81
--
123
--
82
2.7.4
124
2.7.4
83
125
84
126
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
We add the vnet_hdr_support option for filter-rewriter, default is disabled.
3
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
5
You can use it for example:
6
-object filter-rewriter,id=rew0,netdev=hn0,queue=all,vnet_hdr_support
7
8
We get the vnet_hdr_len from NetClientState that make us
9
parse net packet correctly.
10
11
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
12
Signed-off-by: Jason Wang <jasowang@redhat.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
---
5
---
14
net/filter-rewriter.c | 37 ++++++++++++++++++++++++++++++++++++-
6
qemu-options.hx | 25 +++++++++++++++++++++++++
15
qemu-options.hx | 4 ++--
7
1 file changed, 25 insertions(+)
16
2 files changed, 38 insertions(+), 3 deletions(-)
17
8
18
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/net/filter-rewriter.c
21
+++ b/net/filter-rewriter.c
22
@@ -XXX,XX +XXX,XX @@
23
#include "qemu-common.h"
24
#include "qapi/error.h"
25
#include "qapi/qmp/qerror.h"
26
+#include "qemu/error-report.h"
27
#include "qapi-visit.h"
28
#include "qom/object.h"
29
#include "qemu/main-loop.h"
30
@@ -XXX,XX +XXX,XX @@ typedef struct RewriterState {
31
NetQueue *incoming_queue;
32
/* hashtable to save connection */
33
GHashTable *connection_track_table;
34
+ bool vnet_hdr;
35
} RewriterState;
36
37
static void filter_rewriter_flush(NetFilterState *nf)
38
@@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
39
ConnectionKey key;
40
Packet *pkt;
41
ssize_t size = iov_size(iov, iovcnt);
42
+ ssize_t vnet_hdr_len = 0;
43
char *buf = g_malloc0(size);
44
45
iov_to_buf(iov, iovcnt, 0, buf, size);
46
- pkt = packet_new(buf, size, 0);
47
+
48
+ if (s->vnet_hdr) {
49
+ vnet_hdr_len = nf->netdev->vnet_hdr_len;
50
+ }
51
+
52
+ pkt = packet_new(buf, size, vnet_hdr_len);
53
g_free(buf);
54
55
/*
56
@@ -XXX,XX +XXX,XX @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
57
s->incoming_queue = qemu_new_net_queue(qemu_netfilter_pass_to_next, nf);
58
}
59
60
+static bool filter_rewriter_get_vnet_hdr(Object *obj, Error **errp)
61
+{
62
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
63
+
64
+ return s->vnet_hdr;
65
+}
66
+
67
+static void filter_rewriter_set_vnet_hdr(Object *obj,
68
+ bool value,
69
+ Error **errp)
70
+{
71
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
72
+
73
+ s->vnet_hdr = value;
74
+}
75
+
76
+static void filter_rewriter_init(Object *obj)
77
+{
78
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
79
+
80
+ s->vnet_hdr = false;
81
+ object_property_add_bool(obj, "vnet_hdr_support",
82
+ filter_rewriter_get_vnet_hdr,
83
+ filter_rewriter_set_vnet_hdr, NULL);
84
+}
85
+
86
static void colo_rewriter_class_init(ObjectClass *oc, void *data)
87
{
88
NetFilterClass *nfc = NETFILTER_CLASS(oc);
89
@@ -XXX,XX +XXX,XX @@ static const TypeInfo colo_rewriter_info = {
90
.name = TYPE_FILTER_REWRITER,
91
.parent = TYPE_NETFILTER,
92
.class_init = colo_rewriter_class_init,
93
+ .instance_init = filter_rewriter_init,
94
.instance_size = sizeof(RewriterState),
95
};
96
97
diff --git a/qemu-options.hx b/qemu-options.hx
9
diff --git a/qemu-options.hx b/qemu-options.hx
98
index XXXXXXX..XXXXXXX 100644
10
index XXXXXXX..XXXXXXX 100644
99
--- a/qemu-options.hx
11
--- a/qemu-options.hx
100
+++ b/qemu-options.hx
12
+++ b/qemu-options.hx
101
@@ -XXX,XX +XXX,XX @@ Create a filter-redirector we need to differ outdev id from indev id, id can not
13
@@ -XXX,XX +XXX,XX @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
102
be the same. we can just use indev or outdev, but at least one of indev or outdev
14
"-netdev vhost-vdpa,id=str,vhostdev=/path/to/dev\n"
103
need to be specified.
15
" configure a vhost-vdpa network,Establish a vhost-vdpa netdev\n"
104
16
#endif
105
-@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid}[,queue=@var{all|rx|tx}]
17
+#ifdef CONFIG_VMNET
106
+@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},queue=@var{all|rx|tx},[vnet_hdr_support]
18
+ "-netdev vmnet-host,id=str[,isolated=on|off][,net-uuid=uuid]\n"
107
19
+ " [,start-address=addr,end-address=addr,subnet-mask=mask]\n"
108
Filter-rewriter is a part of COLO project.It will rewrite tcp packet to
20
+ " configure a vmnet network backend in host mode with ID 'str',\n"
109
secondary from primary to keep secondary tcp connection,and rewrite
21
+ " isolate this interface from others with 'isolated',\n"
110
tcp packet to primary from secondary make tcp packet can be handled by
22
+ " configure the address range and choose a subnet mask,\n"
111
-client.
23
+ " specify network UUID 'uuid' to disable DHCP and interact with\n"
112
+client.if it has the vnet_hdr_support flag, we can parse packet with vnet header.
24
+ " vmnet-host interfaces within this isolated network\n"
113
25
+ "-netdev vmnet-shared,id=str[,isolated=on|off][,nat66-prefix=addr]\n"
114
usage:
26
+ " [,start-address=addr,end-address=addr,subnet-mask=mask]\n"
115
colo secondary:
27
+ " configure a vmnet network backend in shared mode with ID 'str',\n"
28
+ " configure the address range and choose a subnet mask,\n"
29
+ " set IPv6 ULA prefix (of length 64) to use for internal network,\n"
30
+ " isolate this interface from others with 'isolated'\n"
31
+ "-netdev vmnet-bridged,id=str,ifname=name[,isolated=on|off]\n"
32
+ " configure a vmnet network backend in bridged mode with ID 'str',\n"
33
+ " use 'ifname=name' to select a physical network interface to be bridged,\n"
34
+ " isolate this interface from others with 'isolated'\n"
35
+#endif
36
"-netdev hubport,id=str,hubid=n[,netdev=nd]\n"
37
" configure a hub port on the hub with ID 'n'\n", QEMU_ARCH_ALL)
38
DEF("nic", HAS_ARG, QEMU_OPTION_nic,
39
@@ -XXX,XX +XXX,XX @@ DEF("nic", HAS_ARG, QEMU_OPTION_nic,
40
#ifdef CONFIG_POSIX
41
"vhost-user|"
42
#endif
43
+#ifdef CONFIG_VMNET
44
+ "vmnet-host|vmnet-shared|vmnet-bridged|"
45
+#endif
46
"socket][,option][,...][mac=macaddr]\n"
47
" initialize an on-board / default host NIC (using MAC address\n"
48
" macaddr) and connect it to the given host network backend\n"
49
@@ -XXX,XX +XXX,XX @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
50
#ifdef CONFIG_NETMAP
51
"netmap|"
52
#endif
53
+#ifdef CONFIG_VMNET
54
+ "vmnet-host|vmnet-shared|vmnet-bridged|"
55
+#endif
56
"socket][,option][,option][,...]\n"
57
" old way to initialize a host network interface\n"
58
" (use the -netdev option if possible instead)\n", QEMU_ARCH_ALL)
116
--
59
--
117
2.7.4
60
2.7.4
118
61
119
62
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
2
2
3
We can use this property flush and send packet with vnet_hdr_len.
3
Signed-off-by: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
4
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
5
---
8
net/colo-compare.c | 8 ++++++--
6
MAINTAINERS | 5 +++++
9
net/colo.c | 3 ++-
7
1 file changed, 5 insertions(+)
10
net/colo.h | 4 +++-
11
net/filter-rewriter.c | 2 +-
12
4 files changed, 12 insertions(+), 5 deletions(-)
13
8
14
diff --git a/net/colo-compare.c b/net/colo-compare.c
9
diff --git a/MAINTAINERS b/MAINTAINERS
15
index XXXXXXX..XXXXXXX 100644
10
index XXXXXXX..XXXXXXX 100644
16
--- a/net/colo-compare.c
11
--- a/MAINTAINERS
17
+++ b/net/colo-compare.c
12
+++ b/MAINTAINERS
18
@@ -XXX,XX +XXX,XX @@ static int packet_enqueue(CompareState *s, int mode)
13
@@ -XXX,XX +XXX,XX @@ W: http://info.iet.unipi.it/~luigi/netmap/
19
Connection *conn;
14
S: Maintained
20
15
F: net/netmap.c
21
if (mode == PRIMARY_IN) {
16
22
- pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len);
17
+Apple vmnet network backends
23
+ pkt = packet_new(s->pri_rs.buf,
18
+M: Vladislav Yaroshchuk <yaroshchuk2000@gmail.com>
24
+ s->pri_rs.packet_len,
19
+S: Maintained
25
+ s->pri_rs.vnet_hdr_len);
20
+F: net/vmnet*
26
} else {
21
+
27
- pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len);
22
Host Memory Backends
28
+ pkt = packet_new(s->sec_rs.buf,
23
M: David Hildenbrand <david@redhat.com>
29
+ s->sec_rs.packet_len,
24
M: Igor Mammedov <imammedo@redhat.com>
30
+ s->sec_rs.vnet_hdr_len);
31
}
32
33
if (parse_packet_early(pkt)) {
34
diff --git a/net/colo.c b/net/colo.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/net/colo.c
37
+++ b/net/colo.c
38
@@ -XXX,XX +XXX,XX @@ void connection_destroy(void *opaque)
39
g_slice_free(Connection, conn);
40
}
41
42
-Packet *packet_new(const void *data, int size)
43
+Packet *packet_new(const void *data, int size, int vnet_hdr_len)
44
{
45
Packet *pkt = g_slice_new(Packet);
46
47
pkt->data = g_memdup(data, size);
48
pkt->size = size;
49
pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
50
+ pkt->vnet_hdr_len = vnet_hdr_len;
51
52
return pkt;
53
}
54
diff --git a/net/colo.h b/net/colo.h
55
index XXXXXXX..XXXXXXX 100644
56
--- a/net/colo.h
57
+++ b/net/colo.h
58
@@ -XXX,XX +XXX,XX @@ typedef struct Packet {
59
int size;
60
/* Time of packet creation, in wall clock ms */
61
int64_t creation_ms;
62
+ /* Get vnet_hdr_len from filter */
63
+ uint32_t vnet_hdr_len;
64
} Packet;
65
66
typedef struct ConnectionKey {
67
@@ -XXX,XX +XXX,XX @@ Connection *connection_get(GHashTable *connection_track_table,
68
ConnectionKey *key,
69
GQueue *conn_list);
70
void connection_hashtable_reset(GHashTable *connection_track_table);
71
-Packet *packet_new(const void *data, int size);
72
+Packet *packet_new(const void *data, int size, int vnet_hdr_len);
73
void packet_destroy(void *opaque, void *user_data);
74
75
#endif /* QEMU_COLO_PROXY_H */
76
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
77
index XXXXXXX..XXXXXXX 100644
78
--- a/net/filter-rewriter.c
79
+++ b/net/filter-rewriter.c
80
@@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
81
char *buf = g_malloc0(size);
82
83
iov_to_buf(iov, iovcnt, 0, buf, size);
84
- pkt = packet_new(buf, size);
85
+ pkt = packet_new(buf, size, 0);
86
g_free(buf);
87
88
/*
89
--
25
--
90
2.7.4
26
2.7.4
91
27
92
28
diff view generated by jsdifflib