xref: /minix/external/bsd/dhcpcd/dist/dhcp-common.h (revision bb9622b5)
1 /* $NetBSD: dhcp-common.h,v 1.10 2015/07/09 10:15:34 roy Exp $ */
2 
3 /*
4  * dhcpcd - DHCP client daemon
5  * Copyright (c) 2006-2015 Roy Marples <roy@marples.name>
6  * All rights reserved
7 
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef DHCPCOMMON_H
31 #define DHCPCOMMON_H
32 
33 #include <arpa/inet.h>
34 #include <netinet/in.h>
35 
36 #include <stdint.h>
37 
38 #include "common.h"
39 #include "dhcpcd.h"
40 
41 /* Max MTU - defines dhcp option length */
42 #define MTU_MAX             1500
43 #define MTU_MIN             576
44 
45 #define REQUEST		(1 << 0)
46 #define UINT8		(1 << 1)
47 #define UINT16		(1 << 2)
48 #define SINT16		(1 << 3)
49 #define UINT32		(1 << 4)
50 #define SINT32		(1 << 5)
51 #define ADDRIPV4	(1 << 6)
52 #define STRING		(1 << 7)
53 #define ARRAY		(1 << 8)
54 #define RFC3361		(1 << 9)
55 #define RFC1035		(1 << 10)
56 #define RFC3442		(1 << 11)
57 #define RFC5969		(1 << 12)
58 #define ADDRIPV6	(1 << 13)
59 #define BINHEX		(1 << 14)
60 #define FLAG		(1 << 15)
61 #define NOREQ		(1 << 16)
62 #define EMBED		(1 << 17)
63 #define ENCAP		(1 << 18)
64 #define INDEX		(1 << 19)
65 #define OPTION		(1 << 20)
66 #define DOMAIN		(1 << 21)
67 #define ASCII		(1 << 22)
68 #define RAW		(1 << 23)
69 #define ESCSTRING	(1 << 24)
70 #define ESCFILE		(1 << 25)
71 #define BITFLAG		(1 << 26)
72 #define RESERVED	(1 << 27)
73 
74 struct dhcp_opt {
75 	uint32_t option; /* Also used for IANA Enterpise Number */
76 	int type;
77 	size_t len;
78 	char *var;
79 
80 	int index; /* Index counter for many instances of the same option */
81 	char bitflags[8];
82 
83 	/* Embedded options.
84 	 * The option code is irrelevant here. */
85 	struct dhcp_opt *embopts;
86 	size_t embopts_len;
87 
88 	/* Encapsulated options */
89 	struct dhcp_opt *encopts;
90 	size_t encopts_len;
91 };
92 
93 struct dhcp_opt *vivso_find(uint32_t, const void *);
94 
95 ssize_t dhcp_vendor(char *, size_t);
96 
97 void dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols);
98 #define add_option_mask(var, val) \
99 	((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] | 1 << ((val) & 7)))
100 #define del_option_mask(var, val) \
101 	((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] & ~(1 << ((val) & 7))))
102 #define has_option_mask(var, val) \
103 	((var)[(val) >> 3] & (uint8_t)(1 << ((val) & 7)))
104 int make_option_mask(const struct dhcp_opt *, size_t,
105     const struct dhcp_opt *, size_t,
106     uint8_t *, const char *, int);
107 
108 size_t encode_rfc1035(const char *src, uint8_t *dst);
109 ssize_t decode_rfc1035(char *, size_t, const uint8_t *, size_t);
110 ssize_t print_string(char *, size_t, int, const uint8_t *, size_t);
111 int dhcp_set_leasefile(char *, size_t, int, const struct interface *);
112 
113 size_t dhcp_envoption(struct dhcpcd_ctx *,
114     char **, const char *, const char *, struct dhcp_opt *,
115     const uint8_t *(*dgetopt)(struct dhcpcd_ctx *,
116     size_t *, unsigned int *, size_t *,
117     const uint8_t *, size_t, struct dhcp_opt **),
118     const uint8_t *od, size_t ol);
119 void dhcp_zero_index(struct dhcp_opt *);
120 
121 #endif
122