1 // L2TPNS Command Line Interface
16 #include <arpa/inet.h>
18 #include <sys/socket.h>
19 #include <sys/types.h>
24 #include <linux/rtnetlink.h>
27 #include "constants.h"
39 extern tunnelt
*tunnel
;
40 extern bundlet
*bundle
;
41 extern sessiont
*session
;
42 extern radiust
*radius
;
43 extern ippoolt
*ip_address_pool
;
44 extern struct Tstats
*_statistics
;
45 static struct cli_def
*cli
= NULL
;
46 extern configt
*config
;
47 extern config_descriptt config_values
[];
49 extern struct Tringbuffer
*ringbuffer
;
51 extern struct cli_session_actions
*cli_session_actions
;
52 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
53 extern tbft
*filter_list
;
54 extern ip_filtert
*ip_filters
;
68 static int debug_rb_tail
;
69 static char *debug_levels
[] = {
80 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
100 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
101 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
102 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
103 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
104 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
105 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
107 static int cmd_setforward(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
108 static int cmd_show_rmtlnsconf(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
111 static int regular_stuff(struct cli_def
*cli
);
114 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
115 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
116 #endif /* STATISTICS */
119 #define MODE_CONFIG_BGP 8
120 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
121 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
123 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
124 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
125 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
126 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
129 #define MODE_CONFIG_NACL 9
130 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
131 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
132 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
133 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
134 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
135 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
137 /* match if b is a substr of a */
138 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
144 struct cli_command
*c
;
145 struct cli_command
*c2
;
149 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
150 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
152 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
154 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
155 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
156 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
157 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
158 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
159 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
161 cli_register_command(cli
, c
, "remotelns-conf", cmd_show_rmtlnsconf
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show a list of remote LNS configuration");
163 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
164 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
165 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
166 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
167 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");
168 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
169 cli_register_command(cli
, c
, "access-list", cmd_show_access_list
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show named access-list");
171 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
172 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
173 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
176 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
178 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
179 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
182 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
183 cli_register_command(cli
, NULL
, "shutdown", cmd_shutdown
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Shutdown l2tpns daemon and exit");
184 cli_register_command(cli
, NULL
, "reload", cmd_reload
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Reload configuration");
186 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
187 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
188 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
190 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
191 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
192 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
193 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
196 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
197 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
200 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
201 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
202 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
203 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
204 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
207 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
208 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
210 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
211 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
213 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
214 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
216 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
218 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
219 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
222 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
223 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
224 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
225 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
227 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
228 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
230 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
231 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
233 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
236 cli_register_command(cli
, NULL
, "setforward", cmd_setforward
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set the Remote LNS Forward");
239 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
240 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
242 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
243 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
245 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
246 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
247 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
249 // Enable regular processing
250 cli_regular(cli
, regular_stuff
);
252 if (!(f
= fopen(CLIUSERS
, "r")))
254 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
258 while (fgets(buf
, 4096, f
))
261 if (*buf
== '#') continue;
262 if ((p
= strchr(buf
, '\r'))) *p
= 0;
263 if ((p
= strchr(buf
, '\n'))) *p
= 0;
265 if (!(p
= strchr((char *)buf
, ':'))) continue;
267 if (!strcmp(buf
, "enable"))
269 cli_allow_enable(cli
, p
);
270 LOG(3, 0, 0, "Setting enable password\n");
274 cli_allow_user(cli
, buf
, p
);
275 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
282 void cli_init_complete(char *hostname
)
285 struct sockaddr_in addr
;
287 if (hostname
&& *hostname
)
288 cli_set_hostname(cli
, hostname
);
290 cli_set_hostname(cli
, "l2tpns");
292 memset(&addr
, 0, sizeof(addr
));
293 clifd
= socket(PF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
294 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
297 // Set cli fd as non-blocking
298 flags
= fcntl(clifd
, F_GETFL
, 0);
299 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
301 addr
.sin_family
= AF_INET
;
302 addr
.sin_addr
.s_addr
= config
->cli_bind_address
; /* defaults to INADDR_ANY */
303 addr
.sin_port
= htons(23);
304 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
306 LOG(0, 0, 0, "Error binding cli on port 23: %s\n", strerror(errno
));
311 if (listen(clifd
, 10) < 0)
313 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
320 void cli_do(int sockfd
)
322 int require_auth
= 1;
323 struct sockaddr_in addr
;
324 socklen_t l
= sizeof(addr
);
326 if (fork_and_close()) return;
327 if (getpeername(sockfd
, (struct sockaddr
*) &addr
, &l
) == 0)
329 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
330 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
331 fmtaddr(addr
.sin_addr
.s_addr
, 0));
334 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
338 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
339 if (!cli
->users
) /* paranoia */
341 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
347 /* no username/pass required */
352 debug_rb_tail
= ringbuffer
->tail
;
354 memset(&debug_flags
, 0, sizeof(debug_flags
));
355 debug_flags
.critical
= 1;
357 cli_loop(cli
, sockfd
);
360 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
361 fmtaddr(addr
.sin_addr
.s_addr
, 0));
366 static void cli_print_log(struct cli_def
*cli
, char *string
)
368 LOG(3, 0, 0, "%s\n", string
);
371 void cli_do_file(FILE *fh
)
373 LOG(3, 0, 0, "Reading configuration file\n");
374 cli_print_callback(cli
, cli_print_log
);
375 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
376 cli_print_callback(cli
, NULL
);
379 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
390 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
392 int v
= va_arg(ap
, int);
393 snprintf(buf
, sizeof(buf
), entry
, v
);
399 desc
= va_arg(ap
, char *);
401 cli_error(cli
, " %-20s %s", p
, desc
);
403 cli_error(cli
, " %s", p
);
405 entry
= desc
? va_arg(ap
, char *) : 0;
410 cli_error(cli
, " <cr>");
415 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
419 if (CLI_HELP_REQUESTED
)
420 return cli_arg_help(cli
, 1,
421 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
427 // Show individual session
428 for (i
= 0; i
< argc
; i
++)
430 unsigned int s
, b_in
, b_out
;
432 if (s
<= 0 || s
>= MAXSESSION
)
434 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
437 cli_print(cli
, "\r\nSession %d:", s
);
438 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
439 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
440 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
441 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
442 cli_print(cli
, "\tPPP Phase:\t%s", ppp_phase(session
[s
].ppp
.phase
));
443 switch (session
[s
].ppp
.phase
)
446 cli_print(cli
, "\t LCP state:\t%s", ppp_state(session
[s
].ppp
.lcp
));
451 cli_print(cli
, "\t IPCP state:\t%s", ppp_state(session
[s
].ppp
.ipcp
));
452 cli_print(cli
, "\t IPV6CP state:\t%s", ppp_state(session
[s
].ppp
.ipv6cp
));
453 cli_print(cli
, "\t CCP state:\t%s", ppp_state(session
[s
].ppp
.ccp
));
455 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
456 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
457 cli_print(cli
, "\tOpened:\t\t%u seconds", session
[s
].opened
? abs(time_now
- session
[s
].opened
) : 0);
458 cli_print(cli
, "\tIdle time:\t%u seconds", session
[s
].last_packet
? abs(time_now
- session
[s
].last_packet
) : 0);
459 if (session
[s
].session_timeout
)
461 clockt opened
= session
[s
].opened
;
462 if (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
463 opened
= bundle
[session
[s
].bundle
].online_time
;
465 cli_print(cli
, "\tSess Timeout:\t%u seconds", session
[s
].session_timeout
- (opened
? abs(time_now
- opened
) : 0));
468 if (session
[s
].idle_timeout
)
469 cli_print(cli
, "\tIdle Timeout:\t%u seconds", session
[s
].idle_timeout
- (session
[s
].last_data
? abs(time_now
- session
[s
].last_data
) : 0));
471 if (session
[s
].timeout
)
473 cli_print(cli
, "\tRemaining time:\t%u",
474 (session
[s
].bundle
&& bundle
[session
[s
].bundle
].num_of_links
> 1)
475 ? (unsigned) (session
[s
].timeout
- bundle
[session
[s
].bundle
].online_time
)
476 : (unsigned) (session
[s
].timeout
- (time_now
- session
[s
].opened
)));
479 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].cout
, session
[s
].cin
);
480 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
481 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
482 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
483 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
484 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
485 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
486 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
487 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
488 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
489 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
491 cli_print(cli
, "\tIntercepted:\tno");
493 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
495 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
496 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
497 t
? "YES" : "no", t
? " (" : "",
498 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
500 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
504 b_in
= session
[s
].tbf_in
;
505 b_out
= session
[s
].tbf_out
;
507 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
508 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
509 "ByteSent", "PackSent", "PackDrop", "PackDelay");
512 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
514 (filter_list
[b_in
].next
? "*" : " "),
515 (b_in
< 100 ? "\t" : ""),
516 filter_list
[b_in
].rate
* 8,
517 filter_list
[b_in
].credit
,
518 filter_list
[b_in
].queued
,
519 filter_list
[b_in
].b_queued
,
520 filter_list
[b_in
].p_queued
,
521 filter_list
[b_in
].b_sent
,
522 filter_list
[b_in
].p_sent
,
523 filter_list
[b_in
].p_dropped
,
524 filter_list
[b_in
].p_delayed
);
527 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
529 (filter_list
[b_out
].next
? "*" : " "),
530 (b_out
< 100 ? "\t" : ""),
531 filter_list
[b_out
].rate
* 8,
532 filter_list
[b_out
].credit
,
533 filter_list
[b_out
].queued
,
534 filter_list
[b_out
].b_queued
,
535 filter_list
[b_out
].p_queued
,
536 filter_list
[b_out
].b_sent
,
537 filter_list
[b_out
].p_sent
,
538 filter_list
[b_out
].p_dropped
,
539 filter_list
[b_out
].p_delayed
);
547 cli_print(cli
, "%5s %7s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-18s %s",
549 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %10s %-15s %s",
568 "LAC(L)/RLNS(R)/PPPOE(P)",
574 for (i
= 1; i
< MAXSESSION
; i
++)
577 if (!session
[i
].opened
) continue;
578 if (session
[i
].bundle
&& bundle
[session
[i
].bundle
].num_of_links
> 1)
579 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- bundle
[session
[i
].bundle
].online_time
) : 0;
581 rem_time
= session
[i
].timeout
? (session
[i
].timeout
- (time_now
-session
[i
].opened
)) : 0;
583 cli_print(cli
, "%5d %7d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s",
585 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %10lu %3s%-20s %s",
589 session
[i
].forwardtosession
,
592 session
[i
].user
[0] ? session
[i
].user
: "*",
593 fmtaddr(htonl(session
[i
].ip
), 0),
594 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
595 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
596 (session
[i
].walled_garden
) ? "Y" : "N",
597 (session
[i
].ppp
.ipv6cp
== Opened
) ? "Y" : "N",
598 abs(time_now
- (unsigned long)session
[i
].opened
),
599 (unsigned long)session
[i
].cout
,
600 (unsigned long)session
[i
].cin
,
601 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
602 (unsigned long)(rem_time
),
604 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?"(P)":(tunnel
[session
[i
].tunnel
].isremotelns
?"(R)":"(L)"),
606 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?"(P)":"(L)",
608 (session
[i
].tunnel
== TUNNEL_ID_PPPOE
)?fmtMacAddr(session
[i
].src_hwaddr
):fmtaddr(htonl(tunnel
[session
[i
].tunnel
].ip
), 1),
609 session
[i
].calling
[0] ? session
[i
].calling
: "*");
614 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
616 int i
, x
, show_all
= 0;
624 if (CLI_HELP_REQUESTED
)
627 return cli_arg_help(cli
, 1,
628 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
631 return cli_arg_help(cli
, 1,
632 "all", "Show all tunnels, including unused",
633 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
640 if (strcmp(argv
[0], "all") == 0)
646 // Show individual tunnel
647 for (i
= 0; i
< argc
; i
++)
652 if (t
<= 0 || t
>= MAXTUNNEL
)
654 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
657 cli_print(cli
, "\r\nTunnel %d:", t
);
658 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
659 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
660 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
661 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
662 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
663 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
664 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
665 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
666 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
668 for (x
= 0; x
< MAXSESSION
; x
++)
669 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
670 sprintf(s
, "%s%u ", s
, x
);
672 cli_print(cli
, "\tSessions:\t%s", s
);
678 // Show tunnel summary
679 cli_print(cli
, "%4s %20s %20s %6s %s",
686 for (i
= 1; i
< MAXTUNNEL
; i
++)
689 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
691 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
692 cli_print(cli
, "%4d %20s %20s %6s %6d %s",
694 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
695 fmtaddr(htonl(tunnel
[i
].ip
), 0),
696 states
[tunnel
[i
].state
],
699 ,(i
== TUNNEL_ID_PPPOE
)?"Tunnel pppoe":(tunnel
[i
].isremotelns
?"Tunnel To Remote LNS":"Tunnel To LAC")
701 ,(i
== TUNNEL_ID_PPPOE
)?"Tunnel pppoe":"Tunnel To LAC"
709 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
716 if (CLI_HELP_REQUESTED
)
717 return cli_arg_help(cli
, 1,
718 "USER", "Show details for specific username",
721 for (i
= 0; i
< MAXSESSION
; i
++)
723 if (!session
[i
].opened
) continue;
724 if (!session
[i
].user
[0]) continue;
728 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
730 if (strcmp(argv
[j
], session
[i
].user
) == 0)
732 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
733 sargv
[sargc
] = sid
[sargc
];
741 cli_print(cli
, "%s", session
[i
].user
);
745 return cmd_show_session(cli
, "users", sargv
, sargc
);
751 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
753 if (CLI_HELP_REQUESTED
)
754 return CLI_HELP_NO_ARGS
;
756 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
757 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
758 GET_STAT(tun_rx_bytes
),
759 GET_STAT(tun_rx_packets
),
760 GET_STAT(tun_rx_errors
),
761 GET_STAT(tun_rx_dropped
));
762 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
763 GET_STAT(tun_tx_bytes
),
764 GET_STAT(tun_tx_packets
),
765 GET_STAT(tun_tx_errors
));
768 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
769 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
770 GET_STAT(tunnel_rx_bytes
),
771 GET_STAT(tunnel_rx_packets
),
772 GET_STAT(tunnel_rx_errors
));
773 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
774 GET_STAT(tunnel_tx_bytes
),
775 GET_STAT(tunnel_tx_packets
),
776 GET_STAT(tunnel_tx_errors
),
777 GET_STAT(tunnel_retries
));
780 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
781 cli_print(cli
, "-----------------------------------------");
782 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
783 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
784 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
785 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
786 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
787 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
788 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
789 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
790 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
791 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
792 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
793 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
794 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
795 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
796 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
797 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
798 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
799 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
803 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
804 cli_print(cli
, "-----------------------------------------");
805 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
806 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
807 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
808 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
809 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
810 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
811 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
812 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
813 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
814 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
815 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
816 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
817 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
818 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
819 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
820 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
821 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
822 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
823 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
824 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
825 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
826 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
827 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
828 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
829 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
830 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
831 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
832 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
833 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
834 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
835 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
836 #endif /* STAT_CALLS */
839 time_t l
= GET_STAT(last_reset
);
841 char *p
= strchr(t
, '\n');
845 cli_print(cli
, "Last counter reset %s", t
);
851 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
853 if (CLI_HELP_REQUESTED
)
854 return CLI_HELP_NO_ARGS
;
856 memset(_statistics
, 0, sizeof(struct Tstats
));
857 SET_STAT(last_reset
, time(NULL
));
859 cli_print(cli
, "Counters cleared");
862 #endif /* STATISTICS */
864 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
866 if (CLI_HELP_REQUESTED
)
867 return CLI_HELP_NO_ARGS
;
869 cli_print(cli
, "L2TPNS %s", VERSION
);
873 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
876 int used
= 0, free
= 0, show_all
= 0;
878 if (!config
->cluster_iam_master
)
880 cli_print(cli
, "Can't do this on a slave. Do it on %s",
881 fmtaddr(config
->cluster_master_address
, 0));
886 if (CLI_HELP_REQUESTED
)
889 return cli_arg_help(cli
, 1, NULL
);
891 return cli_arg_help(cli
, 1,
892 "all", "Show all pool addresses, including unused",
896 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
900 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
901 for (i
= 0; i
< MAXIPPOOL
; i
++)
903 if (!ip_address_pool
[i
].address
) continue;
904 if (ip_address_pool
[i
].assigned
)
906 cli_print(cli
, "%-15s\tY %8d %s",
907 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
908 ip_address_pool
[i
].session
,
909 session
[ip_address_pool
[i
].session
].user
);
915 if (ip_address_pool
[i
].last
)
916 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
917 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
918 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
921 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
928 cli_print(cli
, "(Not displaying unused addresses)");
930 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
934 static FILE *save_config_fh
= 0;
935 static void print_save_config(struct cli_def
*cli
, char *string
)
938 fprintf(save_config_fh
, "%s\n", string
);
941 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
943 if (CLI_HELP_REQUESTED
)
944 return CLI_HELP_NO_ARGS
;
946 if ((save_config_fh
= fopen(config
->config_file
, "w")))
948 cli_print(cli
, "Writing configuration");
949 cli_print_callback(cli
, print_save_config
);
950 cmd_show_run(cli
, command
, argv
, argc
);
951 cli_print_callback(cli
, NULL
);
952 fclose(save_config_fh
);
957 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
962 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
964 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
967 char ipv6addr
[INET6_ADDRSTRLEN
];
969 if (CLI_HELP_REQUESTED
)
970 return CLI_HELP_NO_ARGS
;
972 cli_print(cli
, "# Current configuration:");
974 for (i
= 0; config_values
[i
].key
; i
++)
976 void *value
= ((void *)config
) + config_values
[i
].offset
;
977 if (config_values
[i
].type
== STRING
)
978 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
979 else if (config_values
[i
].type
== IPv4
)
980 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
981 else if (config_values
[i
].type
== IPv6
)
982 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
983 else if (config_values
[i
].type
== SHORT
)
984 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
985 else if (config_values
[i
].type
== BOOL
)
986 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
987 else if (config_values
[i
].type
== INT
)
988 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
989 else if (config_values
[i
].type
== UNSIGNED_LONG
)
990 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
993 cli_print(cli
, "# Plugins");
994 for (i
= 0; i
< MAXPLUGINS
; i
++)
996 if (*config
->plugins
[i
])
998 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
1003 if (config
->as_number
)
1008 cli_print(cli
, "# BGP");
1009 cli_print(cli
, "router bgp %u", config
->as_number
);
1010 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1012 if (!config
->neighbour
[i
].name
[0])
1015 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
1017 k
= config
->neighbour
[i
].keepalive
;
1018 h
= config
->neighbour
[i
].hold
;
1025 k
= BGP_KEEPALIVE_TIME
;
1031 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
1033 if (config
->neighbour
[i
].update_source
.s_addr
!= INADDR_ANY
)
1034 cli_print(cli
, " neighbour %s update-source %s",
1035 config
->neighbour
[i
].name
,
1036 inet_ntoa(config
->neighbour
[i
].update_source
));
1041 cli_print(cli
, "# Filters");
1042 for (i
= 0; i
< MAXFILTER
; i
++)
1044 ip_filter_rulet
*rules
;
1045 if (!*ip_filters
[i
].name
)
1048 cli_print(cli
, "ip access-list %s %s",
1049 ip_filters
[i
].extended
? "extended" : "standard",
1050 ip_filters
[i
].name
);
1052 rules
= ip_filters
[i
].rules
;
1053 while (rules
->action
)
1054 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1057 cli_print(cli
, "# end");
1061 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1063 int i
, free
= 0, used
= 0, show_all
= 0;
1075 if (CLI_HELP_REQUESTED
)
1078 return cli_arg_help(cli
, 1, NULL
);
1080 return cli_arg_help(cli
, 1,
1081 "all", "Show all RADIUS sessions, including unused",
1085 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1089 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1092 for (i
= 1; i
< MAXRADIUS
; i
++)
1094 if (radius
[i
].state
== RADIUSNULL
)
1099 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1101 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1105 states
[radius
[i
].state
],
1111 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1116 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1120 if (CLI_HELP_REQUESTED
)
1121 return CLI_HELP_NO_ARGS
;
1123 cli_print(cli
, "Plugins currently loaded:");
1124 for (i
= 0; i
< MAXPLUGINS
; i
++)
1125 if (*config
->plugins
[i
])
1126 cli_print(cli
, " %s", config
->plugins
[i
]);
1131 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1135 if (CLI_HELP_REQUESTED
)
1136 return CLI_HELP_NO_ARGS
;
1138 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1147 for (i
= 0; i
< MAXSESSION
; i
++)
1149 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1150 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1154 session
[i
].throttle_in
,
1155 session
[i
].throttle_out
,
1157 session
[i
].tbf_out
);
1163 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1165 if (CLI_HELP_REQUESTED
)
1166 return CLI_HELP_NO_ARGS
;
1168 cli_print(cli
, " _\n"
1174 " ( \\ `. `-. _,.-:\\\n"
1175 " \\ \\ `. `-._ __..--' ,-';/\n"
1176 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1177 " `. `. `-._ __..--' ,' /\n"
1178 " `. `-_ ``--..'' _.-' ,'\n"
1179 " `-_ `-.___ __,--' ,'\n"
1180 " `-.__ `----\"\"\" __.-'\n"
1181 "hh `--..____..--'");
1186 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1191 if (CLI_HELP_REQUESTED
)
1192 return cli_arg_help(cli
, argc
> 1,
1193 "USER", "Username of session to drop", NULL
);
1195 if (!config
->cluster_iam_master
)
1197 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1198 fmtaddr(config
->cluster_master_address
, 0));
1205 cli_error(cli
, "Specify a user to drop");
1209 for (i
= 0; i
< argc
; i
++)
1211 if (!(s
= sessionbyuser(argv
[i
])))
1213 cli_error(cli
, "User %s is not connected", argv
[i
]);
1217 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1219 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1220 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1227 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1232 if (CLI_HELP_REQUESTED
)
1233 return cli_arg_help(cli
, argc
> 1,
1234 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1236 if (!config
->cluster_iam_master
)
1238 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1239 fmtaddr(config
->cluster_master_address
, 0));
1246 cli_error(cli
, "Specify a tunnel to drop");
1250 for (i
= 0; i
< argc
; i
++)
1252 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1254 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1260 cli_error(cli
, "Tunnel %d is not connected", t
);
1266 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1270 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1271 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1277 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1282 if (CLI_HELP_REQUESTED
)
1283 return cli_arg_help(cli
, argc
> 1,
1284 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1286 if (!config
->cluster_iam_master
)
1288 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1289 fmtaddr(config
->cluster_master_address
, 0));
1296 cli_error(cli
, "Specify a session id to drop");
1300 for (i
= 0; i
< argc
; i
++)
1302 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1304 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1308 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1310 cli_print(cli
, "Dropping session %d", s
);
1311 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1314 else if (session
[s
].forwardtosession
&& session
[s
].opened
&& !session
[s
].die
)
1316 cli_print(cli
, "Dropping session %d", s
);
1317 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1322 cli_error(cli
, "Session %d is not active.", s
);
1329 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1335 if (CLI_HELP_REQUESTED
)
1340 return cli_arg_help(cli
, 0,
1341 "USER", "Username of session to snoop", NULL
);
1344 return cli_arg_help(cli
, 0,
1345 "A.B.C.D", "IP address of snoop destination", NULL
);
1348 return cli_arg_help(cli
, 0,
1349 "N", "Port of snoop destination", NULL
);
1353 return cli_arg_help(cli
, 1, NULL
);
1360 if (!config
->cluster_iam_master
)
1362 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1363 fmtaddr(config
->cluster_master_address
, 0));
1370 cli_error(cli
, "Specify username, ip and port");
1374 if (!(s
= sessionbyuser(argv
[0])))
1376 cli_error(cli
, "User %s is not connected", argv
[0]);
1380 ip
= inet_addr(argv
[1]);
1381 if (!ip
|| ip
== INADDR_NONE
)
1383 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1387 port
= atoi(argv
[2]);
1390 cli_error(cli
, "Invalid port %s", argv
[2]);
1394 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1395 cli_session_actions
[s
].snoop_ip
= ip
;
1396 cli_session_actions
[s
].snoop_port
= port
;
1397 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1402 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1407 if (CLI_HELP_REQUESTED
)
1408 return cli_arg_help(cli
, argc
> 1,
1409 "USER", "Username of session to unsnoop", NULL
);
1411 if (!config
->cluster_iam_master
)
1413 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1414 fmtaddr(config
->cluster_master_address
, 0));
1421 cli_error(cli
, "Specify a user to unsnoop");
1425 for (i
= 0; i
< argc
; i
++)
1427 if (!(s
= sessionbyuser(argv
[i
])))
1429 cli_error(cli
, "User %s is not connected", argv
[i
]);
1433 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1434 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1440 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1447 throttle USER - throttle in/out to default rate
1448 throttle USER RATE - throttle in/out to default rate
1449 throttle USER in RATE - throttle input only
1450 throttle USER out RATE - throttle output only
1451 throttle USER in RATE out RATE - throttle both
1454 if (CLI_HELP_REQUESTED
)
1459 return cli_arg_help(cli
, 0,
1460 "USER", "Username of session to throttle", NULL
);
1463 return cli_arg_help(cli
, 1,
1464 "RATE", "Rate in kbps (in and out)",
1465 "in", "Select incoming rate",
1466 "out", "Select outgoing rate", NULL
);
1469 return cli_arg_help(cli
, 1,
1470 "in", "Select incoming rate",
1471 "out", "Select outgoing rate", NULL
);
1474 if (isdigit(argv
[1][0]))
1475 return cli_arg_help(cli
, 1, NULL
);
1478 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1481 return cli_arg_help(cli
, argc
> 1, NULL
);
1485 if (!config
->cluster_iam_master
)
1487 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1488 fmtaddr(config
->cluster_master_address
, 0));
1495 cli_error(cli
, "Specify a user to throttle");
1499 if (!(s
= sessionbyuser(argv
[0])))
1501 cli_error(cli
, "User %s is not connected", argv
[0]);
1507 rate_in
= rate_out
= config
->rl_rate
;
1511 rate_in
= rate_out
= atoi(argv
[1]);
1514 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1518 else if (argc
== 3 || argc
== 5)
1521 for (i
= 1; i
< argc
- 1; i
+= 2)
1524 if (MATCH("in", argv
[i
]))
1525 r
= rate_in
= atoi(argv
[i
+1]);
1526 else if (MATCH("out", argv
[i
]))
1527 r
= rate_out
= atoi(argv
[i
+1]);
1531 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1538 cli_error(cli
, "Invalid arguments");
1542 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1544 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1548 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1549 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1550 cli_session_actions
[s
].throttle_in
= rate_in
;
1552 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1553 cli_session_actions
[s
].throttle_out
= rate_out
;
1555 if (cli_session_actions
[s
].throttle_in
== -1 &&
1556 cli_session_actions
[s
].throttle_out
== -1)
1558 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1562 cli_print(cli
, "Throttling user %s", argv
[0]);
1563 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1568 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1573 if (CLI_HELP_REQUESTED
)
1574 return cli_arg_help(cli
, argc
> 1,
1575 "USER", "Username of session to unthrottle", NULL
);
1577 if (!config
->cluster_iam_master
)
1579 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1580 fmtaddr(config
->cluster_master_address
, 0));
1587 cli_error(cli
, "Specify a user to unthrottle");
1591 for (i
= 0; i
< argc
; i
++)
1593 if (!(s
= sessionbyuser(argv
[i
])))
1595 cli_error(cli
, "User %s is not connected", argv
[i
]);
1599 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1601 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1602 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1606 cli_error(cli
, "User %s not throttled", argv
[i
]);
1613 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1617 if (CLI_HELP_REQUESTED
)
1618 return cli_arg_help(cli
, 1,
1619 "all", "Enable debugging for all except \"data\"",
1620 "critical", "", // FIXME: add descriptions
1630 char *p
= (char *) &debug_flags
;
1631 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1635 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1636 (debug_flags
.critical
) ? " critical" : "",
1637 (debug_flags
.error
) ? " error" : "",
1638 (debug_flags
.warning
) ? " warning" : "",
1639 (debug_flags
.info
) ? " info" : "",
1640 (debug_flags
.calls
) ? " calls" : "",
1641 (debug_flags
.data
) ? " data" : "");
1647 cli_print(cli
, "Debugging off");
1651 for (i
= 0; i
< argc
; i
++)
1653 int len
= strlen(argv
[i
]);
1655 if (argv
[i
][0] == 'c' && len
< 2)
1656 len
= 2; /* distinguish [cr]itical from [ca]lls */
1658 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1659 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1660 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1661 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1662 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1663 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1664 if (!strncmp("all", argv
[i
], len
))
1666 memset(&debug_flags
, 1, sizeof(debug_flags
));
1667 debug_flags
.data
= 0;
1671 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1677 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1681 if (CLI_HELP_REQUESTED
)
1682 return cli_arg_help(cli
, 1,
1683 "all", "Disable all debugging",
1684 "critical", "", // FIXME: add descriptions
1694 memset(&debug_flags
, 0, sizeof(debug_flags
));
1698 for (i
= 0; i
< argc
; i
++)
1700 int len
= strlen(argv
[i
]);
1702 if (argv
[i
][0] == 'c' && len
< 2)
1703 len
= 2; /* distinguish [cr]itical from [ca]lls */
1705 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1706 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1707 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1708 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1709 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1710 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1711 if (!strncmp("all", argv
[i
], len
))
1713 memset(&debug_flags
, 0, sizeof(debug_flags
));
1717 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1723 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1725 int i
, firstfree
= 0;
1727 if (CLI_HELP_REQUESTED
)
1728 return cli_arg_help(cli
, argc
> 1,
1729 "PLUGIN", "Name of plugin to load", NULL
);
1733 cli_error(cli
, "Specify a plugin to load");
1737 for (i
= 0; i
< MAXPLUGINS
; i
++)
1739 if (!*config
->plugins
[i
] && !firstfree
)
1741 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1743 cli_error(cli
, "Plugin is already loaded");
1750 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1751 config
->reload_config
= 1;
1752 cli_print(cli
, "Loading plugin %s", argv
[0]);
1758 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1762 if (CLI_HELP_REQUESTED
)
1763 return cli_arg_help(cli
, argc
> 1,
1764 "PLUGIN", "Name of plugin to unload", NULL
);
1768 cli_error(cli
, "Specify a plugin to remove");
1772 for (i
= 0; i
< MAXPLUGINS
; i
++)
1774 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1776 config
->reload_config
= 1;
1777 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1782 cli_error(cli
, "Plugin is not loaded");
1786 static char *duration(time_t secs
)
1788 static char *buf
= NULL
;
1791 if (!buf
) buf
= calloc(64, 1);
1795 int days
= secs
/ 86400;
1796 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1802 int mins
= secs
/ 60;
1803 int hrs
= mins
/ 60;
1806 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1808 else if (secs
>= 60)
1810 int mins
= secs
/ 60;
1811 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1814 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1819 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1822 char buf
[100], *p
= buf
, *loads
[3];
1823 int i
, num_sessions
= 0;
1825 if (CLI_HELP_REQUESTED
)
1826 return CLI_HELP_NO_ARGS
;
1828 fh
= fopen("/proc/loadavg", "r");
1829 fgets(buf
, 100, fh
);
1832 for (i
= 0; i
< 3; i
++)
1833 loads
[i
] = strdup(strsep(&p
, " "));
1836 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1838 for (i
= 1; i
< MAXSESSION
; i
++)
1839 if (session
[i
].opened
) num_sessions
++;
1841 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1843 duration(time_now
- config
->start_time
),
1845 loads
[0], loads
[1], loads
[2]
1847 for (i
= 0; i
< 3; i
++)
1848 if (loads
[i
]) free(loads
[i
]);
1850 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1855 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1859 if (CLI_HELP_REQUESTED
)
1865 int len
= strlen(argv
[0])-1;
1866 for (i
= 0; config_values
[i
].key
; i
++)
1867 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1868 cli_error(cli
, " %s", config_values
[i
].key
);
1874 return cli_arg_help(cli
, 0,
1875 "VALUE", "Value for variable", NULL
);
1879 return cli_arg_help(cli
, 1, NULL
);
1888 cli_error(cli
, "Specify variable and value");
1892 for (i
= 0; config_values
[i
].key
; i
++)
1894 void *value
= ((void *) config
) + config_values
[i
].offset
;
1895 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1897 // Found a value to set
1898 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1899 switch (config_values
[i
].type
)
1902 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1905 *(int *) value
= atoi(argv
[1]);
1908 *(unsigned long *) value
= atol(argv
[1]);
1911 *(short *) value
= atoi(argv
[1]);
1914 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1917 inet_pton(AF_INET6
, argv
[1], value
);
1920 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1926 cli_error(cli
, "Unknown variable type");
1929 config
->reload_config
= 1;
1934 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1938 int regular_stuff(struct cli_def
*cli
)
1944 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1946 char *m
= ringbuffer
->buffer
[i
].message
;
1952 switch (ringbuffer
->buffer
[i
].level
)
1954 case 0: show
= debug_flags
.critical
; break;
1955 case 1: show
= debug_flags
.error
; break;
1956 case 2: show
= debug_flags
.warning
; break;
1957 case 3: show
= debug_flags
.info
; break;
1958 case 4: show
= debug_flags
.calls
; break;
1959 case 5: show
= debug_flags
.data
; break;
1962 if (!show
) continue;
1964 if (!(p
= strchr(m
, '\n')))
1967 cli_error(cli
, "\r%s-%u-%u %.*s",
1968 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1969 ringbuffer
->buffer
[i
].tunnel
,
1970 ringbuffer
->buffer
[i
].session
,
1976 debug_rb_tail
= ringbuffer
->tail
;
1984 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1988 if (CLI_HELP_REQUESTED
)
1989 return cli_arg_help(cli
, argc
> 1,
1990 "<1-65535>", "Autonomous system number", NULL
);
1992 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1994 cli_error(cli
, "Invalid autonomous system number");
1998 if (bgp_configured
&& as
!= config
->as_number
)
2000 cli_error(cli
, "Can't change local AS on a running system");
2004 config
->as_number
= as
;
2005 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
2010 static int find_bgp_neighbour(char const *name
)
2015 in_addr_t addrs
[4] = { 0 };
2018 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
2021 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
2022 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
2024 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2026 if (!config
->neighbour
[i
].name
[0])
2028 if (new == -1) new = i
;
2032 if (!strcmp(name
, config
->neighbour
[i
].name
))
2035 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
2038 for (a
= h
->h_addr_list
; *a
; a
++)
2041 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2042 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2050 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2056 if (CLI_HELP_REQUESTED
)
2061 return cli_arg_help(cli
, 0,
2062 "A.B.C.D", "BGP neighbour address",
2063 "NAME", "BGP neighbour name",
2067 return cli_arg_help(cli
, 0,
2068 "remote-as", "Set remote autonomous system number",
2069 "timers", "Set timers",
2070 "update-source", "Set source address to use for the BGP session",
2074 if (MATCH("remote-as", argv
[1]))
2075 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2077 if (MATCH("timers", argv
[1]))
2080 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2083 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2085 if (argc
== 5 && !argv
[4][1])
2086 return cli_arg_help(cli
, 1, NULL
);
2089 if (MATCH("update-source", argv
[1]))
2090 return cli_arg_help(cli
, argc
> 3, "A.B.C.D", "Source IP address", NULL
);
2098 cli_error(cli
, "Invalid arguments");
2102 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2104 cli_error(cli
, "Invalid neighbour");
2110 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2114 if (MATCH("remote-as", argv
[1]))
2116 int as
= atoi(argv
[2]);
2117 if (as
< 0 || as
> 65535)
2119 cli_error(cli
, "Invalid autonomous system number");
2123 if (!config
->neighbour
[i
].name
[0])
2125 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2126 config
->neighbour
[i
].keepalive
= -1;
2127 config
->neighbour
[i
].hold
= -1;
2128 config
->neighbour
[i
].update_source
.s_addr
= INADDR_ANY
;
2131 config
->neighbour
[i
].as
= as
;
2135 if (MATCH("update-source", argv
[1]))
2137 struct in_addr addr
;
2139 if (!config
->neighbour
[i
].name
[0])
2141 cli_error(cli
, "Specify remote-as first");
2145 if (!inet_aton(argv
[2], &addr
))
2147 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[2]);
2151 config
->neighbour
[i
].update_source
= addr
;
2155 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2157 cli_error(cli
, "Invalid arguments");
2161 if (!config
->neighbour
[i
].name
[0])
2163 cli_error(cli
, "Specify remote-as first");
2167 keepalive
= atoi(argv
[2]);
2168 hold
= atoi(argv
[3]);
2170 if (keepalive
< 1 || keepalive
> 65535)
2172 cli_error(cli
, "Invalid keepalive time");
2176 if (hold
< 3 || hold
> 65535)
2178 cli_error(cli
, "Invalid hold time");
2182 if (keepalive
== BGP_KEEPALIVE_TIME
)
2183 keepalive
= -1; // using default value
2185 if (hold
== BGP_HOLD_TIME
)
2188 config
->neighbour
[i
].keepalive
= keepalive
;
2189 config
->neighbour
[i
].hold
= hold
;
2194 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2198 if (CLI_HELP_REQUESTED
)
2199 return cli_arg_help(cli
, argc
> 0,
2200 "A.B.C.D", "BGP neighbour address",
2201 "NAME", "BGP neighbour name",
2206 cli_error(cli
, "Specify a BGP neighbour");
2210 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2212 cli_error(cli
, "Invalid neighbour");
2216 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2218 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2222 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2226 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2232 if (!bgp_configured
)
2235 if (CLI_HELP_REQUESTED
)
2236 return cli_arg_help(cli
, 1,
2237 "A.B.C.D", "BGP neighbour address",
2238 "NAME", "BGP neighbour name",
2241 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2242 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2246 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2248 if (!*bgp_peers
[i
].name
)
2251 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2252 if (argc
&& strcmp(addr
, argv
[0]) &&
2253 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2259 cli_print(cli
, "Peer AS Address "
2260 "State Retries Retry in Route Pend Timers");
2261 cli_print(cli
, "------------------ ----- --------------- "
2262 "----------- ------- -------- ----- ---- ---------");
2265 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2269 bgp_state_str(bgp_peers
[i
].state
),
2270 bgp_peers
[i
].retry_count
,
2271 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2272 bgp_peers
[i
].routing
? "yes" : "no",
2273 bgp_peers
[i
].update_routes
? "yes" : "no",
2274 bgp_peers
[i
].keepalive
,
2281 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2286 if (!bgp_configured
)
2289 if (CLI_HELP_REQUESTED
)
2290 return cli_arg_help(cli
, 1,
2291 "A.B.C.D", "BGP neighbour address",
2292 "NAME", "BGP neighbour name",
2295 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2297 if (bgp_peers
[i
].state
!= Established
)
2300 if (!bgp_peers
[i
].routing
)
2303 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2304 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2307 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2308 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2314 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2319 if (!bgp_configured
)
2322 if (CLI_HELP_REQUESTED
)
2323 return cli_arg_help(cli
, 1,
2324 "A.B.C.D", "BGP neighbour address",
2325 "NAME", "BGP neighbour name",
2328 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2330 if (bgp_peers
[i
].state
!= Established
)
2333 if (bgp_peers
[i
].routing
)
2336 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2337 if (argc
&& strcmp(addr
, argv
[0]) &&
2338 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2341 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2342 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2348 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2353 if (!bgp_configured
)
2356 if (CLI_HELP_REQUESTED
)
2357 return cli_arg_help(cli
, 1,
2358 "A.B.C.D", "BGP neighbour address",
2359 "NAME", "BGP neighbour name",
2362 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2364 if (!*bgp_peers
[i
].name
)
2367 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2368 if (argc
&& strcmp(addr
, argv
[0]) &&
2369 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2372 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2373 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2381 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2385 if (CLI_HELP_REQUESTED
)
2390 return cli_arg_help(cli
, 0,
2391 "standard", "Standard syntax",
2392 "extended", "Extended syntax",
2396 return cli_arg_help(cli
, argv
[1][1],
2397 "NAME", "Access-list name",
2401 if (argc
== 3 && !argv
[2][1])
2402 return cli_arg_help(cli
, 1, NULL
);
2410 cli_error(cli
, "Specify access-list type and name");
2414 if (MATCH("standard", argv
[0]))
2416 else if (MATCH("extended", argv
[0]))
2420 cli_error(cli
, "Invalid access-list type");
2424 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2425 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2427 cli_error(cli
, "Invalid access-list name");
2431 filt
= find_filter(argv
[1], strlen(argv
[1]));
2436 cli_error(cli
, "Too many access-lists");
2441 if (!*ip_filters
[filt
].name
)
2443 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2444 strcpy(ip_filters
[filt
].name
, argv
[1]);
2445 ip_filters
[filt
].extended
= extended
;
2447 else if (ip_filters
[filt
].extended
!= extended
)
2449 cli_error(cli
, "Access-list is %s",
2450 ip_filters
[filt
].extended
? "extended" : "standard");
2455 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2459 if (filt
< 0 || !*ip_filters
[filt
].name
)
2461 cli_error(cli
, "Access-list not defined");
2466 if (ip_filters
[filt
].used
)
2468 cli_error(cli
, "Access-list in use");
2472 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2476 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2478 return access_list(cli
, argv
, argc
, 1);
2481 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2483 return access_list(cli
, argv
, argc
, 0);
2486 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2488 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2489 return sprintf(buf
, " any");
2491 if (wild
== INADDR_ANY
)
2492 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2494 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2497 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2501 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2502 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2503 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2504 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2505 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2511 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2513 static char buf
[256];
2516 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2519 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2520 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2523 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2527 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2528 p
+= show_ports(p
, &rule
->src_ports
);
2530 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2531 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2532 p
+= show_ports(p
, &rule
->dst_ports
);
2534 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2536 switch (rule
->tcp_flag_op
)
2538 case FILTER_FLAG_OP_EST
:
2539 p
+= sprintf(p
, " established");
2542 case FILTER_FLAG_OP_ANY
:
2543 case FILTER_FLAG_OP_ALL
:
2544 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2545 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2546 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2547 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2548 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2549 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2550 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2551 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2552 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2553 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2554 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2555 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2556 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2562 p
+= sprintf(p
, " fragments");
2567 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2569 static ip_filter_rulet rule
;
2570 struct in_addr addr
;
2574 if (CLI_HELP_REQUESTED
)
2578 cli_arg_help(cli
, 0,
2579 "ip", "Match IP packets",
2580 "tcp", "Match TCP packets",
2581 "udp", "Match UDP packets",
2587 // *sigh*, too darned complex
2588 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2594 cli_error(cli
, "Specify rule details");
2598 memset(&rule
, 0, sizeof(rule
));
2599 rule
.action
= (command
[0] == 'p')
2600 ? FILTER_ACTION_PERMIT
2601 : FILTER_ACTION_DENY
;
2603 if (MATCH("ip", argv
[0]))
2604 rule
.proto
= IPPROTO_IP
;
2605 else if (MATCH("udp", argv
[0]))
2606 rule
.proto
= IPPROTO_UDP
;
2607 else if (MATCH("tcp", argv
[0]))
2608 rule
.proto
= IPPROTO_TCP
;
2611 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2615 for (a
= 1, i
= 0; i
< 2; i
++)
2619 ip_filter_portt
*port
;
2624 wild
= &rule
.src_wild
;
2625 port
= &rule
.src_ports
;
2630 wild
= &rule
.dst_wild
;
2631 port
= &rule
.dst_ports
;
2634 cli_error(cli
, "Specify destination");
2639 if (MATCH("any", argv
[a
]))
2642 *wild
= INADDR_BROADCAST
;
2645 else if (MATCH("host", argv
[a
]))
2649 cli_error(cli
, "Specify host ip address");
2653 if (!inet_aton(argv
[a
], &addr
))
2655 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2667 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2671 if (!inet_aton(argv
[a
], &addr
))
2673 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2679 if (!inet_aton(argv
[++a
], &addr
))
2681 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2685 *wild
= addr
.s_addr
;
2689 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2693 if (MATCH("eq", argv
[a
]))
2694 port
->op
= FILTER_PORT_OP_EQ
;
2695 else if (MATCH("neq", argv
[a
]))
2696 port
->op
= FILTER_PORT_OP_NEQ
;
2697 else if (MATCH("gt", argv
[a
]))
2698 port
->op
= FILTER_PORT_OP_GT
;
2699 else if (MATCH("lt", argv
[a
]))
2700 port
->op
= FILTER_PORT_OP_LT
;
2701 else if (MATCH("range", argv
[a
]))
2702 port
->op
= FILTER_PORT_OP_RANGE
;
2709 cli_error(cli
, "Specify port");
2713 if (!(port
->port
= atoi(argv
[a
])))
2715 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2720 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2725 cli_error(cli
, "Specify port");
2729 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2731 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2738 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2740 if (MATCH("established", argv
[a
]))
2742 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2745 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2746 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2748 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2749 ? FILTER_FLAG_OP_ANY
2750 : FILTER_FLAG_OP_ALL
;
2754 cli_error(cli
, "Specify tcp flags");
2758 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2762 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2764 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2765 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2766 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2767 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2768 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2769 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2772 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2781 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2783 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2785 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2795 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2802 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2804 static ip_filter_rulet rule
;
2805 struct in_addr addr
;
2807 if (CLI_HELP_REQUESTED
)
2811 cli_arg_help(cli
, argv
[0][1],
2812 "A.B.C.D", "Source address",
2813 "any", "Any source address",
2814 "host", "Source host",
2820 if (MATCH("any", argv
[0]))
2822 if (argc
== 2 && !argv
[1][1])
2823 cli_arg_help(cli
, 1, NULL
);
2825 else if (MATCH("host", argv
[0]))
2829 cli_arg_help(cli
, argv
[1][1],
2830 "A.B.C.D", "Host address",
2833 else if (argc
== 3 && !argv
[2][1])
2834 cli_arg_help(cli
, 1, NULL
);
2840 cli_arg_help(cli
, 1,
2841 "A.B.C.D", "Wildcard bits",
2844 else if (argc
== 3 && !argv
[2][1])
2845 cli_arg_help(cli
, 1, NULL
);
2853 cli_error(cli
, "Specify rule details");
2857 memset(&rule
, 0, sizeof(rule
));
2858 rule
.action
= (command
[0] == 'p')
2859 ? FILTER_ACTION_PERMIT
2860 : FILTER_ACTION_DENY
;
2862 rule
.proto
= IPPROTO_IP
;
2863 if (MATCH("any", argv
[0]))
2865 rule
.src_ip
= INADDR_ANY
;
2866 rule
.src_wild
= INADDR_BROADCAST
;
2868 else if (MATCH("host", argv
[0]))
2872 cli_error(cli
, "Specify host ip address");
2876 if (!inet_aton(argv
[1], &addr
))
2878 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2882 rule
.src_ip
= addr
.s_addr
;
2883 rule
.src_wild
= INADDR_ANY
;
2889 cli_error(cli
, "Specify source ip address and wildcard");
2893 if (!inet_aton(argv
[0], &addr
))
2895 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2899 rule
.src_ip
= addr
.s_addr
;
2903 if (!inet_aton(argv
[1], &addr
))
2905 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2909 rule
.src_wild
= addr
.s_addr
;
2912 rule
.src_wild
= INADDR_ANY
;
2918 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2921 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2922 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2923 : access_list_rule_std(cli
, command
, argv
, argc
);
2928 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2930 if (!ip_filters
[filt
].rules
[i
].action
)
2932 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2936 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, offsetof(ip_filter_rulet
, counter
)))
2940 cli_error(cli
, "Too many rules");
2944 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2949 /* filter USER {in|out} FILTER ... */
2950 if (CLI_HELP_REQUESTED
)
2955 return cli_arg_help(cli
, 0,
2956 "USER", "Username of session to filter", NULL
);
2960 return cli_arg_help(cli
, 0,
2961 "in", "Set incoming filter",
2962 "out", "Set outgoing filter", NULL
);
2966 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2967 "NAME", "Filter name", NULL
);
2970 return cli_arg_help(cli
, argc
> 1, NULL
);
2974 if (!config
->cluster_iam_master
)
2976 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2977 fmtaddr(config
->cluster_master_address
, 0));
2982 if (argc
!= 3 && argc
!= 5)
2984 cli_error(cli
, "Specify a user and filters");
2988 if (!(s
= sessionbyuser(argv
[0])))
2990 cli_error(cli
, "User %s is not connected", argv
[0]);
2994 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2995 for (i
= 1; i
< argc
; i
+= 2)
3000 if (MATCH("in", argv
[i
]))
3002 if (session
[s
].filter_in
)
3004 cli_error(cli
, "Input already filtered");
3007 f
= &cli_session_actions
[s
].filter_in
;
3009 else if (MATCH("out", argv
[i
]))
3011 if (session
[s
].filter_out
)
3013 cli_error(cli
, "Output already filtered");
3016 f
= &cli_session_actions
[s
].filter_out
;
3020 cli_error(cli
, "Invalid filter specification");
3024 v
= find_filter(argv
[i
+1], strlen(argv
[i
+1]));
3025 if (v
< 0 || !*ip_filters
[v
].name
)
3027 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
3034 cli_print(cli
, "Filtering user %s", argv
[0]);
3035 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
3040 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3045 if (CLI_HELP_REQUESTED
)
3046 return cli_arg_help(cli
, argc
> 1,
3047 "USER", "Username of session to remove filters from", NULL
);
3049 if (!config
->cluster_iam_master
)
3051 cli_error(cli
, "Can't do this on a slave. Do it on %s",
3052 fmtaddr(config
->cluster_master_address
, 0));
3059 cli_error(cli
, "Specify a user to remove filters from");
3063 for (i
= 0; i
< argc
; i
++)
3065 if (!(s
= sessionbyuser(argv
[i
])))
3067 cli_error(cli
, "User %s is not connected", argv
[i
]);
3071 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3073 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3074 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3078 cli_error(cli
, "User %s not filtered", argv
[i
]);
3085 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3089 if (CLI_HELP_REQUESTED
)
3090 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3094 cli_error(cli
, "Specify a filter name");
3098 for (i
= 0; i
< argc
; i
++)
3100 int f
= find_filter(argv
[i
], strlen(argv
[i
]));
3101 ip_filter_rulet
*rules
;
3103 if (f
< 0 || !*ip_filters
[f
].name
)
3105 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3112 cli_print(cli
, "%s IP access list %s",
3113 ip_filters
[f
].extended
? "Extended" : "Standard",
3114 ip_filters
[f
].name
);
3116 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3118 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3120 cli_print(cli
, "%s (%u match%s)", r
,
3121 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3123 cli_print(cli
, "%s", r
);
3130 static int cmd_shutdown(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3132 if (CLI_HELP_REQUESTED
)
3133 return CLI_HELP_NO_ARGS
;
3135 kill(getppid(), SIGQUIT
);
3139 static int cmd_reload(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3141 if (CLI_HELP_REQUESTED
)
3142 return CLI_HELP_NO_ARGS
;
3144 kill(getppid(), SIGHUP
);
3150 static int cmd_setforward(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3154 if (CLI_HELP_REQUESTED
)
3159 return cli_arg_help(cli
, 0,
3160 "MASK", "Users mask to forward (ex: myISP@operator.com)", NULL
);
3163 return cli_arg_help(cli
, 0,
3164 "IP", "IP of the remote LNS(ex: 64.64.64.64)", NULL
);
3167 return cli_arg_help(cli
, 0,
3168 "PORT", "Port of the remote LNS (ex: 1701)", NULL
);
3171 return cli_arg_help(cli
, 0,
3172 "SECRET", "l2tp secret of the remote LNS (ex: mysecretpsw)", NULL
);
3175 return cli_arg_help(cli
, argc
> 1, NULL
);
3181 cli_error(cli
, "Specify variable and value");
3185 // lac_addremotelns(mask, IP_RemoteLNS, Port_RemoteLNS, SecretRemoteLNS)
3186 ret
= lac_addremotelns(argv
[0], argv
[1], argv
[2], argv
[3]);
3190 cli_print(cli
, "setforward %s %s %s %s", argv
[0], argv
[1], argv
[2], argv
[3]);
3192 cli_print(cli
, "%s Updated, the tunnel must be dropped", argv
[0]);
3195 cli_error(cli
, "ERROR setforward %s %s %s %s", argv
[0], argv
[1], argv
[2], argv
[3]);
3200 static int cmd_show_rmtlnsconf(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3205 if (CLI_HELP_REQUESTED
)
3207 return cli_arg_help(cli
, 0, "remotelns-conf", "Show a list of remote LNS configurations", NULL
);
3210 for (idrlns
= 0; idrlns
< MAXRLNSTUNNEL
; idrlns
++)
3212 if (lac_cli_show_remotelns(idrlns
, strdisp
) != 0)
3213 cli_print(cli
, "%s", strdisp
);