edgecomllc / eupf

5G User Plane Function (UPF) based on eBPF
Apache License 2.0
99 stars 18 forks source link

Implement xdp native attach mode #116

Closed pirog-spb closed 1 year ago

pirog-spb commented 1 year ago
pirog-spb commented 1 year ago

When applying --attach native option eupf successfully starts.

upf              | 2023/06/10 16:20:34 Apply eUPF config: {InterfaceName:[eth0 eth1] XDPAttachMode:native ApiAddress::8080 PfcpAddress::8805 PfcpNodeId:10.100.200.4 MetricsAddress::9090 N3Address:10.100.200.4 QerMapSize:1024 FarMapSize:1024 PdrMapSize:1024}
upf              | 2023/06/10 16:20:34 Attached XDP program to iface "eth0" (index 316)
upf              | 2023/06/10 16:20:34 Attached XDP program to iface "eth1" (index 318)

But packets aren't redirected (XDP_REDIRECT).

To fix it just load "zero" xdp program in native(driver) mode on the opposite interface of veth pair.

Show all eUPF interfaces, get ids of the interfaces in host namespace

/ # ip l sh
...
316: eth0@if317: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:0a:64:c8:04 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    prog/xdp id 628 name upf_ip_entrypoi tag a77c715aaac4979b jited 
318: eth1@if319: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp qdisc noqueue state UP mode DEFAULT group default 
    link/ether 02:42:0a:64:fa:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    prog/xdp id 628 name upf_ip_entrypoi tag a77c715aaac4979b jited

Get interfaces in the host namespace by id

# ip l sh | grep 317
317: veth1f7ef0e@if316: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-free5gc state UP mode DEFAULT group default 
# ip l sh | grep 319
319: veth0915238@if318: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-free5gc-n6 state UP mode DEFAULT group default

Attach simple xdp program to both interfaces

sudo ip link set dev veth1f7ef0e xdpdrv obj zero_entrypoint_bpf.o sec xdp/upf_zero_entrypoint
sudo ip link set dev veth0915238 xdpdrv obj zero_entrypoint_bpf.o sec xdp/upf_zero_entrypoint