diff options
author | Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 2017-07-04 14:53:46 +0800 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2017-07-17 20:02:11 +0800 |
commit | 3cde5ea211ead04997e2ecd7f8bdc831f84700e6 (patch) | |
tree | e63da97b2e530ad8f580643e69b618adff446f14 /net | |
parent | d6b732e953673e4e1f4b36868c206a08213b6708 (diff) | |
download | qemu-3cde5ea211ead04997e2ecd7f8bdc831f84700e6.zip qemu-3cde5ea211ead04997e2ecd7f8bdc831f84700e6.tar.gz qemu-3cde5ea211ead04997e2ecd7f8bdc831f84700e6.tar.bz2 |
net/net.c: Add vnet_hdr support in SocketReadState
We add a flag to decide whether net_fill_rstate() need read
the vnet_hdr_len or not.
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Suggested-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/colo-compare.c | 4 | ||||
-rw-r--r-- | net/filter-mirror.c | 2 | ||||
-rw-r--r-- | net/net.c | 36 | ||||
-rw-r--r-- | net/socket.c | 8 |
4 files changed, 39 insertions, 11 deletions
diff --git a/net/colo-compare.c b/net/colo-compare.c index abfc23c..ea9bccc 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -743,8 +743,8 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize); - net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); + net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false); + net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false); g_queue_init(&s->conn_list); diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 6043549..1b6211b 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -229,7 +229,7 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) } } - net_socket_rs_init(&s->rs, redirector_rs_finalize); + net_socket_rs_init(&s->rs, redirector_rs_finalize, false); if (s->indev) { chr = qemu_chr_find(s->indev); @@ -1616,11 +1616,14 @@ QemuOptsList qemu_net_opts = { }; void net_socket_rs_init(SocketReadState *rs, - SocketReadStateFinalize *finalize) + SocketReadStateFinalize *finalize, + bool vnet_hdr) { rs->state = 0; + rs->vnet_hdr = vnet_hdr; rs->index = 0; rs->packet_len = 0; + rs->vnet_hdr_len = 0; memset(rs->buf, 0, sizeof(rs->buf)); rs->finalize = finalize; } @@ -1635,8 +1638,12 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size) unsigned int l; while (size > 0) { - /* reassemble a packet from the network */ - switch (rs->state) { /* 0 = getting length, 1 = getting data */ + /* Reassemble a packet from the network. + * 0 = getting length. + * 1 = getting vnet header length. + * 2 = getting data. + */ + switch (rs->state) { case 0: l = 4 - rs->index; if (l > size) { @@ -1650,10 +1657,31 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size) /* got length */ rs->packet_len = ntohl(*(uint32_t *)rs->buf); rs->index = 0; - rs->state = 1; + if (rs->vnet_hdr) { + rs->state = 1; + } else { + rs->state = 2; + rs->vnet_hdr_len = 0; + } } break; case 1: + l = 4 - rs->index; + if (l > size) { + l = size; + } + memcpy(rs->buf + rs->index, buf, l); + buf += l; + size -= l; + rs->index += l; + if (rs->index == 4) { + /* got vnet header length */ + rs->vnet_hdr_len = ntohl(*(uint32_t *)rs->buf); + rs->index = 0; + rs->state = 2; + } + break; + case 2: l = rs->packet_len - rs->index; if (l > size) { l = size; diff --git a/net/socket.c b/net/socket.c index dcae1ae..f85ef7d 100644 --- a/net/socket.c +++ b/net/socket.c @@ -174,7 +174,7 @@ static void net_socket_send(void *opaque) closesocket(s->fd); s->fd = -1; - net_socket_rs_init(&s->rs, net_socket_rs_finalize); + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); s->nc.link_down = true; memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); @@ -366,7 +366,7 @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, s->fd = fd; s->listen_fd = -1; s->send_fn = net_socket_send_dgram; - net_socket_rs_init(&s->rs, net_socket_rs_finalize); + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); net_socket_read_poll(s, true); /* mcast: save bound address as dst */ @@ -417,7 +417,7 @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, s->fd = fd; s->listen_fd = -1; - net_socket_rs_init(&s->rs, net_socket_rs_finalize); + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); /* Disable Nagle algorithm on TCP sockets to reduce latency */ socket_set_nodelay(fd); @@ -522,7 +522,7 @@ static int net_socket_listen_init(NetClientState *peer, s->fd = -1; s->listen_fd = fd; s->nc.link_down = true; - net_socket_rs_init(&s->rs, net_socket_rs_finalize); + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); return 0; |