annotate src/ipv6nd.c @ 5557:e65d193a1960 draft

Linux: Support wireless IP roaming This is achieved by checking that the interface is wireless, IFF_UP and IFF_LOWER_UP are present, but IFF_RUNNING is missing. This gives exactly the same support as modern NetBSD when carrier loss is detected, but without the address verifications when the carrier comes back as that needs to be handled in the kernel. While IP setup is maintained, other configuration data is discarded. Note that this should be improved in the future. Thanks to Boris Krasnovskiy <borkra@gmail.com> for helping with this.
author Roy Marples <roy@marples.name>
date Sat, 12 Dec 2020 13:12:26 +0000
parents a0d828e25482
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: 4534
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 - IPv6 ND handling
4922
555d7d1a4939 Welcome to 2020!
Roy Marples <roy@marples.name>
parents: 4916
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/ioctl.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/param.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 <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
33 #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
34 #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
35 #include <netinet/ip6.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 <netinet/icmp6.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
37
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
38 #include <assert.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
39 #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
40 #include <fcntl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
41 #include <stddef.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
42 #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
43 #include <string.h>
5065
641e15827969 Be pedantic and move syslog.h into the right place
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
44 #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
45 #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
46
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4990
diff changeset
47 #define ELOOP_QUEUE ELOOP_IPV6ND
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
48 #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
49 #include "dhcpcd.h"
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
50 #include "dhcp-common.h"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
51 #include "dhcp6.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 "eloop.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
53 #include "if.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
54 #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
55 #include "ipv6nd.h"
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
56 #include "logerr.h"
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
57 #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
58 #include "route.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
59 #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
60
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
61 /* Debugging Router Solicitations is a lot of spam, so disable it */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
62 //#define DEBUG_RS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
63
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
64 #ifndef ND_RA_FLAG_HOME_AGENT
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
65 #define ND_RA_FLAG_HOME_AGENT 0x20 /* Home Agent flag in RA */
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
66 #endif
5363
e161ef164608 inet6: Report RA Proxy flag if set
Roy Marples <roy@marples.name>
parents: 5362
diff changeset
67 #ifndef ND_RA_FLAG_PROXY
e161ef164608 inet6: Report RA Proxy flag if set
Roy Marples <roy@marples.name>
parents: 5362
diff changeset
68 #define ND_RA_FLAG_PROXY 0x04 /* Proxy */
e161ef164608 inet6: Report RA Proxy flag if set
Roy Marples <roy@marples.name>
parents: 5362
diff changeset
69 #endif
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
70 #ifndef ND_OPT_PI_FLAG_ROUTER
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
71 #define ND_OPT_PI_FLAG_ROUTER 0x20 /* Router flag in PI */
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
72 #endif
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
73
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
74 #ifndef ND_OPT_RDNSS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
75 #define ND_OPT_RDNSS 25
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
76 struct nd_opt_rdnss { /* RDNSS option RFC 6106 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
77 uint8_t nd_opt_rdnss_type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
78 uint8_t nd_opt_rdnss_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
79 uint16_t nd_opt_rdnss_reserved;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
80 uint32_t nd_opt_rdnss_lifetime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81 /* followed by list of IP prefixes */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
82 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
83 __CTASSERT(sizeof(struct nd_opt_rdnss) == 8);
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 ND_OPT_DNSSL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
87 #define ND_OPT_DNSSL 31
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88 struct nd_opt_dnssl { /* DNSSL option RFC 6106 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
89 uint8_t nd_opt_dnssl_type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
90 uint8_t nd_opt_dnssl_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
91 uint16_t nd_opt_dnssl_reserved;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
92 uint32_t nd_opt_dnssl_lifetime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
93 /* followed by list of DNS servers */
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 __CTASSERT(sizeof(struct nd_opt_rdnss) == 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
96 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
97
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 /* Impossible options, so we can easily add extras */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99 #define _ND_OPT_PREFIX_ADDR 255 + 1
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
100
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
101 /* Minimal IPv6 MTU */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102 #ifndef IPV6_MMTU
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
103 #define IPV6_MMTU 1280
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
104 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
105
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
106 #ifndef ND_RA_FLAG_RTPREF_HIGH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
107 #define ND_RA_FLAG_RTPREF_MASK 0x18
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
108 #define ND_RA_FLAG_RTPREF_HIGH 0x08
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
109 #define ND_RA_FLAG_RTPREF_MEDIUM 0x00
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
110 #define ND_RA_FLAG_RTPREF_LOW 0x18
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
111 #define ND_RA_FLAG_RTPREF_RSV 0x10
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
112 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
113
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
114 #define EXPIRED_MAX 5 /* Remember 5 expired routers to avoid
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
115 logspam. */
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
116
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
117 #define MIN_RANDOM_FACTOR 500 /* millisecs */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
118 #define MAX_RANDOM_FACTOR 1500 /* millisecs */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
119 #define MIN_RANDOM_FACTOR_U MIN_RANDOM_FACTOR * 1000 /* usecs */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
120 #define MAX_RANDOM_FACTOR_U MAX_RANDOM_FACTOR * 1000 /* usecs */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
121
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
122 #if BYTE_ORDER == BIG_ENDIAN
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
123 #define IPV6_ADDR_INT32_ONE 1
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
124 #define IPV6_ADDR_INT16_MLL 0xff02
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
125 #elif BYTE_ORDER == LITTLE_ENDIAN
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
126 #define IPV6_ADDR_INT32_ONE 0x01000000
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
127 #define IPV6_ADDR_INT16_MLL 0x02ff
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
128 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
129
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
130 /* Debugging Neighbor Solicitations is a lot of spam, so disable it */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
131 //#define DEBUG_NS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
132 //
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
133
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
134 static void ipv6nd_handledata(void *);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
135
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
136 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
137 * Android ships buggy ICMP6 filter headers.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
138 * Supply our own until they fix their shit.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
139 * References:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
140 * https://android-review.googlesource.com/#/c/58438/
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
141 * http://code.google.com/p/android/issues/original?id=32621&seq=24
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
142 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
143 #ifdef __ANDROID__
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
144 #undef ICMP6_FILTER_WILLPASS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
145 #undef ICMP6_FILTER_WILLBLOCK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
146 #undef ICMP6_FILTER_SETPASS
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
147 #undef ICMP6_FILTER_SETBLOCK
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
148 #undef ICMP6_FILTER_SETPASSALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
149 #undef ICMP6_FILTER_SETBLOCKALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
150 #define ICMP6_FILTER_WILLPASS(type, filterp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
151 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
152 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
153 ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
154 #define ICMP6_FILTER_SETPASS(type, filterp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
155 ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
156 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
157 ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
158 #define ICMP6_FILTER_SETPASSALL(filterp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
159 memset(filterp, 0, sizeof(struct icmp6_filter));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
160 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
161 memset(filterp, 0xff, sizeof(struct icmp6_filter));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
162 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
163
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
164 /* Support older systems with different defines */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
165 #if !defined(IPV6_RECVHOPLIMIT) && defined(IPV6_HOPLIMIT)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
166 #define IPV6_RECVHOPLIMIT IPV6_HOPLIMIT
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
168 #if !defined(IPV6_RECVPKTINFO) && defined(IPV6_PKTINFO)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
169 #define IPV6_RECVPKTINFO IPV6_PKTINFO
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
170 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
171
4140
57e2a4bfb9b7 ipv6nd_freedrop is no longer public.
Roy Marples <roy@marples.name>
parents: 4123
diff changeset
172 /* Handy defines */
57e2a4bfb9b7 ipv6nd_freedrop is no longer public.
Roy Marples <roy@marples.name>
parents: 4123
diff changeset
173 #define ipv6nd_free_ra(ra) ipv6nd_freedrop_ra((ra), 0)
57e2a4bfb9b7 ipv6nd_freedrop is no longer public.
Roy Marples <roy@marples.name>
parents: 4123
diff changeset
174 #define ipv6nd_drop_ra(ra) ipv6nd_freedrop_ra((ra), 1)
57e2a4bfb9b7 ipv6nd_freedrop is no longer public.
Roy Marples <roy@marples.name>
parents: 4123
diff changeset
175
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
176 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
177 ipv6nd_printoptions(const 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
178 const struct dhcp_opt *opts, size_t opts_len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
179 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
180 size_t i, j;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
181 const struct dhcp_opt *opt, *opt2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
182 int cols;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
183
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
184 for (i = 0, opt = ctx->nd_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
185 i < ctx->nd_opts_len; i++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
186 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
187 for (j = 0, opt2 = opts; j < opts_len; j++, opt2++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
188 if (opt2->option == opt->option)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
189 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
190 if (j == opts_len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
191 cols = printf("%03d %s", opt->option, opt->var);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
192 dhcp_print_option_encoding(opt, cols);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
193 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
194 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
195 for (i = 0, opt = opts; i < opts_len; i++, opt++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
196 cols = printf("%03d %s", opt->option, opt->var);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
197 dhcp_print_option_encoding(opt, cols);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
198 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
199 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
200
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
201 int
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
202 ipv6nd_open(bool recv)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
203 {
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
204 int fd, on;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
205 struct icmp6_filter filt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
206
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
207 fd = xsocket(PF_INET6, SOCK_RAW | SOCK_CXNB, IPPROTO_ICMPV6);
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
208 if (fd == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
209 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
210
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
211 ICMP6_FILTER_SETBLOCKALL(&filt);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
212
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
213 /* RFC4861 4.1 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
214 on = 255;
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
215 if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
216 &on, sizeof(on)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
217 goto eexit;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
218
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
219 if (recv) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
220 on = 1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
221 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
222 &on, sizeof(on)) == -1)
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
223 goto eexit;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
224
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
225 on = 1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
226 if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
227 &on, sizeof(on)) == -1)
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
228 goto eexit;
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
229
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
230 ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
231
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
232 #ifdef SO_RERROR
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
233 on = 1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
234 if (setsockopt(fd, SOL_SOCKET, SO_RERROR,
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
235 &on, sizeof(on)) == -1)
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
236 goto eexit;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
237 #endif
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
238 }
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
239
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
240 if (setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
241 &filt, sizeof(filt)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
242 goto eexit;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
243
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
244 return fd;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
245
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
246 eexit:
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
247 close(fd);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
248 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
249 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
250
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
251 #ifdef __sun
4841
bace61b4b4ff Solaris: Fix non PRIVSEP compile
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
252 int
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
253 ipv6nd_openif(struct interface *ifp)
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
254 {
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
255 int fd;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
256 struct ipv6_mreq mreq = {
4486
ecc12563d4ad sun: Simplify initialisation of the multicast destination
Roy Marples <roy@marples.name>
parents: 4484
diff changeset
257 .ipv6mr_multiaddr = IN6ADDR_LINKLOCAL_ALLNODES_INIT,
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
258 .ipv6mr_interface = ifp->index
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
259 };
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
260 struct rs_state *state = RS_STATE(ifp);
4474
5038198ddbae sun: Bind IPv6ND socket to interface.
Roy Marples <roy@marples.name>
parents: 4473
diff changeset
261 uint_t ifindex = ifp->index;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
262
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
263 if (state->nd_fd != -1)
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
264 return state->nd_fd;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
265
5276
3bc21bfa52f8 Solaris: Fix compile
Roy Marples <roy@marples.name>
parents: 5258
diff changeset
266 fd = ipv6nd_open(true);
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
267 if (fd == -1)
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
268 return -1;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
269
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
270 if (setsockopt(fd, IPPROTO_IPV6, IPV6_BOUND_IF,
4474
5038198ddbae sun: Bind IPv6ND socket to interface.
Roy Marples <roy@marples.name>
parents: 4473
diff changeset
271 &ifindex, sizeof(ifindex)) == -1)
5038198ddbae sun: Bind IPv6ND socket to interface.
Roy Marples <roy@marples.name>
parents: 4473
diff changeset
272 {
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
273 close(fd);
4474
5038198ddbae sun: Bind IPv6ND socket to interface.
Roy Marples <roy@marples.name>
parents: 4473
diff changeset
274 return -1;
5038198ddbae sun: Bind IPv6ND socket to interface.
Roy Marples <roy@marples.name>
parents: 4473
diff changeset
275 }
5038198ddbae sun: Bind IPv6ND socket to interface.
Roy Marples <roy@marples.name>
parents: 4473
diff changeset
276
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
277 if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
278 &mreq, sizeof(mreq)) == -1)
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
279 {
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
280 close(fd);
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
281 return -1;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
282 }
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
283
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
284 state->nd_fd = fd;
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
285 eloop_event_add(ifp->ctx->eloop, fd, ipv6nd_handledata, ifp);
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
286 return fd;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
287 }
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
288 #endif
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
289
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
290 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
291 ipv6nd_makersprobe(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
292 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
293 struct rs_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
294 struct nd_router_solicit *rs;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
295
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
296 state = RS_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
297 free(state->rs);
4076
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
298 state->rslen = sizeof(*rs);
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
299 if (ifp->hwlen != 0)
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
300 state->rslen += (size_t)ROUNDUP8(ifp->hwlen + 2);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
301 state->rs = calloc(1, state->rslen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
302 if (state->rs == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
303 return -1;
4114
ac458a95c4c7 Fix a memory issue.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
304 rs = state->rs;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
305 rs->nd_rs_type = ND_ROUTER_SOLICIT;
4114
ac458a95c4c7 Fix a memory issue.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
306 //rs->nd_rs_code = 0;
ac458a95c4c7 Fix a memory issue.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
307 //rs->nd_rs_cksum = 0;
ac458a95c4c7 Fix a memory issue.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
308 //rs->nd_rs_reserved = 0;
4076
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
309
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
310 if (ifp->hwlen != 0) {
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
311 struct nd_opt_hdr *nd;
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
312
4114
ac458a95c4c7 Fix a memory issue.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
313 nd = (struct nd_opt_hdr *)(state->rs + 1);
4076
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
314 nd->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
315 nd->nd_opt_len = (uint8_t)((ROUNDUP8(ifp->hwlen + 2)) >> 3);
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
316 memcpy(nd + 1, ifp->hwaddr, ifp->hwlen);
9433864aa014 Hardware Address validation
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
317 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
318 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
319 }
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 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
322 ipv6nd_sendrsprobe(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
323 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
324 struct interface *ifp = arg;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
325 struct rs_state *state = RS_STATE(ifp);
4476
60b8905c878e IPv6ND: Use generic initialisers rather than inet_pton
Roy Marples <roy@marples.name>
parents: 4474
diff changeset
326 struct sockaddr_in6 dst = {
60b8905c878e IPv6ND: Use generic initialisers rather than inet_pton
Roy Marples <roy@marples.name>
parents: 4474
diff changeset
327 .sin6_family = AF_INET6,
60b8905c878e IPv6ND: Use generic initialisers rather than inet_pton
Roy Marples <roy@marples.name>
parents: 4474
diff changeset
328 .sin6_addr = IN6ADDR_LINKLOCAL_ALLROUTERS_INIT,
60b8905c878e IPv6ND: Use generic initialisers rather than inet_pton
Roy Marples <roy@marples.name>
parents: 4474
diff changeset
329 .sin6_scope_id = ifp->index,
60b8905c878e IPv6ND: Use generic initialisers rather than inet_pton
Roy Marples <roy@marples.name>
parents: 4474
diff changeset
330 };
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
331 struct iovec iov = { .iov_base = state->rs, .iov_len = state->rslen };
5172
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
332 union {
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
333 struct cmsghdr hdr;
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
334 uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
335 } cmsgbuf = { .buf = { 0 } };
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
336 struct msghdr msg = {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
337 .msg_name = &dst, .msg_namelen = sizeof(dst),
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
338 .msg_iov = &iov, .msg_iovlen = 1,
5172
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
339 .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
340 };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
341 struct cmsghdr *cm;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
342 struct in6_pktinfo pi = { .ipi6_ifindex = ifp->index };
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
343 int s;
5276
3bc21bfa52f8 Solaris: Fix compile
Roy Marples <roy@marples.name>
parents: 5258
diff changeset
344 #ifndef __sun
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
345 struct dhcpcd_ctx *ctx = ifp->ctx;
5276
3bc21bfa52f8 Solaris: Fix compile
Roy Marples <roy@marples.name>
parents: 5258
diff changeset
346 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
347
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
348 if (ipv6_linklocal(ifp) == NULL) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
349 logdebugx("%s: delaying Router Solicitation for LL address",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
350 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
351 ipv6_addlinklocalcallback(ifp, ipv6nd_sendrsprobe, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
352 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
353 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
354
4192
72557c2f086e bsd: set sa_len
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
355 #ifdef HAVE_SA_LEN
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
356 dst.sin6_len = sizeof(dst);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
357 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
358
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
359 /* Set the outbound interface */
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
360 cm = CMSG_FIRSTHDR(&msg);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
361 if (cm == NULL) /* unlikely */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
362 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
363 cm->cmsg_level = IPPROTO_IPV6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
364 cm->cmsg_type = IPV6_PKTINFO;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
365 cm->cmsg_len = CMSG_LEN(sizeof(pi));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
366 memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
367
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
368 logdebugx("%s: sending Router Solicitation", ifp->name);
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
369 #ifdef PRIVSEP
4869
5bad3606b951 privsep: prefer IN_PRIVSEP macros
Roy Marples <roy@marples.name>
parents: 4856
diff changeset
370 if (IN_PRIVSEP(ifp->ctx)) {
4842
efc22a0dde81 Solaris: start privsep support
Roy Marples <roy@marples.name>
parents: 4841
diff changeset
371 if (ps_inet_sendnd(ifp, &msg) == -1)
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
372 logerr(__func__);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
373 goto sent;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
374 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
375 #endif
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
376 #ifdef __sun
5278
ffa72e19fcb8 Solaris: Fix sending RS probes
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
377 if (state->nd_fd == -1) {
ffa72e19fcb8 Solaris: Fix sending RS probes
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
378 if (ipv6nd_openif(ifp) == -1) {
ffa72e19fcb8 Solaris: Fix sending RS probes
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
379 logerr(__func__);
ffa72e19fcb8 Solaris: Fix sending RS probes
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
380 return;
ffa72e19fcb8 Solaris: Fix sending RS probes
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
381 }
ffa72e19fcb8 Solaris: Fix sending RS probes
Roy Marples <roy@marples.name>
parents: 5276
diff changeset
382 }
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
383 s = state->nd_fd;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
384 #else
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
385 if (ctx->nd_fd == -1) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
386 ctx->nd_fd = ipv6nd_open(true);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
387 if (ctx->nd_fd == -1) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
388 logerr(__func__);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
389 return;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
390 }
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
391 eloop_event_add(ctx->eloop, ctx->nd_fd, ipv6nd_handledata, ctx);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5204
diff changeset
392 }
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
393 s = ifp->ctx->nd_fd;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
394 #endif
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
395 if (sendmsg(s, &msg, 0) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
396 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
397 /* Allow IPv6ND to continue .... at most a few errors
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
398 * would be logged.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
399 * Generally the error is ENOBUFS when struggling to
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
400 * associate with an access point. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
401 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
402
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
403 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
404 sent:
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
405 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
406 if (state->rsprobes++ < MAX_RTR_SOLICITATIONS)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
407 eloop_timeout_add_sec(ifp->ctx->eloop,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
408 RTR_SOLICITATION_INTERVAL, ipv6nd_sendrsprobe, ifp);
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
409 else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
410 logwarnx("%s: no IPv6 Routers available", 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
411 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
412
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4564
diff changeset
413 #ifdef ND6_ADVERTISE
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
414 static void
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
415 ipv6nd_sendadvertisement(void *arg)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
416 {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
417 struct ipv6_addr *ia = arg;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
418 struct interface *ifp = ia->iface;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
419 struct dhcpcd_ctx *ctx = ifp->ctx;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
420 struct sockaddr_in6 dst = {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
421 .sin6_family = AF_INET6,
4476
60b8905c878e IPv6ND: Use generic initialisers rather than inet_pton
Roy Marples <roy@marples.name>
parents: 4474
diff changeset
422 .sin6_addr = IN6ADDR_LINKLOCAL_ALLNODES_INIT,
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
423 .sin6_scope_id = ifp->index,
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
424 };
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
425 struct iovec iov = { .iov_base = ia->na, .iov_len = ia->na_len };
5172
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
426 union {
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
427 struct cmsghdr hdr;
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
428 uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
429 } cmsgbuf = { .buf = { 0 } };
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
430 struct msghdr msg = {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
431 .msg_name = &dst, .msg_namelen = sizeof(dst),
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
432 .msg_iov = &iov, .msg_iovlen = 1,
5172
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
433 .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
434 };
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
435 struct cmsghdr *cm;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
436 struct in6_pktinfo pi = { .ipi6_ifindex = ifp->index };
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
437 const struct rs_state *state = RS_CSTATE(ifp);
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
438 int s;
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
439
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
440 if (state == NULL || !if_is_link_up(ifp))
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
441 goto freeit;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
442
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
443 #ifdef SIN6_LEN
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
444 dst.sin6_len = sizeof(dst);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
445 #endif
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
446
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
447 /* Set the outbound interface. */
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
448 cm = CMSG_FIRSTHDR(&msg);
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
449 assert(cm != NULL);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
450 cm->cmsg_level = IPPROTO_IPV6;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
451 cm->cmsg_type = IPV6_PKTINFO;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
452 cm->cmsg_len = CMSG_LEN(sizeof(pi));
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
453 memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
454 logdebugx("%s: sending NA for %s", ifp->name, ia->saddr);
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
455
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
456 #ifdef PRIVSEP
4869
5bad3606b951 privsep: prefer IN_PRIVSEP macros
Roy Marples <roy@marples.name>
parents: 4856
diff changeset
457 if (IN_PRIVSEP(ifp->ctx)) {
4842
efc22a0dde81 Solaris: start privsep support
Roy Marples <roy@marples.name>
parents: 4841
diff changeset
458 if (ps_inet_sendnd(ifp, &msg) == -1)
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
459 logerr(__func__);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
460 goto sent;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
461 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
462 #endif
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
463 #ifdef __sun
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
464 s = state->nd_fd;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
465 #else
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
466 s = ctx->nd_fd;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
467 #endif
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
468 if (sendmsg(s, &msg, 0) == -1)
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
469 logerr(__func__);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
470
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
471 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
472 sent:
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
473 #endif
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
474 if (++ia->na_count < MAX_NEIGHBOR_ADVERTISEMENT) {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
475 eloop_timeout_add_sec(ctx->eloop,
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
476 state->retrans / 1000, ipv6nd_sendadvertisement, ia);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
477 return;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
478 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
479
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
480 freeit:
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
481 free(ia->na);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
482 ia->na = NULL;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
483 ia->na_count = 0;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
484 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
485
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
486 void
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
487 ipv6nd_advertise(struct ipv6_addr *ia)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
488 {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
489 struct dhcpcd_ctx *ctx;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
490 struct interface *ifp;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
491 struct ipv6_state *state;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
492 struct ipv6_addr *iap, *iaf;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
493 struct nd_neighbor_advert *na;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
494
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
495 if (IN6_IS_ADDR_MULTICAST(&ia->addr))
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
496 return;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
497
4686
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
498 #ifdef __sun
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
499 if (!(ia->flags & IPV6_AF_AUTOCONF) && ia->flags & IPV6_AF_RAPFX)
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
500 return;
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
501 #endif
4e051b494520 Solaris: Sending NA now seems to work!
Roy Marples <roy@marples.name>
parents: 4669
diff changeset
502
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
503 ctx = ia->iface->ctx;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
504 /* Find the most preferred address to advertise. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
505 iaf = NULL;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
506 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
507 state = IPV6_STATE(ifp);
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
508 if (state == NULL || !if_is_link_up(ifp))
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
509 continue;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
510
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
511 TAILQ_FOREACH(iap, &state->addrs, next) {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
512 if (!IN6_ARE_ADDR_EQUAL(&iap->addr, &ia->addr))
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
513 continue;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
514
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
515 /* Cancel any current advertisement. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
516 eloop_timeout_delete(ctx->eloop,
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
517 ipv6nd_sendadvertisement, iap);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
518
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
519 /* Don't advertise what we can't use. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
520 if (iap->prefix_vltime == 0 ||
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
521 iap->addr_flags & IN6_IFF_NOTUSEABLE)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
522 continue;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
523
4393
c75918907654 ipv6nd: Don't sort interfaces when picking best address
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
524 if (iaf == NULL ||
c75918907654 ipv6nd: Don't sort interfaces when picking best address
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
525 iaf->iface->metric > iap->iface->metric)
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
526 iaf = iap;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
527 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
528 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
529 if (iaf == NULL)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
530 return;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
531
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
532 /* Make the packet. */
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
533 ifp = iaf->iface;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
534 iaf->na_len = sizeof(*na);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
535 if (ifp->hwlen != 0)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
536 iaf->na_len += (size_t)ROUNDUP8(ifp->hwlen + 2);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
537 na = calloc(1, iaf->na_len);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
538 if (na == NULL) {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
539 logerr(__func__);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
540 return;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
541 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
542
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
543 na->nd_na_type = ND_NEIGHBOR_ADVERT;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
544 na->nd_na_flags_reserved = ND_NA_FLAG_OVERRIDE;
5258
f29e384aa13e privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
545 #if defined(PRIVSEP) && (defined(__linux__) || defined(HAVE_PLEDGE))
f29e384aa13e privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
546 if (IN_PRIVSEP(ctx)) {
5413
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5372
diff changeset
547 if (ps_root_ip6forwarding(ctx, ifp->name) != 0)
5258
f29e384aa13e privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
548 na->nd_na_flags_reserved |= ND_NA_FLAG_ROUTER;
f29e384aa13e privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
549 } else
f29e384aa13e privsep: Allow Linux to work without needing any mounts
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
550 #endif
5413
bb929420bc5d Linux: IP6 forwaring only applies to "all" interface
Roy Marples <roy@marples.name>
parents: 5372
diff changeset
551 if (ip6_forwarding(ifp->name) != 0)
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
552 na->nd_na_flags_reserved |= ND_NA_FLAG_ROUTER;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
553 na->nd_na_target = ia->addr;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
554
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
555 if (ifp->hwlen != 0) {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
556 struct nd_opt_hdr *opt;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
557
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
558 opt = (struct nd_opt_hdr *)(na + 1);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
559 opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
560 opt->nd_opt_len = (uint8_t)((ROUNDUP8(ifp->hwlen + 2)) >> 3);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
561 memcpy(opt + 1, ifp->hwaddr, ifp->hwlen);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
562 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
563
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
564 iaf->na_count = 0;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
565 free(iaf->na);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
566 iaf->na = na;
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
567 eloop_timeout_delete(ctx->eloop, ipv6nd_sendadvertisement, iaf);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
568 ipv6nd_sendadvertisement(iaf);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
569 }
4604
1224950f9862 BSD: Warn when kernel does not support sending ND6 advertisements
Roy Marples <roy@marples.name>
parents: 4603
diff changeset
570 #elif !defined(SMALL)
1224950f9862 BSD: Warn when kernel does not support sending ND6 advertisements
Roy Marples <roy@marples.name>
parents: 4603
diff changeset
571 #warning kernel does not support userland sending ND6 advertisements
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4564
diff changeset
572 #endif /* ND6_ADVERTISE */
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
573
4534
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
574 static void
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
575 ipv6nd_expire(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
576 {
4534
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
577 struct interface *ifp = arg;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
578 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
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 (ifp->ctx->ra_routers == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
581 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
582
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
583 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
584 if (rap->iface == ifp && rap->willexpire)
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
585 rap->doexpire = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
586 }
4534
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
587 ipv6nd_expirera(ifp);
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
588 }
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
589
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
590 void
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
591 ipv6nd_startexpire(struct interface *ifp)
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
592 {
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
593 struct ra *rap;
4534
003dc9907bba RA: expire whole RA on carrier up
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
594
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
595 if (ifp->ctx->ra_routers == NULL)
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
596 return;
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
597
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
598 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
599 if (rap->iface == ifp)
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
600 rap->willexpire = true;
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
601 }
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
602 eloop_q_timeout_add_sec(ifp->ctx->eloop, ELOOP_IPV6RA_EXPIRE,
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
603 RTR_CARRIER_EXPIRE, ipv6nd_expire, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
604 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
605
5130
d34c808ae81e Linux: Note router preference when adding routes
Roy Marples <roy@marples.name>
parents: 5109
diff changeset
606 int
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
607 ipv6nd_rtpref(struct ra *rap)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
608 {
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
609
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
610 switch (rap->flags & ND_RA_FLAG_RTPREF_MASK) {
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
611 case ND_RA_FLAG_RTPREF_HIGH:
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
612 return RTPREF_HIGH;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
613 case ND_RA_FLAG_RTPREF_MEDIUM:
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
614 case ND_RA_FLAG_RTPREF_RSV:
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
615 return RTPREF_MEDIUM;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
616 case ND_RA_FLAG_RTPREF_LOW:
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
617 return RTPREF_LOW;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
618 default:
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
619 logerrx("%s: impossible RA flag %x", __func__, rap->flags);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
620 return RTPREF_INVALID;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
621 }
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
622 /* NOTREACHED */
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
623 }
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
624
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
625 static void
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
626 ipv6nd_sortrouters(struct dhcpcd_ctx *ctx)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
627 {
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
628 struct ra_head sorted_routers = TAILQ_HEAD_INITIALIZER(sorted_routers);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
629 struct ra *ra1, *ra2;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
630
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
631 while ((ra1 = TAILQ_FIRST(ctx->ra_routers)) != NULL) {
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
632 TAILQ_REMOVE(ctx->ra_routers, ra1, next);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
633 TAILQ_FOREACH(ra2, &sorted_routers, next) {
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
634 if (ra1->iface->metric > ra2->iface->metric)
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
635 continue;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
636 if (ra1->expired && !ra2->expired)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
637 continue;
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
638 if (ra1->willexpire && !ra2->willexpire)
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
639 continue;
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
640 if (ra1->lifetime == 0 && ra2->lifetime != 0)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
641 continue;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
642 if (!ra1->isreachable && ra2->reachable)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
643 continue;
5085
c56d345a7b0d RA: Prefer older routers at the preference
Roy Marples <roy@marples.name>
parents: 5083
diff changeset
644 if (ipv6nd_rtpref(ra1) <= ipv6nd_rtpref(ra2))
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
645 continue;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
646 /* All things being equal, prefer older routers. */
4929
597274e21b1a inet6: Don't compare router dates when sorting
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
647 /* We don't need to check time, becase newer
597274e21b1a inet6: Don't compare router dates when sorting
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
648 * routers are always added to the tail and then
597274e21b1a inet6: Don't compare router dates when sorting
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
649 * sorted. */
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
650 TAILQ_INSERT_BEFORE(ra2, ra1, next);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
651 break;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
652 }
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
653 if (ra2 == NULL)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
654 TAILQ_INSERT_TAIL(&sorted_routers, ra1, next);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
655 }
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
656
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
657 TAILQ_CONCAT(ctx->ra_routers, &sorted_routers, next);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
658 }
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
659
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
660 static void
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
661 ipv6nd_applyra(struct interface *ifp)
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
662 {
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
663 struct ra *rap;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
664 struct rs_state *state = RS_STATE(ifp);
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
665 struct ra defra = {
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
666 .iface = ifp,
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
667 .hoplimit = IPV6_DEFHLIM ,
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
668 .reachable = REACHABLE_TIME,
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
669 .retrans = RETRANS_TIMER,
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
670 };
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
671
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
672 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
5181
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
673 if (rap->iface == ifp)
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
674 break;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
675 }
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
676
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
677 /* If we have no Router Advertisement, then set default values. */
5181
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
678 if (rap == NULL || rap->expired || rap->willexpire)
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
679 rap = &defra;
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
680
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
681 state->retrans = rap->retrans;
4916
7513775ead91 inet6: Adjust prior so that we don't support old kernels
Roy Marples <roy@marples.name>
parents: 4872
diff changeset
682 if (if_applyra(rap) == -1 && errno != ENOENT)
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
683 logerr(__func__);
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
684 }
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
685
4669
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
686 /*
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
687 * Neighbour reachability.
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
688 *
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
689 * RFC 4681 6.2.5 says when a node is no longer a router it MUST
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
690 * send a RA with a zero lifetime.
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
691 * All OS's I know of set the NA router flag if they are a router
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
692 * or not and disregard that they are actively advertising or
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
693 * shutting down. If the interface is disabled, it cant't send a NA at all.
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
694 *
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
695 * As such we CANNOT rely on the NA Router flag and MUST use
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
696 * unreachability or receive a RA with a lifetime of zero to remove
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
697 * the node as a default router.
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
698 */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
699 void
4669
ec9d26e0de41 inet6: Stop reacting to kernel neighbour messages about a router
Roy Marples <roy@marples.name>
parents: 4667
diff changeset
700 ipv6nd_neighbour(struct dhcpcd_ctx *ctx, struct in6_addr *addr, bool reachable)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
701 {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
702 struct ra *rap, *rapr;
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
703
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
704 if (ctx->ra_routers == NULL)
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
705 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
706
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
707 TAILQ_FOREACH(rap, ctx->ra_routers, next) {
4667
7cf17538b8b7 inet6: Stop listening to NA messages
Roy Marples <roy@marples.name>
parents: 4648
diff changeset
708 if (IN6_ARE_ADDR_EQUAL(&rap->from, addr))
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
709 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
710 }
4667
7cf17538b8b7 inet6: Stop listening to NA messages
Roy Marples <roy@marples.name>
parents: 4648
diff changeset
711
4872
8a51f7ed7061 IPv6ND: Fix reachable test
Roy Marples <roy@marples.name>
parents: 4869
diff changeset
712 if (rap == NULL || rap->expired || rap->isreachable == reachable)
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
713 return;
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
714
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
715 rap->isreachable = reachable;
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
716 loginfox("%s: %s is %s", rap->iface->name, rap->sfrom,
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
717 reachable ? "reachable again" : "unreachable");
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
718
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
719 /* See if we can install a reachable default router. */
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
720 ipv6nd_sortrouters(ctx);
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
721 ipv6nd_applyra(rap->iface);
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
722 rt_build(ctx, AF_INET6);
4667
7cf17538b8b7 inet6: Stop listening to NA messages
Roy Marples <roy@marples.name>
parents: 4648
diff changeset
723
4820
646c8e73cc8a IPv6ND: If a router is reachable again, don't solicit another.
Roy Marples <roy@marples.name>
parents: 4819
diff changeset
724 if (reachable)
646c8e73cc8a IPv6ND: If a router is reachable again, don't solicit another.
Roy Marples <roy@marples.name>
parents: 4819
diff changeset
725 return;
646c8e73cc8a IPv6ND: If a router is reachable again, don't solicit another.
Roy Marples <roy@marples.name>
parents: 4819
diff changeset
726
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
727 /* If we have no reachable default routers, try and solicit one. */
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
728 TAILQ_FOREACH(rapr, ctx->ra_routers, next) {
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
729 if (rap == rapr || rap->iface != rapr->iface)
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
730 continue;
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
731 if (rapr->isreachable && !rapr->expired && rapr->lifetime)
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
732 break;
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
733 }
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
734
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
735 if (rapr == NULL)
4647
82fa5c0d9714 inet6: Just solicit when a router is unreachable
Roy Marples <roy@marples.name>
parents: 4646
diff changeset
736 ipv6nd_startrs(rap->iface);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
737 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
738
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
739 const 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
740 ipv6nd_iffindaddr(const struct interface *ifp, const struct in6_addr *addr,
4123
441ac8d90316 Promote IPv6 dhcpcd address flags to unsignned int to allow expansion.
Roy Marples <roy@marples.name>
parents: 4116
diff changeset
741 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
742 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
743 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
744 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
745
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
746 if (ifp->ctx->ra_routers == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
747 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
748
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
749 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
750 if (rap->iface != ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
751 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
752 TAILQ_FOREACH(ap, &rap->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
753 if (ipv6_findaddrmatch(ap, addr, flags))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
754 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
755 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
756 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
757 return NULL;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
760 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
761 ipv6nd_findaddr(struct dhcpcd_ctx *ctx, const struct in6_addr *addr,
4123
441ac8d90316 Promote IPv6 dhcpcd address flags to unsignned int to allow expansion.
Roy Marples <roy@marples.name>
parents: 4116
diff changeset
762 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
763 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
764 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
765 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
766
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
767 if (ctx->ra_routers == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
768 return NULL;
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 TAILQ_FOREACH(rap, ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
771 TAILQ_FOREACH(ap, &rap->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
772 if (ipv6_findaddrmatch(ap, addr, flags))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
773 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
774 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
775 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
776 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
777 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
778
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
779 static struct ipv6_addr *
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
780 ipv6nd_rapfindprefix(struct ra *rap,
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
781 const struct in6_addr *pfx, uint8_t pfxlen)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
782 {
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
783 struct ipv6_addr *ia;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
784
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
785 TAILQ_FOREACH(ia, &rap->addrs, next) {
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
786 if (ia->prefix_vltime == 0)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
787 continue;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
788 if (ia->prefix_len == pfxlen &&
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
789 IN6_ARE_ADDR_EQUAL(&ia->prefix, pfx))
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
790 break;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
791 }
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
792 return ia;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
793 }
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
794
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
795 struct ipv6_addr *
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
796 ipv6nd_iffindprefix(struct interface *ifp,
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
797 const struct in6_addr *pfx, uint8_t pfxlen)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
798 {
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
799 struct ra *rap;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
800 struct ipv6_addr *ia;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
801
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
802 ia = NULL;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
803 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
804 if (rap->iface != ifp)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
805 continue;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
806 ia = ipv6nd_rapfindprefix(rap, pfx, pfxlen);
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
807 if (ia != NULL)
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
808 break;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
809 }
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
810 return ia;
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
811 }
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
812
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
813 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
814 ipv6nd_removefreedrop_ra(struct ra *rap, int remove_ra, int drop_ra)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
815 {
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 eloop_timeout_delete(rap->iface->ctx->eloop, NULL, rap->iface);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
818 eloop_timeout_delete(rap->iface->ctx->eloop, NULL, rap);
4141
45e849031aec Ensure that all RA's are actually dropped when dropping an interface.
Roy Marples <roy@marples.name>
parents: 4140
diff changeset
819 if (remove_ra)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
820 TAILQ_REMOVE(rap->iface->ctx->ra_routers, rap, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
821 ipv6_freedrop_addrs(&rap->addrs, drop_ra, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
822 free(rap->data);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
823 free(rap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
824 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
825
4140
57e2a4bfb9b7 ipv6nd_freedrop is no longer public.
Roy Marples <roy@marples.name>
parents: 4123
diff changeset
826 static void
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
827 ipv6nd_freedrop_ra(struct ra *rap, int drop)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
828 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
829
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
830 ipv6nd_removefreedrop_ra(rap, 1, drop);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
831 }
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 ssize_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
834 ipv6nd_free(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
835 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
836 struct rs_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
837 struct ra *rap, *ran;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
838 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
839 ssize_t n;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
840
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
841 state = RS_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
842 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
843 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
844
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
845 ctx = ifp->ctx;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
846 #ifdef __sun
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
847 eloop_event_delete(ctx->eloop, state->nd_fd);
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
848 close(state->nd_fd);
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
849 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
850 free(state->rs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
851 free(state);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
852 ifp->if_data[IF_DATA_IPV6ND] = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
853 n = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
854 TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
855 if (rap->iface == ifp) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
856 ipv6nd_free_ra(rap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
857 n++;
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
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
861 #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
862 /* If we don't have any more IPv6 enabled interfaces,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
863 * close the global socket and release resources */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
864 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
865 if (RS_STATE(ifp))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
866 break;
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 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
869 if (ctx->nd_fd != -1) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
870 eloop_event_delete(ctx->eloop, ctx->nd_fd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
871 close(ctx->nd_fd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
872 ctx->nd_fd = -1;
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 }
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
875 #endif
3932
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 return n;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
878 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
879
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4842
diff changeset
880 static void
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
881 ipv6nd_scriptrun(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
882 {
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4842
diff changeset
883 int hasdns, hasaddress;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
884 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
885
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
886 hasaddress = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
887 /* If all addresses have completed DAD run the script */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
888 TAILQ_FOREACH(ap, &rap->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
889 if ((ap->flags & (IPV6_AF_AUTOCONF | 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
890 (IPV6_AF_AUTOCONF | 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
891 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
892 hasaddress = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
893 if (!(ap->flags & IPV6_AF_DADCOMPLETED) &&
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
894 ipv6_iffindaddr(ap->iface, &ap->addr,
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
895 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
896 ap->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
897 if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
898 logdebugx("%s: waiting for Router Advertisement"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
899 " DAD to complete",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
900 rap->iface->name);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4842
diff changeset
901 return;
3932
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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
904 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
905
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
906 /* If we don't require RDNSS then set hasdns = 1 so we fork */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
907 if (!(rap->iface->options->options & DHCPCD_IPV6RA_REQRDNSS))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
908 hasdns = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
909 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
910 hasdns = rap->hasdns;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
911 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
912
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
913 script_runreason(rap->iface, "ROUTERADVERT");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
914 if (hasdns && (hasaddress ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
915 !(rap->flags & (ND_RA_FLAG_MANAGED | ND_RA_FLAG_OTHER))))
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4842
diff changeset
916 dhcpcd_daemonise(rap->iface->ctx);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
917 #if 0
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
918 else if (options & DHCPCD_DAEMONISE &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
919 !(options & DHCPCD_DAEMONISED) && new_data)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
920 logwarnx("%s: did not fork due to an absent"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
921 " RDNSS option in the RA",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
922 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
923 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
924 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
925
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
926 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
927 ipv6nd_addaddr(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
928 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
929 struct ipv6_addr *ap = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
930
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
931 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
932 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
933
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
934 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
935 ipv6nd_dadcompleted(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
936 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
937 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
938 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
939
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
940 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
941 if (rap->iface != ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
942 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
943 TAILQ_FOREACH(ap, &rap->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
944 if (ap->flags & 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
945 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
946 !(ap->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
947 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
948 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
949 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
950 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
951 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
952
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
953 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
954 ipv6nd_dadcallback(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
955 {
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
956 struct ipv6_addr *ia = arg, *rapap;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
957 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
958 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
959 int wascompleted, found;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
960 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
961 const char *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
962 int dadcounter;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
963
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
964 ifp = ia->iface;
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
965 wascompleted = (ia->flags & IPV6_AF_DADCOMPLETED);
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
966 ia->flags |= IPV6_AF_DADCOMPLETED;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
967 if (ia->addr_flags & IN6_IFF_DUPLICATED) {
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
968 ia->dadcounter++;
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
969 logwarnx("%s: DAD detected %s", ifp->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
970
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
971 /* Try and make another stable private address.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
972 * Because ap->dadcounter is always increamented,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
973 * a different address is generated. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
974 /* XXX Cache DAD counter per prefix/id/ssid? */
4982
661857d82a40 inet6: Check if we can try a new address on DAD failure.
Roy Marples <roy@marples.name>
parents: 4981
diff changeset
975 if (ifp->options->options & DHCPCD_SLAACPRIVATE &&
661857d82a40 inet6: Check if we can try a new address on DAD failure.
Roy Marples <roy@marples.name>
parents: 4981
diff changeset
976 IA6_CANAUTOCONF(ia))
661857d82a40 inet6: Check if we can try a new address on DAD failure.
Roy Marples <roy@marples.name>
parents: 4981
diff changeset
977 {
4934
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
978 unsigned int delay;
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
979
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
980 if (ia->dadcounter >= IDGEN_RETRIES) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
981 logerrx("%s: unable to obtain a"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
982 " stable private address",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
983 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
984 goto try_script;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
985 }
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
986 loginfox("%s: deleting address %s",
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
987 ifp->name, ia->saddr);
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
988 if (if_address6(RTM_DELADDR, ia) == -1 &&
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
989 errno != EADDRNOTAVAIL && errno != ENXIO)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
990 logerr(__func__);
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
991 dadcounter = ia->dadcounter;
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
992 if (ipv6_makestableprivate(&ia->addr,
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
993 &ia->prefix, ia->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
994 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
995 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
996 logerr("ipv6_makestableprivate");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
997 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
998 }
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
999 ia->dadcounter = dadcounter;
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1000 ia->flags &= ~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1001 ia->flags |= IPV6_AF_NEW;
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1002 p = inet_ntop(AF_INET6, &ia->addr, buf, sizeof(buf));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1003 if (p)
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1004 snprintf(ia->saddr,
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1005 sizeof(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
1006 "%s/%d",
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1007 p, ia->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
1008 else
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1009 ia->saddr[0] = '\0';
4934
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
1010 delay = arc4random_uniform(IDGEN_DELAY * MSEC_PER_SEC);
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
1011 eloop_timeout_add_msec(ifp->ctx->eloop, delay,
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1012 ipv6nd_addaddr, ia);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1013 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1014 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1015 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1016
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1017 try_script:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1018 if (!wascompleted) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1019 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1020 if (rap->iface != ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1021 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1022 wascompleted = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1023 found = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1024 TAILQ_FOREACH(rapap, &rap->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1025 if (rapap->flags & 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
1026 rapap->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
1027 (rapap->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
1028 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1029 wascompleted = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1030 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1031 }
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4115
diff changeset
1032 if (rapap == ia)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1033 found = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1034 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1035
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1036 if (wascompleted && found) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1037 logdebugx("%s: Router Advertisement DAD "
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1038 "completed",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1039 rap->iface->name);
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4842
diff changeset
1040 ipv6nd_scriptrun(rap);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1041 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1042 }
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4564
diff changeset
1043 #ifdef ND6_ADVERTISE
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
1044 ipv6nd_advertise(ia);
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4564
diff changeset
1045 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1046 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1047 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1048
5107
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1049 static struct ipv6_addr *
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1050 ipv6nd_findmarkstale(struct ra *rap, struct ipv6_addr *ia, bool mark)
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1051 {
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1052 struct dhcpcd_ctx *ctx = ia->iface->ctx;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1053 struct ra *rap2;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1054 struct ipv6_addr *ia2;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1055
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1056 TAILQ_FOREACH(rap2, ctx->ra_routers, next) {
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1057 if (rap2 == rap ||
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1058 rap2->iface != rap->iface ||
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1059 rap2->expired)
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1060 continue;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1061 TAILQ_FOREACH(ia2, &rap2->addrs, next) {
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1062 if (!IN6_ARE_ADDR_EQUAL(&ia->prefix, &ia2->prefix))
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1063 continue;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1064 if (!(ia2->flags & IPV6_AF_STALE))
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1065 return ia2;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1066 if (mark)
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1067 ia2->prefix_pltime = 0;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1068 }
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1069 }
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1070 return NULL;
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1071 }
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1072
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1073 #ifndef DHCP6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1074 /* If DHCPv6 is compiled out, supply a shim to provide an error message
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1075 * if IPv6RA requests DHCPv6. */
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1076 enum DH6S {
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1077 DH6S_REQUEST,
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1078 DH6S_INFORM,
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1079 };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1080 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1081 dhcp6_start(__unused struct interface *ifp, __unused enum DH6S init_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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1084 errno = ENOTSUP;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1085 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1086 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1087 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1088
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1089 static void
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1090 ipv6nd_handlera(struct dhcpcd_ctx *ctx,
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1091 const struct sockaddr_in6 *from, const char *sfrom,
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1092 struct interface *ifp, struct icmp6_hdr *icp, size_t len, int hoplimit)
3932
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 size_t i, olen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1095 struct nd_router_advert *nd_ra;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1096 struct nd_opt_hdr ndo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1097 struct nd_opt_prefix_info pi;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1098 struct nd_opt_mtu mtu;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1099 struct nd_opt_rdnss rdnss;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1100 uint8_t *p;
5107
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1101 struct ra *rap;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1102 struct in6_addr pi_prefix;
5107
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1103 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
1104 struct dhcp_opt *dho;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1105 bool new_rap, new_data, has_address;
4268
bd01addbb40f ipv6nd: warn if router lifetime is set to zero
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
1106 uint32_t old_lifetime;
4819
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1107 int ifmtu;
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1108 int loglevel;
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1109 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
1110 #ifdef IPV6_MANAGETEMPADDR
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1111 bool new_ia;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1112 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1113
5322
3dd079b1d37b RA: Abort if no state
Roy Marples <roy@marples.name>
parents: 5278
diff changeset
1114 if (ifp == NULL || RS_STATE(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
1115 #ifdef DEBUG_RS
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1116 logdebugx("RA for unexpected interface from %s", sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1117 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1118 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1119 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1120
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1121 if (len < sizeof(struct nd_router_advert)) {
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1122 logerrx("IPv6 RA packet too short from %s", sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1123 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1124 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1125
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1126 /* RFC 4861 7.1.2 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1127 if (hoplimit != 255) {
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1128 logerrx("invalid hoplimit(%d) in RA from %s", hoplimit, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1129 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1130 }
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1131 if (!IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1132 logerrx("RA from non local address %s", sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1133 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1134 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1135
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1136 if (!(ifp->options->options & DHCPCD_IPV6RS)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1137 #ifdef DEBUG_RS
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1138 logerrx("%s: unexpected RA from %s", ifp->name, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1139 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1140 return;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1143 /* We could receive a RA before we sent a RS*/
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1144 if (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
1145 #ifdef DEBUG_RS
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1146 logdebugx("%s: received RA from %s (no link-local)",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1147 ifp->name, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1148 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1149 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1150 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1151
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1152 if (ipv6_iffindaddr(ifp, &from->sin6_addr, IN6_IFF_TENTATIVE)) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1153 logdebugx("%s: ignoring RA from ourself %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1154 ifp->name, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1155 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1156 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1157
5181
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1158 /*
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1159 * Because we preserve RA's and expire them quickly after
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1160 * carrier up, it's important to reset the kernels notion of
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1161 * reachable timers back to default values before applying
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1162 * new RA values.
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1163 */
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1164 TAILQ_FOREACH(rap, ctx->ra_routers, next) {
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1165 if (ifp == rap->iface)
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1166 break;
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1167 }
5346
3ceefc13699e minor cleanup
Roy Marples <roy@marples.name>
parents: 5322
diff changeset
1168 if (rap != NULL && rap->willexpire)
5181
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1169 ipv6nd_applyra(ifp);
6788ac9191a7 inet6: Set default ND timers before a RA arrives after preservation
Roy Marples <roy@marples.name>
parents: 5180
diff changeset
1170
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1171 TAILQ_FOREACH(rap, ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1172 if (ifp == rap->iface &&
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1173 IN6_ARE_ADDR_EQUAL(&rap->from, &from->sin6_addr))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1174 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1175 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1176
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1177 nd_ra = (struct nd_router_advert *)icp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1178
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1179 /* We don't want to spam the log with the fact we got an RA every
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1180 * 30 seconds or so, so only spam the log if it's different. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1181 if (rap == NULL || (rap->data_len != len ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1182 memcmp(rap->data, (unsigned char *)icp, rap->data_len) != 0))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1183 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1184 if (rap) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1185 free(rap->data);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1186 rap->data_len = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1187 }
4269
3050be161143 ipv6nd: use bools here
Roy Marples <roy@marples.name>
parents: 4268
diff changeset
1188 new_data = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1189 } else
4269
3050be161143 ipv6nd: use bools here
Roy Marples <roy@marples.name>
parents: 4268
diff changeset
1190 new_data = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1191 if (rap == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1192 rap = calloc(1, sizeof(*rap));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1193 if (rap == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1194 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
1195 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1196 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1197 rap->iface = ifp;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1198 rap->from = from->sin6_addr;
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1199 strlcpy(rap->sfrom, sfrom, sizeof(rap->sfrom));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1200 TAILQ_INIT(&rap->addrs);
4269
3050be161143 ipv6nd: use bools here
Roy Marples <roy@marples.name>
parents: 4268
diff changeset
1201 new_rap = true;
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1202 rap->isreachable = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1203 } else
4269
3050be161143 ipv6nd: use bools here
Roy Marples <roy@marples.name>
parents: 4268
diff changeset
1204 new_rap = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1205 if (rap->data_len == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1206 rap->data = malloc(len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1207 if (rap->data == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1208 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
1209 if (new_rap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1210 free(rap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1211 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1212 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1213 memcpy(rap->data, icp, len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1214 rap->data_len = len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1215 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1216
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1217 /* We could change the debug level based on new_data, but some
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1218 * routers like to decrease the advertised valid and preferred times
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1219 * in accordance with the own prefix times which would result in too
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1220 * much needless log spam. */
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5040
diff changeset
1221 if (rap->willexpire)
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5040
diff changeset
1222 new_data = true;
5150
85569e7510f2 inet6: Only log RA's when they are from a new server
Roy Marples <roy@marples.name>
parents: 5130
diff changeset
1223 loglevel = new_rap || rap->willexpire || !rap->isreachable ?
5484
e01d8ea25a42 Clean up some warnings.
Sascha Wildner <saw@online.de>
parents: 5413
diff changeset
1224 LOG_INFO : LOG_DEBUG;
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1225 logmessage(loglevel, "%s: Router Advertisement from %s",
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1226 ifp->name, rap->sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1227
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1228 clock_gettime(CLOCK_MONOTONIC, &rap->acquired);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1229 rap->flags = nd_ra->nd_ra_flags_reserved;
4268
bd01addbb40f ipv6nd: warn if router lifetime is set to zero
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
1230 old_lifetime = rap->lifetime;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1231 rap->lifetime = ntohs(nd_ra->nd_ra_router_lifetime);
4268
bd01addbb40f ipv6nd: warn if router lifetime is set to zero
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
1232 if (!new_rap && rap->lifetime == 0 && old_lifetime != 0)
bd01addbb40f ipv6nd: warn if router lifetime is set to zero
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
1233 logwarnx("%s: %s: no longer a default router",
bd01addbb40f ipv6nd: warn if router lifetime is set to zero
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
1234 ifp->name, rap->sfrom);
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1235 if (nd_ra->nd_ra_curhoplimit != 0)
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1236 rap->hoplimit = nd_ra->nd_ra_curhoplimit;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1237 else
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1238 rap->hoplimit = IPV6_DEFHLIM;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1239 if (nd_ra->nd_ra_reachable != 0) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1240 rap->reachable = ntohl(nd_ra->nd_ra_reachable);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1241 if (rap->reachable > MAX_REACHABLE_TIME)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1242 rap->reachable = 0;
4813
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1243 } else
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1244 rap->reachable = REACHABLE_TIME;
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1245 if (nd_ra->nd_ra_retransmit != 0)
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1246 rap->retrans = ntohl(nd_ra->nd_ra_retransmit);
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1247 else
ef33eb73e97d INET6: Apply hoplimit, reachable and retrans timer values from RA.
Roy Marples <roy@marples.name>
parents: 4812
diff changeset
1248 rap->retrans = RETRANS_TIMER;
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1249 rap->expired = rap->willexpire = rap->doexpire = false;
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1250 rap->hasdns = false;
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1251 rap->isreachable = true;
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1252 has_address = false;
4822
8ea5c8980467 RA: Set mtu to zero and then pull in the MTU option if any
Roy Marples <roy@marples.name>
parents: 4820
diff changeset
1253 rap->mtu = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1254
4237
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
1255 #ifdef IPV6_AF_TEMPORARY
4235
27bad70c0d9c link: detect buffer overflow / desync and relearn interface state
Roy Marples <roy@marples.name>
parents: 4234
diff changeset
1256 ipv6_markaddrsstale(ifp, IPV6_AF_TEMPORARY);
4237
db600851438a Fix compile on OpenBSD.
Roy Marples <roy@marples.name>
parents: 4235
diff changeset
1257 #endif
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1258 TAILQ_FOREACH(ia, &rap->addrs, next) {
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1259 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
1260 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1261
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1262 len -= sizeof(struct nd_router_advert);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1263 p = ((uint8_t *)icp) + sizeof(struct nd_router_advert);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1264 for (; len > 0; p += olen, len -= olen) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1265 if (len < sizeof(ndo)) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1266 logerrx("%s: short option", 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
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 memcpy(&ndo, p, sizeof(ndo));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1270 olen = (size_t)ndo.nd_opt_len * 8;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1271 if (olen == 0) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1272 logerrx("%s: zero length option", 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
1273 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1274 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1275 if (olen > len) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1276 logerrx("%s: option length exceeds message",
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1277 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
1278 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1279 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1280
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1281 if (has_option_mask(ifp->options->rejectmasknd,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1282 ndo.nd_opt_type))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1283 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1284 for (i = 0, dho = ctx->nd_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1285 i < ctx->nd_opts_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1286 i++, dho++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1287 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1288 if (dho->option == ndo.nd_opt_type)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1289 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1290 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1291 if (dho != NULL)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1292 logwarnx("%s: reject RA (option %s) from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1293 ifp->name, dho->var, rap->sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1294 else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1295 logwarnx("%s: reject RA (option %d) from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1296 ifp->name, ndo.nd_opt_type, rap->sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1297 if (new_rap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1298 ipv6nd_removefreedrop_ra(rap, 0, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1299 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1300 ipv6nd_free_ra(rap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1301 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1302 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1303
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1304 if (has_option_mask(ifp->options->nomasknd, ndo.nd_opt_type))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1305 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1306
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1307 switch (ndo.nd_opt_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1308 case ND_OPT_PREFIX_INFORMATION:
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1309 loglevel = new_data ? LOG_ERR : LOG_DEBUG;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1310 if (ndo.nd_opt_len != 4) {
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1311 logmessage(loglevel,
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1312 "%s: invalid option len for prefix",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1313 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1314 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1315 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1316 memcpy(&pi, p, sizeof(pi));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1317 if (pi.nd_opt_pi_prefix_len > 128) {
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1318 logmessage(loglevel, "%s: invalid prefix len",
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1319 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
1320 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1321 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1322 /* nd_opt_pi_prefix is not aligned. */
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1323 memcpy(&pi_prefix, &pi.nd_opt_pi_prefix,
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
1324 sizeof(pi_prefix));
3932
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_IS_ADDR_MULTICAST(&pi_prefix) ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 IN6_IS_ADDR_LINKLOCAL(&pi_prefix))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1327 {
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1328 logmessage(loglevel, "%s: invalid prefix in RA",
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1329 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
1330 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1331 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1332 if (ntohl(pi.nd_opt_pi_preferred_time) >
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1333 ntohl(pi.nd_opt_pi_valid_time))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1334 {
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1335 logmessage(loglevel, "%s: pltime > vltime",
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1336 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
1337 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1338 }
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1339
5372
a64688cee252 inet6: No flags on the prefix means the prefix is via the router
Roy Marples <roy@marples.name>
parents: 5363
diff changeset
1340 flags = IPV6_AF_RAPFX;
a64688cee252 inet6: No flags on the prefix means the prefix is via the router
Roy Marples <roy@marples.name>
parents: 5363
diff changeset
1341 /* If no flags are set, that means the prefix is
a64688cee252 inet6: No flags on the prefix means the prefix is via the router
Roy Marples <roy@marples.name>
parents: 5363
diff changeset
1342 * available via the router. */
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1343 if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ONLINK)
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1344 flags |= IPV6_AF_ONLINK;
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1345 if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_AUTO &&
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1346 rap->iface->options->options &
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1347 DHCPCD_IPV6RA_AUTOCONF)
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1348 flags |= IPV6_AF_AUTOCONF;
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1349 if (pi.nd_opt_pi_flags_reserved & ND_OPT_PI_FLAG_ROUTER)
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1350 flags |= IPV6_AF_ROUTER;
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1351
5105
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
1352 ia = ipv6nd_rapfindprefix(rap,
88e25390d763 ND: If a secondary router adds the same prefix, use it's address
Roy Marples <roy@marples.name>
parents: 5104
diff changeset
1353 &pi_prefix, pi.nd_opt_pi_prefix_len);
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1354 if (ia == NULL) {
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1355 ia = ipv6_newaddr(rap->iface,
5372
a64688cee252 inet6: No flags on the prefix means the prefix is via the router
Roy Marples <roy@marples.name>
parents: 5363
diff changeset
1356 &pi_prefix, pi.nd_opt_pi_prefix_len, flags);
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1357 if (ia == NULL)
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4076
diff changeset
1358 break;
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1359 ia->prefix = pi_prefix;
4336
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
1360 if (flags & IPV6_AF_AUTOCONF)
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1361 ia->dadcallback = ipv6nd_dadcallback;
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1362 ia->created = ia->acquired = rap->acquired;
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1363 TAILQ_INSERT_TAIL(&rap->addrs, ia, next);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1364
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1365 #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
1366 /* New address to dhcpcd RA handling.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1367 * If the address already exists and a valid
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1368 * temporary address also exists then
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1369 * extend the existing one rather than
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1370 * create a new one */
4336
881356480905 ip6: Install not on link routes with a gateway of the router
Roy Marples <roy@marples.name>
parents: 4335
diff changeset
1371 if (flags & IPV6_AF_AUTOCONF &&
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1372 ipv6_iffindaddr(ifp, &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
1373 IN6_IFF_NOTUSEABLE) &&
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1374 ipv6_settemptime(ia, 0))
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1375 new_ia = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1376 else
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1377 new_ia = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1378 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1379 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1380 #ifdef IPV6_MANAGETEMPADDR
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1381 new_ia = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1382 #endif
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1383 ia->flags |= flags;
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1384 ia->flags &= ~IPV6_AF_STALE;
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1385 ia->acquired = rap->acquired;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1386 }
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1387 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
1388 ntohl(pi.nd_opt_pi_valid_time);
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1389 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
1390 ntohl(pi.nd_opt_pi_preferred_time);
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1391 if (ia->prefix_vltime != 0 &&
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1392 ia->flags & IPV6_AF_AUTOCONF)
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1393 has_address = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1394
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1395 #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
1396 /* RFC4941 Section 3.3.3 */
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1397 if (ia->flags & IPV6_AF_AUTOCONF &&
5153
8248b3a04908 inet6: Add 'temporary' directive to the slaac option
Roy Marples <roy@marples.name>
parents: 5150
diff changeset
1398 ia->iface->options->options & DHCPCD_SLAACTEMP &&
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1399 IA6_CANAUTOCONF(ia))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1400 {
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1401 if (!new_ia) {
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1402 if (ipv6_settemptime(ia, 1) == NULL)
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1403 new_ia = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1404 }
5082
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1405 if (new_ia && ia->prefix_pltime) {
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1406 if (ipv6_createtempaddr(ia,
5f7d664db35c IPv6ND: ap -> ia rototill
Roy Marples <roy@marples.name>
parents: 5065
diff changeset
1407 &ia->acquired) == NULL)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1408 logerr("ipv6_createtempaddr");
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1409 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1410 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1411 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1412 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1413
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1414 case ND_OPT_MTU:
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1415 if (len < sizeof(mtu)) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1416 logmessage(loglevel, "%s: short MTU option", ifp->name);
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1417 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1418 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1419 memcpy(&mtu, p, sizeof(mtu));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1420 mtu.nd_opt_mtu_mtu = ntohl(mtu.nd_opt_mtu_mtu);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1421 if (mtu.nd_opt_mtu_mtu < IPV6_MMTU) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1422 logmessage(loglevel, "%s: invalid MTU %d",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1423 ifp->name, mtu.nd_opt_mtu_mtu);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1424 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1425 }
4819
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1426 ifmtu = if_getmtu(ifp);
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1427 if (ifmtu == -1)
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1428 logerr("if_getmtu");
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1429 else if (mtu.nd_opt_mtu_mtu > (uint32_t)ifmtu) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1430 logmessage(loglevel, "%s: advertised MTU %d"
4819
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1431 " is greater than link MTU %d",
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1432 ifp->name, mtu.nd_opt_mtu_mtu, ifmtu);
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1433 rap->mtu = (uint32_t)ifmtu;
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1434 } else
20f0d2d242a1 RA: Warn if advertised MTU is greater than link MTU
Roy Marples <roy@marples.name>
parents: 4813
diff changeset
1435 rap->mtu = mtu.nd_opt_mtu_mtu;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1436 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1437 case ND_OPT_RDNSS:
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1438 if (len < sizeof(rdnss)) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5044
diff changeset
1439 logmessage(loglevel, "%s: short RDNSS option", ifp->name);
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1440 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1441 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1442 memcpy(&rdnss, p, sizeof(rdnss));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1443 if (rdnss.nd_opt_rdnss_lifetime &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1444 rdnss.nd_opt_rdnss_len > 1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1445 rap->hasdns = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1446 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1447 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1448 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1449 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1450 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1451
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1452 for (i = 0, dho = ctx->nd_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1453 i < ctx->nd_opts_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1454 i++, dho++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1455 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1456 if (has_option_mask(ifp->options->requiremasknd,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1457 dho->option))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1458 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1459 logwarnx("%s: reject RA (no option %s) from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1460 ifp->name, dho->var, rap->sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1461 if (new_rap)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1462 ipv6nd_removefreedrop_ra(rap, 0, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1463 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1464 ipv6nd_free_ra(rap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1465 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1466 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1467 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1468
5083
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1469 TAILQ_FOREACH(ia, &rap->addrs, next) {
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1470 if (!(ia->flags & IPV6_AF_STALE) || ia->prefix_pltime == 0)
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1471 continue;
5107
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1472 if (ipv6nd_findmarkstale(rap, ia, false) != NULL)
5104
2804763cefbd ND: Only deprecate prefixes when all stale
Roy Marples <roy@marples.name>
parents: 5096
diff changeset
1473 continue;
5107
a3da4f12835f ND: Improve stale detection for >1 router
Roy Marples <roy@marples.name>
parents: 5106
diff changeset
1474 ipv6nd_findmarkstale(rap, ia, true);
5083
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1475 logdebugx("%s: %s: became stale", ifp->name, ia->saddr);
5109
a7b7abb6211c Note that setting pltime to zero for stale addresses isn't RFC compliant
Roy Marples <roy@marples.name>
parents: 5107
diff changeset
1476 /* Technically this violates RFC 4861 6.3.4,
a7b7abb6211c Note that setting pltime to zero for stale addresses isn't RFC compliant
Roy Marples <roy@marples.name>
parents: 5107
diff changeset
1477 * but we need a mechanism to tell the kernel to
a7b7abb6211c Note that setting pltime to zero for stale addresses isn't RFC compliant
Roy Marples <roy@marples.name>
parents: 5107
diff changeset
1478 * try and prefer other addresses. */
5083
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1479 ia->prefix_pltime = 0;
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1480 }
705e8e8d8f60 IPv6ND: Mark stale addresses/prefixes with a pltime of zero.
Roy Marples <roy@marples.name>
parents: 5082
diff changeset
1481
4702
b2b39cc615ad inet6: Fix default route not being installed
Roy Marples <roy@marples.name>
parents: 4686
diff changeset
1482 if (new_data && !has_address && rap->lifetime && !ipv6_anyglobal(ifp))
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1483 logwarnx("%s: no global addresses for default route",
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1484 ifp->name);
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1485
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1486 if (new_rap)
4812
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
1487 TAILQ_INSERT_TAIL(ctx->ra_routers, rap, next);
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
1488 if (new_data)
2d85b6abdb3b INET6: Sort routers when reachability changes
Roy Marples <roy@marples.name>
parents: 4789
diff changeset
1489 ipv6nd_sortrouters(ifp->ctx);
3932
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 if (ifp->ctx->options & DHCPCD_TEST) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1492 script_runreason(ifp, "TEST");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1493 goto handle_flag;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1494 }
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1495
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1496 if (!(ifp->options->options & DHCPCD_CONFIGURE))
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1497 goto run;
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1498
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
1499 ipv6nd_applyra(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1500 ipv6_addaddrs(&rap->addrs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1501 #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
1502 ipv6_addtempaddrs(ifp, &rap->acquired);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1503 #endif
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1504 rt_build(ifp->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
1505
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
1506 run:
4856
a0a073f9c5ef dhcpcd: Rework daemonisation
Roy Marples <roy@marples.name>
parents: 4842
diff changeset
1507 ipv6nd_scriptrun(rap);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1508
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1509 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
1510 eloop_timeout_delete(ifp->ctx->eloop, NULL, rap); /* reachable timer */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1511
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1512 handle_flag:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1513 if (!(ifp->options->options & DHCPCD_DHCP6))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1514 goto nodhcp6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1515 /* Only log a DHCPv6 start error if compiled in or debugging is enabled. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1516 #ifdef DHCP6
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1517 #define LOG_DHCP6 logerr
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1518 #else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1519 #define LOG_DHCP6 logdebug
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1520 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1521 if (rap->flags & ND_RA_FLAG_MANAGED) {
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4182
diff changeset
1522 if (new_data && dhcp6_start(ifp, DH6S_REQUEST) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1523 LOG_DHCP6("dhcp6_start: %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
1524 } else if (rap->flags & ND_RA_FLAG_OTHER) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1525 if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1526 LOG_DHCP6("dhcp6_start: %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
1527 } else {
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1528 #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
1529 if (new_data)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
1530 logdebugx("%s: No DHCPv6 instruction in RA", ifp->name);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1531 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1532 nodhcp6:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1533 if (ifp->ctx->options & DHCPCD_TEST) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1534 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1535 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1536 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1537 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1538
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1539 /* Expire should be called last as the rap object could be destroyed */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1540 ipv6nd_expirera(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1541 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1542
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1543 bool
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1544 ipv6nd_hasralifetime(const struct interface *ifp, bool lifetime)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1545 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1546 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
1547
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1548 if (ifp->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
1549 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next)
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1550 if (rap->iface == ifp &&
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1551 !rap->expired &&
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1552 (!lifetime ||rap->lifetime))
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1553 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
1554 }
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1555 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
1556 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1557
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1558 bool
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1559 ipv6nd_hasradhcp(const struct interface *ifp, bool managed)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1560 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1561 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
1562
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1563 if (ifp->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
1564 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1565 if (rap->iface == ifp &&
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1566 !rap->expired && !rap->willexpire &&
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1567 ((managed && rap->flags & ND_RA_FLAG_MANAGED) ||
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1568 (!managed && rap->flags & ND_RA_FLAG_OTHER)))
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1569 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
1570 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1571 }
4648
16b119f7fc39 inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents: 4647
diff changeset
1572 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
1573 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1574
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1575 static const uint8_t *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1576 ipv6nd_getoption(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
1577 size_t *os, unsigned int *code, 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
1578 const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1579 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1580 struct nd_opt_hdr ndo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1581 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
1582 struct dhcp_opt *opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1583
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1584 if (od) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1585 *os = sizeof(ndo);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1586 if (ol < *os) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1587 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1588 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1589 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1590 memcpy(&ndo, od, sizeof(ndo));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1591 i = (size_t)(ndo.nd_opt_len * 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1592 if (i > ol) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1593 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1594 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1595 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1596 *len = i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1597 *code = ndo.nd_opt_type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1598 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1599
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1600 for (i = 0, opt = ctx->nd_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1601 i < ctx->nd_opts_len; i++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1602 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1603 if (opt->option == *code) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1604 *oopt = opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1605 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1606 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1607 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1608
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1609 if (od)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1610 return od + sizeof(ndo);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1611 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1612 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1613
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1614 ssize_t
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1615 ipv6nd_env(FILE *fp, 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
1616 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1617 size_t i, j, n, len, olen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1618 struct ra *rap;
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1619 char ndprefix[32];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1620 struct dhcp_opt *opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1621 uint8_t *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1622 struct nd_opt_hdr ndo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1623 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
1624 struct timespec now;
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1625 int pref;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1626
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1627 clock_gettime(CLOCK_MONOTONIC, &now);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1628 i = n = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1629 TAILQ_FOREACH(rap, ifp->ctx->ra_routers, next) {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1630 if (rap->iface != ifp || 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
1631 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1632 i++;
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1633 snprintf(ndprefix, sizeof(ndprefix), "nd%zu", i);
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1634 if (efprintf(fp, "%s_from=%s", ndprefix, rap->sfrom) == -1)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1635 return -1;
4564
622983991bf6 Cast time_t to long long to satisfy printf.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1636 if (efprintf(fp, "%s_acquired=%lld", ndprefix,
622983991bf6 Cast time_t to long long to satisfy printf.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1637 (long long)rap->acquired.tv_sec) == -1)
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1638 return -1;
4564
622983991bf6 Cast time_t to long long to satisfy printf.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1639 if (efprintf(fp, "%s_now=%lld", ndprefix,
622983991bf6 Cast time_t to long long to satisfy printf.
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
1640 (long long)now.tv_sec) == -1)
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1641 return -1;
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1642 if (efprintf(fp, "%s_hoplimit=%u", ndprefix, rap->hoplimit) == -1)
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1643 return -1;
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1644 pref = ipv6nd_rtpref(rap);
5363
e161ef164608 inet6: Report RA Proxy flag if set
Roy Marples <roy@marples.name>
parents: 5362
diff changeset
1645 if (efprintf(fp, "%s_flags=%s%s%s%s%s", ndprefix,
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1646 rap->flags & ND_RA_FLAG_MANAGED ? "M" : "",
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1647 rap->flags & ND_RA_FLAG_OTHER ? "O" : "",
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1648 rap->flags & ND_RA_FLAG_HOME_AGENT ? "H" : "",
5363
e161ef164608 inet6: Report RA Proxy flag if set
Roy Marples <roy@marples.name>
parents: 5362
diff changeset
1649 pref == RTPREF_HIGH ? "h" : pref == RTPREF_LOW ? "l" : "",
e161ef164608 inet6: Report RA Proxy flag if set
Roy Marples <roy@marples.name>
parents: 5362
diff changeset
1650 rap->flags & ND_RA_FLAG_PROXY ? "P" : "") == -1)
5362
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1651 return -1;
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1652 if (efprintf(fp, "%s_lifetime=%u", ndprefix, rap->lifetime) == -1)
17f0de2ed2aa inet6: Add support for reporting Mobile IPv6 RA's
Roy Marples <roy@marples.name>
parents: 5346
diff changeset
1653 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
1654
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1655 /* Zero our indexes */
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1656 for (j = 0, opt = rap->iface->ctx->nd_opts;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1657 j < rap->iface->ctx->nd_opts_len;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1658 j++, opt++)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1659 dhcp_zero_index(opt);
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1660 for (j = 0, opt = rap->iface->options->nd_override;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1661 j < rap->iface->options->nd_override_len;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1662 j++, opt++)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1663 dhcp_zero_index(opt);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1664
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1665 /* Unlike DHCP, ND6 options *may* occur more than once.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1666 * There is also no provision for option concatenation
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1667 * unlike DHCP. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1668 len = rap->data_len - sizeof(struct nd_router_advert);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1669 for (p = rap->data + sizeof(struct nd_router_advert);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1670 len >= sizeof(ndo);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1671 p += olen, len -= olen)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1672 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1673 memcpy(&ndo, p, sizeof(ndo));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1674 olen = (size_t)(ndo.nd_opt_len * 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1675 if (olen > len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1676 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1677 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1678 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1679 if (has_option_mask(rap->iface->options->nomasknd,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1680 ndo.nd_opt_type))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1681 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1682 for (j = 0, opt = rap->iface->options->nd_override;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1683 j < rap->iface->options->nd_override_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1684 j++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1685 if (opt->option == ndo.nd_opt_type)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1686 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1687 if (j == rap->iface->options->nd_override_len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1688 for (j = 0, opt = rap->iface->ctx->nd_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1689 j < rap->iface->ctx->nd_opts_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1690 j++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1691 if (opt->option == ndo.nd_opt_type)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1692 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1693 if (j == rap->iface->ctx->nd_opts_len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1694 opt = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1695 }
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1696 if (opt == NULL)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1697 continue;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1698 dhcp_envoption(rap->iface->ctx, fp,
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1699 ndprefix, rap->iface->name,
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1700 opt, ipv6nd_getoption,
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1701 p + sizeof(ndo), olen - sizeof(ndo));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1702 }
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 /* We need to output the addresses we actually made
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1705 * from the prefix information options as well. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1706 j = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1707 TAILQ_FOREACH(ia, &rap->addrs, next) {
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1708 if (!(ia->flags & IPV6_AF_AUTOCONF) ||
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1709 #ifdef IPV6_AF_TEMPORARY
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1710 ia->flags & IPV6_AF_TEMPORARY ||
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1711 #endif
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1712 !(ia->flags & IPV6_AF_ADDED) ||
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1713 ia->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
1714 continue;
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1715 if (efprintf(fp, "%s_addr%zu=%s",
5096
d6af8586cbaf script: Start RA addresses from 1, not 0.
Roy Marples <roy@marples.name>
parents: 5085
diff changeset
1716 ndprefix, ++j, ia->saddr) == -1)
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1717 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
1718 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1719 }
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4534
diff changeset
1720 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
1721 }
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 void
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4231
diff changeset
1724 ipv6nd_handleifa(int cmd, 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
1725 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1726 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
1727
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1728 /* IPv6 init may not have happened yet if we are learning
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1729 * existing addresses when dhcpcd starts. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1730 if (addr->iface->ctx->ra_routers == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1731 return;
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 TAILQ_FOREACH(rap, addr->iface->ctx->ra_routers, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1734 if (rap->iface != addr->iface)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1735 continue;
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4231
diff changeset
1736 ipv6_handleifa_addrs(cmd, &rap->addrs, addr, pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1737 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1738 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1739
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1740 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1741 ipv6nd_expirera(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1742 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1743 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
1744 struct ra *rap, *ran;
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1745 struct timespec now;
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1746 uint32_t elapsed;
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1747 bool expired, valid;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1748 struct ipv6_addr *ia;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1749 size_t len, olen;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1750 uint8_t *p;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1751 struct nd_opt_hdr ndo;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1752 #if 0
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1753 struct nd_opt_prefix_info pi;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1754 #endif
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1755 struct nd_opt_dnssl dnssl;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1756 struct nd_opt_rdnss rdnss;
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1757 unsigned int next = 0, ltime;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1758 size_t nexpired = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1759
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1760 ifp = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1761 clock_gettime(CLOCK_MONOTONIC, &now);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1762 expired = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1763
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1764 TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1765 if (rap->iface != ifp || 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
1766 continue;
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1767 valid = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1768 if (rap->lifetime) {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1769 elapsed = (uint32_t)eloop_timespec_diff(&now,
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1770 &rap->acquired, NULL);
5180
0e4f56cb4c03 inet6: Expire ND on the second, not after it
Roy Marples <roy@marples.name>
parents: 5179
diff changeset
1771 if (elapsed >= rap->lifetime || rap->doexpire) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1772 if (!rap->expired) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1773 logwarnx("%s: %s: router expired",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1774 ifp->name, rap->sfrom);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1775 rap->lifetime = 0;
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1776 expired = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1777 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1778 } else {
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1779 valid = true;
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1780 ltime = rap->lifetime - elapsed;
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1781 if (next == 0 || ltime < next)
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1782 next = ltime;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1783 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1784 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1785
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1786 /* Not every prefix is tied to an address which
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1787 * the kernel can expire, so we need to handle it ourself.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1788 * Also, some OS don't support address lifetimes (Solaris). */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1789 TAILQ_FOREACH(ia, &rap->addrs, next) {
4231
0dcc72ad719c ipv6nd: drop DHCPv6 when RA fully expires
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1790 if (ia->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
1791 continue;
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1792 if (ia->prefix_vltime == ND6_INFINITE_LIFETIME &&
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1793 !rap->doexpire)
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1794 {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1795 valid = true;
4231
0dcc72ad719c ipv6nd: drop DHCPv6 when RA fully expires
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1796 continue;
0dcc72ad719c ipv6nd: drop DHCPv6 when RA fully expires
Roy Marples <roy@marples.name>
parents: 4197
diff changeset
1797 }
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1798 elapsed = (uint32_t)eloop_timespec_diff(&now,
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1799 &ia->acquired, NULL);
5180
0e4f56cb4c03 inet6: Expire ND on the second, not after it
Roy Marples <roy@marples.name>
parents: 5179
diff changeset
1800 if (elapsed >= ia->prefix_vltime || rap->doexpire) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1801 if (ia->flags & IPV6_AF_ADDED) {
4981
0fa3ebf43a1d inet6: Log expiration of a prefix if autoconf is not set
Roy Marples <roy@marples.name>
parents: 4978
diff changeset
1802 logwarnx("%s: expired %s %s",
0fa3ebf43a1d inet6: Log expiration of a prefix if autoconf is not set
Roy Marples <roy@marples.name>
parents: 4978
diff changeset
1803 ia->iface->name,
0fa3ebf43a1d inet6: Log expiration of a prefix if autoconf is not set
Roy Marples <roy@marples.name>
parents: 4978
diff changeset
1804 ia->flags & IPV6_AF_AUTOCONF ?
0fa3ebf43a1d inet6: Log expiration of a prefix if autoconf is not set
Roy Marples <roy@marples.name>
parents: 4978
diff changeset
1805 "address" : "prefix",
0fa3ebf43a1d inet6: Log expiration of a prefix if autoconf is not set
Roy Marples <roy@marples.name>
parents: 4978
diff changeset
1806 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
1807 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
1808 errno != EADDRNOTAVAIL &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1809 errno != ENXIO)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
1810 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
1811 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1812 ia->prefix_vltime = 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
1813 ia->flags &=
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1814 ~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
4349
f87c2ed9ff46 DHCP6: Remove #defines for functions when DHCP6 is disabled
Roy Marples <roy@marples.name>
parents: 4336
diff changeset
1815 expired = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1816 } else {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1817 valid = true;
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1818 ltime = ia->prefix_vltime - elapsed;
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1819 if (next == 0 || ltime < next)
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1820 next = ltime;
3932
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 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1823
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1824 /* Work out expiry for ND options */
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1825 elapsed = (uint32_t)eloop_timespec_diff(&now,
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1826 &rap->acquired, NULL);
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1827 len = rap->data_len - sizeof(struct nd_router_advert);
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1828 for (p = rap->data + sizeof(struct nd_router_advert);
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1829 len >= sizeof(ndo);
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1830 p += olen, len -= olen)
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1831 {
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1832 memcpy(&ndo, p, sizeof(ndo));
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1833 olen = (size_t)(ndo.nd_opt_len * 8);
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1834 if (olen > len) {
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1835 errno = EINVAL;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1836 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1837 }
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1838
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1839 if (has_option_mask(rap->iface->options->nomasknd,
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1840 ndo.nd_opt_type))
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1841 continue;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1842
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1843 switch (ndo.nd_opt_type) {
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1844 /* Prefix info is already checked in the above loop. */
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1845 #if 0
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1846 case ND_OPT_PREFIX_INFORMATION:
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1847 if (len < sizeof(pi))
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1848 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1849 memcpy(&pi, p, sizeof(pi));
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1850 ltime = pi.nd_opt_pi_valid_time;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1851 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1852 #endif
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1853 case ND_OPT_DNSSL:
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1854 if (len < sizeof(dnssl))
4539
3d212cac74d3 ND: Ensure that ltime is always set
Roy Marples <roy@marples.name>
parents: 4535
diff changeset
1855 continue;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1856 memcpy(&dnssl, p, sizeof(dnssl));
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1857 ltime = dnssl.nd_opt_dnssl_lifetime;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1858 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1859 case ND_OPT_RDNSS:
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1860 if (len < sizeof(rdnss))
4539
3d212cac74d3 ND: Ensure that ltime is always set
Roy Marples <roy@marples.name>
parents: 4535
diff changeset
1861 continue;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1862 memcpy(&rdnss, p, sizeof(rdnss));
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1863 ltime = rdnss.nd_opt_rdnss_lifetime;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1864 break;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1865 default:
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1866 continue;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1867 }
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1868
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1869 if (ltime == 0)
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1870 continue;
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1871 if (rap->doexpire) {
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1872 expired = true;
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1873 continue;
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1874 }
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1875 if (ltime == ND6_INFINITE_LIFETIME) {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1876 valid = true;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1877 continue;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1878 }
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1879
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1880 ltime = ntohl(ltime);
5180
0e4f56cb4c03 inet6: Expire ND on the second, not after it
Roy Marples <roy@marples.name>
parents: 5179
diff changeset
1881 if (elapsed >= ltime) {
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1882 expired = true;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1883 continue;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1884 }
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1885
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1886 valid = true;
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
1887 ltime -= elapsed;
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1888 if (next == 0 || ltime < next)
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1889 next = ltime;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1890 }
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1891
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1892 if (valid)
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1893 continue;
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1894
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1895 /* Router has expired. Let's not keep a lot of them. */
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1896 rap->expired = true;
4530
999c0c21711d RA: expire RDNSS and DNSSL entries
Roy Marples <roy@marples.name>
parents: 4526
diff changeset
1897 if (++nexpired > EXPIRED_MAX)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1898 ipv6nd_free_ra(rap);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1899 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1900
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1901 if (next != 0)
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1902 eloop_timeout_add_sec(ifp->ctx->eloop,
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
1903 next, ipv6nd_expirera, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1904 if (expired) {
5040
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1905 logwarnx("%s: part of a Router Advertisement expired",
c44b319ae036 inet6: Ensure expired routers are cleared after a carrier loss
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1906 ifp->name);
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
1907 ipv6nd_sortrouters(ifp->ctx);
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
1908 ipv6nd_applyra(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1909 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
1910 script_runreason(ifp, "ROUTERADVERT");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1911 }
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 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1915 ipv6nd_drop(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
1916 {
4141
45e849031aec Ensure that all RA's are actually dropped when dropping an interface.
Roy Marples <roy@marples.name>
parents: 4140
diff changeset
1917 struct ra *rap, *ran;
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1918 bool expired = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1919
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1920 if (ifp->ctx->ra_routers == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1921 return;
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 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
4141
45e849031aec Ensure that all RA's are actually dropped when dropping an interface.
Roy Marples <roy@marples.name>
parents: 4140
diff changeset
1924 TAILQ_FOREACH_SAFE(rap, ifp->ctx->ra_routers, next, ran) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1925 if (rap->iface == ifp) {
4646
c83adc0e8b5f inet6: Only remove default route when router becomes unreachable
Roy Marples <roy@marples.name>
parents: 4604
diff changeset
1926 rap->expired = expired = true;
4141
45e849031aec Ensure that all RA's are actually dropped when dropping an interface.
Roy Marples <roy@marples.name>
parents: 4140
diff changeset
1927 ipv6nd_drop_ra(rap);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1928 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1929 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1930 if (expired) {
5179
e241904845af inet6: Apply the best RA which is still valid.
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
1931 ipv6nd_applyra(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1932 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
1933 if ((ifp->options->options & DHCPCD_NODROP) != DHCPCD_NODROP)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1934 script_runreason(ifp, "ROUTERADVERT");
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
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4822
diff changeset
1938 void
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1939 ipv6nd_recvmsg(struct dhcpcd_ctx *ctx, struct msghdr *msg)
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1940 {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1941 struct sockaddr_in6 *from = (struct sockaddr_in6 *)msg->msg_name;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1942 char sfrom[INET6_ADDRSTRLEN];
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1943 int hoplimit = 0;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1944 struct icmp6_hdr *icp;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1945 struct interface *ifp;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1946 size_t len = msg->msg_iov[0].iov_len;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1947
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1948 inet_ntop(AF_INET6, &from->sin6_addr, sfrom, sizeof(sfrom));
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1949 if ((size_t)len < sizeof(struct icmp6_hdr)) {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1950 logerrx("IPv6 ICMP packet too short from %s", sfrom);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1951 return;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1952 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1953
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1954 ifp = if_findifpfromcmsg(ctx, msg, &hoplimit);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1955 if (ifp == NULL) {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1956 logerr(__func__);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1957 return;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1958 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1959
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1960 /* Don't do anything if the user hasn't configured it. */
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1961 if (ifp->active != IF_ACTIVE_USER ||
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1962 !(ifp->options->options & DHCPCD_IPV6))
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1963 return;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1964
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1965 icp = (struct icmp6_hdr *)msg->msg_iov[0].iov_base;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1966 if (icp->icmp6_code == 0) {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1967 switch(icp->icmp6_type) {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1968 case ND_ROUTER_ADVERT:
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1969 ipv6nd_handlera(ctx, from, sfrom,
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1970 ifp, icp, (size_t)len, hoplimit);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1971 return;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1972 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1973 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1974
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1975 logerrx("invalid IPv6 type %d or code %d from %s",
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1976 icp->icmp6_type, icp->icmp6_code, sfrom);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1977 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1978
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
1979 static void
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1980 ipv6nd_handledata(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1981 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1982 struct dhcpcd_ctx *ctx;
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
1983 int fd;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1984 struct sockaddr_in6 from;
5193
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5183
diff changeset
1985 union {
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5183
diff changeset
1986 struct icmp6_hdr hdr;
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5183
diff changeset
1987 uint8_t buf[64 * 1024]; /* Maximum ICMPv6 size */
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5183
diff changeset
1988 } iovbuf;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1989 struct iovec iov = {
5193
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5183
diff changeset
1990 .iov_base = iovbuf.buf, .iov_len = sizeof(iovbuf.buf),
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1991 };
5160
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1992 union {
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1993 struct cmsghdr hdr;
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1994 uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo)) +
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1995 CMSG_SPACE(sizeof(int))];
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
1996 } cmsgbuf = { .buf = { 0 } };
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1997 struct msghdr msg = {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1998 .msg_name = &from, .msg_namelen = sizeof(from),
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
1999 .msg_iov = &iov, .msg_iovlen = 1,
5160
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5153
diff changeset
2000 .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
2001 };
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2002 ssize_t len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2003
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2004 #ifdef __sun
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
2005 struct interface *ifp;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2006 struct rs_state *state;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2007
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2008 ifp = arg;
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2009 state = RS_STATE(ifp);
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2010 ctx = ifp->ctx;
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
2011 fd = state->nd_fd;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2012 #else
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2013 ctx = arg;
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
2014 fd = ctx->nd_fd;
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2015 #endif
4788
8d8165824b16 Solaris: Fix prior by receving IP6_PKTINFO
Roy Marples <roy@marples.name>
parents: 4787
diff changeset
2016 len = recvmsg(fd, &msg, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2017 if (len == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
2018 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
2019 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2020 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2021
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
2022 iov.iov_len = (size_t)len;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4702
diff changeset
2023 ipv6nd_recvmsg(ctx, &msg);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2024 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2025
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2026 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2027 ipv6nd_startrs1(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2028 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2029 struct interface *ifp = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2030 struct rs_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2031
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
2032 loginfox("%s: soliciting an IPv6 router", 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
2033 state = RS_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2034 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
2035 ifp->if_data[IF_DATA_IPV6ND] = 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
2036 state = RS_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2037 if (state == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
2038 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
2039 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2040 }
4472
9fc687d07672 Fix compile for non-sun
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2041 #ifdef __sun
4471
15b9659186e8 sun: Open an IPv6ND socket per interface
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
2042 state->nd_fd = -1;
4472
9fc687d07672 Fix compile for non-sun
Roy Marples <roy@marples.name>
parents: 4471
diff changeset
2043 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2044 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2045
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2046 /* Always make a new probe as the underlying hardware
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2047 * address could have changed. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2048 ipv6nd_makersprobe(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2049 if (state->rs == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3966
diff changeset
2050 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
2051 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2052 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2053
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
2054 state->retrans = RETRANS_TIMER;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2055 state->rsprobes = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2056 ipv6nd_sendrsprobe(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2057 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2058
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2059 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2060 ipv6nd_startrs(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
2061 {
4934
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
2062 unsigned int delay;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2063
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2064 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
2065 if (!(ifp->options->options & DHCPCD_INITIAL_DELAY)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2066 ipv6nd_startrs1(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2067 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2068 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2069
4934
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
2070 delay = arc4random_uniform(MAX_RTR_SOLICITATION_DELAY * MSEC_PER_SEC);
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2071 logdebugx("%s: delaying IPv6 router solicitation for %0.1f seconds",
4934
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
2072 ifp->name, (float)delay / MSEC_PER_SEC);
64d2e5e77cc3 inet6: Use milliseconds rather than timespec for calcuating delays
Roy Marples <roy@marples.name>
parents: 4929
diff changeset
2073 eloop_timeout_add_msec(ifp->ctx->eloop, delay, ipv6nd_startrs1, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2074 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2075 }