bpf/flow_dissector: don't adjust nhoff by ETH_HLEN in BPF_PROG_TEST_RUN
Now that we use skb-less flow dissector let's return true nhoff and thoff. We used to adjust them by ETH_HLEN because that's how it was done in the skb case. For VLAN tests that looks confusing: nhoff is pointing to vlan parts :-\ Warning, this is an API change for BPF_PROG_TEST_RUN! Feel free to drop if you think that it's too late at this point to fix it. Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:

committed by
Daniel Borkmann

parent
fe993c6468
commit
02ee065836
@@ -418,9 +418,6 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
|
|||||||
retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN,
|
retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN,
|
||||||
size);
|
size);
|
||||||
|
|
||||||
flow_keys.nhoff -= ETH_HLEN;
|
|
||||||
flow_keys.thoff -= ETH_HLEN;
|
|
||||||
|
|
||||||
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
||||||
preempt_enable();
|
preempt_enable();
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
@@ -82,8 +82,8 @@ struct test tests[] = {
|
|||||||
.tcp.doff = 5,
|
.tcp.doff = 5,
|
||||||
},
|
},
|
||||||
.keys = {
|
.keys = {
|
||||||
.nhoff = 0,
|
.nhoff = ETH_HLEN,
|
||||||
.thoff = sizeof(struct iphdr),
|
.thoff = ETH_HLEN + sizeof(struct iphdr),
|
||||||
.addr_proto = ETH_P_IP,
|
.addr_proto = ETH_P_IP,
|
||||||
.ip_proto = IPPROTO_TCP,
|
.ip_proto = IPPROTO_TCP,
|
||||||
.n_proto = __bpf_constant_htons(ETH_P_IP),
|
.n_proto = __bpf_constant_htons(ETH_P_IP),
|
||||||
@@ -98,8 +98,8 @@ struct test tests[] = {
|
|||||||
.tcp.doff = 5,
|
.tcp.doff = 5,
|
||||||
},
|
},
|
||||||
.keys = {
|
.keys = {
|
||||||
.nhoff = 0,
|
.nhoff = ETH_HLEN,
|
||||||
.thoff = sizeof(struct ipv6hdr),
|
.thoff = ETH_HLEN + sizeof(struct ipv6hdr),
|
||||||
.addr_proto = ETH_P_IPV6,
|
.addr_proto = ETH_P_IPV6,
|
||||||
.ip_proto = IPPROTO_TCP,
|
.ip_proto = IPPROTO_TCP,
|
||||||
.n_proto = __bpf_constant_htons(ETH_P_IPV6),
|
.n_proto = __bpf_constant_htons(ETH_P_IPV6),
|
||||||
@@ -116,8 +116,8 @@ struct test tests[] = {
|
|||||||
.tcp.doff = 5,
|
.tcp.doff = 5,
|
||||||
},
|
},
|
||||||
.keys = {
|
.keys = {
|
||||||
.nhoff = VLAN_HLEN,
|
.nhoff = ETH_HLEN + VLAN_HLEN,
|
||||||
.thoff = VLAN_HLEN + sizeof(struct iphdr),
|
.thoff = ETH_HLEN + VLAN_HLEN + sizeof(struct iphdr),
|
||||||
.addr_proto = ETH_P_IP,
|
.addr_proto = ETH_P_IP,
|
||||||
.ip_proto = IPPROTO_TCP,
|
.ip_proto = IPPROTO_TCP,
|
||||||
.n_proto = __bpf_constant_htons(ETH_P_IP),
|
.n_proto = __bpf_constant_htons(ETH_P_IP),
|
||||||
@@ -134,8 +134,9 @@ struct test tests[] = {
|
|||||||
.tcp.doff = 5,
|
.tcp.doff = 5,
|
||||||
},
|
},
|
||||||
.keys = {
|
.keys = {
|
||||||
.nhoff = VLAN_HLEN * 2,
|
.nhoff = ETH_HLEN + VLAN_HLEN * 2,
|
||||||
.thoff = VLAN_HLEN * 2 + sizeof(struct ipv6hdr),
|
.thoff = ETH_HLEN + VLAN_HLEN * 2 +
|
||||||
|
sizeof(struct ipv6hdr),
|
||||||
.addr_proto = ETH_P_IPV6,
|
.addr_proto = ETH_P_IPV6,
|
||||||
.ip_proto = IPPROTO_TCP,
|
.ip_proto = IPPROTO_TCP,
|
||||||
.n_proto = __bpf_constant_htons(ETH_P_IPV6),
|
.n_proto = __bpf_constant_htons(ETH_P_IPV6),
|
||||||
@@ -238,9 +239,6 @@ void test_flow_dissector(void)
|
|||||||
* We use a known path in the net/tun driver that calls
|
* We use a known path in the net/tun driver that calls
|
||||||
* eth_get_headlen and we manually export bpf_flow_keys
|
* eth_get_headlen and we manually export bpf_flow_keys
|
||||||
* via BPF map in this case.
|
* via BPF map in this case.
|
||||||
*
|
|
||||||
* Note, that since eth_get_headlen operates on a L2 level,
|
|
||||||
* we adjust exported nhoff/thoff by ETH_HLEN.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
err = bpf_prog_attach(prog_fd, 0, BPF_FLOW_DISSECTOR, 0);
|
err = bpf_prog_attach(prog_fd, 0, BPF_FLOW_DISSECTOR, 0);
|
||||||
@@ -262,9 +260,6 @@ void test_flow_dissector(void)
|
|||||||
err = bpf_map_lookup_elem(keys_fd, &key, &flow_keys);
|
err = bpf_map_lookup_elem(keys_fd, &key, &flow_keys);
|
||||||
CHECK_ATTR(err, tests[i].name, "bpf_map_lookup_elem %d\n", err);
|
CHECK_ATTR(err, tests[i].name, "bpf_map_lookup_elem %d\n", err);
|
||||||
|
|
||||||
flow_keys.nhoff -= ETH_HLEN;
|
|
||||||
flow_keys.thoff -= ETH_HLEN;
|
|
||||||
|
|
||||||
CHECK_ATTR(err, tests[i].name, "skb-less err %d\n", err);
|
CHECK_ATTR(err, tests[i].name, "skb-less err %d\n", err);
|
||||||
CHECK_FLOW_KEYS(tests[i].name, flow_keys, tests[i].keys);
|
CHECK_FLOW_KEYS(tests[i].name, flow_keys, tests[i].keys);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user