Skip to content

Commit

Permalink
net: introduce SO_BPF_EXTENSIONS
Browse files Browse the repository at this point in the history
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 aa1113d ("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 <[email protected]>
Cc: David Miller <[email protected]>
Reviewed-by: Daniel Borkmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
msekletar authored and davem330 committed Jan 19, 2014
1 parent 4180442 commit ea02f94
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/alpha/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/avr32/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _UAPI__ASM_AVR32_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/cris/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_SOCKET_H */


2 changes: 2 additions & 0 deletions arch/frv/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_SOCKET_H */

2 changes: 2 additions & 0 deletions arch/ia64/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_IA64_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/m32r/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_M32R_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/mips/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/mn10300/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/parisc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@

#define SO_MAX_PACING_RATE 0x4028

#define SO_BPF_EXTENSIONS 0x4029

#endif /* _UAPI_ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/powerpc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_POWERPC_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/s390/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _ASM_SOCKET_H */
2 changes: 2 additions & 0 deletions arch/sparc/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions arch/xtensa/include/uapi/asm/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* _XTENSA_SOCKET_H */
11 changes: 11 additions & 0 deletions include/linux/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions include/uapi/asm-generic/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@

#define SO_MAX_PACING_RATE 47

#define SO_BPF_EXTENSIONS 48

#endif /* __ASM_GENERIC_SOCKET_H */
4 changes: 4 additions & 0 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ea02f94

Please sign in to comment.