Mercurial > hg > dhcpcd
annotate src/dhcp.c @ 5530:226b850d158d draft
Fix compile without various defines
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Fri, 30 Oct 2020 22:18:57 +0000 |
| parents | 16610f4104a4 |
| children | a0d828e25482 |
| rev | line source |
|---|---|
|
4548
c7df03794de3
Add SPDX identifiers to all dhcpcd source files.
Yegor Yefremov <yegorslists@googlemail.com>
parents:
4536
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 | 4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
5 * All rights reserved |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
8 * modification, are permitted provided that the following conditions |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
9 * are met: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
10 * 1. Redistributions of source code must retain the above copyright |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
11 * notice, this list of conditions and the following disclaimer. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
13 * notice, this list of conditions and the following disclaimer in the |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
14 * documentation and/or other materials provided with the distribution. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
15 * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
26 * SUCH DAMAGE. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
27 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
28 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
29 #include <sys/param.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
30 #include <sys/socket.h> |
|
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 <arpa/inet.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
33 #include <net/if.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
34 #include <net/route.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
35 #include <netinet/if_ether.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
36 #include <netinet/in_systm.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
37 #include <netinet/in.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
38 #include <netinet/ip.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
39 #define __FAVOR_BSD /* Nasty glibc hack so we can use BSD semantics for UDP */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
40 #include <netinet/udp.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
41 #undef __FAVOR_BSD |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
42 |
| 4784 | 43 #ifdef AF_LINK |
| 44 # include <net/if_dl.h> | |
| 45 #endif | |
| 46 | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
47 #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
|
48 #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
|
49 #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
|
50 #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
|
51 #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
|
52 #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
|
53 #include <stddef.h> |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
54 #include <stdio.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
55 #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
|
56 #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
|
57 #include <unistd.h> |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
58 #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
|
59 |
|
5038
1e35e845790a
eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents:
5033
diff
changeset
|
60 #define ELOOP_QUEUE ELOOP_DHCP |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
61 #include "config.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
62 #include "arp.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 "bpf.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
64 #include "common.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
65 #include "dhcp.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
66 #include "dhcpcd.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
67 #include "dhcp-common.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
68 #include "duid.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
69 #include "eloop.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
70 #include "if.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
71 #include "ipv4.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
72 #include "ipv4ll.h" |
| 4010 | 73 #include "logerr.h" |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
74 #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
|
75 #include "sa.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
76 #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
|
77 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
78 #define DAD "Duplicate address detected" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
79 #define DHCP_MIN_LEASE 20 |
|
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 #define IPV4A ADDRIPV4 | ARRAY |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
82 #define IPV4R ADDRIPV4 | REQUEST |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
83 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
84 /* We should define a maximum for the NAK exponential backoff */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
85 #define NAKOFF_MAX 60 |
|
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 /* Wait N nanoseconds between sending a RELEASE and dropping the address. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
88 * This gives the kernel enough time to actually send it. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
89 #define RELEASE_DELAY_S 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
90 #define RELEASE_DELAY_NS 10000000 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
91 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
92 #ifndef IPDEFTTL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
93 #define IPDEFTTL 64 /* RFC1340 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
94 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
95 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
96 /* Support older systems with different defines */ |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
97 #if !defined(IP_RECVPKTINFO) && defined(IP_PKTINFO) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
98 #define IP_RECVPKTINFO IP_PKTINFO |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
99 #endif |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
100 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
101 /* 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
|
102 __CTASSERT(sizeof(struct ip) == 20); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
103 __CTASSERT(sizeof(struct udphdr) == 8); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
104 __CTASSERT(sizeof(struct bootp) == 300); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
105 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
106 struct dhcp_op { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
107 uint8_t value; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
108 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
|
109 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
110 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
111 static const struct dhcp_op dhcp_ops[] = { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
112 { DHCP_DISCOVER, "DISCOVER" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
113 { DHCP_OFFER, "OFFER" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
114 { DHCP_REQUEST, "REQUEST" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
115 { DHCP_DECLINE, "DECLINE" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
116 { DHCP_ACK, "ACK" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
117 { DHCP_NAK, "NAK" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
118 { DHCP_RELEASE, "RELEASE" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
119 { DHCP_INFORM, "INFORM" }, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
120 { DHCP_FORCERENEW, "FORCERENEW"}, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
121 { 0, NULL } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
122 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
123 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
124 static const char * const dhcp_params[] = { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
125 "ip_address", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
126 "subnet_cidr", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
127 "network_number", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
128 "filename", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
129 "server_name", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
130 NULL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
131 }; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
132 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
133 static int dhcp_openbpf(struct interface *); |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
134 static void dhcp_start1(void *); |
|
4585
745c62847a59
Fix compile on NetBSD with ARP but not ARPING
Roy Marples <roy@marples.name>
parents:
4584
diff
changeset
|
135 #if defined(ARP) && (!defined(KERNEL_RFC5227) || defined(ARPING)) |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
136 static void dhcp_arp_found(struct arp_state *, const struct arp_msg *); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
137 #endif |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
138 static void dhcp_handledhcp(struct interface *, struct bootp *, size_t, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
139 const struct in_addr *); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
140 static void dhcp_handleifudp(void *); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
141 static int dhcp_initstate(struct interface *); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
142 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
143 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
144 dhcp_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
|
145 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
|
146 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
147 const char * const *p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
148 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
|
149 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
|
150 int cols; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
151 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
152 for (p = dhcp_params; *p; p++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
153 printf(" %s\n", *p); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
154 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
155 for (i = 0, opt = ctx->dhcp_opts; i < ctx->dhcp_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
|
156 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
|
157 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
|
158 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
159 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
|
160 cols = printf("%03d %s", opt->option, opt->var); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
161 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
|
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 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
|
165 cols = printf("%03d %s", opt->option, opt->var); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
166 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
|
167 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
168 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
169 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
170 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
|
171 get_option(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
|
172 const struct bootp *bootp, size_t bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
173 unsigned int opt, size_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
|
174 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
175 const uint8_t *p, *e; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
176 uint8_t l, o, ol, overl, *bp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
177 const uint8_t *op; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
178 size_t bl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
179 |
|
4904
8a4470e92585
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4868
diff
changeset
|
180 if (bootp == NULL || bootp_len < DHCP_MIN_LEN) { |
|
8a4470e92585
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4868
diff
changeset
|
181 errno = EINVAL; |
|
8a4470e92585
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4868
diff
changeset
|
182 return NULL; |
|
8a4470e92585
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4868
diff
changeset
|
183 } |
|
8a4470e92585
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4868
diff
changeset
|
184 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
185 /* Check we have the magic cookie */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
186 if (!IS_DHCP(bootp)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
187 errno = ENOTSUP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
188 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
189 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
190 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
191 p = bootp->vend + 4; /* options after the 4 byte cookie */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
192 e = (const uint8_t *)bootp + bootp_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
193 ol = o = overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
194 bp = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
195 op = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
196 bl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
197 while (p < e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
198 o = *p++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
199 switch (o) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
200 case DHO_PAD: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
201 /* No length to read */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
202 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
203 case DHO_END: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
204 if (overl & 1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
205 /* bit 1 set means parse boot file */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
206 overl = (uint8_t)(overl & ~1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
207 p = bootp->file; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
208 e = p + sizeof(bootp->file); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
209 } else if (overl & 2) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
210 /* bit 2 set means parse server name */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
211 overl = (uint8_t)(overl & ~2); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
212 p = bootp->sname; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
213 e = p + sizeof(bootp->sname); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
214 } else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
215 goto exit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
216 /* No length to read */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
217 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
218 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
219 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
220 /* Check we can read the length */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
221 if (p == e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
222 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
223 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
224 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
225 l = *p++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
226 |
|
4459
293fe50331c8
DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
227 /* Check we can read the option data, if present */ |
|
293fe50331c8
DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
228 if (p + l > e) { |
|
293fe50331c8
DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
229 errno = EINVAL; |
|
293fe50331c8
DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
230 return NULL; |
|
293fe50331c8
DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
231 } |
|
293fe50331c8
DHCP: Fix a potential 1 byte read overflow with DHO_OPTSOVERLOADED
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
232 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
233 if (o == DHO_OPTSOVERLOADED) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
234 /* Ensure we only get this option once by setting |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
235 * the last bit as well as the value. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
236 * This is valid because only the first two bits |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
237 * actually mean anything in RFC2132 Section 9.3 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
238 if (l == 1 && !overl) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
239 overl = 0x80 | p[0]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
240 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
241 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
242 if (o == opt) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
243 if (op) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
244 /* We must concatonate the options. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
245 if (bl + l > ctx->opt_buffer_len) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
246 size_t pos; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
247 uint8_t *nb; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
248 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
249 if (bp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
250 pos = (size_t) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
251 (bp - ctx->opt_buffer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
252 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
253 pos = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
254 nb = realloc(ctx->opt_buffer, bl + l); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
255 if (nb == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
256 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
257 ctx->opt_buffer = nb; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
258 ctx->opt_buffer_len = bl + l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
259 bp = ctx->opt_buffer + pos; |
|
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 if (bp == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
262 bp = ctx->opt_buffer; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
263 memcpy(bp, op, ol); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
264 bp += ol; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
265 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
266 ol = l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
267 op = p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
268 bl += ol; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
269 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
270 p += l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
271 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
272 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
273 exit: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
274 if (opt_len) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
275 *opt_len = bl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
276 if (bp) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
277 memcpy(bp, op, ol); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
278 return (const uint8_t *)ctx->opt_buffer; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
279 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
280 if (op) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
281 return op; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
282 errno = ENOENT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
283 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
284 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
285 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
286 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
287 get_option_addr(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
|
288 struct in_addr *a, const struct bootp *bootp, size_t bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
289 uint8_t option) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
290 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
291 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
|
292 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
|
293 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
294 p = get_option(ctx, bootp, bootp_len, option, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
295 if (!p || len < (ssize_t)sizeof(a->s_addr)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
296 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
297 memcpy(&a->s_addr, p, sizeof(a->s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
298 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
299 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
300 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
301 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
302 get_option_uint32(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
|
303 uint32_t *i, const struct bootp *bootp, size_t bootp_len, uint8_t option) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
304 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
305 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
|
306 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
|
307 uint32_t d; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
308 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
309 p = get_option(ctx, bootp, bootp_len, option, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
310 if (!p || len < (ssize_t)sizeof(d)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
311 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
312 memcpy(&d, p, sizeof(d)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
313 if (i) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
314 *i = ntohl(d); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
315 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
316 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
317 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
318 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
319 get_option_uint16(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
|
320 uint16_t *i, const struct bootp *bootp, size_t bootp_len, uint8_t option) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
321 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
322 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
|
323 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
|
324 uint16_t d; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
325 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
326 p = get_option(ctx, bootp, bootp_len, option, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
327 if (!p || len < (ssize_t)sizeof(d)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
328 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
329 memcpy(&d, p, sizeof(d)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
330 if (i) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
331 *i = ntohs(d); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
332 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
333 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
334 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
335 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
336 get_option_uint8(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
|
337 uint8_t *i, const struct bootp *bootp, size_t bootp_len, uint8_t option) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
338 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
339 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
|
340 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
|
341 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
342 p = get_option(ctx, bootp, bootp_len, option, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
343 if (!p || len < (ssize_t)sizeof(*p)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
344 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
345 if (i) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
346 *i = *(p); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
347 return 0; |
|
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 ssize_t |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
351 print_rfc3442(FILE *fp, const uint8_t *data, size_t data_len) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
352 { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
353 const uint8_t *p = data, *e; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
354 size_t ocets; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
355 uint8_t cidr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
356 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
357 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
358 /* Minimum is 5 -first is CIDR and a router length of 4 */ |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
359 if (data_len < 5) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
360 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
361 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
362 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
363 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
364 e = p + data_len; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
365 while (p < e) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
366 if (p != data) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
367 if (fputc(' ', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
368 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
369 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
370 cidr = *p++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
371 if (cidr > 32) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
372 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
373 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
374 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
375 ocets = (size_t)(cidr + 7) / NBBY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
376 if (p + 4 + ocets > e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
377 errno = ERANGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
378 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
379 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
380 /* If we have ocets then we have a destination and netmask */ |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
381 addr.s_addr = 0; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
382 if (ocets > 0) { |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
383 memcpy(&addr.s_addr, p, ocets); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
384 p += ocets; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
385 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
386 if (fprintf(fp, "%s/%d", inet_ntoa(addr), cidr) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
387 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
|
388 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
389 /* Finally, snag the router */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
390 memcpy(&addr.s_addr, p, 4); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
391 p += 4; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
392 if (fprintf(fp, " %s", inet_ntoa(addr)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
393 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
|
394 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
395 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
396 if (fputc('\0', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
397 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
398 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
|
399 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
400 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
401 static int |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
402 decode_rfc3442_rt(rb_tree_t *routes, 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
|
403 const uint8_t *data, size_t dl, const struct bootp *bootp) |
|
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 const uint8_t *p = data; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
406 const uint8_t *e; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
407 uint8_t cidr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
408 size_t ocets; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
409 struct rt *rt = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
410 struct in_addr dest, netmask, gateway; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
411 int n; |
|
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 /* Minimum is 5 -first is CIDR and a router length of 4 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
414 if (dl < 5) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
415 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
416 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
417 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
418 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
419 n = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
420 e = p + dl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
421 while (p < e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
422 cidr = *p++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
423 if (cidr > 32) { |
|
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 -1; |
|
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 ocets = (size_t)(cidr + 7) / NBBY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
429 if (p + 4 + ocets > e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
430 errno = ERANGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
431 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
432 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
433 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
434 if ((rt = rt_new(ifp)) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
435 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
436 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
437 /* If we have ocets then we have a destination and netmask */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
438 dest.s_addr = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
439 if (ocets > 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
440 memcpy(&dest.s_addr, p, ocets); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
441 p += ocets; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
442 netmask.s_addr = htonl(~0U << (32 - cidr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
443 } else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
444 netmask.s_addr = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
445 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
446 /* Finally, snag the router */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
447 memcpy(&gateway.s_addr, p, 4); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
448 p += 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
449 |
|
4362
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
450 /* An on-link host route is normally set by having the |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
451 * gateway match the destination or assigned address */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
452 if (gateway.s_addr == dest.s_addr || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
453 (gateway.s_addr == bootp->yiaddr || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
454 gateway.s_addr == bootp->ciaddr)) |
|
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 gateway.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
457 netmask.s_addr = INADDR_BROADCAST; |
|
4362
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
458 } |
|
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
459 if (netmask.s_addr == INADDR_BROADCAST) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
460 rt->rt_flags = RTF_HOST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
461 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
462 sa_in_init(&rt->rt_dest, &dest); |
|
4077
43b960e65bd5
dhcp: Fix classless static routes
Roy Marples <roy@marples.name>
parents:
4024
diff
changeset
|
463 sa_in_init(&rt->rt_netmask, &netmask); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
464 sa_in_init(&rt->rt_gateway, &gateway); |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4511
diff
changeset
|
465 if (rt_proto_add(routes, rt)) |
|
4524
578ac745c627
Fix a gcc warning about signed overflow
Roy Marples <roy@marples.name>
parents:
4522
diff
changeset
|
466 n = 1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
467 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
468 return n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
469 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
470 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
471 ssize_t |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
472 print_rfc3361(FILE *fp, const uint8_t *data, size_t dl) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
473 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
474 uint8_t enc; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
475 char sip[NS_MAXDNAME]; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
476 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
477 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
478 if (dl < 2) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
479 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
480 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
481 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
482 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
483 enc = *data++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
484 dl--; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
485 switch (enc) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
486 case 0: |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
487 if (decode_rfc1035(sip, sizeof(sip), data, dl) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
488 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
489 if (efprintf(fp, "%s", sip) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
490 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
|
491 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
492 case 1: |
|
4866
6c1db207d549
DHCP: dl is always >0 at this point, so remove check.
Roy Marples <roy@marples.name>
parents:
4846
diff
changeset
|
493 if (dl % 4 != 0) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
494 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
495 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
496 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
497 addr.s_addr = INADDR_BROADCAST; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
498 for (; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
499 dl != 0; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
500 data += sizeof(addr.s_addr), dl -= sizeof(addr.s_addr)) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
501 { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
502 memcpy(&addr.s_addr, data, sizeof(addr.s_addr)); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
503 if (fprintf(fp, "%s", inet_ntoa(addr)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
504 return -1; |
|
5256
32665ffe1782
Avoid putting an extra space here.
Roy Marples <roy@marples.name>
parents:
5247
diff
changeset
|
505 if (dl != sizeof(addr.s_addr)) { |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
506 if (fputc(' ', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
507 return -1; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
508 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
509 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
510 if (fputc('\0', fp) == EOF) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
511 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
|
512 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
513 default: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
514 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
515 return 0; |
|
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 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
518 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
|
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 char * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
522 get_option_string(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
|
523 const struct bootp *bootp, size_t bootp_len, uint8_t option) |
|
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 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
|
526 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
|
527 char *s; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
528 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
529 p = get_option(ctx, bootp, bootp_len, option, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
530 if (!p || len == 0 || *p == '\0') |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
531 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
532 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
533 s = malloc(sizeof(char) * (len + 1)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
534 if (s) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
535 memcpy(s, p, len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
536 s[len] = '\0'; |
|
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 return s; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
539 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
540 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
541 /* This calculates the netmask that we should use for static routes. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
542 * This IS different from the calculation used to calculate the netmask |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
543 * for an interface address. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
544 static uint32_t |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
545 route_netmask(uint32_t ip_in) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
546 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
547 /* used to be unsigned long - check if error */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
548 uint32_t p = ntohl(ip_in); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
549 uint32_t t; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
550 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
551 if (IN_CLASSA(p)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
552 t = ~IN_CLASSA_NET; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
553 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
554 if (IN_CLASSB(p)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
555 t = ~IN_CLASSB_NET; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
556 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
557 if (IN_CLASSC(p)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
558 t = ~IN_CLASSC_NET; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
559 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
560 t = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
561 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
562 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
563 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
564 while (t & p) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
565 t >>= 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
566 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
567 return (htonl(~t)); |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
570 /* We need to obey routing options. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
571 * If we have a CSR then we only use that. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
572 * Otherwise we add static routes and then routers. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
573 static int |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
574 get_option_routes(rb_tree_t *routes, 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
|
575 const struct bootp *bootp, size_t bootp_len) |
|
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 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
|
578 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
|
579 const uint8_t *e; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
580 struct rt *rt = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
581 struct in_addr dest, netmask, gateway; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
582 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
|
583 const char *csr = ""; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
584 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
585 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
586 /* If we have CSR's then we MUST use these only */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
587 if (!has_option_mask(ifo->nomask, DHO_CSR)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
588 p = get_option(ifp->ctx, bootp, bootp_len, DHO_CSR, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
589 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
590 p = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
591 /* Check for crappy MS option */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
592 if (!p && !has_option_mask(ifo->nomask, DHO_MSCSR)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
593 p = get_option(ifp->ctx, bootp, bootp_len, DHO_MSCSR, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
594 if (p) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
595 csr = "MS "; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
596 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
597 if (p && (n = decode_rfc3442_rt(routes, ifp, p, len, bootp)) != -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
598 const struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
599 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
600 state = D_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
601 if (!(ifo->options & DHCPCD_CSR_WARNED) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
602 !(state->added & STATE_FAKE)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
603 { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
604 logdebugx("%s: using %sClassless Static Routes", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
605 ifp->name, csr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
606 ifo->options |= DHCPCD_CSR_WARNED; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
607 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
608 return n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
609 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
610 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
611 n = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
612 /* OK, get our static routes first. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
613 if (!has_option_mask(ifo->nomask, DHO_STATICROUTE)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
614 p = get_option(ifp->ctx, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
615 DHO_STATICROUTE, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
616 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
617 p = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
618 /* RFC 2131 Section 5.8 states length MUST be in multiples of 8 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
619 if (p && len % 8 == 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
620 e = p + len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
621 while (p < e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
622 memcpy(&dest.s_addr, p, sizeof(dest.s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
623 p += 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
624 memcpy(&gateway.s_addr, p, sizeof(gateway.s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
625 p += 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
626 /* RFC 2131 Section 5.8 states default route is |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
627 * illegal */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
628 if (gateway.s_addr == INADDR_ANY) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
629 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
630 if ((rt = rt_new(ifp)) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
631 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
632 |
|
4362
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
633 /* A on-link host route is normally set by having the |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
634 * gateway match the destination or assigned address */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
635 if (gateway.s_addr == dest.s_addr || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
636 (gateway.s_addr == bootp->yiaddr || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
637 gateway.s_addr == bootp->ciaddr)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
638 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
639 gateway.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
640 netmask.s_addr = INADDR_BROADCAST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
641 } else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
642 netmask.s_addr = route_netmask(dest.s_addr); |
|
4362
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
643 if (netmask.s_addr == INADDR_BROADCAST) |
|
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
644 rt->rt_flags = RTF_HOST; |
|
2e028387b21c
dhcp: if the netmask is all ones, it's a host route
Roy Marples <roy@marples.name>
parents:
4355
diff
changeset
|
645 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
646 sa_in_init(&rt->rt_dest, &dest); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
647 sa_in_init(&rt->rt_netmask, &netmask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
648 sa_in_init(&rt->rt_gateway, &gateway); |
|
4536
ce9e8fb0e6a3
route: Build list of static routes and routers correctly.
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
649 if (rt_proto_add(routes, rt)) |
|
4396
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4379
diff
changeset
|
650 n++; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
651 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
652 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
653 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
654 /* Now grab our routers */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
655 if (!has_option_mask(ifo->nomask, DHO_ROUTER)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
656 p = get_option(ifp->ctx, bootp, bootp_len, DHO_ROUTER, &len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
657 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
658 p = NULL; |
|
4536
ce9e8fb0e6a3
route: Build list of static routes and routers correctly.
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
659 if (p && len % 4 == 0) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
660 e = p + len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
661 dest.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
662 netmask.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
663 while (p < e) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
664 if ((rt = rt_new(ifp)) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
665 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
666 memcpy(&gateway.s_addr, p, sizeof(gateway.s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
667 p += 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
668 sa_in_init(&rt->rt_dest, &dest); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
669 sa_in_init(&rt->rt_netmask, &netmask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
670 sa_in_init(&rt->rt_gateway, &gateway); |
|
4536
ce9e8fb0e6a3
route: Build list of static routes and routers correctly.
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
671 if (rt_proto_add(routes, rt)) |
|
4396
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4379
diff
changeset
|
672 n++; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
673 } |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
676 return n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
677 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
678 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
679 uint16_t |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
680 dhcp_get_mtu(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
|
681 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
682 const struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
683 uint16_t mtu; |
|
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 if (ifp->options->mtu) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
686 return (uint16_t)ifp->options->mtu; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 mtu = 0; /* bogus gcc warning */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
688 if ((state = D_CSTATE(ifp)) == NULL || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
689 has_option_mask(ifp->options->nomask, DHO_MTU) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
690 get_option_uint16(ifp->ctx, &mtu, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
691 state->new, state->new_len, DHO_MTU) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
692 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
693 return mtu; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
694 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
695 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
696 /* Grab our routers from the DHCP message and apply any MTU value |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
697 * the message contains */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
698 int |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
699 dhcp_get_routes(rb_tree_t *routes, 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
|
700 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
701 const struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
702 |
|
4108
84bdb647122c
dhcp: return routes when renewing
Roy Marples <roy@marples.name>
parents:
4104
diff
changeset
|
703 if ((state = D_CSTATE(ifp)) == NULL || !(state->added & STATE_ADDED)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
704 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
705 return get_option_routes(routes, 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
|
706 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
707 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
708 /* Assumes DHCP options */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
709 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
710 dhcp_message_add_addr(struct bootp *bootp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
711 uint8_t type, struct in_addr addr) |
|
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 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
|
714 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
|
715 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
716 p = bootp->vend; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
717 while (*p != DHO_END) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
718 p++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
719 p += *p + 1; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
722 len = (size_t)(p - bootp->vend); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
723 if (len + 6 > sizeof(bootp->vend)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
724 errno = ENOMEM; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
725 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
726 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
727 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
728 *p++ = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
729 *p++ = 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
730 memcpy(p, &addr.s_addr, 4); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
731 p += 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
732 *p = DHO_END; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
733 return 0; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
736 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
|
737 make_message(struct bootp **bootpm, const struct interface *ifp, 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
|
738 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
739 struct bootp *bootp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
740 uint8_t *lp, *p, *e; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
741 uint8_t *n_params = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
742 uint32_t ul; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
743 uint16_t sz; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
744 size_t len, i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
745 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
|
746 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
|
747 const struct dhcp_state *state = D_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
748 const struct dhcp_lease *lease = &state->lease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
749 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
|
750 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
|
751 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
|
752 int mtu; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
753 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
754 uint8_t *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
|
755 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
756 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
757 if ((mtu = if_getmtu(ifp)) == -1) |
| 4010 | 758 logerr("%s: if_getmtu", 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
|
759 else if (mtu < MTU_MIN) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
760 if (if_setmtu(ifp, MTU_MIN) == -1) |
| 4010 | 761 logerr("%s: if_setmtu", 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
|
762 mtu = MTU_MIN; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
763 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
764 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
765 if (ifo->options & DHCPCD_BOOTP) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
766 bootp = calloc(1, sizeof (*bootp)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
767 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
768 /* Make the maximal message we could send */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
769 bootp = calloc(1, (size_t)(mtu - IP_UDP_SIZE)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
770 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
771 if (bootp == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
772 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
773 *bootpm = bootp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
774 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
775 if (state->addr != NULL && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
776 (type == DHCP_INFORM || type == DHCP_RELEASE || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
777 (type == DHCP_REQUEST && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
778 state->addr->mask.s_addr == lease->mask.s_addr && |
|
4188
23ff91710a01
dhcp: Don't set ciaddr or unicast if the address we have is faked.
Roy Marples <roy@marples.name>
parents:
4187
diff
changeset
|
779 (state->new == NULL || IS_DHCP(state->new)) && |
|
5424
28a650d93729
DHCP: Mark the state as expired on lase lease extension
Roy Marples <roy@marples.name>
parents:
5299
diff
changeset
|
780 !(state->added & (STATE_FAKE | STATE_EXPIRED))))) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
781 bootp->ciaddr = state->addr->addr.s_addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
782 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
783 bootp->op = BOOTREQUEST; |
|
5166
a70f6ddefe3c
Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents:
5160
diff
changeset
|
784 bootp->htype = (uint8_t)ifp->hwtype; |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
785 if (ifp->hwlen != 0 && ifp->hwlen < sizeof(bootp->chaddr)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
786 bootp->hlen = (uint8_t)ifp->hwlen; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
787 memcpy(&bootp->chaddr, &ifp->hwaddr, ifp->hwlen); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
788 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
789 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
790 if (ifo->options & DHCPCD_BROADCAST && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
791 bootp->ciaddr == 0 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
792 type != DHCP_DECLINE && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
793 type != DHCP_RELEASE) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
794 bootp->flags = htons(BROADCAST_FLAG); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
795 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
796 if (type != DHCP_DECLINE && type != DHCP_RELEASE) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
797 struct timespec tv; |
|
4924
7c1a365b1e2d
eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents:
4923
diff
changeset
|
798 unsigned long long secs; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
799 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
800 clock_gettime(CLOCK_MONOTONIC, &tv); |
|
4924
7c1a365b1e2d
eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents:
4923
diff
changeset
|
801 secs = eloop_timespec_diff(&tv, &state->started, NULL); |
|
7c1a365b1e2d
eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents:
4923
diff
changeset
|
802 if (secs > UINT16_MAX) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
803 bootp->secs = htons((uint16_t)UINT16_MAX); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
804 else |
|
4924
7c1a365b1e2d
eloop: reduce timers rather than calculating expiry
Roy Marples <roy@marples.name>
parents:
4923
diff
changeset
|
805 bootp->secs = htons((uint16_t)secs); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
806 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
807 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
808 bootp->xid = htonl(state->xid); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
809 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
810 if (ifo->options & DHCPCD_BOOTP) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
811 return sizeof(*bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
812 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
813 p = bootp->vend; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
814 e = (uint8_t *)bootp + (mtu - IP_UDP_SIZE) - 1; /* -1 for DHO_END */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
815 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
816 ul = htonl(MAGIC_COOKIE); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
817 memcpy(p, &ul, sizeof(ul)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
818 p += sizeof(ul); |
|
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 #define AREA_LEFT (size_t)(e - p) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
821 #define AREA_FIT(s) if ((s) > AREA_LEFT) goto toobig |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
822 #define AREA_CHECK(s) if ((s) + 2UL > AREA_LEFT) goto toobig |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
823 #define PUT_ADDR(o, a) do { \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
824 AREA_CHECK(4); \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
825 *p++ = (o); \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
826 *p++ = 4; \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
827 memcpy(p, &(a)->s_addr, 4); \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
828 p += 4; \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
829 } while (0 /* CONSTCOND */) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
830 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
831 /* Options are listed in numerical order as per RFC 7844 Section 3.1 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
832 * XXX: They should be randomised. */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
833 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
834 bool putip = false; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
835 if (lease->addr.s_addr && lease->cookie == htonl(MAGIC_COOKIE)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
836 if (type == DHCP_DECLINE || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
837 (type == DHCP_REQUEST && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
838 (state->addr == NULL || |
|
5426
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
839 state->added & (STATE_FAKE | STATE_EXPIRED) || |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
840 lease->addr.s_addr != state->addr->addr.s_addr))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
841 { |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
842 putip = true; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
843 PUT_ADDR(DHO_IPADDRESS, &lease->addr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
844 } |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
845 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
846 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
847 AREA_CHECK(3); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
848 *p++ = DHO_MESSAGETYPE; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
849 *p++ = 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
850 *p++ = type; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
851 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
852 if (lease->addr.s_addr && lease->cookie == htonl(MAGIC_COOKIE)) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
853 if (type == DHCP_RELEASE || putip) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
854 if (lease->server.s_addr) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
855 PUT_ADDR(DHO_SERVERID, &lease->server); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
856 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
857 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
858 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
859 if (type == DHCP_DECLINE) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
860 len = strlen(DAD); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
861 if (len > AREA_LEFT) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
862 *p++ = DHO_MESSAGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
863 *p++ = (uint8_t)len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
864 memcpy(p, DAD, len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
865 p += len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
866 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
867 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
868 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
869 #define DHCP_DIR(type) ((type) == DHCP_DISCOVER || (type) == DHCP_INFORM || \ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
870 (type) == DHCP_REQUEST) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
871 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
872 if (DHCP_DIR(type)) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
873 /* vendor is already encoded correctly, so just add it */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
874 if (ifo->vendor[0]) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
875 AREA_CHECK(ifo->vendor[0]); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
876 *p++ = DHO_VENDOR; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
877 memcpy(p, ifo->vendor, (size_t)ifo->vendor[0] + 1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
878 p += ifo->vendor[0] + 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
881 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
882 if (type == DHCP_DISCOVER && ifo->options & DHCPCD_REQUEST) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
883 PUT_ADDR(DHO_IPADDRESS, &ifo->req_addr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
884 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
885 if (DHCP_DIR(type)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
886 if (type != DHCP_INFORM) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
887 if (ifo->leasetime != 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
888 AREA_CHECK(4); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
889 *p++ = DHO_LEASETIME; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
890 *p++ = 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
891 ul = htonl(ifo->leasetime); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
892 memcpy(p, &ul, 4); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
893 p += 4; |
|
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 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
897 AREA_CHECK(0); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
898 *p++ = DHO_PARAMETERREQUESTLIST; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
899 n_params = p; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
900 *p++ = 0; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
901 for (i = 0, opt = ifp->ctx->dhcp_opts; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
902 i < ifp->ctx->dhcp_opts_len; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
903 i++, opt++) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
904 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
905 if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
906 continue; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
907 if (type == DHCP_INFORM && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
908 (opt->option == DHO_RENEWALTIME || |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
909 opt->option == DHO_REBINDTIME)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
910 continue; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
911 AREA_FIT(1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
912 *p++ = (uint8_t)opt->option; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
913 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
914 for (i = 0, opt = ifo->dhcp_override; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
915 i < ifo->dhcp_override_len; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
916 i++, opt++) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
917 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
918 /* Check if added above */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
919 for (lp = n_params + 1; lp < p; lp++) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
920 if (*lp == (uint8_t)opt->option) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
921 break; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
922 if (lp < p) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
923 continue; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
924 if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
925 continue; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
926 if (type == DHCP_INFORM && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
927 (opt->option == DHO_RENEWALTIME || |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
928 opt->option == DHO_REBINDTIME)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
929 continue; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
930 AREA_FIT(1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
931 *p++ = (uint8_t)opt->option; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
932 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
933 *n_params = (uint8_t)(p - n_params - 1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
934 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
935 if (mtu != -1 && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
936 !(has_option_mask(ifo->nomask, DHO_MAXMESSAGESIZE))) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
937 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
938 AREA_CHECK(2); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
939 *p++ = DHO_MAXMESSAGESIZE; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
940 *p++ = 2; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
941 sz = htons((uint16_t)(mtu - IP_UDP_SIZE)); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
942 memcpy(p, &sz, 2); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
943 p += 2; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
944 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
945 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
946 if (ifo->userclass[0] && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
947 !has_option_mask(ifo->nomask, DHO_USERCLASS)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
948 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
949 AREA_CHECK(ifo->userclass[0]); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
950 *p++ = DHO_USERCLASS; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
951 memcpy(p, ifo->userclass, |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
952 (size_t)ifo->userclass[0] + 1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
953 p += ifo->userclass[0] + 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
954 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
955 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
956 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
957 if (state->clientid) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
958 AREA_CHECK(state->clientid[0]); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
959 *p++ = DHO_CLIENTID; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
960 memcpy(p, state->clientid, (size_t)state->clientid[0] + 1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
961 p += state->clientid[0] + 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
962 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
963 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
964 if (DHCP_DIR(type) && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
965 !has_option_mask(ifo->nomask, DHO_VENDORCLASSID) && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
966 ifo->vendorclassid[0]) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
967 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
968 AREA_CHECK(ifo->vendorclassid[0]); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
969 *p++ = DHO_VENDORCLASSID; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
970 memcpy(p, ifo->vendorclassid, (size_t)ifo->vendorclassid[0]+1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
971 p += ifo->vendorclassid[0] + 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
972 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
973 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
974 if (type == DHCP_DISCOVER && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
975 !(ifp->ctx->options & DHCPCD_TEST) && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
976 DHC_REQ(ifo->requestmask, ifo->nomask, DHO_RAPIDCOMMIT)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
977 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
978 /* RFC 4039 Section 3 */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
979 AREA_CHECK(0); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
980 *p++ = DHO_RAPIDCOMMIT; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
981 *p++ = 0; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
982 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
983 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
984 if (DHCP_DIR(type)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
985 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
|
986 |
|
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 * RFC4702 3.1 States that if we send the Client FQDN option |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
989 * then we MUST NOT also send the Host Name option. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
990 * Technically we could, but that is not RFC conformant and |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
991 * also seems to break some DHCP server implemetations such as |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
992 * Windows. On the other hand, ISC dhcpd is just as non RFC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
993 * conformant by not accepting a partially qualified FQDN. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
994 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
995 if (ifo->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
|
996 /* IETF DHC-FQDN option (81), RFC4702 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
997 i = 3; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
998 if (hostname) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
999 i += 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
|
1000 AREA_CHECK(i); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1001 *p++ = DHO_FQDN; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1002 *p++ = (uint8_t)i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1003 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1004 * Flags: 0000NEOS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1005 * S: 1 => Client requests Server to update |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1006 * a RR in DNS as well as PTR |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1007 * O: 1 => Server indicates to client that |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1008 * DNS has been updated |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1009 * E: 1 => Name data is DNS format |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1010 * N: 1 => Client requests Server to not |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1011 * update DNS |
|
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 if (hostname) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1014 *p++ = (uint8_t)((ifo->fqdn & 0x09) | 0x04); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1015 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1016 *p++ = (FQDN_NONE & 0x09) | 0x04; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1017 *p++ = 0; /* from server for PTR RR */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1018 *p++ = 0; /* from server for A RR if S=1 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1019 if (hostname) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1020 i = 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
|
1021 p += i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1022 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1023 } else if (ifo->options & DHCPCD_HOSTNAME && hostname) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1024 len = strlen(hostname); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1025 AREA_CHECK(len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1026 *p++ = DHO_HOSTNAME; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1027 *p++ = (uint8_t)len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1028 memcpy(p, hostname, len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1029 p += len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1030 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1031 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1032 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1033 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1034 auth = NULL; /* appease GCC */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1035 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
|
1036 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
|
1037 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
|
1038 state->auth.token, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1039 NULL, 0, 4, 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
|
1040 if (alen != -1 && alen > UINT8_MAX) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1041 errno = ERANGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1042 alen = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1043 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1044 if (alen == -1) |
| 4010 | 1045 logerr("%s: dhcp_auth_encode", 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
|
1046 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
|
1047 auth_len = (uint8_t)alen; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1048 AREA_CHECK(auth_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1049 *p++ = DHO_AUTHENTICATION; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1050 *p++ = auth_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1051 auth = p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1052 p += auth_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1053 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1054 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1055 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1056 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1057 /* RFC 2563 Auto Configure */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1058 if (type == DHCP_DISCOVER && ifo->options & DHCPCD_IPV4LL && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1059 !(has_option_mask(ifo->nomask, DHO_AUTOCONFIGURE))) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1060 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1061 AREA_CHECK(1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1062 *p++ = DHO_AUTOCONFIGURE; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1063 *p++ = 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1064 *p++ = 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1065 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1066 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1067 if (DHCP_DIR(type)) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1068 if (ifo->mudurl[0]) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1069 AREA_CHECK(ifo->mudurl[0]); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1070 *p++ = DHO_MUDURL; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1071 memcpy(p, ifo->mudurl, (size_t)ifo->mudurl[0] + 1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1072 p += ifo->mudurl[0] + 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1073 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1074 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1075 if (ifo->vivco_len && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1076 !has_option_mask(ifo->nomask, DHO_VIVCO)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1077 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1078 AREA_CHECK(sizeof(ul)); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1079 *p++ = DHO_VIVCO; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1080 lp = p++; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1081 *lp = sizeof(ul); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1082 ul = htonl(ifo->vivco_en); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1083 memcpy(p, &ul, sizeof(ul)); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1084 p += sizeof(ul); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1085 for (i = 0, vivco = ifo->vivco; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1086 i < ifo->vivco_len; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1087 i++, vivco++) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1088 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1089 AREA_FIT(vivco->len); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1090 if (vivco->len + 2 + *lp > 255) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1091 logerrx("%s: VIVCO option too big", |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1092 ifp->name); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1093 free(bootp); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1094 return -1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1095 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1096 *p++ = (uint8_t)vivco->len; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1097 memcpy(p, vivco->data, vivco->len); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1098 p += vivco->len; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1099 *lp = (uint8_t)(*lp + vivco->len + 1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1100 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1101 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1102 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1103 #ifdef AUTH |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1104 if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) != |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1105 DHCPCD_AUTH_SENDREQUIRE && |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1106 !has_option_mask(ifo->nomask, DHO_FORCERENEW_NONCE)) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1107 { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1108 /* We support HMAC-MD5 */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1109 AREA_CHECK(1); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1110 *p++ = DHO_FORCERENEW_NONCE; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1111 *p++ = 1; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1112 *p++ = AUTH_ALG_HMAC_MD5; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1113 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1114 #endif |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1115 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
1116 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1117 *p++ = DHO_END; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1118 len = (size_t)(p - (uint8_t *)bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1119 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1120 /* Pad out to the BOOTP message length. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1121 * Even if we send a DHCP packet with a variable length vendor area, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1122 * some servers / relay agents don't like packets smaller than |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1123 * a BOOTP message which is fine because that's stipulated |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1124 * in RFC1542 section 2.1. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1125 while (len < sizeof(*bootp)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1126 *p++ = DHO_PAD; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1127 len++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1128 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1129 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1130 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1131 if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len != 0) |
|
5299
b7e676ac73c1
privsep: Access the RDM monotic file via IPC
Roy Marples <roy@marples.name>
parents:
5294
diff
changeset
|
1132 dhcp_auth_encode(ifp->ctx, &ifo->auth, state->auth.token, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1133 (uint8_t *)bootp, len, 4, type, 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
|
1134 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1135 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1136 return (ssize_t)len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1137 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1138 toobig: |
| 4010 | 1139 logerrx("%s: DHCP message 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
|
1140 free(bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1141 return -1; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1144 static size_t |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1145 read_lease(struct interface *ifp, struct bootp **bootp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1146 { |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1147 union { |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1148 struct bootp bootp; |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1149 uint8_t buf[FRAMELEN_MAX]; |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1150 } buf; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1151 struct dhcp_state *state = D_STATE(ifp); |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1152 ssize_t sbytes; |
|
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1153 size_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
|
1154 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
|
1155 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1156 const 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
|
1157 size_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
|
1158 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1159 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1160 /* Safety */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1161 *bootp = NULL; |
|
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 if (state->leasefile[0] == '\0') { |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1164 logdebugx("reading standard input"); |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1165 sbytes = 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
|
1166 } else { |
| 5494 | 1167 logdebugx("%s: reading lease: %s", |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1168 ifp->name, state->leasefile); |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1169 sbytes = dhcp_readfile(ifp->ctx, state->leasefile, |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1170 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
|
1171 } |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1172 if (sbytes == -1) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1173 if (errno != ENOENT) |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1174 logerr("%s: %s", ifp->name, 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
|
1175 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1176 } |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1177 bytes = (size_t)sbytes; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1178 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1179 /* Ensure the packet is at lease BOOTP sized |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1180 * with a vendor area of 4 octets |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1181 * (it should be more, and our read packet enforces this so this |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1182 * code should not be needed, but of course people could |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1183 * scribble whatever in the stored lease file. */ |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1184 if (bytes < DHCP_MIN_LEN) { |
| 4010 | 1185 logerrx("%s: %s: truncated lease", ifp->name, __func__); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1186 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1187 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1188 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1189 if (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
|
1190 goto out; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1191 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1192 /* We may have found a BOOTP server */ |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1193 if (get_option_uint8(ifp->ctx, &type, &buf.bootp, bytes, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1194 DHO_MESSAGETYPE) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1195 type = 0; |
|
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 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1198 /* Authenticate the message */ |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1199 auth = get_option(ifp->ctx, &buf.bootp, bytes, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1200 DHO_AUTHENTICATION, &auth_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1201 if (auth) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1202 if (dhcp_auth_validate(&state->auth, &ifp->options->auth, |
| 5211 | 1203 &buf.bootp, bytes, 4, type, auth, auth_len) == NULL) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1204 { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1205 logerr("%s: authentication failed", 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
|
1206 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1207 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1208 if (state->auth.token) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1209 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
|
1210 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
|
1211 else |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1212 logdebugx("%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
|
1213 } 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
|
1214 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
|
1215 { |
| 4010 | 1216 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
|
1217 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1218 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1219 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1220 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1221 out: |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1222 *bootp = malloc(bytes); |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1223 if (*bootp == NULL) { |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1224 logerr(__func__); |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1225 return 0; |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1226 } |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
1227 memcpy(*bootp, buf.buf, bytes); |
|
5208
6e53055c9989
Fix compile warnings with prior.
Roy Marples <roy@marples.name>
parents:
5207
diff
changeset
|
1228 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
|
1229 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1230 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1231 static const struct dhcp_opt * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1232 dhcp_getoverride(const struct if_options *ifo, unsigned int o) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1233 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1234 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
|
1235 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
|
1236 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1237 for (i = 0, opt = ifo->dhcp_override; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1238 i < ifo->dhcp_override_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1239 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1240 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1241 if (opt->option == o) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1242 return opt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1243 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1244 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1245 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1246 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1247 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
|
1248 dhcp_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
|
1249 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
|
1250 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
|
1251 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1252 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
|
1253 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
|
1254 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1255 if (od) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1256 if (ol < 2) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1257 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1258 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1259 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1260 *os = 2; /* code + len */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1261 *code = (unsigned int)*od++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1262 *len = (size_t)*od++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1263 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
|
1264 errno = ERANGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1265 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1266 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1267 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1268 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1269 *oopt = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1270 for (i = 0, opt = ctx->dhcp_opts; i < ctx->dhcp_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
|
1271 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
|
1272 *oopt = opt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1273 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1274 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1275 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1276 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1277 return od; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1278 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1279 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1280 ssize_t |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1281 dhcp_env(FILE *fenv, const char *prefix, const struct interface *ifp, |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1282 const struct bootp *bootp, size_t bootp_len) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1283 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1284 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
|
1285 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
|
1286 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1287 struct in_addr net; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1288 struct in_addr brd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1289 struct dhcp_opt *opt, *vo; |
|
4538
8e383f84ebd0
Remove now unused variables.
Roy Marples <roy@marples.name>
parents:
4537
diff
changeset
|
1290 size_t i, pl; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1291 char safe[(BOOTP_FILE_LEN * 4) + 1]; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1292 uint8_t overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1293 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
|
1294 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1295 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
|
1296 if (get_option_uint8(ifp->ctx, &overl, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1297 DHO_OPTSOVERLOADED) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1298 overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1299 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1300 if (bootp->yiaddr || bootp->ciaddr) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1301 /* Set some useful variables that we derive from the DHCP |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1302 * message but are not necessarily in the options */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1303 addr.s_addr = bootp->yiaddr ? bootp->yiaddr : bootp->ciaddr; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1304 if (efprintf(fenv, "%s_ip_address=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1305 prefix, inet_ntoa(addr)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1306 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
|
1307 if (get_option_addr(ifp->ctx, &net, |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1308 bootp, bootp_len, DHO_SUBNETMASK) == -1) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1309 net.s_addr = ipv4_getnetmask(addr.s_addr); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1310 if (efprintf(fenv, "%s_subnet_mask=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1311 prefix, inet_ntoa(net)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1312 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
|
1313 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1314 if (efprintf(fenv, "%s_subnet_cidr=%d", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1315 prefix, inet_ntocidr(net))== -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1316 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
|
1317 if (get_option_addr(ifp->ctx, &brd, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1318 bootp, bootp_len, DHO_BROADCAST) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1319 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1320 brd.s_addr = addr.s_addr | ~net.s_addr; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1321 if (efprintf(fenv, "%s_broadcast_address=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1322 prefix, inet_ntoa(brd)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1323 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
|
1324 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1325 addr.s_addr = bootp->yiaddr & net.s_addr; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1326 if (efprintf(fenv, "%s_network_number=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1327 prefix, inet_ntoa(addr)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1328 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
|
1329 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1330 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1331 if (*bootp->file && !(overl & 1)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1332 print_string(safe, sizeof(safe), OT_STRING, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1333 bootp->file, sizeof(bootp->file)); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1334 if (efprintf(fenv, "%s_filename=%s", prefix, safe) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1335 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
|
1336 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1337 if (*bootp->sname && !(overl & 2)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1338 print_string(safe, sizeof(safe), OT_STRING | OT_DOMAIN, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1339 bootp->sname, sizeof(bootp->sname)); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1340 if (efprintf(fenv, "%s_server_name=%s", prefix, safe) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1341 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
|
1342 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1343 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1344 /* Zero our indexes */ |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1345 for (i = 0, opt = ifp->ctx->dhcp_opts; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1346 i < ifp->ctx->dhcp_opts_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1347 i++, opt++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1348 dhcp_zero_index(opt); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1349 for (i = 0, opt = ifp->options->dhcp_override; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1350 i < ifp->options->dhcp_override_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1351 i++, opt++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1352 dhcp_zero_index(opt); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1353 for (i = 0, opt = ifp->ctx->vivso; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1354 i < ifp->ctx->vivso_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1355 i++, opt++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1356 dhcp_zero_index(opt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1357 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1358 for (i = 0, opt = ifp->ctx->dhcp_opts; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1359 i < ifp->ctx->dhcp_opts_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1360 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1361 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1362 if (has_option_mask(ifo->nomask, opt->option)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1363 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1364 if (dhcp_getoverride(ifo, opt->option)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1365 continue; |
| 4166 | 1366 p = get_option(ifp->ctx, bootp, bootp_len, opt->option, &pl); |
| 1367 if (p == NULL) | |
| 1368 continue; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1369 dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, |
| 4166 | 1370 opt, dhcp_getoption, p, pl); |
| 1371 | |
| 1372 if (opt->option != DHO_VIVSO || pl <= (int)sizeof(uint32_t)) | |
| 1373 continue; | |
| 1374 memcpy(&en, p, sizeof(en)); | |
| 1375 en = ntohl(en); | |
| 1376 vo = vivso_find(en, ifp); | |
| 1377 if (vo == NULL) | |
| 1378 continue; | |
| 1379 /* Skip over en + total size */ | |
| 1380 p += sizeof(en) + 1; | |
| 1381 pl -= sizeof(en) + 1; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1382 dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, |
| 4166 | 1383 vo, dhcp_getoption, p, pl); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1384 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1385 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1386 for (i = 0, opt = ifo->dhcp_override; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1387 i < ifo->dhcp_override_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1388 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1389 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1390 if (has_option_mask(ifo->nomask, opt->option)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1391 continue; |
| 4166 | 1392 p = get_option(ifp->ctx, bootp, bootp_len, opt->option, &pl); |
| 1393 if (p == NULL) | |
| 1394 continue; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1395 dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, |
| 4166 | 1396 opt, dhcp_getoption, p, pl); |
|
3932
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 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1399 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
|
1400 } |
|
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 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1403 get_lease(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
|
1404 struct dhcp_lease *lease, const struct bootp *bootp, 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
|
1405 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1406 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
|
1407 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1408 assert(bootp != NULL); |
|
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 memcpy(&lease->cookie, bootp->vend, sizeof(lease->cookie)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1411 /* BOOTP does not set yiaddr for replies when ciaddr is set. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1412 lease->addr.s_addr = bootp->yiaddr ? bootp->yiaddr : bootp->ciaddr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1413 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
|
1414 if (ifp->options->options & (DHCPCD_STATIC | DHCPCD_INFORM)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1415 if (ifp->options->req_addr.s_addr != INADDR_ANY) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1416 lease->mask = ifp->options->req_mask; |
|
4207
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1417 if (ifp->options->req_brd.s_addr != INADDR_ANY) |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1418 lease->brd = ifp->options->req_brd; |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1419 else |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1420 lease->brd.s_addr = |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1421 lease->addr.s_addr | ~lease->mask.s_addr; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1422 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1423 const struct ipv4_addr *ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1424 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1425 ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1426 assert(ia != NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1427 lease->mask = ia->mask; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1428 lease->brd = ia->brd; |
|
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 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1431 if (get_option_addr(ctx, &lease->mask, bootp, len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1432 DHO_SUBNETMASK) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1433 lease->mask.s_addr = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1434 ipv4_getnetmask(lease->addr.s_addr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1435 if (get_option_addr(ctx, &lease->brd, bootp, len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1436 DHO_BROADCAST) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1437 lease->brd.s_addr = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1438 lease->addr.s_addr | ~lease->mask.s_addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1439 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1440 if (get_option_uint32(ctx, &lease->leasetime, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1441 bootp, len, DHO_LEASETIME) != 0) |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
1442 lease->leasetime = DHCP_INFINITE_LIFETIME; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1443 if (get_option_uint32(ctx, &lease->renewaltime, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1444 bootp, len, DHO_RENEWALTIME) != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1445 lease->renewaltime = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1446 if (get_option_uint32(ctx, &lease->rebindtime, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1447 bootp, len, DHO_REBINDTIME) != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1448 lease->rebindtime = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1449 if (get_option_addr(ctx, &lease->server, bootp, len, DHO_SERVERID) != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1450 lease->server.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1451 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1452 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1453 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
|
1454 get_dhcp_op(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
|
1455 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1456 const struct dhcp_op *d; |
|
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 for (d = dhcp_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
|
1459 if (d->value == type) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1460 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
|
1461 return NULL; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1464 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1465 dhcp_fallback(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1466 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1467 struct interface *iface; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1468 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1469 iface = (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
|
1470 dhcpcd_selectprofile(iface, iface->options->fallback); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1471 dhcpcd_startinterface(iface); |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1474 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1475 dhcp_new_xid(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
|
1476 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1477 struct dhcp_state *state; |
|
4177
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1478 const struct interface *ifp1; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1479 const struct dhcp_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
|
1480 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1481 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1482 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
|
1483 ifp->hwlen >= sizeof(state->xid)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1484 /* 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
|
1485 memcpy(&state->xid, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1486 (ifp->hwaddr + ifp->hwlen) - sizeof(state->xid), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1487 sizeof(state->xid)); |
|
4177
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1488 else { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1489 again: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1490 state->xid = arc4random(); |
|
4177
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1491 } |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1492 |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1493 /* Ensure it's unique */ |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1494 TAILQ_FOREACH(ifp1, ifp->ctx->ifaces, next) { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1495 if (ifp == ifp1) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1496 continue; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1497 if ((state1 = D_CSTATE(ifp1)) == NULL) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1498 continue; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1499 if (state1->xid == state->xid) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1500 break; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1501 } |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1502 if (ifp1 != NULL) { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1503 if (ifp->options->options & DHCPCD_XID_HWADDR && |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1504 ifp->hwlen >= sizeof(state->xid)) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1505 { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1506 logerrx("%s: duplicate xid on %s", |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1507 ifp->name, ifp1->name); |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1508 return; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1509 } |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1510 goto again; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1511 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1512 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1513 /* We can't do this when sharing leases across interfaes */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1514 #if 0 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1515 /* As the XID changes, re-apply the filter. */ |
|
4014
eed6b78ac418
Log bpf_arp and bpf_bootp failures.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
1516 if (state->bpf_fd != -1) { |
|
eed6b78ac418
Log bpf_arp and bpf_bootp failures.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
1517 if (bpf_bootp(ifp, state->bpf_fd) == -1) |
|
eed6b78ac418
Log bpf_arp and bpf_bootp failures.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
1518 logerr(__func__); /* try to continue */ |
|
eed6b78ac418
Log bpf_arp and bpf_bootp failures.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
1519 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1520 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1521 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1522 |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1523 static void |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1524 dhcp_closebpf(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
|
1525 { |
|
4846
fa69c463f3ad
privsep: Don't close BPF listeners when forked
Roy Marples <roy@marples.name>
parents:
4845
diff
changeset
|
1526 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
|
1527 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1528 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1529 #ifdef PRIVSEP |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1530 if (IN_PRIVSEP_SE(ctx)) |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1531 ps_bpf_closebootp(ifp); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1532 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1533 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1534 if (state->bpf != NULL) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1535 eloop_event_delete(ctx->eloop, state->bpf->bpf_fd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1536 bpf_close(state->bpf); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1537 state->bpf = NULL; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1538 } |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1539 } |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1540 |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1541 static void |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1542 dhcp_closeinet(struct interface *ifp) |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1543 { |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1544 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1545 struct dhcp_state *state = D_STATE(ifp); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1546 |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1547 #ifdef PRIVSEP |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1548 if (IN_PRIVSEP_SE(ctx)) { |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1549 if (state->addr != NULL) |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1550 ps_inet_closebootp(state->addr); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1551 } |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1552 #endif |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1553 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1554 if (state->udp_rfd != -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1555 eloop_event_delete(ctx->eloop, state->udp_rfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1556 close(state->udp_rfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1557 state->udp_rfd = -1; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1558 } |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1559 } |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1560 |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1561 void |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1562 dhcp_close(struct interface *ifp) |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1563 { |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1564 struct dhcp_state *state = D_STATE(ifp); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1565 |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1566 if (state == NULL) |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1567 return; |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1568 |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1569 dhcp_closebpf(ifp); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
1570 dhcp_closeinet(ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1571 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1572 state->interval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1573 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1574 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1575 int |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1576 dhcp_openudp(struct in_addr *ia) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1577 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1578 int s; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1579 struct sockaddr_in sin; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1580 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1581 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1582 if ((s = xsocket(PF_INET, SOCK_DGRAM | SOCK_CXNB, IPPROTO_UDP)) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1583 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1584 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1585 n = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1586 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1587 goto errexit; |
| 4784 | 1588 #ifdef IP_RECVIF |
| 1589 if (setsockopt(s, IPPROTO_IP, IP_RECVIF, &n, sizeof(n)) == -1) | |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1590 goto errexit; |
| 4784 | 1591 #else |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1592 if (setsockopt(s, IPPROTO_IP, IP_RECVPKTINFO, &n, sizeof(n)) == -1) |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1593 goto errexit; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1594 #endif |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1595 #ifdef SO_RERROR |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1596 if (setsockopt(s, SOL_SOCKET, SO_RERROR, &n, sizeof(n)) == -1) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1597 goto errexit; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1598 #endif |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1599 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1600 memset(&sin, 0, sizeof(sin)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1601 sin.sin_family = AF_INET; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1602 sin.sin_port = htons(BOOTPC); |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1603 if (ia != NULL) |
|
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1604 sin.sin_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
|
1605 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1606 goto errexit; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1607 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1608 return s; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1609 |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1610 errexit: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1611 close(s); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1612 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1613 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1614 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1615 static uint16_t |
|
4675
5c59227c6c91
DHCP: Fix in_cksum for big endian
Roy Marples <roy@marples.name>
parents:
4642
diff
changeset
|
1616 in_cksum(const void *data, size_t len, uint32_t *isum) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1617 { |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1618 const uint16_t *word = data; |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1619 uint32_t sum = isum != NULL ? *isum : 0; |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1620 |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1621 for (; len > 1; len -= sizeof(*word)) |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1622 sum += *word++; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1623 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1624 if (len == 1) |
|
4676
d8a9fff079d6
Cast away a conversion warning with prior
Roy Marples <roy@marples.name>
parents:
4675
diff
changeset
|
1625 sum += htons((uint16_t)(*(const uint8_t *)word << 8)); |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1626 |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1627 if (isum != NULL) |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1628 *isum = sum; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1629 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1630 sum = (sum >> 16) + (sum & 0xffff); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1631 sum += (sum >> 16); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1632 |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1633 return (uint16_t)~sum; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1634 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1635 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1636 static struct bootp_pkt * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1637 dhcp_makeudppacket(size_t *sz, const uint8_t *data, size_t length, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1638 struct in_addr source, struct in_addr dest) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1639 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1640 struct bootp_pkt *udpp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1641 struct ip *ip; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1642 struct udphdr *udp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1643 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1644 if ((udpp = calloc(1, sizeof(*ip) + sizeof(*udp) + length)) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1645 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1646 ip = &udpp->ip; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1647 udp = &udpp->udp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1648 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1649 /* OK, this is important :) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1650 * We copy the data to our packet and then create a small part of the |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1651 * ip structure and an invalid ip_len (basically udp length). |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1652 * We then fill the udp structure and put the checksum |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1653 * of the whole packet into the udp checksum. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1654 * Finally we complete the ip structure and ip checksum. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1655 * If we don't do the ordering like so then the udp checksum will be |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1656 * broken, so find another way of doing it! */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1657 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1658 memcpy(&udpp->bootp, data, length); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1659 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1660 ip->ip_p = IPPROTO_UDP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1661 ip->ip_src.s_addr = source.s_addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1662 if (dest.s_addr == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1663 ip->ip_dst.s_addr = INADDR_BROADCAST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1664 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1665 ip->ip_dst.s_addr = dest.s_addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1666 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1667 udp->uh_sport = htons(BOOTPC); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1668 udp->uh_dport = htons(BOOTPS); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1669 udp->uh_ulen = htons((uint16_t)(sizeof(*udp) + length)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1670 ip->ip_len = udp->uh_ulen; |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1671 udp->uh_sum = in_cksum(udpp, sizeof(*ip) + sizeof(*udp) + length, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1672 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1673 ip->ip_v = IPVERSION; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1674 ip->ip_hl = sizeof(*ip) >> 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1675 ip->ip_id = (uint16_t)arc4random_uniform(UINT16_MAX); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1676 ip->ip_ttl = IPDEFTTL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1677 ip->ip_len = htons((uint16_t)(sizeof(*ip) + sizeof(*udp) + length)); |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1678 ip->ip_sum = in_cksum(ip, sizeof(*ip), NULL); |
|
4617
fff03a5ca0b8
DHCP: If IP checksum is zero for the message, make it all ones.
Roy Marples <roy@marples.name>
parents:
4610
diff
changeset
|
1679 if (ip->ip_sum == 0) |
|
fff03a5ca0b8
DHCP: If IP checksum is zero for the message, make it all ones.
Roy Marples <roy@marples.name>
parents:
4610
diff
changeset
|
1680 ip->ip_sum = 0xffff; /* RFC 768 */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1681 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1682 *sz = sizeof(*ip) + sizeof(*udp) + length; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1683 return udpp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1684 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1685 |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1686 static ssize_t |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1687 dhcp_sendudp(struct interface *ifp, struct in_addr *to, void *data, size_t len) |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1688 { |
| 4784 | 1689 struct sockaddr_in sin = { |
| 1690 .sin_family = AF_INET, | |
| 1691 .sin_addr = *to, | |
| 1692 .sin_port = htons(BOOTPS), | |
| 1693 #ifdef HAVE_SA_LEN | |
| 1694 .sin_len = sizeof(sin), | |
| 1695 #endif | |
| 1696 }; | |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1697 struct udphdr udp = { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1698 .uh_sport = htons(BOOTPC), |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1699 .uh_dport = htons(BOOTPS), |
| 5234 | 1700 .uh_ulen = htons((uint16_t)(sizeof(udp) + len)), |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1701 }; |
| 4784 | 1702 struct iovec iov[] = { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1703 { .iov_base = &udp, .iov_len = sizeof(udp), }, |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1704 { .iov_base = data, .iov_len = len, }, |
| 4784 | 1705 }; |
| 1706 struct msghdr msg = { | |
| 1707 .msg_name = (void *)&sin, | |
| 1708 .msg_namelen = sizeof(sin), | |
| 1709 .msg_iov = iov, | |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1710 .msg_iovlen = __arraycount(iov), |
| 4784 | 1711 }; |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1712 struct dhcpcd_ctx *ctx = ifp->ctx; |
| 4784 | 1713 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1714 #ifdef PRIVSEP |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1715 if (ctx->options & DHCPCD_PRIVSEP) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1716 return ps_inet_sendbootp(ifp, &msg); |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1717 #endif |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1718 return sendmsg(ctx->udp_wfd, &msg, 0); |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1719 } |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1720 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1721 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1722 send_message(struct interface *ifp, 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
|
1723 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
|
1724 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1725 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1726 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
|
1727 struct bootp *bootp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1728 struct bootp_pkt *udp; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1729 size_t len, ulen; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1730 ssize_t r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1731 struct in_addr from, to; |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
1732 unsigned int RT; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1733 |
|
4940
a0d2d9dd08f3
DHCP: Fix a bogus gcc warning
Roy Marples <roy@marples.name>
parents:
4932
diff
changeset
|
1734 if (callback == NULL) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1735 /* No carrier? Don't bother sending the packet. */ |
|
5499
6a2da5651841
dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents:
5497
diff
changeset
|
1736 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
|
1737 return; |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1738 logdebugx("%s: sending %s with xid 0x%x", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1739 ifp->name, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1740 ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1741 state->xid); |
|
4940
a0d2d9dd08f3
DHCP: Fix a bogus gcc warning
Roy Marples <roy@marples.name>
parents:
4932
diff
changeset
|
1742 RT = 0; /* bogus gcc warning */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1743 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1744 if (state->interval == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1745 state->interval = 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1746 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1747 state->interval *= 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1748 if (state->interval > 64) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1749 state->interval = 64; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1750 } |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
1751 RT = (state->interval * MSEC_PER_SEC) + |
|
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
1752 (arc4random_uniform(MSEC_PER_SEC * 2) - 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
|
1753 /* No carrier? Don't bother sending the packet. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1754 * However, we do need to advance the timeout. */ |
|
5499
6a2da5651841
dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents:
5497
diff
changeset
|
1755 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
|
1756 goto fail; |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1757 logdebugx("%s: sending %s (xid 0x%x), next in %0.1f seconds", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1758 ifp->name, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1759 ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1760 state->xid, |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
1761 (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
|
1762 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1763 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1764 r = make_message(&bootp, ifp, type); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1765 if (r == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1766 goto fail; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1767 len = (size_t)r; |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1768 |
|
5424
28a650d93729
DHCP: Mark the state as expired on lase lease extension
Roy Marples <roy@marples.name>
parents:
5299
diff
changeset
|
1769 if (!(state->added & (STATE_FAKE | STATE_EXPIRED)) && |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1770 state->addr != NULL && |
|
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1771 ipv4_iffindaddr(ifp, &state->lease.addr, NULL) != NULL) |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1772 from.s_addr = state->lease.addr.s_addr; |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1773 else |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1774 from.s_addr = INADDR_ANY; |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1775 if (from.s_addr != INADDR_ANY && |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1776 state->lease.server.s_addr != INADDR_ANY) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1777 to.s_addr = state->lease.server.s_addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1778 else |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1779 to.s_addr = INADDR_BROADCAST; |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1780 |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1781 /* |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1782 * If not listening on the unspecified address we can |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1783 * only receive broadcast messages via BPF. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1784 * Sockets bound to an address cannot receive broadcast messages |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1785 * even if they are setup to send them. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1786 * Broadcasting from UDP is only an optimisation for rebinding |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1787 * and on BSD, at least, is reliant on the subnet route being |
| 4825 | 1788 * correctly configured to receive the unicast reply. |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1789 * As such, we always broadcast and receive the reply to it via BPF. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1790 * This also guarantees we have a DHCP server attached to the |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1791 * interface we want to configure because we can't dictate the |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1792 * interface via IP_PKTINFO unlike for IPv6. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1793 */ |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1794 if (to.s_addr != INADDR_BROADCAST) { |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1795 if (dhcp_sendudp(ifp, &to, bootp, len) != -1) |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1796 goto out; |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1797 logerr("%s: dhcp_sendudp", ifp->name); |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1798 } |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1799 |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1800 if (dhcp_openbpf(ifp) == -1) |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1801 goto out; |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1802 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1803 udp = dhcp_makeudppacket(&ulen, (uint8_t *)bootp, len, from, to); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1804 if (udp == NULL) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1805 logerr("%s: dhcp_makeudppacket", ifp->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1806 r = 0; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1807 #ifdef PRIVSEP |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1808 } else if (ifp->ctx->options & DHCPCD_PRIVSEP) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1809 r = ps_bpf_sendbootp(ifp, udp, ulen); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1810 free(udp); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
1811 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1812 } else { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
1813 r = bpf_send(state->bpf, ETHERTYPE_IP, udp, ulen); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1814 free(udp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1815 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1816 /* If we failed to send a raw packet this normally means |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1817 * we don't have the ability to work beneath the IP layer |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1818 * for this interface. |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1819 * As such we remove it from consideration without actually |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1820 * stopping the interface. */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1821 if (r == -1) { |
| 4784 | 1822 logerr("%s: bpf_send", ifp->name); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1823 switch(errno) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1824 case ENETDOWN: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1825 case ENETRESET: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1826 case ENETUNREACH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1827 case ENOBUFS: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1828 break; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1829 default: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1830 if (!(ifp->ctx->options & DHCPCD_TEST)) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1831 dhcp_drop(ifp, "FAIL"); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1832 eloop_timeout_delete(ifp->ctx->eloop, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1833 NULL, ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1834 callback = NULL; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1835 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1836 } |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1837 |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1838 out: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1839 free(bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1840 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1841 fail: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1842 /* Even if we fail to send a packet we should continue as we are |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1843 * as our failure timeouts will change out codepath when needed. */ |
|
4940
a0d2d9dd08f3
DHCP: Fix a bogus gcc warning
Roy Marples <roy@marples.name>
parents:
4932
diff
changeset
|
1844 if (callback != NULL) |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
1845 eloop_timeout_add_msec(ifp->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
|
1846 } |
|
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 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1849 send_inform(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1850 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1851 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1852 send_message((struct interface *)arg, DHCP_INFORM, send_inform); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1853 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1854 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1855 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1856 send_discover(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1857 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1858 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1859 send_message((struct interface *)arg, DHCP_DISCOVER, send_discover); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1860 } |
|
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 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1863 send_request(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1864 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1865 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1866 send_message((struct interface *)arg, DHCP_REQUEST, send_request); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1867 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1868 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1869 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1870 send_renew(void *arg) |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1873 send_message((struct interface *)arg, DHCP_REQUEST, send_renew); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1874 } |
|
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 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1877 send_rebind(void *arg) |
|
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 send_message((struct interface *)arg, DHCP_REQUEST, send_rebind); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1881 } |
|
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 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1884 dhcp_discover(void *arg) |
|
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 struct interface *ifp = arg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1887 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1888 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
|
1889 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1890 state->state = DHS_DISCOVER; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1891 dhcp_new_xid(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1892 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); |
|
5428
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1893 if (!(state->added & STATE_EXPIRED)) { |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1894 if (ifo->fallback) |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1895 eloop_timeout_add_sec(ifp->ctx->eloop, |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1896 ifo->reboot, dhcp_fallback, ifp); |
|
5449
b8078525aa41
DHCP: Fix compile without IPv4LL
Roy Marples <roy@marples.name>
parents:
5429
diff
changeset
|
1897 #ifdef IPV4LL |
|
5428
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1898 else if (ifo->options & DHCPCD_IPV4LL) |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1899 eloop_timeout_add_sec(ifp->ctx->eloop, |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1900 ifo->reboot, ipv4ll_start, ifp); |
|
5449
b8078525aa41
DHCP: Fix compile without IPv4LL
Roy Marples <roy@marples.name>
parents:
5429
diff
changeset
|
1901 #endif |
|
5428
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1902 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1903 if (ifo->options & DHCPCD_REQUEST) |
|
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
|
1904 loginfox("%s: soliciting a DHCP lease (requesting %s)", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1905 ifp->name, inet_ntoa(ifo->req_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1906 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
|
1907 loginfox("%s: soliciting a %s lease", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1908 ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP"); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1909 send_discover(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1910 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1911 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1912 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1913 dhcp_request(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1914 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1915 struct interface *ifp = arg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1916 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1917 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1918 state->state = DHS_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1919 send_request(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1920 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1921 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1922 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1923 dhcp_expire(void *arg) |
|
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 struct interface *ifp = arg; |
|
5428
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1926 struct dhcp_state *state = D_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
|
1927 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1928 if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) { |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1929 logwarnx("%s: DHCP lease expired, extending lease", ifp->name); |
|
5424
28a650d93729
DHCP: Mark the state as expired on lase lease extension
Roy Marples <roy@marples.name>
parents:
5299
diff
changeset
|
1930 state->added |= STATE_EXPIRED; |
|
5428
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1931 } else { |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1932 logerrx("%s: DHCP lease expired", ifp->name); |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1933 dhcp_drop(ifp, "EXPIRE"); |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1934 dhcp_unlink(ifp->ctx, state->leasefile); |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1935 } |
|
5428
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1936 state->interval = 0; |
|
ab53e42710ae
DHCP: When extending the lease, re-enter the DISCOVER phase.
Roy Marples <roy@marples.name>
parents:
5426
diff
changeset
|
1937 dhcp_discover(ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1938 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1939 |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
1940 #if defined(ARP) || defined(IN_IFF_DUPLICATED) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1941 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1942 dhcp_decline(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
|
1943 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1944 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1945 send_message(ifp, DHCP_DECLINE, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1946 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1947 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1948 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1949 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1950 dhcp_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
|
1951 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1952 struct interface *ifp = arg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1953 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1954 struct dhcp_lease *lease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1955 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1956 if ((state = D_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
|
1957 return; |
|
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 /* 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
|
1960 if (state->state != DHS_BOUND && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1961 state->state != DHS_RENEW) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1962 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1963 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1964 /* 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
|
1965 eloop_timeout_delete(ifp->ctx->eloop, dhcp_startrenew, ifp); |
|
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 lease = &state->lease; |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1968 logdebugx("%s: renewing lease of %s", ifp->name, |
|
3960
42a6a3d1596e
Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
1969 inet_ntoa(lease->addr)); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1970 state->state = DHS_RENEW; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1971 dhcp_new_xid(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1972 state->interval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1973 send_renew(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1974 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1975 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1976 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1977 dhcp_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
|
1978 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1979 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1980 dhcp_startrenew(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1981 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1982 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1983 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1984 dhcp_rebind(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1985 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1986 struct interface *ifp = arg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1987 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1988 struct dhcp_lease *lease = &state->lease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1989 |
| 4010 | 1990 logwarnx("%s: failed to renew DHCP, rebinding", ifp->name); |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1991 logdebugx("%s: expire in %"PRIu32" seconds", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1992 ifp->name, lease->leasetime - lease->rebindtime); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1993 state->state = DHS_REBIND; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1994 eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp); |
|
4188
23ff91710a01
dhcp: Don't set ciaddr or unicast if the address we have is faked.
Roy Marples <roy@marples.name>
parents:
4187
diff
changeset
|
1995 state->lease.server.s_addr = INADDR_ANY; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1996 state->interval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1997 ifp->options->options &= ~(DHCPCD_CSR_WARNED | |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1998 DHCPCD_ROUTER_HOST_ROUTE_WARNED); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1999 send_rebind(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2000 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2001 |
|
4584
978e3fbbec6c
Fix compile on Linux without ARPING
Roy Marples <roy@marples.name>
parents:
4581
diff
changeset
|
2002 #if defined(ARP) || defined(IN_IFF_DUPLICATED) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2003 static void |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2004 dhcp_finish_dad(struct interface *ifp, struct in_addr *ia) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2005 { |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2006 struct dhcp_state *state = D_STATE(ifp); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2007 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2008 if (state->state != DHS_PROBE) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2009 return; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2010 if (state->offer == NULL || state->offer->yiaddr != ia->s_addr) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2011 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2012 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2013 logdebugx("%s: DAD completed for %s", ifp->name, inet_ntoa(*ia)); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2014 if (!(ifp->options->options & DHCPCD_INFORM)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2015 dhcp_bind(ifp); |
| 4485 | 2016 #ifndef IN_IFF_DUPLICATED |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
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 struct bootp *bootp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2019 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
|
2020 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2021 bootp = state->new; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2022 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
|
2023 state->new = state->offer; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2024 state->new_len = state->offer_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2025 get_lease(ifp, &state->lease, state->new, state->new_len); |
| 4457 | 2026 ipv4_applyaddr(ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2027 state->new = bootp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2028 state->new_len = len; |
|
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 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2031 |
|
4287
2b519911f230
dhcp: Fix more fallout for builds without IPv4LL
Roy Marples <roy@marples.name>
parents:
4278
diff
changeset
|
2032 #ifdef IPV4LL |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2033 /* Stop IPv4LL now we have a working DHCP address */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2034 ipv4ll_drop(ifp); |
|
4287
2b519911f230
dhcp: Fix more fallout for builds without IPv4LL
Roy Marples <roy@marples.name>
parents:
4278
diff
changeset
|
2035 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2036 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2037 if (ifp->options->options & DHCPCD_INFORM) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2038 dhcp_inform(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2039 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2040 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2041 |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2042 static bool |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2043 dhcp_addr_duplicated(struct interface *ifp, struct in_addr *ia) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2044 { |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2045 struct dhcp_state *state = D_STATE(ifp); |
|
4731
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2046 unsigned long long opts = ifp->options->options; |
|
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2047 struct dhcpcd_ctx *ctx = ifp->ctx; |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2048 bool deleted = false; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2049 #ifdef IN_IFF_DUPLICATED |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2050 struct ipv4_addr *iap; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2051 #endif |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2052 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2053 if ((state->offer == NULL || state->offer->yiaddr != ia->s_addr) && |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2054 !IN_ARE_ADDR_EQUAL(ia, &state->lease.addr)) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2055 return deleted; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2056 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2057 /* RFC 2131 3.1.5, Client-server interaction */ |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2058 logerrx("%s: DAD detected %s", ifp->name, inet_ntoa(*ia)); |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2059 dhcp_unlink(ifp->ctx, state->leasefile); |
|
4731
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2060 if (!(opts & DHCPCD_STATIC) && !state->lease.frominfo) |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2061 dhcp_decline(ifp); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2062 #ifdef IN_IFF_DUPLICATED |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2063 if ((iap = ipv4_iffindaddr(ifp, ia, NULL)) != NULL) { |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2064 ipv4_deladdr(iap, 0); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2065 deleted = true; |
|
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2066 } |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2067 #endif |
|
4731
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2068 eloop_timeout_delete(ctx->eloop, NULL, ifp); |
|
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2069 if (opts & (DHCPCD_STATIC | DHCPCD_INFORM)) { |
|
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2070 state->reason = "EXPIRE"; |
|
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2071 script_runreason(ifp, state->reason); |
|
4738
f85dad8813de
DHCP: Don't exit on static DaD failure if master or using IPv6.
Roy Marples <roy@marples.name>
parents:
4737
diff
changeset
|
2072 #define NOT_ONLY_SELF (DHCPCD_MASTER | DHCPCD_IPV6RS | DHCPCD_DHCP6) |
|
f85dad8813de
DHCP: Don't exit on static DaD failure if master or using IPv6.
Roy Marples <roy@marples.name>
parents:
4737
diff
changeset
|
2073 if (!(ctx->options & NOT_ONLY_SELF)) |
|
4731
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2074 eloop_exit(ifp->ctx->eloop, EXIT_FAILURE); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2075 return deleted; |
|
4731
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2076 } |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2077 eloop_timeout_add_sec(ifp->ctx->eloop, |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2078 DHCP_RAND_MAX, dhcp_discover, ifp); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2079 return deleted; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2080 } |
|
4584
978e3fbbec6c
Fix compile on Linux without ARPING
Roy Marples <roy@marples.name>
parents:
4581
diff
changeset
|
2081 #endif |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2082 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2083 #ifdef ARP |
|
5232
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2084 #ifdef KERNEL_RFC5227 |
|
5530
226b850d158d
Fix compile without various defines
Roy Marples <roy@marples.name>
parents:
5529
diff
changeset
|
2085 #ifdef ARPING |
|
5232
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2086 static void |
|
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2087 dhcp_arp_announced(struct arp_state *state) |
|
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2088 { |
|
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2089 |
|
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2090 arp_free(state); |
|
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2091 } |
|
5530
226b850d158d
Fix compile without various defines
Roy Marples <roy@marples.name>
parents:
5529
diff
changeset
|
2092 #endif |
|
5232
d09c879cc4d5
Fix compile for prior on NetBSD
Roy Marples <roy@marples.name>
parents:
5231
diff
changeset
|
2093 #else |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2094 static void |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2095 dhcp_arp_defend_failed(struct arp_state *astate) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2096 { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2097 struct interface *ifp = astate->iface; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2098 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2099 dhcp_drop(ifp, "EXPIRED"); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2100 dhcp_start1(ifp); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2101 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2102 #endif |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2103 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2104 #if !defined(KERNEL_RFC5227) || defined(ARPING) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2105 static void dhcp_arp_not_found(struct arp_state *); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2106 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2107 static struct arp_state * |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2108 dhcp_arp_new(struct interface *ifp, struct in_addr *addr) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2109 { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2110 struct arp_state *astate; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2111 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2112 astate = arp_new(ifp, addr); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2113 if (astate == NULL) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2114 return NULL; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2115 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2116 astate->found_cb = dhcp_arp_found; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2117 astate->not_found_cb = dhcp_arp_not_found; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2118 #ifdef KERNEL_RFC5227 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2119 astate->announced_cb = dhcp_arp_announced; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2120 #else |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2121 astate->announced_cb = NULL; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2122 astate->defend_failed_cb = dhcp_arp_defend_failed; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2123 #endif |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2124 return astate; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2125 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2126 #endif |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2127 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2128 #ifdef ARPING |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2129 static int |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2130 dhcp_arping(struct interface *ifp) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2131 { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2132 struct dhcp_state *state; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2133 struct if_options *ifo; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2134 struct arp_state *astate; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2135 struct in_addr addr; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2136 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2137 state = D_STATE(ifp); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2138 ifo = ifp->options; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2139 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2140 if (ifo->arping_len == 0 || state->arping_index > ifo->arping_len) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2141 return 0; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2142 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2143 if (state->arping_index + 1 == ifo->arping_len) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2144 state->arping_index++; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2145 dhcpcd_startinterface(ifp); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2146 return 1; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2147 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2148 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2149 addr.s_addr = ifo->arping[++state->arping_index]; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2150 astate = dhcp_arp_new(ifp, &addr); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2151 if (astate == NULL) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2152 logerr(__func__); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2153 return -1; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2154 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2155 arp_probe(astate); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2156 return 1; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2157 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2158 #endif |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2159 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2160 #if !defined(KERNEL_RFC5227) || defined(ARPING) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2161 static void |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2162 dhcp_arp_not_found(struct arp_state *astate) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2163 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2164 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
|
2165 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2166 ifp = astate->iface; |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2167 #ifdef ARPING |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2168 if (dhcp_arping(ifp) == 1) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2169 arp_free(astate); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2170 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2171 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2172 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2173 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2174 dhcp_finish_dad(ifp, &astate->addr); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2175 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2176 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2177 static void |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2178 dhcp_arp_found(struct arp_state *astate, const struct arp_msg *amsg) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2179 { |
| 4457 | 2180 struct in_addr addr; |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2181 struct interface *ifp = astate->iface; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2182 #ifdef ARPING |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2183 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2184 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
|
2185 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2186 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2187 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2188 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
|
2189 if (state->arping_index != -1 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2190 state->arping_index < ifo->arping_len && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2191 amsg && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2192 amsg->sip.s_addr == ifo->arping[state->arping_index]) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2193 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2194 char buf[HWADDR_LEN * 3]; |
|
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 hwaddr_ntoa(amsg->sha, ifp->hwlen, 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
|
2197 if (dhcpcd_selectprofile(ifp, buf) == -1 && |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2198 dhcpcd_selectprofile(ifp, inet_ntoa(amsg->sip)) == -1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2199 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2200 /* We didn't find a profile for this |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2201 * address or hwaddr, so move to the next |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2202 * arping profile */ |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2203 dhcp_arp_not_found(astate); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2204 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2205 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2206 arp_free(astate); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2207 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
|
2208 dhcpcd_startinterface(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2209 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2210 } |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2211 #else |
|
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2212 UNUSED(amsg); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2213 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2214 |
| 4457 | 2215 addr = astate->addr; |
| 2216 arp_free(astate); | |
|
4567
dda61c0a55f5
DHCP: On ARP duplication, ensure the interface pointer is valid
Roy Marples <roy@marples.name>
parents:
4562
diff
changeset
|
2217 dhcp_addr_duplicated(ifp, &addr); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2218 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2219 #endif |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2220 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2221 #endif /* ARP */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2222 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2223 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2224 dhcp_bind(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
|
2225 { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2226 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
|
2227 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2228 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
|
2229 struct dhcp_lease *lease = &state->lease; |
|
4952
e77138b6ec3b
DHCP: Spawn a listener in non master mode for a new lease
Roy Marples <roy@marples.name>
parents:
4940
diff
changeset
|
2230 uint8_t old_state; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2231 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2232 state->reason = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2233 /* If we don't have an offer, we are re-binding a lease on preference, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2234 * normally when two interfaces have a lease matching IP addresses. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2235 if (state->offer) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2236 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
|
2237 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
|
2238 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
|
2239 state->new = state->offer; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2240 state->new_len = state->offer_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2241 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2242 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2243 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2244 get_lease(ifp, lease, 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
|
2245 if (ifo->options & DHCPCD_STATIC) { |
|
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
|
2246 loginfox("%s: using static address %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
|
2247 ifp->name, inet_ntoa(lease->addr), |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2248 inet_ntocidr(lease->mask)); |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
2249 lease->leasetime = DHCP_INFINITE_LIFETIME; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2250 state->reason = "STATIC"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2251 } else if (ifo->options & DHCPCD_INFORM) { |
|
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
|
2252 loginfox("%s: received approval for %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2253 ifp->name, inet_ntoa(lease->addr)); |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
2254 lease->leasetime = DHCP_INFINITE_LIFETIME; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2255 state->reason = "INFORM"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2256 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2257 if (lease->frominfo) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2258 state->reason = "TIMEOUT"; |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
2259 if (lease->leasetime == DHCP_INFINITE_LIFETIME) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2260 lease->renewaltime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2261 lease->rebindtime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2262 lease->leasetime; |
|
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
|
2263 loginfox("%s: leased %s for infinity", |
| 4010 | 2264 ifp->name, inet_ntoa(lease->addr)); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2265 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2266 if (lease->leasetime < DHCP_MIN_LEASE) { |
| 4010 | 2267 logwarnx("%s: minimum lease is %d seconds", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2268 ifp->name, DHCP_MIN_LEASE); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2269 lease->leasetime = DHCP_MIN_LEASE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2270 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2271 if (lease->rebindtime == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2272 lease->rebindtime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2273 (uint32_t)(lease->leasetime * T2); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2274 else if (lease->rebindtime >= lease->leasetime) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2275 lease->rebindtime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2276 (uint32_t)(lease->leasetime * T2); |
| 4010 | 2277 logwarnx("%s: rebind time greater than lease " |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2278 "time, forcing to %"PRIu32" seconds", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2279 ifp->name, lease->rebindtime); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2280 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2281 if (lease->renewaltime == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2282 lease->renewaltime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2283 (uint32_t)(lease->leasetime * T1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2284 else if (lease->renewaltime > lease->rebindtime) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2285 lease->renewaltime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2286 (uint32_t)(lease->leasetime * T1); |
| 4010 | 2287 logwarnx("%s: renewal time greater than " |
| 2288 "rebind time, forcing to %"PRIu32" seconds", | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2289 ifp->name, lease->renewaltime); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2290 } |
|
5226
06575a46bbdd
DHCP: always log inform when not renewing
Roy Marples <roy@marples.name>
parents:
5211
diff
changeset
|
2291 if (state->state == DHS_RENEW && state->addr && |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2292 lease->addr.s_addr == state->addr->addr.s_addr && |
| 4010 | 2293 !(state->added & STATE_FAKE)) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
2294 logdebugx("%s: leased %s for %"PRIu32" seconds", |
| 4010 | 2295 ifp->name, inet_ntoa(lease->addr), |
| 2296 lease->leasetime); | |
| 2297 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
|
2298 loginfox("%s: leased %s for %"PRIu32" seconds", |
| 4010 | 2299 ifp->name, inet_ntoa(lease->addr), |
| 2300 lease->leasetime); | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2301 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2302 } |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2303 if (ctx->options & DHCPCD_TEST) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2304 state->reason = "TEST"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2305 script_runreason(ifp, state->reason); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2306 eloop_exit(ctx->eloop, EXIT_SUCCESS); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2307 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2308 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2309 if (state->reason == NULL) { |
|
5429
4729f8db7842
DHCP: reason is BOUND when recovering from an expired extended lease
Roy Marples <roy@marples.name>
parents:
5428
diff
changeset
|
2310 if (state->old && |
|
4729f8db7842
DHCP: reason is BOUND when recovering from an expired extended lease
Roy Marples <roy@marples.name>
parents:
5428
diff
changeset
|
2311 !(state->added & (STATE_FAKE | STATE_EXPIRED))) |
|
4729f8db7842
DHCP: reason is BOUND when recovering from an expired extended lease
Roy Marples <roy@marples.name>
parents:
5428
diff
changeset
|
2312 { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2313 if (state->old->yiaddr == state->new->yiaddr && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2314 lease->server.s_addr && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2315 state->state != DHS_REBIND) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2316 state->reason = "RENEW"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2317 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2318 state->reason = "REBIND"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2319 } else if (state->state == DHS_REBOOT) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2320 state->reason = "REBOOT"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2321 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2322 state->reason = "BOUND"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2323 } |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
2324 if (lease->leasetime == DHCP_INFINITE_LIFETIME) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2325 lease->renewaltime = lease->rebindtime = lease->leasetime; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2326 else { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2327 eloop_timeout_add_sec(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
|
2328 lease->renewaltime, dhcp_startrenew, ifp); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2329 eloop_timeout_add_sec(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
|
2330 lease->rebindtime, dhcp_rebind, ifp); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2331 eloop_timeout_add_sec(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
|
2332 lease->leasetime, dhcp_expire, ifp); |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
2333 logdebugx("%s: renew in %"PRIu32" seconds, rebind in %"PRIu32 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2334 " seconds", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2335 ifp->name, lease->renewaltime, lease->rebindtime); |
|
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 state->state = DHS_BOUND; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2338 if (!state->lease.frominfo && |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2339 !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))) { |
| 5494 | 2340 logdebugx("%s: writing lease: %s", |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2341 ifp->name, state->leasefile); |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2342 if (dhcp_writefile(ifp->ctx, state->leasefile, 0640, |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2343 state->new, state->new_len) == -1) |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2344 logerr("dhcp_writefile: %s", state->leasefile); |
|
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2345 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2346 |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2347 old_state = state->added; |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2348 |
|
4681
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
2349 /* Close the BPF filter as we can now receive DHCP messages |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2350 * on a UDP socket. */ |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2351 dhcp_closebpf(ifp); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2352 |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2353 /* Add the address */ |
|
4833
aadc0d25a706
DHCP: Require unspecificed BOOTP port for master mode
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
2354 ipv4_applyaddr(ifp); |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2355 |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2356 /* If not in master mode, open an address specific socket. */ |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2357 if (ctx->options & DHCPCD_MASTER || |
|
4952
e77138b6ec3b
DHCP: Spawn a listener in non master mode for a new lease
Roy Marples <roy@marples.name>
parents:
4940
diff
changeset
|
2358 (state->old != NULL && |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2359 state->old->yiaddr == state->new->yiaddr && |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2360 old_state & STATE_ADDED && !(old_state & STATE_FAKE))) |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2361 return; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2362 |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2363 dhcp_closeinet(ifp); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2364 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2365 #ifdef PRIVSEP |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
2366 if (IN_PRIVSEP_SE(ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2367 if (ps_inet_openbootp(state->addr) == -1) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2368 logerr(__func__); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2369 return; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2370 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2371 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2372 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2373 state->udp_rfd = dhcp_openudp(&state->addr->addr); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2374 if (state->udp_rfd == -1) { |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2375 logerr(__func__); |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2376 /* Address sharing without master mode is not supported. |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2377 * It's also possible another DHCP client could be running, |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2378 * which is even worse. |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2379 * We still need to work, so re-open BPF. */ |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2380 dhcp_openbpf(ifp); |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2381 return; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2382 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2383 eloop_event_add(ctx->eloop, state->udp_rfd, dhcp_handleifudp, ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2384 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2385 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2386 static size_t |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2387 dhcp_message_new(struct bootp **bootp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2388 const struct in_addr *addr, const struct in_addr *mask) |
|
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 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
|
2391 uint32_t cookie; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2392 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2393 if ((*bootp = calloc(1, sizeof(**bootp))) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2394 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2395 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2396 (*bootp)->yiaddr = addr->s_addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2397 p = (*bootp)->vend; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2398 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2399 cookie = htonl(MAGIC_COOKIE); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2400 memcpy(p, &cookie, sizeof(cookie)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2401 p += sizeof(cookie); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2402 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2403 if (mask->s_addr != INADDR_ANY) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2404 *p++ = DHO_SUBNETMASK; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2405 *p++ = sizeof(mask->s_addr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2406 memcpy(p, &mask->s_addr, sizeof(mask->s_addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2407 p+= sizeof(mask->s_addr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2408 } |
|
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 *p = DHO_END; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2411 return sizeof(**bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2412 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2413 |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2414 #if defined(ARP) || defined(KERNEL_RFC5227) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2415 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2416 dhcp_arp_address(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
|
2417 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2418 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2419 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2420 struct ipv4_addr *ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2421 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2422 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
|
2423 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2424 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2425 addr.s_addr = state->offer->yiaddr == INADDR_ANY ? |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2426 state->offer->ciaddr : state->offer->yiaddr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2427 /* If the interface already has the address configured |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2428 * then we can't ARP for duplicate detection. */ |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2429 ia = ipv4_iffindaddr(ifp, &addr, NULL); |
|
4481
7848309c100c
sun: Don't define IN_IFF_TENTATIVE or IN_IFF_DETACHED
Roy Marples <roy@marples.name>
parents:
4459
diff
changeset
|
2430 #ifdef IN_IFF_NOTUSEABLE |
|
3932
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 == NULL || ia->addr_flags & IN_IFF_NOTUSEABLE) { |
|
4191
30f5f070a4aa
dhcp: set probe state only when probing.
Roy Marples <roy@marples.name>
parents:
4188
diff
changeset
|
2432 state->state = DHS_PROBE; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2433 if (ia == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2434 struct dhcp_lease l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2435 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2436 get_lease(ifp, &l, state->offer, state->offer_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2437 /* Add the address now, let the kernel handle DAD. */ |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
2438 ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd, |
|
4562
559c1ce40f54
Use rebindtime rather than renewaltime.
Roy Marples <roy@marples.name>
parents:
4561
diff
changeset
|
2439 l.leasetime, l.rebindtime); |
|
4731
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2440 } else if (ia->addr_flags & IN_IFF_DUPLICATED) |
|
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2441 dhcp_addr_duplicated(ifp, &ia->addr); |
|
f421b59ced72
DHCP: Don't start DHCP if we fail DAD for static or informed addrs
Roy Marples <roy@marples.name>
parents:
4726
diff
changeset
|
2442 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
|
2443 loginfox("%s: waiting for DAD on %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2444 ifp->name, inet_ntoa(addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2445 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2446 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2447 #else |
|
4630
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2448 if (!(ifp->flags & IFF_NOARP) && |
|
5002
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2449 ifp->options->options & DHCPCD_ARP) |
|
4630
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2450 { |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2451 struct arp_state *astate; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2452 struct dhcp_lease l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2453 |
|
5002
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2454 /* Even if the address exists, we need to defend it. */ |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2455 astate = dhcp_arp_new(ifp, &addr); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2456 if (astate == NULL) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2457 return -1; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2458 |
|
5002
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2459 if (ia == NULL) { |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2460 state->state = DHS_PROBE; |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2461 get_lease(ifp, &l, state->offer, state->offer_len); |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2462 loginfox("%s: probing address %s/%d", |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2463 ifp->name, inet_ntoa(l.addr), inet_ntocidr(l.mask)); |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2464 /* We need to handle DAD. */ |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2465 arp_probe(astate); |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2466 return 0; |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2467 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2468 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2469 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2470 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2471 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2472 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2473 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2474 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2475 dhcp_arp_bind(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
|
2476 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2477 |
|
4425
7cd9fb2bbbe3
DHCP: Dont really add static address in test mode
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
2478 if (ifp->ctx->options & DHCPCD_TEST || |
|
7cd9fb2bbbe3
DHCP: Dont really add static address in test mode
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
2479 dhcp_arp_address(ifp) == 1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2480 dhcp_bind(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2481 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2482 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2483 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2484 static void |
|
5426
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2485 dhcp_lastlease(void *arg) |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2486 { |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2487 struct interface *ifp = arg; |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2488 struct dhcp_state *state = D_STATE(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2489 |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2490 loginfox("%s: timed out contacting a DHCP server, using last lease", |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2491 ifp->name); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2492 #if defined(ARP) || defined(KERNEL_RFC5227) |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2493 dhcp_arp_bind(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2494 #else |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2495 dhcp_bind(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2496 #endif |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2497 /* Set expired here because dhcp_bind() -> ipv4_addaddr() will reset |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2498 * state */ |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2499 state->added |= STATE_EXPIRED; |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2500 state->interval = 0; |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2501 dhcp_discover(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2502 } |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2503 |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2504 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
|
2505 dhcp_static(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
|
2506 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2507 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
|
2508 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2509 struct ipv4_addr *ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2510 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2511 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2512 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
|
2513 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2514 ia = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2515 if (ifo->req_addr.s_addr == INADDR_ANY && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2516 (ia = ipv4_iffindaddr(ifp, NULL, NULL)) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2517 { |
|
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
|
2518 loginfox("%s: waiting for 3rd party to " |
|
3960
42a6a3d1596e
Remove custom logger and output all diagnostics via syslog(3).
Roy Marples <roy@marples.name>
parents:
3932
diff
changeset
|
2519 "configure IP 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
|
2520 state->reason = "3RDPARTY"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2521 script_runreason(ifp, state->reason); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2522 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2523 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2524 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2525 state->offer_len = dhcp_message_new(&state->offer, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2526 ia ? &ia->addr : &ifo->req_addr, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2527 ia ? &ia->mask : &ifo->req_mask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2528 if (state->offer_len) |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2529 #if defined(ARP) || defined(KERNEL_RFC5227) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2530 dhcp_arp_bind(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2531 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2532 dhcp_bind(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2533 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2534 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2535 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2536 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2537 dhcp_inform(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
|
2538 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2539 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2540 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
|
2541 struct ipv4_addr *ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2542 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2543 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2544 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
|
2545 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2546 state->state = DHS_INFORM; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2547 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2548 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2549 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2550 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2551 if (ifo->req_addr.s_addr == INADDR_ANY) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2552 ia = ipv4_iffindaddr(ifp, NULL, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2553 if (ia == NULL) { |
|
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
|
2554 loginfox("%s: waiting for 3rd party to " |
| 4010 | 2555 "configure IP address", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2556 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2557 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
|
2558 state->reason = "3RDPARTY"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2559 script_runreason(ifp, state->reason); |
|
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 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2562 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2563 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2564 ia = ipv4_iffindaddr(ifp, &ifo->req_addr, &ifo->req_mask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2565 if (ia == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2566 if (ifp->ctx->options & DHCPCD_TEST) { |
| 4010 | 2567 logerrx("%s: cannot add IP address in test mode", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2568 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2569 return; |
|
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 ia = ipv4_iffindaddr(ifp, &ifo->req_addr, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2572 if (ia != NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2573 /* Netmask must be different, delete it. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2574 ipv4_deladdr(ia, 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2575 state->offer_len = dhcp_message_new(&state->offer, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2576 &ifo->req_addr, &ifo->req_mask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2577 #ifdef ARP |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2578 if (dhcp_arp_address(ifp) != 1) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2579 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2580 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2581 ia = ipv4_iffindaddr(ifp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2582 &ifo->req_addr, &ifo->req_mask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2583 assert(ia != NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2584 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2585 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2586 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2587 state->addr = ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2588 state->offer_len = dhcp_message_new(&state->offer, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2589 &ia->addr, &ia->mask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2590 if (state->offer_len) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2591 dhcp_new_xid(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2592 get_lease(ifp, &state->lease, state->offer, state->offer_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2593 send_inform(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2594 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2595 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2596 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2597 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2598 dhcp_reboot_newopts(struct interface *ifp, unsigned long long oldopts) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2599 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2600 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
|
2601 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2602 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2603 if (state == NULL || state->state == DHS_NONE) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2604 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2605 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
|
2606 if ((ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2607 (state->addr == NULL || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2608 state->addr->addr.s_addr != ifo->req_addr.s_addr)) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2609 (oldopts & (DHCPCD_INFORM | DHCPCD_STATIC) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2610 !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2611 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2612 dhcp_drop(ifp, "EXPIRE"); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2613 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2614 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2615 |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2616 #ifdef ARP |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2617 static int |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2618 dhcp_activeaddr(const struct interface *ifp, const struct in_addr *addr) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2619 { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2620 const struct interface *ifp1; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2621 const struct dhcp_state *state; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2622 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2623 TAILQ_FOREACH(ifp1, ifp->ctx->ifaces, next) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2624 if (ifp1 == ifp) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2625 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2626 if ((state = D_CSTATE(ifp1)) == NULL) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2627 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2628 switch(state->state) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2629 case DHS_REBOOT: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2630 case DHS_RENEW: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2631 case DHS_REBIND: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2632 case DHS_BOUND: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2633 case DHS_INFORM: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2634 break; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2635 default: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2636 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2637 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2638 if (state->lease.addr.s_addr == addr->s_addr) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2639 return 1; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2640 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2641 return 0; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2642 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2643 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2644 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2645 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2646 dhcp_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
|
2647 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2648 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
|
2649 struct dhcp_state *state = D_STATE(ifp); |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2650 #ifdef ARP |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2651 struct ipv4_addr *ia; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2652 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2653 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2654 if (state == NULL || state->state == DHS_NONE) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2655 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2656 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
|
2657 state->state = DHS_REBOOT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2658 state->interval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2659 |
|
5499
6a2da5651841
dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents:
5497
diff
changeset
|
2660 if (ifo->options & DHCPCD_LINK && !if_is_link_up(ifp)) { |
|
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
|
2661 loginfox("%s: waiting for carrier", 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
|
2662 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2663 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2664 if (ifo->options & DHCPCD_STATIC) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2665 dhcp_static(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2666 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2667 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2668 if (ifo->options & DHCPCD_INFORM) { |
|
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
|
2669 loginfox("%s: informing address of %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2670 ifp->name, inet_ntoa(state->lease.addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2671 dhcp_inform(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2672 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2673 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2674 if (ifo->reboot == 0 || state->offer == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2675 dhcp_discover(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2676 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2677 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2678 if (!IS_DHCP(state->offer)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2679 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2680 |
|
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
|
2681 loginfox("%s: rebinding lease of %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2682 ifp->name, inet_ntoa(state->lease.addr)); |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2683 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2684 #ifdef ARP |
|
4810
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2685 #ifndef KERNEL_RFC5227 |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2686 /* Create the DHCP ARP state so we can defend it. */ |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2687 (void)dhcp_arp_new(ifp, &state->lease.addr); |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2688 #endif |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2689 |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2690 /* If the address exists on the interface and no other interface |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2691 * is currently using it then announce it to ensure this |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2692 * interface gets the reply. */ |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2693 ia = ipv4_iffindaddr(ifp, &state->lease.addr, NULL); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2694 if (ia != NULL && |
|
4332
8777d91277fc
dhcp: Don't ARP announce bound addresses when testing
Roy Marples <roy@marples.name>
parents:
4299
diff
changeset
|
2695 !(ifp->ctx->options & DHCPCD_TEST) && |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2696 #ifdef IN_IFF_NOTUSEABLE |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2697 !(ia->addr_flags & IN_IFF_NOTUSEABLE) && |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2698 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2699 dhcp_activeaddr(ifp, &state->lease.addr) == 0) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2700 arp_ifannounceaddr(ifp, &state->lease.addr); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2701 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2702 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2703 dhcp_new_xid(ifp); |
|
4188
23ff91710a01
dhcp: Don't set ciaddr or unicast if the address we have is faked.
Roy Marples <roy@marples.name>
parents:
4187
diff
changeset
|
2704 state->lease.server.s_addr = INADDR_ANY; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2705 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
|
2706 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2707 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2708 /* Need to add this before dhcp_expire and friends. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2709 if (!ifo->fallback && ifo->options & DHCPCD_IPV4LL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2710 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
|
2711 ifo->reboot, ipv4ll_start, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2712 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2713 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2714 if (ifo->options & DHCPCD_LASTLEASE && state->lease.frominfo) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2715 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
|
2716 ifo->reboot, dhcp_lastlease, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2717 else if (!(ifo->options & DHCPCD_INFORM)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2718 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
|
2719 ifo->reboot, dhcp_expire, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2720 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2721 /* Don't bother ARP checking as the server could NAK us first. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2722 * Don't call dhcp_request as that would change the state */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2723 send_request(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2724 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2725 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2726 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2727 dhcp_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
|
2728 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2729 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2730 #ifdef RELEASE_SLOW |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2731 struct timespec ts; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2732 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2733 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2734 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2735 /* dhcp_start may just have been called and we don't yet have a state |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2736 * but we do have a timeout, so punt it. */ |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2737 if (state == NULL || state->state == DHS_NONE) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2738 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
|
2739 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2740 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2741 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2742 #ifdef ARP |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2743 if (state->addr != NULL) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2744 arp_freeaddr(ifp, &state->addr->addr); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2745 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2746 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2747 state->arping_index = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2748 #endif |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2749 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2750 if (ifp->options->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
|
2751 !(ifp->options->options & DHCPCD_INFORM)) |
|
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 /* 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
|
2754 * re-enter so guard by setting the state. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2755 if (state->state == DHS_RELEASE) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2756 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2757 state->state = DHS_RELEASE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2758 |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2759 dhcp_unlink(ifp->ctx, state->leasefile); |
|
5499
6a2da5651841
dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents:
5497
diff
changeset
|
2760 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
|
2761 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
|
2762 state->lease.server.s_addr != INADDR_ANY) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2763 { |
|
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
|
2764 loginfox("%s: releasing lease of %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2765 ifp->name, inet_ntoa(state->lease.addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2766 dhcp_new_xid(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2767 send_message(ifp, DHCP_RELEASE, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2768 #ifdef RELEASE_SLOW |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2769 /* Give the packet a chance to go */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2770 ts.tv_sec = RELEASE_DELAY_S; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2771 ts.tv_nsec = RELEASE_DELAY_NS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2772 nanosleep(&ts, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2773 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2774 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2775 } |
|
5294
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2776 #ifdef AUTH |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2777 else if (state->auth.reconf != NULL) { |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2778 /* |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2779 * 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
|
2780 * 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
|
2781 * renewals. |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2782 * 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
|
2783 * XXX persist this in another file? |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2784 */ |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2785 dhcp_unlink(ifp->ctx, state->leasefile); |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2786 } |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2787 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2788 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2789 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
|
2790 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2791 dhcp_auth_reset(&state->auth); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2792 #endif |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2793 |
|
5176
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2794 /* Close DHCP ports so a changed interface family is picked |
|
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2795 * up by a new BPF state. */ |
|
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2796 dhcp_close(ifp); |
|
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2797 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2798 state->state = DHS_NONE; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2799 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2800 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2801 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2802 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
|
2803 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
|
2804 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
|
2805 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
|
2806 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
|
2807 state->reason = reason; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2808 ipv4_applyaddr(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2809 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
|
2810 state->old = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2811 state->old_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2812 state->lease.addr.s_addr = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2813 ifp->options->options &= ~(DHCPCD_CSR_WARNED | |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2814 DHCPCD_ROUTER_HOST_ROUTE_WARNED); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2815 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2816 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2817 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2818 blacklisted_ip(const struct if_options *ifo, in_addr_t addr) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2819 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2820 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
|
2821 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2822 for (i = 0; i < ifo->blacklist_len; i += 2) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2823 if (ifo->blacklist[i] == (addr & ifo->blacklist[i + 1])) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2824 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2825 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2826 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2827 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2828 #define WHTLST_NONE 0 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2829 #define WHTLST_MATCH 1 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2830 #define WHTLST_NOMATCH 2 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2831 static unsigned int |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2832 whitelisted_ip(const struct if_options *ifo, in_addr_t addr) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2833 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2834 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
|
2835 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2836 if (ifo->whitelist_len == 0) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2837 return WHTLST_NONE; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2838 for (i = 0; i < ifo->whitelist_len; i += 2) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2839 if (ifo->whitelist[i] == (addr & ifo->whitelist[i + 1])) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2840 return WHTLST_MATCH; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2841 return WHTLST_NOMATCH; |
|
3932
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 static void |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
2845 log_dhcp(int loglevel, const char *msg, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2846 const struct interface *ifp, const struct bootp *bootp, size_t bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2847 const struct in_addr *from, int ad) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2848 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2849 const char *tfrom; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2850 char *a, sname[sizeof(bootp->sname) * 4]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2851 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2852 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2853 uint8_t overl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2854 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2855 if (strcmp(msg, "NAK:") == 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2856 a = get_option_string(ifp->ctx, bootp, bootp_len, DHO_MESSAGE); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2857 if (a) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2858 char *tmp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2859 size_t al, tmpl; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2860 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2861 al = strlen(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2862 tmpl = (al * 4) + 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2863 tmp = malloc(tmpl); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2864 if (tmp == NULL) { |
| 4010 | 2865 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
|
2866 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2867 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2868 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2869 print_string(tmp, tmpl, OT_STRING, (uint8_t *)a, al); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2870 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2871 a = tmp; |
|
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 } else if (ad && bootp->yiaddr != 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2874 addr.s_addr = bootp->yiaddr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2875 a = strdup(inet_ntoa(addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2876 if (a == NULL) { |
| 4010 | 2877 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
|
2878 return; |
|
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 } else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2881 a = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2882 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2883 tfrom = "from"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2884 r = get_option_addr(ifp->ctx, &addr, bootp, bootp_len, DHO_SERVERID); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2885 if (get_option_uint8(ifp->ctx, &overl, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2886 DHO_OPTSOVERLOADED) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2887 overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2888 if (bootp->sname[0] && r == 0 && !(overl & 2)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2889 print_string(sname, sizeof(sname), OT_STRING | OT_DOMAIN, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2890 bootp->sname, sizeof(bootp->sname)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2891 if (a == NULL) |
| 5494 | 2892 logmessage(loglevel, "%s: %s %s %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
|
2893 ifp->name, msg, tfrom, inet_ntoa(addr), sname); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2894 else |
| 5494 | 2895 logmessage(loglevel, "%s: %s %s %s %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
|
2896 ifp->name, msg, a, tfrom, inet_ntoa(addr), sname); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2897 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2898 if (r != 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2899 tfrom = "via"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2900 addr = *from; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2901 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2902 if (a == NULL) |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
2903 logmessage(loglevel, "%s: %s %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
|
2904 ifp->name, msg, tfrom, inet_ntoa(addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2905 else |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
2906 logmessage(loglevel, "%s: %s %s %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
|
2907 ifp->name, msg, a, tfrom, inet_ntoa(addr)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2908 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2909 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2910 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2911 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2912 /* If we're sharing the same IP address with another interface on the |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2913 * same network, we may receive the DHCP reply on the wrong interface. |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2914 * Try and re-direct it here. */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2915 static void |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2916 dhcp_redirect_dhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2917 const struct in_addr *from) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2918 { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2919 struct interface *ifn; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2920 const struct dhcp_state *state; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2921 uint32_t xid; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2922 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2923 xid = ntohl(bootp->xid); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2924 TAILQ_FOREACH(ifn, ifp->ctx->ifaces, next) { |
|
5009
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
2925 if (ifn == ifp) |
|
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
2926 continue; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2927 state = D_CSTATE(ifn); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2928 if (state == NULL || state->state == DHS_NONE) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2929 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2930 if (state->xid != xid) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2931 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2932 if (ifn->hwlen <= sizeof(bootp->chaddr) && |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2933 memcmp(bootp->chaddr, ifn->hwaddr, ifn->hwlen)) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2934 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2935 logdebugx("%s: redirecting DHCP message to %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2936 ifp->name, ifn->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2937 dhcp_handledhcp(ifn, bootp, bootp_len, from); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2938 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2939 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2940 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2941 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2942 dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2943 const struct in_addr *from) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2944 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2945 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2946 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
|
2947 struct dhcp_lease *lease = &state->lease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2948 uint8_t type, tmp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2949 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2950 unsigned int i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2951 char *msg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2952 bool bootp_copied; |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
2953 uint32_t v6only_time = 0; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
2954 bool use_v6only = false; |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
2955 #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
|
2956 const 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
|
2957 size_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
|
2958 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2959 #ifdef IN_IFF_DUPLICATED |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2960 struct ipv4_addr *ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2961 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2962 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2963 #define LOGDHCP0(l, m) \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2964 log_dhcp((l), (m), ifp, bootp, bootp_len, from, 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2965 #define LOGDHCP(l, m) \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2966 log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2967 |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2968 #define IS_STATE_ACTIVE(s) ((s)-state != DHS_NONE && \ |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2969 (s)->state != DHS_INIT && (s)->state != DHS_BOUND) |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2970 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2971 if (bootp->op != BOOTREPLY) { |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2972 if (IS_STATE_ACTIVE(state)) |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2973 logdebugx("%s: op (%d) is not BOOTREPLY", |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2974 ifp->name, bootp->op); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2975 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2976 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2977 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2978 if (state->xid != ntohl(bootp->xid)) { |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2979 if (IS_STATE_ACTIVE(state)) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2980 logdebugx("%s: wrong xid 0x%x (expecting 0x%x) from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2981 ifp->name, ntohl(bootp->xid), state->xid, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2982 inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2983 dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2984 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2985 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2986 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2987 if (ifp->hwlen <= sizeof(bootp->chaddr) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2988 memcmp(bootp->chaddr, ifp->hwaddr, ifp->hwlen)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2989 { |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2990 if (IS_STATE_ACTIVE(state)) { |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2991 char buf[sizeof(bootp->chaddr) * 3]; |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2992 |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2993 logdebugx("%s: xid 0x%x is for hwaddr %s", |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2994 ifp->name, ntohl(bootp->xid), |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2995 hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr), |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2996 buf, sizeof(buf))); |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2997 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2998 dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2999 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3000 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3001 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3002 if (!ifp->active) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3003 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3004 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3005 i = whitelisted_ip(ifp->options, from->s_addr); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3006 switch (i) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3007 case WHTLST_NOMATCH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3008 logwarnx("%s: non whitelisted DHCP packet from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3009 ifp->name, inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3010 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3011 case WHTLST_MATCH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3012 break; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3013 case WHTLST_NONE: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3014 if (blacklisted_ip(ifp->options, from->s_addr) == 1) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3015 logwarnx("%s: blacklisted DHCP packet from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3016 ifp->name, inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3017 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3018 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3019 } |
|
3932
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 /* We may have found a BOOTP server */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3022 if (get_option_uint8(ifp->ctx, &type, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3023 bootp, bootp_len, DHO_MESSAGETYPE) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3024 type = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3025 else if (ifo->options & DHCPCD_BOOTP) { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3026 logdebugx("%s: ignoring DHCP reply (expecting BOOTP)", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3027 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3028 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3029 } |
|
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 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3032 /* 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
|
3033 auth = get_option(ifp->ctx, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3034 DHO_AUTHENTICATION, &auth_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3035 if (auth) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3036 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
|
3037 (uint8_t *)bootp, bootp_len, 4, type, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3038 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
|
3039 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3040 LOGDHCP0(LOG_ERR, "authentication failed"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3041 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3042 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3043 if (state->auth.token) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3044 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
|
3045 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
|
3046 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
|
3047 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
|
3048 } 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
|
3049 if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3050 LOGDHCP0(LOG_ERR, "no authentication"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3051 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3052 } |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3053 LOGDHCP0(LOG_WARNING, "no authentication"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3054 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3055 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3056 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3057 /* RFC 3203 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3058 if (type == DHCP_FORCERENEW) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3059 if (from->s_addr == INADDR_ANY || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3060 from->s_addr == INADDR_BROADCAST) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3061 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3062 LOGDHCP(LOG_ERR, "discarding Force Renew"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3063 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3064 } |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
3065 #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
|
3066 if (auth == NULL) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3067 LOGDHCP(LOG_ERR, "unauthenticated Force Renew"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3068 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
|
3069 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3070 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3071 if (state->state != DHS_BOUND && state->state != DHS_INFORM) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3072 LOGDHCP(LOG_DEBUG, "not bound, ignoring Force Renew"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3073 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3074 } |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3075 LOGDHCP(LOG_INFO, "Force Renew from"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3076 /* The rebind and expire timings are still the same, we just |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3077 * enter the renew state early */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3078 if (state->state == DHS_BOUND) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3079 dhcp_renew(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3080 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3081 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
|
3082 send_inform, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3083 dhcp_inform(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3084 } |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
3085 #else |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3086 LOGDHCP(LOG_ERR, "unauthenticated Force Renew"); |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
3087 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3088 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3089 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3090 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3091 if (state->state == DHS_BOUND) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3092 LOGDHCP(LOG_DEBUG, "bound, ignoring"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3093 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3094 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3095 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3096 if (state->state == DHS_PROBE) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3097 /* Ignore any DHCP messages whilst probing a lease to bind. */ |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3098 LOGDHCP(LOG_DEBUG, "probing, ignoring"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3099 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3100 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3101 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3102 /* reset the message counter */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3103 state->interval = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3104 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3105 /* Ensure that no reject options are present */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3106 for (i = 1; i < 255; i++) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3107 if (has_option_mask(ifo->rejectmask, i) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3108 get_option_uint8(ifp->ctx, &tmp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3109 bootp, bootp_len, (uint8_t)i) == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3110 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3111 LOGDHCP(LOG_WARNING, "reject DHCP"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3112 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3113 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3114 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3115 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3116 if (type == DHCP_NAK) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3117 /* For NAK, only check if we require the ServerID */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3118 if (has_option_mask(ifo->requiremask, DHO_SERVERID) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3119 get_option_addr(ifp->ctx, &addr, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3120 bootp, bootp_len, DHO_SERVERID) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3121 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3122 LOGDHCP(LOG_WARNING, "reject NAK"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3123 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3124 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3125 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3126 /* We should restart on a NAK */ |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3127 LOGDHCP(LOG_WARNING, "NAK:"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3128 if ((msg = get_option_string(ifp->ctx, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3129 bootp, bootp_len, DHO_MESSAGE))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3130 { |
| 4010 | 3131 logwarnx("%s: message: %s", ifp->name, msg); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3132 free(msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3133 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3134 if (state->state == DHS_INFORM) /* INFORM should not be NAKed */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3135 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3136 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
|
3137 dhcp_drop(ifp, "NAK"); |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
3138 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
|
3139 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3140 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3141 /* If we constantly get NAKS then we should slowly back off */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3142 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
|
3143 state->nakoff, dhcp_discover, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3144 if (state->nakoff == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3145 state->nakoff = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3146 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3147 state->nakoff *= 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3148 if (state->nakoff > NAKOFF_MAX) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3149 state->nakoff = NAKOFF_MAX; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3150 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3151 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3152 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3153 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3154 /* Ensure that all required options are present */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3155 for (i = 1; i < 255; i++) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3156 if (has_option_mask(ifo->requiremask, i) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3157 get_option_uint8(ifp->ctx, &tmp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3158 bootp, bootp_len, (uint8_t)i) != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3159 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3160 /* If we are BOOTP, then ignore the need for serverid. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3161 * To ignore BOOTP, require dhcp_message_type. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3162 * However, nothing really stops BOOTP from providing |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3163 * DHCP style options as well so the above isn't |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3164 * always true. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3165 if (type == 0 && i == DHO_SERVERID) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3166 continue; |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3167 LOGDHCP(LOG_WARNING, "reject DHCP"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3168 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3169 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3170 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3171 |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3172 if (has_option_mask(ifo->requestmask, DHO_IPV6_PREFERRED_ONLY)) { |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3173 if (get_option_uint32(ifp->ctx, &v6only_time, bootp, bootp_len, |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3174 DHO_IPV6_PREFERRED_ONLY) == 0 && |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3175 (state->state == DHS_DISCOVER || state->state == DHS_REBOOT)) |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3176 { |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3177 char v6msg[128]; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3178 |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3179 use_v6only = true; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3180 if (v6only_time < MIN_V6ONLY_WAIT) |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3181 v6only_time = MIN_V6ONLY_WAIT; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3182 snprintf(v6msg, sizeof(v6msg), |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3183 "IPv6-Only Preferred received (%u seconds)", |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3184 v6only_time); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3185 LOGDHCP(LOG_INFO, v6msg); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3186 } |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3187 } |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3188 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3189 /* DHCP Auto-Configure, RFC 2563 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3190 if (type == DHCP_OFFER && bootp->yiaddr == 0) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3191 LOGDHCP(LOG_WARNING, "no address given"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3192 if ((msg = get_option_string(ifp->ctx, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3193 bootp, bootp_len, DHO_MESSAGE))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3194 { |
| 4010 | 3195 logwarnx("%s: message: %s", ifp->name, msg); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3196 free(msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3197 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3198 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3199 if (state->state == DHS_DISCOVER && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3200 get_option_uint8(ifp->ctx, &tmp, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3201 DHO_AUTOCONFIGURE) == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3202 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3203 switch (tmp) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3204 case 0: |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3205 LOGDHCP(LOG_WARNING, "IPv4LL disabled from"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3206 ipv4ll_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3207 #ifdef ARP |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3208 arp_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3209 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3210 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3211 case 1: |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3212 LOGDHCP(LOG_WARNING, "IPv4LL enabled from"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3213 ipv4ll_start(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3214 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3215 default: |
| 4010 | 3216 logerrx("%s: unknown auto configuration " |
| 3217 "option %d", | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3218 ifp->name, tmp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3219 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3220 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3221 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
|
3222 eloop_timeout_add_sec(ifp->ctx->eloop, |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3223 use_v6only ? v6only_time : DHCP_MAX, |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3224 dhcp_discover, ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3225 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3226 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3227 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3228 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3229 |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3230 if (use_v6only) { |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3231 dhcp_drop(ifp, "EXPIRE"); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3232 dhcp_unlink(ifp->ctx, state->leasefile); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3233 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3234 eloop_timeout_add_sec(ifp->ctx->eloop, v6only_time, |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3235 dhcp_discover, ifp); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3236 return; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3237 } |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3238 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3239 /* Ensure that the address offered is valid */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3240 if ((type == 0 || type == DHCP_OFFER || type == DHCP_ACK) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3241 (bootp->ciaddr == INADDR_ANY || bootp->ciaddr == INADDR_BROADCAST) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3242 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3243 (bootp->yiaddr == INADDR_ANY || bootp->yiaddr == INADDR_BROADCAST)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3244 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3245 LOGDHCP(LOG_WARNING, "reject invalid address"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3246 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3247 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3248 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3249 #ifdef IN_IFF_DUPLICATED |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3250 ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3251 if (ia && ia->addr_flags & IN_IFF_DUPLICATED) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3252 LOGDHCP(LOG_WARNING, "declined duplicate address"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3253 if (type) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3254 dhcp_decline(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3255 ipv4_deladdr(ia, 0); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3256 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
|
3257 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
|
3258 DHCP_RAND_MAX, dhcp_discover, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3259 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3260 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3261 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3262 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3263 bootp_copied = false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3264 if ((type == 0 || type == DHCP_OFFER) && state->state == DHS_DISCOVER) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3265 lease->frominfo = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3266 lease->addr.s_addr = bootp->yiaddr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3267 memcpy(&lease->cookie, bootp->vend, sizeof(lease->cookie)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3268 if (type == 0 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3269 get_option_addr(ifp->ctx, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3270 &lease->server, bootp, bootp_len, DHO_SERVERID) != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3271 lease->server.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3272 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3273 /* Test for rapid commit in the OFFER */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3274 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
|
3275 has_option_mask(ifo->requestmask, DHO_RAPIDCOMMIT) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3276 get_option(ifp->ctx, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3277 DHO_RAPIDCOMMIT, NULL)) |
|
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 state->state = DHS_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3280 goto rapidcommit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3281 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3282 |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3283 LOGDHCP(LOG_INFO, "offered"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3284 if (state->offer_len < bootp_len) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3285 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3286 if ((state->offer = malloc(bootp_len)) == NULL) { |
| 4010 | 3287 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
|
3288 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3289 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3290 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3291 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3292 state->offer_len = bootp_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3293 memcpy(state->offer, bootp, bootp_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3294 bootp_copied = true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3295 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
|
3296 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
|
3297 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
|
3298 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
|
3299 state->new = state->offer; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3300 state->new_len = state->offer_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3301 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3302 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3303 state->reason = "TEST"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3304 script_runreason(ifp, state->reason); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3305 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3306 state->bpf->bpf_flags |= BPF_EOF; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3307 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3308 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3309 eloop_timeout_delete(ifp->ctx->eloop, send_discover, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3310 /* We don't request BOOTP addresses */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3311 if (type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3312 /* We used to ARP check here, but that seems to be in |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3313 * violation of RFC2131 where it only describes |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3314 * DECLINE after REQUEST. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3315 * It also seems that some MS DHCP servers actually |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3316 * ignore DECLINE if no REQUEST, ie we decline a |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3317 * DISCOVER. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3318 dhcp_request(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3319 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3320 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3321 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3322 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3323 if (type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3324 if (type == DHCP_OFFER) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3325 LOGDHCP(LOG_WARNING, "ignoring offer of"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3326 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3327 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3328 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3329 /* We should only be dealing with acks */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3330 if (type != DHCP_ACK) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3331 LOGDHCP(LOG_ERR, "not ACK or OFFER"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3332 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3333 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3334 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3335 if (state->state == DHS_DISCOVER) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3336 /* We only allow ACK of rapid commit DISCOVER. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3337 if (has_option_mask(ifo->requestmask, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3338 DHO_RAPIDCOMMIT) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3339 get_option(ifp->ctx, bootp, bootp_len, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3340 DHO_RAPIDCOMMIT, NULL)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3341 state->state = DHS_REQUEST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3342 else { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3343 LOGDHCP(LOG_DEBUG, "ignoring ack of"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3344 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3345 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3346 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3347 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3348 rapidcommit: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3349 if (!(ifo->options & DHCPCD_INFORM)) |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3350 LOGDHCP(LOG_DEBUG, "acknowledged"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3351 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3352 ifo->options &= ~DHCPCD_STATIC; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3353 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3354 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3355 /* No NAK, so reset the backoff |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3356 * We don't reset on an OFFER message because the server could |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3357 * potentially NAK the REQUEST. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3358 state->nakoff = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3359 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3360 /* BOOTP could have already assigned this above. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3361 if (!bootp_copied) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3362 if (state->offer_len < bootp_len) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3363 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3364 if ((state->offer = malloc(bootp_len)) == NULL) { |
| 4010 | 3365 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
|
3366 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3367 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3368 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3369 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3370 state->offer_len = bootp_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3371 memcpy(state->offer, bootp, bootp_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3372 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3373 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3374 lease->frominfo = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3375 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
|
3376 |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
3377 #if defined(ARP) || defined(KERNEL_RFC5227) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3378 dhcp_arp_bind(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3379 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3380 dhcp_bind(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3381 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3382 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3383 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3384 static void * |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3385 get_udp_data(void *packet, 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
|
3386 { |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3387 const struct ip *ip = packet; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3388 size_t ip_hl = (size_t)ip->ip_hl * 4; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3389 char *p = packet; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3390 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3391 p += ip_hl + sizeof(struct udphdr); |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3392 *len = (size_t)ntohs(ip->ip_len) - sizeof(struct udphdr) - ip_hl; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3393 return p; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3394 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3395 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3396 static bool |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3397 is_packet_udp_bootp(void *packet, size_t plen) |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3398 { |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3399 struct ip *ip = packet; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3400 size_t ip_hlen; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3401 struct udphdr udp; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3402 |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3403 if (plen < sizeof(*ip)) |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3404 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3405 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3406 if (ip->ip_v != IPVERSION || ip->ip_p != IPPROTO_UDP) |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3407 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3408 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3409 /* Sanity. */ |
|
4762
d68ac6b143c5
dhcp: Allow for trailing FCS in the packet.
Roy Marples <roy@marples.name>
parents:
4761
diff
changeset
|
3410 if (ntohs(ip->ip_len) > plen) |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3411 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3412 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3413 ip_hlen = (size_t)ip->ip_hl * 4; |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3414 if (ip_hlen < sizeof(*ip)) |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3415 return false; |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3416 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3417 /* Check we have a UDP header and BOOTP. */ |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3418 if (ip_hlen + sizeof(udp) + offsetof(struct bootp, vend) > plen) |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3419 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3420 |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3421 /* Sanity. */ |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3422 memcpy(&udp, (char *)ip + ip_hlen, sizeof(udp)); |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3423 if (ntohs(udp.uh_ulen) < sizeof(udp)) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3424 return false; |
|
5072
b1ab228ac3b3
Revert "dhcp: Cast away a compile warning"
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
3425 if (ip_hlen + ntohs(udp.uh_ulen) > plen) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3426 return false; |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3427 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3428 /* Check it's to and from the right ports. */ |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3429 if (udp.uh_dport != htons(BOOTPC) || udp.uh_sport != htons(BOOTPS)) |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3430 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3431 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3432 return true; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3433 } |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3434 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3435 /* Lengths have already been checked. */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3436 static bool |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3437 checksums_valid(void *packet, |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3438 struct in_addr *from, 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
|
3439 { |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3440 struct ip *ip = packet; |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3441 union pip { |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3442 struct ip ip; |
|
4775
9a29b37bc5cb
DHCP: Fix prior to not waste space
Sergei Trofimovich <slyfox@gentoo.org>
parents:
4773
diff
changeset
|
3443 uint16_t w[sizeof(struct ip) / 2]; |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3444 } pip = { |
| 5272 | 3445 .ip = { |
| 3446 .ip_p = IPPROTO_UDP, | |
| 3447 .ip_src = ip->ip_src, | |
| 3448 .ip_dst = ip->ip_dst, | |
| 3449 } | |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3450 }; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3451 size_t ip_hlen; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3452 struct udphdr udp; |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3453 char *udpp, *uh_sump; |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3454 uint32_t csum; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3455 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3456 if (from != NULL) |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3457 from->s_addr = ip->ip_src.s_addr; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3458 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3459 ip_hlen = (size_t)ip->ip_hl * 4; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3460 if (in_cksum(ip, ip_hlen, NULL) != 0) |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3461 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3462 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3463 if (flags & BPF_PARTIALCSUM) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3464 return true; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3465 |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3466 udpp = (char *)ip + ip_hlen; |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3467 memcpy(&udp, udpp, sizeof(udp)); |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3468 if (udp.uh_sum == 0) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3469 return true; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3470 |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3471 /* UDP checksum is based on a pseudo IP header alongside |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3472 * the UDP header and payload. */ |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3473 pip.ip.ip_len = udp.uh_ulen; |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3474 csum = 0; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3475 |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3476 /* Need to zero the UDP sum in the packet for the checksum to work. */ |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3477 uh_sump = udpp + offsetof(struct udphdr, uh_sum); |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3478 memset(uh_sump, 0, sizeof(udp.uh_sum)); |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3479 |
| 4773 | 3480 /* Checksum pseudo header and then UDP + payload. */ |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3481 in_cksum(pip.w, sizeof(pip.w), &csum); |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3482 csum = in_cksum(udpp, ntohs(udp.uh_ulen), &csum); |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3483 |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3484 #if 0 /* Not needed, just here for completeness. */ |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3485 /* Put the checksum back. */ |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3486 memcpy(uh_sump, &udp.uh_sum, sizeof(udp.uh_sum)); |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3487 #endif |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3488 |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3489 return csum == udp.uh_sum; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3490 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3491 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3492 static void |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3493 dhcp_handlebootp(struct interface *ifp, struct bootp *bootp, size_t len, |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3494 struct in_addr *from) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3495 { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3496 size_t v; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3497 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3498 if (len < offsetof(struct bootp, vend)) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3499 logerrx("%s: truncated packet (%zu) from %s", |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3500 ifp->name, len, inet_ntoa(*from)); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3501 return; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3502 } |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3503 |
|
5079
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3504 /* Unlikely, but appeases sanitizers. */ |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3505 if (len > FRAMELEN_MAX) { |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3506 logerrx("%s: packet exceeded frame length (%zu) from %s", |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3507 ifp->name, len, inet_ntoa(*from)); |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3508 return; |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3509 } |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3510 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3511 /* To make our IS_DHCP macro easy, ensure the vendor |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3512 * area has at least 4 octets. */ |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3513 v = len - offsetof(struct bootp, vend); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3514 while (v < 4) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3515 bootp->vend[v++] = '\0'; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3516 len++; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3517 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3518 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3519 dhcp_handledhcp(ifp, bootp, len, from); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3520 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3521 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3522 void |
| 5234 | 3523 dhcp_packet(struct interface *ifp, uint8_t *data, size_t len, |
| 3524 unsigned int bpf_flags) | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3525 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3526 struct bootp *bootp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3527 struct in_addr from; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3528 size_t udp_len; |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3529 size_t fl = bpf_frame_header_len(ifp); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3530 #ifdef PRIVSEP |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3531 const struct dhcp_state *state = D_CSTATE(ifp); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3532 |
|
5489
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3533 /* It's possible that an interface departs and arrives in short |
|
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3534 * order to receive a BPF frame out of order. |
|
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3535 * There is a similar check in ARP, but much lower down the stack. |
|
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3536 * It's not needed for other inet protocols because we send the |
|
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3537 * message as a whole and select the interface off that and then |
|
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3538 * check state. BPF on the other hand is very interface |
|
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3539 * specific and we do need this check. */ |
|
5487
23f35ea1a34a
privsep: fix crash when interface departs before bpf returns for it
Roy Marples <roy@marples.name>
parents:
5449
diff
changeset
|
3540 if (state == NULL) |
|
23f35ea1a34a
privsep: fix crash when interface departs before bpf returns for it
Roy Marples <roy@marples.name>
parents:
5449
diff
changeset
|
3541 return; |
|
23f35ea1a34a
privsep: fix crash when interface departs before bpf returns for it
Roy Marples <roy@marples.name>
parents:
5449
diff
changeset
|
3542 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3543 /* Ignore double reads */ |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
3544 if (IN_PRIVSEP(ifp->ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3545 switch (state->state) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3546 case DHS_BOUND: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3547 case DHS_RENEW: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3548 return; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3549 default: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3550 break; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3551 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3552 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3553 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3554 |
|
5033
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3555 /* Trim frame header */ |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3556 if (fl != 0) { |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3557 if (len < fl) { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3558 logerrx("%s: %s: short frame header %zu", |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3559 __func__, ifp->name, len); |
|
5033
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3560 return; |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3561 } |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3562 len -= fl; |
|
5158
5f18174b5eb2
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5120
diff
changeset
|
3563 /* Move the data to avoid alignment errors. */ |
|
5f18174b5eb2
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5120
diff
changeset
|
3564 memmove(data, data + fl, len); |
|
5033
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3565 } |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3566 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3567 /* Validate filter. */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3568 if (!is_packet_udp_bootp(data, len)) { |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3569 #ifdef BPF_DEBUG |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3570 logerrx("%s: DHCP BPF validation failure", ifp->name); |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3571 #endif |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3572 return; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3573 } |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3574 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3575 if (!checksums_valid(data, &from, bpf_flags)) { |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3576 logerrx("%s: checksum failure from %s", |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3577 ifp->name, inet_ntoa(from)); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3578 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3579 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3580 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3581 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3582 * DHCP has a variable option area rather than a fixed vendor area. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3583 * Because DHCP uses the BOOTP protocol it should still send BOOTP |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3584 * sized packets to be RFC compliant. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3585 * However some servers send a truncated vendor area. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3586 * dhcpcd can work fine without the vendor area being sent. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3587 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3588 bootp = get_udp_data(data, &udp_len); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3589 dhcp_handlebootp(ifp, bootp, udp_len, &from); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3590 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3591 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3592 static void |
|
4717
3cce06e28d99
DHCP: Rename dhcp_readpacket to dhcp_readbpf
Roy Marples <roy@marples.name>
parents:
4715
diff
changeset
|
3593 dhcp_readbpf(void *arg) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3594 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3595 struct interface *ifp = arg; |
| 5028 | 3596 uint8_t buf[FRAMELEN_MAX]; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3597 ssize_t bytes; |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3598 struct dhcp_state *state = D_STATE(ifp); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3599 struct bpf *bpf = state->bpf; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3600 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3601 bpf->bpf_flags &= ~BPF_EOF; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3602 while (!(bpf->bpf_flags & BPF_EOF)) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3603 bytes = bpf_read(bpf, buf, sizeof(buf)); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3604 if (bytes == -1) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3605 if (state->state != DHS_NONE) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3606 logerr("%s: %s", __func__, ifp->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3607 dhcp_close(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3608 } |
|
4171
4ff80b2bbba1
Fix prior patches by using correct bitmasks for flags.
Roy Marples <roy@marples.name>
parents:
4169
diff
changeset
|
3609 break; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3610 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3611 dhcp_packet(ifp, buf, (size_t)bytes, bpf->bpf_flags); |
|
3970
c31023f676be
Fix a potential crash where the DHCP state could be freed during processing.
Roy Marples <roy@marples.name>
parents:
3960
diff
changeset
|
3612 /* Check we still have a state after processing. */ |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3613 if ((state = D_STATE(ifp)) == NULL) |
|
3970
c31023f676be
Fix a potential crash where the DHCP state could be freed during processing.
Roy Marples <roy@marples.name>
parents:
3960
diff
changeset
|
3614 break; |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3615 if ((bpf = state->bpf) == NULL) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3616 break; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3617 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3618 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3619 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3620 void |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3621 dhcp_recvmsg(struct dhcpcd_ctx *ctx, struct msghdr *msg) |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3622 { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3623 struct sockaddr_in *from = (struct sockaddr_in *)msg->msg_name; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3624 struct iovec *iov = &msg->msg_iov[0]; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3625 struct interface *ifp; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3626 const struct dhcp_state *state; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3627 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3628 ifp = if_findifpfromcmsg(ctx, msg, NULL); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3629 if (ifp == NULL) { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3630 logerr(__func__); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3631 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3632 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3633 state = D_CSTATE(ifp); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3634 if (state == NULL) { |
|
5009
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
3635 /* Try re-directing it to another interface. */ |
|
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
3636 dhcp_redirect_dhcp(ifp, (struct bootp *)iov->iov_base, |
|
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
3637 iov->iov_len, &from->sin_addr); |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3638 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3639 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3640 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3641 if (state->bpf != NULL) { |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3642 /* Avoid a duplicate read if BPF is open for the interface. */ |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3643 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3644 } |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3645 #ifdef PRIVSEP |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
3646 if (IN_PRIVSEP(ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3647 switch (state->state) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3648 case DHS_BOUND: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3649 case DHS_RENEW: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3650 break; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3651 default: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3652 /* Any other state we ignore it or will receive |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3653 * via BPF. */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3654 return; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3655 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3656 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3657 #endif |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3658 |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3659 dhcp_handlebootp(ifp, iov->iov_base, iov->iov_len, |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3660 &from->sin_addr); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3661 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3662 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3663 static void |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3664 dhcp_readudp(struct dhcpcd_ctx *ctx, struct interface *ifp) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3665 { |
| 4602 | 3666 const struct dhcp_state *state; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3667 struct sockaddr_in from; |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3668 union { |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3669 struct bootp bootp; |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3670 uint8_t buf[10 * 1024]; /* Maximum MTU */ |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3671 } iovbuf; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3672 struct iovec iov = { |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3673 .iov_base = iovbuf.buf, |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3674 .iov_len = sizeof(iovbuf.buf), |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3675 }; |
| 5160 | 3676 union { |
| 3677 struct cmsghdr hdr; | |
| 4784 | 3678 #ifdef IP_RECVIF |
| 5160 | 3679 uint8_t buf[CMSG_SPACE(sizeof(struct sockaddr_dl))]; |
| 4784 | 3680 #else |
| 5160 | 3681 uint8_t buf[CMSG_SPACE(sizeof(struct in_pktinfo))]; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3682 #endif |
| 5160 | 3683 } cmsgbuf = { .buf = { 0 } }; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3684 struct msghdr msg = { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3685 .msg_name = &from, .msg_namelen = sizeof(from), |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3686 .msg_iov = &iov, .msg_iovlen = 1, |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3687 .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf), |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3688 }; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3689 int s; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3690 ssize_t bytes; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3691 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3692 if (ifp != NULL) { |
|
4594
81f346f0e892
DHCP: Avoid duplicate read of packet
Roy Marples <roy@marples.name>
parents:
4587
diff
changeset
|
3693 state = D_CSTATE(ifp); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3694 s = state->udp_rfd; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3695 } else |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3696 s = ctx->udp_rfd; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3697 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3698 bytes = recvmsg(s, &msg, 0); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3699 if (bytes == -1) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3700 logerr(__func__); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3701 return; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3702 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3703 |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3704 iov.iov_len = (size_t)bytes; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3705 dhcp_recvmsg(ctx, &msg); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3706 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3707 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3708 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
|
3709 dhcp_handleudp(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3710 { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3711 struct dhcpcd_ctx *ctx = arg; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3712 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3713 dhcp_readudp(ctx, NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3714 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3715 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3716 static void |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3717 dhcp_handleifudp(void *arg) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3718 { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3719 struct interface *ifp = arg; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3720 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3721 dhcp_readudp(ifp->ctx, ifp); |
|
4791
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3722 } |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3723 |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3724 static int |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3725 dhcp_openbpf(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
|
3726 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3727 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3728 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3729 state = D_STATE(ifp); |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3730 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3731 #ifdef PRIVSEP |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
3732 if (IN_PRIVSEP_SE(ifp->ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3733 if (ps_bpf_openbootp(ifp) == -1) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3734 logerr(__func__); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3735 return -1; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3736 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3737 return 0; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3738 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3739 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3740 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3741 if (state->bpf != NULL) |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3742 return 0; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3743 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3744 state->bpf = bpf_open(ifp, bpf_bootp, NULL); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3745 if (state->bpf == NULL) { |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3746 if (errno == ENOENT) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3747 logerrx("%s not found", bpf_name); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3748 /* May as well disable IPv4 entirely at |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3749 * this point as we really need it. */ |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3750 ifp->options->options &= ~DHCPCD_IPV4; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3751 } else |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3752 logerr("%s: %s", __func__, ifp->name); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3753 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
|
3754 } |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3755 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3756 eloop_event_add(ifp->ctx->eloop, |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3757 state->bpf->bpf_fd, dhcp_readbpf, ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3758 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3759 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3760 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3761 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3762 dhcp_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
|
3763 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3764 struct dhcp_state *state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3765 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
|
3766 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3767 dhcp_close(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3768 #ifdef ARP |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3769 arp_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3770 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3771 if (state) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3772 state->state = DHS_NONE; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3773 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
|
3774 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
|
3775 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3776 free(state->clientid); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3777 free(state); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3778 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3779 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3780 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
|
3781 /* If we don't have any more DHCP enabled interfaces, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3782 * 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
|
3783 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
|
3784 TAILQ_FOREACH(ifp, ctx->ifaces, next) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3785 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3786 if (state != NULL && state->state != DHS_NONE) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3787 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3788 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3789 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3790 if (ifp == NULL) { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3791 if (ctx->udp_rfd != -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3792 eloop_event_delete(ctx->eloop, ctx->udp_rfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3793 close(ctx->udp_rfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3794 ctx->udp_rfd = -1; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3795 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3796 if (ctx->udp_wfd != -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3797 close(ctx->udp_wfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3798 ctx->udp_wfd = -1; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3799 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3800 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3801 free(ctx->opt_buffer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3802 ctx->opt_buffer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3803 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3804 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3805 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3806 static int |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3807 dhcp_initstate(struct interface *ifp) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3808 { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3809 struct dhcp_state *state; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3810 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3811 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3812 if (state != NULL) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3813 return 0; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3814 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3815 ifp->if_data[IF_DATA_DHCP] = calloc(1, sizeof(*state)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3816 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3817 if (state == NULL) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3818 return -1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3819 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3820 state->state = DHS_NONE; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3821 /* 0 is a valid fd, so init to -1 */ |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3822 state->udp_rfd = -1; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3823 #ifdef ARPING |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3824 state->arping_index = -1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3825 #endif |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3826 return 1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3827 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3828 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3829 static int |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3830 dhcp_init(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
|
3831 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3832 struct dhcp_state *state; |
|
5280
a986083da0ba
Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents:
5272
diff
changeset
|
3833 struct if_options *ifo; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3834 uint8_t len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3835 char buf[(sizeof(ifo->clientid) - 1) * 3]; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
3836 |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
3837 if (dhcp_initstate(ifp) == -1) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3838 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
|
3839 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3840 state = D_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
|
3841 state->state = DHS_INIT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3842 state->reason = "PREINIT"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3843 state->nakoff = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3844 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
|
3845 AF_INET, ifp); |
|
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 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
|
3848 /* We need to drop the leasefile so that dhcp_start |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3849 * doesn't load it. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3850 if (ifo->options & DHCPCD_REQUEST) |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
3851 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
|
3852 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3853 free(state->clientid); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3854 state->clientid = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3855 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3856 if (ifo->options & DHCPCD_ANONYMOUS) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3857 uint8_t duid[DUID_LEN]; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3858 uint8_t duid_len; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3859 |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3860 duid_len = (uint8_t)duid_make(duid, ifp, DUID_LL); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3861 if (duid_len != 0) { |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3862 state->clientid = malloc((size_t)duid_len + 6); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3863 if (state->clientid == NULL) |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3864 goto eexit; |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3865 state->clientid[0] =(uint8_t)(duid_len + 5); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3866 state->clientid[1] = 255; /* RFC 4361 */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3867 memcpy(state->clientid + 2, ifo->iaid, 4); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3868 memset(state->clientid + 2, 0, 4); /* IAID */ |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3869 memcpy(state->clientid + 6, duid, duid_len); |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3870 } |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3871 } else if (*ifo->clientid) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3872 state->clientid = malloc((size_t)(ifo->clientid[0] + 1)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3873 if (state->clientid == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3874 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3875 memcpy(state->clientid, ifo->clientid, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3876 (size_t)(ifo->clientid[0]) + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3877 } else if (ifo->options & DHCPCD_CLIENTID) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3878 if (ifo->options & DHCPCD_DUID) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3879 state->clientid = malloc(ifp->ctx->duid_len + 6); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3880 if (state->clientid == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3881 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3882 state->clientid[0] =(uint8_t)(ifp->ctx->duid_len + 5); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3883 state->clientid[1] = 255; /* RFC 4361 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3884 memcpy(state->clientid + 2, ifo->iaid, 4); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3885 memcpy(state->clientid + 6, ifp->ctx->duid, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3886 ifp->ctx->duid_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3887 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3888 len = (uint8_t)(ifp->hwlen + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3889 state->clientid = malloc((size_t)len + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3890 if (state->clientid == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3891 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3892 state->clientid[0] = len; |
|
5166
a70f6ddefe3c
Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents:
5160
diff
changeset
|
3893 state->clientid[1] = (uint8_t)ifp->hwtype; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3894 memcpy(state->clientid + 2, ifp->hwaddr, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3895 ifp->hwlen); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3896 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3897 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3898 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3899 if (ifo->options & DHCPCD_DUID) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3900 /* Don't bother logging as DUID and IAID are reported |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3901 * at device start. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3902 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3903 |
|
5280
a986083da0ba
Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents:
5272
diff
changeset
|
3904 if (ifo->options & DHCPCD_CLIENTID && state->clientid != NULL) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3905 logdebugx("%s: using ClientID %s", ifp->name, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3906 hwaddr_ntoa(state->clientid + 1, state->clientid[0], |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3907 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
|
3908 else if (ifp->hwlen) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3909 logdebugx("%s: using hwaddr %s", ifp->name, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3910 hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, 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
|
3911 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3912 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3913 eexit: |
| 4010 | 3914 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
|
3915 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3916 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3917 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3918 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3919 dhcp_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
|
3920 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3921 struct interface *ifp = arg; |
|
4681
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
3922 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
|
3923 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
|
3924 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3925 uint32_t l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3926 int nolease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3927 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3928 if (!(ifo->options & DHCPCD_IPV4)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3929 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3930 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3931 /* Listen on *.*.*.*:bootpc so that the kernel never sends an |
|
4681
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
3932 * ICMP port unreachable message back to the DHCP server. |
|
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
3933 * Only do this in master mode so we don't swallow messages |
|
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
3934 * for dhcpcd running on another interface. */ |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3935 if ((ctx->options & (DHCPCD_MASTER|DHCPCD_PRIVSEP)) == DHCPCD_MASTER |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3936 && ctx->udp_rfd == -1) |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3937 { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3938 ctx->udp_rfd = dhcp_openudp(NULL); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3939 if (ctx->udp_rfd == -1) { |
|
4833
aadc0d25a706
DHCP: Require unspecificed BOOTP port for master mode
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
3940 logerr(__func__); |
|
aadc0d25a706
DHCP: Require unspecificed BOOTP port for master mode
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
3941 return; |
|
4791
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3942 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3943 eloop_event_add(ctx->eloop, ctx->udp_rfd, dhcp_handleudp, ctx); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3944 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3945 if (!IN_PRIVSEP(ctx) && ctx->udp_wfd == -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3946 ctx->udp_wfd = xsocket(PF_INET, SOCK_RAW|SOCK_CXNB,IPPROTO_UDP); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3947 if (ctx->udp_wfd == -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3948 logerr(__func__); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3949 return; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3950 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3951 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3952 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3953 if (dhcp_init(ifp) == -1) { |
| 4010 | 3954 logerr("%s: dhcp_init", 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
|
3955 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3956 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3957 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3958 state = D_STATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3959 clock_gettime(CLOCK_MONOTONIC, &state->started); |
|
4224
595761ecbde0
dhcp: reset interval during init
Roy Marples <roy@marples.name>
parents:
4207
diff
changeset
|
3960 state->interval = 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3961 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3962 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3963 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3964 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3965 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3966 if (ifo->arping_len && state->arping_index < ifo->arping_len) { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3967 dhcp_arping(ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3968 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3969 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3970 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3971 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3972 if (ifo->options & DHCPCD_STATIC) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3973 dhcp_static(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3974 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3975 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3976 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3977 if (ifo->options & DHCPCD_INFORM) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3978 dhcp_inform(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3979 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3980 } |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3981 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3982 /* We don't want to read the old lease if we NAK an old test */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3983 nolease = state->offer && 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
|
3984 if (!nolease && ifo->options & DHCPCD_DHCP) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3985 state->offer_len = read_lease(ifp, &state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3986 /* Check the saved lease matches the type we want */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3987 if (state->offer) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3988 #ifdef IN_IFF_DUPLICATED |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3989 struct in_addr addr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3990 struct ipv4_addr *ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3991 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3992 addr.s_addr = state->offer->yiaddr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3993 ia = ipv4_iffindaddr(ifp, &addr, NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3994 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3995 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3996 if ((!IS_DHCP(state->offer) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3997 !(ifo->options & DHCPCD_BOOTP)) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3998 #ifdef IN_IFF_DUPLICATED |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3999 (ia && ia->addr_flags & IN_IFF_DUPLICATED) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4000 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4001 (IS_DHCP(state->offer) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4002 ifo->options & DHCPCD_BOOTP)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4003 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4004 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4005 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4006 state->offer_len = 0; |
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4010 if (state->offer) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4011 struct ipv4_addr *ia; |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4012 time_t mtime; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4013 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4014 get_lease(ifp, &state->lease, state->offer, state->offer_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4015 state->lease.frominfo = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4016 if (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
|
4017 (ia = ipv4_iffindaddr(ifp, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4018 &state->lease.addr, &state->lease.mask)) != NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4019 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4020 /* We still have the IP address from the last lease. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4021 * Fake add the address and routes from it so the lease |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4022 * can be cleaned up. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4023 state->new = malloc(state->offer_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4024 if (state->new) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4025 memcpy(state->new, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4026 state->offer, state->offer_len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4027 state->new_len = state->offer_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4028 state->addr = ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4029 state->added |= STATE_ADDED | STATE_FAKE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4030 rt_build(ifp->ctx, AF_INET); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4031 } else |
| 4010 | 4032 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
|
4033 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4034 if (!IS_DHCP(state->offer)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4035 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4036 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4037 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4038 } else if (!(ifo->options & DHCPCD_LASTLEASE_EXTEND) && |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
4039 state->lease.leasetime != DHCP_INFINITE_LIFETIME && |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4040 dhcp_filemtime(ifp->ctx, state->leasefile, &mtime) == 0) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4041 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4042 time_t now; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4043 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4044 /* Offset lease times and check expiry */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4045 now = time(NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4046 if (now == -1 || |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4047 (time_t)state->lease.leasetime < 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
|
4048 { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
4049 logdebugx("%s: discarding expired lease", |
| 4010 | 4050 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
|
4051 free(state->offer); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4052 state->offer = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4053 state->offer_len = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4054 state->lease.addr.s_addr = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4055 /* Technically we should discard the lease |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4056 * as it's expired, just as DHCPv6 addresses |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4057 * would be by the kernel. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4058 * However, this may violate POLA so |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4059 * we currently leave it be. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4060 * If we get a totally different lease from |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4061 * the DHCP server we'll drop it anyway, as |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4062 * we will on any other event which would |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4063 * trigger a lease drop. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4064 * This should only happen if dhcpcd stops |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4065 * running and the lease expires before |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4066 * dhcpcd starts again. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4067 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4068 if (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 dhcp_drop(ifp, "EXPIRE"); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4070 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4071 } else { |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4072 l = (uint32_t)(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
|
4073 state->lease.leasetime -= l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4074 state->lease.renewaltime -= l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4075 state->lease.rebindtime -= l; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4076 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4077 } |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4080 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4081 if (!(ifo->options & DHCPCD_DHCP)) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4082 if (ifo->options & DHCPCD_IPV4LL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4083 ipv4ll_start(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4084 return; |
|
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 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4087 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
4088 if (state->offer == NULL || |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
4089 !IS_DHCP(state->offer) || |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
4090 ifo->options & DHCPCD_ANONYMOUS) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4091 dhcp_discover(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4092 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4093 dhcp_reboot(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4094 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4095 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4096 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4097 dhcp_start(struct interface *ifp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4098 { |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4099 unsigned int delay; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4100 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4101 const struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4102 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4103 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4104 if (!(ifp->options->options & DHCPCD_IPV4)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4105 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4106 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4107 /* If we haven't been given a netmask for our requested address, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4108 * set it now. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4109 if (ifp->options->req_addr.s_addr != INADDR_ANY && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4110 ifp->options->req_mask.s_addr == INADDR_ANY) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4111 ifp->options->req_mask.s_addr = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4112 ipv4_getnetmask(ifp->options->req_addr.s_addr); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4113 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4114 /* If we haven't specified a ClientID and our hardware address |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4115 * length is greater than BOOTP CHADDR then we enforce a ClientID |
|
5166
a70f6ddefe3c
Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents:
5160
diff
changeset
|
4116 * of the hardware address type and the hardware address. |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4117 * If there is no hardware address and no ClientID set, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4118 * force a DUID based ClientID. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4119 if (ifp->hwlen > 16) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4120 ifp->options->options |= DHCPCD_CLIENTID; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4121 else if (ifp->hwlen == 0 && !(ifp->options->options & DHCPCD_CLIENTID)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4122 ifp->options->options |= DHCPCD_CLIENTID | DHCPCD_DUID; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4123 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4124 /* Firewire and InfiniBand interfaces require ClientID and |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4125 * the broadcast option being set. */ |
|
5166
a70f6ddefe3c
Rename ifp->family -> ifp->hwtype so it's less confusing
Roy Marples <roy@marples.name>
parents:
5160
diff
changeset
|
4126 switch (ifp->hwtype) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4127 case ARPHRD_IEEE1394: /* FALLTHROUGH */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4128 case ARPHRD_INFINIBAND: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4129 ifp->options->options |= DHCPCD_CLIENTID | DHCPCD_BROADCAST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4130 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4131 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4132 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4133 /* If we violate RFC2131 section 3.7 then require ARP |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4134 * to detect if any other client wants our address. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4135 if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4136 ifp->options->options |= DHCPCD_ARP; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4137 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4138 /* No point in delaying a static configuration */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4139 if (ifp->options->options & DHCPCD_STATIC || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4140 !(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
|
4141 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4142 dhcp_start1(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4143 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4144 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4145 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4146 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4147 /* If we have arpinged then we have already delayed. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4148 state = D_CSTATE(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4149 if (state != NULL && state->arping_index != -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4150 dhcp_start1(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4151 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4152 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4153 #endif |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4154 delay = MSEC_PER_SEC + |
|
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4155 (arc4random_uniform(MSEC_PER_SEC * 2) - MSEC_PER_SEC); |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
4156 logdebugx("%s: delaying IPv4 for %0.1f seconds", |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4157 ifp->name, (float)delay / MSEC_PER_SEC); |
|
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4158 |
|
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4159 eloop_timeout_add_msec(ifp->ctx->eloop, delay, dhcp_start1, ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4160 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4161 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4162 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4163 dhcp_abort(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
|
4164 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4165 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4166 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4167 state = D_STATE(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
4168 #ifdef ARPING |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4169 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
|
4170 state->arping_index = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4171 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4172 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4173 eloop_timeout_delete(ifp->ctx->eloop, dhcp_start1, ifp); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4174 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4175 if (state != NULL && state->added) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4176 rt_build(ifp->ctx, AF_INET); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4177 #ifdef ARP |
|
5241
989bcc6c8e70
ARP: A few minor fixes for prior
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
4178 if (ifp->options->options & DHCPCD_ARP) |
|
989bcc6c8e70
ARP: A few minor fixes for prior
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
4179 arp_announceaddr(ifp->ctx, &state->addr->addr); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4180 #endif |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4181 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4182 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4183 |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4184 struct ipv4_addr * |
|
4232
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4224
diff
changeset
|
4185 dhcp_handleifa(int cmd, struct ipv4_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
|
4186 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4187 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
|
4188 struct dhcp_state *state; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4189 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 uint8_t i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4191 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4192 ifp = ia->iface; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4193 state = D_STATE(ifp); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4194 if (state == NULL || state->state == DHS_NONE) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4195 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4196 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4197 if (cmd == RTM_DELADDR) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4198 if (state->addr == ia) { |
|
4232
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4224
diff
changeset
|
4199 loginfox("%s: pid %d deleted IP address %s", |
|
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4224
diff
changeset
|
4200 ifp->name, pid, ia->saddr); |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
4201 dhcp_close(ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4202 state->addr = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4203 /* Don't clear the added state as we need |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4204 * to drop the lease. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4205 dhcp_drop(ifp, "EXPIRE"); |
|
4242
9f4dc610f30c
Really start dhcp on deletion of address.
Roy Marples <roy@marples.name>
parents:
4240
diff
changeset
|
4206 dhcp_start1(ifp); |
|
4782
8a9ec0631165
INET: Fix a potential memory leak
Roy Marples <roy@marples.name>
parents:
4775
diff
changeset
|
4207 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4208 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4209 } |
|
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 if (cmd != RTM_NEWADDR) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4212 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4213 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4214 #ifdef IN_IFF_NOTUSEABLE |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
4215 if (!(ia->addr_flags & IN_IFF_NOTUSEABLE)) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
4216 dhcp_finish_dad(ifp, &ia->addr); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
4217 else if (ia->addr_flags & IN_IFF_DUPLICATED) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4218 return dhcp_addr_duplicated(ifp, &ia->addr) ? NULL : ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4219 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4220 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4221 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
|
4222 if (ifo->options & DHCPCD_INFORM) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4223 if (state->state != DHS_INFORM) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4224 dhcp_inform(ifp); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4225 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4226 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4227 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4228 if (!(ifo->options & DHCPCD_STATIC)) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4229 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4230 if (ifo->req_addr.s_addr != INADDR_ANY) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4231 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4232 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4233 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
|
4234 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
|
4235 state->new_len = dhcp_message_new(&state->new, &ia->addr, &ia->mask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4236 if (state->new == NULL) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4237 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4238 if (ifp->flags & IFF_POINTOPOINT) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4239 for (i = 1; i < 255; i++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4240 if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4241 dhcp_message_add_addr(state->new, i, ia->brd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4242 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4243 state->reason = "STATIC"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4244 rt_build(ifp->ctx, AF_INET); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4245 script_runreason(ifp, state->reason); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4246 if (ifo->options & DHCPCD_INFORM) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4247 state->state = DHS_INFORM; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4248 dhcp_new_xid(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4249 state->lease.server.s_addr = INADDR_ANY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4250 state->addr = ia; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4251 dhcp_inform(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4252 } |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4253 |
|
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4254 return ia; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4255 } |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4256 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4257 #ifndef SMALL |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4258 int |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4259 dhcp_dump(struct interface *ifp) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4260 { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4261 struct dhcp_state *state; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4262 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4263 ifp->if_data[IF_DATA_DHCP] = state = calloc(1, sizeof(*state)); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4264 if (state == NULL) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4265 logerr(__func__); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4266 return -1; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4267 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4268 state->new_len = read_lease(ifp, &state->new); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4269 if (state->new == NULL) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4270 logerr("read_lease"); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4271 return -1; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4272 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4273 state->reason = "DUMP"; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4274 return script_runreason(ifp, state->reason); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4275 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4276 #endif |
