1 /* $NetBSD: config.c,v 1.12 2003/05/16 18:10:38 itojun Exp $ */
4 * The mrouted program is covered by the license in the accompanying file
5 * named "LICENSE". Use of the mrouted program represents acceptance of
6 * the terms and conditions listed in that file.
8 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
9 * Leland Stanford Junior University.
18 * Query the kernel to find network interfaces that are multicast-capable
19 * and install them in the uvifs array.
22 config_vifs_from_kernel(void)
24 struct ifaddrs
*ifa
, *ifap
;
27 u_int32_t addr
, mask
, subnet
;
30 if (getifaddrs(&ifap
) < 0)
31 logit(LOG_ERR
, errno
, "getifaddrs");
33 for (ifa
= ifap
; ifa
; ifa
= ifa
->ifa_next
) {
35 * Ignore any interface for an address family other than IP.
37 if (ifa
->ifa_addr
->sa_family
!= AF_INET
)
40 addr
= ((struct sockaddr_in
*)ifa
->ifa_addr
)->sin_addr
.s_addr
;
43 * Ignore loopback interfaces and interfaces that do not support
46 flags
= ifa
->ifa_flags
;
47 if ((flags
& (IFF_LOOPBACK
|IFF_MULTICAST
)) != IFF_MULTICAST
)
51 * Ignore any interface whose address and mask do not define a
52 * valid subnet number, or whose address is of the form {subnet,0}
55 mask
= ((struct sockaddr_in
*)ifa
->ifa_netmask
)->sin_addr
.s_addr
;
57 if (!inet_valid_subnet(subnet
, mask
) ||
59 addr
== (subnet
| ~mask
)) {
61 "ignoring %s, has invalid address (%s) and/or mask (%s)",
62 ifa
->ifa_name
, inet_fmt(addr
),
68 * Ignore any interface that is connected to the same subnet as
69 * one already installed in the uvifs array.
71 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
72 if ((addr
& v
->uv_subnetmask
) == v
->uv_subnet
||
73 (v
->uv_subnet
& mask
) == subnet
) {
74 logit(LOG_WARNING
, 0, "ignoring %s, same subnet as %s",
75 ifa
->ifa_name
, v
->uv_name
);
83 * If there is room in the uvifs array, install this interface.
85 if (numvifs
== MAXVIFS
) {
86 logit(LOG_WARNING
, 0, "too many vifs, ignoring %s", ifa
->ifa_name
);
91 v
->uv_metric
= DEFAULT_METRIC
;
92 v
->uv_rate_limit
= DEFAULT_PHY_RATE_LIMIT
;
93 v
->uv_threshold
= DEFAULT_THRESHOLD
;
94 v
->uv_lcl_addr
= addr
;
96 v
->uv_subnet
= subnet
;
97 v
->uv_subnetmask
= mask
;
98 v
->uv_subnetbcast
= subnet
| ~mask
;
99 strlcpy(v
->uv_name
, ifa
->ifa_name
, sizeof(v
->uv_name
));
101 v
->uv_neighbors
= NULL
;
105 logit(LOG_INFO
,0,"installing %s (%s on subnet %s) as vif #%u - rate=%d",
106 v
->uv_name
, inet_fmt(addr
),
107 inet_fmts(subnet
, mask
),
108 numvifs
, v
->uv_rate_limit
);
113 * If the interface is not yet up, set the vifs_down flag to
114 * remind us to check again later.
116 if (!(flags
& IFF_UP
)) {
117 v
->uv_flags
|= VIFF_DOWN
;