annotate src/if-sun.c @ 5557:e65d193a1960 draft

Linux: Support wireless IP roaming This is achieved by checking that the interface is wireless, IFF_UP and IFF_LOWER_UP are present, but IFF_RUNNING is missing. This gives exactly the same support as modern NetBSD when carrier loss is detected, but without the address verifications when the carrier comes back as that needs to be handled in the kernel. While IP setup is maintained, other configuration data is discarded. Note that this should be improved in the future. Thanks to Boris Krasnovskiy <borkra@gmail.com> for helping with this.
author Roy Marples <roy@marples.name>
date Sat, 12 Dec 2020 13:12:26 +0000
parents 8e2b8ce8c972
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4548
c7df03794de3 Add SPDX identifiers to all dhcpcd source files.
Yegor Yefremov <yegorslists@googlemail.com>
parents: 4520
diff changeset
1 /* SPDX-License-Identifier: BSD-2-Clause */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3 * Solaris interface driver for dhcpcd
4922
555d7d1a4939 Welcome to 2020!
Roy Marples <roy@marples.name>
parents: 4815
diff changeset
4 * Copyright (c) 2016-2020 Roy Marples <roy@marples.name>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
5 * All rights reserved
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
7 * Redistribution and use in source and binary forms, with or without
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
8 * modification, are permitted provided that the following conditions
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
9 * are met:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
10 * 1. Redistributions of source code must retain the above copyright
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
15 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
26 * SUCH DAMAGE.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
27 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
28
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
29 #include <assert.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
30 #include <errno.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
31 #include <fcntl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
32 #include <ifaddrs.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
33 #include <libdlpi.h>
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
34 #include <kstat.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
35 #include <stddef.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
36 #include <stdlib.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
37 #include <stropts.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
38 #include <string.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
39 #include <unistd.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
40
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
41 #include <inet/ip.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
42
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
43 #include <net/if_dl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
44 #include <net/if_types.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
45
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
46 #include <netinet/if_ether.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
47 #include <netinet/udp.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
48
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
49 #include <sys/ioctl.h>
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
50 #include <sys/mac.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
51 #include <sys/pfmod.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
52 #include <sys/tihdr.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
53 #include <sys/utsname.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
54
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
55 /* Private libsocket interface we can hook into to get
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
56 * a better getifaddrs(3).
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
57 * From libsocket_priv.h, which is not always distributed so is here. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
58 extern int getallifaddrs(sa_family_t, struct ifaddrs **, int64_t);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
59
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
60 #include "config.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
61 #include "bpf.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
62 #include "common.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
63 #include "dhcp.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
64 #include "if.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
65 #include "if-options.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
66 #include "ipv4.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
67 #include "ipv6.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
68 #include "ipv6nd.h"
4430
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
69 #include "logerr.h"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
70 #include "route.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
71 #include "sa.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
72
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
73 #ifndef ARP_MOD_NAME
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
74 # define ARP_MOD_NAME "arp"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
75 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
76
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
77 #ifndef RT_ROUNDUP
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
78 #define RT_ROUNDUP(a) \
4470
974677be560f sun: Making routing work with both 64-bit and 32-bit userlands
Roy Marples <roy@marples.name>
parents: 4469
diff changeset
79 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t))
4520
9c9d2b0827eb sun: Use sa_len rather than our variant.
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
80 #define RT_ADVANCE(x, n) ((x) += RT_ROUNDUP(sa_len((n))))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
82
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
83 #define COPYOUT(sin, sa) do { \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
84 if ((sa) && ((sa)->sa_family == AF_INET)) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
85 (sin) = ((const struct sockaddr_in *)(const void *) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
86 (sa))->sin_addr; \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
87 } while (0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
89 #define COPYOUT6(sin, sa) do { \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
90 if ((sa) && ((sa)->sa_family == AF_INET6)) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
91 (sin) = ((const struct sockaddr_in6 *)(const void *) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
92 (sa))->sin6_addr; \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
93 } while (0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
94
4520
9c9d2b0827eb sun: Use sa_len rather than our variant.
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
95 #define COPYSA(dst, src) memcpy((dst), (src), sa_len((src)))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
96
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
97 struct priv {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99 int pf_inet6_fd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
100 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
101 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
103 struct rtm
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
104 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
105 struct rt_msghdr hdr;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
106 char buffer[sizeof(struct sockaddr_storage) * RTAX_MAX];
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
107 };
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
108
4682
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
109 static int if_plumb(int, const struct dhcpcd_ctx *, int, const char *);
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
110
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
111 int
5458
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
112 os_init(void)
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
113 {
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
114 return 0;
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
115 }
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
116
dd8347a0ea1c Adjust prior so that message is logged before starting dev
Roy Marples <roy@marples.name>
parents: 5356
diff changeset
117 int
4682
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
118 if_init(struct interface *ifp)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
119 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
120
4682
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
121 #ifdef INET
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
122 if (if_plumb(RTM_NEWADDR, ifp->ctx, AF_INET, ifp->name) == -1 &&
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
123 errno != EEXIST)
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
124 return -1;
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
125 #endif
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
126
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
127 #ifdef INET6
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
128 if (if_plumb(RTM_NEWADDR, ifp->ctx, AF_INET6, ifp->name) == -1 &&
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
129 errno != EEXIST)
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
130 return -1;
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
131 #endif
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
132
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
133 if (ifp->index == 0)
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
134 ifp->index = if_nametoindex(ifp->name);
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
135
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
136 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
137 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
138
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
139 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
140 if_conf(__unused struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
141 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
142
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
143 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
144 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
145
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
146 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
147 if_opensockets_os(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
148 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
149 struct priv *priv;
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
150 int n;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
151
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
152 if ((priv = malloc(sizeof(*priv))) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
153 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
154 ctx->priv = priv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
155
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
156 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
157 priv->pf_inet6_fd = xsocket(PF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
158 /* Don't return an error so we at least work on kernels witout INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
159 * even though we expect INET6 support.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
160 * We will fail noisily elsewhere anyway. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
161 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
162
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
163 ctx->link_fd = socket(PF_ROUTE,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
164 SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
165
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
166 if (ctx->link_fd == -1) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 free(ctx->priv);
4326
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
168 return -1;
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
169 }
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
170
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
171 /* Ignore our own route(4) messages.
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
172 * Sadly there is no way of doing this for route(4) messages
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
173 * generated from addresses we add/delete. */
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
174 n = 0;
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
175 if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_USELOOPBACK,
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
176 &n, sizeof(n)) == -1)
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
177 logerr("%s: SO_USELOOPBACK", __func__);
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
178
009a47703a99 BSD: don't listen to own route messages
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
179 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
180 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
181
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
182 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
183 if_closesockets_os(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
184 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
185 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
186 struct priv *priv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
187
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
188 priv = (struct priv *)ctx->priv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
189 if (priv->pf_inet6_fd != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
190 close(priv->pf_inet6_fd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
191 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
192
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
193 /* each interface should have closed itself */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
194 free(ctx->priv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
195 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
196
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
197 int
4964
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
198 if_setmac(struct interface *ifp, void *mac, uint8_t maclen)
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
199 {
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
200
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
201 errno = ENOTSUP;
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
202 return -1;
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
203 }
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
204
f148a1b8a6e5 Solaris: Add a shim for hardware address randomisation
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
205 int
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5475
diff changeset
206 if_carrier(struct interface *ifp, __unused const void *ifadata)
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
207 {
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
208 kstat_ctl_t *kcp;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
209 kstat_t *ksp;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
210 kstat_named_t *knp;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
211 link_state_t linkstate;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
212
4495
74aa6ad52b0d BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents: 4480
diff changeset
213 if (if_getflags(ifp) == -1)
74aa6ad52b0d BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents: 4480
diff changeset
214 return LINK_UNKNOWN;
74aa6ad52b0d BSD: RTM_IFINFO is not emitted for all interfaces past unknown link
Roy Marples <roy@marples.name>
parents: 4480
diff changeset
215
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
216 kcp = kstat_open();
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
217 if (kcp == NULL)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
218 goto err;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
219 ksp = kstat_lookup(kcp, UNCONST("link"), 0, ifp->name);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
220 if (ksp == NULL)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
221 goto err;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
222 if (kstat_read(kcp, ksp, NULL) == -1)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
223 goto err;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
224 knp = kstat_data_lookup(ksp, UNCONST("link_state"));
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
225 if (knp == NULL)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
226 goto err;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
227 if (knp->data_type != KSTAT_DATA_UINT32)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
228 goto err;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
229 linkstate = (link_state_t)knp->value.ui32;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
230 kstat_close(kcp);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
231
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
232 switch (linkstate) {
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
233 case LINK_STATE_UP:
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
234 ifp->flags |= IFF_UP;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
235 return LINK_UP;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
236 case LINK_STATE_DOWN:
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
237 return LINK_DOWN;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
238 default:
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
239 return LINK_UNKNOWN;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
240 }
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
241
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
242 err:
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
243 if (kcp != NULL)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
244 kstat_close(kcp);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
245 return LINK_UNKNOWN;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
246 }
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
247
5557
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
248 bool
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
249 if_roaming(__unused struct interface *ifp)
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
250 {
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
251
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
252 return false;
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
253 }
e65d193a1960 Linux: Support wireless IP roaming
Roy Marples <roy@marples.name>
parents: 5486
diff changeset
254
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
255 int
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
256 if_mtu_os(const struct interface *ifp)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
257 {
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
258 dlpi_handle_t dh;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
259 dlpi_info_t dlinfo;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
260 int mtu;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
261
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
262 if (dlpi_open(ifp->name, &dh, 0) != DLPI_SUCCESS)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
263 return -1;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
264 if (dlpi_info(dh, &dlinfo, 0) == DLPI_SUCCESS)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
265 mtu = dlinfo.di_max_sdu;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
266 else
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
267 mtu = -1;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
268 dlpi_close(dh);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
269 return mtu;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
270 }
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
271
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
272 int
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
273 if_getssid(__unused struct interface *ifp)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
274 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
275
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
276 errno = ENOTSUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
277 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
278 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
279
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
280 /* XXX work out TAP interfaces? */
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
281 bool
4748
4cfd9d38741f BSD: Ignore interface groups as we would the interface name
Roy Marples <roy@marples.name>
parents: 4747
diff changeset
282 if_ignore(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname)
4747
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
283 {
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
284
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
285 return false;
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
286 }
c995401f5572 if: Ignore TAP interfaces by default
Roy Marples <roy@marples.name>
parents: 4698
diff changeset
287
4052
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
288 unsigned short
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
289 if_vlanid(__unused const struct interface *ifp)
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
290 {
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
291
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
292 return 0;
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
293 }
08038b46c0f5 Detect VLANID to use in IAID.
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
294
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
295 int
5215
c246c5e40b03 Fix compile on Linux and Solaris
Roy Marples <roy@marples.name>
parents: 5168
diff changeset
296 if_vimaster(__unused struct dhcpcd_ctx *ctx, __unused const char *ifname)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
297 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
298
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
299 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
300 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
301
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
302 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
303 if_machinearch(__unused char *str, __unused size_t len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
304 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
305
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
306 /* There is no extra data really.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
307 * isainfo -v does return amd64, but also i386. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
308 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
309 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
310
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
311 struct linkwalk {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
312 struct ifaddrs *lw_ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
313 int lw_error;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
314 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
315
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
316 static boolean_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
317 if_newaddr(const char *ifname, void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
318 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
319 struct linkwalk *lw = arg;
4466
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
320 int error;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
321 struct ifaddrs *ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
322 dlpi_handle_t dh;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
323 dlpi_info_t dlinfo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
324 uint8_t pa[DLPI_PHYSADDR_MAX];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
325 size_t pa_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
326 struct sockaddr_dl *sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
327
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
328 ifa = NULL;
4466
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
329 error = dlpi_open(ifname, &dh, 0);
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
330 if (error == DLPI_ENOLINK) /* Just vanished or in global zone */
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
331 return B_FALSE;
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
332 if (error != DLPI_SUCCESS)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
333 goto failed1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
334 if (dlpi_info(dh, &dlinfo, 0) != DLPI_SUCCESS)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
335 goto failed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
336
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
337 /* For some reason, dlpi_info won't return the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
338 * physical address, it's all zero's.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
339 * So cal dlpi_get_physaddr. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
340 pa_len = DLPI_PHYSADDR_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
341 if (dlpi_get_physaddr(dh, DL_CURR_PHYS_ADDR,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
342 pa, &pa_len) != DLPI_SUCCESS)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
343 goto failed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
344
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
345 if ((ifa = calloc(1, sizeof(*ifa))) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
346 goto failed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
347 if ((ifa->ifa_name = strdup(ifname)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
348 goto failed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
349 if ((sdl = calloc(1, sizeof(*sdl))) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
350 goto failed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
351
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
352 ifa->ifa_addr = (struct sockaddr *)sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
353 sdl->sdl_index = if_nametoindex(ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
354 sdl->sdl_family = AF_LINK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
355 switch (dlinfo.di_mactype) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
356 case DL_ETHER:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
357 sdl->sdl_type = IFT_ETHER;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
358 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
359 case DL_IB:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
360 sdl->sdl_type = IFT_IB;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
361 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
362 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
363 sdl->sdl_type = IFT_OTHER;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
364 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
365 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
366
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
367 sdl->sdl_alen = pa_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
368 memcpy(sdl->sdl_data, pa, pa_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
369
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
370 ifa->ifa_next = lw->lw_ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
371 lw->lw_ifa = ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
372 dlpi_close(dh);
4466
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
373 return B_FALSE;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
374
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
375 failed:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
376 dlpi_close(dh);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
377 if (ifa != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
378 free(ifa->ifa_name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
379 free(ifa->ifa_addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
380 free(ifa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
381 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
382 failed1:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
383 lw->lw_error = errno;
4466
bbc28f477a10 sun: Continue walking dlpi links when dlpi_open returns no link
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
384 return B_TRUE;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
385 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
386
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
387 /* Creates an empty sockaddr_dl for lo0. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
388 static struct ifaddrs *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
389 if_ifa_lo0(void)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
390 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
391 struct ifaddrs *ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
392 struct sockaddr_dl *sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
393
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
394 if ((ifa = calloc(1, sizeof(*ifa))) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
395 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
396 if ((sdl = calloc(1, sizeof(*sdl))) == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
397 free(ifa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
398 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
399 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
400 if ((ifa->ifa_name = strdup("lo0")) == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
401 free(ifa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
402 free(sdl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
403 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
404 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
405
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
406 ifa->ifa_addr = (struct sockaddr *)sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
407 ifa->ifa_flags = IFF_LOOPBACK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
408 sdl->sdl_family = AF_LINK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
409 sdl->sdl_index = if_nametoindex("lo0");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
410
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
411 return ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
412 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
413
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
414 /* getifaddrs(3) does not support AF_LINK, strips aliases and won't
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
415 * report addresses that are not UP.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
416 * As such it's just totally useless, so we need to roll our own. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
417 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
418 if_getifaddrs(struct ifaddrs **ifap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
419 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
420 struct linkwalk lw;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
421 struct ifaddrs *ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
422
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
423 /* Private libc function which we should not have to call
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
424 * to get non UP addresses. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
425 if (getallifaddrs(AF_UNSPEC, &lw.lw_ifa, 0) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
426 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
427
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
428 /* Start with some AF_LINK addresses. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
429 lw.lw_error = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
430 dlpi_walk(if_newaddr, &lw, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
431 if (lw.lw_error != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
432 freeifaddrs(lw.lw_ifa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
433 errno = lw.lw_error;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
434 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
435 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
436
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
437 /* lo0 doesn't appear in dlpi_walk, so fudge it. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
438 if ((ifa = if_ifa_lo0()) == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
439 freeifaddrs(lw.lw_ifa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
440 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
441 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
442 ifa->ifa_next = lw.lw_ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
443
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
444 *ifap = ifa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
445 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
446 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
447
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
448 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
449 if_linkaddr(struct sockaddr_dl *sdl, const struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
450 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
451
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
452 memset(sdl, 0, sizeof(*sdl));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
453 sdl->sdl_family = AF_LINK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
454 sdl->sdl_nlen = sdl->sdl_alen = sdl->sdl_slen = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
455 sdl->sdl_index = (unsigned short)ifp->index;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
456 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
457
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
458 static int
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
459 get_addrs(int type, const void *data, size_t data_len,
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
460 const struct sockaddr **sa)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
461 {
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
462 const char *cp, *ep;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
463 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
464
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
465 cp = data;
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
466 ep = cp + data_len;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
467 for (i = 0; i < RTAX_MAX; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
468 if (type & (1 << i)) {
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
469 if (cp >= ep) {
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
470 errno = EINVAL;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
471 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
472 }
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
473 sa[i] = (const struct sockaddr *)cp;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
474 RT_ADVANCE(cp, sa[i]);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
475 } else
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
476 sa[i] = NULL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
477 }
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
478
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
479 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
480 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
481
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
482 static struct interface *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
483 if_findsdl(struct dhcpcd_ctx *ctx, const struct sockaddr_dl *sdl)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
484 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
485
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
486 if (sdl->sdl_index)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
487 return if_findindex(ctx->ifaces, sdl->sdl_index);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
488
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
489 if (sdl->sdl_nlen) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
490 char ifname[IF_NAMESIZE];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
491
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
492 memcpy(ifname, sdl->sdl_data, sdl->sdl_nlen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
493 ifname[sdl->sdl_nlen] = '\0';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
494 return if_find(ctx->ifaces, ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
495 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
496 if (sdl->sdl_alen) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
497 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
498
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
499 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
500 if (ifp->hwlen == sdl->sdl_alen &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
501 memcmp(ifp->hwaddr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
502 sdl->sdl_data, sdl->sdl_alen) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
503 return ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
504 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
505 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
506
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
507 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
508 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
509 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
510
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
511 static struct interface *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
512 if_findsa(struct dhcpcd_ctx *ctx, const struct sockaddr *sa)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
513 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
514 if (sa == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
515 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
516 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
517 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
518
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
519 switch (sa->sa_family) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
520 case AF_LINK:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
521 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
522 const struct sockaddr_dl *sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
523
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
524 sdl = (const void *)sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
525 return if_findsdl(ctx, sdl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
526 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
527 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
528 case AF_INET:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
529 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
530 const struct sockaddr_in *sin;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
531 struct ipv4_addr *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
532
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
533 sin = (const void *)sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
534 if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
535 return ia->iface;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
536 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
537 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
538 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
539 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
540 case AF_INET6:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
541 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
542 const struct sockaddr_in6 *sin;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
543 struct ipv6_addr *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
544
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
545 sin = (const void *)sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
546 if ((ia = ipv6_findmaskaddr(ctx, &sin->sin6_addr)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
547 return ia->iface;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
548 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
549 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
550 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
551 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
552 errno = EAFNOSUPPORT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
553 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
554 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
555
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
556 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
557 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
558 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
559
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
560 static void
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
561 if_route0(struct dhcpcd_ctx *ctx, struct rtm *rtmsg,
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
562 unsigned char cmd, const struct rt *rt)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
563 {
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
564 struct rt_msghdr *rtm;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
565 char *bp = rtmsg->buffer;
4440
116946128ea1 sun: Don't read beyond the sockaddr length when making RTM
Roy Marples <roy@marples.name>
parents: 4436
diff changeset
566 socklen_t sl;
4475
0f69a209f608 sun: Fix adding IPv4LL default route
Roy Marples <roy@marples.name>
parents: 4470
diff changeset
567 bool gateway_unspec;
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
568
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
569 /* WARNING: Solaris will not allow you to delete RTF_KERNEL routes.
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
570 * This includes subnet/prefix routes. */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
571
4440
116946128ea1 sun: Don't read beyond the sockaddr length when making RTM
Roy Marples <roy@marples.name>
parents: 4436
diff changeset
572 #define ADDSA(sa) do { \
4520
9c9d2b0827eb sun: Use sa_len rather than our variant.
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
573 sl = sa_len((sa)); \
4440
116946128ea1 sun: Don't read beyond the sockaddr length when making RTM
Roy Marples <roy@marples.name>
parents: 4436
diff changeset
574 memcpy(bp, (sa), sl); \
116946128ea1 sun: Don't read beyond the sockaddr length when making RTM
Roy Marples <roy@marples.name>
parents: 4436
diff changeset
575 bp += RT_ROUNDUP(sl); \
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
576 } while (/* CONSTCOND */ 0)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
577
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
578 memset(rtmsg, 0, sizeof(*rtmsg));
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
579 rtm = &rtmsg->hdr;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
580 rtm->rtm_version = RTM_VERSION;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
581 rtm->rtm_type = cmd;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
582 rtm->rtm_seq = ++ctx->seq;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
583 rtm->rtm_flags = rt->rt_flags;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
584 rtm->rtm_addrs = RTA_DST | RTA_GATEWAY;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
585
4475
0f69a209f608 sun: Fix adding IPv4LL default route
Roy Marples <roy@marples.name>
parents: 4470
diff changeset
586 gateway_unspec = sa_is_unspecified(&rt->rt_gateway);
0f69a209f608 sun: Fix adding IPv4LL default route
Roy Marples <roy@marples.name>
parents: 4470
diff changeset
587
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
588 if (cmd == RTM_ADD || cmd == RTM_CHANGE) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
589 bool netmask_bcast = sa_is_allones(&rt->rt_netmask);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
590
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
591 rtm->rtm_flags |= RTF_UP;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
592 if (!(rtm->rtm_flags & RTF_REJECT) &&
4467
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
593 !sa_is_loopback(&rt->rt_gateway))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
594 {
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
595 rtm->rtm_addrs |= RTA_IFP;
4467
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
596 /* RTA_IFA is currently ignored by the kernel.
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
597 * RTA_SRC and RTF_SETSRC look like what we want,
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
598 * but they don't work with RTF_GATEWAY.
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
599 * We set RTA_IFA just in the hope that the
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
600 * kernel will one day support this. */
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
601 if (!sa_is_unspecified(&rt->rt_ifa))
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
602 rtm->rtm_addrs |= RTA_IFA;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
603 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
604
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
605 if (netmask_bcast)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
606 rtm->rtm_flags |= RTF_HOST;
4475
0f69a209f608 sun: Fix adding IPv4LL default route
Roy Marples <roy@marples.name>
parents: 4470
diff changeset
607 else if (!gateway_unspec)
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
608 rtm->rtm_flags |= RTF_GATEWAY;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
609
5356
39a8d5dfe695 BSD: Mark routes as static only from static config
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
610 if (rt->rt_dflags & RTDF_STATIC)
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
611 rtm->rtm_flags |= RTF_STATIC;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
612
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
613 if (rt->rt_mtu != 0) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
614 rtm->rtm_inits |= RTV_MTU;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
615 rtm->rtm_rmx.rmx_mtu = rt->rt_mtu;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
616 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
617 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
618
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
619 if (!(rtm->rtm_flags & RTF_HOST))
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
620 rtm->rtm_addrs |= RTA_NETMASK;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
621
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
622 ADDSA(&rt->rt_dest);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
623
4475
0f69a209f608 sun: Fix adding IPv4LL default route
Roy Marples <roy@marples.name>
parents: 4470
diff changeset
624 if (gateway_unspec)
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
625 ADDSA(&rt->rt_ifa);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
626 else
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
627 ADDSA(&rt->rt_gateway);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
628
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
629 if (rtm->rtm_addrs & RTA_NETMASK)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
630 ADDSA(&rt->rt_netmask);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
631
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
632 if (rtm->rtm_addrs & RTA_IFP) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
633 struct sockaddr_dl sdl;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
634
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
635 if_linkaddr(&sdl, rt->rt_ifp);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
636 ADDSA((struct sockaddr *)&sdl);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
637 }
4431
d9379821c392 sun: Fix routing issues
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
638
4467
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
639 if (rtm->rtm_addrs & RTA_IFA)
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
640 ADDSA(&rt->rt_ifa);
4467
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
641
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
642 #if 0
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
643 if (rtm->rtm_addrs & RTA_SRC)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
644 ADDSA(&rt->rt_ifa);
4467
4e3feb48fffb sun: Set RTA_IFP and RTA_IFA again for default routes
Roy Marples <roy@marples.name>
parents: 4466
diff changeset
645 #endif
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
646
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
647 rtm->rtm_msglen = (unsigned short)(bp - (char *)rtm);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
648 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
649
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
650 int
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
651 if_route(unsigned char cmd, const struct rt *rt)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
652 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
653 struct rtm rtm;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
654 struct dhcpcd_ctx *ctx = rt->rt_ifp->ctx;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
655
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
656 if_route0(ctx, &rtm, cmd, rt);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
657
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
658 if (write(ctx->link_fd, &rtm, rtm.hdr.rtm_msglen) == -1)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
659 return -1;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
660 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
661 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
662
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
663 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
664 if_copyrt(struct dhcpcd_ctx *ctx, struct rt *rt, const struct rt_msghdr *rtm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
665 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
666 const struct sockaddr *rti_info[RTAX_MAX];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
667
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
668 if (~rtm->rtm_addrs & RTA_DST) {
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
669 errno = EINVAL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
670 return -1;
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
671 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
672
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
673 if (get_addrs(rtm->rtm_addrs, (const char *)rtm + sizeof(*rtm),
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
674 rtm->rtm_msglen - sizeof(*rtm), rti_info) == -1)
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
675 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
676
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
677 memset(rt, 0, sizeof(*rt));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
678
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
679 rt->rt_flags = (unsigned int)rtm->rtm_flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
680 COPYSA(&rt->rt_dest, rti_info[RTAX_DST]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
681 if (rtm->rtm_addrs & RTA_NETMASK)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
682 COPYSA(&rt->rt_netmask, rti_info[RTAX_NETMASK]);
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
683
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
684 /* dhcpcd likes an unspecified gateway to indicate via the link.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
685 * However we need to know if gateway was a link with an address. */
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
686 if (rtm->rtm_addrs & RTA_GATEWAY) {
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
687 if (rti_info[RTAX_GATEWAY]->sa_family == AF_LINK) {
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
688 const struct sockaddr_dl *sdl;
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
689
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
690 sdl = (const struct sockaddr_dl*)
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
691 (const void *)rti_info[RTAX_GATEWAY];
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
692 if (sdl->sdl_alen != 0)
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
693 rt->rt_dflags |= RTDF_GATELINK;
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
694 } else if (rtm->rtm_flags & RTF_GATEWAY)
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
695 COPYSA(&rt->rt_gateway, rti_info[RTAX_GATEWAY]);
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
696 }
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
697
4431
d9379821c392 sun: Fix routing issues
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
698 if (rtm->rtm_addrs & RTA_SRC)
d9379821c392 sun: Fix routing issues
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
699 COPYSA(&rt->rt_ifa, rti_info[RTAX_SRC]);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
700 rt->rt_mtu = (unsigned int)rtm->rtm_rmx.rmx_mtu;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
701
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
702 if (rtm->rtm_index)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
703 rt->rt_ifp = if_findindex(ctx->ifaces, rtm->rtm_index);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
704 else if (rtm->rtm_addrs & RTA_IFP)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
705 rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_IFP]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
706 else if (rtm->rtm_addrs & RTA_GATEWAY)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
707 rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_GATEWAY]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
708 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
709 rt->rt_ifp = if_findsa(ctx, rti_info[RTAX_DST]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
710
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
711 if (rt->rt_ifp == NULL && rtm->rtm_type == RTM_MISS)
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
712 rt->rt_ifp = if_loopback(ctx);
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
713
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
714 if (rt->rt_ifp == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
715 errno = ESRCH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
716 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
717 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
718
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
719 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
720 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
721
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
722 static struct rt *
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
723 if_route_get(struct dhcpcd_ctx *ctx, struct rt *rt)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
724 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
725 struct rtm rtm;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
726 int s;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
727 struct iovec iov = { .iov_base = &rtm, .iov_len = sizeof(rtm) };
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
728 struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1 };
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
729 ssize_t len;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
730 struct rt *rtw = rt;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
731
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
732 if_route0(ctx, &rtm, RTM_GET, rt);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
733 rt = NULL;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
734 s = socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC, 0);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
735 if (s == -1)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
736 return NULL;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
737 if (write(s, &rtm, rtm.hdr.rtm_msglen) == -1)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
738 goto out;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
739 if ((len = recvmsg(s, &msg, 0)) == -1)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
740 goto out;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
741 if ((size_t)len < sizeof(rtm.hdr) || len < rtm.hdr.rtm_msglen) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
742 errno = EINVAL;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
743 goto out;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
744 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
745 if (if_copyrt(ctx, rtw, &rtm.hdr) == -1)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
746 goto out;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
747 rt = rtw;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
748
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
749 out:
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
750 close(s);
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
751 return rt;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
752 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
753
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
754 static int
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
755 if_finishrt(struct dhcpcd_ctx *ctx, struct rt *rt)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
756 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
757 int mtu;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
758
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
759 /* Solaris has a subnet route with the gateway
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
760 * of the owning address.
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
761 * dhcpcd has a blank gateway here to indicate a
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
762 * subnet route. */
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
763 if (!sa_is_unspecified(&rt->rt_dest) &&
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
764 !sa_is_unspecified(&rt->rt_gateway))
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
765 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
766 switch(rt->rt_gateway.sa_family) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
767 #ifdef INET
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
768 case AF_INET:
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
769 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
770 struct in_addr *in;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
771
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
772 in = &satosin(&rt->rt_gateway)->sin_addr;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
773 if (ipv4_findaddr(ctx, in))
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
774 in->s_addr = INADDR_ANY;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
775 break;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
776 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
777 #endif
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
778 #ifdef INET6
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
779 case AF_INET6:
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
780 {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
781 struct in6_addr *in6;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
782
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
783 in6 = &satosin6(&rt->rt_gateway)->sin6_addr;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
784 if (ipv6_findaddr(ctx, in6, 0))
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
785 *in6 = in6addr_any;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
786 break;
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
787 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
788 #endif
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
789 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
790 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
791
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
792 /* Solaris doesn't set interfaces for some routes.
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
793 * This sucks, so we need to call RTM_GET to
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
794 * work out the interface. */
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
795 if (rt->rt_ifp == NULL) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
796 if (if_route_get(ctx, rt) == NULL) {
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
797 rt->rt_ifp = if_loopback(ctx);
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
798 if (rt->rt_ifp == NULL)
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
799 return - 1;
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
800 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
801 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
802
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
803 /* Solaris likes to set route MTU to match
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
804 * interface MTU when adding routes.
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
805 * This confuses dhcpcd as it expects MTU to be 0
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
806 * when no explicit MTU has been set. */
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
807 mtu = if_getmtu(rt->rt_ifp);
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
808 if (mtu == -1)
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
809 return -1;
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
810 if (rt->rt_mtu == (unsigned int)mtu)
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
811 rt->rt_mtu = 0;
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
812
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
813 return 0;
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
814 }
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
815
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
816 static int
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
817 if_addrflags0(int fd, int af, const char *ifname)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
818 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
819 struct lifreq lifr;
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
820 int flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
821
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
822 memset(&lifr, 0, sizeof(lifr));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
823 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
824 if (ioctl(fd, SIOCGLIFFLAGS, &lifr) == -1)
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
825 return -1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
826
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
827 flags = 0;
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
828 if (lifr.lifr_flags & IFF_DUPLICATE)
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
829 flags |= af == AF_INET6 ? IN6_IFF_DUPLICATED:IN_IFF_DUPLICATED;
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
830 else if (!(lifr.lifr_flags & IFF_UP))
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
831 flags |= af == AF_INET6 ? IN6_IFF_TENTATIVE:IN_IFF_TENTATIVE;
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
832 return flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
833 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
834
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
835 static int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
836 if_rtm(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
837 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
838 const struct sockaddr *sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
839 struct rt rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
840
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
841 if (rtm->rtm_msglen < sizeof(*rtm) + sizeof(*sa)) {
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
842 errno = EINVAL;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
843 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
844 }
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
845
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
846 if (if_copyrt(ctx, &rt, rtm) == -1 && errno != ESRCH)
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
847 return -1;
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
848
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
849 #ifdef INET6
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
850 /*
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
851 * BSD announces host routes.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
852 * As such, we should be notified of reachability by its
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
853 * existance with a hardware address.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
854 * Ensure we don't call this for a newly incomplete state.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
855 */
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
856 if (rt.rt_dest.sa_family == AF_INET6 &&
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
857 (rt.rt_flags & RTF_HOST || rtm->rtm_type == RTM_MISS) &&
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
858 !(rtm->rtm_type == RTM_ADD && !(rt.rt_dflags & RTDF_GATELINK)))
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
859 {
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
860 bool reachable;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
861
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
862 reachable = (rtm->rtm_type == RTM_ADD ||
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
863 rtm->rtm_type == RTM_CHANGE) &&
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
864 rt.rt_dflags & RTDF_GATELINK;
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
865 ipv6nd_neighbour(ctx, &rt.rt_ss_dest.sin6.sin6_addr, reachable);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
866 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
867 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
868
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
869 if (if_finishrt(ctx, &rt) == -1)
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
870 return -1;
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
871 rt_recvrt(rtm->rtm_type, &rt, rtm->rtm_pid);
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
872 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
873 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
874
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
875 static bool
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
876 if_getalias(struct interface *ifp, const struct sockaddr *sa, char *alias)
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
877 {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
878 struct ifaddrs *ifaddrs, *ifa;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
879 struct interface *ifpx;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
880 bool found;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
881
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
882 ifaddrs = NULL;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
883 if (getallifaddrs(sa->sa_family, &ifaddrs, 0) == -1)
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
884 return false;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
885 found = false;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
886 for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
887 if (ifa->ifa_addr == NULL)
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
888 continue;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
889 if (sa_cmp(sa, ifa->ifa_addr) != 0)
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
890 continue;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
891 /* Check it's for the right interace. */
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
892 ifpx = if_find(ifp->ctx->ifaces, ifa->ifa_name);
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
893 if (ifp == ifpx) {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
894 strlcpy(alias, ifa->ifa_name, IF_NAMESIZE);
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
895 found = true;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
896 break;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
897 }
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
898 }
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
899 freeifaddrs(ifaddrs);
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
900 return found;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
901 }
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
902
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
903 static int
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
904 if_getbrdaddr(struct dhcpcd_ctx *ctx, const char *ifname, struct in_addr *brd)
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
905 {
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
906 struct lifreq lifr = { 0 };
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
907 int r;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
908
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
909 memset(&lifr, 0, sizeof(lifr));
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
910 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
911 errno = 0;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
912 r = ioctl(ctx->pf_inet_fd, SIOCGLIFBRDADDR, &lifr, sizeof(lifr));
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
913 if (r != -1)
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
914 COPYOUT(*brd, (struct sockaddr *)&lifr.lifr_broadaddr);
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
915 return r;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
916 }
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
917
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
918 static int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
919 if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
920 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
921 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
922 const struct sockaddr *sa, *rti_info[RTAX_MAX];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
923 int flags;
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
924 char ifalias[IF_NAMESIZE];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
925
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
926 if (ifam->ifam_msglen < sizeof(*ifam)) {
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
927 errno = EINVAL;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
928 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
929 }
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
930 if (~ifam->ifam_addrs & RTA_IFA)
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
931 return 0;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
932
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
933 if (get_addrs(ifam->ifam_addrs, (const char *)ifam + sizeof(*ifam),
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
934 ifam->ifam_msglen - sizeof(*ifam), rti_info) == -1)
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
935 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
936 sa = rti_info[RTAX_IFA];
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
937
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
938 /* XXX We have no way of knowing who generated these
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
939 * messages wich truely sucks because we want to
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
940 * avoid listening to our own delete messages. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
941 if ((ifp = if_findindex(ctx->ifaces, ifam->ifam_index)) == NULL)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
942 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
943
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
944 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
945 * ifa_msghdr does not supply the alias, just the interface index.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
946 * This is very bad, because it means we have to call getifaddrs
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
947 * and trawl the list of addresses to find the added address.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
948 * To make life worse, you can have the same address on the same
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
949 * interface with different aliases.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
950 * So this hack is not entirely accurate.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
951 *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
952 * IF anyone is going to fix Solaris, plesse consider adding the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
953 * following fields to extend ifa_msghdr:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
954 * ifam_alias
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
955 * ifam_pid
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
956 */
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
957 if (ifam->ifam_type != RTM_DELADDR && !if_getalias(ifp, sa, ifalias))
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
958 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
959
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
960 switch (sa->sa_family) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
961 case AF_LINK:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
962 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
963 struct sockaddr_dl sdl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
964
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
965 if (ifam->ifam_type != RTM_CHGADDR &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
966 ifam->ifam_type != RTM_NEWADDR)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
967 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
968 memcpy(&sdl, rti_info[RTAX_IFA], sizeof(sdl));
5168
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 4964
diff changeset
969 dhcpcd_handlehwaddr(ifp, ifp->hwtype,
1f5dc6102f9b if: support changing hardware address type on Linux
Roy Marples <roy@marples.name>
parents: 4964
diff changeset
970 CLLADDR(&sdl), sdl.sdl_alen);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
971 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
972 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
973 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
974 case AF_INET:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
975 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
976 struct in_addr addr, mask, bcast;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
977
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
978 COPYOUT(addr, rti_info[RTAX_IFA]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
979 COPYOUT(mask, rti_info[RTAX_NETMASK]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
980 COPYOUT(bcast, rti_info[RTAX_BRD]);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
981
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
982 if (ifam->ifam_type == RTM_DELADDR) {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
983 struct ipv4_addr *ia;
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
984
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
985 ia = ipv4_iffindaddr(ifp, &addr, &mask);
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
986 if (ia == NULL)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
987 return 0;
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
988 strlcpy(ifalias, ia->alias, sizeof(ifalias));
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
989 } else if (bcast.s_addr == INADDR_ANY) {
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
990 /* Work around a bug where broadcast
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
991 * address is not correctly reported. */
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
992 if (if_getbrdaddr(ctx, ifalias, &bcast) == -1)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
993 return 0;
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
994 }
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
995 flags = if_addrflags(ifp, NULL, ifalias);
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
996 if (ifam->ifam_type == RTM_DELADDR) {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
997 if (flags != -1)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
998 return 0;
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
999 } else if (flags == -1)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1000 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1001
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1002 ipv4_handleifa(ctx,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1003 ifam->ifam_type == RTM_CHGADDR ?
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1004 RTM_NEWADDR : ifam->ifam_type,
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4221
diff changeset
1005 NULL, ifalias, &addr, &mask, &bcast, flags, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1006 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1007 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1008 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1009 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1010 case AF_INET6:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1011 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1012 struct in6_addr addr6, mask6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1013 const struct sockaddr_in6 *sin6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1014
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1015 sin6 = (const void *)rti_info[RTAX_IFA];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1016 addr6 = sin6->sin6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1017 sin6 = (const void *)rti_info[RTAX_NETMASK];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1018 mask6 = sin6->sin6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1019
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1020 if (ifam->ifam_type == RTM_DELADDR) {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1021 struct ipv6_addr *ia;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1022
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1023 ia = ipv6_iffindaddr(ifp, &addr6, 0);
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1024 if (ia == NULL)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1025 return 0;
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1026 strlcpy(ifalias, ia->alias, sizeof(ifalias));
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1027 }
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
1028 flags = if_addrflags6(ifp, NULL, ifalias);
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1029 if (ifam->ifam_type == RTM_DELADDR) {
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1030 if (flags != -1)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1031 return 0;
4469
246f6cfa2f6b sun: Fix numerous issues handling route messages
Roy Marples <roy@marples.name>
parents: 4468
diff changeset
1032 } else if (flags == -1)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1033 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1034
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1035 ipv6_handleifa(ctx,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1036 ifam->ifam_type == RTM_CHGADDR ?
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1037 RTM_NEWADDR : ifam->ifam_type,
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4221
diff changeset
1038 NULL, ifalias, &addr6, ipv6_prefixlen(&mask6), flags, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1039 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1040 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1041 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1042 }
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1043
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1044 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1045 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1046
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1047 static int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1048 if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1049 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1050 struct interface *ifp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1051 int state;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1052 unsigned int flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1053
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1054 if (ifm->ifm_msglen < sizeof(*ifm)) {
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1055 errno = EINVAL;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1056 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1057 }
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1058
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1059 if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1060 return 0;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1061 flags = (unsigned int)ifm->ifm_flags;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1062 if (ifm->ifm_flags & IFF_OFFLINE)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1063 state = LINK_DOWN;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1064 else {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1065 state = LINK_UP;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1066 flags |= IFF_UP;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1067 }
5486
8e2b8ce8c972 BSD: struct if_data->ifi_link_state is the single source of truth
Roy Marples <roy@marples.name>
parents: 5475
diff changeset
1068 dhcpcd_handlecarrier(ifp, state, flags);
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1069 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1070 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1071
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1072 static int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1073 if_dispatch(struct dhcpcd_ctx *ctx, const struct rt_msghdr *rtm)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1074 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1075
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1076 if (rtm->rtm_version != RTM_VERSION)
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1077 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1078
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1079 switch(rtm->rtm_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1080 case RTM_IFINFO:
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1081 return if_ifinfo(ctx, (const void *)rtm);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1082 case RTM_ADD: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1083 case RTM_CHANGE: /* FALLTHROUGH */
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1084 case RTM_DELETE: /* FALLTHROUGH */
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1085 case RTM_MISS:
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1086 return if_rtm(ctx, (const void *)rtm);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1087 case RTM_CHGADDR: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1088 case RTM_DELADDR: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1089 case RTM_NEWADDR:
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1090 return if_ifa(ctx, (const void *)rtm);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1091 }
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1092
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1093 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1094 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1095
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1096 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1097 if_handlelink(struct dhcpcd_ctx *ctx)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1098 {
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
1099 struct rtm rtm;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1100 ssize_t len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1101
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1102 len = read(ctx->link_fd, &rtm, sizeof(rtm));
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1103 if (len == -1)
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1104 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1105 if (len == 0)
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1106 return 0;
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1107 if ((size_t)len < sizeof(rtm.hdr.rtm_msglen) ||
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1108 len != rtm.hdr.rtm_msglen)
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1109 {
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1110 errno = EINVAL;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1111 return -1;
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1112 }
4680
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1113 /*
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1114 * Coverity thinks that the data could be tainted from here.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1115 * I have no idea how because the length of the data we read
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1116 * is guarded by len and checked to match rtm_msglen.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1117 * The issue seems to be related to extracting the addresses
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1118 * at the end of the header, but seems to have no issues with the
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1119 * equivalent call in if_initrt.
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1120 */
04b5168213cc Solaris: Bring across recent BSD improvements
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
1121 /* coverity[tainted_data] */
4504
d2b939b8b5bc sun: Apply same RTM validation from BSD
Roy Marples <roy@marples.name>
parents: 4495
diff changeset
1122 return if_dispatch(ctx, &rtm.hdr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1123 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1124
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1125 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1126 if_octetstr(char *buf, const Octet_t *o, ssize_t len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1127 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1128 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1129 char *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1130
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1131 p = buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1132 for (i = 0; i < o->o_length; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1133 if ((p + 1) - buf < len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1134 *p++ = o->o_bytes[i];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1135 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1136 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1137 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1138 *p = '\0';
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1139 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1140
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1141 static int
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1142 if_setflags(int fd, const char *ifname, uint64_t flags)
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1143 {
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1144 struct lifreq lifr = { .lifr_addrlen = 0 };
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1145
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1146 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1147 if (ioctl(fd, SIOCGLIFFLAGS, &lifr) == -1)
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1148 return -1;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1149 if ((lifr.lifr_flags & flags) != flags) {
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1150 lifr.lifr_flags |= flags;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1151 if (ioctl(fd, SIOCSLIFFLAGS, &lifr) == -1)
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1152 return -1;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1153 }
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1154 return 0;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1155 }
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1156
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1157 static int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1158 if_addaddr(int fd, const char *ifname,
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1159 struct sockaddr_storage *addr, struct sockaddr_storage *mask,
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1160 struct sockaddr_storage *brd, uint8_t plen)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1161 {
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1162 struct lifreq lifr = { .lifr_addrlen = plen };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1163
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1164 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1165
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1166 /* First assign the netmask. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1167 lifr.lifr_addr = *mask;
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1168 if (addr == NULL) {
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1169 lifr.lifr_addrlen = plen;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1170 if (ioctl(fd, SIOCSLIFSUBNET, &lifr) == -1)
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1171 return -1;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1172 goto up;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1173 } else {
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1174 if (ioctl(fd, SIOCSLIFNETMASK, &lifr) == -1)
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1175 return -1;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1176 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1177
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1178 /* Then assign the address. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1179 lifr.lifr_addr = *addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1180 if (ioctl(fd, SIOCSLIFADDR, &lifr) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1181 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1182
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1183 /* Then assign the broadcast address. */
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1184 if (brd != NULL) {
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1185 lifr.lifr_broadaddr = *brd;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1186 if (ioctl(fd, SIOCSLIFBRDADDR, &lifr) == -1)
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1187 return -1;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1188 }
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1189
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1190 up:
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1191 return if_setflags(fd, ifname, IFF_UP);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1192 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1193
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1194 static int
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1195 if_getaf_fd(const struct dhcpcd_ctx *ctx, int af)
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1196 {
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1197
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1198 if (af == AF_INET)
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1199 return ctx->pf_inet_fd;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1200 if (af == AF_INET6) {
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1201 struct priv *priv;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1202
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1203 priv = (struct priv *)ctx->priv;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1204 return priv->pf_inet6_fd;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1205 }
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1206
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1207 errno = EAFNOSUPPORT;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1208 return -1;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1209 }
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1210
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1211 int
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1212 if_getsubnet(struct dhcpcd_ctx *ctx, const char *ifname, int af,
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1213 void *subnet, size_t subnet_len)
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1214 {
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1215 struct lifreq lifr = { .lifr_addrlen = 0 };
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1216 int fd;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1217
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1218 fd = if_getaf_fd(ctx, af);
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1219 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1220 if (ioctl(fd, SIOCGLIFSUBNET, &lifr) == -1)
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1221 return -1;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1222 memcpy(subnet, &lifr.lifr_addr, MIN(subnet_len,sizeof(lifr.lifr_addr)));
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1223 return 0;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1224 }
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1225
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1226 static int
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1227 if_plumblif(int cmd, const struct dhcpcd_ctx *ctx, int af, const char *ifname)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1228 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1229 struct lifreq lifr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1230 int s;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1231
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1232 memset(&lifr, 0, sizeof(lifr));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1233 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1234 lifr.lifr_addr.ss_family = af;
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1235 s = if_getaf_fd(ctx, af);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1236 return ioctl(s,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1237 cmd == RTM_NEWADDR ? SIOCLIFADDIF : SIOCLIFREMOVEIF,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1238 &lifr) == -1 && errno != EEXIST ? -1 : 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1239 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1240
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1241 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1242 if_plumbif(const struct dhcpcd_ctx *ctx, int af, const char *ifname)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1243 {
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1244 dlpi_handle_t dh, dh_arp = NULL;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1245 int fd, af_fd, mux_fd, arp_fd = -1, mux_id, retval;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1246 uint64_t flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1247 struct lifreq lifr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1248 const char *udp_dev;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1249 struct strioctl ioc;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1250 struct if_spec spec;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1251
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1252 if (if_nametospec(ifname, &spec) == -1)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1253 return -1;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1254
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1255 af_fd = if_getaf_fd(ctx, af);
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1256
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1257 switch (af) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1258 case AF_INET:
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1259 flags = IFF_IPV4;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1260 udp_dev = UDP_DEV_NAME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1261 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1262 case AF_INET6:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1263 /* We will take care of setting the link local address. */
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1264 flags = IFF_IPV6 | IFF_NOLINKLOCAL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1265 udp_dev = UDP6_DEV_NAME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1266 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1267 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1268 errno = EPROTONOSUPPORT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1269 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1270 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1271
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1272 if (dlpi_open(ifname, &dh, DLPI_NOATTACH) != DLPI_SUCCESS) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1273 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1274 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1275 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1276
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1277 fd = dlpi_fd(dh);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1278 retval = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1279 mux_fd = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1280 if (ioctl(fd, I_PUSH, IP_MOD_NAME) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1281 goto out;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1282 memset(&lifr, 0, sizeof(lifr));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1283 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1284 lifr.lifr_ppa = spec.ppa;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1285 lifr.lifr_flags = flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1286 if (ioctl(fd, SIOCSLIFNAME, &lifr) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1287 goto out;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1288
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1289 /* Get full flags. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1290 if (ioctl(af_fd, SIOCGLIFFLAGS, &lifr) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1291 goto out;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1292 flags = lifr.lifr_flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1293
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1294 /* Open UDP as a multiplexor to PLINK the interface stream.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1295 * UDP is used because STREAMS will not let you PLINK a driver
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1296 * under itself and IP is generally at the bottom of the stream. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1297 if ((mux_fd = open(udp_dev, O_RDWR)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1298 goto out;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1299 /* POP off all undesired modules. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1300 while (ioctl(mux_fd, I_POP, 0) != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1301 ;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1302 if (errno != EINVAL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1303 goto out;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1304 if(ioctl(mux_fd, I_PUSH, ARP_MOD_NAME) == -1)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1305 goto out;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1306
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1307 if (flags & (IFF_NOARP | IFF_IPV6)) {
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1308 /* PLINK the interface stream so it persists. */
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1309 if (ioctl(mux_fd, I_PLINK, fd) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1310 goto out;
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1311 goto done;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1312 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1313
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1314 if (dlpi_open(ifname, &dh_arp, DLPI_NOATTACH) != DLPI_SUCCESS)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1315 goto out;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1316 arp_fd = dlpi_fd(dh_arp);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1317 if (ioctl(arp_fd, I_PUSH, ARP_MOD_NAME) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1318 goto out;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1319
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1320 memset(&lifr, 0, sizeof(lifr));
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1321 strlcpy(lifr.lifr_name, ifname, sizeof(lifr.lifr_name));
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1322 lifr.lifr_ppa = spec.ppa;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1323 lifr.lifr_flags = flags;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1324 memset(&ioc, 0, sizeof(ioc));
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1325 ioc.ic_cmd = SIOCSLIFNAME;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1326 ioc.ic_dp = (char *)&lifr;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1327 ioc.ic_len = sizeof(lifr);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1328 if (ioctl(arp_fd, I_STR, &ioc) == -1)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1329 goto out;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1330
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1331 /* PLINK the interface stream so it persists. */
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1332 mux_id = ioctl(mux_fd, I_PLINK, fd);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1333 if (mux_id == -1)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1334 goto out;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1335 if (ioctl(mux_fd, I_PLINK, arp_fd) == -1) {
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1336 ioctl(mux_fd, I_PUNLINK, mux_id);
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1337 goto out;
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1338 }
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1339
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1340 done:
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1341 retval = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1342
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1343 out:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1344 dlpi_close(dh);
4433
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1345 if (dh_arp != NULL)
4262dbc903e8 sun: Fix carrier detection, MTU detection and plumbing
Roy Marples <roy@marples.name>
parents: 4431
diff changeset
1346 dlpi_close(dh_arp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1347 if (mux_fd != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1348 close(mux_fd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1349 return retval;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1350 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1351
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1352 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1353 if_unplumbif(const struct dhcpcd_ctx *ctx, int af, const char *ifname)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1354 {
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1355 struct sockaddr_storage addr = { .ss_family = af };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1356 int fd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1357
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1358 /* For the time being, don't unplumb the interface, just
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1359 * set the address to zero. */
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1360 fd = if_getaf_fd(ctx, af);
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1361 return if_addaddr(fd, ifname, &addr, &addr,
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1362 af == AF_INET ? &addr : NULL, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1363 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1364
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1365 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1366 if_plumb(int cmd, const struct dhcpcd_ctx *ctx, int af, const char *ifname)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1367 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1368 struct if_spec spec;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1369
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1370 if (if_nametospec(ifname, &spec) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1371 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1372 if (spec.lun != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1373 return if_plumblif(cmd, ctx, af, ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1374 if (cmd == RTM_NEWADDR)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1375 return if_plumbif(ctx, af, ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1376 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1377 return if_unplumbif(ctx, af, ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1378 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1379
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1380 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1381 static int
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1382 if_walkrt(struct dhcpcd_ctx *ctx, rb_tree_t *routes, char *data, size_t len)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1383 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1384 mib2_ipRouteEntry_t *re, *e;
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1385 struct rt rt, *rtn;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1386 char ifname[IF_NAMESIZE];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1387 struct in_addr in;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1388
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1389 if (len % sizeof(*re) != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1390 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1391 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1392 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1393
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1394 re = (mib2_ipRouteEntry_t *)data;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1395 e = (mib2_ipRouteEntry_t *)(data + len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1396 do {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1397 /* Skip route types we don't want. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1398 switch (re->ipRouteInfo.re_ire_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1399 case IRE_IF_CLONE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1400 case IRE_BROADCAST:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1401 case IRE_MULTICAST:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1402 case IRE_NOROUTE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1403 case IRE_LOCAL:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1404 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1405 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1406 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1407 }
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
1408
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1409 memset(&rt, 0, sizeof(rt));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1410 in.s_addr = re->ipRouteDest;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1411 sa_in_init(&rt.rt_dest, &in);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1412 in.s_addr = re->ipRouteMask;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1413 sa_in_init(&rt.rt_netmask, &in);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1414 in.s_addr = re->ipRouteNextHop;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1415 sa_in_init(&rt.rt_gateway, &in);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1416 rt.rt_flags = re->ipRouteInfo.re_flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1417 in.s_addr = re->ipRouteInfo.re_src_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1418 sa_in_init(&rt.rt_ifa, &in);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1419 rt.rt_mtu = re->ipRouteInfo.re_max_frag;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1420 if_octetstr(ifname, &re->ipRouteIfIndex, sizeof(ifname));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1421 rt.rt_ifp = if_find(ctx->ifaces, ifname);
4511
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1422 if (if_finishrt(ctx, &rt) == -1) {
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1423 logerr(__func__);
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1424 continue;
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1425 }
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1426 if ((rtn = rt_new(rt.rt_ifp)) == NULL) {
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
1427 logerr(__func__);
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1428 break;
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1429 }
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1430 memcpy(rtn, &rt, sizeof(*rtn));
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1431 if (rb_tree_insert_node(routes, rtn) != rtn)
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1432 rt_free(rtn);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1433 } while (++re < e);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1434 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1435 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1436 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1437
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1438 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1439 static int
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1440 if_walkrt6(struct dhcpcd_ctx *ctx, rb_tree_t *routes, char *data, size_t len)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1441 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1442 mib2_ipv6RouteEntry_t *re, *e;
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1443 struct rt rt, *rtn;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1444 char ifname[IF_NAMESIZE];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1445 struct in6_addr in6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1446
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1447 if (len % sizeof(*re) != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1448 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1449 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1450 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1451
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1452 re = (mib2_ipv6RouteEntry_t *)data;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1453 e = (mib2_ipv6RouteEntry_t *)(data + len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1454
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1455 do {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1456 /* Skip route types we don't want. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1457 switch (re->ipv6RouteInfo.re_ire_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1458 case IRE_IF_CLONE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1459 case IRE_BROADCAST:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1460 case IRE_MULTICAST:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1461 case IRE_NOROUTE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1462 case IRE_LOCAL:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1463 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1464 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1465 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1466 }
4436
52c29572025b sun: Find the interface in if_finishrt
Roy Marples <roy@marples.name>
parents: 4435
diff changeset
1467
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1468 memset(&rt, 0, sizeof(rt));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1469 sa_in6_init(&rt.rt_dest, &re->ipv6RouteDest);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1470 ipv6_mask(&in6, re->ipv6RoutePfxLength);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1471 sa_in6_init(&rt.rt_netmask, &in6);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1472 sa_in6_init(&rt.rt_gateway, &re->ipv6RouteNextHop);
4468
714f593946d5 sun: Read RTA_IFA for IPv6 routes.
Roy Marples <roy@marples.name>
parents: 4467
diff changeset
1473 sa_in6_init(&rt.rt_ifa, &re->ipv6RouteInfo.re_src_addr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1474 rt.rt_mtu = re->ipv6RouteInfo.re_max_frag;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1475 if_octetstr(ifname, &re->ipv6RouteIfIndex, sizeof(ifname));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1476 rt.rt_ifp = if_find(ctx->ifaces, ifname);
4511
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1477 if (if_finishrt(ctx, &rt) == -1) {
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1478 logerr(__func__);
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1479 continue;
a4f492ca06a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4443 4505
diff changeset
1480 }
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1481 if ((rtn = rt_new(rt.rt_ifp)) == NULL) {
4505
b64cc1ef18bb sun: More validation around route messages
Roy Marples <roy@marples.name>
parents: 4504
diff changeset
1482 logerr(__func__);
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1483 break;
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1484 }
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1485 memcpy(rtn, &rt, sizeof(*rtn));
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1486 if (rb_tree_insert_node(routes, rtn) != rtn)
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1487 rt_free(rtn);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 } while (++re < e);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1489 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1490 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1491 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1492
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1493 static int
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1494 if_parsert(struct dhcpcd_ctx *ctx, rb_tree_t *routes,
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1495 unsigned int level, unsigned int name,
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1496 int (*walkrt)(struct dhcpcd_ctx *, rb_tree_t *, char *, size_t))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1497 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1498 int s, retval, code, flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1499 uintptr_t buf[512 / sizeof(uintptr_t)];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1500 struct strbuf ctlbuf, databuf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1501 struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1502 struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1503 struct T_error_ack *tea = (struct T_error_ack *)buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1504 struct opthdr *req;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1505
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1506 if ((s = open("/dev/arp", O_RDWR)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1507 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1508
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1509 /* Assume we are erroring. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1510 retval = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1511
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1512 tor->PRIM_type = T_SVR4_OPTMGMT_REQ;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1513 tor->OPT_offset = sizeof (struct T_optmgmt_req);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1514 tor->OPT_length = sizeof (struct opthdr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1515 tor->MGMT_flags = T_CURRENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1516
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1517 req = (struct opthdr *)&tor[1];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1518 req->level = EXPER_IP_AND_ALL_IRES;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1519 req->name = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1520 req->len = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1521
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1522 ctlbuf.buf = (char *)buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1523 ctlbuf.len = tor->OPT_length + tor->OPT_offset;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1524 if (putmsg(s, &ctlbuf, NULL, 0) == 1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1525 goto out;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1526
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1527 req = (struct opthdr *)&toa[1];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1528 ctlbuf.maxlen = sizeof(buf);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1529
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1530 /* Create a reasonable buffer to start with */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1531 databuf.maxlen = BUFSIZ * 2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1532 if ((databuf.buf = malloc(databuf.maxlen)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1533 goto out;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1534
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1535 for (;;) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1536 flags = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1537 if ((code = getmsg(s, &ctlbuf, 0, &flags)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1538 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1539 if (code == 0 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1540 toa->PRIM_type == T_OPTMGMT_ACK &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1541 toa->MGMT_flags == T_SUCCESS &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1542 (size_t)ctlbuf.len >= sizeof(struct T_optmgmt_ack))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1543 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1544 /* End of messages, so return success! */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1545 retval = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1546 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1547 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1548 if (tea->PRIM_type == T_ERROR_ACK) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1549 errno = tea->TLI_error == TSYSERR ?
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1550 tea->UNIX_error : EPROTO;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1551 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1552 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1553 if (code != MOREDATA ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1554 toa->PRIM_type != T_OPTMGMT_ACK ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1555 toa->MGMT_flags != T_SUCCESS)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1556 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1557 errno = ENOMSG;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1558 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1559 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1560
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1561 /* Try to ensure out buffer is big enough
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1562 * for future messages as well. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1563 if ((size_t)databuf.maxlen < req->len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1564 size_t newlen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1565
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1566 free(databuf.buf);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1567 newlen = roundup(req->len, BUFSIZ);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1568 if ((databuf.buf = malloc(newlen)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1569 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1570 databuf.maxlen = newlen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1571 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1572
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1573 flags = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1574 if (getmsg(s, NULL, &databuf, &flags) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1575 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1576
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1577 /* We always have to get the data before moving onto
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1578 * the next item, so don't move this test higher up
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1579 * to avoid the buffer allocation and getmsg calls. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1580 if (req->level == level && req->name == name) {
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1581 if (walkrt(ctx, routes, databuf.buf, req->len) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1582 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1583 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1584 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1585
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1586 free(databuf.buf);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1587 out:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1588 close(s);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1589 return retval;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1590 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1591
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1592
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1593 int
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1594 if_initrt(struct dhcpcd_ctx *ctx, rb_tree_t *routes, int af)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1595 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1596
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1597 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1598 if ((af == AF_UNSPEC || af == AF_INET) &&
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1599 if_parsert(ctx, routes, MIB2_IP,MIB2_IP_ROUTE, if_walkrt) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1600 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1601 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1602 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1603 if ((af == AF_UNSPEC || af == AF_INET6) &&
4443
ec7ded7718ae sun: Add rbtree support
Roy Marples <roy@marples.name>
parents: 4440
diff changeset
1604 if_parsert(ctx, routes, MIB2_IP6, MIB2_IP6_ROUTE, if_walkrt6) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1605 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1606 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1607 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1608 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1609
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1610
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1611 #ifdef INET
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1612 /* XXX We should fix this to write via the BPF interface. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1613 ssize_t
5276
3bc21bfa52f8 Solaris: Fix compile
Roy Marples <roy@marples.name>
parents: 5215
diff changeset
1614 bpf_send(const struct bpf *bpf, uint16_t protocol, const void *data, size_t len)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1615 {
5276
3bc21bfa52f8 Solaris: Fix compile
Roy Marples <roy@marples.name>
parents: 5215
diff changeset
1616 const struct interface *ifp = bpf->bpf_ifp;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1617 dlpi_handle_t dh;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1618 dlpi_info_t di;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1619 int r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1620
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1621 if (dlpi_open(ifp->name, &dh, 0) != DLPI_SUCCESS)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1622 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1623 if ((r = dlpi_info(dh, &di, 0)) == DLPI_SUCCESS &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1624 (r = dlpi_bind(dh, protocol, NULL)) == DLPI_SUCCESS)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1625 r = dlpi_send(dh, di.di_bcastaddr, ifp->hwlen, data, len, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1626 dlpi_close(dh);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1627 return r == DLPI_SUCCESS ? (ssize_t)len : -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1628 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1629
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1630 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1631 if_address(unsigned char cmd, const struct ipv4_addr *ia)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1632 {
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1633 union {
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1634 struct sockaddr sa;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1635 struct sockaddr_storage ss;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1636 } addr, mask, brd;
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1637 int fd = ia->iface->ctx->pf_inet_fd;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1638
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1639 /* Either remove the alias or ensure it exists. */
4682
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
1640 if (if_plumb(cmd, ia->iface->ctx, AF_INET, ia->alias) == -1 &&
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
1641 errno != EEXIST)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1642 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1643
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1644 if (cmd == RTM_DELADDR)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1645 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1646
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1647 if (cmd != RTM_NEWADDR) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1648 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1649 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1650 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1651
4435
3adc126c82e3 sun: Update the interface index after plumbing
Roy Marples <roy@marples.name>
parents: 4434
diff changeset
1652 /* We need to update the index now */
3adc126c82e3 sun: Update the interface index after plumbing
Roy Marples <roy@marples.name>
parents: 4434
diff changeset
1653 ia->iface->index = if_nametoindex(ia->alias);
3adc126c82e3 sun: Update the interface index after plumbing
Roy Marples <roy@marples.name>
parents: 4434
diff changeset
1654
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1655 sa_in_init(&addr.sa, &ia->addr);
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1656 sa_in_init(&mask.sa, &ia->mask);
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1657 sa_in_init(&brd.sa, &ia->brd);
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1658 return if_addaddr(fd, ia->alias, &addr.ss, &mask.ss, &brd.ss, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1659 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1660
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1661 int
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
1662 if_addrflags(const struct interface *ifp, __unused const struct in_addr * ia,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1663 const char *alias)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1664 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1665
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
1666 return if_addrflags0(ifp->ctx->pf_inet_fd, AF_INET, alias);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1667 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1668
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1669 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1670
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1671 #ifdef INET6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1672 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1673 if_address6(unsigned char cmd, const struct ipv6_addr *ia)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1674 {
4480
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1675 union {
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1676 struct sockaddr sa;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1677 struct sockaddr_in6 sin6;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1678 struct sockaddr_storage ss;
d3e01f5908b4 sun: Detect correct broadcast address as RTM_NEWADDR lies
Roy Marples <roy@marples.name>
parents: 4475
diff changeset
1679 } addr, mask;
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1680 int fd, r;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1681
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1682 /* Either remove the alias or ensure it exists. */
4682
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
1683 if (if_plumb(cmd, ia->iface->ctx, AF_INET6, ia->alias) == -1 &&
aec41ec4e762 Solaris: plumb interface at init if does not exist
Roy Marples <roy@marples.name>
parents: 4680
diff changeset
1684 errno != EEXIST)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1685 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1686
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1687 if (cmd == RTM_DELADDR)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1688 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1689
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1690 if (cmd != RTM_NEWADDR) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1691 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1692 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1693 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1694
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1695 fd = if_getaf_fd(ia->iface->ctx, AF_INET6);
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1696
4698
2750ed3b1d21 Solaris: Only set IFF_NOLOCAL for onlink only prefixes
Roy Marples <roy@marples.name>
parents: 4697
diff changeset
1697 if (!(ia->flags & IPV6_AF_AUTOCONF) && ia->flags & IPV6_AF_RAPFX) {
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1698 if (if_setflags(fd, ia->alias, IFF_NOLOCAL) ==-1)
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1699 return -1;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1700 sa_in6_init(&mask.sa, &ia->prefix);
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1701 r = if_addaddr(fd, ia->alias,
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1702 NULL, &mask.ss, NULL, ia->prefix_len);
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1703 } else {
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1704 sa_in6_init(&addr.sa, &ia->addr);
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1705 mask.sin6.sin6_family = AF_INET6;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1706 ipv6_mask(&mask.sin6.sin6_addr, ia->prefix_len);
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1707 r = if_addaddr(fd, ia->alias,
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1708 &addr.ss, &mask.ss, NULL, ia->prefix_len);
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1709 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1710 if (r == -1 && errno == EEXIST)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1711 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1712 return r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1713 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1714
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1715 int
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4682
diff changeset
1716 if_addrflags6(const struct interface *ifp, __unused const struct in6_addr *ia,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1717 const char *alias)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1718 {
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1719 int fd;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1720
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1721 fd = if_getaf_fd(ifp->ctx, AF_INET6);
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4690
diff changeset
1722 return if_addrflags0(fd, AF_INET6, alias);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1723 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1724
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1725 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1726 if_getlifetime6(struct ipv6_addr *addr)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1727 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1728
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1729 UNUSED(addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1730 errno = ENOTSUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1731 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1732 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1733
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1734 int
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1735 if_applyra(const struct ra *rap)
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1736 {
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1737 struct lifreq lifr = {
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1738 .lifr_ifinfo.lir_maxhops = rap->hoplimit,
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1739 .lifr_ifinfo.lir_reachtime = rap->reachable,
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1740 .lifr_ifinfo.lir_reachretrans = rap->retrans,
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1741 };
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1742
4815
e5212d0c460d Solaris: Fix compile with prior
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1743 strlcpy(lifr.lifr_name, rap->iface->name, sizeof(lifr.lifr_name));
e5212d0c460d Solaris: Fix compile with prior
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1744 return ioctl(rap->iface->ctx->pf_inet_fd, SIOCSLIFLNKINFO, &lifr);
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1745 }
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4748
diff changeset
1746
4221
b95a90df2c1b Fix compile on IllumOS.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1747 void
b95a90df2c1b Fix compile on IllumOS.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1748 if_setup_inet6(__unused const struct interface *ifp)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1749 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1750
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1751 }
4430
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1752
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1753 int
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1754 ip6_forwarding(__unused const char *ifname)
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1755 {
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1756
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1757 return 1;
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4421
diff changeset
1758 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1759 #endif