|
| 1 | +#+Title: XDP SYNPROXY sample application |
| 2 | + |
| 3 | +This is a sample application for XDP SYNPROXY. It was cloned from |
| 4 | +the Linux source code tree under tools/testing/selftests/bpf and called |
| 5 | +xdp_synproxy. main purpose of it is to demonstrate capabilities of |
| 6 | +XDP accelerating SYN Proxying for SYN flood DDOS protection. It is |
| 7 | +a real practical example for user to use. For an overview of accelerating |
| 8 | +SYNPROXY WITH XDP, Please refer to this paper |
| 9 | +(https://netdevconf.info/0x15/slides/30/Netdev%200x15%20Accelerating%20synproxy%20with%20XDP.pdf) |
| 10 | + |
| 11 | +This sample application is tested with Ubuntu 22.04 with 6.2 kernel. |
| 12 | + |
| 13 | +Note XDP SYNPROXY requires netfilter connection tracking and here are the |
| 14 | +sysctl knobs and iptables rules preparation for XDP SYNPROXY: |
| 15 | +#+BEGIN_SRC sh |
| 16 | + sudo sysctl -w net.ipv4.tcp_syncookies=2 |
| 17 | + sudo sysctl -w net.ipv4.tcp_timestamps=1 |
| 18 | + sudo sysctl -w net.netfilter.nf_conntrack_tcp_loose=0 |
| 19 | + sudo iptables -t raw -I PREROUTING -i <interface> -p tcp -m tcp --syn --dport <port> -j CT --notrack |
| 20 | + sudo iptables -t filter -A INPUT -i <interface> -p tcp -m tcp --dport <port> -m state --state INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460 |
| 21 | + sudo iptables -t filter -A INPUT -i <interface> -m state --state INVALID -j DROP |
| 22 | +#+END_SRC |
| 23 | + |
| 24 | +Here is how to start the XDP SYNPROXY application: |
| 25 | +#+BEGIN_SRC sh |
| 26 | + sudo xdp_synproxy --iface <interface> --mss4 1460 --mss6 1440 --wscale 7 --ttl 64 --ports <port1>,<port2> |
| 27 | +#+END_SRC |
| 28 | + |
| 29 | +XDP SYNPROXY could be built in in container and run by docker |
| 30 | +#+BEGIN_SRC sh |
| 31 | + sudo docker build . -t xdp-synproxy:0.1 |
| 32 | + sudo docker run -it -h xdp-synproxy --network=host --privileged xdp-synproxy:0.1 |
| 33 | +#+END_SRC |
| 34 | + |
| 35 | +XDP SYNPROXY could be deployed in Kubernetes cluster as DaemonSet, Please see |
| 36 | +(https://youtu.be/nIrp0Lv-e0g?si=g-pXl4agVQM6_FYW) |
| 37 | +#+BEGIN_SRC sh |
| 38 | + sudo kubectl apply -f xdp-synproxy-daemonset.yaml |
| 39 | + sudo kubectl get po -o wide -l app=xdp-synproxy |
| 40 | + |
| 41 | + NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES |
| 42 | + xdp-synproxy-6x29j 1/1 Running 0 5d2h 10.169.72.239 cilium-dev <none> <none> |
| 43 | + xdp-synproxy-xj98j 1/1 Running 0 5d2h 10.169.72.233 centos-dev.localdomain <none> <none> |
| 44 | +#+END_SRC |
| 45 | + |
| 46 | +XDP SYNPROXY can coexist with other XDP programs since we use libxdp |
| 47 | +to attach the XDP SYNPROXY program, meaning you could build chain of |
| 48 | +XDP programs and attach them to same network interface. Note xdp-loader |
| 49 | +could be built statically and shipped with xdp-synproxy container. |
| 50 | + |
| 51 | +#+BEGIN_SRC sh |
| 52 | + sudo kubectl exec -it xdp-synproxy-6x29j -- xdp-loader status |
| 53 | + |
| 54 | + CURRENT XDP PROGRAM STATUS: |
| 55 | + |
| 56 | + Interface Prio Program name Mode ID Tag Chain actions |
| 57 | + -------------------------------------------------------------------------------------- |
| 58 | + ens192 xdp_dispatcher native 899 90f686eb86991928 |
| 59 | + => 50 syncookie_xdp 908 6c6615566a2e0419 XDP_PASS |
| 60 | +#+END_SRC |
| 61 | + |
0 commit comments