1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.69 2005/12/05 14:10:42 bodea Exp $";
19 #include <arpa/inet.h>
21 #include <sys/socket.h>
22 #include <sys/types.h>
29 #include "constants.h"
38 extern tunnelt
*tunnel
;
39 extern sessiont
*session
;
40 extern radiust
*radius
;
41 extern ippoolt
*ip_address_pool
;
42 extern struct Tstats
*_statistics
;
43 static struct cli_def
*cli
= NULL
;
44 extern configt
*config
;
45 extern config_descriptt config_values
[];
47 extern struct Tringbuffer
*ringbuffer
;
49 extern struct cli_session_actions
*cli_session_actions
;
50 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
51 extern tbft
*filter_list
;
52 extern ip_filtert
*ip_filters
;
66 static int debug_rb_tail
;
67 static char *debug_levels
[] = {
78 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
79 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
100 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
101 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
103 static int regular_stuff(struct cli_def
*cli
);
104 static void parsemac(char *string
, char mac
[6]);
107 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
108 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
109 #endif /* STATISTICS */
112 #define MODE_CONFIG_BGP 8
113 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
114 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
115 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
116 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
117 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
118 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
119 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 #define MODE_CONFIG_NACL 9
123 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
124 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
125 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
126 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
127 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
128 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
130 /* match if b is a substr of a */
131 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
133 void init_cli(char *hostname
)
137 struct cli_command
*c
;
138 struct cli_command
*c2
;
140 struct sockaddr_in addr
;
143 if (hostname
&& *hostname
)
144 cli_set_hostname(cli
, hostname
);
146 cli_set_hostname(cli
, "l2tpns");
148 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
149 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
151 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
153 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
154 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
155 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
156 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
157 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
158 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
159 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
160 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
161 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
162 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
163 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");
164 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
165 cli_register_command(cli
, c
, "access-list", cmd_show_access_list
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show named access-list");
167 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
168 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
169 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
172 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
174 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
175 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
178 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
180 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
181 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
182 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
184 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
185 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
186 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
187 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
190 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
191 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
194 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
195 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
196 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
197 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
198 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
201 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
202 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
204 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
205 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
207 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
208 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
210 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
212 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
213 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
216 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
217 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
218 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
219 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
221 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
222 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
224 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
225 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
227 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
229 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
230 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
232 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
233 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
235 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
236 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
237 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
239 // Enable regular processing
240 cli_regular(cli
, regular_stuff
);
242 if (!(f
= fopen(CLIUSERS
, "r")))
244 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
248 while (fgets(buf
, 4096, f
))
251 if (*buf
== '#') continue;
252 if ((p
= strchr(buf
, '\r'))) *p
= 0;
253 if ((p
= strchr(buf
, '\n'))) *p
= 0;
255 if (!(p
= strchr((char *)buf
, ':'))) continue;
257 if (!strcmp(buf
, "enable"))
259 cli_allow_enable(cli
, p
);
260 LOG(3, 0, 0, "Setting enable password\n");
264 cli_allow_user(cli
, buf
, p
);
265 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
271 memset(&addr
, 0, sizeof(addr
));
272 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
273 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
276 // Set cli fd as non-blocking
277 flags
= fcntl(clifd
, F_GETFL
, 0);
278 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
280 addr
.sin_family
= AF_INET
;
281 addr
.sin_port
= htons(23);
282 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
284 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
290 void cli_do(int sockfd
)
292 int require_auth
= 1;
293 struct sockaddr_in addr
;
294 socklen_t l
= sizeof(addr
);
296 if (fork_and_close()) return;
297 if (getpeername(sockfd
, (struct sockaddr
*) &addr
, &l
) == 0)
299 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
300 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
301 fmtaddr(addr
.sin_addr
.s_addr
, 0));
304 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
308 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
309 if (!cli
->users
) /* paranoia */
311 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
317 /* no username/pass required */
322 debug_rb_tail
= ringbuffer
->tail
;
324 memset(&debug_flags
, 0, sizeof(debug_flags
));
325 debug_flags
.critical
= 1;
327 cli_loop(cli
, sockfd
);
330 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
331 fmtaddr(addr
.sin_addr
.s_addr
, 0));
336 static void cli_print_log(struct cli_def
*cli
, char *string
)
338 LOG(3, 0, 0, "%s\n", string
);
341 void cli_do_file(FILE *fh
)
343 LOG(3, 0, 0, "Reading configuration file\n");
344 cli_print_callback(cli
, cli_print_log
);
345 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
346 cli_print_callback(cli
, NULL
);
349 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
360 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
362 int v
= va_arg(ap
, int);
363 snprintf(buf
, sizeof(buf
), entry
, v
);
369 desc
= va_arg(ap
, char *);
371 cli_error(cli
, " %-20s %s", p
, desc
);
373 cli_error(cli
, " %s", p
);
375 entry
= desc
? va_arg(ap
, char *) : 0;
380 cli_error(cli
, " <cr>");
385 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
389 if (CLI_HELP_REQUESTED
)
390 return cli_arg_help(cli
, 1,
391 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
397 // Show individual session
398 for (i
= 0; i
< argc
; i
++)
400 unsigned int s
, b_in
, b_out
;
402 if (s
<= 0 || s
>= MAXSESSION
)
404 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
407 cli_print(cli
, "\r\nSession %d:", s
);
408 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
409 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
410 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
411 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
412 cli_print(cli
, "\tPPP Phase:\t%s", ppp_phase(session
[s
].ppp
.phase
));
413 switch (session
[s
].ppp
.phase
)
416 cli_print(cli
, "\t LCP state:\t%s", ppp_state(session
[s
].ppp
.lcp
));
421 cli_print(cli
, "\t IPCP state:\t%s", ppp_state(session
[s
].ppp
.ipcp
));
422 cli_print(cli
, "\t IPV6CP state:\t%s", ppp_state(session
[s
].ppp
.ipv6cp
));
423 cli_print(cli
, "\t CCP state:\t%s", ppp_state(session
[s
].ppp
.ccp
));
425 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
426 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
427 cli_print(cli
, "\tOpened:\t\t%u seconds", session
[s
].opened
? abs(time_now
- session
[s
].opened
) : 0);
428 cli_print(cli
, "\tIdle time:\t%u seconds", session
[s
].last_packet
? abs(time_now
- session
[s
].last_packet
) : 0);
429 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
430 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
431 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
432 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
433 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
434 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
435 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
436 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
437 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
438 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
439 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
441 cli_print(cli
, "\tIntercepted:\tno");
443 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
445 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
446 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
447 t
? "YES" : "no", t
? " (" : "",
448 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
450 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
454 b_in
= session
[s
].tbf_in
;
455 b_out
= session
[s
].tbf_out
;
457 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
458 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
459 "ByteSent", "PackSent", "PackDrop", "PackDelay");
462 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
464 (filter_list
[b_in
].next
? "*" : " "),
465 (b_in
< 100 ? "\t" : ""),
466 filter_list
[b_in
].rate
* 8,
467 filter_list
[b_in
].credit
,
468 filter_list
[b_in
].queued
,
469 filter_list
[b_in
].b_queued
,
470 filter_list
[b_in
].p_queued
,
471 filter_list
[b_in
].b_sent
,
472 filter_list
[b_in
].p_sent
,
473 filter_list
[b_in
].p_dropped
,
474 filter_list
[b_in
].p_delayed
);
477 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
479 (filter_list
[b_out
].next
? "*" : " "),
480 (b_out
< 100 ? "\t" : ""),
481 filter_list
[b_out
].rate
* 8,
482 filter_list
[b_out
].credit
,
483 filter_list
[b_out
].queued
,
484 filter_list
[b_out
].b_queued
,
485 filter_list
[b_out
].p_queued
,
486 filter_list
[b_out
].b_sent
,
487 filter_list
[b_out
].p_sent
,
488 filter_list
[b_out
].p_dropped
,
489 filter_list
[b_out
].p_delayed
);
496 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %-15s %s",
512 for (i
= 1; i
< MAXSESSION
; i
++)
514 if (!session
[i
].opened
) continue;
515 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %-15s %s",
518 session
[i
].user
[0] ? session
[i
].user
: "*",
519 fmtaddr(htonl(session
[i
].ip
), 0),
520 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
521 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
522 (session
[i
].walled_garden
) ? "Y" : "N",
523 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
524 abs(time_now
- (unsigned long)session
[i
].opened
),
525 (unsigned long)session
[i
].cout
,
526 (unsigned long)session
[i
].cin
,
527 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
528 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
529 session
[i
].calling
[0] ? session
[i
].calling
: "*");
534 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
536 int i
, x
, show_all
= 0;
544 if (CLI_HELP_REQUESTED
)
547 return cli_arg_help(cli
, 1,
548 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
551 return cli_arg_help(cli
, 1,
552 "all", "Show all tunnels, including unused",
553 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
560 if (strcmp(argv
[0], "all") == 0)
566 // Show individual tunnel
567 for (i
= 0; i
< argc
; i
++)
572 if (t
<= 0 || t
>= MAXTUNNEL
)
574 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
577 cli_print(cli
, "\r\nTunnel %d:", t
);
578 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
579 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
580 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
581 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
582 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
583 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
584 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
585 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
586 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
588 for (x
= 0; x
< MAXSESSION
; x
++)
589 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
590 sprintf(s
, "%s%u ", s
, x
);
592 cli_print(cli
, "\tSessions:\t%s", s
);
598 // Show tunnel summary
599 cli_print(cli
, "%4s %20s %20s %6s %s",
606 for (i
= 1; i
< MAXTUNNEL
; i
++)
609 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
611 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
612 cli_print(cli
, "%4d %20s %20s %6s %6d",
614 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
615 fmtaddr(htonl(tunnel
[i
].ip
), 0),
616 states
[tunnel
[i
].state
],
623 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
630 if (CLI_HELP_REQUESTED
)
631 return cli_arg_help(cli
, 1,
632 "USER", "Show details for specific username",
635 for (i
= 0; i
< MAXSESSION
; i
++)
637 if (!session
[i
].opened
) continue;
638 if (!session
[i
].user
[0]) continue;
642 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
644 if (strcmp(argv
[j
], session
[i
].user
) == 0)
646 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
647 sargv
[sargc
] = sid
[sargc
];
655 cli_print(cli
, "%s", session
[i
].user
);
659 return cmd_show_session(cli
, "users", sargv
, sargc
);
665 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
667 if (CLI_HELP_REQUESTED
)
668 return CLI_HELP_NO_ARGS
;
670 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
671 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
672 GET_STAT(tun_rx_bytes
),
673 GET_STAT(tun_rx_packets
),
674 GET_STAT(tun_rx_errors
),
675 GET_STAT(tun_rx_dropped
));
676 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
677 GET_STAT(tun_tx_bytes
),
678 GET_STAT(tun_tx_packets
),
679 GET_STAT(tun_tx_errors
));
682 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
683 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
684 GET_STAT(tunnel_rx_bytes
),
685 GET_STAT(tunnel_rx_packets
),
686 GET_STAT(tunnel_rx_errors
));
687 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
688 GET_STAT(tunnel_tx_bytes
),
689 GET_STAT(tunnel_tx_packets
),
690 GET_STAT(tunnel_tx_errors
),
691 GET_STAT(tunnel_retries
));
694 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
695 cli_print(cli
, "-----------------------------------------");
696 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
697 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
698 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
699 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
700 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
701 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
702 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
703 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
704 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
705 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
706 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
707 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
708 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
709 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
710 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
711 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
712 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
713 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
717 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
718 cli_print(cli
, "-----------------------------------------");
719 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
720 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
721 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
722 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
723 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
724 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
725 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
726 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
727 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
728 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
729 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
730 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
731 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
732 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
733 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
734 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
735 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
736 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
737 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
738 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
739 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
740 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
741 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
742 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
743 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
744 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
745 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
746 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
747 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
748 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
749 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
750 #endif /* STAT_CALLS */
753 time_t l
= GET_STAT(last_reset
);
755 char *p
= strchr(t
, '\n');
759 cli_print(cli
, "Last counter reset %s", t
);
765 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
767 if (CLI_HELP_REQUESTED
)
768 return CLI_HELP_NO_ARGS
;
770 memset(_statistics
, 0, sizeof(struct Tstats
));
771 SET_STAT(last_reset
, time(NULL
));
773 cli_print(cli
, "Counters cleared");
776 #endif /* STATISTICS */
778 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
784 if (CLI_HELP_REQUESTED
)
785 return cli_arg_help(cli
, 1,
786 "tag", "Include CVS release tag",
787 "file", "Include file versions",
790 for (i
= 0; i
< argc
; i
++)
791 if (!strcmp(argv
[i
], "tag"))
793 else if (!strcmp(argv
[i
], "file"))
796 cli_print(cli
, "L2TPNS %s", VERSION
);
799 char const *p
= strchr(cvs_name
, ':');
811 e
= strpbrk(p
, " \t$");
812 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
817 extern linked_list
*loaded_plugins
;
820 cli_print(cli
, "Files:");
821 cli_print(cli
, " %s", cvs_id_arp
);
823 cli_print(cli
, " %s", cvs_id_bgp
);
825 cli_print(cli
, " %s", cvs_id_cli
);
826 cli_print(cli
, " %s", cvs_id_cluster
);
827 cli_print(cli
, " %s", cvs_id_constants
);
828 cli_print(cli
, " %s", cvs_id_control
);
829 cli_print(cli
, " %s", cvs_id_icmp
);
830 cli_print(cli
, " %s", cvs_id_l2tpns
);
831 cli_print(cli
, " %s", cvs_id_ll
);
832 cli_print(cli
, " %s", cvs_id_ppp
);
833 cli_print(cli
, " %s", cvs_id_radius
);
834 cli_print(cli
, " %s", cvs_id_tbf
);
835 cli_print(cli
, " %s", cvs_id_util
);
837 ll_reset(loaded_plugins
);
838 while ((p
= ll_next(loaded_plugins
)))
840 char const **id
= dlsym(p
, "cvs_id");
842 cli_print(cli
, " %s", *id
);
849 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
852 int used
= 0, free
= 0, show_all
= 0;
854 if (!config
->cluster_iam_master
)
856 cli_print(cli
, "Can't do this on a slave. Do it on %s",
857 fmtaddr(config
->cluster_master_address
, 0));
862 if (CLI_HELP_REQUESTED
)
865 return cli_arg_help(cli
, 1, NULL
);
867 return cli_arg_help(cli
, 1,
868 "all", "Show all pool addresses, including unused",
872 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
876 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
877 for (i
= 0; i
< MAXIPPOOL
; i
++)
879 if (!ip_address_pool
[i
].address
) continue;
880 if (ip_address_pool
[i
].assigned
)
882 cli_print(cli
, "%-15s\tY %8d %s",
883 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
884 ip_address_pool
[i
].session
,
885 session
[ip_address_pool
[i
].session
].user
);
891 if (ip_address_pool
[i
].last
)
892 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
893 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
894 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
897 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
904 cli_print(cli
, "(Not displaying unused addresses)");
906 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
910 static FILE *save_config_fh
= 0;
911 static void print_save_config(struct cli_def
*cli
, char *string
)
914 fprintf(save_config_fh
, "%s\n", string
);
917 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
919 if (CLI_HELP_REQUESTED
)
920 return CLI_HELP_NO_ARGS
;
922 if ((save_config_fh
= fopen(config
->config_file
, "w")))
924 cli_print(cli
, "Writing configuration");
925 cli_print_callback(cli
, print_save_config
);
926 cmd_show_run(cli
, command
, argv
, argc
);
927 cli_print_callback(cli
, NULL
);
928 fclose(save_config_fh
);
933 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
938 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
940 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
943 char ipv6addr
[INET6_ADDRSTRLEN
];
945 if (CLI_HELP_REQUESTED
)
946 return CLI_HELP_NO_ARGS
;
948 cli_print(cli
, "# Current configuration:");
950 for (i
= 0; config_values
[i
].key
; i
++)
952 void *value
= ((void *)config
) + config_values
[i
].offset
;
953 if (config_values
[i
].type
== STRING
)
954 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
955 else if (config_values
[i
].type
== IPv4
)
956 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
957 else if (config_values
[i
].type
== IPv6
)
958 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
959 else if (config_values
[i
].type
== SHORT
)
960 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
961 else if (config_values
[i
].type
== BOOL
)
962 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
963 else if (config_values
[i
].type
== INT
)
964 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
965 else if (config_values
[i
].type
== UNSIGNED_LONG
)
966 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
967 else if (config_values
[i
].type
== MAC
)
968 cli_print(cli
, "set %s %02x%02x.%02x%02x.%02x%02x", config_values
[i
].key
,
969 *(unsigned short *) (value
+ 0),
970 *(unsigned short *) (value
+ 1),
971 *(unsigned short *) (value
+ 2),
972 *(unsigned short *) (value
+ 3),
973 *(unsigned short *) (value
+ 4),
974 *(unsigned short *) (value
+ 5));
977 cli_print(cli
, "# Plugins");
978 for (i
= 0; i
< MAXPLUGINS
; i
++)
980 if (*config
->plugins
[i
])
982 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
987 if (config
->as_number
)
992 cli_print(cli
, "# BGP");
993 cli_print(cli
, "router bgp %u", config
->as_number
);
994 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
996 if (!config
->neighbour
[i
].name
[0])
999 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1001 k
= config
->neighbour
[i
].keepalive
;
1002 h
= config
->neighbour
[i
].hold
;
1009 k
= BGP_KEEPALIVE_TIME
;
1015 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1020 cli_print(cli
, "# Filters");
1021 for (i
= 0; i
< MAXFILTER
; i
++)
1023 ip_filter_rulet
*rules
;
1024 if (!*ip_filters
[i
].name
)
1027 cli_print(cli
, "ip access-list %s %s",
1028 ip_filters
[i
].extended
? "extended" : "standard",
1029 ip_filters
[i
].name
);
1031 rules
= ip_filters
[i
].rules
;
1032 while (rules
->action
)
1033 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1036 cli_print(cli
, "# end");
1040 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1042 int i
, free
= 0, used
= 0, show_all
= 0;
1054 if (CLI_HELP_REQUESTED
)
1057 return cli_arg_help(cli
, 1, NULL
);
1059 return cli_arg_help(cli
, 1,
1060 "all", "Show all RADIUS sessions, including unused",
1064 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1068 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1071 for (i
= 1; i
< MAXRADIUS
; i
++)
1073 if (radius
[i
].state
== RADIUSNULL
)
1078 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1080 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1084 states
[radius
[i
].state
],
1090 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1095 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1099 if (CLI_HELP_REQUESTED
)
1100 return CLI_HELP_NO_ARGS
;
1102 cli_print(cli
, "Plugins currently loaded:");
1103 for (i
= 0; i
< MAXPLUGINS
; i
++)
1104 if (*config
->plugins
[i
])
1105 cli_print(cli
, " %s", config
->plugins
[i
]);
1110 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1114 if (CLI_HELP_REQUESTED
)
1115 return CLI_HELP_NO_ARGS
;
1117 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1126 for (i
= 0; i
< MAXSESSION
; i
++)
1128 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1129 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1133 session
[i
].throttle_in
,
1134 session
[i
].throttle_out
,
1136 session
[i
].tbf_out
);
1142 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1144 if (CLI_HELP_REQUESTED
)
1145 return CLI_HELP_NO_ARGS
;
1147 cli_print(cli
, " _\n"
1153 " ( \\ `. `-. _,.-:\\\n"
1154 " \\ \\ `. `-._ __..--' ,-';/\n"
1155 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1156 " `. `. `-._ __..--' ,' /\n"
1157 " `. `-_ ``--..'' _.-' ,'\n"
1158 " `-_ `-.___ __,--' ,'\n"
1159 " `-.__ `----\"\"\" __.-'\n"
1160 "hh `--..____..--'");
1165 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1170 if (CLI_HELP_REQUESTED
)
1171 return cli_arg_help(cli
, argc
> 1,
1172 "USER", "Username of session to drop", NULL
);
1174 if (!config
->cluster_iam_master
)
1176 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1177 fmtaddr(config
->cluster_master_address
, 0));
1184 cli_error(cli
, "Specify a user to drop");
1188 for (i
= 0; i
< argc
; i
++)
1190 if (!(s
= sessionbyuser(argv
[i
])))
1192 cli_error(cli
, "User %s is not connected", argv
[i
]);
1196 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1198 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1199 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1206 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1211 if (CLI_HELP_REQUESTED
)
1212 return cli_arg_help(cli
, argc
> 1,
1213 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1215 if (!config
->cluster_iam_master
)
1217 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1218 fmtaddr(config
->cluster_master_address
, 0));
1225 cli_error(cli
, "Specify a tunnel to drop");
1229 for (i
= 0; i
< argc
; i
++)
1231 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1233 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1239 cli_error(cli
, "Tunnel %d is not connected", t
);
1245 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1249 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1250 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1256 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1261 if (CLI_HELP_REQUESTED
)
1262 return cli_arg_help(cli
, argc
> 1,
1263 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1265 if (!config
->cluster_iam_master
)
1267 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1268 fmtaddr(config
->cluster_master_address
, 0));
1275 cli_error(cli
, "Specify a session id to drop");
1279 for (i
= 0; i
< argc
; i
++)
1281 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1283 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1287 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1289 cli_print(cli
, "Dropping session %d", s
);
1290 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1294 cli_error(cli
, "Session %d is not active.", s
);
1301 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1307 if (CLI_HELP_REQUESTED
)
1312 return cli_arg_help(cli
, 0,
1313 "USER", "Username of session to snoop", NULL
);
1316 return cli_arg_help(cli
, 0,
1317 "A.B.C.D", "IP address of snoop destination", NULL
);
1320 return cli_arg_help(cli
, 0,
1321 "N", "Port of snoop destination", NULL
);
1325 return cli_arg_help(cli
, 1, NULL
);
1332 if (!config
->cluster_iam_master
)
1334 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1335 fmtaddr(config
->cluster_master_address
, 0));
1342 cli_error(cli
, "Specify username, ip and port");
1346 if (!(s
= sessionbyuser(argv
[0])))
1348 cli_error(cli
, "User %s is not connected", argv
[0]);
1352 ip
= inet_addr(argv
[1]);
1353 if (!ip
|| ip
== INADDR_NONE
)
1355 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1359 port
= atoi(argv
[2]);
1362 cli_error(cli
, "Invalid port %s", argv
[2]);
1366 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1367 cli_session_actions
[s
].snoop_ip
= ip
;
1368 cli_session_actions
[s
].snoop_port
= port
;
1369 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1374 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1379 if (CLI_HELP_REQUESTED
)
1380 return cli_arg_help(cli
, argc
> 1,
1381 "USER", "Username of session to unsnoop", NULL
);
1383 if (!config
->cluster_iam_master
)
1385 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1386 fmtaddr(config
->cluster_master_address
, 0));
1393 cli_error(cli
, "Specify a user to unsnoop");
1397 for (i
= 0; i
< argc
; i
++)
1399 if (!(s
= sessionbyuser(argv
[i
])))
1401 cli_error(cli
, "User %s is not connected", argv
[i
]);
1405 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1406 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1412 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1419 throttle USER - throttle in/out to default rate
1420 throttle USER RATE - throttle in/out to default rate
1421 throttle USER in RATE - throttle input only
1422 throttle USER out RATE - throttle output only
1423 throttle USER in RATE out RATE - throttle both
1426 if (CLI_HELP_REQUESTED
)
1431 return cli_arg_help(cli
, 0,
1432 "USER", "Username of session to throttle", NULL
);
1435 return cli_arg_help(cli
, 1,
1436 "RATE", "Rate in kbps (in and out)",
1437 "in", "Select incoming rate",
1438 "out", "Select outgoing rate", NULL
);
1441 return cli_arg_help(cli
, 1,
1442 "in", "Select incoming rate",
1443 "out", "Select outgoing rate", NULL
);
1446 if (isdigit(argv
[1][0]))
1447 return cli_arg_help(cli
, 1, NULL
);
1450 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1453 return cli_arg_help(cli
, argc
> 1, NULL
);
1457 if (!config
->cluster_iam_master
)
1459 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1460 fmtaddr(config
->cluster_master_address
, 0));
1467 cli_error(cli
, "Specify a user to throttle");
1471 if (!(s
= sessionbyuser(argv
[0])))
1473 cli_error(cli
, "User %s is not connected", argv
[0]);
1479 rate_in
= rate_out
= config
->rl_rate
;
1483 rate_in
= rate_out
= atoi(argv
[1]);
1486 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1490 else if (argc
== 3 || argc
== 5)
1493 for (i
= 1; i
< argc
- 1; i
+= 2)
1496 if (MATCH("in", argv
[i
]))
1497 r
= rate_in
= atoi(argv
[i
+1]);
1498 else if (MATCH("out", argv
[i
]))
1499 r
= rate_out
= atoi(argv
[i
+1]);
1503 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1510 cli_error(cli
, "Invalid arguments");
1514 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1516 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1520 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1521 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1522 cli_session_actions
[s
].throttle_in
= rate_in
;
1524 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1525 cli_session_actions
[s
].throttle_out
= rate_out
;
1527 if (cli_session_actions
[s
].throttle_in
== -1 &&
1528 cli_session_actions
[s
].throttle_out
== -1)
1530 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1534 cli_print(cli
, "Throttling user %s", argv
[0]);
1535 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1540 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1545 if (CLI_HELP_REQUESTED
)
1546 return cli_arg_help(cli
, argc
> 1,
1547 "USER", "Username of session to unthrottle", NULL
);
1549 if (!config
->cluster_iam_master
)
1551 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1552 fmtaddr(config
->cluster_master_address
, 0));
1559 cli_error(cli
, "Specify a user to unthrottle");
1563 for (i
= 0; i
< argc
; i
++)
1565 if (!(s
= sessionbyuser(argv
[i
])))
1567 cli_error(cli
, "User %s is not connected", argv
[i
]);
1571 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1573 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1574 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1578 cli_error(cli
, "User %s not throttled", argv
[i
]);
1585 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1589 if (CLI_HELP_REQUESTED
)
1590 return cli_arg_help(cli
, 1,
1591 "all", "Enable debugging for all except \"data\"",
1592 "critical", "", // FIXME: add descriptions
1602 char *p
= (char *) &debug_flags
;
1603 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1607 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1608 (debug_flags
.critical
) ? " critical" : "",
1609 (debug_flags
.error
) ? " error" : "",
1610 (debug_flags
.warning
) ? " warning" : "",
1611 (debug_flags
.info
) ? " info" : "",
1612 (debug_flags
.calls
) ? " calls" : "",
1613 (debug_flags
.data
) ? " data" : "");
1619 cli_print(cli
, "Debugging off");
1623 for (i
= 0; i
< argc
; i
++)
1625 int len
= strlen(argv
[i
]);
1627 if (argv
[i
][0] == 'c' && len
< 2)
1628 len
= 2; /* distinguish [cr]itical from [ca]lls */
1630 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1631 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1632 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1633 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1634 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1635 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1636 if (!strncmp("all", argv
[i
], len
))
1638 memset(&debug_flags
, 1, sizeof(debug_flags
));
1639 debug_flags
.data
= 0;
1643 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1649 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1653 if (CLI_HELP_REQUESTED
)
1654 return cli_arg_help(cli
, 1,
1655 "all", "Disable all debugging",
1656 "critical", "", // FIXME: add descriptions
1666 memset(&debug_flags
, 0, sizeof(debug_flags
));
1670 for (i
= 0; i
< argc
; i
++)
1672 int len
= strlen(argv
[i
]);
1674 if (argv
[i
][0] == 'c' && len
< 2)
1675 len
= 2; /* distinguish [cr]itical from [ca]lls */
1677 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1678 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1679 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1680 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1681 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1682 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1683 if (!strncmp("all", argv
[i
], len
))
1685 memset(&debug_flags
, 0, sizeof(debug_flags
));
1689 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1695 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1697 int i
, firstfree
= 0;
1699 if (CLI_HELP_REQUESTED
)
1700 return cli_arg_help(cli
, argc
> 1,
1701 "PLUGIN", "Name of plugin to load", NULL
);
1705 cli_error(cli
, "Specify a plugin to load");
1709 for (i
= 0; i
< MAXPLUGINS
; i
++)
1711 if (!*config
->plugins
[i
] && !firstfree
)
1713 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1715 cli_error(cli
, "Plugin is already loaded");
1722 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1723 config
->reload_config
= 1;
1724 cli_print(cli
, "Loading plugin %s", argv
[0]);
1730 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1734 if (CLI_HELP_REQUESTED
)
1735 return cli_arg_help(cli
, argc
> 1,
1736 "PLUGIN", "Name of plugin to unload", NULL
);
1740 cli_error(cli
, "Specify a plugin to remove");
1744 for (i
= 0; i
< MAXPLUGINS
; i
++)
1746 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1748 config
->reload_config
= 1;
1749 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1754 cli_error(cli
, "Plugin is not loaded");
1758 static char *duration(time_t secs
)
1760 static char *buf
= NULL
;
1763 if (!buf
) buf
= calloc(64, 1);
1767 int days
= secs
/ 86400;
1768 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1774 int mins
= secs
/ 60;
1775 int hrs
= mins
/ 60;
1778 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1780 else if (secs
>= 60)
1782 int mins
= secs
/ 60;
1783 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1786 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1791 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1794 char buf
[100], *p
= buf
, *loads
[3];
1795 int i
, num_sessions
= 0;
1797 if (CLI_HELP_REQUESTED
)
1798 return CLI_HELP_NO_ARGS
;
1800 fh
= fopen("/proc/loadavg", "r");
1801 fgets(buf
, 100, fh
);
1804 for (i
= 0; i
< 3; i
++)
1805 loads
[i
] = strdup(strsep(&p
, " "));
1808 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1810 for (i
= 1; i
< MAXSESSION
; i
++)
1811 if (session
[i
].opened
) num_sessions
++;
1813 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1815 duration(time_now
- config
->start_time
),
1817 loads
[0], loads
[1], loads
[2]
1819 for (i
= 0; i
< 3; i
++)
1820 if (loads
[i
]) free(loads
[i
]);
1822 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1827 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1831 if (CLI_HELP_REQUESTED
)
1837 int len
= strlen(argv
[0])-1;
1838 for (i
= 0; config_values
[i
].key
; i
++)
1839 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1840 cli_error(cli
, " %s", config_values
[i
].key
);
1846 return cli_arg_help(cli
, 0,
1847 "VALUE", "Value for variable", NULL
);
1851 return cli_arg_help(cli
, 1, NULL
);
1860 cli_error(cli
, "Specify variable and value");
1864 for (i
= 0; config_values
[i
].key
; i
++)
1866 void *value
= ((void *) config
) + config_values
[i
].offset
;
1867 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1869 // Found a value to set
1870 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1871 switch (config_values
[i
].type
)
1874 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1877 *(int *) value
= atoi(argv
[1]);
1880 *(unsigned long *) value
= atol(argv
[1]);
1883 *(short *) value
= atoi(argv
[1]);
1886 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1889 inet_pton(AF_INET6
, argv
[1], value
);
1892 parsemac(argv
[1], (char *)value
);
1895 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1901 cli_error(cli
, "Unknown variable type");
1904 config
->reload_config
= 1;
1909 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1913 int regular_stuff(struct cli_def
*cli
)
1919 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1921 char *m
= ringbuffer
->buffer
[i
].message
;
1927 switch (ringbuffer
->buffer
[i
].level
)
1929 case 0: show
= debug_flags
.critical
; break;
1930 case 1: show
= debug_flags
.error
; break;
1931 case 2: show
= debug_flags
.warning
; break;
1932 case 3: show
= debug_flags
.info
; break;
1933 case 4: show
= debug_flags
.calls
; break;
1934 case 5: show
= debug_flags
.data
; break;
1937 if (!show
) continue;
1939 if (!(p
= strchr(m
, '\n')))
1942 cli_error(cli
, "\r%s-%u-%u %.*s",
1943 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1944 ringbuffer
->buffer
[i
].tunnel
,
1945 ringbuffer
->buffer
[i
].session
,
1951 debug_rb_tail
= ringbuffer
->tail
;
1959 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1963 if (CLI_HELP_REQUESTED
)
1964 return cli_arg_help(cli
, argc
> 1,
1965 "<1-65535>", "Autonomous system number", NULL
);
1967 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1969 cli_error(cli
, "Invalid autonomous system number");
1973 if (bgp_configured
&& as
!= config
->as_number
)
1975 cli_error(cli
, "Can't change local AS on a running system");
1979 config
->as_number
= as
;
1980 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1985 static int find_bgp_neighbour(char const *name
)
1990 in_addr_t addrs
[4] = { 0 };
1993 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1996 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1997 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1999 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2001 if (!config
->neighbour
[i
].name
[0])
2003 if (new == -1) new = i
;
2007 if (!strcmp(name
, config
->neighbour
[i
].name
))
2010 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2013 for (a
= h
->h_addr_list
; *a
; a
++)
2016 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2017 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2025 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2031 if (CLI_HELP_REQUESTED
)
2036 return cli_arg_help(cli
, 0,
2037 "A.B.C.D", "BGP neighbour address",
2038 "NAME", "BGP neighbour name",
2042 return cli_arg_help(cli
, 0,
2043 "remote-as", "Set remote autonomous system number",
2044 "timers", "Set timers",
2048 if (MATCH("remote-as", argv
[1]))
2049 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2051 if (MATCH("timers", argv
[1]))
2054 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2057 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2059 if (argc
== 5 && !argv
[4][1])
2060 return cli_arg_help(cli
, 1, NULL
);
2069 cli_error(cli
, "Invalid arguments");
2073 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2075 cli_error(cli
, "Invalid neighbour");
2081 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2085 if (MATCH("remote-as", argv
[1]))
2087 int as
= atoi(argv
[2]);
2088 if (as
< 0 || as
> 65535)
2090 cli_error(cli
, "Invalid autonomous system number");
2094 if (!config
->neighbour
[i
].name
[0])
2096 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2097 config
->neighbour
[i
].keepalive
= -1;
2098 config
->neighbour
[i
].hold
= -1;
2101 config
->neighbour
[i
].as
= as
;
2105 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2107 cli_error(cli
, "Invalid arguments");
2111 if (!config
->neighbour
[i
].name
[0])
2113 cli_error(cli
, "Specify remote-as first");
2117 keepalive
= atoi(argv
[2]);
2118 hold
= atoi(argv
[3]);
2120 if (keepalive
< 1 || keepalive
> 65535)
2122 cli_error(cli
, "Invalid keepalive time");
2126 if (hold
< 3 || hold
> 65535)
2128 cli_error(cli
, "Invalid hold time");
2132 if (keepalive
== BGP_KEEPALIVE_TIME
)
2133 keepalive
= -1; // using default value
2135 if (hold
== BGP_HOLD_TIME
)
2138 config
->neighbour
[i
].keepalive
= keepalive
;
2139 config
->neighbour
[i
].hold
= hold
;
2144 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2148 if (CLI_HELP_REQUESTED
)
2149 return cli_arg_help(cli
, argc
> 0,
2150 "A.B.C.D", "BGP neighbour address",
2151 "NAME", "BGP neighbour name",
2156 cli_error(cli
, "Specify a BGP neighbour");
2160 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2162 cli_error(cli
, "Invalid neighbour");
2166 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2168 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2172 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2176 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2182 if (!bgp_configured
)
2185 if (CLI_HELP_REQUESTED
)
2186 return cli_arg_help(cli
, 1,
2187 "A.B.C.D", "BGP neighbour address",
2188 "NAME", "BGP neighbour name",
2191 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2192 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2196 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2198 if (!*bgp_peers
[i
].name
)
2201 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2202 if (argc
&& strcmp(addr
, argv
[0]) &&
2203 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2209 cli_print(cli
, "Peer AS Address "
2210 "State Retries Retry in Route Pend Timers");
2211 cli_print(cli
, "------------------ ----- --------------- "
2212 "----------- ------- -------- ----- ---- ---------");
2215 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2219 bgp_state_str(bgp_peers
[i
].state
),
2220 bgp_peers
[i
].retry_count
,
2221 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2222 bgp_peers
[i
].routing
? "yes" : "no",
2223 bgp_peers
[i
].update_routes
? "yes" : "no",
2224 bgp_peers
[i
].keepalive
,
2231 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2236 if (!bgp_configured
)
2239 if (CLI_HELP_REQUESTED
)
2240 return cli_arg_help(cli
, 1,
2241 "A.B.C.D", "BGP neighbour address",
2242 "NAME", "BGP neighbour name",
2245 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2247 if (bgp_peers
[i
].state
!= Established
)
2250 if (!bgp_peers
[i
].routing
)
2253 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2254 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2257 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2258 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2264 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2269 if (!bgp_configured
)
2272 if (CLI_HELP_REQUESTED
)
2273 return cli_arg_help(cli
, 1,
2274 "A.B.C.D", "BGP neighbour address",
2275 "NAME", "BGP neighbour name",
2278 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2280 if (bgp_peers
[i
].state
!= Established
)
2283 if (bgp_peers
[i
].routing
)
2286 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2287 if (argc
&& strcmp(addr
, argv
[0]) &&
2288 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2291 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2292 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2298 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2303 if (!bgp_configured
)
2306 if (CLI_HELP_REQUESTED
)
2307 return cli_arg_help(cli
, 1,
2308 "A.B.C.D", "BGP neighbour address",
2309 "NAME", "BGP neighbour name",
2312 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2314 if (!*bgp_peers
[i
].name
)
2317 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2318 if (argc
&& strcmp(addr
, argv
[0]) &&
2319 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2322 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2323 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2331 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2335 if (CLI_HELP_REQUESTED
)
2340 return cli_arg_help(cli
, 0,
2341 "standard", "Standard syntax",
2342 "extended", "Extended syntax",
2346 return cli_arg_help(cli
, argv
[1][1],
2347 "NAME", "Access-list name",
2351 if (argc
== 3 && !argv
[2][1])
2352 return cli_arg_help(cli
, 1, NULL
);
2360 cli_error(cli
, "Specify access-list type and name");
2364 if (MATCH("standard", argv
[0]))
2366 else if (MATCH("extended", argv
[0]))
2370 cli_error(cli
, "Invalid access-list type");
2374 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2375 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2377 cli_error(cli
, "Invalid access-list name");
2381 filt
= find_filter(argv
[1], strlen(argv
[1]));
2386 cli_error(cli
, "Too many access-lists");
2391 if (!*ip_filters
[filt
].name
)
2393 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2394 strcpy(ip_filters
[filt
].name
, argv
[1]);
2395 ip_filters
[filt
].extended
= extended
;
2397 else if (ip_filters
[filt
].extended
!= extended
)
2399 cli_error(cli
, "Access-list is %s",
2400 ip_filters
[filt
].extended
? "extended" : "standard");
2405 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2409 if (filt
< 0 || !*ip_filters
[filt
].name
)
2411 cli_error(cli
, "Access-list not defined");
2416 if (ip_filters
[filt
].used
)
2418 cli_error(cli
, "Access-list in use");
2422 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2426 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2428 return access_list(cli
, argv
, argc
, 1);
2431 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2433 return access_list(cli
, argv
, argc
, 0);
2436 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2438 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2439 return sprintf(buf
, " any");
2441 if (wild
== INADDR_ANY
)
2442 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2444 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2447 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2451 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2452 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2453 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2454 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2455 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2461 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2463 static char buf
[256];
2466 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2469 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2470 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2473 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2477 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2478 p
+= show_ports(p
, &rule
->src_ports
);
2480 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2481 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2482 p
+= show_ports(p
, &rule
->dst_ports
);
2484 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2486 switch (rule
->tcp_flag_op
)
2488 case FILTER_FLAG_OP_EST
:
2489 p
+= sprintf(p
, " established");
2492 case FILTER_FLAG_OP_ANY
:
2493 case FILTER_FLAG_OP_ALL
:
2494 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2495 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2496 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2497 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2498 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2499 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2500 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2501 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2502 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2503 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2504 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2505 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2506 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2512 p
+= sprintf(p
, " fragments");
2517 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2519 static ip_filter_rulet rule
;
2520 struct in_addr addr
;
2524 if (CLI_HELP_REQUESTED
)
2528 cli_arg_help(cli
, 0,
2529 "ip", "Match IP packets",
2530 "tcp", "Match TCP packets",
2531 "udp", "Match UDP packets",
2537 // *sigh*, too darned complex
2538 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2544 cli_error(cli
, "Specify rule details");
2548 memset(&rule
, 0, sizeof(rule
));
2549 rule
.action
= (command
[0] == 'p')
2550 ? FILTER_ACTION_PERMIT
2551 : FILTER_ACTION_DENY
;
2553 if (MATCH("ip", argv
[0]))
2554 rule
.proto
= IPPROTO_IP
;
2555 else if (MATCH("udp", argv
[0]))
2556 rule
.proto
= IPPROTO_UDP
;
2557 else if (MATCH("tcp", argv
[0]))
2558 rule
.proto
= IPPROTO_TCP
;
2561 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2565 for (a
= 1, i
= 0; i
< 2; i
++)
2569 ip_filter_portt
*port
;
2574 wild
= &rule
.src_wild
;
2575 port
= &rule
.src_ports
;
2580 wild
= &rule
.dst_wild
;
2581 port
= &rule
.dst_ports
;
2584 cli_error(cli
, "Specify destination");
2589 if (MATCH("any", argv
[a
]))
2592 *wild
= INADDR_BROADCAST
;
2595 else if (MATCH("host", argv
[a
]))
2599 cli_error(cli
, "Specify host ip address");
2603 if (!inet_aton(argv
[a
], &addr
))
2605 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2617 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2621 if (!inet_aton(argv
[a
], &addr
))
2623 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2629 if (!inet_aton(argv
[++a
], &addr
))
2631 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2635 *wild
= addr
.s_addr
;
2639 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2643 if (MATCH("eq", argv
[a
]))
2644 port
->op
= FILTER_PORT_OP_EQ
;
2645 else if (MATCH("neq", argv
[a
]))
2646 port
->op
= FILTER_PORT_OP_NEQ
;
2647 else if (MATCH("gt", argv
[a
]))
2648 port
->op
= FILTER_PORT_OP_GT
;
2649 else if (MATCH("lt", argv
[a
]))
2650 port
->op
= FILTER_PORT_OP_LT
;
2651 else if (MATCH("range", argv
[a
]))
2652 port
->op
= FILTER_PORT_OP_RANGE
;
2659 cli_error(cli
, "Specify port");
2663 if (!(port
->port
= atoi(argv
[a
])))
2665 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2670 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2675 cli_error(cli
, "Specify port");
2679 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2681 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2688 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2690 if (MATCH("established", argv
[a
]))
2692 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2695 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2696 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2698 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2699 ? FILTER_FLAG_OP_ANY
2700 : FILTER_FLAG_OP_ALL
;
2704 cli_error(cli
, "Specify tcp flags");
2708 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2712 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2714 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2715 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2716 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2717 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2718 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2719 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2722 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2731 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2733 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2735 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2745 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2752 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2754 static ip_filter_rulet rule
;
2755 struct in_addr addr
;
2757 if (CLI_HELP_REQUESTED
)
2761 cli_arg_help(cli
, argv
[0][1],
2762 "A.B.C.D", "Source address",
2763 "any", "Any source address",
2764 "host", "Source host",
2770 if (MATCH("any", argv
[0]))
2772 if (argc
== 2 && !argv
[1][1])
2773 cli_arg_help(cli
, 1, NULL
);
2775 else if (MATCH("host", argv
[0]))
2779 cli_arg_help(cli
, argv
[1][1],
2780 "A.B.C.D", "Host address",
2783 else if (argc
== 3 && !argv
[2][1])
2784 cli_arg_help(cli
, 1, NULL
);
2790 cli_arg_help(cli
, 1,
2791 "A.B.C.D", "Wildcard bits",
2794 else if (argc
== 3 && !argv
[2][1])
2795 cli_arg_help(cli
, 1, NULL
);
2803 cli_error(cli
, "Specify rule details");
2807 memset(&rule
, 0, sizeof(rule
));
2808 rule
.action
= (command
[0] == 'p')
2809 ? FILTER_ACTION_PERMIT
2810 : FILTER_ACTION_DENY
;
2812 rule
.proto
= IPPROTO_IP
;
2813 if (MATCH("any", argv
[0]))
2815 rule
.src_ip
= INADDR_ANY
;
2816 rule
.src_wild
= INADDR_BROADCAST
;
2818 else if (MATCH("host", argv
[0]))
2822 cli_error(cli
, "Specify host ip address");
2826 if (!inet_aton(argv
[1], &addr
))
2828 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2832 rule
.src_ip
= addr
.s_addr
;
2833 rule
.src_wild
= INADDR_ANY
;
2839 cli_error(cli
, "Specify source ip address and wildcard");
2843 if (!inet_aton(argv
[0], &addr
))
2845 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2849 rule
.src_ip
= addr
.s_addr
;
2853 if (!inet_aton(argv
[1], &addr
))
2855 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2859 rule
.src_wild
= addr
.s_addr
;
2862 rule
.src_wild
= INADDR_ANY
;
2868 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2871 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2872 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2873 : access_list_rule_std(cli
, command
, argv
, argc
);
2878 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2880 if (!ip_filters
[filt
].rules
[i
].action
)
2882 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2886 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2890 cli_error(cli
, "Too many rules");
2894 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2899 /* filter USER {in|out} FILTER ... */
2900 if (CLI_HELP_REQUESTED
)
2905 return cli_arg_help(cli
, 0,
2906 "USER", "Username of session to filter", NULL
);
2910 return cli_arg_help(cli
, 0,
2911 "in", "Set incoming filter",
2912 "out", "Set outgoing filter", NULL
);
2916 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2917 "NAME", "Filter name", NULL
);
2920 return cli_arg_help(cli
, argc
> 1, NULL
);
2924 if (!config
->cluster_iam_master
)
2926 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2927 fmtaddr(config
->cluster_master_address
, 0));
2932 if (argc
!= 3 && argc
!= 5)
2934 cli_error(cli
, "Specify a user and filters");
2938 if (!(s
= sessionbyuser(argv
[0])))
2940 cli_error(cli
, "User %s is not connected", argv
[0]);
2944 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2945 for (i
= 1; i
< argc
; i
+= 2)
2950 if (MATCH("in", argv
[i
]))
2952 if (session
[s
].filter_in
)
2954 cli_error(cli
, "Input already filtered");
2957 f
= &cli_session_actions
[s
].filter_in
;
2959 else if (MATCH("out", argv
[i
]))
2961 if (session
[s
].filter_out
)
2963 cli_error(cli
, "Output already filtered");
2966 f
= &cli_session_actions
[s
].filter_out
;
2970 cli_error(cli
, "Invalid filter specification");
2974 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
2975 if (v
< 0 || !*ip_filters
[v
].name
)
2977 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
2984 cli_print(cli
, "Filtering user %s", argv
[0]);
2985 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
2990 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2995 if (CLI_HELP_REQUESTED
)
2996 return cli_arg_help(cli
, argc
> 1,
2997 "USER", "Username of session to remove filters from", NULL
);
2999 if (!config
->cluster_iam_master
)
3001 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3002 fmtaddr(config
->cluster_master_address
, 0));
3009 cli_error(cli
, "Specify a user to remove filters from");
3013 for (i
= 0; i
< argc
; i
++)
3015 if (!(s
= sessionbyuser(argv
[i
])))
3017 cli_error(cli
, "User %s is not connected", argv
[i
]);
3021 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3023 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3024 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3028 cli_error(cli
, "User %s not filtered", argv
[i
]);
3035 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3039 if (CLI_HELP_REQUESTED
)
3040 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3044 cli_error(cli
, "Specify a filter name");
3048 for (i
= 0; i
< argc
; i
++)
3050 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3051 ip_filter_rulet
*rules
;
3053 if (f
< 0 || !*ip_filters
[f
].name
)
3055 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3062 cli_print(cli
, "%s IP access list %s",
3063 ip_filters
[f
].extended
? "Extended" : "Standard",
3064 ip_filters
[f
].name
);
3066 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3068 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3070 cli_print(cli
, "%s (%u match%s)", r
,
3071 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3073 cli_print(cli
, "%s", r
);
3080 // Convert a string in the form of abcd.ef12.3456 into char[6]
3081 void parsemac(char *string
, char mac
[6])
3083 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)
3085 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)