|
15 | 15 | #include "tcp_pkt_router_maps.h" |
16 | 16 | #include "tcp_pkt_router_structs.h" |
17 | 17 |
|
18 | | -static inline bool kde_enabled() { |
19 | | - __u32 sinfo_key = SERVER_INFO_INDEX; |
20 | | - struct server_info* s_info = bpf_map_lookup_elem(&server_infos, &sinfo_key); |
21 | | - return (s_info && s_info->kde_enabled != 0); |
22 | | -} |
23 | | - |
24 | | -static inline bool has_syn_with_kde_opt(struct bpf_sock_ops* skops) { |
25 | | - __u64 load_flags = BPF_LOAD_HDR_OPT_TCP_SYN; |
26 | | - struct kde_clt_tcp_opt_v2 kde_opt = {}; |
27 | | - kde_opt.kind = KDE_CLT_TCP_HDR_OPT_KIND; |
28 | | - int ret = bpf_load_hdr_opt(skops, &kde_opt, sizeof(kde_opt), load_flags); |
29 | | - return (ret == KDE_CLT_TCP_HDR_OPT_LEN) || |
30 | | - (ret == KDE_CLT_TCP_HDR_OPT_V2_LEN); |
31 | | -} |
| 18 | +const volatile __u8 KDE_ZONE_ALL = 0xFF; |
32 | 19 |
|
33 | 20 | static inline bool should_ignore_due_to_kde(struct bpf_sock_ops* skops) { |
34 | | - return kde_enabled() && has_syn_with_kde_opt(skops); |
| 21 | + __u32 sinfo_key = SERVER_INFO_INDEX; |
| 22 | + struct server_info* s_info = bpf_map_lookup_elem(&server_infos, &sinfo_key); |
| 23 | + // if kde is enabled, check if zone in hdr opts is matching server zone |
| 24 | + if (s_info && s_info->kde_enabled) { |
| 25 | + __u64 load_flags = BPF_LOAD_HDR_OPT_TCP_SYN; |
| 26 | + struct kde_clt_tcp_opt_v2 kde_opt = {}; |
| 27 | + kde_opt.kind = KDE_CLT_TCP_HDR_OPT_KIND; |
| 28 | + int ret = bpf_load_hdr_opt(skops, &kde_opt, sizeof(kde_opt), load_flags); |
| 29 | + if (ret == KDE_CLT_TCP_HDR_OPT_V2_LEN) { |
| 30 | + if (s_info->kde_zones) |
| 31 | + if ((s_info->kde_zones & kde_opt.zone) == kde_opt.zone) { |
| 32 | + return true; |
| 33 | + } else if (s_info->kde_zones == KDE_ZONE_ALL) { |
| 34 | + return true; |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + return false; |
35 | 39 | } |
36 | 40 |
|
37 | 41 | static inline int handle_passive_parse_hdr( |
|
0 commit comments