1 /* $NetBSD: af_link.c,v 1.7 2014/01/19 22:31:13 matt Exp $ */
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
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
28 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: af_link.c,v 1.7 2014/01/19 22:31:13 matt Exp $");
33 #include <sys/param.h>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
38 #include <net/if_dl.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
= PKW_INITIALIZER(&link_pkw
, "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
));
75 link_status(prop_dictionary_t env
, prop_dictionary_t oenv
, bool force
)
77 print_link_addresses(env
, false);
81 link_pre_aifaddr(prop_dictionary_t env
, const struct afparam
*param
)
84 struct if_laddrreq
*iflr
= param
->req
.buf
;
86 if (prop_dictionary_get_bool(env
, "active", &active
) && active
)
87 iflr
->flags
|= IFLR_ACTIVE
;
93 link_commit_address(prop_dictionary_t env
, prop_dictionary_t oenv
)
95 struct if_laddrreq dgreq
= {
98 .ss_len
= sizeof(dgreq
.addr
),
101 struct if_laddrreq req
= {
103 .ss_family
= AF_LINK
,
104 .ss_len
= sizeof(req
.addr
),
107 struct afparam linkparam
= {
109 , .dgreq
= BUFPARAM(dgreq
)
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
);
127 link_constructor(void)
129 register_family(&af
);
130 cmdloop_branch_init(&branch
, &link_pkw
.pk_parser
);
131 register_cmdloop_branch(&branch
);