Browse code

sctp rpc: core.sctp_options debugging version

core.sctp_options can now have 1 optional parameter. If the
parameter is missing it works as before: displays ser's idea of
all the sctp config options. If the parameter is present it should
have one of the following values: "default" (default send socket),
"first" (first sctp socket) or addr[:port]. In this case the
kernel sctp options for that particular socket will be displayed,
with 0 used for the options that are userspace only.
E.g.: sercmd core.sctp_options 127.0.0.1

Andrei Pelinescu-Onciul authored on 12/11/2009 15:29:40
Showing 1 changed files
... ...
@@ -647,7 +647,13 @@ static void core_tcp_options(rpc_t* rpc, void* c)
647 647
 
648 648
 
649 649
 static const char* core_sctp_options_doc[] = {
650
-	"Returns active sctp options.",    /* Documentation string */
650
+	"Returns active sctp options. With one parameter"
651
+	" it returns the sctp options set in the kernel for a specific socket"
652
+	"(debugging), with 0 filled in for non-kernel related options."
653
+	" The parameter can be: \"default\" | \"first\" | address[:port] ."
654
+	" With no parameters it returns ser's idea of the current sctp options"
655
+	 " (intended non-debugging use).",
656
+	/* Documentation string */
651 657
 	0                                 /* Method signature(s) */
652 658
 };
653 659
 
... ...
@@ -656,9 +662,54 @@ static void core_sctp_options(rpc_t* rpc, void* c)
656 662
 #ifdef USE_SCTP
657 663
 	void *handle;
658 664
 	struct cfg_group_sctp t;
659
-
665
+	char* param;
666
+	struct socket_info* si;
667
+	char* host;
668
+	str hs;
669
+	int hlen;
670
+	int port;
671
+	int proto;
672
+
673
+	param=0;
660 674
 	if (!sctp_disable){
661
-		sctp_options_get(&t);
675
+		/* look for optional socket parameter */
676
+		if (rpc->scan(c, "*s", &param)>0){
677
+			si=0;
678
+			if (strcasecmp(param, "default")==0){
679
+				si=sendipv4_sctp?sendipv4_sctp:sendipv6_sctp;
680
+			}else if (strcasecmp(param, "first")==0){
681
+				si=sctp_listen;
682
+			}else{
683
+				if (parse_phostport(param, &host, &hlen, &port, &proto)!=0){
684
+					rpc->fault(c, 500, "bad param (use address, address:port,"
685
+										" default or first)");
686
+					return;
687
+				}
688
+				if (proto && proto!=PROTO_SCTP){
689
+					rpc->fault(c, 500, "bad protocol in param (only SCTP"
690
+										" allowed)");
691
+					return;
692
+				}
693
+				hs.s=host;
694
+				hs.len=hlen;
695
+				si=grep_sock_info(&hs, port, PROTO_SCTP);
696
+				if (si==0){
697
+					rpc->fault(c, 500, "not listening on sctp %s", param);
698
+					return;
699
+				}
700
+			}
701
+			if (si==0 || si->socket==-1){
702
+				rpc->fault(c, 500, "could not find a sctp socket");
703
+				return;
704
+			}
705
+			memset(&t, 0, sizeof(t));
706
+			if (sctp_get_cfg_from_sock(si->socket, &t)!=0){
707
+				rpc->fault(c, 500, "failed to get socket options");
708
+				return;
709
+			}
710
+		}else{
711
+			sctp_options_get(&t);
712
+		}
662 713
 		rpc->add(c, "{", &handle);
663 714
 		rpc->struct_add(handle, "ddddddddddddddddddd",
664 715
 			"sctp_socket_rcvbuf",	t.so_rcvbuf,