Mercurial > hg > dhcpcd
annotate src/dhcp.c @ 5563:da781e97946d draft dhcpcd-8
DHCP: Fix reading RENEW messages from inet socket
It helps to use the correct buffer to store the control message ....
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Sun, 20 Dec 2020 07:08:08 +0000 |
| parents | f5dbfb2af80c |
| 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 |
| 4333 | 4 * Copyright (c) 2006-2019 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 #include <sys/stat.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
32 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
33 #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
|
34 #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
|
35 #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
|
36 #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
|
37 #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
|
38 #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
|
39 #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
|
40 #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
|
41 #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
|
42 #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
|
43 |
| 4784 | 44 #ifdef AF_LINK |
| 45 # include <net/if_dl.h> | |
| 46 #endif | |
| 47 | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
48 #include <assert.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 <ctype.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 <errno.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 <fcntl.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 <inttypes.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 <stdbool.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
54 #include <stddef.h> |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
55 #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
|
56 #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
|
57 #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
|
58 #include <unistd.h> |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
59 #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
|
60 |
|
5037
f395aac24e9c
eloop: define eloop queue numbers in common.h
Roy Marples <roy@marples.name>
parents:
5030
diff
changeset
|
61 #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
|
62 #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
|
63 #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
|
64 #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
|
65 #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
|
66 #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
|
67 #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
|
68 #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
|
69 #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
|
70 #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
|
71 #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
|
72 #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
|
73 #include "ipv4ll.h" |
| 4010 | 74 #include "logerr.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 |
|
4900
5d4365759fbb
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
180 if (bootp == NULL || bootp_len < DHCP_MIN_LEN) { |
|
5d4365759fbb
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
181 errno = EINVAL; |
|
5d4365759fbb
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
182 return NULL; |
|
5d4365759fbb
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
183 } |
|
5d4365759fbb
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4829
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: |
|
4903
2a001af002fe
DHCP: dl is always >0 at this point, so remove check.
Roy Marples <roy@marples.name>
parents:
4900
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; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
505 if (dl != 0) { |
|
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)) && |
|
23ff91710a01
dhcp: Don't set ciaddr or unicast if the address we have is faked.
Roy Marples <roy@marples.name>
parents:
4187
diff
changeset
|
780 !(state->added & STATE_FAKE)))) |
|
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; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
784 bootp->htype = (uint8_t)ifp->family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
785 switch (ifp->family) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
786 case ARPHRD_ETHER: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
787 case ARPHRD_IEEE802: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
788 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
|
789 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
|
790 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
791 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
792 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
793 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
|
794 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
|
795 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
|
796 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 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
|
798 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
799 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
|
800 struct timespec tv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
801 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
802 clock_gettime(CLOCK_MONOTONIC, &tv); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
803 timespecsub(&tv, &state->started, &tv); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
804 if (tv.tv_sec < 0 || tv.tv_sec > (time_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
|
805 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
|
806 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
807 bootp->secs = htons((uint16_t)tv.tv_sec); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
808 } |
|
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 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
|
811 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
812 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
|
813 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
|
814 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
815 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
|
816 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
|
817 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
818 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
|
819 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
|
820 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
|
821 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
822 *p++ = DHO_MESSAGETYPE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
823 *p++ = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
824 *p++ = type; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
825 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
826 #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
|
827 #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
|
828 #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
|
829 #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
|
830 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
|
831 *p++ = (o); \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
832 *p++ = 4; \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
833 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
|
834 p += 4; \ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
835 } 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
|
836 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
837 if (state->clientid) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
838 AREA_CHECK(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
|
839 *p++ = DHO_CLIENTID; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
840 memcpy(p, state->clientid, (size_t)state->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
|
841 p += state->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
|
842 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
843 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
844 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
|
845 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
|
846 (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
|
847 (state->addr == NULL || |
|
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
|
848 state->added & STATE_FAKE || |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
849 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
|
850 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
851 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
|
852 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
|
853 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
|
854 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
855 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
856 if (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
|
857 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
|
858 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
|
859 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
860 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
861 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
862 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
|
863 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
|
864 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
|
865 *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
|
866 *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
|
867 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
|
868 p += len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
869 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
870 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
871 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
872 if (type == DHCP_DISCOVER && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
873 !(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
|
874 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
|
875 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
876 /* RFC 4039 Section 3 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
877 AREA_CHECK(0); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
878 *p++ = DHO_RAPIDCOMMIT; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
879 *p++ = 0; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
885 /* RFC 2563 Auto Configure */ |
|
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_DISCOVER && 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
|
887 AREA_CHECK(1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
888 *p++ = DHO_AUTOCONFIGURE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
889 *p++ = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
890 *p++ = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
891 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
892 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
893 if (type == DHCP_DISCOVER || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
894 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
|
895 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
|
896 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
897 if (mtu != -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
898 AREA_CHECK(2); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
899 *p++ = DHO_MAXMESSAGESIZE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
900 *p++ = 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
901 sz = htons((uint16_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
|
902 memcpy(p, &sz, 2); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
903 p += 2; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
904 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
905 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
906 if (ifo->userclass[0]) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
907 AREA_CHECK(ifo->userclass[0]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
908 *p++ = DHO_USERCLASS; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
909 memcpy(p, ifo->userclass, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
910 (size_t)ifo->userclass[0] + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
911 p += ifo->userclass[0] + 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
912 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
913 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
914 if (ifo->vendorclassid[0]) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
915 AREA_CHECK(ifo->vendorclassid[0]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
916 *p++ = DHO_VENDORCLASSID; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
917 memcpy(p, ifo->vendorclassid, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
918 (size_t)ifo->vendorclassid[0] + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
919 p += ifo->vendorclassid[0] + 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
920 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
921 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
922 if (ifo->mudurl[0]) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
923 AREA_CHECK(ifo->mudurl[0]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
924 *p++ = DHO_MUDURL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
925 memcpy(p, ifo->mudurl, (size_t)ifo->mudurl[0] + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
926 p += ifo->mudurl[0] + 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
927 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
928 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 *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
|
933 *p++ = 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
934 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
|
935 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
|
936 p += 4; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
937 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
938 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
939 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
940 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
|
941 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
942 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
943 * 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
|
944 * 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
|
945 * 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
|
946 * 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
|
947 * 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
|
948 * 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
|
949 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
950 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
|
951 /* 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
|
952 i = 3; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
953 if (hostname) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
954 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
|
955 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
|
956 *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
|
957 *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
|
958 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
959 * Flags: 0000NEOS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
960 * 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
|
961 * 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
|
962 * 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
|
963 * 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
|
964 * 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
|
965 * 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
|
966 * update DNS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
967 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
968 if (hostname) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
969 *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
|
970 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
971 *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
|
972 *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
|
973 *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
|
974 if (hostname) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
975 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
|
976 p += i; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
977 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
978 } 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
|
979 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
|
980 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
|
981 *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
|
982 *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
|
983 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
|
984 p += len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
985 } |
|
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 /* vendor is already encoded correctly, so just add it */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
988 if (ifo->vendor[0]) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
989 AREA_CHECK(ifo->vendor[0]); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
990 *p++ = DHO_VENDOR; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
991 memcpy(p, ifo->vendor, (size_t)ifo->vendor[0] + 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
992 p += ifo->vendor[0] + 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
993 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
994 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
995 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
996 if ((ifo->auth.options & DHCPCD_AUTH_SENDREQUIRE) != |
|
4726
ac7d83882d52
DHCP: Don't send force renew none or reconf accept if not asked for
Roy Marples <roy@marples.name>
parents:
4724
diff
changeset
|
997 DHCPCD_AUTH_SENDREQUIRE && |
|
ac7d83882d52
DHCP: Don't send force renew none or reconf accept if not asked for
Roy Marples <roy@marples.name>
parents:
4724
diff
changeset
|
998 !has_option_mask(ifo->nomask, DHO_FORCERENEW_NONCE)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
999 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1000 /* We support HMAC-MD5 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1001 AREA_CHECK(1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1002 *p++ = DHO_FORCERENEW_NONCE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1003 *p++ = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1004 *p++ = AUTH_ALG_HMAC_MD5; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1005 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1006 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1007 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1008 if (ifo->vivco_len) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1009 AREA_CHECK(sizeof(ul)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1010 *p++ = DHO_VIVCO; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1011 lp = p++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1012 *lp = sizeof(ul); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1013 ul = htonl(ifo->vivco_en); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1014 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
|
1015 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
|
1016 for (i = 0, vivco = ifo->vivco; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1017 i < ifo->vivco_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1018 i++, vivco++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1019 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1020 AREA_FIT(vivco->len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1021 if (vivco->len + 2 + *lp > 255) { |
| 4010 | 1022 logerrx("%s: VIVCO option too big", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1023 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1024 free(bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1025 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1026 } |
|
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)vivco->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, vivco->data, vivco->len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1029 p += vivco->len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1030 *lp = (uint8_t)(*lp + vivco->len + 1); |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1034 AREA_CHECK(0); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1035 *p++ = DHO_PARAMETERREQUESTLIST; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1036 n_params = p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1037 *p++ = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1038 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
|
1039 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
|
1040 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1041 { |
|
4724
d64400c59a28
DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents:
4720
diff
changeset
|
1042 if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1043 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1044 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
|
1045 (opt->option == DHO_RENEWALTIME || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1046 opt->option == DHO_REBINDTIME)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1047 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1048 AREA_FIT(1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1049 *p++ = (uint8_t)opt->option; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1050 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1051 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
|
1052 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
|
1053 i++, opt++) |
|
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 /* Check if added above */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1056 for (lp = n_params + 1; lp < p; lp++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1057 if (*lp == (uint8_t)opt->option) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1058 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1059 if (lp < p) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1060 continue; |
|
4724
d64400c59a28
DHCP: Don't request an automatically requested option if not wanted
Roy Marples <roy@marples.name>
parents:
4720
diff
changeset
|
1061 if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1062 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1063 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
|
1064 (opt->option == DHO_RENEWALTIME || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1065 opt->option == DHO_REBINDTIME)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1066 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1067 AREA_FIT(1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1068 *p++ = (uint8_t)opt->option; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1069 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1070 *n_params = (uint8_t)(p - n_params - 1); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1071 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1072 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1073 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1074 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
|
1075 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
|
1076 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
|
1077 ssize_t alen = dhcp_auth_encode(&ifo->auth, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1078 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
|
1079 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
|
1080 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
|
1081 errno = ERANGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1082 alen = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1083 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1084 if (alen == -1) |
| 4010 | 1085 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
|
1086 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
|
1087 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
|
1088 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
|
1089 *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
|
1090 *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
|
1091 auth = p; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1092 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
|
1093 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1094 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1095 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1096 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1097 *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
|
1098 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
|
1099 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1100 /* 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
|
1101 * 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
|
1102 * 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
|
1103 * 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
|
1104 * 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
|
1105 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
|
1106 *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
|
1107 len++; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1108 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1109 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1110 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1111 if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len != 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1112 dhcp_auth_encode(&ifo->auth, 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
|
1113 (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
|
1114 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1115 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1116 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
|
1117 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1118 toobig: |
| 4010 | 1119 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
|
1120 free(bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1121 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1122 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1123 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1124 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
|
1125 write_lease(const struct interface *ifp, 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
|
1126 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1127 int fd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1128 ssize_t bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1129 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
|
1130 |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1131 logdebugx("%s: writing lease `%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
|
1132 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1133 fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1134 if (fd == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1135 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1136 bytes = write(fd, bootp, len); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1137 close(fd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1138 return bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1139 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1140 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1141 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
|
1142 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
|
1143 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1144 int fd; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1145 bool fd_opened; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1146 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
|
1147 struct bootp *lease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1148 size_t bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1149 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
|
1150 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1151 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
|
1152 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
|
1153 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1154 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1155 /* Safety */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1156 *bootp = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1157 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1158 if (state->leasefile[0] == '\0') { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1159 fd = fileno(stdin); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1160 fd_opened = false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1161 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1162 fd = open(state->leasefile, O_RDONLY); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1163 fd_opened = true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1164 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1165 if (fd == -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1166 if (errno != ENOENT) |
| 4010 | 1167 logerr("%s: open `%s'", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1168 ifp->name, state->leasefile); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1169 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1170 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1171 if (state->leasefile[0] == '\0') |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1172 logdebugx("reading standard input"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1173 else |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1174 logdebugx("%s: reading lease `%s'", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1175 ifp->name, state->leasefile); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1176 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1177 bytes = dhcp_read_lease_fd(fd, (void **)&lease); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1178 if (fd_opened) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1179 close(fd); |
|
4693
4c494088b85e
DHCP: Don't leak the malloc of the truncated lease file
Roy Marples <roy@marples.name>
parents:
4681
diff
changeset
|
1180 if (bytes == 0) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1181 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1182 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1183 /* 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
|
1184 * 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
|
1185 * (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
|
1186 * 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
|
1187 * scribble whatever in the stored lease file. */ |
|
4900
5d4365759fbb
DHCP: Ensure we have a lease to extract options from.
Roy Marples <roy@marples.name>
parents:
4829
diff
changeset
|
1188 if (bytes < DHCP_MIN_LEN) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1189 free(lease); |
| 4010 | 1190 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
|
1191 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1192 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1193 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1194 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
|
1195 goto out; |
|
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 /* 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
|
1198 if (get_option_uint8(ifp->ctx, &type, (struct bootp *)lease, bytes, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1199 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
|
1200 type = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1201 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1202 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1203 /* 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
|
1204 auth = get_option(ifp->ctx, (struct bootp *)lease, bytes, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1205 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
|
1206 if (auth) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1207 if (dhcp_auth_validate(&state->auth, &ifp->options->auth, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1208 lease, bytes, 4, type, auth, auth_len) == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1209 { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1210 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
|
1211 free(lease); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1212 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1213 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1214 if (state->auth.token) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1215 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
|
1216 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
|
1217 else |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1218 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
|
1219 } 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
|
1220 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
|
1221 { |
| 4010 | 1222 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
|
1223 free(lease); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1224 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1225 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1226 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1227 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1228 out: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1229 *bootp = (struct bootp *)lease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1230 return bytes; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1231 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1232 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1233 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
|
1234 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
|
1235 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1236 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
|
1237 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
|
1238 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1239 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
|
1240 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
|
1241 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1242 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1243 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
|
1244 return opt; |
|
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 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1247 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1248 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1254 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
|
1255 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
|
1256 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1257 if (od) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1258 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
|
1259 errno = EINVAL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1260 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1261 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1262 *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
|
1263 *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
|
1264 *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
|
1265 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
|
1266 errno = ERANGE; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1267 return NULL; |
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1270 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1271 *oopt = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1272 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
|
1273 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
|
1274 *oopt = opt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1275 break; |
|
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 } |
|
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 return od; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1280 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1281 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1282 ssize_t |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1283 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
|
1284 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
|
1285 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 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
|
1291 struct dhcp_opt *opt, *vo; |
|
4538
8e383f84ebd0
Remove now unused variables.
Roy Marples <roy@marples.name>
parents:
4537
diff
changeset
|
1292 size_t i, pl; |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1293 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
|
1294 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
|
1295 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
|
1296 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1297 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
|
1298 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
|
1299 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
|
1300 overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1301 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1302 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
|
1303 /* 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
|
1304 * 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
|
1305 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
|
1306 if (efprintf(fenv, "%s_ip_address=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1307 prefix, inet_ntoa(addr)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1308 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
|
1309 if (get_option_addr(ifp->ctx, &net, |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1310 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
|
1311 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
|
1312 if (efprintf(fenv, "%s_subnet_mask=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1313 prefix, inet_ntoa(net)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1314 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
|
1315 } |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1316 if (efprintf(fenv, "%s_subnet_cidr=%d", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1317 prefix, inet_ntocidr(net))== -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1318 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
|
1319 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
|
1320 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
|
1321 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1322 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
|
1323 if (efprintf(fenv, "%s_broadcast_address=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1324 prefix, inet_ntoa(brd)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1325 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
|
1326 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1327 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
|
1328 if (efprintf(fenv, "%s_network_number=%s", |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1329 prefix, inet_ntoa(addr)) == -1) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1330 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
|
1331 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1332 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1333 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
|
1334 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
|
1335 bootp->file, sizeof(bootp->file)); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1336 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
|
1337 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
|
1338 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1339 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
|
1340 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
|
1341 bootp->sname, sizeof(bootp->sname)); |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1342 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
|
1343 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
|
1344 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1345 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1346 /* Zero our indexes */ |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1347 for (i = 0, opt = ifp->ctx->dhcp_opts; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1348 i < ifp->ctx->dhcp_opts_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1349 i++, opt++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1350 dhcp_zero_index(opt); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1351 for (i = 0, opt = ifp->options->dhcp_override; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1352 i < ifp->options->dhcp_override_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1353 i++, opt++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1354 dhcp_zero_index(opt); |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1355 for (i = 0, opt = ifp->ctx->vivso; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1356 i < ifp->ctx->vivso_len; |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1357 i++, opt++) |
|
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1358 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
|
1359 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1360 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
|
1361 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
|
1362 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1363 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1364 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
|
1365 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1366 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
|
1367 continue; |
| 4166 | 1368 p = get_option(ifp->ctx, bootp, bootp_len, opt->option, &pl); |
| 1369 if (p == NULL) | |
| 1370 continue; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1371 dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, |
| 4166 | 1372 opt, dhcp_getoption, p, pl); |
| 1373 | |
| 1374 if (opt->option != DHO_VIVSO || pl <= (int)sizeof(uint32_t)) | |
| 1375 continue; | |
| 1376 memcpy(&en, p, sizeof(en)); | |
| 1377 en = ntohl(en); | |
| 1378 vo = vivso_find(en, ifp); | |
| 1379 if (vo == NULL) | |
| 1380 continue; | |
| 1381 /* Skip over en + total size */ | |
| 1382 p += sizeof(en) + 1; | |
| 1383 pl -= sizeof(en) + 1; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1384 dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, |
| 4166 | 1385 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
|
1386 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1387 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1388 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
|
1389 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
|
1390 i++, opt++) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1391 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1392 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
|
1393 continue; |
| 4166 | 1394 p = get_option(ifp->ctx, bootp, bootp_len, opt->option, &pl); |
| 1395 if (p == NULL) | |
| 1396 continue; | |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1397 dhcp_envoption(ifp->ctx, fenv, prefix, ifp->name, |
| 4166 | 1398 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
|
1399 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1400 |
|
4535
f2ddefe6c69e
script: Write variables to a FILE
Roy Marples <roy@marples.name>
parents:
4524
diff
changeset
|
1401 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
|
1402 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1403 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1404 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1405 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
|
1406 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
|
1407 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1408 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
|
1409 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1410 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
|
1411 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1412 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
|
1413 /* 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
|
1414 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
|
1415 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
|
1416 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
|
1417 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
|
1418 lease->mask = ifp->options->req_mask; |
|
4207
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1419 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
|
1420 lease->brd = ifp->options->req_brd; |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1421 else |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1422 lease->brd.s_addr = |
|
d9c3c7008d20
ipv4: allow configuration of static broadcast address
Roy Marples <roy@marples.name>
parents:
4199
diff
changeset
|
1423 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
|
1424 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1425 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
|
1426 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1427 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
|
1428 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
|
1429 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
|
1430 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
|
1431 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1432 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 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
|
1439 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
|
1440 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
|
1441 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1442 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
|
1443 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
|
1444 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
|
1445 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
|
1446 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
|
1447 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
|
1448 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
|
1449 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
|
1450 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
|
1451 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
|
1452 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
|
1453 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1454 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1455 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
|
1456 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
|
1457 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1458 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
|
1459 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1460 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
|
1461 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
|
1462 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
|
1463 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1464 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1465 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1466 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1467 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
|
1468 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1469 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
|
1470 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1471 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
|
1472 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
|
1473 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
|
1474 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1475 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1476 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1477 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
|
1478 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1479 struct dhcp_state *state; |
|
4177
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1480 const struct interface *ifp1; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1481 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
|
1482 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1483 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
|
1484 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
|
1485 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
|
1486 /* 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
|
1487 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
|
1488 (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
|
1489 sizeof(state->xid)); |
|
4177
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1490 else { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1491 again: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1492 state->xid = arc4random(); |
|
4177
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1493 } |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1494 |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1495 /* Ensure it's unique */ |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1496 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
|
1497 if (ifp == ifp1) |
|
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 = D_CSTATE(ifp1)) == NULL) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1500 continue; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1501 if (state1->xid == state->xid) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1502 break; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1503 } |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1504 if (ifp1 != NULL) { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1505 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
|
1506 ifp->hwlen >= sizeof(state->xid)) |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1507 { |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1508 logerrx("%s: duplicate xid on %s", |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1509 ifp->name, ifp1->name); |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1510 return; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1511 } |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1512 goto again; |
|
bce060648873
Ensure that xid is unique across all interfaces.
Roy Marples <roy@marples.name>
parents:
4171
diff
changeset
|
1513 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1514 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1515 /* 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
|
1516 #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
|
1517 /* 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
|
1518 if (state->bpf_fd != -1) { |
|
eed6b78ac418
Log bpf_arp and bpf_bootp failures.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
1519 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
|
1520 logerr(__func__); /* try to continue */ |
|
eed6b78ac418
Log bpf_arp and bpf_bootp failures.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
1521 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1522 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1523 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1524 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1525 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1526 dhcp_close(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
|
1527 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1528 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
|
1529 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1530 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
|
1531 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1532 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1533 if (state->bpf_fd != -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1534 eloop_event_delete(ifp->ctx->eloop, state->bpf_fd); |
|
4002
c5685de01156
bpf: rewind the buffer on close
Roy Marples <roy@marples.name>
parents:
3999
diff
changeset
|
1535 bpf_close(ifp, state->bpf_fd); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1536 state->bpf_fd = -1; |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
1537 state->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
|
1538 } |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1539 if (state->udp_fd != -1) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1540 eloop_event_delete(ifp->ctx->eloop, state->udp_fd); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1541 close(state->udp_fd); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1542 state->udp_fd = -1; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1543 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1544 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1545 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
|
1546 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1547 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1548 static int |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1549 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
|
1550 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1551 int s; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1552 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
|
1553 int n; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1554 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1555 if ((s = xsocket(PF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP)) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1556 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1557 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1558 n = 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1559 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
|
1560 goto errexit; |
| 4784 | 1561 #ifdef IP_RECVIF |
| 1562 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
|
1563 goto errexit; |
| 4784 | 1564 #else |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1565 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
|
1566 goto errexit; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1567 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1568 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
|
1569 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
|
1570 sin.sin_port = htons(BOOTPC); |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1571 if (ia != NULL) |
|
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1572 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
|
1573 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
|
1574 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
|
1575 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1576 return s; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1577 |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1578 errexit: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1579 close(s); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1580 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1581 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1582 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1583 static uint16_t |
|
4675
5c59227c6c91
DHCP: Fix in_cksum for big endian
Roy Marples <roy@marples.name>
parents:
4642
diff
changeset
|
1584 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
|
1585 { |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1586 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
|
1587 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
|
1588 |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1589 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
|
1590 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
|
1591 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1592 if (len == 1) |
|
4676
d8a9fff079d6
Cast away a conversion warning with prior
Roy Marples <roy@marples.name>
parents:
4675
diff
changeset
|
1593 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
|
1594 |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1595 if (isum != NULL) |
|
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1596 *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
|
1597 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1598 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
|
1599 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
|
1600 |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
1601 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
|
1602 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1603 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1604 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
|
1605 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
|
1606 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
|
1607 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1608 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
|
1609 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
|
1610 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
|
1611 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1612 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
|
1613 return NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1614 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
|
1615 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
|
1616 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1617 /* 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
|
1618 * 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
|
1619 * 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
|
1620 * 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
|
1621 * 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
|
1622 * 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
|
1623 * 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
|
1624 * 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
|
1625 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1626 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
|
1627 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1628 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
|
1629 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
|
1630 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
|
1631 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
|
1632 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1633 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
|
1634 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1635 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
|
1636 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
|
1637 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
|
1638 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
|
1639 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
|
1640 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1641 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
|
1642 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
|
1643 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
|
1644 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
|
1645 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
|
1646 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
|
1647 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
|
1648 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
|
1649 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1650 *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
|
1651 return udpp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1652 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1653 |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1654 static ssize_t |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1655 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
|
1656 { |
| 4784 | 1657 struct sockaddr_in sin = { |
| 1658 .sin_family = AF_INET, | |
| 1659 .sin_addr = *to, | |
| 1660 .sin_port = htons(BOOTPS), | |
| 1661 #ifdef HAVE_SA_LEN | |
| 1662 .sin_len = sizeof(sin), | |
| 1663 #endif | |
| 1664 }; | |
| 1665 struct iovec iov[] = { | |
| 1666 { .iov_base = data, .iov_len = len } | |
| 1667 }; | |
| 1668 struct msghdr msg = { | |
| 1669 .msg_name = (void *)&sin, | |
| 1670 .msg_namelen = sizeof(sin), | |
| 1671 .msg_iov = iov, | |
| 1672 .msg_iovlen = 1, | |
| 1673 }; | |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1674 struct dhcp_state *state = D_STATE(ifp); |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1675 ssize_t r; |
| 4784 | 1676 int fd; |
| 1677 | |
| 1678 fd = state->udp_fd; | |
| 1679 if (fd == -1) { | |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1680 fd = dhcp_openudp(state->addr != NULL ?&state->addr->addr:NULL); |
| 4784 | 1681 if (fd == -1) |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1682 return -1; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1683 } |
| 4784 | 1684 r = sendmsg(fd, &msg, 0); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
1685 if (state->udp_fd == -1) |
| 4784 | 1686 close(fd); |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1687 return r; |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1688 } |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1689 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1690 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1691 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
|
1692 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
|
1693 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1694 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
|
1695 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
|
1696 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
|
1697 struct bootp_pkt *udp; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1698 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
|
1699 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
|
1700 struct in_addr from, to; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1701 struct timespec tv; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1702 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1703 if (!callback) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1704 /* No carrier? Don't bother sending the packet. */ |
|
4355
226e00ec9457
link: introduce LINK_DOWN_IFFUP
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
1705 if (ifp->carrier <= LINK_DOWN) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1706 return; |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1707 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
|
1708 ifp->name, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1709 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
|
1710 state->xid); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1711 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1712 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
|
1713 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
|
1714 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1715 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
|
1716 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
|
1717 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
|
1718 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1719 tv.tv_sec = state->interval + DHCP_RAND_MIN; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1720 tv.tv_nsec = (suseconds_t)arc4random_uniform( |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1721 (DHCP_RAND_MAX - DHCP_RAND_MIN) * NSEC_PER_SEC); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1722 timespecnorm(&tv); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1723 /* 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
|
1724 * However, we do need to advance the timeout. */ |
|
4355
226e00ec9457
link: introduce LINK_DOWN_IFFUP
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
1725 if (ifp->carrier <= LINK_DOWN) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1726 goto fail; |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1727 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
|
1728 ifp->name, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1729 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
|
1730 state->xid, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1731 timespec_to_double(&tv)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1732 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1733 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1734 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
|
1735 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
|
1736 goto fail; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1737 len = (size_t)r; |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1738 |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1739 if (!(state->added & STATE_FAKE) && |
|
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1740 state->addr != NULL && |
|
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
1741 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
|
1742 from.s_addr = state->lease.addr.s_addr; |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1743 else |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1744 from.s_addr = INADDR_ANY; |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1745 if (from.s_addr != INADDR_ANY && |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1746 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
|
1747 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
|
1748 else |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1749 to.s_addr = INADDR_BROADCAST; |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1750 |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1751 /* |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1752 * 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
|
1753 * only receive broadcast messages via BPF. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1754 * 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
|
1755 * even if they are setup to send them. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1756 * 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
|
1757 * and on BSD, at least, is reliant on the subnet route being |
| 4825 | 1758 * correctly configured to receive the unicast reply. |
|
4719
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1759 * 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
|
1760 * 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
|
1761 * 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
|
1762 * interface via IP_PKTINFO unlike for IPv6. |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1763 */ |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1764 if (to.s_addr != INADDR_BROADCAST) |
|
bb76c20ed3ac
DHCP: Improve from/to address selection
Roy Marples <roy@marples.name>
parents:
4718
diff
changeset
|
1765 { |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1766 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
|
1767 goto out; |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1768 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
|
1769 } |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1770 |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1771 if (dhcp_openbpf(ifp) == -1) |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1772 goto out; |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1773 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1774 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
|
1775 if (udp == NULL) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1776 logerr("%s: dhcp_makeudppacket", ifp->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1777 r = 0; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1778 } else { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1779 r = bpf_send(ifp, state->bpf_fd, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1780 ETHERTYPE_IP, (uint8_t *)udp, ulen); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1781 free(udp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1782 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1783 /* 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
|
1784 * 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
|
1785 * for this interface. |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1786 * 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
|
1787 * stopping the interface. */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1788 if (r == -1) { |
| 4784 | 1789 logerr("%s: bpf_send", ifp->name); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1790 switch(errno) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1791 case ENETDOWN: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1792 case ENETRESET: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1793 case ENETUNREACH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1794 case ENOBUFS: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1795 break; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1796 default: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1797 if (!(ifp->ctx->options & DHCPCD_TEST)) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1798 dhcp_drop(ifp, "FAIL"); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1799 eloop_timeout_delete(ifp->ctx->eloop, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1800 NULL, ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
1801 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
|
1802 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1803 } |
|
4187
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1804 |
|
73de5e0edf30
dhcp: when unicasting, don't use a L2 broadcast
Roy Marples <roy@marples.name>
parents:
4177
diff
changeset
|
1805 out: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1806 free(bootp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1807 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1808 fail: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1809 /* 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
|
1810 * as our failure timeouts will change out codepath when needed. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1811 if (callback) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1812 eloop_timeout_add_tv(ifp->ctx->eloop, &tv, callback, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1813 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1814 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1815 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1816 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
|
1817 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1818 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1819 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
|
1820 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1821 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1822 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1823 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
|
1824 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1825 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1826 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
|
1827 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1828 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1829 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1830 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
|
1831 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1832 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1833 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
|
1834 } |
|
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 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1837 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
|
1838 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1839 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1840 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
|
1841 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1842 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1843 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1844 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
|
1845 { |
|
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 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
|
1848 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1849 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1850 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1851 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
|
1852 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1853 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
|
1854 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
|
1855 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
|
1856 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1857 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
|
1858 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
|
1859 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
|
1860 if (ifo->fallback) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1861 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
|
1862 ifo->reboot, dhcp_fallback, ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1863 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1864 else 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
|
1865 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
|
1866 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
|
1867 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1868 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
|
1869 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
|
1870 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
|
1871 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
|
1872 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
|
1873 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
|
1874 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
|
1875 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1876 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1877 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1878 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
|
1879 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1880 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
|
1881 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
|
1882 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1883 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
|
1884 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
|
1885 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1886 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1887 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1888 dhcp_expire1(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
|
1889 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1890 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
|
1891 |
|
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); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1893 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
|
1894 unlink(state->leasefile); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1895 state->interval = 0; |
|
4355
226e00ec9457
link: introduce LINK_DOWN_IFFUP
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
1896 if (!(ifp->options->options & DHCPCD_LINK) || ifp->carrier > LINK_DOWN) |
|
4102
36a663818cb0
Only start discovery on lease expiration if we have a carrier.
Roy Marples <roy@marples.name>
parents:
4077
diff
changeset
|
1897 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
|
1898 } |
| 4104 | 1899 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1900 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1901 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
|
1902 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1903 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
|
1904 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1905 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
|
1906 logwarnx("%s: DHCP lease expired, extending lease", ifp->name); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1907 return; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1908 } |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1909 |
| 4010 | 1910 logerrx("%s: DHCP lease expired", 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
|
1911 dhcp_expire1(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1912 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1913 |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
1914 #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
|
1915 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1916 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
|
1917 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1918 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1919 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
|
1920 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1921 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1922 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1923 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1924 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
|
1925 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1926 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
|
1927 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
|
1928 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
|
1929 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1930 if ((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
|
1931 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1932 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1933 /* 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
|
1934 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
|
1935 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
|
1936 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1937 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1938 /* 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
|
1939 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
|
1940 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1941 lease = &state->lease; |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
1942 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
|
1943 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
|
1944 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
|
1945 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
|
1946 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
|
1947 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
|
1948 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1949 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1950 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1951 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
|
1952 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1953 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1954 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
|
1955 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1956 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1957 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1958 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
|
1959 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1960 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
|
1961 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
|
1962 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
|
1963 |
| 4010 | 1964 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
|
1965 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
|
1966 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
|
1967 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
|
1968 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
|
1969 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
|
1970 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
|
1971 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
|
1972 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
|
1973 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
|
1974 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1975 |
|
4584
978e3fbbec6c
Fix compile on Linux without ARPING
Roy Marples <roy@marples.name>
parents:
4581
diff
changeset
|
1976 #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
|
1977 static void |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1978 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
|
1979 { |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1980 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
|
1981 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1982 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
|
1983 return; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1984 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
|
1985 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1986 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
1987 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
|
1988 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
|
1989 dhcp_bind(ifp); |
| 4485 | 1990 #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
|
1991 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1992 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
|
1993 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
|
1994 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
1995 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
|
1996 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
|
1997 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
|
1998 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
|
1999 get_lease(ifp, &state->lease, state->new, state->new_len); |
| 4457 | 2000 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
|
2001 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
|
2002 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
|
2003 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2004 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2005 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2006 /* If we forked, stop here. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2007 if (ifp->ctx->options & DHCPCD_FORKED) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2008 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2009 |
|
4287
2b519911f230
dhcp: Fix more fallout for builds without IPv4LL
Roy Marples <roy@marples.name>
parents:
4278
diff
changeset
|
2010 #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
|
2011 /* 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
|
2012 ipv4ll_drop(ifp); |
|
4287
2b519911f230
dhcp: Fix more fallout for builds without IPv4LL
Roy Marples <roy@marples.name>
parents:
4278
diff
changeset
|
2013 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2014 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2015 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
|
2016 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
|
2017 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2018 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2019 |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2020 static bool |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2021 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
|
2022 { |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2023 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
|
2024 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
|
2025 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
|
2026 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
|
2027 #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
|
2028 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
|
2029 #endif |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2030 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2031 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
|
2032 !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
|
2033 return deleted; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2034 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2035 /* 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
|
2036 logerrx("%s: DAD detected %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
|
2037 unlink(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
|
2038 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
|
2039 dhcp_decline(ifp); |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2040 #ifdef IN_IFF_DUPLICATED |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2041 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
|
2042 ipv4_deladdr(iap, 0); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2043 deleted = true; |
|
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
2044 } |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2045 #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
|
2046 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
|
2047 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
|
2048 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
|
2049 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
|
2050 #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
|
2051 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
|
2052 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
|
2053 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
|
2054 } |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2055 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
|
2056 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
|
2057 return deleted; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2058 } |
|
4584
978e3fbbec6c
Fix compile on Linux without ARPING
Roy Marples <roy@marples.name>
parents:
4581
diff
changeset
|
2059 #endif |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2060 |
|
4585
745c62847a59
Fix compile on NetBSD with ARP but not ARPING
Roy Marples <roy@marples.name>
parents:
4584
diff
changeset
|
2061 #if defined(ARP) && (!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
|
2062 static void |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2063 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
|
2064 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2065 struct interface *ifp; |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2066 #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
|
2067 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
|
2068 struct if_options *ifo; |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2069 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2070 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2071 ifp = astate->iface; |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2072 #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
|
2073 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
|
2074 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
|
2075 if (ifo->arping_len && 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
|
2076 /* 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
|
2077 * 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
|
2078 * arping profile */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2079 if (++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
|
2080 astate->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
|
2081 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
|
2082 arp_probe(astate); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2083 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2084 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2085 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
|
2086 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
|
2087 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2088 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2089 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2090 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2091 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
|
2092 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2093 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2094 static void |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2095 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
|
2096 { |
| 4457 | 2097 struct in_addr addr; |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2098 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
|
2099 #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
|
2100 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
|
2101 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
|
2102 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2103 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
|
2104 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2105 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
|
2106 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
|
2107 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
|
2108 amsg && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2109 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
|
2110 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2111 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
|
2112 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2113 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
|
2114 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
|
2115 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
|
2116 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2117 /* 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
|
2118 * 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
|
2119 * arping profile */ |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2120 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
|
2121 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2122 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2123 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
|
2124 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
|
2125 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
|
2126 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2127 } |
|
4581
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2128 #else |
|
f069d6d7f542
Fix build without ARP and/or ARPING
Roy Marples <roy@marples.name>
parents:
4567
diff
changeset
|
2129 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
|
2130 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2131 |
| 4457 | 2132 addr = astate->addr; |
| 2133 arp_free(astate); | |
|
4567
dda61c0a55f5
DHCP: On ARP duplication, ensure the interface pointer is valid
Roy Marples <roy@marples.name>
parents:
4562
diff
changeset
|
2134 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
|
2135 } |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2136 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2137 #ifdef KERNEL_RFC5227 |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2138 static void |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2139 dhcp_arp_announced(struct arp_state *state) |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2140 { |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2141 |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2142 arp_free(state); |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2143 } |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2144 #endif /* KERNEL_RFC5227 */ |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2145 #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
|
2146 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2147 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2148 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
|
2149 { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2150 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
|
2151 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
|
2152 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
|
2153 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
|
2154 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2155 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
|
2156 /* 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
|
2157 * 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
|
2158 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
|
2159 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
|
2160 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
|
2161 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
|
2162 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
|
2163 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
|
2164 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
|
2165 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
|
2166 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2167 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
|
2168 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
|
2169 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
|
2170 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
|
2171 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
|
2172 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
|
2173 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
|
2174 } 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
|
2175 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
|
2176 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
|
2177 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
|
2178 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
|
2179 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2180 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
|
2181 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
|
2182 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
|
2183 lease->renewaltime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2184 lease->rebindtime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2185 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
|
2186 loginfox("%s: leased %s for infinity", |
| 4010 | 2187 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
|
2188 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2189 if (lease->leasetime < DHCP_MIN_LEASE) { |
| 4010 | 2190 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
|
2191 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
|
2192 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
|
2193 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2194 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
|
2195 lease->rebindtime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2196 (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
|
2197 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
|
2198 lease->rebindtime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2199 (uint32_t)(lease->leasetime * T2); |
| 4010 | 2200 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
|
2201 "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
|
2202 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
|
2203 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2204 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
|
2205 lease->renewaltime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2206 (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
|
2207 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
|
2208 lease->renewaltime = |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2209 (uint32_t)(lease->leasetime * T1); |
| 4010 | 2210 logwarnx("%s: renewal time greater than " |
| 2211 "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
|
2212 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
|
2213 } |
| 4010 | 2214 if (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
|
2215 lease->addr.s_addr == state->addr->addr.s_addr && |
| 4010 | 2216 !(state->added & STATE_FAKE)) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
2217 logdebugx("%s: leased %s for %"PRIu32" seconds", |
| 4010 | 2218 ifp->name, inet_ntoa(lease->addr), |
| 2219 lease->leasetime); | |
| 2220 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
|
2221 loginfox("%s: leased %s for %"PRIu32" seconds", |
| 4010 | 2222 ifp->name, inet_ntoa(lease->addr), |
| 2223 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
|
2224 } |
|
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 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
|
2227 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
|
2228 script_runreason(ifp, state->reason); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2229 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
|
2230 return; |
|
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 if (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 (state->old && !(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
|
2234 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
|
2235 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
|
2236 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
|
2237 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
|
2238 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2239 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
|
2240 } 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
|
2241 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
|
2242 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2243 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
|
2244 } |
|
4555
93b4eb29d297
DHCP: Set address vltime and pltime to the length of the lease
Roy Marples <roy@marples.name>
parents:
4549
diff
changeset
|
2245 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
|
2246 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
|
2247 else { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2248 eloop_timeout_add_sec(ctx->eloop, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2249 (time_t)lease->renewaltime, dhcp_startrenew, ifp); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2250 eloop_timeout_add_sec(ctx->eloop, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2251 (time_t)lease->rebindtime, dhcp_rebind, ifp); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2252 eloop_timeout_add_sec(ctx->eloop, |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2253 (time_t)lease->leasetime, dhcp_expire, ifp); |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
2254 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
|
2255 " seconds", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2256 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
|
2257 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2258 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
|
2259 if (!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
|
2260 !(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
|
2261 if (write_lease(ifp, state->new, state->new_len) == -1) |
| 4010 | 2262 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
|
2263 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2264 ipv4_applyaddr(ifp); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2265 |
|
4681
c0b19aa0ee47
DHCP: Don't listen on the unspecified address when not in master mode
Roy Marples <roy@marples.name>
parents:
4677
diff
changeset
|
2266 /* 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
|
2267 * on a UDP socket. */ |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2268 if (!(state->udp_fd == -1 || |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2269 (state->old != NULL && state->old->yiaddr != state->new->yiaddr))) |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2270 return; |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2271 dhcp_close(ifp); |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2272 |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2273 |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2274 /* If not in master mode, open an address specific socket. */ |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2275 if (ctx->udp_fd != -1) |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2276 return; |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2277 state->udp_fd = dhcp_openudp(&state->addr->addr); |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2278 if (state->udp_fd == -1) { |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2279 logerr(__func__); |
|
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2280 /* 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
|
2281 * 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
|
2282 * 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
|
2283 * 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
|
2284 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
|
2285 return; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
2286 } |
|
4792
ed9e1c73478f
DHCP: Rework closing BPF and seeing if we need to open UDP
Roy Marples <roy@marples.name>
parents:
4791
diff
changeset
|
2287 eloop_event_add(ctx->eloop, state->udp_fd, 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
|
2288 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2289 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2290 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2291 dhcp_lastlease(void *arg) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2292 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2293 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
|
2294 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
|
2295 |
|
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
|
2296 loginfox("%s: timed out contacting a DHCP server, using last lease", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2297 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2298 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
|
2299 /* If we forked, stop here. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2300 if (ifp->ctx->options & DHCPCD_FORKED) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2301 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2302 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
|
2303 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
|
2304 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2305 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2306 static size_t |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2307 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
|
2308 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
|
2309 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2310 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
|
2311 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
|
2312 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2313 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
|
2314 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2315 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2316 (*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
|
2317 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
|
2318 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2319 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
|
2320 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
|
2321 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
|
2322 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2323 if (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
|
2324 *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
|
2325 *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
|
2326 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
|
2327 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
|
2328 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2329 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2330 *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
|
2331 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
|
2332 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2333 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2334 #ifdef ARP |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2335 #ifndef KERNEL_RFC5227 |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2336 static void |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2337 dhcp_arp_defend_failed(struct arp_state *astate) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2338 { |
|
4998
2d8fdeec9674
DHCP: Take interface reference on Address Defend failure
Roy Marples <roy@marples.name>
parents:
4903
diff
changeset
|
2339 struct interface *ifp = astate->iface; |
|
2d8fdeec9674
DHCP: Take interface reference on Address Defend failure
Roy Marples <roy@marples.name>
parents:
4903
diff
changeset
|
2340 |
|
2d8fdeec9674
DHCP: Take interface reference on Address Defend failure
Roy Marples <roy@marples.name>
parents:
4903
diff
changeset
|
2341 dhcp_drop(ifp, "EXPIRED"); |
|
2d8fdeec9674
DHCP: Take interface reference on Address Defend failure
Roy Marples <roy@marples.name>
parents:
4903
diff
changeset
|
2342 dhcp_start1(ifp); |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2343 } |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2344 #endif |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2345 |
|
4585
745c62847a59
Fix compile on NetBSD with ARP but not ARPING
Roy Marples <roy@marples.name>
parents:
4584
diff
changeset
|
2346 #if !defined(KERNEL_RFC5227) || defined(ARPING) |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2347 static struct arp_state * |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2348 dhcp_arp_new(struct interface *ifp, struct in_addr *addr) |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2349 { |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2350 struct arp_state *astate; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2351 |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2352 astate = arp_new(ifp, addr); |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2353 if (astate == NULL) |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2354 return NULL; |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2355 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2356 astate->found_cb = dhcp_arp_found; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2357 astate->not_found_cb = dhcp_arp_not_found; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2358 #ifdef KERNEL_RFC5227 |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2359 astate->announced_cb = dhcp_arp_announced; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2360 #else |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2361 astate->announced_cb = NULL; |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2362 astate->defend_failed_cb = dhcp_arp_defend_failed; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2363 #endif |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2364 return astate; |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
2365 } |
|
4585
745c62847a59
Fix compile on NetBSD with ARP but not ARPING
Roy Marples <roy@marples.name>
parents:
4584
diff
changeset
|
2366 #endif |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2367 #endif /* ARP */ |
|
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2368 |
|
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2369 #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
|
2370 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2371 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
|
2372 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2373 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
|
2374 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
|
2375 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
|
2376 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2377 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
|
2378 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2379 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
|
2380 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
|
2381 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
|
2382 /* 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
|
2383 * 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
|
2384 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
|
2385 #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
|
2386 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
|
2387 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
|
2388 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
|
2389 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
|
2390 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2391 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
|
2392 /* 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
|
2393 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
|
2394 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
|
2395 } 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
|
2396 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
|
2397 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
|
2398 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
|
2399 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
|
2400 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2401 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2402 #else |
|
4630
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2403 if (!(ifp->flags & IFF_NOARP) && |
|
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2404 ifp->options->options & DHCPCD_ARP && |
|
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2405 ia == NULL) |
|
fe510f5ee194
ARP: Respect IFF_NOARP interface flag more
Roy Marples <roy@marples.name>
parents:
4617
diff
changeset
|
2406 { |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2407 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
|
2408 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
|
2409 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2410 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
|
2411 if (astate == NULL) |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2412 return -1; |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2413 |
|
4191
30f5f070a4aa
dhcp: set probe state only when probing.
Roy Marples <roy@marples.name>
parents:
4188
diff
changeset
|
2414 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
|
2415 get_lease(ifp, &l, state->offer, state->offer_len); |
|
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
|
2416 loginfox("%s: probing 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
|
2417 ifp->name, inet_ntoa(l.addr), inet_ntocidr(l.mask)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2418 /* We need to handle DAD. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2419 arp_probe(astate); |
|
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 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2423 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2424 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2425 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2426 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2427 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2428 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
|
2429 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2430 |
|
4425
7cd9fb2bbbe3
DHCP: Dont really add static address in test mode
Roy Marples <roy@marples.name>
parents:
4377
diff
changeset
|
2431 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
|
2432 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
|
2433 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
|
2434 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2435 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2436 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2437 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2438 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
|
2439 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2440 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
|
2441 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
|
2442 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
|
2443 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2444 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
|
2445 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
|
2446 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2447 ia = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2448 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
|
2449 (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
|
2450 { |
|
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
|
2451 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
|
2452 "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
|
2453 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
|
2454 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
|
2455 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2456 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2457 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2458 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
|
2459 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
|
2460 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
|
2461 if (state->offer_len) |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
2462 #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
|
2463 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
|
2464 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2465 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
|
2466 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2467 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2468 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2469 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2470 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
|
2471 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2472 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
|
2473 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
|
2474 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
|
2475 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2476 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
|
2477 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
|
2478 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2479 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
|
2480 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
|
2481 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
|
2482 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
|
2483 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2484 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
|
2485 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
|
2486 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
|
2487 loginfox("%s: waiting for 3rd party to " |
| 4010 | 2488 "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
|
2489 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2490 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
|
2491 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
|
2492 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
|
2493 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2494 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2495 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2496 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2497 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
|
2498 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
|
2499 if (ifp->ctx->options & DHCPCD_TEST) { |
| 4010 | 2500 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
|
2501 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2502 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2503 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2504 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
|
2505 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
|
2506 /* 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
|
2507 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
|
2508 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
|
2509 &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
|
2510 #ifdef ARP |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
2511 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
|
2512 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2513 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2514 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
|
2515 &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
|
2516 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
|
2517 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2518 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2519 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2520 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
|
2521 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
|
2522 &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
|
2523 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
|
2524 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
|
2525 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
|
2526 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
|
2527 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2528 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2529 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2530 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2531 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
|
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 = 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
|
2535 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2536 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
|
2537 return; |
|
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 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
|
2540 (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
|
2541 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
|
2542 (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
|
2543 !(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
|
2544 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2545 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
|
2546 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2547 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2548 |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2549 #ifdef ARP |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2550 static int |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2551 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
|
2552 { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2553 const struct interface *ifp1; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2554 const struct dhcp_state *state; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2555 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2556 TAILQ_FOREACH(ifp1, ifp->ctx->ifaces, next) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2557 if (ifp1 == ifp) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2558 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2559 if ((state = D_CSTATE(ifp1)) == NULL) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2560 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2561 switch(state->state) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2562 case DHS_REBOOT: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2563 case DHS_RENEW: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2564 case DHS_REBIND: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2565 case DHS_BOUND: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2566 case DHS_INFORM: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2567 break; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2568 default: |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2569 continue; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2570 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2571 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
|
2572 return 1; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2573 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2574 return 0; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2575 } |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2576 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2577 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2578 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2579 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
|
2580 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2581 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
|
2582 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
|
2583 #ifdef ARP |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2584 struct ipv4_addr *ia; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2585 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2586 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2587 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
|
2588 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2589 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
|
2590 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
|
2591 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
|
2592 |
|
4355
226e00ec9457
link: introduce LINK_DOWN_IFFUP
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2593 if (ifo->options & DHCPCD_LINK && ifp->carrier <= LINK_DOWN) { |
|
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
|
2594 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
|
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 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
|
2598 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
|
2599 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2600 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2601 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
|
2602 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
|
2603 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
|
2604 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
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2607 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
|
2608 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
|
2609 return; |
|
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 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
|
2612 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2613 |
|
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
|
2614 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
|
2615 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
|
2616 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2617 #ifdef ARP |
|
4810
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2618 #ifndef KERNEL_RFC5227 |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2619 /* 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
|
2620 (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
|
2621 #endif |
|
88ffa4a9431f
DHCP: When rebinding ensure we have a DHCP ARP state
Roy Marples <roy@marples.name>
parents:
4792
diff
changeset
|
2622 |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2623 /* 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
|
2624 * 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
|
2625 * interface gets the reply. */ |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2626 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
|
2627 if (ia != NULL && |
|
4332
8777d91277fc
dhcp: Don't ARP announce bound addresses when testing
Roy Marples <roy@marples.name>
parents:
4299
diff
changeset
|
2628 !(ifp->ctx->options & DHCPCD_TEST) && |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2629 #ifdef IN_IFF_NOTUSEABLE |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2630 !(ia->addr_flags & IN_IFF_NOTUSEABLE) && |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2631 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2632 dhcp_activeaddr(ifp, &state->lease.addr) == 0) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2633 arp_ifannounceaddr(ifp, &state->lease.addr); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2634 #endif |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
2635 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2636 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
|
2637 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
|
2638 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
|
2639 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2640 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2641 /* 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
|
2642 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
|
2643 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
|
2644 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
|
2645 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2646 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2647 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
|
2648 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
|
2649 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
|
2650 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
|
2651 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
|
2652 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
|
2653 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2654 /* 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
|
2655 * 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
|
2656 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
|
2657 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2658 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2659 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2660 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
|
2661 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2662 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
|
2663 #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
|
2664 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
|
2665 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2666 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2667 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
|
2668 /* 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
|
2669 * 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
|
2670 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
|
2671 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
|
2672 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2673 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2674 |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2675 #ifdef ARP |
|
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2676 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
|
2677 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
|
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 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2680 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
|
2681 #endif |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
2682 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2683 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
|
2684 !(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
|
2685 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2686 /* 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
|
2687 * 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
|
2688 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
|
2689 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2690 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
|
2691 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2692 unlink(state->leasefile); |
|
4355
226e00ec9457
link: introduce LINK_DOWN_IFFUP
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
2693 if (ifp->carrier > LINK_DOWN && |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2694 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
|
2695 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
|
2696 { |
|
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
|
2697 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
|
2698 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
|
2699 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
|
2700 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
|
2701 #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
|
2702 /* 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
|
2703 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
|
2704 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
|
2705 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
|
2706 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2707 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2708 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2709 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2710 eloop_timeout_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
|
2711 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2712 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
|
2713 #endif |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2714 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2715 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
|
2716 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
|
2717 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
|
2718 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
|
2719 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
|
2720 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
|
2721 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
|
2722 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
|
2723 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
|
2724 state->reason = reason; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2725 ipv4_applyaddr(ifp); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2726 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
|
2727 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
|
2728 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
|
2729 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
|
2730 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
|
2731 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
|
2732 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2733 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2734 static int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2735 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
|
2736 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2737 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
|
2738 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2739 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
|
2740 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
|
2741 return 1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2742 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2743 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2744 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2745 #define WHTLST_NONE 0 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2746 #define WHTLST_MATCH 1 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2747 #define WHTLST_NOMATCH 2 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2748 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
|
2749 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
|
2750 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2751 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
|
2752 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2753 if (ifo->whitelist_len == 0) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2754 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
|
2755 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
|
2756 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
|
2757 return WHTLST_MATCH; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2758 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
|
2759 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2760 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2761 static void |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2762 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
|
2763 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
|
2764 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
|
2765 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2766 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
|
2767 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
|
2768 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
|
2769 int r; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2770 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
|
2771 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2772 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
|
2773 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
|
2774 if (a) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2775 char *tmp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2776 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
|
2777 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2778 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
|
2779 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
|
2780 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
|
2781 if (tmp == NULL) { |
| 4010 | 2782 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
|
2783 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2784 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2785 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2786 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
|
2787 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2788 a = tmp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2789 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2790 } 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
|
2791 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
|
2792 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
|
2793 if (a == NULL) { |
| 4010 | 2794 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
|
2795 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2796 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2797 } else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2798 a = NULL; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2799 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2800 tfrom = "from"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2801 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
|
2802 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
|
2803 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
|
2804 overl = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2805 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
|
2806 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
|
2807 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
|
2808 if (a == NULL) |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2809 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
|
2810 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
|
2811 else |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2812 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
|
2813 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
|
2814 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2815 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
|
2816 tfrom = "via"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2817 addr = *from; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2818 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2819 if (a == NULL) |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2820 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
|
2821 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
|
2822 else |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2823 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
|
2824 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
|
2825 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2826 free(a); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2827 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2828 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2829 /* 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
|
2830 * 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
|
2831 * Try and re-direct it here. */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2832 static void |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2833 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
|
2834 const struct in_addr *from) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2835 { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2836 struct interface *ifn; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2837 const struct dhcp_state *state; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2838 uint32_t xid; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2839 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2840 xid = ntohl(bootp->xid); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2841 TAILQ_FOREACH(ifn, ifp->ctx->ifaces, next) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2842 state = D_CSTATE(ifn); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2843 if (state == NULL || state->state == DHS_NONE) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2844 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2845 if (state->xid != xid) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2846 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2847 if (ifn->hwlen <= sizeof(bootp->chaddr) && |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2848 memcmp(bootp->chaddr, ifn->hwaddr, ifn->hwlen)) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2849 continue; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2850 logdebugx("%s: redirecting DHCP message to %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2851 ifp->name, ifn->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2852 dhcp_handledhcp(ifn, bootp, bootp_len, from); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2853 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2854 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2855 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2856 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2857 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
|
2858 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
|
2859 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2860 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
|
2861 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
|
2862 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
|
2863 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
|
2864 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
|
2865 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
|
2866 char *msg; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2867 bool bootp_copied; |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
2868 #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
|
2869 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
|
2870 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
|
2871 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2872 #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
|
2873 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
|
2874 #endif |
|
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 #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
|
2877 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
|
2878 #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
|
2879 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
|
2880 |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2881 #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
|
2882 (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
|
2883 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2884 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
|
2885 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
|
2886 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
|
2887 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
|
2888 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2889 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2890 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2891 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
|
2892 if (IS_STATE_ACTIVE(state)) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2893 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
|
2894 ifp->name, ntohl(bootp->xid), state->xid, |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2895 inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2896 dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2897 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2898 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2899 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2900 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
|
2901 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
|
2902 { |
|
4736
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2903 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
|
2904 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
|
2905 |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2906 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
|
2907 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
|
2908 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
|
2909 buf, sizeof(buf))); |
|
4104f563fcc3
DHCP: Don't log diagnostics when state is not running
Roy Marples <roy@marples.name>
parents:
4731
diff
changeset
|
2910 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2911 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
|
2912 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2913 } |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2914 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2915 if (!ifp->active) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2916 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2917 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2918 i = whitelisted_ip(ifp->options, from->s_addr); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2919 switch (i) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2920 case WHTLST_NOMATCH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2921 logwarnx("%s: non whitelisted DHCP packet from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2922 ifp->name, inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2923 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2924 case WHTLST_MATCH: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2925 break; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2926 case WHTLST_NONE: |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2927 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
|
2928 logwarnx("%s: blacklisted DHCP packet from %s", |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2929 ifp->name, inet_ntoa(*from)); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2930 return; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2931 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
2932 } |
|
3932
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 /* 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
|
2935 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
|
2936 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
|
2937 type = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2938 else if (ifo->options & DHCPCD_BOOTP) { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
2939 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
|
2940 ifp->name); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2941 return; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2944 #ifdef AUTH |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2945 /* 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
|
2946 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
|
2947 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
|
2948 if (auth) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2949 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
|
2950 (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
|
2951 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
|
2952 { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2953 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
|
2954 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2955 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2956 if (state->auth.token) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
2957 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
|
2958 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
|
2959 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
|
2960 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
|
2961 } 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
|
2962 if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2963 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
|
2964 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2965 } |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2966 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
|
2967 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2968 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2969 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2970 /* RFC 3203 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2971 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
|
2972 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
|
2973 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
|
2974 { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2975 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
|
2976 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2977 } |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
2978 #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
|
2979 if (auth == NULL) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2980 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
|
2981 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
|
2982 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2983 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2984 if (state->state != DHS_BOUND && state->state != DHS_INFORM) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2985 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
|
2986 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2987 } |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2988 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
|
2989 /* 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
|
2990 * 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
|
2991 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
|
2992 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
|
2993 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2994 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
|
2995 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
|
2996 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
|
2997 } |
|
3989
b05654495fd8
If auth is disabled, then disable FORCERENEW and RECONFIGURE_ACCEPT
Roy Marples <roy@marples.name>
parents:
3970
diff
changeset
|
2998 #else |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
2999 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
|
3000 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3001 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3002 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3003 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3004 if (state->state == DHS_BOUND) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3005 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
|
3006 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3007 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3008 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3009 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
|
3010 /* Ignore any DHCP messages whilst probing a lease to bind. */ |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3011 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
|
3012 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3013 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3014 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3015 /* 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
|
3016 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
|
3017 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3018 /* 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
|
3019 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
|
3020 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
|
3021 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
|
3022 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
|
3023 { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3024 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
|
3025 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3026 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3027 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3028 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3029 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
|
3030 /* 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
|
3031 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
|
3032 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
|
3033 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
|
3034 { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3035 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
|
3036 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3037 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3038 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3039 /* We should restart on a NAK */ |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3040 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
|
3041 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
|
3042 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
|
3043 { |
| 4010 | 3044 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
|
3045 free(msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3046 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3047 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
|
3048 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3049 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
|
3050 dhcp_drop(ifp, "NAK"); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3051 unlink(state->leasefile); |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3054 /* 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
|
3055 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
|
3056 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
|
3057 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
|
3058 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
|
3059 else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3060 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
|
3061 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
|
3062 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
|
3063 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3064 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3065 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3066 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3067 /* 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
|
3068 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
|
3069 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
|
3070 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
|
3071 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
|
3072 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3073 /* 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
|
3074 * 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
|
3075 * 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
|
3076 * 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
|
3077 * always true. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3078 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
|
3079 continue; |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3080 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
|
3081 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3082 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3083 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3084 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3085 /* 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
|
3086 if (type == DHCP_OFFER && bootp->yiaddr == 0) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3087 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
|
3088 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
|
3089 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
|
3090 { |
| 4010 | 3091 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
|
3092 free(msg); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3093 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3094 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3095 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
|
3096 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
|
3097 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
|
3098 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3099 switch (tmp) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3100 case 0: |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3101 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
|
3102 ipv4ll_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3103 #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
|
3104 arp_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3105 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3106 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3107 case 1: |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3108 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
|
3109 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
|
3110 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3111 default: |
| 4010 | 3112 logerrx("%s: unknown auto configuration " |
| 3113 "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
|
3114 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
|
3115 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3116 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3117 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
|
3118 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
|
3119 DHCP_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
|
3120 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3121 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3122 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3123 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3124 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3125 /* 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
|
3126 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
|
3127 (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
|
3128 && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3129 (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
|
3130 { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3131 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
|
3132 return; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3135 #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
|
3136 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
|
3137 if (ia && ia->addr_flags & IN_IFF_DUPLICATED) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3138 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
|
3139 if (type) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3140 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
|
3141 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
|
3142 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
|
3143 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
|
3144 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
|
3145 return; |
|
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 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3148 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3149 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
|
3150 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
|
3151 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
|
3152 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
|
3153 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
|
3154 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
|
3155 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
|
3156 &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
|
3157 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
|
3158 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3159 /* 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
|
3160 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
|
3161 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
|
3162 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
|
3163 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
|
3164 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3165 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
|
3166 goto rapidcommit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3167 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3168 |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3169 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
|
3170 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
|
3171 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
|
3172 if ((state->offer = malloc(bootp_len)) == NULL) { |
| 4010 | 3173 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
|
3174 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
|
3175 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3176 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3177 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3178 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
|
3179 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
|
3180 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
|
3181 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
|
3182 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
|
3183 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
|
3184 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
|
3185 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
|
3186 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
|
3187 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
|
3188 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
|
3189 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
|
3190 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
|
3191 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS); |
|
4427
960c888a8c4f
DHCP: abort BPF in test mode on receipt of message.
Roy Marples <roy@marples.name>
parents:
4425
diff
changeset
|
3192 state->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
|
3193 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3194 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3195 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
|
3196 /* 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
|
3197 if (type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3198 /* 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
|
3199 * 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
|
3200 * 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
|
3201 * 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
|
3202 * 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
|
3203 * DISCOVER. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3204 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
|
3205 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3206 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3207 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3208 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3209 if (type) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3210 if (type == DHCP_OFFER) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3211 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
|
3212 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3213 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3214 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3215 /* 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
|
3216 if (type != DHCP_ACK) { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3217 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
|
3218 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3219 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3220 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3221 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
|
3222 /* 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
|
3223 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
|
3224 DHO_RAPIDCOMMIT) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3225 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
|
3226 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
|
3227 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
|
3228 else { |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3229 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
|
3230 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3231 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3232 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3233 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3234 rapidcommit: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3235 if (!(ifo->options & DHCPCD_INFORM)) |
|
5070
55164c3f5aae
logerr: Use macros to call log functions
Sergey Nikiforov <Sergey.Nikiforov@kaspersky.com>
parents:
5053
diff
changeset
|
3236 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
|
3237 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3238 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
|
3239 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3240 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3241 /* 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
|
3242 * 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
|
3243 * 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
|
3244 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
|
3245 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3246 /* 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
|
3247 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
|
3248 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
|
3249 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
|
3250 if ((state->offer = malloc(bootp_len)) == NULL) { |
| 4010 | 3251 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
|
3252 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
|
3253 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3254 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3255 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3256 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
|
3257 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
|
3258 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3259 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3260 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
|
3261 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
|
3262 |
|
4587
02c41622154f
NetBSD: Allow dhcpcd to be built without ARP support
Roy Marples <roy@marples.name>
parents:
4585
diff
changeset
|
3263 #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
|
3264 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
|
3265 #else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3266 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
|
3267 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3268 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3269 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3270 static void * |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3271 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
|
3272 { |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3273 const struct ip *ip = packet; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3274 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
|
3275 char *p = packet; |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3276 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3277 p += ip_hl + sizeof(struct udphdr); |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3278 *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
|
3279 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
|
3280 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3281 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3282 static bool |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3283 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
|
3284 { |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3285 struct ip *ip = packet; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3286 size_t ip_hlen; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3287 struct udphdr udp; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3288 |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3289 if (plen < sizeof(*ip)) |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3290 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3291 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3292 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
|
3293 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3294 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3295 /* Sanity. */ |
|
4762
d68ac6b143c5
dhcp: Allow for trailing FCS in the packet.
Roy Marples <roy@marples.name>
parents:
4761
diff
changeset
|
3296 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
|
3297 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3298 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3299 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
|
3300 if (ip_hlen < sizeof(*ip)) |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3301 return false; |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3302 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3303 /* 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
|
3304 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
|
3305 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3306 |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3307 /* Sanity. */ |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3308 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
|
3309 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
|
3310 return false; |
| 5154 | 3311 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
|
3312 return false; |
|
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3313 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3314 /* 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
|
3315 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
|
3316 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3317 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3318 return true; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3319 } |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3320 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3321 /* Lengths have already been checked. */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3322 static bool |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3323 checksums_valid(void *packet, |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3324 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
|
3325 { |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3326 struct ip *ip = packet; |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3327 union pip { |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3328 struct ip ip; |
|
4775
9a29b37bc5cb
DHCP: Fix prior to not waste space
Sergei Trofimovich <slyfox@gentoo.org>
parents:
4773
diff
changeset
|
3329 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
|
3330 } pip = { |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3331 .ip.ip_p = IPPROTO_UDP, |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3332 .ip.ip_src = ip->ip_src, |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3333 .ip.ip_dst = ip->ip_dst, |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3334 }; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3335 size_t ip_hlen; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3336 struct udphdr udp; |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3337 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
|
3338 uint32_t csum; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3339 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3340 if (from != NULL) |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3341 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
|
3342 |
|
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3343 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
|
3344 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
|
3345 return false; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3346 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3347 if (flags & BPF_PARTIALCSUM) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3348 return true; |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3349 |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3350 udpp = (char *)ip + ip_hlen; |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3351 memcpy(&udp, udpp, sizeof(udp)); |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3352 if (udp.uh_sum == 0) |
|
4761
6fc5fe895c67
dhcp: Fix incoming verification and checksum routines
Maxime Villard <max@m00nbsd.net>
parents:
4757
diff
changeset
|
3353 return true; |
|
4605
5ed975095c4e
IP: Work with IP headers with options.
Roy Marples <roy@marples.name>
parents:
4602
diff
changeset
|
3354 |
|
4608
3aef2b50ef03
DHCP: Rework checksuming so that the packet isn't touched.
Roy Marples <roy@marples.name>
parents:
4605
diff
changeset
|
3355 /* 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
|
3356 * 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
|
3357 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
|
3358 csum = 0; |
|
4768
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3359 |
|
55d113e3c287
DHCP: Fix aliasing issues accessing the UDP header
Roy Marples <roy@marples.name>
parents:
4762
diff
changeset
|
3360 /* 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
|
3361 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
|
3362 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
|
3363 |
| 4773 | 3364 /* 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
|
3365 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
|
3366 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
|
3367 |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3368 #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
|
3369 /* Put the checksum back. */ |
|
4770
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3370 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
|
3371 #endif |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3372 |
|
e9cb321935ac
DHCP: Fix strict aliasing of checksumming the pseudo header
Roy Marples <roy@marples.name>
parents:
4768
diff
changeset
|
3373 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
|
3374 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3375 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3376 static void |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3377 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
|
3378 struct in_addr *from) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3379 { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3380 size_t v; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3381 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3382 if (len < offsetof(struct bootp, vend)) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3383 logerrx("%s: truncated packet (%zu) from %s", |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3384 ifp->name, len, inet_ntoa(*from)); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3385 return; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3386 } |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3387 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3388 /* 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
|
3389 * area has at least 4 octets. */ |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3390 v = len - offsetof(struct bootp, vend); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3391 while (v < 4) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3392 bootp->vend[v++] = '\0'; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3393 len++; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3394 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3395 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3396 dhcp_handledhcp(ifp, bootp, len, from); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3397 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3398 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3399 static void |
|
4829
0609c95174a7
DHCP: Improve API for privsep
Roy Marples <roy@marples.name>
parents:
4825
diff
changeset
|
3400 dhcp_packet(struct interface *ifp, uint8_t *data, 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
|
3401 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3402 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
|
3403 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
|
3404 size_t udp_len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3405 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
|
3406 |
|
4757
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3407 /* Validate filter. */ |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3408 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
|
3409 #ifdef BPF_DEBUG |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3410 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
|
3411 #endif |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3412 return; |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3413 } |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3414 |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3415 if (!checksums_valid(data, &from, state->bpf_flags)) { |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3416 logerrx("%s: checksum failure from %s", |
|
19c3b77a9940
BPF: Move validation logic from BPF to consumers
Roy Marples <roy@marples.name>
parents:
4738
diff
changeset
|
3417 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
|
3418 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3419 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3420 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3421 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3422 * 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
|
3423 * 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
|
3424 * 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
|
3425 * 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
|
3426 * 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
|
3427 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3428 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
|
3429 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
|
3430 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3431 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3432 static void |
|
4717
3cce06e28d99
DHCP: Rename dhcp_readpacket to dhcp_readbpf
Roy Marples <roy@marples.name>
parents:
4715
diff
changeset
|
3433 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
|
3434 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3435 struct interface *ifp = arg; |
|
5030
28bb50e31931
BPF: Don't use magic in buffer length assignments
Roy Marples <roy@marples.name>
parents:
5027
diff
changeset
|
3436 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
|
3437 ssize_t bytes; |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3438 struct dhcp_state *state = D_STATE(ifp); |
|
5025
38495dc55a10
BPF: Return the frame header with the data
Roy Marples <roy@marples.name>
parents:
4998
diff
changeset
|
3439 ssize_t fl = (ssize_t)bpf_frame_header_len(ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3440 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3441 /* Some RAW mechanisms are generic file descriptors, not sockets. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3442 * This means we have no kernel call to just get one packet, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3443 * so we have to process the entire buffer. */ |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3444 state->bpf_flags &= ~BPF_EOF; |
|
4171
4ff80b2bbba1
Fix prior patches by using correct bitmasks for flags.
Roy Marples <roy@marples.name>
parents:
4169
diff
changeset
|
3445 state->bpf_flags |= BPF_READING; |
|
4169
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3446 while (!(state->bpf_flags & BPF_EOF)) { |
|
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3447 bytes = bpf_read(ifp, state->bpf_fd, buf, sizeof(buf), |
|
07bfee79bd7a
bpf: store flags in state for a better abort
Roy Marples <roy@marples.name>
parents:
4168
diff
changeset
|
3448 &state->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
|
3449 if (bytes == -1) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3450 if (state->state != DHS_NONE) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3451 logerr("%s: %s", __func__, ifp->name); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3452 dhcp_close(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3453 } |
|
4171
4ff80b2bbba1
Fix prior patches by using correct bitmasks for flags.
Roy Marples <roy@marples.name>
parents:
4169
diff
changeset
|
3454 break; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3455 } |
|
5157
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3456 if (fl != 0) { |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3457 if (bytes < fl) { |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3458 logerrx("%s: %s: short frame header", |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3459 __func__, ifp->name); |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3460 break; |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3461 } |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3462 bytes -= fl; |
|
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3463 memmove(buf, buf + fl, (size_t)bytes); |
|
5025
38495dc55a10
BPF: Return the frame header with the data
Roy Marples <roy@marples.name>
parents:
4998
diff
changeset
|
3464 } |
|
5157
9a50ab509182
DHCP: Avoid mis-aligned BOOTP structure
Roy Marples <roy@marples.name>
parents:
5154
diff
changeset
|
3465 dhcp_packet(ifp, buf, (size_t)bytes); |
|
3970
c31023f676be
Fix a potential crash where the DHCP state could be freed during processing.
Roy Marples <roy@marples.name>
parents:
3960
diff
changeset
|
3466 /* 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
|
3467 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
|
3468 break; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3469 } |
|
4171
4ff80b2bbba1
Fix prior patches by using correct bitmasks for flags.
Roy Marples <roy@marples.name>
parents:
4169
diff
changeset
|
3470 if (state != NULL) |
|
4ff80b2bbba1
Fix prior patches by using correct bitmasks for flags.
Roy Marples <roy@marples.name>
parents:
4169
diff
changeset
|
3471 state->bpf_flags &= ~BPF_READING; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3472 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3473 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3474 static void |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3475 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
|
3476 { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3477 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
|
3478 struct iovec *iov = &msg->msg_iov[0]; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3479 struct interface *ifp; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3480 const struct dhcp_state *state; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3481 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3482 ifp = if_findifpfromcmsg(ctx, msg, NULL); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3483 if (ifp == NULL) { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3484 logerr(__func__); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3485 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3486 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3487 state = D_CSTATE(ifp); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3488 if (state == NULL) { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3489 logdebugx("%s: received BOOTP for inactive interface", |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3490 ifp->name); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3491 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3492 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3493 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3494 if (state->bpf_fd != -1) { |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3495 /* 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
|
3496 return; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3497 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3498 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3499 dhcp_handlebootp(ifp, (struct bootp *)iov->iov_base, iov->iov_len, |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3500 &from->sin_addr); |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3501 } |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3502 |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3503 static void |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3504 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
|
3505 { |
| 4602 | 3506 const struct dhcp_state *state; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3507 struct sockaddr_in from; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3508 unsigned char buf[10 * 1024]; /* Maximum MTU */ |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3509 struct iovec iov = { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3510 .iov_base = buf, |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3511 .iov_len = sizeof(buf), |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3512 }; |
| 5159 | 3513 union { |
| 3514 struct cmsghdr hdr; | |
| 4784 | 3515 #ifdef IP_RECVIF |
| 5159 | 3516 uint8_t buf[CMSG_SPACE(sizeof(struct sockaddr_dl))]; |
| 4784 | 3517 #else |
| 5159 | 3518 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
|
3519 #endif |
| 5159 | 3520 } cmsgbuf = { .buf = { 0 } }; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3521 struct msghdr msg = { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3522 .msg_name = &from, .msg_namelen = sizeof(from), |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3523 .msg_iov = &iov, .msg_iovlen = 1, |
|
5563
da781e97946d
DHCP: Fix reading RENEW messages from inet socket
Roy Marples <roy@marples.name>
parents:
5159
diff
changeset
|
3524 .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
|
3525 }; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3526 int s; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3527 ssize_t bytes; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3528 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3529 if (ifp != NULL) { |
|
4594
81f346f0e892
DHCP: Avoid duplicate read of packet
Roy Marples <roy@marples.name>
parents:
4587
diff
changeset
|
3530 state = D_CSTATE(ifp); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3531 s = state->udp_fd; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3532 } else |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3533 s = ctx->udp_fd; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3534 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3535 bytes = recvmsg(s, &msg, 0); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3536 if (bytes == -1) { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3537 logerr(__func__); |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3538 return; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3539 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3540 |
|
4787
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3541 iov.iov_len = (size_t)bytes; |
|
d3a3a2ab8ba9
Split *_recv() into *_recv() and *_recvmsg() functions
Roy Marples <roy@marples.name>
parents:
4786
diff
changeset
|
3542 dhcp_recvmsg(ctx, &msg); |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3543 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3544 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3545 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
|
3546 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
|
3547 { |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3548 struct dhcpcd_ctx *ctx = arg; |
|
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 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
|
3551 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3552 |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3553 static void |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3554 dhcp_handleifudp(void *arg) |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3555 { |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3556 struct interface *ifp = arg; |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3557 |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3558 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
|
3559 } |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3560 |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3561 static int |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3562 dhcp_open(struct dhcpcd_ctx *ctx) |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3563 { |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3564 |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3565 if (ctx->udp_fd != -1 || (ctx->udp_fd = dhcp_openudp(NULL)) == -1) |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3566 return ctx->udp_fd; |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3567 |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3568 eloop_event_add(ctx->eloop, ctx->udp_fd, dhcp_handleudp, ctx); |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3569 return ctx->udp_fd; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3570 } |
|
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3571 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3572 static int |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3573 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
|
3574 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3575 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
|
3576 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3577 state = D_STATE(ifp); |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3578 if (state->bpf_fd != -1) |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3579 return 0; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3580 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3581 state->bpf_fd = bpf_open(ifp, bpf_bootp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3582 if (state->bpf_fd == -1) { |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3583 if (errno == ENOENT) { |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3584 logerrx("%s not found", bpf_name); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3585 /* May as well disable IPv4 entirely at |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3586 * this point as we really need it. */ |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3587 ifp->options->options &= ~DHCPCD_IPV4; |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3588 } else |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3589 logerr("%s: %s", __func__, ifp->name); |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3590 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
|
3591 } |
|
4168
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3592 |
|
e8510a89cdb2
dhcp: arp announce existing address before reboot
Roy Marples <roy@marples.name>
parents:
4167
diff
changeset
|
3593 eloop_event_add(ifp->ctx->eloop, |
|
4717
3cce06e28d99
DHCP: Rename dhcp_readpacket to dhcp_readbpf
Roy Marples <roy@marples.name>
parents:
4715
diff
changeset
|
3594 state->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
|
3595 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3596 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3597 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3598 int |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3599 dhcp_dump(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
|
3600 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3601 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
|
3602 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3603 ifp->if_data[IF_DATA_DHCP] = state = calloc(1, sizeof(*state)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3604 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
|
3605 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3606 state->bpf_fd = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3607 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
|
3608 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
|
3609 state->new_len = read_lease(ifp, &state->new); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3610 if (state->new == NULL) { |
| 4010 | 3611 logerr("%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
|
3612 *ifp->name ? ifp->name : state->leasefile, __func__); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3613 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3614 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3615 state->reason = "DUMP"; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3616 return 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
|
3617 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3618 eexit: |
| 4010 | 3619 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
|
3620 return -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3621 } |
|
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 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3624 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
|
3625 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3626 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
|
3627 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
|
3628 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3629 dhcp_close(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3630 #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
|
3631 arp_drop(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
3632 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3633 if (state) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3634 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
|
3635 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
|
3636 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
|
3637 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
|
3638 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
|
3639 free(state); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3640 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3641 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3642 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
|
3643 /* 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
|
3644 * 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
|
3645 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
|
3646 TAILQ_FOREACH(ifp, ctx->ifaces, next) { |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3647 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3648 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
|
3649 break; |
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3652 if (ifp == NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3653 if (ctx->udp_fd != -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3654 eloop_event_delete(ctx->eloop, ctx->udp_fd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3655 close(ctx->udp_fd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3656 ctx->udp_fd = -1; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3657 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3658 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3659 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
|
3660 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
|
3661 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3662 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3663 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3664 static int |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3665 dhcp_initstate(struct interface *ifp) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3666 { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3667 struct dhcp_state *state; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3668 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3669 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3670 if (state != NULL) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3671 return 0; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3672 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3673 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
|
3674 state = D_STATE(ifp); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3675 if (state == NULL) |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3676 return -1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3677 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3678 state->state = DHS_NONE; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3679 /* 0 is a valid fd, so init to -1 */ |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3680 state->bpf_fd = -1; |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3681 state->udp_fd = -1; |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3682 #ifdef ARPING |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3683 state->arping_index = -1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3684 #endif |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3685 return 1; |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3686 } |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3687 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3688 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
|
3689 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
|
3690 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3691 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
|
3692 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
|
3693 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
|
3694 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
|
3695 |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
3696 if (dhcp_initstate(ifp) == -1) |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3697 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
|
3698 |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
3699 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
|
3700 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
|
3701 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
|
3702 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
|
3703 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
|
3704 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
|
3705 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3706 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
|
3707 /* 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
|
3708 * 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
|
3709 if (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
|
3710 unlink(state->leasefile); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3711 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3712 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
|
3713 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
|
3714 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3715 if (*ifo->clientid) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3716 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
|
3717 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
|
3718 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3719 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
|
3720 (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
|
3721 } 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
|
3722 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
|
3723 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
|
3724 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
|
3725 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3726 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
|
3727 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
|
3728 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
|
3729 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
|
3730 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
|
3731 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3732 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
|
3733 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
|
3734 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
|
3735 goto eexit; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3736 state->clientid[0] = len; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3737 state->clientid[1] = (uint8_t)ifp->family; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3738 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
|
3739 ifp->hwlen); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3740 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3741 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3742 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3743 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
|
3744 /* 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
|
3745 * 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
|
3746 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3747 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3748 if (ifo->options & DHCPCD_CLIENTID) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3749 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
|
3750 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
|
3751 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
|
3752 else if (ifp->hwlen) |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3753 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
|
3754 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
|
3755 return 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3756 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3757 eexit: |
| 4010 | 3758 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
|
3759 return -1; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3762 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3763 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
|
3764 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3765 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
|
3766 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
|
3767 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
|
3768 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
|
3769 struct stat st; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3770 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
|
3771 int nolease; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3772 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3773 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
|
3774 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3775 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3776 /* 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
|
3777 * 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
|
3778 * 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
|
3779 * for dhcpcd running on another interface. */ |
|
4791
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3780 if (ctx->options & DHCPCD_MASTER) { |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3781 if (dhcp_open(ctx) == -1) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3782 /* Don't log an error if some other process |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3783 * is handling this. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3784 if (errno != EADDRINUSE) |
|
4791
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3785 logerr("%s: dhcp_open", __func__); |
|
3ba8c76fc5af
DHCP: Simplify opening the UDP port for all interfaces.
Roy Marples <roy@marples.name>
parents:
4787
diff
changeset
|
3786 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3787 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3788 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3789 if (dhcp_init(ifp) == -1) { |
| 4010 | 3790 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
|
3791 return; |
|
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 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3794 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
|
3795 clock_gettime(CLOCK_MONOTONIC, &state->started); |
|
4224
595761ecbde0
dhcp: reset interval during init
Roy Marples <roy@marples.name>
parents:
4207
diff
changeset
|
3796 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
|
3797 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
|
3798 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
|
3799 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
|
3800 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3801 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3802 if (ifo->arping_len && 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
|
3803 struct arp_state *astate; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3804 |
|
4376
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
3805 astate = dhcp_arp_new(ifp, NULL); |
|
579ab74cded9
DHCP: free the ARP state of the address once announced
Roy Marples <roy@marples.name>
parents:
4374
diff
changeset
|
3806 if (astate) |
|
4453
00fb50fd1a45
ARP: Refactor so that ACD is available for all inet addresses
Roy Marples <roy@marples.name>
parents:
4427
diff
changeset
|
3807 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
|
3808 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3809 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3810 #endif |
|
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 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
|
3813 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
|
3814 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3815 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3816 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3817 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
|
3818 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
|
3819 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3820 } |
|
4373
5ebc4718f728
DHCP: Close the BPF socket once BOUND
Roy Marples <roy@marples.name>
parents:
4365
diff
changeset
|
3821 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3822 /* 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
|
3823 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
|
3824 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
|
3825 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
|
3826 /* 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
|
3827 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
|
3828 #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
|
3829 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
|
3830 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
|
3831 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3832 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
|
3833 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
|
3834 #endif |
|
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 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
|
3837 !(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
|
3838 #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
|
3839 (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
|
3840 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3841 (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
|
3842 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
|
3843 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3844 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
|
3845 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
|
3846 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
|
3847 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3848 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3849 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3850 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
|
3851 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
|
3852 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3853 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
|
3854 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
|
3855 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
|
3856 (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
|
3857 &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
|
3858 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3859 /* 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
|
3860 * 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
|
3861 * 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
|
3862 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
|
3863 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
|
3864 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
|
3865 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
|
3866 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
|
3867 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
|
3868 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
|
3869 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
|
3870 } else |
| 4010 | 3871 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
|
3872 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3873 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
|
3874 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
|
3875 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
|
3876 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
|
3877 } 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
|
3878 state->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
|
3879 stat(state->leasefile, &st) == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3880 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3881 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
|
3882 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3883 /* 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
|
3884 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
|
3885 if (now == -1 || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3886 (time_t)state->lease.leasetime < now - st.st_mtime) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3887 { |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3888 logdebugx("%s: discarding expired lease", |
| 4010 | 3889 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
|
3890 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
|
3891 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
|
3892 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
|
3893 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
|
3894 /* 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
|
3895 * 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
|
3896 * 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
|
3897 * 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
|
3898 * 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
|
3899 * 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
|
3900 * 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
|
3901 * 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
|
3902 * 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
|
3903 * 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
|
3904 * 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
|
3905 * 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
|
3906 #if 0 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3907 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
|
3908 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
|
3909 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3910 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3911 l = (uint32_t)(now - st.st_mtime); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3912 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
|
3913 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
|
3914 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
|
3915 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3916 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3917 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3918 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3919 #ifdef IPV4LL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3920 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
|
3921 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
|
3922 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
|
3923 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3924 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3925 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3926 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3927 if (state->offer == NULL || !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
|
3928 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
|
3929 else |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3930 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
|
3931 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3932 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3933 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3934 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
|
3935 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3936 struct timespec tv; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3937 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3938 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
|
3939 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3940 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3941 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
|
3942 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3943 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3944 /* 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
|
3945 * 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
|
3946 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
|
3947 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
|
3948 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
|
3949 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
|
3950 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3951 /* 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
|
3952 * length is greater than BOOTP CHADDR then we enforce a ClientID |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3953 * of the hardware address family and the hardware address. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3954 * 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
|
3955 * 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
|
3956 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
|
3957 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
|
3958 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
|
3959 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
|
3960 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3961 /* 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
|
3962 * the broadcast option being set. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3963 switch (ifp->family) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3964 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
|
3965 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
|
3966 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
|
3967 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3968 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3969 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3970 /* 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
|
3971 * 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
|
3972 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
|
3973 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
|
3974 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3975 /* 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
|
3976 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
|
3977 !(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
|
3978 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3979 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
|
3980 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3981 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3982 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3983 #ifdef ARPING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3984 /* 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
|
3985 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
|
3986 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
|
3987 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
|
3988 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3989 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3990 #endif |
|
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 tv.tv_sec = DHCP_MIN_DELAY; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3993 tv.tv_nsec = (suseconds_t)arc4random_uniform( |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3994 (DHCP_MAX_DELAY - DHCP_MIN_DELAY) * NSEC_PER_SEC); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3995 timespecnorm(&tv); |
|
4023
66f9399ba5c6
Add logdebugx, similar to logerrx and logwarnx.
Roy Marples <roy@marples.name>
parents:
4014
diff
changeset
|
3996 logdebugx("%s: delaying IPv4 for %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
|
3997 ifp->name, timespec_to_double(&tv)); |
|
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 eloop_timeout_add_tv(ifp->ctx->eloop, &tv, 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
|
4000 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4001 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4002 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4003 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
|
4004 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4005 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
|
4006 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4007 state = D_STATE(ifp); |
|
4135
64796240ee75
arp: RFC5227 kernels need to send ARP too
Roy Marples <roy@marples.name>
parents:
4125
diff
changeset
|
4008 #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
|
4009 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
|
4010 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
|
4011 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4012 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4013 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
|
4014 |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4015 if (state != NULL && state->added) { |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4016 rt_build(ifp->ctx, AF_INET); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4017 #ifdef ARP |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4018 arp_announceaddr(ifp->ctx, &state->addr->addr); |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4019 #endif |
|
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4020 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4021 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4022 |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4023 struct ipv4_addr * |
|
4232
8b92c1844860
Log the pid of the process deleting an assigned address.
Roy Marples <roy@marples.name>
parents:
4224
diff
changeset
|
4024 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
|
4025 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4026 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
|
4027 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
|
4028 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
|
4029 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
|
4030 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4031 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
|
4032 state = D_STATE(ifp); |
|
4113
d30461d23e91
Persist shared IP address on interfaces.
Roy Marples <roy@marples.name>
parents:
4108
diff
changeset
|
4033 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
|
4034 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
|
4035 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4036 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
|
4037 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
|
4038 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
|
4039 ifp->name, pid, ia->saddr); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4040 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
|
4041 /* 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
|
4042 * 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
|
4043 dhcp_drop(ifp, "EXPIRE"); |
|
4242
9f4dc610f30c
Really start dhcp on deletion of address.
Roy Marples <roy@marples.name>
parents:
4240
diff
changeset
|
4044 dhcp_start1(ifp); |
|
4782
8a9ec0631165
INET: Fix a potential memory leak
Roy Marples <roy@marples.name>
parents:
4775
diff
changeset
|
4045 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
|
4046 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4047 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4048 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4049 if (cmd != RTM_NEWADDR) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4050 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
|
4051 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4052 #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
|
4053 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
|
4054 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
|
4055 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
|
4056 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
|
4057 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4058 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4059 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
|
4060 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
|
4061 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
|
4062 dhcp_inform(ifp); |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4063 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
|
4064 } |
|
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 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
|
4067 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
|
4068 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
|
4069 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
|
4070 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4071 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
|
4072 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
|
4073 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
|
4074 if (state->new == NULL) |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4075 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
|
4076 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
|
4077 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
|
4078 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
|
4079 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
|
4080 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
4081 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
|
4082 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
|
4083 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
|
4084 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
|
4085 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
|
4086 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
|
4087 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
|
4088 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
|
4089 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
|
4090 } |
|
4737
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4091 |
|
65679ce5c370
inet: Rework prior incase DHCP uses an IPv4LL address
Roy Marples <roy@marples.name>
parents:
4736
diff
changeset
|
4092 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
|
4093 } |
