Skip to contentSkip to conversation

net: add inet/inet6 rand_socket sctp support

PATCH In review Hangbin Liu 2 participants 2 messages Aug 1, 2014 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: add inet/inet6 rand_socket sctp support

---
 net/proto-ipv4.c | 30 +++++++++++++++++++++++-------
 net/proto-ipv6.c | 31 +++++++++++++++++++++++++------
 2 files changed, 48 insertions(+), 13 deletions(-)
net/proto-ipv4.c +23 -7
index 8babe6d..3e24b54 100644
@@ -97,13 +97,21 @@ 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
-		if (rand_bool())
+	switch (rand() % 4) {
+	case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+		switch (rand() % 3) {
+		case 0:
 			st->protocol = 0;
-		else
+			break;
+		case 1:
 			st->protocol = IPPROTO_TCP;
-		break;
+			break;
+		case 2:
+			st->protocol = IPPROTO_SCTP;
+			break;
+		default:
+			break;
+		}
 
 	case 1: st->type = SOCK_DGRAM;      // UDP
 		if (rand_bool())
@@ -112,11 +120,19 @@ void inet_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;
 
-	default:break;
+	default:
+		break;
 	}
 }
 
net/proto-ipv6.c +25 -6
index 16bceb3..02bb373 100644
@@ -29,10 +29,21 @@ 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,11 +52,19 @@ 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;
 
-	default:break;
+	default:
+		break;
 	}
 }
 
Signature · 1 line
1.9.3
Acked-by on v2 1/1
#1 lore raw
Quoted 1 line · Hangbin Liu

Thanks!

Quoted 111 lines
---
  net/proto-ipv4.c | 30 +++++++++++++++++++++++-------
  net/proto-ipv6.c | 31 +++++++++++++++++++++++++------
  2 files changed, 48 insertions(+), 13 deletions(-)
net/proto-ipv4.c +23 -7
index 8babe6d..3e24b54 100644
@@ -97,13 +97,21 @@ 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
-		if (rand_bool())
+	switch (rand() % 4) {
+	case 0: st->type = SOCK_STREAM;     // TCP/SCTP
+		switch (rand() % 3) {
+		case 0:
  			st->protocol = 0;
-		else
+			break;
+		case 1:
  			st->protocol = IPPROTO_TCP;
-		break;
+			break;
+		case 2:
+			st->protocol = IPPROTO_SCTP;
+			break;
+		default:
+			break;
+		}
 
  	case 1: st->type = SOCK_DGRAM;      // UDP
  		if (rand_bool())
@@ -112,11 +120,19 @@ void inet_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;
 
-	default:break;
+	default:
+		break;
  	}
  }
 
net/proto-ipv6.c +25 -6
index 16bceb3..02bb373 100644
@@ -29,10 +29,21 @@ 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,11 +52,19 @@ 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;
 
-	default:break;
+	default:
+		break;
  	}
  }