Permalink
Browse files

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

…tual terminal for shisa.
  • Loading branch information...
1 parent 2429372 commit c2fdd46ee12411fae6b672e415086d4e2f8a7698 t-momose committed Feb 12, 2005
@@ -1,4 +1,4 @@
-/* $KAME: binding.c,v 1.5 2005/01/26 07:41:59 t-momose Exp $ */
+/* $KAME: binding.c,v 1.6 2005/02/12 15:22:38 t-momose Exp $ */
/*
* Copyright (C) 2004 WIDE Project. All rights reserved.
*
@@ -57,8 +57,8 @@
#include "callout.h"
#include "shisad.h"
-#include "fsm.h"
#include "stat.h"
+#include "command.h"
#ifdef MIP_MN
void bul_flush(struct mip6_hoainfo *);
@@ -232,38 +232,35 @@ mip6_bc_lookup(hoa, src, bid)
};
void
-command_show_bc(s)
+command_show_bc(s, line)
int s;
+ char *line;
{
time_t now;
- char buff[2048];
struct binding_cache *bc;
now = time(NULL);
for (bc = LIST_FIRST(&bchead); bc; bc = LIST_NEXT(bc, bc_entry)) {
- sprintf(buff, "%s ", ip6_sprintf(&bc->bc_hoa));
- sprintf(buff + strlen(buff), "%s ", ip6_sprintf(&bc->bc_coa));
- sprintf(buff + strlen(buff), "%s ", ip6_sprintf(&bc->bc_myaddr));
- sprintf(buff + strlen(buff), "%d/%d %c%c%c%c %d\n",
+ command_printf(s, "%s ", ip6_sprintf(&bc->bc_hoa));
+ command_printf(s, "%s ", ip6_sprintf(&bc->bc_coa));
+ command_printf(s, "%s ", ip6_sprintf(&bc->bc_myaddr));
+ command_printf(s, "%d/%d %c%c%c%c %d\n",
(int)(bc->bc_expire - now),
bc->bc_lifetime,
(bc->bc_flags & IP6_MH_BU_ACK) ? 'A' : '-',
(bc->bc_flags & IP6_MH_BU_HOME) ? 'H' : '-',
(bc->bc_flags & IP6_MH_BU_LLOCAL) ? 'L' : '-',
(bc->bc_flags & IP6_MH_BU_KEYM) ? 'K' : '-',
bc->bc_seqno);
- write(s, buff, strlen(buff));
}
}
void
-command_show_kbc(s)
+command_show_kbc(s, line)
int s;
+ char *line;
{
- char buff[2048];
-
- sprintf(buff, "Not Supported yet\n");
- write(s, buff, strlen(buff));
+ command_printf(s, "Not Supported yet\n");
}
@@ -783,10 +780,10 @@ bul_get_nohoa(cookie, coa, peer)
};
void
-command_show_bul(s)
+command_show_bul(s, dummy)
int s;
+ char *dummy;
{
- char buff[2048];
struct mip6_hoainfo *hoainfo = NULL;
struct binding_update_list *bul = NULL;
struct timeval now;
@@ -799,23 +796,22 @@ command_show_bul(s)
for (bul = LIST_FIRST(&hoainfo->hinfo_bul_head); bul;
bul = LIST_NEXT(bul, bul_entry)) {
- sprintf(buff, "%s ", ip6_sprintf(&bul->bul_peeraddr));
+ command_printf(s, "%s ", ip6_sprintf(&bul->bul_peeraddr));
#ifndef MIP_MCOA
- sprintf(buff + strlen(buff), "%s ",
+ command_printf(s, "%s ",
ip6_sprintf(&hoainfo->hinfo_hoa));
#else
if (bul->bul_bid)
- sprintf(buff + strlen(buff), "%s$%d ",
+ command_printf(s, "%s$%d ",
ip6_sprintf(&hoainfo->hinfo_hoa), bul->bul_bid);
else
- sprintf(buff + strlen(buff), "%s ",
+ command_printf(s, "%s ",
ip6_sprintf(&hoainfo->hinfo_hoa));
#endif /* MIP_MCOA */
- sprintf(buff + strlen(buff), "%s\n",
+ command_printf(s, "%s\n",
ip6_sprintf(&bul->bul_coa));
- write(s, buff, strlen(buff));
- sprintf(buff,
+ command_printf(s,
" lif=%d, ref=%d, seq=%d, %c%c%c%c%c%c, %c, ",
bul->bul_lifetime,
bul->bul_refresh,
@@ -828,28 +824,26 @@ command_show_bul(s)
(bul->bul_flags & IP6_MH_BU_MCOA) ? 'M' : '-',
(bul->bul_state & MIP6_BUL_STATE_DISABLE) ? 'D' : '-');
- sprintf(buff + strlen(buff),
+ command_printf(s,
"reg=%d, rr=%d, ret=%ld, exp=%ld\n",
bul->bul_reg_fsm_state,
bul->bul_rr_fsm_state,
(bul->bul_retrans) ?
(bul->bul_retrans->exptime.tv_sec - now.tv_sec) : -1,
(bul->bul_expire) ?
(bul->bul_expire->exptime.tv_sec - now.tv_sec) : -1);
- write(s, buff, strlen(buff));
}
}
}
void
-command_show_kbul(s)
+command_show_kbul(s, dummy)
int s;
+ char *dummy;
{
- struct if_bulreq bulreq;
- struct bul6info *bul6;
- int sock, i;
-
- char buff[2048];
+ struct if_bulreq bulreq;
+ struct bul6info *bul6;
+ int sock, i;
struct mip6_hoainfo *hoainfo = NULL;
char ifname[IFNAMSIZ];
@@ -885,25 +879,24 @@ command_show_kbul(s)
/* dump bul */
for (i = 0; i < bulreq.ifbu_count; i ++) {
bul6 = bulreq.ifbu_info + i * sizeof(struct bul6info);
- sprintf(buff, "%s ", ip6_sprintf(&bul6->bul_peeraddr));
+ command_printf(s, "%s ", ip6_sprintf(&bul6->bul_peeraddr));
#ifndef MIP_MCOA
- sprintf(buff + strlen(buff), "%s ",
+ command_printf(s, "%s ",
ip6_sprintf(&bul6->bul_hoa));
#else
if (bul6->bul_bid)
- sprintf(buff + strlen(buff), "%s$%d ",
+ command_printf(s, "%s$%d ",
ip6_sprintf(&bul6->bul_hoa), bul6->bul_bid);
else
- sprintf(buff + strlen(buff), "%s ",
+ command_printf(s, "%s ",
ip6_sprintf(&bul6->bul_hoa));
#endif /* MIP_MCOA */
- sprintf(buff + strlen(buff), "%s\n",
+ command_printf(s, "%s\n",
ip6_sprintf(&bul6->bul_coa));
- write(s, buff, strlen(buff));
- sprintf(buff,
+ command_printf(s,
" %s, %c%c%c%c%c%c\n",
if_indextoname(bul6->bul_ifindex, ifname),
(bul6->bul_flags & IP6_MH_BU_ACK) ? 'A' : '-',
@@ -912,8 +905,6 @@ command_show_kbul(s)
(bul6->bul_flags & IP6_MH_BU_KEYM) ? 'K' : '-',
(bul6->bul_flags & IP6_MH_BU_ROUTER) ? 'R' : '-',
(bul6->bul_flags & IP6_MH_BU_MCOA) ? 'M' : '-');
-
- write(s, buff, strlen(buff));
}
}
@@ -1,4 +1,4 @@
-/* $KAME: callout.c,v 1.2 2005/01/26 07:41:59 t-momose Exp $ */
+/* $KAME: callout.c,v 1.3 2005/02/12 15:22:38 t-momose Exp $ */
/*
* Copyright (C) 2004 WIDE Project.
@@ -51,6 +51,13 @@ struct callout_queue_t_head callout_head;
static void insert_callout_queue(struct callout_queue_t *);
+/*
+ * You have to include following header prior including "callout.h"
+ *
+ * #include <sys/queue.h>
+ * #include <sys/time.h>
+ */
+
/*
* The data structures in this libarary like a list of callout
* table are assumed to use in synchronized sequence. Don't operate
@@ -66,7 +73,6 @@ static void insert_callout_queue(struct callout_queue_t *);
* table which can be used to remove it.
*/
-
void
callout_init()
{
@@ -197,8 +203,9 @@ get_next_timeout()
}
void
-show_callout_table(s)
+show_callout_table(s, line)
int s;
+ char *line; /* dummy */
{
struct timeval current_time, t;
struct callout_queue_t *cq;
@@ -1,4 +1,4 @@
-/* $KAME: callout.h,v 1.2 2005/01/26 07:41:59 t-momose Exp $ */
+/* $KAME: callout.h,v 1.3 2005/02/12 15:22:38 t-momose Exp $ */
/*
* Copyright (C) 2004 WIDE Project.
@@ -50,5 +50,5 @@ CALLOUT_HANDLE new_callout_entry(int, void (*)(), void *, char *);
void remove_callout_entry(CALLOUT_HANDLE ch);
void update_callout_entry(CALLOUT_HANDLE ch, int);
int get_next_timeout();
-void show_callout_table(int);
+void show_callout_table(int, char *);
@@ -1,4 +1,4 @@
-/* $KAME: cnd.c,v 1.3 2005/02/03 13:22:08 t-momose Exp $ */
+/* $KAME: cnd.c,v 1.4 2005/02/12 15:22:39 t-momose Exp $ */
/*
* Copyright (C) 2004 WIDE Project.
@@ -55,16 +55,23 @@
#include "callout.h"
#include "stat.h"
#include "shisad.h"
-#include "fsm.h"
#include "fdlist.h"
#include "command.h"
-static void command_show_status(int, char *);
+/*static void command_show_status(int, char *);*/
static void command_flush(int, char *);
static void terminate(int);
+struct command_table show_command_table[] = {
+ {"bc", command_show_bc, "binding chache"},
+ {"kbc", command_show_kbc, "binding chache in kernel"},
+ {"stat", command_show_stat, "statisticts"},
+ {"callout", show_callout_table, "show callout table "},
+ {NULL}
+};
+
struct command_table command_table[] = {
- {"show", command_show_status, "Show status"},
+ {"show", NULL, "Show status", show_command_table},
{"flush", command_flush, "Flush binding caches"},
};
@@ -103,20 +110,9 @@ main(argc, argv)
int pfds;
int pid;
int ch = 0;
- char *arg_string; /* XXX Bad var name; what is used for ? */
FILE *pidfp;
-#if 0
- /* XXX Is this check needed ? */
- if (argc < 2) {
- cn_usage(argv[0]);
- /* Not reach */
- return (EINVAL);
- }
-#endif
-
/* get options */
- arg_string = NULL;
while ((ch = getopt(argc, argv, "dni:")) != -1) {
switch (ch) {
case 'd':
@@ -125,9 +121,6 @@ main(argc, argv)
case 'n':
numerichost = 1;
break;
- case 'i':
- arg_string = optarg;
- break;
default:
fprintf(stderr, "unknown option\n");
cn_usage();
@@ -139,7 +132,7 @@ main(argc, argv)
/* open syslog infomation. */
openlog("shisad(cnd)", 0, LOG_DAEMON);
- syslog(LOG_INFO, "-- Start CN daemon at %s -- \n", arg_string);
+ syslog(LOG_INFO, "-- Start CN daemon at -- \n");
/* open sockets */
mhsock_open();
@@ -227,45 +220,6 @@ mipsock_input(miphdr)
}
static void
-command_show_status(s, arg)
- int s;
- char *arg;
-{
- char msg[1024];
-
- if (strcmp(arg, "bc") == 0) {
- sprintf(msg, "-- Binding Cache (Shisa) --\n");
- write(s, msg, strlen(msg));
-
- command_show_bc(s);
-
- } else if (strcmp(arg, "kbc") == 0) {
- sprintf(msg, "-- Binding Cache (kernel) --\n");
- write(s, msg, strlen(msg));
-
- command_show_kbc(s);
-
- } else if (strcmp(arg, "stat") == 0) {
- sprintf(msg, "-- Shisa Statistics --\n");
- write(s, msg, strlen(msg));
-
- command_show_stat(s);
-
- } else if (strcmp(arg, "callout") == 0) {
- sprintf(msg, "-- List of callout table --\n");
- write(s, msg, strlen(msg));
-
- show_callout_table(s);
- } else {
- sprintf(msg, "Available options are:\n");
- sprintf(msg + strlen(msg), "\tbc (Binding Cache in Shisa)\n\tkbc (Binding Cache in kernel)\n\tstat (Statistics)\n");
- write(s, msg, strlen(msg));
- }
-
- return;
-}
-
-static void
command_flush(s, arg)
int s;
char *arg;
@@ -281,4 +235,3 @@ terminate(dummy)
unlink(pid_file);
exit(1);
}
-
Oops, something went wrong. Retry.

0 comments on commit c2fdd46

Please sign in to comment.