Home | History | Annotate | Download | only in dhcpcd
      1 /*
      2  * dhcpcd - DHCP client daemon
      3  * Copyright (c) 2006-2012 Roy Marples <roy (at) 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 IF_OPTIONS_H
     29 #define IF_OPTIONS_H
     30 
     31 #include <sys/socket.h>
     32 #include <net/if.h>
     33 #include <netinet/in.h>
     34 
     35 #include <getopt.h>
     36 #include <limits.h>
     37 
     38 /* Don't set any optional arguments here so we retain POSIX
     39  * compatibility with getopt */
     40 #define IF_OPTS "abc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:"
     41 
     42 #define DEFAULT_TIMEOUT		30
     43 #define DEFAULT_REBOOT		5
     44 
     45 #define HOSTNAME_MAX_LEN	250	/* 255 - 3 (FQDN) - 2 (DNS enc) */
     46 #define VENDORCLASSID_MAX_LEN	255
     47 #define CLIENTID_MAX_LEN	48
     48 #define USERCLASS_MAX_LEN	255
     49 #define VENDOR_MAX_LEN		255
     50 
     51 #define DHCPCD_ARP			(1ULL << 0)
     52 #define DHCPCD_RELEASE			(1ULL << 1)
     53 #define DHCPCD_DOMAIN			(1ULL << 2)
     54 #define DHCPCD_GATEWAY			(1ULL << 3)
     55 #define DHCPCD_STATIC			(1ULL << 4)
     56 #define DHCPCD_DEBUG			(1ULL << 5)
     57 #define DHCPCD_LASTLEASE		(1ULL << 7)
     58 #define DHCPCD_INFORM			(1ULL << 8)
     59 #define DHCPCD_REQUEST			(1ULL << 9)
     60 #define DHCPCD_IPV4LL			(1ULL << 10)
     61 #define DHCPCD_DUID			(1ULL << 11)
     62 #define DHCPCD_PERSISTENT		(1ULL << 12)
     63 #define DHCPCD_DAEMONISE		(1ULL << 14)
     64 #define DHCPCD_DAEMONISED		(1ULL << 15)
     65 #define DHCPCD_TEST			(1ULL << 16)
     66 #define DHCPCD_MASTER			(1ULL << 17)
     67 #define DHCPCD_HOSTNAME			(1ULL << 18)
     68 #define DHCPCD_CLIENTID			(1ULL << 19)
     69 #define DHCPCD_LINK			(1ULL << 20)
     70 #define DHCPCD_QUIET			(1ULL << 21)
     71 #define DHCPCD_BACKGROUND		(1ULL << 22)
     72 #define DHCPCD_VENDORRAW		(1ULL << 23)
     73 #define DHCPCD_TIMEOUT_IPV4LL		(1ULL << 24)
     74 #define DHCPCD_WAITIP			(1ULL << 25)
     75 #define DHCPCD_WAITUP			(1ULL << 26)
     76 #define DHCPCD_CSR_WARNED		(1ULL << 27)
     77 #define DHCPCD_XID_HWADDR		(1ULL << 28)
     78 #define DHCPCD_BROADCAST		(1ULL << 29)
     79 #define DHCPCD_DUMPLEASE		(1ULL << 30)
     80 #define DHCPCD_IPV6RS			(1ULL << 31)
     81 #define DHCPCD_IPV6RA_REQRDNSS		(1ULL << 32)
     82 
     83 extern const struct option cf_options[];
     84 
     85 struct if_options {
     86 	int metric;
     87 	uint8_t requestmask[256 / 8];
     88 	uint8_t requiremask[256 / 8];
     89 	uint8_t nomask[256 / 8];
     90 	uint8_t dstmask[256 / 8];
     91 	uint32_t leasetime;
     92 	time_t timeout;
     93 	time_t reboot;
     94 	unsigned long long options;
     95 
     96 	struct in_addr req_addr;
     97 	struct in_addr req_mask;
     98 	struct rt *routes;
     99 	char **config;
    100 
    101 	char **environ;
    102 	char script[PATH_MAX];
    103 
    104 	char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
    105 	int fqdn;
    106 	uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
    107 	char clientid[CLIENTID_MAX_LEN + 2];
    108 	uint8_t userclass[USERCLASS_MAX_LEN + 2];
    109 	uint8_t vendor[VENDOR_MAX_LEN + 2];
    110 
    111 	size_t blacklist_len;
    112 	in_addr_t *blacklist;
    113 	size_t whitelist_len;
    114 	in_addr_t *whitelist;
    115 	size_t arping_len;
    116 	in_addr_t *arping;
    117 	char *fallback;
    118 };
    119 
    120 struct if_options *read_config(const char *,
    121     const char *, const char *, const char *);
    122 int add_options(struct if_options *, int, char **);
    123 void free_options(struct if_options *);
    124 
    125 #endif
    126