• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * dhcpcd - DHCP client daemon
3  * Copyright (c) 2006-2011 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 #include <netinet/in.h>
34 
35 #include <limits.h>
36 
37 #include "control.h"
38 #include "dhcp.h"
39 #include "if-options.h"
40 
41 #define HWADDR_LEN 20
42 #define IF_SSIDSIZE 33
43 #define PROFILE_LEN 64
44 
45 enum DHS {
46 	DHS_INIT,
47 	DHS_DISCOVER,
48 	DHS_REQUEST,
49 	DHS_BOUND,
50 	DHS_RENEW,
51 	DHS_REBIND,
52 	DHS_REBOOT,
53 	DHS_INFORM,
54 	DHS_RENEW_REQUESTED,
55 	DHS_INIT_IPV4LL,
56 	DHS_PROBE
57 };
58 
59 #define LINK_UP 	1
60 #define LINK_UNKNOWN	0
61 #define LINK_DOWN 	-1
62 
63 struct if_state {
64 	enum DHS state;
65 	char profile[PROFILE_LEN];
66 	struct if_options *options;
67 	struct dhcp_message *sent;
68 	struct dhcp_message *offer;
69 	struct dhcp_message *new;
70 	struct dhcp_message *old;
71 	struct dhcp_lease lease;
72 	const char *reason;
73 	time_t interval;
74 	time_t nakoff;
75 	uint32_t xid;
76 	int socket;
77 	int probes;
78 	int claims;
79 	int conflicts;
80 	time_t defend;
81 	struct in_addr fail;
82 	size_t arping_index;
83 };
84 
85 struct ra_opt {
86 	uint8_t type;
87 	struct timeval expire;
88 	char *option;
89 	struct ra_opt *next;
90 };
91 
92 struct ra {
93 	struct in6_addr from;
94 	char sfrom[INET6_ADDRSTRLEN];
95 	unsigned char *data;
96 	ssize_t data_len;
97 	struct timeval received;
98 	uint32_t lifetime;
99 	struct in6_addr prefix;
100 	int prefix_len;
101 	uint32_t prefix_vltime;
102 	uint32_t prefix_pltime;
103 	char sprefix[INET6_ADDRSTRLEN];
104 	struct ra_opt *options;
105 	int expired;
106 	struct ra *next;
107 };
108 
109 struct interface {
110 	char name[IF_NAMESIZE];
111 	struct if_state *state;
112 
113 	int flags;
114 	sa_family_t family;
115 	unsigned char hwaddr[HWADDR_LEN];
116 	size_t hwlen;
117 	int metric;
118 	int carrier;
119 	int wireless;
120 	char ssid[IF_SSIDSIZE];
121 
122 	int raw_fd;
123 	int udp_fd;
124 	int arp_fd;
125 	size_t buffer_size, buffer_len, buffer_pos;
126 	unsigned char *buffer;
127 
128 	struct in_addr addr;
129 	struct in_addr net;
130 	struct in_addr dst;
131 
132 	char leasefile[PATH_MAX];
133 	time_t start_uptime;
134 
135 	unsigned char *clientid;
136 
137 	unsigned char *rs;
138 	size_t rslen;
139 	int rsprobes;
140 	struct ra *ras;
141 
142 	struct interface *next;
143 };
144 
145 extern int pidfd;
146 extern unsigned long long options;
147 extern int ifac;
148 extern char **ifav;
149 extern int ifdc;
150 extern char **ifdv;
151 extern struct interface *ifaces;
152 extern int avoid_routes;
153 
154 struct interface *find_interface(const char *);
155 int handle_args(struct fd_list *, int, char **);
156 void handle_carrier(int, int, const char *);
157 void handle_interface(int, const char *);
158 void handle_hwaddr(const char *, unsigned char *, size_t);
159 void handle_ifa(int, const char *,
160     struct in_addr *, struct in_addr *, struct in_addr *);
161 void handle_exit_timeout(void *);
162 void start_interface(void *);
163 void start_discover(void *);
164 void start_request(void *);
165 void start_renew(void *);
166 void start_rebind(void *);
167 void start_reboot(struct interface *);
168 void start_expire(void *);
169 void send_decline(struct interface *);
170 void open_sockets(struct interface *);
171 void close_sockets(struct interface *);
172 void drop_dhcp(struct interface *, const char *);
173 void drop_interface(struct interface *, const char *);
174 int select_profile(struct interface *, const char *);
175 
176 #endif
177