Mercurial > hg > dhcpcd
annotate src/dhcp.c @ 5573:5bf8e1fc0634 draft
DHCP: For anonymous, just use a generic clientid
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Sun, 27 Dec 2020 23:52:44 +0000 |
| parents | 6d72dc67a984 |
| children |
| 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 |
| 5535 | 2349 if (!(ifo->options & DHCPCD_CONFIGURE)) { |
| 2350 struct ipv4_addr *ia; | |
| 2351 | |
| 2352 script_runreason(ifp, state->reason); | |
| 2353 dhcpcd_daemonise(ifp->ctx); | |
| 2354 | |
| 2355 /* We we are not configuring the address, we need to keep | |
| 2356 * the BPF socket open if the address does not exist. */ | |
| 2357 ia = ipv4_iffindaddr(ifp, &state->lease.addr, NULL); | |
| 2358 if (ia != NULL) { | |
| 2359 state->addr = ia; | |
| 2360 state->added = STATE_ADDED; | |
| 2361 dhcp_closebpf(ifp); | |
| 2362 goto openudp; | |
| 2363 } | |
| 2364 return; | |
| 2365 } | |
| 2366 | |
|
5548
bcca2ff28a64
DHCP: Only listen to the address if we successfully added it
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
2367 /* Add the address */ |
|
5549
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2368 if (ipv4_applyaddr(ifp) == NULL) { |
|
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2369 /* There was an error adding the address. |
|
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2370 * If we are in oneshot, exit with a failure. */ |
|
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2371 if (ctx->options & DHCPCD_ONESHOT) { |
|
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2372 loginfox("exiting due to oneshot"); |
|
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2373 eloop_exit(ctx->eloop, EXIT_FAILURE); |
|
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2374 } |
|
5548
bcca2ff28a64
DHCP: Only listen to the address if we successfully added it
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
2375 return; |
|
5549
6d72dc67a984
DHCP: If error adding the address in oneshot, exit with failure
Roy Marples <roy@marples.name>
parents:
5548
diff
changeset
|
2376 } |
|
5548
bcca2ff28a64
DHCP: Only listen to the address if we successfully added it
Roy Marples <roy@marples.name>
parents:
5535
diff
changeset
|
2377 |
|
4681
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
2378 /* 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
|
2379 * 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
|
2380 dhcp_closebpf(ifp); |
|
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2381 |
| 5535 | 2382 openudp: |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2383 /* 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
|
2384 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
|
2385 (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
|
2386 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
|
2387 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
|
2388 return; |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2389 |
|
5528
274d31419935
privsep: don't leave a BOOTP process hanging around on SIGUSR1
Roy Marples <roy@marples.name>
parents:
5524
diff
changeset
|
2390 dhcp_closeinet(ifp); |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2391 #ifdef PRIVSEP |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
2392 if (IN_PRIVSEP_SE(ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2393 if (ps_inet_openbootp(state->addr) == -1) |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2394 logerr(__func__); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2395 return; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2396 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2397 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
2398 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2399 state->udp_rfd = dhcp_openudp(&state->addr->addr); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2400 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
|
2401 logerr(__func__); |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2402 /* 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
|
2403 * 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
|
2404 * 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
|
2405 * 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
|
2406 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
|
2407 return; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2408 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
2409 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
|
2410 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2411 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2412 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
|
2413 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
|
2414 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
|
2415 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2416 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
|
2417 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
|
2418 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2419 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
|
2420 return 0; |
|
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 (*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
|
2423 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
|
2424 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2425 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
|
2426 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
|
2427 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
|
2428 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2429 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
|
2430 *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
|
2431 *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
|
2432 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
|
2433 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
|
2434 } |
|
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 *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
|
2437 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
|
2438 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2439 |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2440 #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
|
2441 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2442 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
|
2443 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2444 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
|
2445 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
|
2446 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
|
2447 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2448 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
|
2449 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2450 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
|
2451 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
|
2452 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
|
2453 /* 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
|
2454 * 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
|
2455 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
|
2456 #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
|
2457 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
|
2458 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
|
2459 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
|
2460 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
|
2461 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2462 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
|
2463 /* 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
|
2464 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
|
2465 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
|
2466 } 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
|
2467 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
|
2468 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
|
2469 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
|
2470 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
|
2471 return 0; |
|
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 #else |
|
4630
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2474 if (!(ifp->flags & IFF_NOARP) && |
|
5002
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2475 ifp->options->options & DHCPCD_ARP) |
|
4630
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2476 { |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2477 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
|
2478 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
|
2479 |
|
5002
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2480 /* 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
|
2481 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
|
2482 if (astate == NULL) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2483 return -1; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2484 |
|
5002
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2485 if (ia == NULL) { |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2486 state->state = DHS_PROBE; |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2487 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
|
2488 loginfox("%s: probing address %s/%d", |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2489 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
|
2490 /* We need to handle DAD. */ |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2491 arp_probe(astate); |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2492 return 0; |
|
d3925b512c41
DHCP: Defend already configured static addresses
Roy Marples <roy@marples.name>
parents:
4999
diff
changeset
|
2493 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2494 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2495 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2496 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2497 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2498 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2499 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2500 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2501 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
|
2502 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2503 |
|
4425
7cd9fb2bbbe3
DHCP: Dont really add static address in test mode
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
2504 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
|
2505 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
|
2506 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
|
2507 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2508 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2509 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2510 static void |
|
5426
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2511 dhcp_lastlease(void *arg) |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2512 { |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2513 struct interface *ifp = arg; |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2514 struct dhcp_state *state = D_STATE(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2515 |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2516 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
|
2517 ifp->name); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2518 #if defined(ARP) || defined(KERNEL_RFC5227) |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2519 dhcp_arp_bind(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2520 #else |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2521 dhcp_bind(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2522 #endif |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2523 /* 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
|
2524 * state */ |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2525 state->added |= STATE_EXPIRED; |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2526 state->interval = 0; |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2527 dhcp_discover(ifp); |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2528 } |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2529 |
|
edcbeacf2225
DHCP: Request offered IP when using lastlease
Roy Marples <roy@marples.name>
parents:
5424
diff
changeset
|
2530 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
|
2531 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
|
2532 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2533 struct 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
|
2534 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
|
2535 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
|
2536 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2537 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
|
2538 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
|
2539 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2540 ia = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2541 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
|
2542 (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
|
2543 { |
|
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
|
2544 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
|
2545 "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
|
2546 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
|
2547 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
|
2548 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2549 } |
|
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 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
|
2552 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
|
2553 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
|
2554 if (state->offer_len) |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2555 #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
|
2556 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
|
2557 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2558 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
|
2559 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2560 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2561 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2562 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2563 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
|
2564 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2565 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
|
2566 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
|
2567 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
|
2568 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2569 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
|
2570 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
|
2571 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2572 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
|
2573 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
|
2574 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
|
2575 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
|
2576 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2577 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
|
2578 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
|
2579 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
|
2580 loginfox("%s: waiting for 3rd party to " |
| 4010 | 2581 "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
|
2582 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2583 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
|
2584 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
|
2585 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
|
2586 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2587 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2588 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2589 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2590 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
|
2591 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
|
2592 if (ifp->ctx->options & DHCPCD_TEST) { |
| 4010 | 2593 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
|
2594 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2595 return; |
|
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 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
|
2598 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
|
2599 /* 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
|
2600 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
|
2601 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
|
2602 &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
|
2603 #ifdef ARP |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2604 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
|
2605 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2606 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2607 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
|
2608 &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
|
2609 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
|
2610 } |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2613 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
|
2614 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
|
2615 &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
|
2616 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
|
2617 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
|
2618 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
|
2619 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
|
2620 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2621 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2622 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2623 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2624 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
|
2625 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2626 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
|
2627 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
|
2628 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2629 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
|
2630 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2631 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
|
2632 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
|
2633 (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
|
2634 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
|
2635 (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
|
2636 !(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
|
2637 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2638 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
|
2639 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2640 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2641 |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2642 #ifdef ARP |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2643 static int |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2644 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
|
2645 { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2646 const struct interface *ifp1; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2647 const struct dhcp_state *state; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2648 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2649 TAILQ_FOREACH(ifp1, ifp->ctx->ifaces, next) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2650 if (ifp1 == ifp) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2651 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2652 if ((state = D_CSTATE(ifp1)) == NULL) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2653 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2654 switch(state->state) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2655 case DHS_REBOOT: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2656 case DHS_RENEW: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2657 case DHS_REBIND: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2658 case DHS_BOUND: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2659 case DHS_INFORM: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2660 break; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2661 default: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2662 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2663 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2664 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
|
2665 return 1; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2666 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2667 return 0; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2668 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2669 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2670 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2671 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2672 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
|
2673 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2674 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
|
2675 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
|
2676 #ifdef ARP |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2677 struct ipv4_addr *ia; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2678 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2679 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2680 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
|
2681 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2682 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
|
2683 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
|
2684 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
|
2685 |
|
5499
6a2da5651841
dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents:
5497
diff
changeset
|
2686 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
|
2687 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
|
2688 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2689 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2690 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
|
2691 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
|
2692 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2693 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2694 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
|
2695 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
|
2696 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
|
2697 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
|
2698 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2699 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2700 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
|
2701 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
|
2702 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2703 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2704 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
|
2705 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2706 |
|
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
|
2707 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
|
2708 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
|
2709 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2710 #ifdef ARP |
|
4810
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2711 #ifndef KERNEL_RFC5227 |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2712 /* 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
|
2713 (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
|
2714 #endif |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2715 |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2716 /* 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
|
2717 * 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
|
2718 * interface gets the reply. */ |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2719 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
|
2720 if (ia != NULL && |
|
4332
8777d91277fc
dhcp: Don't ARP announce bound addresses when testing
Roy Marples <roy@marples.name>
parents:
4299
diff
changeset
|
2721 !(ifp->ctx->options & DHCPCD_TEST) && |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2722 #ifdef IN_IFF_NOTUSEABLE |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2723 !(ia->addr_flags & IN_IFF_NOTUSEABLE) && |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2724 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2725 dhcp_activeaddr(ifp, &state->lease.addr) == 0) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2726 arp_ifannounceaddr(ifp, &state->lease.addr); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2727 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2728 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2729 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
|
2730 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
|
2731 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
|
2732 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2733 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2734 /* 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
|
2735 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
|
2736 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
|
2737 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
|
2738 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2739 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2740 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
|
2741 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
|
2742 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
|
2743 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
|
2744 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
|
2745 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
|
2746 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2747 /* 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
|
2748 * 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
|
2749 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
|
2750 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2751 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2752 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2753 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
|
2754 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2755 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
|
2756 #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
|
2757 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
|
2758 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2759 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2760 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
|
2761 /* 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
|
2762 * 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
|
2763 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
|
2764 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
|
2765 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2766 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2767 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2768 #ifdef ARP |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2769 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
|
2770 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
|
2771 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2772 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2773 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
|
2774 #endif |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2775 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2776 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
|
2777 !(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
|
2778 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2779 /* 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
|
2780 * 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
|
2781 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
|
2782 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2783 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
|
2784 |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
2785 dhcp_unlink(ifp->ctx, state->leasefile); |
|
5499
6a2da5651841
dhcpcd: Simplify the link handling even more
Roy Marples <roy@marples.name>
parents:
5497
diff
changeset
|
2786 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
|
2787 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
|
2788 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
|
2789 { |
|
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
|
2790 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
|
2791 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
|
2792 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
|
2793 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
|
2794 #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
|
2795 /* 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
|
2796 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
|
2797 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
|
2798 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
|
2799 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2800 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2801 } |
|
5294
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2802 #ifdef AUTH |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2803 else if (state->auth.reconf != NULL) { |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2804 /* |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2805 * 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
|
2806 * 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
|
2807 * renewals. |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2808 * 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
|
2809 * XXX persist this in another file? |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2810 */ |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2811 dhcp_unlink(ifp->ctx, state->leasefile); |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2812 } |
|
942ddb46cd55
auth: Only accept RECONFIGURE messages from LL hosts
Roy Marples <roy@marples.name>
parents:
5288
diff
changeset
|
2813 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2814 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2815 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
|
2816 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2817 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
|
2818 #endif |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2819 |
|
5176
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2820 /* 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
|
2821 * up by a new BPF state. */ |
|
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2822 dhcp_close(ifp); |
|
9f2e260a7369
DHCP: Close sockets on carrier down
Roy Marples <roy@marples.name>
parents:
5166
diff
changeset
|
2823 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2824 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
|
2825 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
|
2826 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
|
2827 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
|
2828 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
|
2829 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
|
2830 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
|
2831 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
|
2832 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
|
2833 state->reason = reason; |
| 5535 | 2834 if (ifp->options->options & DHCPCD_CONFIGURE) |
| 2835 ipv4_applyaddr(ifp); | |
| 2836 else { | |
| 2837 state->addr = NULL; | |
| 2838 state->added = 0; | |
| 2839 script_runreason(ifp, state->reason); | |
| 2840 } | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2841 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
|
2842 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
|
2843 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
|
2844 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
|
2845 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
|
2846 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
|
2847 } |
|
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 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2850 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
|
2851 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2852 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
|
2853 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2854 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
|
2855 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
|
2856 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2857 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2858 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2859 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2860 #define WHTLST_NONE 0 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2861 #define WHTLST_MATCH 1 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2862 #define WHTLST_NOMATCH 2 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2863 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
|
2864 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
|
2865 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2866 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
|
2867 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2868 if (ifo->whitelist_len == 0) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2869 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
|
2870 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
|
2871 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
|
2872 return WHTLST_MATCH; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2873 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
|
2874 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2875 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2876 static void |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
2877 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
|
2878 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
|
2879 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
|
2880 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2881 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
|
2882 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
|
2883 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
|
2884 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2885 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
|
2886 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2887 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
|
2888 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
|
2889 if (a) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2890 char *tmp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2891 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
|
2892 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2893 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
|
2894 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
|
2895 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
|
2896 if (tmp == NULL) { |
| 4010 | 2897 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
|
2898 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2899 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2900 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2901 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
|
2902 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2903 a = tmp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2904 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2905 } 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
|
2906 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
|
2907 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
|
2908 if (a == NULL) { |
| 4010 | 2909 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
|
2910 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2911 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2912 } else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2913 a = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2914 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2915 tfrom = "from"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2916 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
|
2917 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
|
2918 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
|
2919 overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2920 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
|
2921 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
|
2922 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
|
2923 if (a == NULL) |
| 5494 | 2924 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
|
2925 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
|
2926 else |
| 5494 | 2927 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
|
2928 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
|
2929 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2930 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
|
2931 tfrom = "via"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2932 addr = *from; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2933 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2934 if (a == NULL) |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
2935 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
|
2936 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
|
2937 else |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
2938 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
|
2939 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
|
2940 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2941 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2942 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2943 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2944 /* 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
|
2945 * 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
|
2946 * Try and re-direct it here. */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2947 static void |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2948 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
|
2949 const struct in_addr *from) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2950 { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2951 struct interface *ifn; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2952 const struct dhcp_state *state; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2953 uint32_t xid; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2954 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2955 xid = ntohl(bootp->xid); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2956 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
|
2957 if (ifn == ifp) |
|
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
2958 continue; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2959 state = D_CSTATE(ifn); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2960 if (state == NULL || state->state == DHS_NONE) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2961 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2962 if (state->xid != xid) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2963 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2964 if (ifn->hwlen <= sizeof(bootp->chaddr) && |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2965 memcmp(bootp->chaddr, ifn->hwaddr, ifn->hwlen)) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2966 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2967 logdebugx("%s: redirecting DHCP message to %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2968 ifp->name, ifn->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2969 dhcp_handledhcp(ifn, bootp, bootp_len, from); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2970 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2971 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2972 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2973 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2974 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
|
2975 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
|
2976 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2977 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
|
2978 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
|
2979 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
|
2980 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
|
2981 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
|
2982 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
|
2983 char *msg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2984 bool bootp_copied; |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
2985 uint32_t v6only_time = 0; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
2986 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
|
2987 #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
|
2988 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
|
2989 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
|
2990 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2991 #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
|
2992 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
|
2993 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2994 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2995 #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
|
2996 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
|
2997 #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
|
2998 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
|
2999 |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
3000 #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
|
3001 (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
|
3002 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3003 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
|
3004 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
|
3005 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
|
3006 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
|
3007 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3008 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3009 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3010 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
|
3011 if (IS_STATE_ACTIVE(state)) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3012 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
|
3013 ifp->name, ntohl(bootp->xid), state->xid, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3014 inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3015 dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3016 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3017 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3018 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3019 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
|
3020 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
|
3021 { |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
3022 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
|
3023 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
|
3024 |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
3025 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
|
3026 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
|
3027 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
|
3028 buf, sizeof(buf))); |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
3029 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3030 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
|
3031 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3032 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3033 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3034 if (!ifp->active) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3035 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3036 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3037 i = whitelisted_ip(ifp->options, from->s_addr); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3038 switch (i) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3039 case WHTLST_NOMATCH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3040 logwarnx("%s: non whitelisted DHCP packet from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3041 ifp->name, inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3042 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3043 case WHTLST_MATCH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3044 break; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3045 case WHTLST_NONE: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3046 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
|
3047 logwarnx("%s: blacklisted DHCP packet from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3048 ifp->name, inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3049 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3050 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3051 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3052 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3053 /* 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
|
3054 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
|
3055 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
|
3056 type = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3057 else if (ifo->options & DHCPCD_BOOTP) { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3058 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
|
3059 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3060 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3061 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3062 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3063 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3064 /* 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
|
3065 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
|
3066 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
|
3067 if (auth) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3068 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
|
3069 (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
|
3070 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
|
3071 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3072 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
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3075 if (state->auth.token) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3076 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
|
3077 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
|
3078 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
|
3079 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
|
3080 } 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
|
3081 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
|
3082 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
|
3083 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3084 } |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3085 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
|
3086 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3087 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3088 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3089 /* RFC 3203 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3090 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
|
3091 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
|
3092 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
|
3093 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3094 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
|
3095 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3096 } |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
3097 #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
|
3098 if (auth == NULL) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3099 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
|
3100 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
|
3101 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3102 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3103 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
|
3104 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
|
3105 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3106 } |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3107 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
|
3108 /* 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
|
3109 * 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
|
3110 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
|
3111 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
|
3112 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3113 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
|
3114 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
|
3115 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
|
3116 } |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
3117 #else |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3118 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
|
3119 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3120 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3121 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3122 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3123 if (state->state == DHS_BOUND) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3124 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
|
3125 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3126 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3127 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3128 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
|
3129 /* 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
|
3130 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
|
3131 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3132 } |
|
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 /* 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
|
3135 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
|
3136 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3137 /* 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
|
3138 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
|
3139 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
|
3140 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
|
3141 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
|
3142 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3143 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
|
3144 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3145 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3146 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3147 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3148 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
|
3149 /* 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
|
3150 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
|
3151 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
|
3152 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
|
3153 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3154 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
|
3155 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3156 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3157 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3158 /* 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
|
3159 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
|
3160 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
|
3161 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
|
3162 { |
| 4010 | 3163 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
|
3164 free(msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3165 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3166 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
|
3167 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3168 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
|
3169 dhcp_drop(ifp, "NAK"); |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
3170 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
|
3171 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3172 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3173 /* 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
|
3174 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
|
3175 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
|
3176 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
|
3177 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
|
3178 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3179 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
|
3180 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
|
3181 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
|
3182 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3183 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3184 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3185 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3186 /* 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
|
3187 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
|
3188 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
|
3189 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
|
3190 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
|
3191 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3192 /* 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
|
3193 * 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
|
3194 * 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
|
3195 * 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
|
3196 * always true. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3197 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
|
3198 continue; |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3199 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
|
3200 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3201 } |
|
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 |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3204 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
|
3205 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
|
3206 DHO_IPV6_PREFERRED_ONLY) == 0 && |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3207 (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
|
3208 { |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3209 char v6msg[128]; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3210 |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3211 use_v6only = true; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3212 if (v6only_time < MIN_V6ONLY_WAIT) |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3213 v6only_time = MIN_V6ONLY_WAIT; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3214 snprintf(v6msg, sizeof(v6msg), |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3215 "IPv6-Only Preferred received (%u seconds)", |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3216 v6only_time); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3217 LOGDHCP(LOG_INFO, v6msg); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3218 } |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3219 } |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3220 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3221 /* 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
|
3222 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
|
3223 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
|
3224 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
|
3225 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
|
3226 { |
| 4010 | 3227 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
|
3228 free(msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3229 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3230 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3231 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
|
3232 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
|
3233 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
|
3234 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3235 switch (tmp) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3236 case 0: |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3237 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
|
3238 ipv4ll_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3239 #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
|
3240 arp_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3241 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3242 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3243 case 1: |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3244 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
|
3245 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
|
3246 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3247 default: |
| 4010 | 3248 logerrx("%s: unknown auto configuration " |
| 3249 "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
|
3250 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
|
3251 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3252 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3253 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
|
3254 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
|
3255 use_v6only ? v6only_time : DHCP_MAX, |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3256 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
|
3257 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3258 #endif |
|
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 |
|
5524
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3262 if (use_v6only) { |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3263 dhcp_drop(ifp, "EXPIRE"); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3264 dhcp_unlink(ifp->ctx, state->leasefile); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3265 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
|
3266 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
|
3267 dhcp_discover, ifp); |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3268 return; |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3269 } |
|
8c0e5dc34824
DHCP: Implement IPv6-Only Preferred option, RFC 8925.
Roy Marples <roy@marples.name>
parents:
5499
diff
changeset
|
3270 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3271 /* 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
|
3272 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
|
3273 (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
|
3274 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3275 (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
|
3276 { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3277 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
|
3278 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3279 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3280 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3281 #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
|
3282 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
|
3283 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
|
3284 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
|
3285 if (type) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3286 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
|
3287 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
|
3288 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
|
3289 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
|
3290 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
|
3291 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3292 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3293 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3294 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3295 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
|
3296 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
|
3297 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
|
3298 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
|
3299 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
|
3300 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
|
3301 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
|
3302 &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
|
3303 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
|
3304 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3305 /* 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
|
3306 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
|
3307 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
|
3308 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
|
3309 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
|
3310 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3311 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
|
3312 goto rapidcommit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3313 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3314 |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3315 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
|
3316 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
|
3317 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
|
3318 if ((state->offer = malloc(bootp_len)) == NULL) { |
| 4010 | 3319 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
|
3320 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
|
3321 return; |
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3324 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
|
3325 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
|
3326 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
|
3327 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
|
3328 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
|
3329 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
|
3330 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
|
3331 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
|
3332 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
|
3333 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
|
3334 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
|
3335 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
|
3336 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
|
3337 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3338 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
|
3339 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3340 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3341 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
|
3342 /* 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
|
3343 if (type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3344 /* 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
|
3345 * 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
|
3346 * 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
|
3347 * 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
|
3348 * 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
|
3349 * DISCOVER. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3350 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
|
3351 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3352 } |
|
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 if (type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3356 if (type == DHCP_OFFER) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3357 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
|
3358 return; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3361 /* 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
|
3362 if (type != DHCP_ACK) { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3363 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
|
3364 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3365 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3366 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3367 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
|
3368 /* 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
|
3369 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
|
3370 DHO_RAPIDCOMMIT) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3371 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
|
3372 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
|
3373 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
|
3374 else { |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3375 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
|
3376 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3377 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3378 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3379 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3380 rapidcommit: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3381 if (!(ifo->options & DHCPCD_INFORM)) |
|
5064
7721231839f5
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5054
diff
changeset
|
3382 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
|
3383 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3384 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
|
3385 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3386 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3387 /* 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
|
3388 * 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
|
3389 * 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
|
3390 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
|
3391 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3392 /* 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
|
3393 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
|
3394 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
|
3395 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
|
3396 if ((state->offer = malloc(bootp_len)) == NULL) { |
| 4010 | 3397 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
|
3398 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
|
3399 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3400 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3401 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3402 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
|
3403 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
|
3404 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3405 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3406 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
|
3407 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
|
3408 |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
3409 #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
|
3410 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
|
3411 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3412 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
|
3413 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3414 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3415 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3416 static void * |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3417 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
|
3418 { |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3419 const struct ip *ip = packet; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3420 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
|
3421 char *p = packet; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3422 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3423 p += ip_hl + sizeof(struct udphdr); |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3424 *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
|
3425 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
|
3426 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3427 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3428 static bool |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3429 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
|
3430 { |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3431 struct ip *ip = packet; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3432 size_t ip_hlen; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3433 struct udphdr udp; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3434 |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3435 if (plen < sizeof(*ip)) |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3436 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3437 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3438 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
|
3439 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3440 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3441 /* Sanity. */ |
|
4762
d68ac6b143c5
dhcp: Allow for trailing FCS in the packet.
Roy Marples <roy@marples.name>
parents:
4761
diff
changeset
|
3442 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
|
3443 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3444 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3445 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
|
3446 if (ip_hlen < sizeof(*ip)) |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3447 return false; |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3448 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3449 /* 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
|
3450 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
|
3451 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3452 |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3453 /* Sanity. */ |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3454 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
|
3455 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
|
3456 return false; |
|
5072
b1ab228ac3b3
Revert "dhcp: Cast away a compile warning"
Roy Marples <roy@marples.name>
parents:
5064
diff
changeset
|
3457 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
|
3458 return false; |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3459 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3460 /* 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
|
3461 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
|
3462 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3463 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3464 return true; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3465 } |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3466 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3467 /* Lengths have already been checked. */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3468 static bool |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3469 checksums_valid(void *packet, |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3470 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
|
3471 { |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3472 struct ip *ip = packet; |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3473 union pip { |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3474 struct ip ip; |
|
4775
9a29b37bc5cb
DHCP: Fix prior to not waste space
Sergei Trofimovich <slyfox@gentoo.org>
parents:
4773
diff
changeset
|
3475 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
|
3476 } pip = { |
| 5272 | 3477 .ip = { |
| 3478 .ip_p = IPPROTO_UDP, | |
| 3479 .ip_src = ip->ip_src, | |
| 3480 .ip_dst = ip->ip_dst, | |
| 3481 } | |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3482 }; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3483 size_t ip_hlen; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3484 struct udphdr udp; |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3485 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
|
3486 uint32_t csum; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3487 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3488 if (from != NULL) |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3489 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
|
3490 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3491 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
|
3492 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
|
3493 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3494 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3495 if (flags & BPF_PARTIALCSUM) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3496 return true; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3497 |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3498 udpp = (char *)ip + ip_hlen; |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3499 memcpy(&udp, udpp, sizeof(udp)); |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3500 if (udp.uh_sum == 0) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3501 return true; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3502 |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3503 /* 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
|
3504 * 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
|
3505 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
|
3506 csum = 0; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3507 |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3508 /* 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
|
3509 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
|
3510 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
|
3511 |
| 4773 | 3512 /* 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
|
3513 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
|
3514 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
|
3515 |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3516 #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
|
3517 /* Put the checksum back. */ |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3518 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
|
3519 #endif |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3520 |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3521 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
|
3522 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3523 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3524 static void |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3525 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
|
3526 struct in_addr *from) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3527 { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3528 size_t v; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3529 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3530 if (len < offsetof(struct bootp, vend)) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3531 logerrx("%s: truncated packet (%zu) from %s", |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3532 ifp->name, len, inet_ntoa(*from)); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3533 return; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3534 } |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3535 |
|
5079
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3536 /* Unlikely, but appeases sanitizers. */ |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3537 if (len > FRAMELEN_MAX) { |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3538 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
|
3539 ifp->name, len, inet_ntoa(*from)); |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3540 return; |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3541 } |
|
415c98a69db0
DHCP: Move the max frame length check
Roy Marples <roy@marples.name>
parents:
5078
diff
changeset
|
3542 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3543 /* 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
|
3544 * area has at least 4 octets. */ |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3545 v = len - offsetof(struct bootp, vend); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3546 while (v < 4) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3547 bootp->vend[v++] = '\0'; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3548 len++; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3549 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3550 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3551 dhcp_handledhcp(ifp, bootp, len, from); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3552 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3553 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3554 void |
| 5234 | 3555 dhcp_packet(struct interface *ifp, uint8_t *data, size_t len, |
| 3556 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
|
3557 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3558 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
|
3559 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
|
3560 size_t udp_len; |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3561 size_t fl = bpf_frame_header_len(ifp); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3562 #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
|
3563 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
|
3564 |
|
5489
a3d5af47a4e3
Add a comment to prior incase I do something dumb like removing it
Roy Marples <roy@marples.name>
parents:
5487
diff
changeset
|
3565 /* 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
|
3566 * 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
|
3567 * 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
|
3568 * 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
|
3569 * 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
|
3570 * 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
|
3571 * 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
|
3572 if (state == NULL) |
|
23f35ea1a34a
privsep: fix crash when interface departs before bpf returns for it
Roy Marples <roy@marples.name>
parents:
5449
diff
changeset
|
3573 return; |
|
23f35ea1a34a
privsep: fix crash when interface departs before bpf returns for it
Roy Marples <roy@marples.name>
parents:
5449
diff
changeset
|
3574 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3575 /* Ignore double reads */ |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
3576 if (IN_PRIVSEP(ifp->ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3577 switch (state->state) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3578 case DHS_BOUND: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3579 case DHS_RENEW: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3580 return; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3581 default: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3582 break; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3583 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3584 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3585 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3586 |
|
5033
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3587 /* Trim frame header */ |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3588 if (fl != 0) { |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3589 if (len < fl) { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3590 logerrx("%s: %s: short frame header %zu", |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3591 __func__, ifp->name, len); |
|
5033
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3592 return; |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3593 } |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3594 len -= fl; |
|
5158
5f18174b5eb2
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5120
diff
changeset
|
3595 /* Move the data to avoid alignment errors. */ |
|
5f18174b5eb2
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5120
diff
changeset
|
3596 memmove(data, data + fl, len); |
|
5033
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3597 } |
|
d8f63eaa4d2b
DHCP: Fix receiving BPF from privsep.
Roy Marples <roy@marples.name>
parents:
5028
diff
changeset
|
3598 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3599 /* Validate filter. */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3600 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
|
3601 #ifdef BPF_DEBUG |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3602 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
|
3603 #endif |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3604 return; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3605 } |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3606 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3607 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
|
3608 logerrx("%s: checksum failure from %s", |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3609 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
|
3610 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3611 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3612 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3613 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3614 * 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
|
3615 * 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
|
3616 * 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
|
3617 * 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
|
3618 * 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
|
3619 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3620 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
|
3621 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
|
3622 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3623 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3624 static void |
|
4717
3cce06e28d99
DHCP: Rename dhcp_readpacket to dhcp_readbpf
Roy Marples <roy@marples.name>
parents:
4715
diff
changeset
|
3625 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
|
3626 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3627 struct interface *ifp = arg; |
| 5028 | 3628 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
|
3629 ssize_t bytes; |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3630 struct dhcp_state *state = D_STATE(ifp); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3631 struct bpf *bpf = state->bpf; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3632 |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3633 bpf->bpf_flags &= ~BPF_EOF; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3634 while (!(bpf->bpf_flags & BPF_EOF)) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3635 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
|
3636 if (bytes == -1) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3637 if (state->state != DHS_NONE) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3638 logerr("%s: %s", __func__, ifp->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3639 dhcp_close(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3640 } |
|
4171
4ff80b2bbba1
Fix prior patches by using correct bitmasks for flags.
Roy Marples <roy@marples.name>
parents:
4169
diff
changeset
|
3641 break; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3642 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3643 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
|
3644 /* 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
|
3645 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
|
3646 break; |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3647 if ((bpf = state->bpf) == NULL) |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3648 break; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3649 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3650 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3651 |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3652 void |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3653 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
|
3654 { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3655 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
|
3656 struct iovec *iov = &msg->msg_iov[0]; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3657 struct interface *ifp; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3658 const struct dhcp_state *state; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3659 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3660 ifp = if_findifpfromcmsg(ctx, msg, NULL); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3661 if (ifp == NULL) { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3662 logerr(__func__); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3663 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3664 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3665 state = D_CSTATE(ifp); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3666 if (state == NULL) { |
|
5009
0f76dcb791a4
DHCP: redirect message to other interfaces if received for inactive
Roy Marples <roy@marples.name>
parents:
5002
diff
changeset
|
3667 /* 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
|
3668 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
|
3669 iov->iov_len, &from->sin_addr); |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3670 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3671 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3672 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3673 if (state->bpf != NULL) { |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3674 /* 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
|
3675 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3676 } |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3677 #ifdef PRIVSEP |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
3678 if (IN_PRIVSEP(ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3679 switch (state->state) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3680 case DHS_BOUND: /* FALLTHROUGH */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3681 case DHS_RENEW: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3682 break; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3683 default: |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3684 /* 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
|
3685 * via BPF. */ |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3686 return; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3687 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3688 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3689 #endif |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3690 |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3691 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
|
3692 &from->sin_addr); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3693 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3694 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3695 static void |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3696 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
|
3697 { |
| 4602 | 3698 const struct dhcp_state *state; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3699 struct sockaddr_in from; |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3700 union { |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3701 struct bootp bootp; |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3702 uint8_t buf[10 * 1024]; /* Maximum MTU */ |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3703 } iovbuf; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3704 struct iovec iov = { |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3705 .iov_base = iovbuf.buf, |
|
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3706 .iov_len = sizeof(iovbuf.buf), |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3707 }; |
| 5160 | 3708 union { |
| 3709 struct cmsghdr hdr; | |
| 4784 | 3710 #ifdef IP_RECVIF |
| 5160 | 3711 uint8_t buf[CMSG_SPACE(sizeof(struct sockaddr_dl))]; |
| 4784 | 3712 #else |
| 5160 | 3713 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
|
3714 #endif |
| 5160 | 3715 } cmsgbuf = { .buf = { 0 } }; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3716 struct msghdr msg = { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3717 .msg_name = &from, .msg_namelen = sizeof(from), |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3718 .msg_iov = &iov, .msg_iovlen = 1, |
|
5193
658eb5d94c0b
DHCP: Use correct buffer for receiving UDP
Roy Marples <roy@marples.name>
parents:
5176
diff
changeset
|
3719 .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
|
3720 }; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3721 int s; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3722 ssize_t bytes; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3723 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3724 if (ifp != NULL) { |
|
4594
81f346f0e892
DHCP: Avoid duplicate read of packet
Roy Marples <roy@marples.name>
parents:
4587
diff
changeset
|
3725 state = D_CSTATE(ifp); |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3726 s = state->udp_rfd; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3727 } else |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3728 s = ctx->udp_rfd; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3729 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3730 bytes = recvmsg(s, &msg, 0); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3731 if (bytes == -1) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3732 logerr(__func__); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3733 return; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3734 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3735 |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3736 iov.iov_len = (size_t)bytes; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3737 dhcp_recvmsg(ctx, &msg); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3738 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3739 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3740 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
|
3741 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
|
3742 { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3743 struct dhcpcd_ctx *ctx = arg; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3744 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3745 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
|
3746 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3747 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3748 static void |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3749 dhcp_handleifudp(void *arg) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3750 { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3751 struct interface *ifp = arg; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3752 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3753 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
|
3754 } |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3755 |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3756 static int |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3757 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
|
3758 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3759 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
|
3760 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3761 state = D_STATE(ifp); |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3762 |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3763 #ifdef PRIVSEP |
|
4868
119c8986dfc8
privsep: Enable ARP BPF filtering for interesting addresses
Roy Marples <roy@marples.name>
parents:
4866
diff
changeset
|
3764 if (IN_PRIVSEP_SE(ifp->ctx)) { |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3765 if (ps_bpf_openbootp(ifp) == -1) { |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3766 logerr(__func__); |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3767 return -1; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3768 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3769 return 0; |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3770 } |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3771 #endif |
|
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3772 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3773 if (state->bpf != NULL) |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3774 return 0; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3775 |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3776 state->bpf = bpf_open(ifp, bpf_bootp, NULL); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3777 if (state->bpf == NULL) { |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3778 if (errno == ENOENT) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3779 logerrx("%s not found", bpf_name); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3780 /* May as well disable IPv4 entirely at |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3781 * this point as we really need it. */ |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3782 ifp->options->options &= ~DHCPCD_IPV4; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3783 } else |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3784 logerr("%s: %s", __func__, ifp->name); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3785 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
|
3786 } |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3787 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3788 eloop_event_add(ifp->ctx->eloop, |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3789 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
|
3790 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3791 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3792 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3793 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3794 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
|
3795 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3796 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
|
3797 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
|
3798 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3799 dhcp_close(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3800 #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
|
3801 arp_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3802 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3803 if (state) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3804 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
|
3805 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
|
3806 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
|
3807 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
|
3808 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
|
3809 free(state); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3810 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3811 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3812 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
|
3813 /* 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
|
3814 * 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
|
3815 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
|
3816 TAILQ_FOREACH(ifp, ctx->ifaces, next) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3817 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3818 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
|
3819 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3820 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3821 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3822 if (ifp == NULL) { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3823 if (ctx->udp_rfd != -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3824 eloop_event_delete(ctx->eloop, ctx->udp_rfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3825 close(ctx->udp_rfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3826 ctx->udp_rfd = -1; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3827 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3828 if (ctx->udp_wfd != -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3829 close(ctx->udp_wfd); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3830 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
|
3831 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3832 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3833 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
|
3834 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
|
3835 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3836 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3837 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3838 static int |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3839 dhcp_initstate(struct interface *ifp) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3840 { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3841 struct dhcp_state *state; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3842 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3843 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3844 if (state != NULL) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3845 return 0; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3846 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3847 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
|
3848 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3849 if (state == NULL) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3850 return -1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3851 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3852 state->state = DHS_NONE; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3853 /* 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
|
3854 state->udp_rfd = -1; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3855 #ifdef ARPING |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3856 state->arping_index = -1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3857 #endif |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3858 return 1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3859 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3860 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3861 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
|
3862 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
|
3863 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3864 struct dhcp_state *state; |
|
5280
a986083da0ba
Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents:
5272
diff
changeset
|
3865 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
|
3866 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
|
3867 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
|
3868 |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
3869 if (dhcp_initstate(ifp) == -1) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3870 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
|
3871 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3872 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
|
3873 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
|
3874 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
|
3875 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
|
3876 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
|
3877 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
|
3878 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3879 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
|
3880 /* 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
|
3881 * 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
|
3882 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
|
3883 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
|
3884 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3885 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
|
3886 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
|
3887 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3888 if (ifo->options & DHCPCD_ANONYMOUS) { |
|
5573
5bf8e1fc0634
DHCP: For anonymous, just use a generic clientid
Roy Marples <roy@marples.name>
parents:
5549
diff
changeset
|
3889 /* Removing the option could show that we want anonymous. |
|
5bf8e1fc0634
DHCP: For anonymous, just use a generic clientid
Roy Marples <roy@marples.name>
parents:
5549
diff
changeset
|
3890 * As such keep it as it's already in the hwaddr field. */ |
|
5bf8e1fc0634
DHCP: For anonymous, just use a generic clientid
Roy Marples <roy@marples.name>
parents:
5549
diff
changeset
|
3891 goto make_clientid; |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
3892 } 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
|
3893 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
|
3894 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
|
3895 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3896 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
|
3897 (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
|
3898 } 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
|
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 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
|
3901 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
|
3902 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3903 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
|
3904 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
|
3905 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
|
3906 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
|
3907 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
|
3908 } else { |
|
5573
5bf8e1fc0634
DHCP: For anonymous, just use a generic clientid
Roy Marples <roy@marples.name>
parents:
5549
diff
changeset
|
3909 make_clientid: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3910 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
|
3911 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
|
3912 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
|
3913 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3914 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
|
3915 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
|
3916 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
|
3917 ifp->hwlen); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3918 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3919 } |
|
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 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
|
3922 /* 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
|
3923 * 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
|
3924 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3925 |
|
5280
a986083da0ba
Fix some clang analyzer issues
Roy Marples <roy@marples.name>
parents:
5272
diff
changeset
|
3926 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
|
3927 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
|
3928 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
|
3929 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
|
3930 else if (ifp->hwlen) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3931 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
|
3932 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
|
3933 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3934 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3935 eexit: |
| 4010 | 3936 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
|
3937 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3938 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3939 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3940 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3941 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
|
3942 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3943 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
|
3944 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
|
3945 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
|
3946 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
|
3947 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
|
3948 int nolease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3949 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3950 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
|
3951 return; |
|
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 /* 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
|
3954 * 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
|
3955 * 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
|
3956 * for dhcpcd running on another interface. */ |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3957 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
|
3958 && ctx->udp_rfd == -1) |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
3959 { |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3960 ctx->udp_rfd = dhcp_openudp(NULL); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3961 if (ctx->udp_rfd == -1) { |
|
4833
aadc0d25a706
DHCP: Require unspecificed BOOTP port for master mode
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
3962 logerr(__func__); |
|
aadc0d25a706
DHCP: Require unspecificed BOOTP port for master mode
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
3963 return; |
|
4791
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3964 } |
|
5231
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3965 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
|
3966 } |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3967 if (!IN_PRIVSEP(ctx) && ctx->udp_wfd == -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3968 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
|
3969 if (ctx->udp_wfd == -1) { |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3970 logerr(__func__); |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3971 return; |
|
a2c342295221
privsep: Enable Capsicum for all processes.
Roy Marples <roy@marples.name>
parents:
5229
diff
changeset
|
3972 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3973 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3974 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3975 if (dhcp_init(ifp) == -1) { |
| 4010 | 3976 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
|
3977 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3978 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3979 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3980 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
|
3981 clock_gettime(CLOCK_MONOTONIC, &state->started); |
|
4224
595761ecbde0
dhcp: reset interval during init
Roy Marples <roy@marples.name>
parents:
4207
diff
changeset
|
3982 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
|
3983 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
|
3984 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
|
3985 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
|
3986 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3987 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3988 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
|
3989 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
|
3990 return; |
|
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 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3993 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3994 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
|
3995 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
|
3996 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3997 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3998 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3999 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
|
4000 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
|
4001 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4002 } |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
4003 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4004 /* 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
|
4005 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
|
4006 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
|
4007 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
|
4008 /* 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
|
4009 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
|
4010 #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
|
4011 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
|
4012 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
|
4013 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4014 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
|
4015 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
|
4016 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4017 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4018 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
|
4019 !(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
|
4020 #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
|
4021 (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
|
4022 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4023 (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
|
4024 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
|
4025 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4026 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
|
4027 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
|
4028 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
|
4029 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4030 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4031 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4032 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
|
4033 struct ipv4_addr *ia; |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4034 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
|
4035 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4036 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
|
4037 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
|
4038 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
|
4039 (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
|
4040 &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
|
4041 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4042 /* 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
|
4043 * 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
|
4044 * 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
|
4045 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
|
4046 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
|
4047 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
|
4048 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
|
4049 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
|
4050 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
|
4051 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
|
4052 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
|
4053 } else |
| 4010 | 4054 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
|
4055 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4056 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
|
4057 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
|
4058 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
|
4059 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
|
4060 } 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
|
4061 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
|
4062 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
|
4063 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4064 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
|
4065 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4066 /* 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
|
4067 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
|
4068 if (now == -1 || |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4069 (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
|
4070 { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
4071 logdebugx("%s: discarding expired lease", |
| 4010 | 4072 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
|
4073 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
|
4074 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
|
4075 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
|
4076 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
|
4077 /* 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
|
4078 * 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
|
4079 * 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
|
4080 * 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
|
4081 * 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
|
4082 * 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
|
4083 * 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
|
4084 * 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
|
4085 * 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
|
4086 * 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
|
4087 * 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
|
4088 * 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
|
4089 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4090 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
|
4091 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
|
4092 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4093 } else { |
|
5207
84b63f09c8a4
privsep: Handle all file IO in the Priviledged Actioneer
Roy Marples <roy@marples.name>
parents:
5193
diff
changeset
|
4094 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
|
4095 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
|
4096 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
|
4097 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
|
4098 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4099 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4100 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4101 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4102 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4103 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
|
4104 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
|
4105 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
|
4106 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4107 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4108 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4109 |
|
4958
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
4110 if (state->offer == NULL || |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
4111 !IS_DHCP(state->offer) || |
|
a120f447fe74
Implement Anonymity Profiles for DHCP Clients, RFC 7844
Roy Marples <roy@marples.name>
parents:
4952
diff
changeset
|
4112 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
|
4113 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
|
4114 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4115 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
|
4116 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4117 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4118 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4119 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
|
4120 { |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4121 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
|
4122 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4123 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
|
4124 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4125 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4126 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
|
4127 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4128 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4129 /* 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
|
4130 * 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
|
4131 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
|
4132 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
|
4133 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
|
4134 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
|
4135 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4136 /* 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
|
4137 * 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
|
4138 * 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
|
4139 * 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
|
4140 * 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
|
4141 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
|
4142 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
|
4143 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
|
4144 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
|
4145 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4146 /* 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
|
4147 * 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
|
4148 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
|
4149 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
|
4150 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
|
4151 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
|
4152 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4153 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4154 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4155 /* 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
|
4156 * 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
|
4157 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
|
4158 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
|
4159 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4160 /* 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
|
4161 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
|
4162 !(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
|
4163 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4164 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
|
4165 return; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4168 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4169 /* 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
|
4170 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
|
4171 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
|
4172 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
|
4173 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4174 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4175 #endif |
|
4932
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4176 delay = MSEC_PER_SEC + |
|
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4177 (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
|
4178 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
|
4179 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
|
4180 |
|
8e1948e75f39
DHCP: Use milliseconds rather than timespec for retranmission
Roy Marples <roy@marples.name>
parents:
4924
diff
changeset
|
4181 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
|
4182 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4183 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4184 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4185 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
|
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 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
|
4188 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4189 state = D_STATE(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
4190 #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
|
4191 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
|
4192 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
|
4193 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4194 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4195 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
|
4196 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4197 if (state != NULL && state->added) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4198 rt_build(ifp->ctx, AF_INET); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4199 #ifdef ARP |
|
5241
989bcc6c8e70
ARP: A few minor fixes for prior
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
4200 if (ifp->options->options & DHCPCD_ARP) |
|
989bcc6c8e70
ARP: A few minor fixes for prior
Roy Marples <roy@marples.name>
parents:
5234
diff
changeset
|
4201 arp_announceaddr(ifp->ctx, &state->addr->addr); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4202 #endif |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4203 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4204 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4205 |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4206 struct ipv4_addr * |
|
4232
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4224
diff
changeset
|
4207 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
|
4208 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4209 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
|
4210 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
|
4211 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
|
4212 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
|
4213 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4214 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
|
4215 state = D_STATE(ifp); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4216 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
|
4217 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
|
4218 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4219 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
|
4220 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
|
4221 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
|
4222 ifp->name, pid, ia->saddr); |
|
4840
073fcd86db9b
privsep: Add support for priviledge separation
Roy Marples <roy@marples.name>
parents:
4833
diff
changeset
|
4223 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
|
4224 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
|
4225 /* 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
|
4226 * 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
|
4227 dhcp_drop(ifp, "EXPIRE"); |
|
4242
9f4dc610f30c
Really start dhcp on deletion of address.
Roy Marples <roy@marples.name>
parents:
4240
diff
changeset
|
4228 dhcp_start1(ifp); |
|
4782
8a9ec0631165
INET: Fix a potential memory leak
Roy Marples <roy@marples.name>
parents:
4775
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4231 } |
|
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 if (cmd != RTM_NEWADDR) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4234 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
|
4235 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4236 #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
|
4237 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
|
4238 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
|
4239 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
|
4240 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
|
4241 #endif |
|
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 ifo = ifp->options; |
| 5535 | 4244 |
| 4245 #ifdef PRIVSEP | |
| 4246 if (IN_PRIVSEP_SE(ifp->ctx) && | |
| 4247 !(ifp->ctx->options & (DHCPCD_MASTER | DHCPCD_CONFIGURE)) && | |
| 4248 IN_ARE_ADDR_EQUAL(&state->lease.addr, &ia->addr)) | |
| 4249 { | |
| 4250 state->addr = ia; | |
| 4251 state->added = STATE_ADDED; | |
| 4252 dhcp_closebpf(ifp); | |
| 4253 if (ps_inet_openbootp(ia) == -1) | |
| 4254 logerr(__func__); | |
| 4255 } | |
| 4256 #endif | |
| 4257 | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4258 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
|
4259 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
|
4260 dhcp_inform(ifp); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4261 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
|
4262 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4263 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4264 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
|
4265 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
|
4266 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
|
4267 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
|
4268 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4269 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
|
4270 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
|
4271 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
|
4272 if (state->new == NULL) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4273 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
|
4274 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
|
4275 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
|
4276 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
|
4277 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
|
4278 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4279 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
|
4280 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
|
4281 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
|
4282 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
|
4283 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
|
4284 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
|
4285 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
|
4286 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
|
4287 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
|
4288 } |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4289 |
|
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4290 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
|
4291 } |
|
5288
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4292 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4293 #ifndef SMALL |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4294 int |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4295 dhcp_dump(struct interface *ifp) |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4296 { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4297 struct dhcp_state *state; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4298 |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4299 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
|
4300 if (state == NULL) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4301 logerr(__func__); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4302 return -1; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4303 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4304 state->new_len = read_lease(ifp, &state->new); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4305 if (state->new == NULL) { |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4306 logerr("read_lease"); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4307 return -1; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4308 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4309 state->reason = "DUMP"; |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4310 return script_runreason(ifp, state->reason); |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4311 } |
|
30958d539e6c
Restore dumping a lease from stdin
Roy Marples <roy@marples.name>
parents:
5280
diff
changeset
|
4312 #endif |
