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