fix(xdp): correct payload length, attach/detach, whitelist and ban upkeep
BPF program (the first two made the filter wrong on real hardware): - Compute the TCP payload length from ip->tot_len (IPv4) / payload_len (IPv6) instead of data_end. Ethernet padding on a real NIC added 6 bogus payload bytes, broke expected_seq and dropped every connection after the fourth segment. scripts/xdp_pkt_test.sh reproduces it on synthetic frames and fails against the old code. - Read map values (conn->fails, sent_at) before bpf_map_delete_elem; the LRU element is freed by the delete. - Parse up to two VLAN/QinQ tags before L3; fragments are checked against the blacklist and passed instead of bypassing all filtering; first fragments are no longer dropped. - Unknown non-SYN flows PASS: the program is a stateless filter fed by the conntrack state machine, not a firewall, so spoofed SYNs cannot evict established flows into a drop and replies to the daemon's own outbound TCP keep working. - Reset conn->fails on in-order segments, honour SYN payload (TFO), fix the IPv6 SYN-ACK address swap, count every DROP path, drop SYN with IP options. - Expired prefix bans are no longer deleted with the wrong LPM key; userspace reaps them with the exact key. Loader: - Remember the effective attach flags (native vs generic) and use them for detach/query, verifying the interface is clean afterwards. The old code always detached the native slot, leaving a generic program attached after shutdown. - DetachGuard rolls back the attach if anything after it fails. - ban_cidr validates the prefix length and masks host bits. - Whitelist maps (v4 and the new v6 LPM trie) are populated from the config at startup and fail fast on error. - Stats read all 13 counters, and a test asserts every map's key/value size against the Rust encodings. Tests: xdp_pkt_test (padding, VLAN/QinQ, fragments), xdp_loader (attach flags, rollback, detach), xdp_ban_keys, xdp_whitelist_keys, xdp_services, live xdp_attach_smoke (ignored, needs root).
This commit is contained in:
parent
a8a3057719
commit
14dcaccdbf
27 changed files with 1578 additions and 408 deletions
|
|
@ -7,11 +7,25 @@
|
|||
|
||||
#define ETH_P_IP 0x0800
|
||||
#define ETH_P_IPV6 0x86DD
|
||||
#define ETH_P_8021Q 0x8100
|
||||
#define ETH_P_8021AD 0x88A8
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
#define IPPROTO_FRAGMENT 44
|
||||
#define IP_OFFSET 0x1FFF
|
||||
#define IP_MF 0x2000
|
||||
|
||||
/**
|
||||
* One 802.1Q / 802.1ad tag.
|
||||
*
|
||||
* The filter only needs the encapsulated EtherType to skip up to two tags
|
||||
* before L3; the TCI (PCP/DEI/VID) has no bearing on L3/L4 policy.
|
||||
*/
|
||||
struct rampart_vlan_hdr {
|
||||
__u16 tci; // PCP/DEI/VID, unused
|
||||
__u16 encap_proto; // EtherType of the next header
|
||||
};
|
||||
|
||||
/**
|
||||
* Protocol-agnostic TCP connection states.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue