-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: add test cases for queue and stack maps
test_maps: Tests that queue/stack maps are behaving correctly even in corner cases test_progs: Tests new ebpf helpers Signed-off-by: Mauricio Vasquez B <mauricio.vasquez@polito.it> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Mauricio Vasquez B
authored and
Alexei Starovoitov
committed
Oct 19, 2018
1 parent
da4e1b1
commit 43b987d
Showing
9 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2018 Politecnico di Torino | ||
#define MAP_TYPE BPF_MAP_TYPE_QUEUE | ||
#include "test_queue_stack_map.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
// Copyright (c) 2018 Politecnico di Torino | ||
#include <stddef.h> | ||
#include <string.h> | ||
#include <linux/bpf.h> | ||
#include <linux/if_ether.h> | ||
#include <linux/ip.h> | ||
#include <linux/pkt_cls.h> | ||
#include "bpf_helpers.h" | ||
|
||
int _version SEC("version") = 1; | ||
|
||
struct bpf_map_def __attribute__ ((section("maps"), used)) map_in = { | ||
.type = MAP_TYPE, | ||
.key_size = 0, | ||
.value_size = sizeof(__u32), | ||
.max_entries = 32, | ||
.map_flags = 0, | ||
}; | ||
|
||
struct bpf_map_def __attribute__ ((section("maps"), used)) map_out = { | ||
.type = MAP_TYPE, | ||
.key_size = 0, | ||
.value_size = sizeof(__u32), | ||
.max_entries = 32, | ||
.map_flags = 0, | ||
}; | ||
|
||
SEC("test") | ||
int _test(struct __sk_buff *skb) | ||
{ | ||
void *data_end = (void *)(long)skb->data_end; | ||
void *data = (void *)(long)skb->data; | ||
struct ethhdr *eth = (struct ethhdr *)(data); | ||
__u32 value; | ||
int err; | ||
|
||
if (eth + 1 > data_end) | ||
return TC_ACT_SHOT; | ||
|
||
struct iphdr *iph = (struct iphdr *)(eth + 1); | ||
|
||
if (iph + 1 > data_end) | ||
return TC_ACT_SHOT; | ||
|
||
err = bpf_map_pop_elem(&map_in, &value); | ||
if (err) | ||
return TC_ACT_SHOT; | ||
|
||
iph->daddr = value; | ||
|
||
err = bpf_map_push_elem(&map_out, &iph->saddr, 0); | ||
if (err) | ||
return TC_ACT_SHOT; | ||
|
||
return TC_ACT_OK; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2018 Politecnico di Torino | ||
#define MAP_TYPE BPF_MAP_TYPE_STACK | ||
#include "test_queue_stack_map.h" |