Skip to content

Commit 2f030d2

Browse files
committed
packet02: xdp_parser_func use a variable for the action
This is in preparation for having a single call point that updates stats. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
1 parent 1b5e8c8 commit 2f030d2

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

packet02-rewriting/xdp_prog_kern.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// The parsing helper functions from the packet01 lesson have moved here
88
#include "../common/parsing_helpers.h"
99

10-
1110
/* Pops the outermost VLAN tag off the packet. Returns the popped VLAN ID on
1211
* success or -1 on failure.
1312
*/
@@ -92,6 +91,12 @@ int xdp_parser_func(struct xdp_md *ctx)
9291
void *data_end = (void *)(long)ctx->data_end;
9392
void *data = (void *)(long)ctx->data;
9493

94+
/* Default action XDP_PASS, imply everything we couldn't parse, or that
95+
* we don't want to deal with, we just pass up the stack and let the
96+
* kernel deal with it.
97+
*/
98+
__u32 action = XDP_PASS; /* Default action */
99+
95100
/* These keep track of the next header type and iterator pointer */
96101
struct hdr_cursor nh;
97102
int nh_type;
@@ -118,7 +123,7 @@ int xdp_parser_func(struct xdp_md *ctx)
118123
goto out;
119124

120125
if (bpf_ntohs(icmp6h->icmp6_sequence) % 2 == 0)
121-
return XDP_DROP;
126+
action = XDP_DROP;
122127

123128
} else if (nh_type == ETH_P_IP) {
124129
struct iphdr *iph;
@@ -133,13 +138,10 @@ int xdp_parser_func(struct xdp_md *ctx)
133138
goto out;
134139

135140
if (bpf_ntohs(icmph->un.echo.sequence) % 2 == 0)
136-
return XDP_DROP;
141+
action = XDP_DROP;
137142
}
138143
out:
139-
/* Everything we couldn't parse, or that we don't want to deal with, we
140-
* just pass up the stack and let the kernel deal with it.
141-
*/
142-
return XDP_PASS;
144+
return action;
143145
}
144146

145147
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)