aboutsummaryrefslogtreecommitdiffstats
path: root/samples/bpf/sockex2_user.c
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@plumgrid.com>2015-03-13 11:57:43 -0700
committerDavid S. Miller <davem@davemloft.net>2015-03-15 22:02:28 -0400
commit614cd3bd3758a806cea497d493b584e6157561f7 (patch)
tree3c294086671617614f672aeb0d14bd2496fdb23c /samples/bpf/sockex2_user.c
parentbpf: allow extended BPF programs access skb fields (diff)
downloadlinux-dev-614cd3bd3758a806cea497d493b584e6157561f7.tar.xz
linux-dev-614cd3bd3758a806cea497d493b584e6157561f7.zip
samples: bpf: add skb->field examples and tests
- modify sockex1 example to count number of bytes in outgoing packets - modify sockex2 example to count number of bytes and packets per flow - add 4 stress tests that exercise 'skb->field' code path of verifier Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf/sockex2_user.c')
-rw-r--r--samples/bpf/sockex2_user.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/samples/bpf/sockex2_user.c b/samples/bpf/sockex2_user.c
index d2d5f5a790d3..29a276d766fc 100644
--- a/samples/bpf/sockex2_user.c
+++ b/samples/bpf/sockex2_user.c
@@ -6,6 +6,11 @@
#include <unistd.h>
#include <arpa/inet.h>
+struct pair {
+ __u64 packets;
+ __u64 bytes;
+};
+
int main(int ac, char **argv)
{
char filename[256];
@@ -29,13 +34,13 @@ int main(int ac, char **argv)
for (i = 0; i < 5; i++) {
int key = 0, next_key;
- long long value;
+ struct pair value;
while (bpf_get_next_key(map_fd[0], &key, &next_key) == 0) {
bpf_lookup_elem(map_fd[0], &next_key, &value);
- printf("ip %s count %lld\n",
+ printf("ip %s bytes %lld packets %lld\n",
inet_ntoa((struct in_addr){htonl(next_key)}),
- value);
+ value.bytes, value.packets);
key = next_key;
}
sleep(1);