Skip to content

Commit bf0fff9

Browse files
committed
packet01: add xdp_stats usage
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
1 parent 714f1ec commit bf0fff9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packet01-parsing/xdp_prog_kern.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <linux/icmpv6.h>
99
#include "bpf_helpers.h"
1010
#include "bpf_endian.h"
11+
/* Defines xdp_stats_map from packet04 */
12+
#include "../common/xdp_stats_kern_user.h"
13+
#include "../common/xdp_stats_kern.h"
1114

1215
/* Header cursor to keep track of current parsing position */
1316
struct hdr_cursor {
@@ -63,6 +66,12 @@ int xdp_parser_func(struct xdp_md *ctx)
6366
void *data = (void *)(long)ctx->data;
6467
struct ethhdr *eth;
6568

69+
/* Default action XDP_PASS, imply everything we couldn't parse, or that
70+
* we don't want to deal with, we just pass up the stack and let the
71+
* kernel deal with it.
72+
*/
73+
__u32 action = XDP_PASS; /* Default action */
74+
6675
/* These keep track of the next header type and iterator pointer */
6776
struct hdr_cursor nh;
6877
int nh_type;
@@ -80,13 +89,9 @@ int xdp_parser_func(struct xdp_md *ctx)
8089

8190
/* Assignment additions go below here */
8291

83-
return XDP_DROP;
84-
92+
action = XDP_DROP;
8593
out:
86-
/* Everything we couldn't parse, or that we don't want to deal with, we
87-
* just pass up the stack and let the kernel deal with it.
88-
*/
89-
return XDP_PASS;
94+
return xdp_stats_record_action(ctx, action); /* read via xdp_stats */
9095
}
9196

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

packet02-rewriting/xdp_prog_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int xdp_parser_func(struct xdp_md *ctx)
9999
* we don't want to deal with, we just pass up the stack and let the
100100
* kernel deal with it.
101101
*/
102-
__u32 action = XDP_PASS; /* Default action */
102+
__u32 action = XDP_PASS; /* Default action */
103103

104104
/* These keep track of the next header type and iterator pointer */
105105
struct hdr_cursor nh;

0 commit comments

Comments
 (0)