Skip to contentSkip to conversation

Change sock->sk_protocol to a 16-bit value

RFC PATCH In review Mat Martineau 2 participants 5 messages Jun 21, 2019 – Jun 28, 2019

Subsystems (4)
lore
Share & tools
lore

Mat Martineau

author
#0 lore raw

cover Change sock->sk_protocol to a 16-bit value

While debugging socket state transitions in MPTCP sockets, I found that MPTCP sockets were listing IPPROTO_TCP as their protocol in /sys/kernel/debug/tracing/trace. sock->sk_protocol was only 8 bits wide, truncating the new value of IPPROTO_MPTCP (0x0106) to IPPROTO_TCP (0x06).

The networking code has varying integer widths for 'protocol' at different layers:

* POSIX socket API: 32 bits
* sk_buff->protocol: 16 bits
* IP header (on the wire): 8 bits

MPTCP shows a use for protocol values outside those that fit in an IP header. The change to struct sock fills an 8-bit hole, so there is no change in the size of the structure.

Given that we are currently discussing the appropriate value for IPPROTO_MPTCP, I'm sending this as an RFC to inform those discussions. I had previously thought that the 16-bit value for IPPROTO_MPTCP was compatible with the existing code base.

Mat Martineau (3):
net: Make sock protocol value checks more specific
sock: Make sk_protocol a 16-bit value
net: Add IPPROTO_MPTCP to inet_sock_set_state tracepoint output

 include/net/sock.h          | 5 ++---
 include/trace/events/sock.h | 5 +++--
 net/ax25/af_ax25.c          | 2 +-
 net/decnet/af_decnet.c      | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.22.0
author
#1 lore raw

RFC PATCH 1/3 net: Make sock protocol value checks more specific

SK_PROTOCOL_MAX is only used in two places, for DECNet and AX.25. The limits have more to do with the those protocol definitions than they do with the data type of sk_protocol, so remove SK_PROTOCOL_MAX and use U8_MAX directly.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 include/net/sock.h     | 1 -
 net/ax25/af_ax25.c     | 2 +-
 net/decnet/af_decnet.c | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)
include/net/sock.h +0 -1
index c6a0fc4151bc..fc6308773d18 100644
@@ -459,7 +459,6 @@ struct sock {
 				sk_userlocks : 4,
 				sk_protocol  : 8,
 				sk_type      : 16;
-#define SK_PROTOCOL_MAX U8_MAX
 	u16			sk_gso_max_segs;
 	u8			sk_pacing_shift;
 	unsigned long	        sk_lingertime;
net/ax25/af_ax25.c +1 -1
index ca5207767dc2..d880e941f1a6 100644
@@ -808,7 +808,7 @@ static int ax25_create(struct net *net, struct socket *sock, int protocol,
 	struct sock *sk;
 	ax25_cb *ax25;
 
-	if (protocol < 0 || protocol > SK_PROTOCOL_MAX)
+	if (protocol < 0 || protocol > U8_MAX)
 		return -EINVAL;
 
 	if (!net_eq(net, &init_net))
net/decnet/af_decnet.c +1 -1
index 0ea75286abf4..7c0c769a8b26 100644
@@ -670,7 +670,7 @@ static int dn_create(struct net *net, struct socket *sock, int protocol,
 {
 	struct sock *sk;
 
-	if (protocol < 0 || protocol > SK_PROTOCOL_MAX)
+	if (protocol < 0 || protocol > U8_MAX)
 		return -EINVAL;
 
 	if (!net_eq(net, &init_net))
Signature · 1 line
2.22.0
author
#2 lore raw

RFC PATCH 2/3 sock: Make sk_protocol a 16-bit value

In reply to Mat Martineau

Match the 16-bit width of skbuff->protocol. Fills an 8-bit hole so sizeof(struct sock) does not change.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 include/net/sock.h          | 4 ++--
 include/trace/events/sock.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/sock.h +2 -2
index fc6308773d18..2af5b8547b39 100644
@@ -457,10 +457,10 @@ struct sock {
 				sk_no_check_tx : 1,
 				sk_no_check_rx : 1,
 				sk_userlocks : 4,
-				sk_protocol  : 8,
+				sk_pacing_shift : 8,
 				sk_type      : 16;
+	u16			sk_protocol;
 	u16			sk_gso_max_segs;
-	u8			sk_pacing_shift;
 	unsigned long	        sk_lingertime;
 	struct proto		*sk_prot_creator;
 	rwlock_t		sk_callback_lock;
include/trace/events/sock.h +1 -1
index a0c4b8a30966..dc749c651318 100644
@@ -147,7 +147,7 @@ TRACE_EVENT(inet_sock_set_state,
 		__field(__u16, sport)
 		__field(__u16, dport)
 		__field(__u16, family)
-		__field(__u8, protocol)
+		__field(__u16, protocol)
 		__array(__u8, saddr, 4)
 		__array(__u8, daddr, 4)
 		__array(__u8, saddr_v6, 16)
Signature · 1 line
2.22.0
author
#3 lore raw

RFC PATCH 3/3 net: Add IPPROTO_MPTCP to inet_sock_set_state tracepoint output

In reply to Mat Martineau

Add MPTCP to the list of protocols that socket state change tracepoints can output in symbolic form.

Signed-off-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>
---
 include/trace/events/sock.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/trace/events/sock.h +2 -1
index dc749c651318..bfbcba315a12 100644
@@ -19,7 +19,8 @@
 #define inet_protocol_names		\
 		EM(IPPROTO_TCP)			\
 		EM(IPPROTO_DCCP)		\
-		EMe(IPPROTO_SCTP)
+		EM(IPPROTO_SCTP)		\
+		EMe(IPPROTO_MPTCP)
 
 #define tcp_state_names			\
 		EM(TCP_ESTABLISHED)		\
Signature · 1 line
2.22.0
#4 lore raw
In reply to Mat Martineau

Hi Mat,

Quoted 22 lines · Mat Martineau

While debugging socket state transitions in MPTCP sockets, I found that MPTCP sockets were listing IPPROTO_TCP as their protocol in /sys/kernel/debug/tracing/trace. sock->sk_protocol was only 8 bits wide, truncating the new value of IPPROTO_MPTCP (0x0106) to IPPROTO_TCP (0x06).

The networking code has varying integer widths for 'protocol' at different layers:

* POSIX socket API: 32 bits
* sk_buff->protocol: 16 bits
* IP header (on the wire): 8 bits

MPTCP shows a use for protocol values outside those that fit in an IP header. The change to struct sock fills an 8-bit hole, so there is no change in the size of the structure.

Given that we are currently discussing the appropriate value for IPPROTO_MPTCP, I'm sending this as an RFC to inform those discussions. I had previously thought that the 16-bit value for IPPROTO_MPTCP was compatible with the existing code base.

Quoted 4 lines

Mat Martineau (3):
net: Make sock protocol value checks more specific
sock: Make sk_protocol a 16-bit value
net: Add IPPROTO_MPTCP to inet_sock_set_state tracepoint output

Thank you for the patches!

As discussed yesterday, we said it is OK to add them in our repo and wait for feedback from maintainers later.

I added the 2 firsts ones just before "tcp: Define IPPROTO_MPTCP" and "squashed" the last one in "tcp: Define IPPROTO_MPTCP", see a4ed239bad09. The result is visible there: 7312e2219900..78d9680a7731

I hope it is what you had in mind, I can of course change that later if needed.

Tests are still OK!

Cheers,
Matt

Signature · 5 lines
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium