1 /* SPDX-License-Identifier: BSD-2-Clause */
3 * dhcpcd - DHCP client daemon
4 * Copyright (c) 2006-2023 Roy Marples <roy@marples.name>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/socket.h>
38 #ifdef HAVE_SYS_QUEUE_H
39 #include <sys/queue.h>
44 #include "if-options.h"
48 #define PROFILE_LEN 64
53 #define IF_ACTIVE_USER 2
56 #define LINK_UNKNOWN 0
59 #define IF_DATA_IPV4 0
61 #define IF_DATA_IPV4LL 2
62 #define IF_DATA_DHCP 3
63 #define IF_DATA_IPV6 4
64 #define IF_DATA_IPV6ND 5
65 #define IF_DATA_DHCP6 6
69 /* QNX carries defines for, but does not actually support PF_LINK */
74 struct dhcpcd_ctx
*ctx
;
75 TAILQ_ENTRY(interface
) next
;
76 char name
[IF_NAMESIZE
];
80 uint16_t hwtype
; /* ARPHRD_ETHER for example */
81 unsigned char hwaddr
[HWADDR_LEN
];
83 unsigned short vlanid
;
87 uint8_t ssid
[IF_SSIDLEN
];
88 unsigned int ssid_len
;
90 char profile
[PROFILE_LEN
];
91 struct if_options
*options
;
92 void *if_data
[IF_DATA_MAX
];
94 TAILQ_HEAD(if_head
, interface
);
98 /* dhcpcd requires CMSG_SPACE to evaluate to a compile time constant. */
99 #if defined(__QNX) || \
100 (defined(__NetBSD_Version__) && __NetBSD_Version__ < 600000000)
105 #define ALIGNBYTES (sizeof(int) - 1)
108 #define ALIGN(p) (((unsigned int)(p) + ALIGNBYTES) & ~ALIGNBYTES)
111 #define CMSG_SPACE(len) (ALIGN(sizeof(struct cmsghdr)) + ALIGN(len))
117 char pidfile
[sizeof(PIDFILE
) + IF_NAMESIZE
+ 1];
119 int fork_fd
; /* FD for the fork init signal pipe */
121 unsigned long long options
;
125 int ifac
; /* allowed interfaces */
126 char **ifav
; /* allowed interfaces */
127 int ifdc
; /* denied interfaces */
128 char **ifdv
; /* denied interfaces */
129 int ifc
; /* listed interfaces */
130 char **ifv
; /* listed interfaces */
131 int ifcc
; /* configured interfaces */
132 char **ifcv
; /* configured interfaces */
136 struct if_head
*ifaces
;
143 rb_tree_t routes
; /* our routes */
144 #ifdef RT_FREE_ROUTE_TABLE
145 rb_tree_t froutes
; /* free routes for re-use */
147 size_t rt_order
; /* route order storage */
158 int seq
; /* route message sequence no */
159 int sseq
; /* successful seq no sent */
167 #ifdef HAVE_OPEN_MEMSTREAM
171 size_t script_buflen
;
173 size_t script_envlen
;
176 int control_unpriv_fd
;
177 struct fd_list_head control_fds
;
178 char control_sock
[sizeof(CONTROLSOCKET
) + IF_NAMESIZE
];
179 char control_sock_unpriv
[sizeof(CONTROLSOCKET
) + IF_NAMESIZE
+ 7];
182 /* DHCP Enterprise options, RFC3925 */
183 struct dhcp_opt
*vivso
;
186 char *randomstate
; /* original state */
188 /* For filtering RTM_MISS messages per router */
190 uint8_t *rt_missfilter
;
191 size_t rt_missfilterlen
;
192 size_t rt_missfiltersize
;
196 struct passwd
*ps_user
; /* struct passwd for privsep user */
197 struct ps_process_head ps_processes
; /* List of spawned processes */
198 struct ps_process
*ps_root
;
199 struct ps_process
*ps_inet
;
200 struct ps_process
*ps_ctl
;
201 int ps_data_fd
; /* data returned from processes */
202 int ps_log_fd
; /* chroot logging */
203 int ps_log_root_fd
; /* outside chroot log reader */
204 struct eloop
*ps_eloop
; /* eloop for polling root data */
205 struct fd_list
*ps_control
; /* Queue for the above */
206 struct fd_list
*ps_control_client
; /* Queue for the above */
210 struct dhcp_opt
*dhcp_opts
;
211 size_t dhcp_opts_len
;
216 /* Our aggregate option buffer.
217 * We ONLY use this when options are split, which for most purposes is
218 * practically never. See RFC3396 for details. */
220 size_t opt_buffer_len
;
229 struct ra_head
*ra_routers
;
231 struct dhcp_opt
*nd_opts
;
236 struct dhcp_opt
*dhcp6_opts
;
237 size_t dhcp6_opts_len
;
254 extern const int dhcpcd_signals
[];
255 extern const size_t dhcpcd_signals_len
;
256 extern const int dhcpcd_signals_ignore
[];
257 extern const size_t dhcpcd_signals_ignore_len
;
260 extern const char *dhcpcd_default_script
;
262 int dhcpcd_ifafwaiting(const struct interface
*);
263 int dhcpcd_afwaiting(const struct dhcpcd_ctx
*);
264 void dhcpcd_daemonised(struct dhcpcd_ctx
*);
265 void dhcpcd_daemonise(struct dhcpcd_ctx
*);
267 void dhcpcd_signal_cb(int, void *);
269 void dhcpcd_linkoverflow(struct dhcpcd_ctx
*);
270 int dhcpcd_handleargs(struct dhcpcd_ctx
*, struct fd_list
*, int, char **);
271 void dhcpcd_handlecarrier(struct interface
*, int, unsigned int);
272 int dhcpcd_handleinterface(void *, int, const char *);
273 void dhcpcd_handlehwaddr(struct interface
*, uint16_t, const void *, uint8_t);
274 void dhcpcd_dropinterface(struct interface
*, const char *);
275 int dhcpcd_selectprofile(struct interface
*, const char *);
277 void dhcpcd_startinterface(void *);
278 void dhcpcd_activateinterface(struct interface
*, unsigned long long);