Skip to contentSkip to conversation

net: add ipv4/ipv6 sctp support

PATCH In review Hangbin Liu 2 participants 3 messages Jul 25, 2014 – Jul 26, 2014 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: add ipv4/ipv6 sctp support

---
 net/proto-ipv4.c | 20 ++++++++++++++------
 net/proto-ipv6.c | 21 ++++++++++++++++-----
 2 files changed, 30 insertions(+), 11 deletions(-)
net/proto-ipv4.c +14 -6
index 8babe6d..5588518 100644
@@ -97,22 +97,30 @@ void ipv4_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
 
 void inet_rand_socket(struct socket_triplet *st)
 {
-	switch (rand() % 3) {
-	case 0: st->type = SOCK_STREAM;     // TCP
+	switch (rand() % 4) {
+	case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+		switch (rand() % 3) {
+		case 0: st->protocol = 0; break;
+		case 1: st->protocol = IPPROTO_TCP; break;
+		case 2: st->protocol = IPPROTO_SCTP; break;
+		default:break;
+		}
+
+	case 1: st->type = SOCK_DGRAM;      // UDP
 		if (rand_bool())
 			st->protocol = 0;
 		else
-			st->protocol = IPPROTO_TCP;
+			st->protocol = IPPROTO_UDP;
 		break;
 
-	case 1: st->type = SOCK_DGRAM;      // UDP
+	case 2: st->type = SOCK_SEQPACKET;      // SCTP
 		if (rand_bool())
 			st->protocol = 0;
 		else
-			st->protocol = IPPROTO_UDP;
+			st->protocol = IPPROTO_SCTP;
 		break;
 
-	case 2: st->type = SOCK_RAW;
+	case 3: st->type = SOCK_RAW;
 		st->protocol = rand() % PROTO_MAX;
 		break;
 
net/proto-ipv6.c +16 -5
index 16bceb3..d094939 100644
@@ -29,10 +29,14 @@ void ipv6_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
 
 void inet6_rand_socket(struct socket_triplet *st)
 {
-	switch (rand() % 3) {
-	case 0: st->type = SOCK_STREAM;     // TCP
-		st->protocol = 0;
-		break;
+	switch (rand() % 4) {
+	case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+		switch (rand() % 3) {
+		case 0: st->protocol = 0; break;
+		case 1: st->protocol = IPPROTO_TCP; break;
+		case 2: st->protocol = IPPROTO_SCTP; break;
+		default:break;
+		}
 
 	case 1: st->type = SOCK_DGRAM;      // UDP
 		if (rand_bool())
@@ -41,7 +45,14 @@ void inet6_rand_socket(struct socket_triplet *st)
 			st->protocol = IPPROTO_UDP;
 		break;
 
-	case 2: st->type = SOCK_RAW;
+	case 2: st->type = SOCK_SEQPACKET;      // SCTP
+		if (rand_bool())
+			st->protocol = 0;
+		else
+			st->protocol = IPPROTO_SCTP;
+		break;
+
+	case 3: st->type = SOCK_RAW;
 		st->protocol = rand() % PROTO_MAX;
 		break;
 
Signature · 1 line
1.9.3
#1 lore raw

Hi Hangbin,

Quoted 14 lines · Hangbin Liu
---
  net/proto-ipv4.c | 20 ++++++++++++++------
  net/proto-ipv6.c | 21 ++++++++++++++++-----
  2 files changed, 30 insertions(+), 11 deletions(-)
net/proto-ipv4.c +0 -0
index 8babe6d..5588518 100644
@@ -97,22 +97,30 @@ void ipv4_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
 
  void inet_rand_socket(struct socket_triplet *st)
  {

net/proto-ipv4.c void ipv4_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) · line 107

Quoted 10 lines
net/proto-ipv4.c +8 -2
-	switch (rand() % 3) {
-	case 0: st->type = SOCK_STREAM;     // TCP
+	switch (rand() % 4) {
+	case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+		switch (rand() % 3) {
+		case 0: st->protocol = 0; break;
+		case 1: st->protocol = IPPROTO_TCP; break;
+		case 2: st->protocol = IPPROTO_SCTP; break;
+		default:break;
+		}

I think it would be good for readability reasons to use the kernel coding style convention, but I'm not sure what Dave's preference is as the style is also present elsewhere.

Other than that, the patch looks good to me, thanks a lot Hangbin!

Daniel

Quoted 62 lines
net/proto-ipv4.c +5 -4
+	case 1: st->type = SOCK_DGRAM;      // UDP
  		if (rand_bool())
  			st->protocol = 0;
  		else
-			st->protocol = IPPROTO_TCP;
+			st->protocol = IPPROTO_UDP;
  		break;
 
-	case 1: st->type = SOCK_DGRAM;      // UDP
+	case 2: st->type = SOCK_SEQPACKET;      // SCTP
  		if (rand_bool())
  			st->protocol = 0;
  		else
-			st->protocol = IPPROTO_UDP;
+			st->protocol = IPPROTO_SCTP;
  		break;
 
-	case 2: st->type = SOCK_RAW;
+	case 3: st->type = SOCK_RAW;
  		st->protocol = rand() % PROTO_MAX;
  		break;
 
net/proto-ipv6.c +16 -5
index 16bceb3..d094939 100644
@@ -29,10 +29,14 @@ void ipv6_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen)
 
  void inet6_rand_socket(struct socket_triplet *st)
  {
-	switch (rand() % 3) {
-	case 0: st->type = SOCK_STREAM;     // TCP
-		st->protocol = 0;
-		break;
+	switch (rand() % 4) {
+	case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+		switch (rand() % 3) {
+		case 0: st->protocol = 0; break;
+		case 1: st->protocol = IPPROTO_TCP; break;
+		case 2: st->protocol = IPPROTO_SCTP; break;
+		default:break;
+		}
 
  	case 1: st->type = SOCK_DGRAM;      // UDP
  		if (rand_bool())
@@ -41,7 +45,14 @@ void inet6_rand_socket(struct socket_triplet *st)
  			st->protocol = IPPROTO_UDP;
  		break;
 
-	case 2: st->type = SOCK_RAW;
+	case 2: st->type = SOCK_SEQPACKET;      // SCTP
+		if (rand_bool())
+			st->protocol = 0;
+		else
+			st->protocol = IPPROTO_SCTP;
+		break;
+
+	case 3: st->type = SOCK_RAW;
  		st->protocol = rand() % PROTO_MAX;
  		break;
 
#2 lore raw

2014-07-25 18:13 GMT+08:00 Daniel Borkmann <[email protected]>:

Quoted 27 lines

Hi Hangbin,

Quoted 23 lines · Hangbin Liu
---
  net/proto-ipv4.c | 20 ++++++++++++++------
  net/proto-ipv6.c | 21 ++++++++++++++++-----
  2 files changed, 30 insertions(+), 11 deletions(-)
net/proto-ipv4.c +5 -2
index 8babe6d..5588518 100644
@@ -97,22 +97,30 @@ void ipv4_gen_sockaddr(struct sockaddr **addr,
 socklen_t *addrlen)
 
  void inet_rand_socket(struct socket_triplet *st)
  {
-       switch (rand() % 3) {
-       case 0: st->type = SOCK_STREAM;     // TCP
+       switch (rand() % 4) {
+       case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+               switch (rand() % 3) {
+               case 0: st->protocol = 0; break;
+               case 1: st->protocol = IPPROTO_TCP; break;
Quoted 8 lines

net/proto-ipv4.c void ipv4_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) · line 107

Quoted 3 lines
net/proto-ipv4.c +3 -0
+               case 2: st->protocol = IPPROTO_SCTP; break;
+               default:break;
+               }

I think it would be good for readability reasons to use the kernel coding style convention, but I'm not sure what Dave's preference is as the style is also present elsewhere.

I'm OK to change the code style, wait for Dave's response.

Thanks
Hangbin Liu