1 /** 2 * Copyright (C) 2012 Steven Barth <steven@midlink.org> 3 * Copyright (C) 2016 Hans Dedecker <dedeckeh@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 7 * as published by the Free Software Foundation. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License version 2 for more details. 13 * 14 */ 15 16 #ifndef _DHCPV4_H_ 17 #define _DHCPV4_H_ 18 19 #define DHCPV4_CLIENT_PORT 68 20 #define DHCPV4_SERVER_PORT 67 21 #define DHCPV4_MAX_PREFIX_LEN 28 22 23 #define DHCPV4_FLAG_BROADCAST 0x8000 24 25 // RFC951, §3; RFC1542, §2.1; RFC2131, §2 26 // draft-ietf-dhc-implementation-02, §4.19.1 27 #define DHCPV4_MIN_PACKET_SIZE 300 28 29 #define DHCPV4_FR_MIN_DELAY 500 30 #define DHCPV4_FR_MAX_FUZZ 500 31 32 // RFC8925, §3.4 33 #define DHCPV4_MIN_V6ONLY_WAIT 300 34 35 // RFC4361, §6.1 36 #define DHCPV4_CLIENTID_TYPE_DUID_IAID 255 37 38 enum dhcpv4_op { 39 DHCPV4_OP_BOOTREQUEST = 1, 40 DHCPV4_OP_BOOTREPLY = 2, 41 }; 42 43 // https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#message-type-53 44 enum dhcpv4_msg { 45 DHCPV4_MSG_DISCOVER = 1, // RFC2132 46 DHCPV4_MSG_OFFER = 2, // RFC2132 47 DHCPV4_MSG_REQUEST = 3, // RFC2132 48 DHCPV4_MSG_DECLINE = 4, // RFC2132 49 DHCPV4_MSG_ACK = 5, // RFC2132 50 DHCPV4_MSG_NAK = 6, // RFC2132 51 DHCPV4_MSG_RELEASE = 7, // RFC2132 52 DHCPV4_MSG_INFORM = 8, // RFC2132 53 DHCPV4_MSG_FORCERENEW = 9, // RFC3203 54 DHCPV4_MSG_LEASEQUERY = 10, // RFC4388 55 DHCPV4_MSG_LEASEUNASSIGNED = 11, // RFC4388 56 DHCPV4_MSG_LEASEUNKNOWN = 12, // RFC4388 57 DHCPV4_MSG_LEASEACTIVE = 13, // RFC4388 58 DHCPV4_MSG_BULKLEASEQUERY = 14, // RFC6926 59 DHCPV4_MSG_LEASEQUERYDONE = 15, // RFC6926 60 DHCPV4_MSG_ACTIVELEASEQUERY = 16, // RFC7724 61 DHCPV4_MSG_LEASEQUERYSTATUS = 17, // RFC7724 62 DHCPV4_MSG_TLS = 18, // RFC7724 63 }; 64 65 enum dhcpv4_opt { 66 DHCPV4_OPT_PAD = 0, 67 DHCPV4_OPT_NETMASK = 1, 68 DHCPV4_OPT_ROUTER = 3, 69 DHCPV4_OPT_DNSSERVER = 6, 70 DHCPV4_OPT_HOSTNAME = 12, 71 DHCPV4_OPT_DOMAIN = 15, 72 DHCPV4_OPT_REQUEST = 17, 73 DHCPV4_OPT_MTU = 26, 74 DHCPV4_OPT_BROADCAST = 28, 75 DHCPV4_OPT_NTPSERVER = 42, 76 DHCPV4_OPT_IPADDRESS = 50, 77 DHCPV4_OPT_LEASETIME = 51, 78 DHCPV4_OPT_MESSAGE = 53, 79 DHCPV4_OPT_SERVERID = 54, 80 DHCPV4_OPT_REQOPTS = 55, 81 DHCPV4_OPT_RENEW = 58, 82 DHCPV4_OPT_REBIND = 59, 83 DHCPV4_OPT_CLIENTID = 61, 84 DHCPV4_OPT_USER_CLASS = 77, 85 DHCPV4_OPT_AUTHENTICATION = 90, 86 DHCPV4_OPT_IPV6_ONLY_PREFERRED = 108, // RFC8925 87 DHCPV4_OPT_CAPTIVE_PORTAL = 114, // RFC8910 88 DHCPV4_OPT_DNS_DOMAIN_SEARCH = 119, 89 DHCPV4_OPT_FORCERENEW_NONCE_CAPABLE = 145, 90 DHCPV4_OPT_DNR = 162, 91 DHCPV4_OPT_END = 255, 92 }; 93 94 struct dhcpv4_message { 95 uint8_t op; 96 uint8_t htype; 97 uint8_t hlen; 98 uint8_t hops; 99 uint32_t xid; 100 uint16_t secs; 101 uint16_t flags; 102 struct in_addr ciaddr; 103 struct in_addr yiaddr; 104 struct in_addr siaddr; 105 struct in_addr giaddr; 106 uint8_t chaddr[16]; 107 char sname[64]; 108 char file[128]; 109 uint32_t cookie; 110 uint8_t options[]; 111 } _o_packed; 112 113 // RFC2131, §3 114 #define DHCPV4_MAGIC_COOKIE 0x63825363 115 116 // RFC3203, §6; RFC3118, §2; RFC6704, §3.1.2 117 struct dhcpv4_auth_forcerenew { 118 uint8_t protocol; 119 uint8_t algorithm; 120 uint8_t rdm; 121 uint32_t replay[2]; 122 uint8_t type; 123 uint8_t key[16]; 124 } _o_packed; 125 126 // https://www.iana.org/assignments/auth-namespaces/auth-namespaces.xhtml#auth-namespaces-1 127 enum dhcpv4_auth_protocol { 128 DHCPV4_AUTH_PROTO_CFG_TOKEN = 0, // RFC3118 129 DHCPV4_AUTH_PROTO_DELAYED = 1, // RFC3118 130 DHCPV4_AUTH_PROTO_DELAYED_OBS = 2, // RFC8415, Obsolete 131 DHCPV4_AUTH_PROTO_RKAP = 3, // RFC8415, also RFC6704 132 DHCPV4_AUTH_PROTO_SPLIT_DNS = 4, // RFC9704 133 }; 134 135 // https://www.iana.org/assignments/auth-namespaces/auth-namespaces.xhtml#auth-namespaces-2 136 enum dhcpv4_auth_algorithm { 137 DHCPV4_AUTH_ALG_CFG_TOKEN = 0, // RFC3118 138 DHCPV4_AUTH_ALG_HMAC_MD5 = 1, // RFC3118, RFC8415, also RFC6704 139 }; 140 141 // https://www.iana.org/assignments/auth-namespaces/auth-namespaces.xhtml#auth-namespaces-2 142 enum dhcpv4_auth_rdm { 143 DHCPV4_AUTH_RDM_MONOTONIC = 0, // RFC3118, RFC8415, also RFC6704 144 }; 145 146 // RFC6704, §3.1.2 (for DHCPv6: RFC8415, §20.4) 147 enum dhcpv4_auth_rkap_ai_type { 148 DHCPV4_AUTH_RKAP_AI_TYPE_KEY = 1, 149 DHCPV4_AUTH_RKAP_AI_TYPE_MD5_DIGEST = 2, 150 }; 151 152 struct dhcpv4_option { 153 uint8_t code; 154 uint8_t len; 155 uint8_t data[]; 156 }; 157 158 struct dhcpv4_option_u8 { 159 uint8_t code; 160 uint8_t len; 161 uint8_t data; 162 }; 163 164 struct dhcpv4_option_u16 { 165 uint8_t code; 166 uint8_t len; 167 uint16_t data; 168 }; 169 170 struct dhcpv4_option_u32 { 171 uint8_t code; 172 uint8_t len; 173 uint32_t data; 174 } _o_packed; 175 176 /* DNR */ 177 struct dhcpv4_dnr { 178 uint16_t len; 179 uint16_t priority; 180 uint8_t adn_len; 181 uint8_t body[]; 182 }; 183 184 185 #define dhcpv4_for_each_option(start, end, opt)\ 186 for (opt = (struct dhcpv4_option*)(start); \ 187 &opt[1] <= (struct dhcpv4_option*)(end) && \ 188 &opt->data[opt->len] <= (end); \ 189 opt = (struct dhcpv4_option*)&opt->data[opt->len]) 190 191 #endif /* _DHCPV4_H_ */ 192
This page was automatically generated by LXR 0.3.1. • OpenWrt