@@ -111,9 +111,11 @@ typedef struct NICState {
} NICState;
struct SocketReadState {
- int state; /* 0 = getting length, 1 = getting data */
+ /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
+ int state;
uint32_t index;
uint32_t packet_len;
+ uint32_t vnet_hdr_len;
uint8_t buf[NET_BUFSIZE];
SocketReadStateFinalize *finalize;
};
@@ -1621,8 +1621,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) {
@@ -1640,6 +1644,22 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
}
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;
Address Jason Wang's comments add vnet header length to SocketReadState. So we change net_fill_rstate() to read struct {int size; int vnet_hdr_len; const uint8_t buf[];}. Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> --- include/net/net.h | 4 +++- net/net.c | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-)