]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: add layer 2 encap support to bpf_skb_adjust_room
authorAlan Maguire <alan.maguire@oracle.com>
Tue, 9 Apr 2019 14:06:41 +0000 (15:06 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 11 Apr 2019 20:50:56 +0000 (22:50 +0200)
commit074490f8dd9e29b83987d2c9233fbe546a6799da
treec4dce174784b269ec1064a5a84b697b1e88f9187
parentcae0b16ac7810543f792b5b11bc93526a537b69f
bpf: add layer 2 encap support to bpf_skb_adjust_room

commit b3119a1249ec ("bpf: add bpf_skb_adjust_room encap flags")
introduced support to bpf_skb_adjust_room for GSO-friendly GRE
and UDP encapsulation.

For GSO to work for skbs, the inner headers (mac and network) need to
be marked.  For L3 encapsulation using bpf_skb_adjust_room, the mac
and network headers are identical.  Here we provide a way of specifying
the inner mac header length for cases where L2 encap is desired.  Such
an approach can support encapsulated ethernet headers, MPLS headers etc.
For example to convert from a packet of form [eth][ip][tcp] to
[eth][ip][udp][inner mac][ip][tcp], something like the following could
be done:

headroom = sizeof(iph) + sizeof(struct udphdr) + inner_maclen;

ret = bpf_skb_adjust_room(skb, headroom, BPF_ADJ_ROOM_MAC,
  BPF_F_ADJ_ROOM_ENCAP_L4_UDP |
  BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 |
  BPF_F_ADJ_ROOM_ENCAP_L2(inner_maclen));

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/uapi/linux/bpf.h
net/core/filter.c