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 #pragma once 16 17 #define DHCPV4_CLIENT_PORT 68 18 #define DHCPV4_SERVER_PORT 67 19 20 #define DHCPV4_FLAG_BROADCAST 0x8000 21 22 #define DHCPV4_MIN_PACKET_SIZE 300 23 24 #define DHCPV4_FR_MIN_DELAY 500 25 #define DHCPV4_FR_MAX_FUZZ 500 26 27 enum dhcpv4_op { 28 DHCPV4_OP_BOOTREQUEST = 1, 29 DHCPV4_OP_BOOTREPLY = 2, 30 }; 31 32 // https://www.iana.org/assignments/bootp-dhcp-parameters/bootp-dhcp-parameters.xhtml#message-type-53 33 enum dhcpv4_msg { 34 DHCPV4_MSG_DISCOVER = 1, // RFC2132 35 DHCPV4_MSG_OFFER = 2, // RFC2132 36 DHCPV4_MSG_REQUEST = 3, // RFC2132 37 DHCPV4_MSG_DECLINE = 4, // RFC2132 38 DHCPV4_MSG_ACK = 5, // RFC2132 39 DHCPV4_MSG_NAK = 6, // RFC2132 40 DHCPV4_MSG_RELEASE = 7, // RFC2132 41 DHCPV4_MSG_INFORM = 8, // RFC2132 42 DHCPV4_MSG_FORCERENEW = 9, // RFC3203 43 DHCPV4_MSG_LEASEQUERY = 10, // RFC4388 44 DHCPV4_MSG_LEASEUNASSIGNED = 11, // RFC4388 45 DHCPV4_MSG_LEASEUNKNOWN = 12, // RFC4388 46 DHCPV4_MSG_LEASEACTIVE = 13, // RFC4388 47 DHCPV4_MSG_BULKLEASEQUERY = 14, // RFC6926 48 DHCPV4_MSG_LEASEQUERYDONE = 15, // RFC6926 49 DHCPV4_MSG_ACTIVELEASEQUERY = 16, // RFC7724 50 DHCPV4_MSG_LEASEQUERYSTATUS = 17, // RFC7724 51 DHCPV4_MSG_TLS = 18, // RFC7724 52 }; 53 54 enum dhcpv4_opt { 55 DHCPV4_OPT_PAD = 0, 56 DHCPV4_OPT_NETMASK = 1, 57 DHCPV4_OPT_ROUTER = 3, 58 DHCPV4_OPT_DNSSERVER = 6, 59 DHCPV4_OPT_DOMAIN = 15, 60 DHCPV4_OPT_MTU = 26, 61 DHCPV4_OPT_BROADCAST = 28, 62 DHCPV4_OPT_NTPSERVER = 42, 63 DHCPV4_OPT_LEASETIME = 51, 64 DHCPV4_OPT_MESSAGE = 53, 65 DHCPV4_OPT_SERVERID = 54, 66 DHCPV4_OPT_REQOPTS = 55, 67 DHCPV4_OPT_RENEW = 58, 68 DHCPV4_OPT_REBIND = 59, 69 DHCPV4_OPT_IPADDRESS = 50, 70 DHCPV4_OPT_HOSTNAME = 12, 71 DHCPV4_OPT_REQUEST = 17, 72 DHCPV4_OPT_USER_CLASS = 77, 73 DHCPV4_OPT_AUTHENTICATION = 90, 74 DHCPV4_OPT_SEARCH_DOMAIN = 119, 75 DHCPV4_OPT_FORCERENEW_NONCE_CAPABLE = 145, 76 DHCPV4_OPT_DNR = 162, 77 DHCPV4_OPT_END = 255, 78 }; 79 80 struct dhcpv4_message { 81 uint8_t op; 82 uint8_t htype; 83 uint8_t hlen; 84 uint8_t hops; 85 uint32_t xid; 86 uint16_t secs; 87 uint16_t flags; 88 struct in_addr ciaddr; 89 struct in_addr yiaddr; 90 struct in_addr siaddr; 91 struct in_addr giaddr; 92 uint8_t chaddr[16]; 93 char sname[64]; 94 char file[128]; 95 uint32_t cookie; 96 uint8_t options[308]; 97 } _packed; 98 99 // RFC2131, §3 100 #define DHCPV4_MAGIC_COOKIE 0x63825363 101 102 // RFC3203, §6; RFC3118, §2; RFC6704, §3.1.2 103 struct dhcpv4_auth_forcerenew { 104 uint8_t protocol; 105 uint8_t algorithm; 106 uint8_t rdm; 107 uint32_t replay[2]; 108 uint8_t type; 109 uint8_t key[16]; 110 } _packed; 111 112 // https://www.iana.org/assignments/auth-namespaces/auth-namespaces.xhtml#auth-namespaces-1 113 enum dhcpv4_auth_protocol { 114 DHCPV4_AUTH_PROTO_CFG_TOKEN = 0, // RFC3118 115 DHCPV4_AUTH_PROTO_DELAYED = 1, // RFC3118 116 DHCPV4_AUTH_PROTO_DELAYED_OBS = 2, // RFC8415, Obsolete 117 DHCPV4_AUTH_PROTO_RKAP = 3, // RFC8415, also RFC6704 118 DHCPV4_AUTH_PROTO_SPLIT_DNS = 4, // RFC9704 119 }; 120 121 // https://www.iana.org/assignments/auth-namespaces/auth-namespaces.xhtml#auth-namespaces-2 122 enum dhcpv4_auth_algorithm { 123 DHCPV4_AUTH_ALG_CFG_TOKEN = 0, // RFC3118 124 DHCPV4_AUTH_ALG_HMAC_MD5 = 1, // RFC3118, RFC8415, also RFC6704 125 }; 126 127 // https://www.iana.org/assignments/auth-namespaces/auth-namespaces.xhtml#auth-namespaces-2 128 enum dhcpv4_auth_rdm { 129 DHCPV4_AUTH_RDM_MONOTONIC = 0, // RFC3118, RFC8415, also RFC6704 130 }; 131 132 // RFC6704, §3.1.2 (for DHCPv6: RFC8415, §20.4) 133 enum dhcpv4_auth_rkap_ai_type { 134 DHCPV4_AUTH_RKAP_AI_TYPE_KEY = 1, 135 DHCPV4_AUTH_RKAP_AI_TYPE_MD5_DIGEST = 2, 136 }; 137 138 struct dhcpv4_option { 139 uint8_t type; 140 uint8_t len; 141 uint8_t data[]; 142 }; 143 144 /* DNR */ 145 struct dhcpv4_dnr { 146 uint16_t len; 147 uint16_t priority; 148 uint8_t adn_len; 149 uint8_t body[]; 150 }; 151 152 153 #define dhcpv4_for_each_option(start, end, opt)\ 154 for (opt = (struct dhcpv4_option*)(start); \ 155 &opt[1] <= (struct dhcpv4_option*)(end) && \ 156 &opt->data[opt->len] <= (end); \ 157 opt = (struct dhcpv4_option*)&opt->data[opt->len]) 158
This page was automatically generated by LXR 0.3.1. • OpenWrt