mbox series

[bpf-next,0/2] bpf: Update h_proto of ethhdr when the outer protocol changed

Message ID cover.1691639830.git.william.xuanziyang@huawei.com (mailing list archive)
Headers show
Series bpf: Update h_proto of ethhdr when the outer protocol changed | expand

Message

Ziyang Xuan (William) Aug. 10, 2023, 6:25 a.m. UTC
When use bpf_skb_adjust_room() to encapsulate or decapsulate packet,
and outer protocol changed, we can update h_proto of ethhdr directly.

$./test_tc_tunnel.sh
ipip
encap 192.168.1.1 to 192.168.1.2, type ipip, mac none len 100
test basic connectivity
0
test bpf encap without decap (expect failure)
Ncat: TIMEOUT.
1
test bpf encap with tunnel device decap
0
test bpf encap with bpf decap
0
OK
ipip6
encap 192.168.1.1 to 192.168.1.2, type ipip6, mac none len 100
test basic connectivity
0
test bpf encap without decap (expect failure)
Ncat: TIMEOUT.
1
test bpf encap with tunnel device decap
0
test bpf encap with bpf decap
0
OK
ip6ip6
encap fd::1 to fd::2, type ip6tnl, mac none len 100
test basic connectivity
0
test bpf encap without decap (expect failure)
Ncat: TIMEOUT.
1
test bpf encap with tunnel device decap
0
test bpf encap with bpf decap
0
OK
sit
encap fd::1 to fd::2, type sit, mac none len 100
test basic connectivity
0
test bpf encap without decap (expect failure)
Ncat: TIMEOUT.
1
test bpf encap with tunnel device decap
0
test bpf encap with bpf decap
0
OK
...
OK. All tests passed

Ziyang Xuan (2):
  bpf: Update h_proto of ethhdr when the outer protocol changed
  selftests/bpf: Remove unnecessary codes for updating h_proto of ethhdr

 net/core/filter.c                             | 20 +++++++++++++------
 .../selftests/bpf/progs/test_tc_tunnel.c      | 18 -----------------
 2 files changed, 14 insertions(+), 24 deletions(-)

Comments

Yonghong Song Aug. 10, 2023, 3:54 p.m. UTC | #1
On 8/9/23 11:25 PM, Ziyang Xuan wrote:
> When use bpf_skb_adjust_room() to encapsulate or decapsulate packet,
> and outer protocol changed, we can update h_proto of ethhdr directly.

My mailbox somehow lost patch 1/2.

Looks like current bpf_skb_adjust_room() only changes skb meta data and
tries not to modify the packet. Probably there is a reason for this.

> 
> $./test_tc_tunnel.sh
> ipip
> encap 192.168.1.1 to 192.168.1.2, type ipip, mac none len 100
> test basic connectivity
> 0
> test bpf encap without decap (expect failure)
> Ncat: TIMEOUT.
> 1
> test bpf encap with tunnel device decap
> 0
> test bpf encap with bpf decap
> 0
> OK
> ipip6
[...]
Ziyang Xuan (William) Aug. 11, 2023, 9:44 a.m. UTC | #2
> On 8/9/23 11:25 PM, Ziyang Xuan wrote:
>> When use bpf_skb_adjust_room() to encapsulate or decapsulate packet,
>> and outer protocol changed, we can update h_proto of ethhdr directly.
> 
> My mailbox somehow lost patch 1/2.
> 
> Looks like current bpf_skb_adjust_room() only changes skb meta data and
> tries not to modify the packet. Probably there is a reason for this.
> 
I found that this could reduce updating h_proto of ethhdr by bpf_skb_store_bytes()
in bpf program when I used bpf_skb_adjust_room(). I thought it should be a small
optimization. So I did it. No other problems.

Thank you!
William Xuan
>>
>> $./test_tc_tunnel.sh
>> ipip
>> encap 192.168.1.1 to 192.168.1.2, type ipip, mac none len 100
>> test basic connectivity
>> 0
>> test bpf encap without decap (expect failure)
>> Ncat: TIMEOUT.
>> 1
>> test bpf encap with tunnel device decap
>> 0
>> test bpf encap with bpf decap
>> 0
>> OK
>> ipip6
> [...]
> 
> .