1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.26 2004/11/11 05:38:01 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_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
108 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
109 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
110 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
111 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
112 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
115 void init_cli(char *hostname
)
119 struct cli_command
*c
;
120 struct cli_command
*c2
;
122 struct sockaddr_in addr
;
125 if (hostname
&& *hostname
)
126 cli_set_hostname(cli
, hostname
);
128 cli_set_hostname(cli
, "l2tpns");
130 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
131 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
133 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
135 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
136 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
137 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
138 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
139 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
140 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
141 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
142 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
143 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
144 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
145 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");
146 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
148 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
149 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
150 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
153 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
155 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
156 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
159 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
161 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
162 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
163 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
165 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily enable interception for a user");
166 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily enable throttling for a user");
167 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
170 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
171 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
174 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
175 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily disable interception for a user");
176 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Temporarily disable throttling for a user");
177 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
180 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
181 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
183 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
184 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
186 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
187 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
189 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
191 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
192 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
195 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
196 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
197 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
198 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
200 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
201 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
203 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
204 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
206 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
208 // Enable regular processing
209 cli_regular(cli
, regular_stuff
);
211 if (!(f
= fopen(CLIUSERS
, "r")))
213 LOG(0, 0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
217 while (fgets(buf
, 4096, f
))
220 if (*buf
== '#') continue;
221 if ((p
= strchr(buf
, '\r'))) *p
= 0;
222 if ((p
= strchr(buf
, '\n'))) *p
= 0;
224 if (!(p
= strchr((char *)buf
, ':'))) continue;
226 if (!strcmp(buf
, "enable"))
228 cli_allow_enable(cli
, p
);
229 LOG(3, 0, 0, 0, "Setting enable password\n");
233 cli_allow_user(cli
, buf
, p
);
234 LOG(3, 0, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
240 memset(&addr
, 0, sizeof(addr
));
241 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
242 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
245 // Set cli fd as non-blocking
246 flags
= fcntl(clifd
, F_GETFL
, 0);
247 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
249 addr
.sin_family
= AF_INET
;
250 addr
.sin_port
= htons(23);
251 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
253 LOG(0, 0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
259 void cli_do(int sockfd
)
261 int require_auth
= 1;
262 struct sockaddr_in addr
;
263 int l
= sizeof(addr
);
265 if (fork_and_close()) return;
266 if (getpeername(sockfd
, (struct sockaddr
*)&addr
, &l
) == 0)
268 LOG(3, 0, 0, 0, "Accepted connection to CLI from %s\n", inet_toa(addr
.sin_addr
.s_addr
));
269 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
272 LOG(0, 0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
276 LOG(3, 0, 0, 0, "CLI is remote, requiring authentication\n");
277 if (!cli
->users
) /* paranoia */
279 LOG(0, 0, 0, 0, "No users for remote authentication! Exiting CLI\n");
285 /* no username/pass required */
292 debug_rb_tail
= ringbuffer
->tail
;
294 memset(&debug_flags
, 0, sizeof(debug_flags
));
295 debug_flags
.critical
= 1;
297 cli_loop(cli
, sockfd
);
300 LOG(3, 0, 0, 0, "Closed CLI connection from %s\n", inet_toa(addr
.sin_addr
.s_addr
));
304 void cli_print_log(struct cli_def
*cli
, char *string
)
306 LOG(3, 0, 0, 0, "%s\n", string
);
309 void cli_do_file(FILE *fh
)
311 LOG(3, 0, 0, 0, "Reading configuration file\n");
312 cli_print_callback(cli
, cli_print_log
);
313 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
314 cli_print_callback(cli
, NULL
);
317 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
328 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
330 int v
= va_arg(ap
, int);
331 snprintf(buf
, sizeof(buf
), entry
, v
);
337 desc
= va_arg(ap
, char *);
339 cli_print(cli
, " %-20s %s", p
, desc
);
341 cli_print(cli
, " %s", p
);
343 entry
= desc
? va_arg(ap
, char *) : 0;
348 cli_print(cli
, " <cr>");
353 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
357 if (CLI_HELP_REQUESTED
)
358 return cli_arg_help(cli
, 1,
359 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
365 // Show individual session
366 for (i
= 0; i
< argc
; i
++)
368 unsigned int s
, b_in
, b_out
;
370 if (s
<= 0 || s
>= MAXSESSION
)
372 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
375 cli_print(cli
, "\r\nSession %d:", s
);
376 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
377 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
378 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
379 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
380 cli_print(cli
, "\tIP address:\t%s", inet_toa(htonl(session
[s
].ip
)));
381 cli_print(cli
, "\tUnique SID:\t%lu", session
[s
].unique_id
);
382 cli_print(cli
, "\tIdle time:\t%u seconds", abs(time_now
- session
[s
].last_packet
));
383 cli_print(cli
, "\tNext Recv:\t%u", session
[s
].nr
);
384 cli_print(cli
, "\tNext Send:\t%u", session
[s
].ns
);
385 cli_print(cli
, "\tBytes In/Out:\t%lu/%lu", (unsigned long)session
[s
].total_cout
, (unsigned long)session
[s
].total_cin
);
386 cli_print(cli
, "\tPkts In/Out:\t%lu/%lu", (unsigned long)session
[s
].pout
, (unsigned long)session
[s
].pin
);
387 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
388 cli_print(cli
, "\tRadius Session:\t%u", session
[s
].radius
);
389 cli_print(cli
, "\tRx Speed:\t%lu", session
[s
].rx_connect_speed
);
390 cli_print(cli
, "\tTx Speed:\t%lu", session
[s
].tx_connect_speed
);
391 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
392 cli_print(cli
, "\tIntercepted:\t%s:%d", inet_toa(session
[s
].snoop_ip
), session
[s
] .snoop_port
);
394 cli_print(cli
, "\tIntercepted:\tno");
396 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
398 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
399 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
400 t
? "YES" : "no", t
? " (" : "",
401 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
403 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
407 b_in
= session
[s
].tbf_in
;
408 b_out
= session
[s
].tbf_out
;
410 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
411 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
412 "ByteSent", "PackSent", "PackDrop", "PackDelay");
415 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
417 (filter_list
[b_in
].next
? "*" : " "),
418 (b_in
< 100 ? "\t" : ""),
419 filter_list
[b_in
].rate
* 8,
420 filter_list
[b_in
].credit
,
421 filter_list
[b_in
].queued
,
422 filter_list
[b_in
].b_queued
,
423 filter_list
[b_in
].p_queued
,
424 filter_list
[b_in
].b_sent
,
425 filter_list
[b_in
].p_sent
,
426 filter_list
[b_in
].p_dropped
,
427 filter_list
[b_in
].p_delayed
);
430 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
432 (filter_list
[b_out
].next
? "*" : " "),
433 (b_out
< 100 ? "\t" : ""),
434 filter_list
[b_out
].rate
* 8,
435 filter_list
[b_out
].credit
,
436 filter_list
[b_out
].queued
,
437 filter_list
[b_out
].b_queued
,
438 filter_list
[b_out
].p_queued
,
439 filter_list
[b_out
].b_sent
,
440 filter_list
[b_out
].p_sent
,
441 filter_list
[b_out
].p_dropped
,
442 filter_list
[b_out
].p_delayed
);
449 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %10s %10s %10s %4s %-15s %s",
464 for (i
= 1; i
< MAXSESSION
; i
++)
466 char *userip
, *tunnelip
;
467 if (!session
[i
].opened
) continue;
468 userip
= strdup(inet_toa(htonl(session
[i
].ip
)));
469 tunnelip
= strdup(inet_toa(htonl(tunnel
[ session
[i
].tunnel
].ip
)));
470 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %10u %10lu %10lu %4u %-15s %s",
473 session
[i
].user
[0] ? session
[i
].user
: "*",
475 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
476 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
477 (session
[i
].walled_garden
) ? "Y" : "N",
478 abs(time_now
- (unsigned long)session
[i
].opened
),
479 (unsigned long)session
[i
].total_cout
,
480 (unsigned long)session
[i
].total_cin
,
481 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
483 session
[i
].calling
[0] ? session
[i
].calling
: "*");
484 if (userip
) free(userip
);
485 if (tunnelip
) free(tunnelip
);
490 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
492 int i
, x
, show_all
= 0;
500 if (CLI_HELP_REQUESTED
)
503 return cli_arg_help(cli
, 1,
504 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
507 return cli_arg_help(cli
, 1,
508 "all", "Show all tunnels, including unused",
509 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
516 if (strcmp(argv
[0], "all") == 0)
522 // Show individual tunnel
523 for (i
= 0; i
< argc
; i
++)
528 if (t
<= 0 || t
>= MAXTUNNEL
)
530 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
533 cli_print(cli
, "\r\nTunnel %d:", t
);
534 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
535 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
536 cli_print(cli
, "\tRemote IP:\t%s", inet_toa(htonl(tunnel
[t
].ip
)));
537 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
538 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
539 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
540 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
541 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
542 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
544 for (x
= 0; x
< MAXSESSION
; x
++)
545 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
546 sprintf(s
, "%s%u ", s
, x
);
548 cli_print(cli
, "\tSessions:\t%s", s
);
554 // Show tunnel summary
555 cli_print(cli
, "%4s %20s %20s %6s %s",
562 for (i
= 1; i
< MAXTUNNEL
; i
++)
565 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
567 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
568 cli_print(cli
, "%4d %20s %20s %6s %6d",
570 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
571 inet_toa(htonl(tunnel
[i
].ip
)),
572 states
[tunnel
[i
].state
],
579 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
586 if (CLI_HELP_REQUESTED
)
587 return cli_arg_help(cli
, 1,
588 "USER", "Show details for specific username",
591 for (i
= 0; i
< MAXSESSION
; i
++)
593 if (!session
[i
].opened
) continue;
594 if (!session
[i
].user
[0]) continue;
598 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
600 if (strcmp(argv
[j
], session
[i
].user
) == 0)
602 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
603 sargv
[sargc
] = sid
[sargc
];
611 cli_print(cli
, "%s", session
[i
].user
);
615 return cmd_show_session(cli
, "users", sargv
, sargc
);
620 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
622 if (CLI_HELP_REQUESTED
)
623 return CLI_HELP_NO_ARGS
;
625 cli_print(cli
, "%-10s %-8s %-10s %-8s", "Ethernet", "Bytes", "Packets", "Errors");
626 cli_print(cli
, "%-10s %8lu %8lu %8lu", "RX",
627 GET_STAT(tun_rx_bytes
),
628 GET_STAT(tun_rx_packets
),
629 GET_STAT(tun_rx_errors
));
630 cli_print(cli
, "%-10s %8lu %8lu %8lu", "TX",
631 GET_STAT(tun_tx_bytes
),
632 GET_STAT(tun_tx_packets
),
633 GET_STAT(tun_tx_errors
));
636 cli_print(cli
, "%-10s %-8s %-10s %-8s %-8s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
637 cli_print(cli
, "%-10s %8lu %8lu %8lu %8lu", "RX",
638 GET_STAT(tunnel_rx_bytes
),
639 GET_STAT(tunnel_rx_packets
),
640 GET_STAT(tunnel_rx_errors
),
642 cli_print(cli
, "%-10s %8lu %8lu %8lu %8lu", "TX",
643 GET_STAT(tunnel_tx_bytes
),
644 GET_STAT(tunnel_tx_packets
),
645 GET_STAT(tunnel_tx_errors
),
646 GET_STAT(tunnel_retries
));
649 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
650 cli_print(cli
, "-----------------------------------------");
651 cli_print(cli
, "%-30s%lu", "radius_retries", GET_STAT(radius_retries
));
652 cli_print(cli
, "%-30s%lu", "arp_sent", GET_STAT(arp_sent
));
653 cli_print(cli
, "%-30s%lu", "packets_snooped", GET_STAT(packets_snooped
));
654 cli_print(cli
, "%-30s%lu", "tunnel_created", GET_STAT(tunnel_created
));
655 cli_print(cli
, "%-30s%lu", "session_created", GET_STAT(session_created
));
656 cli_print(cli
, "%-30s%lu", "tunnel_timeout", GET_STAT(tunnel_timeout
));
657 cli_print(cli
, "%-30s%lu", "session_timeout", GET_STAT(session_timeout
));
658 cli_print(cli
, "%-30s%lu", "radius_timeout", GET_STAT(radius_timeout
));
659 cli_print(cli
, "%-30s%lu", "radius_overflow", GET_STAT(radius_overflow
));
660 cli_print(cli
, "%-30s%lu", "tunnel_overflow", GET_STAT(tunnel_overflow
));
661 cli_print(cli
, "%-30s%lu", "session_overflow", GET_STAT(session_overflow
));
662 cli_print(cli
, "%-30s%lu", "ip_allocated", GET_STAT(ip_allocated
));
663 cli_print(cli
, "%-30s%lu", "ip_freed", GET_STAT(ip_freed
));
664 cli_print(cli
, "%-30s%lu", "cluster_forwarded", GET_STAT(c_forwarded
));
665 cli_print(cli
, "%-30s%lu", "recv_forward", GET_STAT(recv_forward
));
669 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
670 cli_print(cli
, "-----------------------------------------");
671 cli_print(cli
, "%-30s%lu", "call_processtun", GET_STAT(call_processtun
));
672 cli_print(cli
, "%-30s%lu", "call_processipout", GET_STAT(call_processipout
));
673 cli_print(cli
, "%-30s%lu", "call_processudp", GET_STAT(call_processudp
));
674 cli_print(cli
, "%-30s%lu", "call_processpap", GET_STAT(call_processpap
));
675 cli_print(cli
, "%-30s%lu", "call_processchap", GET_STAT(call_processchap
));
676 cli_print(cli
, "%-30s%lu", "call_processlcp", GET_STAT(call_processlcp
));
677 cli_print(cli
, "%-30s%lu", "call_processipcp", GET_STAT(call_processipcp
));
678 cli_print(cli
, "%-30s%lu", "call_processipin", GET_STAT(call_processipin
));
679 cli_print(cli
, "%-30s%lu", "call_processccp", GET_STAT(call_processccp
));
680 cli_print(cli
, "%-30s%lu", "call_processrad", GET_STAT(call_processrad
));
681 cli_print(cli
, "%-30s%lu", "call_sendarp", GET_STAT(call_sendarp
));
682 cli_print(cli
, "%-30s%lu", "call_sendipcp", GET_STAT(call_sendipcp
));
683 cli_print(cli
, "%-30s%lu", "call_sendchap", GET_STAT(call_sendchap
));
684 cli_print(cli
, "%-30s%lu", "call_sessionbyip", GET_STAT(call_sessionbyip
));
685 cli_print(cli
, "%-30s%lu", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
686 cli_print(cli
, "%-30s%lu", "call_tunnelsend", GET_STAT(call_tunnelsend
));
687 cli_print(cli
, "%-30s%lu", "call_tunnelkill", GET_STAT(call_tunnelkill
));
688 cli_print(cli
, "%-30s%lu", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
689 cli_print(cli
, "%-30s%lu", "call_sessionkill", GET_STAT(call_sessionkill
));
690 cli_print(cli
, "%-30s%lu", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
691 cli_print(cli
, "%-30s%lu", "call_sessionsetup", GET_STAT(call_sessionsetup
));
692 cli_print(cli
, "%-30s%lu", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
693 cli_print(cli
, "%-30s%lu", "call_free_ip_address", GET_STAT(call_free_ip_address
));
694 cli_print(cli
, "%-30s%lu", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
695 cli_print(cli
, "%-30s%lu", "call_radiussend", GET_STAT(call_radiussend
));
696 cli_print(cli
, "%-30s%lu", "call_radiusretry", GET_STAT(call_radiusretry
));
701 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
707 if (CLI_HELP_REQUESTED
)
708 return cli_arg_help(cli
, 1,
709 "tag", "Include CVS release tag",
710 "file", "Include file versions",
713 for (i
= 0; i
< argc
; i
++)
714 if (!strcmp(argv
[i
], "tag"))
716 else if (!strcmp(argv
[i
], "file"))
719 cli_print(cli
, "L2TPNS %s", VERSION
);
722 char const *p
= strchr(cvs_name
, ':');
734 e
= strpbrk(p
, " \t$");
735 cli_print(cli
, "Tag: %.*s", e
? e
- p
+ 1 : strlen(p
), p
);
740 extern linked_list
*loaded_plugins
;
743 cli_print(cli
, "Files:");
744 cli_print(cli
, " %s", cvs_id_arp
);
746 cli_print(cli
, " %s", cvs_id_bgp
);
748 cli_print(cli
, " %s", cvs_id_cli
);
749 cli_print(cli
, " %s", cvs_id_cluster
);
750 cli_print(cli
, " %s", cvs_id_constants
);
751 cli_print(cli
, " %s", cvs_id_control
);
752 cli_print(cli
, " %s", cvs_id_icmp
);
753 cli_print(cli
, " %s", cvs_id_l2tpns
);
754 cli_print(cli
, " %s", cvs_id_ll
);
755 cli_print(cli
, " %s", cvs_id_md5
);
756 cli_print(cli
, " %s", cvs_id_ppp
);
757 cli_print(cli
, " %s", cvs_id_radius
);
758 cli_print(cli
, " %s", cvs_id_tbf
);
759 cli_print(cli
, " %s", cvs_id_util
);
761 ll_reset(loaded_plugins
);
762 while ((p
= ll_next(loaded_plugins
)))
764 char const **id
= dlsym(p
, "cvs_id");
766 cli_print(cli
, " %s", *id
);
773 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
776 int used
= 0, free
= 0, show_all
= 0;
778 if (!config
->cluster_iam_master
)
780 cli_print(cli
, "Can't do this on a slave. Do it on %s", inet_toa(config
->cluster_master_address
));
784 if (CLI_HELP_REQUESTED
)
787 return cli_arg_help(cli
, 1, NULL
);
789 return cli_arg_help(cli
, 1,
790 "all", "Show all pool addresses, including unused",
794 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
798 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
799 for (i
= 0; i
< MAXIPPOOL
; i
++)
801 if (!ip_address_pool
[i
].address
) continue;
802 if (ip_address_pool
[i
].assigned
)
804 cli_print(cli
, "%-15s\tY %8d %s",
805 inet_toa(htonl(ip_address_pool
[i
].address
)), ip_address_pool
[i
].session
, session
[ip_address_pool
[i
].session
].user
);
811 if (ip_address_pool
[i
].last
)
812 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
813 inet_toa(htonl(ip_address_pool
[i
].address
)), "",
814 ip_address_pool
[i
].user
, time_now
- ip_address_pool
[i
].last
);
816 cli_print(cli
, "%-15s\tN", inet_toa(htonl(ip_address_pool
[i
].address
)));
823 cli_print(cli
, "(Not displaying unused addresses)");
825 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
829 void print_save_config(struct cli_def
*cli
, char *string
)
832 fprintf(save_config_fh
, "%s\n", string
);
835 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
837 if (CLI_HELP_REQUESTED
)
838 return CLI_HELP_NO_ARGS
;
840 if ((save_config_fh
= fopen(config
->config_file
, "w")))
842 cli_print(cli
, "Writing configuration");
843 cli_print_callback(cli
, print_save_config
);
844 cmd_show_run(cli
, command
, argv
, argc
);
845 cli_print_callback(cli
, NULL
);
846 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 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 cmd_router_bgp_exit(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1882 if (CLI_HELP_REQUESTED
)
1883 return CLI_HELP_NO_ARGS
;
1885 cli_set_configmode(cli
, MODE_CONFIG
, NULL
);
1889 static int find_bgp_neighbour(char *name
)
1894 in_addr_t addrs
[4] = { 0 };
1897 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1900 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1901 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1903 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1905 if (!config
->neighbour
[i
].name
[0])
1907 if (new == -1) new = i
;
1911 if (!strcmp(name
, config
->neighbour
[i
].name
))
1914 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
1917 for (a
= h
->h_addr_list
; *a
; a
++)
1920 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
1921 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
1929 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1935 if (CLI_HELP_REQUESTED
)
1940 return cli_arg_help(cli
, 0,
1941 "A.B.C.D", "BGP neighbour address",
1942 "NAME", "BGP neighbour name",
1946 return cli_arg_help(cli
, 0,
1947 "remote-as", "Set remote autonomous system number",
1948 "timers", "Set timers",
1952 if (!strncmp("remote-as", argv
[1], strlen(argv
[1])))
1953 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
1955 if (!strncmp("timers", argv
[1], strlen(argv
[1])))
1958 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
1961 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
1963 if (argc
== 5 && !argv
[4][1])
1964 return cli_arg_help(cli
, 1, NULL
);
1973 cli_print(cli
, "Invalid arguments");
1977 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
1979 cli_print(cli
, "Invalid neighbour");
1985 cli_print(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
1989 if (!strncmp("remote-as", argv
[1], strlen(argv
[1])))
1991 int as
= atoi(argv
[2]);
1992 if (as
< 0 || as
> 65535)
1994 cli_print(cli
, "Invalid autonomous system number");
1998 if (!config
->neighbour
[i
].name
[0])
2000 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), argv
[0]);
2001 config
->neighbour
[i
].keepalive
= -1;
2002 config
->neighbour
[i
].hold
= -1;
2005 config
->neighbour
[i
].as
= as
;
2009 if (argc
!= 4 || strncmp("timers", argv
[1], strlen(argv
[1])))
2011 cli_print(cli
, "Invalid arguments");
2015 if (!config
->neighbour
[i
].name
[0])
2017 cli_print(cli
, "Specify remote-as first");
2021 keepalive
= atoi(argv
[2]);
2022 hold
= atoi(argv
[3]);
2024 if (keepalive
< 1 || keepalive
> 65535)
2026 cli_print(cli
, "Invalid keepalive time");
2030 if (hold
< 3 || hold
> 65535)
2032 cli_print(cli
, "Invalid hold time");
2036 if (keepalive
== BGP_KEEPALIVE_TIME
)
2037 keepalive
= -1; // using default value
2039 if (hold
== BGP_HOLD_TIME
)
2042 config
->neighbour
[i
].keepalive
= keepalive
;
2043 config
->neighbour
[i
].hold
= hold
;
2048 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2052 if (CLI_HELP_REQUESTED
)
2053 return cli_arg_help(cli
, argc
> 0,
2054 "A.B.C.D", "BGP neighbour address",
2055 "NAME", "BGP neighbour name",
2060 cli_print(cli
, "Specify a BGP neighbour");
2064 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2066 cli_print(cli
, "Invalid neighbour");
2070 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2072 cli_print(cli
, "Neighbour %s not configured", argv
[0]);
2076 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2080 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2086 if (!bgp_configured
)
2089 if (CLI_HELP_REQUESTED
)
2090 return cli_arg_help(cli
, 1,
2091 "A.B.C.D", "BGP neighbour address",
2092 "NAME", "BGP neighbour name",
2095 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2096 BGP_VERSION
, inet_toa(my_address
), (int) config
->as_number
);
2100 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2102 if (!*bgp_peers
[i
].name
)
2105 addr
= inet_toa(bgp_peers
[i
].addr
);
2106 if (argc
&& strcmp(addr
, argv
[0]) &&
2107 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2113 cli_print(cli
, "Peer AS Address "
2114 "State Retries Retry in Route Pend Timers");
2115 cli_print(cli
, "------------------ ----- --------------- "
2116 "----------- ------- -------- ----- ---- ---------");
2119 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7ds %5s %4s %4d %4d",
2123 bgp_state_str(bgp_peers
[i
].state
),
2124 bgp_peers
[i
].retry_count
,
2125 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2126 bgp_peers
[i
].routing
? "yes" : "no",
2127 bgp_peers
[i
].update_routes
? "yes" : "no",
2128 bgp_peers
[i
].keepalive
,
2135 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2140 if (!bgp_configured
)
2143 if (CLI_HELP_REQUESTED
)
2144 return cli_arg_help(cli
, 1,
2145 "A.B.C.D", "BGP neighbour address",
2146 "NAME", "BGP neighbour name",
2149 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2151 if (bgp_peers
[i
].state
!= Established
)
2154 if (!bgp_peers
[i
].routing
)
2157 addr
= inet_toa(bgp_peers
[i
].addr
);
2158 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2161 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2162 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2168 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2173 if (!bgp_configured
)
2176 if (CLI_HELP_REQUESTED
)
2177 return cli_arg_help(cli
, 1,
2178 "A.B.C.D", "BGP neighbour address",
2179 "NAME", "BGP neighbour name",
2182 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2184 if (bgp_peers
[i
].state
!= Established
)
2187 if (bgp_peers
[i
].routing
)
2190 addr
= inet_toa(bgp_peers
[i
].addr
);
2191 if (argc
&& strcmp(addr
, argv
[0]) &&
2192 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2195 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2196 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2202 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2207 if (!bgp_configured
)
2210 if (CLI_HELP_REQUESTED
)
2211 return cli_arg_help(cli
, 1,
2212 "A.B.C.D", "BGP neighbour address",
2213 "NAME", "BGP neighbour name",
2216 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2218 if (!*bgp_peers
[i
].name
)
2221 addr
= inet_toa(bgp_peers
[i
].addr
);
2222 if (argc
&& strcmp(addr
, argv
[0]) &&
2223 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2226 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2227 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2234 // Convert a string in the form of abcd.ef12.3456 into char[6]
2235 void parsemac(char *string
, char mac
[6])
2237 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)
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)