1 // L2TPNS Command Line Interface
4 char const *cvs_name
= "$Name: $";
5 char const *cvs_id_cli
= "$Id: cli.c,v 1.58 2005/05/16 06:01:08 bodea Exp $";
18 #include <arpa/inet.h>
20 #include <sys/socket.h>
21 #include <sys/types.h>
36 extern tunnelt
*tunnel
;
37 extern sessiont
*session
;
38 extern radiust
*radius
;
39 extern ippoolt
*ip_address_pool
;
40 extern struct Tstats
*_statistics
;
41 static struct cli_def
*cli
= NULL
;
42 extern configt
*config
;
43 extern config_descriptt config_values
[];
45 extern struct Tringbuffer
*ringbuffer
;
47 extern struct cli_session_actions
*cli_session_actions
;
48 extern struct cli_tunnel_actions
*cli_tunnel_actions
;
49 extern tbft
*filter_list
;
50 extern ip_filtert
*ip_filters
;
52 static char *debug_levels
[] = {
71 static int debug_session
;
72 static int debug_tunnel
;
73 static int debug_rb_tail
;
75 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
76 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
77 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
78 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
79 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
80 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
81 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
82 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
83 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
84 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
85 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
86 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
87 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
88 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
89 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
90 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
91 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
92 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
93 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
94 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
95 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
96 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
97 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
98 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
99 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
100 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
102 static int regular_stuff(struct cli_def
*cli
);
103 static void parsemac(char *string
, char mac
[6]);
106 #define MODE_CONFIG_BGP 8
107 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
108 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
109 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
110 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
111 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
112 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
113 static int cmd_restart_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
116 #define MODE_CONFIG_NACL 9
117 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
118 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
119 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
120 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
121 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
122 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
);
124 /* match if b is a substr of a */
125 #define MATCH(a,b) (!strncmp((a), (b), strlen(b)))
127 void init_cli(char *hostname
)
131 struct cli_command
*c
;
132 struct cli_command
*c2
;
134 struct sockaddr_in addr
;
137 if (hostname
&& *hostname
)
138 cli_set_hostname(cli
, hostname
);
140 cli_set_hostname(cli
, "l2tpns");
142 c
= cli_register_command(cli
, NULL
, "show", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
143 cli_register_command(cli
, c
, "banana", cmd_show_banana
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a banana");
145 cli_register_command(cli
, c
, "bgp", cmd_show_bgp
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show BGP status");
147 cli_register_command(cli
, c
, "cluster", cmd_show_cluster
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show cluster information");
148 cli_register_command(cli
, c
, "ipcache", cmd_show_ipcache
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show contents of the IP cache");
149 cli_register_command(cli
, c
, "plugins", cmd_show_plugins
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all installed plugins");
150 cli_register_command(cli
, c
, "pool", cmd_show_pool
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the IP address allocation pool");
151 cli_register_command(cli
, c
, "radius", cmd_show_radius
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show active radius queries");
152 cli_register_command(cli
, c
, "running-config", cmd_show_run
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Show the currently running configuration");
153 cli_register_command(cli
, c
, "session", cmd_show_session
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of sessions or details for a single session");
154 cli_register_command(cli
, c
, "tbf", cmd_show_tbf
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all token bucket filters in use");
155 cli_register_command(cli
, c
, "throttle", cmd_show_throttle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "List all throttled sessions and associated TBFs");
156 cli_register_command(cli
, c
, "tunnels", cmd_show_tunnels
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show a list of tunnels or details for a single tunnel");
157 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");
158 cli_register_command(cli
, c
, "version", cmd_show_version
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show currently running software version");
159 cli_register_command(cli
, c
, "access-list", cmd_show_access_list
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show named access-list");
161 c2
= cli_register_command(cli
, c
, "histogram", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
162 cli_register_command(cli
, c2
, "idle", cmd_show_hist_idle
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session idle times");
163 cli_register_command(cli
, c2
, "open", cmd_show_hist_open
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show histogram of session durations");
166 cli_register_command(cli
, c
, "counters", cmd_show_counters
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Display all the internal counters and running totals");
168 c
= cli_register_command(cli
, NULL
, "clear", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
169 cli_register_command(cli
, c
, "counters", cmd_clear_counters
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Clear internal counters");
172 cli_register_command(cli
, NULL
, "uptime", cmd_uptime
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show uptime and bandwidth utilisation");
174 c
= cli_register_command(cli
, NULL
, "write", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
175 cli_register_command(cli
, c
, "memory", cmd_write_memory
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Save the running config to flash");
176 cli_register_command(cli
, c
, "terminal", cmd_show_run
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Show the running config");
178 cli_register_command(cli
, NULL
, "snoop", cmd_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable interception of a session");
179 cli_register_command(cli
, NULL
, "throttle", cmd_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Enable throttling of a session");
180 cli_register_command(cli
, NULL
, "filter", cmd_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Add filtering to a session");
181 cli_register_command(cli
, NULL
, "debug", cmd_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Set the level of logging that is shown on the console");
184 c
= cli_register_command(cli
, NULL
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
185 cli_register_command(cli
, c
, "bgp", cmd_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Withdraw routes from BGP neighbour");
188 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, NULL
);
189 cli_register_command(cli
, c
, "snoop", cmd_no_snoop
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable interception of a session");
190 cli_register_command(cli
, c
, "throttle", cmd_no_throttle
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disable throttling of a session");
191 cli_register_command(cli
, c
, "filter", cmd_no_filter
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Remove filtering from a session");
192 cli_register_command(cli
, c
, "debug", cmd_no_debug
, PRIVILEGE_UNPRIVILEGED
, MODE_EXEC
, "Turn off logging of a certain level of debugging");
195 c2
= cli_register_command(cli
, c
, "suspend", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
196 cli_register_command(cli
, c2
, "bgp", cmd_no_suspend_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Advertise routes to BGP neighbour");
198 c
= cli_register_command(cli
, NULL
, "restart", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
199 cli_register_command(cli
, c
, "bgp", cmd_restart_bgp
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Restart BGP");
201 c
= cli_register_command(cli
, NULL
, "router", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
202 cli_register_command(cli
, c
, "bgp", cmd_router_bgp
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Configure BGP");
204 cli_register_command(cli
, NULL
, "neighbour", cmd_router_bgp_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Configure BGP neighbour");
206 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, NULL
);
207 cli_register_command(cli
, c
, "neighbour", cmd_router_bgp_no_neighbour
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_BGP
, "Remove BGP neighbour");
210 c
= cli_register_command(cli
, NULL
, "drop", NULL
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, NULL
);
211 cli_register_command(cli
, c
, "user", cmd_drop_user
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a user");
212 cli_register_command(cli
, c
, "tunnel", cmd_drop_tunnel
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a tunnel and all sessions on that tunnel");
213 cli_register_command(cli
, c
, "session", cmd_drop_session
, PRIVILEGE_PRIVILEGED
, MODE_EXEC
, "Disconnect a session");
215 c
= cli_register_command(cli
, NULL
, "load", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
216 cli_register_command(cli
, c
, "plugin", cmd_load_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Load a plugin");
218 c
= cli_register_command(cli
, NULL
, "remove", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
219 cli_register_command(cli
, c
, "plugin", cmd_remove_plugin
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove a plugin");
221 cli_register_command(cli
, NULL
, "set", cmd_set
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Set a configuration variable");
223 c
= cli_register_command(cli
, NULL
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
224 cli_register_command(cli
, c
, "access-list", cmd_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Add named access-list");
226 cli_register_command(cli
, NULL
, "permit", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Permit rule");
227 cli_register_command(cli
, NULL
, "deny", cmd_ip_access_list_rule
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG_NACL
, "Deny rule");
229 c
= cli_register_command(cli
, NULL
, "no", NULL
, PRIVILEGE_UNPRIVILEGED
, MODE_CONFIG
, NULL
);
230 c2
= cli_register_command(cli
, c
, "ip", NULL
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, NULL
);
231 cli_register_command(cli
, c2
, "access-list", cmd_no_ip_access_list
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
, "Remove named access-list");
233 // Enable regular processing
234 cli_regular(cli
, regular_stuff
);
236 if (!(f
= fopen(CLIUSERS
, "r")))
238 LOG(0, 0, 0, "WARNING! No users specified. Command-line access is open to all\n");
242 while (fgets(buf
, 4096, f
))
245 if (*buf
== '#') continue;
246 if ((p
= strchr(buf
, '\r'))) *p
= 0;
247 if ((p
= strchr(buf
, '\n'))) *p
= 0;
249 if (!(p
= strchr((char *)buf
, ':'))) continue;
251 if (!strcmp(buf
, "enable"))
253 cli_allow_enable(cli
, p
);
254 LOG(3, 0, 0, "Setting enable password\n");
258 cli_allow_user(cli
, buf
, p
);
259 LOG(3, 0, 0, "Allowing user %s to connect to the CLI\n", buf
);
265 memset(&addr
, 0, sizeof(addr
));
266 clifd
= socket(PF_INET
, SOCK_STREAM
, 6);
267 setsockopt(clifd
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
270 // Set cli fd as non-blocking
271 flags
= fcntl(clifd
, F_GETFL
, 0);
272 fcntl(clifd
, F_SETFL
, flags
| O_NONBLOCK
);
274 addr
.sin_family
= AF_INET
;
275 addr
.sin_port
= htons(23);
276 if (bind(clifd
, (void *) &addr
, sizeof(addr
)) < 0)
278 LOG(0, 0, 0, "Error listening on cli port 23: %s\n", strerror(errno
));
284 void cli_do(int sockfd
)
286 int require_auth
= 1;
287 struct sockaddr_in addr
;
288 int l
= sizeof(addr
);
290 if (fork_and_close()) return;
291 if (getpeername(sockfd
, (struct sockaddr
*)&addr
, &l
) == 0)
293 require_auth
= addr
.sin_addr
.s_addr
!= inet_addr("127.0.0.1");
294 LOG(require_auth
? 3 : 4, 0, 0, "Accepted connection to CLI from %s\n",
295 fmtaddr(addr
.sin_addr
.s_addr
, 0));
298 LOG(0, 0, 0, "getpeername() failed on cli socket. Requiring authentication: %s\n", strerror(errno
));
302 LOG(3, 0, 0, "CLI is remote, requiring authentication\n");
303 if (!cli
->users
) /* paranoia */
305 LOG(0, 0, 0, "No users for remote authentication! Exiting CLI\n");
311 /* no username/pass required */
318 debug_rb_tail
= ringbuffer
->tail
;
320 memset(&debug_flags
, 0, sizeof(debug_flags
));
321 debug_flags
.critical
= 1;
323 cli_loop(cli
, sockfd
);
326 LOG(require_auth
? 3 : 4, 0, 0, "Closed CLI connection from %s\n",
327 fmtaddr(addr
.sin_addr
.s_addr
, 0));
332 static void cli_print_log(struct cli_def
*cli
, char *string
)
334 LOG(3, 0, 0, "%s\n", string
);
337 void cli_do_file(FILE *fh
)
339 LOG(3, 0, 0, "Reading configuration file\n");
340 cli_print_callback(cli
, cli_print_log
);
341 cli_file(cli
, fh
, PRIVILEGE_PRIVILEGED
, MODE_CONFIG
);
342 cli_print_callback(cli
, NULL
);
345 int cli_arg_help(struct cli_def
*cli
, int cr_ok
, char *entry
, ...)
356 if ((p
= strchr(entry
, '%')) && !strchr(p
+1, '%') && p
[1] == 'd')
358 int v
= va_arg(ap
, int);
359 snprintf(buf
, sizeof(buf
), entry
, v
);
365 desc
= va_arg(ap
, char *);
367 cli_error(cli
, " %-20s %s", p
, desc
);
369 cli_error(cli
, " %s", p
);
371 entry
= desc
? va_arg(ap
, char *) : 0;
376 cli_error(cli
, " <cr>");
381 static int cmd_show_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
385 if (CLI_HELP_REQUESTED
)
386 return cli_arg_help(cli
, 1,
387 "<1-%d>", MAXSESSION
-1, "Show specific session by id",
393 // Show individual session
394 for (i
= 0; i
< argc
; i
++)
396 unsigned int s
, b_in
, b_out
;
398 if (s
<= 0 || s
>= MAXSESSION
)
400 cli_print(cli
, "Invalid session id \"%s\"", argv
[i
]);
403 cli_print(cli
, "\r\nSession %d:", s
);
404 cli_print(cli
, "\tUser:\t\t%s", session
[s
].user
[0] ? session
[s
].user
: "none");
405 cli_print(cli
, "\tCalling Num:\t%s", session
[s
].calling
);
406 cli_print(cli
, "\tCalled Num:\t%s", session
[s
].called
);
407 cli_print(cli
, "\tTunnel ID:\t%d", session
[s
].tunnel
);
408 cli_print(cli
, "\tIP address:\t%s", fmtaddr(htonl(session
[s
].ip
), 0));
409 cli_print(cli
, "\tUnique SID:\t%u", session
[s
].unique_id
);
410 cli_print(cli
, "\tIdle time:\t%u seconds", abs(time_now
- session
[s
].last_packet
));
411 cli_print(cli
, "\tNext Recv:\t%u", session
[s
].nr
);
412 cli_print(cli
, "\tNext Send:\t%u", session
[s
].ns
);
413 cli_print(cli
, "\tBytes In/Out:\t%u/%u", session
[s
].total_cout
, session
[s
].total_cin
);
414 cli_print(cli
, "\tPkts In/Out:\t%u/%u", session
[s
].pout
, session
[s
].pin
);
415 cli_print(cli
, "\tMRU:\t\t%d", session
[s
].mru
);
416 cli_print(cli
, "\tRx Speed:\t%u", session
[s
].rx_connect_speed
);
417 cli_print(cli
, "\tTx Speed:\t%u", session
[s
].tx_connect_speed
);
418 if (session
[s
].filter_in
&& session
[s
].filter_in
<= MAXFILTER
)
419 cli_print(cli
, "\tFilter in:\t%u (%s)", session
[s
].filter_in
, ip_filters
[session
[s
].filter_in
- 1].name
);
420 if (session
[s
].filter_out
&& session
[s
].filter_out
<= MAXFILTER
)
421 cli_print(cli
, "\tFilter out:\t%u (%s)", session
[s
].filter_out
, ip_filters
[session
[s
].filter_out
- 1].name
);
422 if (session
[s
].snoop_ip
&& session
[s
].snoop_port
)
423 cli_print(cli
, "\tIntercepted:\t%s:%d", fmtaddr(session
[s
].snoop_ip
, 0), session
[s
] .snoop_port
);
425 cli_print(cli
, "\tIntercepted:\tno");
427 cli_print(cli
, "\tWalled Garden:\t%s", session
[s
].walled_garden
? "YES" : "no");
429 int t
= (session
[s
].throttle_in
|| session
[s
].throttle_out
);
430 cli_print(cli
, "\tThrottled:\t%s%s%.0d%s%s%.0d%s%s",
431 t
? "YES" : "no", t
? " (" : "",
432 session
[s
].throttle_in
, session
[s
].throttle_in
? "kbps" : t
? "-" : "",
434 session
[s
].throttle_out
, session
[s
].throttle_out
? "kbps" : t
? "-" : "",
438 b_in
= session
[s
].tbf_in
;
439 b_out
= session
[s
].tbf_out
;
441 cli_print(cli
, "\t\t\t%5s %6s %6s | %7s %7s %8s %8s %8s %8s",
442 "Rate", "Credit", "Queued", "ByteIn", "PackIn",
443 "ByteSent", "PackSent", "PackDrop", "PackDelay");
446 cli_print(cli
, "\tTBFI#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
448 (filter_list
[b_in
].next
? "*" : " "),
449 (b_in
< 100 ? "\t" : ""),
450 filter_list
[b_in
].rate
* 8,
451 filter_list
[b_in
].credit
,
452 filter_list
[b_in
].queued
,
453 filter_list
[b_in
].b_queued
,
454 filter_list
[b_in
].p_queued
,
455 filter_list
[b_in
].b_sent
,
456 filter_list
[b_in
].p_sent
,
457 filter_list
[b_in
].p_dropped
,
458 filter_list
[b_in
].p_delayed
);
461 cli_print(cli
, "\tTBFO#%d%1s%s\t%5d %6d %6d | %7d %7d %8d %8d %8d %8d",
463 (filter_list
[b_out
].next
? "*" : " "),
464 (b_out
< 100 ? "\t" : ""),
465 filter_list
[b_out
].rate
* 8,
466 filter_list
[b_out
].credit
,
467 filter_list
[b_out
].queued
,
468 filter_list
[b_out
].b_queued
,
469 filter_list
[b_out
].p_queued
,
470 filter_list
[b_out
].b_sent
,
471 filter_list
[b_out
].p_sent
,
472 filter_list
[b_out
].p_dropped
,
473 filter_list
[b_out
].p_delayed
);
480 cli_print(cli
, "%5s %4s %-32s %-15s %s %s %s %s %10s %10s %10s %4s %-15s %s",
496 for (i
= 1; i
< MAXSESSION
; i
++)
498 if (!session
[i
].opened
) continue;
499 cli_print(cli
, "%5d %4d %-32s %-15s %s %s %s %s %10u %10lu %10lu %4u %-15s %s",
502 session
[i
].user
[0] ? session
[i
].user
: "*",
503 fmtaddr(htonl(session
[i
].ip
), 0),
504 (session
[i
].snoop_ip
&& session
[i
].snoop_port
) ? "Y" : "N",
505 (session
[i
].throttle_in
|| session
[i
].throttle_out
) ? "Y" : "N",
506 (session
[i
].walled_garden
) ? "Y" : "N",
507 (session
[i
].flags
& SF_IPV6CP_ACKED
) ? "Y" : "N",
508 abs(time_now
- (unsigned long)session
[i
].opened
),
509 (unsigned long)session
[i
].total_cout
,
510 (unsigned long)session
[i
].total_cin
,
511 abs(time_now
- (session
[i
].last_packet
? session
[i
].last_packet
: time_now
)),
512 fmtaddr(htonl(tunnel
[ session
[i
].tunnel
].ip
), 1),
513 session
[i
].calling
[0] ? session
[i
].calling
: "*");
518 static int cmd_show_tunnels(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
520 int i
, x
, show_all
= 0;
528 if (CLI_HELP_REQUESTED
)
531 return cli_arg_help(cli
, 1,
532 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
535 return cli_arg_help(cli
, 1,
536 "all", "Show all tunnels, including unused",
537 "<1-%d>", MAXTUNNEL
-1, "Show specific tunnel by id",
544 if (strcmp(argv
[0], "all") == 0)
550 // Show individual tunnel
551 for (i
= 0; i
< argc
; i
++)
556 if (t
<= 0 || t
>= MAXTUNNEL
)
558 cli_print(cli
, "Invalid tunnel id \"%s\"", argv
[i
]);
561 cli_print(cli
, "\r\nTunnel %d:", t
);
562 cli_print(cli
, "\tState:\t\t%s", states
[tunnel
[t
].state
]);
563 cli_print(cli
, "\tHostname:\t%s", tunnel
[t
].hostname
[0] ? tunnel
[t
].hostname
: "(none)");
564 cli_print(cli
, "\tRemote IP:\t%s", fmtaddr(htonl(tunnel
[t
].ip
), 0));
565 cli_print(cli
, "\tRemote Port:\t%d", tunnel
[t
].port
);
566 cli_print(cli
, "\tRx Window:\t%u", tunnel
[t
].window
);
567 cli_print(cli
, "\tNext Recv:\t%u", tunnel
[t
].nr
);
568 cli_print(cli
, "\tNext Send:\t%u", tunnel
[t
].ns
);
569 cli_print(cli
, "\tQueue Len:\t%u", tunnel
[t
].controlc
);
570 cli_print(cli
, "\tLast Packet Age:%u", (unsigned)(time_now
- tunnel
[t
].last
));
572 for (x
= 0; x
< MAXSESSION
; x
++)
573 if (session
[x
].tunnel
== t
&& session
[x
].opened
&& !session
[x
].die
)
574 sprintf(s
, "%s%u ", s
, x
);
576 cli_print(cli
, "\tSessions:\t%s", s
);
582 // Show tunnel summary
583 cli_print(cli
, "%4s %20s %20s %6s %s",
590 for (i
= 1; i
< MAXTUNNEL
; i
++)
593 if (!show_all
&& (!tunnel
[i
].ip
|| tunnel
[i
].die
)) continue;
595 for (x
= 0; x
< MAXSESSION
; x
++) if (session
[x
].tunnel
== i
&& session
[x
].opened
&& !session
[x
].die
) sessions
++;
596 cli_print(cli
, "%4d %20s %20s %6s %6d",
598 *tunnel
[i
].hostname
? tunnel
[i
].hostname
: "(null)",
599 fmtaddr(htonl(tunnel
[i
].ip
), 0),
600 states
[tunnel
[i
].state
],
607 static int cmd_show_users(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
614 if (CLI_HELP_REQUESTED
)
615 return cli_arg_help(cli
, 1,
616 "USER", "Show details for specific username",
619 for (i
= 0; i
< MAXSESSION
; i
++)
621 if (!session
[i
].opened
) continue;
622 if (!session
[i
].user
[0]) continue;
626 for (j
= 0; j
< argc
&& sargc
< 32; j
++)
628 if (strcmp(argv
[j
], session
[i
].user
) == 0)
630 snprintf(sid
[sargc
], sizeof(sid
[0]), "%d", i
);
631 sargv
[sargc
] = sid
[sargc
];
639 cli_print(cli
, "%s", session
[i
].user
);
643 return cmd_show_session(cli
, "users", sargv
, sargc
);
648 static int cmd_show_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
650 if (CLI_HELP_REQUESTED
)
651 return CLI_HELP_NO_ARGS
;
653 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Ethernet", "Bytes", "Packets", "Errors", "Dropped");
654 cli_print(cli
, "%-10s %10u %10u %10u %10u", "RX",
655 GET_STAT(tun_rx_bytes
),
656 GET_STAT(tun_rx_packets
),
657 GET_STAT(tun_rx_errors
),
658 GET_STAT(tun_rx_dropped
));
659 cli_print(cli
, "%-10s %10u %10u %10u", "TX",
660 GET_STAT(tun_tx_bytes
),
661 GET_STAT(tun_tx_packets
),
662 GET_STAT(tun_tx_errors
));
665 cli_print(cli
, "%-10s %10s %10s %10s %10s", "Tunnel", "Bytes", "Packets", "Errors", "Retries");
666 cli_print(cli
, "%-10s %10u %10u %10u", "RX",
667 GET_STAT(tunnel_rx_bytes
),
668 GET_STAT(tunnel_rx_packets
),
669 GET_STAT(tunnel_rx_errors
));
670 cli_print(cli
, "%-10s %10u %10u %10u %10u", "TX",
671 GET_STAT(tunnel_tx_bytes
),
672 GET_STAT(tunnel_tx_packets
),
673 GET_STAT(tunnel_tx_errors
),
674 GET_STAT(tunnel_retries
));
677 cli_print(cli
, "%-30s%-10s", "Counter", "Value");
678 cli_print(cli
, "-----------------------------------------");
679 cli_print(cli
, "%-30s%u", "radius_retries", GET_STAT(radius_retries
));
680 cli_print(cli
, "%-30s%u", "arp_sent", GET_STAT(arp_sent
));
681 cli_print(cli
, "%-30s%u", "packets_snooped", GET_STAT(packets_snooped
));
682 cli_print(cli
, "%-30s%u", "tunnel_created", GET_STAT(tunnel_created
));
683 cli_print(cli
, "%-30s%u", "session_created", GET_STAT(session_created
));
684 cli_print(cli
, "%-30s%u", "tunnel_timeout", GET_STAT(tunnel_timeout
));
685 cli_print(cli
, "%-30s%u", "session_timeout", GET_STAT(session_timeout
));
686 cli_print(cli
, "%-30s%u", "radius_timeout", GET_STAT(radius_timeout
));
687 cli_print(cli
, "%-30s%u", "radius_overflow", GET_STAT(radius_overflow
));
688 cli_print(cli
, "%-30s%u", "tunnel_overflow", GET_STAT(tunnel_overflow
));
689 cli_print(cli
, "%-30s%u", "session_overflow", GET_STAT(session_overflow
));
690 cli_print(cli
, "%-30s%u", "ip_allocated", GET_STAT(ip_allocated
));
691 cli_print(cli
, "%-30s%u", "ip_freed", GET_STAT(ip_freed
));
692 cli_print(cli
, "%-30s%u", "cluster_forwarded", GET_STAT(c_forwarded
));
693 cli_print(cli
, "%-30s%u", "recv_forward", GET_STAT(recv_forward
));
694 cli_print(cli
, "%-30s%u", "select_called", GET_STAT(select_called
));
695 cli_print(cli
, "%-30s%u", "multi_read_used", GET_STAT(multi_read_used
));
696 cli_print(cli
, "%-30s%u", "multi_read_exceeded", GET_STAT(multi_read_exceeded
));
700 cli_print(cli
, "\n%-30s%-10s", "Counter", "Value");
701 cli_print(cli
, "-----------------------------------------");
702 cli_print(cli
, "%-30s%u", "call_processtun", GET_STAT(call_processtun
));
703 cli_print(cli
, "%-30s%u", "call_processipout", GET_STAT(call_processipout
));
704 cli_print(cli
, "%-30s%u", "call_processipv6out", GET_STAT(call_processipv6out
));
705 cli_print(cli
, "%-30s%u", "call_processudp", GET_STAT(call_processudp
));
706 cli_print(cli
, "%-30s%u", "call_processpap", GET_STAT(call_processpap
));
707 cli_print(cli
, "%-30s%u", "call_processchap", GET_STAT(call_processchap
));
708 cli_print(cli
, "%-30s%u", "call_processlcp", GET_STAT(call_processlcp
));
709 cli_print(cli
, "%-30s%u", "call_processipcp", GET_STAT(call_processipcp
));
710 cli_print(cli
, "%-30s%u", "call_processipv6cp", GET_STAT(call_processipv6cp
));
711 cli_print(cli
, "%-30s%u", "call_processipin", GET_STAT(call_processipin
));
712 cli_print(cli
, "%-30s%u", "call_processipv6in", GET_STAT(call_processipv6in
));
713 cli_print(cli
, "%-30s%u", "call_processccp", GET_STAT(call_processccp
));
714 cli_print(cli
, "%-30s%u", "call_processrad", GET_STAT(call_processrad
));
715 cli_print(cli
, "%-30s%u", "call_sendarp", GET_STAT(call_sendarp
));
716 cli_print(cli
, "%-30s%u", "call_sendipcp", GET_STAT(call_sendipcp
));
717 cli_print(cli
, "%-30s%u", "call_sendchap", GET_STAT(call_sendchap
));
718 cli_print(cli
, "%-30s%u", "call_sessionbyip", GET_STAT(call_sessionbyip
));
719 cli_print(cli
, "%-30s%u", "call_sessionbyipv6", GET_STAT(call_sessionbyipv6
));
720 cli_print(cli
, "%-30s%u", "call_sessionbyuser", GET_STAT(call_sessionbyuser
));
721 cli_print(cli
, "%-30s%u", "call_tunnelsend", GET_STAT(call_tunnelsend
));
722 cli_print(cli
, "%-30s%u", "call_tunnelkill", GET_STAT(call_tunnelkill
));
723 cli_print(cli
, "%-30s%u", "call_tunnelshutdown", GET_STAT(call_tunnelshutdown
));
724 cli_print(cli
, "%-30s%u", "call_sessionkill", GET_STAT(call_sessionkill
));
725 cli_print(cli
, "%-30s%u", "call_sessionshutdown", GET_STAT(call_sessionshutdown
));
726 cli_print(cli
, "%-30s%u", "call_sessionsetup", GET_STAT(call_sessionsetup
));
727 cli_print(cli
, "%-30s%u", "call_assign_ip_address", GET_STAT(call_assign_ip_address
));
728 cli_print(cli
, "%-30s%u", "call_free_ip_address", GET_STAT(call_free_ip_address
));
729 cli_print(cli
, "%-30s%u", "call_dump_acct_info", GET_STAT(call_dump_acct_info
));
730 cli_print(cli
, "%-30s%u", "call_radiussend", GET_STAT(call_radiussend
));
731 cli_print(cli
, "%-30s%u", "call_radiusretry", GET_STAT(call_radiusretry
));
732 cli_print(cli
, "%-30s%u", "call_random_data", GET_STAT(call_random_data
));
736 time_t l
= GET_STAT(last_reset
);
738 char *p
= strchr(t
, '\n');
742 cli_print(cli
, "Last counter reset %s", t
);
748 static int cmd_show_version(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
754 if (CLI_HELP_REQUESTED
)
755 return cli_arg_help(cli
, 1,
756 "tag", "Include CVS release tag",
757 "file", "Include file versions",
760 for (i
= 0; i
< argc
; i
++)
761 if (!strcmp(argv
[i
], "tag"))
763 else if (!strcmp(argv
[i
], "file"))
766 cli_print(cli
, "L2TPNS %s", VERSION
);
769 char const *p
= strchr(cvs_name
, ':');
781 e
= strpbrk(p
, " \t$");
782 cli_print(cli
, "Tag: %.*s", (int) (e
? e
- p
+ 1 : strlen(p
)), p
);
787 extern linked_list
*loaded_plugins
;
790 cli_print(cli
, "Files:");
791 cli_print(cli
, " %s", cvs_id_arp
);
793 cli_print(cli
, " %s", cvs_id_bgp
);
795 cli_print(cli
, " %s", cvs_id_cli
);
796 cli_print(cli
, " %s", cvs_id_cluster
);
797 cli_print(cli
, " %s", cvs_id_constants
);
798 cli_print(cli
, " %s", cvs_id_control
);
799 cli_print(cli
, " %s", cvs_id_icmp
);
800 cli_print(cli
, " %s", cvs_id_l2tpns
);
801 cli_print(cli
, " %s", cvs_id_ll
);
802 cli_print(cli
, " %s", cvs_id_md5
);
803 cli_print(cli
, " %s", cvs_id_ppp
);
804 cli_print(cli
, " %s", cvs_id_radius
);
805 cli_print(cli
, " %s", cvs_id_tbf
);
806 cli_print(cli
, " %s", cvs_id_util
);
808 ll_reset(loaded_plugins
);
809 while ((p
= ll_next(loaded_plugins
)))
811 char const **id
= dlsym(p
, "cvs_id");
813 cli_print(cli
, " %s", *id
);
820 static int cmd_show_pool(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
823 int used
= 0, free
= 0, show_all
= 0;
825 if (!config
->cluster_iam_master
)
827 cli_print(cli
, "Can't do this on a slave. Do it on %s",
828 fmtaddr(config
->cluster_master_address
, 0));
833 if (CLI_HELP_REQUESTED
)
836 return cli_arg_help(cli
, 1, NULL
);
838 return cli_arg_help(cli
, 1,
839 "all", "Show all pool addresses, including unused",
843 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
847 cli_print(cli
, "%-15s %4s %8s %s", "IP Address", "Used", "Session", "User");
848 for (i
= 0; i
< MAXIPPOOL
; i
++)
850 if (!ip_address_pool
[i
].address
) continue;
851 if (ip_address_pool
[i
].assigned
)
853 cli_print(cli
, "%-15s\tY %8d %s",
854 fmtaddr(htonl(ip_address_pool
[i
].address
), 0),
855 ip_address_pool
[i
].session
,
856 session
[ip_address_pool
[i
].session
].user
);
862 if (ip_address_pool
[i
].last
)
863 cli_print(cli
, "%-15s\tN %8s [%s] %ds",
864 fmtaddr(htonl(ip_address_pool
[i
].address
), 0), "",
865 ip_address_pool
[i
].user
, (int) time_now
- ip_address_pool
[i
].last
);
868 cli_print(cli
, "%-15s\tN", fmtaddr(htonl(ip_address_pool
[i
].address
), 0));
875 cli_print(cli
, "(Not displaying unused addresses)");
877 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
881 static FILE *save_config_fh
= 0;
882 static void print_save_config(struct cli_def
*cli
, char *string
)
885 fprintf(save_config_fh
, "%s\n", string
);
888 static int cmd_write_memory(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
890 if (CLI_HELP_REQUESTED
)
891 return CLI_HELP_NO_ARGS
;
893 if ((save_config_fh
= fopen(config
->config_file
, "w")))
895 cli_print(cli
, "Writing configuration");
896 cli_print_callback(cli
, print_save_config
);
897 cmd_show_run(cli
, command
, argv
, argc
);
898 cli_print_callback(cli
, NULL
);
899 fclose(save_config_fh
);
904 cli_error(cli
, "Error writing configuration: %s", strerror(errno
));
909 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
);
911 static int cmd_show_run(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
914 char ipv6addr
[INET6_ADDRSTRLEN
];
916 if (CLI_HELP_REQUESTED
)
917 return CLI_HELP_NO_ARGS
;
919 cli_print(cli
, "# Current configuration:");
921 for (i
= 0; config_values
[i
].key
; i
++)
923 void *value
= ((void *)config
) + config_values
[i
].offset
;
924 if (config_values
[i
].type
== STRING
)
925 cli_print(cli
, "set %s \"%.*s\"", config_values
[i
].key
, config_values
[i
].size
, (char *) value
);
926 else if (config_values
[i
].type
== IPv4
)
927 cli_print(cli
, "set %s %s", config_values
[i
].key
, fmtaddr(*(in_addr_t
*) value
, 0));
928 else if (config_values
[i
].type
== IPv6
)
929 cli_print(cli
, "set %s %s", config_values
[i
].key
, inet_ntop(AF_INET6
, value
, ipv6addr
, INET6_ADDRSTRLEN
));
930 else if (config_values
[i
].type
== SHORT
)
931 cli_print(cli
, "set %s %hu", config_values
[i
].key
, *(short *) value
);
932 else if (config_values
[i
].type
== BOOL
)
933 cli_print(cli
, "set %s %s", config_values
[i
].key
, (*(int *) value
) ? "yes" : "no");
934 else if (config_values
[i
].type
== INT
)
935 cli_print(cli
, "set %s %d", config_values
[i
].key
, *(int *) value
);
936 else if (config_values
[i
].type
== UNSIGNED_LONG
)
937 cli_print(cli
, "set %s %lu", config_values
[i
].key
, *(unsigned long *) value
);
938 else if (config_values
[i
].type
== MAC
)
939 cli_print(cli
, "set %s %02x%02x.%02x%02x.%02x%02x", config_values
[i
].key
,
940 *(unsigned short *) (value
+ 0),
941 *(unsigned short *) (value
+ 1),
942 *(unsigned short *) (value
+ 2),
943 *(unsigned short *) (value
+ 3),
944 *(unsigned short *) (value
+ 4),
945 *(unsigned short *) (value
+ 5));
948 cli_print(cli
, "# Plugins");
949 for (i
= 0; i
< MAXPLUGINS
; i
++)
951 if (*config
->plugins
[i
])
953 cli_print(cli
, "load plugin \"%s\"", config
->plugins
[i
]);
958 if (config
->as_number
)
963 cli_print(cli
, "# BGP");
964 cli_print(cli
, "router bgp %u", config
->as_number
);
965 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
967 if (!config
->neighbour
[i
].name
[0])
970 cli_print(cli
, " neighbour %s remote-as %u", config
->neighbour
[i
].name
, config
->neighbour
[i
].as
);
972 k
= config
->neighbour
[i
].keepalive
;
973 h
= config
->neighbour
[i
].hold
;
980 k
= BGP_KEEPALIVE_TIME
;
986 cli_print(cli
, " neighbour %s timers %d %d", config
->neighbour
[i
].name
, k
, h
);
991 cli_print(cli
, "# Filters");
992 for (i
= 0; i
< MAXFILTER
; i
++)
994 ip_filter_rulet
*rules
;
995 if (!*ip_filters
[i
].name
)
998 cli_print(cli
, "ip access-list %s %s",
999 ip_filters
[i
].extended
? "extended" : "standard",
1000 ip_filters
[i
].name
);
1002 rules
= ip_filters
[i
].rules
;
1003 while (rules
->action
)
1004 cli_print(cli
, "%s", show_access_list_rule(ip_filters
[i
].extended
, rules
++));
1007 cli_print(cli
, "# end");
1011 static int cmd_show_radius(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1013 int i
, free
= 0, used
= 0, show_all
= 0;
1025 if (CLI_HELP_REQUESTED
)
1028 return cli_arg_help(cli
, 1, NULL
);
1030 return cli_arg_help(cli
, 1,
1031 "all", "Show all RADIUS sessions, including unused",
1035 cli_print(cli
, "%6s%7s%5s%6s%9s%9s%4s", "ID", "Radius", "Sock", "State", "Session", "Retry", "Try");
1039 if (argc
> 0 && strcmp(argv
[0], "all") == 0)
1042 for (i
= 1; i
< MAXRADIUS
; i
++)
1044 if (radius
[i
].state
== RADIUSNULL
)
1049 if (!show_all
&& radius
[i
].state
== RADIUSNULL
) continue;
1051 cli_print(cli
, "%6d%7d%5d%6s%9d%9u%4d",
1055 states
[radius
[i
].state
],
1061 cli_print(cli
, "\r\nFree: %d\r\nUsed: %d", free
, used
);
1066 static int cmd_show_plugins(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1070 if (CLI_HELP_REQUESTED
)
1071 return CLI_HELP_NO_ARGS
;
1073 cli_print(cli
, "Plugins currently loaded:");
1074 for (i
= 0; i
< MAXPLUGINS
; i
++)
1075 if (*config
->plugins
[i
])
1076 cli_print(cli
, " %s", config
->plugins
[i
]);
1081 static int cmd_show_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1085 if (CLI_HELP_REQUESTED
)
1086 return CLI_HELP_NO_ARGS
;
1088 cli_print(cli
, "%5s %4s %-32s %7s %6s %6s %6s",
1097 for (i
= 0; i
< MAXSESSION
; i
++)
1099 if (session
[i
].throttle_in
|| session
[i
].throttle_out
)
1100 cli_print(cli
, "%5d %4d %-32s %6d %6d %6d %6d",
1104 session
[i
].throttle_in
,
1105 session
[i
].throttle_out
,
1107 session
[i
].tbf_out
);
1113 static int cmd_show_banana(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1115 if (CLI_HELP_REQUESTED
)
1116 return CLI_HELP_NO_ARGS
;
1118 cli_print(cli
, " _\n"
1124 " ( \\ `. `-. _,.-:\\\n"
1125 " \\ \\ `. `-._ __..--' ,-';/\n"
1126 " \\ `. `-. `-..___..---' _.--' ,'/\n"
1127 " `. `. `-._ __..--' ,' /\n"
1128 " `. `-_ ``--..'' _.-' ,'\n"
1129 " `-_ `-.___ __,--' ,'\n"
1130 " `-.__ `----\"\"\" __.-'\n"
1131 "hh `--..____..--'");
1136 static int cmd_clear_counters(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1138 if (CLI_HELP_REQUESTED
)
1139 return CLI_HELP_NO_ARGS
;
1141 memset(_statistics
, 0, sizeof(struct Tstats
));
1142 SET_STAT(last_reset
, time(NULL
));
1144 cli_print(cli
, "Counters cleared");
1148 static int cmd_drop_user(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1153 if (CLI_HELP_REQUESTED
)
1154 return cli_arg_help(cli
, argc
> 1,
1155 "USER", "Username of session to drop", NULL
);
1157 if (!config
->cluster_iam_master
)
1159 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1160 fmtaddr(config
->cluster_master_address
, 0));
1167 cli_error(cli
, "Specify a user to drop");
1171 for (i
= 0; i
< argc
; i
++)
1173 if (!(s
= sessionbyuser(argv
[i
])))
1175 cli_error(cli
, "User %s is not connected", argv
[i
]);
1179 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1181 cli_print(cli
, "Dropping user %s", session
[s
].user
);
1182 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1189 static int cmd_drop_tunnel(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1194 if (CLI_HELP_REQUESTED
)
1195 return cli_arg_help(cli
, argc
> 1,
1196 "<1-%d>", MAXTUNNEL
-1, "Tunnel id to drop", NULL
);
1198 if (!config
->cluster_iam_master
)
1200 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1201 fmtaddr(config
->cluster_master_address
, 0));
1208 cli_error(cli
, "Specify a tunnel to drop");
1212 for (i
= 0; i
< argc
; i
++)
1214 if ((t
= atol(argv
[i
])) <= 0 || (t
>= MAXTUNNEL
))
1216 cli_error(cli
, "Invalid tunnel ID (1-%d)", MAXTUNNEL
-1);
1222 cli_error(cli
, "Tunnel %d is not connected", t
);
1228 cli_error(cli
, "Tunnel %d is already being shut down", t
);
1232 cli_print(cli
, "Tunnel %d shut down (%s)", t
, tunnel
[t
].hostname
);
1233 cli_tunnel_actions
[t
].action
|= CLI_TUN_KILL
;
1239 static int cmd_drop_session(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1244 if (CLI_HELP_REQUESTED
)
1245 return cli_arg_help(cli
, argc
> 1,
1246 "<1-%d>", MAXSESSION
-1, "Session id to drop", NULL
);
1248 if (!config
->cluster_iam_master
)
1250 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1251 fmtaddr(config
->cluster_master_address
, 0));
1258 cli_error(cli
, "Specify a session id to drop");
1262 for (i
= 0; i
< argc
; i
++)
1264 if ((s
= atol(argv
[i
])) <= 0 || (s
> MAXSESSION
))
1266 cli_error(cli
, "Invalid session ID (1-%d)", MAXSESSION
-1);
1270 if (session
[s
].ip
&& session
[s
].opened
&& !session
[s
].die
)
1272 cli_print(cli
, "Dropping session %d", s
);
1273 cli_session_actions
[s
].action
|= CLI_SESS_KILL
;
1277 cli_error(cli
, "Session %d is not active.", s
);
1284 static int cmd_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1290 if (CLI_HELP_REQUESTED
)
1295 return cli_arg_help(cli
, 0,
1296 "USER", "Username of session to snoop", NULL
);
1299 return cli_arg_help(cli
, 0,
1300 "A.B.C.D", "IP address of snoop destination", NULL
);
1303 return cli_arg_help(cli
, 0,
1304 "N", "Port of snoop destination", NULL
);
1308 return cli_arg_help(cli
, 1, NULL
);
1315 if (!config
->cluster_iam_master
)
1317 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1318 fmtaddr(config
->cluster_master_address
, 0));
1325 cli_error(cli
, "Specify username, ip and port");
1329 if (!(s
= sessionbyuser(argv
[0])))
1331 cli_error(cli
, "User %s is not connected", argv
[0]);
1335 ip
= inet_addr(argv
[1]);
1336 if (!ip
|| ip
== INADDR_NONE
)
1338 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
1342 port
= atoi(argv
[2]);
1345 cli_error(cli
, "Invalid port %s", argv
[2]);
1349 cli_print(cli
, "Snooping user %s to %s:%d", argv
[0], fmtaddr(ip
, 0), port
);
1350 cli_session_actions
[s
].snoop_ip
= ip
;
1351 cli_session_actions
[s
].snoop_port
= port
;
1352 cli_session_actions
[s
].action
|= CLI_SESS_SNOOP
;
1357 static int cmd_no_snoop(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1362 if (CLI_HELP_REQUESTED
)
1363 return cli_arg_help(cli
, argc
> 1,
1364 "USER", "Username of session to unsnoop", NULL
);
1366 if (!config
->cluster_iam_master
)
1368 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1369 fmtaddr(config
->cluster_master_address
, 0));
1376 cli_error(cli
, "Specify a user to unsnoop");
1380 for (i
= 0; i
< argc
; i
++)
1382 if (!(s
= sessionbyuser(argv
[i
])))
1384 cli_error(cli
, "User %s is not connected", argv
[i
]);
1388 cli_print(cli
, "Not snooping user %s", argv
[i
]);
1389 cli_session_actions
[s
].action
|= CLI_SESS_NOSNOOP
;
1395 static int cmd_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1402 throttle USER - throttle in/out to default rate
1403 throttle USER RATE - throttle in/out to default rate
1404 throttle USER in RATE - throttle input only
1405 throttle USER out RATE - throttle output only
1406 throttle USER in RATE out RATE - throttle both
1409 if (CLI_HELP_REQUESTED
)
1414 return cli_arg_help(cli
, 0,
1415 "USER", "Username of session to throttle", NULL
);
1418 return cli_arg_help(cli
, 1,
1419 "RATE", "Rate in kbps (in and out)",
1420 "in", "Select incoming rate",
1421 "out", "Select outgoing rate", NULL
);
1424 return cli_arg_help(cli
, 1,
1425 "in", "Select incoming rate",
1426 "out", "Select outgoing rate", NULL
);
1429 if (isdigit(argv
[1][0]))
1430 return cli_arg_help(cli
, 1, NULL
);
1433 return cli_arg_help(cli
, 0, "RATE", "Rate in kbps", NULL
);
1436 return cli_arg_help(cli
, argc
> 1, NULL
);
1440 if (!config
->cluster_iam_master
)
1442 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1443 fmtaddr(config
->cluster_master_address
, 0));
1450 cli_error(cli
, "Specify a user to throttle");
1454 if (!(s
= sessionbyuser(argv
[0])))
1456 cli_error(cli
, "User %s is not connected", argv
[0]);
1462 rate_in
= rate_out
= config
->rl_rate
;
1466 rate_in
= rate_out
= atoi(argv
[1]);
1469 cli_error(cli
, "Invalid rate \"%s\"", argv
[1]);
1473 else if (argc
== 3 || argc
== 5)
1476 for (i
= 1; i
< argc
- 1; i
+= 2)
1479 if (MATCH("in", argv
[i
]))
1480 r
= rate_in
= atoi(argv
[i
+1]);
1481 else if (MATCH("out", argv
[i
]))
1482 r
= rate_out
= atoi(argv
[i
+1]);
1486 cli_error(cli
, "Invalid rate specification \"%s %s\"", argv
[i
], argv
[i
+1]);
1493 cli_error(cli
, "Invalid arguments");
1497 if ((rate_in
&& session
[s
].throttle_in
) || (rate_out
&& session
[s
].throttle_out
))
1499 cli_error(cli
, "User %s already throttled, unthrottle first", argv
[0]);
1503 cli_session_actions
[s
].throttle_in
= cli_session_actions
[s
].throttle_out
= -1;
1504 if (rate_in
&& session
[s
].throttle_in
!= rate_in
)
1505 cli_session_actions
[s
].throttle_in
= rate_in
;
1507 if (rate_out
&& session
[s
].throttle_out
!= rate_out
)
1508 cli_session_actions
[s
].throttle_out
= rate_out
;
1510 if (cli_session_actions
[s
].throttle_in
== -1 &&
1511 cli_session_actions
[s
].throttle_out
== -1)
1513 cli_error(cli
, "User %s already throttled at this rate", argv
[0]);
1517 cli_print(cli
, "Throttling user %s", argv
[0]);
1518 cli_session_actions
[s
].action
|= CLI_SESS_THROTTLE
;
1523 static int cmd_no_throttle(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1528 if (CLI_HELP_REQUESTED
)
1529 return cli_arg_help(cli
, argc
> 1,
1530 "USER", "Username of session to unthrottle", NULL
);
1532 if (!config
->cluster_iam_master
)
1534 cli_error(cli
, "Can't do this on a slave. Do it on %s",
1535 fmtaddr(config
->cluster_master_address
, 0));
1542 cli_error(cli
, "Specify a user to unthrottle");
1546 for (i
= 0; i
< argc
; i
++)
1548 if (!(s
= sessionbyuser(argv
[i
])))
1550 cli_error(cli
, "User %s is not connected", argv
[i
]);
1554 if (session
[s
].throttle_in
|| session
[s
].throttle_out
)
1556 cli_print(cli
, "Unthrottling user %s", argv
[i
]);
1557 cli_session_actions
[s
].action
|= CLI_SESS_NOTHROTTLE
;
1561 cli_error(cli
, "User %s not throttled", argv
[i
]);
1568 static int cmd_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1572 if (CLI_HELP_REQUESTED
)
1573 return cli_arg_help(cli
, 1,
1574 "all", "Enable debugging for all except \"data\"",
1575 "critical", "", // FIXME: add descriptions
1585 char *p
= (char *) &debug_flags
;
1586 for (i
= 0; i
< sizeof(debug_flags
); i
++)
1590 cli_print(cli
, "Currently debugging:%s%s%s%s%s%s",
1591 (debug_flags
.critical
) ? " critical" : "",
1592 (debug_flags
.error
) ? " error" : "",
1593 (debug_flags
.warning
) ? " warning" : "",
1594 (debug_flags
.info
) ? " info" : "",
1595 (debug_flags
.calls
) ? " calls" : "",
1596 (debug_flags
.data
) ? " data" : "");
1602 cli_print(cli
, "Debugging off");
1606 for (i
= 0; i
< argc
; i
++)
1608 int len
= strlen(argv
[i
]);
1610 if (argv
[i
][0] == 'c' && len
< 2)
1611 len
= 2; /* distinguish [cr]itical from [ca]lls */
1613 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 1; continue; }
1614 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 1; continue; }
1615 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 1; continue; }
1616 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 1; continue; }
1617 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 1; continue; }
1618 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 1; continue; }
1619 if (!strncmp("all", argv
[i
], len
))
1621 memset(&debug_flags
, 1, sizeof(debug_flags
));
1622 debug_flags
.data
= 0;
1626 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1632 static int cmd_no_debug(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1636 if (CLI_HELP_REQUESTED
)
1637 return cli_arg_help(cli
, 1,
1638 "all", "Disable all debugging",
1639 "critical", "", // FIXME: add descriptions
1649 memset(&debug_flags
, 0, sizeof(debug_flags
));
1653 for (i
= 0; i
< argc
; i
++)
1655 int len
= strlen(argv
[i
]);
1657 if (argv
[i
][0] == 'c' && len
< 2)
1658 len
= 2; /* distinguish [cr]itical from [ca]lls */
1660 if (!strncmp("critical", argv
[i
], len
)) { debug_flags
.critical
= 0; continue; }
1661 if (!strncmp("error", argv
[i
], len
)) { debug_flags
.error
= 0; continue; }
1662 if (!strncmp("warning", argv
[i
], len
)) { debug_flags
.warning
= 0; continue; }
1663 if (!strncmp("info", argv
[i
], len
)) { debug_flags
.info
= 0; continue; }
1664 if (!strncmp("calls", argv
[i
], len
)) { debug_flags
.calls
= 0; continue; }
1665 if (!strncmp("data", argv
[i
], len
)) { debug_flags
.data
= 0; continue; }
1666 if (!strncmp("all", argv
[i
], len
))
1668 memset(&debug_flags
, 0, sizeof(debug_flags
));
1672 cli_error(cli
, "Invalid debugging flag \"%s\"", argv
[i
]);
1678 static int cmd_load_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1680 int i
, firstfree
= 0;
1682 if (CLI_HELP_REQUESTED
)
1683 return cli_arg_help(cli
, argc
> 1,
1684 "PLUGIN", "Name of plugin to load", NULL
);
1688 cli_error(cli
, "Specify a plugin to load");
1692 for (i
= 0; i
< MAXPLUGINS
; i
++)
1694 if (!*config
->plugins
[i
] && !firstfree
)
1696 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1698 cli_error(cli
, "Plugin is already loaded");
1705 strncpy(config
->plugins
[firstfree
], argv
[0], sizeof(config
->plugins
[firstfree
]) - 1);
1706 config
->reload_config
= 1;
1707 cli_print(cli
, "Loading plugin %s", argv
[0]);
1713 static int cmd_remove_plugin(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1717 if (CLI_HELP_REQUESTED
)
1718 return cli_arg_help(cli
, argc
> 1,
1719 "PLUGIN", "Name of plugin to unload", NULL
);
1723 cli_error(cli
, "Specify a plugin to remove");
1727 for (i
= 0; i
< MAXPLUGINS
; i
++)
1729 if (strcmp(config
->plugins
[i
], argv
[0]) == 0)
1731 config
->reload_config
= 1;
1732 memset(config
->plugins
[i
], 0, sizeof(config
->plugins
[i
]));
1737 cli_error(cli
, "Plugin is not loaded");
1741 static char *duration(time_t secs
)
1743 static char *buf
= NULL
;
1746 if (!buf
) buf
= calloc(64, 1);
1750 int days
= secs
/ 86400;
1751 p
= sprintf(buf
, "%d day%s, ", days
, days
> 1 ? "s" : "");
1757 int mins
= secs
/ 60;
1758 int hrs
= mins
/ 60;
1761 sprintf(buf
+ p
, "%d:%02d", hrs
, mins
);
1763 else if (secs
>= 60)
1765 int mins
= secs
/ 60;
1766 sprintf(buf
+ p
, "%d min%s", mins
, mins
> 1 ? "s" : "");
1769 sprintf(buf
, "%ld sec%s", secs
, secs
> 1 ? "s" : "");
1774 static int cmd_uptime(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1777 char buf
[100], *p
= buf
, *loads
[3];
1778 int i
, num_sessions
= 0;
1780 if (CLI_HELP_REQUESTED
)
1781 return CLI_HELP_NO_ARGS
;
1783 fh
= fopen("/proc/loadavg", "r");
1784 fgets(buf
, 100, fh
);
1787 for (i
= 0; i
< 3; i
++)
1788 loads
[i
] = strdup(strsep(&p
, " "));
1791 strftime(buf
, 99, "%H:%M:%S", localtime(&time_now
));
1793 for (i
= 1; i
< MAXSESSION
; i
++)
1794 if (session
[i
].opened
) num_sessions
++;
1796 cli_print(cli
, "%s up %s, %d users, load average: %s, %s, %s",
1798 duration(time_now
- config
->start_time
),
1800 loads
[0], loads
[1], loads
[2]
1802 for (i
= 0; i
< 3; i
++)
1803 if (loads
[i
]) free(loads
[i
]);
1805 cli_print(cli
, "Bandwidth: %s", config
->bandwidth
);
1810 static int cmd_set(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1814 if (CLI_HELP_REQUESTED
)
1820 int len
= strlen(argv
[0])-1;
1821 for (i
= 0; config_values
[i
].key
; i
++)
1822 if (!len
|| !strncmp(config_values
[i
].key
, argv
[0], len
))
1823 cli_error(cli
, " %s", config_values
[i
].key
);
1829 return cli_arg_help(cli
, 0,
1830 "VALUE", "Value for variable", NULL
);
1834 return cli_arg_help(cli
, 1, NULL
);
1843 cli_error(cli
, "Specify variable and value");
1847 for (i
= 0; config_values
[i
].key
; i
++)
1849 void *value
= ((void *) config
) + config_values
[i
].offset
;
1850 if (strcmp(config_values
[i
].key
, argv
[0]) == 0)
1852 // Found a value to set
1853 cli_print(cli
, "Setting \"%s\" to \"%s\"", argv
[0], argv
[1]);
1854 switch (config_values
[i
].type
)
1857 snprintf((char *) value
, config_values
[i
].size
, "%s", argv
[1]);
1860 *(int *) value
= atoi(argv
[1]);
1863 *(unsigned long *) value
= atol(argv
[1]);
1866 *(short *) value
= atoi(argv
[1]);
1869 *(in_addr_t
*) value
= inet_addr(argv
[1]);
1872 inet_pton(AF_INET6
, argv
[1], value
);
1875 parsemac(argv
[1], (char *)value
);
1878 if (strcasecmp(argv
[1], "yes") == 0 || strcasecmp(argv
[1], "true") == 0 || strcasecmp(argv
[1], "1") == 0)
1884 cli_error(cli
, "Unknown variable type");
1887 config
->reload_config
= 1;
1892 cli_error(cli
, "Unknown variable \"%s\"", argv
[0]);
1896 int regular_stuff(struct cli_def
*cli
)
1902 for (i
= debug_rb_tail
; i
!= ringbuffer
->tail
; i
= (i
+ 1) % RINGBUFFER_SIZE
)
1904 char *m
= ringbuffer
->buffer
[i
].message
;
1910 switch (ringbuffer
->buffer
[i
].level
)
1912 case 0: show
= debug_flags
.critical
; break;
1913 case 1: show
= debug_flags
.error
; break;
1914 case 2: show
= debug_flags
.warning
; break;
1915 case 3: show
= debug_flags
.info
; break;
1916 case 4: show
= debug_flags
.calls
; break;
1917 case 5: show
= debug_flags
.data
; break;
1920 if (!show
) continue;
1922 if (!(p
= strchr(m
, '\n')))
1925 cli_error(cli
, "\r%s-%u-%u %.*s",
1926 debug_levels
[(int)ringbuffer
->buffer
[i
].level
],
1927 ringbuffer
->buffer
[i
].tunnel
,
1928 ringbuffer
->buffer
[i
].session
,
1934 debug_rb_tail
= ringbuffer
->tail
;
1942 static int cmd_router_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
1946 if (CLI_HELP_REQUESTED
)
1947 return cli_arg_help(cli
, argc
> 1,
1948 "<1-65535>", "Autonomous system number", NULL
);
1950 if (argc
!= 1 || (as
= atoi(argv
[0])) < 1 || as
> 65535)
1952 cli_error(cli
, "Invalid autonomous system number");
1956 if (bgp_configured
&& as
!= config
->as_number
)
1958 cli_error(cli
, "Can't change local AS on a running system");
1962 config
->as_number
= as
;
1963 cli_set_configmode(cli
, MODE_CONFIG_BGP
, "router");
1968 static int find_bgp_neighbour(char const *name
)
1973 in_addr_t addrs
[4] = { 0 };
1976 if (!(h
= gethostbyname(name
)) || h
->h_addrtype
!= AF_INET
)
1979 for (i
= 0; i
< sizeof(addrs
) / sizeof(*addrs
) && h
->h_addr_list
[i
]; i
++)
1980 memcpy(&addrs
[i
], h
->h_addr_list
[i
], sizeof(*addrs
));
1982 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
1984 if (!config
->neighbour
[i
].name
[0])
1986 if (new == -1) new = i
;
1990 if (!strcmp(name
, config
->neighbour
[i
].name
))
1993 if (!(h
= gethostbyname(config
->neighbour
[i
].name
)) || h
->h_addrtype
!= AF_INET
)
1996 for (a
= h
->h_addr_list
; *a
; a
++)
1999 for (j
= 0; j
< sizeof(addrs
) / sizeof(*addrs
) && addrs
[j
]; j
++)
2000 if (!memcmp(&addrs
[j
], *a
, sizeof(*addrs
)))
2008 static int cmd_router_bgp_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2014 if (CLI_HELP_REQUESTED
)
2019 return cli_arg_help(cli
, 0,
2020 "A.B.C.D", "BGP neighbour address",
2021 "NAME", "BGP neighbour name",
2025 return cli_arg_help(cli
, 0,
2026 "remote-as", "Set remote autonomous system number",
2027 "timers", "Set timers",
2031 if (MATCH("remote-as", argv
[1]))
2032 return cli_arg_help(cli
, argv
[2][1], "<1-65535>", "Autonomous system number", NULL
);
2034 if (MATCH("timers", argv
[1]))
2037 return cli_arg_help(cli
, 0, "<1-65535>", "Keepalive time", NULL
);
2040 return cli_arg_help(cli
, argv
[3][1], "<3-65535>", "Hold time", NULL
);
2042 if (argc
== 5 && !argv
[4][1])
2043 return cli_arg_help(cli
, 1, NULL
);
2052 cli_error(cli
, "Invalid arguments");
2056 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2058 cli_error(cli
, "Invalid neighbour");
2064 cli_error(cli
, "Too many neighbours (max %d)", BGP_NUM_PEERS
);
2068 if (MATCH("remote-as", argv
[1]))
2070 int as
= atoi(argv
[2]);
2071 if (as
< 0 || as
> 65535)
2073 cli_error(cli
, "Invalid autonomous system number");
2077 if (!config
->neighbour
[i
].name
[0])
2079 snprintf(config
->neighbour
[i
].name
, sizeof(config
->neighbour
[i
].name
), "%s", argv
[0]);
2080 config
->neighbour
[i
].keepalive
= -1;
2081 config
->neighbour
[i
].hold
= -1;
2084 config
->neighbour
[i
].as
= as
;
2088 if (argc
!= 4 || !MATCH("timers", argv
[1]))
2090 cli_error(cli
, "Invalid arguments");
2094 if (!config
->neighbour
[i
].name
[0])
2096 cli_error(cli
, "Specify remote-as first");
2100 keepalive
= atoi(argv
[2]);
2101 hold
= atoi(argv
[3]);
2103 if (keepalive
< 1 || keepalive
> 65535)
2105 cli_error(cli
, "Invalid keepalive time");
2109 if (hold
< 3 || hold
> 65535)
2111 cli_error(cli
, "Invalid hold time");
2115 if (keepalive
== BGP_KEEPALIVE_TIME
)
2116 keepalive
= -1; // using default value
2118 if (hold
== BGP_HOLD_TIME
)
2121 config
->neighbour
[i
].keepalive
= keepalive
;
2122 config
->neighbour
[i
].hold
= hold
;
2127 static int cmd_router_bgp_no_neighbour(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2131 if (CLI_HELP_REQUESTED
)
2132 return cli_arg_help(cli
, argc
> 0,
2133 "A.B.C.D", "BGP neighbour address",
2134 "NAME", "BGP neighbour name",
2139 cli_error(cli
, "Specify a BGP neighbour");
2143 if ((i
= find_bgp_neighbour(argv
[0])) == -2)
2145 cli_error(cli
, "Invalid neighbour");
2149 if (i
< 0 || !config
->neighbour
[i
].name
[0])
2151 cli_error(cli
, "Neighbour %s not configured", argv
[0]);
2155 memset(&config
->neighbour
[i
], 0, sizeof(config
->neighbour
[i
]));
2159 static int cmd_show_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2165 if (!bgp_configured
)
2168 if (CLI_HELP_REQUESTED
)
2169 return cli_arg_help(cli
, 1,
2170 "A.B.C.D", "BGP neighbour address",
2171 "NAME", "BGP neighbour name",
2174 cli_print(cli
, "BGPv%d router identifier %s, local AS number %d",
2175 BGP_VERSION
, fmtaddr(my_address
, 0), (int) config
->as_number
);
2179 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2181 if (!*bgp_peers
[i
].name
)
2184 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2185 if (argc
&& strcmp(addr
, argv
[0]) &&
2186 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2192 cli_print(cli
, "Peer AS Address "
2193 "State Retries Retry in Route Pend Timers");
2194 cli_print(cli
, "------------------ ----- --------------- "
2195 "----------- ------- -------- ----- ---- ---------");
2198 cli_print(cli
, "%-18.18s %5d %15s %-11s %7d %7lds %5s %4s %4d %4d",
2202 bgp_state_str(bgp_peers
[i
].state
),
2203 bgp_peers
[i
].retry_count
,
2204 bgp_peers
[i
].retry_time
? bgp_peers
[i
].retry_time
- time_now
: 0,
2205 bgp_peers
[i
].routing
? "yes" : "no",
2206 bgp_peers
[i
].update_routes
? "yes" : "no",
2207 bgp_peers
[i
].keepalive
,
2214 static int cmd_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2219 if (!bgp_configured
)
2222 if (CLI_HELP_REQUESTED
)
2223 return cli_arg_help(cli
, 1,
2224 "A.B.C.D", "BGP neighbour address",
2225 "NAME", "BGP neighbour name",
2228 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2230 if (bgp_peers
[i
].state
!= Established
)
2233 if (!bgp_peers
[i
].routing
)
2236 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2237 if (argc
&& strcmp(addr
, argv
[0]) && strcmp(bgp_peers
[i
].name
, argv
[0]))
2240 bgp_peers
[i
].cli_flag
= BGP_CLI_SUSPEND
;
2241 cli_print(cli
, "Suspending peer %s", bgp_peers
[i
].name
);
2247 static int cmd_no_suspend_bgp(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2252 if (!bgp_configured
)
2255 if (CLI_HELP_REQUESTED
)
2256 return cli_arg_help(cli
, 1,
2257 "A.B.C.D", "BGP neighbour address",
2258 "NAME", "BGP neighbour name",
2261 for (i
= 0; i
< BGP_NUM_PEERS
; i
++)
2263 if (bgp_peers
[i
].state
!= Established
)
2266 if (bgp_peers
[i
].routing
)
2269 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2270 if (argc
&& strcmp(addr
, argv
[0]) &&
2271 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2274 bgp_peers
[i
].cli_flag
= BGP_CLI_ENABLE
;
2275 cli_print(cli
, "Un-suspending peer %s", bgp_peers
[i
].name
);
2281 static int cmd_restart_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
].name
)
2300 addr
= fmtaddr(bgp_peers
[i
].addr
, 0);
2301 if (argc
&& strcmp(addr
, argv
[0]) &&
2302 strncmp(bgp_peers
[i
].name
, argv
[0], strlen(argv
[0])))
2305 bgp_peers
[i
].cli_flag
= BGP_CLI_RESTART
;
2306 cli_print(cli
, "Restarting peer %s", bgp_peers
[i
].name
);
2314 static int find_access_list(char const *name
)
2318 for (i
= 0; i
< MAXFILTER
; i
++)
2319 if (!(*ip_filters
[i
].name
&& strcmp(ip_filters
[i
].name
, name
)))
2325 static int access_list(struct cli_def
*cli
, char **argv
, int argc
, int add
)
2329 if (CLI_HELP_REQUESTED
)
2334 return cli_arg_help(cli
, 0,
2335 "standard", "Standard syntax",
2336 "extended", "Extended syntax",
2340 return cli_arg_help(cli
, argv
[1][1],
2341 "NAME", "Access-list name",
2345 if (argc
== 3 && !argv
[2][1])
2346 return cli_arg_help(cli
, 1, NULL
);
2354 cli_error(cli
, "Specify access-list type and name");
2358 if (MATCH("standard", argv
[0]))
2360 else if (MATCH("extended", argv
[0]))
2364 cli_error(cli
, "Invalid access-list type");
2368 if (strlen(argv
[1]) > sizeof(ip_filters
[0].name
) - 1 ||
2369 strspn(argv
[1], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-") != strlen(argv
[1]))
2371 cli_error(cli
, "Invalid access-list name");
2375 filt
= find_access_list(argv
[1]);
2380 cli_error(cli
, "Too many access-lists");
2385 if (!*ip_filters
[filt
].name
)
2387 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2388 strcpy(ip_filters
[filt
].name
, argv
[1]);
2389 ip_filters
[filt
].extended
= extended
;
2391 else if (ip_filters
[filt
].extended
!= extended
)
2393 cli_error(cli
, "Access-list is %s",
2394 ip_filters
[filt
].extended
? "extended" : "standard");
2399 cli_set_configmode(cli
, MODE_CONFIG_NACL
, extended
? "ext-nacl" : "std-nacl");
2403 if (filt
< 0 || !*ip_filters
[filt
].name
)
2405 cli_error(cli
, "Access-list not defined");
2410 if (ip_filters
[filt
].used
)
2412 cli_error(cli
, "Access-list in use");
2416 memset(&ip_filters
[filt
], 0, sizeof(ip_filters
[filt
]));
2420 static int cmd_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2422 return access_list(cli
, argv
, argc
, 1);
2425 static int cmd_no_ip_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2427 return access_list(cli
, argv
, argc
, 0);
2430 static int show_ip_wild(char *buf
, in_addr_t ip
, in_addr_t wild
)
2432 if (ip
== INADDR_ANY
&& wild
== INADDR_BROADCAST
)
2433 return sprintf(buf
, " any");
2435 if (wild
== INADDR_ANY
)
2436 return sprintf(buf
, " host %s", fmtaddr(ip
, 0));
2438 return sprintf(buf
, " %s %s", fmtaddr(ip
, 0), fmtaddr(wild
, 1));
2441 static int show_ports(char *buf
, ip_filter_portt
*ports
)
2445 case FILTER_PORT_OP_EQ
: return sprintf(buf
, " eq %u", ports
->port
);
2446 case FILTER_PORT_OP_NEQ
: return sprintf(buf
, " neq %u", ports
->port
);
2447 case FILTER_PORT_OP_GT
: return sprintf(buf
, " gt %u", ports
->port
);
2448 case FILTER_PORT_OP_LT
: return sprintf(buf
, " lt %u", ports
->port
);
2449 case FILTER_PORT_OP_RANGE
: return sprintf(buf
, " range %u %u", ports
->port
, ports
->port2
);
2455 static char const *show_access_list_rule(int extended
, ip_filter_rulet
*rule
)
2457 static char buf
[256];
2460 p
+= sprintf(p
, " %s", rule
->action
== FILTER_ACTION_PERMIT
? "permit" : "deny");
2463 struct protoent
*proto
= getprotobynumber(rule
->proto
);
2464 p
+= sprintf(p
, " %s", proto
? proto
->p_name
: "ERR");
2467 p
+= show_ip_wild(p
, rule
->src_ip
, rule
->src_wild
);
2471 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2472 p
+= show_ports(p
, &rule
->src_ports
);
2474 p
+= show_ip_wild(p
, rule
->dst_ip
, rule
->dst_wild
);
2475 if (rule
->proto
== IPPROTO_TCP
|| rule
->proto
== IPPROTO_UDP
)
2476 p
+= show_ports(p
, &rule
->dst_ports
);
2478 if (rule
->proto
== IPPROTO_TCP
&& rule
->tcp_flag_op
)
2480 switch (rule
->tcp_flag_op
)
2482 case FILTER_FLAG_OP_EST
:
2483 p
+= sprintf(p
, " established");
2486 case FILTER_FLAG_OP_ANY
:
2487 case FILTER_FLAG_OP_ALL
:
2488 p
+= sprintf(p
, " match-%s", rule
->tcp_flag_op
== FILTER_FLAG_OP_ALL
? "all" : "any");
2489 if (rule
->tcp_sflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " +fin");
2490 if (rule
->tcp_cflags
& TCP_FLAG_FIN
) p
+= sprintf(p
, " -fin");
2491 if (rule
->tcp_sflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " +syn");
2492 if (rule
->tcp_cflags
& TCP_FLAG_SYN
) p
+= sprintf(p
, " -syn");
2493 if (rule
->tcp_sflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " +rst");
2494 if (rule
->tcp_cflags
& TCP_FLAG_RST
) p
+= sprintf(p
, " -rst");
2495 if (rule
->tcp_sflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " +psh");
2496 if (rule
->tcp_cflags
& TCP_FLAG_PSH
) p
+= sprintf(p
, " -psh");
2497 if (rule
->tcp_sflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " +ack");
2498 if (rule
->tcp_cflags
& TCP_FLAG_ACK
) p
+= sprintf(p
, " -ack");
2499 if (rule
->tcp_sflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " +urg");
2500 if (rule
->tcp_cflags
& TCP_FLAG_URG
) p
+= sprintf(p
, " -urg");
2506 p
+= sprintf(p
, " fragments");
2511 static ip_filter_rulet
*access_list_rule_ext(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2513 static ip_filter_rulet rule
;
2514 struct in_addr addr
;
2518 if (CLI_HELP_REQUESTED
)
2522 cli_arg_help(cli
, 0,
2523 "ip", "Match IP packets",
2524 "tcp", "Match TCP packets",
2525 "udp", "Match UDP packets",
2531 // *sigh*, too darned complex
2532 cli_arg_help(cli
, 0, "RULE", "SOURCE [PORTS] DEST [PORTS] FLAGS", NULL
);
2538 cli_error(cli
, "Specify rule details");
2542 memset(&rule
, 0, sizeof(rule
));
2543 rule
.action
= (command
[0] == 'p')
2544 ? FILTER_ACTION_PERMIT
2545 : FILTER_ACTION_DENY
;
2547 if (MATCH("ip", argv
[0]))
2548 rule
.proto
= IPPROTO_IP
;
2549 else if (MATCH("udp", argv
[0]))
2550 rule
.proto
= IPPROTO_UDP
;
2551 else if (MATCH("tcp", argv
[0]))
2552 rule
.proto
= IPPROTO_TCP
;
2555 cli_error(cli
, "Invalid protocol \"%s\"", argv
[0]);
2559 for (a
= 1, i
= 0; i
< 2; i
++)
2563 ip_filter_portt
*port
;
2568 wild
= &rule
.src_wild
;
2569 port
= &rule
.src_ports
;
2574 wild
= &rule
.dst_wild
;
2575 port
= &rule
.dst_ports
;
2578 cli_error(cli
, "Specify destination");
2583 if (MATCH("any", argv
[a
]))
2586 *wild
= INADDR_BROADCAST
;
2589 else if (MATCH("host", argv
[a
]))
2593 cli_error(cli
, "Specify host ip address");
2597 if (!inet_aton(argv
[a
], &addr
))
2599 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2611 cli_error(cli
, "Specify %s ip address and wildcard", i
? "destination" : "source");
2615 if (!inet_aton(argv
[a
], &addr
))
2617 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2623 if (!inet_aton(argv
[++a
], &addr
))
2625 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[a
]);
2629 *wild
= addr
.s_addr
;
2633 if (rule
.proto
== IPPROTO_IP
|| a
>= argc
)
2637 if (MATCH("eq", argv
[a
]))
2638 port
->op
= FILTER_PORT_OP_EQ
;
2639 else if (MATCH("neq", argv
[a
]))
2640 port
->op
= FILTER_PORT_OP_NEQ
;
2641 else if (MATCH("gt", argv
[a
]))
2642 port
->op
= FILTER_PORT_OP_GT
;
2643 else if (MATCH("lt", argv
[a
]))
2644 port
->op
= FILTER_PORT_OP_LT
;
2645 else if (MATCH("range", argv
[a
]))
2646 port
->op
= FILTER_PORT_OP_RANGE
;
2653 cli_error(cli
, "Specify port");
2657 if (!(port
->port
= atoi(argv
[a
])))
2659 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2664 if (port
->op
!= FILTER_PORT_OP_RANGE
)
2669 cli_error(cli
, "Specify port");
2673 if (!(port
->port2
= atoi(argv
[a
])) || port
->port2
< port
->port
)
2675 cli_error(cli
, "Invalid port \"%s\"", argv
[a
]);
2682 if (rule
.proto
== IPPROTO_TCP
&& a
< argc
)
2684 if (MATCH("established", argv
[a
]))
2686 rule
.tcp_flag_op
= FILTER_FLAG_OP_EST
;
2689 else if (!strcmp(argv
[a
], "match-any") || !strcmp(argv
[a
], "match-an") ||
2690 !strcmp(argv
[a
], "match-all") || !strcmp(argv
[a
], "match-al"))
2692 rule
.tcp_flag_op
= argv
[a
][7] == 'n'
2693 ? FILTER_FLAG_OP_ANY
2694 : FILTER_FLAG_OP_ALL
;
2698 cli_error(cli
, "Specify tcp flags");
2702 while (a
< argc
&& (argv
[a
][0] == '+' || argv
[a
][0] == '-'))
2706 f
= (argv
[a
][0] == '+') ? &rule
.tcp_sflags
: &rule
.tcp_cflags
;
2708 if (MATCH("fin", &argv
[a
][1])) *f
|= TCP_FLAG_FIN
;
2709 else if (MATCH("syn", &argv
[a
][1])) *f
|= TCP_FLAG_SYN
;
2710 else if (MATCH("rst", &argv
[a
][1])) *f
|= TCP_FLAG_RST
;
2711 else if (MATCH("psh", &argv
[a
][1])) *f
|= TCP_FLAG_PSH
;
2712 else if (MATCH("ack", &argv
[a
][1])) *f
|= TCP_FLAG_ACK
;
2713 else if (MATCH("urg", &argv
[a
][1])) *f
|= TCP_FLAG_URG
;
2716 cli_error(cli
, "Invalid tcp flag \"%s\"", argv
[a
]);
2725 if (a
< argc
&& MATCH("fragments", argv
[a
]))
2727 if (rule
.src_ports
.op
|| rule
.dst_ports
.op
|| rule
.tcp_flag_op
)
2729 cli_error(cli
, "Can't specify \"fragments\" on rules with layer 4 matches");
2739 cli_error(cli
, "Invalid flag \"%s\"", argv
[a
]);
2746 static ip_filter_rulet
*access_list_rule_std(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2748 static ip_filter_rulet rule
;
2749 struct in_addr addr
;
2751 if (CLI_HELP_REQUESTED
)
2755 cli_arg_help(cli
, argv
[0][1],
2756 "A.B.C.D", "Source address",
2757 "any", "Any source address",
2758 "host", "Source host",
2764 if (MATCH("any", argv
[0]))
2766 if (argc
== 2 && !argv
[1][1])
2767 cli_arg_help(cli
, 1, NULL
);
2769 else if (MATCH("host", argv
[0]))
2773 cli_arg_help(cli
, argv
[1][1],
2774 "A.B.C.D", "Host address",
2777 else if (argc
== 3 && !argv
[2][1])
2778 cli_arg_help(cli
, 1, NULL
);
2784 cli_arg_help(cli
, 1,
2785 "A.B.C.D", "Wildcard bits",
2788 else if (argc
== 3 && !argv
[2][1])
2789 cli_arg_help(cli
, 1, NULL
);
2797 cli_error(cli
, "Specify rule details");
2801 memset(&rule
, 0, sizeof(rule
));
2802 rule
.action
= (command
[0] == 'p')
2803 ? FILTER_ACTION_PERMIT
2804 : FILTER_ACTION_DENY
;
2806 rule
.proto
= IPPROTO_IP
;
2807 if (MATCH("any", argv
[0]))
2809 rule
.src_ip
= INADDR_ANY
;
2810 rule
.src_wild
= INADDR_BROADCAST
;
2812 else if (MATCH("host", argv
[0]))
2816 cli_error(cli
, "Specify host ip address");
2820 if (!inet_aton(argv
[1], &addr
))
2822 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2826 rule
.src_ip
= addr
.s_addr
;
2827 rule
.src_wild
= INADDR_ANY
;
2833 cli_error(cli
, "Specify source ip address and wildcard");
2837 if (!inet_aton(argv
[0], &addr
))
2839 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[0]);
2843 rule
.src_ip
= addr
.s_addr
;
2847 if (!inet_aton(argv
[1], &addr
))
2849 cli_error(cli
, "Cannot parse IP \"%s\"", argv
[1]);
2853 rule
.src_wild
= addr
.s_addr
;
2856 rule
.src_wild
= INADDR_ANY
;
2862 static int cmd_ip_access_list_rule(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2865 ip_filter_rulet
*rule
= ip_filters
[filt
].extended
2866 ? access_list_rule_ext(cli
, command
, argv
, argc
)
2867 : access_list_rule_std(cli
, command
, argv
, argc
);
2872 for (i
= 0; i
< MAXFILTER_RULES
- 1; i
++) // -1: list always terminated by empty rule
2874 if (!ip_filters
[filt
].rules
[i
].action
)
2876 memcpy(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
));
2880 if (!memcmp(&ip_filters
[filt
].rules
[i
], rule
, sizeof(*rule
)))
2884 cli_error(cli
, "Too many rules");
2888 static int cmd_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2893 /* filter USER {in|out} FILTER ... */
2894 if (CLI_HELP_REQUESTED
)
2899 return cli_arg_help(cli
, 0,
2900 "USER", "Username of session to filter", NULL
);
2904 return cli_arg_help(cli
, 0,
2905 "in", "Set incoming filter",
2906 "out", "Set outgoing filter", NULL
);
2910 return cli_arg_help(cli
, argc
== 5 && argv
[4][1],
2911 "NAME", "Filter name", NULL
);
2914 return cli_arg_help(cli
, argc
> 1, NULL
);
2918 if (!config
->cluster_iam_master
)
2920 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2921 fmtaddr(config
->cluster_master_address
, 0));
2926 if (argc
!= 3 && argc
!= 5)
2928 cli_error(cli
, "Specify a user and filters");
2932 if (!(s
= sessionbyuser(argv
[0])))
2934 cli_error(cli
, "User %s is not connected", argv
[0]);
2938 cli_session_actions
[s
].filter_in
= cli_session_actions
[s
].filter_out
= -1;
2939 for (i
= 1; i
< argc
; i
+= 2)
2944 if (MATCH("in", argv
[i
]))
2946 if (session
[s
].filter_in
)
2948 cli_error(cli
, "Input already filtered");
2951 f
= &cli_session_actions
[s
].filter_in
;
2953 else if (MATCH("out", argv
[i
]))
2955 if (session
[s
].filter_out
)
2957 cli_error(cli
, "Output already filtered");
2960 f
= &cli_session_actions
[s
].filter_out
;
2964 cli_error(cli
, "Invalid filter specification");
2968 v
= find_access_list(argv
[i
+1]);
2969 if (v
< 0 || !*ip_filters
[v
].name
)
2971 cli_error(cli
, "Access-list %s not defined", argv
[i
+1]);
2978 cli_print(cli
, "Filtering user %s", argv
[0]);
2979 cli_session_actions
[s
].action
|= CLI_SESS_FILTER
;
2984 static int cmd_no_filter(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
2989 if (CLI_HELP_REQUESTED
)
2990 return cli_arg_help(cli
, argc
> 1,
2991 "USER", "Username of session to remove filters from", NULL
);
2993 if (!config
->cluster_iam_master
)
2995 cli_error(cli
, "Can't do this on a slave. Do it on %s",
2996 fmtaddr(config
->cluster_master_address
, 0));
3003 cli_error(cli
, "Specify a user to remove filters from");
3007 for (i
= 0; i
< argc
; i
++)
3009 if (!(s
= sessionbyuser(argv
[i
])))
3011 cli_error(cli
, "User %s is not connected", argv
[i
]);
3015 if (session
[s
].filter_in
|| session
[s
].filter_out
)
3017 cli_print(cli
, "Removing filters from user %s", argv
[i
]);
3018 cli_session_actions
[s
].action
|= CLI_SESS_NOFILTER
;
3022 cli_error(cli
, "User %s not filtered", argv
[i
]);
3029 static int cmd_show_access_list(struct cli_def
*cli
, char *command
, char **argv
, int argc
)
3033 if (CLI_HELP_REQUESTED
)
3034 return cli_arg_help(cli
, argc
> 1, "NAME", "Filter name", NULL
);
3038 cli_error(cli
, "Specify a filter name");
3042 for (i
= 0; i
< argc
; i
++)
3044 int f
= find_access_list(argv
[i
]);
3045 ip_filter_rulet
*rules
;
3047 if (f
< 0 || !*ip_filters
[f
].name
)
3049 cli_error(cli
, "Access-list %s not defined", argv
[i
]);
3056 cli_print(cli
, "%s IP access list %s",
3057 ip_filters
[f
].extended
? "Extended" : "Standard",
3058 ip_filters
[f
].name
);
3060 for (rules
= ip_filters
[f
].rules
; rules
->action
; rules
++)
3062 char const *r
= show_access_list_rule(ip_filters
[f
].extended
, rules
);
3064 cli_print(cli
, "%s (%d match%s)", r
,
3065 rules
->counter
, rules
->counter
> 1 ? "es" : "");
3067 cli_print(cli
, "%s", r
);
3074 // Convert a string in the form of abcd.ef12.3456 into char[6]
3075 void parsemac(char *string
, char mac
[6])
3077 if (sscanf(string
, "%02x%02x.%02x%02x.%02x%02x", (unsigned int *)&mac
[0], (unsigned int *)&mac
[1], (unsigned int *)&mac
[2], (unsigned int *)&mac
[3], (unsigned int *)&mac
[4], (unsigned int *)&mac
[5]) == 6)
3079 if (sscanf(string
, "%02x%02x:%02x%02x:%02x%02x", (unsigned int *)&mac
[0], (unsigned int *)&mac
[1], (unsigned int *)&mac
[2], (unsigned int *)&mac
[3], (unsigned int *)&mac
[4], (unsigned int *)&mac
[5]) == 6)