Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Introduced a mechanism to use hierarchical command system on on a vir…

…tual terminal for shisa.
  • Loading branch information...
commit c2fdd46ee12411fae6b672e415086d4e2f8a7698 1 parent 2429372
authored February 12, 2005
71  kame/kame/shisad/binding.c
... ...
@@ -1,4 +1,4 @@
1  
-/*      $KAME: binding.c,v 1.5 2005/01/26 07:41:59 t-momose Exp $	*/
  1
+/*      $KAME: binding.c,v 1.6 2005/02/12 15:22:38 t-momose Exp $	*/
2 2
 /*
3 3
  * Copyright (C) 2004 WIDE Project.  All rights reserved.
4 4
  *
@@ -57,8 +57,8 @@
57 57
 
58 58
 #include "callout.h"
59 59
 #include "shisad.h"
60  
-#include "fsm.h"
61 60
 #include "stat.h"
  61
+#include "command.h"
62 62
 
63 63
 #ifdef MIP_MN
64 64
 void bul_flush(struct mip6_hoainfo *);
@@ -232,19 +232,19 @@ mip6_bc_lookup(hoa, src, bid)
232 232
 };
233 233
 
234 234
 void
235  
-command_show_bc(s)
  235
+command_show_bc(s, line)
236 236
 	int s;
  237
+	char *line;
237 238
 {
238 239
 	time_t now;
239  
-	char buff[2048];
240 240
 	struct binding_cache *bc;
241 241
 
242 242
 	now = time(NULL);
243 243
         for (bc = LIST_FIRST(&bchead); bc; bc = LIST_NEXT(bc, bc_entry)) {
244  
-		sprintf(buff, "%s ", ip6_sprintf(&bc->bc_hoa));
245  
-		sprintf(buff + strlen(buff), "%s ", ip6_sprintf(&bc->bc_coa));
246  
-		sprintf(buff + strlen(buff), "%s ", ip6_sprintf(&bc->bc_myaddr));
247  
-		sprintf(buff + strlen(buff), "%d/%d %c%c%c%c %d\n",
  244
+		command_printf(s, "%s ", ip6_sprintf(&bc->bc_hoa));
  245
+		command_printf(s, "%s ", ip6_sprintf(&bc->bc_coa));
  246
+		command_printf(s, "%s ", ip6_sprintf(&bc->bc_myaddr));
  247
+		command_printf(s, "%d/%d %c%c%c%c %d\n",
248 248
 			(int)(bc->bc_expire - now),
249 249
 			bc->bc_lifetime,
250 250
 			(bc->bc_flags & IP6_MH_BU_ACK)  ? 'A' : '-',
@@ -252,18 +252,15 @@ command_show_bc(s)
252 252
 			(bc->bc_flags & IP6_MH_BU_LLOCAL) ? 'L' : '-',
253 253
 			(bc->bc_flags & IP6_MH_BU_KEYM)  ? 'K' : '-',
254 254
 			bc->bc_seqno);
255  
-		write(s, buff, strlen(buff));
256 255
 	}
257 256
 }
258 257
 
259 258
 void
260  
-command_show_kbc(s)
  259
+command_show_kbc(s, line)
261 260
 	int s;
  261
+	char *line;
262 262
 {
263  
-	char buff[2048];
264  
-
265  
-	sprintf(buff, "Not Supported yet\n");
266  
-	write(s, buff, strlen(buff));
  263
+	command_printf(s, "Not Supported yet\n");
267 264
 }
268 265
 
269 266
 
@@ -783,10 +780,10 @@ bul_get_nohoa(cookie, coa, peer)
783 780
 };
784 781
 
785 782
 void
786  
-command_show_bul(s)
  783
+command_show_bul(s, dummy)
787 784
 	int s;
  785
+	char *dummy;
788 786
 {
789  
-	char buff[2048];
790 787
 	struct mip6_hoainfo *hoainfo = NULL;
791 788
 	struct binding_update_list *bul = NULL;
792 789
         struct timeval now;
@@ -799,23 +796,22 @@ command_show_bul(s)
799 796
 		for (bul = LIST_FIRST(&hoainfo->hinfo_bul_head); bul;
800 797
 		     bul = LIST_NEXT(bul, bul_entry)) {
801 798
 
802  
-			sprintf(buff, "%s ", ip6_sprintf(&bul->bul_peeraddr));
  799
+			command_printf(s, "%s ", ip6_sprintf(&bul->bul_peeraddr));
803 800
 #ifndef MIP_MCOA
804  
-			sprintf(buff + strlen(buff), "%s ", 
  801
+			command_printf(s, "%s ", 
805 802
 				ip6_sprintf(&hoainfo->hinfo_hoa));
806 803
 #else
807 804
 			if (bul->bul_bid)
808  
-				sprintf(buff + strlen(buff), "%s$%d ", 
  805
+				command_printf(s, "%s$%d ", 
809 806
 					ip6_sprintf(&hoainfo->hinfo_hoa), bul->bul_bid);
810 807
 			else
811  
-				sprintf(buff + strlen(buff), "%s ", 
  808
+				command_printf(s, "%s ", 
812 809
 					ip6_sprintf(&hoainfo->hinfo_hoa));
813 810
 #endif /* MIP_MCOA */
814  
-			sprintf(buff + strlen(buff), "%s\n", 
  811
+			command_printf(s, "%s\n", 
815 812
 				ip6_sprintf(&bul->bul_coa));
816  
-			write(s, buff, strlen(buff));
817 813
 			
818  
-			sprintf(buff,
  814
+			command_printf(s,
819 815
 				"     lif=%d, ref=%d, seq=%d, %c%c%c%c%c%c, %c, ", 
820 816
 				bul->bul_lifetime,
821 817
 				bul->bul_refresh,
@@ -828,7 +824,7 @@ command_show_bul(s)
828 824
 				(bul->bul_flags & IP6_MH_BU_MCOA)  ? 'M' : '-',
829 825
 				(bul->bul_state & MIP6_BUL_STATE_DISABLE) ? 'D' : '-');
830 826
 
831  
-			sprintf(buff + strlen(buff),
  827
+			command_printf(s,
832 828
 				"reg=%d, rr=%d, ret=%ld, exp=%ld\n",
833 829
 				bul->bul_reg_fsm_state,
834 830
 				bul->bul_rr_fsm_state,
@@ -836,20 +832,18 @@ command_show_bul(s)
836 832
 				(bul->bul_retrans->exptime.tv_sec - now.tv_sec) : -1,
837 833
 				(bul->bul_expire) ? 
838 834
 				(bul->bul_expire->exptime.tv_sec - now.tv_sec) : -1);
839  
-			write(s, buff, strlen(buff));
840 835
 		}
841 836
 	}
842 837
 } 
843 838
 
844 839
 void
845  
-command_show_kbul(s)
  840
+command_show_kbul(s, dummy)
846 841
 	int s;
  842
+	char *dummy;
847 843
 {
848  
-        struct if_bulreq bulreq;
849  
-        struct bul6info *bul6;
850  
-        int sock, i;
851  
-
852  
-	char buff[2048];
  844
+	struct if_bulreq bulreq;
  845
+	struct bul6info *bul6;
  846
+	int sock, i;
853 847
 	struct mip6_hoainfo *hoainfo = NULL;
854 848
 	char ifname[IFNAMSIZ];
855 849
 
@@ -885,25 +879,24 @@ command_show_kbul(s)
885 879
 		/* dump bul */
886 880
 		for (i = 0; i < bulreq.ifbu_count; i ++) {
887 881
 			bul6 = bulreq.ifbu_info + i * sizeof(struct bul6info);
888  
-			sprintf(buff, "%s ", ip6_sprintf(&bul6->bul_peeraddr));
  882
+			command_printf(s, "%s ", ip6_sprintf(&bul6->bul_peeraddr));
889 883
 
890 884
 #ifndef MIP_MCOA
891  
-			sprintf(buff + strlen(buff), "%s ", 
  885
+			command_printf(s, "%s ", 
892 886
 				ip6_sprintf(&bul6->bul_hoa));
893 887
 #else
894 888
 			if (bul6->bul_bid)
895  
-				sprintf(buff + strlen(buff), "%s$%d ", 
  889
+				command_printf(s, "%s$%d ", 
896 890
 					ip6_sprintf(&bul6->bul_hoa), bul6->bul_bid);
897 891
 			else
898  
-				sprintf(buff + strlen(buff), "%s ", 
  892
+				command_printf(s, "%s ", 
899 893
 					ip6_sprintf(&bul6->bul_hoa));
900 894
 #endif /* MIP_MCOA */
901 895
 
902  
-			sprintf(buff + strlen(buff), "%s\n", 
  896
+			command_printf(s, "%s\n", 
903 897
 				ip6_sprintf(&bul6->bul_coa));
904  
-			write(s, buff, strlen(buff));
905 898
 
906  
-			sprintf(buff,
  899
+			command_printf(s,
907 900
 				"     %s, %c%c%c%c%c%c\n", 
908 901
 				if_indextoname(bul6->bul_ifindex, ifname), 
909 902
 				(bul6->bul_flags & IP6_MH_BU_ACK)  ? 'A' : '-',
@@ -912,8 +905,6 @@ command_show_kbul(s)
912 905
 				(bul6->bul_flags & IP6_MH_BU_KEYM)  ? 'K' : '-',
913 906
 				(bul6->bul_flags & IP6_MH_BU_ROUTER)  ? 'R' : '-',
914 907
 				(bul6->bul_flags & IP6_MH_BU_MCOA)  ? 'M' : '-');
915  
-
916  
-			write(s, buff, strlen(buff));
917 908
 		}
918 909
         }
919 910
 
13  kame/kame/shisad/callout.c
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: callout.c,v 1.2 2005/01/26 07:41:59 t-momose Exp $	*/
  1
+/*	$KAME: callout.c,v 1.3 2005/02/12 15:22:38 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -51,6 +51,13 @@ struct callout_queue_t_head callout_head;
51 51
 
52 52
 static void insert_callout_queue(struct callout_queue_t *);
53 53
 
  54
+/* 
  55
+ * You have to include following header prior including "callout.h"
  56
+ *
  57
+ * #include <sys/queue.h>
  58
+ * #include <sys/time.h>
  59
+ */
  60
+
54 61
 /*
55 62
  *  The data structures in this libarary like a list of callout 
56 63
  *  table are assumed to use in synchronized sequence. Don't operate
@@ -66,7 +73,6 @@ static void insert_callout_queue(struct callout_queue_t *);
66 73
  *    table which can be used to remove it. 
67 74
  */
68 75
 
69  
-
70 76
 void
71 77
 callout_init()
72 78
 {
@@ -197,8 +203,9 @@ get_next_timeout()
197 203
 }
198 204
 
199 205
 void
200  
-show_callout_table(s)
  206
+show_callout_table(s, line)
201 207
 	int s;
  208
+	char *line; /* dummy */
202 209
 {
203 210
 	struct timeval current_time, t;
204 211
 	struct callout_queue_t *cq;
4  kame/kame/shisad/callout.h
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: callout.h,v 1.2 2005/01/26 07:41:59 t-momose Exp $	*/
  1
+/*	$KAME: callout.h,v 1.3 2005/02/12 15:22:38 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -50,5 +50,5 @@ CALLOUT_HANDLE new_callout_entry(int, void (*)(), void *, char *);
50 50
 void remove_callout_entry(CALLOUT_HANDLE ch);
51 51
 void update_callout_entry(CALLOUT_HANDLE ch, int);
52 52
 int get_next_timeout();
53  
-void show_callout_table(int);
  53
+void show_callout_table(int, char *);
54 54
 
71  kame/kame/shisad/cnd.c
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: cnd.c,v 1.3 2005/02/03 13:22:08 t-momose Exp $	*/
  1
+/*	$KAME: cnd.c,v 1.4 2005/02/12 15:22:39 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -55,16 +55,23 @@
55 55
 #include "callout.h"
56 56
 #include "stat.h"
57 57
 #include "shisad.h"
58  
-#include "fsm.h"
59 58
 #include "fdlist.h"
60 59
 #include "command.h"
61 60
 
62  
-static void command_show_status(int, char *);
  61
+/*static void command_show_status(int, char *);*/
63 62
 static void command_flush(int, char *);
64 63
 static void terminate(int);
65 64
 
  65
+struct command_table show_command_table[] = {
  66
+	{"bc", command_show_bc, "binding chache"},
  67
+	{"kbc", command_show_kbc, "binding chache in kernel"},
  68
+	{"stat", command_show_stat, "statisticts"},
  69
+	{"callout", show_callout_table, "show callout table "},
  70
+	{NULL}
  71
+};
  72
+
66 73
 struct command_table command_table[] = {
67  
-	{"show", command_show_status, "Show status"},
  74
+	{"show", NULL, "Show status", show_command_table},
68 75
 	{"flush", command_flush, "Flush binding caches"},
69 76
 };
70 77
 
@@ -103,20 +110,9 @@ main(argc, argv)
103 110
 	int pfds;
104 111
 	int pid;
105 112
 	int ch = 0;
106  
-	char *arg_string;	/* XXX Bad var name; what is used for ? */
107 113
 	FILE *pidfp;
108 114
 
109  
-#if 0
110  
-	/* XXX Is this check needed ? */
111  
-        if (argc < 2) {
112  
-		cn_usage(argv[0]);
113  
-		/* Not reach */
114  
-		return (EINVAL);
115  
-	}
116  
-#endif
117  
-
118 115
 	/* get options */
119  
-	arg_string = NULL;
120 116
 	while ((ch = getopt(argc, argv, "dni:")) != -1) {
121 117
 		switch (ch) {
122 118
 		case 'd':
@@ -125,9 +121,6 @@ main(argc, argv)
125 121
 		case 'n':
126 122
 			numerichost = 1;
127 123
 			break;
128  
-		case 'i':
129  
-			arg_string = optarg;
130  
-			break;
131 124
 		default:
132 125
 			fprintf(stderr, "unknown option\n");
133 126
 			cn_usage();
@@ -139,7 +132,7 @@ main(argc, argv)
139 132
 
140 133
 	/* open syslog infomation. */
141 134
 	openlog("shisad(cnd)", 0, LOG_DAEMON);
142  
-	syslog(LOG_INFO, "-- Start CN daemon at %s -- \n", arg_string);
  135
+	syslog(LOG_INFO, "-- Start CN daemon at -- \n");
143 136
 
144 137
 	/* open sockets */
145 138
 	mhsock_open();
@@ -227,45 +220,6 @@ mipsock_input(miphdr)
227 220
 }
228 221
 
229 222
 static void
230  
-command_show_status(s, arg)
231  
-	int s;
232  
-	char *arg;
233  
-{
234  
-        char msg[1024];
235  
-
236  
-	if (strcmp(arg, "bc") == 0) {
237  
-                sprintf(msg, "-- Binding Cache (Shisa) --\n");
238  
-                write(s, msg, strlen(msg));
239  
-		
240  
-                command_show_bc(s);
241  
-
242  
-        } else if (strcmp(arg, "kbc") == 0) {
243  
-                sprintf(msg, "-- Binding Cache (kernel) --\n");
244  
-                write(s, msg, strlen(msg));
245  
-
246  
-                command_show_kbc(s);
247  
-
248  
-        } else if (strcmp(arg, "stat") == 0) {
249  
-                sprintf(msg, "-- Shisa Statistics --\n");
250  
-                write(s, msg, strlen(msg));
251  
-
252  
-                command_show_stat(s);
253  
-
254  
-	} else if (strcmp(arg, "callout") == 0) {
255  
-		sprintf(msg, "-- List of callout table --\n");
256  
-		write(s, msg, strlen(msg));
257  
-
258  
-		show_callout_table(s);
259  
-        } else {
260  
-                sprintf(msg, "Available options are:\n");
261  
-                sprintf(msg + strlen(msg), "\tbc (Binding Cache in Shisa)\n\tkbc (Binding Cache in kernel)\n\tstat (Statistics)\n");
262  
-                write(s, msg, strlen(msg));
263  
-        }
264  
-
265  
-	return;
266  
-}
267  
-
268  
-static void
269 223
 command_flush(s, arg)
270 224
 	int s;
271 225
 	char *arg;
@@ -281,4 +235,3 @@ terminate(dummy)
281 235
 	unlink(pid_file);
282 236
 	exit(1);
283 237
 }
284  
-
81  kame/kame/shisad/command.c
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: command.c,v 1.1 2004/12/09 02:18:31 t-momose Exp $	*/
  1
+/*	$KAME: command.c,v 1.2 2005/02/12 15:22:39 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -31,6 +31,7 @@
31 31
 
32 32
 #include <stdio.h>
33 33
 #include <stdlib.h>
  34
+#include <stdarg.h>
34 35
 #include <string.h>
35 36
 #include <strings.h>
36 37
 #include <unistd.h>
@@ -46,12 +47,12 @@
46 47
 static struct sockaddr_in6 sin6_ci;
47 48
 char *prompt = "> ";
48 49
 
49  
-
50 50
 void command_help(int, char *);
51 51
 void quit_ui(int, char *);
52 52
 int command_in(int);
53 53
 int new_connection(int);
54 54
 #define disp_prompt(s)	write((s), prompt, strlen(prompt))
  55
+static void dispatch_command(int, char *, struct command_table *);
55 56
 
56 57
 struct command_table basic_command_table[] = {
57 58
 	{"help", command_help, "Show help"},
@@ -145,33 +146,66 @@ command_in(s)
145 146
 {
146 147
 	int bytes;
147 148
 	char buffer[2048];
148  
-	struct command_table *ctbl;
149  
-	char *errmsg = "??? unknown command\n";
150 149
 	
151 150
 	bytes = read(s, buffer, 2048);
152 151
 
153 152
 	buffer[bytes] = '\0';
154 153
 	while (strlen(buffer) && isspace(buffer[strlen(buffer) - 1]))
155 154
 		buffer[strlen(buffer) - 1] = '\0';
156  
-	if (strlen(buffer) == 0)
157  
-		goto prompt;
  155
+	if (strlen(buffer) > 0)
  156
+		dispatch_command(s, buffer, commands);
  157
+
  158
+	disp_prompt(s);
  159
+
  160
+	return (0);
  161
+}
  162
+
  163
+static void
  164
+dispatch_command(s, command_line, command_table)
  165
+	int s;
  166
+	char *command_line;
  167
+	struct command_table *command_table;
  168
+{
  169
+	char *arg;
  170
+	struct command_table *ctbl;
  171
+	char *errmsg = "??? unknown command\n";
  172
+	
  173
+	if ((strncmp(command_line, "help", 4) == 0) ||
  174
+	    (strncmp(command_line, "?", 1) == 0)) {
  175
+		command_help(s, (char *)command_table);
  176
+		return;
  177
+	}
  178
+	
  179
+	for (ctbl = command_table; ctbl->command != NULL; ctbl++) {
  180
+		if ((strncmp(ctbl->command, command_line, strlen(ctbl->command)) != 0))
  181
+			continue;
  182
+
  183
+		arg = command_line + strlen(ctbl->command);
158 184
 
159  
-	for (ctbl = commands; ctbl->command != NULL; ctbl++) {
160  
-		if (strncmp(ctbl->command, buffer, strlen(ctbl->command)) == 0) {
161  
-			char *arg = buffer + strlen(ctbl->command);
  185
+		while (isspace(*arg))
  186
+			arg++;
162 187
 
163  
-			while (isspace(*arg))
164  
-				arg++;
  188
+		if (ctbl->sub_cmds)
  189
+			dispatch_command(s, arg, ctbl->sub_cmds);
  190
+		else
165 191
 			(*ctbl->cmdfunc)(s, arg);
166  
-			goto prompt;
167  
-		}
  192
+		return;
168 193
 	}
169 194
 
170 195
 	write(s, errmsg, strlen(errmsg));
  196
+	return;
  197
+}
171 198
 
172  
- prompt:
173  
-	disp_prompt(s);
174  
-	return (0);
  199
+void
  200
+command_printf(int s, const char *fmt, ...)
  201
+{
  202
+	va_list ap;
  203
+	char buffer[512];
  204
+	
  205
+	va_start(ap, fmt);
  206
+	vsnprintf(buffer, 512, fmt, ap);
  207
+	va_end(ap);
  208
+	write(s, buffer, strlen(buffer));
175 209
 }
176 210
 
177 211
 void
@@ -179,12 +213,13 @@ command_help(s, line)
179 213
 	int s;
180 214
 	char *line;
181 215
 {
182  
-	char msg[1024];
183  
-	struct command_table *ctbl;
  216
+	struct command_table *ctbl, *base;
  217
+
  218
+	base =(struct command_table *)line;
184 219
 	
185  
-	for (ctbl = commands; ctbl->command != NULL; ctbl++) {
186  
-		sprintf(msg, "%-10s - %s\n", ctbl->command, ctbl->helpmsg);
187  
-		write(s, msg, strlen(msg));
  220
+	for (ctbl = base; ctbl->command != NULL; ctbl++) {
  221
+		command_printf(s, "%-10s - %s\n",
  222
+			       ctbl->command, ctbl->helpmsg);
188 223
 	}
189 224
 }
190 225
 
@@ -193,9 +228,7 @@ quit_ui(s, line)
193 228
 	int s;
194 229
 	char *line;
195 230
 {
196  
-	char *msg = "bye bye\n";
197  
-
198  
-	write(s, msg, strlen(msg));
  231
+	command_printf(s, "bye bye\n");
199 232
 	delete_fd_list_entry(s);
200 233
 	close(s);
201 234
 }
4  kame/kame/shisad/command.h
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: command.h,v 1.1 2004/12/09 02:18:31 t-momose Exp $	*/
  1
+/*	$KAME: command.h,v 1.2 2005/02/12 15:22:39 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -33,7 +33,9 @@ struct command_table {
33 33
 	char *command;
34 34
 	void (*cmdfunc)(int, char *);
35 35
 	char *helpmsg;
  36
+	struct command_table *sub_cmds;
36 37
 };
37 38
 
38 39
 int command_init(char *, struct command_table *, size_t, u_short);
  40
+void command_printf(int s, const char *fmt, ...);
39 41
 
46  kame/kame/shisad/common.c
... ...
@@ -1,4 +1,4 @@
1  
-/*      $KAME: common.c,v 1.10 2005/02/05 09:15:02 t-momose Exp $  */
  1
+/*      $KAME: common.c,v 1.11 2005/02/12 15:22:39 t-momose Exp $  */
2 2
 /*
3 3
  * Copyright (C) 2004 WIDE Project.  All rights reserved.
4 4
  *
@@ -62,6 +62,7 @@
62 62
 #include <arpa/inet.h>
63 63
 
64 64
 #include "callout.h"
  65
+#include "command.h"
65 66
 #include "stat.h"
66 67
 #include "shisad.h"
67 68
 #include "fsm.h"
@@ -109,7 +110,7 @@ mipsock_open()
109 110
 
110 111
 int
111 112
 mipsock_input_common(fd)
112  
-     int fd;
  113
+	int fd;
113 114
 {
114 115
 	int n;
115 116
         char msg[1280];
@@ -1722,20 +1723,18 @@ static const char *binding_error_status_desc[] = {
1722 1723
 
1723 1724
 
1724 1725
 void
1725  
-command_show_stat(s)
  1726
+command_show_stat(s, line)
1726 1727
 	int s;
  1728
+	char *line; /* dummy */
1727 1729
 {
1728 1730
 	int i;
1729 1731
 	u_quad_t mip6s_mh;
1730  
-	char buff[2048];
1731 1732
 
1732 1733
 #define PS(msg, value) do {\
1733  
-         sprintf(buff, "     %qu " msg "\n", value);\
1734  
-         write(s, buff, strlen(buff));\
  1734
+         command_printf(s, "     %qu " msg "\n", value);\
1735 1735
 	} while(/*CONSTCOND*/0)
1736 1736
 
1737  
-	sprintf(buff, "Input Statistic:\n");
1738  
-	write(s, buff, strlen(buff));
  1737
+	command_printf(s, "Input Statistic:\n");
1739 1738
 
1740 1739
 	mip6s_mh = 0;
1741 1740
 	for (i = 0; i < sizeof(mip6stat.mip6s_mobility) / sizeof(u_quad_t); i++)
@@ -1750,18 +1749,18 @@ command_show_stat(s)
1750 1749
 	PS("BA messages", mip6stat.mip6s_ba);
1751 1750
 	for (i =0; i < 256; i++) {
1752 1751
 		if ((&mip6stat)->mip6s_ba_hist[i] != 0) {
1753  
-			sprintf(buff, "\t\t%qu %s\n", (&mip6stat)->mip6s_ba_hist[i],
1754  
-			    binding_ack_status_desc[i]);
1755  
-			write(s, buff, strlen(buff));
  1752
+			command_printf(s, "\t\t%qu %s\n",
  1753
+				       (&mip6stat)->mip6s_ba_hist[i],
  1754
+				       binding_ack_status_desc[i]);
1756 1755
 		}
1757 1756
 	}
1758 1757
 	PS("BR messages", mip6stat.mip6s_br);
1759 1758
 	PS("BE messages", mip6stat.mip6s_be);
1760  
-	for (i =0; i < 2; i++) { /* currently only 2 codes are available */
  1759
+	for (i = 1; i <= 2; i++) { /* currently only 2 codes are available */
1761 1760
 		if ((&mip6stat)->mip6s_be_hist[i] != 0) {
1762  
-			sprintf(buff, "\t\t%qu %s\n", (&mip6stat)->mip6s_be_hist[i],
1763  
-			    binding_error_status_desc[i]);
1764  
-			write(s, buff, strlen(buff));
  1761
+			command_printf(s, "\t\t%qu %s\n",
  1762
+				       (&mip6stat)->mip6s_be_hist[i],
  1763
+				       binding_error_status_desc[i]);
1765 1764
 		}
1766 1765
 	}
1767 1766
 	PS("DHAAD request", mip6stat.mip6s_dhreq);
@@ -1786,8 +1785,7 @@ command_show_stat(s)
1786 1785
 	PS("Invalid Care-of address", mip6stat.mip6s_invalidcoa);
1787 1786
 	PS("Invalid mobility options", mip6stat.mip6s_invalidopt);
1788 1787
 
1789  
-	sprintf(buff, "Output Statistic:\n");
1790  
-	write(s, buff, strlen(buff));
  1788
+	command_printf(s, "Output Statistic:\n");
1791 1789
 
1792 1790
 	mip6s_mh = 0;
1793 1791
 	for (i = 0; i < sizeof(mip6stat.mip6s_omobility) / sizeof(u_quad_t); i++)
@@ -1801,18 +1799,18 @@ command_show_stat(s)
1801 1799
 	PS("BA messages", mip6stat.mip6s_oba);
1802 1800
 	for (i =0; i < 256; i++) {
1803 1801
 		if ((&mip6stat)->mip6s_oba_hist[i] != 0) {
1804  
-			sprintf(buff, "\t\t%qu %s\n", (&mip6stat)->mip6s_oba_hist[i],
1805  
-			    binding_ack_status_desc[i]);
1806  
-			write(s, buff, strlen(buff));
  1802
+			command_printf(s, "\t\t%qu %s\n",
  1803
+				       (&mip6stat)->mip6s_oba_hist[i],
  1804
+				       binding_ack_status_desc[i]);
1807 1805
 		}
1808 1806
 	}
1809 1807
 	PS("BR messages", mip6stat.mip6s_obr);
1810 1808
 	PS("BE messages", mip6stat.mip6s_obe);
1811  
-	for (i =0; i < 2; i++) { /* currently only 2 codes are available */
  1809
+	for (i = 1; i <= 2; i++) { /* currently only 2 codes are available */
1812 1810
 		if ((&mip6stat)->mip6s_obe_hist[i] != 0) {
1813  
-			printf("\t\t%qu %s\n", (&mip6stat)->mip6s_obe_hist[i],
1814  
-			    binding_error_status_desc[i]);
1815  
-			write(s, buff, strlen(buff));
  1811
+			command_printf(s, "\t\t%qu %s\n",
  1812
+				       (&mip6stat)->mip6s_obe_hist[i],
  1813
+				       binding_error_status_desc[i]);
1816 1814
 		}
1817 1815
 	}
1818 1816
 	PS("DHAAD request", mip6stat.mip6s_odhreq);
49  kame/kame/shisad/had.c
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: had.c,v 1.6 2005/02/05 10:04:45 t-momose Exp $	*/
  1
+/*	$KAME: had.c,v 1.7 2005/02/12 15:22:39 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -62,7 +62,6 @@
62 62
 #include "callout.h"
63 63
 #include "stat.h"
64 64
 #include "shisad.h"
65  
-#include "fsm.h"
66 65
 #include "fdlist.h"
67 66
 #include "command.h"
68 67
 
@@ -96,12 +95,20 @@ struct ha_ifinfo {
96 95
 
97 96
 static void ha_lists_init(void);
98 97
 static void had_init_homeprefix(char *, int);
99  
-static void command_show_status(int, char *);
  98
+/*static void command_show_status(int, char *);*/
100 99
 static void command_flush(int, char *);
101 100
 static void terminate(int);
102 101
 
  102
+struct command_table show_command_table[] = {
  103
+	{"bc", command_show_bc, "binding chache"},
  104
+	{"kbc", command_show_kbc, "binding chache in kernel"},
  105
+	{"stat", command_show_stat, "statisticts"},
  106
+	{"callout", show_callout_table, "show callout table "},
  107
+	{NULL}
  108
+};
  109
+
103 110
 struct command_table command_table[] = {
104  
-	{"show", command_show_status, "Show status"},
  111
+	{"show", NULL, "Show status", show_command_table},
105 112
         {"flush", command_flush, "Flush stat, bc, hal"},
106 113
 };
107 114
 
@@ -641,40 +648,6 @@ send_haadrep(dst, anycastaddr, dhreq, ifindex)
641 648
 }
642 649
 
643 650
 static void
644  
-command_show_status(s, arg)
645  
-	int s;
646  
-	char *arg;
647  
-{
648  
-        char msg[1024];
649  
-
650  
-	if (strcmp(arg, "bc") == 0) {
651  
-                sprintf(msg, "-- Binding Cache (Shisa) --\n");
652  
-                write(s, msg, strlen(msg));
653  
-		
654  
-                command_show_bc(s);
655  
-
656  
-        } else if (strcmp(arg, "kbc") == 0) {
657  
-                sprintf(msg, "-- Binding Cache (kernel) --\n");
658  
-                write(s, msg, strlen(msg));
659  
-
660  
-                command_show_kbc(s);
661  
-
662  
-        } else if (strcmp(arg, "stat") == 0) {
663  
-                sprintf(msg, "-- Shisa Statistics --\n");
664  
-                write(s, msg, strlen(msg));
665  
-
666  
-                command_show_stat(s);
667  
-
668  
-        } else {
669  
-                sprintf(msg, "Available options are:\n");
670  
-                sprintf(msg + strlen(msg), "\tbc (Binding Cache in Shisa)\n\tkbc (Binding Cache in kernel)\n\tstat (Statistics)\n");
671  
-                write(s, msg, strlen(msg));
672  
-        }
673  
-
674  
-	return;
675  
-}
676  
-
677  
-static void
678 651
 command_flush(s, arg)
679 652
 	int s;
680 653
 	char *arg;
142  kame/kame/shisad/mnd.c
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: mnd.c,v 1.6 2005/01/28 02:12:07 ryuji Exp $	*/
  1
+/*	$KAME: mnd.c,v 1.7 2005/02/12 15:22:39 t-momose Exp $	*/
2 2
 
3 3
 /*
4 4
  * Copyright (C) 2004 WIDE Project.
@@ -82,20 +82,10 @@ struct mip6stat mip6stat;
82 82
 
83 83
 static int default_lifetime = MIP6_DEFAULT_BINDING_LIFE;
84 84
 
85  
-static void command_show_status(int, char *);
  85
+/*static void command_show_status(int, char *);*/
86 86
 static void command_flush(int, char *);
87  
-static void command_show_hal(int);
88  
-static void show_current_config(int);
89  
-
90  
-struct command_table command_table[] = {
91  
-#ifndef MIP_NEMO
92  
-	{"show", command_show_status, "Show stat, bul, hal, kbul, noro, config"},
93  
-#else
94  
-	{"show", command_show_status, "Show stat, bul, hal, kbul, noro, config, pt"},
95  
-#endif /* MIP_NEMO */
96  
-	{"flush", command_flush, "Flush stat, bul, hal, noro"},
97  
-};
98  
-
  87
+static void command_show_hal(int, char *);
  88
+static void show_current_config(int, char *);
99 89
 
100 90
 static void mn_lists_init(void);
101 91
 static int mipsock_recv_rr_hint(struct mip_msghdr *);
@@ -107,10 +97,34 @@ static int mipsock_md_dereg_bul_fl(struct in6_addr *, struct in6_addr *,
107 97
 
108 98
 static int add_hal_by_commandline_xxx(char *);
109 99
 
110  
-static void noro_show(int);
111 100
 static void noro_init(void);
  101
+static void noro_show(int, char *);
112 102
 static void noro_sync(void);
113 103
 
  104
+struct command_table show_command_table[] = {
  105
+	{"bul", command_show_bul, "Binding Update List in Shisa"},
  106
+	{"kbul", command_show_kbul, "Binding Update List in kernel"},
  107
+	{"hal", command_show_hal, "Home Agent List"},
  108
+	{"stat", command_show_stat, "statistics"},
  109
+	{"noro", noro_show, ""},
  110
+	{"config", show_current_config, ""},
  111
+	{"callout", show_callout_table, ""},
  112
+#ifdef MIP_NEMO
  113
+	{"pt", command_show_pt, "Prefix Table, MR only"},
  114
+#endif /* MIP_NEMO */
  115
+	{NULL}
  116
+};
  117
+
  118
+struct command_table command_table[] = {
  119
+	{"show", NULL, "Show stat, bul, hal, kbul, noro, config"
  120
+#ifdef MIP_NEMO
  121
+	 ", pt"
  122
+#endif /* MIP_NEMO */
  123
+	 , show_command_table
  124
+	},
  125
+	{"flush", command_flush, "Flush stat, bul, hal, noro"},
  126
+};
  127
+
114 128
 #ifdef MIP_NEMO
115 129
 #define NODETYPE MIP6_NODETYPE_MOBILE_ROUTER
116 130
 #else /* MIP_NEMO */
@@ -385,6 +399,7 @@ mipsock_recv_mdinfo(miphdr)
385 399
 {
386 400
 	struct mipm_md_info *mdinfo;
387 401
 	struct sockaddr *sin;
  402
+	struct sockaddr_in6 sin6;
388 403
 	struct in6_addr *hoa, *coa, *acoa;
389 404
 	int err = 0;
390 405
 	u_int16_t bid = 0;
@@ -400,10 +415,10 @@ mipsock_recv_mdinfo(miphdr)
400 415
 	hoa = &((struct sockaddr_in6 *)sin)->sin6_addr;
401 416
 
402 417
 	/* Get CoA */
403  
-	sin = MIPD_COA(mdinfo); 
404  
-	if (sin->sa_family != AF_INET6)
  418
+	if (MIPD_COA(mdinfo)->sa_family != AF_INET6)
405 419
 		return (0);
406  
-	coa = &((struct sockaddr_in6 *)sin)->sin6_addr;
  420
+	memcpy(&sin6, MIPD_COA(mdinfo), sizeof(sin6));
  421
+	coa = &sin6.sin6_addr;
407 422
 
408 423
 	/* If new CoA is not global, ignore */
409 424
 	if (IN6_IS_ADDR_LINKLOCAL(coa)
@@ -901,7 +916,6 @@ send_haadreq(hoainfo, hoa_plen, src)
901 916
 	struct sockaddr_in6 *ar_sin6 = NULL, ar_sin6_orig;
902 917
 #endif
903 918
 
904  
-
905 919
         memset(&to, 0, sizeof(to));
906 920
         if (mip6_icmp6_create_haanyaddr(&to.sin6_addr, 
907 921
 				&hoainfo->hinfo_hoa, hoa_plen)) 
@@ -1413,17 +1427,15 @@ noro_get(tgt)
1413 1427
 
1414 1428
 
1415 1429
 static void
1416  
-noro_show(s)
  1430
+noro_show(s, dummy)
1417 1431
 	int s;
  1432
+	char *dummy;
1418 1433
 { 
1419  
-	char buff[2048];
1420 1434
 	struct noro_host_list *noro = NULL;
1421 1435
 
1422 1436
         for (noro = LIST_FIRST(&noro_head); noro; 
1423 1437
 	     noro = LIST_NEXT(noro, noro_entry)) {
1424  
-		
1425  
-		sprintf(buff, "%s\n", ip6_sprintf(&noro->noro_host));
1426  
-		write(s, buff, strlen(buff));
  1438
+		command_printf(s, "%s\n", ip6_sprintf(&noro->noro_host));
1427 1439
 	}
1428 1440
 };
1429 1441
 
@@ -1447,10 +1459,10 @@ noro_sync()
1447 1459
 
1448 1460
 
1449 1461
 static void
1450  
-command_show_hal(s)
  1462
+command_show_hal(s, dummy)
1451 1463
 	int s;
  1464
+	char *dummy;
1452 1465
 {
1453  
-	char buff[2048];
1454 1466
         struct home_agent_list *hal = NULL, *haln = NULL;
1455 1467
         struct mip6_hpfxl *hpfx;
1456 1468
 	struct mip6_mipif *mipif = NULL;
@@ -1460,18 +1472,16 @@ command_show_hal(s)
1460 1472
 			for (hal = LIST_FIRST(&hpfx->hpfx_hal_head); hal; hal = haln) {
1461 1473
 				haln =  LIST_NEXT(hal, hal_entry);
1462 1474
 				
1463  
-				sprintf(buff, "%s ", ip6_sprintf(&hal->hal_ip6addr));
1464  
-				sprintf(buff + strlen(buff), "%s\n", 
  1475
+				command_printf(s, "%s ", ip6_sprintf(&hal->hal_ip6addr));
  1476
+				command_printf(s, "%s\n", 
1465 1477
 					ip6_sprintf(&hal->hal_lladdr));
1466 1478
 #ifdef MIP_HA
1467  
-				sprintf(buff + strlen(buff), 
  1479
+				command_printf(s,
1468 1480
 					"     lif=%d pref=%d flag=%s%s\n",
1469 1481
 					hal->hal_lifetime, hal->hal_preference, 
1470 1482
 					(hal->hal_flag & MIP6_HA_OWN)  ? "mine" : ""
1471 1483
 					(hal->hal_flag & MIP6_HA_STATIC)  ? "static" : "");
1472 1484
 #endif /* MIP_HA */
1473  
-				write(s, buff, strlen(buff));
1474  
-				
1475 1485
 			}
1476 1486
 		}
1477 1487
 	}
@@ -1479,68 +1489,6 @@ command_show_hal(s)
1479 1489
 	return;
1480 1490
 }
1481 1491
 
1482  
-
1483  
-static void
1484  
-command_show_status(s, arg)
1485  
-	int s;
1486  
-	char *arg;
1487  
-{
1488  
-	char msg[1024];
1489  
-
1490  
-	if (strcmp(arg, "bul") == 0) {
1491  
-		sprintf(msg, "-- Binding Update List (Shisa) --\n");
1492  
-		write(s, msg, strlen(msg));
1493  
-
1494  
-		command_show_bul(s);
1495  
-
1496  
-	} else if (strcmp(arg, "kbul") == 0) {
1497  
-		sprintf(msg, "-- Binding Update List (kernel) --\n");
1498  
-		write(s, msg, strlen(msg));
1499  
-
1500  
-		command_show_kbul(s);
1501  
-	} else if (strcmp(arg, "hal") == 0) {
1502  
-		sprintf(msg, "-- Home Agent List --\n");
1503  
-		write(s, msg, strlen(msg));
1504  
-
1505  
-		command_show_hal(s);
1506  
-	} else if (strcmp(arg, "bc") == 0) {
1507  
-		sprintf(msg, "Wrong port!\nPlease find Binding Cache at cnd\n");
1508  
-		write(s, msg, strlen(msg));
1509  
- 	} else if (strcmp(arg, "stat") == 0) {
1510  
-		sprintf(msg, "-- Shisa Statistics --\n");
1511  
-		write(s, msg, strlen(msg));
1512  
-
1513  
-		command_show_stat(s);
1514  
-	} else if (strcmp(arg, "noro") == 0) {
1515  
-		sprintf(msg, "-- No Route Optimization --\n");
1516  
-		write(s, msg, strlen(msg));
1517  
-
1518  
-		noro_show(s);
1519  
-	} else if (strcmp(arg, "config") == 0) {
1520  
-		show_current_config(s);
1521  
-	} else if (strcmp(arg, "callout") == 0) {
1522  
-		sprintf(msg, "-- List of callout table --\n");
1523  
-		write(s, msg, strlen(msg));
1524  
-
1525  
-		show_callout_table(s);
1526  
-	}
1527  
-#ifdef MIP_NEMO
1528  
-	else if (strcmp(arg, "pt") == 0) {
1529  
-		sprintf(msg, "-- Prefix Table --\n");
1530  
-		write(s, msg, strlen(msg));
1531  
-		
1532  
-		command_show_pt(s);
1533  
-	}
1534  
-#endif /* MIP_NEMO */
1535  
-	else {
1536  
-		sprintf(msg, "Available options are:\n");
1537  
-		sprintf(msg + strlen(msg), "\tbul (Binding Update List in Shisa)\n\tkbul (Binding Update List in kernel)\n\thal (Home Agent List)\n\tstat (Statistics)\n\tpt (Prefix Table, MR only)\n\n");
1538  
-		write(s, msg, strlen(msg));
1539  
-	}
1540  
-
1541  
-	return;
1542  
-}
1543  
-
1544 1492
 /* Flush BC should be done by cnd */
1545 1493
 static void
1546 1494
 command_flush(s, arg)
@@ -1573,12 +1521,10 @@ command_flush(s, arg)
1573 1521
 }
1574 1522
 
1575 1523
 static void
1576  
-show_current_config(s)
  1524
+show_current_config(s, dummy)
1577 1525
 	int s;
  1526
+	char *dummy;
1578 1527
 {
1579  
-	char msg[1024];
1580  
-	
1581  
-	sprintf(msg, "Binding Update Lifetime for Home registration: %d(s)\n",
  1528
+	command_printf(s, "Binding Update Lifetime for Home registration: %d(s)\n",
1582 1529
 		default_lifetime * 4);
1583  
-	write(s, msg, strlen(msg));
1584 1530
 }
15  kame/kame/shisad/nemo_var.c
... ...
@@ -1,4 +1,4 @@
1  
-/*      $KAME: nemo_var.c,v 1.4 2005/01/24 04:14:44 ryuji Exp $  */
  1
+/*      $KAME: nemo_var.c,v 1.5 2005/02/12 15:22:40 t-momose Exp $  */
2 2
 /*
3 3
  * Copyright (C) 2004 WIDE Project.  All rights reserved.
4 4
  *
@@ -58,6 +58,7 @@
58 58
 #include <arpa/inet.h>
59 59
 
60 60
 #include "callout.h"
  61
+#include "command.h"
61 62
 #include "shisad.h"
62 63
 #include "stat.h"
63 64
 #include "fsm.h"
@@ -128,10 +129,10 @@ nemo_mpt_add(hoainfo, nemoprefix, prefixlen, mode)
128 129
 }
129 130
 
130 131
 void
131  
-command_show_pt(s)
  132
+command_show_pt(s, dummy)
132 133
 	int s;
  134
+	char *dummy;
133 135
 {
134  
-	char buff[2048];
135 136
 	struct nemo_mptable *mpt, *mptn;
136 137
         struct mip6_hoainfo *hoainfo = NULL;
137 138
 	
@@ -142,14 +143,12 @@ command_show_pt(s)
142 143
 		     mpt; mpt = mptn) {
143 144
 			mptn = LIST_NEXT(mpt, mpt_entry);
144 145
 			
145  
-			sprintf(buff, "%s ", ip6_sprintf(&hoainfo->hinfo_hoa));
146  
-			sprintf(buff + strlen(buff), "%s%%%d ", 
  146
+			command_printf(s, "%s ", ip6_sprintf(&hoainfo->hinfo_hoa));
  147
+			command_printf(s, "%s%%%d ", 
147 148
 				ip6_sprintf(&mpt->mpt_prefix), mpt->mpt_prefixlen);
148  
-			sprintf(buff + strlen(buff), "%s\n", 
  149
+			command_printf(s, "%s\n", 
149 150
 				(mpt->mpt_regmode == NEMO_IMPLICIT) ? 
150 151
 				"implicit" : "explicit");
151  
-			
152  
-			write(s, buff, strlen(buff));
153 152
 		}
154 153
 	}
155 154
 }
14  kame/kame/shisad/shisad.h
... ...
@@ -1,4 +1,4 @@
1  
-/*	$KAME: shisad.h,v 1.7 2005/01/28 02:12:07 ryuji Exp $	*/
  1
+/*	$KAME: shisad.h,v 1.8 2005/02/12 15:22:40 t-momose Exp $	*/
2 2
 /*
3 3
  * Copyright (C) 2004 WIDE Project.
4 4
  * All rights reserved.
@@ -415,11 +415,11 @@ void mip6_flush_kernel_bc(void);
415 415
 void mip6_bc_delete(struct binding_cache *);
416 416
 void mip6_bc_refresh_timer(void *);
417 417
 void mipscok_bc_request(struct binding_cache *, u_char);
418  
-void command_show_bc(int);
419  
-void command_show_kbc(int);
  418
+void command_show_bc(int, char *);
  419
+void command_show_kbc(int, char *);
420 420
 
421  
-void command_show_bul(int);
422  
-void command_show_kbul(int);
  421
+void command_show_bul(int, char *);
  422
+void command_show_kbul(int, char *);
423 423
 struct binding_cache *mip6_bc_lookup(struct in6_addr *, struct in6_addr *, 
424 424
     u_int16_t);
425 425
 struct binding_cache *mip6_bc_add(struct in6_addr *, struct in6_addr *, 
@@ -462,7 +462,7 @@ void mip6_delete_hpfxlist(struct in6_addr *, u_int16_t,
462 462
 void hal_set_expire_timer(struct home_agent_list *, int);
463 463
 void hal_stop_expire_timer(struct home_agent_list *);
464 464
 void hal_expire_timer(void *);
465  
-void command_show_stat(int);
  465
+void command_show_stat(int, char *);
466 466
 
467 467
 /* mnd.c */
468 468
 int mipsock_bul_request(struct binding_update_list *, u_char);
@@ -511,7 +511,7 @@ struct nemo_hptable *nemo_hpt_add(struct in6_addr *, struct in6_addr *,
511 511
 
512 512
 #define NEMOPREFIXINFO "./nemo_prefixtable.conf"
513 513
 void nemo_parse_conf(char *);
514  
-void command_show_pt(int s);
  514
+void command_show_pt(int, char *);
515 515
 
516 516
 #endif /* MIP_NEMO */
517 517
 #endif /* _SHISAD_H_ */

0 notes on commit c2fdd46

Please sign in to comment.
Something went wrong with that request. Please try again.