1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.25 2004-11-11 03:07:42 bodea Exp $";
17 #include <arpa/inet.h>
19 #include <sys/socket.h>
20 #include <sys/types.h>
35 extern tunnelt
*tunnel
;
36 extern sessiont
*session
;
37 extern radiust
*radius
;
38 extern ippoolt
*ip_address_pool
;
39 extern struct Tstats
*_statistics
;
40 struct cli_def
*cli
= NULL
;
42 extern struct configt
*config
;
43 extern struct config_descriptt config_values
[];
45 extern struct Tringbuffer
*ringbuffer
;
47 extern struct cli_session_actions
*cli_session_actions
;
48 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
49 extern tbft
*filter_list
;
51 char *debug_levels
[] = {
75 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
76 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
77 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
78 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
79 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
100 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
101 static int regular_stuff(struct cli_def
*cli
);
102 static void parsemac(char *string
, char mac
[6]);
105 #define MODE_CONFIG_BGP 8
106 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 static int cmd_router_bgp_exit(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
108 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
109 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
110 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
111 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
112 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
113 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
116 void init_cli(char *hostname
)
120 struct cli_command
*c
;
121 struct cli_command
*c2
;
123 struct sockaddr_in addr
;
126 if (hostname
&& *hostname
)
127 cli_set_hostname(cli
, hostname
);
129 cli_set_hostname(cli
, "l2tpns");
131 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
132 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
134 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
136 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
137 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
138 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
139 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
140 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
141 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
142 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
143 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
144 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
145 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
146 cli_register_command(cli
, c
, "users", cmd_show_users
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of all connected users or details of selected user");
147 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
149 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
150 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
151 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
154 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
156 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
157 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
160 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
162 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
163 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
164 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
166 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily enable interception for a user");
167 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily enable throttling for a user");
168 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
171 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
172 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
175 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
176 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily disable interception for a user");
177 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily disable throttling for a user");
178 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
181 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
182 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
184 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
185 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
187 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
188 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
190 cli_register_command(cli
, NULL
, "exit", cmd_router_bgp_exit
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Exit from BGP configuration");
191 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
193 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
194 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
197 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
198 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
199 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
200 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
202 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
203 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
205 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
206 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
208 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
210 // Enable regular processing
211 cli_regular(cli
, regular_stuff
);
213 if (!(f
= fopen(CLIUSERS
, "r")))
215 LOG(0, 0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
219 while (fgets(buf
, 4096, f
))
222 if (*buf
== '#') continue;
223 if ((p
= strchr(buf
, '\r'))) *p
= 0;
224 if ((p
= strchr(buf
, '\n'))) *p
= 0;
226 if (!(p
= strchr((char *)buf
, ':'))) continue;
228 if (!strcmp(buf
, "enable"))
230 cli_allow_enable(cli
, p
);
231 LOG(3, 0, 0, 0, "Setting enable password\n");
235 cli_allow_user(cli
, buf
, p
);
236 LOG(3, 0, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
242 memset(&addr
, 0, sizeof(addr
));
243 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
244 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
247 // Set cli fd as non-blocking
248 flags
= fcntl(clifd
, F_GETFL
, 0);
249 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
251 addr
.sin_family
= AF_INET
;
252 addr
.sin_port
= htons(23);
253 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
255 LOG(0, 0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
261 void cli_do(int sockfd
)
263 int require_auth
= 1;
264 struct sockaddr_in addr
;
265 int l
= sizeof(addr
);
267 if (fork_and_close()) return;
268 if (getpeername(sockfd
, (struct sockaddr
*)&addr
, &l
) == 0)
270 LOG(3, 0, 0, 0, "Accepted connection to CLI from %s\n", inet_toa(addr
.sin_addr
.s_addr
));
271 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
274 LOG(0, 0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
278 LOG(3, 0, 0, 0, "CLI is remote, requiring authentication\n");
279 if (!cli
->users
) /* paranoia */
281 LOG(0, 0, 0, 0, "No users for remote authentication! Exiting CLI\n");
287 /* no username/pass required */
294 debug_rb_tail
= ringbuffer
->tail
;
296 memset(&debug_flags
, 0, sizeof(debug_flags
));
297 debug_flags
.critical
= 1;
299 cli_loop(cli
, sockfd
);
302 LOG(3, 0, 0, 0, "Closed CLI connection from %s\n", inet_toa(addr
.sin_addr
.s_addr
));
306 void cli_print_log(struct cli_def
*cli
, char *string
)
308 LOG(3, 0, 0, 0, "%s\n", string
);
311 void cli_do_file(FILE *fh
)
313 LOG(3, 0, 0, 0, "Reading configuration file\n");
314 cli_print_callback(cli
, cli_print_log
);
315 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
316 cli_print_callback(cli
, NULL
);
319 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
330 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
332 int v
= va_arg(ap
, int);
333 snprintf(buf
, sizeof(buf
), entry
, v
);
339 desc
= va_arg(ap
, char *);
341 cli_print(cli
, " %-20s %s", p
, desc
);
343 cli_print(cli
, " %s", p
);
345 entry
= desc
? va_arg(ap
, char *) : 0;
350 cli_print(cli
, " <cr>");
355 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
359 if (CLI_HELP_REQUESTED
)
360 return cli_arg_help(cli
, 1,
361 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
367 // Show individual session
368 for (i
= 0; i
< argc
; i
++)
370 unsigned int s
, b_in
, b_out
;
372 if (s
<= 0 || s
>= MAXSESSION
)
374 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
377 cli_print(cli
, "\r\nSession %d:", s
);
378 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
379 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
380 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
381 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
382 cli_print(cli
, "\tIP address:\t%s", inet_toa(htonl(session
[s
].ip
)));
383 cli_print(cli
, "\tUnique SID:\t%lu", session
[s
].unique_id
);
384 cli_print(cli
, "\tIdle time:\t%u seconds", abs(time_now
- session
[s
].last_packet
));
385 cli_print(cli
, "\tNext Recv:\t%u", session
[s
].nr
);
386 cli_print(cli
, "\tNext Send:\t%u", session
[s
].ns
);
387 cli_print(cli
, "\tBytes In/Out:\t%lu/%lu", (unsigned long)session
[s
].total_cout
, (unsigned long)session
[s
].total_cin
);
388 cli_print(cli
, "\tPkts In/Out:\t%lu/%lu", (unsigned long)session
[s
].pout
, (unsigned long)session
[s
].pin
);
389 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
390 cli_print(cli
, "\tRadius Session:\t%u", session
[s
].radius
);
391 cli_print(cli
, "\tRx Speed:\t%lu", session
[s
].rx_connect_speed
);
392 cli_print(cli
, "\tTx Speed:\t%lu", session
[s
].tx_connect_speed
);
393 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
394 cli_print(cli
, "\tIntercepted:\t%s:%d", inet_toa(session
[s
].snoop_ip
), session
[s
] .snoop_port
);
396 cli_print(cli
, "\tIntercepted:\tno");
398 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
400 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
401 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
402 t
? "YES" : "no", t
? " (" : "",
403 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
405 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
409 b_in
= session
[s
].tbf_in
;
410 b_out
= session
[s
].tbf_out
;
412 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
413 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
414 "ByteSent", "PackSent", "PackDrop", "PackDelay");
417 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
419 (filter_list
[b_in
].next
? "*" : " "),
420 (b_in
< 100 ? "\t" : ""),
421 filter_list
[b_in
].rate
* 8,
422 filter_list
[b_in
].credit
,
423 filter_list
[b_in
].queued
,
424 filter_list
[b_in
].b_queued
,
425 filter_list
[b_in
].p_queued
,
426 filter_list
[b_in
].b_sent
,
427 filter_list
[b_in
].p_sent
,
428 filter_list
[b_in
].p_dropped
,
429 filter_list
[b_in
].p_delayed
);
432 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
434 (filter_list
[b_out
].next
? "*" : " "),
435 (b_out
< 100 ? "\t" : ""),
436 filter_list
[b_out
].rate
* 8,
437 filter_list
[b_out
].credit
,
438 filter_list
[b_out
].queued
,
439 filter_list
[b_out
].b_queued
,
440 filter_list
[b_out
].p_queued
,
441 filter_list
[b_out
].b_sent
,
442 filter_list
[b_out
].p_sent
,
443 filter_list
[b_out
].p_dropped
,
444 filter_list
[b_out
].p_delayed
);
451 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %10s %10s %10s %4s %-15s %s",
466 for (i
= 1; i
< MAXSESSION
; i
++)
468 char *userip
, *tunnelip
;
469 if (!session
[i
].opened
) continue;
470 userip
= strdup(inet_toa(htonl(session
[i
].ip
)));
471 tunnelip
= strdup(inet_toa(htonl(tunnel
[ session
[i
].tunnel
].ip
)));
472 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %10u %10lu %10lu %4u %-15s %s",
475 session
[i
].user
[0] ? session
[i
].user
: "*",
477 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
478 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
479 (session
[i
].walled_garden
) ? "Y" : "N",
480 abs(time_now
- (unsigned long)session
[i
].opened
),
481 (unsigned long)session
[i
].total_cout
,
482 (unsigned long)session
[i
].total_cin
,
483 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
485 session
[i
].calling
[0] ? session
[i
].calling
: "*");
486 if (userip
) free(userip
);
487 if (tunnelip
) free(tunnelip
);
492 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
494 int i
, x
, show_all
= 0;
502 if (CLI_HELP_REQUESTED
)
505 return cli_arg_help(cli
, 1,
506 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
509 return cli_arg_help(cli
, 1,
510 "all", "Show all tunnels, including unused",
511 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
518 if (strcmp(argv
[0], "all") == 0)
524 // Show individual tunnel
525 for (i
= 0; i
< argc
; i
++)
530 if (t
<= 0 || t
>= MAXTUNNEL
)
532 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
535 cli_print(cli
, "\r\nTunnel %d:", t
);
536 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
537 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
538 cli_print(cli
, "\tRemote IP:\t%s", inet_toa(htonl(tunnel
[t
].ip
)));
539 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
540 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
541 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
542 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
543 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
544 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
546 for (x
= 0; x
< MAXSESSION
; x
++)
547 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
548 sprintf(s
, "%s%u ", s
, x
);
550 cli_print(cli
, "\tSessions:\t%s", s
);
556 // Show tunnel summary
557 cli_print(cli
, "%4s %20s %20s %6s %s",
564 for (i
= 1; i
< MAXTUNNEL
; i
++)
567 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
569 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
570 cli_print(cli
, "%4d %20s %20s %6s %6d",
572 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
573 inet_toa(htonl(tunnel
[i
].ip
)),
574 states
[tunnel
[i
].state
],
581 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
588 if (CLI_HELP_REQUESTED
)
589 return cli_arg_help(cli
, 1,
590 "USER", "Show details for specific username",
593 for (i
= 0; i
< MAXSESSION
; i
++)
595 if (!session
[i
].opened
) continue;
596 if (!session
[i
].user
[0]) continue;
600 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
602 if (strcmp(argv
[j
], session
[i
].user
) == 0)
604 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
605 sargv
[sargc
] = sid
[sargc
];
613 cli_print(cli
, "%s", session
[i
].user
);
617 return cmd_show_session(cli
, "users", sargv
, sargc
);
622 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
624 if (CLI_HELP_REQUESTED
)
625 return CLI_HELP_NO_ARGS
;
627 cli_print(cli
, "%-10s %-8s %-10s %-8s", "Ethernet", "Bytes", "Packets", "Errors");
628 cli_print(cli
, "%-10s %8lu %8lu %8lu", "RX",
629 GET_STAT(tun_rx_bytes
),
630 GET_STAT(tun_rx_packets
),
631 GET_STAT(tun_rx_errors
));
632 cli_print(cli
, "%-10s %8lu %8lu %8lu", "TX",
633 GET_STAT(tun_tx_bytes
),
634 GET_STAT(tun_tx_packets
),
635 GET_STAT(tun_tx_errors
));
638 cli_print(cli
, "%-10s %-8s %-10s %-8s %-8s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
639 cli_print(cli
, "%-10s %8lu %8lu %8lu %8lu", "RX",
640 GET_STAT(tunnel_rx_bytes
),
641 GET_STAT(tunnel_rx_packets
),
642 GET_STAT(tunnel_rx_errors
),
644 cli_print(cli
, "%-10s %8lu %8lu %8lu %8lu", "TX",
645 GET_STAT(tunnel_tx_bytes
),
646 GET_STAT(tunnel_tx_packets
),
647 GET_STAT(tunnel_tx_errors
),
648 GET_STAT(tunnel_retries
));
651 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
652 cli_print(cli
, "-----------------------------------------");
653 cli_print(cli
, "%-30s%lu", "radius_retries", GET_STAT(radius_retries
));
654 cli_print(cli
, "%-30s%lu", "arp_sent", GET_STAT(arp_sent
));
655 cli_print(cli
, "%-30s%lu", "packets_snooped", GET_STAT(packets_snooped
));
656 cli_print(cli
, "%-30s%lu", "tunnel_created", GET_STAT(tunnel_created
));
657 cli_print(cli
, "%-30s%lu", "session_created", GET_STAT(session_created
));
658 cli_print(cli
, "%-30s%lu", "tunnel_timeout", GET_STAT(tunnel_timeout
));
659 cli_print(cli
, "%-30s%lu", "session_timeout", GET_STAT(session_timeout
));
660 cli_print(cli
, "%-30s%lu", "radius_timeout", GET_STAT(radius_timeout
));
661 cli_print(cli
, "%-30s%lu", "radius_overflow", GET_STAT(radius_overflow
));
662 cli_print(cli
, "%-30s%lu", "tunnel_overflow", GET_STAT(tunnel_overflow
));
663 cli_print(cli
, "%-30s%lu", "session_overflow", GET_STAT(session_overflow
));
664 cli_print(cli
, "%-30s%lu", "ip_allocated", GET_STAT(ip_allocated
));
665 cli_print(cli
, "%-30s%lu", "ip_freed", GET_STAT(ip_freed
));
666 cli_print(cli
, "%-30s%lu", "cluster_forwarded", GET_STAT(c_forwarded
));
667 cli_print(cli
, "%-30s%lu", "recv_forward", GET_STAT(recv_forward
));
671 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
672 cli_print(cli
, "-----------------------------------------");
673 cli_print(cli
, "%-30s%lu", "call_processtun", GET_STAT(call_processtun
));
674 cli_print(cli
, "%-30s%lu", "call_processipout", GET_STAT(call_processipout
));
675 cli_print(cli
, "%-30s%lu", "call_processudp", GET_STAT(call_processudp
));
676 cli_print(cli
, "%-30s%lu", "call_processpap", GET_STAT(call_processpap
));
677 cli_print(cli
, "%-30s%lu", "call_processchap", GET_STAT(call_processchap
));
678 cli_print(cli
, "%-30s%lu", "call_processlcp", GET_STAT(call_processlcp
));
679 cli_print(cli
, "%-30s%lu", "call_processipcp", GET_STAT(call_processipcp
));
680 cli_print(cli
, "%-30s%lu", "call_processipin", GET_STAT(call_processipin
));
681 cli_print(cli
, "%-30s%lu", "call_processccp", GET_STAT(call_processccp
));
682 cli_print(cli
, "%-30s%lu", "call_processrad", GET_STAT(call_processrad
));
683 cli_print(cli
, "%-30s%lu", "call_sendarp", GET_STAT(call_sendarp
));
684 cli_print(cli
, "%-30s%lu", "call_sendipcp", GET_STAT(call_sendipcp
));
685 cli_print(cli
, "%-30s%lu", "call_sendchap", GET_STAT(call_sendchap
));
686 cli_print(cli
, "%-30s%lu", "call_sessionbyip", GET_STAT(call_sessionbyip
));
687 cli_print(cli
, "%-30s%lu", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
688 cli_print(cli
, "%-30s%lu", "call_tunnelsend", GET_STAT(call_tunnelsend
));
689 cli_print(cli
, "%-30s%lu", "call_tunnelkill", GET_STAT(call_tunnelkill
));
690 cli_print(cli
, "%-30s%lu", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
691 cli_print(cli
, "%-30s%lu", "call_sessionkill", GET_STAT(call_sessionkill
));
692 cli_print(cli
, "%-30s%lu", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
693 cli_print(cli
, "%-30s%lu", "call_sessionsetup", GET_STAT(call_sessionsetup
));
694 cli_print(cli
, "%-30s%lu", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
695 cli_print(cli
, "%-30s%lu", "call_free_ip_address", GET_STAT(call_free_ip_address
));
696 cli_print(cli
, "%-30s%lu", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
697 cli_print(cli
, "%-30s%lu", "call_radiussend", GET_STAT(call_radiussend
));
698 cli_print(cli
, "%-30s%lu", "call_radiusretry", GET_STAT(call_radiusretry
));
703 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
709 if (CLI_HELP_REQUESTED
)
710 return cli_arg_help(cli
, 1,
711 "tag", "Include CVS release tag",
712 "file", "Include file versions",
715 for (i
= 0; i
< argc
; i
++)
716 if (!strcmp(argv
[i
], "tag"))
718 else if (!strcmp(argv
[i
], "file"))
721 cli_print(cli
, "L2TPNS %s", VERSION
);
724 char const *p
= strchr(cvs_name
, ':');
736 e
= strpbrk(p
, " \t$");
737 cli_print(cli
, "Tag: %.*s", e
? e
- p
+ 1 : strlen(p
), p
);
742 extern linked_list
*loaded_plugins
;
745 cli_print(cli
, "Files:");
746 cli_print(cli
, " %s", cvs_id_arp
);
748 cli_print(cli
, " %s", cvs_id_bgp
);
750 cli_print(cli
, " %s", cvs_id_cli
);
751 cli_print(cli
, " %s", cvs_id_cluster
);
752 cli_print(cli
, " %s", cvs_id_constants
);
753 cli_print(cli
, " %s", cvs_id_control
);
754 cli_print(cli
, " %s", cvs_id_icmp
);
755 cli_print(cli
, " %s", cvs_id_l2tpns
);
756 cli_print(cli
, " %s", cvs_id_ll
);
757 cli_print(cli
, " %s", cvs_id_md5
);
758 cli_print(cli
, " %s", cvs_id_ppp
);
759 cli_print(cli
, " %s", cvs_id_radius
);
760 cli_print(cli
, " %s", cvs_id_tbf
);
761 cli_print(cli
, " %s", cvs_id_util
);
763 ll_reset(loaded_plugins
);
764 while ((p
= ll_next(loaded_plugins
)))
766 char const **id
= dlsym(p
, "cvs_id");
768 cli_print(cli
, " %s", *id
);
775 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
778 int used
= 0, free
= 0, show_all
= 0;
780 if (!config
->cluster_iam_master
)
782 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
786 if (CLI_HELP_REQUESTED
)
789 return cli_arg_help(cli
, 1, NULL
);
791 return cli_arg_help(cli
, 1,
792 "all", "Show all pool addresses, including unused",
796 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
800 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
801 for (i
= 0; i
< MAXIPPOOL
; i
++)
803 if (!ip_address_pool
[i
].address
) continue;
804 if (ip_address_pool
[i
].assigned
)
806 cli_print(cli
, "%-15s\tY %8d %s",
807 inet_toa(htonl(ip_address_pool
[i
].address
)), ip_address_pool
[i
].session
, session
[ip_address_pool
[i
].session
].user
);
813 if (ip_address_pool
[i
].last
)
814 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
815 inet_toa(htonl(ip_address_pool
[i
].address
)), "",
816 ip_address_pool
[i
].user
, time_now
- ip_address_pool
[i
].last
);
818 cli_print(cli
, "%-15s\tN", inet_toa(htonl(ip_address_pool
[i
].address
)));
825 cli_print(cli
, "(Not displaying unused addresses)");
827 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
831 void print_save_config(struct cli_def
*cli
, char *string
)
834 fprintf(save_config_fh
, "%s\n", string
);
837 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
839 if (CLI_HELP_REQUESTED
)
840 return CLI_HELP_NO_ARGS
;
842 if ((save_config_fh
= fopen(config
->config_file
, "w")))
844 cli_print(cli
, "Writing configuration");
845 cli_print_callback(cli
, print_save_config
);
846 cmd_show_run(cli
, command
, argv
, argc
);
847 cli_print_callback(cli
, NULL
);
848 fclose(save_config_fh
);
852 cli_print(cli
, "Error writing configuration: %s", strerror(errno
));
857 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
861 if (CLI_HELP_REQUESTED
)
862 return CLI_HELP_NO_ARGS
;
864 cli_print(cli
, "# Current configuration:");
866 for (i
= 0; config_values
[i
].key
; i
++)
868 void *value
= ((void *)config
) + config_values
[i
].offset
;
869 if (config_values
[i
].type
== STRING
)
870 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *)value
);
871 else if (config_values
[i
].type
== IP
)
872 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_toa(*(unsigned *)value
));
873 else if (config_values
[i
].type
== SHORT
)
874 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *)value
);
875 else if (config_values
[i
].type
== BOOL
)
876 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *)value
) ? "yes" : "no");
877 else if (config_values
[i
].type
== INT
)
878 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *)value
);
879 else if (config_values
[i
].type
== UNSIGNED_LONG
)
880 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *)value
);
881 else if (config_values
[i
].type
== MAC
)
882 cli_print(cli
, "set %s %02x%02x.%02x%02x.%02x%02x", config_values
[i
].key
,
883 *(unsigned short *)(value
+ 0),
884 *(unsigned short *)(value
+ 1),
885 *(unsigned short *)(value
+ 2),
886 *(unsigned short *)(value
+ 3),
887 *(unsigned short *)(value
+ 4),
888 *(unsigned short *)(value
+ 5));
891 cli_print(cli
, "# Plugins");
892 for (i
= 0; i
< MAXPLUGINS
; i
++)
894 if (*config
->plugins
[i
])
896 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
901 if (config
->as_number
)
906 cli_print(cli
, "# BGP");
907 cli_print(cli
, "router bgp %u", config
->as_number
);
908 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
910 if (!config
->neighbour
[i
].name
[0])
913 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
915 k
= config
->neighbour
[i
].keepalive
;
916 h
= config
->neighbour
[i
].hold
;
923 k
= BGP_KEEPALIVE_TIME
;
929 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
934 cli_print(cli
, "# end");
938 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
940 int i
, free
= 0, used
= 0, show_all
= 0;
951 if (CLI_HELP_REQUESTED
)
954 return cli_arg_help(cli
, 1, NULL
);
956 return cli_arg_help(cli
, 1,
957 "all", "Show all RADIUS sessions, including unused",
961 cli_print(cli
, "%6s%6s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
965 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
968 for (i
= 1; i
< MAXRADIUS
; i
++)
970 if (radius
[i
].state
== RADIUSNULL
)
975 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
977 cli_print(cli
, "%6d%6d%5d%6s%9d%9u%4d",
981 states
[radius
[i
].state
],
987 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
992 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
996 if (CLI_HELP_REQUESTED
)
997 return CLI_HELP_NO_ARGS
;
999 cli_print(cli
, "Plugins currently loaded:");
1000 for (i
= 0; i
< MAXPLUGINS
; i
++)
1001 if (*config
->plugins
[i
])
1002 cli_print(cli
, " %s", config
->plugins
[i
]);
1007 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1011 if (CLI_HELP_REQUESTED
)
1012 return CLI_HELP_NO_ARGS
;
1014 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1023 for (i
= 0; i
< MAXSESSION
; i
++)
1025 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1026 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1030 session
[i
].throttle_in
,
1031 session
[i
].throttle_out
,
1033 session
[i
].tbf_out
);
1039 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1041 if (CLI_HELP_REQUESTED
)
1042 return CLI_HELP_NO_ARGS
;
1044 cli_print(cli
, " _\n"
1050 " ( \\ `. `-. _,.-:\\\n"
1051 " \\ \\ `. `-._ __..--' ,-';/\n"
1052 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1053 " `. `. `-._ __..--' ,' /\n"
1054 " `. `-_ ``--..'' _.-' ,'\n"
1055 " `-_ `-.___ __,--' ,'\n"
1056 " `-.__ `----\"\"\" __.-'\n"
1057 "hh `--..____..--'");
1062 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1064 if (CLI_HELP_REQUESTED
)
1065 return CLI_HELP_NO_ARGS
;
1067 cli_print(cli
, "Counters cleared");
1068 SET_STAT(last_reset
, time(NULL
));
1072 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1077 if (CLI_HELP_REQUESTED
)
1078 return cli_arg_help(cli
, argc
> 1,
1079 "USER", "Username of session to drop", NULL
);
1081 if (!config
->cluster_iam_master
)
1083 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1089 cli_print(cli
, "Specify a user to drop");
1093 for (i
= 0; i
< argc
; i
++)
1095 if (!(s
= sessionbyuser(argv
[i
])))
1097 cli_print(cli
, "User %s is not connected", argv
[i
]);
1101 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1103 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1104 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1111 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1116 if (CLI_HELP_REQUESTED
)
1117 return cli_arg_help(cli
, argc
> 1,
1118 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1120 if (!config
->cluster_iam_master
)
1122 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1128 cli_print(cli
, "Specify a tunnel to drop");
1132 for (i
= 0; i
< argc
; i
++)
1134 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1136 cli_print(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1142 cli_print(cli
, "Tunnel %d is not connected", t
);
1148 cli_print(cli
, "Tunnel %d is already being shut down", t
);
1152 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1153 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1159 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1164 if (CLI_HELP_REQUESTED
)
1165 return cli_arg_help(cli
, argc
> 1,
1166 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1168 if (!config
->cluster_iam_master
)
1170 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1176 cli_print(cli
, "Specify a session id to drop");
1180 for (i
= 0; i
< argc
; i
++)
1182 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1184 cli_print(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1188 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1190 cli_print(cli
, "Dropping session %d", s
);
1191 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1195 cli_print(cli
, "Session %d is not active.", s
);
1202 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1208 if (CLI_HELP_REQUESTED
)
1213 return cli_arg_help(cli
, 0,
1214 "USER", "Username of session to snoop", NULL
);
1217 return cli_arg_help(cli
, 0,
1218 "A.B.C.D", "IP address of snoop destination", NULL
);
1221 return cli_arg_help(cli
, 0,
1222 "N", "Port of snoop destination", NULL
);
1226 return cli_arg_help(cli
, 1, NULL
);
1233 if (!config
->cluster_iam_master
)
1235 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1241 cli_print(cli
, "Specify username, ip and port");
1245 if (!(s
= sessionbyuser(argv
[0])))
1247 cli_print(cli
, "User %s is not connected", argv
[0]);
1251 ip
= inet_addr(argv
[1]);
1252 if (!ip
|| ip
== INADDR_NONE
)
1254 cli_print(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1258 port
= atoi(argv
[2]);
1261 cli_print(cli
, "Invalid port %s", argv
[2]);
1265 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], inet_toa(ip
), port
);
1266 cli_session_actions
[s
].snoop_ip
= ip
;
1267 cli_session_actions
[s
].snoop_port
= port
;
1268 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1273 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1278 if (CLI_HELP_REQUESTED
)
1279 return cli_arg_help(cli
, argc
> 1,
1280 "USER", "Username of session to unsnoop", NULL
);
1282 if (!config
->cluster_iam_master
)
1284 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1290 cli_print(cli
, "Specify a user to unsnoop");
1294 for (i
= 0; i
< argc
; i
++)
1296 if (!(s
= sessionbyuser(argv
[i
])))
1298 cli_print(cli
, "User %s is not connected", argv
[i
]);
1302 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1303 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1309 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1316 throttle USER - throttle in/out to default rate
1317 throttle USER RATE - throttle in/out to default rate
1318 throttle USER in RATE - throttle input only
1319 throttle USER out RATE - throttle output only
1320 throttle USER in RATE out RATE - throttle both
1323 if (CLI_HELP_REQUESTED
)
1328 return cli_arg_help(cli
, 0,
1329 "USER", "Username of session to throttle", NULL
);
1332 return cli_arg_help(cli
, 1,
1333 "RATE", "Rate in kbps (in and out)",
1334 "in", "Select incoming rate",
1335 "out", "Select outgoing rate", NULL
);
1338 return cli_arg_help(cli
, 1,
1339 "in", "Select incoming rate",
1340 "out", "Select outgoing rate", NULL
);
1343 if (isdigit(argv
[1][0]))
1344 return cli_arg_help(cli
, 1, NULL
);
1347 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1350 return cli_arg_help(cli
, argc
> 1, NULL
);
1354 if (!config
->cluster_iam_master
)
1356 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1362 cli_print(cli
, "Specify a user to throttle");
1366 if (!(s
= sessionbyuser(argv
[0])))
1368 cli_print(cli
, "User %s is not connected", argv
[0]);
1374 rate_in
= rate_out
= config
->rl_rate
;
1378 rate_in
= rate_out
= atoi(argv
[1]);
1381 cli_print(cli
, "Invalid rate \"%s\"", argv
[1]);
1385 else if (argc
== 3 || argc
== 5)
1388 for (i
= 1; i
< argc
- 1; i
+= 2)
1390 int len
= strlen(argv
[i
]);
1392 if (!strncasecmp(argv
[i
], "in", len
))
1393 r
= rate_in
= atoi(argv
[i
+1]);
1394 else if (!strncasecmp(argv
[i
], "out", len
))
1395 r
= rate_out
= atoi(argv
[i
+1]);
1399 cli_print(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1406 cli_print(cli
, "Invalid arguments");
1410 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1412 cli_print(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1416 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1417 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1418 cli_session_actions
[s
].throttle_in
= rate_in
;
1420 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1421 cli_session_actions
[s
].throttle_out
= rate_out
;
1423 if (cli_session_actions
[s
].throttle_in
== -1 &&
1424 cli_session_actions
[s
].throttle_out
== -1)
1426 cli_print(cli
, "User %s already throttled at this rate", argv
[0]);
1430 cli_print(cli
, "Throttling user %s", argv
[0]);
1431 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1436 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1441 if (CLI_HELP_REQUESTED
)
1442 return cli_arg_help(cli
, argc
> 1,
1443 "USER", "Username of session to unthrottle", NULL
);
1445 if (!config
->cluster_iam_master
)
1447 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1453 cli_print(cli
, "Specify a user to unthrottle");
1457 for (i
= 0; i
< argc
; i
++)
1459 if (!(s
= sessionbyuser(argv
[i
])))
1461 cli_print(cli
, "User %s is not connected", argv
[i
]);
1465 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1467 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1468 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1472 cli_print(cli
, "User %s not throttled", argv
[i
]);
1479 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1483 if (CLI_HELP_REQUESTED
)
1484 return cli_arg_help(cli
, 1,
1485 "all", "Enable debugging for all except \"data\"",
1486 "critical", "", // FIXME: add descriptions
1496 char *p
= (char *) &debug_flags
;
1497 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1501 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1502 (debug_flags
.critical
) ? " critical" : "",
1503 (debug_flags
.error
) ? " error" : "",
1504 (debug_flags
.warning
) ? " warning" : "",
1505 (debug_flags
.info
) ? " info" : "",
1506 (debug_flags
.calls
) ? " calls" : "",
1507 (debug_flags
.data
) ? " data" : "");
1513 cli_print(cli
, "Debugging off");
1517 for (i
= 0; i
< argc
; i
++)
1519 int len
= strlen(argv
[i
]);
1521 if (argv
[i
][0] == 'c' && len
< 2)
1522 len
= 2; /* distinguish [cr]itical from [ca]lls */
1524 if (!strncasecmp(argv
[i
], "critical", len
)) { debug_flags
.critical
= 1; continue; }
1525 if (!strncasecmp(argv
[i
], "error", len
)) { debug_flags
.error
= 1; continue; }
1526 if (!strncasecmp(argv
[i
], "warning", len
)) { debug_flags
.warning
= 1; continue; }
1527 if (!strncasecmp(argv
[i
], "info", len
)) { debug_flags
.info
= 1; continue; }
1528 if (!strncasecmp(argv
[i
], "calls", len
)) { debug_flags
.calls
= 1; continue; }
1529 if (!strncasecmp(argv
[i
], "data", len
)) { debug_flags
.data
= 1; continue; }
1530 if (!strncasecmp(argv
[i
], "all", len
))
1532 memset(&debug_flags
, 1, sizeof(debug_flags
));
1533 debug_flags
.data
= 0;
1537 cli_print(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1543 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1547 if (CLI_HELP_REQUESTED
)
1548 return cli_arg_help(cli
, 1,
1549 "all", "Disable all debugging",
1550 "critical", "", // FIXME: add descriptions
1560 memset(&debug_flags
, 0, sizeof(debug_flags
));
1564 for (i
= 0; i
< argc
; i
++)
1566 int len
= strlen(argv
[i
]);
1568 if (argv
[i
][0] == 'c' && len
< 2)
1569 len
= 2; /* distinguish [cr]itical from [ca]lls */
1571 if (!strncasecmp(argv
[i
], "critical", len
)) { debug_flags
.critical
= 0; continue; }
1572 if (!strncasecmp(argv
[i
], "error", len
)) { debug_flags
.error
= 0; continue; }
1573 if (!strncasecmp(argv
[i
], "warning", len
)) { debug_flags
.warning
= 0; continue; }
1574 if (!strncasecmp(argv
[i
], "info", len
)) { debug_flags
.info
= 0; continue; }
1575 if (!strncasecmp(argv
[i
], "calls", len
)) { debug_flags
.calls
= 0; continue; }
1576 if (!strncasecmp(argv
[i
], "data", len
)) { debug_flags
.data
= 0; continue; }
1577 if (!strncasecmp(argv
[i
], "all", len
))
1579 memset(&debug_flags
, 0, sizeof(debug_flags
));
1583 cli_print(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1589 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1591 int i
, firstfree
= 0;
1593 if (CLI_HELP_REQUESTED
)
1594 return cli_arg_help(cli
, argc
> 1,
1595 "PLUGIN", "Name of plugin to load", NULL
);
1599 cli_print(cli
, "Specify a plugin to load");
1603 for (i
= 0; i
< MAXPLUGINS
; i
++)
1605 if (!*config
->plugins
[i
] && !firstfree
)
1607 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1609 cli_print(cli
, "Plugin is already loaded");
1616 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1617 config
->reload_config
= 1;
1618 cli_print(cli
, "Loading plugin %s", argv
[0]);
1624 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1628 if (CLI_HELP_REQUESTED
)
1629 return cli_arg_help(cli
, argc
> 1,
1630 "PLUGIN", "Name of plugin to unload", NULL
);
1634 cli_print(cli
, "Specify a plugin to remove");
1638 for (i
= 0; i
< MAXPLUGINS
; i
++)
1640 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1642 config
->reload_config
= 1;
1643 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1648 cli_print(cli
, "Plugin is not loaded");
1652 char *duration(time_t secs
)
1654 static char *buf
= NULL
;
1657 if (!buf
) buf
= calloc(64, 1);
1661 int days
= secs
/ 86400;
1662 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1668 int mins
= secs
/ 60;
1669 int hrs
= mins
/ 60;
1672 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1674 else if (secs
>= 60)
1676 int mins
= secs
/ 60;
1677 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1680 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1685 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1688 char buf
[100], *p
= buf
, *loads
[3];
1689 int i
, num_sessions
= 0;
1691 if (CLI_HELP_REQUESTED
)
1692 return CLI_HELP_NO_ARGS
;
1694 fh
= fopen("/proc/loadavg", "r");
1695 fgets(buf
, 100, fh
);
1698 for (i
= 0; i
< 3; i
++)
1699 loads
[i
] = strdup(strsep(&p
, " "));
1702 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1704 for (i
= 1; i
< MAXSESSION
; i
++)
1705 if (session
[i
].opened
) num_sessions
++;
1707 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1709 duration(time_now
- config
->start_time
),
1711 loads
[0], loads
[1], loads
[2]
1713 for (i
= 0; i
< 3; i
++)
1714 if (loads
[i
]) free(loads
[i
]);
1716 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1721 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1725 if (CLI_HELP_REQUESTED
)
1731 int len
= strlen(argv
[0])-1;
1732 for (i
= 0; config_values
[i
].key
; i
++)
1733 if (!len
|| !strncmp(argv
[0], config_values
[i
].key
, len
))
1734 cli_print(cli
, " %s", config_values
[i
].key
);
1740 return cli_arg_help(cli
, 0,
1741 "VALUE", "Value for variable", NULL
);
1745 return cli_arg_help(cli
, 1, NULL
);
1754 cli_print(cli
, "Specify variable and value");
1758 for (i
= 0; config_values
[i
].key
; i
++)
1760 void *value
= ((void *)config
) + config_values
[i
].offset
;
1761 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1763 // Found a value to set
1764 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1765 switch (config_values
[i
].type
)
1768 strncpy((char *)value
, argv
[1], config_values
[i
].size
- 1);
1771 *(int *)value
= atoi(argv
[1]);
1774 *(unsigned long *)value
= atol(argv
[1]);
1777 *(short *)value
= atoi(argv
[1]);
1780 *(unsigned *)value
= inet_addr(argv
[1]);
1783 parsemac(argv
[1], (char *)value
);
1786 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1792 cli_print(cli
, "Unknown variable type");
1795 config
->reload_config
= 1;
1800 cli_print(cli
, "Unknown variable \"%s\"", argv
[0]);
1804 int regular_stuff(struct cli_def
*cli
)
1806 int i
= debug_rb_tail
;
1810 while (i
!= ringbuffer
->tail
)
1812 int show_message
= 0;
1814 if (*ringbuffer
->buffer
[i
].message
)
1816 // Always show messages if we are doing general debug
1817 if (ringbuffer
->buffer
[i
].level
== 0 && debug_flags
.critical
) show_message
= 1;
1818 if (ringbuffer
->buffer
[i
].level
== 1 && debug_flags
.error
) show_message
= 1;
1819 if (ringbuffer
->buffer
[i
].level
== 2 && debug_flags
.warning
) show_message
= 1;
1820 if (ringbuffer
->buffer
[i
].level
== 3 && debug_flags
.info
) show_message
= 1;
1821 if (ringbuffer
->buffer
[i
].level
== 4 && debug_flags
.calls
) show_message
= 1;
1822 if (ringbuffer
->buffer
[i
].level
== 5 && debug_flags
.data
) show_message
= 1;
1827 ipt address
= htonl(ringbuffer
->buffer
[i
].address
);
1829 struct in_addr addr
;
1831 memcpy(&addr
, &address
, sizeof(ringbuffer
->buffer
[i
].address
));
1832 ipaddr
= inet_ntoa(addr
);
1834 cli_print(cli
, "\r%s-%s-%u-%u %s",
1835 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1837 ringbuffer
->buffer
[i
].tunnel
,
1838 ringbuffer
->buffer
[i
].session
,
1839 ringbuffer
->buffer
[i
].message
);
1844 if (++i
== ringbuffer
->tail
) break;
1845 if (i
== RINGBUFFER_SIZE
) i
= 0;
1848 debug_rb_tail
= ringbuffer
->tail
;
1856 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1860 if (CLI_HELP_REQUESTED
)
1861 return cli_arg_help(cli
, argc
> 1,
1862 "<1-65535>", "Autonomous system number", NULL
);
1864 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1866 cli_print(cli
, "Invalid autonomous system number");
1870 if (bgp_configured
&& as
!= config
->as_number
)
1872 cli_print(cli
, "Can't change local AS on a running system");
1876 config
->as_number
= as
;
1877 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1882 static int cmd_router_bgp_exit(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1884 if (CLI_HELP_REQUESTED
)
1885 return CLI_HELP_NO_ARGS
;
1887 cli_set_configmode(cli
, MODE_CONFIG
, NULL
);
1891 static int find_bgp_neighbour(char *name
)
1896 in_addr_t addrs
[4] = { 0 };
1899 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1902 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1903 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1905 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1907 if (!config
->neighbour
[i
].name
[0])
1909 if (new == -1) new = i
;
1913 if (!strcmp(name
, config
->neighbour
[i
].name
))
1916 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
1919 for (a
= h
->h_addr_list
; *a
; a
++)
1922 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
1923 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
1931 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1937 if (CLI_HELP_REQUESTED
)
1942 return cli_arg_help(cli
, 0,
1943 "A.B.C.D", "BGP neighbour address",
1944 "NAME", "BGP neighbour name",
1948 return cli_arg_help(cli
, 0,
1949 "remote-as", "Set remote autonomous system number",
1950 "timers", "Set timers",
1954 if (!strncmp("remote-as", argv
[1], strlen(argv
[1])))
1955 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
1957 if (!strncmp("timers", argv
[1], strlen(argv
[1])))
1960 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
1963 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
1965 if (argc
== 5 && !argv
[4][1])
1966 return cli_arg_help(cli
, 1, NULL
);
1975 cli_print(cli
, "Invalid arguments");
1979 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
1981 cli_print(cli
, "Invalid neighbour");
1987 cli_print(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
1991 if (!strncmp("remote-as", argv
[1], strlen(argv
[1])))
1993 int as
= atoi(argv
[2]);
1994 if (as
< 0 || as
> 65535)
1996 cli_print(cli
, "Invalid autonomous system number");
2000 if (!config
->neighbour
[i
].name
[0])
2002 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), argv
[0]);
2003 config
->neighbour
[i
].keepalive
= -1;
2004 config
->neighbour
[i
].hold
= -1;
2007 config
->neighbour
[i
].as
= as
;
2011 if (argc
!= 4 || strncmp("timers", argv
[1], strlen(argv
[1])))
2013 cli_print(cli
, "Invalid arguments");
2017 if (!config
->neighbour
[i
].name
[0])
2019 cli_print(cli
, "Specify remote-as first");
2023 keepalive
= atoi(argv
[2]);
2024 hold
= atoi(argv
[3]);
2026 if (keepalive
< 1 || keepalive
> 65535)
2028 cli_print(cli
, "Invalid keepalive time");
2032 if (hold
< 3 || hold
> 65535)
2034 cli_print(cli
, "Invalid hold time");
2038 if (keepalive
== BGP_KEEPALIVE_TIME
)
2039 keepalive
= -1; // using default value
2041 if (hold
== BGP_HOLD_TIME
)
2044 config
->neighbour
[i
].keepalive
= keepalive
;
2045 config
->neighbour
[i
].hold
= hold
;
2050 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2054 if (CLI_HELP_REQUESTED
)
2055 return cli_arg_help(cli
, argc
> 0,
2056 "A.B.C.D", "BGP neighbour address",
2057 "NAME", "BGP neighbour name",
2062 cli_print(cli
, "Specify a BGP neighbour");
2066 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2068 cli_print(cli
, "Invalid neighbour");
2072 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2074 cli_print(cli
, "Neighbour %s not configured", argv
[0]);
2078 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2082 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2088 if (!bgp_configured
)
2091 if (CLI_HELP_REQUESTED
)
2092 return cli_arg_help(cli
, 1,
2093 "A.B.C.D", "BGP neighbour address",
2094 "NAME", "BGP neighbour name",
2097 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2098 BGP_VERSION
, inet_toa(my_address
), (int) config
->as_number
);
2102 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2104 if (!*bgp_peers
[i
].name
)
2107 addr
= inet_toa(bgp_peers
[i
].addr
);
2108 if (argc
&& strcmp(addr
, argv
[0]) &&
2109 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2115 cli_print(cli
, "Peer AS Address "
2116 "State Retries Retry in Route Pend Timers");
2117 cli_print(cli
, "------------------ ----- --------------- "
2118 "----------- ------- -------- ----- ---- ---------");
2121 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7ds %5s %4s %4d %4d",
2125 bgp_state_str(bgp_peers
[i
].state
),
2126 bgp_peers
[i
].retry_count
,
2127 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2128 bgp_peers
[i
].routing
? "yes" : "no",
2129 bgp_peers
[i
].update_routes
? "yes" : "no",
2130 bgp_peers
[i
].keepalive
,
2137 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2142 if (!bgp_configured
)
2145 if (CLI_HELP_REQUESTED
)
2146 return cli_arg_help(cli
, 1,
2147 "A.B.C.D", "BGP neighbour address",
2148 "NAME", "BGP neighbour name",
2151 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2153 if (bgp_peers
[i
].state
!= Established
)
2156 if (!bgp_peers
[i
].routing
)
2159 addr
= inet_toa(bgp_peers
[i
].addr
);
2160 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2163 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2164 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2170 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2175 if (!bgp_configured
)
2178 if (CLI_HELP_REQUESTED
)
2179 return cli_arg_help(cli
, 1,
2180 "A.B.C.D", "BGP neighbour address",
2181 "NAME", "BGP neighbour name",
2184 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2186 if (bgp_peers
[i
].state
!= Established
)
2189 if (bgp_peers
[i
].routing
)
2192 addr
= inet_toa(bgp_peers
[i
].addr
);
2193 if (argc
&& strcmp(addr
, argv
[0]) &&
2194 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2197 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2198 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2204 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2209 if (!bgp_configured
)
2212 if (CLI_HELP_REQUESTED
)
2213 return cli_arg_help(cli
, 1,
2214 "A.B.C.D", "BGP neighbour address",
2215 "NAME", "BGP neighbour name",
2218 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2220 if (!*bgp_peers
[i
].name
)
2223 addr
= inet_toa(bgp_peers
[i
].addr
);
2224 if (argc
&& strcmp(addr
, argv
[0]) &&
2225 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2228 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2229 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2236 // Convert a string in the form of abcd.ef12.3456 into char[6]
2237 void parsemac(char *string
, char mac
[6])
2239 if (sscanf(string
, "%02x%02x.%02x%02x.%02x%02x", (unsigned int *)&mac
[0], (unsigned int *)&mac
[1], (unsigned int *)&mac
[2], (unsigned int *)&mac
[3], (unsigned int *)&mac
[4], (unsigned int *)&mac
[5]) == 6)
2241 if (sscanf(string
, "%02x%02x:%02x%02x:%02x%02x", (unsigned int *)&mac
[0], (unsigned int *)&mac
[1], (unsigned int *)&mac
[2], (unsigned int *)&mac
[3], (unsigned int *)&mac
[4], (unsigned int *)&mac
[5]) == 6)