annotate src/ipv6.c @ 5535:a0d828e25482 draft

Add --noconfigure option With this set dhcpcd will not configure anything on the host. The expectation is that a 3rd party script will instead.
author Roy Marples <roy@marples.name>
date Wed, 04 Nov 2020 14:18:48 +0000
parents 6a2da5651841
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: 4532
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 * dhcpcd - DHCP client daemon
4922
555d7d1a4939 Welcome to 2020!
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
4 * Copyright (c) 2006-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 <sys/param.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 <sys/types.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 <sys/socket.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 <sys/stat.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
33
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
34 #include <arpa/inet.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 <net/if.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 <net/route.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 <netinet/in.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 <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
39
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
40 #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
41
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
42 #ifdef HAVE_SYS_BITOPS_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
43 #include <sys/bitops.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
44 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
45 #include "compat/bitops.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
46 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
47
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
48 #ifdef BSD
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
49 /* Purely for the ND6_IFF_AUTO_LINKLOCAL #define which is solely used
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
50 * to generate our CAN_ADD_LLADDR #define. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
51 # include <netinet6/in6_var.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 <netinet6/nd6.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
53 #endif
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 #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
56 #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
57 #include <inttypes.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
58 #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
59 #include <string.h>
5065
641e15827969 Be pedantic and move syslog.h into the right place
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
60 #include <syslog.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
61 #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
62
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4975
diff changeset
63 #define ELOOP_QUEUE ELOOP_IPV6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
64 #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
65 #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
66 #include "dhcpcd.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 "dhcp6.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 "eloop.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
69 #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
70 #include "ipv6nd.h"
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
71 #include "logerr.h"
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
72 #include "privsep.h"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
73 #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
74 #include "script.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
75
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
76 #ifdef HAVE_MD5_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
77 # ifndef DEPGEN
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
78 # include <md5.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
79 # endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
80 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
82 #ifdef SHA2_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
83 # include SHA2_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
84 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
85
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
86 #ifndef SHA256_DIGEST_LENGTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
87 # define SHA256_DIGEST_LENGTH 32
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
89
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
90 #ifdef IPV6_POLLADDRFLAG
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
91 # warning kernel does not report IPv6 address flag changes
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
92 # warning polling tentative address flags periodically
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
93 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
94
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
95 /* Hackery at it's finest. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
96 #ifndef s6_addr32
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
97 # ifdef __sun
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 # define s6_addr32 _S6_un._S6_u32
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99 # else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
100 # define s6_addr32 __u6_addr.__u6_addr32
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
101 # endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
103
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
104 #if defined(HAVE_IN6_ADDR_GEN_MODE_NONE) || defined(ND6_IFF_AUTO_LINKLOCAL) || \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
105 defined(IFF_NOLINKLOCAL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
106 /* Only add the LL address if we have a carrier, so DaD works. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
107 #define CAN_ADD_LLADDR(ifp) \
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
108 (!((ifp)->options->options & DHCPCD_LINK) || if_is_link_up((ifp)))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
109 #ifdef __sun
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
110 /* Although we can add our own LL address, we cannot drop it
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
111 * without unplumbing the if which is a lot of code.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
112 * So just keep it for the time being. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
113 #define CAN_DROP_LLADDR(ifp) (0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
114 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
115 #define CAN_DROP_LLADDR(ifp) (1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
116 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
117 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
118 /* We have no control over the OS adding the LLADDR, so just let it do it
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
119 * as we cannot force our own view on it. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
120 #define CAN_ADD_LLADDR(ifp) (0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
121 #define CAN_DROP_LLADDR(ifp) (0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
122 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
123
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
124 #ifdef IPV6_MANAGETEMPADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
125 static void ipv6_regentempaddr(void *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
126 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
127
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
128 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
129 ipv6_init(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
130 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
131
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
132 if (ctx->ra_routers != NULL)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
133 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
134
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
135 ctx->ra_routers = malloc(sizeof(*ctx->ra_routers));
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
136 if (ctx->ra_routers == NULL)
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4349
diff changeset
137 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
138 TAILQ_INIT(ctx->ra_routers);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
139
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4439
diff changeset
140 #ifndef __sun
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
141 ctx->nd_fd = -1;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4439
diff changeset
142 #endif
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
143 #ifdef DHCP6
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
144 ctx->dhcp6_rfd = -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
145 ctx->dhcp6_wfd = -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
146 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
147 return 0;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
150 static ssize_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
151 ipv6_readsecret(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
152 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
153 char line[1024];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
154 unsigned char *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
155 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
156 uint32_t r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
157
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
158 ctx->secret_len = dhcp_read_hwaddr_aton(ctx, &ctx->secret, SECRET);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
159 if (ctx->secret_len != 0)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
160 return (ssize_t)ctx->secret_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
161
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
162 if (errno != ENOENT)
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
163 logerr("%s: cannot read secret", __func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
164
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
165 /* Chaining arc4random should be good enough.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
166 * RFC7217 section 5.1 states the key SHOULD be at least 128 bits.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 * To attempt and future proof ourselves, we'll generate a key of
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
168 * 512 bits (64 bytes). */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
169 if (ctx->secret_len < 64) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
170 if ((ctx->secret = malloc(64)) == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
171 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
172 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
173 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
174 ctx->secret_len = 64;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
175 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
176 p = ctx->secret;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
177 for (len = 0; len < 512 / NBBY; len += sizeof(r)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
178 r = arc4random();
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
179 memcpy(p, &r, sizeof(r));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
180 p += sizeof(r);
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
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
183 hwaddr_ntoa(ctx->secret, ctx->secret_len, line, sizeof(line));
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
184 len = strlen(line);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
185 if (len < sizeof(line) - 2) {
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
186 line[len++] = '\n';
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
187 line[len] = '\0';
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
188 }
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
189 if (dhcp_writefile(ctx, SECRET, S_IRUSR, line, len) == -1) {
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
190 logerr("%s: cannot write secret", __func__);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
191 ctx->secret_len = 0;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
192 return -1;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
193 }
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
194 return (ssize_t)ctx->secret_len;
3932
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 /* http://www.iana.org/assignments/ipv6-interface-ids/ipv6-interface-ids.xhtml
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
198 * RFC5453 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
199 static const struct reslowhigh {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
200 const uint8_t high[8];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
201 const uint8_t low[8];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
202 } reslowhigh[] = {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
203 /* RFC4291 + RFC6543 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
204 { { 0x02, 0x00, 0x5e, 0xff, 0xfe, 0x00, 0x00, 0x00 },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
205 { 0x02, 0x00, 0x5e, 0xff, 0xfe, 0xff, 0xff, 0xff } },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
206 /* RFC2526 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
207 { { 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
208 { 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
209 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
210
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
211 static bool
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
212 ipv6_reserved(const struct in6_addr *addr)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
213 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
214 uint64_t id, low, high;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
215 size_t i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
216 const struct reslowhigh *r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
217
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
218 id = be64dec(addr->s6_addr + sizeof(id));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
219 if (id == 0) /* RFC4291 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
220 return 1;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
221 for (i = 0; i < __arraycount(reslowhigh); i++) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
222 r = &reslowhigh[i];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
223 low = be64dec(r->low);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
224 high = be64dec(r->high);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
225 if (id >= low && id <= high)
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
226 return true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
227 }
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
228 return false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
229 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
230
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
231 /* RFC7217 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
232 static int
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
233 ipv6_makestableprivate1(struct dhcpcd_ctx *ctx,
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
234 struct in6_addr *addr, const struct in6_addr *prefix, int prefix_len,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
235 const unsigned char *netiface, size_t netiface_len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
236 const unsigned char *netid, size_t netid_len,
4291
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
237 unsigned short vlanid,
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
238 uint32_t *dad_counter)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
239 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
240 unsigned char buf[2048], *p, digest[SHA256_DIGEST_LENGTH];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
241 size_t len, l;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
242 SHA256_CTX sha_ctx;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
243
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
244 if (prefix_len < 0 || prefix_len > 120) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
245 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
246 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
247 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
248
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
249 if (ctx->secret_len == 0) {
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
250 if (ipv6_readsecret(ctx) == -1)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
251 return -1;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
252 }
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
253
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
254 l = (size_t)(ROUNDUP8(prefix_len) / NBBY);
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
255 len = l + netiface_len + netid_len + sizeof(*dad_counter) +
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
256 ctx->secret_len;
4291
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
257 if (vlanid != 0)
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
258 len += sizeof(vlanid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
259 if (len > sizeof(buf)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
260 errno = ENOBUFS;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
261 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
262 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
263
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
264 for (;; (*dad_counter)++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
265 /* Combine all parameters into one buffer */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
266 p = buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
267 memcpy(p, prefix, l);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
268 p += l;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
269 memcpy(p, netiface, netiface_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
270 p += netiface_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
271 memcpy(p, netid, netid_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
272 p += netid_len;
4291
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
273 /* Don't use a vlanid if not set.
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
274 * This ensures prior versions have the same unique address. */
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
275 if (vlanid != 0) {
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
276 memcpy(p, &vlanid, sizeof(vlanid));
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
277 p += sizeof(vlanid);
cedfddd21034 ip6: use vlanid if present in working out stable private addresses
Roy Marples <roy@marples.name>
parents: 4285
diff changeset
278 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
279 memcpy(p, dad_counter, sizeof(*dad_counter));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
280 p += sizeof(*dad_counter);
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
281 memcpy(p, ctx->secret, ctx->secret_len);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
282
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
283 /* Make an address using the digest of the above.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
284 * RFC7217 Section 5.1 states that we shouldn't use MD5.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
285 * Pity as we use that for HMAC-MD5 which is still deemed OK.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
286 * SHA-256 is recommended */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
287 SHA256_Init(&sha_ctx);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
288 SHA256_Update(&sha_ctx, buf, len);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
289 SHA256_Final(digest, &sha_ctx);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
290
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
291 p = addr->s6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
292 memcpy(p, prefix, l);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
293 /* RFC7217 section 5.2 says we need to start taking the id from
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
294 * the least significant bit */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
295 len = sizeof(addr->s6_addr) - l;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
296 memcpy(p + l, digest + (sizeof(digest) - len), len);
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 /* Ensure that the Interface ID does not match a reserved one,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
299 * if it does then treat it as a DAD failure.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
300 * RFC7217 section 5.2 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
301 if (prefix_len != 64)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
302 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
303 if (!ipv6_reserved(addr))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
304 break;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
307 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
308 }
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 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
311 ipv6_makestableprivate(struct in6_addr *addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
312 const struct in6_addr *prefix, int prefix_len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
313 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
314 int *dad_counter)
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 uint32_t dad;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
317 int r;
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 dad = (uint32_t)*dad_counter;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
320
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
321 /* For our implementation, we shall set the hardware address
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
322 * as the interface identifier */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
323 r = ipv6_makestableprivate1(ifp->ctx, addr, prefix, prefix_len,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
324 ifp->hwaddr, ifp->hwlen,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
325 ifp->ssid, ifp->ssid_len,
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
326 ifp->vlanid, &dad);
3932
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 if (r == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
329 *dad_counter = (int)dad;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
330 return r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
331 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
332
5129
8be78957f374 Linux: doesn't need to create temp addrs
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
333 #ifdef IPV6_AF_TEMPORARY
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
334 static int
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
335 ipv6_maketemporaryaddress(struct in6_addr *addr,
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
336 const struct in6_addr *prefix, int prefix_len,
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
337 const struct interface *ifp)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
338 {
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
339 struct in6_addr mask;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
340 struct interface *ifpn;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
341
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
342 if (ipv6_mask(&mask, prefix_len) == -1)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
343 return -1;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
344 *addr = *prefix;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
345
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
346 again:
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
347 addr->s6_addr32[2] |= (arc4random() & ~mask.s6_addr32[2]);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
348 addr->s6_addr32[3] |= (arc4random() & ~mask.s6_addr32[3]);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
349
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
350 TAILQ_FOREACH(ifpn, ifp->ctx->ifaces, next) {
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
351 if (ipv6_iffindaddr(ifpn, addr, 0) != NULL)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
352 break;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
353 }
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
354 if (ifpn != NULL)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
355 goto again;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
356 if (ipv6_reserved(addr))
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
357 goto again;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
358 return 0;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
359 }
5129
8be78957f374 Linux: doesn't need to create temp addrs
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
360 #endif
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
361
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
362 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
363 ipv6_makeaddr(struct in6_addr *addr, struct interface *ifp,
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
364 const struct in6_addr *prefix, int prefix_len, 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
365 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
366 const struct ipv6_addr *ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
367 int dad;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
368
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
369 if (prefix_len < 0 || prefix_len > 120) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
370 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
371 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
372 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
373
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
374 #ifdef IPV6_AF_TEMPORARY
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
375 if (flags & IPV6_AF_TEMPORARY)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
376 return ipv6_maketemporaryaddress(addr, prefix, prefix_len, ifp);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
377 #else
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
378 UNUSED(flags);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
379 #endif
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
380
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
381 if (ifp->options->options & DHCPCD_SLAACPRIVATE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
382 dad = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
383 if (ipv6_makestableprivate(addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
384 prefix, prefix_len, ifp, &dad) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
385 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
386 return dad;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
387 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
388
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
389 if (prefix_len > 64) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
390 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
391 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
392 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
393 if ((ap = ipv6_linklocal(ifp)) == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
394 /* We delay a few functions until we get a local-link address
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
395 * so this should never be hit. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
396 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
397 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
398 }
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 /* Make the address from the first local-link address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
401 memcpy(addr, prefix, sizeof(*prefix));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
402 addr->s6_addr32[2] = ap->addr.s6_addr32[2];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
403 addr->s6_addr32[3] = ap->addr.s6_addr32[3];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
404 return 0;
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
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
407 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
408 ipv6_makeprefix(struct in6_addr *prefix, const struct in6_addr *addr, int len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
409 {
5048
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
410 struct in6_addr mask;
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
411 size_t i;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
412
5048
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
413 if (ipv6_mask(&mask, len) == -1)
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
414 return -1;
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
415 *prefix = *addr;
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
416 for (i = 0; i < sizeof(prefix->s6_addr); i++)
1d342610ff74 inet6: Calculate the prefix in the canonical form
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
417 prefix->s6_addr[i] &= mask.s6_addr[i];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
418 return 0;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
421 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
422 ipv6_mask(struct in6_addr *mask, int len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
423 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
424 static const unsigned char masks[NBBY] =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
425 { 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
426 int bytes, bits, i;
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 if (len < 0 || len > 128) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
429 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
430 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
431 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
432
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
433 memset(mask, 0, sizeof(*mask));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
434 bytes = len / NBBY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
435 bits = len % NBBY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
436 for (i = 0; i < bytes; i++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
437 mask->s6_addr[i] = 0xff;
4302
d648c2f6b198 Consistency
Roy Marples <roy@marples.name>
parents: 4301
diff changeset
438 if (bits != 0) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
439 /* Coverify false positive.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
440 * bytelen cannot be 16 if bitlen is non zero */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
441 /* coverity[overrun-local] */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
442 mask->s6_addr[bytes] = masks[bits - 1];
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 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
445 }
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 uint8_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
448 ipv6_prefixlen(const struct in6_addr *mask)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
449 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
450 int x = 0, y;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
451 const unsigned char *lim, *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
452
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
453 lim = (const unsigned char *)mask + sizeof(*mask);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
454 for (p = (const unsigned char *)mask; p < lim; x++, p++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
455 if (*p != 0xff)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
456 break;
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 y = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
459 if (p < lim) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
460 for (y = 0; y < NBBY; y++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
461 if ((*p & (0x80 >> y)) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
462 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
463 }
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
466 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
467 * when the limit pointer is given, do a stricter check on the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
468 * remaining bits.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
469 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
470 if (p < lim) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
471 if (y != 0 && (*p & (0x00ff >> y)) != 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
472 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
473 for (p = p + 1; p < lim; p++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
474 if (*p != 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
475 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
476 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
477
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
478 return (uint8_t)(x * NBBY + y);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
479 }
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 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
482 in6_to_h64(uint64_t *vhigh, uint64_t *vlow, const struct in6_addr *addr)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
483 {
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 *vhigh = be64dec(addr->s6_addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
486 *vlow = be64dec(addr->s6_addr + 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
487 }
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 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
490 h64_to_in6(struct in6_addr *addr, uint64_t vhigh, uint64_t vlow)
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
493 be64enc(addr->s6_addr, vhigh);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
494 be64enc(addr->s6_addr + 8, vlow);
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
497 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
498 ipv6_userprefix(
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
499 const struct in6_addr *prefix, // prefix from router
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
500 short prefix_len, // length of prefix received
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
501 uint64_t user_number, // "random" number from user
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
502 struct in6_addr *result, // resultant prefix
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
503 short result_len) // desired prefix length
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 uint64_t vh, vl, user_low, user_high;
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 if (prefix_len < 1 || prefix_len > 128 ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
508 result_len < 1 || result_len > 128)
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 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
511 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
512 }
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 /* Check that the user_number fits inside result_len less prefix_len */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
515 if (result_len < prefix_len ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
516 fls64(user_number) > result_len - prefix_len)
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 errno = ERANGE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
519 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
520 }
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 /* If user_number is zero, just copy the prefix into the result. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
523 if (user_number == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
524 *result = *prefix;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
525 return 0;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
528 /* Shift user_number so it fit's just inside result_len.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
529 * Shifting by 0 or sizeof(user_number) is undefined,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
530 * so we cater for that. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
531 if (result_len == 128) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
532 user_high = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
533 user_low = user_number;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
534 } else if (result_len > 64) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
535 if (prefix_len >= 64)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
536 user_high = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
537 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
538 user_high = user_number >> (result_len - prefix_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
539 user_low = user_number << (128 - result_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
540 } else if (result_len == 64) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
541 user_high = user_number;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
542 user_low = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
543 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
544 user_high = user_number << (64 - result_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
545 user_low = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
546 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
547
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
548 /* convert to two 64bit host order values */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
549 in6_to_h64(&vh, &vl, prefix);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
550
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
551 vh |= user_high;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
552 vl |= user_low;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
553
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
554 /* copy back result */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
555 h64_to_in6(result, vh, vl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
556
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
557 return 0;
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 #ifdef IPV6_POLLADDRFLAG
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
561 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
562 ipv6_checkaddrflags(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
563 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
564 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
565 int flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
566 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
567
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
568 ia = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
569 #ifdef ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
570 alias = ia->alias;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
571 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
572 alias = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
573 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
574 if ((flags = if_addrflags6(ia->iface, &ia->addr, alias)) == -1) {
4301
79099257b0ce BSD: Silence debug when address no longer exists when getting flags
Roy Marples <roy@marples.name>
parents: 4291
diff changeset
575 if (errno != EEXIST && errno != EADDRNOTAVAIL)
79099257b0ce BSD: Silence debug when address no longer exists when getting flags
Roy Marples <roy@marples.name>
parents: 4291
diff changeset
576 logerr("%s: if_addrflags6", __func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
577 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
578 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
579
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
580 if (!(flags & IN6_IFF_TENTATIVE)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
581 /* Simulate the kernel announcing the new address. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
582 ipv6_handleifa(ia->iface->ctx, RTM_NEWADDR,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
583 ia->iface->ctx->ifaces, ia->iface->name,
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
584 &ia->addr, ia->prefix_len, 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
585 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
586 /* Still tentative? Check again in a bit. */
4935
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
587 eloop_timeout_add_msec(ia->iface->ctx->eloop,
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
588 RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
589 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
590 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
591 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
592
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
593 static void
4057
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
594 ipv6_deletedaddr(struct ipv6_addr *ia)
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
595 {
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
596
5286
b820f26385b7 Fix compile with inet or inet6 disabled
Roy Marples <roy@marples.name>
parents: 5263
diff changeset
597 #ifdef DHCP6
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4759
diff changeset
598 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4759
diff changeset
599 if (!(ia->iface->ctx->options & DHCPCD_MASTER))
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4759
diff changeset
600 ps_inet_closedhcp6(ia);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4759
diff changeset
601 #elif defined(SMALL)
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
602 UNUSED(ia);
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
603 #else
4057
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
604 /* NOREJECT is set if we delegated exactly the prefix to another
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
605 * address.
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
606 * This can only be one address, so just clear the flag.
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
607 * This should ensure the reject route will be restored. */
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
608 if (ia->delegating_prefix != NULL)
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
609 ia->delegating_prefix->flags &= ~IPV6_AF_NOREJECT;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
610 #endif
5286
b820f26385b7 Fix compile with inet or inet6 disabled
Roy Marples <roy@marples.name>
parents: 5263
diff changeset
611 #else
b820f26385b7 Fix compile with inet or inet6 disabled
Roy Marples <roy@marples.name>
parents: 5263
diff changeset
612 UNUSED(ia);
b820f26385b7 Fix compile with inet or inet6 disabled
Roy Marples <roy@marples.name>
parents: 5263
diff changeset
613 #endif
4057
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
614 }
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
615
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4109
diff changeset
616 void
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
617 ipv6_deleteaddr(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
618 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
619 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
620 struct ipv6_addr *ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
621
4024
0984f93d896e To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents: 4023
diff changeset
622 loginfox("%s: deleting address %s", ia->iface->name, ia->saddr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
623 if (if_address6(RTM_DELADDR, ia) == -1 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
624 errno != EADDRNOTAVAIL && errno != ESRCH &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
625 errno != ENXIO && errno != ENODEV)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
626 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
627
4057
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
628 ipv6_deletedaddr(ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
629
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
630 state = IPV6_STATE(ia->iface);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
631 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
632 if (IN6_ARE_ADDR_EQUAL(&ap->addr, &ia->addr)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
633 TAILQ_REMOVE(&state->addrs, ap, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
634 ipv6_freeaddr(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
635 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
636 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
637 }
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
638
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
639 #ifdef ND6_ADVERTISE
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
640 /* Advertise the address if it exists on another interface. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
641 ipv6nd_advertise(ia);
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
642 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
643 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
644
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
645 static int
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
646 ipv6_addaddr1(struct ipv6_addr *ia, const struct timespec *now)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
647 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
648 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
649 uint32_t pltime, vltime;
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5059
diff changeset
650 int loglevel;
4589
d75c5238579e Fix define for prior
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
651 #ifdef ND6_ADVERTISE
4686
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4684
diff changeset
652 bool vltime_was_zero = ia->prefix_vltime == 0;
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
653 #endif
4430
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4371
diff changeset
654 #ifdef __sun
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4371
diff changeset
655 struct ipv6_state *state;
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4371
diff changeset
656 struct ipv6_addr *ia2;
4598
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
657
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
658 /* If we re-add then address on Solaris then the prefix
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
659 * route will be scrubbed and re-added. Something might
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
660 * be using it, so let's avoid it. */
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
661 if (ia->flags & IPV6_AF_DADCOMPLETED) {
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
662 logdebugx("%s: IP address %s already exists",
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
663 ia->iface->name, ia->saddr);
4686
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4684
diff changeset
664 #ifdef ND6_ADVERTISE
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4684
diff changeset
665 goto advertise;
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4684
diff changeset
666 #else
4598
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
667 return 0;
4686
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4684
diff changeset
668 #endif
4598
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
669 }
4430
4d90f9a458cc sun: Compile once more
Joerg Sonnenberger <joerg@NetBSD.org>
parents: 4371
diff changeset
670 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
671
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
672 /* Remember the interface of the address. */
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
673 ifp = ia->iface;
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
674
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
675 if (!(ia->flags & IPV6_AF_DADCOMPLETED) &&
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
676 ipv6_iffindaddr(ifp, &ia->addr, IN6_IFF_NOTUSEABLE))
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
677 ia->flags |= IPV6_AF_DADCOMPLETED;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
678
4063
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
679 /* Adjust plftime and vltime based on acquired time */
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
680 pltime = ia->prefix_pltime;
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
681 vltime = ia->prefix_vltime;
5432
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
682
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
683 if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
684 /* We don't want the kernel to expire the address.
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
685 * The saved times will be re-applied to the ia
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
686 * before exiting this function. */
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
687 ia->prefix_vltime = ia->prefix_pltime = ND6_INFINITE_LIFETIME;
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
688 }
d7cc41338b01 DHCP: Don't set address lifetimes when extending leases
Roy Marples <roy@marples.name>
parents: 5415
diff changeset
689
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
690 if (timespecisset(&ia->acquired) &&
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
691 (ia->prefix_pltime != ND6_INFINITE_LIFETIME ||
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
692 ia->prefix_vltime != ND6_INFINITE_LIFETIME))
4063
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
693 {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
694 uint32_t elapsed;
4063
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
695 struct timespec n;
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
696
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
697 if (now == NULL) {
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
698 clock_gettime(CLOCK_MONOTONIC, &n);
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
699 now = &n;
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
700 }
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
701 elapsed = (uint32_t)eloop_timespec_diff(now, &ia->acquired,
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
702 NULL);
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
703 if (ia->prefix_pltime != ND6_INFINITE_LIFETIME) {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
704 if (elapsed > ia->prefix_pltime)
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
705 ia->prefix_pltime = 0;
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
706 else
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
707 ia->prefix_pltime -= elapsed;
4063
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
708 }
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
709 if (ia->prefix_vltime != ND6_INFINITE_LIFETIME) {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
710 if (elapsed > ia->prefix_vltime)
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
711 ia->prefix_vltime = 0;
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
712 else
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
713 ia->prefix_vltime -= elapsed;
4063
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
714 }
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
715 }
613ad6f1c681 IPv6: show actual address lifetimes being applied
Roy Marples <roy@marples.name>
parents: 4057
diff changeset
716
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5059
diff changeset
717 loglevel = ia->flags & IPV6_AF_NEW ? LOG_INFO : LOG_DEBUG;
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5059
diff changeset
718 logmessage(loglevel, "%s: adding %saddress %s", ifp->name,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
719 #ifdef IPV6_AF_TEMPORARY
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
720 ia->flags & IPV6_AF_TEMPORARY ? "temporary " : "",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
721 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
722 "",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
723 #endif
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
724 ia->saddr);
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
725 if (ia->prefix_pltime == ND6_INFINITE_LIFETIME &&
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
726 ia->prefix_vltime == ND6_INFINITE_LIFETIME)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
727 logdebugx("%s: pltime infinity, vltime infinity",
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
728 ifp->name);
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
729 else if (ia->prefix_pltime == ND6_INFINITE_LIFETIME)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
730 logdebugx("%s: pltime infinity, vltime %"PRIu32" seconds",
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
731 ifp->name, ia->prefix_vltime);
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
732 else if (ia->prefix_vltime == ND6_INFINITE_LIFETIME)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
733 logdebugx("%s: pltime %"PRIu32"seconds, vltime infinity",
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
734 ifp->name, ia->prefix_pltime);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
735 else
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
736 logdebugx("%s: pltime %"PRIu32" seconds, vltime %"PRIu32
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
737 " seconds",
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
738 ifp->name, ia->prefix_pltime, ia->prefix_vltime);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
739
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
740 if (if_address6(RTM_NEWADDR, ia) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
741 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
742 /* Restore real pltime and vltime */
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
743 ia->prefix_pltime = pltime;
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
744 ia->prefix_vltime = vltime;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
745 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
746 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
747
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
748 #ifdef IPV6_MANAGETEMPADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
749 /* RFC4941 Section 3.4 */
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
750 if (ia->flags & IPV6_AF_TEMPORARY &&
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
751 ia->prefix_pltime &&
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
752 ia->prefix_vltime &&
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
753 ifp->options->options & DHCPCD_SLAACTEMP)
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
754 eloop_timeout_add_sec(ifp->ctx->eloop,
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
755 ia->prefix_pltime - REGEN_ADVANCE,
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
756 ipv6_regentempaddr, ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
757 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
758
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
759 /* Restore real pltime and vltime */
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
760 ia->prefix_pltime = pltime;
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
761 ia->prefix_vltime = vltime;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
762
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
763 ia->flags &= ~IPV6_AF_NEW;
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
764 ia->flags |= IPV6_AF_ADDED;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
765 #ifndef SMALL
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
766 if (ia->delegating_prefix != NULL)
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
767 ia->flags |= IPV6_AF_DELEGATED;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
768 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
769
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
770 #ifdef IPV6_POLLADDRFLAG
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
771 eloop_timeout_delete(ifp->ctx->eloop,
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
772 ipv6_checkaddrflags, ia);
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
773 if (!(ia->flags & IPV6_AF_DADCOMPLETED)) {
4935
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
774 eloop_timeout_add_msec(ifp->ctx->eloop,
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
775 RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
776 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
777 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
778
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
779 #ifdef __sun
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
780 /* Solaris does not announce new addresses which need DaD
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
781 * so we need to take a copy and add it to our list.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
782 * Otherwise aliasing gets confused if we add another
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
783 * address during DaD. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
784
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
785 state = IPV6_STATE(ifp);
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
786 TAILQ_FOREACH(ia2, &state->addrs, next) {
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
787 if (IN6_ARE_ADDR_EQUAL(&ia2->addr, &ia->addr))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
788 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
789 }
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
790 if (ia2 == NULL) {
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
791 if ((ia2 = malloc(sizeof(*ia2))) == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
792 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
793 return 0; /* Well, we did add the address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
794 }
4109
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
795 memcpy(ia2, ia, sizeof(*ia2));
e536050faf64 Fix sefault when address lifetime overflows
Roy Marples <roy@marples.name>
parents: 4100
diff changeset
796 TAILQ_INSERT_TAIL(&state->addrs, ia2, next);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
797 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
798 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
799
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
800 #ifdef ND6_ADVERTISE
4687
df54c3ba91f9 Solaris: Fix issue with prior on other OS
Roy Marples <roy@marples.name>
parents: 4686
diff changeset
801 #ifdef __sun
4686
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4684
diff changeset
802 advertise:
4687
df54c3ba91f9 Solaris: Fix issue with prior on other OS
Roy Marples <roy@marples.name>
parents: 4686
diff changeset
803 #endif
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
804 /* Re-advertise the preferred address to be safe. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
805 if (!vltime_was_zero)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
806 ipv6nd_advertise(ia);
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
807 #endif
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
808
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
809 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
810 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
811
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
812 #ifdef ALIAS_ADDR
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
813 /* Find the next logical alias address we can use. */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
814 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
815 ipv6_aliasaddr(struct ipv6_addr *ia, struct ipv6_addr **repl)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
816 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
817 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
818 struct ipv6_addr *iap;
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
819 unsigned int lun;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
820 char alias[IF_NAMESIZE];
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 if (ia->alias[0] != '\0')
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
823 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
824 state = IPV6_STATE(ia->iface);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
825
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
826 /* First find an existng address.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
827 * This can happen when dhcpcd restarts as ND and DHCPv6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
828 * maintain their own lists of addresses. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
829 TAILQ_FOREACH(iap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
830 if (iap->alias[0] != '\0' &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
831 IN6_ARE_ADDR_EQUAL(&iap->addr, &ia->addr))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
832 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
833 strlcpy(ia->alias, iap->alias, sizeof(ia->alias));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
834 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
835 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
836 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
837
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
838 lun = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
839 find_unit:
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
840 if (if_makealias(alias, IF_NAMESIZE, ia->iface->name, lun) >=
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
841 IF_NAMESIZE)
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
842 {
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
843 errno = ENOMEM;
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
844 return -1;
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
845 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
846 TAILQ_FOREACH(iap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
847 if (iap->alias[0] == '\0')
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
848 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
849 if (IN6_IS_ADDR_UNSPECIFIED(&iap->addr)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
850 /* No address assigned? Lets use it. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
851 strlcpy(ia->alias, iap->alias, sizeof(ia->alias));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
852 if (repl)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
853 *repl = iap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
854 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
855 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
856 if (strcmp(iap->alias, alias) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
857 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
858 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
859
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
860 if (iap != NULL) {
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
861 if (lun == UINT_MAX) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
862 errno = ERANGE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
863 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
864 }
4439
5ed513825ce5 if: Add a generic function to create an aliased address name
Roy Marples <roy@marples.name>
parents: 4430
diff changeset
865 lun++;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
866 goto find_unit;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
867 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
868
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
869 strlcpy(ia->alias, alias, sizeof(ia->alias));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
870 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
871 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
872 #endif
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 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
875 ipv6_addaddr(struct ipv6_addr *ia, const struct timespec *now)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
876 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
877 int r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
878 #ifdef ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
879 int replaced, blank;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
880 struct ipv6_addr *replaced_ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
881
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
882 blank = (ia->alias[0] == '\0');
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
883 if ((replaced = ipv6_aliasaddr(ia, &replaced_ia)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
884 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
885 if (blank)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
886 logdebugx("%s: aliased %s", ia->alias, ia->saddr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
887 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
888
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
889 if ((r = ipv6_addaddr1(ia, now)) == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
890 #ifdef ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
891 if (replaced) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
892 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
893
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
894 state = IPV6_STATE(ia->iface);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
895 TAILQ_REMOVE(&state->addrs, replaced_ia, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
896 ipv6_freeaddr(replaced_ia);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
897 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
898 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
899 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
900 return r;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
901 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
902
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
903 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
904 ipv6_findaddrmatch(const struct ipv6_addr *addr, const struct in6_addr *match,
4123
441ac8d90316 Promote IPv6 dhcpcd address flags to unsignned int to allow expansion.
Roy Marples <roy@marples.name>
parents: 4122
diff changeset
905 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
906 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
907
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
908 if (match == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
909 if ((addr->flags &
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
910 (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)) ==
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
911 (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
912 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
913 } else if (addr->prefix_vltime &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
914 IN6_ARE_ADDR_EQUAL(&addr->addr, match) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
915 (!flags || addr->flags & flags))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
916 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
917
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
918 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
919 }
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 ipv6_addr *
4123
441ac8d90316 Promote IPv6 dhcpcd address flags to unsignned int to allow expansion.
Roy Marples <roy@marples.name>
parents: 4122
diff changeset
922 ipv6_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr, 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
923 {
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
924 struct ipv6_addr *nap;
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
925 #ifdef DHCP6
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
926 struct ipv6_addr *dap;
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
927 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
928
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
929 nap = ipv6nd_findaddr(ctx, addr, flags);
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
930 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
931 dap = dhcp6_findaddr(ctx, addr, flags);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
932 if (!dap && !nap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
933 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
934 if (dap && !nap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
935 return dap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
936 if (nap && !dap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
937 return nap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
938 if (nap->iface->metric < dap->iface->metric)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
939 return nap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
940 return dap;
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
941 #else
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
942 return nap;
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
943 #endif
3932
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
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
946 int
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
947 ipv6_doaddr(struct ipv6_addr *ia, struct timespec *now)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
948 {
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
949
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
950 /* A delegated prefix is not an address. */
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
951 if (ia->flags & IPV6_AF_DELEGATEDPFX)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
952 return 0;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
953
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
954 if (ia->prefix_vltime == 0) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
955 if (ia->flags & IPV6_AF_ADDED)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
956 ipv6_deleteaddr(ia);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
957 eloop_q_timeout_delete(ia->iface->ctx->eloop,
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4975
diff changeset
958 ELOOP_QUEUE_ALL, NULL, ia);
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
959 if (ia->flags & IPV6_AF_REQUEST) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
960 ia->flags &= ~IPV6_AF_ADDED;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
961 return 0;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
962 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
963 return -1;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
964 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
965
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
966 if (ia->flags & IPV6_AF_STALE ||
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
967 IN6_IS_ADDR_UNSPECIFIED(&ia->addr))
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
968 return 0;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
969
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
970 if (!timespecisset(now))
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
971 clock_gettime(CLOCK_MONOTONIC, now);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
972 ipv6_addaddr(ia, now);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
973 return ia->flags & IPV6_AF_NEW ? 1 : 0;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
974 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
975
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
976 ssize_t
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
977 ipv6_addaddrs(struct ipv6_addrhead *iaddrs)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
978 {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
979 struct timespec now;
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
980 struct ipv6_addr *ia, *ian;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
981 ssize_t i, r;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
982
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
983 i = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
984 timespecclear(&now);
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
985 TAILQ_FOREACH_SAFE(ia, iaddrs, next, ian) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
986 r = ipv6_doaddr(ia, &now);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
987 if (r != 0)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
988 i++;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
989 if (r == -1) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
990 TAILQ_REMOVE(iaddrs, ia, next);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
991 ipv6_freeaddr(ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
992 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
993 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
994 return i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
995 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
996
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
997 void
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
998 ipv6_freeaddr(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
999 {
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4975
diff changeset
1000 struct eloop *eloop = ia->iface->ctx->eloop;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1001 #ifndef SMALL
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1002 struct ipv6_addr *iad;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1003
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1004 /* Forget the reference */
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1005 if (ia->flags & IPV6_AF_DELEGATEDPFX) {
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1006 TAILQ_FOREACH(iad, &ia->pd_pfxs, pd_next) {
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1007 iad->delegating_prefix = NULL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1008 }
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1009 } else if (ia->delegating_prefix != NULL) {
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1010 TAILQ_REMOVE(&ia->delegating_prefix->pd_pfxs, ia, pd_next);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1011 }
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1012 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1013
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1014 if (ia->dhcp6_fd != -1) {
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1015 close(ia->dhcp6_fd);
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4975
diff changeset
1016 eloop_event_delete(eloop, ia->dhcp6_fd);
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1017 }
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1018
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4975
diff changeset
1019 eloop_q_timeout_delete(eloop, ELOOP_QUEUE_ALL, NULL, ia);
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1020 free(ia->na);
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1021 free(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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1023
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1024 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1025 ipv6_freedrop_addrs(struct ipv6_addrhead *addrs, int drop,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1026 const struct interface *ifd)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1027 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1028 struct ipv6_addr *ap, *apn, *apf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1029 struct timespec now;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1030
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1031 #ifdef SMALL
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1032 UNUSED(ifd);
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1033 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1034 timespecclear(&now);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1035 TAILQ_FOREACH_SAFE(ap, addrs, next, apn) {
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1036 #ifndef SMALL
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1037 if (ifd != NULL &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1038 (ap->delegating_prefix == NULL ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1039 ap->delegating_prefix->iface != ifd))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1040 continue;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4063
diff changeset
1041 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1042 if (drop != 2)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1043 TAILQ_REMOVE(addrs, ap, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1044 if (drop && ap->flags & IPV6_AF_ADDED &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1045 (ap->iface->options->options &
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1046 (DHCPCD_EXITING | DHCPCD_PERSISTENT)) !=
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1047 (DHCPCD_EXITING | DHCPCD_PERSISTENT))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1048 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1049 /* Don't drop link-local addresses. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1050 if (!IN6_IS_ADDR_LINKLOCAL(&ap->addr) ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1051 CAN_DROP_LLADDR(ap->iface))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1052 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1053 if (drop == 2)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1054 TAILQ_REMOVE(addrs, ap, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1055 /* Find the same address somewhere else */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1056 apf = ipv6_findaddr(ap->iface->ctx, &ap->addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1057 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1058 if ((apf == NULL ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1059 (apf->iface != ap->iface)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1060 ipv6_deleteaddr(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1061 if (!(ap->iface->options->options &
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1062 DHCPCD_EXITING) && apf)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1063 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1064 if (!timespecisset(&now))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1065 clock_gettime(CLOCK_MONOTONIC,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1066 &now);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1067 ipv6_addaddr(apf, &now);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1068 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1069 if (drop == 2)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1070 ipv6_freeaddr(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1071 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1072 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1073 if (drop != 2)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1074 ipv6_freeaddr(ap);
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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1077
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1078 static struct ipv6_state *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1079 ipv6_getstate(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
1080 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1081 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1082
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1083 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1084 if (state == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1085 ifp->if_data[IF_DATA_IPV6] = calloc(1, sizeof(*state));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1086 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1087 if (state == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1088 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1089 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1090 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1091 TAILQ_INIT(&state->addrs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1092 TAILQ_INIT(&state->ll_callbacks);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1093 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1094 return state;
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
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1097 struct ipv6_addr *
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1098 ipv6_anyglobal(struct interface *sifp)
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1099 {
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1100 struct interface *ifp;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1101 struct ipv6_state *state;
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1102 struct ipv6_addr *ia;
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
1103 bool forwarding;
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
1104
5413
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5391
diff changeset
1105 /* BSD forwarding is either on or off.
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5391
diff changeset
1106 * Linux forwarding is technically the same as it's
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5391
diff changeset
1107 * configured by the "all" interface.
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5391
diff changeset
1108 * Per interface only affects IsRouter of NA messages. */
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5391
diff changeset
1109 #if defined(PRIVSEP) && (defined(HAVE_PLEDGE) || defined(__linux__))
5238
73659576d485 OpenBSD: Fix non privsep builds.
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1110 if (IN_PRIVSEP(sifp->ctx))
5415
5fae7c5c0f25 inet6: Linux will convert NULL to all, so don't specify all
Roy Marples <roy@marples.name>
parents: 5413
diff changeset
1111 forwarding = ps_root_ip6forwarding(sifp->ctx, NULL) != 0;
5238
73659576d485 OpenBSD: Fix non privsep builds.
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1112 else
5263
1e7ce40ed871 Fix prior for BSD
Roy Marples <roy@marples.name>
parents: 5258
diff changeset
1113 #endif
5415
5fae7c5c0f25 inet6: Linux will convert NULL to all, so don't specify all
Roy Marples <roy@marples.name>
parents: 5413
diff changeset
1114 forwarding = ip6_forwarding(NULL) != 0;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1115
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1116 TAILQ_FOREACH(ifp, sifp->ctx->ifaces, next) {
5204
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
1117 if (ifp != sifp && !forwarding)
47f18579daae privsep: Implement pledge(2) support as found on OpenBSD
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
1118 continue;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1119
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1120 state = IPV6_STATE(ifp);
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1121 if (state == NULL)
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1122 continue;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1123
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1124 TAILQ_FOREACH(ia, &state->addrs, next) {
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1125 if (IN6_IS_ADDR_LINKLOCAL(&ia->addr))
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1126 continue;
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1127 /* Let's be optimistic.
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1128 * Any decent OS won't forward or accept traffic
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1129 * from/to tentative or detached addresses. */
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1130 if (!(ia->addr_flags & IN6_IFF_DUPLICATED))
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1131 return ia;
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1132 }
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1133 }
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1134 return NULL;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1135 }
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1136
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1137 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1138 ipv6_handleifa(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
1139 int cmd, struct if_head *ifs, const char *ifname,
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1140 const struct in6_addr *addr, uint8_t prefix_len, int addrflags, pid_t pid)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1141 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1142 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
1143 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1144 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
1145 struct ll_callback *cb;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1146 bool anyglobal;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1147
4692
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1148 #ifdef __sun
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1149 struct sockaddr_in6 subnet;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1150
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1151 /* Solaris on-link route is an unspecified address! */
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1152 if (IN6_IS_ADDR_UNSPECIFIED(addr)) {
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1153 if (if_getsubnet(ctx, ifname, AF_INET6,
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1154 &subnet, sizeof(subnet)) == -1)
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1155 {
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1156 logerr(__func__);
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1157 return;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1158 }
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1159 addr = &subnet.sin6_addr;
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1160 }
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1161 #endif
4a8c51be0604 Solaris: Get the subnet in ipv6 ifa handler
Roy Marples <roy@marples.name>
parents: 4687
diff changeset
1162
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1163 #if 0
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1164 char dbuf[INET6_ADDRSTRLEN];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1165 const char *dbp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1166
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1167 dbp = inet_ntop(AF_INET6, &addr->s6_addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1168 dbuf, INET6_ADDRSTRLEN);
4683
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4674
diff changeset
1169 loginfox("%s: cmd %d addr %s addrflags %d",
290102dddf11 Solaris: Fix address flags
Roy Marples <roy@marples.name>
parents: 4674
diff changeset
1170 ifname, cmd, dbp, addrflags);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1171 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1172
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1173 if (ifs == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1174 ifs = ctx->ifaces;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1175 if (ifs == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1176 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1177 if ((ifp = if_find(ifs, ifname)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1178 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1179 if ((state = ipv6_getstate(ifp)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1180 return;
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1181 anyglobal = ipv6_anyglobal(ifp) != NULL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1182
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1183 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1184 if (IN6_ARE_ADDR_EQUAL(&ia->addr, addr))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1185 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1186 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1187
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1188 switch (cmd) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1189 case RTM_DELADDR:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1190 if (ia != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1191 TAILQ_REMOVE(&state->addrs, ia, next);
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1192 #ifdef ND6_ADVERTISE
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1193 /* Advertise the address if it exists on
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1194 * another interface. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1195 ipv6nd_advertise(ia);
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1196 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1197 /* We'll free it at the end of the function. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1198 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1199 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1200 case RTM_NEWADDR:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1201 if (ia == NULL) {
4175
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4162
diff changeset
1202 ia = ipv6_newaddr(ifp, addr, prefix_len, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1203 #ifdef ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1204 strlcpy(ia->alias, ifname, sizeof(ia->alias));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1205 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1206 if (if_getlifetime6(ia) == -1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1207 /* No support or address vanished.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1208 * Either way, just set a deprecated
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1209 * infinite time lifetime and continue.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1210 * This is fine because we only want
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1211 * to know this when trying to extend
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1212 * temporary addresses.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1213 * As we can't extend infinite, we'll
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1214 * create a new temporary address. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1215 ia->prefix_pltime = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1216 ia->prefix_vltime =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1217 ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1218 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1219 /* This is a minor regression against RFC 4941
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1220 * because the kernel only knows when the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1221 * lifetimes were last updated, not when the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1222 * address was initially created.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1223 * Provided dhcpcd is not restarted, this
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1224 * won't be a problem.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1225 * If we don't like it, we can always
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1226 * pretend lifetimes are infinite and always
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1227 * generate a new temporary address on
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1228 * restart. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1229 ia->acquired = ia->created;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1230 TAILQ_INSERT_TAIL(&state->addrs, ia, next);
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 ia->addr_flags = addrflags;
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
1233 ia->flags &= ~IPV6_AF_STALE;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1234 #ifdef IPV6_MANAGETEMPADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1235 if (ia->addr_flags & IN6_IFF_TEMPORARY)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1236 ia->flags |= IPV6_AF_TEMPORARY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1237 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1238 if (IN6_IS_ADDR_LINKLOCAL(&ia->addr) || ia->dadcallback) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1239 #ifdef IPV6_POLLADDRFLAG
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1240 if (ia->addr_flags & IN6_IFF_TENTATIVE) {
4935
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1241 eloop_timeout_add_msec(
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1242 ia->iface->ctx->eloop,
4935
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1243 RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1244 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1245 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1246 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1247
5247
30906bee600b Remove some old FORKED logic.
Roy Marples <roy@marples.name>
parents: 5238
diff changeset
1248 if (ia->dadcallback)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1249 ia->dadcallback(ia);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1250
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1251 if (IN6_IS_ADDR_LINKLOCAL(&ia->addr) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1252 !(ia->addr_flags & IN6_IFF_NOTUSEABLE))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1253 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1254 /* Now run any callbacks.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1255 * Typically IPv6RS or DHCPv6 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1256 while ((cb =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1257 TAILQ_FIRST(&state->ll_callbacks)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1258 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1259 TAILQ_REMOVE(
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1260 &state->ll_callbacks,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1261 cb, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1262 cb->callback(cb->arg);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1263 free(cb);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1264 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1265 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1266 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1267 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1268 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1269
4283
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1270 if (ia == NULL)
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1271 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1272
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1273 ctx->options &= ~DHCPCD_RTBUILD;
4283
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1274 ipv6nd_handleifa(cmd, ia, pid);
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4283
diff changeset
1275 #ifdef DHCP6
4283
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1276 dhcp6_handleifa(cmd, ia, pid);
4285
92c215d75a0c Fix compile without INET6
Roy Marples <roy@marples.name>
parents: 4283
diff changeset
1277 #endif
4283
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1278
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1279 /* Done with the ia now, so free it. */
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1280 if (cmd == RTM_DELADDR)
c66180322ab9 ip6: if forked from ia callback, don't run ia handlers
Roy Marples <roy@marples.name>
parents: 4241
diff changeset
1281 ipv6_freeaddr(ia);
4598
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
1282 else if (!(ia->addr_flags & IN6_IFF_NOTUSEABLE))
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
1283 ia->flags |= IPV6_AF_DADCOMPLETED;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1284
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1285 /* If we've not already called rt_build via the IPv6ND
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1286 * or DHCP6 handlers and the existance of any useable
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1287 * global address on the interface has changed,
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1288 * call rt_build to add/remove the default route. */
4759
2e62e5b3a0db inet6: Fix a potential crash learning addresses
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1289 if (ifp->active &&
2e62e5b3a0db inet6: Fix a potential crash learning addresses
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1290 ((ifp->options != NULL && ifp->options->options & DHCPCD_IPV6) ||
2e62e5b3a0db inet6: Fix a potential crash learning addresses
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1291 (ifp->options == NULL && ctx->options & DHCPCD_IPV6)) &&
4674
3aac360385c2 Better fix for prior.
Roy Marples <roy@marples.name>
parents: 4673
diff changeset
1292 !(ctx->options & DHCPCD_RTBUILD) &&
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
1293 (ipv6_anyglobal(ifp) != NULL) != anyglobal)
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1294 rt_build(ctx, AF_INET6);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1295 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1296
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1297 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1298 ipv6_hasaddr(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
1299 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1300
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1301 if (ipv6nd_iffindaddr(ifp, NULL, 0) != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1302 return 1;
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1303 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1304 if (dhcp6_iffindaddr(ifp, NULL, 0) != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1305 return 1;
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1306 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1307 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1308 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1309
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1310 struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1311 ipv6_iffindaddr(struct interface *ifp, const struct in6_addr *addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1312 int revflags)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1313 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1314 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1315 struct ipv6_addr *ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1316
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1317 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1318 if (state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1319 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1320 if (addr == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1321 if (IN6_IS_ADDR_LINKLOCAL(&ap->addr) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1322 (!revflags || !(ap->addr_flags & revflags)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1323 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1324 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1325 if (IN6_ARE_ADDR_EQUAL(&ap->addr, addr) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 (!revflags || !(ap->addr_flags & revflags)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1327 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1328 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1329 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1330 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1331 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1332 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1333
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1334 static struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1335 ipv6_iffindmaskaddr(const struct interface *ifp, const struct in6_addr *addr)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1336 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1337 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1338 struct ipv6_addr *ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1339 struct in6_addr mask;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1340
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1341 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1342 if (state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1343 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1344 if (ipv6_mask(&mask, ap->prefix_len) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1345 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1346 if (IN6_ARE_MASKED_ADDR_EQUAL(&ap->addr, addr, &mask))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1347 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1348 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1349 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1350 return NULL;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1353 struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1354 ipv6_findmaskaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1355 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1356 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
1357 struct ipv6_addr *ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1358
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1359 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
1360 ap = ipv6_iffindmaskaddr(ifp, addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1361 if (ap != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1362 return ap;
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 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1365 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1366
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1367 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1368 ipv6_addlinklocalcallback(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
1369 void (*callback)(void *), void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1370 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1371 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1372 struct ll_callback *cb;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1373
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1374 state = ipv6_getstate(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1375 TAILQ_FOREACH(cb, &state->ll_callbacks, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1376 if (cb->callback == callback && cb->arg == arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1377 break;
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 if (cb == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1380 cb = malloc(sizeof(*cb));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1381 if (cb == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1382 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1383 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1384 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1385 cb->callback = callback;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1386 cb->arg = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1387 TAILQ_INSERT_TAIL(&state->ll_callbacks, cb, next);
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 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1390 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1391
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1392 static struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1393 ipv6_newlinklocal(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
1394 {
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1395 struct ipv6_addr *ia;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1396 struct in6_addr in6;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1397
4100
b4dd6f52265d Fix a valgrind error.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
1398 memset(&in6, 0, sizeof(in6));
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1399 in6.s6_addr32[0] = htonl(0xfe800000);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1400 ia = ipv6_newaddr(ifp, &in6, 64, 0);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1401 if (ia != NULL) {
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1402 ia->prefix_pltime = ND6_INFINITE_LIFETIME;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1403 ia->prefix_vltime = ND6_INFINITE_LIFETIME;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1404 }
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1405 return ia;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1406 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1407
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1408 static const uint8_t allzero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1409 static const uint8_t allone[8] =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1410 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1411
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1412 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1413 ipv6_addlinklocal(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
1414 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1415 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1416 struct ipv6_addr *ap, *ap2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1417 int dadcounter;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1418
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1419 if (!(ifp->options->options & DHCPCD_CONFIGURE))
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1420 return 0;
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1421
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1422 /* Check sanity before malloc */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1423 if (!(ifp->options->options & DHCPCD_SLAACPRIVATE)) {
5166
a70f6ddefe3c Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1424 switch (ifp->hwtype) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1425 case ARPHRD_ETHER:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1426 /* Check for a valid hardware address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1427 if (ifp->hwlen != 6 && ifp->hwlen != 8) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1428 errno = ENOTSUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1429 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1430 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1431 if (memcmp(ifp->hwaddr, allzero, ifp->hwlen) == 0 ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1432 memcmp(ifp->hwaddr, allone, ifp->hwlen) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1433 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1434 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1435 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1436 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1437 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1438 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1439 errno = ENOTSUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1440 return -1;
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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1443
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1444 state = ipv6_getstate(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1445 if (state == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1446 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1447
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1448 ap = ipv6_newlinklocal(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1449 if (ap == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1450 return -1;
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 dadcounter = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1453 if (ifp->options->options & DHCPCD_SLAACPRIVATE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1454 nextslaacprivate:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1455 if (ipv6_makestableprivate(&ap->addr,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1456 &ap->prefix, ap->prefix_len, ifp, &dadcounter) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1457 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1458 free(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1459 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1460 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1461 ap->dadcounter = dadcounter;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1462 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1463 memcpy(ap->addr.s6_addr, ap->prefix.s6_addr, 8);
5166
a70f6ddefe3c Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1464 switch (ifp->hwtype) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1465 case ARPHRD_ETHER:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1466 if (ifp->hwlen == 6) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1467 ap->addr.s6_addr[ 8] = ifp->hwaddr[0];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1468 ap->addr.s6_addr[ 9] = ifp->hwaddr[1];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1469 ap->addr.s6_addr[10] = ifp->hwaddr[2];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1470 ap->addr.s6_addr[11] = 0xff;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1471 ap->addr.s6_addr[12] = 0xfe;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1472 ap->addr.s6_addr[13] = ifp->hwaddr[3];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1473 ap->addr.s6_addr[14] = ifp->hwaddr[4];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1474 ap->addr.s6_addr[15] = ifp->hwaddr[5];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1475 } else if (ifp->hwlen == 8)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1476 memcpy(&ap->addr.s6_addr[8], ifp->hwaddr, 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1477 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1478 free(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1479 errno = ENOTSUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1480 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1481 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1482 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1483 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1484
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1485 /* Sanity check: g bit must not indciate "group" */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1486 if (EUI64_GROUP(&ap->addr)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1487 free(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1489 return -1;
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 EUI64_TO_IFID(&ap->addr);
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1494 /* Do we already have this address? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1495 TAILQ_FOREACH(ap2, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1496 if (IN6_ARE_ADDR_EQUAL(&ap->addr, &ap2->addr)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1497 if (ap2->addr_flags & IN6_IFF_DUPLICATED) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1498 if (ifp->options->options &
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1499 DHCPCD_SLAACPRIVATE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1500 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1501 dadcounter++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1502 goto nextslaacprivate;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1503 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1504 free(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1505 errno = EADDRNOTAVAIL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1506 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1507 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1508
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1509 logwarnx("%s: waiting for %s to complete",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1510 ap2->iface->name, ap2->saddr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1511 free(ap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1512 errno = EEXIST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1513 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1514 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1515 }
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 inet_ntop(AF_INET6, &ap->addr, ap->saddr, sizeof(ap->saddr));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1518 TAILQ_INSERT_TAIL(&state->addrs, ap, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1519 ipv6_addaddr(ap, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1520 return 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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1523 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1524 ipv6_tryaddlinklocal(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
1525 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1526 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
1527
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1528 /* We can't assign a link-locak address to this,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1529 * the ppp process has to. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1530 if (ifp->flags & IFF_POINTOPOINT)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1531 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1532
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1533 ia = ipv6_iffindaddr(ifp, NULL, IN6_IFF_DUPLICATED);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1534 if (ia != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1535 #ifdef IPV6_POLLADDRFLAG
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1536 if (ia->addr_flags & IN6_IFF_TENTATIVE) {
4935
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1537 eloop_timeout_add_msec(
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1538 ia->iface->ctx->eloop,
4935
978c1d5b04e8 inet6: Use milliseconds rather than timespec for calculating delays
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1539 RETRANS_TIMER / 2, ipv6_checkaddrflags, ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1540 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1541 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1542 return 0;
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 if (!CAN_ADD_LLADDR(ifp))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1545 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1546
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1547 return ipv6_addlinklocal(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1548 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1549
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1550 void
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1551 ipv6_setscope(struct sockaddr_in6 *sin, unsigned int ifindex)
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1552 {
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1553
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1554 #ifdef __KAME__
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1555 /* KAME based systems want to store the scope inside the sin6_addr
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1556 * for link local addresses */
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1557 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1558 uint16_t scope = htons((uint16_t)ifindex);
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1559 memcpy(&sin->sin6_addr.s6_addr[2], &scope,
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1560 sizeof(scope));
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1561 }
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1562 sin->sin6_scope_id = 0;
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1563 #else
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1564 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr))
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1565 sin->sin6_scope_id = ifindex;
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1566 else
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1567 sin->sin6_scope_id = 0;
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1568 #endif
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1569 }
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1570
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1571 unsigned int
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1572 ipv6_getscope(const struct sockaddr_in6 *sin)
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1573 {
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1574 #ifdef __KAME__
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1575 uint16_t scope;
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1576 #endif
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1577
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1578 if (!IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr))
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1579 return 0;
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1580 #ifdef __KAME__
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1581 memcpy(&scope, &sin->sin6_addr.s6_addr[2], sizeof(scope));
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1582 return (unsigned int)ntohs(scope);
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1583 #else
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1584 return (unsigned int)sin->sin6_scope_id;
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1585 #endif
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1586 }
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5182
diff changeset
1587
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1588 struct ipv6_addr *
4175
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4162
diff changeset
1589 ipv6_newaddr(struct interface *ifp, const struct in6_addr *addr,
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4162
diff changeset
1590 uint8_t prefix_len, 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
1591 {
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1592 struct ipv6_addr *ia, *iaf;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1593 char buf[INET6_ADDRSTRLEN];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1594 const char *cbp;
4122
fc82ecf2d118 Don't create temporary addresses based off prefix in newaddr.
Roy Marples <roy@marples.name>
parents: 4116
diff changeset
1595 bool tempaddr;
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1596 int addr_flags;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1597
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1598 #ifdef IPV6_AF_TEMPORARY
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1599 tempaddr = flags & IPV6_AF_TEMPORARY;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1600 #else
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1601 tempaddr = false;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1602 #endif
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1603
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1604 /* If adding a new DHCP / RA derived address, check current flags
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1605 * from an existing address. */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1606 if (tempaddr)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1607 iaf = NULL;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1608 else if (flags & IPV6_AF_AUTOCONF)
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1609 iaf = ipv6nd_iffindprefix(ifp, addr, prefix_len);
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1610 else
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1611 iaf = ipv6_iffindaddr(ifp, addr, 0);
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1612 if (iaf != NULL) {
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1613 addr_flags = iaf->addr_flags;
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1614 flags |= IPV6_AF_ADDED;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1615 } else
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1616 addr_flags = IN6_IFF_TENTATIVE;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1617
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1618 ia = calloc(1, sizeof(*ia));
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1619 if (ia == NULL)
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1620 goto err;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1621
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1622 ia->iface = ifp;
4598
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
1623 ia->addr_flags = addr_flags;
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1624 ia->flags = IPV6_AF_NEW | flags;
4598
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
1625 if (!(ia->addr_flags & IN6_IFF_NOTUSEABLE))
8a5d1746e441 Solaris: Avoid re-adding IPv6 addresses to preserve the prefix route
Roy Marples <roy@marples.name>
parents: 4589
diff changeset
1626 ia->flags |= IPV6_AF_DADCOMPLETED;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1627 ia->prefix_len = prefix_len;
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4128
diff changeset
1628 ia->dhcp6_fd = -1;
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1629
4883
a6eeb584a437 DHCP6: Fix deprecating a delegated prefix
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
1630 #ifndef SMALL
a6eeb584a437 DHCP6: Fix deprecating a delegated prefix
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
1631 TAILQ_INIT(&ia->pd_pfxs);
a6eeb584a437 DHCP6: Fix deprecating a delegated prefix
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
1632 #endif
a6eeb584a437 DHCP6: Fix deprecating a delegated prefix
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
1633
4975
1c75ddb407bf inet6: Support a /128 autoconf prefix from RA
Roy Marples <roy@marples.name>
parents: 4935
diff changeset
1634 if (prefix_len == 128)
1c75ddb407bf inet6: Support a /128 autoconf prefix from RA
Roy Marples <roy@marples.name>
parents: 4935
diff changeset
1635 goto makepfx;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1636 else if (ia->flags & IPV6_AF_AUTOCONF) {
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1637 ia->prefix = *addr;
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1638 if (iaf != NULL)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1639 memcpy(&ia->addr, &iaf->addr, sizeof(ia->addr));
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1640 else {
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1641 ia->dadcounter = ipv6_makeaddr(&ia->addr, ifp,
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1642 &ia->prefix,
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1643 ia->prefix_len,
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1644 ia->flags);
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1645 if (ia->dadcounter == -1)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1646 goto err;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1647 }
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1648 } else if (ia->flags & IPV6_AF_RAPFX) {
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1649 ia->prefix = *addr;
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1650 #ifdef __sun
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1651 ia->addr = *addr;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1652 cbp = inet_ntop(AF_INET6, &ia->addr, buf, sizeof(buf));
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1653 goto paddr;
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1654 #else
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1655 return ia;
4684
e277aaad03b7 Solaris: Fix Prefix routes without an address
Roy Marples <roy@marples.name>
parents: 4683
diff changeset
1656 #endif
4975
1c75ddb407bf inet6: Support a /128 autoconf prefix from RA
Roy Marples <roy@marples.name>
parents: 4935
diff changeset
1657 } else if (ia->flags & (IPV6_AF_REQUEST | IPV6_AF_DELEGATEDPFX)) {
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1658 ia->prefix = *addr;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1659 cbp = inet_ntop(AF_INET6, &ia->prefix, buf, sizeof(buf));
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1660 goto paddr;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1661 } else {
4975
1c75ddb407bf inet6: Support a /128 autoconf prefix from RA
Roy Marples <roy@marples.name>
parents: 4935
diff changeset
1662 makepfx:
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1663 ia->addr = *addr;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1664 if (ipv6_makeprefix(&ia->prefix,
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1665 &ia->addr, ia->prefix_len) == -1)
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1666 goto err;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1667 }
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1668
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1669 cbp = inet_ntop(AF_INET6, &ia->addr, buf, sizeof(buf));
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1670 paddr:
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1671 if (cbp == NULL)
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1672 goto err;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1673 snprintf(ia->saddr, sizeof(ia->saddr), "%s/%d", cbp, ia->prefix_len);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1674
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1675 return ia;
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1676
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1677 err:
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1678 logerr(__func__);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1679 free(ia);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1680 return NULL;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1683 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1684 ipv6_staticdadcallback(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1685 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1686 struct ipv6_addr *ia = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1687 int wascompleted;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1688
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1689 wascompleted = (ia->flags & IPV6_AF_DADCOMPLETED);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1690 ia->flags |= IPV6_AF_DADCOMPLETED;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5166
diff changeset
1691 if (ia->addr_flags & IN6_IFF_DUPLICATED)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1692 logwarnx("%s: DAD detected %s", ia->iface->name,
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3941
diff changeset
1693 ia->saddr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1694 else if (!wascompleted) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1695 logdebugx("%s: IPv6 static DAD completed",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1696 ia->iface->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1697 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1698
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1699 #define FINISHED (IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1700 if (!wascompleted) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1701 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
1702 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1703
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1704 ifp = ia->iface;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1705 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1706 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1707 if (ia->flags & IPV6_AF_STATIC &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1708 (ia->flags & FINISHED) != FINISHED)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1709 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1710 wascompleted = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1711 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1712 }
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 if (!wascompleted)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1715 script_runreason(ifp, "STATIC6");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1716 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1717 #undef FINISHED
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1718 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1719
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1720 ssize_t
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
1721 ipv6_env(FILE *fp, const char *prefix, 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
1722 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1723 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
1724
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3941
diff changeset
1725 ia = ipv6_iffindaddr(UNCONST(ifp), &ifp->options->req_addr6,
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3941
diff changeset
1726 IN6_IFF_NOTUSEABLE);
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
1727 if (ia == NULL)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
1728 return 0;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
1729 if (efprintf(fp, "%s_ip6_address=%s", prefix, ia->saddr) == -1)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
1730 return -1;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
1731 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
1732 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1733
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1734 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1735 ipv6_staticdadcompleted(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
1736 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1737 const struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1738 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
1739 int n;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1740
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1741 if ((state = IPV6_CSTATE(ifp)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1742 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1743 n = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1744 #define COMPLETED (IPV6_AF_STATIC | IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1745 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1746 if ((ia->flags & COMPLETED) == COMPLETED &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1747 !(ia->addr_flags & IN6_IFF_NOTUSEABLE))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1748 n++;
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 return n;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1751 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1752
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1753 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1754 ipv6_startstatic(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
1755 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1756 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
1757 int run_script;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1758
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1759 if (IN6_IS_ADDR_UNSPECIFIED(&ifp->options->req_addr6))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1760 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1761
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1762 ia = ipv6_iffindaddr(ifp, &ifp->options->req_addr6, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1763 if (ia != NULL &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1764 (ia->prefix_len != ifp->options->req_prefix_len ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1765 ia->addr_flags & IN6_IFF_NOTUSEABLE))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1766 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1767 ipv6_deleteaddr(ia);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1768 ia = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1769 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1770 if (ia == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1771 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1772
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1773 ia = ipv6_newaddr(ifp, &ifp->options->req_addr6,
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
1774 ifp->options->req_prefix_len, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1775 if (ia == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1776 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1777 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1778 TAILQ_INSERT_TAIL(&state->addrs, ia, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1779 run_script = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1780 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1781 run_script = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1782 ia->flags |= IPV6_AF_STATIC | IPV6_AF_ONLINK;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1783 ia->prefix_vltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1784 ia->prefix_pltime = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1785 ia->dadcallback = ipv6_staticdadcallback;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1786 ipv6_addaddr(ia, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1787 rt_build(ifp->ctx, AF_INET6);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1788 if (run_script)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1789 script_runreason(ifp, "STATIC6");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1790 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1791 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1792
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1793 /* Ensure the interface has a link-local address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1794 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1795 ipv6_start(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
1796 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1797 #ifdef IPV6_POLLADDRFLAG
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1798 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1799
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1800 /* We need to update the address flags. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1801 if ((state = IPV6_STATE(ifp)) != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1802 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
1803 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
1804 int flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1805
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1806 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1807 #ifdef ALIAS_ADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1808 alias = ia->alias;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1809 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1810 alias = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1811 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1812 flags = if_addrflags6(ia->iface, &ia->addr, alias);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1813 if (flags != -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1814 ia->addr_flags = flags;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1815 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1816 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1817 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1818
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1819 if (ipv6_tryaddlinklocal(ifp) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1820 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1821
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1822 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1823 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1824
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1825 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1826 ipv6_freedrop(struct interface *ifp, int drop)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1827 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1828 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1829 struct ll_callback *cb;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1830
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1831 if (ifp == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1832 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1833
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1834 if ((state = IPV6_STATE(ifp)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1835 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1836
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1837 /* If we got here, we can get rid of any LL callbacks. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1838 while ((cb = TAILQ_FIRST(&state->ll_callbacks))) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1839 TAILQ_REMOVE(&state->ll_callbacks, cb, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1840 free(cb);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1841 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1842
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1843 ipv6_freedrop_addrs(&state->addrs, drop ? 2 : 0, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1844 if (drop) {
4400
2d6a2c8c6b56 route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents: 4396
diff changeset
1845 if (ifp->ctx->ra_routers != NULL)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1846 rt_build(ifp->ctx, AF_INET6);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1847 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1848 /* Because we need to cache the addresses we don't control,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1849 * we only free the state on when NOT dropping addresses. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1850 free(state);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1851 ifp->if_data[IF_DATA_IPV6] = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1852 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1853 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1854 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1855
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1856 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1857 ipv6_ctxfree(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
1858 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1859
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1860 free(ctx->ra_routers);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1861 free(ctx->secret);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1862 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1863
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1864 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1865 ipv6_handleifa_addrs(int cmd,
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1866 struct ipv6_addrhead *addrs, const struct ipv6_addr *addr, pid_t pid)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1867 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1868 struct ipv6_addr *ia, *ian;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1869 uint8_t found, alldadcompleted;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1870
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1871 alldadcompleted = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1872 found = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1873 TAILQ_FOREACH_SAFE(ia, addrs, next, ian) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1874 if (!IN6_ARE_ADDR_EQUAL(&addr->addr, &ia->addr)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1875 if (ia->flags & IPV6_AF_ADDED &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1876 !(ia->flags & IPV6_AF_DADCOMPLETED))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1877 alldadcompleted = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1878 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1879 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1880 switch (cmd) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1881 case RTM_DELADDR:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1882 if (ia->flags & IPV6_AF_ADDED) {
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1883 logwarnx("%s: pid %d deleted address %s",
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1884 ia->iface->name, pid, ia->saddr);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1885 ia->flags &= ~IPV6_AF_ADDED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1886 }
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4759
diff changeset
1887 ipv6_deletedaddr(ia);
4057
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
1888 if (ia->flags & IPV6_AF_DELEGATED) {
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
1889 TAILQ_REMOVE(addrs, ia, next);
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
1890 ipv6_freeaddr(ia);
aa430176fb7a prefix delegation: Remove deleted addresses from consideration
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
1891 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1892 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1893 case RTM_NEWADDR:
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5166
diff changeset
1894 ia->addr_flags = addr->addr_flags;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1895 /* Safety - ignore tentative announcements */
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5166
diff changeset
1896 if (ia->addr_flags &
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1897 (IN6_IFF_DETACHED | IN6_IFF_TENTATIVE))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1898 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1899 if ((ia->flags & IPV6_AF_DADCOMPLETED) == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1900 found++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1901 if (ia->dadcallback)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1902 ia->dadcallback(ia);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1903 /* We need to set this here in-case the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1904 * dadcallback function checks it */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1905 ia->flags |= IPV6_AF_DADCOMPLETED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1906 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1907 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1908 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1909 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1910
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1911 return alldadcompleted ? found : 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1912 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1913
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1914 #ifdef IPV6_MANAGETEMPADDR
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1915 static void
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1916 ipv6_regen_desync(struct interface *ifp, bool force)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1917 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1918 struct ipv6_state *state;
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
1919 unsigned int max;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1920
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1921 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1922
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1923 /* RFC4941 Section 5 states that DESYNC_FACTOR must never be
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1924 * greater than TEMP_VALID_LIFETIME - REGEN_ADVANCE.
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1925 * I believe this is an error and it should be never be greater than
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1926 * TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE. */
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
1927 max = TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1928 if (state->desync_factor && !force && state->desync_factor < max)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1929 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1930 if (state->desync_factor == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1931 state->desync_factor =
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1932 arc4random_uniform(MIN(MAX_DESYNC_FACTOR, max));
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
1933 max = TEMP_PREFERRED_LIFETIME - state->desync_factor - REGEN_ADVANCE;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1934 eloop_timeout_add_sec(ifp->ctx->eloop, max, ipv6_regentempaddrs, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1935 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1936
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1937 /* RFC4941 Section 3.3.7 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1938 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1939 ipv6_tempdadcallback(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1940 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1941 struct ipv6_addr *ia = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1942
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5166
diff changeset
1943 if (ia->addr_flags & IN6_IFF_DUPLICATED) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1944 struct ipv6_addr *ia1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1945 struct timespec tv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1946
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1947 if (++ia->dadcounter == TEMP_IDGEN_RETRIES) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1948 logerrx("%s: too many duplicate temporary addresses",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1949 ia->iface->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1950 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1951 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1952 clock_gettime(CLOCK_MONOTONIC, &tv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1953 if ((ia1 = ipv6_createtempaddr(ia, &tv)) == NULL)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
1954 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1955 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1956 ia1->dadcounter = ia->dadcounter;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1957 ipv6_deleteaddr(ia);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1958 if (ia1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1959 ipv6_addaddr(ia1, &ia1->acquired);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1960 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1961 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1962
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1963 struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1964 ipv6_createtempaddr(struct ipv6_addr *ia0, const struct timespec *now)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1965 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1966 struct ipv6_state *state;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1967 struct interface *ifp = ia0->iface;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1968 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
1969
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1970 ia = ipv6_newaddr(ifp, &ia0->prefix, ia0->prefix_len,
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1971 IPV6_AF_AUTOCONF | IPV6_AF_TEMPORARY);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1972 if (ia == NULL)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1973 return NULL;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1974
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1975 ia->dadcallback = ipv6_tempdadcallback;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1976 ia->created = ia->acquired = now ? *now : ia0->acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1977
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1978 /* Ensure desync is still valid */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1979 ipv6_regen_desync(ifp, false);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1980
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1981 /* RFC4941 Section 3.3.4 */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
1982 state = IPV6_STATE(ia->iface);
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
1983 ia->prefix_pltime = MIN(ia0->prefix_pltime,
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
1984 TEMP_PREFERRED_LIFETIME - state->desync_factor);
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
1985 ia->prefix_vltime = MIN(ia0->prefix_vltime, TEMP_VALID_LIFETIME);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1986 if (ia->prefix_pltime <= REGEN_ADVANCE ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1987 ia->prefix_pltime > ia0->prefix_vltime)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1988 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1989 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1990 free(ia);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1991 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1992 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1993
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1994 TAILQ_INSERT_TAIL(&state->addrs, ia, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1995 return ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1996 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1997
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1998 struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1999 ipv6_settemptime(struct ipv6_addr *ia, int flags)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2000 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2001 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2002 struct ipv6_addr *ap, *first;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2003
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2004 state = IPV6_STATE(ia->iface);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2005 first = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2006 TAILQ_FOREACH_REVERSE(ap, &state->addrs, ipv6_addrhead, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2007 if (ap->flags & IPV6_AF_TEMPORARY &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2008 ap->prefix_pltime &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2009 IN6_ARE_ADDR_EQUAL(&ia->prefix, &ap->prefix))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2010 {
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2011 unsigned int max, ext;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2012
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2013 if (flags == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2014 if (ap->prefix_pltime -
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2015 (uint32_t)(ia->acquired.tv_sec -
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2016 ap->acquired.tv_sec)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2017 < REGEN_ADVANCE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2018 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2019
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2020 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2021 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2022
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2023 if (!(ap->flags & IPV6_AF_ADDED))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2024 ap->flags |= IPV6_AF_NEW | IPV6_AF_AUTOCONF;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2025 ap->flags &= ~IPV6_AF_STALE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2026
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2027 /* RFC4941 Section 3.4
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2028 * Deprecated prefix, deprecate the temporary address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2029 if (ia->prefix_pltime == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2030 ap->prefix_pltime = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2031 goto valid;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2032 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2033
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2034 /* Ensure desync is still valid */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2035 ipv6_regen_desync(ap->iface, false);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2036
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2037 /* RFC4941 Section 3.3.2
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2038 * Extend temporary times, but ensure that they
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2039 * never last beyond the system limit. */
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2040 ext = (unsigned int)ia->acquired.tv_sec
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2041 + ia->prefix_pltime;
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2042 max = (unsigned int)(ap->created.tv_sec +
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
2043 TEMP_PREFERRED_LIFETIME -
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2044 state->desync_factor);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2045 if (ext < max)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2046 ap->prefix_pltime = ia->prefix_pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2047 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2048 ap->prefix_pltime =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2049 (uint32_t)(max - ia->acquired.tv_sec);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2050
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2051 valid:
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2052 ext = (unsigned int)ia->acquired.tv_sec +
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2053 ia->prefix_vltime;
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
2054 max = (unsigned int)(ap->created.tv_sec +
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5149
diff changeset
2055 TEMP_VALID_LIFETIME);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2056 if (ext < max)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2057 ap->prefix_vltime = ia->prefix_vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2058 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2059 ap->prefix_vltime =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2060 (uint32_t)(max - ia->acquired.tv_sec);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2061
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2062 /* Just extend the latest matching prefix */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2063 ap->acquired = ia->acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2064
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2065 /* If extending return the last match as
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2066 * it's the most current.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2067 * If deprecating, deprecate any other addresses we
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2068 * may have, although this should not be needed */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2069 if (ia->prefix_pltime)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2070 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2071 if (first == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2072 first = ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2073 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2074 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2075 return first;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2076 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2077
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2078 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2079 ipv6_addtempaddrs(struct interface *ifp, const struct timespec *now)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2080 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2081 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2082 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
2083
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2084 state = IPV6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2085 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2086 if (ia->flags & IPV6_AF_TEMPORARY &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2087 !(ia->flags & IPV6_AF_STALE))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2088 ipv6_addaddr(ia, now);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2089 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2090 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2091
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2092 static void
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2093 ipv6_regentempaddr0(struct ipv6_addr *ia, struct timespec *tv)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2094 {
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2095 struct ipv6_addr *ia1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2096
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2097 logdebugx("%s: regen temp addr %s", ia->iface->name, ia->saddr);
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2098 ia1 = ipv6_createtempaddr(ia, tv);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2099 if (ia1)
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2100 ipv6_addaddr(ia1, tv);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2101 else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
2102 logerr(__func__);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2103 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2104
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2105 static void
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2106 ipv6_regentempaddr(void *arg)
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2107 {
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2108 struct timespec tv;
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2109
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2110 clock_gettime(CLOCK_MONOTONIC, &tv);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2111 ipv6_regentempaddr0(arg, &tv);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2112 }
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2113
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2114 void
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2115 ipv6_regentempaddrs(void *arg)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2116 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2117 struct interface *ifp = arg;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2118 struct timespec tv;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2119 struct ipv6_state *state;
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2120 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
2121
5149
8f2f891cff4c inet6: Don't regen temporary addresses without an IPv6 state
Roy Marples <roy@marples.name>
parents: 5130
diff changeset
2122 state = IPV6_STATE(ifp);
8f2f891cff4c inet6: Don't regen temporary addresses without an IPv6 state
Roy Marples <roy@marples.name>
parents: 5130
diff changeset
2123 if (state == NULL)
8f2f891cff4c inet6: Don't regen temporary addresses without an IPv6 state
Roy Marples <roy@marples.name>
parents: 5130
diff changeset
2124 return;
8f2f891cff4c inet6: Don't regen temporary addresses without an IPv6 state
Roy Marples <roy@marples.name>
parents: 5130
diff changeset
2125
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2126 ipv6_regen_desync(ifp, true);
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2128 clock_gettime(CLOCK_MONOTONIC, &tv);
5182
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2129
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2130 /* Mark addresses for regen so we don't infinite loop. */
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2131 TAILQ_FOREACH(ia, &state->addrs, next) {
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2132 if (ia->flags & IPV6_AF_TEMPORARY &&
5391
e9cc33189abd inet6: Don't regen temp addresses we didn't add.
Roy Marples <roy@marples.name>
parents: 5286
diff changeset
2133 ia->flags & IPV6_AF_ADDED &&
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2134 !(ia->flags & IPV6_AF_STALE))
5182
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2135 ia->flags |= IPV6_AF_REGEN;
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2136 else
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2137 ia->flags &= ~IPV6_AF_REGEN;
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2138 }
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2139
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2140 /* Now regen temp addrs */
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2141 TAILQ_FOREACH(ia, &state->addrs, next) {
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2142 if (ia->flags & IPV6_AF_REGEN) {
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2143 ipv6_regentempaddr0(ia, &tv);
5182
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2144 ia->flags &= ~IPV6_AF_REGEN;
72d627ef016e inet6: Mark temp addrs for regen
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
2145 }
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5105
diff changeset
2146 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2147 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2148 #endif /* IPV6_MANAGETEMPADDR */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2149
4237
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2150 void
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2151 ipv6_markaddrsstale(struct interface *ifp, unsigned int flags)
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2152 {
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2153 struct ipv6_state *state;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2154 struct ipv6_addr *ia;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2155
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2156 state = IPV6_STATE(ifp);
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2157 if (state == NULL)
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2158 return;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2159
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2160 TAILQ_FOREACH(ia, &state->addrs, next) {
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2161 if (flags == 0 || ia->flags & flags)
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2162 ia->flags |= IPV6_AF_STALE;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2163 }
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2164 }
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2165
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2166 void
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2167 ipv6_deletestaleaddrs(struct interface *ifp)
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2168 {
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2169 struct ipv6_state *state;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2170 struct ipv6_addr *ia, *ia1;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2171
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2172 state = IPV6_STATE(ifp);
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2173 if (state == NULL)
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2174 return;
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2175
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2176 TAILQ_FOREACH_SAFE(ia, &state->addrs, next, ia1) {
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2177 if (ia->flags & IPV6_AF_STALE)
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2178 ipv6_handleifa(ifp->ctx, RTM_DELADDR,
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2179 ifp->ctx->ifaces, ifp->name,
4241
616f73cad975 For IPv4, override any existing address when adding it.
Roy Marples <roy@marples.name>
parents: 4237
diff changeset
2180 &ia->addr, ia->prefix_len, 0, getpid());
4237
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2181 }
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2182 }
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
2183
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2184
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2185 static struct rt *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2186 inet6_makeroute(struct interface *ifp, const struct ra *rap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2187 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2188 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
2189
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2190 if ((rt = rt_new(ifp)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2191 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2192
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2193 #ifdef HAVE_ROUTE_METRIC
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2194 rt->rt_metric = ifp->metric;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2195 #endif
4162
fbed6260b7e1 Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents: 4161
diff changeset
2196 if (rap != NULL)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2197 rt->rt_mtu = rap->mtu;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2198 return rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2199 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2200
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2201 static struct rt *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2202 inet6_makeprefix(struct interface *ifp, const struct ra *rap,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2203 const 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
2204 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2205 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
2206 struct in6_addr netmask;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2207
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2208 if (addr == NULL || addr->prefix_len > 128) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2209 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2210 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2211 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2212
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2213 /* There is no point in trying to manage a /128 prefix,
4336
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
2214 * ones without a lifetime. */
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
2215 if (addr->prefix_len == 128 || addr->prefix_vltime == 0)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2216 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2217
4336
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
2218 /* Don't install a reject route when not creating bigger prefixes. */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2219 if (addr->flags & IPV6_AF_NOREJECT)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2220 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2221
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2222 /* This address is the delegated prefix, so add a reject route for
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2223 * it via the loopback interface. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2224 if (addr->flags & IPV6_AF_DELEGATEDPFX) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2225 struct interface *lo0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2226
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2227 TAILQ_FOREACH(lo0, 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
2228 if (lo0->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
2229 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2230 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2231 if (lo0 == NULL)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
2232 logwarnx("cannot find a loopback interface "
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3965
diff changeset
2233 "to reject via");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2234 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2235 ifp = lo0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2236 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2237
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2238 if ((rt = inet6_makeroute(ifp, rap)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2239 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2240
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2241 sa_in6_init(&rt->rt_dest, &addr->prefix);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2242 ipv6_mask(&netmask, addr->prefix_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2243 sa_in6_init(&rt->rt_netmask, &netmask);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2244 if (addr->flags & IPV6_AF_DELEGATEDPFX) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2245 rt->rt_flags |= RTF_REJECT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2246 /* Linux does not like a gateway for a reject route. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2247 #ifndef __linux__
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2248 sa_in6_init(&rt->rt_gateway, &in6addr_loopback);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2249 #endif
4336
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
2250 } else if (!(addr->flags & IPV6_AF_ONLINK))
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
2251 sa_in6_init(&rt->rt_gateway, &rap->from);
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
2252 else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2253 rt->rt_gateway.sa_family = AF_UNSPEC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2254 sa_in6_init(&rt->rt_ifa, &addr->addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2255 return rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2256 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2257
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2258 static struct rt *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2259 inet6_makerouter(struct ra *rap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2260 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2261 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
2262
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2263 if ((rt = inet6_makeroute(rap->iface, rap)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2264 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2265 sa_in6_init(&rt->rt_dest, &in6addr_any);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2266 sa_in6_init(&rt->rt_netmask, &in6addr_any);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2267 sa_in6_init(&rt->rt_gateway, &rap->from);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2268 return rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2269 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2270
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2271 #define RT_IS_DEFAULT(rtp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2272 (IN6_ARE_ADDR_EQUAL(&((rtp)->dest), &in6addr_any) && \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2273 IN6_ARE_ADDR_EQUAL(&((rtp)->mask), &in6addr_any))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2274
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2275 static int
4379
e9573d5cbf1e Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
2276 inet6_staticroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2277 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2278 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
2279 struct ipv6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2280 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
2281 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
2282
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2283 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
2284 if ((state = IPV6_STATE(ifp)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2285 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2286 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2287 if ((ia->flags & (IPV6_AF_ADDED | IPV6_AF_STATIC)) ==
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2288 (IPV6_AF_ADDED | IPV6_AF_STATIC))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2289 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2290 rt = inet6_makeprefix(ifp, NULL, ia);
4150
4d9679283c1e We don't actually care about the number of added routes, just
Roy Marples <roy@marples.name>
parents: 4130
diff changeset
2291 if (rt)
4522
e2582c7c7e1d route: Use order from message / config
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
2292 rt_proto_add(routes, rt);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2293 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2294 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2295 }
4150
4d9679283c1e We don't actually care about the number of added routes, just
Roy Marples <roy@marples.name>
parents: 4130
diff changeset
2296 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
2297 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2298
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2299 static int
4532
23730414d0a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4522 4530
diff changeset
2300 inet6_raroutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2301 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2302 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
2303 struct ra *rap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2304 const 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
2305
5059
bd0bfd64aa0e inet6: guard getting RA routers if inet6 not initialised
Roy Marples <roy@marples.name>
parents: 5048
diff changeset
2306 if (ctx->ra_routers == NULL)
bd0bfd64aa0e inet6: guard getting RA routers if inet6 not initialised
Roy Marples <roy@marples.name>
parents: 5048
diff changeset
2307 return 0;
bd0bfd64aa0e inet6: guard getting RA routers if inet6 not initialised
Roy Marples <roy@marples.name>
parents: 5048
diff changeset
2308
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2309 TAILQ_FOREACH(rap, ctx->ra_routers, next) {
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2310 if (rap->expired)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2311 continue;
3965
fa328584bbd1 Remove ipv6ra_own and ipv6ra_own_default options.
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
2312 TAILQ_FOREACH(addr, &rap->addrs, next) {
fa328584bbd1 Remove ipv6ra_own and ipv6ra_own_default options.
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
2313 if (addr->prefix_vltime == 0)
fa328584bbd1 Remove ipv6ra_own and ipv6ra_own_default options.
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
2314 continue;
fa328584bbd1 Remove ipv6ra_own and ipv6ra_own_default options.
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
2315 rt = inet6_makeprefix(rap->iface, rap, addr);
4162
fbed6260b7e1 Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents: 4161
diff changeset
2316 if (rt) {
fbed6260b7e1 Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents: 4161
diff changeset
2317 rt->rt_dflags |= RTDF_RA;
5130
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5129
diff changeset
2318 #ifdef HAVE_ROUTE_PREF
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5129
diff changeset
2319 rt->rt_pref = ipv6nd_rtpref(rap);
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5129
diff changeset
2320 #endif
4522
e2582c7c7e1d route: Use order from message / config
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
2321 rt_proto_add(routes, rt);
4162
fbed6260b7e1 Set DHCP routes as DHCP in supported OS's.
Roy Marples <roy@marples.name>
parents: 4161
diff changeset
2322 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2323 }
4647
82fa5c0d9714 inet6: Just solicit when a router is unreachable
Roy Marples <roy@marples.name>
parents: 4646
diff changeset
2324 if (rap->lifetime == 0)
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2325 continue;
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4692
diff changeset
2326 if (ipv6_anyglobal(rap->iface) == NULL)
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
2327 continue;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2328 rt = inet6_makerouter(rap);
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2329 if (rt == NULL)
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2330 continue;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2331 rt->rt_dflags |= RTDF_RA;
5130
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5129
diff changeset
2332 #ifdef HAVE_ROUTE_PREF
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5129
diff changeset
2333 rt->rt_pref = ipv6nd_rtpref(rap);
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5129
diff changeset
2334 #endif
4532
23730414d0a6 Merge branch 'master' into rbtree
Roy Marples <roy@marples.name>
parents: 4522 4530
diff changeset
2335 rt_proto_add(routes, rt);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2336 }
4150
4d9679283c1e We don't actually care about the number of added routes, just
Roy Marples <roy@marples.name>
parents: 4130
diff changeset
2337 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
2338 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2339
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
2340 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2341 static int
4379
e9573d5cbf1e Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
2342 inet6_dhcproutes(rb_tree_t *routes, struct dhcpcd_ctx *ctx,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2343 enum DH6S dstate)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2344 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2345 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
2346 const struct dhcp6_state *d6_state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2347 const 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
2348 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
2349
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2350 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
2351 d6_state = D6_CSTATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2352 if (d6_state && d6_state->state == dstate) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2353 TAILQ_FOREACH(addr, &d6_state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2354 rt = inet6_makeprefix(ifp, NULL, addr);
4379
e9573d5cbf1e Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
2355 if (rt == NULL)
e9573d5cbf1e Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
2356 continue;
e9573d5cbf1e Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
2357 rt->rt_dflags |= RTDF_DHCP;
4522
e2582c7c7e1d route: Use order from message / config
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
2358 rt_proto_add(routes, rt);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2359 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2360 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2361 }
4150
4d9679283c1e We don't actually care about the number of added routes, just
Roy Marples <roy@marples.name>
parents: 4130
diff changeset
2362 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
2363 }
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
2364 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2365
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2366 bool
4379
e9573d5cbf1e Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
2367 inet6_getroutes(struct dhcpcd_ctx *ctx, rb_tree_t *routes)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2368 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2369
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2370 /* Should static take priority? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2371 if (inet6_staticroutes(routes, ctx) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2372 return false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2373
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2374 /* First add reachable routers and their prefixes */
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2375 if (inet6_raroutes(routes, ctx) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2376 return false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2377
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
2378 #ifdef DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2379 /* We have no way of knowing if prefixes added by DHCP are reachable
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2380 * or not, so we have to assume they are.
4522
e2582c7c7e1d route: Use order from message / config
Roy Marples <roy@marples.name>
parents: 4511
diff changeset
2381 * Add bound before delegated so we can prefer interfaces better. */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2382 if (inet6_dhcproutes(routes, ctx, DH6S_BOUND) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2383 return false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2384 if (inet6_dhcproutes(routes, ctx, DH6S_DELEGATED) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2385 return false;
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
2386 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2387
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2388 return true;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2389 }