1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.75 2006-08-02 13:35:39 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
, IPPROTO_TCP
);
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 if (session
[s
].session_timeout
)
431 clockt opened
= session
[s
].opened
;
432 if (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
433 opened
= bundle
[session
[s
].bundle
].online_time
;
435 cli_print(cli
, "\tSess Timeout:\t%u seconds", session
[s
].session_timeout
- (opened
? abs(time_now
- opened
) : 0));
438 if (session
[s
].idle_timeout
)
439 cli_print(cli
, "\tIdle Timeout:\t%u seconds", session
[s
].idle_timeout
- (session
[s
].last_data
? abs(time_now
- session
[s
].last_data
) : 0));
441 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
442 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
443 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
444 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
445 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
446 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
447 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
448 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
449 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
450 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
451 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
453 cli_print(cli
, "\tIntercepted:\tno");
455 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
457 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
458 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
459 t
? "YES" : "no", t
? " (" : "",
460 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
462 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
466 b_in
= session
[s
].tbf_in
;
467 b_out
= session
[s
].tbf_out
;
469 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
470 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
471 "ByteSent", "PackSent", "PackDrop", "PackDelay");
474 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
476 (filter_list
[b_in
].next
? "*" : " "),
477 (b_in
< 100 ? "\t" : ""),
478 filter_list
[b_in
].rate
* 8,
479 filter_list
[b_in
].credit
,
480 filter_list
[b_in
].queued
,
481 filter_list
[b_in
].b_queued
,
482 filter_list
[b_in
].p_queued
,
483 filter_list
[b_in
].b_sent
,
484 filter_list
[b_in
].p_sent
,
485 filter_list
[b_in
].p_dropped
,
486 filter_list
[b_in
].p_delayed
);
489 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
491 (filter_list
[b_out
].next
? "*" : " "),
492 (b_out
< 100 ? "\t" : ""),
493 filter_list
[b_out
].rate
* 8,
494 filter_list
[b_out
].credit
,
495 filter_list
[b_out
].queued
,
496 filter_list
[b_out
].b_queued
,
497 filter_list
[b_out
].p_queued
,
498 filter_list
[b_out
].b_sent
,
499 filter_list
[b_out
].p_sent
,
500 filter_list
[b_out
].p_dropped
,
501 filter_list
[b_out
].p_delayed
);
508 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %-15s %s",
524 for (i
= 1; i
< MAXSESSION
; i
++)
526 if (!session
[i
].opened
) continue;
527 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %-15s %s",
530 session
[i
].user
[0] ? session
[i
].user
: "*",
531 fmtaddr(htonl(session
[i
].ip
), 0),
532 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
533 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
534 (session
[i
].walled_garden
) ? "Y" : "N",
535 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
536 abs(time_now
- (unsigned long)session
[i
].opened
),
537 (unsigned long)session
[i
].cout
,
538 (unsigned long)session
[i
].cin
,
539 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
540 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
541 session
[i
].calling
[0] ? session
[i
].calling
: "*");
546 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
548 int i
, x
, show_all
= 0;
556 if (CLI_HELP_REQUESTED
)
559 return cli_arg_help(cli
, 1,
560 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
563 return cli_arg_help(cli
, 1,
564 "all", "Show all tunnels, including unused",
565 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
572 if (strcmp(argv
[0], "all") == 0)
578 // Show individual tunnel
579 for (i
= 0; i
< argc
; i
++)
584 if (t
<= 0 || t
>= MAXTUNNEL
)
586 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
589 cli_print(cli
, "\r\nTunnel %d:", t
);
590 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
591 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
592 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
593 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
594 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
595 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
596 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
597 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
598 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
600 for (x
= 0; x
< MAXSESSION
; x
++)
601 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
602 sprintf(s
, "%s%u ", s
, x
);
604 cli_print(cli
, "\tSessions:\t%s", s
);
610 // Show tunnel summary
611 cli_print(cli
, "%4s %20s %20s %6s %s",
618 for (i
= 1; i
< MAXTUNNEL
; i
++)
621 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
623 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
624 cli_print(cli
, "%4d %20s %20s %6s %6d",
626 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
627 fmtaddr(htonl(tunnel
[i
].ip
), 0),
628 states
[tunnel
[i
].state
],
635 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
642 if (CLI_HELP_REQUESTED
)
643 return cli_arg_help(cli
, 1,
644 "USER", "Show details for specific username",
647 for (i
= 0; i
< MAXSESSION
; i
++)
649 if (!session
[i
].opened
) continue;
650 if (!session
[i
].user
[0]) continue;
654 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
656 if (strcmp(argv
[j
], session
[i
].user
) == 0)
658 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
659 sargv
[sargc
] = sid
[sargc
];
667 cli_print(cli
, "%s", session
[i
].user
);
671 return cmd_show_session(cli
, "users", sargv
, sargc
);
677 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
679 if (CLI_HELP_REQUESTED
)
680 return CLI_HELP_NO_ARGS
;
682 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
683 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
684 GET_STAT(tun_rx_bytes
),
685 GET_STAT(tun_rx_packets
),
686 GET_STAT(tun_rx_errors
),
687 GET_STAT(tun_rx_dropped
));
688 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
689 GET_STAT(tun_tx_bytes
),
690 GET_STAT(tun_tx_packets
),
691 GET_STAT(tun_tx_errors
));
694 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
695 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
696 GET_STAT(tunnel_rx_bytes
),
697 GET_STAT(tunnel_rx_packets
),
698 GET_STAT(tunnel_rx_errors
));
699 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
700 GET_STAT(tunnel_tx_bytes
),
701 GET_STAT(tunnel_tx_packets
),
702 GET_STAT(tunnel_tx_errors
),
703 GET_STAT(tunnel_retries
));
706 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
707 cli_print(cli
, "-----------------------------------------");
708 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
709 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
710 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
711 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
712 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
713 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
714 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
715 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
716 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
717 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
718 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
719 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
720 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
721 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
722 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
723 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
724 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
725 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
729 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
730 cli_print(cli
, "-----------------------------------------");
731 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
732 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
733 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
734 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
735 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
736 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
737 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
738 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
739 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
740 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
741 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
742 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
743 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
744 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
745 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
746 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
747 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
748 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
749 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
750 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
751 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
752 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
753 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
754 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
755 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
756 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
757 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
758 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
759 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
760 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
761 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
762 #endif /* STAT_CALLS */
765 time_t l
= GET_STAT(last_reset
);
767 char *p
= strchr(t
, '\n');
771 cli_print(cli
, "Last counter reset %s", t
);
777 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
779 if (CLI_HELP_REQUESTED
)
780 return CLI_HELP_NO_ARGS
;
782 memset(_statistics
, 0, sizeof(struct Tstats
));
783 SET_STAT(last_reset
, time(NULL
));
785 cli_print(cli
, "Counters cleared");
788 #endif /* STATISTICS */
790 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
796 if (CLI_HELP_REQUESTED
)
797 return cli_arg_help(cli
, 1,
798 "tag", "Include CVS release tag",
799 "file", "Include file versions",
802 for (i
= 0; i
< argc
; i
++)
803 if (!strcmp(argv
[i
], "tag"))
805 else if (!strcmp(argv
[i
], "file"))
808 cli_print(cli
, "L2TPNS %s", VERSION
);
811 char const *p
= strchr(cvs_name
, ':');
823 e
= strpbrk(p
, " \t$");
824 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
829 extern linked_list
*loaded_plugins
;
832 cli_print(cli
, "Files:");
833 cli_print(cli
, " %s", cvs_id_arp
);
835 cli_print(cli
, " %s", cvs_id_bgp
);
837 cli_print(cli
, " %s", cvs_id_cli
);
838 cli_print(cli
, " %s", cvs_id_cluster
);
839 cli_print(cli
, " %s", cvs_id_constants
);
840 cli_print(cli
, " %s", cvs_id_control
);
841 cli_print(cli
, " %s", cvs_id_icmp
);
842 cli_print(cli
, " %s", cvs_id_l2tpns
);
843 cli_print(cli
, " %s", cvs_id_ll
);
844 cli_print(cli
, " %s", cvs_id_ppp
);
845 cli_print(cli
, " %s", cvs_id_radius
);
846 cli_print(cli
, " %s", cvs_id_tbf
);
847 cli_print(cli
, " %s", cvs_id_util
);
849 ll_reset(loaded_plugins
);
850 while ((p
= ll_next(loaded_plugins
)))
852 char const **id
= dlsym(p
, "cvs_id");
854 cli_print(cli
, " %s", *id
);
861 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
864 int used
= 0, free
= 0, show_all
= 0;
866 if (!config
->cluster_iam_master
)
868 cli_print(cli
, "Can't do this on a slave. Do it on %s",
869 fmtaddr(config
->cluster_master_address
, 0));
874 if (CLI_HELP_REQUESTED
)
877 return cli_arg_help(cli
, 1, NULL
);
879 return cli_arg_help(cli
, 1,
880 "all", "Show all pool addresses, including unused",
884 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
888 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
889 for (i
= 0; i
< MAXIPPOOL
; i
++)
891 if (!ip_address_pool
[i
].address
) continue;
892 if (ip_address_pool
[i
].assigned
)
894 cli_print(cli
, "%-15s\tY %8d %s",
895 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
896 ip_address_pool
[i
].session
,
897 session
[ip_address_pool
[i
].session
].user
);
903 if (ip_address_pool
[i
].last
)
904 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
905 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
906 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
909 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
916 cli_print(cli
, "(Not displaying unused addresses)");
918 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
922 static FILE *save_config_fh
= 0;
923 static void print_save_config(struct cli_def
*cli
, char *string
)
926 fprintf(save_config_fh
, "%s\n", string
);
929 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
931 if (CLI_HELP_REQUESTED
)
932 return CLI_HELP_NO_ARGS
;
934 if ((save_config_fh
= fopen(config
->config_file
, "w")))
936 cli_print(cli
, "Writing configuration");
937 cli_print_callback(cli
, print_save_config
);
938 cmd_show_run(cli
, command
, argv
, argc
);
939 cli_print_callback(cli
, NULL
);
940 fclose(save_config_fh
);
945 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
950 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
952 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
955 char ipv6addr
[INET6_ADDRSTRLEN
];
957 if (CLI_HELP_REQUESTED
)
958 return CLI_HELP_NO_ARGS
;
960 cli_print(cli
, "# Current configuration:");
962 for (i
= 0; config_values
[i
].key
; i
++)
964 void *value
= ((void *)config
) + config_values
[i
].offset
;
965 if (config_values
[i
].type
== STRING
)
966 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
967 else if (config_values
[i
].type
== IPv4
)
968 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
969 else if (config_values
[i
].type
== IPv6
)
970 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
971 else if (config_values
[i
].type
== SHORT
)
972 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
973 else if (config_values
[i
].type
== BOOL
)
974 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
975 else if (config_values
[i
].type
== INT
)
976 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
977 else if (config_values
[i
].type
== UNSIGNED_LONG
)
978 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
981 cli_print(cli
, "# Plugins");
982 for (i
= 0; i
< MAXPLUGINS
; i
++)
984 if (*config
->plugins
[i
])
986 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
991 if (config
->as_number
)
996 cli_print(cli
, "# BGP");
997 cli_print(cli
, "router bgp %u", config
->as_number
);
998 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1000 if (!config
->neighbour
[i
].name
[0])
1003 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1005 k
= config
->neighbour
[i
].keepalive
;
1006 h
= config
->neighbour
[i
].hold
;
1013 k
= BGP_KEEPALIVE_TIME
;
1019 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1024 cli_print(cli
, "# Filters");
1025 for (i
= 0; i
< MAXFILTER
; i
++)
1027 ip_filter_rulet
*rules
;
1028 if (!*ip_filters
[i
].name
)
1031 cli_print(cli
, "ip access-list %s %s",
1032 ip_filters
[i
].extended
? "extended" : "standard",
1033 ip_filters
[i
].name
);
1035 rules
= ip_filters
[i
].rules
;
1036 while (rules
->action
)
1037 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1040 cli_print(cli
, "# end");
1044 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1046 int i
, free
= 0, used
= 0, show_all
= 0;
1058 if (CLI_HELP_REQUESTED
)
1061 return cli_arg_help(cli
, 1, NULL
);
1063 return cli_arg_help(cli
, 1,
1064 "all", "Show all RADIUS sessions, including unused",
1068 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1072 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1075 for (i
= 1; i
< MAXRADIUS
; i
++)
1077 if (radius
[i
].state
== RADIUSNULL
)
1082 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1084 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1088 states
[radius
[i
].state
],
1094 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1099 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1103 if (CLI_HELP_REQUESTED
)
1104 return CLI_HELP_NO_ARGS
;
1106 cli_print(cli
, "Plugins currently loaded:");
1107 for (i
= 0; i
< MAXPLUGINS
; i
++)
1108 if (*config
->plugins
[i
])
1109 cli_print(cli
, " %s", config
->plugins
[i
]);
1114 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1118 if (CLI_HELP_REQUESTED
)
1119 return CLI_HELP_NO_ARGS
;
1121 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1130 for (i
= 0; i
< MAXSESSION
; i
++)
1132 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1133 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1137 session
[i
].throttle_in
,
1138 session
[i
].throttle_out
,
1140 session
[i
].tbf_out
);
1146 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1148 if (CLI_HELP_REQUESTED
)
1149 return CLI_HELP_NO_ARGS
;
1151 cli_print(cli
, " _\n"
1157 " ( \\ `. `-. _,.-:\\\n"
1158 " \\ \\ `. `-._ __..--' ,-';/\n"
1159 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1160 " `. `. `-._ __..--' ,' /\n"
1161 " `. `-_ ``--..'' _.-' ,'\n"
1162 " `-_ `-.___ __,--' ,'\n"
1163 " `-.__ `----\"\"\" __.-'\n"
1164 "hh `--..____..--'");
1169 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1174 if (CLI_HELP_REQUESTED
)
1175 return cli_arg_help(cli
, argc
> 1,
1176 "USER", "Username of session to drop", NULL
);
1178 if (!config
->cluster_iam_master
)
1180 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1181 fmtaddr(config
->cluster_master_address
, 0));
1188 cli_error(cli
, "Specify a user to drop");
1192 for (i
= 0; i
< argc
; i
++)
1194 if (!(s
= sessionbyuser(argv
[i
])))
1196 cli_error(cli
, "User %s is not connected", argv
[i
]);
1200 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1202 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1203 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1210 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1215 if (CLI_HELP_REQUESTED
)
1216 return cli_arg_help(cli
, argc
> 1,
1217 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1219 if (!config
->cluster_iam_master
)
1221 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1222 fmtaddr(config
->cluster_master_address
, 0));
1229 cli_error(cli
, "Specify a tunnel to drop");
1233 for (i
= 0; i
< argc
; i
++)
1235 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1237 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1243 cli_error(cli
, "Tunnel %d is not connected", t
);
1249 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1253 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1254 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1260 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1265 if (CLI_HELP_REQUESTED
)
1266 return cli_arg_help(cli
, argc
> 1,
1267 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1269 if (!config
->cluster_iam_master
)
1271 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1272 fmtaddr(config
->cluster_master_address
, 0));
1279 cli_error(cli
, "Specify a session id to drop");
1283 for (i
= 0; i
< argc
; i
++)
1285 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1287 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1291 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1293 cli_print(cli
, "Dropping session %d", s
);
1294 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1298 cli_error(cli
, "Session %d is not active.", s
);
1305 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1311 if (CLI_HELP_REQUESTED
)
1316 return cli_arg_help(cli
, 0,
1317 "USER", "Username of session to snoop", NULL
);
1320 return cli_arg_help(cli
, 0,
1321 "A.B.C.D", "IP address of snoop destination", NULL
);
1324 return cli_arg_help(cli
, 0,
1325 "N", "Port of snoop destination", NULL
);
1329 return cli_arg_help(cli
, 1, NULL
);
1336 if (!config
->cluster_iam_master
)
1338 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1339 fmtaddr(config
->cluster_master_address
, 0));
1346 cli_error(cli
, "Specify username, ip and port");
1350 if (!(s
= sessionbyuser(argv
[0])))
1352 cli_error(cli
, "User %s is not connected", argv
[0]);
1356 ip
= inet_addr(argv
[1]);
1357 if (!ip
|| ip
== INADDR_NONE
)
1359 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1363 port
= atoi(argv
[2]);
1366 cli_error(cli
, "Invalid port %s", argv
[2]);
1370 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1371 cli_session_actions
[s
].snoop_ip
= ip
;
1372 cli_session_actions
[s
].snoop_port
= port
;
1373 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1378 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1383 if (CLI_HELP_REQUESTED
)
1384 return cli_arg_help(cli
, argc
> 1,
1385 "USER", "Username of session to unsnoop", NULL
);
1387 if (!config
->cluster_iam_master
)
1389 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1390 fmtaddr(config
->cluster_master_address
, 0));
1397 cli_error(cli
, "Specify a user to unsnoop");
1401 for (i
= 0; i
< argc
; i
++)
1403 if (!(s
= sessionbyuser(argv
[i
])))
1405 cli_error(cli
, "User %s is not connected", argv
[i
]);
1409 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1410 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1416 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1423 throttle USER - throttle in/out to default rate
1424 throttle USER RATE - throttle in/out to default rate
1425 throttle USER in RATE - throttle input only
1426 throttle USER out RATE - throttle output only
1427 throttle USER in RATE out RATE - throttle both
1430 if (CLI_HELP_REQUESTED
)
1435 return cli_arg_help(cli
, 0,
1436 "USER", "Username of session to throttle", NULL
);
1439 return cli_arg_help(cli
, 1,
1440 "RATE", "Rate in kbps (in and out)",
1441 "in", "Select incoming rate",
1442 "out", "Select outgoing rate", NULL
);
1445 return cli_arg_help(cli
, 1,
1446 "in", "Select incoming rate",
1447 "out", "Select outgoing rate", NULL
);
1450 if (isdigit(argv
[1][0]))
1451 return cli_arg_help(cli
, 1, NULL
);
1454 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1457 return cli_arg_help(cli
, argc
> 1, NULL
);
1461 if (!config
->cluster_iam_master
)
1463 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1464 fmtaddr(config
->cluster_master_address
, 0));
1471 cli_error(cli
, "Specify a user to throttle");
1475 if (!(s
= sessionbyuser(argv
[0])))
1477 cli_error(cli
, "User %s is not connected", argv
[0]);
1483 rate_in
= rate_out
= config
->rl_rate
;
1487 rate_in
= rate_out
= atoi(argv
[1]);
1490 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1494 else if (argc
== 3 || argc
== 5)
1497 for (i
= 1; i
< argc
- 1; i
+= 2)
1500 if (MATCH("in", argv
[i
]))
1501 r
= rate_in
= atoi(argv
[i
+1]);
1502 else if (MATCH("out", argv
[i
]))
1503 r
= rate_out
= atoi(argv
[i
+1]);
1507 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1514 cli_error(cli
, "Invalid arguments");
1518 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1520 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1524 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1525 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1526 cli_session_actions
[s
].throttle_in
= rate_in
;
1528 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1529 cli_session_actions
[s
].throttle_out
= rate_out
;
1531 if (cli_session_actions
[s
].throttle_in
== -1 &&
1532 cli_session_actions
[s
].throttle_out
== -1)
1534 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1538 cli_print(cli
, "Throttling user %s", argv
[0]);
1539 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1544 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1549 if (CLI_HELP_REQUESTED
)
1550 return cli_arg_help(cli
, argc
> 1,
1551 "USER", "Username of session to unthrottle", NULL
);
1553 if (!config
->cluster_iam_master
)
1555 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1556 fmtaddr(config
->cluster_master_address
, 0));
1563 cli_error(cli
, "Specify a user to unthrottle");
1567 for (i
= 0; i
< argc
; i
++)
1569 if (!(s
= sessionbyuser(argv
[i
])))
1571 cli_error(cli
, "User %s is not connected", argv
[i
]);
1575 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1577 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1578 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1582 cli_error(cli
, "User %s not throttled", argv
[i
]);
1589 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1593 if (CLI_HELP_REQUESTED
)
1594 return cli_arg_help(cli
, 1,
1595 "all", "Enable debugging for all except \"data\"",
1596 "critical", "", // FIXME: add descriptions
1606 char *p
= (char *) &debug_flags
;
1607 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1611 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1612 (debug_flags
.critical
) ? " critical" : "",
1613 (debug_flags
.error
) ? " error" : "",
1614 (debug_flags
.warning
) ? " warning" : "",
1615 (debug_flags
.info
) ? " info" : "",
1616 (debug_flags
.calls
) ? " calls" : "",
1617 (debug_flags
.data
) ? " data" : "");
1623 cli_print(cli
, "Debugging off");
1627 for (i
= 0; i
< argc
; i
++)
1629 int len
= strlen(argv
[i
]);
1631 if (argv
[i
][0] == 'c' && len
< 2)
1632 len
= 2; /* distinguish [cr]itical from [ca]lls */
1634 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1635 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1636 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1637 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1638 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1639 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1640 if (!strncmp("all", argv
[i
], len
))
1642 memset(&debug_flags
, 1, sizeof(debug_flags
));
1643 debug_flags
.data
= 0;
1647 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1653 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1657 if (CLI_HELP_REQUESTED
)
1658 return cli_arg_help(cli
, 1,
1659 "all", "Disable all debugging",
1660 "critical", "", // FIXME: add descriptions
1670 memset(&debug_flags
, 0, sizeof(debug_flags
));
1674 for (i
= 0; i
< argc
; i
++)
1676 int len
= strlen(argv
[i
]);
1678 if (argv
[i
][0] == 'c' && len
< 2)
1679 len
= 2; /* distinguish [cr]itical from [ca]lls */
1681 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1682 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1683 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1684 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1685 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1686 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1687 if (!strncmp("all", argv
[i
], len
))
1689 memset(&debug_flags
, 0, sizeof(debug_flags
));
1693 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1699 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1701 int i
, firstfree
= 0;
1703 if (CLI_HELP_REQUESTED
)
1704 return cli_arg_help(cli
, argc
> 1,
1705 "PLUGIN", "Name of plugin to load", NULL
);
1709 cli_error(cli
, "Specify a plugin to load");
1713 for (i
= 0; i
< MAXPLUGINS
; i
++)
1715 if (!*config
->plugins
[i
] && !firstfree
)
1717 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1719 cli_error(cli
, "Plugin is already loaded");
1726 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1727 config
->reload_config
= 1;
1728 cli_print(cli
, "Loading plugin %s", argv
[0]);
1734 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1738 if (CLI_HELP_REQUESTED
)
1739 return cli_arg_help(cli
, argc
> 1,
1740 "PLUGIN", "Name of plugin to unload", NULL
);
1744 cli_error(cli
, "Specify a plugin to remove");
1748 for (i
= 0; i
< MAXPLUGINS
; i
++)
1750 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1752 config
->reload_config
= 1;
1753 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1758 cli_error(cli
, "Plugin is not loaded");
1762 static char *duration(time_t secs
)
1764 static char *buf
= NULL
;
1767 if (!buf
) buf
= calloc(64, 1);
1771 int days
= secs
/ 86400;
1772 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1778 int mins
= secs
/ 60;
1779 int hrs
= mins
/ 60;
1782 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1784 else if (secs
>= 60)
1786 int mins
= secs
/ 60;
1787 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1790 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1795 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1798 char buf
[100], *p
= buf
, *loads
[3];
1799 int i
, num_sessions
= 0;
1801 if (CLI_HELP_REQUESTED
)
1802 return CLI_HELP_NO_ARGS
;
1804 fh
= fopen("/proc/loadavg", "r");
1805 fgets(buf
, 100, fh
);
1808 for (i
= 0; i
< 3; i
++)
1809 loads
[i
] = strdup(strsep(&p
, " "));
1812 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1814 for (i
= 1; i
< MAXSESSION
; i
++)
1815 if (session
[i
].opened
) num_sessions
++;
1817 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1819 duration(time_now
- config
->start_time
),
1821 loads
[0], loads
[1], loads
[2]
1823 for (i
= 0; i
< 3; i
++)
1824 if (loads
[i
]) free(loads
[i
]);
1826 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1831 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1835 if (CLI_HELP_REQUESTED
)
1841 int len
= strlen(argv
[0])-1;
1842 for (i
= 0; config_values
[i
].key
; i
++)
1843 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1844 cli_error(cli
, " %s", config_values
[i
].key
);
1850 return cli_arg_help(cli
, 0,
1851 "VALUE", "Value for variable", NULL
);
1855 return cli_arg_help(cli
, 1, NULL
);
1864 cli_error(cli
, "Specify variable and value");
1868 for (i
= 0; config_values
[i
].key
; i
++)
1870 void *value
= ((void *) config
) + config_values
[i
].offset
;
1871 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1873 // Found a value to set
1874 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1875 switch (config_values
[i
].type
)
1878 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1881 *(int *) value
= atoi(argv
[1]);
1884 *(unsigned long *) value
= atol(argv
[1]);
1887 *(short *) value
= atoi(argv
[1]);
1890 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1893 inet_pton(AF_INET6
, argv
[1], value
);
1896 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1902 cli_error(cli
, "Unknown variable type");
1905 config
->reload_config
= 1;
1910 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1914 int regular_stuff(struct cli_def
*cli
)
1920 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1922 char *m
= ringbuffer
->buffer
[i
].message
;
1928 switch (ringbuffer
->buffer
[i
].level
)
1930 case 0: show
= debug_flags
.critical
; break;
1931 case 1: show
= debug_flags
.error
; break;
1932 case 2: show
= debug_flags
.warning
; break;
1933 case 3: show
= debug_flags
.info
; break;
1934 case 4: show
= debug_flags
.calls
; break;
1935 case 5: show
= debug_flags
.data
; break;
1938 if (!show
) continue;
1940 if (!(p
= strchr(m
, '\n')))
1943 cli_error(cli
, "\r%s-%u-%u %.*s",
1944 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1945 ringbuffer
->buffer
[i
].tunnel
,
1946 ringbuffer
->buffer
[i
].session
,
1952 debug_rb_tail
= ringbuffer
->tail
;
1960 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1964 if (CLI_HELP_REQUESTED
)
1965 return cli_arg_help(cli
, argc
> 1,
1966 "<1-65535>", "Autonomous system number", NULL
);
1968 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1970 cli_error(cli
, "Invalid autonomous system number");
1974 if (bgp_configured
&& as
!= config
->as_number
)
1976 cli_error(cli
, "Can't change local AS on a running system");
1980 config
->as_number
= as
;
1981 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1986 static int find_bgp_neighbour(char const *name
)
1991 in_addr_t addrs
[4] = { 0 };
1994 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1997 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1998 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2000 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2002 if (!config
->neighbour
[i
].name
[0])
2004 if (new == -1) new = i
;
2008 if (!strcmp(name
, config
->neighbour
[i
].name
))
2011 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2014 for (a
= h
->h_addr_list
; *a
; a
++)
2017 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2018 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2026 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2032 if (CLI_HELP_REQUESTED
)
2037 return cli_arg_help(cli
, 0,
2038 "A.B.C.D", "BGP neighbour address",
2039 "NAME", "BGP neighbour name",
2043 return cli_arg_help(cli
, 0,
2044 "remote-as", "Set remote autonomous system number",
2045 "timers", "Set timers",
2049 if (MATCH("remote-as", argv
[1]))
2050 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2052 if (MATCH("timers", argv
[1]))
2055 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2058 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2060 if (argc
== 5 && !argv
[4][1])
2061 return cli_arg_help(cli
, 1, NULL
);
2070 cli_error(cli
, "Invalid arguments");
2074 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2076 cli_error(cli
, "Invalid neighbour");
2082 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2086 if (MATCH("remote-as", argv
[1]))
2088 int as
= atoi(argv
[2]);
2089 if (as
< 0 || as
> 65535)
2091 cli_error(cli
, "Invalid autonomous system number");
2095 if (!config
->neighbour
[i
].name
[0])
2097 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2098 config
->neighbour
[i
].keepalive
= -1;
2099 config
->neighbour
[i
].hold
= -1;
2102 config
->neighbour
[i
].as
= as
;
2106 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2108 cli_error(cli
, "Invalid arguments");
2112 if (!config
->neighbour
[i
].name
[0])
2114 cli_error(cli
, "Specify remote-as first");
2118 keepalive
= atoi(argv
[2]);
2119 hold
= atoi(argv
[3]);
2121 if (keepalive
< 1 || keepalive
> 65535)
2123 cli_error(cli
, "Invalid keepalive time");
2127 if (hold
< 3 || hold
> 65535)
2129 cli_error(cli
, "Invalid hold time");
2133 if (keepalive
== BGP_KEEPALIVE_TIME
)
2134 keepalive
= -1; // using default value
2136 if (hold
== BGP_HOLD_TIME
)
2139 config
->neighbour
[i
].keepalive
= keepalive
;
2140 config
->neighbour
[i
].hold
= hold
;
2145 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2149 if (CLI_HELP_REQUESTED
)
2150 return cli_arg_help(cli
, argc
> 0,
2151 "A.B.C.D", "BGP neighbour address",
2152 "NAME", "BGP neighbour name",
2157 cli_error(cli
, "Specify a BGP neighbour");
2161 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2163 cli_error(cli
, "Invalid neighbour");
2167 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2169 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2173 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2177 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2183 if (!bgp_configured
)
2186 if (CLI_HELP_REQUESTED
)
2187 return cli_arg_help(cli
, 1,
2188 "A.B.C.D", "BGP neighbour address",
2189 "NAME", "BGP neighbour name",
2192 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2193 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2197 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2199 if (!*bgp_peers
[i
].name
)
2202 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2203 if (argc
&& strcmp(addr
, argv
[0]) &&
2204 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2210 cli_print(cli
, "Peer AS Address "
2211 "State Retries Retry in Route Pend Timers");
2212 cli_print(cli
, "------------------ ----- --------------- "
2213 "----------- ------- -------- ----- ---- ---------");
2216 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2220 bgp_state_str(bgp_peers
[i
].state
),
2221 bgp_peers
[i
].retry_count
,
2222 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2223 bgp_peers
[i
].routing
? "yes" : "no",
2224 bgp_peers
[i
].update_routes
? "yes" : "no",
2225 bgp_peers
[i
].keepalive
,
2232 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2237 if (!bgp_configured
)
2240 if (CLI_HELP_REQUESTED
)
2241 return cli_arg_help(cli
, 1,
2242 "A.B.C.D", "BGP neighbour address",
2243 "NAME", "BGP neighbour name",
2246 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2248 if (bgp_peers
[i
].state
!= Established
)
2251 if (!bgp_peers
[i
].routing
)
2254 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2255 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2258 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2259 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2265 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2270 if (!bgp_configured
)
2273 if (CLI_HELP_REQUESTED
)
2274 return cli_arg_help(cli
, 1,
2275 "A.B.C.D", "BGP neighbour address",
2276 "NAME", "BGP neighbour name",
2279 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2281 if (bgp_peers
[i
].state
!= Established
)
2284 if (bgp_peers
[i
].routing
)
2287 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2288 if (argc
&& strcmp(addr
, argv
[0]) &&
2289 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2292 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2293 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2299 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2304 if (!bgp_configured
)
2307 if (CLI_HELP_REQUESTED
)
2308 return cli_arg_help(cli
, 1,
2309 "A.B.C.D", "BGP neighbour address",
2310 "NAME", "BGP neighbour name",
2313 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2315 if (!*bgp_peers
[i
].name
)
2318 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2319 if (argc
&& strcmp(addr
, argv
[0]) &&
2320 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2323 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2324 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2332 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2336 if (CLI_HELP_REQUESTED
)
2341 return cli_arg_help(cli
, 0,
2342 "standard", "Standard syntax",
2343 "extended", "Extended syntax",
2347 return cli_arg_help(cli
, argv
[1][1],
2348 "NAME", "Access-list name",
2352 if (argc
== 3 && !argv
[2][1])
2353 return cli_arg_help(cli
, 1, NULL
);
2361 cli_error(cli
, "Specify access-list type and name");
2365 if (MATCH("standard", argv
[0]))
2367 else if (MATCH("extended", argv
[0]))
2371 cli_error(cli
, "Invalid access-list type");
2375 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2376 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2378 cli_error(cli
, "Invalid access-list name");
2382 filt
= find_filter(argv
[1], strlen(argv
[1]));
2387 cli_error(cli
, "Too many access-lists");
2392 if (!*ip_filters
[filt
].name
)
2394 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2395 strcpy(ip_filters
[filt
].name
, argv
[1]);
2396 ip_filters
[filt
].extended
= extended
;
2398 else if (ip_filters
[filt
].extended
!= extended
)
2400 cli_error(cli
, "Access-list is %s",
2401 ip_filters
[filt
].extended
? "extended" : "standard");
2406 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2410 if (filt
< 0 || !*ip_filters
[filt
].name
)
2412 cli_error(cli
, "Access-list not defined");
2417 if (ip_filters
[filt
].used
)
2419 cli_error(cli
, "Access-list in use");
2423 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2427 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2429 return access_list(cli
, argv
, argc
, 1);
2432 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2434 return access_list(cli
, argv
, argc
, 0);
2437 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2439 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2440 return sprintf(buf
, " any");
2442 if (wild
== INADDR_ANY
)
2443 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2445 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2448 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2452 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2453 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2454 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2455 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2456 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2462 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2464 static char buf
[256];
2467 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2470 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2471 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2474 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2478 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2479 p
+= show_ports(p
, &rule
->src_ports
);
2481 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2482 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2483 p
+= show_ports(p
, &rule
->dst_ports
);
2485 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2487 switch (rule
->tcp_flag_op
)
2489 case FILTER_FLAG_OP_EST
:
2490 p
+= sprintf(p
, " established");
2493 case FILTER_FLAG_OP_ANY
:
2494 case FILTER_FLAG_OP_ALL
:
2495 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2496 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2497 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2498 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2499 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2500 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2501 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2502 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2503 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2504 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2505 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2506 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2507 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2513 p
+= sprintf(p
, " fragments");
2518 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2520 static ip_filter_rulet rule
;
2521 struct in_addr addr
;
2525 if (CLI_HELP_REQUESTED
)
2529 cli_arg_help(cli
, 0,
2530 "ip", "Match IP packets",
2531 "tcp", "Match TCP packets",
2532 "udp", "Match UDP packets",
2538 // *sigh*, too darned complex
2539 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2545 cli_error(cli
, "Specify rule details");
2549 memset(&rule
, 0, sizeof(rule
));
2550 rule
.action
= (command
[0] == 'p')
2551 ? FILTER_ACTION_PERMIT
2552 : FILTER_ACTION_DENY
;
2554 if (MATCH("ip", argv
[0]))
2555 rule
.proto
= IPPROTO_IP
;
2556 else if (MATCH("udp", argv
[0]))
2557 rule
.proto
= IPPROTO_UDP
;
2558 else if (MATCH("tcp", argv
[0]))
2559 rule
.proto
= IPPROTO_TCP
;
2562 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2566 for (a
= 1, i
= 0; i
< 2; i
++)
2570 ip_filter_portt
*port
;
2575 wild
= &rule
.src_wild
;
2576 port
= &rule
.src_ports
;
2581 wild
= &rule
.dst_wild
;
2582 port
= &rule
.dst_ports
;
2585 cli_error(cli
, "Specify destination");
2590 if (MATCH("any", argv
[a
]))
2593 *wild
= INADDR_BROADCAST
;
2596 else if (MATCH("host", argv
[a
]))
2600 cli_error(cli
, "Specify host ip address");
2604 if (!inet_aton(argv
[a
], &addr
))
2606 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2618 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2622 if (!inet_aton(argv
[a
], &addr
))
2624 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2630 if (!inet_aton(argv
[++a
], &addr
))
2632 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2636 *wild
= addr
.s_addr
;
2640 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2644 if (MATCH("eq", argv
[a
]))
2645 port
->op
= FILTER_PORT_OP_EQ
;
2646 else if (MATCH("neq", argv
[a
]))
2647 port
->op
= FILTER_PORT_OP_NEQ
;
2648 else if (MATCH("gt", argv
[a
]))
2649 port
->op
= FILTER_PORT_OP_GT
;
2650 else if (MATCH("lt", argv
[a
]))
2651 port
->op
= FILTER_PORT_OP_LT
;
2652 else if (MATCH("range", argv
[a
]))
2653 port
->op
= FILTER_PORT_OP_RANGE
;
2660 cli_error(cli
, "Specify port");
2664 if (!(port
->port
= atoi(argv
[a
])))
2666 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2671 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2676 cli_error(cli
, "Specify port");
2680 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2682 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2689 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2691 if (MATCH("established", argv
[a
]))
2693 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2696 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2697 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2699 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2700 ? FILTER_FLAG_OP_ANY
2701 : FILTER_FLAG_OP_ALL
;
2705 cli_error(cli
, "Specify tcp flags");
2709 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2713 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2715 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2716 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2717 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2718 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2719 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2720 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2723 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2732 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2734 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2736 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2746 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2753 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2755 static ip_filter_rulet rule
;
2756 struct in_addr addr
;
2758 if (CLI_HELP_REQUESTED
)
2762 cli_arg_help(cli
, argv
[0][1],
2763 "A.B.C.D", "Source address",
2764 "any", "Any source address",
2765 "host", "Source host",
2771 if (MATCH("any", argv
[0]))
2773 if (argc
== 2 && !argv
[1][1])
2774 cli_arg_help(cli
, 1, NULL
);
2776 else if (MATCH("host", argv
[0]))
2780 cli_arg_help(cli
, argv
[1][1],
2781 "A.B.C.D", "Host address",
2784 else if (argc
== 3 && !argv
[2][1])
2785 cli_arg_help(cli
, 1, NULL
);
2791 cli_arg_help(cli
, 1,
2792 "A.B.C.D", "Wildcard bits",
2795 else if (argc
== 3 && !argv
[2][1])
2796 cli_arg_help(cli
, 1, NULL
);
2804 cli_error(cli
, "Specify rule details");
2808 memset(&rule
, 0, sizeof(rule
));
2809 rule
.action
= (command
[0] == 'p')
2810 ? FILTER_ACTION_PERMIT
2811 : FILTER_ACTION_DENY
;
2813 rule
.proto
= IPPROTO_IP
;
2814 if (MATCH("any", argv
[0]))
2816 rule
.src_ip
= INADDR_ANY
;
2817 rule
.src_wild
= INADDR_BROADCAST
;
2819 else if (MATCH("host", argv
[0]))
2823 cli_error(cli
, "Specify host ip address");
2827 if (!inet_aton(argv
[1], &addr
))
2829 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2833 rule
.src_ip
= addr
.s_addr
;
2834 rule
.src_wild
= INADDR_ANY
;
2840 cli_error(cli
, "Specify source ip address and wildcard");
2844 if (!inet_aton(argv
[0], &addr
))
2846 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2850 rule
.src_ip
= addr
.s_addr
;
2854 if (!inet_aton(argv
[1], &addr
))
2856 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2860 rule
.src_wild
= addr
.s_addr
;
2863 rule
.src_wild
= INADDR_ANY
;
2869 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2872 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2873 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2874 : access_list_rule_std(cli
, command
, argv
, argc
);
2879 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2881 if (!ip_filters
[filt
].rules
[i
].action
)
2883 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2887 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2891 cli_error(cli
, "Too many rules");
2895 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2900 /* filter USER {in|out} FILTER ... */
2901 if (CLI_HELP_REQUESTED
)
2906 return cli_arg_help(cli
, 0,
2907 "USER", "Username of session to filter", NULL
);
2911 return cli_arg_help(cli
, 0,
2912 "in", "Set incoming filter",
2913 "out", "Set outgoing filter", NULL
);
2917 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2918 "NAME", "Filter name", NULL
);
2921 return cli_arg_help(cli
, argc
> 1, NULL
);
2925 if (!config
->cluster_iam_master
)
2927 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2928 fmtaddr(config
->cluster_master_address
, 0));
2933 if (argc
!= 3 && argc
!= 5)
2935 cli_error(cli
, "Specify a user and filters");
2939 if (!(s
= sessionbyuser(argv
[0])))
2941 cli_error(cli
, "User %s is not connected", argv
[0]);
2945 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2946 for (i
= 1; i
< argc
; i
+= 2)
2951 if (MATCH("in", argv
[i
]))
2953 if (session
[s
].filter_in
)
2955 cli_error(cli
, "Input already filtered");
2958 f
= &cli_session_actions
[s
].filter_in
;
2960 else if (MATCH("out", argv
[i
]))
2962 if (session
[s
].filter_out
)
2964 cli_error(cli
, "Output already filtered");
2967 f
= &cli_session_actions
[s
].filter_out
;
2971 cli_error(cli
, "Invalid filter specification");
2975 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
2976 if (v
< 0 || !*ip_filters
[v
].name
)
2978 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
2985 cli_print(cli
, "Filtering user %s", argv
[0]);
2986 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
2991 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2996 if (CLI_HELP_REQUESTED
)
2997 return cli_arg_help(cli
, argc
> 1,
2998 "USER", "Username of session to remove filters from", NULL
);
3000 if (!config
->cluster_iam_master
)
3002 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3003 fmtaddr(config
->cluster_master_address
, 0));
3010 cli_error(cli
, "Specify a user to remove filters from");
3014 for (i
= 0; i
< argc
; i
++)
3016 if (!(s
= sessionbyuser(argv
[i
])))
3018 cli_error(cli
, "User %s is not connected", argv
[i
]);
3022 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3024 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3025 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3029 cli_error(cli
, "User %s not filtered", argv
[i
]);
3036 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3040 if (CLI_HELP_REQUESTED
)
3041 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3045 cli_error(cli
, "Specify a filter name");
3049 for (i
= 0; i
< argc
; i
++)
3051 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3052 ip_filter_rulet
*rules
;
3054 if (f
< 0 || !*ip_filters
[f
].name
)
3056 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3063 cli_print(cli
, "%s IP access list %s",
3064 ip_filters
[f
].extended
? "Extended" : "Standard",
3065 ip_filters
[f
].name
);
3067 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3069 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3071 cli_print(cli
, "%s (%u match%s)", r
,
3072 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3074 cli_print(cli
, "%s", r
);