Skip to content

Commit f988eec

Browse files
committed
packet04-tailgrow: cleanup, remove unused code
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
1 parent 8c144dd commit f988eec

1 file changed

Lines changed: 10 additions & 122 deletions

File tree

packet04-tailgrow/xdp_prog_kern.c

Lines changed: 10 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,14 @@
1212
#include "../common/xdp_stats_kern_user.h"
1313
#include "../common/xdp_stats_kern.h"
1414

15-
#ifndef memcpy
16-
#define memcpy(dest, src, n) __builtin_memcpy((dest), (src), (n))
17-
#endif
18-
19-
struct bpf_map_def SEC("maps") tx_port = {
20-
.type = BPF_MAP_TYPE_DEVMAP,
21-
.key_size = sizeof(int),
22-
.value_size = sizeof(int),
23-
.max_entries = 256,
24-
};
25-
26-
struct bpf_map_def SEC("maps") redirect_params = {
27-
.type = BPF_MAP_TYPE_HASH,
28-
.key_size = ETH_ALEN,
29-
.value_size = ETH_ALEN,
30-
.max_entries = 1,
31-
};
32-
33-
/* Solution to packet03/assignment-2 */
34-
SEC("xdp_redirect")
35-
int xdp_redirect_func(struct xdp_md *ctx)
36-
{
37-
void *data_end = (void *)(long)ctx->data_end;
38-
void *data = (void *)(long)ctx->data;
39-
struct hdr_cursor nh;
40-
struct ethhdr *eth;
41-
int eth_type;
42-
int action = XDP_PASS;
43-
unsigned char dst[ETH_ALEN] = { /* TODO: put your values here */ };
44-
unsigned ifindex = 0/* TODO: put your values here */;
45-
46-
/* These keep track of the next header type and iterator pointer */
47-
nh.pos = data;
48-
49-
/* Parse Ethernet and IP/IPv6 headers */
50-
eth_type = parse_ethhdr(&nh, data_end, &eth);
51-
if (eth_type == -1)
52-
goto out;
53-
54-
/* Set a proper destination address */
55-
memcpy(eth->h_dest, dst, ETH_ALEN);
56-
action = bpf_redirect(ifindex, 0);
57-
58-
out:
59-
return xdp_stats_record_action(ctx, action);
60-
}
61-
62-
/* Solution to packet03/assignment-3 */
63-
SEC("xdp_redirect_map")
64-
int xdp_redirect_map_func(struct xdp_md *ctx)
15+
SEC("xdp_tailgrow")
16+
int tailgrow_pass(struct xdp_md *ctx)
6517
{
66-
void *data_end = (void *)(long)ctx->data_end;
67-
void *data = (void *)(long)ctx->data;
68-
struct hdr_cursor nh;
69-
struct ethhdr *eth;
70-
int eth_type;
71-
int action = XDP_PASS;
72-
unsigned char *dst;
73-
74-
/* These keep track of the next header type and iterator pointer */
75-
nh.pos = data;
76-
77-
/* Parse Ethernet and IP/IPv6 headers */
78-
eth_type = parse_ethhdr(&nh, data_end, &eth);
79-
if (eth_type == -1)
80-
goto out;
81-
82-
/* Do we know where to redirect this packet? */
83-
dst = bpf_map_lookup_elem(&redirect_params, eth->h_source);
84-
if (!dst)
85-
goto out;
86-
87-
/* Set a proper destination address */
88-
memcpy(eth->h_dest, dst, ETH_ALEN);
89-
action = bpf_redirect_map(&tx_port, 0, 0);
18+
int offset;
9019

91-
out:
92-
return xdp_stats_record_action(ctx, action);
20+
offset = 10;
21+
bpf_xdp_adjust_tail(ctx, offset);
22+
return xdp_stats_record_action(ctx, XDP_PASS);
9323
}
9424

9525
SEC("xdp_pass")
@@ -98,34 +28,20 @@ int xdp_pass_func(struct xdp_md *ctx)
9828
return xdp_stats_record_action(ctx, XDP_PASS);
9929
}
10030

101-
SEC("xdp_tailgrow")
102-
int xdp_tailgrow_func(struct xdp_md *ctx)
103-
{
104-
// void *data_end = (void *)(long)ctx->data_end;
105-
// void *data = (void *)(long)ctx->data;
106-
//struct hdr_cursor nh;
107-
int offset;
108-
109-
offset = 10;
110-
bpf_xdp_adjust_tail(ctx, offset);
111-
return xdp_stats_record_action(ctx, XDP_PASS);
112-
}
113-
31+
/* For benchmarking tail grow overhead (does a memset)*/
11432
SEC("xdp_tailgrow_tx")
115-
int xdp_tailgrow_func2(struct xdp_md *ctx)
33+
int tailgrow_tx(struct xdp_md *ctx)
11634
{
117-
// void *data_end = (void *)(long)ctx->data_end;
118-
// void *data = (void *)(long)ctx->data;
119-
//struct hdr_cursor nh;
12035
int offset;
12136

12237
offset = 32;
12338
bpf_xdp_adjust_tail(ctx, offset);
12439
return xdp_stats_record_action(ctx, XDP_TX);
12540
}
12641

42+
/* Baseline benchmark of XDP_TX */
12743
SEC("xdp_tx")
128-
int xdp_tx_func(struct xdp_md *ctx)
44+
int xdp_tx_rec(struct xdp_md *ctx)
12945
{
13046
return xdp_stats_record_action(ctx, XDP_TX);
13147
}
@@ -135,34 +51,6 @@ struct my_timestamp {
13551
__u64 time;
13652
} __attribute__((packed));
13753

138-
SEC("xdp_tailgrow_use")
139-
int xdp_tailgrow3(struct xdp_md *ctx)
140-
{
141-
void *data_end = (void *)(long)ctx->data_end;
142-
void *data = (void *)(long)ctx->data;
143-
//struct hdr_cursor nh;
144-
int offset;
145-
struct my_timestamp *ts;
146-
147-
offset = 8;
148-
// if (data + offset > data_end)
149-
// return XDP_ABORTED;
150-
151-
bpf_xdp_adjust_tail(ctx, offset);
152-
data_end = (void *)(long)ctx->data_end;
153-
data = (void *)(long)ctx->data;
154-
155-
if (data + offset > data_end)
156-
return XDP_ABORTED;
157-
// if (data + 2048 > data_end)
158-
// return XDP_ABORTED;
159-
160-
ts = data;
161-
// ts->time = 42;
162-
163-
return xdp_stats_record_action(ctx, XDP_PASS);
164-
}
165-
16654
SEC("xdp_tailgrow_parse")
16755
int grow_parse(struct xdp_md *ctx)
16856
{

0 commit comments

Comments
 (0)