xref: /minix/external/bsd/dhcpcd/dist/dhcpcd.h (revision fb9c64b2)
1 /* $NetBSD: dhcpcd.h,v 1.13 2015/08/21 10:39:00 roy Exp $ */
2 
3 /*
4  * dhcpcd - DHCP client daemon
5  * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
6  * All rights reserved
7 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef DHCPCD_H
31 #define DHCPCD_H
32 
33 #include <sys/socket.h>
34 #include <net/if.h>
35 
36 #include "config.h"
37 #ifdef HAVE_SYS_QUEUE_H
38 #include <sys/queue.h>
39 #endif
40 
41 #include "defs.h"
42 #include "control.h"
43 #include "if-options.h"
44 
45 #define HWADDR_LEN	20
46 #define IF_SSIDSIZE	33
47 #define PROFILE_LEN	64
48 #define SECRET_LEN	64
49 
50 #define LINK_UP		1
51 #define LINK_UNKNOWN	0
52 #define LINK_DOWN	-1
53 
54 #define IF_DATA_IPV4	0
55 #define IF_DATA_ARP	1
56 #define IF_DATA_IPV4LL	2
57 #define IF_DATA_DHCP	3
58 #define IF_DATA_IPV6	4
59 #define IF_DATA_IPV6ND	5
60 #define IF_DATA_DHCP6	6
61 #define IF_DATA_MAX	7
62 
63 /* If the interface does not support carrier status (ie PPP),
64  * dhcpcd can poll it for the relevant flags periodically */
65 #define IF_POLL_UP	100	/* milliseconds */
66 
67 #ifdef __QNX__
68 /* QNX carries defines for, but does not actually support PF_LINK */
69 #undef IFLR_ACTIVE
70 #endif
71 
72 struct interface {
73 	struct dhcpcd_ctx *ctx;
74 	TAILQ_ENTRY(interface) next;
75 	char name[IF_NAMESIZE];
76 #ifdef __linux__
77 	char alias[IF_NAMESIZE];
78 #endif
79 	unsigned int index;
80 	unsigned int flags;
81 	sa_family_t family;
82 	unsigned char hwaddr[HWADDR_LEN];
83 	uint8_t hwlen;
84 	unsigned int metric;
85 	int carrier;
86 	int wireless;
87 	uint8_t ssid[IF_SSIDSIZE];
88 	unsigned int ssid_len;
89 
90 	char profile[PROFILE_LEN];
91 	struct if_options *options;
92 	void *if_data[IF_DATA_MAX];
93 };
94 TAILQ_HEAD(if_head, interface);
95 
96 struct dhcpcd_ctx {
97 	int pid_fd;
98 	char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
99 	const char *cffile;
100 	unsigned long long options;
101 	char *logfile;
102 	int log_fd;
103 	int argc;
104 	char **argv;
105 	int ifac;	/* allowed interfaces */
106 	char **ifav;	/* allowed interfaces */
107 	int ifdc;	/* denied interfaces */
108 	char **ifdv;	/* denied interfaces */
109 	int ifc;	/* listed interfaces */
110 	char **ifv;	/* listed interfaces */
111 	int ifcc;	/* configured interfaces */
112 	char **ifcv;	/* configured interfaces */
113 	unsigned char *duid;
114 	size_t duid_len;
115 	struct if_head *ifaces;
116 
117 	int pf_inet_fd;
118 #if defined(INET6) && defined(BSD)
119 	int pf_inet6_fd;
120 #endif
121 #ifdef IFLR_ACTIVE
122 	int pf_link_fd;
123 #endif
124 	int link_fd;
125 
126 #ifdef USE_SIGNALS
127 	sigset_t sigset;
128 #endif
129 	struct eloop *eloop;
130 
131 	int control_fd;
132 	int control_unpriv_fd;
133 	struct fd_list_head control_fds;
134 	char control_sock[sizeof(CONTROLSOCKET) + IF_NAMESIZE];
135 	gid_t control_group;
136 
137 	/* DHCP Enterprise options, RFC3925 */
138 	struct dhcp_opt *vivso;
139 	size_t vivso_len;
140 
141 	char *randomstate; /* original state */
142 
143 #ifdef INET
144 	struct dhcp_opt *dhcp_opts;
145 	size_t dhcp_opts_len;
146 	struct rt_head *ipv4_routes;
147 	struct rt_head *ipv4_kroutes;
148 
149 	int udp_fd;
150 	uint8_t *packet;
151 
152 	/* Our aggregate option buffer.
153 	 * We ONLY use this when options are split, which for most purposes is
154 	 * practically never. See RFC3396 for details. */
155 	uint8_t *opt_buffer;
156 #endif
157 #ifdef INET6
158 	unsigned char secret[SECRET_LEN];
159 	size_t secret_len;
160 
161 	struct dhcp_opt *nd_opts;
162 	size_t nd_opts_len;
163 	struct dhcp_opt *dhcp6_opts;
164 	size_t dhcp6_opts_len;
165 	struct ipv6_ctx *ipv6;
166 #ifndef __linux__
167 	int ra_global;
168 #endif
169 #endif /* INET6 */
170 
171 #ifdef PLUGIN_DEV
172 	char *dev_load;
173 	int dev_fd;
174 	struct dev *dev;
175 	void *dev_handle;
176 #endif
177 };
178 
179 #ifdef USE_SIGNALS
180 extern const int dhcpcd_signals[];
181 extern const size_t dhcpcd_signals_len;
182 #endif
183 
184 int dhcpcd_ifafwaiting(const struct interface *);
185 int dhcpcd_afwaiting(const struct dhcpcd_ctx *);
186 pid_t dhcpcd_daemonise(struct dhcpcd_ctx *);
187 
188 int dhcpcd_handleargs(struct dhcpcd_ctx *, struct fd_list *, int, char **);
189 void dhcpcd_handlecarrier(struct dhcpcd_ctx *, int, unsigned int, const char *);
190 int dhcpcd_handleinterface(void *, int, const char *);
191 void dhcpcd_handlehwaddr(struct dhcpcd_ctx *, const char *,
192     const unsigned char *, uint8_t);
193 void dhcpcd_dropinterface(struct interface *, const char *);
194 int dhcpcd_selectprofile(struct interface *, const char *);
195 
196 void dhcpcd_startinterface(void *);
197 void dhcpcd_initstate(struct interface *, unsigned long long);
198 
199 #endif
200