ifconfig.c revision 1.222 1 /* $NetBSD: ifconfig.c,v 1.222 2010/11/05 13:52:41 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1983, 1993
35 * The Regents of the University of California. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 */
61
62 #include <sys/cdefs.h>
63 #ifndef lint
64 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
65 The Regents of the University of California. All rights reserved.");
66 __RCSID("$NetBSD: ifconfig.c,v 1.222 2010/11/05 13:52:41 pooka Exp $");
67 #endif /* not lint */
68
69 #include <sys/param.h>
70 #include <sys/queue.h>
71 #include <sys/socket.h>
72 #include <sys/ioctl.h>
73
74 #include <net/if.h>
75 #include <net/if_dl.h>
76 #include <net/if_media.h>
77 #include <net/if_ether.h>
78 #include <netinet/in.h> /* XXX */
79 #include <netinet/in_var.h> /* XXX */
80
81 #include <netdb.h>
82
83 #include <sys/protosw.h>
84
85 #include <assert.h>
86 #include <ctype.h>
87 #include <err.h>
88 #include <errno.h>
89 #include <stdbool.h>
90 #include <stddef.h>
91 #include <stdio.h>
92 #include <stdlib.h>
93 #include <string.h>
94 #include <unistd.h>
95 #include <ifaddrs.h>
96 #include <util.h>
97
98 #include "extern.h"
99
100 #include "media.h"
101 #include "parse.h"
102 #include "env.h"
103
104 static bool bflag, dflag, hflag, sflag, uflag;
105 bool lflag, Nflag, vflag, zflag;
106
107 static char gflags[10 + 26 * 2 + 1] = "AabCdhlNsuvz";
108 bool gflagset[10 + 26 * 2];
109
110 static int carrier(prop_dictionary_t);
111 static int clone_command(prop_dictionary_t, prop_dictionary_t);
112 static void do_setifpreference(prop_dictionary_t);
113 static int flag_index(int);
114 static void init_afs(void);
115 static int list_cloners(prop_dictionary_t, prop_dictionary_t);
116 static int media_status_exec(prop_dictionary_t, prop_dictionary_t);
117 static int no_cmds_exec(prop_dictionary_t, prop_dictionary_t);
118 static int notrailers(prop_dictionary_t, prop_dictionary_t);
119 static void printall(const char *, prop_dictionary_t);
120 static int setifaddr(prop_dictionary_t, prop_dictionary_t);
121 static int setifbroadaddr(prop_dictionary_t, prop_dictionary_t);
122 static int setifcaps(prop_dictionary_t, prop_dictionary_t);
123 static int setifdstormask(prop_dictionary_t, prop_dictionary_t);
124 static int setifflags(prop_dictionary_t, prop_dictionary_t);
125 static int setifmetric(prop_dictionary_t, prop_dictionary_t);
126 static int setifmtu(prop_dictionary_t, prop_dictionary_t);
127 static int setifnetmask(prop_dictionary_t, prop_dictionary_t);
128 static int setifprefixlen(prop_dictionary_t, prop_dictionary_t);
129 static void status(const struct sockaddr *, prop_dictionary_t,
130 prop_dictionary_t);
131 static void usage(void);
132
133 static const struct kwinst ifflagskw[] = {
134 IFKW("arp", -IFF_NOARP)
135 , IFKW("debug", IFF_DEBUG)
136 , IFKW("link0", IFF_LINK0)
137 , IFKW("link1", IFF_LINK1)
138 , IFKW("link2", IFF_LINK2)
139 , {.k_word = "down", .k_type = KW_T_INT, .k_int = -IFF_UP}
140 , {.k_word = "up", .k_type = KW_T_INT, .k_int = IFF_UP}
141 };
142
143 static const struct kwinst ifcapskw[] = {
144 IFKW("ip4csum-tx", IFCAP_CSUM_IPv4_Tx)
145 , IFKW("ip4csum-rx", IFCAP_CSUM_IPv4_Rx)
146 , IFKW("tcp4csum-tx", IFCAP_CSUM_TCPv4_Tx)
147 , IFKW("tcp4csum-rx", IFCAP_CSUM_TCPv4_Rx)
148 , IFKW("udp4csum-tx", IFCAP_CSUM_UDPv4_Tx)
149 , IFKW("udp4csum-rx", IFCAP_CSUM_UDPv4_Rx)
150 , IFKW("tcp6csum-tx", IFCAP_CSUM_TCPv6_Tx)
151 , IFKW("tcp6csum-rx", IFCAP_CSUM_TCPv6_Rx)
152 , IFKW("udp6csum-tx", IFCAP_CSUM_UDPv6_Tx)
153 , IFKW("udp6csum-rx", IFCAP_CSUM_UDPv6_Rx)
154 , IFKW("ip4csum", IFCAP_CSUM_IPv4_Tx|IFCAP_CSUM_IPv4_Rx)
155 , IFKW("tcp4csum", IFCAP_CSUM_TCPv4_Tx|IFCAP_CSUM_TCPv4_Rx)
156 , IFKW("udp4csum", IFCAP_CSUM_UDPv4_Tx|IFCAP_CSUM_UDPv4_Rx)
157 , IFKW("tcp6csum", IFCAP_CSUM_TCPv6_Tx|IFCAP_CSUM_TCPv6_Rx)
158 , IFKW("udp6csum", IFCAP_CSUM_UDPv6_Tx|IFCAP_CSUM_UDPv6_Rx)
159 , IFKW("tso4", IFCAP_TSOv4)
160 , IFKW("tso6", IFCAP_TSOv6)
161 };
162
163 extern struct pbranch command_root;
164 extern struct pbranch opt_command;
165 extern struct pbranch opt_family, opt_silent_family;
166 extern struct pkw cloning, silent_family, family, ifcaps, ifflags, misc;
167
168 struct pinteger parse_metric = PINTEGER_INITIALIZER(&parse_metric, "metric", 10,
169 setifmetric, "metric", &command_root.pb_parser);
170
171 struct pinteger parse_mtu = PINTEGER_INITIALIZER(&parse_mtu, "mtu", 10,
172 setifmtu, "mtu", &command_root.pb_parser);
173
174 struct pinteger parse_prefixlen = PINTEGER_INITIALIZER(&parse_prefixlen,
175 "prefixlen", 10, setifprefixlen, "prefixlen", &command_root.pb_parser);
176
177 struct pinteger parse_preference = PINTEGER_INITIALIZER1(&parse_preference,
178 "preference", INT16_MIN, INT16_MAX, 10, NULL, "preference",
179 &command_root.pb_parser);
180
181 struct paddr parse_netmask = PADDR_INITIALIZER(&parse_netmask, "netmask",
182 setifnetmask, "dstormask", NULL, NULL, NULL, &command_root.pb_parser);
183
184 struct paddr parse_broadcast = PADDR_INITIALIZER(&parse_broadcast,
185 "broadcast address",
186 setifbroadaddr, "broadcast", NULL, NULL, NULL, &command_root.pb_parser);
187
188 static const struct kwinst misckw[] = {
189 {.k_word = "alias", .k_key = "alias", .k_deact = "alias",
190 .k_type = KW_T_BOOL, .k_neg = true,
191 .k_bool = true, .k_negbool = false,
192 .k_nextparser = &command_root.pb_parser}
193 , {.k_word = "broadcast", .k_nextparser = &parse_broadcast.pa_parser}
194 , {.k_word = "delete", .k_key = "alias", .k_deact = "alias",
195 .k_type = KW_T_BOOL, .k_bool = false,
196 .k_nextparser = &command_root.pb_parser}
197 , {.k_word = "metric", .k_nextparser = &parse_metric.pi_parser}
198 , {.k_word = "mtu", .k_nextparser = &parse_mtu.pi_parser}
199 , {.k_word = "netmask", .k_nextparser = &parse_netmask.pa_parser}
200 , {.k_word = "preference", .k_act = "address",
201 .k_nextparser = &parse_preference.pi_parser}
202 , {.k_word = "prefixlen", .k_nextparser = &parse_prefixlen.pi_parser}
203 , {.k_word = "trailers", .k_neg = true,
204 .k_exec = notrailers, .k_nextparser = &command_root.pb_parser}
205 };
206
207 /* key: clonecmd */
208 static const struct kwinst clonekw[] = {
209 {.k_word = "create", .k_type = KW_T_INT, .k_int = SIOCIFCREATE,
210 .k_nextparser = &opt_silent_family.pb_parser},
211 {.k_word = "destroy", .k_type = KW_T_INT, .k_int = SIOCIFDESTROY}
212 };
213
214 static struct kwinst familykw[24];
215
216 struct pterm cloneterm = PTERM_INITIALIZER(&cloneterm, "list cloners",
217 list_cloners, "none");
218
219 struct pterm no_cmds = PTERM_INITIALIZER(&no_cmds, "no commands", no_cmds_exec,
220 "none");
221
222 struct pkw family_only =
223 PKW_INITIALIZER(&family_only, "family-only", NULL, "af", familykw,
224 __arraycount(familykw), &no_cmds.pt_parser);
225
226 struct paddr address = PADDR_INITIALIZER(&address,
227 "local address (address 1)",
228 setifaddr, "address", "netmask", NULL, "address", &command_root.pb_parser);
229
230 struct paddr dstormask = PADDR_INITIALIZER(&dstormask,
231 "destination/netmask (address 2)",
232 setifdstormask, "dstormask", NULL, "address", "dstormask",
233 &command_root.pb_parser);
234
235 struct paddr broadcast = PADDR_INITIALIZER(&broadcast,
236 "broadcast address (address 3)",
237 setifbroadaddr, "broadcast", NULL, "dstormask", "broadcast",
238 &command_root.pb_parser);
239
240 static SIMPLEQ_HEAD(, afswtch) aflist = SIMPLEQ_HEAD_INITIALIZER(aflist);
241
242 static SIMPLEQ_HEAD(, usage_func) usage_funcs =
243 SIMPLEQ_HEAD_INITIALIZER(usage_funcs);
244 static SIMPLEQ_HEAD(, status_func) status_funcs =
245 SIMPLEQ_HEAD_INITIALIZER(status_funcs);
246 static SIMPLEQ_HEAD(, statistics_func) statistics_funcs =
247 SIMPLEQ_HEAD_INITIALIZER(statistics_funcs);
248 static SIMPLEQ_HEAD(, cmdloop_branch) cmdloop_branches =
249 SIMPLEQ_HEAD_INITIALIZER(cmdloop_branches);
250
251 struct branch opt_clone_brs[] = {
252 {.b_nextparser = &cloning.pk_parser}
253 , {.b_nextparser = &opt_family.pb_parser}
254 }, opt_silent_family_brs[] = {
255 {.b_nextparser = &silent_family.pk_parser}
256 , {.b_nextparser = &command_root.pb_parser}
257 }, opt_family_brs[] = {
258 {.b_nextparser = &family.pk_parser}
259 , {.b_nextparser = &opt_command.pb_parser}
260 }, command_root_brs[] = {
261 {.b_nextparser = &ifflags.pk_parser}
262 , {.b_nextparser = &ifcaps.pk_parser}
263 , {.b_nextparser = &kwmedia.pk_parser}
264 , {.b_nextparser = &misc.pk_parser}
265 , {.b_nextparser = &address.pa_parser}
266 , {.b_nextparser = &dstormask.pa_parser}
267 , {.b_nextparser = &broadcast.pa_parser}
268 , {.b_nextparser = NULL}
269 }, opt_command_brs[] = {
270 {.b_nextparser = &no_cmds.pt_parser}
271 , {.b_nextparser = &command_root.pb_parser}
272 };
273
274 struct branch opt_family_only_brs[] = {
275 {.b_nextparser = &no_cmds.pt_parser}
276 , {.b_nextparser = &family_only.pk_parser}
277 };
278 struct pbranch opt_family_only = PBRANCH_INITIALIZER(&opt_family_only,
279 "opt-family-only", opt_family_only_brs,
280 __arraycount(opt_family_only_brs), true);
281 struct pbranch opt_command = PBRANCH_INITIALIZER(&opt_command,
282 "optional command",
283 opt_command_brs, __arraycount(opt_command_brs), true);
284
285 struct pbranch command_root = PBRANCH_INITIALIZER(&command_root,
286 "command-root", command_root_brs, __arraycount(command_root_brs), true);
287
288 struct piface iface_opt_family_only =
289 PIFACE_INITIALIZER(&iface_opt_family_only, "iface-opt-family-only",
290 NULL, "if", &opt_family_only.pb_parser);
291
292 struct pkw family = PKW_INITIALIZER(&family, "family", NULL, "af",
293 familykw, __arraycount(familykw), &opt_command.pb_parser);
294
295 struct pkw silent_family = PKW_INITIALIZER(&silent_family, "silent family",
296 NULL, "af", familykw, __arraycount(familykw), &command_root.pb_parser);
297
298 struct pkw *family_users[] = {&family_only, &family, &silent_family};
299
300 struct pkw ifcaps = PKW_INITIALIZER(&ifcaps, "ifcaps", setifcaps,
301 "ifcap", ifcapskw, __arraycount(ifcapskw), &command_root.pb_parser);
302
303 struct pkw ifflags = PKW_INITIALIZER(&ifflags, "ifflags", setifflags,
304 "ifflag", ifflagskw, __arraycount(ifflagskw), &command_root.pb_parser);
305
306 struct pkw cloning = PKW_INITIALIZER(&cloning, "cloning", clone_command,
307 "clonecmd", clonekw, __arraycount(clonekw), NULL);
308
309 struct pkw misc = PKW_INITIALIZER(&misc, "misc", NULL, NULL,
310 misckw, __arraycount(misckw), NULL);
311
312 struct pbranch opt_clone = PBRANCH_INITIALIZER(&opt_clone,
313 "opt-clone", opt_clone_brs, __arraycount(opt_clone_brs), true);
314
315 struct pbranch opt_silent_family = PBRANCH_INITIALIZER(&opt_silent_family,
316 "optional silent family", opt_silent_family_brs,
317 __arraycount(opt_silent_family_brs), true);
318
319 struct pbranch opt_family = PBRANCH_INITIALIZER(&opt_family,
320 "opt-family", opt_family_brs, __arraycount(opt_family_brs), true);
321
322 struct piface iface_start = PIFACE_INITIALIZER(&iface_start,
323 "iface-opt-family", NULL, "if", &opt_clone.pb_parser);
324
325 struct piface iface_only = PIFACE_INITIALIZER(&iface_only, "iface",
326 media_status_exec, "if", NULL);
327
328 static bool
329 flag_is_registered(const char *flags, int flag)
330 {
331 return flags != NULL && strchr(flags, flag) != NULL;
332 }
333
334 static int
335 check_flag(const char *flags, int flag)
336 {
337 if (flag_is_registered(flags, flag)) {
338 errno = EEXIST;
339 return -1;
340 }
341
342 if (flag >= '0' && flag <= '9')
343 return 0;
344 if (flag >= 'a' && flag <= 'z')
345 return 0;
346 if (flag >= 'A' && flag <= 'Z')
347 return 0;
348
349 errno = EINVAL;
350 return -1;
351 }
352
353 void
354 cmdloop_branch_init(cmdloop_branch_t *b, struct parser *p)
355 {
356 b->b_parser = p;
357 }
358
359 void
360 statistics_func_init(statistics_func_t *f, statistics_cb_t func)
361 {
362 f->f_func = func;
363 }
364
365 void
366 status_func_init(status_func_t *f, status_cb_t func)
367 {
368 f->f_func = func;
369 }
370
371 void
372 usage_func_init(usage_func_t *f, usage_cb_t func)
373 {
374 f->f_func = func;
375 }
376
377 int
378 register_cmdloop_branch(cmdloop_branch_t *b)
379 {
380 SIMPLEQ_INSERT_TAIL(&cmdloop_branches, b, b_next);
381 return 0;
382 }
383
384 int
385 register_statistics(statistics_func_t *f)
386 {
387 SIMPLEQ_INSERT_TAIL(&statistics_funcs, f, f_next);
388 return 0;
389 }
390
391 int
392 register_status(status_func_t *f)
393 {
394 SIMPLEQ_INSERT_TAIL(&status_funcs, f, f_next);
395 return 0;
396 }
397
398 int
399 register_usage(usage_func_t *f)
400 {
401 SIMPLEQ_INSERT_TAIL(&usage_funcs, f, f_next);
402 return 0;
403 }
404
405 int
406 register_family(struct afswtch *af)
407 {
408 SIMPLEQ_INSERT_TAIL(&aflist, af, af_next);
409 return 0;
410 }
411
412 int
413 register_flag(int flag)
414 {
415 if (check_flag(gflags, flag) == -1)
416 return -1;
417
418 if (strlen(gflags) + 1 >= sizeof(gflags)) {
419 errno = ENOMEM;
420 return -1;
421 }
422
423 gflags[strlen(gflags)] = flag;
424
425 return 0;
426 }
427
428 static int
429 flag_index(int flag)
430 {
431 if (flag >= '0' && flag <= '9')
432 return flag - '0';
433 if (flag >= 'a' && flag <= 'z')
434 return 10 + flag - 'a';
435 if (flag >= 'A' && flag <= 'Z')
436 return 10 + 26 + flag - 'a';
437
438 errno = EINVAL;
439 return -1;
440 }
441
442 static bool
443 set_flag(int flag)
444 {
445 int idx;
446
447 if ((idx = flag_index(flag)) == -1)
448 return false;
449
450 return gflagset[idx] = true;
451 }
452
453 bool
454 get_flag(int flag)
455 {
456 int idx;
457
458 if ((idx = flag_index(flag)) == -1)
459 return false;
460
461 return gflagset[idx];
462 }
463
464 static struct parser *
465 init_parser(void)
466 {
467 cmdloop_branch_t *b;
468
469 if (parser_init(&iface_opt_family_only.pif_parser) == -1)
470 err(EXIT_FAILURE, "parser_init(iface_opt_family_only)");
471 if (parser_init(&iface_only.pif_parser) == -1)
472 err(EXIT_FAILURE, "parser_init(iface_only)");
473 if (parser_init(&iface_start.pif_parser) == -1)
474 err(EXIT_FAILURE, "parser_init(iface_start)");
475
476 SIMPLEQ_FOREACH(b, &cmdloop_branches, b_next)
477 pbranch_addbranch(&command_root, b->b_parser);
478
479 return &iface_start.pif_parser;
480 }
481
482 static int
483 no_cmds_exec(prop_dictionary_t env, prop_dictionary_t oenv)
484 {
485 const char *ifname;
486 unsigned short ignore;
487
488 /* ifname == NULL is ok. It indicates 'ifconfig -a'. */
489 if ((ifname = getifname(env)) == NULL)
490 ;
491 else if (getifflags(env, oenv, &ignore) == -1)
492 err(EXIT_FAILURE, "SIOCGIFFLAGS %s", ifname);
493
494 printall(ifname, env);
495 exit(EXIT_SUCCESS);
496 }
497
498 static int
499 media_status_exec(prop_dictionary_t env, prop_dictionary_t oenv)
500 {
501 const char *ifname;
502 unsigned short ignore;
503
504 /* ifname == NULL is ok. It indicates 'ifconfig -a'. */
505 if ((ifname = getifname(env)) == NULL)
506 ;
507 else if (getifflags(env, oenv, &ignore) == -1)
508 err(EXIT_FAILURE, "SIOCGIFFLAGS %s", ifname);
509
510 exit(carrier(env));
511 }
512
513 static void
514 do_setifcaps(prop_dictionary_t env)
515 {
516 struct ifcapreq ifcr;
517 prop_data_t d;
518
519 d = (prop_data_t )prop_dictionary_get(env, "ifcaps");
520 if (d == NULL)
521 return;
522
523 assert(sizeof(ifcr) == prop_data_size(d));
524
525 memcpy(&ifcr, prop_data_data_nocopy(d), sizeof(ifcr));
526 if (direct_ioctl(env, SIOCSIFCAP, &ifcr) == -1)
527 err(EXIT_FAILURE, "SIOCSIFCAP");
528 }
529
530 int
531 main(int argc, char **argv)
532 {
533 const struct afswtch *afp;
534 int af, s;
535 bool aflag = false, Cflag = false;
536 struct match match[32];
537 size_t nmatch;
538 struct parser *start;
539 int ch, narg = 0, rc;
540 prop_dictionary_t env, oenv;
541 const char *ifname;
542
543 #ifdef RUMP_ACTION
544 if (rumpclient_init() == -1)
545 err(1, "rump client init");
546 #endif
547 memset(match, 0, sizeof(match));
548
549 init_afs();
550
551 start = init_parser();
552
553 /* Parse command-line options */
554 aflag = Nflag = vflag = zflag = false;
555 while ((ch = getopt(argc, argv, gflags)) != -1) {
556 switch (ch) {
557 case 'A':
558 warnx("-A is deprecated");
559 break;
560
561 case 'a':
562 aflag = true;
563 break;
564
565 case 'b':
566 bflag = true;
567 break;
568
569 case 'C':
570 Cflag = true;
571 break;
572
573 case 'd':
574 dflag = true;
575 break;
576 case 'h':
577 hflag = true;
578 break;
579 case 'l':
580 lflag = true;
581 break;
582 case 'N':
583 Nflag = true;
584 break;
585
586 case 's':
587 sflag = true;
588 break;
589
590 case 'u':
591 uflag = true;
592 break;
593
594 case 'v':
595 vflag = true;
596 break;
597
598 case 'z':
599 zflag = true;
600 break;
601
602 default:
603 if (!set_flag(ch))
604 usage();
605 break;
606 }
607 switch (ch) {
608 case 'a':
609 start = &opt_family_only.pb_parser;
610 break;
611
612 case 'L':
613 case 'm':
614 case 'v':
615 case 'z':
616 if (start != &opt_family_only.pb_parser)
617 start = &iface_opt_family_only.pif_parser;
618 break;
619 case 'C':
620 start = &cloneterm.pt_parser;
621 break;
622 case 'l':
623 start = &no_cmds.pt_parser;
624 break;
625 case 's':
626 if (start != &no_cmds.pt_parser &&
627 start != &opt_family_only.pb_parser)
628 start = &iface_only.pif_parser;
629 break;
630 default:
631 break;
632 }
633 }
634 argc -= optind;
635 argv += optind;
636
637 /*
638 * -l means "list all interfaces", and is mutally exclusive with
639 * all other flags/commands.
640 *
641 * -C means "list all names of cloners", and it mutually exclusive
642 * with all other flags/commands.
643 *
644 * -a means "print status of all interfaces".
645 */
646 if ((lflag || Cflag) && (aflag || get_flag('m') || vflag || zflag))
647 usage();
648 if ((lflag || Cflag) && get_flag('L'))
649 usage();
650 if (lflag && Cflag)
651 usage();
652
653 nmatch = __arraycount(match);
654
655 rc = parse(argc, argv, start, match, &nmatch, &narg);
656 if (rc != 0)
657 usage();
658
659 if ((oenv = prop_dictionary_create()) == NULL)
660 err(EXIT_FAILURE, "%s: prop_dictionary_create", __func__);
661
662 if (matches_exec(match, oenv, nmatch) == -1)
663 err(EXIT_FAILURE, "exec_matches");
664
665 argc -= narg;
666 argv += narg;
667
668 env = (nmatch > 0) ? match[(int)nmatch - 1].m_env : NULL;
669 if (env == NULL)
670 env = oenv;
671 else
672 env = prop_dictionary_augment(env, oenv);
673
674 /* Process any media commands that may have been issued. */
675 process_media_commands(env);
676
677 if ((af = getaf(env)) == -1)
678 af = AF_INET;
679
680 if ((s = getsock(af)) == -1)
681 err(EXIT_FAILURE, "%s: getsock", __func__);
682
683 if ((ifname = getifname(env)) == NULL)
684 err(EXIT_FAILURE, "%s: getifname", __func__);
685
686 if ((afp = lookup_af_bynum(af)) == NULL)
687 errx(EXIT_FAILURE, "%s: lookup_af_bynum", __func__);
688
689 assert(afp->af_addr_commit != NULL);
690 (*afp->af_addr_commit)(env, oenv);
691
692 do_setifpreference(env);
693 do_setifcaps(env);
694
695 exit(EXIT_SUCCESS);
696 }
697
698 static void
699 init_afs(void)
700 {
701 size_t i;
702 const struct afswtch *afp;
703 struct kwinst kw = {.k_type = KW_T_INT};
704
705 SIMPLEQ_FOREACH(afp, &aflist, af_next) {
706 kw.k_word = afp->af_name;
707 kw.k_int = afp->af_af;
708 for (i = 0; i < __arraycount(familykw); i++) {
709 if (familykw[i].k_word == NULL) {
710 familykw[i] = kw;
711 break;
712 }
713 }
714 }
715 }
716
717 const struct afswtch *
718 lookup_af_bynum(int afnum)
719 {
720 const struct afswtch *afp;
721
722 SIMPLEQ_FOREACH(afp, &aflist, af_next) {
723 if (afp->af_af == afnum)
724 break;
725 }
726 return afp;
727 }
728
729 void
730 printall(const char *ifname, prop_dictionary_t env0)
731 {
732 struct ifaddrs *ifap, *ifa;
733 struct ifreq ifr;
734 const struct sockaddr *sdl = NULL;
735 prop_dictionary_t env, oenv;
736 int idx;
737 char *p;
738
739 if (env0 == NULL)
740 env = prop_dictionary_create();
741 else
742 env = prop_dictionary_copy_mutable(env0);
743
744 oenv = prop_dictionary_create();
745
746 if (env == NULL || oenv == NULL)
747 errx(EXIT_FAILURE, "%s: prop_dictionary_copy/create", __func__);
748
749 if (getifaddrs(&ifap) != 0)
750 err(EXIT_FAILURE, "getifaddrs");
751 p = NULL;
752 idx = 0;
753 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
754 memset(&ifr, 0, sizeof(ifr));
755 estrlcpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
756 if (sizeof(ifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
757 memcpy(&ifr.ifr_addr, ifa->ifa_addr,
758 ifa->ifa_addr->sa_len);
759 }
760
761 if (ifname != NULL && strcmp(ifname, ifa->ifa_name) != 0)
762 continue;
763 if (ifa->ifa_addr->sa_family == AF_LINK)
764 sdl = ifa->ifa_addr;
765 if (p && strcmp(p, ifa->ifa_name) == 0)
766 continue;
767 if (!prop_dictionary_set_cstring(env, "if", ifa->ifa_name))
768 continue;
769 p = ifa->ifa_name;
770
771 if (bflag && (ifa->ifa_flags & IFF_BROADCAST) == 0)
772 continue;
773 if (dflag && (ifa->ifa_flags & IFF_UP) != 0)
774 continue;
775 if (uflag && (ifa->ifa_flags & IFF_UP) == 0)
776 continue;
777
778 if (sflag && carrier(env))
779 continue;
780 idx++;
781 /*
782 * Are we just listing the interfaces?
783 */
784 if (lflag) {
785 if (idx > 1)
786 printf(" ");
787 fputs(ifa->ifa_name, stdout);
788 continue;
789 }
790
791 status(sdl, env, oenv);
792 sdl = NULL;
793 }
794 if (lflag)
795 printf("\n");
796 prop_object_release((prop_object_t)env);
797 prop_object_release((prop_object_t)oenv);
798 freeifaddrs(ifap);
799 }
800
801 static int
802 list_cloners(prop_dictionary_t env, prop_dictionary_t oenv)
803 {
804 struct if_clonereq ifcr;
805 char *cp, *buf;
806 int idx, s;
807
808 memset(&ifcr, 0, sizeof(ifcr));
809
810 s = getsock(AF_INET);
811
812 if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
813 err(EXIT_FAILURE, "SIOCIFGCLONERS for count");
814
815 buf = malloc(ifcr.ifcr_total * IFNAMSIZ);
816 if (buf == NULL)
817 err(EXIT_FAILURE, "unable to allocate cloner name buffer");
818
819 ifcr.ifcr_count = ifcr.ifcr_total;
820 ifcr.ifcr_buffer = buf;
821
822 if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1)
823 err(EXIT_FAILURE, "SIOCIFGCLONERS for names");
824
825 /*
826 * In case some disappeared in the mean time, clamp it down.
827 */
828 if (ifcr.ifcr_count > ifcr.ifcr_total)
829 ifcr.ifcr_count = ifcr.ifcr_total;
830
831 for (cp = buf, idx = 0; idx < ifcr.ifcr_count; idx++, cp += IFNAMSIZ) {
832 if (idx > 0)
833 printf(" ");
834 printf("%s", cp);
835 }
836
837 printf("\n");
838 free(buf);
839 exit(EXIT_SUCCESS);
840 }
841
842 static int
843 clone_command(prop_dictionary_t env, prop_dictionary_t oenv)
844 {
845 int64_t cmd;
846
847 if (!prop_dictionary_get_int64(env, "clonecmd", &cmd)) {
848 errno = ENOENT;
849 return -1;
850 }
851
852 if (indirect_ioctl(env, (unsigned long)cmd, NULL) == -1) {
853 warn("%s", __func__);
854 return -1;
855 }
856 return 0;
857 }
858
859 /*ARGSUSED*/
860 static int
861 setifaddr(prop_dictionary_t env, prop_dictionary_t oenv)
862 {
863 const struct paddr_prefix *pfx0;
864 struct paddr_prefix *pfx;
865 prop_data_t d;
866 int af;
867
868 if ((af = getaf(env)) == -1)
869 af = AF_INET;
870
871 d = (prop_data_t)prop_dictionary_get(env, "address");
872 assert(d != NULL);
873 pfx0 = prop_data_data_nocopy(d);
874
875 if (pfx0->pfx_len >= 0) {
876 pfx = prefixlen_to_mask(af, pfx0->pfx_len);
877 if (pfx == NULL)
878 err(EXIT_FAILURE, "prefixlen_to_mask");
879 free(pfx);
880 }
881
882 return 0;
883 }
884
885 static int
886 setifnetmask(prop_dictionary_t env, prop_dictionary_t oenv)
887 {
888 const struct paddr_prefix *pfx;
889 prop_data_t d;
890
891 d = (prop_data_t)prop_dictionary_get(env, "dstormask");
892 assert(d != NULL);
893 pfx = prop_data_data_nocopy(d);
894
895 if (!prop_dictionary_set(oenv, "netmask", (prop_object_t)d))
896 return -1;
897
898 return 0;
899 }
900
901 static int
902 setifbroadaddr(prop_dictionary_t env, prop_dictionary_t oenv)
903 {
904 const struct paddr_prefix *pfx;
905 prop_data_t d;
906 unsigned short flags;
907
908 if (getifflags(env, oenv, &flags) == -1)
909 err(EXIT_FAILURE, "%s: getifflags", __func__);
910
911 if ((flags & IFF_BROADCAST) == 0)
912 errx(EXIT_FAILURE, "not a broadcast interface");
913
914 d = (prop_data_t)prop_dictionary_get(env, "broadcast");
915 assert(d != NULL);
916 pfx = prop_data_data_nocopy(d);
917
918 if (!prop_dictionary_set(oenv, "broadcast", (prop_object_t)d))
919 return -1;
920
921 return 0;
922 }
923
924 /*ARGSUSED*/
925 static int
926 notrailers(prop_dictionary_t env, prop_dictionary_t oenv)
927 {
928 puts("Note: trailers are no longer sent, but always received");
929 return 0;
930 }
931
932 /*ARGSUSED*/
933 static int
934 setifdstormask(prop_dictionary_t env, prop_dictionary_t oenv)
935 {
936 const char *key;
937 const struct paddr_prefix *pfx;
938 prop_data_t d;
939 unsigned short flags;
940
941 if (getifflags(env, oenv, &flags) == -1)
942 err(EXIT_FAILURE, "%s: getifflags", __func__);
943
944 d = (prop_data_t)prop_dictionary_get(env, "dstormask");
945 assert(d != NULL);
946 pfx = prop_data_data_nocopy(d);
947
948 if ((flags & IFF_BROADCAST) == 0) {
949 key = "dst";
950 } else {
951 key = "netmask";
952 }
953
954 if (!prop_dictionary_set(oenv, key, (prop_object_t)d))
955 return -1;
956
957 return 0;
958 }
959
960 static int
961 setifflags(prop_dictionary_t env, prop_dictionary_t oenv)
962 {
963 struct ifreq ifr;
964 int64_t ifflag;
965 bool rc;
966
967 rc = prop_dictionary_get_int64(env, "ifflag", &ifflag);
968 assert(rc);
969
970 if (direct_ioctl(env, SIOCGIFFLAGS, &ifr) == -1)
971 return -1;
972
973 if (ifflag < 0) {
974 ifflag = -ifflag;
975 ifr.ifr_flags &= ~ifflag;
976 } else
977 ifr.ifr_flags |= ifflag;
978
979 if (direct_ioctl(env, SIOCSIFFLAGS, &ifr) == -1)
980 return -1;
981
982 return 0;
983 }
984
985 static int
986 getifcaps(prop_dictionary_t env, prop_dictionary_t oenv, struct ifcapreq *oifcr)
987 {
988 bool rc;
989 struct ifcapreq ifcr;
990 const struct ifcapreq *tmpifcr;
991 prop_data_t capdata;
992
993 capdata = (prop_data_t)prop_dictionary_get(env, "ifcaps");
994
995 if (capdata != NULL) {
996 tmpifcr = prop_data_data_nocopy(capdata);
997 *oifcr = *tmpifcr;
998 return 0;
999 }
1000
1001 (void)direct_ioctl(env, SIOCGIFCAP, &ifcr);
1002 *oifcr = ifcr;
1003
1004 capdata = prop_data_create_data(&ifcr, sizeof(ifcr));
1005
1006 rc = prop_dictionary_set(oenv, "ifcaps", capdata);
1007
1008 prop_object_release((prop_object_t)capdata);
1009
1010 return rc ? 0 : -1;
1011 }
1012
1013 static int
1014 setifcaps(prop_dictionary_t env, prop_dictionary_t oenv)
1015 {
1016 int64_t ifcap;
1017 int s;
1018 bool rc;
1019 prop_data_t capdata;
1020 struct ifcapreq ifcr;
1021
1022 s = getsock(AF_INET);
1023
1024 rc = prop_dictionary_get_int64(env, "ifcap", &ifcap);
1025 assert(rc);
1026
1027 if (getifcaps(env, oenv, &ifcr) == -1)
1028 return -1;
1029
1030 if (ifcap < 0) {
1031 ifcap = -ifcap;
1032 ifcr.ifcr_capenable &= ~ifcap;
1033 } else
1034 ifcr.ifcr_capenable |= ifcap;
1035
1036 if ((capdata = prop_data_create_data(&ifcr, sizeof(ifcr))) == NULL)
1037 return -1;
1038
1039 rc = prop_dictionary_set(oenv, "ifcaps", capdata);
1040 prop_object_release((prop_object_t)capdata);
1041
1042 return rc ? 0 : -1;
1043 }
1044
1045 static int
1046 setifmetric(prop_dictionary_t env, prop_dictionary_t oenv)
1047 {
1048 struct ifreq ifr;
1049 bool rc;
1050 int64_t metric;
1051
1052 rc = prop_dictionary_get_int64(env, "metric", &metric);
1053 assert(rc);
1054
1055 ifr.ifr_metric = metric;
1056 if (direct_ioctl(env, SIOCSIFMETRIC, &ifr) == -1)
1057 warn("SIOCSIFMETRIC");
1058 return 0;
1059 }
1060
1061 static void
1062 do_setifpreference(prop_dictionary_t env)
1063 {
1064 struct if_addrprefreq ifap;
1065 prop_data_t d;
1066 const struct paddr_prefix *pfx;
1067
1068 memset(&ifap, 0, sizeof(ifap));
1069
1070 if (!prop_dictionary_get_int16(env, "preference",
1071 &ifap.ifap_preference))
1072 return;
1073
1074 d = (prop_data_t)prop_dictionary_get(env, "address");
1075 assert(d != NULL);
1076
1077 pfx = prop_data_data_nocopy(d);
1078
1079 memcpy(&ifap.ifap_addr, &pfx->pfx_addr,
1080 MIN(sizeof(ifap.ifap_addr), pfx->pfx_addr.sa_len));
1081 if (direct_ioctl(env, SIOCSIFADDRPREF, &ifap) == -1)
1082 warn("SIOCSIFADDRPREF");
1083 }
1084
1085 static int
1086 setifmtu(prop_dictionary_t env, prop_dictionary_t oenv)
1087 {
1088 int64_t mtu;
1089 bool rc;
1090 struct ifreq ifr;
1091
1092 rc = prop_dictionary_get_int64(env, "mtu", &mtu);
1093 assert(rc);
1094
1095 ifr.ifr_mtu = mtu;
1096 if (direct_ioctl(env, SIOCSIFMTU, &ifr) == -1)
1097 warn("SIOCSIFMTU");
1098
1099 return 0;
1100 }
1101
1102 static int
1103 carrier(prop_dictionary_t env)
1104 {
1105 struct ifmediareq ifmr;
1106
1107 memset(&ifmr, 0, sizeof(ifmr));
1108
1109 if (direct_ioctl(env, SIOCGIFMEDIA, &ifmr) == -1) {
1110 /*
1111 * Interface doesn't support SIOC{G,S}IFMEDIA;
1112 * assume ok.
1113 */
1114 return EXIT_SUCCESS;
1115 }
1116 if ((ifmr.ifm_status & IFM_AVALID) == 0) {
1117 /*
1118 * Interface doesn't report media-valid status.
1119 * assume ok.
1120 */
1121 return EXIT_SUCCESS;
1122 }
1123 /* otherwise, return ok for active, not-ok if not active. */
1124 if (ifmr.ifm_status & IFM_ACTIVE)
1125 return EXIT_SUCCESS;
1126 else
1127 return EXIT_FAILURE;
1128 }
1129
1130 static void
1131 print_plural(const char *prefix, uint64_t n, const char *unit)
1132 {
1133 printf("%s%" PRIu64 " %s%s", prefix, n, unit, (n == 1) ? "" : "s");
1134 }
1135
1136 static void
1137 print_human_bytes(bool humanize, uint64_t n)
1138 {
1139 char buf[5];
1140
1141 if (humanize) {
1142 (void)humanize_number(buf, sizeof(buf),
1143 (int64_t)n, "", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL);
1144 printf(", %s byte%s", buf, (atof(buf) == 1.0) ? "" : "s");
1145 } else
1146 print_plural(", ", n, "byte");
1147 }
1148
1149 /*
1150 * Print the status of the interface. If an address family was
1151 * specified, show it and it only; otherwise, show them all.
1152 */
1153 void
1154 status(const struct sockaddr *sdl, prop_dictionary_t env,
1155 prop_dictionary_t oenv)
1156 {
1157 const struct if_data *ifi;
1158 status_func_t *status_f;
1159 statistics_func_t *statistics_f;
1160 struct ifdatareq ifdr;
1161 struct ifreq ifr;
1162 char fbuf[BUFSIZ];
1163 int af, s;
1164 const char *ifname;
1165 struct ifcapreq ifcr;
1166 unsigned short flags;
1167 const struct afswtch *afp;
1168
1169 if ((af = getaf(env)) == -1) {
1170 afp = NULL;
1171 af = AF_UNSPEC;
1172 } else
1173 afp = lookup_af_bynum(af);
1174
1175 /* get out early if the family is unsupported by the kernel */
1176 if ((s = getsock(af)) == -1)
1177 err(EXIT_FAILURE, "%s: getsock", __func__);
1178
1179 if ((ifname = getifinfo(env, oenv, &flags)) == NULL)
1180 err(EXIT_FAILURE, "%s: getifinfo", __func__);
1181
1182 (void)snprintb(fbuf, sizeof(fbuf), IFFBITS, flags);
1183 printf("%s: flags=%s", ifname, &fbuf[2]);
1184
1185 estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1186 if (ioctl(s, SIOCGIFMETRIC, &ifr) == -1)
1187 warn("SIOCGIFMETRIC %s", ifr.ifr_name);
1188 else if (ifr.ifr_metric != 0)
1189 printf(" metric %d", ifr.ifr_metric);
1190
1191 estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
1192 if (ioctl(s, SIOCGIFMTU, &ifr) != -1 && ifr.ifr_mtu != 0)
1193 printf(" mtu %d", ifr.ifr_mtu);
1194 printf("\n");
1195
1196 if (getifcaps(env, oenv, &ifcr) == -1)
1197 err(EXIT_FAILURE, "%s: getifcaps", __func__);
1198
1199 if (ifcr.ifcr_capabilities != 0) {
1200 (void)snprintb(fbuf, sizeof(fbuf), IFCAPBITS,
1201 ifcr.ifcr_capabilities);
1202 printf("\tcapabilities=%s\n", &fbuf[2]);
1203 (void)snprintb(fbuf, sizeof(fbuf), IFCAPBITS,
1204 ifcr.ifcr_capenable);
1205 printf("\tenabled=%s\n", &fbuf[2]);
1206 }
1207
1208 SIMPLEQ_FOREACH(status_f, &status_funcs, f_next)
1209 (*status_f->f_func)(env, oenv);
1210
1211 print_link_addresses(env, true);
1212
1213 media_status(env, oenv);
1214
1215 if (!vflag && !zflag)
1216 goto proto_status;
1217
1218 estrlcpy(ifdr.ifdr_name, ifname, sizeof(ifdr.ifdr_name));
1219
1220 if (ioctl(s, zflag ? SIOCZIFDATA : SIOCGIFDATA, &ifdr) == -1)
1221 err(EXIT_FAILURE, zflag ? "SIOCZIFDATA" : "SIOCGIFDATA");
1222
1223 ifi = &ifdr.ifdr_data;
1224
1225 print_plural("\tinput: ", ifi->ifi_ipackets, "packet");
1226 print_human_bytes(hflag, ifi->ifi_ibytes);
1227 if (ifi->ifi_imcasts)
1228 print_plural(", ", ifi->ifi_imcasts, "multicast");
1229 if (ifi->ifi_ierrors)
1230 print_plural(", ", ifi->ifi_ierrors, "error");
1231 if (ifi->ifi_iqdrops)
1232 print_plural(", ", ifi->ifi_iqdrops, "queue drop");
1233 if (ifi->ifi_noproto)
1234 printf(", %" PRIu64 " unknown protocol", ifi->ifi_noproto);
1235 print_plural("\n\toutput: ", ifi->ifi_opackets, "packet");
1236 print_human_bytes(hflag, ifi->ifi_obytes);
1237 if (ifi->ifi_omcasts)
1238 print_plural(", ", ifi->ifi_omcasts, "multicast");
1239 if (ifi->ifi_oerrors)
1240 print_plural(", ", ifi->ifi_oerrors, "error");
1241 if (ifi->ifi_collisions)
1242 print_plural(", ", ifi->ifi_collisions, "collision");
1243 printf("\n");
1244
1245 SIMPLEQ_FOREACH(statistics_f, &statistics_funcs, f_next)
1246 (*statistics_f->f_func)(env);
1247
1248 proto_status:
1249
1250 if (afp != NULL)
1251 (*afp->af_status)(env, oenv, true);
1252 else SIMPLEQ_FOREACH(afp, &aflist, af_next)
1253 (*afp->af_status)(env, oenv, false);
1254 }
1255
1256 static int
1257 setifprefixlen(prop_dictionary_t env, prop_dictionary_t oenv)
1258 {
1259 bool rc;
1260 int64_t plen;
1261 int af;
1262 struct paddr_prefix *pfx;
1263 prop_data_t d;
1264
1265 if ((af = getaf(env)) == -1)
1266 af = AF_INET;
1267
1268 rc = prop_dictionary_get_int64(env, "prefixlen", &plen);
1269 assert(rc);
1270
1271 pfx = prefixlen_to_mask(af, plen);
1272 if (pfx == NULL)
1273 err(EXIT_FAILURE, "prefixlen_to_mask");
1274
1275 d = prop_data_create_data(pfx, paddr_prefix_size(pfx));
1276 if (d == NULL)
1277 err(EXIT_FAILURE, "%s: prop_data_create_data", __func__);
1278
1279 if (!prop_dictionary_set(oenv, "netmask", (prop_object_t)d))
1280 err(EXIT_FAILURE, "%s: prop_dictionary_set", __func__);
1281
1282 free(pfx);
1283 return 0;
1284 }
1285
1286 static void
1287 usage(void)
1288 {
1289 const char *progname = getprogname();
1290 usage_func_t *usage_f;
1291 prop_dictionary_t env;
1292
1293 if ((env = prop_dictionary_create()) == NULL)
1294 err(EXIT_FAILURE, "%s: prop_dictionary_create", __func__);
1295
1296 fprintf(stderr, "usage: %s [-h] %s[-v] [-z] %sinterface\n"
1297 "\t[ af [ address [ dest_addr ] ] [ netmask mask ] [ prefixlen n ]\n"
1298 "\t\t[ alias | -alias ] ]\n"
1299 "\t[ up ] [ down ] [ metric n ] [ mtu n ]\n", progname,
1300 flag_is_registered(gflags, 'm') ? "[-m] " : "",
1301 flag_is_registered(gflags, 'L') ? "[-L] " : "");
1302
1303 SIMPLEQ_FOREACH(usage_f, &usage_funcs, f_next)
1304 (*usage_f->f_func)(env);
1305
1306 fprintf(stderr,
1307 "\t[ arp | -arp ]\n"
1308 "\t[ preference n ]\n"
1309 "\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
1310 " %s -a [-b] [-d] [-h] %s[-u] [-v] [-z] [ af ]\n"
1311 " %s -l [-b] [-d] [-s] [-u]\n"
1312 " %s -C\n"
1313 " %s interface create\n"
1314 " %s interface destroy\n",
1315 progname, flag_is_registered(gflags, 'm') ? "[-m] " : "",
1316 progname, progname, progname, progname);
1317
1318 prop_object_release((prop_object_t)env);
1319 exit(EXIT_FAILURE);
1320 }
1321