summaryrefslogtreecommitdiffstats
path: root/samples/bpf/xdp1_kern.c
diff options
context:
space:
mode:
authorToke Høiland-Jørgensen <toke@redhat.com>2023-08-24 12:22:47 +0200
committerAlexei Starovoitov <ast@kernel.org>2023-08-24 17:43:50 +0200
commiteaca21d6eee9bb9b9f53c1c187d488ff1cbb6168 (patch)
treea3960c2954b9c0f6fa2251cb06f65a034b71d136 /samples/bpf/xdp1_kern.c
parentsamples/bpf: Remove the xdp_rxq_info utility (diff)
downloadlinux-eaca21d6eee9bb9b9f53c1c187d488ff1cbb6168.tar.xz
linux-eaca21d6eee9bb9b9f53c1c187d488ff1cbb6168.zip
samples/bpf: Remove the xdp1 and xdp2 utilities
The functionality of these utilities have been incorporated into the xdp-bench utility in xdp-tools. Equivalent functionality is: xdp1 eth0 --> xdp-bench drop -p parse-ip -l load-bytes eth0 xdp2 eth0 --> xdp-bench drop -p swap-macs eth0 Note that there's a slight difference in behaviour of those examples: the swap-macs operation of xdp-bench doesn't use the bpf_xdp_load_bytes() helper to load the packet data, whereas the xdp2 utility did so unconditionally. For the parse-ip action the use of bpf_xdp_load_bytes() can be selected by the '-l load-bytes' switch, with the difference that the xdp-bench utility will perform two separate calls to the helper, one to load the ethernet header and another to load the IP header; where the xdp1 utility only performed one call always loading 60 bytes of data. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://lore.kernel.org/r/20230824102255.1561885-5-toke@redhat.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf/xdp1_kern.c')
-rw-r--r--samples/bpf/xdp1_kern.c100
1 files changed, 0 insertions, 100 deletions
diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
deleted file mode 100644
index d91f27cbcfa9..000000000000
--- a/samples/bpf/xdp1_kern.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Copyright (c) 2016 PLUMgrid
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- */
-#define KBUILD_MODNAME "foo"
-#include <uapi/linux/bpf.h>
-#include <linux/in.h>
-#include <linux/if_ether.h>
-#include <linux/if_packet.h>
-#include <linux/if_vlan.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
-#include <bpf/bpf_helpers.h>
-
-struct {
- __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
- __type(key, u32);
- __type(value, long);
- __uint(max_entries, 256);
-} rxcnt SEC(".maps");
-
-static int parse_ipv4(void *data, u64 nh_off, void *data_end)
-{
- struct iphdr *iph = data + nh_off;
-
- if (iph + 1 > data_end)
- return 0;
- return iph->protocol;
-}
-
-static int parse_ipv6(void *data, u64 nh_off, void *data_end)
-{
- struct ipv6hdr *ip6h = data + nh_off;
-
- if (ip6h + 1 > data_end)
- return 0;
- return ip6h->nexthdr;
-}
-
-#define XDPBUFSIZE 60
-SEC("xdp.frags")
-int xdp_prog1(struct xdp_md *ctx)
-{
- __u8 pkt[XDPBUFSIZE] = {};
- void *data_end = &pkt[XDPBUFSIZE-1];
- void *data = pkt;
- struct ethhdr *eth = data;
- int rc = XDP_DROP;
- long *value;
- u16 h_proto;
- u64 nh_off;
- u32 ipproto;
-
- if (bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt)))
- return rc;
-
- nh_off = sizeof(*eth);
- if (data + nh_off > data_end)
- return rc;
-
- h_proto = eth->h_proto;
-
- /* Handle VLAN tagged packet */
- if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
- struct vlan_hdr *vhdr;
-
- vhdr = data + nh_off;
- nh_off += sizeof(struct vlan_hdr);
- if (data + nh_off > data_end)
- return rc;
- h_proto = vhdr->h_vlan_encapsulated_proto;
- }
- /* Handle double VLAN tagged packet */
- if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
- struct vlan_hdr *vhdr;
-
- vhdr = data + nh_off;
- nh_off += sizeof(struct vlan_hdr);
- if (data + nh_off > data_end)
- return rc;
- h_proto = vhdr->h_vlan_encapsulated_proto;
- }
-
- if (h_proto == htons(ETH_P_IP))
- ipproto = parse_ipv4(data, nh_off, data_end);
- else if (h_proto == htons(ETH_P_IPV6))
- ipproto = parse_ipv6(data, nh_off, data_end);
- else
- ipproto = 0;
-
- value = bpf_map_lookup_elem(&rxcnt, &ipproto);
- if (value)
- *value += 1;
-
- return rc;
-}
-
-char _license[] SEC("license") = "GPL";