Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: introduce SO_BPF_EXTENSIONS

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>

authored by

Michal Sekletar and committed by
David S. Miller
ea02f941 41804420

+43
+2
arch/alpha/include/uapi/asm/socket.h
··· 85 85 86 86 #define SO_MAX_PACING_RATE 47 87 87 88 + #define SO_BPF_EXTENSIONS 48 89 + 88 90 #endif /* _UAPI_ASM_SOCKET_H */
+2
arch/avr32/include/uapi/asm/socket.h
··· 78 78 79 79 #define SO_MAX_PACING_RATE 47 80 80 81 + #define SO_BPF_EXTENSIONS 48 82 + 81 83 #endif /* _UAPI__ASM_AVR32_SOCKET_H */
+2
arch/cris/include/uapi/asm/socket.h
··· 80 80 81 81 #define SO_MAX_PACING_RATE 47 82 82 83 + #define SO_BPF_EXTENSIONS 48 84 + 83 85 #endif /* _ASM_SOCKET_H */ 84 86 85 87
+2
arch/frv/include/uapi/asm/socket.h
··· 78 78 79 79 #define SO_MAX_PACING_RATE 47 80 80 81 + #define SO_BPF_EXTENSIONS 48 82 + 81 83 #endif /* _ASM_SOCKET_H */ 82 84
+2
arch/ia64/include/uapi/asm/socket.h
··· 87 87 88 88 #define SO_MAX_PACING_RATE 47 89 89 90 + #define SO_BPF_EXTENSIONS 48 91 + 90 92 #endif /* _ASM_IA64_SOCKET_H */
+2
arch/m32r/include/uapi/asm/socket.h
··· 78 78 79 79 #define SO_MAX_PACING_RATE 47 80 80 81 + #define SO_BPF_EXTENSIONS 48 82 + 81 83 #endif /* _ASM_M32R_SOCKET_H */
+2
arch/mips/include/uapi/asm/socket.h
··· 96 96 97 97 #define SO_MAX_PACING_RATE 47 98 98 99 + #define SO_BPF_EXTENSIONS 48 100 + 99 101 #endif /* _UAPI_ASM_SOCKET_H */
+2
arch/mn10300/include/uapi/asm/socket.h
··· 78 78 79 79 #define SO_MAX_PACING_RATE 47 80 80 81 + #define SO_BPF_EXTENSIONS 48 82 + 81 83 #endif /* _ASM_SOCKET_H */
+2
arch/parisc/include/uapi/asm/socket.h
··· 77 77 78 78 #define SO_MAX_PACING_RATE 0x4028 79 79 80 + #define SO_BPF_EXTENSIONS 0x4029 81 + 80 82 #endif /* _UAPI_ASM_SOCKET_H */
+2
arch/powerpc/include/uapi/asm/socket.h
··· 85 85 86 86 #define SO_MAX_PACING_RATE 47 87 87 88 + #define SO_BPF_EXTENSIONS 48 89 + 88 90 #endif /* _ASM_POWERPC_SOCKET_H */
+2
arch/s390/include/uapi/asm/socket.h
··· 84 84 85 85 #define SO_MAX_PACING_RATE 47 86 86 87 + #define SO_BPF_EXTENSIONS 48 88 + 87 89 #endif /* _ASM_SOCKET_H */
+2
arch/sparc/include/uapi/asm/socket.h
··· 74 74 75 75 #define SO_MAX_PACING_RATE 0x0031 76 76 77 + #define SO_BPF_EXTENSIONS 0x0032 78 + 77 79 /* Security levels - as per NRL IPv6 - don't actually do anything */ 78 80 #define SO_SECURITY_AUTHENTICATION 0x5001 79 81 #define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002
+2
arch/xtensa/include/uapi/asm/socket.h
··· 89 89 90 90 #define SO_MAX_PACING_RATE 47 91 91 92 + #define SO_BPF_EXTENSIONS 48 93 + 92 94 #endif /* _XTENSA_SOCKET_H */
+11
include/linux/filter.h
··· 83 83 #define SK_RUN_FILTER(FILTER, SKB) sk_run_filter(SKB, FILTER->insns) 84 84 #endif 85 85 86 + static inline int bpf_tell_extensions(void) 87 + { 88 + /* When adding new BPF extension it is necessary to enumerate 89 + * it here, so userspace software which wants to know what is 90 + * supported can do so by inspecting return value of this 91 + * function 92 + */ 93 + 94 + return 0; 95 + } 96 + 86 97 enum { 87 98 BPF_S_RET_K = 1, 88 99 BPF_S_RET_A,
+2
include/uapi/asm-generic/socket.h
··· 80 80 81 81 #define SO_MAX_PACING_RATE 47 82 82 83 + #define SO_BPF_EXTENSIONS 48 84 + 83 85 #endif /* __ASM_GENERIC_SOCKET_H */
+4
net/core/sock.c
··· 1167 1167 v.val = sock_flag(sk, SOCK_FILTER_LOCKED); 1168 1168 break; 1169 1169 1170 + case SO_BPF_EXTENSIONS: 1171 + v.val = bpf_tell_extensions(); 1172 + break; 1173 + 1170 1174 case SO_SELECT_ERR_QUEUE: 1171 1175 v.val = sock_flag(sk, SOCK_SELECT_ERR_QUEUE); 1172 1176 break;