Skip to content

Commit

Permalink
xdp: fix xdp_bench01 action XDP_TX, such packets reach the TX wire
Browse files Browse the repository at this point in the history
Simply bouncing the packet via XDP_TX is getting blocked by the
NIC hardware, in this case the ConnectX-4 driver mlx5.

The MAC-addresses need to be swapped, before the NIC HW allows
these packets to reach the wire.

For now, allow keeping the "invalid" case to allow further testing.
But print a big WARNING that packets might not reach the wire.

The correct use is enabled via using option --readmem and action XDP_TX.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
  • Loading branch information
netoptimizer committed Apr 21, 2017
1 parent e4745de commit 85f7ba2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions kernel/samples/bpf/xdp_bench01_mem_access_cost_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ struct bpf_map_def SEC("maps") touch_memory = {
.max_entries = 1,
};

static void swap_src_dst_mac(void *data)
{
unsigned short *p = data;
unsigned short dst[3];

dst[0] = p[0];
dst[1] = p[1];
dst[2] = p[2];
p[0] = p[3];
p[1] = p[4];
p[2] = p[5];
p[3] = dst[0];
p[4] = dst[1];
p[5] = dst[2];
}

SEC("xdp_bench01")
int xdp_prog(struct xdp_md *ctx)
{
Expand Down Expand Up @@ -57,6 +73,13 @@ int xdp_prog(struct xdp_md *ctx)
/* Avoid compile removing this: e.g Drop non 802.3 Ethertypes */
if (ntohs(eth_type) < ETH_P_802_3_MIN)
return XDP_DROP;

/* If touch_mem, also swap MACs for XDP_TX. This is
* needed for action XDP_TX, else HW will not TX packet
* (this was observed with mlx5 driver).
*/
if (*action == XDP_TX)
swap_src_dst_mac(data);
}

value = bpf_map_lookup_elem(&rx_cnt, &key);
Expand Down
5 changes: 5 additions & 0 deletions kernel/samples/bpf/xdp_bench01_mem_access_cost_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ int main(int argc, char **argv)
set_xdp_action(action);
set_touch_mem(touch_mem);

/* Some NIC drop packets on XDP_TX if MAC-addr isn't changed */
if ((action == XDP_TX) && !(touch_mem))
fprintf(stderr, "\n **WARNING** "
"XDP_TX without --readmem, might not TX to wire\n\n");

/* Remove XDP program when program is interrupted */
signal(SIGINT, int_exit);

Expand Down

0 comments on commit 85f7ba2

Please sign in to comment.