Skip to content

Commit fed8da5

Browse files
committed
Add xdp-synproxy to bpf-examples
this code is from kernel bpf selftests xdp synproxy, removed the tc part for simplicity, shows an exmaple of using libxdp to attach xdp synproxy program on network interface. if port is not in allowed ports, the packet will be dropped by xdp synproxy by default, this would break tcp connections to ports that user does not want to do synproxy, change the default to allow connection pass through. Signed-off-by: Vincent Li <[email protected]>
1 parent c726367 commit fed8da5

File tree

7 files changed

+1244
-0
lines changed

7 files changed

+1244
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SUBDIRS += tc-policy
2525
SUBDIRS += traffic-pacing-edt
2626
SUBDIRS += AF_XDP-forwarding
2727
SUBDIRS += AF_XDP-example
28+
SUBDIRS += xdp-synproxy
2829

2930
.PHONY: check_submodule help clobber distclean clean $(SUBDIRS)
3031

headers/vmlinux/vmlinux_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#ifndef __VMLINUX_COMMON_H__
22
#define __VMLINUX_COMMON_H__
33

4+
enum {
5+
false = 0,
6+
true = 1,
7+
};
8+
9+
typedef _Bool bool;
10+
411
struct list_head {
512
struct list_head *next;
613
struct list_head *prev;

headers/vmlinux/vmlinux_net.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,13 @@ struct sk_buff {
135135
struct skb_ext *extensions;
136136
};
137137

138+
struct nf_conn {
139+
unsigned long status;
140+
};
141+
142+
enum ip_conntrack_status {
143+
/* Connection is confirmed: originating packet has left box */
144+
IPS_CONFIRMED_BIT = 3,
145+
};
146+
138147
#endif /* __VMLINUX_NET_H__ */

xdp-synproxy/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
3+
USER_TARGETS := xdp_synproxy
4+
BPF_TARGETS := xdp_synproxy_kern
5+
BPF_SKEL_OBJ := xdp_synproxy_kern.o
6+
7+
LIB_DIR = ../lib
8+
9+
include $(LIB_DIR)/common.mk

xdp-synproxy/README.org

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
Note XDP SYNPROXY requires netfilter connection tracking and here are the
12+
sysctl knobs and iptables rules preparation for XDP SYNPROXY:
13+
#+BEGIN_SRC sh
14+
sudo sysctl -w net.ipv4.tcp_syncookies=2
15+
sudo sysctl -w net.ipv4.tcp_timestamps=1
16+
sudo sysctl -w net.netfilter.nf_conntrack_tcp_loose=0
17+
sudo iptables -t raw -I PREROUTING -i <interface> -p tcp -m tcp --syn --dport <port> -j CT --notrack
18+
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
19+
sudo iptables -t filter -A INPUT -i <interface> -m state --state INVALID -j DROP
20+
#+END_SRC
21+
22+
Here is how to start the XDP SYNPROXY application:
23+
#+BEGIN_SRC sh
24+
sudo xdp_synproxy --iface <interface> --file <path-to-xdp_synproxy_kern.o> --mss4 1460 --mss6 1440 --wscale 7 --ttl 254 --ports <port1>,<port2>
25+
#+END_SRC
26+
27+
XDP SYNPROXY can coexist with other XDP programs since we use libxdp
28+
to attach the XDP SYNPROXY program, meaning you could build chain of
29+
XDP programs and attach them to same network interface.

0 commit comments

Comments
 (0)