]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
samples/bpf: Move open_raw_sock to separate header
authorJoe Stringer <joe@ovn.org>
Fri, 9 Dec 2016 02:46:20 +0000 (18:46 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 20 Dec 2016 15:00:40 +0000 (12:00 -0300)
This function was declared in libbpf.c and was the only remaining
function in this library, but has nothing to do with BPF. Shift it out
into a new header, sock_example.h, and include it from the relevant
samples.

Signed-off-by: Joe Stringer <joe@ovn.org>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20161209024620.31660-8-joe@ovn.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
samples/bpf/Makefile
samples/bpf/fds_example.c
samples/bpf/libbpf.c [deleted file]
samples/bpf/libbpf.h
samples/bpf/sock_example.c
samples/bpf/sock_example.h [new file with mode: 0644]
samples/bpf/sockex1_user.c
samples/bpf/sockex2_user.c
samples/bpf/sockex3_user.c

index 5a73f5a7ace1a054ce7f7dafa5369322031336e5..f01b66f277b0b33e5874b7e3bca4b9d895fced9a 100644 (file)
@@ -36,7 +36,7 @@ hostprogs-y += lwt_len_hist
 hostprogs-y += xdp_tx_iptunnel
 
 # Libbpf dependencies
-LIBBPF := libbpf.o ../../tools/lib/bpf/bpf.o
+LIBBPF := ../../tools/lib/bpf/bpf.o
 
 test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
 sock_example-objs := sock_example.o $(LIBBPF)
index a5cddc99cccdea8165ff567adea7c2fdc31dcc12..e29bd52ff9e85c6dd6a2996bd213567e51e0328e 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "bpf_load.h"
 #include "libbpf.h"
+#include "sock_example.h"
 
 #define BPF_F_PIN      (1 << 0)
 #define BPF_F_GET      (1 << 1)
diff --git a/samples/bpf/libbpf.c b/samples/bpf/libbpf.c
deleted file mode 100644 (file)
index bee473a..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* eBPF mini library */
-#include <stdlib.h>
-#include <stdio.h>
-#include <linux/unistd.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <net/ethernet.h>
-#include <net/if.h>
-#include <linux/if_packet.h>
-#include <arpa/inet.h>
-#include "libbpf.h"
-
-int open_raw_sock(const char *name)
-{
-       struct sockaddr_ll sll;
-       int sock;
-
-       sock = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, htons(ETH_P_ALL));
-       if (sock < 0) {
-               printf("cannot create raw socket\n");
-               return -1;
-       }
-
-       memset(&sll, 0, sizeof(sll));
-       sll.sll_family = AF_PACKET;
-       sll.sll_ifindex = if_nametoindex(name);
-       sll.sll_protocol = htons(ETH_P_ALL);
-       if (bind(sock, (struct sockaddr *)&sll, sizeof(sll)) < 0) {
-               printf("bind to %s: %s\n", name, strerror(errno));
-               close(sock);
-               return -1;
-       }
-
-       return sock;
-}
index 09aedc320009db23e8800145b8518da9b0e5ce77..3705fba453a005fb32f5dfb51dd5763f5f364ccf 100644 (file)
@@ -185,7 +185,4 @@ struct bpf_insn;
                .off   = 0,                                     \
                .imm   = 0 })
 
-/* create RAW socket and bind to interface 'name' */
-int open_raw_sock(const char *name);
-
 #endif
index 5546f8aac37e627a40bd7774e0b9edfb1bc4358e..6fc6e193ef1b12ecbb13f5c7729552306632708b 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/ip.h>
 #include <stddef.h>
 #include "libbpf.h"
+#include "sock_example.h"
 
 char bpf_log_buf[BPF_LOG_BUF_SIZE];
 
diff --git a/samples/bpf/sock_example.h b/samples/bpf/sock_example.h
new file mode 100644 (file)
index 0000000..09f7fe7
--- /dev/null
@@ -0,0 +1,35 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <linux/unistd.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <net/ethernet.h>
+#include <net/if.h>
+#include <linux/if_packet.h>
+#include <arpa/inet.h>
+#include "libbpf.h"
+
+static inline int open_raw_sock(const char *name)
+{
+       struct sockaddr_ll sll;
+       int sock;
+
+       sock = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, htons(ETH_P_ALL));
+       if (sock < 0) {
+               printf("cannot create raw socket\n");
+               return -1;
+       }
+
+       memset(&sll, 0, sizeof(sll));
+       sll.sll_family = AF_PACKET;
+       sll.sll_ifindex = if_nametoindex(name);
+       sll.sll_protocol = htons(ETH_P_ALL);
+       if (bind(sock, (struct sockaddr *)&sll, sizeof(sll)) < 0) {
+               printf("bind to %s: %s\n", name, strerror(errno));
+               close(sock);
+               return -1;
+       }
+
+       return sock;
+}
index 9454448bf198504de53d1883c664a1067385b784..6cd2feb3e9b364aa4ec75c538fe954e581fbd84e 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/bpf.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "sock_example.h"
 #include <unistd.h>
 #include <arpa/inet.h>
 
index 6a40600d5a838952dc0f56e987c32bdad5bb3047..0e0207c9084130c362b600f6b8cd453d2541c4dc 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/bpf.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "sock_example.h"
 #include <unistd.h>
 #include <arpa/inet.h>
 #include <sys/resource.h>
index 9099c4255f23919d6a988ec7982c3e36d6d66de5..b5524d417eb57acd808aa07f4e876191df734166 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/bpf.h>
 #include "libbpf.h"
 #include "bpf_load.h"
+#include "sock_example.h"
 #include <unistd.h>
 #include <arpa/inet.h>
 #include <sys/resource.h>