Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * client.h: dhcp client |
| 17 | */ |
| 18 | |
| 19 | #ifndef included_dhcp_client_h |
| 20 | #define included_dhcp_client_h |
| 21 | |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 22 | #include <vnet/ip/ip.h> |
Neale Ranns | 2dd6852 | 2017-02-16 03:38:59 -0800 | [diff] [blame] | 23 | #include <vnet/dhcp/dhcp4_packet.h> |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 24 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | #define foreach_dhcp_client_state \ |
| 26 | _(DHCP_DISCOVER) \ |
| 27 | _(DHCP_REQUEST) \ |
| 28 | _(DHCP_BOUND) |
| 29 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 30 | typedef enum |
| 31 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | #define _(a) a, |
| 33 | foreach_dhcp_client_state |
| 34 | #undef _ |
| 35 | } dhcp_client_state_t; |
| 36 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 37 | typedef struct |
| 38 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | dhcp_client_state_t state; |
| 40 | |
| 41 | /* the interface in question */ |
| 42 | u32 sw_if_index; |
| 43 | |
| 44 | /* State machine retry counter */ |
| 45 | u32 retry_count; |
| 46 | |
| 47 | /* Send next pkt at this time */ |
| 48 | f64 next_transmit; |
| 49 | f64 lease_expires; |
| 50 | |
| 51 | /* DHCP transaction ID, a random number */ |
| 52 | u32 transaction_id; |
| 53 | |
| 54 | /* leased address, other learned info DHCP */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 55 | ip4_address_t leased_address; /* from your_ip_address field */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | ip4_address_t dhcp_server; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 57 | u32 subnet_mask_width; /* option 1 */ |
| 58 | ip4_address_t router_address; /* option 3 */ |
| 59 | u32 lease_renewal_interval; /* option 51 */ |
| 60 | u32 lease_lifetime; /* option 59 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | |
| 62 | /* Requested data (option 55) */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 63 | u8 *option_55_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 65 | u8 *l2_rewrite; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | |
| 67 | /* hostname and software client identifiers */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 68 | u8 *hostname; |
| 69 | u8 *client_identifier; /* software version, e.g. vpe 1.0 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | |
| 71 | /* Information used for event callback */ |
| 72 | u32 client_index; |
| 73 | u32 pid; |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 74 | |
| 75 | /* Set the broadcast Flag in the Discover/Request messages */ |
| 76 | u8 set_broadcast_flag; |
| 77 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 78 | void *event_callback; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | } dhcp_client_t; |
| 80 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 81 | typedef struct |
| 82 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | /* DHCP client pool */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 84 | dhcp_client_t *clients; |
| 85 | uword *client_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | u32 seed; |
| 87 | |
| 88 | /* convenience */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 89 | vlib_main_t *vlib_main; |
| 90 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | } dhcp_client_main_t; |
| 92 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 93 | typedef struct |
| 94 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | int is_add; |
| 96 | u32 sw_if_index; |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 97 | u8 set_broadcast_flag; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 98 | |
| 99 | /* vectors, consumed by dhcp client code */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 100 | u8 *hostname; |
| 101 | u8 *client_identifier; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | |
| 103 | /* Bytes containing requested option numbers */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 104 | u8 *option_55_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
| 106 | /* Information used for event callback */ |
| 107 | u32 client_index; |
| 108 | u32 pid; |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 109 | void *event_callback; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | } dhcp_client_add_del_args_t; |
| 111 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 112 | extern dhcp_client_main_t dhcp_client_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | |
| 114 | #define EVENT_DHCP_CLIENT_WAKEUP 1 |
| 115 | |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 116 | int dhcp_client_for_us (u32 bi0, |
| 117 | vlib_buffer_t * b0, |
| 118 | ip4_header_t * ip0, |
| 119 | udp_header_t * u0, dhcp_header_t * dh0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | |
| 121 | int dhcp_client_config (vlib_main_t * vm, |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 122 | u32 sw_if_index, |
| 123 | u8 * hostname, |
| 124 | u8 * client_id, |
| 125 | u32 is_add, |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 126 | u32 client_index, |
| 127 | void *event_callback, u8 set_broadcast_flag, u32 pid); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 128 | |
| 129 | #endif /* included_dhcp_client_h */ |
khemendra kumar | 34719e3 | 2017-12-08 18:06:52 +0530 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * fd.io coding-style-patch-verification: ON |
| 133 | * |
| 134 | * Local Variables: |
| 135 | * eval: (c-set-style "gnu") |
| 136 | * End: |
| 137 | */ |