Home | History | Annotate | Download | only in dhcpcd-6.8.2
      1 /*
      2  * dhcpcd - DHCP client daemon
      3  * Copyright (c) 2006-2015 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/param.h>
     32 #include <sys/socket.h>
     33 #include <net/if.h>
     34 #include <netinet/in.h>
     35 
     36 #include <getopt.h>
     37 #include <limits.h>
     38 #include <stdint.h>
     39 
     40 #include "auth.h"
     41 
     42 /* Don't set any optional arguments here so we retain POSIX
     43  * compatibility with getopt */
     44 #define IF_OPTS "46abc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
     45 		"ABC:DEF:GHI:JKLMO:PQ:RS:TUVW:X:Z:"
     46 
     47 #define DEFAULT_TIMEOUT		30
     48 #define DEFAULT_REBOOT		5
     49 
     50 #ifndef HOSTNAME_MAX_LEN
     51 #define HOSTNAME_MAX_LEN	250	/* 255 - 3 (FQDN) - 2 (DNS enc) */
     52 #endif
     53 #define VENDORCLASSID_MAX_LEN	255
     54 #define CLIENTID_MAX_LEN	48
     55 #define USERCLASS_MAX_LEN	255
     56 #define VENDOR_MAX_LEN		255
     57 
     58 #define DHCPCD_ARP			(1ULL << 0)
     59 #define DHCPCD_RELEASE			(1ULL << 1)
     60 #define DHCPCD_DOMAIN			(1ULL << 2)
     61 #define DHCPCD_GATEWAY			(1ULL << 3)
     62 #define DHCPCD_STATIC			(1ULL << 4)
     63 #define DHCPCD_DEBUG			(1ULL << 5)
     64 #define DHCPCD_LASTLEASE		(1ULL << 7)
     65 #define DHCPCD_INFORM			(1ULL << 8)
     66 #define DHCPCD_REQUEST			(1ULL << 9)
     67 #define DHCPCD_IPV4LL			(1ULL << 10)
     68 #define DHCPCD_DUID			(1ULL << 11)
     69 #define DHCPCD_PERSISTENT		(1ULL << 12)
     70 #define DHCPCD_DAEMONISE		(1ULL << 14)
     71 #define DHCPCD_DAEMONISED		(1ULL << 15)
     72 #define DHCPCD_TEST			(1ULL << 16)
     73 #define DHCPCD_MASTER			(1ULL << 17)
     74 #define DHCPCD_HOSTNAME			(1ULL << 18)
     75 #define DHCPCD_CLIENTID			(1ULL << 19)
     76 #define DHCPCD_LINK			(1ULL << 20)
     77 #define DHCPCD_QUIET			(1ULL << 21)
     78 #define DHCPCD_BACKGROUND		(1ULL << 22)
     79 #define DHCPCD_VENDORRAW		(1ULL << 23)
     80 #define DHCPCD_NOWAITIP			(1ULL << 24) /* To force daemonise */
     81 #define DHCPCD_WAITIP			(1ULL << 25)
     82 #define DHCPCD_SLAACPRIVATE		(1ULL << 26)
     83 #define DHCPCD_CSR_WARNED		(1ULL << 27)
     84 #define DHCPCD_XID_HWADDR		(1ULL << 28)
     85 #define DHCPCD_BROADCAST		(1ULL << 29)
     86 #define DHCPCD_DUMPLEASE		(1ULL << 30)
     87 #define DHCPCD_IPV6RS			(1ULL << 31)
     88 #define DHCPCD_IPV6RA_REQRDNSS		(1ULL << 32)
     89 #define DHCPCD_IPV6RA_OWN		(1ULL << 33)
     90 #define DHCPCD_IPV6RA_OWN_DEFAULT	(1ULL << 34)
     91 #define DHCPCD_IPV4			(1ULL << 35)
     92 #define DHCPCD_FORKED			(1ULL << 36)
     93 #define DHCPCD_IPV6			(1ULL << 37)
     94 #define DHCPCD_STARTED			(1ULL << 38)
     95 #define DHCPCD_NOALIAS			(1ULL << 39)
     96 #define DHCPCD_IA_FORCED		(1ULL << 40)
     97 #define DHCPCD_STOPPING			(1ULL << 41)
     98 #define DHCPCD_DEPARTED			(1ULL << 42)
     99 #define DHCPCD_HOSTNAME_SHORT		(1ULL << 43)
    100 #define DHCPCD_EXITING			(1ULL << 44)
    101 #define DHCPCD_WAITIP4			(1ULL << 45)
    102 #define DHCPCD_WAITIP6			(1ULL << 46)
    103 #define DHCPCD_DEV			(1ULL << 47)
    104 #define DHCPCD_IAID			(1ULL << 48)
    105 #define DHCPCD_DHCP			(1ULL << 49)
    106 #define DHCPCD_DHCP6			(1ULL << 50)
    107 #define DHCPCD_NOPFXDLG			(1ULL << 51)
    108 #define DHCPCD_PFXDLGONLY		(1ULL << 52)
    109 #define DHCPCD_PFXDLGMIX		(1ULL << 53)
    110 #define DHCPCD_IPV6RA_AUTOCONF		(1ULL << 54)
    111 #define DHCPCD_ROUTER_HOST_ROUTE_WARNED	(1ULL << 55)
    112 #define DHCPCD_IPV6RA_ACCEPT_NOPUBLIC	(1ULL << 56)
    113 #define DHCPCD_BOOTP			(1ULL << 57)
    114 #define DHCPCD_ARPGW			(1ULL << 58)
    115 #define DHCPCD_UNICAST_ARP		(1ULL << 59)
    116 
    117 #define DHCPCD_WARNINGS (DHCPCD_CSR_WARNED | \
    118 		DHCPCD_ROUTER_HOST_ROUTE_WARNED)
    119 #define DHCPCD_CONF (DHCPCD_NOPFXDLG | DHCPCD_PFXDLGONLY)
    120 
    121 extern const struct option cf_options[];
    122 
    123 /* The number of bytes it takes to hold a flag for each of the 256 options. */
    124 #define OPTION_MASK_SIZE (256 / NBBY)
    125 
    126 struct if_sla {
    127 	char ifname[IF_NAMESIZE];
    128 	uint32_t sla;
    129 	uint8_t prefix_len;
    130 	int8_t sla_set;
    131 };
    132 
    133 struct if_ia {
    134 	uint8_t iaid[4];
    135 #ifdef INET6
    136 	uint16_t ia_type;
    137 	uint8_t iaid_set;
    138 	struct in6_addr addr;
    139 	uint8_t prefix_len;
    140 	uint32_t sla_max;
    141 	size_t sla_len;
    142 	struct if_sla *sla;
    143 #endif
    144 };
    145 
    146 struct vivco {
    147 	size_t len;
    148 	uint8_t *data;
    149 };
    150 
    151 struct if_options {
    152 	time_t mtime;
    153 	uint8_t iaid[4];
    154 	int metric;
    155 	uint8_t requestmask[OPTION_MASK_SIZE];
    156 	uint8_t requiremask[OPTION_MASK_SIZE];
    157 	uint8_t nomask[OPTION_MASK_SIZE];
    158 	uint8_t rejectmask[OPTION_MASK_SIZE];
    159 	uint8_t requestmask6[(UINT16_MAX + 1) / NBBY];
    160 	uint8_t requiremask6[(UINT16_MAX + 1) / NBBY];
    161 	uint8_t nomask6[(UINT16_MAX + 1) / NBBY];
    162 	uint8_t rejectmask6[(UINT16_MAX + 1) / NBBY];
    163 	uint8_t dstmask[256 / NBBY];
    164 	uint32_t leasetime;
    165 	time_t timeout;
    166 	time_t reboot;
    167 	unsigned long long options;
    168 
    169 	struct in_addr req_addr;
    170 	struct in_addr req_mask;
    171 	struct rt_head *routes;
    172 	char **config;
    173 
    174 	char **environ;
    175 	char *script;
    176 
    177 	char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
    178 	uint8_t fqdn;
    179 	uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
    180 	uint8_t clientid[CLIENTID_MAX_LEN + 2];
    181 	uint8_t userclass[USERCLASS_MAX_LEN + 2];
    182 	uint8_t vendor[VENDOR_MAX_LEN + 2];
    183 
    184 	size_t blacklist_len;
    185 	in_addr_t *blacklist;
    186 	size_t whitelist_len;
    187 	in_addr_t *whitelist;
    188 	size_t arping_len;
    189 	in_addr_t *arping;
    190 	char *fallback;
    191 
    192 	struct if_ia *ia;
    193 	size_t ia_len;
    194 
    195 	struct dhcp_opt *dhcp_override;
    196 	size_t dhcp_override_len;
    197 	struct dhcp_opt *dhcp6_override;
    198 	size_t dhcp6_override_len;
    199 	uint32_t vivco_en;
    200 	struct vivco *vivco;
    201 	size_t vivco_len;
    202 	struct dhcp_opt *vivso_override;
    203 	size_t vivso_override_len;
    204 
    205 	struct auth auth;
    206 };
    207 
    208 struct if_options *read_config(struct dhcpcd_ctx *,
    209     const char *, const char *, const char *);
    210 int add_options(struct dhcpcd_ctx *, const char *,
    211     struct if_options *, int, char **);
    212 void free_dhcp_opt_embenc(struct dhcp_opt *);
    213 void free_options(struct if_options *);
    214 
    215 #endif
    216