Skip to content

Commit

Permalink
Fix TPR validation for inner ipv4
Browse files Browse the repository at this point in the history
Summary: Fixing the TPR validation login in decap for a case where inner packet is ipv4 while outer is ipv6

Reviewed By: frankfeir

Differential Revision: D49713082

fbshipit-source-id: 1715496b90154134b04c2eb7998d97591ac1c7db
  • Loading branch information
Nikhil Dixit Limaye authored and facebook-github-bot committed Oct 3, 2023
1 parent 0659be9 commit 3645d5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 7 additions & 4 deletions katran/decap/bpf/decap.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ __attribute__((__always_inline__)) static inline int process_encaped_gue_pckt(
void** data,
void** data_end,
struct xdp_md* xdp,
bool is_ipv6) {
bool is_ipv6,
bool* inner_ipv6) {
int offset = 0;
if (is_ipv6) {
__u8 v6 = 0;
Expand All @@ -183,6 +184,7 @@ __attribute__((__always_inline__)) static inline int process_encaped_gue_pckt(
}
v6 = ((__u8*)(*data))[offset];
v6 &= GUEV1_IPV6MASK;
*inner_ipv6 = v6 ? true : false;
if (v6) {
// inner packet is ipv6 as well
if (!gue_decap_v6(xdp, data, data_end, false)) {
Expand Down Expand Up @@ -312,13 +314,14 @@ __attribute__((__always_inline__)) static inline int process_packet(
data_stats->decap_v4 += 1;
}
data_stats->total += 1;

action = process_encaped_gue_pckt(&data, &data_end, xdp, is_ipv6);
bool inner_ipv6 = false;
action =
process_encaped_gue_pckt(&data, &data_end, xdp, is_ipv6, &inner_ipv6);
if (action >= 0) {
return action;
}
// For inner packet - check TPR server id and capture stats
validate_tpr_server_id(data, off, data_end, is_ipv6, xdp, data_stats);
validate_tpr_server_id(data, off, data_end, inner_ipv6, xdp, data_stats);
}
}
#endif // INLINE_DECAP_GUE
Expand Down
8 changes: 8 additions & 0 deletions katran/decap/testing/XdpDecapGueTestFixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ const std::vector<PacketAttributes> gueTestFixtures = {
.expectedReturnValue = "XDP_PASS",
.expectedOutputPacket = "AgAAAAAAAQAAAAAAht1gAAAAACsGQPwAAAIAAAAAAAAAAAAAAAH8AAABAAAAAAAAAAAAAAABemkAUAAAAAAAAAAAcBAgAF5AAAC3BsgAAAAAAGthdHJhbiB0ZXN0IHBrdA=="
},
// 14
{ // data_value = int(200).to_bytes(4, byteorder='little')
// Ether(src="0x1", dst="0x2")/IPv6(src="100::1", dst="100::2")/UDP(sport=1337, dport=9886)/IP(src="192.168.1.1", dst="10.200.1.1")/TCP(sport=31337, dport=80,flags="A", options=[(0xB7, data_value)])/"katran test pkt"
.inputPacket = "AgAAAAAAAQAAAAAAht1gAAAAAEcRQAEAAAAAAAAAAAAAAAAAAAEBAAAAAAAAAAAAAAAAAAACBTkmngBHnypFAAA/AAEAAEAGrUbAqAEBCsgBAXppAFAAAAAAAAAAAHAQIACI1AAAtwbIAAAAAABrYXRyYW4gdGVzdCBwa3Q=",
.description = "ipv6 gue ipv4 innner with TPR option set with server id 200",
.expectedReturnValue = "XDP_PASS",
.expectedOutputPacket = "AgAAAAAAAQAAAAAACABFAAA/AAEAAEAGrUbAqAEBCsgBAXppAFAAAAAAAAAAAHAQIACI1AAAtwbIAAAAAABrYXRyYW4gdGVzdCBwa3Q="
},
};

} // namespace testing
Expand Down
8 changes: 4 additions & 4 deletions katran/decap/testing/xdpdecap_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void testXdpDecapCounters(katran::XdpDecap& decap) {
LOG(INFO) << "Testing counter's sanity";
auto stats = decap.getXdpDecapStats();
int expectedV4DecapPkts = 1;
int expectedV6DecapPkts = FLAGS_gue ? 5 : 2;
int expectedTotalPkts = FLAGS_gue ? 6 : 7;
int expectedTotalTPRPkts = 2;
int expectedMisroutedTPRPkts = 1;
int expectedV6DecapPkts = FLAGS_gue ? 6 : 2;
int expectedTotalPkts = FLAGS_gue ? 7 : 7;
int expectedTotalTPRPkts = 3;
int expectedMisroutedTPRPkts = 2;
if (stats.decap_v4 != expectedV4DecapPkts ||
stats.decap_v6 != expectedV6DecapPkts ||
stats.total != expectedTotalPkts ||
Expand Down

0 comments on commit 3645d5f

Please sign in to comment.