2007-11-15 19:35:53 +08:00
|
|
|
/*
|
2007-11-08 00:26:41 +08:00
|
|
|
* dhcpcd - DHCP client daemon
|
2009-01-02 04:51:04 +08:00
|
|
|
* Copyright 2006-2009 Roy Marples <roy@marples.name>
|
2007-11-15 19:35:53 +08:00
|
|
|
* All rights reserved
|
|
|
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2006-11-28 04:23:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DHCPCD_H
|
|
|
|
#define DHCPCD_H
|
|
|
|
|
2008-09-04 00:50:52 +08:00
|
|
|
#include <sys/socket.h>
|
2006-12-06 17:37:15 +08:00
|
|
|
#include <net/if.h>
|
2008-03-21 00:47:51 +08:00
|
|
|
|
2006-11-28 04:23:22 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2009-01-13 00:39:01 +08:00
|
|
|
#include "control.h"
|
2008-09-02 21:28:11 +08:00
|
|
|
#include "dhcp.h"
|
2008-11-10 19:15:27 +08:00
|
|
|
#include "if-options.h"
|
2008-09-02 21:28:11 +08:00
|
|
|
|
|
|
|
#define HWADDR_LEN 20
|
2009-01-02 04:51:04 +08:00
|
|
|
#define IF_SSIDSIZE 33
|
2009-03-31 16:35:38 +08:00
|
|
|
#define PROFILE_LEN 32
|
2008-09-02 21:28:11 +08:00
|
|
|
|
|
|
|
enum DHS {
|
|
|
|
DHS_INIT,
|
2008-09-15 23:23:46 +08:00
|
|
|
DHS_DISCOVER,
|
|
|
|
DHS_REQUEST,
|
2008-09-02 21:28:11 +08:00
|
|
|
DHS_BOUND,
|
2008-09-15 23:23:46 +08:00
|
|
|
DHS_RENEW,
|
|
|
|
DHS_REBIND,
|
2008-09-02 21:28:11 +08:00
|
|
|
DHS_REBOOT,
|
2009-03-06 00:35:03 +08:00
|
|
|
DHS_INFORM,
|
2008-09-02 21:28:11 +08:00
|
|
|
DHS_RENEW_REQUESTED,
|
2008-12-18 18:23:40 +08:00
|
|
|
DHS_INIT_IPV4LL,
|
|
|
|
DHS_PROBE
|
2008-09-02 21:28:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define LINK_UP 1
|
|
|
|
#define LINK_UNKNOWN 0
|
|
|
|
#define LINK_DOWN -1
|
|
|
|
|
|
|
|
struct if_state {
|
|
|
|
enum DHS state;
|
2009-03-31 16:35:38 +08:00
|
|
|
char profile[PROFILE_LEN];
|
2008-09-02 21:28:11 +08:00
|
|
|
struct if_options *options;
|
|
|
|
struct dhcp_message *sent;
|
|
|
|
struct dhcp_message *offer;
|
|
|
|
struct dhcp_message *new;
|
|
|
|
struct dhcp_message *old;
|
|
|
|
struct dhcp_lease lease;
|
2009-01-14 01:04:28 +08:00
|
|
|
const char *reason;
|
2008-09-02 21:28:11 +08:00
|
|
|
time_t interval;
|
|
|
|
time_t nakoff;
|
|
|
|
uint32_t xid;
|
|
|
|
int socket;
|
|
|
|
int probes;
|
|
|
|
int claims;
|
|
|
|
int conflicts;
|
|
|
|
time_t defend;
|
|
|
|
struct in_addr fail;
|
2009-03-31 16:35:38 +08:00
|
|
|
size_t arping_index;
|
2008-09-02 21:28:11 +08:00
|
|
|
};
|
|
|
|
|
2009-02-12 18:07:30 +08:00
|
|
|
struct interface {
|
2008-09-02 21:28:11 +08:00
|
|
|
char name[IF_NAMESIZE];
|
|
|
|
struct if_state *state;
|
|
|
|
|
2009-03-20 01:52:12 +08:00
|
|
|
int flags;
|
2008-09-02 21:28:11 +08:00
|
|
|
sa_family_t family;
|
|
|
|
unsigned char hwaddr[HWADDR_LEN];
|
|
|
|
size_t hwlen;
|
2008-07-04 21:02:33 +08:00
|
|
|
int metric;
|
2008-09-10 01:07:48 +08:00
|
|
|
int carrier;
|
2008-09-02 21:28:11 +08:00
|
|
|
int arpable;
|
2009-01-23 06:52:41 +08:00
|
|
|
int wireless;
|
2009-01-02 04:51:04 +08:00
|
|
|
char ssid[IF_SSIDSIZE];
|
2008-09-02 21:28:11 +08:00
|
|
|
|
|
|
|
int raw_fd;
|
|
|
|
int udp_fd;
|
|
|
|
int arp_fd;
|
|
|
|
size_t buffer_size, buffer_len, buffer_pos;
|
|
|
|
unsigned char *buffer;
|
|
|
|
|
|
|
|
struct in_addr addr;
|
|
|
|
struct in_addr net;
|
2009-03-24 06:02:37 +08:00
|
|
|
struct in_addr dst;
|
2008-09-02 21:28:11 +08:00
|
|
|
|
|
|
|
char leasefile[PATH_MAX];
|
|
|
|
time_t start_uptime;
|
|
|
|
|
|
|
|
unsigned char *clientid;
|
|
|
|
|
|
|
|
struct interface *next;
|
2008-03-21 00:47:51 +08:00
|
|
|
};
|
2008-09-02 21:28:11 +08:00
|
|
|
|
|
|
|
extern int pidfd;
|
2008-09-05 15:22:03 +08:00
|
|
|
extern int options;
|
2008-09-11 17:38:02 +08:00
|
|
|
extern int ifac;
|
|
|
|
extern char **ifav;
|
|
|
|
extern int ifdc;
|
|
|
|
extern char **ifdv;
|
2008-09-10 01:07:48 +08:00
|
|
|
extern struct interface *ifaces;
|
2008-09-04 19:30:11 +08:00
|
|
|
|
2009-01-28 02:09:02 +08:00
|
|
|
struct interface *find_interface(const char *);
|
2009-01-13 00:39:01 +08:00
|
|
|
int handle_args(struct fd_list *, int, char **);
|
2009-03-20 01:52:12 +08:00
|
|
|
void handle_interface(int, const char *);
|
|
|
|
void handle_ifa(int, const char *,
|
|
|
|
struct in_addr *, struct in_addr *, struct in_addr *);
|
2008-09-04 00:49:28 +08:00
|
|
|
void handle_exit_timeout(void *);
|
|
|
|
void start_interface(void *);
|
|
|
|
void start_discover(void *);
|
2008-12-18 18:23:40 +08:00
|
|
|
void start_request(void *);
|
2008-09-04 00:49:28 +08:00
|
|
|
void start_renew(void *);
|
|
|
|
void start_rebind(void *);
|
2008-09-02 21:28:11 +08:00
|
|
|
void start_reboot(struct interface *);
|
2008-09-04 00:49:28 +08:00
|
|
|
void start_expire(void *);
|
2008-09-02 21:28:11 +08:00
|
|
|
void send_decline(struct interface *);
|
|
|
|
void close_sockets(struct interface *);
|
|
|
|
void drop_config(struct interface *, const char *);
|
2009-03-31 16:35:38 +08:00
|
|
|
int select_profile(struct interface *, const char *);
|
2008-09-02 21:28:11 +08:00
|
|
|
|
2006-11-28 04:23:22 +08:00
|
|
|
#endif
|