net/core: Make bpf_skb_adjust_room BPF helper available for packets with non IPv4 or IPv6 payload
Subsystems (4)
PATCH 1/1 net/core: Make bpf_skb_adjust_room BPF helper available for packets with non IPv4 or IPv6 payload
Network traffic is not limited to only IPv4 and IPv6 protocols, but several other L3 networking protocols are in common use in several applications and deployment scenarios which also could utilize BPF. This change enables the bpf_skb_adjust_room BPF helper to adjust the room after the MAC header using BPF_ADJ_ROOM_MAC option for packets with any L3 payload. For BPF_ADJ_ROOM_NET option only IPv4 and IPv6 are still supported as each L3 protocol would need it's own logic to determine the length of the L3 header to enable adjustment after the L3 headers.
---net/core/filter.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
net/core/filter.c +0 -0
@@ -3362,7 +3362,7 @@ static u32 bpf_skb_net_base_len(const struct sk_buff
*skb)
case htons(ETH_P_IPV6):
return sizeof(struct ipv6hdr);
default:
- return ~0U;
+ return 0U;
}
}@@ -3582,7 +3582,8 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff,
if (unlikely(len_diff_abs > 0xfffU))
return -EFAULT;
if (unlikely(proto != htons(ETH_P_IP) &&
- proto != htons(ETH_P_IPV6)))
+ proto != htons(ETH_P_IPV6) &&
+ mode != BPF_ADJ_ROOM_MAC))
return -ENOTSUPP;
off = skb_mac_header_len(skb);--
2.32.0
Quoted 9 lines · Wille Kuutti
Network traffic is not limited to only IPv4 and IPv6 protocols, but several other L3 networking protocols are in common use in several applications and deployment scenarios which also could utilize BPF. This change enables the
bpf_skb_adjust_roomBPF helper to adjust the room after the MAC header usingBPF_ADJ_ROOM_MACoption for packets with any L3 payload. ForBPF_ADJ_ROOM_NEToption only IPv4 and IPv6 are still supported as each L3 protocol would need it's own logic to determine the length of the L3 header to enable adjustment after the L3 headers.
What are the non IPv4/6 use cases ? selftests are required for at least some of these use cases.
Please tag the 'Subject' with bpf-next.
Quoted 10 lines
Signed-off-by Wille Kuutti <[email protected]>---
net/core/filter.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)net/core/filter.c +0
-0
net/core/filter.c static u32 bpf_skb_net_base_len(const struct sk_buff · line 3366
Quoted 6 lines
net/core/filter.c +1
-1@@ -3362,7 +3362,7 @@ static u32 bpf_skb_net_base_len(const struct sk_buff *skb)case htons (ETH_P_IPV6 ):return sizeof (struct ipv6hdr );default : -return ~0U ; +return 0U ;
Does it affect the len_min test in bpf_skb_adjust_room ?
Quoted 18 lines
net/core/filter.c +2
-1} }@@ -3582,7 +3582,8 @@ BPF_CALL_4(bpf_skb_adjust_room, struct sk_buff *, skb, s32, len_diff, if (unlikely(len_diff_abs > 0xfffU)) return -EFAULT;if (unlikely (proto !=htons (ETH_P_IP ) && - proto !=htons (ETH_P_IPV6 ))) + proto !=htons (ETH_P_IPV6 ) && + mode !=BPF_ADJ_ROOM_MAC ))return -ENOTSUPP ;off = skb_mac_header_len(skb);--
2.32.0