Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 1 | #ifndef included_vnet_dhcp6_packet_h |
| 2 | #define included_vnet_dhcp6_packet_h |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * DHCP packet format |
| 6 | * |
| 7 | * Copyright (c) 2013 Cisco and/or its affiliates. |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at: |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | #include <vnet/ip/ip6_packet.h> |
| 21 | |
| 22 | // #define DHCP_VRF_NAME_MAX_LEN L3VM_MAX_NAME_STR_LEN |
| 23 | // #define DHCPV6_MAX_VRF_NAME_LEN L3VM_MAX_NAME_STR_LEN |
| 24 | #define DHCP_MAX_RELAY_ADDR 16 |
| 25 | #define PROTO_UDP 17 |
| 26 | #define DHCPV6_CLIENT_PORT 546 |
| 27 | #define DHCPV6_SERVER_PORT 547 |
| 28 | #define HOP_COUNT_LIMIT 32 |
| 29 | #define DHCPV6_CISCO_ENT_NUM 9 |
| 30 | |
| 31 | /* |
| 32 | * DHCPv6 message types |
| 33 | */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 34 | typedef enum dhcpv6_msg_type_ |
| 35 | { |
| 36 | DHCPV6_MSG_SOLICIT = 1, |
| 37 | DHCPV6_MSG_ADVERTISE = 2, |
| 38 | DHCPV6_MSG_REQUEST = 3, |
| 39 | DHCPV6_MSG_CONFIRM = 4, |
| 40 | DHCPV6_MSG_RENEW = 5, |
| 41 | DHCPV6_MSG_REBIND = 6, |
| 42 | DHCPV6_MSG_REPLY = 7, |
| 43 | DHCPV6_MSG_RELEASE = 8, |
| 44 | DHCPV6_MSG_DECLINE = 9, |
| 45 | DHCPV6_MSG_RECONFIGURE = 10, |
| 46 | DHCPV6_MSG_INFORMATION_REQUEST = 11, |
| 47 | DHCPV6_MSG_RELAY_FORW = 12, |
| 48 | DHCPV6_MSG_RELAY_REPL = 13, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | } dhcpv6_msg_type_t; |
| 50 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 51 | /* Name, code, min payload length */ |
| 52 | #define dhcpv6_foreach_option \ |
| 53 | _(CLIENTID , 1 , 4 ) \ |
| 54 | _(SERVERID , 2 , 4 ) \ |
| 55 | _(IA_NA , 3 , 12) \ |
| 56 | _(IA_TA , 4 , 4 ) \ |
| 57 | _(IAADDR , 5 , 24) \ |
| 58 | _(ORO , 6 , 0 ) \ |
| 59 | _(PREFERENCE , 7 , 1 ) \ |
| 60 | _(ELAPSED_TIME , 8 , 2 ) \ |
| 61 | _(RELAY_MSG , 9 , 0 ) \ |
| 62 | _(AUTH , 11 , 11) \ |
| 63 | _(UNICAST , 12 , 16) \ |
| 64 | _(STATUS_CODE , 13 , 2 ) \ |
| 65 | _(RAPID_COMMIT , 14 , 0 ) \ |
| 66 | _(USER_CLASS , 15 , 0 ) \ |
| 67 | _(VENDOR_CLASS , 16 , 4 ) \ |
| 68 | _(VENDOR_OPTS , 17 , 4 ) \ |
| 69 | _(INTERFACE_ID , 18 , 0 ) \ |
| 70 | _(RECONF_MSG , 19 , 1 ) \ |
| 71 | _(RECONF_ACCEPT , 20 , 0 ) \ |
| 72 | _(DNS_SEARCH , 24 , 0 ) \ |
| 73 | _(IA_PD , 25 , 12) \ |
| 74 | _(IAPREFIX , 26 , 25) \ |
| 75 | _(REMOTEID , 37 , 4 ) \ |
| 76 | _(VSS , 68 , 1 ) \ |
| 77 | _(CLIENT_LINK_LAYER_ADDRESS, 79 , 2 ) |
| 78 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | /* |
| 80 | * DHCPv6 options types |
| 81 | */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 82 | enum |
| 83 | { |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 84 | #define _(a,b,c) DHCPV6_OPTION_##a = b, |
| 85 | dhcpv6_foreach_option |
| 86 | #undef _ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 87 | DHCPV6_OPTION_MAX |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * DHCPv6 status codes |
| 92 | */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 93 | enum |
| 94 | { |
| 95 | DHCPV6_STATUS_SUCCESS = 0, |
| 96 | DHCPV6_STATUS_UNSPEC_FAIL = 1, |
| 97 | DHCPV6_STATUS_NOADDRS_AVAIL = 2, |
| 98 | DHCPV6_STATUS_NO_BINDING = 3, |
| 99 | DHCPV6_STATUS_NOT_ONLINK = 4, |
| 100 | DHCPV6_STATUS_USE_MULTICAST = 5, |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 101 | DHCPV6_STATUS_NOPREFIX_AVAIL = 6, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * DHCPv6 DUID types |
| 106 | */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 107 | enum |
| 108 | { |
| 109 | DHCPV6_DUID_LLT = 1, /* DUID Based on Link-layer Address Plus Time */ |
| 110 | DHCPV6_DUID_EN = 2, /* DUID Based on Enterprise Number */ |
| 111 | DHCPV6_DUID_LL = 3, /* DUID Based on Link-layer Address */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | //Structure for DHCPv6 payload from client |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 115 | typedef struct dhcpv6_hdr_ |
| 116 | { |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 117 | u8 msg_type; //DHCP msg type |
| 118 | u8 xid[3]; //Transaction id |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 119 | u8 data[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | } dhcpv6_header_t; |
| 121 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 122 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | typedef CLIB_PACKED (struct dhcpv6_relay_ctx_ { |
| 124 | dhcpv6_header_t *pkt; |
| 125 | u32 pkt_len; |
| 126 | u32 dhcpv6_len; //DHCPv6 payload load |
| 127 | // if_ordinal iod; |
| 128 | u32 if_index; |
| 129 | u32 ctx_id; |
| 130 | char ctx_name[32+1]; |
| 131 | u8 dhcp_msg_type; |
| 132 | }) dhcpv6_relay_ctx_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 133 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | |
| 135 | //Structure for DHCPv6 RELAY-FORWARD and DHCPv6 RELAY-REPLY pkts |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 136 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 137 | typedef CLIB_PACKED (struct dhcpv6_relay_hdr_ { |
| 138 | u8 msg_type; |
| 139 | u8 hop_count; |
| 140 | ip6_address_t link_addr; |
| 141 | ip6_address_t peer_addr; |
| 142 | u8 data[0]; |
| 143 | }) dhcpv6_relay_hdr_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 144 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 146 | typedef enum dhcp_stats_action_type_ |
| 147 | { |
| 148 | DHCP_STATS_ACTION_FORWARDED = 1, |
| 149 | DHCP_STATS_ACTION_RECEIVED, |
| 150 | DHCP_STATS_ACTION_DROPPED |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | } dhcp_stats_action_type_t; |
| 152 | //Generic counters for a packet |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 153 | typedef struct dhcp_stats_counters_ |
| 154 | { |
| 155 | u64 rx_pkts; //counter for received pkts |
| 156 | u64 tx_pkts; //counter for forwarded pkts |
| 157 | u64 drops; //counter for dropped pkts |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | } dhcp_stats_counters_t; |
| 159 | |
| 160 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 161 | typedef enum dhcpv6_stats_drop_reason_ |
| 162 | { |
| 163 | DHCPV6_RELAY_PKT_DROP_RELAYDISABLE = 1, |
| 164 | DHCPV6_RELAY_PKT_DROP_MAX_HOPS, |
| 165 | DHCPV6_RELAY_PKT_DROP_VALIDATION_FAIL, |
| 166 | DHCPV6_RELAY_PKT_DROP_UNKNOWN_OP_INTF, |
| 167 | DHCPV6_RELAY_PKT_DROP_BAD_CONTEXT, |
| 168 | DHCPV6_RELAY_PKT_DROP_OPT_INSERT_FAIL, |
| 169 | DHCPV6_RELAY_PKT_DROP_REPLY_FROM_CLIENT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | } dhcpv6_stats_drop_reason_t; |
| 171 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 172 | #define dhcpv6_optlen(opt) clib_net_to_host_u16((opt)->length) |
| 173 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 174 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | typedef CLIB_PACKED (struct { |
| 176 | u16 option; |
| 177 | u16 length; |
| 178 | u8 data[0]; |
| 179 | }) dhcpv6_option_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 180 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 182 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | typedef CLIB_PACKED (struct { |
| 184 | dhcpv6_option_t opt; |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 185 | u16 status_code; |
| 186 | }) dhcpv6_status_code_t; |
| 187 | /* *INDENT-ON* */ |
| 188 | |
| 189 | /* *INDENT-OFF* */ |
| 190 | typedef CLIB_PACKED (struct { |
| 191 | dhcpv6_option_t opt; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | u32 int_idx; |
| 193 | }) dhcpv6_int_id_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 194 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 196 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | typedef CLIB_PACKED (struct { |
| 198 | dhcpv6_option_t opt; |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 199 | u8 vss_type; |
| 200 | u8 data[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | }) dhcpv6_vss_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 202 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 203 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 204 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | typedef CLIB_PACKED (struct { |
| 206 | dhcpv6_option_t opt; |
| 207 | u32 ent_num; |
| 208 | u32 rmt_id; |
| 209 | }) dhcpv6_rmt_id_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 210 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 211 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 212 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | typedef CLIB_PACKED (struct { |
| 214 | dhcpv6_option_t opt; |
| 215 | u16 link_type; |
| 216 | u8 data[6]; // data[0]:data[5]: MAC address |
| 217 | }) dhcpv6_client_mac_t; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 218 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 220 | typedef CLIB_PACKED (struct |
| 221 | { |
| 222 | dhcpv6_option_t opt; u32 iaid; u32 t1; |
| 223 | u32 t2; |
| 224 | u8 data[0]; |
| 225 | }) dhcpv6_ia_header_t; |
| 226 | |
| 227 | typedef CLIB_PACKED (struct |
| 228 | { |
| 229 | dhcpv6_option_t opt; u32 preferred; u32 valid; u8 prefix; |
| 230 | ip6_address_t addr; |
| 231 | }) dhcpv6_ia_opt_pd_t; |
| 232 | |
| 233 | typedef CLIB_PACKED (struct |
| 234 | { |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame^] | 235 | dhcpv6_option_t opt; ip6_address_t addr; u32 preferred; |
| 236 | u32 valid; |
| 237 | }) dhcpv6_ia_opt_addr_t; |
| 238 | |
| 239 | typedef CLIB_PACKED (struct |
| 240 | { |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 241 | dhcpv6_option_t opt; |
| 242 | u16 options[0]; |
| 243 | }) dhcpv6_oro_t; |
| 244 | |
| 245 | typedef CLIB_PACKED (struct |
| 246 | { |
| 247 | dhcpv6_option_t opt; u16 elapsed_10ms; |
| 248 | }) dhcpv6_elapsed_t; |
| 249 | |
| 250 | typedef CLIB_PACKED (struct |
| 251 | { |
| 252 | dhcpv6_option_t opt; u16 duid_type; |
| 253 | u16 hardware_type; |
| 254 | }) dhcpv6_duid_t; |
| 255 | |
| 256 | typedef CLIB_PACKED (struct |
| 257 | { |
| 258 | dhcpv6_option_t opt; u16 status_code; |
| 259 | u8 message[0]; |
| 260 | }) dhcpv6_status_t; |
| 261 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 262 | |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 263 | #endif /* included_vnet_dhcp6_packet_h */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 264 | |
| 265 | /* |
| 266 | * fd.io coding-style-patch-verification: ON |
| 267 | * |
| 268 | * Local Variables: |
| 269 | * eval: (c-set-style "gnu") |
| 270 | * End: |
| 271 | */ |