Sync usage with man page.
[netbsd-mini2440.git] / sbin / ifconfig / af_link.c
blobe784eb778b8bd98a6fd1193d7bc2541c231bef13
1 /* $NetBSD: af_link.c,v 1.5 2009/04/21 21:42:35 dyoung Exp $ */
3 /*-
4 * Copyright (c) 2008 David Young. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 #ifndef lint
30 __RCSID("$NetBSD: af_link.c,v 1.5 2009/04/21 21:42:35 dyoung Exp $");
31 #endif /* not lint */
33 #include <sys/param.h>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
37 #include <net/if.h>
38 #include <net/if_dl.h>
40 #include <assert.h>
41 #include <err.h>
42 #include <errno.h>
43 #include <ifaddrs.h>
44 #include <netdb.h>
45 #include <string.h>
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <util.h>
50 #include "env.h"
51 #include "extern.h"
52 #include "af_inetany.h"
54 static void link_status(prop_dictionary_t, prop_dictionary_t, bool);
55 static void link_commit_address(prop_dictionary_t, prop_dictionary_t);
57 static const struct kwinst linkkw[] = {
58 {.k_word = "active", .k_key = "active", .k_type = KW_T_BOOL,
59 .k_bool = true, .k_nextparser = &command_root.pb_parser}
62 struct pkw link = PKW_INITIALIZER(&link, "link", NULL, NULL,
63 linkkw, __arraycount(linkkw), NULL);
65 static struct afswtch af = {
66 .af_name = "link", .af_af = AF_LINK, .af_status = link_status,
67 .af_addr_commit = link_commit_address
70 static cmdloop_branch_t branch;
72 static void link_constructor(void) __attribute__((constructor));
74 static void
75 link_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
77 print_link_addresses(env, false);
80 static int
81 link_pre_aifaddr(prop_dictionary_t env, const struct afparam *param)
83 bool active;
84 struct if_laddrreq *iflr = param->req.buf;
86 if (prop_dictionary_get_bool(env, "active", &active) && active)
87 iflr->flags |= IFLR_ACTIVE;
89 return 0;
92 static void
93 link_commit_address(prop_dictionary_t env, prop_dictionary_t oenv)
95 struct if_laddrreq dgreq = {
96 .addr = {
97 .ss_family = AF_LINK,
98 .ss_len = sizeof(dgreq.addr),
101 struct if_laddrreq req = {
102 .addr = {
103 .ss_family = AF_LINK,
104 .ss_len = sizeof(req.addr),
107 struct afparam linkparam = {
108 .req = BUFPARAM(req)
109 , .dgreq = BUFPARAM(dgreq)
110 , .name = {
111 {.buf = dgreq.iflr_name,
112 .buflen = sizeof(dgreq.iflr_name)},
113 {.buf = req.iflr_name,
114 .buflen = sizeof(req.iflr_name)}
116 , .dgaddr = BUFPARAM(dgreq.addr)
117 , .addr = BUFPARAM(req.addr)
118 , .aifaddr = IFADDR_PARAM(SIOCALIFADDR)
119 , .difaddr = IFADDR_PARAM(SIOCDLIFADDR)
120 , .gifaddr = IFADDR_PARAM(0)
121 , .pre_aifaddr = link_pre_aifaddr
123 commit_address(env, oenv, &linkparam);
126 static void
127 link_constructor(void)
129 register_family(&af);
130 cmdloop_branch_init(&branch, &link.pk_parser);
131 register_cmdloop_branch(&branch);