test_run.c (10a558374f3751cf4eb55143008975641dfc2cf4) test_run.c (65073a67331de3d2cce35607807ddec284e75e81)
1/* Copyright (c) 2017 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#include <linux/bpf.h>
8#include <linux/slab.h>

--- 137 unchanged lines hidden (view full) ---

146 return ret;
147}
148
149int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
150 union bpf_attr __user *uattr)
151{
152 u32 size = kattr->test.data_size_in;
153 u32 repeat = kattr->test.repeat;
1/* Copyright (c) 2017 Facebook
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#include <linux/bpf.h>
8#include <linux/slab.h>

--- 137 unchanged lines hidden (view full) ---

146 return ret;
147}
148
149int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
150 union bpf_attr __user *uattr)
151{
152 u32 size = kattr->test.data_size_in;
153 u32 repeat = kattr->test.repeat;
154 struct netdev_rx_queue *rxqueue;
154 struct xdp_buff xdp = {};
155 u32 retval, duration;
156 void *data;
157 int ret;
158
159 data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM + NET_IP_ALIGN, 0);
160 if (IS_ERR(data))
161 return PTR_ERR(data);
162
163 xdp.data_hard_start = data;
164 xdp.data = data + XDP_PACKET_HEADROOM + NET_IP_ALIGN;
165 xdp.data_meta = xdp.data;
166 xdp.data_end = xdp.data + size;
167
155 struct xdp_buff xdp = {};
156 u32 retval, duration;
157 void *data;
158 int ret;
159
160 data = bpf_test_init(kattr, size, XDP_PACKET_HEADROOM + NET_IP_ALIGN, 0);
161 if (IS_ERR(data))
162 return PTR_ERR(data);
163
164 xdp.data_hard_start = data;
165 xdp.data = data + XDP_PACKET_HEADROOM + NET_IP_ALIGN;
166 xdp.data_meta = xdp.data;
167 xdp.data_end = xdp.data + size;
168
169 rxqueue = __netif_get_rx_queue(current->nsproxy->net_ns->loopback_dev, 0);
170 xdp.rxq = &rxqueue->xdp_rxq;
171
168 retval = bpf_test_run(prog, &xdp, repeat, &duration);
169 if (xdp.data != data + XDP_PACKET_HEADROOM + NET_IP_ALIGN)
170 size = xdp.data_end - xdp.data;
171 ret = bpf_test_finish(kattr, uattr, xdp.data, size, retval, duration);
172 kfree(data);
173 return ret;
174}
172 retval = bpf_test_run(prog, &xdp, repeat, &duration);
173 if (xdp.data != data + XDP_PACKET_HEADROOM + NET_IP_ALIGN)
174 size = xdp.data_end - xdp.data;
175 ret = bpf_test_finish(kattr, uattr, xdp.data, size, retval, duration);
176 kfree(data);
177 return ret;
178}