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 45enum 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 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 85struct 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 109struct 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 145extern int pidfd; 146extern unsigned long long options; 147extern int ifac; 148extern char **ifav; 149extern int ifdc; 150extern char **ifdv; 151extern struct interface *ifaces; 152extern int avoid_routes; 153 154struct interface *find_interface(const char *); 155int handle_args(struct fd_list *, int, char **); 156void handle_carrier(int, int, const char *); 157void 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 *); 172void drop_dhcp(struct interface *, const char *); 173void drop_interface(struct interface *, const char *); 174int select_profile(struct interface *, const char *); 175 176#endif 177