net: introduce SO_BPF_EXTENSIONS
authorMichal Sekletar <msekleta@redhat.com>
Fri, 17 Jan 2014 16:09:45 +0000 (17:09 +0100)
committerDavid S. Miller <davem@davemloft.net>
Sun, 19 Jan 2014 03:08:58 +0000 (19:08 -0800)
For user space packet capturing libraries such as libpcap, there's
currently only one way to check which BPF extensions are supported
by the kernel, that is, commit aa1113d9f85d ("net: filter: return
-EINVAL if BPF_S_ANC* operation is not supported"). For querying all
extensions at once this might be rather inconvenient.

Therefore, this patch introduces a new option which can be used as
an argument for getsockopt(), and allows one to obtain information
about which BPF extensions are supported by the current kernel.

As David Miller suggests, we do not need to define any bits right
now and status quo can just return 0 in order to state that this
versions supports SKF_AD_PROTOCOL up to SKF_AD_PAY_OFFSET. Later
additions to BPF extensions need to add their bits to the
bpf_tell_extensions() function, as documented in the comment.

Signed-off-by: Michal Sekletar <msekleta@redhat.com>
Cc: David Miller <davem@davemloft.net>
Reviewed-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
16 files changed:
arch/alpha/include/uapi/asm/socket.h
arch/avr32/include/uapi/asm/socket.h
arch/cris/include/uapi/asm/socket.h
arch/frv/include/uapi/asm/socket.h
arch/ia64/include/uapi/asm/socket.h
arch/m32r/include/uapi/asm/socket.h
arch/mips/include/uapi/asm/socket.h
arch/mn10300/include/uapi/asm/socket.h
arch/parisc/include/uapi/asm/socket.h
arch/powerpc/include/uapi/asm/socket.h
arch/s390/include/uapi/asm/socket.h
arch/sparc/include/uapi/asm/socket.h
arch/xtensa/include/uapi/asm/socket.h
include/linux/filter.h
include/uapi/asm-generic/socket.h
net/core/sock.c

index e3a1491d5073a0b59a6b9eb207c4a684ae6c9495..3de1394bcab821984674e89a3ee022cc6dd5f0f2 100644 (file)
@@ -85,4 +85,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _UAPI_ASM_SOCKET_H */
index cbf902e4cd9e9ef1528e48a24f3d56c3fc2d889d..6e6cd159924b1855aa5f1811ad4e4c60b403c431 100644 (file)
@@ -78,4 +78,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _UAPI__ASM_AVR32_SOCKET_H */
index 13829aaaeec565b8e53726e95fcf4e7fde638c25..ed94e5ed0a238c2750e677ccb806a6bc0a94041a 100644 (file)
@@ -80,6 +80,8 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_SOCKET_H */
 
 
index 5d4299762426b108057a33faf71b85efdfe4f74b..ca2c6e6f31c6817780d31a246652adcc9847e373 100644 (file)
@@ -78,5 +78,7 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_SOCKET_H */
 
index c25302fb48d95636b59670efa423a59ff2d055c0..a1b49bac7951929127ed08db549218c2c16ccf89 100644 (file)
@@ -87,4 +87,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_IA64_SOCKET_H */
index 52966650114f3198df49c109c02d70ae82d8adcb..6c9a24b3aefa3a4f3048c17a7fa06d97b585ec14 100644 (file)
@@ -78,4 +78,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_M32R_SOCKET_H */
index 0df9787cd84d9e4a93e04513f1654b0327b3df0f..a14baa218c76f14de988ef106bdac5dadc48aceb 100644 (file)
@@ -96,4 +96,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _UAPI_ASM_SOCKET_H */
index 71dedcae55a69c4ea93c5c71c7edfd93583864a9..6aa3ce1854aa9523d46bc28851eddabd59edeb37 100644 (file)
@@ -78,4 +78,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_SOCKET_H */
index 70b3674dac4e39c1048b1844dc53dee85f907296..fe35ceacf0e72cad69a43d9b1ce7b8f5ec3da98a 100644 (file)
@@ -77,4 +77,6 @@
 
 #define SO_MAX_PACING_RATE     0x4028
 
+#define SO_BPF_EXTENSIONS      0x4029
+
 #endif /* _UAPI_ASM_SOCKET_H */
index fa698324a1fd13e50ec0d5e01d526b5a00a2b0b8..a9c3e2e18c054a1e952fe33599401de57c6a6544 100644 (file)
@@ -85,4 +85,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_POWERPC_SOCKET_H */
index c286c2e868f03f9683481b82689af19f1a222e2d..e031332096d7c7b23b5953680289e8f3bcc3b378 100644 (file)
@@ -84,4 +84,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _ASM_SOCKET_H */
index 0f21e9a5ca18879f5d919aa0fa05532204244eba..54d9608681b6947ae25dab008f808841d96125c0 100644 (file)
@@ -74,6 +74,8 @@
 
 #define SO_MAX_PACING_RATE     0x0031
 
+#define SO_BPF_EXTENSIONS      0x0032
+
 /* Security levels - as per NRL IPv6 - don't actually do anything */
 #define SO_SECURITY_AUTHENTICATION             0x5001
 #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
index 7db5c22faa68a1803cad4708d9047ad8396b637e..39acec0cf0b1d500c1c40f9b523ef3a9a142c2f1 100644 (file)
@@ -89,4 +89,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* _XTENSA_SOCKET_H */
index ff4e40cd45b1dcb15c66f1e178b655df7c40c0eb..1a95a2dcf113a9a61a479b99abd564ac617ef413 100644 (file)
@@ -83,6 +83,17 @@ static inline void bpf_jit_free(struct sk_filter *fp)
 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns)
 #endif
 
+static inline int bpf_tell_extensions(void)
+{
+       /* When adding new BPF extension it is necessary to enumerate
+        * it here, so userspace software which wants to know what is
+        * supported can do so by inspecting return value of this
+        * function
+        */
+
+       return 0;
+}
+
 enum {
        BPF_S_RET_K = 1,
        BPF_S_RET_A,
index 38f14d0264c3aa78f3b62b93cba405c655e23ae6..ea0796bdcf88404ef0f127eb6e64ba00c16ea856 100644 (file)
@@ -80,4 +80,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_BPF_EXTENSIONS      48
+
 #endif /* __ASM_GENERIC_SOCKET_H */
index b3f7ee3008a0d0e055c108689f7efee489372226..0c127dcdf6a8ba9d25d544b02bf798d25fd67f6e 100644 (file)
@@ -1167,6 +1167,10 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
                v.val = sock_flag(sk, SOCK_FILTER_LOCKED);
                break;
 
+       case SO_BPF_EXTENSIONS:
+               v.val = bpf_tell_extensions();
+               break;
+
        case SO_SELECT_ERR_QUEUE:
                v.val = sock_flag(sk, SOCK_SELECT_ERR_QUEUE);
                break;
This page took 0.053311 seconds and 5 git commands to generate.