1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.72 2006/04/27 09:53:49 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 bundlet
*bundle
;
40 extern sessiont
*session
;
41 extern radiust
*radius
;
42 extern ippoolt
*ip_address_pool
;
43 extern struct Tstats
*_statistics
;
44 static struct cli_def
*cli
= NULL
;
45 extern configt
*config
;
46 extern config_descriptt config_values
[];
48 extern struct Tringbuffer
*ringbuffer
;
50 extern struct cli_session_actions
*cli_session_actions
;
51 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
52 extern tbft
*filter_list
;
53 extern ip_filtert
*ip_filters
;
67 static int debug_rb_tail
;
68 static char *debug_levels
[] = {
79 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
100 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
101 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
102 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
104 static int regular_stuff(struct cli_def
*cli
);
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 if (session
[s
].timeout
)
432 cli_print(cli
, "\tRemaing time:\t%u",
433 (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
434 ? (unsigned) (session
[s
].timeout
- bundle
[session
[s
].bundle
].online_time
)
435 : (unsigned) (session
[s
].timeout
- (time_now
- session
[s
].opened
)));
438 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
439 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
440 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
441 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
442 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
443 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
444 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
445 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
446 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
447 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
449 cli_print(cli
, "\tIntercepted:\tno");
451 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
453 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
454 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
455 t
? "YES" : "no", t
? " (" : "",
456 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
458 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
462 b_in
= session
[s
].tbf_in
;
463 b_out
= session
[s
].tbf_out
;
465 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
466 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
467 "ByteSent", "PackSent", "PackDrop", "PackDelay");
470 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
472 (filter_list
[b_in
].next
? "*" : " "),
473 (b_in
< 100 ? "\t" : ""),
474 filter_list
[b_in
].rate
* 8,
475 filter_list
[b_in
].credit
,
476 filter_list
[b_in
].queued
,
477 filter_list
[b_in
].b_queued
,
478 filter_list
[b_in
].p_queued
,
479 filter_list
[b_in
].b_sent
,
480 filter_list
[b_in
].p_sent
,
481 filter_list
[b_in
].p_dropped
,
482 filter_list
[b_in
].p_delayed
);
485 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
487 (filter_list
[b_out
].next
? "*" : " "),
488 (b_out
< 100 ? "\t" : ""),
489 filter_list
[b_out
].rate
* 8,
490 filter_list
[b_out
].credit
,
491 filter_list
[b_out
].queued
,
492 filter_list
[b_out
].b_queued
,
493 filter_list
[b_out
].p_queued
,
494 filter_list
[b_out
].b_sent
,
495 filter_list
[b_out
].p_sent
,
496 filter_list
[b_out
].p_dropped
,
497 filter_list
[b_out
].p_delayed
);
504 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s",
521 for (i
= 1; i
< MAXSESSION
; i
++)
524 if (!session
[i
].opened
) continue;
525 if (session
[i
].bundle
&& bundle
[session
[i
].bundle
].num_of_links
> 1)
526 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- bundle
[session
[i
].bundle
].online_time
) : 0;
528 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- (time_now
-session
[i
].opened
)) : 0;
530 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %-15s %s",
533 session
[i
].user
[0] ? session
[i
].user
: "*",
534 fmtaddr(htonl(session
[i
].ip
), 0),
535 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
536 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
537 (session
[i
].walled_garden
) ? "Y" : "N",
538 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
539 abs(time_now
- (unsigned long)session
[i
].opened
),
540 (unsigned long)session
[i
].cout
,
541 (unsigned long)session
[i
].cin
,
542 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
543 (unsigned long)(rem_time
),
544 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
545 session
[i
].calling
[0] ? session
[i
].calling
: "*");
550 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
552 int i
, x
, show_all
= 0;
560 if (CLI_HELP_REQUESTED
)
563 return cli_arg_help(cli
, 1,
564 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
567 return cli_arg_help(cli
, 1,
568 "all", "Show all tunnels, including unused",
569 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
576 if (strcmp(argv
[0], "all") == 0)
582 // Show individual tunnel
583 for (i
= 0; i
< argc
; i
++)
588 if (t
<= 0 || t
>= MAXTUNNEL
)
590 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
593 cli_print(cli
, "\r\nTunnel %d:", t
);
594 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
595 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
596 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
597 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
598 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
599 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
600 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
601 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
602 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
604 for (x
= 0; x
< MAXSESSION
; x
++)
605 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
606 sprintf(s
, "%s%u ", s
, x
);
608 cli_print(cli
, "\tSessions:\t%s", s
);
614 // Show tunnel summary
615 cli_print(cli
, "%4s %20s %20s %6s %s",
622 for (i
= 1; i
< MAXTUNNEL
; i
++)
625 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
627 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
628 cli_print(cli
, "%4d %20s %20s %6s %6d",
630 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
631 fmtaddr(htonl(tunnel
[i
].ip
), 0),
632 states
[tunnel
[i
].state
],
639 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
646 if (CLI_HELP_REQUESTED
)
647 return cli_arg_help(cli
, 1,
648 "USER", "Show details for specific username",
651 for (i
= 0; i
< MAXSESSION
; i
++)
653 if (!session
[i
].opened
) continue;
654 if (!session
[i
].user
[0]) continue;
658 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
660 if (strcmp(argv
[j
], session
[i
].user
) == 0)
662 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
663 sargv
[sargc
] = sid
[sargc
];
671 cli_print(cli
, "%s", session
[i
].user
);
675 return cmd_show_session(cli
, "users", sargv
, sargc
);
681 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
683 if (CLI_HELP_REQUESTED
)
684 return CLI_HELP_NO_ARGS
;
686 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
687 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
688 GET_STAT(tun_rx_bytes
),
689 GET_STAT(tun_rx_packets
),
690 GET_STAT(tun_rx_errors
),
691 GET_STAT(tun_rx_dropped
));
692 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
693 GET_STAT(tun_tx_bytes
),
694 GET_STAT(tun_tx_packets
),
695 GET_STAT(tun_tx_errors
));
698 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
699 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
700 GET_STAT(tunnel_rx_bytes
),
701 GET_STAT(tunnel_rx_packets
),
702 GET_STAT(tunnel_rx_errors
));
703 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
704 GET_STAT(tunnel_tx_bytes
),
705 GET_STAT(tunnel_tx_packets
),
706 GET_STAT(tunnel_tx_errors
),
707 GET_STAT(tunnel_retries
));
710 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
711 cli_print(cli
, "-----------------------------------------");
712 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
713 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
714 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
715 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
716 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
717 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
718 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
719 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
720 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
721 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
722 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
723 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
724 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
725 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
726 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
727 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
728 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
729 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
733 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
734 cli_print(cli
, "-----------------------------------------");
735 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
736 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
737 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
738 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
739 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
740 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
741 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
742 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
743 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
744 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
745 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
746 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
747 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
748 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
749 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
750 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
751 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
752 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
753 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
754 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
755 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
756 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
757 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
758 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
759 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
760 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
761 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
762 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
763 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
764 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
765 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
766 #endif /* STAT_CALLS */
769 time_t l
= GET_STAT(last_reset
);
771 char *p
= strchr(t
, '\n');
775 cli_print(cli
, "Last counter reset %s", t
);
781 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
783 if (CLI_HELP_REQUESTED
)
784 return CLI_HELP_NO_ARGS
;
786 memset(_statistics
, 0, sizeof(struct Tstats
));
787 SET_STAT(last_reset
, time(NULL
));
789 cli_print(cli
, "Counters cleared");
792 #endif /* STATISTICS */
794 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
800 if (CLI_HELP_REQUESTED
)
801 return cli_arg_help(cli
, 1,
802 "tag", "Include CVS release tag",
803 "file", "Include file versions",
806 for (i
= 0; i
< argc
; i
++)
807 if (!strcmp(argv
[i
], "tag"))
809 else if (!strcmp(argv
[i
], "file"))
812 cli_print(cli
, "L2TPNS %s", VERSION
);
815 char const *p
= strchr(cvs_name
, ':');
827 e
= strpbrk(p
, " \t$");
828 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
833 extern linked_list
*loaded_plugins
;
836 cli_print(cli
, "Files:");
837 cli_print(cli
, " %s", cvs_id_arp
);
839 cli_print(cli
, " %s", cvs_id_bgp
);
841 cli_print(cli
, " %s", cvs_id_cli
);
842 cli_print(cli
, " %s", cvs_id_cluster
);
843 cli_print(cli
, " %s", cvs_id_constants
);
844 cli_print(cli
, " %s", cvs_id_control
);
845 cli_print(cli
, " %s", cvs_id_icmp
);
846 cli_print(cli
, " %s", cvs_id_l2tpns
);
847 cli_print(cli
, " %s", cvs_id_ll
);
848 cli_print(cli
, " %s", cvs_id_ppp
);
849 cli_print(cli
, " %s", cvs_id_radius
);
850 cli_print(cli
, " %s", cvs_id_tbf
);
851 cli_print(cli
, " %s", cvs_id_util
);
853 ll_reset(loaded_plugins
);
854 while ((p
= ll_next(loaded_plugins
)))
856 char const **id
= dlsym(p
, "cvs_id");
858 cli_print(cli
, " %s", *id
);
865 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
868 int used
= 0, free
= 0, show_all
= 0;
870 if (!config
->cluster_iam_master
)
872 cli_print(cli
, "Can't do this on a slave. Do it on %s",
873 fmtaddr(config
->cluster_master_address
, 0));
878 if (CLI_HELP_REQUESTED
)
881 return cli_arg_help(cli
, 1, NULL
);
883 return cli_arg_help(cli
, 1,
884 "all", "Show all pool addresses, including unused",
888 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
892 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
893 for (i
= 0; i
< MAXIPPOOL
; i
++)
895 if (!ip_address_pool
[i
].address
) continue;
896 if (ip_address_pool
[i
].assigned
)
898 cli_print(cli
, "%-15s\tY %8d %s",
899 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
900 ip_address_pool
[i
].session
,
901 session
[ip_address_pool
[i
].session
].user
);
907 if (ip_address_pool
[i
].last
)
908 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
909 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
910 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
913 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
920 cli_print(cli
, "(Not displaying unused addresses)");
922 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
926 static FILE *save_config_fh
= 0;
927 static void print_save_config(struct cli_def
*cli
, char *string
)
930 fprintf(save_config_fh
, "%s\n", string
);
933 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
935 if (CLI_HELP_REQUESTED
)
936 return CLI_HELP_NO_ARGS
;
938 if ((save_config_fh
= fopen(config
->config_file
, "w")))
940 cli_print(cli
, "Writing configuration");
941 cli_print_callback(cli
, print_save_config
);
942 cmd_show_run(cli
, command
, argv
, argc
);
943 cli_print_callback(cli
, NULL
);
944 fclose(save_config_fh
);
949 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
954 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
956 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
959 char ipv6addr
[INET6_ADDRSTRLEN
];
961 if (CLI_HELP_REQUESTED
)
962 return CLI_HELP_NO_ARGS
;
964 cli_print(cli
, "# Current configuration:");
966 for (i
= 0; config_values
[i
].key
; i
++)
968 void *value
= ((void *)config
) + config_values
[i
].offset
;
969 if (config_values
[i
].type
== STRING
)
970 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
971 else if (config_values
[i
].type
== IPv4
)
972 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
973 else if (config_values
[i
].type
== IPv6
)
974 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
975 else if (config_values
[i
].type
== SHORT
)
976 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
977 else if (config_values
[i
].type
== BOOL
)
978 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
979 else if (config_values
[i
].type
== INT
)
980 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
981 else if (config_values
[i
].type
== UNSIGNED_LONG
)
982 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
985 cli_print(cli
, "# Plugins");
986 for (i
= 0; i
< MAXPLUGINS
; i
++)
988 if (*config
->plugins
[i
])
990 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
995 if (config
->as_number
)
1000 cli_print(cli
, "# BGP");
1001 cli_print(cli
, "router bgp %u", config
->as_number
);
1002 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1004 if (!config
->neighbour
[i
].name
[0])
1007 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1009 k
= config
->neighbour
[i
].keepalive
;
1010 h
= config
->neighbour
[i
].hold
;
1017 k
= BGP_KEEPALIVE_TIME
;
1023 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1028 cli_print(cli
, "# Filters");
1029 for (i
= 0; i
< MAXFILTER
; i
++)
1031 ip_filter_rulet
*rules
;
1032 if (!*ip_filters
[i
].name
)
1035 cli_print(cli
, "ip access-list %s %s",
1036 ip_filters
[i
].extended
? "extended" : "standard",
1037 ip_filters
[i
].name
);
1039 rules
= ip_filters
[i
].rules
;
1040 while (rules
->action
)
1041 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1044 cli_print(cli
, "# end");
1048 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1050 int i
, free
= 0, used
= 0, show_all
= 0;
1062 if (CLI_HELP_REQUESTED
)
1065 return cli_arg_help(cli
, 1, NULL
);
1067 return cli_arg_help(cli
, 1,
1068 "all", "Show all RADIUS sessions, including unused",
1072 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1076 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1079 for (i
= 1; i
< MAXRADIUS
; i
++)
1081 if (radius
[i
].state
== RADIUSNULL
)
1086 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1088 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1092 states
[radius
[i
].state
],
1098 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1103 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1107 if (CLI_HELP_REQUESTED
)
1108 return CLI_HELP_NO_ARGS
;
1110 cli_print(cli
, "Plugins currently loaded:");
1111 for (i
= 0; i
< MAXPLUGINS
; i
++)
1112 if (*config
->plugins
[i
])
1113 cli_print(cli
, " %s", config
->plugins
[i
]);
1118 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1122 if (CLI_HELP_REQUESTED
)
1123 return CLI_HELP_NO_ARGS
;
1125 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1134 for (i
= 0; i
< MAXSESSION
; i
++)
1136 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1137 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1141 session
[i
].throttle_in
,
1142 session
[i
].throttle_out
,
1144 session
[i
].tbf_out
);
1150 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1152 if (CLI_HELP_REQUESTED
)
1153 return CLI_HELP_NO_ARGS
;
1155 cli_print(cli
, " _\n"
1161 " ( \\ `. `-. _,.-:\\\n"
1162 " \\ \\ `. `-._ __..--' ,-';/\n"
1163 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1164 " `. `. `-._ __..--' ,' /\n"
1165 " `. `-_ ``--..'' _.-' ,'\n"
1166 " `-_ `-.___ __,--' ,'\n"
1167 " `-.__ `----\"\"\" __.-'\n"
1168 "hh `--..____..--'");
1173 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1178 if (CLI_HELP_REQUESTED
)
1179 return cli_arg_help(cli
, argc
> 1,
1180 "USER", "Username of session to drop", NULL
);
1182 if (!config
->cluster_iam_master
)
1184 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1185 fmtaddr(config
->cluster_master_address
, 0));
1192 cli_error(cli
, "Specify a user to drop");
1196 for (i
= 0; i
< argc
; i
++)
1198 if (!(s
= sessionbyuser(argv
[i
])))
1200 cli_error(cli
, "User %s is not connected", argv
[i
]);
1204 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1206 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1207 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1214 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1219 if (CLI_HELP_REQUESTED
)
1220 return cli_arg_help(cli
, argc
> 1,
1221 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1223 if (!config
->cluster_iam_master
)
1225 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1226 fmtaddr(config
->cluster_master_address
, 0));
1233 cli_error(cli
, "Specify a tunnel to drop");
1237 for (i
= 0; i
< argc
; i
++)
1239 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1241 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1247 cli_error(cli
, "Tunnel %d is not connected", t
);
1253 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1257 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1258 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1264 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1269 if (CLI_HELP_REQUESTED
)
1270 return cli_arg_help(cli
, argc
> 1,
1271 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1273 if (!config
->cluster_iam_master
)
1275 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1276 fmtaddr(config
->cluster_master_address
, 0));
1283 cli_error(cli
, "Specify a session id to drop");
1287 for (i
= 0; i
< argc
; i
++)
1289 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1291 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1295 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1297 cli_print(cli
, "Dropping session %d", s
);
1298 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1302 cli_error(cli
, "Session %d is not active.", s
);
1309 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1315 if (CLI_HELP_REQUESTED
)
1320 return cli_arg_help(cli
, 0,
1321 "USER", "Username of session to snoop", NULL
);
1324 return cli_arg_help(cli
, 0,
1325 "A.B.C.D", "IP address of snoop destination", NULL
);
1328 return cli_arg_help(cli
, 0,
1329 "N", "Port of snoop destination", NULL
);
1333 return cli_arg_help(cli
, 1, NULL
);
1340 if (!config
->cluster_iam_master
)
1342 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1343 fmtaddr(config
->cluster_master_address
, 0));
1350 cli_error(cli
, "Specify username, ip and port");
1354 if (!(s
= sessionbyuser(argv
[0])))
1356 cli_error(cli
, "User %s is not connected", argv
[0]);
1360 ip
= inet_addr(argv
[1]);
1361 if (!ip
|| ip
== INADDR_NONE
)
1363 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1367 port
= atoi(argv
[2]);
1370 cli_error(cli
, "Invalid port %s", argv
[2]);
1374 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1375 cli_session_actions
[s
].snoop_ip
= ip
;
1376 cli_session_actions
[s
].snoop_port
= port
;
1377 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1382 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1387 if (CLI_HELP_REQUESTED
)
1388 return cli_arg_help(cli
, argc
> 1,
1389 "USER", "Username of session to unsnoop", NULL
);
1391 if (!config
->cluster_iam_master
)
1393 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1394 fmtaddr(config
->cluster_master_address
, 0));
1401 cli_error(cli
, "Specify a user to unsnoop");
1405 for (i
= 0; i
< argc
; i
++)
1407 if (!(s
= sessionbyuser(argv
[i
])))
1409 cli_error(cli
, "User %s is not connected", argv
[i
]);
1413 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1414 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1420 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1427 throttle USER - throttle in/out to default rate
1428 throttle USER RATE - throttle in/out to default rate
1429 throttle USER in RATE - throttle input only
1430 throttle USER out RATE - throttle output only
1431 throttle USER in RATE out RATE - throttle both
1434 if (CLI_HELP_REQUESTED
)
1439 return cli_arg_help(cli
, 0,
1440 "USER", "Username of session to throttle", NULL
);
1443 return cli_arg_help(cli
, 1,
1444 "RATE", "Rate in kbps (in and out)",
1445 "in", "Select incoming rate",
1446 "out", "Select outgoing rate", NULL
);
1449 return cli_arg_help(cli
, 1,
1450 "in", "Select incoming rate",
1451 "out", "Select outgoing rate", NULL
);
1454 if (isdigit(argv
[1][0]))
1455 return cli_arg_help(cli
, 1, NULL
);
1458 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1461 return cli_arg_help(cli
, argc
> 1, NULL
);
1465 if (!config
->cluster_iam_master
)
1467 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1468 fmtaddr(config
->cluster_master_address
, 0));
1475 cli_error(cli
, "Specify a user to throttle");
1479 if (!(s
= sessionbyuser(argv
[0])))
1481 cli_error(cli
, "User %s is not connected", argv
[0]);
1487 rate_in
= rate_out
= config
->rl_rate
;
1491 rate_in
= rate_out
= atoi(argv
[1]);
1494 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1498 else if (argc
== 3 || argc
== 5)
1501 for (i
= 1; i
< argc
- 1; i
+= 2)
1504 if (MATCH("in", argv
[i
]))
1505 r
= rate_in
= atoi(argv
[i
+1]);
1506 else if (MATCH("out", argv
[i
]))
1507 r
= rate_out
= atoi(argv
[i
+1]);
1511 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1518 cli_error(cli
, "Invalid arguments");
1522 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1524 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1528 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1529 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1530 cli_session_actions
[s
].throttle_in
= rate_in
;
1532 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1533 cli_session_actions
[s
].throttle_out
= rate_out
;
1535 if (cli_session_actions
[s
].throttle_in
== -1 &&
1536 cli_session_actions
[s
].throttle_out
== -1)
1538 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1542 cli_print(cli
, "Throttling user %s", argv
[0]);
1543 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1548 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1553 if (CLI_HELP_REQUESTED
)
1554 return cli_arg_help(cli
, argc
> 1,
1555 "USER", "Username of session to unthrottle", NULL
);
1557 if (!config
->cluster_iam_master
)
1559 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1560 fmtaddr(config
->cluster_master_address
, 0));
1567 cli_error(cli
, "Specify a user to unthrottle");
1571 for (i
= 0; i
< argc
; i
++)
1573 if (!(s
= sessionbyuser(argv
[i
])))
1575 cli_error(cli
, "User %s is not connected", argv
[i
]);
1579 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1581 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1582 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1586 cli_error(cli
, "User %s not throttled", argv
[i
]);
1593 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1597 if (CLI_HELP_REQUESTED
)
1598 return cli_arg_help(cli
, 1,
1599 "all", "Enable debugging for all except \"data\"",
1600 "critical", "", // FIXME: add descriptions
1610 char *p
= (char *) &debug_flags
;
1611 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1615 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1616 (debug_flags
.critical
) ? " critical" : "",
1617 (debug_flags
.error
) ? " error" : "",
1618 (debug_flags
.warning
) ? " warning" : "",
1619 (debug_flags
.info
) ? " info" : "",
1620 (debug_flags
.calls
) ? " calls" : "",
1621 (debug_flags
.data
) ? " data" : "");
1627 cli_print(cli
, "Debugging off");
1631 for (i
= 0; i
< argc
; i
++)
1633 int len
= strlen(argv
[i
]);
1635 if (argv
[i
][0] == 'c' && len
< 2)
1636 len
= 2; /* distinguish [cr]itical from [ca]lls */
1638 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1639 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1640 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1641 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1642 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1643 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1644 if (!strncmp("all", argv
[i
], len
))
1646 memset(&debug_flags
, 1, sizeof(debug_flags
));
1647 debug_flags
.data
= 0;
1651 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1657 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1661 if (CLI_HELP_REQUESTED
)
1662 return cli_arg_help(cli
, 1,
1663 "all", "Disable all debugging",
1664 "critical", "", // FIXME: add descriptions
1674 memset(&debug_flags
, 0, sizeof(debug_flags
));
1678 for (i
= 0; i
< argc
; i
++)
1680 int len
= strlen(argv
[i
]);
1682 if (argv
[i
][0] == 'c' && len
< 2)
1683 len
= 2; /* distinguish [cr]itical from [ca]lls */
1685 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1686 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1687 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1688 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1689 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1690 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1691 if (!strncmp("all", argv
[i
], len
))
1693 memset(&debug_flags
, 0, sizeof(debug_flags
));
1697 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1703 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1705 int i
, firstfree
= 0;
1707 if (CLI_HELP_REQUESTED
)
1708 return cli_arg_help(cli
, argc
> 1,
1709 "PLUGIN", "Name of plugin to load", NULL
);
1713 cli_error(cli
, "Specify a plugin to load");
1717 for (i
= 0; i
< MAXPLUGINS
; i
++)
1719 if (!*config
->plugins
[i
] && !firstfree
)
1721 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1723 cli_error(cli
, "Plugin is already loaded");
1730 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1731 config
->reload_config
= 1;
1732 cli_print(cli
, "Loading plugin %s", argv
[0]);
1738 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1742 if (CLI_HELP_REQUESTED
)
1743 return cli_arg_help(cli
, argc
> 1,
1744 "PLUGIN", "Name of plugin to unload", NULL
);
1748 cli_error(cli
, "Specify a plugin to remove");
1752 for (i
= 0; i
< MAXPLUGINS
; i
++)
1754 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1756 config
->reload_config
= 1;
1757 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1762 cli_error(cli
, "Plugin is not loaded");
1766 static char *duration(time_t secs
)
1768 static char *buf
= NULL
;
1771 if (!buf
) buf
= calloc(64, 1);
1775 int days
= secs
/ 86400;
1776 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1782 int mins
= secs
/ 60;
1783 int hrs
= mins
/ 60;
1786 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1788 else if (secs
>= 60)
1790 int mins
= secs
/ 60;
1791 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1794 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1799 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1802 char buf
[100], *p
= buf
, *loads
[3];
1803 int i
, num_sessions
= 0;
1805 if (CLI_HELP_REQUESTED
)
1806 return CLI_HELP_NO_ARGS
;
1808 fh
= fopen("/proc/loadavg", "r");
1809 fgets(buf
, 100, fh
);
1812 for (i
= 0; i
< 3; i
++)
1813 loads
[i
] = strdup(strsep(&p
, " "));
1816 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1818 for (i
= 1; i
< MAXSESSION
; i
++)
1819 if (session
[i
].opened
) num_sessions
++;
1821 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1823 duration(time_now
- config
->start_time
),
1825 loads
[0], loads
[1], loads
[2]
1827 for (i
= 0; i
< 3; i
++)
1828 if (loads
[i
]) free(loads
[i
]);
1830 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1835 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1839 if (CLI_HELP_REQUESTED
)
1845 int len
= strlen(argv
[0])-1;
1846 for (i
= 0; config_values
[i
].key
; i
++)
1847 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1848 cli_error(cli
, " %s", config_values
[i
].key
);
1854 return cli_arg_help(cli
, 0,
1855 "VALUE", "Value for variable", NULL
);
1859 return cli_arg_help(cli
, 1, NULL
);
1868 cli_error(cli
, "Specify variable and value");
1872 for (i
= 0; config_values
[i
].key
; i
++)
1874 void *value
= ((void *) config
) + config_values
[i
].offset
;
1875 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1877 // Found a value to set
1878 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1879 switch (config_values
[i
].type
)
1882 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1885 *(int *) value
= atoi(argv
[1]);
1888 *(unsigned long *) value
= atol(argv
[1]);
1891 *(short *) value
= atoi(argv
[1]);
1894 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1897 inet_pton(AF_INET6
, argv
[1], value
);
1900 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1906 cli_error(cli
, "Unknown variable type");
1909 config
->reload_config
= 1;
1914 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1918 int regular_stuff(struct cli_def
*cli
)
1924 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1926 char *m
= ringbuffer
->buffer
[i
].message
;
1932 switch (ringbuffer
->buffer
[i
].level
)
1934 case 0: show
= debug_flags
.critical
; break;
1935 case 1: show
= debug_flags
.error
; break;
1936 case 2: show
= debug_flags
.warning
; break;
1937 case 3: show
= debug_flags
.info
; break;
1938 case 4: show
= debug_flags
.calls
; break;
1939 case 5: show
= debug_flags
.data
; break;
1942 if (!show
) continue;
1944 if (!(p
= strchr(m
, '\n')))
1947 cli_error(cli
, "\r%s-%u-%u %.*s",
1948 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1949 ringbuffer
->buffer
[i
].tunnel
,
1950 ringbuffer
->buffer
[i
].session
,
1956 debug_rb_tail
= ringbuffer
->tail
;
1964 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1968 if (CLI_HELP_REQUESTED
)
1969 return cli_arg_help(cli
, argc
> 1,
1970 "<1-65535>", "Autonomous system number", NULL
);
1972 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1974 cli_error(cli
, "Invalid autonomous system number");
1978 if (bgp_configured
&& as
!= config
->as_number
)
1980 cli_error(cli
, "Can't change local AS on a running system");
1984 config
->as_number
= as
;
1985 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1990 static int find_bgp_neighbour(char const *name
)
1995 in_addr_t addrs
[4] = { 0 };
1998 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2001 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2002 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2004 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2006 if (!config
->neighbour
[i
].name
[0])
2008 if (new == -1) new = i
;
2012 if (!strcmp(name
, config
->neighbour
[i
].name
))
2015 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2018 for (a
= h
->h_addr_list
; *a
; a
++)
2021 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2022 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2030 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2036 if (CLI_HELP_REQUESTED
)
2041 return cli_arg_help(cli
, 0,
2042 "A.B.C.D", "BGP neighbour address",
2043 "NAME", "BGP neighbour name",
2047 return cli_arg_help(cli
, 0,
2048 "remote-as", "Set remote autonomous system number",
2049 "timers", "Set timers",
2053 if (MATCH("remote-as", argv
[1]))
2054 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2056 if (MATCH("timers", argv
[1]))
2059 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2062 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2064 if (argc
== 5 && !argv
[4][1])
2065 return cli_arg_help(cli
, 1, NULL
);
2074 cli_error(cli
, "Invalid arguments");
2078 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2080 cli_error(cli
, "Invalid neighbour");
2086 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2090 if (MATCH("remote-as", argv
[1]))
2092 int as
= atoi(argv
[2]);
2093 if (as
< 0 || as
> 65535)
2095 cli_error(cli
, "Invalid autonomous system number");
2099 if (!config
->neighbour
[i
].name
[0])
2101 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2102 config
->neighbour
[i
].keepalive
= -1;
2103 config
->neighbour
[i
].hold
= -1;
2106 config
->neighbour
[i
].as
= as
;
2110 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2112 cli_error(cli
, "Invalid arguments");
2116 if (!config
->neighbour
[i
].name
[0])
2118 cli_error(cli
, "Specify remote-as first");
2122 keepalive
= atoi(argv
[2]);
2123 hold
= atoi(argv
[3]);
2125 if (keepalive
< 1 || keepalive
> 65535)
2127 cli_error(cli
, "Invalid keepalive time");
2131 if (hold
< 3 || hold
> 65535)
2133 cli_error(cli
, "Invalid hold time");
2137 if (keepalive
== BGP_KEEPALIVE_TIME
)
2138 keepalive
= -1; // using default value
2140 if (hold
== BGP_HOLD_TIME
)
2143 config
->neighbour
[i
].keepalive
= keepalive
;
2144 config
->neighbour
[i
].hold
= hold
;
2149 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2153 if (CLI_HELP_REQUESTED
)
2154 return cli_arg_help(cli
, argc
> 0,
2155 "A.B.C.D", "BGP neighbour address",
2156 "NAME", "BGP neighbour name",
2161 cli_error(cli
, "Specify a BGP neighbour");
2165 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2167 cli_error(cli
, "Invalid neighbour");
2171 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2173 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2177 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2181 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2187 if (!bgp_configured
)
2190 if (CLI_HELP_REQUESTED
)
2191 return cli_arg_help(cli
, 1,
2192 "A.B.C.D", "BGP neighbour address",
2193 "NAME", "BGP neighbour name",
2196 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2197 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2201 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2203 if (!*bgp_peers
[i
].name
)
2206 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2207 if (argc
&& strcmp(addr
, argv
[0]) &&
2208 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2214 cli_print(cli
, "Peer AS Address "
2215 "State Retries Retry in Route Pend Timers");
2216 cli_print(cli
, "------------------ ----- --------------- "
2217 "----------- ------- -------- ----- ---- ---------");
2220 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2224 bgp_state_str(bgp_peers
[i
].state
),
2225 bgp_peers
[i
].retry_count
,
2226 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2227 bgp_peers
[i
].routing
? "yes" : "no",
2228 bgp_peers
[i
].update_routes
? "yes" : "no",
2229 bgp_peers
[i
].keepalive
,
2236 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2241 if (!bgp_configured
)
2244 if (CLI_HELP_REQUESTED
)
2245 return cli_arg_help(cli
, 1,
2246 "A.B.C.D", "BGP neighbour address",
2247 "NAME", "BGP neighbour name",
2250 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2252 if (bgp_peers
[i
].state
!= Established
)
2255 if (!bgp_peers
[i
].routing
)
2258 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2259 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2262 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2263 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2269 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2274 if (!bgp_configured
)
2277 if (CLI_HELP_REQUESTED
)
2278 return cli_arg_help(cli
, 1,
2279 "A.B.C.D", "BGP neighbour address",
2280 "NAME", "BGP neighbour name",
2283 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2285 if (bgp_peers
[i
].state
!= Established
)
2288 if (bgp_peers
[i
].routing
)
2291 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2292 if (argc
&& strcmp(addr
, argv
[0]) &&
2293 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2296 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2297 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2303 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2308 if (!bgp_configured
)
2311 if (CLI_HELP_REQUESTED
)
2312 return cli_arg_help(cli
, 1,
2313 "A.B.C.D", "BGP neighbour address",
2314 "NAME", "BGP neighbour name",
2317 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2319 if (!*bgp_peers
[i
].name
)
2322 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2323 if (argc
&& strcmp(addr
, argv
[0]) &&
2324 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2327 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2328 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2336 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2340 if (CLI_HELP_REQUESTED
)
2345 return cli_arg_help(cli
, 0,
2346 "standard", "Standard syntax",
2347 "extended", "Extended syntax",
2351 return cli_arg_help(cli
, argv
[1][1],
2352 "NAME", "Access-list name",
2356 if (argc
== 3 && !argv
[2][1])
2357 return cli_arg_help(cli
, 1, NULL
);
2365 cli_error(cli
, "Specify access-list type and name");
2369 if (MATCH("standard", argv
[0]))
2371 else if (MATCH("extended", argv
[0]))
2375 cli_error(cli
, "Invalid access-list type");
2379 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2380 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2382 cli_error(cli
, "Invalid access-list name");
2386 filt
= find_filter(argv
[1], strlen(argv
[1]));
2391 cli_error(cli
, "Too many access-lists");
2396 if (!*ip_filters
[filt
].name
)
2398 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2399 strcpy(ip_filters
[filt
].name
, argv
[1]);
2400 ip_filters
[filt
].extended
= extended
;
2402 else if (ip_filters
[filt
].extended
!= extended
)
2404 cli_error(cli
, "Access-list is %s",
2405 ip_filters
[filt
].extended
? "extended" : "standard");
2410 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2414 if (filt
< 0 || !*ip_filters
[filt
].name
)
2416 cli_error(cli
, "Access-list not defined");
2421 if (ip_filters
[filt
].used
)
2423 cli_error(cli
, "Access-list in use");
2427 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2431 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2433 return access_list(cli
, argv
, argc
, 1);
2436 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2438 return access_list(cli
, argv
, argc
, 0);
2441 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2443 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2444 return sprintf(buf
, " any");
2446 if (wild
== INADDR_ANY
)
2447 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2449 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2452 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2456 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2457 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2458 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2459 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2460 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2466 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2468 static char buf
[256];
2471 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2474 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2475 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2478 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2482 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2483 p
+= show_ports(p
, &rule
->src_ports
);
2485 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2486 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2487 p
+= show_ports(p
, &rule
->dst_ports
);
2489 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2491 switch (rule
->tcp_flag_op
)
2493 case FILTER_FLAG_OP_EST
:
2494 p
+= sprintf(p
, " established");
2497 case FILTER_FLAG_OP_ANY
:
2498 case FILTER_FLAG_OP_ALL
:
2499 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2500 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2501 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2502 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2503 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2504 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2505 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2506 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2507 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2508 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2509 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2510 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2511 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2517 p
+= sprintf(p
, " fragments");
2522 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2524 static ip_filter_rulet rule
;
2525 struct in_addr addr
;
2529 if (CLI_HELP_REQUESTED
)
2533 cli_arg_help(cli
, 0,
2534 "ip", "Match IP packets",
2535 "tcp", "Match TCP packets",
2536 "udp", "Match UDP packets",
2542 // *sigh*, too darned complex
2543 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2549 cli_error(cli
, "Specify rule details");
2553 memset(&rule
, 0, sizeof(rule
));
2554 rule
.action
= (command
[0] == 'p')
2555 ? FILTER_ACTION_PERMIT
2556 : FILTER_ACTION_DENY
;
2558 if (MATCH("ip", argv
[0]))
2559 rule
.proto
= IPPROTO_IP
;
2560 else if (MATCH("udp", argv
[0]))
2561 rule
.proto
= IPPROTO_UDP
;
2562 else if (MATCH("tcp", argv
[0]))
2563 rule
.proto
= IPPROTO_TCP
;
2566 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2570 for (a
= 1, i
= 0; i
< 2; i
++)
2574 ip_filter_portt
*port
;
2579 wild
= &rule
.src_wild
;
2580 port
= &rule
.src_ports
;
2585 wild
= &rule
.dst_wild
;
2586 port
= &rule
.dst_ports
;
2589 cli_error(cli
, "Specify destination");
2594 if (MATCH("any", argv
[a
]))
2597 *wild
= INADDR_BROADCAST
;
2600 else if (MATCH("host", argv
[a
]))
2604 cli_error(cli
, "Specify host ip address");
2608 if (!inet_aton(argv
[a
], &addr
))
2610 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2622 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2626 if (!inet_aton(argv
[a
], &addr
))
2628 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2634 if (!inet_aton(argv
[++a
], &addr
))
2636 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2640 *wild
= addr
.s_addr
;
2644 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2648 if (MATCH("eq", argv
[a
]))
2649 port
->op
= FILTER_PORT_OP_EQ
;
2650 else if (MATCH("neq", argv
[a
]))
2651 port
->op
= FILTER_PORT_OP_NEQ
;
2652 else if (MATCH("gt", argv
[a
]))
2653 port
->op
= FILTER_PORT_OP_GT
;
2654 else if (MATCH("lt", argv
[a
]))
2655 port
->op
= FILTER_PORT_OP_LT
;
2656 else if (MATCH("range", argv
[a
]))
2657 port
->op
= FILTER_PORT_OP_RANGE
;
2664 cli_error(cli
, "Specify port");
2668 if (!(port
->port
= atoi(argv
[a
])))
2670 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2675 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2680 cli_error(cli
, "Specify port");
2684 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2686 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2693 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2695 if (MATCH("established", argv
[a
]))
2697 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2700 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2701 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2703 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2704 ? FILTER_FLAG_OP_ANY
2705 : FILTER_FLAG_OP_ALL
;
2709 cli_error(cli
, "Specify tcp flags");
2713 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2717 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2719 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2720 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2721 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2722 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2723 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2724 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2727 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2736 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2738 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2740 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2750 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2757 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2759 static ip_filter_rulet rule
;
2760 struct in_addr addr
;
2762 if (CLI_HELP_REQUESTED
)
2766 cli_arg_help(cli
, argv
[0][1],
2767 "A.B.C.D", "Source address",
2768 "any", "Any source address",
2769 "host", "Source host",
2775 if (MATCH("any", argv
[0]))
2777 if (argc
== 2 && !argv
[1][1])
2778 cli_arg_help(cli
, 1, NULL
);
2780 else if (MATCH("host", argv
[0]))
2784 cli_arg_help(cli
, argv
[1][1],
2785 "A.B.C.D", "Host address",
2788 else if (argc
== 3 && !argv
[2][1])
2789 cli_arg_help(cli
, 1, NULL
);
2795 cli_arg_help(cli
, 1,
2796 "A.B.C.D", "Wildcard bits",
2799 else if (argc
== 3 && !argv
[2][1])
2800 cli_arg_help(cli
, 1, NULL
);
2808 cli_error(cli
, "Specify rule details");
2812 memset(&rule
, 0, sizeof(rule
));
2813 rule
.action
= (command
[0] == 'p')
2814 ? FILTER_ACTION_PERMIT
2815 : FILTER_ACTION_DENY
;
2817 rule
.proto
= IPPROTO_IP
;
2818 if (MATCH("any", argv
[0]))
2820 rule
.src_ip
= INADDR_ANY
;
2821 rule
.src_wild
= INADDR_BROADCAST
;
2823 else if (MATCH("host", argv
[0]))
2827 cli_error(cli
, "Specify host ip address");
2831 if (!inet_aton(argv
[1], &addr
))
2833 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2837 rule
.src_ip
= addr
.s_addr
;
2838 rule
.src_wild
= INADDR_ANY
;
2844 cli_error(cli
, "Specify source ip address and wildcard");
2848 if (!inet_aton(argv
[0], &addr
))
2850 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2854 rule
.src_ip
= addr
.s_addr
;
2858 if (!inet_aton(argv
[1], &addr
))
2860 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2864 rule
.src_wild
= addr
.s_addr
;
2867 rule
.src_wild
= INADDR_ANY
;
2873 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2876 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2877 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2878 : access_list_rule_std(cli
, command
, argv
, argc
);
2883 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2885 if (!ip_filters
[filt
].rules
[i
].action
)
2887 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2891 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2895 cli_error(cli
, "Too many rules");
2899 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2904 /* filter USER {in|out} FILTER ... */
2905 if (CLI_HELP_REQUESTED
)
2910 return cli_arg_help(cli
, 0,
2911 "USER", "Username of session to filter", NULL
);
2915 return cli_arg_help(cli
, 0,
2916 "in", "Set incoming filter",
2917 "out", "Set outgoing filter", NULL
);
2921 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2922 "NAME", "Filter name", NULL
);
2925 return cli_arg_help(cli
, argc
> 1, NULL
);
2929 if (!config
->cluster_iam_master
)
2931 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2932 fmtaddr(config
->cluster_master_address
, 0));
2937 if (argc
!= 3 && argc
!= 5)
2939 cli_error(cli
, "Specify a user and filters");
2943 if (!(s
= sessionbyuser(argv
[0])))
2945 cli_error(cli
, "User %s is not connected", argv
[0]);
2949 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2950 for (i
= 1; i
< argc
; i
+= 2)
2955 if (MATCH("in", argv
[i
]))
2957 if (session
[s
].filter_in
)
2959 cli_error(cli
, "Input already filtered");
2962 f
= &cli_session_actions
[s
].filter_in
;
2964 else if (MATCH("out", argv
[i
]))
2966 if (session
[s
].filter_out
)
2968 cli_error(cli
, "Output already filtered");
2971 f
= &cli_session_actions
[s
].filter_out
;
2975 cli_error(cli
, "Invalid filter specification");
2979 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
2980 if (v
< 0 || !*ip_filters
[v
].name
)
2982 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
2989 cli_print(cli
, "Filtering user %s", argv
[0]);
2990 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
2995 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3000 if (CLI_HELP_REQUESTED
)
3001 return cli_arg_help(cli
, argc
> 1,
3002 "USER", "Username of session to remove filters from", NULL
);
3004 if (!config
->cluster_iam_master
)
3006 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3007 fmtaddr(config
->cluster_master_address
, 0));
3014 cli_error(cli
, "Specify a user to remove filters from");
3018 for (i
= 0; i
< argc
; i
++)
3020 if (!(s
= sessionbyuser(argv
[i
])))
3022 cli_error(cli
, "User %s is not connected", argv
[i
]);
3026 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3028 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3029 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3033 cli_error(cli
, "User %s not filtered", argv
[i
]);
3040 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3044 if (CLI_HELP_REQUESTED
)
3045 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3049 cli_error(cli
, "Specify a filter name");
3053 for (i
= 0; i
< argc
; i
++)
3055 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3056 ip_filter_rulet
*rules
;
3058 if (f
< 0 || !*ip_filters
[f
].name
)
3060 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3067 cli_print(cli
, "%s IP access list %s",
3068 ip_filters
[f
].extended
? "Extended" : "Standard",
3069 ip_filters
[f
].name
);
3071 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3073 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3075 cli_print(cli
, "%s (%u match%s)", r
,
3076 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3078 cli_print(cli
, "%s", r
);