Samuel Tan | d7ed851 | 2015-08-13 16:11:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dhcpcd - DHCP client daemon |
| 3 | * Copyright (c) 2006-2015 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 | #include "dhcpcd.h" |
| 38 | |
| 39 | /* Max MTU - defines dhcp option length */ |
| 40 | #define MTU_MAX 1500 |
| 41 | #define MTU_MIN 576 |
| 42 | |
| 43 | #define REQUEST (1 << 0) |
| 44 | #define UINT8 (1 << 1) |
| 45 | #define UINT16 (1 << 2) |
| 46 | #define SINT16 (1 << 3) |
| 47 | #define UINT32 (1 << 4) |
| 48 | #define SINT32 (1 << 5) |
| 49 | #define ADDRIPV4 (1 << 6) |
| 50 | #define STRING (1 << 7) |
| 51 | #define ARRAY (1 << 8) |
| 52 | #define RFC3361 (1 << 9) |
| 53 | #define RFC3397 (1 << 10) |
| 54 | #define RFC3442 (1 << 11) |
| 55 | #define RFC5969 (1 << 12) |
| 56 | #define ADDRIPV6 (1 << 13) |
| 57 | #define BINHEX (1 << 14) |
| 58 | #define FLAG (1 << 15) |
| 59 | #define NOREQ (1 << 16) |
| 60 | #define EMBED (1 << 17) |
| 61 | #define ENCAP (1 << 18) |
| 62 | #define INDEX (1 << 19) |
| 63 | #define OPTION (1 << 20) |
| 64 | #define DOMAIN (1 << 21) |
| 65 | #define ASCII (1 << 22) |
| 66 | #define RAW (1 << 23) |
| 67 | #define ESCSTRING (1 << 24) |
| 68 | #define ESCFILE (1 << 25) |
Samuel Tan | ddbf02a | 2016-01-05 11:15:54 -0800 | [diff] [blame] | 69 | #define BITFLAG (1 << 26) |
Samuel Tan | d7ed851 | 2015-08-13 16:11:35 -0700 | [diff] [blame] | 70 | |
| 71 | struct dhcp_opt { |
| 72 | uint32_t option; /* Also used for IANA Enterpise Number */ |
| 73 | int type; |
| 74 | size_t len; |
| 75 | char *var; |
| 76 | |
| 77 | int index; /* Index counter for many instances of the same option */ |
| 78 | |
| 79 | /* Embedded options. |
| 80 | * The option code is irrelevant here. */ |
| 81 | struct dhcp_opt *embopts; |
| 82 | size_t embopts_len; |
| 83 | |
| 84 | /* Encapsulated options */ |
| 85 | struct dhcp_opt *encopts; |
| 86 | size_t encopts_len; |
| 87 | }; |
| 88 | |
| 89 | struct dhcp_opt *vivso_find(uint32_t, const void *); |
| 90 | |
| 91 | ssize_t dhcp_vendor(char *, size_t); |
| 92 | |
| 93 | void dhcp_print_option_encoding(const struct dhcp_opt *opt, int cols); |
| 94 | #define add_option_mask(var, val) \ |
| 95 | ((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] | 1 << ((val) & 7))) |
| 96 | #define del_option_mask(var, val) \ |
| 97 | ((var)[(val) >> 3] = (uint8_t)((var)[(val) >> 3] & ~(1 << ((val) & 7)))) |
| 98 | #define has_option_mask(var, val) \ |
| 99 | ((var)[(val) >> 3] & (uint8_t)(1 << ((val) & 7))) |
| 100 | int make_option_mask(const struct dhcp_opt *, size_t, |
| 101 | const struct dhcp_opt *, size_t, |
| 102 | uint8_t *, const char *, int); |
| 103 | |
| 104 | size_t encode_rfc1035(const char *src, uint8_t *dst); |
| 105 | ssize_t decode_rfc3397(char *, size_t, const uint8_t *, size_t); |
| 106 | ssize_t print_string(char *, size_t, int, const uint8_t *, size_t); |
| 107 | ssize_t print_option(char *, size_t, int, const uint8_t *, size_t, |
| 108 | const char *); |
| 109 | int dhcp_set_leasefile(char *, size_t, int, |
| 110 | const struct interface *, const char *); |
| 111 | |
| 112 | size_t dhcp_envoption(struct dhcpcd_ctx *, |
| 113 | char **, const char *, const char *, struct dhcp_opt *, |
| 114 | const uint8_t *(*dgetopt)(struct dhcpcd_ctx *, |
| 115 | size_t *, unsigned int *, size_t *, |
| 116 | const uint8_t *, size_t, struct dhcp_opt **), |
| 117 | const uint8_t *od, size_t ol); |
| 118 | void dhcp_zero_index(struct dhcp_opt *); |
| 119 | |
| 120 | #endif |