1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.28 2004/11/16 07:54:32 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 static struct cli_def
*cli
= NULL
;
41 extern struct configt
*config
;
42 extern struct config_descriptt config_values
[];
44 extern struct Tringbuffer
*ringbuffer
;
46 extern struct cli_session_actions
*cli_session_actions
;
47 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
48 extern tbft
*filter_list
;
50 static char *debug_levels
[] = {
69 static int debug_session
;
70 static int debug_tunnel
;
71 static int debug_rb_tail
;
73 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
74 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
75 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
76 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
77 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
78 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
79 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int regular_stuff(struct cli_def
*cli
);
100 static void parsemac(char *string
, char mac
[6]);
103 #define MODE_CONFIG_BGP 8
104 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
105 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
106 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
108 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
109 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
110 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
113 void init_cli(char *hostname
)
117 struct cli_command
*c
;
118 struct cli_command
*c2
;
120 struct sockaddr_in addr
;
123 if (hostname
&& *hostname
)
124 cli_set_hostname(cli
, hostname
);
126 cli_set_hostname(cli
, "l2tpns");
128 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
129 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
131 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
133 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
134 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
135 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
136 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
137 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
138 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
139 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
140 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
141 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
142 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
143 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");
144 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
146 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
147 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
148 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
151 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
153 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
154 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
157 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
159 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
160 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
161 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
163 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily enable interception for a user");
164 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily enable throttling for a user");
165 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
168 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
169 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
172 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
173 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily disable interception for a user");
174 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily disable throttling for a user");
175 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
178 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
179 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
181 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
182 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
184 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
185 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
187 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
189 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
190 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
193 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
194 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
195 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
196 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
198 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
199 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
201 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
202 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
204 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
206 // Enable regular processing
207 cli_regular(cli
, regular_stuff
);
209 if (!(f
= fopen(CLIUSERS
, "r")))
211 LOG(0, 0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
215 while (fgets(buf
, 4096, f
))
218 if (*buf
== '#') continue;
219 if ((p
= strchr(buf
, '\r'))) *p
= 0;
220 if ((p
= strchr(buf
, '\n'))) *p
= 0;
222 if (!(p
= strchr((char *)buf
, ':'))) continue;
224 if (!strcmp(buf
, "enable"))
226 cli_allow_enable(cli
, p
);
227 LOG(3, 0, 0, 0, "Setting enable password\n");
231 cli_allow_user(cli
, buf
, p
);
232 LOG(3, 0, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
238 memset(&addr
, 0, sizeof(addr
));
239 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
240 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
243 // Set cli fd as non-blocking
244 flags
= fcntl(clifd
, F_GETFL
, 0);
245 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
247 addr
.sin_family
= AF_INET
;
248 addr
.sin_port
= htons(23);
249 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
251 LOG(0, 0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
257 void cli_do(int sockfd
)
259 int require_auth
= 1;
260 struct sockaddr_in addr
;
261 int l
= sizeof(addr
);
263 if (fork_and_close()) return;
264 if (getpeername(sockfd
, (struct sockaddr
*)&addr
, &l
) == 0)
266 LOG(3, 0, 0, 0, "Accepted connection to CLI from %s\n", inet_toa(addr
.sin_addr
.s_addr
));
267 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
270 LOG(0, 0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
274 LOG(3, 0, 0, 0, "CLI is remote, requiring authentication\n");
275 if (!cli
->users
) /* paranoia */
277 LOG(0, 0, 0, 0, "No users for remote authentication! Exiting CLI\n");
283 /* no username/pass required */
290 debug_rb_tail
= ringbuffer
->tail
;
292 memset(&debug_flags
, 0, sizeof(debug_flags
));
293 debug_flags
.critical
= 1;
295 cli_loop(cli
, sockfd
);
298 LOG(3, 0, 0, 0, "Closed CLI connection from %s\n", inet_toa(addr
.sin_addr
.s_addr
));
302 static void cli_print_log(struct cli_def
*cli
, char *string
)
304 LOG(3, 0, 0, 0, "%s\n", string
);
307 void cli_do_file(FILE *fh
)
309 LOG(3, 0, 0, 0, "Reading configuration file\n");
310 cli_print_callback(cli
, cli_print_log
);
311 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
312 cli_print_callback(cli
, NULL
);
315 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
326 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
328 int v
= va_arg(ap
, int);
329 snprintf(buf
, sizeof(buf
), entry
, v
);
335 desc
= va_arg(ap
, char *);
337 cli_print(cli
, " %-20s %s", p
, desc
);
339 cli_print(cli
, " %s", p
);
341 entry
= desc
? va_arg(ap
, char *) : 0;
346 cli_print(cli
, " <cr>");
351 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
355 if (CLI_HELP_REQUESTED
)
356 return cli_arg_help(cli
, 1,
357 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
363 // Show individual session
364 for (i
= 0; i
< argc
; i
++)
366 unsigned int s
, b_in
, b_out
;
368 if (s
<= 0 || s
>= MAXSESSION
)
370 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
373 cli_print(cli
, "\r\nSession %d:", s
);
374 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
375 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
376 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
377 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
378 cli_print(cli
, "\tIP address:\t%s", inet_toa(htonl(session
[s
].ip
)));
379 cli_print(cli
, "\tUnique SID:\t%lu", session
[s
].unique_id
);
380 cli_print(cli
, "\tIdle time:\t%u seconds", abs(time_now
- session
[s
].last_packet
));
381 cli_print(cli
, "\tNext Recv:\t%u", session
[s
].nr
);
382 cli_print(cli
, "\tNext Send:\t%u", session
[s
].ns
);
383 cli_print(cli
, "\tBytes In/Out:\t%lu/%lu", (unsigned long)session
[s
].total_cout
, (unsigned long)session
[s
].total_cin
);
384 cli_print(cli
, "\tPkts In/Out:\t%lu/%lu", (unsigned long)session
[s
].pout
, (unsigned long)session
[s
].pin
);
385 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
386 cli_print(cli
, "\tRadius Session:\t%u", session
[s
].radius
);
387 cli_print(cli
, "\tRx Speed:\t%lu", session
[s
].rx_connect_speed
);
388 cli_print(cli
, "\tTx Speed:\t%lu", session
[s
].tx_connect_speed
);
389 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
390 cli_print(cli
, "\tIntercepted:\t%s:%d", inet_toa(session
[s
].snoop_ip
), session
[s
] .snoop_port
);
392 cli_print(cli
, "\tIntercepted:\tno");
394 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
396 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
397 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
398 t
? "YES" : "no", t
? " (" : "",
399 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
401 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
405 b_in
= session
[s
].tbf_in
;
406 b_out
= session
[s
].tbf_out
;
408 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
409 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
410 "ByteSent", "PackSent", "PackDrop", "PackDelay");
413 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
415 (filter_list
[b_in
].next
? "*" : " "),
416 (b_in
< 100 ? "\t" : ""),
417 filter_list
[b_in
].rate
* 8,
418 filter_list
[b_in
].credit
,
419 filter_list
[b_in
].queued
,
420 filter_list
[b_in
].b_queued
,
421 filter_list
[b_in
].p_queued
,
422 filter_list
[b_in
].b_sent
,
423 filter_list
[b_in
].p_sent
,
424 filter_list
[b_in
].p_dropped
,
425 filter_list
[b_in
].p_delayed
);
428 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
430 (filter_list
[b_out
].next
? "*" : " "),
431 (b_out
< 100 ? "\t" : ""),
432 filter_list
[b_out
].rate
* 8,
433 filter_list
[b_out
].credit
,
434 filter_list
[b_out
].queued
,
435 filter_list
[b_out
].b_queued
,
436 filter_list
[b_out
].p_queued
,
437 filter_list
[b_out
].b_sent
,
438 filter_list
[b_out
].p_sent
,
439 filter_list
[b_out
].p_dropped
,
440 filter_list
[b_out
].p_delayed
);
447 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %10s %10s %10s %4s %-15s %s",
462 for (i
= 1; i
< MAXSESSION
; i
++)
464 char *userip
, *tunnelip
;
465 if (!session
[i
].opened
) continue;
466 userip
= strdup(inet_toa(htonl(session
[i
].ip
)));
467 tunnelip
= strdup(inet_toa(htonl(tunnel
[ session
[i
].tunnel
].ip
)));
468 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %10u %10lu %10lu %4u %-15s %s",
471 session
[i
].user
[0] ? session
[i
].user
: "*",
473 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
474 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
475 (session
[i
].walled_garden
) ? "Y" : "N",
476 abs(time_now
- (unsigned long)session
[i
].opened
),
477 (unsigned long)session
[i
].total_cout
,
478 (unsigned long)session
[i
].total_cin
,
479 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
481 session
[i
].calling
[0] ? session
[i
].calling
: "*");
482 if (userip
) free(userip
);
483 if (tunnelip
) free(tunnelip
);
488 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
490 int i
, x
, show_all
= 0;
498 if (CLI_HELP_REQUESTED
)
501 return cli_arg_help(cli
, 1,
502 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
505 return cli_arg_help(cli
, 1,
506 "all", "Show all tunnels, including unused",
507 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
514 if (strcmp(argv
[0], "all") == 0)
520 // Show individual tunnel
521 for (i
= 0; i
< argc
; i
++)
526 if (t
<= 0 || t
>= MAXTUNNEL
)
528 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
531 cli_print(cli
, "\r\nTunnel %d:", t
);
532 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
533 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
534 cli_print(cli
, "\tRemote IP:\t%s", inet_toa(htonl(tunnel
[t
].ip
)));
535 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
536 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
537 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
538 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
539 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
540 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
542 for (x
= 0; x
< MAXSESSION
; x
++)
543 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
544 sprintf(s
, "%s%u ", s
, x
);
546 cli_print(cli
, "\tSessions:\t%s", s
);
552 // Show tunnel summary
553 cli_print(cli
, "%4s %20s %20s %6s %s",
560 for (i
= 1; i
< MAXTUNNEL
; i
++)
563 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
565 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
566 cli_print(cli
, "%4d %20s %20s %6s %6d",
568 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
569 inet_toa(htonl(tunnel
[i
].ip
)),
570 states
[tunnel
[i
].state
],
577 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
584 if (CLI_HELP_REQUESTED
)
585 return cli_arg_help(cli
, 1,
586 "USER", "Show details for specific username",
589 for (i
= 0; i
< MAXSESSION
; i
++)
591 if (!session
[i
].opened
) continue;
592 if (!session
[i
].user
[0]) continue;
596 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
598 if (strcmp(argv
[j
], session
[i
].user
) == 0)
600 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
601 sargv
[sargc
] = sid
[sargc
];
609 cli_print(cli
, "%s", session
[i
].user
);
613 return cmd_show_session(cli
, "users", sargv
, sargc
);
618 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
620 if (CLI_HELP_REQUESTED
)
621 return CLI_HELP_NO_ARGS
;
623 cli_print(cli
, "%-10s %-8s %-10s %-8s", "Ethernet", "Bytes", "Packets", "Errors");
624 cli_print(cli
, "%-10s %8lu %8lu %8lu", "RX",
625 GET_STAT(tun_rx_bytes
),
626 GET_STAT(tun_rx_packets
),
627 GET_STAT(tun_rx_errors
));
628 cli_print(cli
, "%-10s %8lu %8lu %8lu", "TX",
629 GET_STAT(tun_tx_bytes
),
630 GET_STAT(tun_tx_packets
),
631 GET_STAT(tun_tx_errors
));
634 cli_print(cli
, "%-10s %-8s %-10s %-8s %-8s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
635 cli_print(cli
, "%-10s %8lu %8lu %8lu %8lu", "RX",
636 GET_STAT(tunnel_rx_bytes
),
637 GET_STAT(tunnel_rx_packets
),
638 GET_STAT(tunnel_rx_errors
),
640 cli_print(cli
, "%-10s %8lu %8lu %8lu %8lu", "TX",
641 GET_STAT(tunnel_tx_bytes
),
642 GET_STAT(tunnel_tx_packets
),
643 GET_STAT(tunnel_tx_errors
),
644 GET_STAT(tunnel_retries
));
647 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
648 cli_print(cli
, "-----------------------------------------");
649 cli_print(cli
, "%-30s%lu", "radius_retries", GET_STAT(radius_retries
));
650 cli_print(cli
, "%-30s%lu", "arp_sent", GET_STAT(arp_sent
));
651 cli_print(cli
, "%-30s%lu", "packets_snooped", GET_STAT(packets_snooped
));
652 cli_print(cli
, "%-30s%lu", "tunnel_created", GET_STAT(tunnel_created
));
653 cli_print(cli
, "%-30s%lu", "session_created", GET_STAT(session_created
));
654 cli_print(cli
, "%-30s%lu", "tunnel_timeout", GET_STAT(tunnel_timeout
));
655 cli_print(cli
, "%-30s%lu", "session_timeout", GET_STAT(session_timeout
));
656 cli_print(cli
, "%-30s%lu", "radius_timeout", GET_STAT(radius_timeout
));
657 cli_print(cli
, "%-30s%lu", "radius_overflow", GET_STAT(radius_overflow
));
658 cli_print(cli
, "%-30s%lu", "tunnel_overflow", GET_STAT(tunnel_overflow
));
659 cli_print(cli
, "%-30s%lu", "session_overflow", GET_STAT(session_overflow
));
660 cli_print(cli
, "%-30s%lu", "ip_allocated", GET_STAT(ip_allocated
));
661 cli_print(cli
, "%-30s%lu", "ip_freed", GET_STAT(ip_freed
));
662 cli_print(cli
, "%-30s%lu", "cluster_forwarded", GET_STAT(c_forwarded
));
663 cli_print(cli
, "%-30s%lu", "recv_forward", GET_STAT(recv_forward
));
667 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
668 cli_print(cli
, "-----------------------------------------");
669 cli_print(cli
, "%-30s%lu", "call_processtun", GET_STAT(call_processtun
));
670 cli_print(cli
, "%-30s%lu", "call_processipout", GET_STAT(call_processipout
));
671 cli_print(cli
, "%-30s%lu", "call_processudp", GET_STAT(call_processudp
));
672 cli_print(cli
, "%-30s%lu", "call_processpap", GET_STAT(call_processpap
));
673 cli_print(cli
, "%-30s%lu", "call_processchap", GET_STAT(call_processchap
));
674 cli_print(cli
, "%-30s%lu", "call_processlcp", GET_STAT(call_processlcp
));
675 cli_print(cli
, "%-30s%lu", "call_processipcp", GET_STAT(call_processipcp
));
676 cli_print(cli
, "%-30s%lu", "call_processipin", GET_STAT(call_processipin
));
677 cli_print(cli
, "%-30s%lu", "call_processccp", GET_STAT(call_processccp
));
678 cli_print(cli
, "%-30s%lu", "call_processrad", GET_STAT(call_processrad
));
679 cli_print(cli
, "%-30s%lu", "call_sendarp", GET_STAT(call_sendarp
));
680 cli_print(cli
, "%-30s%lu", "call_sendipcp", GET_STAT(call_sendipcp
));
681 cli_print(cli
, "%-30s%lu", "call_sendchap", GET_STAT(call_sendchap
));
682 cli_print(cli
, "%-30s%lu", "call_sessionbyip", GET_STAT(call_sessionbyip
));
683 cli_print(cli
, "%-30s%lu", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
684 cli_print(cli
, "%-30s%lu", "call_tunnelsend", GET_STAT(call_tunnelsend
));
685 cli_print(cli
, "%-30s%lu", "call_tunnelkill", GET_STAT(call_tunnelkill
));
686 cli_print(cli
, "%-30s%lu", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
687 cli_print(cli
, "%-30s%lu", "call_sessionkill", GET_STAT(call_sessionkill
));
688 cli_print(cli
, "%-30s%lu", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
689 cli_print(cli
, "%-30s%lu", "call_sessionsetup", GET_STAT(call_sessionsetup
));
690 cli_print(cli
, "%-30s%lu", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
691 cli_print(cli
, "%-30s%lu", "call_free_ip_address", GET_STAT(call_free_ip_address
));
692 cli_print(cli
, "%-30s%lu", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
693 cli_print(cli
, "%-30s%lu", "call_radiussend", GET_STAT(call_radiussend
));
694 cli_print(cli
, "%-30s%lu", "call_radiusretry", GET_STAT(call_radiusretry
));
699 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
705 if (CLI_HELP_REQUESTED
)
706 return cli_arg_help(cli
, 1,
707 "tag", "Include CVS release tag",
708 "file", "Include file versions",
711 for (i
= 0; i
< argc
; i
++)
712 if (!strcmp(argv
[i
], "tag"))
714 else if (!strcmp(argv
[i
], "file"))
717 cli_print(cli
, "L2TPNS %s", VERSION
);
720 char const *p
= strchr(cvs_name
, ':');
732 e
= strpbrk(p
, " \t$");
733 cli_print(cli
, "Tag: %.*s", e
? e
- p
+ 1 : strlen(p
), p
);
738 extern linked_list
*loaded_plugins
;
741 cli_print(cli
, "Files:");
742 cli_print(cli
, " %s", cvs_id_arp
);
744 cli_print(cli
, " %s", cvs_id_bgp
);
746 cli_print(cli
, " %s", cvs_id_cli
);
747 cli_print(cli
, " %s", cvs_id_cluster
);
748 cli_print(cli
, " %s", cvs_id_constants
);
749 cli_print(cli
, " %s", cvs_id_control
);
750 cli_print(cli
, " %s", cvs_id_icmp
);
751 cli_print(cli
, " %s", cvs_id_l2tpns
);
752 cli_print(cli
, " %s", cvs_id_ll
);
753 cli_print(cli
, " %s", cvs_id_md5
);
754 cli_print(cli
, " %s", cvs_id_ppp
);
755 cli_print(cli
, " %s", cvs_id_radius
);
756 cli_print(cli
, " %s", cvs_id_tbf
);
757 cli_print(cli
, " %s", cvs_id_util
);
759 ll_reset(loaded_plugins
);
760 while ((p
= ll_next(loaded_plugins
)))
762 char const **id
= dlsym(p
, "cvs_id");
764 cli_print(cli
, " %s", *id
);
771 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
774 int used
= 0, free
= 0, show_all
= 0;
776 if (!config
->cluster_iam_master
)
778 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
782 if (CLI_HELP_REQUESTED
)
785 return cli_arg_help(cli
, 1, NULL
);
787 return cli_arg_help(cli
, 1,
788 "all", "Show all pool addresses, including unused",
792 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
796 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
797 for (i
= 0; i
< MAXIPPOOL
; i
++)
799 if (!ip_address_pool
[i
].address
) continue;
800 if (ip_address_pool
[i
].assigned
)
802 cli_print(cli
, "%-15s\tY %8d %s",
803 inet_toa(htonl(ip_address_pool
[i
].address
)), ip_address_pool
[i
].session
, session
[ip_address_pool
[i
].session
].user
);
809 if (ip_address_pool
[i
].last
)
810 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
811 inet_toa(htonl(ip_address_pool
[i
].address
)), "",
812 ip_address_pool
[i
].user
, time_now
- ip_address_pool
[i
].last
);
814 cli_print(cli
, "%-15s\tN", inet_toa(htonl(ip_address_pool
[i
].address
)));
821 cli_print(cli
, "(Not displaying unused addresses)");
823 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
827 static FILE *save_config_fh
= 0;
828 static void print_save_config(struct cli_def
*cli
, char *string
)
831 fprintf(save_config_fh
, "%s\n", string
);
834 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
836 if (CLI_HELP_REQUESTED
)
837 return CLI_HELP_NO_ARGS
;
839 if ((save_config_fh
= fopen(config
->config_file
, "w")))
841 cli_print(cli
, "Writing configuration");
842 cli_print_callback(cli
, print_save_config
);
843 cmd_show_run(cli
, command
, argv
, argc
);
844 cli_print_callback(cli
, NULL
);
845 fclose(save_config_fh
);
850 cli_print(cli
, "Error writing configuration: %s", strerror(errno
));
855 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
859 if (CLI_HELP_REQUESTED
)
860 return CLI_HELP_NO_ARGS
;
862 cli_print(cli
, "# Current configuration:");
864 for (i
= 0; config_values
[i
].key
; i
++)
866 void *value
= ((void *)config
) + config_values
[i
].offset
;
867 if (config_values
[i
].type
== STRING
)
868 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *)value
);
869 else if (config_values
[i
].type
== IP
)
870 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_toa(*(unsigned *)value
));
871 else if (config_values
[i
].type
== SHORT
)
872 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *)value
);
873 else if (config_values
[i
].type
== BOOL
)
874 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *)value
) ? "yes" : "no");
875 else if (config_values
[i
].type
== INT
)
876 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *)value
);
877 else if (config_values
[i
].type
== UNSIGNED_LONG
)
878 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *)value
);
879 else if (config_values
[i
].type
== MAC
)
880 cli_print(cli
, "set %s %02x%02x.%02x%02x.%02x%02x", config_values
[i
].key
,
881 *(unsigned short *)(value
+ 0),
882 *(unsigned short *)(value
+ 1),
883 *(unsigned short *)(value
+ 2),
884 *(unsigned short *)(value
+ 3),
885 *(unsigned short *)(value
+ 4),
886 *(unsigned short *)(value
+ 5));
889 cli_print(cli
, "# Plugins");
890 for (i
= 0; i
< MAXPLUGINS
; i
++)
892 if (*config
->plugins
[i
])
894 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
899 if (config
->as_number
)
904 cli_print(cli
, "# BGP");
905 cli_print(cli
, "router bgp %u", config
->as_number
);
906 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
908 if (!config
->neighbour
[i
].name
[0])
911 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
913 k
= config
->neighbour
[i
].keepalive
;
914 h
= config
->neighbour
[i
].hold
;
921 k
= BGP_KEEPALIVE_TIME
;
927 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
932 cli_print(cli
, "# end");
936 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
938 int i
, free
= 0, used
= 0, show_all
= 0;
949 if (CLI_HELP_REQUESTED
)
952 return cli_arg_help(cli
, 1, NULL
);
954 return cli_arg_help(cli
, 1,
955 "all", "Show all RADIUS sessions, including unused",
959 cli_print(cli
, "%6s%6s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
963 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
966 for (i
= 1; i
< MAXRADIUS
; i
++)
968 if (radius
[i
].state
== RADIUSNULL
)
973 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
975 cli_print(cli
, "%6d%6d%5d%6s%9d%9u%4d",
979 states
[radius
[i
].state
],
985 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
990 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
994 if (CLI_HELP_REQUESTED
)
995 return CLI_HELP_NO_ARGS
;
997 cli_print(cli
, "Plugins currently loaded:");
998 for (i
= 0; i
< MAXPLUGINS
; i
++)
999 if (*config
->plugins
[i
])
1000 cli_print(cli
, " %s", config
->plugins
[i
]);
1005 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1009 if (CLI_HELP_REQUESTED
)
1010 return CLI_HELP_NO_ARGS
;
1012 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1021 for (i
= 0; i
< MAXSESSION
; i
++)
1023 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1024 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1028 session
[i
].throttle_in
,
1029 session
[i
].throttle_out
,
1031 session
[i
].tbf_out
);
1037 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1039 if (CLI_HELP_REQUESTED
)
1040 return CLI_HELP_NO_ARGS
;
1042 cli_print(cli
, " _\n"
1048 " ( \\ `. `-. _,.-:\\\n"
1049 " \\ \\ `. `-._ __..--' ,-';/\n"
1050 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1051 " `. `. `-._ __..--' ,' /\n"
1052 " `. `-_ ``--..'' _.-' ,'\n"
1053 " `-_ `-.___ __,--' ,'\n"
1054 " `-.__ `----\"\"\" __.-'\n"
1055 "hh `--..____..--'");
1060 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1062 if (CLI_HELP_REQUESTED
)
1063 return CLI_HELP_NO_ARGS
;
1065 cli_print(cli
, "Counters cleared");
1066 SET_STAT(last_reset
, time(NULL
));
1070 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1075 if (CLI_HELP_REQUESTED
)
1076 return cli_arg_help(cli
, argc
> 1,
1077 "USER", "Username of session to drop", NULL
);
1079 if (!config
->cluster_iam_master
)
1081 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1087 cli_print(cli
, "Specify a user to drop");
1091 for (i
= 0; i
< argc
; i
++)
1093 if (!(s
= sessionbyuser(argv
[i
])))
1095 cli_print(cli
, "User %s is not connected", argv
[i
]);
1099 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1101 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1102 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1109 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1114 if (CLI_HELP_REQUESTED
)
1115 return cli_arg_help(cli
, argc
> 1,
1116 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1118 if (!config
->cluster_iam_master
)
1120 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1126 cli_print(cli
, "Specify a tunnel to drop");
1130 for (i
= 0; i
< argc
; i
++)
1132 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1134 cli_print(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1140 cli_print(cli
, "Tunnel %d is not connected", t
);
1146 cli_print(cli
, "Tunnel %d is already being shut down", t
);
1150 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1151 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1157 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1162 if (CLI_HELP_REQUESTED
)
1163 return cli_arg_help(cli
, argc
> 1,
1164 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1166 if (!config
->cluster_iam_master
)
1168 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1174 cli_print(cli
, "Specify a session id to drop");
1178 for (i
= 0; i
< argc
; i
++)
1180 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1182 cli_print(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1186 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1188 cli_print(cli
, "Dropping session %d", s
);
1189 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1193 cli_print(cli
, "Session %d is not active.", s
);
1200 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1206 if (CLI_HELP_REQUESTED
)
1211 return cli_arg_help(cli
, 0,
1212 "USER", "Username of session to snoop", NULL
);
1215 return cli_arg_help(cli
, 0,
1216 "A.B.C.D", "IP address of snoop destination", NULL
);
1219 return cli_arg_help(cli
, 0,
1220 "N", "Port of snoop destination", NULL
);
1224 return cli_arg_help(cli
, 1, NULL
);
1231 if (!config
->cluster_iam_master
)
1233 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1239 cli_print(cli
, "Specify username, ip and port");
1243 if (!(s
= sessionbyuser(argv
[0])))
1245 cli_print(cli
, "User %s is not connected", argv
[0]);
1249 ip
= inet_addr(argv
[1]);
1250 if (!ip
|| ip
== INADDR_NONE
)
1252 cli_print(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1256 port
= atoi(argv
[2]);
1259 cli_print(cli
, "Invalid port %s", argv
[2]);
1263 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], inet_toa(ip
), port
);
1264 cli_session_actions
[s
].snoop_ip
= ip
;
1265 cli_session_actions
[s
].snoop_port
= port
;
1266 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1271 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1276 if (CLI_HELP_REQUESTED
)
1277 return cli_arg_help(cli
, argc
> 1,
1278 "USER", "Username of session to unsnoop", NULL
);
1280 if (!config
->cluster_iam_master
)
1282 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1288 cli_print(cli
, "Specify a user to unsnoop");
1292 for (i
= 0; i
< argc
; i
++)
1294 if (!(s
= sessionbyuser(argv
[i
])))
1296 cli_print(cli
, "User %s is not connected", argv
[i
]);
1300 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1301 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1307 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1314 throttle USER - throttle in/out to default rate
1315 throttle USER RATE - throttle in/out to default rate
1316 throttle USER in RATE - throttle input only
1317 throttle USER out RATE - throttle output only
1318 throttle USER in RATE out RATE - throttle both
1321 if (CLI_HELP_REQUESTED
)
1326 return cli_arg_help(cli
, 0,
1327 "USER", "Username of session to throttle", NULL
);
1330 return cli_arg_help(cli
, 1,
1331 "RATE", "Rate in kbps (in and out)",
1332 "in", "Select incoming rate",
1333 "out", "Select outgoing rate", NULL
);
1336 return cli_arg_help(cli
, 1,
1337 "in", "Select incoming rate",
1338 "out", "Select outgoing rate", NULL
);
1341 if (isdigit(argv
[1][0]))
1342 return cli_arg_help(cli
, 1, NULL
);
1345 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1348 return cli_arg_help(cli
, argc
> 1, NULL
);
1352 if (!config
->cluster_iam_master
)
1354 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1360 cli_print(cli
, "Specify a user to throttle");
1364 if (!(s
= sessionbyuser(argv
[0])))
1366 cli_print(cli
, "User %s is not connected", argv
[0]);
1372 rate_in
= rate_out
= config
->rl_rate
;
1376 rate_in
= rate_out
= atoi(argv
[1]);
1379 cli_print(cli
, "Invalid rate \"%s\"", argv
[1]);
1383 else if (argc
== 3 || argc
== 5)
1386 for (i
= 1; i
< argc
- 1; i
+= 2)
1388 int len
= strlen(argv
[i
]);
1390 if (!strncasecmp(argv
[i
], "in", len
))
1391 r
= rate_in
= atoi(argv
[i
+1]);
1392 else if (!strncasecmp(argv
[i
], "out", len
))
1393 r
= rate_out
= atoi(argv
[i
+1]);
1397 cli_print(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1404 cli_print(cli
, "Invalid arguments");
1408 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1410 cli_print(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1414 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1415 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1416 cli_session_actions
[s
].throttle_in
= rate_in
;
1418 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1419 cli_session_actions
[s
].throttle_out
= rate_out
;
1421 if (cli_session_actions
[s
].throttle_in
== -1 &&
1422 cli_session_actions
[s
].throttle_out
== -1)
1424 cli_print(cli
, "User %s already throttled at this rate", argv
[0]);
1428 cli_print(cli
, "Throttling user %s", argv
[0]);
1429 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1434 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1439 if (CLI_HELP_REQUESTED
)
1440 return cli_arg_help(cli
, argc
> 1,
1441 "USER", "Username of session to unthrottle", NULL
);
1443 if (!config
->cluster_iam_master
)
1445 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
1451 cli_print(cli
, "Specify a user to unthrottle");
1455 for (i
= 0; i
< argc
; i
++)
1457 if (!(s
= sessionbyuser(argv
[i
])))
1459 cli_print(cli
, "User %s is not connected", argv
[i
]);
1463 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1465 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1466 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1470 cli_print(cli
, "User %s not throttled", argv
[i
]);
1477 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1481 if (CLI_HELP_REQUESTED
)
1482 return cli_arg_help(cli
, 1,
1483 "all", "Enable debugging for all except \"data\"",
1484 "critical", "", // FIXME: add descriptions
1494 char *p
= (char *) &debug_flags
;
1495 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1499 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1500 (debug_flags
.critical
) ? " critical" : "",
1501 (debug_flags
.error
) ? " error" : "",
1502 (debug_flags
.warning
) ? " warning" : "",
1503 (debug_flags
.info
) ? " info" : "",
1504 (debug_flags
.calls
) ? " calls" : "",
1505 (debug_flags
.data
) ? " data" : "");
1511 cli_print(cli
, "Debugging off");
1515 for (i
= 0; i
< argc
; i
++)
1517 int len
= strlen(argv
[i
]);
1519 if (argv
[i
][0] == 'c' && len
< 2)
1520 len
= 2; /* distinguish [cr]itical from [ca]lls */
1522 if (!strncasecmp(argv
[i
], "critical", len
)) { debug_flags
.critical
= 1; continue; }
1523 if (!strncasecmp(argv
[i
], "error", len
)) { debug_flags
.error
= 1; continue; }
1524 if (!strncasecmp(argv
[i
], "warning", len
)) { debug_flags
.warning
= 1; continue; }
1525 if (!strncasecmp(argv
[i
], "info", len
)) { debug_flags
.info
= 1; continue; }
1526 if (!strncasecmp(argv
[i
], "calls", len
)) { debug_flags
.calls
= 1; continue; }
1527 if (!strncasecmp(argv
[i
], "data", len
)) { debug_flags
.data
= 1; continue; }
1528 if (!strncasecmp(argv
[i
], "all", len
))
1530 memset(&debug_flags
, 1, sizeof(debug_flags
));
1531 debug_flags
.data
= 0;
1535 cli_print(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1541 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1545 if (CLI_HELP_REQUESTED
)
1546 return cli_arg_help(cli
, 1,
1547 "all", "Disable all debugging",
1548 "critical", "", // FIXME: add descriptions
1558 memset(&debug_flags
, 0, sizeof(debug_flags
));
1562 for (i
= 0; i
< argc
; i
++)
1564 int len
= strlen(argv
[i
]);
1566 if (argv
[i
][0] == 'c' && len
< 2)
1567 len
= 2; /* distinguish [cr]itical from [ca]lls */
1569 if (!strncasecmp(argv
[i
], "critical", len
)) { debug_flags
.critical
= 0; continue; }
1570 if (!strncasecmp(argv
[i
], "error", len
)) { debug_flags
.error
= 0; continue; }
1571 if (!strncasecmp(argv
[i
], "warning", len
)) { debug_flags
.warning
= 0; continue; }
1572 if (!strncasecmp(argv
[i
], "info", len
)) { debug_flags
.info
= 0; continue; }
1573 if (!strncasecmp(argv
[i
], "calls", len
)) { debug_flags
.calls
= 0; continue; }
1574 if (!strncasecmp(argv
[i
], "data", len
)) { debug_flags
.data
= 0; continue; }
1575 if (!strncasecmp(argv
[i
], "all", len
))
1577 memset(&debug_flags
, 0, sizeof(debug_flags
));
1581 cli_print(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1587 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1589 int i
, firstfree
= 0;
1591 if (CLI_HELP_REQUESTED
)
1592 return cli_arg_help(cli
, argc
> 1,
1593 "PLUGIN", "Name of plugin to load", NULL
);
1597 cli_print(cli
, "Specify a plugin to load");
1601 for (i
= 0; i
< MAXPLUGINS
; i
++)
1603 if (!*config
->plugins
[i
] && !firstfree
)
1605 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1607 cli_print(cli
, "Plugin is already loaded");
1614 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1615 config
->reload_config
= 1;
1616 cli_print(cli
, "Loading plugin %s", argv
[0]);
1622 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1626 if (CLI_HELP_REQUESTED
)
1627 return cli_arg_help(cli
, argc
> 1,
1628 "PLUGIN", "Name of plugin to unload", NULL
);
1632 cli_print(cli
, "Specify a plugin to remove");
1636 for (i
= 0; i
< MAXPLUGINS
; i
++)
1638 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1640 config
->reload_config
= 1;
1641 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1646 cli_print(cli
, "Plugin is not loaded");
1650 static char *duration(time_t secs
)
1652 static char *buf
= NULL
;
1655 if (!buf
) buf
= calloc(64, 1);
1659 int days
= secs
/ 86400;
1660 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1666 int mins
= secs
/ 60;
1667 int hrs
= mins
/ 60;
1670 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1672 else if (secs
>= 60)
1674 int mins
= secs
/ 60;
1675 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1678 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1683 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1686 char buf
[100], *p
= buf
, *loads
[3];
1687 int i
, num_sessions
= 0;
1689 if (CLI_HELP_REQUESTED
)
1690 return CLI_HELP_NO_ARGS
;
1692 fh
= fopen("/proc/loadavg", "r");
1693 fgets(buf
, 100, fh
);
1696 for (i
= 0; i
< 3; i
++)
1697 loads
[i
] = strdup(strsep(&p
, " "));
1700 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1702 for (i
= 1; i
< MAXSESSION
; i
++)
1703 if (session
[i
].opened
) num_sessions
++;
1705 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1707 duration(time_now
- config
->start_time
),
1709 loads
[0], loads
[1], loads
[2]
1711 for (i
= 0; i
< 3; i
++)
1712 if (loads
[i
]) free(loads
[i
]);
1714 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1719 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1723 if (CLI_HELP_REQUESTED
)
1729 int len
= strlen(argv
[0])-1;
1730 for (i
= 0; config_values
[i
].key
; i
++)
1731 if (!len
|| !strncmp(argv
[0], config_values
[i
].key
, len
))
1732 cli_print(cli
, " %s", config_values
[i
].key
);
1738 return cli_arg_help(cli
, 0,
1739 "VALUE", "Value for variable", NULL
);
1743 return cli_arg_help(cli
, 1, NULL
);
1752 cli_print(cli
, "Specify variable and value");
1756 for (i
= 0; config_values
[i
].key
; i
++)
1758 void *value
= ((void *)config
) + config_values
[i
].offset
;
1759 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1761 // Found a value to set
1762 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1763 switch (config_values
[i
].type
)
1766 strncpy((char *)value
, argv
[1], config_values
[i
].size
- 1);
1769 *(int *)value
= atoi(argv
[1]);
1772 *(unsigned long *)value
= atol(argv
[1]);
1775 *(short *)value
= atoi(argv
[1]);
1778 *(unsigned *)value
= inet_addr(argv
[1]);
1781 parsemac(argv
[1], (char *)value
);
1784 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1790 cli_print(cli
, "Unknown variable type");
1793 config
->reload_config
= 1;
1798 cli_print(cli
, "Unknown variable \"%s\"", argv
[0]);
1802 int regular_stuff(struct cli_def
*cli
)
1804 int i
= debug_rb_tail
;
1808 while (i
!= ringbuffer
->tail
)
1810 int show_message
= 0;
1812 if (*ringbuffer
->buffer
[i
].message
)
1814 // Always show messages if we are doing general debug
1815 if (ringbuffer
->buffer
[i
].level
== 0 && debug_flags
.critical
) show_message
= 1;
1816 if (ringbuffer
->buffer
[i
].level
== 1 && debug_flags
.error
) show_message
= 1;
1817 if (ringbuffer
->buffer
[i
].level
== 2 && debug_flags
.warning
) show_message
= 1;
1818 if (ringbuffer
->buffer
[i
].level
== 3 && debug_flags
.info
) show_message
= 1;
1819 if (ringbuffer
->buffer
[i
].level
== 4 && debug_flags
.calls
) show_message
= 1;
1820 if (ringbuffer
->buffer
[i
].level
== 5 && debug_flags
.data
) show_message
= 1;
1825 ipt address
= htonl(ringbuffer
->buffer
[i
].address
);
1827 struct in_addr addr
;
1829 memcpy(&addr
, &address
, sizeof(ringbuffer
->buffer
[i
].address
));
1830 ipaddr
= inet_ntoa(addr
);
1832 cli_print(cli
, "\r%s-%s-%u-%u %s",
1833 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1835 ringbuffer
->buffer
[i
].tunnel
,
1836 ringbuffer
->buffer
[i
].session
,
1837 ringbuffer
->buffer
[i
].message
);
1842 if (++i
== ringbuffer
->tail
) break;
1843 if (i
== RINGBUFFER_SIZE
) i
= 0;
1846 debug_rb_tail
= ringbuffer
->tail
;
1854 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1858 if (CLI_HELP_REQUESTED
)
1859 return cli_arg_help(cli
, argc
> 1,
1860 "<1-65535>", "Autonomous system number", NULL
);
1862 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1864 cli_print(cli
, "Invalid autonomous system number");
1868 if (bgp_configured
&& as
!= config
->as_number
)
1870 cli_print(cli
, "Can't change local AS on a running system");
1874 config
->as_number
= as
;
1875 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1880 static int find_bgp_neighbour(char *name
)
1885 in_addr_t addrs
[4] = { 0 };
1888 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1891 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1892 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1894 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1896 if (!config
->neighbour
[i
].name
[0])
1898 if (new == -1) new = i
;
1902 if (!strcmp(name
, config
->neighbour
[i
].name
))
1905 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
1908 for (a
= h
->h_addr_list
; *a
; a
++)
1911 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
1912 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
1920 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1926 if (CLI_HELP_REQUESTED
)
1931 return cli_arg_help(cli
, 0,
1932 "A.B.C.D", "BGP neighbour address",
1933 "NAME", "BGP neighbour name",
1937 return cli_arg_help(cli
, 0,
1938 "remote-as", "Set remote autonomous system number",
1939 "timers", "Set timers",
1943 if (!strncmp("remote-as", argv
[1], strlen(argv
[1])))
1944 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
1946 if (!strncmp("timers", argv
[1], strlen(argv
[1])))
1949 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
1952 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
1954 if (argc
== 5 && !argv
[4][1])
1955 return cli_arg_help(cli
, 1, NULL
);
1964 cli_print(cli
, "Invalid arguments");
1968 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
1970 cli_print(cli
, "Invalid neighbour");
1976 cli_print(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
1980 if (!strncmp("remote-as", argv
[1], strlen(argv
[1])))
1982 int as
= atoi(argv
[2]);
1983 if (as
< 0 || as
> 65535)
1985 cli_print(cli
, "Invalid autonomous system number");
1989 if (!config
->neighbour
[i
].name
[0])
1991 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), argv
[0]);
1992 config
->neighbour
[i
].keepalive
= -1;
1993 config
->neighbour
[i
].hold
= -1;
1996 config
->neighbour
[i
].as
= as
;
2000 if (argc
!= 4 || strncmp("timers", argv
[1], strlen(argv
[1])))
2002 cli_print(cli
, "Invalid arguments");
2006 if (!config
->neighbour
[i
].name
[0])
2008 cli_print(cli
, "Specify remote-as first");
2012 keepalive
= atoi(argv
[2]);
2013 hold
= atoi(argv
[3]);
2015 if (keepalive
< 1 || keepalive
> 65535)
2017 cli_print(cli
, "Invalid keepalive time");
2021 if (hold
< 3 || hold
> 65535)
2023 cli_print(cli
, "Invalid hold time");
2027 if (keepalive
== BGP_KEEPALIVE_TIME
)
2028 keepalive
= -1; // using default value
2030 if (hold
== BGP_HOLD_TIME
)
2033 config
->neighbour
[i
].keepalive
= keepalive
;
2034 config
->neighbour
[i
].hold
= hold
;
2039 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2043 if (CLI_HELP_REQUESTED
)
2044 return cli_arg_help(cli
, argc
> 0,
2045 "A.B.C.D", "BGP neighbour address",
2046 "NAME", "BGP neighbour name",
2051 cli_print(cli
, "Specify a BGP neighbour");
2055 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2057 cli_print(cli
, "Invalid neighbour");
2061 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2063 cli_print(cli
, "Neighbour %s not configured", argv
[0]);
2067 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2071 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2077 if (!bgp_configured
)
2080 if (CLI_HELP_REQUESTED
)
2081 return cli_arg_help(cli
, 1,
2082 "A.B.C.D", "BGP neighbour address",
2083 "NAME", "BGP neighbour name",
2086 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2087 BGP_VERSION
, inet_toa(my_address
), (int) config
->as_number
);
2091 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2093 if (!*bgp_peers
[i
].name
)
2096 addr
= inet_toa(bgp_peers
[i
].addr
);
2097 if (argc
&& strcmp(addr
, argv
[0]) &&
2098 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2104 cli_print(cli
, "Peer AS Address "
2105 "State Retries Retry in Route Pend Timers");
2106 cli_print(cli
, "------------------ ----- --------------- "
2107 "----------- ------- -------- ----- ---- ---------");
2110 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7ds %5s %4s %4d %4d",
2114 bgp_state_str(bgp_peers
[i
].state
),
2115 bgp_peers
[i
].retry_count
,
2116 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2117 bgp_peers
[i
].routing
? "yes" : "no",
2118 bgp_peers
[i
].update_routes
? "yes" : "no",
2119 bgp_peers
[i
].keepalive
,
2126 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2131 if (!bgp_configured
)
2134 if (CLI_HELP_REQUESTED
)
2135 return cli_arg_help(cli
, 1,
2136 "A.B.C.D", "BGP neighbour address",
2137 "NAME", "BGP neighbour name",
2140 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2142 if (bgp_peers
[i
].state
!= Established
)
2145 if (!bgp_peers
[i
].routing
)
2148 addr
= inet_toa(bgp_peers
[i
].addr
);
2149 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2152 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2153 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2159 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2164 if (!bgp_configured
)
2167 if (CLI_HELP_REQUESTED
)
2168 return cli_arg_help(cli
, 1,
2169 "A.B.C.D", "BGP neighbour address",
2170 "NAME", "BGP neighbour name",
2173 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2175 if (bgp_peers
[i
].state
!= Established
)
2178 if (bgp_peers
[i
].routing
)
2181 addr
= inet_toa(bgp_peers
[i
].addr
);
2182 if (argc
&& strcmp(addr
, argv
[0]) &&
2183 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2186 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2187 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2193 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2198 if (!bgp_configured
)
2201 if (CLI_HELP_REQUESTED
)
2202 return cli_arg_help(cli
, 1,
2203 "A.B.C.D", "BGP neighbour address",
2204 "NAME", "BGP neighbour name",
2207 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2209 if (!*bgp_peers
[i
].name
)
2212 addr
= inet_toa(bgp_peers
[i
].addr
);
2213 if (argc
&& strcmp(addr
, argv
[0]) &&
2214 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2217 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2218 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2225 // Convert a string in the form of abcd.ef12.3456 into char[6]
2226 void parsemac(char *string
, char mac
[6])
2228 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)
2230 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)