annotate src/dhcp6.c @ 5553:ef762d54fb7a draft

DHCP6: Abort in test mode when an error is returned by server.
author Roy Marples <roy@marples.name>
date Wed, 25 Nov 2020 15:14:11 +0000
parents a0d828e25482
children 3853222e97c7
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: 4543
diff changeset
1 /* SPDX-License-Identifier: BSD-2-Clause */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3 * dhcpcd - DHCP client daemon
4922
555d7d1a4939 Welcome to 2020!
Roy Marples <roy@marples.name>
parents: 4896
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/utsname.h>
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
30 #include <sys/types.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
31
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
32 #include <netinet/in.h>
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
33 #include <netinet/ip6.h>
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
34
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
35 #include <assert.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
36 #include <ctype.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
37 #include <errno.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
38 #include <fcntl.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
39 #include <inttypes.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 <stdbool.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>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
44 #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
45 #include <fcntl.h>
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
46 #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
47
5038
1e35e845790a eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents: 4966
diff changeset
48 #define ELOOP_QUEUE ELOOP_DHCP6
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
49 #include "config.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
50 #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
51 #include "dhcp.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
52 #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
53 #include "duid.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 "eloop.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 "if.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
56 #include "if-options.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
57 #include "ipv6nd.h"
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
58 #include "logerr.h"
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
59 #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
60 #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
61
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
62 #ifdef HAVE_SYS_BITOPS_H
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
63 #include <sys/bitops.h>
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
64 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
65 #include "compat/bitops.h"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
66 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
67
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
68 /* DHCPCD Project has been assigned an IANA PEN of 40712 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
69 #define DHCPCD_IANA_PEN 40712
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
70
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
71 /* Unsure if I want this */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
72 //#define VENDOR_SPLIT
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
73
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
74 /* 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
75 #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
76 #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
77 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
78
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
79 #ifdef DHCP6
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
80
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
81 /* Assert the correct structure size for on wire */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
82 struct dhcp6_message {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
83 uint8_t type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
84 uint8_t xid[3];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
85 /* followed by options */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
86 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
87 __CTASSERT(sizeof(struct dhcp6_message) == 4);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
88
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
89 struct dhcp6_option {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
90 uint16_t code;
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 len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
92 /* followed by data */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
93 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
94 __CTASSERT(sizeof(struct dhcp6_option) == 4);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
95
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
96 struct dhcp6_ia_na {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
97 uint8_t iaid[4];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
98 uint32_t t1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
99 uint32_t t2;
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 __CTASSERT(sizeof(struct dhcp6_ia_na) == 12);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
102
4280
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
103 struct dhcp6_ia_ta {
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
104 uint8_t iaid[4];
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
105 };
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
106 __CTASSERT(sizeof(struct dhcp6_ia_ta) == 4);
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
107
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
108 struct dhcp6_ia_addr {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
109 struct in6_addr addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
110 uint32_t pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
111 uint32_t vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
112 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
113 __CTASSERT(sizeof(struct dhcp6_ia_addr) == 16 + 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
114
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
115 /* XXX FIXME: This is the only packed structure and it does not align.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
116 * Maybe manually decode it? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
117 struct dhcp6_pd_addr {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
118 uint32_t pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
119 uint32_t vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
120 uint8_t prefix_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
121 struct in6_addr prefix;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
122 } __packed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
123 __CTASSERT(sizeof(struct dhcp6_pd_addr) == 8 + 1 + 16);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
124
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
125 struct dhcp6_op {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
126 uint16_t type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
127 const char *name;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
128 };
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 static const struct dhcp6_op dhcp6_ops[] = {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
131 { DHCP6_SOLICIT, "SOLICIT6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
132 { DHCP6_ADVERTISE, "ADVERTISE6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
133 { DHCP6_REQUEST, "REQUEST6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
134 { DHCP6_REPLY, "REPLY6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
135 { DHCP6_RENEW, "RENEW6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
136 { DHCP6_REBIND, "REBIND6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
137 { DHCP6_CONFIRM, "CONFIRM6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
138 { DHCP6_INFORMATION_REQ, "INFORM6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
139 { DHCP6_RELEASE, "RELEASE6" },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
140 { DHCP6_RECONFIGURE, "RECONFIGURE6" },
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
141 { DHCP6_DECLINE, "DECLINE6" },
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
142 { 0, NULL }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
143 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
144
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
145 struct dhcp_compat {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
146 uint8_t dhcp_opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
147 uint16_t dhcp6_opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
148 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
149
5484
e01d8ea25a42 Clean up some warnings.
Sascha Wildner <saw@online.de>
parents: 5398
diff changeset
150 static const struct dhcp_compat dhcp_compats[] = {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
151 { DHO_DNSSERVER, D6_OPTION_DNS_SERVERS },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
152 { DHO_HOSTNAME, D6_OPTION_FQDN },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
153 { DHO_DNSDOMAIN, D6_OPTION_FQDN },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
154 { DHO_NISSERVER, D6_OPTION_NIS_SERVERS },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
155 { DHO_NTPSERVER, D6_OPTION_SNTP_SERVERS },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
156 { DHO_RAPIDCOMMIT, D6_OPTION_RAPID_COMMIT },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
157 { DHO_FQDN, D6_OPTION_FQDN },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
158 { DHO_VIVCO, D6_OPTION_VENDOR_CLASS },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
159 { DHO_VIVSO, D6_OPTION_VENDOR_OPTS },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
160 { DHO_DNSSEARCH, D6_OPTION_DOMAIN_LIST },
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
161 { 0, 0 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
162 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
163
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
164 static const char * const dhcp6_statuses[] = {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
165 "Success",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
166 "Unspecified Failure",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
167 "No Addresses Available",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
168 "No Binding",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
169 "Not On Link",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
170 "Use Multicast",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
171 "No Prefix Available"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
172 };
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
173
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
174 static void dhcp6_bind(struct interface *, const char *, const char *);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
175 static void dhcp6_failinform(void *);
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
176 static void dhcp6_recvaddr(void *);
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
177 static void dhcp6_startdecline(struct interface *);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
178
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
179 #ifdef SMALL
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
180 #define dhcp6_hasprefixdelegation(a) (0)
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
181 #else
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
182 static int dhcp6_hasprefixdelegation(struct interface *);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
183 #endif
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
184
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
185 #define DECLINE_IA(ia) \
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
186 ((ia)->addr_flags & IN6_IFF_DUPLICATED && \
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
187 (ia)->ia_type != 0 && (ia)->ia_type != D6_OPTION_IA_PD && \
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
188 !((ia)->flags & IPV6_AF_STALE) && \
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
189 (ia)->prefix_vltime != 0)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
190
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
191 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
192 dhcp6_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
193 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
194 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
195 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
196 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
197 int 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 for (i = 0, opt = ctx->dhcp6_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
200 i < ctx->dhcp6_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
201 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
202 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
203 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
204 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
205 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
206 cols = printf("%05d %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
207 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
208 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
209 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
210 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
211 cols = printf("%05d %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
212 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
213 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
214 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
215
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
216 static size_t
4258
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
217 dhcp6_makeuser(void *data, const struct interface *ifp)
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
218 {
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
219 const struct if_options *ifo = ifp->options;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
220 struct dhcp6_option o;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
221 uint8_t *p;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
222 const uint8_t *up, *ue;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
223 uint16_t ulen, unlen;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
224 size_t olen;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
225
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
226 /* Convert the DHCPv4 user class option to DHCPv6 */
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
227 up = ifo->userclass;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
228 ulen = *up++;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
229 if (ulen == 0)
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
230 return 0;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
231
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
232 p = data;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
233 olen = 0;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
234 if (p != NULL)
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
235 p += sizeof(o);
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
236
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
237 ue = up + ulen;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
238 for (; up < ue; up += ulen) {
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
239 ulen = *up++;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
240 olen += sizeof(ulen) + ulen;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
241 if (data == NULL)
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
242 continue;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
243 unlen = htons(ulen);
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
244 memcpy(p, &unlen, sizeof(unlen));
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
245 p += sizeof(unlen);
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
246 memcpy(p, up, ulen);
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
247 p += ulen;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
248 }
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
249 if (data != NULL) {
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
250 o.code = htons(D6_OPTION_USER_CLASS);
4259
bf08893bc7fd Cast away a conversion warning.
Roy Marples <roy@marples.name>
parents: 4258
diff changeset
251 o.len = htons((uint16_t)olen);
4258
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
252 memcpy(data, &o, sizeof(o));
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
253 }
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
254
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
255 return sizeof(o) + olen;
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
256 }
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
257
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
258 static size_t
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
259 dhcp6_makevendor(void *data, 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
260 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
261 const struct if_options *ifo;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
262 size_t len, vlen, i;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
263 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
264 const struct vivco *vivco;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
265 struct dhcp6_option o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
266
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
267 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
268 len = sizeof(uint32_t); /* IANA PEN */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
269 if (ifo->vivco_en) {
5273
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
270 vlen = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
271 for (i = 0, vivco = ifo->vivco;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
272 i < ifo->vivco_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
273 i++, vivco++)
5273
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
274 vlen += sizeof(uint16_t) + vivco->len;
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
275 len += vlen;
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
276 } else if (ifo->vendorclassid[0] != '\0') {
5275
b7d18124ad21 DHCP6: Revert part of prior - only allow vendorclassid to disable
Roy Marples <roy@marples.name>
parents: 5273
diff changeset
277 /* dhcpcd owns DHCPCD_IANA_PEN.
b7d18124ad21 DHCP6: Revert part of prior - only allow vendorclassid to disable
Roy Marples <roy@marples.name>
parents: 5273
diff changeset
278 * If you need your own string, get your own IANA PEN. */
b7d18124ad21 DHCP6: Revert part of prior - only allow vendorclassid to disable
Roy Marples <roy@marples.name>
parents: 5273
diff changeset
279 vlen = strlen(ifp->ctx->vendor);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
280 len += sizeof(uint16_t) + vlen;
5273
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
281 } else
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
282 return 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
283
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
284 if (len > UINT16_MAX) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
285 logerrx("%s: DHCPv6 Vendor Class too big", 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
286 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
287 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
288
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
289 if (data != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
290 uint32_t pen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
291 uint16_t hvlen;
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 p = data;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
294 o.code = htons(D6_OPTION_VENDOR_CLASS);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
295 o.len = htons((uint16_t)len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
296 memcpy(p, &o, sizeof(o));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
297 p += sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
298 pen = htonl(ifo->vivco_en ? ifo->vivco_en : DHCPCD_IANA_PEN);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
299 memcpy(p, &pen, sizeof(pen));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
300 p += sizeof(pen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
301
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
302 if (ifo->vivco_en) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
303 for (i = 0, vivco = ifo->vivco;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
304 i < ifo->vivco_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
305 i++, vivco++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
306 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
307 hvlen = htons((uint16_t)vivco->len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
308 memcpy(p, &hvlen, sizeof(hvlen));
4260
8c6250af2ed4 DHCP6: Fix sending custom vendor class option.
Roy Marples <roy@marples.name>
parents: 4259
diff changeset
309 p += sizeof(hvlen);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
310 memcpy(p, vivco->data, vivco->len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
311 p += vivco->len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
312 }
5273
3a33b39120eb DHCP6: Use interface vendorclassid rather than context
Roy Marples <roy@marples.name>
parents: 5236
diff changeset
313 } else if (ifo->vendorclassid[0] != '\0') {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
314 hvlen = htons((uint16_t)vlen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
315 memcpy(p, &hvlen, sizeof(hvlen));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
316 p += sizeof(hvlen);
5275
b7d18124ad21 DHCP6: Revert part of prior - only allow vendorclassid to disable
Roy Marples <roy@marples.name>
parents: 5273
diff changeset
317 memcpy(p, ifp->ctx->vendor, vlen);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
318 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
319 }
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 return sizeof(o) + len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
322 }
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 static void *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
325 dhcp6_findoption(void *data, size_t data_len, uint16_t code, uint16_t *len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
326 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
327 uint8_t *d;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
328 struct dhcp6_option o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
329
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
330 code = htons(code);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
331 for (d = data; data_len != 0; d += o.len, data_len -= o.len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
332 if (data_len < sizeof(o)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
333 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
334 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
335 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
336 memcpy(&o, d, sizeof(o));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
337 d += sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
338 data_len -= sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
339 o.len = htons(o.len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
340 if (data_len < o.len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
341 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
342 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
343 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
344 if (o.code == code) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
345 if (len != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
346 *len = o.len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
347 return d;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
348 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
349 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
350
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
351 errno = ENOENT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
352 return NULL;
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
355 static void *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
356 dhcp6_findmoption(void *data, size_t data_len, uint16_t code,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
357 uint16_t *len)
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 uint8_t *d;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
360
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
361 if (data_len < sizeof(struct dhcp6_message)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
362 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
363 return false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
364 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
365 d = data;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
366 d += sizeof(struct dhcp6_message);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
367 data_len -= sizeof(struct dhcp6_message);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
368 return dhcp6_findoption(d, data_len, code, len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
369 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
370
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
371 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
372 dhcp6_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
373 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
374 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
375 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
376 struct dhcp6_option o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
377 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
378 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
379
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
380 if (od != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
381 *os = sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
382 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
383 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
384 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
385 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
386 memcpy(&o, od, sizeof(o));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
387 *len = ntohs(o.len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
388 if (*len > ol - *os) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
389 errno = ERANGE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
390 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
391 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
392 *code = ntohs(o.code);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
393 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
394
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
395 *oopt = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
396 for (i = 0, opt = ctx->dhcp6_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
397 i < ctx->dhcp6_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
398 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
399 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
400 *oopt = opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
401 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
402 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
403 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
404
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
405 if (od != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
406 return od + sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
407 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
408 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
409
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
410 static bool
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
411 dhcp6_updateelapsed(struct interface *ifp, struct dhcp6_message *m, 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
412 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
413 uint8_t *opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
414 uint16_t opt_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
415 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
416 struct timespec tv;
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
417 unsigned long long hsec;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
418 uint16_t sec;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
419
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
420 opt = dhcp6_findmoption(m, len, D6_OPTION_ELAPSED, &opt_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
421 if (opt == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
422 return false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
423 if (opt_len != sizeof(sec)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
424 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
425 return false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
426 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
427
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
428 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
429 clock_gettime(CLOCK_MONOTONIC, &tv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
430 if (state->RTC == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
431 /* An RTC of zero means we're the first message
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
432 * out of the door, so the elapsed time is zero. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
433 state->started = tv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
434 hsec = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
435 } else {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
436 unsigned long long secs;
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
437 unsigned int nsecs;
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
438
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
439 secs = eloop_timespec_diff(&tv, &state->started, &nsecs);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
440 /* Elapsed time is measured in centiseconds.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
441 * We need to be sure it will not potentially overflow. */
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
442 if (secs >= (UINT16_MAX / CSEC_PER_SEC) + 1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
443 hsec = UINT16_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
444 else {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
445 hsec = (secs * CSEC_PER_SEC) +
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
446 (nsecs / NSEC_PER_CSEC);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
447 if (hsec > UINT16_MAX)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
448 hsec = UINT16_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
449 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
450 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
451 sec = htons((uint16_t)hsec);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
452 memcpy(opt, &sec, sizeof(sec));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
453 return true;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
454 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
455
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
456 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
457 dhcp6_newxid(const struct interface *ifp, struct dhcp6_message *m)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
458 {
4177
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
459 const struct interface *ifp1;
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
460 const struct dhcp6_state *state1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
461 uint32_t xid;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
462
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
463 if (ifp->options->options & DHCPCD_XID_HWADDR &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
464 ifp->hwlen >= sizeof(xid))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
465 /* The lower bits are probably more unique on the network */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
466 memcpy(&xid, (ifp->hwaddr + ifp->hwlen) - sizeof(xid),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
467 sizeof(xid));
4177
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
468 else {
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
469 again:
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
470 xid = arc4random();
4177
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
471 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
472
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
473 m->xid[0] = (xid >> 16) & 0xff;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
474 m->xid[1] = (xid >> 8) & 0xff;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
475 m->xid[2] = xid & 0xff;
4177
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
476
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
477 /* Ensure it's unique */
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
478 TAILQ_FOREACH(ifp1, ifp->ctx->ifaces, next) {
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
479 if (ifp == ifp1)
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
480 continue;
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
481 if ((state1 = D6_CSTATE(ifp1)) == NULL)
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
482 continue;
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
483 if (state1->send != NULL &&
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
484 state1->send->xid[0] == m->xid[0] &&
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
485 state1->send->xid[1] == m->xid[1] &&
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
486 state1->send->xid[2] == m->xid[2])
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
487 break;
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
488 }
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
489
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
490 if (ifp1 != NULL) {
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
491 if (ifp->options->options & DHCPCD_XID_HWADDR &&
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
492 ifp->hwlen >= sizeof(xid))
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
493 {
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
494 logerrx("%s: duplicate xid on %s",
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
495 ifp->name, ifp1->name);
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
496 return;
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
497 }
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
498 goto again;
bce060648873 Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents: 4175
diff changeset
499 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
500 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
501
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
502 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
503 static const struct if_sla *
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
504 dhcp6_findselfsla(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
505 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
506 size_t i, j;
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
507 struct if_ia *ia;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
508
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
509 for (i = 0; i < ifp->options->ia_len; i++) {
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
510 ia = &ifp->options->ia[i];
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
511 if (ia->ia_type != D6_OPTION_IA_PD)
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
512 continue;
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
513 for (j = 0; j < ia->sla_len; j++) {
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
514 if (strcmp(ia->sla[j].ifname, ifp->name) == 0)
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
515 return &ia->sla[j];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
516 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
517 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
518 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
519 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
520
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
521 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
522 dhcp6_delegateaddr(struct in6_addr *addr, 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
523 const struct ipv6_addr *prefix, const struct if_sla *sla, struct if_ia *ia)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
524 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
525 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
526 struct if_sla asla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
527 char sabuf[INET6_ADDRSTRLEN];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
528 const char *sa;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
529
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
530 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
531 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
532 ifp->if_data[IF_DATA_DHCP6] = 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
533 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
534 if (state == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
535 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
536 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
537 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
538
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
539 TAILQ_INIT(&state->addrs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
540 state->state = DH6S_DELEGATED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
541 state->reason = "DELEGATED6";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
542 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
543
5359
e6b89e1a4077 DHCP6: Use sla setting when calculating delegated prefix length
Roy Marples <roy@marples.name>
parents: 5357
diff changeset
544 if (sla == NULL || !sla->sla_set) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
545 /* No SLA set, so make an assumption of
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
546 * desired SLA and prefix length. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
547 asla.sla = ifp->index;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
548 asla.prefix_len = 0;
5359
e6b89e1a4077 DHCP6: Use sla setting when calculating delegated prefix length
Roy Marples <roy@marples.name>
parents: 5357
diff changeset
549 asla.sla_set = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
550 sla = &asla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
551 } else if (sla->prefix_len == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
552 /* An SLA was given, but prefix length was not.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
553 * We need to work out a suitable prefix length for
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
554 * potentially more than one interface. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
555 asla.sla = sla->sla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
556 asla.prefix_len = 0;
5359
e6b89e1a4077 DHCP6: Use sla setting when calculating delegated prefix length
Roy Marples <roy@marples.name>
parents: 5357
diff changeset
557 asla.sla_set = sla->sla_set;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
558 sla = &asla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
559 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
560
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
561 if (sla->prefix_len == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
562 uint32_t sla_max;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
563 int bits;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
564
5359
e6b89e1a4077 DHCP6: Use sla setting when calculating delegated prefix length
Roy Marples <roy@marples.name>
parents: 5357
diff changeset
565 sla_max = ia->sla_max;
e6b89e1a4077 DHCP6: Use sla setting when calculating delegated prefix length
Roy Marples <roy@marples.name>
parents: 5357
diff changeset
566 if (sla_max == 0 && (sla == NULL || !sla->sla_set)) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
567 const struct interface *ifi;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
568
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
569 TAILQ_FOREACH(ifi, 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
570 if (ifi->index > sla_max)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
571 sla_max = ifi->index;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
572 }
5359
e6b89e1a4077 DHCP6: Use sla setting when calculating delegated prefix length
Roy Marples <roy@marples.name>
parents: 5357
diff changeset
573 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
574
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
575 bits = fls32(sla_max);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
576
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
577 if (prefix->prefix_len + bits > (int)UINT8_MAX)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
578 asla.prefix_len = UINT8_MAX;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
579 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
580 asla.prefix_len = (uint8_t)(prefix->prefix_len + bits);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
581
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
582 /* Make a 64 prefix by default, as this makes SLAAC
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
583 * possible.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
584 * Otherwise round up to the nearest 4 bits. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
585 if (asla.prefix_len <= 64)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
586 asla.prefix_len = 64;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
587 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
588 asla.prefix_len =
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
589 (uint8_t)ROUNDUP4(asla.prefix_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
590 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
591
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
592 #define BIT(n) (1UL << (n))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
593 #define BIT_MASK(len) (BIT(len) - 1)
4560
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
594 if (ia->sla_max == 0) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
595 /* Work out the real sla_max from our bits used */
4560
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
596 bits = asla.prefix_len - prefix->prefix_len;
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
597 /* Make static analysis happy.
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
598 * Bits cannot be bigger than 32 thanks to fls32. */
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
599 assert(bits <= 32);
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
600 ia->sla_max = (uint32_t)BIT_MASK(bits);
9745c72fc2eb DHCP6: Assert auto sla is only 32-bits
Roy Marples <roy@marples.name>
parents: 4549
diff changeset
601 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
602 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
603
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
604 if (ipv6_userprefix(&prefix->prefix, prefix->prefix_len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
605 sla->sla, addr, sla->prefix_len) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
606 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
607 sa = inet_ntop(AF_INET6, &prefix->prefix,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
608 sabuf, sizeof(sabuf));
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
609 logerr("%s: invalid prefix %s/%d + %d/%d",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
610 ifp->name, sa, prefix->prefix_len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
611 sla->sla, sla->prefix_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
612 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
613 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
614
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
615 if (prefix->prefix_exclude_len &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
616 IN6_ARE_ADDR_EQUAL(addr, &prefix->prefix_exclude))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
617 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
618 sa = inet_ntop(AF_INET6, &prefix->prefix_exclude,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
619 sabuf, sizeof(sabuf));
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
620 logerrx("%s: cannot delegate excluded prefix %s/%d",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
621 ifp->name, sa, prefix->prefix_exclude_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
622 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
623 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
624
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
625 return sla->prefix_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
626 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
627 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
628
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
629 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
630 dhcp6_makemessage(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
631 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
632 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
633 struct dhcp6_message *m;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
634 struct dhcp6_option o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
635 uint8_t *p, *si, *unicast, IA;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
636 size_t n, l, len, ml, hl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
637 uint8_t type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
638 uint16_t si_len, uni_len, n_options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
639 uint8_t *o_lenp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
640 struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
641 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
642 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
643 char hbuf[HOSTNAME_MAX_LEN + 1];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
644 const char *hostname;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
645 int fqdn;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
646 struct dhcp6_ia_na ia_na;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
647 uint16_t ia_na_len;
4280
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
648 struct if_ia *ifia;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
649 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
650 uint16_t auth_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
651 #endif
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
652 uint8_t duid[DUID_LEN];
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
653 size_t duid_len = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
654
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
655 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
656 if (state->send) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
657 free(state->send);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
658 state->send = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
659 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
660
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
661 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
662 fqdn = ifo->fqdn;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
663
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
664 if (fqdn == FQDN_DISABLE && ifo->options & DHCPCD_HOSTNAME) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
665 /* We're sending the DHCPv4 hostname option, so send FQDN as
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
666 * DHCPv6 has no FQDN option and DHCPv4 must not send
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
667 * hostname and FQDN according to RFC4702 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
668 fqdn = FQDN_BOTH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
669 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
670 if (fqdn != FQDN_DISABLE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
671 hostname = dhcp_get_hostname(hbuf, sizeof(hbuf), ifo);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
672 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
673 hostname = NULL; /* appearse gcc */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
674
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
675 /* Work out option size first */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
676 n_options = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
677 len = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
678 si = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
679 hl = 0; /* Appease gcc */
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
680 if (state->state != DH6S_RELEASE && state->state != DH6S_DECLINE) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
681 for (l = 0, opt = ifp->ctx->dhcp6_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
682 l < ifp->ctx->dhcp6_opts_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
683 l++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
684 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
685 for (n = 0, opt2 = ifo->dhcp6_override;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
686 n < ifo->dhcp6_override_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
687 n++, opt2++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
688 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
689 if (opt->option == opt2->option)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
690 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
691 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
692 if (n < ifo->dhcp6_override_len)
4724
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
693 continue;
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
694 if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
695 continue;
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
696 n_options++;
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
697 len += sizeof(o.len);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
698 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
699 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
700 for (l = 0, opt = ifo->dhcp6_override;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
701 l < ifo->dhcp6_override_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
702 l++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
703 {
4724
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
704 if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
705 continue;
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
706 n_options++;
d64400c59a28 DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents: 4695
diff changeset
707 len += sizeof(o.len);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
708 }
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
709 if (dhcp6_findselfsla(ifp)) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
710 n_options++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
711 len += sizeof(o.len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
712 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
713 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
714 if (len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
715 len += sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
716
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
717 if (fqdn != FQDN_DISABLE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
718 hl = encode_rfc1035(hostname, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
719 len += sizeof(o) + 1 + hl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
720 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
721
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
722 if (!has_option_mask(ifo->nomask6, D6_OPTION_MUDURL) &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
723 ifo->mudurl[0])
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
724 len += sizeof(o) + ifo->mudurl[0];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
725
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
726 #ifdef AUTH
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
727 if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) !=
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
728 DHCPCD_AUTH_SENDREQUIRE &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
729 DHC_REQ(ifo->requestmask6, ifo->nomask6,
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
730 D6_OPTION_RECONF_ACCEPT))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
731 len += sizeof(o); /* Reconfigure Accept */
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
732 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
733 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
734
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
735 len += sizeof(*state->send);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
736 len += sizeof(o) + sizeof(uint16_t); /* elapsed */
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
737
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
738 if (ifo->options & DHCPCD_ANONYMOUS) {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
739 duid_len = duid_make(duid, ifp, DUID_LL);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
740 len += sizeof(o) + duid_len;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
741 } else {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
742 len += sizeof(o) + ifp->ctx->duid_len;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
743 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
744
4258
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
745 if (!has_option_mask(ifo->nomask6, D6_OPTION_USER_CLASS))
f7795e713bf5 DHCPv6: Transpose DHCP userclass option into DHCPv6
Roy Marples <roy@marples.name>
parents: 4247
diff changeset
746 len += dhcp6_makeuser(NULL, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
747 if (!has_option_mask(ifo->nomask6, D6_OPTION_VENDOR_CLASS))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
748 len += dhcp6_makevendor(NULL, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
749
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
750 /* IA */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
751 m = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
752 ml = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
753 switch(state->state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
754 case DH6S_REQUEST:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
755 m = state->recv;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
756 ml = state->recv_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
757 /* FALLTHROUGH */
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
758 case DH6S_DECLINE:
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
759 /* FALLTHROUGH */
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
760 case DH6S_RELEASE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
761 /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
762 case DH6S_RENEW:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
763 if (m == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
764 m = state->new;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
765 ml = state->new_len;
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 si = dhcp6_findmoption(m, ml, D6_OPTION_SERVERID, &si_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
768 if (si == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
769 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
770 len += sizeof(o) + si_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
771 /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
772 case DH6S_REBIND:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
773 /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
774 case DH6S_CONFIRM:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
775 /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
776 case DH6S_DISCOVER:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
777 if (m == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
778 m = state->new;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
779 ml = state->new_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
780 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
781 TAILQ_FOREACH(ap, &state->addrs, next) {
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
782 if (ap->flags & IPV6_AF_STALE)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
783 continue;
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
784 if (!(ap->flags & IPV6_AF_REQUEST) &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
785 (ap->prefix_vltime == 0 ||
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
786 state->state == DH6S_DISCOVER))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
787 continue;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
788 if (DECLINE_IA(ap) && state->state != DH6S_DECLINE)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
789 continue;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
790 if (ap->ia_type == D6_OPTION_IA_PD) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
791 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
792 len += sizeof(o) + sizeof(struct dhcp6_pd_addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
793 if (ap->prefix_exclude_len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
794 len += sizeof(o) + 1 +
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
795 (uint8_t)((ap->prefix_exclude_len -
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
796 ap->prefix_len - 1) / NBBY) + 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
797 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
798 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
799 len += sizeof(o) + sizeof(struct dhcp6_ia_addr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
800 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
801 /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
802 case DH6S_INIT:
4281
0173b37a051b dhcp6: fix a memory issue with prior patch
Roy Marples <roy@marples.name>
parents: 4280
diff changeset
803 for (l = 0; l < ifo->ia_len; l++) {
0173b37a051b dhcp6: fix a memory issue with prior patch
Roy Marples <roy@marples.name>
parents: 4280
diff changeset
804 len += sizeof(o) + sizeof(uint32_t); /* IAID */
0173b37a051b dhcp6: fix a memory issue with prior patch
Roy Marples <roy@marples.name>
parents: 4280
diff changeset
805 /* IA_TA does not have T1 or T2 timers */
0173b37a051b dhcp6: fix a memory issue with prior patch
Roy Marples <roy@marples.name>
parents: 4280
diff changeset
806 if (ifo->ia[l].ia_type != D6_OPTION_IA_TA)
0173b37a051b dhcp6: fix a memory issue with prior patch
Roy Marples <roy@marples.name>
parents: 4280
diff changeset
807 len += sizeof(uint32_t) + sizeof(uint32_t);
0173b37a051b dhcp6: fix a memory issue with prior patch
Roy Marples <roy@marples.name>
parents: 4280
diff changeset
808 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
809 IA = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
810 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
811 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
812 IA = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
813 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
814
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
815 if (state->state == DH6S_DISCOVER &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
816 !(ifp->ctx->options & DHCPCD_TEST) &&
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
817 DHC_REQ(ifo->requestmask6, ifo->nomask6, D6_OPTION_RAPID_COMMIT))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
818 len += sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
819
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
820 if (m == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
821 m = state->new;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
822 ml = state->new_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
823 }
4418
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
824
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
825 switch(state->state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
826 case DH6S_INIT: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
827 case DH6S_DISCOVER:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
828 type = DHCP6_SOLICIT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
829 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
830 case DH6S_REQUEST:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
831 type = DHCP6_REQUEST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
832 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
833 case DH6S_CONFIRM:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
834 type = DHCP6_CONFIRM;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
835 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
836 case DH6S_REBIND:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
837 type = DHCP6_REBIND;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
838 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
839 case DH6S_RENEW:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
840 type = DHCP6_RENEW;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
841 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
842 case DH6S_INFORM:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
843 type = DHCP6_INFORMATION_REQ;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
844 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
845 case DH6S_RELEASE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
846 type = DHCP6_RELEASE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
847 break;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
848 case DH6S_DECLINE:
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
849 type = DHCP6_DECLINE;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
850 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
851 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
852 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
853 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
854 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
855
4418
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
856 switch(state->state) {
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
857 case DH6S_REQUEST: /* FALLTHROUGH */
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
858 case DH6S_RENEW: /* FALLTHROUGH */
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
859 case DH6S_RELEASE:
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
860 if (has_option_mask(ifo->nomask6, D6_OPTION_UNICAST)) {
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
861 unicast = NULL;
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
862 break;
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
863 }
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
864 unicast = dhcp6_findmoption(m, ml, D6_OPTION_UNICAST, &uni_len);
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
865 break;
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
866 default:
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
867 unicast = NULL;
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
868 break;
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
869 }
64579c25e8e3 DHCPv6: Allow nooptions dhcp6_unicast to work.
Roy Marples <roy@marples.name>
parents: 4374
diff changeset
870
4233
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
871 /* In non master mode we listen and send from fixed addresses.
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
872 * We should try and match an address we have to unicast to,
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
873 * but for now this is the safest policy. */
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
874 if (unicast != NULL && !(ifp->ctx->options & DHCPCD_MASTER)) {
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
875 logdebugx("%s: ignoring unicast option as not master",
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
876 ifp->name);
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
877 unicast = NULL;
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
878 }
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
879
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
880 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
881 auth_len = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
882 if (ifo->auth.options & DHCPCD_AUTH_SEND) {
5299
b7e676ac73c1 privsep: Access the RDM monotic file via IPC
Roy Marples <roy@marples.name>
parents: 5294
diff changeset
883 ssize_t alen = dhcp_auth_encode(ifp->ctx, &ifo->auth,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
884 state->auth.token, NULL, 0, 6, type, NULL, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
885 if (alen != -1 && alen > UINT16_MAX) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
886 errno = ERANGE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
887 alen = -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
888 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
889 if (alen == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
890 logerr("%s: %s: dhcp_auth_encode", __func__, 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
891 else if (alen != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
892 auth_len = (uint16_t)alen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
893 len += sizeof(o) + auth_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
894 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
895 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
896 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
897
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
898 state->send = malloc(len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
899 if (state->send == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
900 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
901
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
902 state->send_len = len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
903 state->send->type = type;
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 /* If we found a unicast option, copy it to our state for sending */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
906 if (unicast && uni_len == sizeof(state->unicast))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
907 memcpy(&state->unicast, unicast, sizeof(state->unicast));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
908 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
909 state->unicast = in6addr_any;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
910
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
911 dhcp6_newxid(ifp, state->send);
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 #define COPYIN1(_code, _len) { \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
914 o.code = htons((_code)); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
915 o.len = htons((_len)); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
916 memcpy(p, &o, sizeof(o)); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
917 p += sizeof(o); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
918 }
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
919 #define COPYIN(_code, _data, _len) do { \
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
920 COPYIN1((_code), (_len)); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
921 if ((_len) != 0) { \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
922 memcpy(p, (_data), (_len)); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
923 p += (_len); \
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
924 } \
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
925 } while (0 /* CONSTCOND */)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
926 #define NEXTLEN (p + offsetof(struct dhcp6_option, len))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
927
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
928 /* Options are listed in numerical order as per RFC 7844 Section 4.1
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
929 * XXX: They should be randomised. */
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
930
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
931 p = (uint8_t *)state->send + sizeof(*state->send);
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
932 if (ifo->options & DHCPCD_ANONYMOUS)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
933 COPYIN(D6_OPTION_CLIENTID, duid,
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
934 (uint16_t)duid_len);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
935 else
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
936 COPYIN(D6_OPTION_CLIENTID, ifp->ctx->duid,
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
937 (uint16_t)ifp->ctx->duid_len);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
938
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
939 if (si != NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
940 COPYIN(D6_OPTION_SERVERID, si, si_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
941
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
942 for (l = 0; IA && l < ifo->ia_len; l++) {
4280
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
943 ifia = &ifo->ia[l];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
944 o_lenp = NEXTLEN;
4280
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
945 /* TA structure is the same as the others,
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
946 * it just lacks the T1 and T2 timers.
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
947 * These happen to be at the end of the struct,
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
948 * so we just don't copy them in. */
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
949 if (ifia->ia_type == D6_OPTION_IA_TA)
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
950 ia_na_len = sizeof(struct dhcp6_ia_ta);
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
951 else
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
952 ia_na_len = sizeof(ia_na);
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
953 memcpy(ia_na.iaid, ifia->iaid, sizeof(ia_na.iaid));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
954 ia_na.t1 = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
955 ia_na.t2 = 0;
4280
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
956 COPYIN(ifia->ia_type, &ia_na, ia_na_len);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
957 TAILQ_FOREACH(ap, &state->addrs, next) {
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
958 if (ap->flags & IPV6_AF_STALE)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
959 continue;
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
960 if (!(ap->flags & IPV6_AF_REQUEST) &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
961 (ap->prefix_vltime == 0 ||
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
962 state->state == DH6S_DISCOVER))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
963 continue;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
964 if (DECLINE_IA(ap) && state->state != DH6S_DECLINE)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
965 continue;
4280
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
966 if (ap->ia_type != ifia->ia_type)
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
967 continue;
16dd1b6b5e13 dhcp6: match IA type with request
Roy Marples <roy@marples.name>
parents: 4279
diff changeset
968 if (memcmp(ap->iaid, ifia->iaid, sizeof(ap->iaid)))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
969 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
970 if (ap->ia_type == D6_OPTION_IA_PD) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
971 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
972 struct dhcp6_pd_addr pdp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
973
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
974 pdp.pltime = htonl(ap->prefix_pltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
975 pdp.vltime = htonl(ap->prefix_vltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
976 pdp.prefix_len = ap->prefix_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
977 /* pdp.prefix is not aligned, so copy it in. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
978 memcpy(&pdp.prefix, &ap->prefix, sizeof(pdp.prefix));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
979 COPYIN(D6_OPTION_IAPREFIX, &pdp, sizeof(pdp));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
980 ia_na_len = (uint16_t)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
981 (ia_na_len + sizeof(o) + sizeof(pdp));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
982
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
983 /* RFC6603 Section 4.2 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
984 if (ap->prefix_exclude_len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
985 uint8_t exb[16], *ep, u8;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
986 const uint8_t *pp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
987
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
988 n = (size_t)((ap->prefix_exclude_len -
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
989 ap->prefix_len - 1) / NBBY) + 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
990 ep = exb;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
991 *ep++ = (uint8_t)ap->prefix_exclude_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
992 pp = ap->prefix_exclude.s6_addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
993 pp += (size_t)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
994 ((ap->prefix_len - 1) / NBBY) +
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
995 (n - 1);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
996 u8 = ap->prefix_len % NBBY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
997 if (u8)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
998 n--;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
999 while (n-- > 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1000 *ep++ = *pp--;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1001 if (u8)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1002 *ep = (uint8_t)(*pp << u8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1003 n++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1004 COPYIN(D6_OPTION_PD_EXCLUDE, exb,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1005 (uint16_t)n);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1006 ia_na_len = (uint16_t)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1007 (ia_na_len + sizeof(o) + n);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1008 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1009 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1010 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1011 struct dhcp6_ia_addr ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1012
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1013 ia.addr = ap->addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1014 ia.pltime = htonl(ap->prefix_pltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1015 ia.vltime = htonl(ap->prefix_vltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1016 COPYIN(D6_OPTION_IA_ADDR, &ia, sizeof(ia));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1017 ia_na_len = (uint16_t)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1018 (ia_na_len + sizeof(o) + sizeof(ia));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1019 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1020 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1021
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1022 /* Update the total option lenth. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1023 ia_na_len = htons(ia_na_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1024 memcpy(o_lenp, &ia_na_len, sizeof(ia_na_len));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1025 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1026
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1027 if (state->send->type != DHCP6_RELEASE &&
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1028 state->send->type != DHCP6_DECLINE &&
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1029 n_options)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1030 {
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1031 o_lenp = NEXTLEN;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1032 o.len = 0;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1033 COPYIN1(D6_OPTION_ORO, 0);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1034 for (l = 0, opt = ifp->ctx->dhcp6_opts;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1035 l < ifp->ctx->dhcp6_opts_len;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1036 l++, opt++)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1037 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1038 #ifndef SMALL
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1039 for (n = 0, opt2 = ifo->dhcp6_override;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1040 n < ifo->dhcp6_override_len;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1041 n++, opt2++)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1042 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1043 if (opt->option == opt2->option)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1044 break;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1045 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1046 if (n < ifo->dhcp6_override_len)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1047 continue;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1048 #endif
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1049 if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1050 continue;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1051 o.code = htons((uint16_t)opt->option);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1052 memcpy(p, &o.code, sizeof(o.code));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1053 p += sizeof(o.code);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1054 o.len = (uint16_t)(o.len + sizeof(o.code));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1055 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1056 #ifndef SMALL
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1057 for (l = 0, opt = ifo->dhcp6_override;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1058 l < ifo->dhcp6_override_len;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1059 l++, opt++)
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1060 {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1061 if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1062 continue;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1063 o.code = htons((uint16_t)opt->option);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1064 memcpy(p, &o.code, sizeof(o.code));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1065 p += sizeof(o.code);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1066 o.len = (uint16_t)(o.len + sizeof(o.code));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1067 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1068 if (dhcp6_findselfsla(ifp)) {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1069 o.code = htons(D6_OPTION_PD_EXCLUDE);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1070 memcpy(p, &o.code, sizeof(o.code));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1071 p += sizeof(o.code);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1072 o.len = (uint16_t)(o.len + sizeof(o.code));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1073 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1074 #endif
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1075 o.len = htons(o.len);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1076 memcpy(o_lenp, &o.len, sizeof(o.len));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1077 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1078
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1079 si_len = 0;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1080 COPYIN(D6_OPTION_ELAPSED, &si_len, sizeof(si_len));
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1081
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1082 if (state->state == DH6S_DISCOVER &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1083 !(ifp->ctx->options & DHCPCD_TEST) &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1084 DHC_REQ(ifo->requestmask6, ifo->nomask6, D6_OPTION_RAPID_COMMIT))
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1085 COPYIN1(D6_OPTION_RAPID_COMMIT, 0);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1086
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1087 if (!has_option_mask(ifo->nomask6, D6_OPTION_USER_CLASS))
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1088 p += dhcp6_makeuser(p, ifp);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1089 if (!has_option_mask(ifo->nomask6, D6_OPTION_VENDOR_CLASS))
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1090 p += dhcp6_makevendor(p, ifp);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1091
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1092 if (state->send->type != DHCP6_RELEASE &&
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1093 state->send->type != DHCP6_DECLINE)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1094 {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1095 if (fqdn != FQDN_DISABLE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1096 o_lenp = NEXTLEN;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1097 COPYIN1(D6_OPTION_FQDN, 0);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1098 if (hl == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1099 *p = D6_FQDN_NONE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1100 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1101 switch (fqdn) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1102 case FQDN_BOTH:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1103 *p = D6_FQDN_BOTH;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1104 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1105 case FQDN_PTR:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1106 *p = D6_FQDN_PTR;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1107 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1108 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1109 *p = D6_FQDN_NONE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1110 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1111 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1112 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1113 p++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1114 encode_rfc1035(hostname, p);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1115 p += hl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1116 o.len = htons((uint16_t)(hl + 1));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1117 memcpy(o_lenp, &o.len, sizeof(o.len));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1118 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1119
4966
be0a1437525a DHCP6: Fix writing mudurl
Roy Marples <roy@marples.name>
parents: 4963
diff changeset
1120 if (!has_option_mask(ifo->nomask6, D6_OPTION_MUDURL) &&
be0a1437525a DHCP6: Fix writing mudurl
Roy Marples <roy@marples.name>
parents: 4963
diff changeset
1121 ifo->mudurl[0])
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1122 COPYIN(D6_OPTION_MUDURL,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1123 ifo->mudurl + 1, ifo->mudurl[0]);
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
1124
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
1125 #ifdef AUTH
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1126 if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) !=
4726
ac7d83882d52 DHCP: Don't send force renew none or reconf accept if not asked for
Roy Marples <roy@marples.name>
parents: 4724
diff changeset
1127 DHCPCD_AUTH_SENDREQUIRE &&
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1128 DHC_REQ(ifo->requestmask6, ifo->nomask6,
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
1129 D6_OPTION_RECONF_ACCEPT))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1130 COPYIN1(D6_OPTION_RECONF_ACCEPT, 0);
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
1131 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1132
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1133 }
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 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1136 /* This has to be the last option */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1137 if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1138 COPYIN1(D6_OPTION_AUTH, auth_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1139 /* data will be filled at send message time */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1140 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1141 #endif
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 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1144 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1145
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1146 static const char *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1147 dhcp6_get_op(uint16_t type)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1148 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1149 const struct dhcp6_op *d;
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 for (d = dhcp6_ops; d->name; d++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1152 if (d->type == type)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1153 return d->name;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1154 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1155 }
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 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1158 dhcp6_freedrop_addrs(struct interface *ifp, int drop,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1159 const struct interface *ifd)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1160 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1161 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1162
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1163 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1164 if (state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1165 ipv6_freedrop_addrs(&state->addrs, drop, ifd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1166 if (drop)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1167 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
1168 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1169 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1170
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1171 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1172 static void dhcp6_delete_delegates(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
1173 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1174 struct interface *ifp0;
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 if (ifp->ctx->ifaces) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1177 TAILQ_FOREACH(ifp0, 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
1178 if (ifp0 != ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1179 dhcp6_freedrop_addrs(ifp0, 1, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1180 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1181 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1182 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1183 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1184
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1185 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1186 static ssize_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1187 dhcp6_update_auth(struct interface *ifp, struct dhcp6_message *m, 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
1188 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1189 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1190 uint8_t *opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1191 uint16_t opt_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1192
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1193 opt = dhcp6_findmoption(m, len, D6_OPTION_AUTH, &opt_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1194 if (opt == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1195 return -1;
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 state = D6_STATE(ifp);
5299
b7e676ac73c1 privsep: Access the RDM monotic file via IPC
Roy Marples <roy@marples.name>
parents: 5294
diff changeset
1198 return dhcp_auth_encode(ifp->ctx, &ifp->options->auth,
b7e676ac73c1 privsep: Access the RDM monotic file via IPC
Roy Marples <roy@marples.name>
parents: 5294
diff changeset
1199 state->auth.token, (uint8_t *)state->send, state->send_len, 6,
b7e676ac73c1 privsep: Access the RDM monotic file via IPC
Roy Marples <roy@marples.name>
parents: 5294
diff changeset
1200 state->send->type, opt, opt_len);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1201 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1202 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1203
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1204 static const struct in6_addr alldhcp = IN6ADDR_LINKLOCAL_ALLDHCP_INIT;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1205 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1206 dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1207 {
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1208 struct dhcp6_state *state = D6_STATE(ifp);
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1209 struct dhcpcd_ctx *ctx = ifp->ctx;
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1210 unsigned int RT;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1211 bool broadcast = true;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1212 struct sockaddr_in6 dst = {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1213 .sin6_family = AF_INET6,
5236
40c8b6fa2033 Linux: workaround a kernel bug when sending DHCPv6 over SOCK_RAW
Roy Marples <roy@marples.name>
parents: 5234
diff changeset
1214 /* Setting the port on Linux gives EINVAL when sending.
40c8b6fa2033 Linux: workaround a kernel bug when sending DHCPv6 over SOCK_RAW
Roy Marples <roy@marples.name>
parents: 5234
diff changeset
1215 * This looks like a kernel bug as the equivalent works
40c8b6fa2033 Linux: workaround a kernel bug when sending DHCPv6 over SOCK_RAW
Roy Marples <roy@marples.name>
parents: 5234
diff changeset
1216 * fine with the DHCP counterpart. */
40c8b6fa2033 Linux: workaround a kernel bug when sending DHCPv6 over SOCK_RAW
Roy Marples <roy@marples.name>
parents: 5234
diff changeset
1217 #ifndef __linux__
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1218 .sin6_port = htons(DHCP6_SERVER_PORT),
5236
40c8b6fa2033 Linux: workaround a kernel bug when sending DHCPv6 over SOCK_RAW
Roy Marples <roy@marples.name>
parents: 5234
diff changeset
1219 #endif
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1220 };
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1221 struct udphdr udp = {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1222 .uh_sport = htons(DHCP6_CLIENT_PORT),
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1223 .uh_dport = htons(DHCP6_SERVER_PORT),
5234
bcd021398c1d Fix compile on Linux
Roy Marples <roy@marples.name>
parents: 5231
diff changeset
1224 .uh_ulen = htons((uint16_t)(sizeof(udp) + state->send_len)),
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1225 };
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1226 struct iovec iov[] = {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1227 { .iov_base = &udp, .iov_len = sizeof(udp), },
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1228 { .iov_base = state->send, .iov_len = state->send_len, },
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1229 };
5172
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
1230 union {
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
1231 struct cmsghdr hdr;
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
1232 uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
1233 } cmsgbuf = { .buf = { 0 } };
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1234 struct msghdr msg = {
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1235 .msg_name = &dst, .msg_namelen = sizeof(dst),
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1236 .msg_iov = iov, .msg_iovlen = __arraycount(iov),
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1237 };
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1238 char uaddr[INET6_ADDRSTRLEN];
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1239
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
1240 if (!callback && !if_is_link_up(ifp))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1241 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1242
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1243 if (!IN6_IS_ADDR_UNSPECIFIED(&state->unicast)) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1244 switch (state->send->type) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1245 case DHCP6_SOLICIT: /* FALLTHROUGH */
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1246 case DHCP6_CONFIRM: /* FALLTHROUGH */
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1247 case DHCP6_REBIND:
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1248 /* Unicasting is denied for these types. */
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1249 break;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1250 default:
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1251 broadcast = false;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1252 inet_ntop(AF_INET6, &state->unicast, uaddr,
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1253 sizeof(uaddr));
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1254 break;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1255 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1256 }
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1257 dst.sin6_addr = broadcast ? alldhcp : state->unicast;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1258
4963
c15d5bf525c1 DHCP6: Fix a bogus compile warning
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
1259 if (!callback) {
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1260 logdebugx("%s: %s %s with xid 0x%02x%02x%02x%s%s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1261 ifp->name,
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1262 broadcast ? "broadcasting" : "unicasting",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1263 dhcp6_get_op(state->send->type),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1264 state->send->xid[0],
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1265 state->send->xid[1],
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1266 state->send->xid[2],
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1267 !broadcast ? " " : "",
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1268 !broadcast ? uaddr : "");
4963
c15d5bf525c1 DHCP6: Fix a bogus compile warning
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
1269 RT = 0;
c15d5bf525c1 DHCP6: Fix a bogus compile warning
Roy Marples <roy@marples.name>
parents: 4958
diff changeset
1270 } else {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1271 if (state->IMD &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1272 !(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
1273 state->IMD = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1274 if (state->IMD) {
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1275 state->RT = state->IMD * MSEC_PER_SEC;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1276 /* Some buggy PPP servers close the link too early
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1277 * after sending an invalid status in their reply
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1278 * which means this host won't see it.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1279 * 1 second grace seems to be the sweet spot. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1280 if (ifp->flags & IFF_POINTOPOINT)
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1281 state->RT += MSEC_PER_SEC;
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1282 } else if (state->RTC == 0)
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1283 state->RT = state->IRT * MSEC_PER_SEC;
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1284
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1285 if (state->MRT != 0) {
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1286 unsigned int mrt = state->MRT * MSEC_PER_SEC;
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1287
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1288 if (state->RT > mrt)
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1289 state->RT = mrt;
3932
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
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1292 /* Add -.1 to .1 * RT randomness as per RFC8415 section 15 */
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1293 uint32_t lru = arc4random_uniform(
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1294 state->RTC == 0 ? DHCP6_RAND_MAX
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1295 : DHCP6_RAND_MAX - DHCP6_RAND_MIN);
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1296 int lr = (int)lru - (state->RTC == 0 ? 0 : DHCP6_RAND_MAX);
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1297 RT = state->RT
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1298 + (unsigned int)((float)state->RT
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1299 * ((float)lr / DHCP6_RAND_DIV));
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1300
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
1301 if (if_is_link_up(ifp))
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1302 logdebugx("%s: %s %s (xid 0x%02x%02x%02x)%s%s,"
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1303 " next in %0.1f seconds",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1304 ifp->name,
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1305 state->IMD != 0 ? "delaying" :
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1306 broadcast ? "broadcasting" : "unicasting",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1307 dhcp6_get_op(state->send->type),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1308 state->send->xid[0],
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1309 state->send->xid[1],
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1310 state->send->xid[2],
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1311 state->IMD == 0 && !broadcast ? " " : "",
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1312 state->IMD == 0 && !broadcast ? uaddr : "",
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1313 (float)RT / MSEC_PER_SEC);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1314
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1315 /* Wait the initial delay */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1316 if (state->IMD != 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1317 state->IMD = 0;
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1318 eloop_timeout_add_msec(ctx->eloop, RT, callback, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1319 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1320 }
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
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
1323 if (!if_is_link_up(ifp))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1324 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1325
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1326 /* Update the elapsed time */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1327 dhcp6_updateelapsed(ifp, state->send, state->send_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1328 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1329 if (ifp->options->auth.options & DHCPCD_AUTH_SEND &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1330 dhcp6_update_auth(ifp, state->send, state->send_len) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1331 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1332 logerr("%s: %s: dhcp6_updateauth", __func__, 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
1333 if (errno != ESRCH)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1334 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1335 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1336 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1337
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1338 /* Set the outbound interface */
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1339 if (broadcast) {
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1340 struct cmsghdr *cm;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1341 struct in6_pktinfo pi = { .ipi6_ifindex = ifp->index };
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1342
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1343 dst.sin6_scope_id = ifp->index;
5172
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
1344 msg.msg_control = cmsgbuf.buf;
6efcf294d3a0 Align more CMSG foo.
Roy Marples <roy@marples.name>
parents: 5171
diff changeset
1345 msg.msg_controllen = sizeof(cmsgbuf.buf);
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
1346 cm = CMSG_FIRSTHDR(&msg);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1347 if (cm == NULL) /* unlikely */
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1348 return -1;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1349 cm->cmsg_level = IPPROTO_IPV6;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1350 cm->cmsg_type = IPV6_PKTINFO;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1351 cm->cmsg_len = CMSG_LEN(sizeof(pi));
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1352 memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
1353 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1354
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1355 #ifdef PRIVSEP
4869
5bad3606b951 privsep: prefer IN_PRIVSEP macros
Roy Marples <roy@marples.name>
parents: 4841
diff changeset
1356 if (IN_PRIVSEP(ifp->ctx)) {
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1357 if (ps_inet_senddhcp6(ifp, &msg) == -1)
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1358 logerr(__func__);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1359 goto sent;
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1360 }
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1361 #endif
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1362
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
1363 if (sendmsg(ctx->dhcp6_wfd, &msg, 0) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1364 logerr("%s: %s: sendmsg", __func__, 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
1365 /* Allow DHCPv6 to continue .... the errors
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1366 * would be rate limited by the protocol.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1367 * 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
1368 * 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
1369 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1370
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1371 #ifdef PRIVSEP
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1372 sent:
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
1373 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1374 state->RTC++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1375 if (callback) {
4942
fc102732fa9c DHCP6: Only set RT to state with callbacks.
Roy Marples <roy@marples.name>
parents: 4939
diff changeset
1376 state->RT = RT * 2;
fc102732fa9c DHCP6: Only set RT to state with callbacks.
Roy Marples <roy@marples.name>
parents: 4939
diff changeset
1377 if (state->RT < RT) /* Check overflow */
fc102732fa9c DHCP6: Only set RT to state with callbacks.
Roy Marples <roy@marples.name>
parents: 4939
diff changeset
1378 state->RT = RT;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1379 if (state->MRC == 0 || state->RTC < state->MRC)
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1380 eloop_timeout_add_msec(ctx->eloop,
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1381 RT, callback, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1382 else if (state->MRC != 0 && state->MRCcallback)
4925
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1383 eloop_timeout_add_msec(ctx->eloop,
74b140568feb DHCP6: Calulate ReTransmission using milliseconds
Roy Marples <roy@marples.name>
parents: 4924
diff changeset
1384 RT, state->MRCcallback, ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1385 else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1386 logwarnx("%s: sent %d times with no reply",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1387 ifp->name, state->RTC);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1388 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1389 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1390 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1391
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1392 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1393 dhcp6_sendinform(void *arg)
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
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1396 dhcp6_sendmessage(arg, dhcp6_sendinform);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1397 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1398
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1399 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1400 dhcp6_senddiscover(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1401 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1402
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1403 dhcp6_sendmessage(arg, dhcp6_senddiscover);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1404 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1405
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1406 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1407 dhcp6_sendrequest(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1408 {
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 dhcp6_sendmessage(arg, dhcp6_sendrequest);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1411 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1412
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1413 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1414 dhcp6_sendrebind(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1415 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1416
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1417 dhcp6_sendmessage(arg, dhcp6_sendrebind);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1418 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1419
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1420 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1421 dhcp6_sendrenew(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1422 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1423
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1424 dhcp6_sendmessage(arg, dhcp6_sendrenew);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1425 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1426
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1427 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1428 dhcp6_sendconfirm(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1429 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1430
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1431 dhcp6_sendmessage(arg, dhcp6_sendconfirm);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1432 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1433
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1434 static void
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1435 dhcp6_senddecline(void *arg)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1436 {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1437
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1438 dhcp6_sendmessage(arg, dhcp6_senddecline);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1439 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1440
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1441 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
1442 dhcp6_sendrelease(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1443 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1444
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1445 dhcp6_sendmessage(arg, dhcp6_sendrelease);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1446 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1447
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1448 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1449 dhcp6_startrenew(void *arg)
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 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
1452 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1453
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1454 ifp = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1455 if ((state = D6_STATE(ifp)) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1456 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1457
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1458 /* Only renew in the bound or renew states */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1459 if (state->state != DH6S_BOUND &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1460 state->state != DH6S_RENEW)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1461 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1462
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1463 /* Remove the timeout as the renew may have been forced. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1464 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_startrenew, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1465
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1466 state->state = DH6S_RENEW;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1467 state->RTC = 0;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1468 state->IMD = REN_MAX_DELAY;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1469 state->IRT = REN_TIMEOUT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1470 state->MRT = REN_MAX_RT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1471 state->MRC = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1472
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1473 if (dhcp6_makemessage(ifp) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1474 logerr("%s: %s", __func__, 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
1475 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1476 dhcp6_sendrenew(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1477 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1478
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1479 void dhcp6_renew(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
1480 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1481
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1482 dhcp6_startrenew(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1483 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1484
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1485 bool
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1486 dhcp6_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
1487 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1488 const struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1489 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
1490
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1491 state = D6_CSTATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1492 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1493 if (ap->flags & IPV6_AF_ADDED &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1494 !(ap->flags & IPV6_AF_DADCOMPLETED))
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1495 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
1496 }
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
1497 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
1498 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1499
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1500 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1501 dhcp6_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
1502 {
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1503 struct ipv6_addr *ia = arg;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1504 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
1505 struct dhcp6_state *state;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1506 struct ipv6_addr *ia2;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1507 bool completed, valid, oneduplicated;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1508
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1509 completed = (ia->flags & IPV6_AF_DADCOMPLETED);
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1510 ia->flags |= IPV6_AF_DADCOMPLETED;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1511 if (ia->addr_flags & IN6_IFF_DUPLICATED)
4116
bbc873111f06 More ap -> ia
Roy Marples <roy@marples.name>
parents: 4112
diff changeset
1512 logwarnx("%s: DAD detected %s", ia->iface->name, ia->saddr);
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1513
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1514 #ifdef ND6_ADVERTISE
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1515 else
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1516 ipv6nd_advertise(ia);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1517 #endif
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1518 if (completed)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1519 return;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1520
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1521 ifp = ia->iface;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1522 state = D6_STATE(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1523 if (state->state != DH6S_BOUND && state->state != DH6S_DELEGATED)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1524 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1525
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
1526 #ifdef SMALL
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1527 valid = true;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
1528 #else
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1529 valid = (ia->delegating_prefix == NULL);
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
1530 #endif
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1531 completed = true;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1532 oneduplicated = false;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1533 TAILQ_FOREACH(ia2, &state->addrs, next) {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1534 if (ia2->flags & IPV6_AF_ADDED &&
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1535 !(ia2->flags & IPV6_AF_DADCOMPLETED))
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1536 {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1537 completed = false;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1538 break;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1539 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1540 if (DECLINE_IA(ia))
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1541 oneduplicated = true;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1542 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1543 if (!completed)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1544 return;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1545
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1546 logdebugx("%s: DHCPv6 DAD completed", ifp->name);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1547
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1548 if (oneduplicated && state->state == DH6S_BOUND) {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1549 dhcp6_startdecline(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1550 return;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1551 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1552
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1553 script_runreason(ifp,
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
1554 #ifndef SMALL
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1555 ia->delegating_prefix ? "DELEGATED6" :
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
1556 #endif
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1557 state->reason);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1558 if (valid)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1559 dhcpcd_daemonise(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
1560 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1561
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1562 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1563 dhcp6_addrequestedaddrs(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
1564 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1565 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1566 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
1567 struct if_ia *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1568 struct ipv6_addr *a;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1569
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1570 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1571 /* Add any requested prefixes / addresses */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1572 for (i = 0; i < ifp->options->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1573 ia = &ifp->options->ia[i];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1574 if (!((ia->ia_type == D6_OPTION_IA_PD && ia->prefix_len) ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1575 !IN6_IS_ADDR_UNSPECIFIED(&ia->addr)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1576 continue;
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1577 a = ipv6_newaddr(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
1578 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1579 * RFC 5942 Section 5
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1580 * We cannot assume any prefix length, nor tie the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1581 * address to an existing one as it could expire
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1582 * before the address.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1583 * As such we just give it a 128 prefix.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1584 */
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1585 ia->ia_type == D6_OPTION_IA_PD ? ia->prefix_len : 128,
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1586 IPV6_AF_REQUEST);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1587 if (a == NULL)
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1588 continue;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1589 a->dadcallback = dhcp6_dadcallback;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1590 memcpy(&a->iaid, &ia->iaid, sizeof(a->iaid));
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
1591 a->ia_type = ia->ia_type;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1592 TAILQ_INSERT_TAIL(&state->addrs, a, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1593 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1594 }
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 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1597 dhcp6_startdiscover(void *arg)
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 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
1600 struct dhcp6_state *state;
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1601 int llevel;
3932
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 ifp = arg;
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1604 state = D6_STATE(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1605 #ifndef SMALL
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1606 if (state->reason == NULL || strcmp(state->reason, "TIMEOUT6") != 0)
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1607 dhcp6_delete_delegates(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1608 #endif
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1609 if (state->new == NULL && !state->failed)
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1610 llevel = LOG_INFO;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1611 else
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1612 llevel = LOG_DEBUG;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1613 logmessage(llevel, "%s: soliciting a DHCPv6 lease", 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
1614 state->state = DH6S_DISCOVER;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1615 state->RTC = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1616 state->IMD = SOL_MAX_DELAY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1617 state->IRT = SOL_TIMEOUT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1618 state->MRT = state->sol_max_rt;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1619 state->MRC = SOL_MAX_RC;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1620
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1621 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
1622 free(state->new);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1623 state->new = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1624 state->new_len = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1625
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1626 if (dhcp6_makemessage(ifp) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1627 logerr("%s: %s", __func__, 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
1628 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1629 dhcp6_senddiscover(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1630 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1631
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1632 static void
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1633 dhcp6_startinform(void *arg)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1634 {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1635 struct interface *ifp;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1636 struct dhcp6_state *state;
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1637 int llevel;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1638
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1639 ifp = arg;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1640 state = D6_STATE(ifp);
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1641 if (state->new == NULL && !state->failed)
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1642 llevel = LOG_INFO;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1643 else
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1644 llevel = LOG_DEBUG;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1645 logmessage(llevel, "%s: requesting DHCPv6 information", ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1646 state->state = DH6S_INFORM;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1647 state->RTC = 0;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1648 state->IMD = INF_MAX_DELAY;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1649 state->IRT = INF_TIMEOUT;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1650 state->MRT = state->inf_max_rt;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1651 state->MRC = 0;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1652
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1653 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1654 if (dhcp6_makemessage(ifp) == -1) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1655 logerr("%s: %s", __func__, ifp->name);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1656 return;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1657 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1658 dhcp6_sendinform(ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1659 /* RFC3315 18.1.2 says that if CONFIRM failed then the prior addresses
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1660 * SHOULD be used. The wording here is poor, because the addresses are
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1661 * merely one facet of the lease as a whole.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1662 * This poor wording might explain the lack of similar text for INFORM
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1663 * in 18.1.5 because there are no addresses in the INFORM message. */
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1664 eloop_timeout_add_sec(ifp->ctx->eloop,
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1665 INF_MAX_RD, dhcp6_failinform, ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1666 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1667
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1668 static bool
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1669 dhcp6_startdiscoinform(struct interface *ifp)
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1670 {
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1671 unsigned long long opts = ifp->options->options;
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1672
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1673 if (opts & DHCPCD_IA_FORCED || ipv6nd_hasradhcp(ifp, true))
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1674 dhcp6_startdiscover(ifp);
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1675 else if (opts & DHCPCD_INFORM6 || ipv6nd_hasradhcp(ifp, false))
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1676 dhcp6_startinform(ifp);
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1677 else
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1678 return false;
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1679 return true;
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1680 }
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1681
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1682 static void
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1683 dhcp6_leaseextend(struct interface *ifp)
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1684 {
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1685 struct dhcp6_state *state = D6_STATE(ifp);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1686 struct ipv6_addr *ia;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1687
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1688 logwarnx("%s: extending DHCPv6 lease", ifp->name);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1689 TAILQ_FOREACH(ia, &state->addrs, next) {
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1690 ia->flags |= IPV6_AF_EXTENDED;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1691 /* Set infinite lifetimes. */
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1692 ia->prefix_pltime = ND6_INFINITE_LIFETIME;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1693 ia->prefix_vltime = ND6_INFINITE_LIFETIME;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1694 }
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1695 }
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1696
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1697 static void
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1698 dhcp6_fail(struct interface *ifp)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1699 {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1700 struct dhcp6_state *state = D6_STATE(ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1701
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1702 state->failed = true;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1703
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1704 /* RFC3315 18.1.2 says that prior addresses SHOULD be used on failure.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1705 * RFC2131 3.2.3 says that MAY chose to use the prior address.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1706 * Because dhcpcd was written first for RFC2131, we have the LASTLEASE
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1707 * option which defaults to off as that makes the most sense for
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1708 * mobile clients.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1709 * dhcpcd also has LASTLEASE_EXTEND to extend this lease past it's
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1710 * expiry, but this is strictly not RFC compliant in any way or form. */
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1711 if (state->new != NULL &&
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1712 ifp->options->options & DHCPCD_LASTLEASE_EXTEND)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1713 {
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1714 dhcp6_leaseextend(ifp);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1715 dhcp6_bind(ifp, NULL, NULL);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1716 } else {
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1717 dhcp6_freedrop_addrs(ifp, 1, NULL);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1718 #ifndef SMALL
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1719 dhcp6_delete_delegates(ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1720 #endif
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1721 free(state->old);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1722 state->old = state->new;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1723 state->old_len = state->new_len;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1724 state->new = NULL;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1725 state->new_len = 0;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1726 if (state->old != NULL)
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1727 script_runreason(ifp, "EXPIRE6");
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
1728 dhcp_unlink(ifp->ctx, state->leasefile);
5357
2ddfb6841ebb DHCP6: Add requested addresses after freeing all state addresses
Roy Marples <roy@marples.name>
parents: 5299
diff changeset
1729 dhcp6_addrequestedaddrs(ifp);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1730 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1731
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
1732 if (!dhcp6_startdiscoinform(ifp)) {
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1733 logwarnx("%s: no advertising IPv6 router wants DHCP",ifp->name);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1734 state->state = DH6S_INIT;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1735 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1736 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1737 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1738
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1739 static int
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1740 dhcp6_failloglevel(struct interface *ifp)
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1741 {
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1742 const struct dhcp6_state *state = D6_CSTATE(ifp);
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1743
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1744 return state->failed ? LOG_DEBUG : LOG_ERR;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1745 }
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1746
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1747 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
1748 dhcp6_failconfirm(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1749 {
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1750 struct interface *ifp = arg;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1751 int llevel = dhcp6_failloglevel(ifp);
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1752
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1753 logmessage(llevel, "%s: failed to confirm prior DHCPv6 address",
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1754 ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1755 dhcp6_fail(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1756 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1757
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1758 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1759 dhcp6_failrequest(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1760 {
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1761 struct interface *ifp = arg;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1762 int llevel = dhcp6_failloglevel(ifp);
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1763
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1764 logmessage(llevel, "%s: failed to request DHCPv6 address", ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1765 dhcp6_fail(ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1766 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1767
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1768 static void
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1769 dhcp6_failinform(void *arg)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1770 {
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1771 struct interface *ifp = arg;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1772 int llevel = dhcp6_failloglevel(ifp);
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1773
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1774 logmessage(llevel, "%s: failed to request DHCPv6 information",
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1775 ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1776 dhcp6_fail(ifp);
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
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1779 #ifndef SMALL
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1780 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1781 dhcp6_failrebind(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1782 {
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1783 struct interface *ifp = arg;
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1784
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
1785 logerrx("%s: failed to rebind prior DHCPv6 delegation", ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1786 dhcp6_fail(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1787 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1788
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1789 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1790 dhcp6_hasprefixdelegation(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
1791 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1792 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
1793 uint16_t t;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1794
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1795 t = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1796 for (i = 0; i < ifp->options->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1797 if (t && t != ifp->options->ia[i].ia_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1798 if (t == D6_OPTION_IA_PD ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1799 ifp->options->ia[i].ia_type == D6_OPTION_IA_PD)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1800 return 2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1801 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1802 t = ifp->options->ia[i].ia_type;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1803 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1804 return t == D6_OPTION_IA_PD ? 1 : 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1805 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1806 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1807
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1808 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1809 dhcp6_startrebind(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1810 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1811 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
1812 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1813 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1814 int pd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1815 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1816
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1817 ifp = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1818 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrenew, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1819 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1820 if (state->state == DH6S_RENEW)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1821 logwarnx("%s: failed to renew DHCPv6, rebinding", 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
1822 else
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
1823 loginfox("%s: rebinding prior DHCPv6 lease", 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
1824 state->state = DH6S_REBIND;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1825 state->RTC = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1826 state->MRC = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1827
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1828 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1829 /* RFC 3633 section 12.1 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1830 pd = dhcp6_hasprefixdelegation(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1831 if (pd) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1832 state->IMD = CNF_MAX_DELAY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1833 state->IRT = CNF_TIMEOUT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1834 state->MRT = CNF_MAX_RT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1835 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1836 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1837 {
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1838 state->IMD = REB_MAX_DELAY;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1839 state->IRT = REB_TIMEOUT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1840 state->MRT = REB_MAX_RT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1841 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1842
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1843 if (dhcp6_makemessage(ifp) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1844 logerr("%s: %s", __func__, 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
1845 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1846 dhcp6_sendrebind(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1847
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1848 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1849 /* RFC 3633 section 12.1 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1850 if (pd)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1851 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
1852 CNF_MAX_RD, dhcp6_failrebind, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1853 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1854 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1855
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1856
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1857 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1858 dhcp6_startrequest(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
1859 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1860 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1861
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1862 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_senddiscover, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1863 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1864 state->state = DH6S_REQUEST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1865 state->RTC = 0;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1866 state->IMD = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1867 state->IRT = REQ_TIMEOUT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1868 state->MRT = REQ_MAX_RT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1869 state->MRC = REQ_MAX_RC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1870 state->MRCcallback = dhcp6_failrequest;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1871
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1872 if (dhcp6_makemessage(ifp) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1873 logerr("%s: %s", __func__, 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
1874 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1875 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1876
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1877 dhcp6_sendrequest(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1878 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1879
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1880 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1881 dhcp6_startconfirm(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
1882 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1883 struct dhcp6_state *state;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1884 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
1885
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1886 state = D6_STATE(ifp);
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1887
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1888 TAILQ_FOREACH(ia, &state->addrs, next) {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1889 if (!DECLINE_IA(ia))
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1890 continue;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1891 logerrx("%s: prior DHCPv6 has a duplicated address", ifp->name);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1892 dhcp6_startdecline(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1893 return;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1894 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1895
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1896 state->state = DH6S_CONFIRM;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1897 state->RTC = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1898 state->IMD = CNF_MAX_DELAY;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1899 state->IRT = CNF_TIMEOUT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1900 state->MRT = CNF_MAX_RT;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1901 state->MRC = CNF_MAX_RC;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1902
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
1903 loginfox("%s: confirming prior DHCPv6 lease", ifp->name);
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1904
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1905 if (dhcp6_makemessage(ifp) == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1906 logerr("%s: %s", __func__, 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
1907 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1908 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1909 dhcp6_sendconfirm(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1910 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
1911 CNF_MAX_RD, dhcp6_failconfirm, ifp);
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 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1915 dhcp6_startexpire(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1916 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1917 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
1918
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1919 ifp = arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1920 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrebind, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1921
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1922 logerrx("%s: DHCPv6 lease expired", ifp->name);
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
1923 dhcp6_fail(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1924 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1925
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1926 static void
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1927 dhcp6_faildecline(void *arg)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1928 {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1929 struct interface *ifp = arg;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1930
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1931 logerrx("%s: failed to decline duplicated DHCPv6 addresses", ifp->name);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1932 dhcp6_fail(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1933 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1934
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1935 static void
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1936 dhcp6_startdecline(struct interface *ifp)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1937 {
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1938 struct dhcp6_state *state;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1939
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1940 state = D6_STATE(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1941 loginfox("%s: declining failed DHCPv6 addresses", ifp->name);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1942 state->state = DH6S_DECLINE;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1943 state->RTC = 0;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1944 state->IMD = 0;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1945 state->IRT = DEC_TIMEOUT;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1946 state->MRT = 0;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1947 state->MRC = DEC_MAX_RC;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1948 state->MRCcallback = dhcp6_faildecline;
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1949
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1950 if (dhcp6_makemessage(ifp) == -1)
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1951 logerr("%s: %s", __func__, ifp->name);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1952 else
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1953 dhcp6_senddecline(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1954 }
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1955
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
1956 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
1957 dhcp6_finishrelease(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1958 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1959 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
1960 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1961
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1962 ifp = (struct interface *)arg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1963 if ((state = D6_STATE(ifp)) != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1964 state->state = DH6S_RELEASED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1965 dhcp6_drop(ifp, "RELEASE6");
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1966 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1967 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1968
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1969 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1970 dhcp6_startrelease(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
1971 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1972 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1973
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1974 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1975 if (state->state != DH6S_BOUND)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1976 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1977
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1978 state->state = DH6S_RELEASE;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1979 state->RTC = 0;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1980 state->IMD = REL_MAX_DELAY;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1981 state->IRT = REL_TIMEOUT;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
1982 state->MRT = REL_MAX_RT;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1983 /* MRC of REL_MAX_RC is optional in RFC 3315 18.1.6 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1984 #if 0
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1985 state->MRC = REL_MAX_RC;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1986 state->MRCcallback = dhcp6_finishrelease;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1987 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1988 state->MRC = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1989 state->MRCcallback = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1990 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1991
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1992 if (dhcp6_makemessage(ifp) == -1)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
1993 logerr("%s: %s", __func__, 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
1994 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1995 dhcp6_sendrelease(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1996 dhcp6_finishrelease(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1997 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1998 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
1999
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2000 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2001 dhcp6_checkstatusok(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
2002 struct dhcp6_message *m, uint8_t *p, 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
2003 {
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2004 struct dhcp6_state *state;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2005 uint8_t *opt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2006 uint16_t opt_len, code;
4247
22a5ac71f5c8 dhcp6: fix a potential string termination error on status messages
Roy Marples <roy@marples.name>
parents: 4233
diff changeset
2007 size_t mlen;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2008 void * (*f)(void *, size_t, uint16_t, uint16_t *), *farg;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2009 char buf[32], *sbuf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2010 const char *status;
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2011 int loglevel;
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2012
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2013 state = D6_STATE(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2014 f = p ? dhcp6_findoption : dhcp6_findmoption;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2015 if (p)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2016 farg = p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2017 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2018 farg = m;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2019 if ((opt = f(farg, len, D6_OPTION_STATUS_CODE, &opt_len)) == NULL) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2020 //logdebugx("%s: no status", ifp->name);
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2021 state->lerror = 0;
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2022 errno = ESRCH;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2023 return 0;
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 if (opt_len < sizeof(code)) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2027 logerrx("%s: status truncated", 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
2028 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2029 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2030 memcpy(&code, opt, sizeof(code));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2031 code = ntohs(code);
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2032 if (code == D6_STATUS_OK) {
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2033 state->lerror = 0;
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2034 errno = 0;
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2035 return 0;
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2036 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2037
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2038 /* Anything after the code is a message. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2039 opt += sizeof(code);
4247
22a5ac71f5c8 dhcp6: fix a potential string termination error on status messages
Roy Marples <roy@marples.name>
parents: 4233
diff changeset
2040 mlen = opt_len - sizeof(code);
22a5ac71f5c8 dhcp6: fix a potential string termination error on status messages
Roy Marples <roy@marples.name>
parents: 4233
diff changeset
2041 if (mlen == 0) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2042 sbuf = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2043 if (code < sizeof(dhcp6_statuses) / sizeof(char *))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2044 status = dhcp6_statuses[code];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2045 else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2046 snprintf(buf, sizeof(buf), "Unknown Status (%d)", code);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2047 status = buf;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2048 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2049 } else {
4247
22a5ac71f5c8 dhcp6: fix a potential string termination error on status messages
Roy Marples <roy@marples.name>
parents: 4233
diff changeset
2050 if ((sbuf = malloc(mlen + 1)) == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2051 logerr(__func__);
4105
83dac3d51eae Fix processing of INFORM6 replies without an OK status code.
Roy Marples <roy@marples.name>
parents: 4090
diff changeset
2052 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
2053 }
4247
22a5ac71f5c8 dhcp6: fix a potential string termination error on status messages
Roy Marples <roy@marples.name>
parents: 4233
diff changeset
2054 memcpy(sbuf, opt, mlen);
22a5ac71f5c8 dhcp6: fix a potential string termination error on status messages
Roy Marples <roy@marples.name>
parents: 4233
diff changeset
2055 sbuf[mlen] = '\0';
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2056 status = sbuf;
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
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2059 if (state->lerror == code || state->state == DH6S_INIT)
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2060 loglevel = LOG_DEBUG;
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2061 else
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2062 loglevel = LOG_ERR;
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2063 logmessage(loglevel, "%s: DHCPv6 REPLY: %s", ifp->name, status);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2064 free(sbuf);
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
2065 state->lerror = code;
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2066 errno = 0;
5553
ef762d54fb7a DHCP6: Abort in test mode when an error is returned by server.
Roy Marples <roy@marples.name>
parents: 5535
diff changeset
2067
ef762d54fb7a DHCP6: Abort in test mode when an error is returned by server.
Roy Marples <roy@marples.name>
parents: 5535
diff changeset
2068 if (code != 0 && ifp->ctx->options & DHCPCD_TEST)
ef762d54fb7a DHCP6: Abort in test mode when an error is returned by server.
Roy Marples <roy@marples.name>
parents: 5535
diff changeset
2069 eloop_exit(ifp->ctx->eloop, EXIT_FAILURE);
ef762d54fb7a DHCP6: Abort in test mode when an error is returned by server.
Roy Marples <roy@marples.name>
parents: 5535
diff changeset
2070
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2071 return (int)code;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2072 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2073
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2074 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
2075 dhcp6_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: 4117
diff changeset
2076 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
2077 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2078 const struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2079 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
2080
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2081 if ((state = D6_STATE(ifp)) != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2082 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2083 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
2084 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2085 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2086 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2087 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2088 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2089
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2090 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
2091 dhcp6_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: 4117
diff changeset
2092 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
2093 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2094 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
2095 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
2096 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2097
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2098 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
2099 if ((state = D6_STATE(ifp)) != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2100 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2101 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
2102 return ap;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2103 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2104 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2105 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2106 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2107 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2108
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2109 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2110 dhcp6_findna(struct interface *ifp, uint16_t ot, const uint8_t *iaid,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2111 uint8_t *d, size_t l, const struct timespec *acquired)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2112 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2113 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2114 uint8_t *o, *nd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2115 uint16_t ol;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2116 struct ipv6_addr *a;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2117 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2118 struct dhcp6_ia_addr ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2119
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2120 i = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2121 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2122 while ((o = dhcp6_findoption(d, l, D6_OPTION_IA_ADDR, &ol))) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2123 /* Set d and l first to ensure we find the next option. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2124 nd = o + ol;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2125 l -= (size_t)(nd - d);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2126 d = nd;
4458
0e6212a4aa03 DHCPv6: Fix a potential buffer overflow reading NA/TA addresses
Roy Marples <roy@marples.name>
parents: 4423
diff changeset
2127 if (ol < sizeof(ia)) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2128 errno = EINVAL;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2129 logerrx("%s: IA Address option truncated", 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
2130 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2131 }
4458
0e6212a4aa03 DHCPv6: Fix a potential buffer overflow reading NA/TA addresses
Roy Marples <roy@marples.name>
parents: 4423
diff changeset
2132 memcpy(&ia, o, sizeof(ia));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2133 ia.pltime = ntohl(ia.pltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2134 ia.vltime = ntohl(ia.vltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2135 /* RFC 3315 22.6 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2136 if (ia.pltime > ia.vltime) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2137 errno = EINVAL;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2138 logerr("%s: IA Address pltime %"PRIu32
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2139 " > vltime %"PRIu32,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2140 ifp->name, ia.pltime, ia.vltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2141 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2142 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2143 TAILQ_FOREACH(a, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2144 if (ipv6_findaddrmatch(a, &ia.addr, 0))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2145 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2146 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2147 if (a == NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2148 /*
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2149 * RFC 5942 Section 5
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2150 * We cannot assume any prefix length, nor tie the
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2151 * address to an existing one as it could expire
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2152 * before the address.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2153 * As such we just give it a 128 prefix.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2154 */
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2155 a = ipv6_newaddr(ifp, &ia.addr, 128, IPV6_AF_ONLINK);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2156 a->dadcallback = dhcp6_dadcallback;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2157 a->ia_type = ot;
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2158 memcpy(a->iaid, iaid, sizeof(a->iaid));
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2159 a->created = *acquired;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2160
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2161 TAILQ_INSERT_TAIL(&state->addrs, a, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2162 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2163 if (!(a->flags & IPV6_AF_ONLINK))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2164 a->flags |= IPV6_AF_ONLINK | IPV6_AF_NEW;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2165 a->flags &= ~(IPV6_AF_STALE | IPV6_AF_EXTENDED);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2166 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2167 a->acquired = *acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2168 a->prefix_pltime = ia.pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2169 if (a->prefix_vltime != ia.vltime) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2170 a->flags |= IPV6_AF_NEW;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2171 a->prefix_vltime = ia.vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2172 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2173 if (a->prefix_pltime && a->prefix_pltime < state->lowpl)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2174 state->lowpl = a->prefix_pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2175 if (a->prefix_vltime && a->prefix_vltime > state->expire)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2176 state->expire = a->prefix_vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2177 i++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2178 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2179 return i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2180 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2181
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2182 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2183 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2184 dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2185 uint8_t *d, size_t l, const struct timespec *acquired)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2186 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2187 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2188 uint8_t *o, *nd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2189 struct ipv6_addr *a;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2190 int i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2191 uint8_t nb, *pw;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2192 uint16_t ol;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2193 struct dhcp6_pd_addr pdp;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2194 struct in6_addr pdp_prefix;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2195
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2196 i = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2197 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2198 while ((o = dhcp6_findoption(d, l, D6_OPTION_IAPREFIX, &ol))) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2199 /* Set d and l first to ensure we find the next option. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2200 nd = o + ol;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2201 l -= (size_t)(nd - d);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2202 d = nd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2203 if (ol < sizeof(pdp)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2204 errno = EINVAL;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2205 logerrx("%s: IA Prefix option truncated", 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
2206 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2207 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2208
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2209 memcpy(&pdp, o, sizeof(pdp));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2210 pdp.pltime = ntohl(pdp.pltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2211 pdp.vltime = ntohl(pdp.vltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2212 /* RFC 3315 22.6 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2213 if (pdp.pltime > pdp.vltime) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2214 errno = EINVAL;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2215 logerrx("%s: IA Prefix pltime %"PRIu32
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2216 " > vltime %"PRIu32,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2217 ifp->name, pdp.pltime, pdp.vltime);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2218 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2219 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2220
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2221 o += sizeof(pdp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2222 ol = (uint16_t)(ol - sizeof(pdp));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2223
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2224 /* pdp.prefix is not aligned so copy it out. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2225 memcpy(&pdp_prefix, &pdp.prefix, sizeof(pdp_prefix));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2226 TAILQ_FOREACH(a, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2227 if (IN6_ARE_ADDR_EQUAL(&a->prefix, &pdp_prefix))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2228 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2229 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2230
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2231 if (a == NULL) {
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2232 a = ipv6_newaddr(ifp, &pdp_prefix, pdp.prefix_len,
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2233 IPV6_AF_DELEGATEDPFX);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2234 if (a == NULL)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2235 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2236 a->created = *acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2237 a->dadcallback = dhcp6_dadcallback;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2238 a->ia_type = D6_OPTION_IA_PD;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2239 memcpy(a->iaid, iaid, sizeof(a->iaid));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2240 TAILQ_INSERT_TAIL(&state->addrs, a, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2241 } else {
4883
a6eeb584a437 DHCP6: Fix deprecating a delegated prefix
Roy Marples <roy@marples.name>
parents: 4877
diff changeset
2242 if (!(a->flags & IPV6_AF_DELEGATEDPFX))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2243 a->flags |= IPV6_AF_NEW | IPV6_AF_DELEGATEDPFX;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2244 a->flags &= ~(IPV6_AF_STALE |
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2245 IPV6_AF_EXTENDED |
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2246 IPV6_AF_REQUEST);
4193
a1772bc670f0 dhcp6: fix prefix delegations from spamming syslog
Roy Marples <roy@marples.name>
parents: 4192
diff changeset
2247 if (a->prefix_vltime != pdp.vltime)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2248 a->flags |= IPV6_AF_NEW;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2249 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2250
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2251 a->acquired = *acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2252 a->prefix_pltime = pdp.pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2253 a->prefix_vltime = pdp.vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2254
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2255 if (a->prefix_pltime && a->prefix_pltime < state->lowpl)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2256 state->lowpl = a->prefix_pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2257 if (a->prefix_vltime && a->prefix_vltime > state->expire)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2258 state->expire = a->prefix_vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2259 i++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2260
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2261 a->prefix_exclude_len = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2262 memset(&a->prefix_exclude, 0, sizeof(a->prefix_exclude));
4499
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2263 o = dhcp6_findoption(o, ol, D6_OPTION_PD_EXCLUDE, &ol);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2264 if (o == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2265 continue;
4499
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2266
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2267 /* RFC 6603 4.2 says option length MUST be between 2 and 17.
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2268 * This allows 1 octet for prefix length and 16 for the
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2269 * subnet ID. */
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2270 if (ol < 2 || ol > 17) {
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2271 logerrx("%s: invalid PD Exclude 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
2272 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2273 }
4499
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2274
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2275 /* RFC 6603 4.2 says prefix length MUST be between the
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2276 * length of the IAPREFIX prefix length + 1 and 128. */
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2277 if (*o < a->prefix_len + 1 || *o > 128) {
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2278 logerrx("%s: invalid PD Exclude length", ifp->name);
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2279 continue;
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2280 }
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2281
4509
78cdda45f5d9 DHCPv6: Fix exclude prefix length check.
Roy Marples <roy@marples.name>
parents: 4499
diff changeset
2282 ol--;
4499
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2283 /* Check option length matches prefix length. */
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2284 if (((*o - a->prefix_len - 1) / NBBY) + 1 != ol) {
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2285 logerrx("%s: PD Exclude length mismatch", ifp->name);
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2286 continue;
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2287 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2288 a->prefix_exclude_len = *o++;
4509
78cdda45f5d9 DHCPv6: Fix exclude prefix length check.
Roy Marples <roy@marples.name>
parents: 4499
diff changeset
2289
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2290 memcpy(&a->prefix_exclude, &a->prefix,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2291 sizeof(a->prefix_exclude));
4499
94b77a3ab52f DHCPv6: Fix a potential read overflow with D6_OPTION_PD_EXCLUDE
Roy Marples <roy@marples.name>
parents: 4464
diff changeset
2292 nb = a->prefix_len % NBBY;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2293 if (nb)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2294 ol--;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2295 pw = a->prefix_exclude.s6_addr +
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2296 (a->prefix_exclude_len / NBBY) - 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2297 while (ol-- > 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2298 *pw-- = *o++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2299 if (nb)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2300 *pw = (uint8_t)(*pw | (*o >> nb));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2301 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2302 return i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2303 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2304 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2305
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2306 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2307 dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2308 const char *sfrom, const struct timespec *acquired)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2309 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2310 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2311 const struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2312 struct dhcp6_option o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2313 uint8_t *d, *p;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2314 struct dhcp6_ia_na ia;
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2315 int i, e, error;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2316 size_t j;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2317 uint16_t nl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2318 uint8_t iaid[4];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2319 char buf[sizeof(iaid) * 3];
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2320 struct ipv6_addr *ap;
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
2321 struct if_ia *ifia;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2322
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2323 if (l < sizeof(*m)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2324 /* Should be impossible with guards at packet in
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2325 * and reading leases */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2326 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2327 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2328 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2329
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2330 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2331 i = e = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2332 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2333 TAILQ_FOREACH(ap, &state->addrs, next) {
4179
a996934a143b dhcp6: don't make delegated addresses stale
Roy Marples <roy@marples.name>
parents: 4178
diff changeset
2334 if (!(ap->flags & IPV6_AF_DELEGATED))
a996934a143b dhcp6: don't make delegated addresses stale
Roy Marples <roy@marples.name>
parents: 4178
diff changeset
2335 ap->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
2336 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2337
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2338 d = (uint8_t *)m + sizeof(*m);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2339 l -= sizeof(*m);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2340 while (l > sizeof(o)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2341 memcpy(&o, d, sizeof(o));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2342 o.len = ntohs(o.len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2343 if (o.len > l || sizeof(o) + o.len > l) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2344 errno = EINVAL;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2345 logerrx("%s: option overflow", 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
2346 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2347 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2348 p = d + sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2349 d = p + o.len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2350 l -= sizeof(o) + o.len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2351
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2352 o.code = ntohs(o.code);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2353 switch(o.code) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2354 case D6_OPTION_IA_TA:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2355 nl = 4;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2356 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2357 case D6_OPTION_IA_NA:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2358 case D6_OPTION_IA_PD:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2359 nl = 12;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2360 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2361 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2362 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2363 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2364 if (o.len < nl) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2365 errno = EINVAL;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2366 logerrx("%s: IA option truncated", 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
2367 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2368 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2369
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2370 memcpy(&ia, p, nl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2371 p += nl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2372 o.len = (uint16_t)(o.len - nl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2373
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2374 for (j = 0; j < ifo->ia_len; j++) {
4279
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
2375 ifia = &ifo->ia[j];
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
2376 if (ifia->ia_type == o.code &&
cdffb0137daa dhcp6: IAID is now unique for IA type
Roy Marples <roy@marples.name>
parents: 4267
diff changeset
2377 memcmp(ifia->iaid, ia.iaid, sizeof(ia.iaid)) == 0)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2378 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2379 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2380 if (j == ifo->ia_len &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2381 !(ifo->ia_len == 0 && ifp->ctx->options & DHCPCD_DUMPLEASE))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2382 {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2383 logdebugx("%s: ignoring unrequested IAID %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2384 ifp->name,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2385 hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2386 buf, sizeof(buf)));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2387 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2388 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2389
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2390 if (o.code != D6_OPTION_IA_TA) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2391 ia.t1 = ntohl(ia.t1);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2392 ia.t2 = ntohl(ia.t2);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2393 /* RFC 3315 22.4 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2394 if (ia.t2 > 0 && ia.t1 > ia.t2) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2395 logwarnx("%s: IAID %s T1(%d) > T2(%d) from %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2396 ifp->name,
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
2397 hwaddr_ntoa(iaid, sizeof(iaid), buf,
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
2398 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
2399 ia.t1, ia.t2, sfrom);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2400 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2401 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2402 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2403 ia.t1 = ia.t2 = 0; /* appease gcc */
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2404 if ((error = dhcp6_checkstatusok(ifp, NULL, p, o.len)) != 0) {
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2405 if (error == D6_STATUS_NOBINDING)
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2406 state->has_no_binding = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2407 e = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2408 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2409 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2410 if (o.code == D6_OPTION_IA_PD) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2411 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2412 if (dhcp6_findpd(ifp, ia.iaid, p, o.len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2413 acquired) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2414 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2415 logwarnx("%s: %s: DHCPv6 REPLY missing Prefix",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2416 ifp->name, sfrom);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2417 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2418 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2419 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2420 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2421 if (dhcp6_findna(ifp, o.code, ia.iaid, p, o.len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2422 acquired) == 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2423 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2424 logwarnx("%s: %s: DHCPv6 REPLY missing "
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2425 "IA Address",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2426 ifp->name, sfrom);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2427 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2428 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2429 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2430 if (o.code != D6_OPTION_IA_TA) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2431 if (ia.t1 != 0 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2432 (ia.t1 < state->renew || state->renew == 0))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2433 state->renew = ia.t1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2434 if (ia.t2 != 0 &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2435 (ia.t2 < state->rebind || state->rebind == 0))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2436 state->rebind = ia.t2;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2437 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2438 i++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2439 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2440
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2441 if (i == 0 && e)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2442 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2443 return i;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2444 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2445
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2446 #ifndef SMALL
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2447 static void
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2448 dhcp6_deprecatedele(struct ipv6_addr *ia)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2449 {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2450 struct ipv6_addr *da, *dan, *dda;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2451 struct timespec now;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2452 struct dhcp6_state *state;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2453
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2454 timespecclear(&now);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2455 TAILQ_FOREACH_SAFE(da, &ia->pd_pfxs, pd_next, dan) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2456 if (ia->prefix_vltime == 0) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2457 if (da->prefix_vltime != 0)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2458 da->prefix_vltime = 0;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2459 else
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2460 continue;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2461 } else if (da->prefix_pltime != 0)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2462 da->prefix_pltime = 0;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2463 else
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2464 continue;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2465
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2466 if (ipv6_doaddr(da, &now) != -1)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2467 continue;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2468
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2469 /* Delegation deleted, forget it. */
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2470 TAILQ_REMOVE(&ia->pd_pfxs, da, pd_next);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2471
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2472 /* Delete it from the interface. */
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2473 state = D6_STATE(da->iface);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2474 TAILQ_FOREACH(dda, &state->addrs, next) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2475 if (IN6_ARE_ADDR_EQUAL(&dda->addr, &da->addr))
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2476 break;
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2477 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2478 if (dda != NULL) {
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2479 TAILQ_REMOVE(&state->addrs, dda, next);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2480 ipv6_freeaddr(dda);
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2481 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2482 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2483 }
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2484 #endif
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2485
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2486 static void
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2487 dhcp6_deprecateaddrs(struct ipv6_addrhead *addrs)
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2488 {
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2489 struct ipv6_addr *ia, *ian;
4896
b9b16e0b58d1 DHCP6: Remove now unused vars
Roy Marples <roy@marples.name>
parents: 4893
diff changeset
2490
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2491 TAILQ_FOREACH_SAFE(ia, addrs, next, ian) {
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2492 if (ia->flags & IPV6_AF_EXTENDED)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2493 ;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2494 else if (ia->flags & IPV6_AF_STALE) {
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2495 if (ia->prefix_vltime != 0)
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2496 logdebugx("%s: %s: became stale",
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2497 ia->iface->name, ia->saddr);
5109
a7b7abb6211c Note that setting pltime to zero for stale addresses isn't RFC compliant
Roy Marples <roy@marples.name>
parents: 5092
diff changeset
2498 /* Technically this violates RFC 8415 18.2.10.1,
a7b7abb6211c Note that setting pltime to zero for stale addresses isn't RFC compliant
Roy Marples <roy@marples.name>
parents: 5092
diff changeset
2499 * 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: 5092
diff changeset
2500 * try and prefer other addresses. */
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2501 ia->prefix_pltime = 0;
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2502 } else if (ia->prefix_vltime == 0)
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2503 loginfox("%s: %s: no valid lifetime",
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2504 ia->iface->name, ia->saddr);
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2505 else
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2506 continue;
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2507
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2508 #ifndef SMALL
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2509 /* If we delegated from this prefix, deprecate or remove
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2510 * the delegations. */
4890
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2511 if (ia->flags & IPV6_AF_DELEGATEDPFX)
5cad682cbbae DHCP6: Rework delegation deprecation
Roy Marples <roy@marples.name>
parents: 4883
diff changeset
2512 dhcp6_deprecatedele(ia);
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2513 #endif
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2514
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2515 if (ia->flags & IPV6_AF_REQUEST) {
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2516 ia->prefix_vltime = ia->prefix_pltime = 0;
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2517 eloop_q_timeout_delete(ia->iface->ctx->eloop,
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
2518 ELOOP_QUEUE_ALL, NULL, ia);
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2519 continue;
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2520 }
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2521 TAILQ_REMOVE(addrs, ia, next);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2522 if (ia->flags & IPV6_AF_EXTENDED)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2523 ipv6_deleteaddr(ia);
4065
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2524 ipv6_freeaddr(ia);
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2525 }
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2526 }
710e3f0e1b2f Apply the real D108 patch, my bad.
Roy Marples <roy@marples.name>
parents: 4064
diff changeset
2527
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2528 static int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2529 dhcp6_validatelease(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
2530 struct dhcp6_message *m, 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
2531 const char *sfrom, const struct timespec *acquired)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2532 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2533 struct dhcp6_state *state;
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2534 int nia, ok_errno;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2535 struct timespec aq;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2536
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2537 if (len <= sizeof(*m)) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2538 logerrx("%s: DHCPv6 lease truncated", 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
2539 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2540 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2541
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2542 state = D6_STATE(ifp);
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2543 errno = 0;
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2544 if (dhcp6_checkstatusok(ifp, m, NULL, len) != 0)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2545 return -1;
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2546 ok_errno = errno;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2547
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2548 state->renew = state->rebind = state->expire = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2549 state->lowpl = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2550 if (!acquired) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2551 clock_gettime(CLOCK_MONOTONIC, &aq);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2552 acquired = &aq;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2553 }
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2554 state->has_no_binding = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2555 nia = dhcp6_findia(ifp, m, len, sfrom, acquired);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2556 if (nia == 0) {
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2557 if (state->state != DH6S_CONFIRM && ok_errno != 0) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2558 logerrx("%s: no useable IA found in lease", 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
2559 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2560 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2561
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2562 /* We are confirming and have an OK,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2563 * so look for ia's in our old lease.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2564 * IA's must have existed here otherwise we would
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2565 * have rejected it earlier. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2566 assert(state->new != NULL && state->new_len != 0);
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
2567 state->has_no_binding = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2568 nia = dhcp6_findia(ifp, state->new, state->new_len,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2569 sfrom, acquired);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2570 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2571 return nia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2572 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2573
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2574 static ssize_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2575 dhcp6_readlease(struct interface *ifp, int validate)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2576 {
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2577 union {
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2578 struct dhcp6_message dhcp6;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2579 uint8_t buf[UDPLEN_MAX];
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2580 } buf;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2581 struct dhcp6_state *state;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2582 ssize_t bytes;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2583 int fd;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2584 time_t mtime, now;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2585 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2586 uint8_t *o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2587 uint16_t ol;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2588 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2589
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2590 state = D6_STATE(ifp);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2591 if (state->leasefile[0] == '\0') {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2592 logdebugx("reading standard input");
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2593 bytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2594 } else {
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
2595 logdebugx("%s: reading lease: %s",
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2596 ifp->name, state->leasefile);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2597 bytes = dhcp_readfile(ifp->ctx, state->leasefile,
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2598 buf.buf, sizeof(buf.buf));
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2599 }
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2600 if (bytes == -1)
4677
fbb1a5946f9e DHCP: Don't log an error if the lease file is empty
Roy Marples <roy@marples.name>
parents: 4601
diff changeset
2601 goto ex;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2602
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2603 if (ifp->ctx->options & DHCPCD_DUMPLEASE || state->leasefile[0] == '\0')
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2604 goto out;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2605
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2606 if (bytes == 0)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2607 goto ex;
4677
fbb1a5946f9e DHCP: Don't log an error if the lease file is empty
Roy Marples <roy@marples.name>
parents: 4601
diff changeset
2608
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2609 /* If not validating IA's and if they have expired,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2610 * skip to the auth check. */
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2611 if (!validate)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2612 goto auth;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2613
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2614 if (dhcp_filemtime(ifp->ctx, state->leasefile, &mtime) == -1)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2615 goto ex;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2616 clock_gettime(CLOCK_MONOTONIC, &state->acquired);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2617 if ((now = time(NULL)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2618 goto ex;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2619 state->acquired.tv_sec -= now - mtime;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2620
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2621 /* Check to see if the lease is still valid */
5208
6e53055c9989 Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
2622 fd = dhcp6_validatelease(ifp, &buf.dhcp6, (size_t)bytes, NULL,
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
2623 &state->acquired);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2624 if (fd == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2625 goto ex;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2626
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2627 if (state->expire != ND6_INFINITE_LIFETIME &&
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2628 (time_t)state->expire < now - mtime &&
4695
62e0208e14b9 DHCP6: Solve a scan-build error
Roy Marples <roy@marples.name>
parents: 4693
diff changeset
2629 !(ifp->options->options & DHCPCD_LASTLEASE_EXTEND))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2630 {
4695
62e0208e14b9 DHCP6: Solve a scan-build error
Roy Marples <roy@marples.name>
parents: 4693
diff changeset
2631 logdebugx("%s: discarding expired lease", ifp->name);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2632 bytes = 0;
4695
62e0208e14b9 DHCP6: Solve a scan-build error
Roy Marples <roy@marples.name>
parents: 4693
diff changeset
2633 goto ex;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2634 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2635
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2636 auth:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2637 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2638 /* Authenticate the message */
5208
6e53055c9989 Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
2639 o = dhcp6_findmoption(&buf.dhcp6, (size_t)bytes, D6_OPTION_AUTH, &ol);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2640 if (o) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2641 if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
5208
6e53055c9989 Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
2642 buf.buf, (size_t)bytes, 6, buf.dhcp6.type, o, ol) == NULL)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2643 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2644 logerr("%s: authentication failed", ifp->name);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2645 bytes = 0;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2646 goto ex;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2647 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2648 if (state->auth.token)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2649 logdebugx("%s: validated using 0x%08" PRIu32,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2650 ifp->name, state->auth.token->secretid);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2651 else
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
2652 loginfox("%s: accepted reconfigure key", 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
2653 } else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2654 DHCPCD_AUTH_SENDREQUIRE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2655 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2656 logerrx("%s: authentication now required", 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
2657 goto ex;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2658 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2659 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2660
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2661 out:
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2662 free(state->new);
5208
6e53055c9989 Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
2663 state->new = malloc((size_t)bytes);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2664 if (state->new == NULL) {
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2665 logerr(__func__);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2666 goto ex;
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2667 }
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2668
5208
6e53055c9989 Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
2669 memcpy(state->new, buf.buf, (size_t)bytes);
6e53055c9989 Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents: 5207
diff changeset
2670 state->new_len = (size_t)bytes;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2671 return bytes;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2672
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2673 ex:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2674 dhcp6_freedrop_addrs(ifp, 0, NULL);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2675 dhcp_unlink(ifp->ctx, state->leasefile);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2676 free(state->new);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2677 state->new = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2678 state->new_len = 0;
5357
2ddfb6841ebb DHCP6: Add requested addresses after freeing all state addresses
Roy Marples <roy@marples.name>
parents: 5299
diff changeset
2679 dhcp6_addrequestedaddrs(ifp);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2680 return bytes == 0 ? 0 : -1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2681 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2682
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2683 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2684 dhcp6_startinit(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
2685 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2686 struct dhcp6_state *state;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
2687 ssize_t r;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2688 uint8_t has_ta, has_non_ta;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2689 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
2690
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2691 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2692 state->state = DH6S_INIT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2693 state->expire = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2694 state->lowpl = ND6_INFINITE_LIFETIME;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2695
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2696 dhcp6_addrequestedaddrs(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2697 has_ta = has_non_ta = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2698 for (i = 0; i < ifp->options->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2699 switch (ifp->options->ia[i].ia_type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2700 case D6_OPTION_IA_TA:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2701 has_ta = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2702 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2703 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2704 has_non_ta = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2705 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2706 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2707
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2708 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
2709 !(has_ta && !has_non_ta) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2710 ifp->options->reboot != 0)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2711 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2712 r = dhcp6_readlease(ifp, 1);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2713 if (r == -1) {
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
2714 if (errno != ENOENT && errno != ESRCH)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2715 logerr("%s: %s", __func__, state->leasefile);
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
2716 } else if (r != 0 &&
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
2717 !(ifp->options->options & DHCPCD_ANONYMOUS))
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
2718 {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2719 /* RFC 3633 section 12.1 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2720 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2721 if (dhcp6_hasprefixdelegation(ifp))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2722 dhcp6_startrebind(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2723 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2724 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2725 dhcp6_startconfirm(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2726 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2727 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2728 }
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
2729 dhcp6_startdiscoinform(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2730 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2731
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2732 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2733 static struct ipv6_addr *
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2734 dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2735 const struct if_sla *sla, struct if_ia *if_ia)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2736 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2737 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2738 struct in6_addr addr, daddr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2739 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
2740 int pfxlen, dadcounter;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2741 uint64_t vl;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2742
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2743 /* RFC6603 Section 4.2 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2744 if (strcmp(ifp->name, prefix->iface->name) == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2745 if (prefix->prefix_exclude_len == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2746 /* Don't spam the log automatically */
4055
75fedf83420a sla could be NULL, so check that.
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
2747 if (sla != NULL)
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2748 logwarnx("%s: DHCPv6 server does not support "
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2749 "OPTION_PD_EXCLUDE",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2750 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2751 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2752 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2753 pfxlen = prefix->prefix_exclude_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2754 memcpy(&addr, &prefix->prefix_exclude, sizeof(addr));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2755 } else if ((pfxlen = dhcp6_delegateaddr(&addr, ifp, prefix,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2756 sla, if_ia)) == -1)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2757 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2758
4055
75fedf83420a sla could be NULL, so check that.
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
2759 if (sla != NULL && fls64(sla->suffix) > 128 - pfxlen) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2760 logerrx("%s: suffix %" PRIu64 " + prefix_len %d > 128",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2761 ifp->name, sla->suffix, pfxlen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2762 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2763 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2764
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2765 /* Add our suffix */
4055
75fedf83420a sla could be NULL, so check that.
Roy Marples <roy@marples.name>
parents: 4024
diff changeset
2766 if (sla != NULL && sla->suffix != 0) {
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2767 daddr = addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2768 vl = be64dec(addr.s6_addr + 8);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2769 vl |= sla->suffix;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2770 be64enc(daddr.s6_addr + 8, vl);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2771 } else {
5127
14b737f09947 RA: Rework temporary address management
Roy Marples <roy@marples.name>
parents: 5120
diff changeset
2772 dadcounter = ipv6_makeaddr(&daddr, ifp, &addr, pfxlen, 0);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2773 if (dadcounter == -1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2774 logerrx("%s: error adding slaac to prefix_len %d",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2775 ifp->name, pfxlen);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2776 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2777 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2778 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2779
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2780 /* Find an existing address */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2781 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2782 TAILQ_FOREACH(ia, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2783 if (IN6_ARE_ADDR_EQUAL(&ia->addr, &daddr))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2784 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2785 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2786 if (ia == NULL) {
4090
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2787 ia = ipv6_newaddr(ifp, &daddr, (uint8_t)pfxlen, IPV6_AF_ONLINK);
62f8388ea690 Make ipv6_newaddr() more flexable so it's the sole source of
Roy Marples <roy@marples.name>
parents: 4087
diff changeset
2788 if (ia == NULL)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2789 return NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2790 ia->dadcallback = dhcp6_dadcallback;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2791 memcpy(&ia->iaid, &prefix->iaid, sizeof(ia->iaid));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2792 ia->created = prefix->acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2793
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2794 TAILQ_INSERT_TAIL(&state->addrs, ia, next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2795 TAILQ_INSERT_TAIL(&prefix->pd_pfxs, ia, pd_next);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2796 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2797 ia->delegating_prefix = prefix;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2798 ia->prefix = addr;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2799 ia->prefix_len = (uint8_t)pfxlen;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2800 ia->acquired = prefix->acquired;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2801 ia->prefix_pltime = prefix->prefix_pltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2802 ia->prefix_vltime = prefix->prefix_vltime;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2803
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2804 /* If the prefix length hasn't changed,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2805 * don't install a reject route. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2806 if (prefix->prefix_len == pfxlen)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2807 prefix->flags |= IPV6_AF_NOREJECT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2808 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2809 prefix->flags &= ~IPV6_AF_NOREJECT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2810
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2811 return ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2812 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2813 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2814
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2815 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2816 dhcp6_script_try_run(struct interface *ifp, int delegated)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2817 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2818 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2819 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
2820 int completed;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2821
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2822 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2823 completed = 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2824 /* 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
2825 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2826 if (!(ap->flags & IPV6_AF_ADDED))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2827 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2828 if (ap->flags & IPV6_AF_ONLINK) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2829 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
2830 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
2831 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
2832 ap->flags |= IPV6_AF_DADCOMPLETED;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2833 if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2834 #ifndef SMALL
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2835 && ((delegated && ap->delegating_prefix) ||
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2836 (!delegated && !ap->delegating_prefix))
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2837 #endif
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
2838 )
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2839 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2840 completed = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2841 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2842 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2843 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2844 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2845 if (completed) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2846 script_runreason(ifp, delegated ? "DELEGATED6" : state->reason);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2847 if (!delegated)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2848 dhcpcd_daemonise(ifp->ctx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2849 } else
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2850 logdebugx("%s: waiting for DHCPv6 DAD to complete", 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
2851 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2852
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2853 #ifdef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2854 size_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2855 dhcp6_find_delegates(__unused struct interface *ifp)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2856 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2857
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2858 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2859 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2860 #else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2861 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2862 dhcp6_delegate_prefix(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
2863 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2864 struct if_options *ifo;
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
2865 struct dhcp6_state *state;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2866 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
2867 size_t i, j, k;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2868 struct if_ia *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2869 struct if_sla *sla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2870 struct interface *ifd;
4073
a8ab7020191b Remove abrt as it's unused and change carrier_warned to a bool.
Roy Marples <roy@marples.name>
parents: 4071
diff changeset
2871 bool carrier_warned;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2872
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2873 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2874 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2875
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2876 /* Clear the logged flag. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2877 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2878 ap->flags &= ~IPV6_AF_DELEGATEDLOG;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2879 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2880
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2881 TAILQ_FOREACH(ifd, 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
2882 if (!ifd->active)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2883 continue;
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2884 if (!(ifd->options->options & DHCPCD_CONFIGURE))
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2885 continue;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2886 k = 0;
4073
a8ab7020191b Remove abrt as it's unused and change carrier_warned to a bool.
Roy Marples <roy@marples.name>
parents: 4071
diff changeset
2887 carrier_warned = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2888 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2889 if (!(ap->flags & IPV6_AF_DELEGATEDPFX))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2890 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2891 if (!(ap->flags & IPV6_AF_DELEGATEDLOG)) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2892 int loglevel;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2893
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2894 if (ap->flags & IPV6_AF_NEW)
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2895 loglevel = LOG_INFO;
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
2896 else
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2897 loglevel = 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
2898 /* We only want to log this the once as we loop
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2899 * through many interfaces first. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2900 ap->flags |= IPV6_AF_DELEGATEDLOG;
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
2901 logmessage(loglevel, "%s: delegated prefix %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2902 ifp->name, ap->saddr);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2903 ap->flags &= ~IPV6_AF_NEW;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2904 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2905 for (i = 0; i < ifo->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2906 ia = &ifo->ia[i];
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
2907 if (ia->ia_type != D6_OPTION_IA_PD)
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
2908 continue;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2909 if (memcmp(ia->iaid, ap->iaid,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2910 sizeof(ia->iaid)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2911 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2912 if (ia->sla_len == 0) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2913 /* no SLA configured, so lets
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2914 * automate it */
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
2915 if (!if_is_link_up(ifd)) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2916 logdebugx(
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2917 "%s: has no carrier, cannot"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2918 " delegate addresses",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2919 ifd->name);
4073
a8ab7020191b Remove abrt as it's unused and change carrier_warned to a bool.
Roy Marples <roy@marples.name>
parents: 4071
diff changeset
2920 carrier_warned = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2921 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2922 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2923 if (dhcp6_ifdelegateaddr(ifd, ap,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2924 NULL, ia))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2925 k++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2926 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2927 for (j = 0; j < ia->sla_len; j++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2928 sla = &ia->sla[j];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2929 if (strcmp(ifd->name, sla->ifname))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2930 continue;
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
2931 if (!if_is_link_up(ifd)) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
2932 logdebugx(
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2933 "%s: has no carrier, cannot"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2934 " delegate addresses",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2935 ifd->name);
4073
a8ab7020191b Remove abrt as it's unused and change carrier_warned to a bool.
Roy Marples <roy@marples.name>
parents: 4071
diff changeset
2936 carrier_warned = true;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2937 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2938 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2939 if (dhcp6_ifdelegateaddr(ifd, ap,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2940 sla, ia))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2941 k++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2942 }
4073
a8ab7020191b Remove abrt as it's unused and change carrier_warned to a bool.
Roy Marples <roy@marples.name>
parents: 4071
diff changeset
2943 if (carrier_warned)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2944 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2945 }
4073
a8ab7020191b Remove abrt as it's unused and change carrier_warned to a bool.
Roy Marples <roy@marples.name>
parents: 4071
diff changeset
2946 if (carrier_warned)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2947 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2948 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2949 if (k && !carrier_warned) {
4175
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
2950 struct dhcp6_state *s = D6_STATE(ifd);
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
2951
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
2952 ipv6_addaddrs(&s->addrs);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2953 dhcp6_script_try_run(ifd, 1);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2954 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2955 }
4074
20310dc3ece3 Prefix Delegation: build routes after all addresses delegated
Roy Marples <roy@marples.name>
parents: 4073
diff changeset
2956
20310dc3ece3 Prefix Delegation: build routes after all addresses delegated
Roy Marples <roy@marples.name>
parents: 4073
diff changeset
2957 /* Now all addresses have been added, rebuild the routing table. */
20310dc3ece3 Prefix Delegation: build routes after all addresses delegated
Roy Marples <roy@marples.name>
parents: 4073
diff changeset
2958 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
2959 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2960
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2961 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2962 dhcp6_find_delegates1(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2963 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2964
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2965 dhcp6_find_delegates(arg);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2966 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2967
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2968 size_t
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2969 dhcp6_find_delegates(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
2970 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2971 struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2972 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2973 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
2974 size_t i, j, k;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2975 struct if_ia *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2976 struct if_sla *sla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2977 struct interface *ifd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2978
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2979 if (ifp->options != NULL &&
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2980 !(ifp->options->options & DHCPCD_CONFIGURE))
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2981 return 0;
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
2982
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2983 k = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2984 TAILQ_FOREACH(ifd, 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
2985 ifo = ifd->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2986 state = D6_STATE(ifd);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2987 if (state == NULL || state->state != DH6S_BOUND)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2988 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2989 TAILQ_FOREACH(ap, &state->addrs, next) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2990 if (!(ap->flags & IPV6_AF_DELEGATEDPFX))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2991 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2992 for (i = 0; i < ifo->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2993 ia = &ifo->ia[i];
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
2994 if (ia->ia_type != D6_OPTION_IA_PD)
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
2995 continue;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2996 if (memcmp(ia->iaid, ap->iaid,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2997 sizeof(ia->iaid)))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2998 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
2999 for (j = 0; j < ia->sla_len; j++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3000 sla = &ia->sla[j];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3001 if (strcmp(ifp->name, sla->ifname))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3002 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3003 if (ipv6_linklocal(ifp) == NULL) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
3004 logdebugx(
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3005 "%s: delaying adding"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3006 " delegated addresses for"
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3007 " LL address",
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3008 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3009 ipv6_addlinklocalcallback(ifp,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3010 dhcp6_find_delegates1, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3011 return 1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3012 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3013 if (dhcp6_ifdelegateaddr(ifp, ap,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3014 sla, ia))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3015 k++;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3016 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3017 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3018 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3019 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3020
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3021 if (k) {
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
3022 loginfox("%s: adding delegated prefixes", 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
3023 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3024 state->state = DH6S_DELEGATED;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3025 ipv6_addaddrs(&state->addrs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3026 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
3027 dhcp6_script_try_run(ifp, 1);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3028 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3029 return k;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3030 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3031 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3032
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3033 static void
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3034 dhcp6_bind(struct interface *ifp, const char *op, const char *sfrom)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3035 {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3036 struct dhcp6_state *state = D6_STATE(ifp);
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3037 bool timedout = (op == NULL), has_new = false, confirmed;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3038 struct ipv6_addr *ia;
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3039 int loglevel;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3040 struct timespec now;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3041
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3042 TAILQ_FOREACH(ia, &state->addrs, next) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3043 if (ia->flags & IPV6_AF_NEW) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3044 has_new = true;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3045 break;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3046 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3047 }
5226
06575a46bbdd DHCP: always log inform when not renewing
Roy Marples <roy@marples.name>
parents: 5208
diff changeset
3048 loglevel = has_new || state->state != DH6S_RENEW ? LOG_INFO : LOG_DEBUG;
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3049 if (!timedout) {
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3050 logmessage(loglevel, "%s: %s received from %s",
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3051 ifp->name, op, sfrom);
5074
5df0f92ade6d DHCP6: Fix SMALL build
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
3052 #ifndef SMALL
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3053 /* If we delegated from an unconfirmed lease we MUST drop
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3054 * them now. Hopefully we have new delegations. */
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3055 if (state->reason != NULL &&
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3056 strcmp(state->reason, "TIMEOUT6") == 0)
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3057 dhcp6_delete_delegates(ifp);
5074
5df0f92ade6d DHCP6: Fix SMALL build
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
3058 #endif
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3059 state->reason = NULL;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3060 } else
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3061 state->reason = "TIMEOUT6";
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3062
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3063 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3064 clock_gettime(CLOCK_MONOTONIC, &now);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3065
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3066 switch(state->state) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3067 case DH6S_INFORM:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3068 {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3069 struct dhcp6_option *o;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3070 uint16_t ol;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3071
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3072 if (state->reason == NULL)
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3073 state->reason = "INFORM6";
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3074 o = dhcp6_findmoption(state->new, state->new_len,
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3075 D6_OPTION_INFO_REFRESH_TIME, &ol);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3076 if (o == NULL || ol != sizeof(uint32_t))
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3077 state->renew = IRT_DEFAULT;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3078 else {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3079 memcpy(&state->renew, o, ol);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3080 state->renew = ntohl(state->renew);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3081 if (state->renew < IRT_MINIMUM)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3082 state->renew = IRT_MINIMUM;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3083 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3084 state->rebind = 0;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3085 state->expire = ND6_INFINITE_LIFETIME;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3086 state->lowpl = ND6_INFINITE_LIFETIME;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3087 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3088 break;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3089
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3090 case DH6S_REQUEST:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3091 if (state->reason == NULL)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3092 state->reason = "BOUND6";
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3093 /* FALLTHROUGH */
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3094 case DH6S_RENEW:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3095 if (state->reason == NULL)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3096 state->reason = "RENEW6";
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3097 /* FALLTHROUGH */
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3098 case DH6S_REBIND:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3099 if (state->reason == NULL)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3100 state->reason = "REBIND6";
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3101 /* FALLTHROUGH */
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3102 case DH6S_CONFIRM:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3103 if (state->reason == NULL)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3104 state->reason = "REBOOT6";
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3105 if (state->renew != 0) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3106 bool all_expired = true;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3107
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3108 TAILQ_FOREACH(ia, &state->addrs, next) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3109 if (ia->flags & IPV6_AF_STALE)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3110 continue;
4877
d28785059be5 DHCP: Don't warn about expiry of deprecated addresses
Roy Marples <roy@marples.name>
parents: 4869
diff changeset
3111 if (!(state->renew == ND6_INFINITE_LIFETIME
d28785059be5 DHCP: Don't warn about expiry of deprecated addresses
Roy Marples <roy@marples.name>
parents: 4869
diff changeset
3112 && ia->prefix_vltime == ND6_INFINITE_LIFETIME)
d28785059be5 DHCP: Don't warn about expiry of deprecated addresses
Roy Marples <roy@marples.name>
parents: 4869
diff changeset
3113 && ia->prefix_vltime != 0
4746
1ec4b413dcb3 DHCP6: Work better with infinite addresses
Roy Marples <roy@marples.name>
parents: 4726
diff changeset
3114 && ia->prefix_vltime <= state->renew)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3115 logwarnx(
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3116 "%s: %s will expire before renewal",
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3117 ifp->name, ia->saddr);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3118 else
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3119 all_expired = false;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3120 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3121 if (all_expired) {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3122 /* All address's vltime happens at or before
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3123 * the configured T1 in the IA.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3124 * This is a badly configured server and we
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3125 * have to use our own notion of what
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3126 * T1 and T2 should be as a result.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3127 *
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3128 * Doing this violates RFC 3315 22.4:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3129 * In a message sent by a server to a client,
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3130 * the client MUST use the values in the T1
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3131 * and T2 fields for the T1 and T2 parameters,
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3132 * unless those values in those fields are 0.
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3133 */
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3134 logwarnx("%s: ignoring T1 %"PRIu32
4464
d5a636216f97 DHCPv6: fix warning message wording
Roy Marples <roy@marples.name>
parents: 4458
diff changeset
3135 " due to address expiry",
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3136 ifp->name, state->renew);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3137 state->renew = state->rebind = 0;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3138 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3139 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3140 if (state->renew == 0 && state->lowpl != ND6_INFINITE_LIFETIME)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3141 state->renew = (uint32_t)(state->lowpl * 0.5);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3142 if (state->rebind == 0 && state->lowpl != ND6_INFINITE_LIFETIME)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3143 state->rebind = (uint32_t)(state->lowpl * 0.8);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3144 break;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3145 default:
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3146 state->reason = "UNKNOWN6";
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3147 break;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3148 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3149
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3150 if (state->state != DH6S_CONFIRM && !timedout) {
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3151 state->acquired = now;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3152 free(state->old);
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3153 state->old = state->new;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3154 state->old_len = state->new_len;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3155 state->new = state->recv;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3156 state->new_len = state->recv_len;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3157 state->recv = NULL;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3158 state->recv_len = 0;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3159 confirmed = false;
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3160 } else {
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3161 /* Reduce timers based on when we got the lease. */
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3162 uint32_t elapsed;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3163
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3164 elapsed = (uint32_t)eloop_timespec_diff(&now,
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3165 &state->acquired, NULL);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3166 if (state->renew && state->renew != ND6_INFINITE_LIFETIME) {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3167 if (state->renew > elapsed)
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3168 state->renew -= elapsed;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3169 else
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3170 state->renew = 0;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3171 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3172 if (state->rebind && state->rebind != ND6_INFINITE_LIFETIME) {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3173 if (state->rebind > elapsed)
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3174 state->rebind -= elapsed;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3175 else
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3176 state->rebind = 0;
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3177 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3178 if (state->expire && state->expire != ND6_INFINITE_LIFETIME) {
4924
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3179 if (state->expire > elapsed)
7c1a365b1e2d eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents: 4923
diff changeset
3180 state->expire -= elapsed;
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3181 else
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3182 state->expire = 0;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3183 }
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3184 confirmed = true;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3185 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3186
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3187 if (ifp->ctx->options & DHCPCD_TEST)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3188 script_runreason(ifp, "TEST");
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3189 else {
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3190 if (state->state == DH6S_INFORM)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3191 state->state = DH6S_INFORMED;
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3192 else
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3193 state->state = DH6S_BOUND;
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
3194 state->failed = false;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3195
5398
505ddba6ec99 DHCP6: Restore lease timings
Roy Marples <roy@marples.name>
parents: 5359
diff changeset
3196 if (state->renew && state->renew != ND6_INFINITE_LIFETIME)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3197 eloop_timeout_add_sec(ifp->ctx->eloop,
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
3198 state->renew,
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3199 state->state == DH6S_INFORMED ?
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3200 dhcp6_startinform : dhcp6_startrenew, ifp);
5398
505ddba6ec99 DHCP6: Restore lease timings
Roy Marples <roy@marples.name>
parents: 5359
diff changeset
3201 if (state->rebind && state->rebind != ND6_INFINITE_LIFETIME)
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3202 eloop_timeout_add_sec(ifp->ctx->eloop,
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
3203 state->rebind, dhcp6_startrebind, ifp);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3204 if (state->expire != ND6_INFINITE_LIFETIME)
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3205 eloop_timeout_add_sec(ifp->ctx->eloop,
4923
4fcca755943e eloop: Allow for for timeouts greater than time_t and time wrapping
Roy Marples <roy@marples.name>
parents: 4922
diff changeset
3206 state->expire, dhcp6_startexpire, ifp);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3207
5535
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
3208 if (ifp->options->options & DHCPCD_CONFIGURE) {
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
3209 ipv6_addaddrs(&state->addrs);
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
3210 if (!timedout)
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
3211 dhcp6_deprecateaddrs(&state->addrs);
a0d828e25482 Add --noconfigure option
Roy Marples <roy@marples.name>
parents: 5499
diff changeset
3212 }
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3213
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3214 if (state->state == DH6S_INFORMED)
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3215 logmessage(loglevel, "%s: refresh in %"PRIu32" seconds",
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3216 ifp->name, state->renew);
4746
1ec4b413dcb3 DHCP6: Work better with infinite addresses
Roy Marples <roy@marples.name>
parents: 4726
diff changeset
3217 else if (state->renew == ND6_INFINITE_LIFETIME)
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3218 logmessage(loglevel, "%s: leased for infinity",
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3219 ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3220 else if (state->renew || state->rebind)
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3221 logmessage(loglevel, "%s: renew in %"PRIu32", "
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3222 "rebind in %"PRIu32", "
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3223 "expire in %"PRIu32" seconds",
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3224 ifp->name,
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3225 state->renew, state->rebind, state->expire);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3226 else if (state->expire == 0)
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3227 logmessage(loglevel, "%s: will expire", ifp->name);
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3228 else
5064
7721231839f5 logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents: 5046
diff changeset
3229 logmessage(loglevel, "%s: expire in %"PRIu32" seconds",
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3230 ifp->name, state->expire);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3231 rt_build(ifp->ctx, AF_INET6);
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3232 if (!confirmed && !timedout) {
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
3233 logdebugx("%s: writing lease: %s",
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3234 ifp->name, state->leasefile);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3235 if (dhcp_writefile(ifp->ctx, state->leasefile, 0640,
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3236 state->new, state->new_len) == -1)
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3237 logerr("dhcp_writefile: %s",state->leasefile);
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3238 }
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3239 #ifndef SMALL
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3240 dhcp6_delegate_prefix(ifp);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3241 #endif
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3242 dhcp6_script_try_run(ifp, 0);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3243 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3244
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3245 if (ifp->ctx->options & DHCPCD_TEST ||
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3246 (ifp->options->options & DHCPCD_INFORM &&
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3247 !(ifp->ctx->options & DHCPCD_MASTER)))
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3248 {
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3249 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3250 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3251 }
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3252
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3253 static void
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3254 dhcp6_recvif(struct interface *ifp, const char *sfrom,
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3255 struct dhcp6_message *r, size_t len)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3256 {
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3257 struct dhcpcd_ctx *ctx;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3258 size_t i;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3259 const char *op;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3260 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3261 uint8_t *o;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3262 uint16_t ol;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3263 const 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
3264 const struct if_options *ifo;
4112
3efb356fc08e dhcp6: implement lastlease and lastleaseextend
Roy Marples <roy@marples.name>
parents: 4107
diff changeset
3265 bool valid_op;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3266 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3267 uint8_t *auth;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3268 uint16_t auth_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3269 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3270
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3271 ctx = 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
3272 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3273 if (state == NULL || state->send == NULL) {
4310
e28831be50f3 dhcp6: don't log an error here.
Roy Marples <roy@marples.name>
parents: 4303
diff changeset
3274 logdebugx("%s: DHCPv6 reply received but not running",
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
3275 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
3276 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3277 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3278
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3279 /* We're already bound and this message is for another machine */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3280 /* XXX DELEGATED? */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3281 if (r->type != DHCP6_RECONFIGURE &&
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
3282 (state->state == DH6S_BOUND || state->state == DH6S_INFORMED))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3283 {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
3284 logdebugx("%s: DHCPv6 reply received but already bound",
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
3285 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
3286 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3287 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3288
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3289 if (dhcp6_findmoption(r, len, D6_OPTION_SERVERID, NULL) == NULL) {
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3290 logdebugx("%s: no DHCPv6 server ID 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
3291 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3292 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3293
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3294 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3295 for (i = 0, opt = ctx->dhcp6_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3296 i < ctx->dhcp6_opts_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3297 i++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3298 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3299 if (has_option_mask(ifo->requiremask6, opt->option) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3300 !dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3301 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3302 logwarnx("%s: reject DHCPv6 (no option %s) from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3303 ifp->name, opt->var, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3304 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3305 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3306 if (has_option_mask(ifo->rejectmask6, opt->option) &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3307 dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3308 {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3309 logwarnx("%s: reject DHCPv6 (option %s) from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3310 ifp->name, opt->var, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3311 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3312 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3313 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3314
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3315 #ifdef AUTH
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3316 /* Authenticate the message */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3317 auth = dhcp6_findmoption(r, len, D6_OPTION_AUTH, &auth_len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3318 if (auth != NULL) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3319 if (dhcp_auth_validate(&state->auth, &ifo->auth,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3320 (uint8_t *)r, len, 6, r->type, auth, auth_len) == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3321 {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
3322 logerr("%s: authentication failed from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3323 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
3324 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3325 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3326 if (state->auth.token)
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
3327 logdebugx("%s: validated using 0x%08" PRIu32,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3328 ifp->name, state->auth.token->secretid);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3329 else
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
3330 loginfox("%s: accepted reconfigure key", 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
3331 } else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3332 if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
5294
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3333 logerrx("%s: no authentication from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3334 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
3335 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3336 }
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3337 logwarnx("%s: no authentication 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
3338 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3339 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3340
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3341 op = dhcp6_get_op(r->type);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3342 valid_op = op != NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3343 switch(r->type) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3344 case DHCP6_REPLY:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3345 switch(state->state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3346 case DH6S_INFORM:
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3347 if (dhcp6_checkstatusok(ifp, r, NULL, len) != 0)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3348 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3349 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3350 case DH6S_CONFIRM:
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3351 if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3352 {
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3353 dhcp6_startdiscoinform(ifp);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3354 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3355 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3356 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3357 case DH6S_DISCOVER:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3358 /* Only accept REPLY in DISCOVER for RAPID_COMMIT.
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3359 * Normally we get an ADVERTISE for a DISCOVER. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3360 if (!has_option_mask(ifo->requestmask6,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3361 D6_OPTION_RAPID_COMMIT) ||
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3362 !dhcp6_findmoption(r, len, D6_OPTION_RAPID_COMMIT,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3363 NULL))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3364 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3365 valid_op = false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3366 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3367 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3368 /* Validate lease before setting state to REQUEST. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3369 /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3370 case DH6S_REQUEST: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3371 case DH6S_RENEW: /* FALLTHROUGH */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3372 case DH6S_REBIND:
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3373 if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3374 {
4313
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3375 /*
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3376 * If we can't use the lease, fallback to
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3377 * DISCOVER and try and get a new one.
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3378 *
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3379 * This is needed become some servers
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3380 * renumber the prefix or address
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3381 * and deny the current one before it expires
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3382 * rather than sending it back with a zero
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3383 * lifetime along with the new prefix or
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3384 * address to use.
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3385 * This behavior is wrong, but moving to the
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3386 * DISCOVER phase works around it.
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3387 *
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3388 * The currently held lease is still valid
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3389 * until a new one is found.
0b3ecef3de4a dhcp6: always move to the DISCOVER phase if the offered lease is invalid
Roy Marples <roy@marples.name>
parents: 4312
diff changeset
3390 */
4314
c9c480d74cfe Fix prior - always return if lease is invalid.
Roy Marples <roy@marples.name>
parents: 4313
diff changeset
3391 if (state->state != DH6S_DISCOVER)
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3392 dhcp6_startdiscoinform(ifp);
4314
c9c480d74cfe Fix prior - always return if lease is invalid.
Roy Marples <roy@marples.name>
parents: 4313
diff changeset
3393 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3394 }
4601
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3395 /* RFC8415 18.2.10.1 */
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3396 if ((state->state == DH6S_RENEW ||
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3397 state->state == DH6S_REBIND) &&
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3398 state->has_no_binding)
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3399 {
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3400 dhcp6_startrequest(ifp);
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3401 return;
db69ef4bc972 DHCP6: Change state to REQEST when any IA has NOBINDING status
Roy Marples <roy@marples.name>
parents: 4588
diff changeset
3402 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3403 if (state->state == DH6S_DISCOVER)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3404 state->state = DH6S_REQUEST;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3405 break;
5171
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3406 case DH6S_DECLINE:
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3407 /* This isnt really a failure, but an
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3408 * acknowledgement of one. */
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3409 loginfox("%s: %s acknowledged DECLINE6",
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3410 ifp->name, sfrom);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3411 dhcp6_fail(ifp);
5943646f9dd3 DHCP6: Implement DECLINE support for duplicated addresses
Roy Marples <roy@marples.name>
parents: 5160
diff changeset
3412 return;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3413 default:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3414 valid_op = false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3415 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3416 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3417 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3418 case DHCP6_ADVERTISE:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3419 if (state->state != DH6S_DISCOVER) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3420 valid_op = false;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3421 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3422 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3423 /* RFC7083 */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3424 o = dhcp6_findmoption(r, len, D6_OPTION_SOL_MAX_RT, &ol);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3425 if (o && ol == sizeof(uint32_t)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3426 uint32_t max_rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3427
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3428 memcpy(&max_rt, o, sizeof(max_rt));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3429 max_rt = ntohl(max_rt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3430 if (max_rt >= 60 && max_rt <= 86400) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
3431 logdebugx("%s: SOL_MAX_RT %llu -> %u",
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
3432 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
3433 (unsigned long long)state->sol_max_rt,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3434 max_rt);
4939
b82b1e772a3d This cast is no longer needed.
Roy Marples <roy@marples.name>
parents: 4925
diff changeset
3435 state->sol_max_rt = max_rt;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3436 } else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3437 logerr("%s: invalid SOL_MAX_RT %u",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3438 ifp->name, max_rt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3439 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3440 o = dhcp6_findmoption(r, len, D6_OPTION_INF_MAX_RT, &ol);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3441 if (o && ol == sizeof(uint32_t)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3442 uint32_t max_rt;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3443
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3444 memcpy(&max_rt, o, sizeof(max_rt));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3445 max_rt = ntohl(max_rt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3446 if (max_rt >= 60 && max_rt <= 86400) {
4023
66f9399ba5c6 Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents: 4010
diff changeset
3447 logdebugx("%s: INF_MAX_RT %llu -> %u",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3448 ifp->name,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3449 (unsigned long long)state->inf_max_rt,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3450 max_rt);
4939
b82b1e772a3d This cast is no longer needed.
Roy Marples <roy@marples.name>
parents: 4925
diff changeset
3451 state->inf_max_rt = max_rt;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3452 } else
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3453 logerrx("%s: invalid INF_MAX_RT %u",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3454 ifp->name, max_rt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3455 }
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3456 if (dhcp6_validatelease(ifp, r, len, sfrom, NULL) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3457 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3458 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3459 case DHCP6_RECONFIGURE:
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
3460 #ifdef AUTH
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3461 if (auth == NULL) {
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
3462 #endif
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3463 logerrx("%s: unauthenticated %s from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3464 ifp->name, op, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3465 if (ifo->auth.options & DHCPCD_AUTH_REQUIRE)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3466 return;
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
3467 #ifdef AUTH
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3468 }
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3469 loginfox("%s: %s from %s", ifp->name, op, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3470 o = dhcp6_findmoption(r, len, D6_OPTION_RECONF_MSG, &ol);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3471 if (o == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3472 logerrx("%s: missing Reconfigure Message option",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3473 ifp->name);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3474 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3475 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3476 if (ol != 1) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3477 logerrx("%s: missing Reconfigure Message type",
3960
42a6a3d1596e Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents: 3932
diff changeset
3478 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
3479 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3480 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3481 switch(*o) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3482 case DHCP6_RENEW:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3483 if (state->state != DH6S_BOUND) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3484 logerrx("%s: not bound, ignoring %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3485 ifp->name, op);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3486 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3487 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3488 dhcp6_startrenew(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3489 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3490 case DHCP6_INFORMATION_REQ:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3491 if (state->state != DH6S_INFORMED) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3492 logerrx("%s: not informed, ignoring %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3493 ifp->name, op);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3494 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3495 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3496 eloop_timeout_delete(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
3497 dhcp6_sendinform, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3498 dhcp6_startinform(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3499 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3500 default:
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3501 logerr("%s: unsupported %s type %d",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3502 ifp->name, op, *o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3503 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3504 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3505 return;
4358
dd2971c0df6f gcc: appease gcc-7's implicit fallthrough warning
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
3506 #else
dd2971c0df6f gcc: appease gcc-7's implicit fallthrough warning
Roy Marples <roy@marples.name>
parents: 4355
diff changeset
3507 break;
3989
b05654495fd8 If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents: 3960
diff changeset
3508 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3509 default:
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3510 logerrx("%s: invalid DHCP6 type %s (%d)",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3511 ifp->name, op, r->type);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3512 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3513 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3514 if (!valid_op) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3515 logwarnx("%s: invalid state for DHCP6 type %s (%d)",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3516 ifp->name, op, r->type);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3517 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3518 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3519
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3520 if (state->recv_len < (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
3521 free(state->recv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3522 state->recv = malloc(len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3523 if (state->recv == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3524 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
3525 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3526 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3527 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3528 memcpy(state->recv, r, len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3529 state->recv_len = len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3530
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3531 if (r->type == DHCP6_ADVERTISE) {
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3532 struct ipv6_addr *ia;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3533
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3534 if (state->state == DH6S_REQUEST) /* rapid commit */
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3535 goto bind;
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3536 TAILQ_FOREACH(ia, &state->addrs, next) {
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3537 if (!(ia->flags & (IPV6_AF_STALE | IPV6_AF_REQUEST)))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3538 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3539 }
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3540 if (ia == NULL)
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3541 ia = TAILQ_FIRST(&state->addrs);
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3542 if (ia == NULL)
4071
f5ff6efdcf39 It's possible to receive a DHCPv6 lease without an address.
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
3543 loginfox("%s: ADV (no address) from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3544 ifp->name, sfrom);
4071
f5ff6efdcf39 It's possible to receive a DHCPv6 lease without an address.
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
3545 else
f5ff6efdcf39 It's possible to receive a DHCPv6 lease without an address.
Roy Marples <roy@marples.name>
parents: 4069
diff changeset
3546 loginfox("%s: ADV %s from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3547 ifp->name, ia->saddr, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3548 dhcp6_startrequest(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3549 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3550 }
5042
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3551
dac9291f82f0 DHCP6: Clean up old lease when we fail to confirm/rebind, etc
Roy Marples <roy@marples.name>
parents: 5038
diff changeset
3552 bind:
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3553 dhcp6_bind(ifp, op, sfrom);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3554 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3555
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
3556 void
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3557 dhcp6_recvmsg(struct dhcpcd_ctx *ctx, struct msghdr *msg, struct ipv6_addr *ia)
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3558 {
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3559 struct sockaddr_in6 *from = msg->msg_name;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3560 size_t len = msg->msg_iov[0].iov_len;
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3561 char sfrom[INET6_ADDRSTRLEN];
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3562 struct interface *ifp;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3563 struct dhcp6_message *r;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3564 const struct dhcp6_state *state;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3565 uint8_t *o;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3566 uint16_t ol;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3567
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3568 inet_ntop(AF_INET6, &from->sin6_addr, sfrom, sizeof(sfrom));
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3569 if (len < sizeof(struct dhcp6_message)) {
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3570 logerrx("DHCPv6 packet too short from %s", sfrom);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3571 return;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3572 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3573
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3574 if (ia != NULL)
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3575 ifp = ia->iface;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3576 else {
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3577 ifp = if_findifpfromcmsg(ctx, msg, NULL);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3578 if (ifp == NULL) {
4374
d67204739087 Fold all CMSG parsing into a common function.
Roy Marples <roy@marples.name>
parents: 4371
diff changeset
3579 logerr(__func__);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3580 return;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3581 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3582 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3583
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3584 r = (struct dhcp6_message *)msg->msg_iov[0].iov_base;
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3585
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3586 uint8_t duid[DUID_LEN], *dp;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3587 size_t duid_len;
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3588 o = dhcp6_findmoption(r, len, D6_OPTION_CLIENTID, &ol);
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3589 if (ifp->options->options & DHCPCD_ANONYMOUS) {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3590 duid_len = duid_make(duid, ifp, DUID_LL);
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3591 dp = duid;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3592 } else {
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3593 duid_len = ctx->duid_len;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3594 dp = ctx->duid;
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3595 }
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3596 if (o == NULL || ol != duid_len || memcmp(o, dp, ol) != 0) {
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3597 logdebugx("%s: incorrect client ID from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3598 ifp->name, sfrom);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3599 return;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3600 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3601
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3602 if (dhcp6_findmoption(r, len, D6_OPTION_SERVERID, NULL) == NULL) {
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3603 logdebugx("%s: no DHCPv6 server ID from %s",
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3604 ifp->name, sfrom);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3605 return;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3606 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3607
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3608 if (r->type == DHCP6_RECONFIGURE) {
5294
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3609 if (!IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) {
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3610 logerrx("%s: RECONFIGURE6 recv from %s, not LL",
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3611 ifp->name, sfrom);
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3612 return;
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3613 }
5294
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3614 goto recvif;
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3615 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3616
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3617 state = D6_CSTATE(ifp);
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3618 if (state == NULL ||
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3619 r->xid[0] != state->send->xid[0] ||
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3620 r->xid[1] != state->send->xid[1] ||
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3621 r->xid[2] != state->send->xid[2])
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3622 {
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3623 struct interface *ifp1;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3624 const struct dhcp6_state *state1;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3625
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3626 /* Find an interface with a matching xid. */
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3627 TAILQ_FOREACH(ifp1, ctx->ifaces, next) {
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3628 state1 = D6_CSTATE(ifp1);
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3629 if (state1 == NULL || state1->send == NULL)
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3630 continue;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3631 if (r->xid[0] == state1->send->xid[0] &&
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3632 r->xid[1] == state1->send->xid[1] &&
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3633 r->xid[2] == state1->send->xid[2])
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3634 break;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3635 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3636
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3637 if (ifp1 == NULL) {
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3638 if (state != NULL)
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3639 logdebugx("%s: wrong xid 0x%02x%02x%02x"
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3640 " (expecting 0x%02x%02x%02x) from %s",
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3641 ifp->name,
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3642 r->xid[0], r->xid[1], r->xid[2],
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3643 state->send->xid[0],
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3644 state->send->xid[1],
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3645 state->send->xid[2],
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3646 sfrom);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3647 return;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3648 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3649 logdebugx("%s: redirecting DHCP6 message to %s",
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3650 ifp->name, ifp1->name);
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3651 ifp = ifp1;
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3652 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3653
4893
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3654 #if 0
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3655 /*
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3656 * Handy code to inject raw DHCPv6 packets over responses
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3657 * from our server.
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3658 * This allows me to take a 3rd party wireshark trace and
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3659 * replay it in my code.
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3660 */
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3661 static int replyn = 0;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3662 char fname[PATH_MAX], tbuf[UDPLEN_MAX];
4893
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3663 int fd;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3664 ssize_t tlen;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3665 uint8_t *si1, *si2;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3666 uint16_t si_len1, si_len2;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3667
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3668 snprintf(fname, sizeof(fname),
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3669 "/tmp/dhcp6.reply%d.raw", replyn++);
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3670 fd = open(fname, O_RDONLY, 0);
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3671 if (fd == -1) {
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
3672 logerr("%s: open: %s", __func__, fname);
4893
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3673 return;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3674 }
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3675 tlen = read(fd, tbuf, sizeof(tbuf));
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3676 if (tlen == -1)
5494
0fbde4769bbe Don't log backticks.
Roy Marples <roy@marples.name>
parents: 5484
diff changeset
3677 logerr("%s: read: %s", __func__, fname);
4893
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3678 close(fd);
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3679
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3680 /* Copy across ServerID so we can work with our own server. */
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3681 si1 = dhcp6_findmoption(r, len, D6_OPTION_SERVERID, &si_len1);
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3682 si2 = dhcp6_findmoption(tbuf, (size_t)tlen,
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3683 D6_OPTION_SERVERID, &si_len2);
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3684 if (si1 != NULL && si2 != NULL && si_len1 == si_len2)
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3685 memcpy(si2, si1, si_len2);
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3686 r = (struct dhcp6_message *)tbuf;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3687 len = (size_t)tlen;
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3688 #endif
483c46e3c582 DHCP6: Add disabled code to allow packet replay
Roy Marples <roy@marples.name>
parents: 4890
diff changeset
3689
5294
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
3690 recvif:
4371
a7f3d85f54ce Remove the send/recv structures from dhcpcd context and allocate
Roy Marples <roy@marples.name>
parents: 4358
diff changeset
3691 dhcp6_recvif(ifp, sfrom, r, len);
4178
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3692 }
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3693
ffc26bed14d2 dhcp6: redirect message to interface with matching xid
Roy Marples <roy@marples.name>
parents: 4177
diff changeset
3694 static void
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3695 dhcp6_recv(struct dhcpcd_ctx *ctx, struct ipv6_addr *ia)
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3696 {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3697 struct sockaddr_in6 from;
5193
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
3698 union {
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
3699 struct dhcp6_message dhcp6;
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
3700 uint8_t buf[UDPLEN_MAX]; /* Maximum UDP message size */
5193
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
3701 } iovbuf;
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3702 struct iovec iov = {
5193
658eb5d94c0b DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents: 5172
diff changeset
3703 .iov_base = iovbuf.buf, .iov_len = sizeof(iovbuf.buf),
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3704 };
5160
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5151
diff changeset
3705 union {
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5151
diff changeset
3706 struct cmsghdr hdr;
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5151
diff changeset
3707 uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5151
diff changeset
3708 } cmsgbuf = { .buf = { 0 } };
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3709 struct msghdr msg = {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3710 .msg_name = &from, .msg_namelen = sizeof(from),
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3711 .msg_iov = &iov, .msg_iovlen = 1,
5160
01d56b8eb743 align CMSG buffer
Roy Marples <roy@marples.name>
parents: 5151
diff changeset
3712 .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3713 };
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3714 int s;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3715 ssize_t bytes;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3716
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3717 s = ia != NULL ? ia->dhcp6_fd : ctx->dhcp6_rfd;
4787
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3718 bytes = recvmsg(s, &msg, 0);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3719 if (bytes == -1) {
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3720 logerr(__func__);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3721 return;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3722 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3723
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3724 iov.iov_len = (size_t)bytes;
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3725 dhcp6_recvmsg(ctx, &msg, ia);
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3726 }
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3727
d3a3a2ab8ba9 Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents: 4754
diff changeset
3728 static void
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3729 dhcp6_recvaddr(void *arg)
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3730 {
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3731 struct ipv6_addr *ia = arg;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3732
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3733 dhcp6_recv(ia->iface->ctx, ia);
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3734 }
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3735
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3736 static void
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3737 dhcp6_recvctx(void *arg)
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3738 {
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3739 struct dhcpcd_ctx *ctx = arg;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3740
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3741 dhcp6_recv(ctx, NULL);
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3742 }
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3743
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
3744 int
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3745 dhcp6_openraw(void)
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3746 {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3747 int fd, v;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3748
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3749 fd = socket(PF_INET6, SOCK_RAW | SOCK_CXNB, IPPROTO_UDP);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3750 if (fd == -1)
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3751 return -1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3752
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3753 v = 1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3754 if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &v, sizeof(v)) == -1)
5281
9f9a330f6e24 Fix some Coverity isues
Roy Marples <roy@marples.name>
parents: 5275
diff changeset
3755 goto errexit;
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3756
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3757 v = offsetof(struct udphdr, uh_sum);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3758 if (setsockopt(fd, IPPROTO_IPV6, IPV6_CHECKSUM, &v, sizeof(v)) == -1)
5281
9f9a330f6e24 Fix some Coverity isues
Roy Marples <roy@marples.name>
parents: 5275
diff changeset
3759 goto errexit;
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3760
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3761 return fd;
5281
9f9a330f6e24 Fix some Coverity isues
Roy Marples <roy@marples.name>
parents: 5275
diff changeset
3762
9f9a330f6e24 Fix some Coverity isues
Roy Marples <roy@marples.name>
parents: 5275
diff changeset
3763 errexit:
9f9a330f6e24 Fix some Coverity isues
Roy Marples <roy@marples.name>
parents: 5275
diff changeset
3764 close(fd);
9f9a330f6e24 Fix some Coverity isues
Roy Marples <roy@marples.name>
parents: 5275
diff changeset
3765 return -1;
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3766 }
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3767
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3768 int
4830
4cc46a5fd589 DHCP6: Improve API for privsep
Roy Marples <roy@marples.name>
parents: 4793
diff changeset
3769 dhcp6_openudp(unsigned int ifindex, struct in6_addr *ia)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3770 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3771 struct sockaddr_in6 sa;
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3772 int n, s;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3773
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3774 s = xsocket(PF_INET6, SOCK_DGRAM | SOCK_CXNB, IPPROTO_UDP);
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3775 if (s == -1)
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3776 goto errexit;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3777
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3778 memset(&sa, 0, sizeof(sa));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3779 sa.sin6_family = AF_INET6;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3780 sa.sin6_port = htons(DHCP6_CLIENT_PORT);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3781 #ifdef BSD
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3782 sa.sin6_len = sizeof(sa);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3783 #endif
4175
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
3784
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3785 if (ia != NULL) {
4830
4cc46a5fd589 DHCP6: Improve API for privsep
Roy Marples <roy@marples.name>
parents: 4793
diff changeset
3786 memcpy(&sa.sin6_addr, ia, sizeof(sa.sin6_addr));
5195
45226e01fbdd inet6: Move BSD get/set scope function to ipv6 for general use
Roy Marples <roy@marples.name>
parents: 5193
diff changeset
3787 ipv6_setscope(&sa, ifindex);
4233
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3788 }
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3789
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3790 if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) == -1)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3791 goto errexit;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3792
4233
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3793 n = 1;
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3794 if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &n, sizeof(n)) == -1)
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3795 goto errexit;
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3796
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3797 #ifdef SO_RERROR
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3798 n = 1;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3799 if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1)
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3800 goto errexit;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3801 #endif
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3802
4129
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3803 return s;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3804
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3805 errexit:
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3806 logerr(__func__);
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3807 if (s != -1)
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3808 close(s);
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3809 return -1;
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3810 }
ab62c179db78 dhcp6: listen to each DHCP address for messages
Roy Marples <roy@marples.name>
parents: 4126
diff changeset
3811
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3812 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3813 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3814 dhcp6_activateinterfaces(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
3815 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3816 struct interface *ifd;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3817 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
3818 struct if_ia *ia;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3819 struct if_sla *sla;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3820
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3821 for (i = 0; i < ifp->options->ia_len; i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3822 ia = &ifp->options->ia[i];
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
3823 if (ia->ia_type != D6_OPTION_IA_PD)
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
3824 continue;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3825 for (j = 0; j < ia->sla_len; j++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3826 sla = &ia->sla[j];
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3827 ifd = if_find(ifp->ctx->ifaces, sla->ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3828 if (ifd == NULL) {
4010
746684127581 logerr: errx with logging
Roy Marples <roy@marples.name>
parents: 3989
diff changeset
3829 logwarn("%s: cannot delegate to %s",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3830 ifp->name, sla->ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3831 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3832 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3833 if (!ifd->active) {
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
3834 loginfox("%s: activating for delegation",
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3835 sla->ifname);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3836 dhcpcd_activateinterface(ifd,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3837 DHCPCD_IPV6 | DHCPCD_DHCP6);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3838 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3839 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3840 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3841 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3842 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3843
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3844 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3845 dhcp6_start1(void *arg)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3846 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3847 struct interface *ifp = arg;
4233
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3848 struct dhcpcd_ctx *ctx = 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
3849 struct if_options *ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3850 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3851 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
3852 const struct dhcp_compat *dhc;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3853
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
3854 if ((ctx->options & (DHCPCD_MASTER|DHCPCD_PRIVSEP)) == DHCPCD_MASTER &&
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3855 ctx->dhcp6_rfd == -1)
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
3856 {
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3857 ctx->dhcp6_rfd = dhcp6_openudp(0, NULL);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3858 if (ctx->dhcp6_rfd == -1) {
4831
f60174650135 DHCP6: Fix prior to log an error
Roy Marples <roy@marples.name>
parents: 4830
diff changeset
3859 logerr(__func__);
4233
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3860 return;
4831
f60174650135 DHCP6: Fix prior to log an error
Roy Marples <roy@marples.name>
parents: 4830
diff changeset
3861 }
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3862 eloop_event_add(ctx->eloop, ctx->dhcp6_rfd, dhcp6_recvctx, ctx);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3863 }
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3864
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3865 if (!IN_PRIVSEP(ctx) && ctx->dhcp6_wfd == -1) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3866 ctx->dhcp6_wfd = dhcp6_openraw();
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3867 if (ctx->dhcp6_wfd == -1) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3868 logerr(__func__);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3869 return;
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
3870 }
4233
c2a1efc6b19a dhcp6: deny unicast in non master mode
Roy Marples <roy@marples.name>
parents: 4232
diff changeset
3871 }
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3872
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3873 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3874 /* If no DHCPv6 options are configured,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3875 match configured DHCPv4 options to DHCPv6 equivalents. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3876 for (i = 0; i < sizeof(ifo->requestmask6); i++) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3877 if (ifo->requestmask6[i] != '\0')
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3878 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3879 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3880 if (i == sizeof(ifo->requestmask6)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3881 for (dhc = dhcp_compats; dhc->dhcp_opt; dhc++) {
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3882 if (DHC_REQ(ifo->requestmask, ifo->nomask, dhc->dhcp_opt))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3883 add_option_mask(ifo->requestmask6,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3884 dhc->dhcp6_opt);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3885 }
4958
a120f447fe74 Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents: 4942
diff changeset
3886 if (ifo->fqdn != FQDN_DISABLE || ifo->options & DHCPCD_HOSTNAME)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3887 add_option_mask(ifo->requestmask6, D6_OPTION_FQDN);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3888 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3889
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3890 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3891 /* Rapid commit won't work with Prefix Delegation Exclusion */
4282
18aa55c59279 dhcp6: Stop non delegated addresses being delegated
Roy Marples <roy@marples.name>
parents: 4281
diff changeset
3892 if (dhcp6_findselfsla(ifp))
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3893 del_option_mask(ifo->requestmask6, D6_OPTION_RAPID_COMMIT);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3894 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3895
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3896 if (state->state == DH6S_INFORM) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3897 add_option_mask(ifo->requestmask6, D6_OPTION_INFO_REFRESH_TIME);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3898 dhcp6_startinform(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3899 } else {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3900 del_option_mask(ifo->requestmask6, D6_OPTION_INFO_REFRESH_TIME);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3901 dhcp6_startinit(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3902 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3903
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3904 #ifndef SMALL
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3905 dhcp6_activateinterfaces(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3906 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3907 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3908
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3909 int
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3910 dhcp6_start(struct interface *ifp, 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
3911 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3912 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3913
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3914 state = D6_STATE(ifp);
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3915 if (state != NULL) {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3916 switch (init_state) {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3917 case DH6S_INIT:
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3918 goto gogogo;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3919 case DH6S_INFORM:
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3920 if (state->state == DH6S_INIT ||
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3921 state->state == DH6S_INFORMED ||
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3922 (state->state == DH6S_DISCOVER &&
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3923 !(ifp->options->options & DHCPCD_IA_FORCED) &&
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3924 !ipv6nd_hasradhcp(ifp, true)))
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3925 dhcp6_startinform(ifp);
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3926 break;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3927 case DH6S_REQUEST:
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3928 if (ifp->options->options & DHCPCD_DHCP6 &&
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3929 (state->state == DH6S_INIT ||
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3930 state->state == DH6S_INFORM ||
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3931 state->state == DH6S_INFORMED ||
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3932 state->state == DH6S_DELEGATED))
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3933 {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3934 /* Change from stateless to stateful */
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3935 init_state = DH6S_INIT;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3936 goto gogogo;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3937 }
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3938 break;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3939 case DH6S_CONFIRM:
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3940 init_state = DH6S_INIT;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3941 goto gogogo;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3942 default:
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3943 /* Not possible, but sushes some compiler warnings. */
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3944 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3945 }
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3946 return 0;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3947 } else {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3948 switch (init_state) {
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3949 case DH6S_CONFIRM:
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3950 /* No DHCPv6 config, no existing state
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3951 * so nothing to do. */
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3952 return 0;
4543
a51511507597 DHCP6: Fix INFORM support
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
3953 case DH6S_INFORM:
a51511507597 DHCP6: Fix INFORM support
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
3954 break;
4183
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3955 default:
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3956 init_state = DH6S_INIT;
115cbfa711e2 DHCPv6: confirm lease on carrier up
Roy Marples <roy@marples.name>
parents: 4179
diff changeset
3957 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3958 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3959 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3960
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3961 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
3962 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3963
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3964 ifp->if_data[IF_DATA_DHCP6] = 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
3965 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3966 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
3967 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3968
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3969 state->sol_max_rt = SOL_MAX_RT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3970 state->inf_max_rt = INF_MAX_RT;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3971 TAILQ_INIT(&state->addrs);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3972
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3973 gogogo:
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3974 state->state = init_state;
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
3975 state->lerror = 0;
5151
3c6da4e11150 DHCP6: don't log when things consitently fail
Roy Marples <roy@marples.name>
parents: 5127
diff changeset
3976 state->failed = false;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3977 dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3978 AF_INET6, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3979 if (ipv6_linklocal(ifp) == NULL) {
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
3980 logdebugx("%s: delaying DHCPv6 for LL address", 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
3981 ipv6_addlinklocalcallback(ifp, dhcp6_start1, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3982 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3983 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3984
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3985 dhcp6_start1(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3986 return 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3987 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3988
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3989 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3990 dhcp6_reboot(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
3991 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3992 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3993
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
3994 state = D6_STATE(ifp);
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
3995 if (state == NULL)
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
3996 return;
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
3997
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
3998 state->lerror = 0;
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
3999 switch (state->state) {
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
4000 case DH6S_BOUND:
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
4001 dhcp6_startrebind(ifp);
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
4002 break;
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
4003 default:
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4004 dhcp6_startdiscoinform(ifp);
4423
22c551e08f53 DHCP6: Don't spam syslog if we get the same error over and over
Roy Marples <roy@marples.name>
parents: 4418
diff changeset
4005 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4006 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4007 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4008
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4009 static void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4010 dhcp6_freedrop(struct interface *ifp, int drop, const char *reason)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4011 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4012 struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4013 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
4014 unsigned long long options;
4062
9ecf74393d25 DHCPv6: drop Prefix Delegations when dropping the lease.
Roy Marples <roy@marples.name>
parents: 4056
diff changeset
4015
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4016 if (ifp->options)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4017 options = ifp->options->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4018 else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4019 options = ifp->ctx->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4020
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4021 if (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
4022 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
4023
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4024 #ifndef SMALL
4062
9ecf74393d25 DHCPv6: drop Prefix Delegations when dropping the lease.
Roy Marples <roy@marples.name>
parents: 4056
diff changeset
4025 /* If we're dropping the lease, drop delegated addresses.
9ecf74393d25 DHCPv6: drop Prefix Delegations when dropping the lease.
Roy Marples <roy@marples.name>
parents: 4056
diff changeset
4026 * If, for whatever reason, we don't drop them in the future
9ecf74393d25 DHCPv6: drop Prefix Delegations when dropping the lease.
Roy Marples <roy@marples.name>
parents: 4056
diff changeset
4027 * then they should at least be marked as deprecated (pltime 0). */
9ecf74393d25 DHCPv6: drop Prefix Delegations when dropping the lease.
Roy Marples <roy@marples.name>
parents: 4056
diff changeset
4028 if (drop && (options & DHCPCD_NODROP) != DHCPCD_NODROP)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4029 dhcp6_delete_delegates(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4030 #endif
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4031
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4032 state = D6_STATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4033 if (state) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4034 /* Failure to send the release may cause this function to
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4035 * re-enter */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4036 if (state->state == DH6S_RELEASE) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4037 dhcp6_finishrelease(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4038 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4039 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4040
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4041 if (drop && options & DHCPCD_RELEASE &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4042 state->state != DH6S_DELEGATED)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4043 {
5499
6a2da5651841 dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents: 5497
diff changeset
4044 if (if_is_link_up(ifp) &&
4107
ce438a54efa7 Treat INFORMED as a released state so it's dropped by the hooks
Roy Marples <roy@marples.name>
parents: 4105
diff changeset
4045 state->state != DH6S_RELEASED &&
ce438a54efa7 Treat INFORMED as a released state so it's dropped by the hooks
Roy Marples <roy@marples.name>
parents: 4105
diff changeset
4046 state->state != DH6S_INFORMED)
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4047 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4048 dhcp6_startrelease(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4049 return;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4050 }
5207
84b63f09c8a4 privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents: 5195
diff changeset
4051 dhcp_unlink(ifp->ctx, state->leasefile);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4052 }
5294
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4053 #ifdef AUTH
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4054 else if (state->auth.reconf != NULL) {
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4055 /*
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4056 * Drop the lease as the token may only be present
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4057 * in the initial reply message and not subsequent
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4058 * renewals.
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4059 * If dhcpcd is restarted, the token is lost.
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4060 * XXX persist this in another file?
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4061 */
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4062 dhcp_unlink(ifp->ctx, state->leasefile);
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4063 }
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4064 #endif
942ddb46cd55 auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents: 5288
diff changeset
4065
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4066 dhcp6_freedrop_addrs(ifp, drop, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4067 free(state->old);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4068 state->old = state->new;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4069 state->old_len = state->new_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4070 state->new = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4071 state->new_len = 0;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4072 if (drop && state->old &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4073 (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
4074 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4075 if (reason == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4076 reason = "STOP6";
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4077 script_runreason(ifp, reason);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4078 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4079 free(state->old);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4080 free(state->send);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4081 free(state->recv);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4082 free(state);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4083 ifp->if_data[IF_DATA_DHCP6] = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4084 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4085
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4086 /* If we don't have any more DHCP6 enabled interfaces,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4087 * 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
4088 ctx = ifp->ctx;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4089 if (ctx->ifaces) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4090 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
4091 if (D6_STATE(ifp))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4092 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4093 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4094 }
5231
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
4095 if (ifp == NULL && ctx->dhcp6_rfd != -1) {
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
4096 eloop_event_delete(ctx->eloop, ctx->dhcp6_rfd);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
4097 close(ctx->dhcp6_rfd);
a2c342295221 privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents: 5226
diff changeset
4098 ctx->dhcp6_rfd = -1;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4099 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4100 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4101
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4102 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4103 dhcp6_drop(struct interface *ifp, const char *reason)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4104 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4105
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4106 dhcp6_freedrop(ifp, 1, reason);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4107 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4108
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4109 void
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4110 dhcp6_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
4111 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4112
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4113 dhcp6_freedrop(ifp, 0, NULL);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4114 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4115
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4116 void
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4117 dhcp6_abort(struct interface *ifp)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4118 {
5074
5df0f92ade6d DHCP6: Fix SMALL build
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
4119 struct dhcp6_state *state;
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4560
diff changeset
4120 #ifdef ND6_ADVERTISE
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4121 struct ipv6_addr *ia;
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4560
diff changeset
4122 #endif
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4123
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4124 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_start1, ifp);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4125 state = D6_STATE(ifp);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4126 if (state == NULL)
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4127 return;
5074
5df0f92ade6d DHCP6: Fix SMALL build
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
4128
5df0f92ade6d DHCP6: Fix SMALL build
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
4129 #ifdef ND6_ADVERTISE
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4130 TAILQ_FOREACH(ia, &state->addrs, next) {
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4131 ipv6nd_advertise(ia);
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4132 }
4588
6aced73a8438 Remove ND6 Advertisement from SMALL builds.
Roy Marples <roy@marples.name>
parents: 4560
diff changeset
4133 #endif
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4134
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4135 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_startdiscover, ifp);
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4136 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_senddiscover, ifp);
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4137 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_startinform, ifp);
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4138 eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendinform, ifp);
5074
5df0f92ade6d DHCP6: Fix SMALL build
Roy Marples <roy@marples.name>
parents: 5064
diff changeset
4139
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4140 switch (state->state) {
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4141 case DH6S_DISCOVER: /* FALLTHROUGH */
5046
91d05626f72d Add an extra fallthrough to prior
Roy Marples <roy@marples.name>
parents: 5044
diff changeset
4142 case DH6S_REQUEST: /* FALLTHROUGH */
5044
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4143 case DH6S_INFORM:
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4144 state->state = DH6S_INIT;
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4145 break;
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4146 default:
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4147 break;
f51d310db3b7 inet6: Swap between DISCOVER and INFORM better
Roy Marples <roy@marples.name>
parents: 5042
diff changeset
4148 }
4335
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4149 }
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4150
d0519e1f2f5f ip6: Implement IPv6 address sharing
Roy Marples <roy@marples.name>
parents: 4333
diff changeset
4151 void
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4231
diff changeset
4152 dhcp6_handleifa(int cmd, struct ipv6_addr *ia, 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
4153 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4154 struct dhcp6_state *state;
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
4155 struct interface *ifp = ia->iface;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4156
4175
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
4157 /* If not running in master mode, listen to this address */
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
4158 if (cmd == RTM_NEWADDR &&
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
4159 !(ia->addr_flags & IN6_IFF_NOTUSEABLE) &&
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
4160 ifp->active == IF_ACTIVE_USER &&
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
4161 !(ifp->ctx->options & DHCPCD_MASTER) &&
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4162 ifp->options->options & DHCPCD_DHCP6)
4830
4cc46a5fd589 DHCP6: Improve API for privsep
Roy Marples <roy@marples.name>
parents: 4793
diff changeset
4163 {
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4164 #ifdef PRIVSEP
4869
5bad3606b951 privsep: prefer IN_PRIVSEP macros
Roy Marples <roy@marples.name>
parents: 4841
diff changeset
4165 if (IN_PRIVSEP_SE(ifp->ctx)) {
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4166 if (ps_inet_opendhcp6(ia) == -1)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4167 logerr(__func__);
4841
bace61b4b4ff Solaris: Fix non PRIVSEP compile
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
4168 } else
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4169 #endif
4841
bace61b4b4ff Solaris: Fix non PRIVSEP compile
Roy Marples <roy@marples.name>
parents: 4840
diff changeset
4170 {
4840
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4171 if (ia->dhcp6_fd == -1)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4172 ia->dhcp6_fd = dhcp6_openudp(ia->iface->index,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4173 &ia->addr);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4174 if (ia->dhcp6_fd != -1)
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4175 eloop_event_add(ia->iface->ctx->eloop,
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4176 ia->dhcp6_fd, dhcp6_recvaddr, ia);
073fcd86db9b privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents: 4831
diff changeset
4177 }
4830
4cc46a5fd589 DHCP6: Improve API for privsep
Roy Marples <roy@marples.name>
parents: 4793
diff changeset
4178 }
4cc46a5fd589 DHCP6: Improve API for privsep
Roy Marples <roy@marples.name>
parents: 4793
diff changeset
4179
4175
2a14528ebe96 DHCPv6: listen on all IPv6 addresses for active interface
Roy Marples <roy@marples.name>
parents: 4145
diff changeset
4180
4189
0b088d803b61 dhcp6: don't listen on IPv6 addresses when not using DHCP6
Roy Marples <roy@marples.name>
parents: 4183
diff changeset
4181 if ((state = D6_STATE(ifp)) != NULL)
4232
8b92c1844860 Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents: 4231
diff changeset
4182 ipv6_handleifa_addrs(cmd, &state->addrs, ia, pid);
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4183 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4184
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4185 ssize_t
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4186 dhcp6_env(FILE *fp, const char *prefix, const struct interface *ifp,
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4187 const struct dhcp6_message *m, 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
4188 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4189 const struct if_options *ifo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4190 struct dhcp_opt *opt, *vo;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4191 const 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
4192 struct dhcp6_option o;
4538
8e383f84ebd0 Remove now unused variables.
Roy Marples <roy@marples.name>
parents: 4535
diff changeset
4193 size_t i;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4194 char *pfx;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4195 uint32_t en;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4196 const struct dhcpcd_ctx *ctx;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
4197 #ifndef SMALL
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4198 const struct dhcp6_state *state;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4199 const struct ipv6_addr *ap;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
4200 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4201
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4202 if (m == NULL)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4203 goto delegated;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4204
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4205 if (len < sizeof(*m)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4206 /* Should be impossible with guards at packet in
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4207 * and reading leases */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4208 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4209 return -1;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4210 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4211
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4212 ifo = ifp->options;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4213 ctx = ifp->ctx;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4214
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4215 /* Zero our indexes */
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4216 for (i = 0, opt = ctx->dhcp6_opts;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4217 i < ctx->dhcp6_opts_len;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4218 i++, opt++)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4219 dhcp_zero_index(opt);
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4220 for (i = 0, opt = ifp->options->dhcp6_override;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4221 i < ifp->options->dhcp6_override_len;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4222 i++, opt++)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4223 dhcp_zero_index(opt);
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4224 for (i = 0, opt = ctx->vivso;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4225 i < ctx->vivso_len;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4226 i++, opt++)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4227 dhcp_zero_index(opt);
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4228 if (asprintf(&pfx, "%s_dhcp6", prefix) == -1)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4229 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
4230
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4231 /* Unlike DHCP, DHCPv6 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
4232 * There is also no provision for option concatenation unlike DHCP. */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4233 p = (const uint8_t *)m + sizeof(*m);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4234 len -= sizeof(*m);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4235 for (; len != 0; p += o.len, len -= o.len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4236 if (len < sizeof(o)) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4237 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4238 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4239 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4240 memcpy(&o, p, sizeof(o));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4241 p += sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4242 len -= sizeof(o);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4243 o.len = ntohs(o.len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4244 if (len < o.len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4245 errno = EINVAL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4246 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4247 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4248 o.code = ntohs(o.code);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4249 if (has_option_mask(ifo->nomask6, o.code))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4250 continue;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4251 for (i = 0, opt = ifo->dhcp6_override;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4252 i < ifo->dhcp6_override_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4253 i++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4254 if (opt->option == o.code)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4255 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4256 if (i == ifo->dhcp6_override_len &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4257 o.code == D6_OPTION_VENDOR_OPTS &&
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4258 o.len > sizeof(en))
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4259 {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4260 memcpy(&en, p, sizeof(en));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4261 en = ntohl(en);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4262 vo = vivso_find(en, ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4263 } else
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4264 vo = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4265 if (i == ifo->dhcp6_override_len) {
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4266 for (i = 0, opt = ctx->dhcp6_opts;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4267 i < ctx->dhcp6_opts_len;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4268 i++, opt++)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4269 if (opt->option == o.code)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4270 break;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4271 if (i == ctx->dhcp6_opts_len)
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4272 opt = NULL;
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4273 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4274 if (opt) {
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4275 dhcp_envoption(ifp->ctx,
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4276 fp, pfx, 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
4277 opt, dhcp6_getoption, p, o.len);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4278 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4279 if (vo) {
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4280 dhcp_envoption(ifp->ctx,
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4281 fp, pfx, 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
4282 vo, dhcp6_getoption,
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4283 p + sizeof(en),
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4284 o.len - sizeof(en));
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4285 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4286 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4287 free(pfx);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4288
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4289 delegated:
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
4290 #ifndef SMALL
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4291 /* Needed for Delegated Prefixes */
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4292 state = D6_CSTATE(ifp);
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4293 TAILQ_FOREACH(ap, &state->addrs, next) {
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4294 if (ap->delegating_prefix)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4295 break;
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4296 }
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4297 if (ap == NULL)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4298 return 1;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4299 if (fprintf(fp, "%s_delegated_dhcp6_prefix=", prefix) == -1)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4300 return -1;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4301 TAILQ_FOREACH(ap, &state->addrs, next) {
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4302 if (ap->delegating_prefix == NULL)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4303 continue;
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4304 if (ap != TAILQ_FIRST(&state->addrs)) {
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4305 if (fputc(' ', fp) == EOF)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4306 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
4307 }
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4308 if (fprintf(fp, "%s", ap->saddr) == -1)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4309 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
4310 }
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4311 if (fputc('\0', fp) == EOF)
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4312 return -1;
4069
026bd55d5f0f Remove more prefix delegation code for small binaries.
Roy Marples <roy@marples.name>
parents: 4065
diff changeset
4313 #endif
3932
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4314
4535
f2ddefe6c69e script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents: 4532
diff changeset
4315 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
4316 }
e802a4235d75 Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff changeset
4317 #endif
5288
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4318
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4319 #ifndef SMALL
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4320 int
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4321 dhcp6_dump(struct interface *ifp)
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4322 {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4323 struct dhcp6_state *state;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4324
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4325 ifp->if_data[IF_DATA_DHCP6] = state = calloc(1, sizeof(*state));
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4326 if (state == NULL) {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4327 logerr(__func__);
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4328 return -1;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4329 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4330 TAILQ_INIT(&state->addrs);
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4331 if (dhcp6_readlease(ifp, 0) == -1) {
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4332 logerr("dhcp6_readlease");
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4333 return -1;
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4334 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4335 state->reason = "DUMP6";
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4336 return script_runreason(ifp, state->reason);
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4337 }
30958d539e6c Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents: 5281
diff changeset
4338 #endif