1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.76 2006/12/18 12:08:28 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
);
103 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
104 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 static int regular_stuff(struct cli_def
*cli
);
110 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
111 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
112 #endif /* STATISTICS */
115 #define MODE_CONFIG_BGP 8
116 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
117 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
118 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
119 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
120 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
121 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
125 #define MODE_CONFIG_NACL 9
126 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
127 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
128 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
129 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
130 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
131 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
133 /* match if b is a substr of a */
134 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
136 void init_cli(char *hostname
)
140 struct cli_command
*c
;
141 struct cli_command
*c2
;
143 struct sockaddr_in addr
;
146 if (hostname
&& *hostname
)
147 cli_set_hostname(cli
, hostname
);
149 cli_set_hostname(cli
, "l2tpns");
151 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
152 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
154 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
156 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
157 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
158 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
159 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
160 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
161 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
162 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
163 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
164 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
165 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
166 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");
167 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
168 cli_register_command(cli
, c
, "access-list", cmd_show_access_list
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show named access-list");
170 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
171 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
172 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
175 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
177 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
178 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
181 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
182 cli_register_command(cli
, NULL
, "shutdown", cmd_shutdown
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Shutdown l2tpns daemon and exit");
183 cli_register_command(cli
, NULL
, "reload", cmd_reload
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Reload configuration");
185 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
186 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
187 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
189 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
190 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
191 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
192 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
195 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
196 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
199 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
200 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
201 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
202 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
203 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
206 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
207 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
209 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
210 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
212 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
213 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
215 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
217 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
218 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
221 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
222 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
223 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
224 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
226 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
227 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
229 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
230 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
232 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
234 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
235 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
237 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
238 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
240 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
241 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
242 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
244 // Enable regular processing
245 cli_regular(cli
, regular_stuff
);
247 if (!(f
= fopen(CLIUSERS
, "r")))
249 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
253 while (fgets(buf
, 4096, f
))
256 if (*buf
== '#') continue;
257 if ((p
= strchr(buf
, '\r'))) *p
= 0;
258 if ((p
= strchr(buf
, '\n'))) *p
= 0;
260 if (!(p
= strchr((char *)buf
, ':'))) continue;
262 if (!strcmp(buf
, "enable"))
264 cli_allow_enable(cli
, p
);
265 LOG(3, 0, 0, "Setting enable password\n");
269 cli_allow_user(cli
, buf
, p
);
270 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
276 memset(&addr
, 0, sizeof(addr
));
277 clifd
= socket(PF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
278 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
281 // Set cli fd as non-blocking
282 flags
= fcntl(clifd
, F_GETFL
, 0);
283 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
285 addr
.sin_family
= AF_INET
;
286 addr
.sin_addr
.s_addr
= config
->cli_bind_address
; /* defaults to INADDR_ANY */
287 addr
.sin_port
= htons(23);
288 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
290 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
296 void cli_do(int sockfd
)
298 int require_auth
= 1;
299 struct sockaddr_in addr
;
300 socklen_t l
= sizeof(addr
);
302 if (fork_and_close()) return;
303 if (getpeername(sockfd
, (struct sockaddr
*) &addr
, &l
) == 0)
305 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
306 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
307 fmtaddr(addr
.sin_addr
.s_addr
, 0));
310 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
314 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
315 if (!cli
->users
) /* paranoia */
317 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
323 /* no username/pass required */
328 debug_rb_tail
= ringbuffer
->tail
;
330 memset(&debug_flags
, 0, sizeof(debug_flags
));
331 debug_flags
.critical
= 1;
333 cli_loop(cli
, sockfd
);
336 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
337 fmtaddr(addr
.sin_addr
.s_addr
, 0));
342 static void cli_print_log(struct cli_def
*cli
, char *string
)
344 LOG(3, 0, 0, "%s\n", string
);
347 void cli_do_file(FILE *fh
)
349 LOG(3, 0, 0, "Reading configuration file\n");
350 cli_print_callback(cli
, cli_print_log
);
351 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
352 cli_print_callback(cli
, NULL
);
355 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
366 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
368 int v
= va_arg(ap
, int);
369 snprintf(buf
, sizeof(buf
), entry
, v
);
375 desc
= va_arg(ap
, char *);
377 cli_error(cli
, " %-20s %s", p
, desc
);
379 cli_error(cli
, " %s", p
);
381 entry
= desc
? va_arg(ap
, char *) : 0;
386 cli_error(cli
, " <cr>");
391 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
395 if (CLI_HELP_REQUESTED
)
396 return cli_arg_help(cli
, 1,
397 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
403 // Show individual session
404 for (i
= 0; i
< argc
; i
++)
406 unsigned int s
, b_in
, b_out
;
408 if (s
<= 0 || s
>= MAXSESSION
)
410 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
413 cli_print(cli
, "\r\nSession %d:", s
);
414 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
415 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
416 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
417 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
418 cli_print(cli
, "\tPPP Phase:\t%s", ppp_phase(session
[s
].ppp
.phase
));
419 switch (session
[s
].ppp
.phase
)
422 cli_print(cli
, "\t LCP state:\t%s", ppp_state(session
[s
].ppp
.lcp
));
427 cli_print(cli
, "\t IPCP state:\t%s", ppp_state(session
[s
].ppp
.ipcp
));
428 cli_print(cli
, "\t IPV6CP state:\t%s", ppp_state(session
[s
].ppp
.ipv6cp
));
429 cli_print(cli
, "\t CCP state:\t%s", ppp_state(session
[s
].ppp
.ccp
));
431 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
432 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
433 cli_print(cli
, "\tOpened:\t\t%u seconds", session
[s
].opened
? abs(time_now
- session
[s
].opened
) : 0);
434 cli_print(cli
, "\tIdle time:\t%u seconds", session
[s
].last_packet
? abs(time_now
- session
[s
].last_packet
) : 0);
435 if (session
[s
].session_timeout
)
437 clockt opened
= session
[s
].opened
;
438 if (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
439 opened
= bundle
[session
[s
].bundle
].online_time
;
441 cli_print(cli
, "\tSess Timeout:\t%u seconds", session
[s
].session_timeout
- (opened
? abs(time_now
- opened
) : 0));
444 if (session
[s
].idle_timeout
)
445 cli_print(cli
, "\tIdle Timeout:\t%u seconds", session
[s
].idle_timeout
- (session
[s
].last_data
? abs(time_now
- session
[s
].last_data
) : 0));
447 if (session
[s
].timeout
)
449 cli_print(cli
, "\tRemaining time:\t%u",
450 (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
451 ? (unsigned) (session
[s
].timeout
- bundle
[session
[s
].bundle
].online_time
)
452 : (unsigned) (session
[s
].timeout
- (time_now
- session
[s
].opened
)));
455 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
456 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
457 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
458 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
459 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
460 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
461 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
462 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
463 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
464 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
465 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
467 cli_print(cli
, "\tIntercepted:\tno");
469 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
471 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
472 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
473 t
? "YES" : "no", t
? " (" : "",
474 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
476 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
480 b_in
= session
[s
].tbf_in
;
481 b_out
= session
[s
].tbf_out
;
483 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
484 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
485 "ByteSent", "PackSent", "PackDrop", "PackDelay");
488 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
490 (filter_list
[b_in
].next
? "*" : " "),
491 (b_in
< 100 ? "\t" : ""),
492 filter_list
[b_in
].rate
* 8,
493 filter_list
[b_in
].credit
,
494 filter_list
[b_in
].queued
,
495 filter_list
[b_in
].b_queued
,
496 filter_list
[b_in
].p_queued
,
497 filter_list
[b_in
].b_sent
,
498 filter_list
[b_in
].p_sent
,
499 filter_list
[b_in
].p_dropped
,
500 filter_list
[b_in
].p_delayed
);
503 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
505 (filter_list
[b_out
].next
? "*" : " "),
506 (b_out
< 100 ? "\t" : ""),
507 filter_list
[b_out
].rate
* 8,
508 filter_list
[b_out
].credit
,
509 filter_list
[b_out
].queued
,
510 filter_list
[b_out
].b_queued
,
511 filter_list
[b_out
].p_queued
,
512 filter_list
[b_out
].b_sent
,
513 filter_list
[b_out
].p_sent
,
514 filter_list
[b_out
].p_dropped
,
515 filter_list
[b_out
].p_delayed
);
522 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s",
539 for (i
= 1; i
< MAXSESSION
; i
++)
542 if (!session
[i
].opened
) continue;
543 if (session
[i
].bundle
&& bundle
[session
[i
].bundle
].num_of_links
> 1)
544 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- bundle
[session
[i
].bundle
].online_time
) : 0;
546 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- (time_now
-session
[i
].opened
)) : 0;
548 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %-15s %s",
551 session
[i
].user
[0] ? session
[i
].user
: "*",
552 fmtaddr(htonl(session
[i
].ip
), 0),
553 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
554 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
555 (session
[i
].walled_garden
) ? "Y" : "N",
556 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
557 abs(time_now
- (unsigned long)session
[i
].opened
),
558 (unsigned long)session
[i
].cout
,
559 (unsigned long)session
[i
].cin
,
560 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
561 (unsigned long)(rem_time
),
562 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
563 session
[i
].calling
[0] ? session
[i
].calling
: "*");
568 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
570 int i
, x
, show_all
= 0;
578 if (CLI_HELP_REQUESTED
)
581 return cli_arg_help(cli
, 1,
582 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
585 return cli_arg_help(cli
, 1,
586 "all", "Show all tunnels, including unused",
587 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
594 if (strcmp(argv
[0], "all") == 0)
600 // Show individual tunnel
601 for (i
= 0; i
< argc
; i
++)
606 if (t
<= 0 || t
>= MAXTUNNEL
)
608 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
611 cli_print(cli
, "\r\nTunnel %d:", t
);
612 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
613 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
614 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
615 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
616 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
617 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
618 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
619 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
620 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
622 for (x
= 0; x
< MAXSESSION
; x
++)
623 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
624 sprintf(s
, "%s%u ", s
, x
);
626 cli_print(cli
, "\tSessions:\t%s", s
);
632 // Show tunnel summary
633 cli_print(cli
, "%4s %20s %20s %6s %s",
640 for (i
= 1; i
< MAXTUNNEL
; i
++)
643 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
645 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
646 cli_print(cli
, "%4d %20s %20s %6s %6d",
648 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
649 fmtaddr(htonl(tunnel
[i
].ip
), 0),
650 states
[tunnel
[i
].state
],
657 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
664 if (CLI_HELP_REQUESTED
)
665 return cli_arg_help(cli
, 1,
666 "USER", "Show details for specific username",
669 for (i
= 0; i
< MAXSESSION
; i
++)
671 if (!session
[i
].opened
) continue;
672 if (!session
[i
].user
[0]) continue;
676 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
678 if (strcmp(argv
[j
], session
[i
].user
) == 0)
680 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
681 sargv
[sargc
] = sid
[sargc
];
689 cli_print(cli
, "%s", session
[i
].user
);
693 return cmd_show_session(cli
, "users", sargv
, sargc
);
699 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
701 if (CLI_HELP_REQUESTED
)
702 return CLI_HELP_NO_ARGS
;
704 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
705 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
706 GET_STAT(tun_rx_bytes
),
707 GET_STAT(tun_rx_packets
),
708 GET_STAT(tun_rx_errors
),
709 GET_STAT(tun_rx_dropped
));
710 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
711 GET_STAT(tun_tx_bytes
),
712 GET_STAT(tun_tx_packets
),
713 GET_STAT(tun_tx_errors
));
716 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
717 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
718 GET_STAT(tunnel_rx_bytes
),
719 GET_STAT(tunnel_rx_packets
),
720 GET_STAT(tunnel_rx_errors
));
721 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
722 GET_STAT(tunnel_tx_bytes
),
723 GET_STAT(tunnel_tx_packets
),
724 GET_STAT(tunnel_tx_errors
),
725 GET_STAT(tunnel_retries
));
728 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
729 cli_print(cli
, "-----------------------------------------");
730 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
731 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
732 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
733 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
734 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
735 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
736 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
737 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
738 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
739 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
740 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
741 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
742 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
743 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
744 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
745 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
746 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
747 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
751 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
752 cli_print(cli
, "-----------------------------------------");
753 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
754 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
755 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
756 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
757 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
758 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
759 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
760 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
761 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
762 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
763 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
764 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
765 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
766 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
767 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
768 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
769 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
770 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
771 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
772 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
773 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
774 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
775 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
776 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
777 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
778 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
779 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
780 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
781 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
782 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
783 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
784 #endif /* STAT_CALLS */
787 time_t l
= GET_STAT(last_reset
);
789 char *p
= strchr(t
, '\n');
793 cli_print(cli
, "Last counter reset %s", t
);
799 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
801 if (CLI_HELP_REQUESTED
)
802 return CLI_HELP_NO_ARGS
;
804 memset(_statistics
, 0, sizeof(struct Tstats
));
805 SET_STAT(last_reset
, time(NULL
));
807 cli_print(cli
, "Counters cleared");
810 #endif /* STATISTICS */
812 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
818 if (CLI_HELP_REQUESTED
)
819 return cli_arg_help(cli
, 1,
820 "tag", "Include CVS release tag",
821 "file", "Include file versions",
824 for (i
= 0; i
< argc
; i
++)
825 if (!strcmp(argv
[i
], "tag"))
827 else if (!strcmp(argv
[i
], "file"))
830 cli_print(cli
, "L2TPNS %s", VERSION
);
833 char const *p
= strchr(cvs_name
, ':');
845 e
= strpbrk(p
, " \t$");
846 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
851 extern linked_list
*loaded_plugins
;
854 cli_print(cli
, "Files:");
855 cli_print(cli
, " %s", cvs_id_arp
);
857 cli_print(cli
, " %s", cvs_id_bgp
);
859 cli_print(cli
, " %s", cvs_id_cli
);
860 cli_print(cli
, " %s", cvs_id_cluster
);
861 cli_print(cli
, " %s", cvs_id_constants
);
862 cli_print(cli
, " %s", cvs_id_control
);
863 cli_print(cli
, " %s", cvs_id_icmp
);
864 cli_print(cli
, " %s", cvs_id_l2tpns
);
865 cli_print(cli
, " %s", cvs_id_ll
);
866 cli_print(cli
, " %s", cvs_id_ppp
);
867 cli_print(cli
, " %s", cvs_id_radius
);
868 cli_print(cli
, " %s", cvs_id_tbf
);
869 cli_print(cli
, " %s", cvs_id_util
);
871 ll_reset(loaded_plugins
);
872 while ((p
= ll_next(loaded_plugins
)))
874 char const **id
= dlsym(p
, "cvs_id");
876 cli_print(cli
, " %s", *id
);
883 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
886 int used
= 0, free
= 0, show_all
= 0;
888 if (!config
->cluster_iam_master
)
890 cli_print(cli
, "Can't do this on a slave. Do it on %s",
891 fmtaddr(config
->cluster_master_address
, 0));
896 if (CLI_HELP_REQUESTED
)
899 return cli_arg_help(cli
, 1, NULL
);
901 return cli_arg_help(cli
, 1,
902 "all", "Show all pool addresses, including unused",
906 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
910 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
911 for (i
= 0; i
< MAXIPPOOL
; i
++)
913 if (!ip_address_pool
[i
].address
) continue;
914 if (ip_address_pool
[i
].assigned
)
916 cli_print(cli
, "%-15s\tY %8d %s",
917 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
918 ip_address_pool
[i
].session
,
919 session
[ip_address_pool
[i
].session
].user
);
925 if (ip_address_pool
[i
].last
)
926 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
927 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
928 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
931 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
938 cli_print(cli
, "(Not displaying unused addresses)");
940 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
944 static FILE *save_config_fh
= 0;
945 static void print_save_config(struct cli_def
*cli
, char *string
)
948 fprintf(save_config_fh
, "%s\n", string
);
951 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
953 if (CLI_HELP_REQUESTED
)
954 return CLI_HELP_NO_ARGS
;
956 if ((save_config_fh
= fopen(config
->config_file
, "w")))
958 cli_print(cli
, "Writing configuration");
959 cli_print_callback(cli
, print_save_config
);
960 cmd_show_run(cli
, command
, argv
, argc
);
961 cli_print_callback(cli
, NULL
);
962 fclose(save_config_fh
);
967 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
972 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
974 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
977 char ipv6addr
[INET6_ADDRSTRLEN
];
979 if (CLI_HELP_REQUESTED
)
980 return CLI_HELP_NO_ARGS
;
982 cli_print(cli
, "# Current configuration:");
984 for (i
= 0; config_values
[i
].key
; i
++)
986 void *value
= ((void *)config
) + config_values
[i
].offset
;
987 if (config_values
[i
].type
== STRING
)
988 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
989 else if (config_values
[i
].type
== IPv4
)
990 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
991 else if (config_values
[i
].type
== IPv6
)
992 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
993 else if (config_values
[i
].type
== SHORT
)
994 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
995 else if (config_values
[i
].type
== BOOL
)
996 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
997 else if (config_values
[i
].type
== INT
)
998 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
999 else if (config_values
[i
].type
== UNSIGNED_LONG
)
1000 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
1003 cli_print(cli
, "# Plugins");
1004 for (i
= 0; i
< MAXPLUGINS
; i
++)
1006 if (*config
->plugins
[i
])
1008 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
1013 if (config
->as_number
)
1018 cli_print(cli
, "# BGP");
1019 cli_print(cli
, "router bgp %u", config
->as_number
);
1020 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1022 if (!config
->neighbour
[i
].name
[0])
1025 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1027 k
= config
->neighbour
[i
].keepalive
;
1028 h
= config
->neighbour
[i
].hold
;
1035 k
= BGP_KEEPALIVE_TIME
;
1041 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1043 if (config
->neighbour
[i
].update_source
.s_addr
!= INADDR_ANY
)
1044 cli_print(cli
, " neighbour %s update-source %s",
1045 config
->neighbour
[i
].name
,
1046 inet_ntoa(config
->neighbour
[i
].update_source
));
1051 cli_print(cli
, "# Filters");
1052 for (i
= 0; i
< MAXFILTER
; i
++)
1054 ip_filter_rulet
*rules
;
1055 if (!*ip_filters
[i
].name
)
1058 cli_print(cli
, "ip access-list %s %s",
1059 ip_filters
[i
].extended
? "extended" : "standard",
1060 ip_filters
[i
].name
);
1062 rules
= ip_filters
[i
].rules
;
1063 while (rules
->action
)
1064 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1067 cli_print(cli
, "# end");
1071 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1073 int i
, free
= 0, used
= 0, show_all
= 0;
1085 if (CLI_HELP_REQUESTED
)
1088 return cli_arg_help(cli
, 1, NULL
);
1090 return cli_arg_help(cli
, 1,
1091 "all", "Show all RADIUS sessions, including unused",
1095 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1099 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1102 for (i
= 1; i
< MAXRADIUS
; i
++)
1104 if (radius
[i
].state
== RADIUSNULL
)
1109 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1111 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1115 states
[radius
[i
].state
],
1121 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1126 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1130 if (CLI_HELP_REQUESTED
)
1131 return CLI_HELP_NO_ARGS
;
1133 cli_print(cli
, "Plugins currently loaded:");
1134 for (i
= 0; i
< MAXPLUGINS
; i
++)
1135 if (*config
->plugins
[i
])
1136 cli_print(cli
, " %s", config
->plugins
[i
]);
1141 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1145 if (CLI_HELP_REQUESTED
)
1146 return CLI_HELP_NO_ARGS
;
1148 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1157 for (i
= 0; i
< MAXSESSION
; i
++)
1159 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1160 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1164 session
[i
].throttle_in
,
1165 session
[i
].throttle_out
,
1167 session
[i
].tbf_out
);
1173 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1175 if (CLI_HELP_REQUESTED
)
1176 return CLI_HELP_NO_ARGS
;
1178 cli_print(cli
, " _\n"
1184 " ( \\ `. `-. _,.-:\\\n"
1185 " \\ \\ `. `-._ __..--' ,-';/\n"
1186 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1187 " `. `. `-._ __..--' ,' /\n"
1188 " `. `-_ ``--..'' _.-' ,'\n"
1189 " `-_ `-.___ __,--' ,'\n"
1190 " `-.__ `----\"\"\" __.-'\n"
1191 "hh `--..____..--'");
1196 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1201 if (CLI_HELP_REQUESTED
)
1202 return cli_arg_help(cli
, argc
> 1,
1203 "USER", "Username of session to drop", NULL
);
1205 if (!config
->cluster_iam_master
)
1207 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1208 fmtaddr(config
->cluster_master_address
, 0));
1215 cli_error(cli
, "Specify a user to drop");
1219 for (i
= 0; i
< argc
; i
++)
1221 if (!(s
= sessionbyuser(argv
[i
])))
1223 cli_error(cli
, "User %s is not connected", argv
[i
]);
1227 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1229 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1230 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1237 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1242 if (CLI_HELP_REQUESTED
)
1243 return cli_arg_help(cli
, argc
> 1,
1244 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1246 if (!config
->cluster_iam_master
)
1248 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1249 fmtaddr(config
->cluster_master_address
, 0));
1256 cli_error(cli
, "Specify a tunnel to drop");
1260 for (i
= 0; i
< argc
; i
++)
1262 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1264 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1270 cli_error(cli
, "Tunnel %d is not connected", t
);
1276 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1280 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1281 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1287 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1292 if (CLI_HELP_REQUESTED
)
1293 return cli_arg_help(cli
, argc
> 1,
1294 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1296 if (!config
->cluster_iam_master
)
1298 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1299 fmtaddr(config
->cluster_master_address
, 0));
1306 cli_error(cli
, "Specify a session id to drop");
1310 for (i
= 0; i
< argc
; i
++)
1312 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1314 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1318 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1320 cli_print(cli
, "Dropping session %d", s
);
1321 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1325 cli_error(cli
, "Session %d is not active.", s
);
1332 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1338 if (CLI_HELP_REQUESTED
)
1343 return cli_arg_help(cli
, 0,
1344 "USER", "Username of session to snoop", NULL
);
1347 return cli_arg_help(cli
, 0,
1348 "A.B.C.D", "IP address of snoop destination", NULL
);
1351 return cli_arg_help(cli
, 0,
1352 "N", "Port of snoop destination", NULL
);
1356 return cli_arg_help(cli
, 1, NULL
);
1363 if (!config
->cluster_iam_master
)
1365 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1366 fmtaddr(config
->cluster_master_address
, 0));
1373 cli_error(cli
, "Specify username, ip and port");
1377 if (!(s
= sessionbyuser(argv
[0])))
1379 cli_error(cli
, "User %s is not connected", argv
[0]);
1383 ip
= inet_addr(argv
[1]);
1384 if (!ip
|| ip
== INADDR_NONE
)
1386 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1390 port
= atoi(argv
[2]);
1393 cli_error(cli
, "Invalid port %s", argv
[2]);
1397 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1398 cli_session_actions
[s
].snoop_ip
= ip
;
1399 cli_session_actions
[s
].snoop_port
= port
;
1400 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1405 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1410 if (CLI_HELP_REQUESTED
)
1411 return cli_arg_help(cli
, argc
> 1,
1412 "USER", "Username of session to unsnoop", NULL
);
1414 if (!config
->cluster_iam_master
)
1416 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1417 fmtaddr(config
->cluster_master_address
, 0));
1424 cli_error(cli
, "Specify a user to unsnoop");
1428 for (i
= 0; i
< argc
; i
++)
1430 if (!(s
= sessionbyuser(argv
[i
])))
1432 cli_error(cli
, "User %s is not connected", argv
[i
]);
1436 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1437 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1443 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1450 throttle USER - throttle in/out to default rate
1451 throttle USER RATE - throttle in/out to default rate
1452 throttle USER in RATE - throttle input only
1453 throttle USER out RATE - throttle output only
1454 throttle USER in RATE out RATE - throttle both
1457 if (CLI_HELP_REQUESTED
)
1462 return cli_arg_help(cli
, 0,
1463 "USER", "Username of session to throttle", NULL
);
1466 return cli_arg_help(cli
, 1,
1467 "RATE", "Rate in kbps (in and out)",
1468 "in", "Select incoming rate",
1469 "out", "Select outgoing rate", NULL
);
1472 return cli_arg_help(cli
, 1,
1473 "in", "Select incoming rate",
1474 "out", "Select outgoing rate", NULL
);
1477 if (isdigit(argv
[1][0]))
1478 return cli_arg_help(cli
, 1, NULL
);
1481 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1484 return cli_arg_help(cli
, argc
> 1, NULL
);
1488 if (!config
->cluster_iam_master
)
1490 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1491 fmtaddr(config
->cluster_master_address
, 0));
1498 cli_error(cli
, "Specify a user to throttle");
1502 if (!(s
= sessionbyuser(argv
[0])))
1504 cli_error(cli
, "User %s is not connected", argv
[0]);
1510 rate_in
= rate_out
= config
->rl_rate
;
1514 rate_in
= rate_out
= atoi(argv
[1]);
1517 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1521 else if (argc
== 3 || argc
== 5)
1524 for (i
= 1; i
< argc
- 1; i
+= 2)
1527 if (MATCH("in", argv
[i
]))
1528 r
= rate_in
= atoi(argv
[i
+1]);
1529 else if (MATCH("out", argv
[i
]))
1530 r
= rate_out
= atoi(argv
[i
+1]);
1534 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1541 cli_error(cli
, "Invalid arguments");
1545 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1547 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1551 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1552 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1553 cli_session_actions
[s
].throttle_in
= rate_in
;
1555 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1556 cli_session_actions
[s
].throttle_out
= rate_out
;
1558 if (cli_session_actions
[s
].throttle_in
== -1 &&
1559 cli_session_actions
[s
].throttle_out
== -1)
1561 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1565 cli_print(cli
, "Throttling user %s", argv
[0]);
1566 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1571 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1576 if (CLI_HELP_REQUESTED
)
1577 return cli_arg_help(cli
, argc
> 1,
1578 "USER", "Username of session to unthrottle", NULL
);
1580 if (!config
->cluster_iam_master
)
1582 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1583 fmtaddr(config
->cluster_master_address
, 0));
1590 cli_error(cli
, "Specify a user to unthrottle");
1594 for (i
= 0; i
< argc
; i
++)
1596 if (!(s
= sessionbyuser(argv
[i
])))
1598 cli_error(cli
, "User %s is not connected", argv
[i
]);
1602 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1604 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1605 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1609 cli_error(cli
, "User %s not throttled", argv
[i
]);
1616 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1620 if (CLI_HELP_REQUESTED
)
1621 return cli_arg_help(cli
, 1,
1622 "all", "Enable debugging for all except \"data\"",
1623 "critical", "", // FIXME: add descriptions
1633 char *p
= (char *) &debug_flags
;
1634 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1638 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1639 (debug_flags
.critical
) ? " critical" : "",
1640 (debug_flags
.error
) ? " error" : "",
1641 (debug_flags
.warning
) ? " warning" : "",
1642 (debug_flags
.info
) ? " info" : "",
1643 (debug_flags
.calls
) ? " calls" : "",
1644 (debug_flags
.data
) ? " data" : "");
1650 cli_print(cli
, "Debugging off");
1654 for (i
= 0; i
< argc
; i
++)
1656 int len
= strlen(argv
[i
]);
1658 if (argv
[i
][0] == 'c' && len
< 2)
1659 len
= 2; /* distinguish [cr]itical from [ca]lls */
1661 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1662 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1663 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1664 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1665 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1666 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1667 if (!strncmp("all", argv
[i
], len
))
1669 memset(&debug_flags
, 1, sizeof(debug_flags
));
1670 debug_flags
.data
= 0;
1674 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1680 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1684 if (CLI_HELP_REQUESTED
)
1685 return cli_arg_help(cli
, 1,
1686 "all", "Disable all debugging",
1687 "critical", "", // FIXME: add descriptions
1697 memset(&debug_flags
, 0, sizeof(debug_flags
));
1701 for (i
= 0; i
< argc
; i
++)
1703 int len
= strlen(argv
[i
]);
1705 if (argv
[i
][0] == 'c' && len
< 2)
1706 len
= 2; /* distinguish [cr]itical from [ca]lls */
1708 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1709 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1710 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1711 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1712 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1713 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1714 if (!strncmp("all", argv
[i
], len
))
1716 memset(&debug_flags
, 0, sizeof(debug_flags
));
1720 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1726 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1728 int i
, firstfree
= 0;
1730 if (CLI_HELP_REQUESTED
)
1731 return cli_arg_help(cli
, argc
> 1,
1732 "PLUGIN", "Name of plugin to load", NULL
);
1736 cli_error(cli
, "Specify a plugin to load");
1740 for (i
= 0; i
< MAXPLUGINS
; i
++)
1742 if (!*config
->plugins
[i
] && !firstfree
)
1744 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1746 cli_error(cli
, "Plugin is already loaded");
1753 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1754 config
->reload_config
= 1;
1755 cli_print(cli
, "Loading plugin %s", argv
[0]);
1761 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1765 if (CLI_HELP_REQUESTED
)
1766 return cli_arg_help(cli
, argc
> 1,
1767 "PLUGIN", "Name of plugin to unload", NULL
);
1771 cli_error(cli
, "Specify a plugin to remove");
1775 for (i
= 0; i
< MAXPLUGINS
; i
++)
1777 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1779 config
->reload_config
= 1;
1780 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1785 cli_error(cli
, "Plugin is not loaded");
1789 static char *duration(time_t secs
)
1791 static char *buf
= NULL
;
1794 if (!buf
) buf
= calloc(64, 1);
1798 int days
= secs
/ 86400;
1799 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1805 int mins
= secs
/ 60;
1806 int hrs
= mins
/ 60;
1809 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1811 else if (secs
>= 60)
1813 int mins
= secs
/ 60;
1814 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1817 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1822 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1825 char buf
[100], *p
= buf
, *loads
[3];
1826 int i
, num_sessions
= 0;
1828 if (CLI_HELP_REQUESTED
)
1829 return CLI_HELP_NO_ARGS
;
1831 fh
= fopen("/proc/loadavg", "r");
1832 fgets(buf
, 100, fh
);
1835 for (i
= 0; i
< 3; i
++)
1836 loads
[i
] = strdup(strsep(&p
, " "));
1839 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1841 for (i
= 1; i
< MAXSESSION
; i
++)
1842 if (session
[i
].opened
) num_sessions
++;
1844 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1846 duration(time_now
- config
->start_time
),
1848 loads
[0], loads
[1], loads
[2]
1850 for (i
= 0; i
< 3; i
++)
1851 if (loads
[i
]) free(loads
[i
]);
1853 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1858 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1862 if (CLI_HELP_REQUESTED
)
1868 int len
= strlen(argv
[0])-1;
1869 for (i
= 0; config_values
[i
].key
; i
++)
1870 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1871 cli_error(cli
, " %s", config_values
[i
].key
);
1877 return cli_arg_help(cli
, 0,
1878 "VALUE", "Value for variable", NULL
);
1882 return cli_arg_help(cli
, 1, NULL
);
1891 cli_error(cli
, "Specify variable and value");
1895 for (i
= 0; config_values
[i
].key
; i
++)
1897 void *value
= ((void *) config
) + config_values
[i
].offset
;
1898 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1900 // Found a value to set
1901 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1902 switch (config_values
[i
].type
)
1905 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1908 *(int *) value
= atoi(argv
[1]);
1911 *(unsigned long *) value
= atol(argv
[1]);
1914 *(short *) value
= atoi(argv
[1]);
1917 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1920 inet_pton(AF_INET6
, argv
[1], value
);
1923 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1929 cli_error(cli
, "Unknown variable type");
1932 config
->reload_config
= 1;
1937 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1941 int regular_stuff(struct cli_def
*cli
)
1947 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1949 char *m
= ringbuffer
->buffer
[i
].message
;
1955 switch (ringbuffer
->buffer
[i
].level
)
1957 case 0: show
= debug_flags
.critical
; break;
1958 case 1: show
= debug_flags
.error
; break;
1959 case 2: show
= debug_flags
.warning
; break;
1960 case 3: show
= debug_flags
.info
; break;
1961 case 4: show
= debug_flags
.calls
; break;
1962 case 5: show
= debug_flags
.data
; break;
1965 if (!show
) continue;
1967 if (!(p
= strchr(m
, '\n')))
1970 cli_error(cli
, "\r%s-%u-%u %.*s",
1971 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1972 ringbuffer
->buffer
[i
].tunnel
,
1973 ringbuffer
->buffer
[i
].session
,
1979 debug_rb_tail
= ringbuffer
->tail
;
1987 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1991 if (CLI_HELP_REQUESTED
)
1992 return cli_arg_help(cli
, argc
> 1,
1993 "<1-65535>", "Autonomous system number", NULL
);
1995 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1997 cli_error(cli
, "Invalid autonomous system number");
2001 if (bgp_configured
&& as
!= config
->as_number
)
2003 cli_error(cli
, "Can't change local AS on a running system");
2007 config
->as_number
= as
;
2008 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
2013 static int find_bgp_neighbour(char const *name
)
2018 in_addr_t addrs
[4] = { 0 };
2021 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2024 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2025 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2027 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2029 if (!config
->neighbour
[i
].name
[0])
2031 if (new == -1) new = i
;
2035 if (!strcmp(name
, config
->neighbour
[i
].name
))
2038 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2041 for (a
= h
->h_addr_list
; *a
; a
++)
2044 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2045 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2053 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2059 if (CLI_HELP_REQUESTED
)
2064 return cli_arg_help(cli
, 0,
2065 "A.B.C.D", "BGP neighbour address",
2066 "NAME", "BGP neighbour name",
2070 return cli_arg_help(cli
, 0,
2071 "remote-as", "Set remote autonomous system number",
2072 "timers", "Set timers",
2073 "update-source", "Set source address to use for the BGP session",
2077 if (MATCH("remote-as", argv
[1]))
2078 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2080 if (MATCH("timers", argv
[1]))
2083 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2086 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2088 if (argc
== 5 && !argv
[4][1])
2089 return cli_arg_help(cli
, 1, NULL
);
2092 if (MATCH("update-source", argv
[1]))
2093 return cli_arg_help(cli
, argc
> 3, "A.B.C.D", "Source IP address", NULL
);
2101 cli_error(cli
, "Invalid arguments");
2105 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2107 cli_error(cli
, "Invalid neighbour");
2113 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2117 if (MATCH("remote-as", argv
[1]))
2119 int as
= atoi(argv
[2]);
2120 if (as
< 0 || as
> 65535)
2122 cli_error(cli
, "Invalid autonomous system number");
2126 if (!config
->neighbour
[i
].name
[0])
2128 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2129 config
->neighbour
[i
].keepalive
= -1;
2130 config
->neighbour
[i
].hold
= -1;
2131 config
->neighbour
[i
].update_source
.s_addr
= INADDR_ANY
;
2134 config
->neighbour
[i
].as
= as
;
2138 if (MATCH("update-source", argv
[1]))
2140 struct in_addr addr
;
2142 if (!config
->neighbour
[i
].name
[0])
2144 cli_error(cli
, "Specify remote-as first");
2148 if (!inet_aton(argv
[2], &addr
))
2150 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[2]);
2154 config
->neighbour
[i
].update_source
= addr
;
2158 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2160 cli_error(cli
, "Invalid arguments");
2164 if (!config
->neighbour
[i
].name
[0])
2166 cli_error(cli
, "Specify remote-as first");
2170 keepalive
= atoi(argv
[2]);
2171 hold
= atoi(argv
[3]);
2173 if (keepalive
< 1 || keepalive
> 65535)
2175 cli_error(cli
, "Invalid keepalive time");
2179 if (hold
< 3 || hold
> 65535)
2181 cli_error(cli
, "Invalid hold time");
2185 if (keepalive
== BGP_KEEPALIVE_TIME
)
2186 keepalive
= -1; // using default value
2188 if (hold
== BGP_HOLD_TIME
)
2191 config
->neighbour
[i
].keepalive
= keepalive
;
2192 config
->neighbour
[i
].hold
= hold
;
2197 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2201 if (CLI_HELP_REQUESTED
)
2202 return cli_arg_help(cli
, argc
> 0,
2203 "A.B.C.D", "BGP neighbour address",
2204 "NAME", "BGP neighbour name",
2209 cli_error(cli
, "Specify a BGP neighbour");
2213 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2215 cli_error(cli
, "Invalid neighbour");
2219 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2221 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2225 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2229 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2235 if (!bgp_configured
)
2238 if (CLI_HELP_REQUESTED
)
2239 return cli_arg_help(cli
, 1,
2240 "A.B.C.D", "BGP neighbour address",
2241 "NAME", "BGP neighbour name",
2244 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2245 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2249 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2251 if (!*bgp_peers
[i
].name
)
2254 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2255 if (argc
&& strcmp(addr
, argv
[0]) &&
2256 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2262 cli_print(cli
, "Peer AS Address "
2263 "State Retries Retry in Route Pend Timers");
2264 cli_print(cli
, "------------------ ----- --------------- "
2265 "----------- ------- -------- ----- ---- ---------");
2268 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2272 bgp_state_str(bgp_peers
[i
].state
),
2273 bgp_peers
[i
].retry_count
,
2274 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2275 bgp_peers
[i
].routing
? "yes" : "no",
2276 bgp_peers
[i
].update_routes
? "yes" : "no",
2277 bgp_peers
[i
].keepalive
,
2284 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2289 if (!bgp_configured
)
2292 if (CLI_HELP_REQUESTED
)
2293 return cli_arg_help(cli
, 1,
2294 "A.B.C.D", "BGP neighbour address",
2295 "NAME", "BGP neighbour name",
2298 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2300 if (bgp_peers
[i
].state
!= Established
)
2303 if (!bgp_peers
[i
].routing
)
2306 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2307 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2310 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2311 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2317 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2322 if (!bgp_configured
)
2325 if (CLI_HELP_REQUESTED
)
2326 return cli_arg_help(cli
, 1,
2327 "A.B.C.D", "BGP neighbour address",
2328 "NAME", "BGP neighbour name",
2331 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2333 if (bgp_peers
[i
].state
!= Established
)
2336 if (bgp_peers
[i
].routing
)
2339 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2340 if (argc
&& strcmp(addr
, argv
[0]) &&
2341 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2344 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2345 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2351 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2356 if (!bgp_configured
)
2359 if (CLI_HELP_REQUESTED
)
2360 return cli_arg_help(cli
, 1,
2361 "A.B.C.D", "BGP neighbour address",
2362 "NAME", "BGP neighbour name",
2365 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2367 if (!*bgp_peers
[i
].name
)
2370 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2371 if (argc
&& strcmp(addr
, argv
[0]) &&
2372 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2375 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2376 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2384 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2388 if (CLI_HELP_REQUESTED
)
2393 return cli_arg_help(cli
, 0,
2394 "standard", "Standard syntax",
2395 "extended", "Extended syntax",
2399 return cli_arg_help(cli
, argv
[1][1],
2400 "NAME", "Access-list name",
2404 if (argc
== 3 && !argv
[2][1])
2405 return cli_arg_help(cli
, 1, NULL
);
2413 cli_error(cli
, "Specify access-list type and name");
2417 if (MATCH("standard", argv
[0]))
2419 else if (MATCH("extended", argv
[0]))
2423 cli_error(cli
, "Invalid access-list type");
2427 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2428 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2430 cli_error(cli
, "Invalid access-list name");
2434 filt
= find_filter(argv
[1], strlen(argv
[1]));
2439 cli_error(cli
, "Too many access-lists");
2444 if (!*ip_filters
[filt
].name
)
2446 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2447 strcpy(ip_filters
[filt
].name
, argv
[1]);
2448 ip_filters
[filt
].extended
= extended
;
2450 else if (ip_filters
[filt
].extended
!= extended
)
2452 cli_error(cli
, "Access-list is %s",
2453 ip_filters
[filt
].extended
? "extended" : "standard");
2458 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2462 if (filt
< 0 || !*ip_filters
[filt
].name
)
2464 cli_error(cli
, "Access-list not defined");
2469 if (ip_filters
[filt
].used
)
2471 cli_error(cli
, "Access-list in use");
2475 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2479 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2481 return access_list(cli
, argv
, argc
, 1);
2484 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2486 return access_list(cli
, argv
, argc
, 0);
2489 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2491 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2492 return sprintf(buf
, " any");
2494 if (wild
== INADDR_ANY
)
2495 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2497 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2500 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2504 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2505 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2506 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2507 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2508 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2514 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2516 static char buf
[256];
2519 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2522 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2523 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2526 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2530 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2531 p
+= show_ports(p
, &rule
->src_ports
);
2533 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2534 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2535 p
+= show_ports(p
, &rule
->dst_ports
);
2537 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2539 switch (rule
->tcp_flag_op
)
2541 case FILTER_FLAG_OP_EST
:
2542 p
+= sprintf(p
, " established");
2545 case FILTER_FLAG_OP_ANY
:
2546 case FILTER_FLAG_OP_ALL
:
2547 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2548 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2549 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2550 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2551 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2552 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2553 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2554 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2555 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2556 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2557 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2558 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2559 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2565 p
+= sprintf(p
, " fragments");
2570 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2572 static ip_filter_rulet rule
;
2573 struct in_addr addr
;
2577 if (CLI_HELP_REQUESTED
)
2581 cli_arg_help(cli
, 0,
2582 "ip", "Match IP packets",
2583 "tcp", "Match TCP packets",
2584 "udp", "Match UDP packets",
2590 // *sigh*, too darned complex
2591 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2597 cli_error(cli
, "Specify rule details");
2601 memset(&rule
, 0, sizeof(rule
));
2602 rule
.action
= (command
[0] == 'p')
2603 ? FILTER_ACTION_PERMIT
2604 : FILTER_ACTION_DENY
;
2606 if (MATCH("ip", argv
[0]))
2607 rule
.proto
= IPPROTO_IP
;
2608 else if (MATCH("udp", argv
[0]))
2609 rule
.proto
= IPPROTO_UDP
;
2610 else if (MATCH("tcp", argv
[0]))
2611 rule
.proto
= IPPROTO_TCP
;
2614 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2618 for (a
= 1, i
= 0; i
< 2; i
++)
2622 ip_filter_portt
*port
;
2627 wild
= &rule
.src_wild
;
2628 port
= &rule
.src_ports
;
2633 wild
= &rule
.dst_wild
;
2634 port
= &rule
.dst_ports
;
2637 cli_error(cli
, "Specify destination");
2642 if (MATCH("any", argv
[a
]))
2645 *wild
= INADDR_BROADCAST
;
2648 else if (MATCH("host", argv
[a
]))
2652 cli_error(cli
, "Specify host ip address");
2656 if (!inet_aton(argv
[a
], &addr
))
2658 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2670 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2674 if (!inet_aton(argv
[a
], &addr
))
2676 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2682 if (!inet_aton(argv
[++a
], &addr
))
2684 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2688 *wild
= addr
.s_addr
;
2692 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2696 if (MATCH("eq", argv
[a
]))
2697 port
->op
= FILTER_PORT_OP_EQ
;
2698 else if (MATCH("neq", argv
[a
]))
2699 port
->op
= FILTER_PORT_OP_NEQ
;
2700 else if (MATCH("gt", argv
[a
]))
2701 port
->op
= FILTER_PORT_OP_GT
;
2702 else if (MATCH("lt", argv
[a
]))
2703 port
->op
= FILTER_PORT_OP_LT
;
2704 else if (MATCH("range", argv
[a
]))
2705 port
->op
= FILTER_PORT_OP_RANGE
;
2712 cli_error(cli
, "Specify port");
2716 if (!(port
->port
= atoi(argv
[a
])))
2718 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2723 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2728 cli_error(cli
, "Specify port");
2732 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2734 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2741 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2743 if (MATCH("established", argv
[a
]))
2745 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2748 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2749 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2751 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2752 ? FILTER_FLAG_OP_ANY
2753 : FILTER_FLAG_OP_ALL
;
2757 cli_error(cli
, "Specify tcp flags");
2761 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2765 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2767 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2768 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2769 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2770 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2771 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2772 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2775 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2784 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2786 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2788 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2798 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2805 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2807 static ip_filter_rulet rule
;
2808 struct in_addr addr
;
2810 if (CLI_HELP_REQUESTED
)
2814 cli_arg_help(cli
, argv
[0][1],
2815 "A.B.C.D", "Source address",
2816 "any", "Any source address",
2817 "host", "Source host",
2823 if (MATCH("any", argv
[0]))
2825 if (argc
== 2 && !argv
[1][1])
2826 cli_arg_help(cli
, 1, NULL
);
2828 else if (MATCH("host", argv
[0]))
2832 cli_arg_help(cli
, argv
[1][1],
2833 "A.B.C.D", "Host address",
2836 else if (argc
== 3 && !argv
[2][1])
2837 cli_arg_help(cli
, 1, NULL
);
2843 cli_arg_help(cli
, 1,
2844 "A.B.C.D", "Wildcard bits",
2847 else if (argc
== 3 && !argv
[2][1])
2848 cli_arg_help(cli
, 1, NULL
);
2856 cli_error(cli
, "Specify rule details");
2860 memset(&rule
, 0, sizeof(rule
));
2861 rule
.action
= (command
[0] == 'p')
2862 ? FILTER_ACTION_PERMIT
2863 : FILTER_ACTION_DENY
;
2865 rule
.proto
= IPPROTO_IP
;
2866 if (MATCH("any", argv
[0]))
2868 rule
.src_ip
= INADDR_ANY
;
2869 rule
.src_wild
= INADDR_BROADCAST
;
2871 else if (MATCH("host", argv
[0]))
2875 cli_error(cli
, "Specify host ip address");
2879 if (!inet_aton(argv
[1], &addr
))
2881 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2885 rule
.src_ip
= addr
.s_addr
;
2886 rule
.src_wild
= INADDR_ANY
;
2892 cli_error(cli
, "Specify source ip address and wildcard");
2896 if (!inet_aton(argv
[0], &addr
))
2898 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2902 rule
.src_ip
= addr
.s_addr
;
2906 if (!inet_aton(argv
[1], &addr
))
2908 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2912 rule
.src_wild
= addr
.s_addr
;
2915 rule
.src_wild
= INADDR_ANY
;
2921 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2924 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2925 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2926 : access_list_rule_std(cli
, command
, argv
, argc
);
2931 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2933 if (!ip_filters
[filt
].rules
[i
].action
)
2935 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2939 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2943 cli_error(cli
, "Too many rules");
2947 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2952 /* filter USER {in|out} FILTER ... */
2953 if (CLI_HELP_REQUESTED
)
2958 return cli_arg_help(cli
, 0,
2959 "USER", "Username of session to filter", NULL
);
2963 return cli_arg_help(cli
, 0,
2964 "in", "Set incoming filter",
2965 "out", "Set outgoing filter", NULL
);
2969 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2970 "NAME", "Filter name", NULL
);
2973 return cli_arg_help(cli
, argc
> 1, NULL
);
2977 if (!config
->cluster_iam_master
)
2979 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2980 fmtaddr(config
->cluster_master_address
, 0));
2985 if (argc
!= 3 && argc
!= 5)
2987 cli_error(cli
, "Specify a user and filters");
2991 if (!(s
= sessionbyuser(argv
[0])))
2993 cli_error(cli
, "User %s is not connected", argv
[0]);
2997 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2998 for (i
= 1; i
< argc
; i
+= 2)
3003 if (MATCH("in", argv
[i
]))
3005 if (session
[s
].filter_in
)
3007 cli_error(cli
, "Input already filtered");
3010 f
= &cli_session_actions
[s
].filter_in
;
3012 else if (MATCH("out", argv
[i
]))
3014 if (session
[s
].filter_out
)
3016 cli_error(cli
, "Output already filtered");
3019 f
= &cli_session_actions
[s
].filter_out
;
3023 cli_error(cli
, "Invalid filter specification");
3027 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
3028 if (v
< 0 || !*ip_filters
[v
].name
)
3030 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
3037 cli_print(cli
, "Filtering user %s", argv
[0]);
3038 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
3043 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3048 if (CLI_HELP_REQUESTED
)
3049 return cli_arg_help(cli
, argc
> 1,
3050 "USER", "Username of session to remove filters from", NULL
);
3052 if (!config
->cluster_iam_master
)
3054 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3055 fmtaddr(config
->cluster_master_address
, 0));
3062 cli_error(cli
, "Specify a user to remove filters from");
3066 for (i
= 0; i
< argc
; i
++)
3068 if (!(s
= sessionbyuser(argv
[i
])))
3070 cli_error(cli
, "User %s is not connected", argv
[i
]);
3074 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3076 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3077 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3081 cli_error(cli
, "User %s not filtered", argv
[i
]);
3088 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3092 if (CLI_HELP_REQUESTED
)
3093 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3097 cli_error(cli
, "Specify a filter name");
3101 for (i
= 0; i
< argc
; i
++)
3103 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3104 ip_filter_rulet
*rules
;
3106 if (f
< 0 || !*ip_filters
[f
].name
)
3108 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3115 cli_print(cli
, "%s IP access list %s",
3116 ip_filters
[f
].extended
? "Extended" : "Standard",
3117 ip_filters
[f
].name
);
3119 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3121 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3123 cli_print(cli
, "%s (%u match%s)", r
,
3124 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3126 cli_print(cli
, "%s", r
);
3133 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3135 if (CLI_HELP_REQUESTED
)
3136 return CLI_HELP_NO_ARGS
;
3138 kill(getppid(), SIGQUIT
);
3142 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3144 if (CLI_HELP_REQUESTED
)
3145 return CLI_HELP_NO_ARGS
;
3147 kill(getppid(), SIGHUP
);