Skip to content

Commit

Permalink
introduce a new map to pass server id based routing flags
Browse files Browse the repository at this point in the history
Summary:
don't see an easy way to use the global variable in the current katran flow.
introduce the map instead. The map can be removed later when the flag is enabled by default everywhere.

Reviewed By: nikhildl12, avasylev

Differential Revision: D49548529

fbshipit-source-id: a7c59f1fe3a3cc164adc870e6de9f75435d12fe5
  • Loading branch information
Fei Chen authored and facebook-github-bot committed Oct 11, 2023
1 parent bfb0f60 commit be2795b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions katran/lib/BalancerStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ struct lb_tpr_packets_stats {
uint64_t tcp_syn;
};

// struct for quic routing flags
struct lb_sid_routing_flags {
bool update_quic_sid_based_dst_in_lru;
};

} // namespace katran
13 changes: 13 additions & 0 deletions katran/lib/KatranLb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ void KatranLb::loadBpfProgs() {
if (res) {
throw std::invalid_argument("can't load main bpf program");
}
updateSvrIdRoutingFlags();
}

if (config_.enableHc) {
Expand Down Expand Up @@ -2598,4 +2599,16 @@ lb_stats KatranLb::getSidRoutingStatsForVip(const VipKey& vip) {
return getLbStats(vipNum, "server_id_routing_stats");
}

void KatranLb::updateSvrIdRoutingFlags() {
uint32_t key = 0;
lb_sid_routing_flags flags;
flags.update_quic_sid_based_dst_in_lru = config_.updateLRUForQuic;
int res = bpfAdapter_->bpfUpdateMap(
bpfAdapter_->getMapFdByName("server_id_flags"), &key, &flags);
if (res) {
LOG(ERROR) << "can't update svr_id_routing_flags map, error: "
<< folly::errnoStr(errno);
}
}

} // namespace katran
5 changes: 5 additions & 0 deletions katran/lib/KatranLb.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ class KatranLb {
*/
lb_stats getSidRoutingStatsForVip(const VipKey& vip);

/**
* initialize the server id based routing flags map
*/
void updateSvrIdRoutingFlags();

private:
/**
* update vipmap(add or remove vip) in forwarding plane
Expand Down
1 change: 1 addition & 0 deletions katran/lib/KatranLbStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ struct KatranConfig {
bool enableCidV3 = false;
uint32_t mainInterfaceIndex = kUnspecifiedInterfaceIndex;
uint32_t hcInterfaceIndex = kUnspecifiedInterfaceIndex;
bool updateLRUForQuic = false;
};

/**
Expand Down
9 changes: 7 additions & 2 deletions katran/lib/bpf/balancer.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,13 @@ process_packet(struct xdp_md* xdp, __u64 off, bool is_ipv6) {
xdp, data, data_end - data, false);
return XDP_DROP;
}
int res = check_and_update_real_index_in_lru(
&pckt, lru_map, /* update_lru */ false);
__u32 flags_key = 0;
struct lb_sid_routing_flags* flags_value =
bpf_map_lookup_elem(&server_id_flags, &flags_key);
bool update_lru =
flags_value && flags_value->update_quic_sid_based_dst_in_lru;
int res =
check_and_update_real_index_in_lru(&pckt, lru_map, update_lru);
if (res == DST_MATCH_IN_LRU) {
quic_packets_stats->dst_match_in_lru += 1;
} else if (res == DST_MISMATCH_IN_LRU) {
Expand Down
8 changes: 8 additions & 0 deletions katran/lib/bpf/balancer_maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,12 @@ struct {
__uint(map_flags, NO_FLAGS);
} server_id_routing_stats SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, __u32);
__type(value, struct lb_sid_routing_flags);
__uint(max_entries, 1);
__uint(map_flags, NO_FLAGS);
} server_id_flags SEC(".maps");

#endif // of _BALANCER_MAPS
5 changes: 5 additions & 0 deletions katran/lib/bpf/balancer_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ struct lb_tpr_packets_stats {
__u64 tcp_syn;
};

// struct for quic routing flags
struct lb_sid_routing_flags {
bool update_quic_sid_based_dst_in_lru;
};

#endif // of _BALANCER_STRUCTS

0 comments on commit be2795b

Please sign in to comment.