Merge tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2025-01-07 We've added 7 non-merge commits during the last 32 day(s) which contain a total of 11 files changed, 190 insertions(+), 103 deletions(-). The main changes are: 1) Migrate the test_xdp_meta.sh BPF selftest into test_progs framework, from Bastien Curutchet. 2) Add ability to configure head/tailroom for netkit devices, from Daniel Borkmann. 3) Fixes and improvements to the xdp_hw_metadata selftest, from Song Yoong Siang. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: selftests/bpf: Extend netkit tests to validate set {head,tail}room netkit: Add add netkit {head,tail}room to rt_link.yaml netkit: Allow for configuring needed_{head,tail}room selftests/bpf: Migrate test_xdp_meta.sh into xdp_context_test_run.c selftests/bpf: test_xdp_meta: Rename BPF sections selftests/bpf: Enable Tx hwtstamp in xdp_hw_metadata selftests/bpf: Actuate tx_metadata_len in xdp_hw_metadata ==================== Link: https://patch.msgid.link/20250107130908.143644-1-daniel@iogearbox.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
@@ -2169,6 +2169,12 @@ attribute-sets:
|
||||
name: peer-scrub
|
||||
type: u32
|
||||
enum: netkit-scrub
|
||||
-
|
||||
name: headroom
|
||||
type: u16
|
||||
-
|
||||
name: tailroom
|
||||
type: u16
|
||||
|
||||
sub-messages:
|
||||
-
|
||||
|
||||
@@ -338,6 +338,7 @@ static int netkit_new_link(struct net *peer_net, struct net_device *dev,
|
||||
enum netkit_scrub scrub_peer = NETKIT_SCRUB_DEFAULT;
|
||||
enum netkit_mode mode = NETKIT_L3;
|
||||
unsigned char ifname_assign_type;
|
||||
u16 headroom = 0, tailroom = 0;
|
||||
struct ifinfomsg *ifmp = NULL;
|
||||
struct net_device *peer;
|
||||
char ifname[IFNAMSIZ];
|
||||
@@ -371,6 +372,10 @@ static int netkit_new_link(struct net *peer_net, struct net_device *dev,
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (data[IFLA_NETKIT_HEADROOM])
|
||||
headroom = nla_get_u16(data[IFLA_NETKIT_HEADROOM]);
|
||||
if (data[IFLA_NETKIT_TAILROOM])
|
||||
tailroom = nla_get_u16(data[IFLA_NETKIT_TAILROOM]);
|
||||
}
|
||||
|
||||
if (ifmp && tbp[IFLA_IFNAME]) {
|
||||
@@ -390,6 +395,14 @@ static int netkit_new_link(struct net *peer_net, struct net_device *dev,
|
||||
return PTR_ERR(peer);
|
||||
|
||||
netif_inherit_tso_max(peer, dev);
|
||||
if (headroom) {
|
||||
peer->needed_headroom = headroom;
|
||||
dev->needed_headroom = headroom;
|
||||
}
|
||||
if (tailroom) {
|
||||
peer->needed_tailroom = tailroom;
|
||||
dev->needed_tailroom = tailroom;
|
||||
}
|
||||
|
||||
if (mode == NETKIT_L2 && !(ifmp && tbp[IFLA_ADDRESS]))
|
||||
eth_hw_addr_random(peer);
|
||||
@@ -401,6 +414,7 @@ static int netkit_new_link(struct net *peer_net, struct net_device *dev,
|
||||
nk->policy = policy_peer;
|
||||
nk->scrub = scrub_peer;
|
||||
nk->mode = mode;
|
||||
nk->headroom = headroom;
|
||||
bpf_mprog_bundle_init(&nk->bundle);
|
||||
|
||||
err = register_netdevice(peer);
|
||||
@@ -426,6 +440,7 @@ static int netkit_new_link(struct net *peer_net, struct net_device *dev,
|
||||
nk->policy = policy_prim;
|
||||
nk->scrub = scrub_prim;
|
||||
nk->mode = mode;
|
||||
nk->headroom = headroom;
|
||||
bpf_mprog_bundle_init(&nk->bundle);
|
||||
|
||||
err = register_netdevice(dev);
|
||||
@@ -850,7 +865,18 @@ static int netkit_change_link(struct net_device *dev, struct nlattr *tb[],
|
||||
struct net_device *peer = rtnl_dereference(nk->peer);
|
||||
enum netkit_action policy;
|
||||
struct nlattr *attr;
|
||||
int err;
|
||||
int err, i;
|
||||
static const struct {
|
||||
u32 attr;
|
||||
char *name;
|
||||
} fixed_params[] = {
|
||||
{ IFLA_NETKIT_MODE, "operating mode" },
|
||||
{ IFLA_NETKIT_SCRUB, "scrubbing" },
|
||||
{ IFLA_NETKIT_PEER_SCRUB, "peer scrubbing" },
|
||||
{ IFLA_NETKIT_PEER_INFO, "peer info" },
|
||||
{ IFLA_NETKIT_HEADROOM, "headroom" },
|
||||
{ IFLA_NETKIT_TAILROOM, "tailroom" },
|
||||
};
|
||||
|
||||
if (!nk->primary) {
|
||||
NL_SET_ERR_MSG(extack,
|
||||
@@ -858,28 +884,14 @@ static int netkit_change_link(struct net_device *dev, struct nlattr *tb[],
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
if (data[IFLA_NETKIT_MODE]) {
|
||||
NL_SET_ERR_MSG_ATTR(extack, data[IFLA_NETKIT_MODE],
|
||||
"netkit link operating mode cannot be changed after device creation");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
if (data[IFLA_NETKIT_SCRUB]) {
|
||||
NL_SET_ERR_MSG_ATTR(extack, data[IFLA_NETKIT_SCRUB],
|
||||
"netkit scrubbing cannot be changed after device creation");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
if (data[IFLA_NETKIT_PEER_SCRUB]) {
|
||||
NL_SET_ERR_MSG_ATTR(extack, data[IFLA_NETKIT_PEER_SCRUB],
|
||||
"netkit scrubbing cannot be changed after device creation");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
if (data[IFLA_NETKIT_PEER_INFO]) {
|
||||
NL_SET_ERR_MSG_ATTR(extack, data[IFLA_NETKIT_PEER_INFO],
|
||||
"netkit peer info cannot be changed after device creation");
|
||||
return -EINVAL;
|
||||
for (i = 0; i < ARRAY_SIZE(fixed_params); i++) {
|
||||
attr = data[fixed_params[i].attr];
|
||||
if (attr) {
|
||||
NL_SET_ERR_MSG_ATTR_FMT(extack, attr,
|
||||
"netkit link %s cannot be changed after device creation",
|
||||
fixed_params[i].name);
|
||||
return -EACCES;
|
||||
}
|
||||
}
|
||||
|
||||
if (data[IFLA_NETKIT_POLICY]) {
|
||||
@@ -914,6 +926,8 @@ static size_t netkit_get_size(const struct net_device *dev)
|
||||
nla_total_size(sizeof(u32)) + /* IFLA_NETKIT_PEER_SCRUB */
|
||||
nla_total_size(sizeof(u32)) + /* IFLA_NETKIT_MODE */
|
||||
nla_total_size(sizeof(u8)) + /* IFLA_NETKIT_PRIMARY */
|
||||
nla_total_size(sizeof(u16)) + /* IFLA_NETKIT_HEADROOM */
|
||||
nla_total_size(sizeof(u16)) + /* IFLA_NETKIT_TAILROOM */
|
||||
0;
|
||||
}
|
||||
|
||||
@@ -930,6 +944,10 @@ static int netkit_fill_info(struct sk_buff *skb, const struct net_device *dev)
|
||||
return -EMSGSIZE;
|
||||
if (nla_put_u32(skb, IFLA_NETKIT_SCRUB, nk->scrub))
|
||||
return -EMSGSIZE;
|
||||
if (nla_put_u16(skb, IFLA_NETKIT_HEADROOM, dev->needed_headroom))
|
||||
return -EMSGSIZE;
|
||||
if (nla_put_u16(skb, IFLA_NETKIT_TAILROOM, dev->needed_tailroom))
|
||||
return -EMSGSIZE;
|
||||
|
||||
if (peer) {
|
||||
nk = netkit_priv(peer);
|
||||
@@ -947,6 +965,8 @@ static const struct nla_policy netkit_policy[IFLA_NETKIT_MAX + 1] = {
|
||||
[IFLA_NETKIT_MODE] = NLA_POLICY_MAX(NLA_U32, NETKIT_L3),
|
||||
[IFLA_NETKIT_POLICY] = { .type = NLA_U32 },
|
||||
[IFLA_NETKIT_PEER_POLICY] = { .type = NLA_U32 },
|
||||
[IFLA_NETKIT_HEADROOM] = { .type = NLA_U16 },
|
||||
[IFLA_NETKIT_TAILROOM] = { .type = NLA_U16 },
|
||||
[IFLA_NETKIT_SCRUB] = NLA_POLICY_MAX(NLA_U32, NETKIT_SCRUB_DEFAULT),
|
||||
[IFLA_NETKIT_PEER_SCRUB] = NLA_POLICY_MAX(NLA_U32, NETKIT_SCRUB_DEFAULT),
|
||||
[IFLA_NETKIT_PRIMARY] = { .type = NLA_REJECT,
|
||||
|
||||
@@ -1315,6 +1315,8 @@ enum {
|
||||
IFLA_NETKIT_MODE,
|
||||
IFLA_NETKIT_SCRUB,
|
||||
IFLA_NETKIT_PEER_SCRUB,
|
||||
IFLA_NETKIT_HEADROOM,
|
||||
IFLA_NETKIT_TAILROOM,
|
||||
__IFLA_NETKIT_MAX,
|
||||
};
|
||||
#define IFLA_NETKIT_MAX (__IFLA_NETKIT_MAX - 1)
|
||||
|
||||
@@ -1315,6 +1315,8 @@ enum {
|
||||
IFLA_NETKIT_MODE,
|
||||
IFLA_NETKIT_SCRUB,
|
||||
IFLA_NETKIT_PEER_SCRUB,
|
||||
IFLA_NETKIT_HEADROOM,
|
||||
IFLA_NETKIT_TAILROOM,
|
||||
__IFLA_NETKIT_MAX,
|
||||
};
|
||||
#define IFLA_NETKIT_MAX (__IFLA_NETKIT_MAX - 1)
|
||||
|
||||
@@ -129,7 +129,6 @@ TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c)
|
||||
TEST_PROGS := test_kmod.sh \
|
||||
test_xdp_redirect.sh \
|
||||
test_xdp_redirect_multi.sh \
|
||||
test_xdp_meta.sh \
|
||||
test_tunnel.sh \
|
||||
test_lwt_seg6local.sh \
|
||||
test_lirc_mode2.sh \
|
||||
|
||||
@@ -14,10 +14,16 @@
|
||||
#include "netlink_helpers.h"
|
||||
#include "tc_helpers.h"
|
||||
|
||||
#define NETKIT_HEADROOM 32
|
||||
#define NETKIT_TAILROOM 8
|
||||
|
||||
#define MARK 42
|
||||
#define PRIO 0xeb9f
|
||||
#define ICMP_ECHO 8
|
||||
|
||||
#define FLAG_ADJUST_ROOM (1 << 0)
|
||||
#define FLAG_SAME_NETNS (1 << 1)
|
||||
|
||||
struct icmphdr {
|
||||
__u8 type;
|
||||
__u8 code;
|
||||
@@ -35,7 +41,7 @@ struct iplink_req {
|
||||
};
|
||||
|
||||
static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
|
||||
bool same_netns, int scrub, int peer_scrub)
|
||||
int scrub, int peer_scrub, __u32 flags)
|
||||
{
|
||||
struct rtnl_handle rth = { .fd = -1 };
|
||||
struct iplink_req req = {};
|
||||
@@ -63,6 +69,10 @@ static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
|
||||
addattr32(&req.n, sizeof(req), IFLA_NETKIT_SCRUB, scrub);
|
||||
addattr32(&req.n, sizeof(req), IFLA_NETKIT_PEER_SCRUB, peer_scrub);
|
||||
addattr32(&req.n, sizeof(req), IFLA_NETKIT_MODE, mode);
|
||||
if (flags & FLAG_ADJUST_ROOM) {
|
||||
addattr16(&req.n, sizeof(req), IFLA_NETKIT_HEADROOM, NETKIT_HEADROOM);
|
||||
addattr16(&req.n, sizeof(req), IFLA_NETKIT_TAILROOM, NETKIT_TAILROOM);
|
||||
}
|
||||
addattr_nest_end(&req.n, data);
|
||||
addattr_nest_end(&req.n, linkinfo);
|
||||
|
||||
@@ -87,7 +97,7 @@ static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
|
||||
" addr ee:ff:bb:cc:aa:dd"),
|
||||
"set hwaddress");
|
||||
}
|
||||
if (same_netns) {
|
||||
if (flags & FLAG_SAME_NETNS) {
|
||||
ASSERT_OK(system("ip link set dev " netkit_peer " up"),
|
||||
"up peer");
|
||||
ASSERT_OK(system("ip addr add dev " netkit_peer " 10.0.0.2/24"),
|
||||
@@ -184,8 +194,8 @@ void serial_test_tc_netkit_basic(void)
|
||||
int err, ifindex;
|
||||
|
||||
err = create_netkit(NETKIT_L2, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, false, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT);
|
||||
&ifindex, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT, 0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -299,8 +309,8 @@ static void serial_test_tc_netkit_multi_links_target(int mode, int target)
|
||||
int err, ifindex;
|
||||
|
||||
err = create_netkit(mode, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, false, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT);
|
||||
&ifindex, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT, 0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -428,8 +438,8 @@ static void serial_test_tc_netkit_multi_opts_target(int mode, int target)
|
||||
int err, ifindex;
|
||||
|
||||
err = create_netkit(mode, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, false, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT);
|
||||
&ifindex, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT, 0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -543,8 +553,8 @@ void serial_test_tc_netkit_device(void)
|
||||
int err, ifindex, ifindex2;
|
||||
|
||||
err = create_netkit(NETKIT_L3, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, true, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT);
|
||||
&ifindex, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT, FLAG_SAME_NETNS);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -655,8 +665,8 @@ static void serial_test_tc_netkit_neigh_links_target(int mode, int target)
|
||||
int err, ifindex;
|
||||
|
||||
err = create_netkit(mode, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, false, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT);
|
||||
&ifindex, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT, 0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -733,8 +743,8 @@ static void serial_test_tc_netkit_pkt_type_mode(int mode)
|
||||
struct bpf_link *link;
|
||||
|
||||
err = create_netkit(mode, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, true, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT);
|
||||
&ifindex, NETKIT_SCRUB_DEFAULT,
|
||||
NETKIT_SCRUB_DEFAULT, FLAG_SAME_NETNS);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -799,7 +809,7 @@ void serial_test_tc_netkit_pkt_type(void)
|
||||
serial_test_tc_netkit_pkt_type_mode(NETKIT_L3);
|
||||
}
|
||||
|
||||
static void serial_test_tc_netkit_scrub_type(int scrub)
|
||||
static void serial_test_tc_netkit_scrub_type(int scrub, bool room)
|
||||
{
|
||||
LIBBPF_OPTS(bpf_netkit_opts, optl);
|
||||
struct test_tc_link *skel;
|
||||
@@ -807,7 +817,8 @@ static void serial_test_tc_netkit_scrub_type(int scrub)
|
||||
int err, ifindex;
|
||||
|
||||
err = create_netkit(NETKIT_L2, NETKIT_PASS, NETKIT_PASS,
|
||||
&ifindex, false, scrub, scrub);
|
||||
&ifindex, scrub, scrub,
|
||||
room ? FLAG_ADJUST_ROOM : 0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
@@ -842,6 +853,8 @@ static void serial_test_tc_netkit_scrub_type(int scrub)
|
||||
ASSERT_EQ(skel->bss->seen_tc8, true, "seen_tc8");
|
||||
ASSERT_EQ(skel->bss->mark, scrub == NETKIT_SCRUB_NONE ? MARK : 0, "mark");
|
||||
ASSERT_EQ(skel->bss->prio, scrub == NETKIT_SCRUB_NONE ? PRIO : 0, "prio");
|
||||
ASSERT_EQ(skel->bss->headroom, room ? NETKIT_HEADROOM : 0, "headroom");
|
||||
ASSERT_EQ(skel->bss->tailroom, room ? NETKIT_TAILROOM : 0, "tailroom");
|
||||
cleanup:
|
||||
test_tc_link__destroy(skel);
|
||||
|
||||
@@ -852,6 +865,6 @@ cleanup:
|
||||
|
||||
void serial_test_tc_netkit_scrub(void)
|
||||
{
|
||||
serial_test_tc_netkit_scrub_type(NETKIT_SCRUB_DEFAULT);
|
||||
serial_test_tc_netkit_scrub_type(NETKIT_SCRUB_NONE);
|
||||
serial_test_tc_netkit_scrub_type(NETKIT_SCRUB_DEFAULT, false);
|
||||
serial_test_tc_netkit_scrub_type(NETKIT_SCRUB_NONE, true);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
#include <test_progs.h>
|
||||
#include <network_helpers.h>
|
||||
#include "test_xdp_context_test_run.skel.h"
|
||||
#include "test_xdp_meta.skel.h"
|
||||
|
||||
#define TX_ADDR "10.0.0.1"
|
||||
#define RX_ADDR "10.0.0.2"
|
||||
#define RX_NAME "veth0"
|
||||
#define TX_NAME "veth1"
|
||||
#define TX_NETNS "xdp_context_tx"
|
||||
#define RX_NETNS "xdp_context_rx"
|
||||
|
||||
void test_xdp_context_error(int prog_fd, struct bpf_test_run_opts opts,
|
||||
__u32 data_meta, __u32 data, __u32 data_end,
|
||||
@@ -103,3 +111,82 @@ void test_xdp_context_test_run(void)
|
||||
|
||||
test_xdp_context_test_run__destroy(skel);
|
||||
}
|
||||
|
||||
void test_xdp_context_functional(void)
|
||||
{
|
||||
LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
|
||||
LIBBPF_OPTS(bpf_tc_opts, tc_opts, .handle = 1, .priority = 1);
|
||||
struct netns_obj *rx_ns = NULL, *tx_ns = NULL;
|
||||
struct bpf_program *tc_prog, *xdp_prog;
|
||||
struct test_xdp_meta *skel = NULL;
|
||||
struct nstoken *nstoken = NULL;
|
||||
int rx_ifindex;
|
||||
int ret;
|
||||
|
||||
tx_ns = netns_new(TX_NETNS, false);
|
||||
if (!ASSERT_OK_PTR(tx_ns, "create tx_ns"))
|
||||
return;
|
||||
|
||||
rx_ns = netns_new(RX_NETNS, false);
|
||||
if (!ASSERT_OK_PTR(rx_ns, "create rx_ns"))
|
||||
goto close;
|
||||
|
||||
SYS(close, "ip link add " RX_NAME " netns " RX_NETNS
|
||||
" type veth peer name " TX_NAME " netns " TX_NETNS);
|
||||
|
||||
nstoken = open_netns(RX_NETNS);
|
||||
if (!ASSERT_OK_PTR(nstoken, "setns rx_ns"))
|
||||
goto close;
|
||||
|
||||
SYS(close, "ip addr add " RX_ADDR "/24 dev " RX_NAME);
|
||||
SYS(close, "ip link set dev " RX_NAME " up");
|
||||
|
||||
skel = test_xdp_meta__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "open and load skeleton"))
|
||||
goto close;
|
||||
|
||||
rx_ifindex = if_nametoindex(RX_NAME);
|
||||
if (!ASSERT_GE(rx_ifindex, 0, "if_nametoindex rx"))
|
||||
goto close;
|
||||
|
||||
tc_hook.ifindex = rx_ifindex;
|
||||
ret = bpf_tc_hook_create(&tc_hook);
|
||||
if (!ASSERT_OK(ret, "bpf_tc_hook_create"))
|
||||
goto close;
|
||||
|
||||
tc_prog = bpf_object__find_program_by_name(skel->obj, "ing_cls");
|
||||
if (!ASSERT_OK_PTR(tc_prog, "open ing_cls prog"))
|
||||
goto close;
|
||||
|
||||
tc_opts.prog_fd = bpf_program__fd(tc_prog);
|
||||
ret = bpf_tc_attach(&tc_hook, &tc_opts);
|
||||
if (!ASSERT_OK(ret, "bpf_tc_attach"))
|
||||
goto close;
|
||||
|
||||
xdp_prog = bpf_object__find_program_by_name(skel->obj, "ing_xdp");
|
||||
if (!ASSERT_OK_PTR(xdp_prog, "open ing_xdp prog"))
|
||||
goto close;
|
||||
|
||||
ret = bpf_xdp_attach(rx_ifindex,
|
||||
bpf_program__fd(xdp_prog),
|
||||
0, NULL);
|
||||
if (!ASSERT_GE(ret, 0, "bpf_xdp_attach"))
|
||||
goto close;
|
||||
|
||||
close_netns(nstoken);
|
||||
|
||||
nstoken = open_netns(TX_NETNS);
|
||||
if (!ASSERT_OK_PTR(nstoken, "setns tx_ns"))
|
||||
goto close;
|
||||
|
||||
SYS(close, "ip addr add " TX_ADDR "/24 dev " TX_NAME);
|
||||
SYS(close, "ip link set dev " TX_NAME " up");
|
||||
ASSERT_OK(SYS_NOFAIL("ping -c 1 " RX_ADDR), "ping");
|
||||
|
||||
close:
|
||||
close_netns(nstoken);
|
||||
test_xdp_meta__destroy(skel);
|
||||
netns_free(rx_ns);
|
||||
netns_free(tx_ns);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <linux/if_packet.h>
|
||||
#include <bpf/bpf_endian.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
|
||||
char LICENSE[] SEC("license") = "GPL";
|
||||
|
||||
@@ -27,6 +28,7 @@ bool seen_host;
|
||||
bool seen_mcast;
|
||||
|
||||
int mark, prio;
|
||||
unsigned short headroom, tailroom;
|
||||
|
||||
SEC("tc/ingress")
|
||||
int tc1(struct __sk_buff *skb)
|
||||
@@ -104,11 +106,24 @@ out:
|
||||
return TCX_PASS;
|
||||
}
|
||||
|
||||
struct sk_buff {
|
||||
struct net_device *dev;
|
||||
};
|
||||
|
||||
struct net_device {
|
||||
unsigned short needed_headroom;
|
||||
unsigned short needed_tailroom;
|
||||
};
|
||||
|
||||
SEC("tc/egress")
|
||||
int tc8(struct __sk_buff *skb)
|
||||
{
|
||||
struct net_device *dev = BPF_CORE_READ((struct sk_buff *)skb, dev);
|
||||
|
||||
seen_tc8 = true;
|
||||
mark = skb->mark;
|
||||
prio = skb->priority;
|
||||
headroom = BPF_CORE_READ(dev, needed_headroom);
|
||||
tailroom = BPF_CORE_READ(dev, needed_tailroom);
|
||||
return TCX_PASS;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define round_up(x, y) ((((x) - 1) | __round_mask(x, y)) + 1)
|
||||
#define ctx_ptr(ctx, mem) (void *)(unsigned long)ctx->mem
|
||||
|
||||
SEC("t")
|
||||
SEC("tc")
|
||||
int ing_cls(struct __sk_buff *ctx)
|
||||
{
|
||||
__u8 *data, *data_meta, *data_end;
|
||||
@@ -28,7 +28,7 @@ int ing_cls(struct __sk_buff *ctx)
|
||||
return diff ? TC_ACT_SHOT : TC_ACT_OK;
|
||||
}
|
||||
|
||||
SEC("x")
|
||||
SEC("xdp")
|
||||
int ing_xdp(struct xdp_md *ctx)
|
||||
{
|
||||
__u8 *data, *data_meta, *data_end;
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
BPF_FILE="test_xdp_meta.bpf.o"
|
||||
# Kselftest framework requirement - SKIP code is 4.
|
||||
readonly KSFT_SKIP=4
|
||||
readonly NS1="ns1-$(mktemp -u XXXXXX)"
|
||||
readonly NS2="ns2-$(mktemp -u XXXXXX)"
|
||||
|
||||
cleanup()
|
||||
{
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "selftests: test_xdp_meta [PASS]";
|
||||
else
|
||||
echo "selftests: test_xdp_meta [FAILED]";
|
||||
fi
|
||||
|
||||
set +e
|
||||
ip link del veth1 2> /dev/null
|
||||
ip netns del ${NS1} 2> /dev/null
|
||||
ip netns del ${NS2} 2> /dev/null
|
||||
}
|
||||
|
||||
ip link set dev lo xdp off 2>/dev/null > /dev/null
|
||||
if [ $? -ne 0 ];then
|
||||
echo "selftests: [SKIP] Could not run test without the ip xdp support"
|
||||
exit $KSFT_SKIP
|
||||
fi
|
||||
set -e
|
||||
|
||||
ip netns add ${NS1}
|
||||
ip netns add ${NS2}
|
||||
|
||||
trap cleanup 0 2 3 6 9
|
||||
|
||||
ip link add veth1 type veth peer name veth2
|
||||
|
||||
ip link set veth1 netns ${NS1}
|
||||
ip link set veth2 netns ${NS2}
|
||||
|
||||
ip netns exec ${NS1} ip addr add 10.1.1.11/24 dev veth1
|
||||
ip netns exec ${NS2} ip addr add 10.1.1.22/24 dev veth2
|
||||
|
||||
ip netns exec ${NS1} tc qdisc add dev veth1 clsact
|
||||
ip netns exec ${NS2} tc qdisc add dev veth2 clsact
|
||||
|
||||
ip netns exec ${NS1} tc filter add dev veth1 ingress bpf da obj ${BPF_FILE} sec t
|
||||
ip netns exec ${NS2} tc filter add dev veth2 ingress bpf da obj ${BPF_FILE} sec t
|
||||
|
||||
ip netns exec ${NS1} ip link set dev veth1 xdp obj ${BPF_FILE} sec x
|
||||
ip netns exec ${NS2} ip link set dev veth2 xdp obj ${BPF_FILE} sec x
|
||||
|
||||
ip netns exec ${NS1} ip link set dev veth1 up
|
||||
ip netns exec ${NS2} ip link set dev veth2 up
|
||||
|
||||
ip netns exec ${NS1} ping -c 1 10.1.1.22
|
||||
ip netns exec ${NS2} ping -c 1 10.1.1.11
|
||||
|
||||
exit 0
|
||||
@@ -79,7 +79,7 @@ static int open_xsk(int ifindex, struct xsk *xsk, __u32 queue_id)
|
||||
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
|
||||
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
|
||||
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
|
||||
.flags = XSK_UMEM__DEFAULT_FLAGS,
|
||||
.flags = XDP_UMEM_TX_METADATA_LEN,
|
||||
.tx_metadata_len = sizeof(struct xsk_tx_metadata),
|
||||
};
|
||||
__u32 idx = 0;
|
||||
@@ -551,6 +551,7 @@ static void hwtstamp_enable(const char *ifname)
|
||||
{
|
||||
struct hwtstamp_config cfg = {
|
||||
.rx_filter = HWTSTAMP_FILTER_ALL,
|
||||
.tx_type = HWTSTAMP_TX_ON,
|
||||
};
|
||||
|
||||
hwtstamp_ioctl(SIOCGHWTSTAMP, ifname, &saved_hwtstamp_cfg);
|
||||
|
||||
Reference in New Issue
Block a user