Skip to content

Commit c354f75

Browse files
nikhildl12facebook-github-bot
authored andcommitted
Support KDE zone checking in TPR
Summary: Today when shivless is enabled on server, we have a case where if client enables shivless but if server rejects the zone, tpr still gets disabled from server. This diffs adds zone support in TPR. Next diff will add bpf prog to check the zone before skipping when shivless hdr_opt is present Reviewed By: avasylev Differential Revision: D79602910 fbshipit-source-id: c13023721b672dac10b2b7c35e2263e71d43f7fe
1 parent 7d151fb commit c354f75

5 files changed

Lines changed: 43 additions & 15 deletions

File tree

katran/tpr/TPRTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct tcp_opt {
3030
struct server_info {
3131
RunningMode running_mode;
3232
uint8_t kde_enabled;
33+
uint8_t kde_zones;
3334
// only ipv6 is supported
3435
uint32_t server_id;
3536
};

katran/tpr/TcpPktRouter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,29 @@ bool TcpPktRouter::setServerIdV6(uint32_t id) {
128128
return true;
129129
}
130130

131+
folly::Expected<folly::Unit, std::system_error> TcpPktRouter::setServerKDEZone(
132+
uint8_t kdeZones) {
133+
CHECK_EQ(mode_, RunningMode::SERVER);
134+
LOG(INFO) << "Setting kde zone=" << kdeZones;
135+
136+
kdeZones_ = kdeZones;
137+
if (isInitialized_) {
138+
auto updateRes = updateServerInfo();
139+
if (updateRes.hasError()) {
140+
LOG(ERROR) << "Failed to update KDE zone: " << updateRes.error().what();
141+
return updateRes;
142+
}
143+
}
144+
return folly::Unit();
145+
}
146+
131147
folly::Expected<folly::Unit, std::system_error>
132148
TcpPktRouter::updateServerInfo() noexcept {
133149
struct server_info info = {};
134150
if (mode_ == RunningMode::SERVER) {
135151
info.running_mode = RunningMode::SERVER;
136152
info.kde_enabled = kdeEnabled_;
153+
info.kde_zones = kdeZones_;
137154
info.server_id = v6Id_;
138155
if (info.server_id == 0) {
139156
LOG(WARNING) << "TCP Pkt router is set but server_id is 0. Please check "

katran/tpr/TcpPktRouter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class TcpPktRouter {
7171
return v6Id_;
7272
}
7373

74+
folly::Expected<folly::Unit, std::system_error> setServerKDEZone(
75+
uint8_t kdeZones);
76+
7477
RunningMode getMode() {
7578
return mode_;
7679
}
@@ -102,6 +105,7 @@ class TcpPktRouter {
102105
bool isInitialized_{false};
103106
uint32_t v6Id_;
104107
bool kdeEnabled_;
108+
uint8_t kdeZones_{0};
105109
std::optional<uint32_t> serverPort_;
106110
/**
107111
* Polls stats for packet level events periodically, and

katran/tpr/bpf/tcp_pkt_router_passive_hdlr.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@
1515
#include "tcp_pkt_router_maps.h"
1616
#include "tcp_pkt_router_structs.h"
1717

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;
3219

3320
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;
3539
}
3640

3741
static inline int handle_passive_parse_hdr(

katran/tpr/bpf/tcp_pkt_router_structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ struct server_info {
77
__u8 running_mode;
88
// 0 = no, otherwise yes
99
__u8 kde_enabled;
10+
// zones supported by kde
11+
__u8 kde_zones;
1012
__u32 server_id;
1113
};
1214

0 commit comments

Comments
 (0)