History

net/packet: support mergeable feature of virtio

Packet sockets, like tap, can be used as the backend for kernel vhost. In packet sockets, virtio net header size is currently hardcoded to be the size of struct virtio_net_hdr, which is 10 bytes; however, it is not always the case: some virtio features, such as mrg_rxbuf, need virtio net header to be 12-byte long. Mergeable buffers, as a virtio feature, is worthy of supporting: packets that are larger than one-mbuf size will be dropped in vhost worker's handle_rx if mrg_rxbuf feature is not used, but large packets cannot be avoided and increasing mbuf's size is not economical. With this virtio feature enabled by virtio-user, packet sockets with hardcoded 10-byte virtio net header will parse mac head incorrectly in packet_snd by taking the last two bytes of virtio net header as part of mac header. This incorrect mac header parsing will cause packet to be dropped due to invalid ether head checking in later under-layer device packet receiving. By adding extra field vnet_hdr_sz with utilizing holes in struct packet_sock to record currently used virtio net header size and supporting extra sockopt PACKET_VNET_HDR_SZ to set specified vnet_hdr_sz, packet sockets can know the exact length of virtio net header that virtio user gives. In packet_snd, tpacket_snd and packet_recvmsg, instead of using hardcoded virtio net header size, it can get the exact vnet_hdr_sz from corresponding packet_sock, and parse mac header correctly based on this information to avoid the packets being mistakenly dropped.

Jianfeng Tan committed 3 years ago

Commit dfc39d41 parent 156c9394 files · +60 −40Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/linux/if_packet.h+1−0
@@ -59,6 +59,7 @@ struct sockaddr_ll { · 58 unmodified lines
59#define PACKET_ROLLOVER_STATS 2159#define PACKET_ROLLOVER_STATS 21
60#define PACKET_FANOUT_DATA 2260#define PACKET_FANOUT_DATA 22
61#define PACKET_IGNORE_OUTGOING 2361#define PACKET_IGNORE_OUTGOING 23
62#define PACKET_VNET_HDR_SZ 24
62 63
63#define PACKET_FANOUT_HASH 064#define PACKET_FANOUT_HASH 0
64#define PACKET_FANOUT_LB 165#define PACKET_FANOUT_LB 1

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t