Skip to content

Commit 86ec1b7

Browse files
authored
Merge pull request #111 from vincentmli/xdp-synproxy
Sync in kernel bpf selftest xdp synproxy fix: erroneous bitmask operation
2 parents 63cd400 + 3d6baf8 commit 86ec1b7

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

headers/vmlinux/vmlinux_net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct nf_conn {
142142
enum ip_conntrack_status {
143143
/* Connection is confirmed: originating packet has left box */
144144
IPS_CONFIRMED_BIT = 3,
145+
IPS_CONFIRMED = (1 << IPS_CONFIRMED_BIT),
145146
};
146147

147148
#endif /* __VMLINUX_NET_H__ */

xdp-synproxy/README.org

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,29 @@ could be built statically and shipped with xdp-synproxy container.
5959
=> 50 syncookie_xdp 908 6c6615566a2e0419 XDP_PASS
6060
#+END_SRC
6161

62+
XDP SYNPROXY can also be deployed in Linux router/Firewall, it requires iptables SYNPROXY to be added in filter table FORWARD chain. see https://youtu.be/Cj7SeviTXrw?si=adZ0FrGq84Ygmmy0 for example.
63+
64+
#+BEGIN_SRC sh
65+
sudo sysctl -w net.ipv4.ip_forward=1
66+
sudo sysctl -w net.ipv4.tcp_syncookies=2
67+
sudo sysctl -w net.ipv4.tcp_timestamps=1
68+
sudo sysctl -w net.netfilter.nf_conntrack_tcp_loose=0
69+
sudo iptables -t raw -I PREROUTING -i ens7 -p tcp -m tcp --syn --dport 80 -j CT --notrack
70+
sudo iptables -t filter -A FORWARD -i ens7 -p tcp -m tcp --dport 80 -m state --state INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 7 --mss 1460
71+
sudo iptables -t filter -A FORWARD -i ens7 -m state --state INVALID -j DROP
72+
sudo ./xdp_synproxy --iface ens7 --ports 80 --mss4 1460 --mss6 1440 --wscale 7 --ttl 64
73+
74+
Simple test diagram
75+
76+
client: server:
77+
ip r add 10.6.6.0/24 ip r add 10.3.3.0/24
78+
via 10.3.3.8 via 10.6.6.8
79+
80+
+---------------+ +----------------------------+ +--------------+
81+
| | | | | |
82+
| client | | Firewall/router | | server |
83+
| 10.3.3.9 eno2---ens7 10.3.3.8 10.6.6.8 ens9----ens9 10.6.6.6 |
84+
| | | | | |
85+
| | | | | |
86+
+---------------+ +----------------------------+ +--------------+
87+
#+END_SRC

xdp-synproxy/xdp_synproxy_kern.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,13 @@ static __always_inline int tcp_lookup(void *ctx, struct header_pointers *hdr, bo
447447
unsigned long status = ct->status;
448448

449449
bpf_ct_release(ct);
450-
if (status & IPS_CONFIRMED_BIT)
450+
if (status & IPS_CONFIRMED)
451451
return XDP_PASS;
452452
} else if (ct_lookup_opts.error != -ENOENT) {
453453
return XDP_ABORTED;
454454
}
455455

456-
/* error == -ENOENT || !(status & IPS_CONFIRMED_BIT) */
456+
/* error == -ENOENT || !(status & IPS_CONFIRMED) */
457457
return XDP_TX;
458458
}
459459

0 commit comments

Comments
 (0)