blob: c2fdfdfe52da2ee424b0c3724ef46697ec9861c4 [file] [log] [blame]
The Android Open Source Projectf7c54212009-03-03 19:29:22 -08001/*
2 * dhcpcd - DHCP client daemon
Dmitry Shmidta3a22602012-07-23 16:45:46 -07003 * Copyright (c) 2006-2011 Roy Marples <roy@marples.name>
The Android Open Source Projectf7c54212009-03-03 19:29:22 -08004 * 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
The Android Open Source Projectf7c54212009-03-03 19:29:22 -080031#include <sys/socket.h>
The Android Open Source Projectf7c54212009-03-03 19:29:22 -080032#include <net/if.h>
Dmitry Shmidta3a22602012-07-23 16:45:46 -070033#include <netinet/in.h>
The Android Open Source Projectf7c54212009-03-03 19:29:22 -080034
35#include <limits.h>
36
Dmitry Shmidte86eee12011-01-24 16:27:51 -080037#include "control.h"
38#include "dhcp.h"
39#include "if-options.h"
The Android Open Source Projectf7c54212009-03-03 19:29:22 -080040
Dmitry Shmidte86eee12011-01-24 16:27:51 -080041#define HWADDR_LEN 20
42#define IF_SSIDSIZE 33
43#define PROFILE_LEN 64
The Android Open Source Projectf7c54212009-03-03 19:29:22 -080044
Dmitry Shmidte86eee12011-01-24 16:27:51 -080045enum 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
The Android Open Source Projectf7c54212009-03-03 19:29:22 -080057};
Dmitry Shmidte86eee12011-01-24 16:27:51 -080058
59#define LINK_UP 1
60#define LINK_UNKNOWN 0
61#define LINK_DOWN -1
62
63struct 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
Dmitry Shmidta3a22602012-07-23 16:45:46 -070085struct ra_opt {
86 uint8_t type;
87 struct timeval expire;
88 char *option;
89 struct ra_opt *next;
90};
91
92struct 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
Dmitry Shmidte86eee12011-01-24 16:27:51 -0800109struct 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
Dmitry Shmidta3a22602012-07-23 16:45:46 -0700137 unsigned char *rs;
138 size_t rslen;
139 int rsprobes;
140 struct ra *ras;
141
Dmitry Shmidte86eee12011-01-24 16:27:51 -0800142 struct interface *next;
143};
144
145extern int pidfd;
Dmitry Shmidta3a22602012-07-23 16:45:46 -0700146extern unsigned long long options;
Dmitry Shmidte86eee12011-01-24 16:27:51 -0800147extern int ifac;
148extern char **ifav;
149extern int ifdc;
150extern char **ifdv;
151extern struct interface *ifaces;
repo sync0d3a47d2011-08-10 15:44:47 -0700152extern int avoid_routes;
Dmitry Shmidte86eee12011-01-24 16:27:51 -0800153
154struct interface *find_interface(const char *);
155int handle_args(struct fd_list *, int, char **);
Dmitry Shmidta3a22602012-07-23 16:45:46 -0700156void handle_carrier(int, int, const char *);
Dmitry Shmidte86eee12011-01-24 16:27:51 -0800157void handle_interface(int, const char *);
158void handle_hwaddr(const char *, unsigned char *, size_t);
159void handle_ifa(int, const char *,
160 struct in_addr *, struct in_addr *, struct in_addr *);
161void handle_exit_timeout(void *);
162void start_interface(void *);
163void start_discover(void *);
164void start_request(void *);
165void start_renew(void *);
166void start_rebind(void *);
167void start_reboot(struct interface *);
168void start_expire(void *);
169void send_decline(struct interface *);
170void open_sockets(struct interface *);
171void close_sockets(struct interface *);
Dmitry Shmidta3a22602012-07-23 16:45:46 -0700172void drop_dhcp(struct interface *, const char *);
173void drop_interface(struct interface *, const char *);
Dmitry Shmidte86eee12011-01-24 16:27:51 -0800174int select_profile(struct interface *, const char *);
175
The Android Open Source Projectf7c54212009-03-03 19:29:22 -0800176#endif