Skip to content

Commit

Permalink
bpf: test: use different backend port for hairpin test
Browse files Browse the repository at this point in the history
[ upstream commit f0b44c0 ]

The test currently assumes SVC_PORT == BACKEND_PORT. This limits the test
coverage (we're not testing that L4 NAT works properly), and isn't strictly
required in real world scenarios.

Change the test so that the backend uses a different port.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
  • Loading branch information
julianwiedmann committed Sep 7, 2023
1 parent d514ee2 commit 622781b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 7 additions & 3 deletions bpf/tests/pktgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ static volatile const __u8 v6_node_three[] = {0xfd, 0x07, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 3};

/* Source port to be used by a client */
#define tcp_src_one __bpf_htons(22334)
#define tcp_src_two __bpf_htons(33445)
#define tcp_src_three __bpf_htons(44556)
#define tcp_src_one __bpf_htons(22330)
#define tcp_src_two __bpf_htons(33440)
#define tcp_src_three __bpf_htons(44550)

#define tcp_dst_one __bpf_htons(22331)
#define tcp_dst_two __bpf_htons(33441)
#define tcp_dst_three __bpf_htons(44551)

#define tcp_svc_one __bpf_htons(80)
#define tcp_svc_two __bpf_htons(443)
Expand Down
15 changes: 7 additions & 8 deletions bpf/tests/tc_nodeport_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int hairpin_flow_forward_setup(struct __ctx_buff *ctx)
* packet to.
*/
backend.address = v4_pod_one;
backend.port = tcp_svc_one;
backend.port = tcp_dst_one;
backend.proto = IPPROTO_TCP;
backend.flags = 0;
map_update_elem(&LB4_BACKEND_MAP, &lb_svc_value.backend_id, &backend, BPF_ANY);
Expand Down Expand Up @@ -213,7 +213,7 @@ int hairpin_flow_forward_check(__maybe_unused const struct __ctx_buff *ctx)
if (l4->source != tcp_src_one)
test_fatal("src TCP port was changed");

if (l4->dest != tcp_svc_one)
if (l4->dest != tcp_dst_one)
test_fatal("dst TCP port incorrect");

struct ipv4_ct_tuple tuple = {};
Expand All @@ -240,7 +240,7 @@ int hairpin_flow_forward_check(__maybe_unused const struct __ctx_buff *ctx)
tuple.saddr = IPV4_LOOPBACK;
tuple.sport = tcp_src_one;
tuple.daddr = v4_pod_one;
tuple.dport = tcp_svc_one;
tuple.dport = tcp_dst_one;

/* Addrs are stored in reverse order: */
ipv4_ct_tuple_swap_addrs(&tuple);
Expand Down Expand Up @@ -289,7 +289,7 @@ int hairpin_flow_forward_ingress_pktgen(struct __ctx_buff *ctx)
return TEST_ERROR;

l4->source = tcp_src_one;
l4->dest = tcp_svc_one;
l4->dest = tcp_dst_one;

data = pktgen__push_data(&builder, default_data, sizeof(default_data));

Expand Down Expand Up @@ -352,7 +352,7 @@ int hairpin_flow_forward_ingress_check(__maybe_unused const struct __ctx_buff *c
if (l4->source != tcp_src_one)
test_fatal("src TCP port changed");

if (l4->dest != tcp_svc_one)
if (l4->dest != tcp_dst_one)
test_fatal("dst TCP port changed");

struct ipv4_ct_tuple tuple = {};
Expand All @@ -364,7 +364,7 @@ int hairpin_flow_forward_ingress_check(__maybe_unused const struct __ctx_buff *c
tuple.saddr = IPV4_LOOPBACK;
tuple.sport = tcp_src_one;
tuple.daddr = v4_pod_one;
tuple.dport = tcp_svc_one;
tuple.dport = tcp_dst_one;

/* Addrs are stored in reverse order: */
ipv4_ct_tuple_swap_addrs(&tuple);
Expand Down Expand Up @@ -411,11 +411,10 @@ int hairpin_flow_reverse_pktgen(struct __ctx_buff *ctx)

/* Push TCP header */
l4 = pktgen__push_default_tcphdr(&builder);

if (!l4)
return TEST_ERROR;

l4->source = tcp_svc_one;
l4->source = tcp_dst_one;
l4->dest = tcp_src_one;
l4->ack = 1;

Expand Down

0 comments on commit 622781b

Please sign in to comment.