1 | /* |
---|
2 | * dhcpcd - DHCP client daemon |
---|
3 | * Copyright (c) 2006-2013 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 DHCPCOMMON_H |
---|
29 | #define DHCPCOMMON_H |
---|
30 | |
---|
31 | #include <arpa/inet.h> |
---|
32 | #include <netinet/in.h> |
---|
33 | |
---|
34 | #include <stdint.h> |
---|
35 | |
---|
36 | #include "common.h" |
---|
37 | |
---|
38 | /* Max MTU - defines dhcp option length */ |
---|
39 | #define MTU_MAX 1500 |
---|
40 | #define MTU_MIN 576 |
---|
41 | |
---|
42 | #define REQUEST (1 << 0) |
---|
43 | #define UINT8 (1 << 1) |
---|
44 | #define UINT16 (1 << 2) |
---|
45 | #define SINT16 (1 << 3) |
---|
46 | #define UINT32 (1 << 4) |
---|
47 | #define SINT32 (1 << 5) |
---|
48 | #define ADDRIPV4 (1 << 6) |
---|
49 | #define STRING (1 << 7) |
---|
50 | #define ARRAY (1 << 8) |
---|
51 | #define RFC3361 (1 << 9) |
---|
52 | #define RFC3397 (1 << 10) |
---|
53 | #define RFC3442 (1 << 11) |
---|
54 | #define RFC5969 (1 << 12) |
---|
55 | #define ADDRIPV6 (1 << 13) |
---|
56 | #define BINHEX (1 << 14) |
---|
57 | #define FLAG (1 << 15) |
---|
58 | #define NOREQ (1 << 16) |
---|
59 | #define EMBED (1 << 17) |
---|
60 | #define ENCAP (1 << 18) |
---|
61 | #define INDEX (1 << 19) |
---|
62 | #define OPTION (1 << 20) |
---|
63 | |
---|
64 | struct dhcp_opt { |
---|
65 | uint32_t option; /* Also used for IANA Enterpise Number */ |
---|
66 | int type; |
---|
67 | int len; |
---|
68 | char *var; |
---|
69 | |
---|
70 | int index; /* Index counter for many instances of the same option */ |
---|
71 | |
---|
72 | /* Embedded options. |
---|
73 | * The option code is irrelevant here. */ |
---|
74 | struct dhcp_opt *embopts; |
---|
75 | size_t embopts_len; |
---|
76 | |
---|
77 | /* Encapsulated options */ |
---|
78 | struct dhcp_opt *encopts; |
---|
79 | size_t encopts_len; |
---|
80 | }; |
---|
81 | |
---|
82 | /* DHCP Vendor-Identifying Vendor Options, RFC3925 */ |
---|
83 | extern struct dhcp_opt *vivso; |
---|
84 | extern size_t vivso_len; |
---|
85 | |
---|
86 | struct dhcp_opt *vivso_find(uint16_t, const void *); |
---|
87 | |
---|
88 | #define add_option_mask(var, val) (var[val >> 3] |= 1 << (val & 7)) |
---|
89 | #define del_option_mask(var, val) (var[val >> 3] &= ~(1 << (val & 7))) |
---|
90 | #define has_option_mask(var, val) (var[val >>3] & (1 << (val & 7))) |
---|
91 | int make_option_mask(const struct dhcp_opt *, size_t, |
---|
92 | uint8_t *, const char *, int); |
---|
93 | |
---|
94 | size_t encode_rfc1035(const char *src, uint8_t *dst); |
---|
95 | ssize_t decode_rfc3397(char *, ssize_t, int, const uint8_t *); |
---|
96 | ssize_t print_string(char *, ssize_t, int, const uint8_t *); |
---|
97 | ssize_t print_option(char *, ssize_t, int, int, const uint8_t *, const char *); |
---|
98 | |
---|
99 | ssize_t dhcp_envoption(char **, const char *, const char *, struct dhcp_opt *, |
---|
100 | const uint8_t *(*dgetopt)(unsigned int *, unsigned int *, unsigned int *, |
---|
101 | const uint8_t *, unsigned int, struct dhcp_opt **), |
---|
102 | const uint8_t *od, int ol); |
---|
103 | void dhcp_zero_index(struct dhcp_opt *); |
---|
104 | |
---|
105 | #endif |
---|