Skip to content

Commit

Permalink
bpf: make xdp sample variable names more meaningful
Browse files Browse the repository at this point in the history
The naming choice of index is not terribly descriptive, and dropcnt is
in fact incorrect for xdp2. Pick better names for these: ipproto and
rxcnt.

Signed-off-by: Brenden Blanco <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Brenden Blanco authored and davem330 committed Jul 21, 2016
1 parent 262d862 commit d9094bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions samples/bpf/xdp1_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <linux/ipv6.h>
#include "bpf_helpers.h"

struct bpf_map_def SEC("maps") dropcnt = {
struct bpf_map_def SEC("maps") rxcnt = {
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(long),
Expand Down Expand Up @@ -49,7 +49,7 @@ int xdp_prog1(struct xdp_md *ctx)
long *value;
u16 h_proto;
u64 nh_off;
u32 index;
u32 ipproto;

nh_off = sizeof(*eth);
if (data + nh_off > data_end)
Expand Down Expand Up @@ -77,13 +77,13 @@ int xdp_prog1(struct xdp_md *ctx)
}

if (h_proto == htons(ETH_P_IP))
index = parse_ipv4(data, nh_off, data_end);
ipproto = parse_ipv4(data, nh_off, data_end);
else if (h_proto == htons(ETH_P_IPV6))
index = parse_ipv6(data, nh_off, data_end);
ipproto = parse_ipv6(data, nh_off, data_end);
else
index = 0;
ipproto = 0;

value = bpf_map_lookup_elem(&dropcnt, &index);
value = bpf_map_lookup_elem(&rxcnt, &ipproto);
if (value)
*value += 1;

Expand Down
14 changes: 7 additions & 7 deletions samples/bpf/xdp2_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <linux/ipv6.h>
#include "bpf_helpers.h"

struct bpf_map_def SEC("maps") dropcnt = {
struct bpf_map_def SEC("maps") rxcnt = {
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(long),
Expand Down Expand Up @@ -65,7 +65,7 @@ int xdp_prog1(struct xdp_md *ctx)
long *value;
u16 h_proto;
u64 nh_off;
u32 index;
u32 ipproto;

nh_off = sizeof(*eth);
if (data + nh_off > data_end)
Expand Down Expand Up @@ -93,17 +93,17 @@ int xdp_prog1(struct xdp_md *ctx)
}

if (h_proto == htons(ETH_P_IP))
index = parse_ipv4(data, nh_off, data_end);
ipproto = parse_ipv4(data, nh_off, data_end);
else if (h_proto == htons(ETH_P_IPV6))
index = parse_ipv6(data, nh_off, data_end);
ipproto = parse_ipv6(data, nh_off, data_end);
else
index = 0;
ipproto = 0;

value = bpf_map_lookup_elem(&dropcnt, &index);
value = bpf_map_lookup_elem(&rxcnt, &ipproto);
if (value)
*value += 1;

if (index == 17) {
if (ipproto == IPPROTO_UDP) {
swap_src_dst_mac(data);
rc = XDP_TX;
}
Expand Down

0 comments on commit d9094bd

Please sign in to comment.