Skip to content

Commit 586f852

Browse files
committed
bpf: Align packet data properly in program testing framework.
Make sure we apply NET_IP_ALIGN when reserving headroom for SKB and XDP test runs, just like a real driver would. Signed-off-by: David S. Miller <[email protected]> Acked-by: Daniel Borkmann <[email protected]>
1 parent 78e5227 commit 586f852

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/bpf/test_run.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
100100
void *data;
101101
int ret;
102102

103-
data = bpf_test_init(kattr, size, NET_SKB_PAD,
103+
data = bpf_test_init(kattr, size, NET_SKB_PAD + NET_IP_ALIGN,
104104
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
105105
if (IS_ERR(data))
106106
return PTR_ERR(data);
@@ -125,7 +125,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
125125
return -ENOMEM;
126126
}
127127

128-
skb_reserve(skb, NET_SKB_PAD);
128+
skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
129129
__skb_put(skb, size);
130130
skb->protocol = eth_type_trans(skb, current->nsproxy->net_ns->loopback_dev);
131131
skb_reset_network_header(skb);
@@ -156,16 +156,16 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
156156
void *data;
157157
int ret;
158158

159-
data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM, 0);
159+
data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM + NET_IP_ALIGN, 0);
160160
if (IS_ERR(data))
161161
return PTR_ERR(data);
162162

163163
xdp.data_hard_start = data;
164-
xdp.data = data + XDP_PACKET_HEADROOM;
164+
xdp.data = data + XDP_PACKET_HEADROOM + NET_IP_ALIGN;
165165
xdp.data_end = xdp.data + size;
166166

167167
retval = bpf_test_run(prog, &xdp, repeat, &duration);
168-
if (xdp.data != data + XDP_PACKET_HEADROOM)
168+
if (xdp.data != data + XDP_PACKET_HEADROOM + NET_IP_ALIGN)
169169
size = xdp.data_end - xdp.data;
170170
ret = bpf_test_finish(kattr, uattr, xdp.data, size, retval, duration);
171171
kfree(data);

0 commit comments

Comments
 (0)