Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,9 @@ static inline int __bpf_tx_skb(struct net_device *dev, struct sk_buff *skb)
ret = dev_queue_xmit(skb);
dev_xmit_recursion_dec();

if (ret > 0)
ret = net_xmit_errno(ret);

return ret;
}

Expand Down
12 changes: 10 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/empty_skb.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void test_empty_skb(void)
int *ifindex;
int err;
int ret;
int lwt_egress_ret; /* expected retval at lwt/egress */
bool success_on_tc;
} tests[] = {
/* Empty packets are always rejected. */
Expand Down Expand Up @@ -57,6 +58,7 @@ void test_empty_skb(void)
.data_size_in = sizeof(eth_hlen),
.ifindex = &veth_ifindex,
.ret = -ERANGE,
.lwt_egress_ret = -ERANGE,
.success_on_tc = true,
},
{
Expand All @@ -70,6 +72,7 @@ void test_empty_skb(void)
.data_size_in = sizeof(eth_hlen),
.ifindex = &ipip_ifindex,
.ret = -ERANGE,
.lwt_egress_ret = -ERANGE,
},

/* ETH_HLEN+1-sized packet should be redirected. */
Expand All @@ -79,6 +82,7 @@ void test_empty_skb(void)
.data_in = eth_hlen_pp,
.data_size_in = sizeof(eth_hlen_pp),
.ifindex = &veth_ifindex,
.lwt_egress_ret = -ENOBUFS,
},
{
.msg = "ipip ETH_HLEN+1 packet ingress",
Expand Down Expand Up @@ -108,8 +112,12 @@ void test_empty_skb(void)

for (i = 0; i < ARRAY_SIZE(tests); i++) {
bpf_object__for_each_program(prog, bpf_obj->obj) {
char buf[128];
bool at_egress = strstr(bpf_program__name(prog), "egress") != NULL;
bool at_tc = !strncmp(bpf_program__section_name(prog), "tc", 2);
int expected_ret;
char buf[128];

expected_ret = at_egress && !at_tc ? tests[i].lwt_egress_ret : tests[i].ret;

tattr.data_in = tests[i].data_in;
tattr.data_size_in = tests[i].data_size_in;
Expand All @@ -128,7 +136,7 @@ void test_empty_skb(void)
if (at_tc && tests[i].success_on_tc)
ASSERT_GE(bpf_obj->bss->ret, 0, buf);
else
ASSERT_EQ(bpf_obj->bss->ret, tests[i].ret, buf);
ASSERT_EQ(bpf_obj->bss->ret, expected_ret, buf);
}
}

Expand Down