2015-12-08 15:45:58 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 Cisco and/or its affiliates.
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* client.h: dhcp client
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef included_dhcp_client_h
|
|
|
|
|
#define included_dhcp_client_h
|
|
|
|
|
|
2017-02-14 07:28:41 -08:00
|
|
|
#include <vnet/ip/ip.h>
|
2019-10-07 00:39:28 -07:00
|
|
|
#include <dhcp/dhcp4_packet.h>
|
2017-02-14 07:28:41 -08:00
|
|
|
|
2015-12-08 15:45:58 -07:00
|
|
|
#define foreach_dhcp_client_state \
|
|
|
|
|
_(DHCP_DISCOVER) \
|
|
|
|
|
_(DHCP_REQUEST) \
|
|
|
|
|
_(DHCP_BOUND)
|
|
|
|
|
|
2017-12-08 18:06:52 +05:30
|
|
|
typedef enum
|
|
|
|
|
{
|
2015-12-08 15:45:58 -07:00
|
|
|
#define _(a) a,
|
|
|
|
|
foreach_dhcp_client_state
|
|
|
|
|
#undef _
|
|
|
|
|
} dhcp_client_state_t;
|
|
|
|
|
|
2018-05-16 04:12:18 -07:00
|
|
|
struct dhcp_client_t_;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback function for DHCP complete events
|
|
|
|
|
*/
|
|
|
|
|
typedef void (*dhcp_event_cb_t) (u32 client_index,
|
|
|
|
|
const struct dhcp_client_t_ * client);
|
|
|
|
|
|
2019-10-15 15:47:55 +00:00
|
|
|
/**
|
|
|
|
|
* The set of addresses/mask that contribute forwarding info
|
|
|
|
|
* and are installed.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct dhcp_client_fwd_addresses_t_
|
|
|
|
|
{
|
|
|
|
|
/** the address assigned to this client and it's mask */
|
|
|
|
|
ip4_address_t leased_address;
|
|
|
|
|
u32 subnet_mask_width;
|
|
|
|
|
|
|
|
|
|
/** the address of the DHCP server handing out the address.
|
|
|
|
|
this is used to send any unicast messages */
|
|
|
|
|
ip4_address_t dhcp_server;
|
|
|
|
|
|
|
|
|
|
/** The address of this client's default gateway - may not be present */
|
|
|
|
|
ip4_address_t router_address;
|
|
|
|
|
} dhcp_client_fwd_addresses_t;
|
|
|
|
|
|
2018-05-16 04:12:18 -07:00
|
|
|
typedef struct dhcp_client_t_
|
2017-12-08 18:06:52 +05:30
|
|
|
{
|
2015-12-08 15:45:58 -07:00
|
|
|
dhcp_client_state_t state;
|
|
|
|
|
|
|
|
|
|
/* the interface in question */
|
|
|
|
|
u32 sw_if_index;
|
|
|
|
|
|
|
|
|
|
/* State machine retry counter */
|
|
|
|
|
u32 retry_count;
|
|
|
|
|
|
|
|
|
|
/* Send next pkt at this time */
|
|
|
|
|
f64 next_transmit;
|
|
|
|
|
f64 lease_expires;
|
|
|
|
|
|
|
|
|
|
/* DHCP transaction ID, a random number */
|
|
|
|
|
u32 transaction_id;
|
|
|
|
|
|
2019-10-15 15:47:55 +00:00
|
|
|
/**
|
|
|
|
|
* leased address, other learned info DHCP
|
|
|
|
|
* the learned set is updated by new messages recieved in the DP
|
|
|
|
|
* the installed set is what's actually been added
|
|
|
|
|
*/
|
|
|
|
|
dhcp_client_fwd_addresses_t learned;
|
|
|
|
|
dhcp_client_fwd_addresses_t installed;
|
|
|
|
|
/* have local Addresses and default route been installed */
|
|
|
|
|
u8 addresses_installed;
|
|
|
|
|
|
2019-04-29 12:00:43 +08:00
|
|
|
ip4_address_t *domain_server_address; /* option 6 */
|
2017-12-08 18:06:52 +05:30
|
|
|
u32 lease_renewal_interval; /* option 51 */
|
|
|
|
|
u32 lease_lifetime; /* option 59 */
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
/* Requested data (option 55) */
|
2017-12-08 18:06:52 +05:30
|
|
|
u8 *option_55_data;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
/* hostname and software client identifiers */
|
2017-12-08 18:06:52 +05:30
|
|
|
u8 *hostname;
|
|
|
|
|
u8 *client_identifier; /* software version, e.g. vpe 1.0 */
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
/* Information used for event callback */
|
|
|
|
|
u32 client_index;
|
|
|
|
|
u32 pid;
|
2018-01-17 10:29:10 -08:00
|
|
|
|
|
|
|
|
/* Set the broadcast Flag in the Discover/Request messages */
|
|
|
|
|
u8 set_broadcast_flag;
|
2018-03-23 09:52:52 -04:00
|
|
|
/* Interface MAC address, so we can do an rx-packet-for-us check */
|
|
|
|
|
u8 client_hardware_address[6];
|
VPP-1294: add missing feature arc constraint
the ip4-dhcp-client-detect feature MUST run prior to nat44-out2in, or
inbound dhcp broadcast packets will be dropped. Certain dhcp servers
answer lease renewal dhcp-request packets with broadcast dhcp-acks, leading
to unrecoverable lease loss.
In detail, this constraint:
VNET_FEATURE_INIT (ip4_snat_out2in, static) = {
.arc_name = "ip4-unicast",
.node_name = "nat44-out2in",
.runs_after = VNET_FEATURES ("acl-plugin-in-ip4-fa"),
};
doesn't get the job done:
ip4-unicast:
[17] nat44-out2in
[23] ip4-dhcp-client-detect
[26] ip4-not-enabled
Add a proper constraint:
VNET_FEATURE_INIT (ip4_snat_out2in, static) = {
.arc_name = "ip4-unicast",
.node_name = "nat44-out2in",
.runs_after = VNET_FEATURES ("acl-plugin-in-ip4-fa",
"ip4-dhcp-client-detect"),
};
and the interface feature order is OK, at least in this regard:
ip4-unicast:
[17] ip4-dhcp-client-detect
[18] nat44-out2in
[26] ip4-not-enabled
We need to carefully audit (especially) the ip4-unicast feature arc,
which has [gasp] 37 features on it!
Change-Id: I5e749ead7ab2a25d80839a331de6261e112977ad
Signed-off-by: Dave Barach <dave@barachs.net>
2018-05-26 10:48:55 -04:00
|
|
|
u8 client_detect_feature_enabled;
|
2018-01-17 10:29:10 -08:00
|
|
|
|
2019-07-25 06:11:58 -07:00
|
|
|
/* the unicast adjacency for the DHCP server */
|
|
|
|
|
adj_index_t ai_ucast;
|
|
|
|
|
/* the broadcast adjacency on the link */
|
|
|
|
|
adj_index_t ai_bcast;
|
2019-07-19 14:01:02 +00:00
|
|
|
/* IP DSCP to set in sent packets */
|
|
|
|
|
ip_dscp_t dscp;
|
2019-07-25 06:11:58 -07:00
|
|
|
|
2018-05-16 04:12:18 -07:00
|
|
|
dhcp_event_cb_t event_callback;
|
2015-12-08 15:45:58 -07:00
|
|
|
} dhcp_client_t;
|
|
|
|
|
|
2017-12-08 18:06:52 +05:30
|
|
|
typedef struct
|
|
|
|
|
{
|
2015-12-08 15:45:58 -07:00
|
|
|
/* DHCP client pool */
|
2017-12-08 18:06:52 +05:30
|
|
|
dhcp_client_t *clients;
|
|
|
|
|
uword *client_by_sw_if_index;
|
2015-12-08 15:45:58 -07:00
|
|
|
u32 seed;
|
|
|
|
|
|
|
|
|
|
/* convenience */
|
2017-12-08 18:06:52 +05:30
|
|
|
vlib_main_t *vlib_main;
|
|
|
|
|
vnet_main_t *vnet_main;
|
2015-12-08 15:45:58 -07:00
|
|
|
} dhcp_client_main_t;
|
|
|
|
|
|
2017-12-08 18:06:52 +05:30
|
|
|
typedef struct
|
|
|
|
|
{
|
2015-12-08 15:45:58 -07:00
|
|
|
int is_add;
|
|
|
|
|
u32 sw_if_index;
|
2018-01-17 10:29:10 -08:00
|
|
|
u8 set_broadcast_flag;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
/* vectors, consumed by dhcp client code */
|
2017-12-08 18:06:52 +05:30
|
|
|
u8 *hostname;
|
|
|
|
|
u8 *client_identifier;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
/* Bytes containing requested option numbers */
|
2017-12-08 18:06:52 +05:30
|
|
|
u8 *option_55_data;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
/* Information used for event callback */
|
|
|
|
|
u32 client_index;
|
|
|
|
|
u32 pid;
|
2019-07-19 14:01:02 +00:00
|
|
|
ip_dscp_t dscp;
|
2018-05-16 04:12:18 -07:00
|
|
|
dhcp_event_cb_t event_callback;
|
2015-12-08 15:45:58 -07:00
|
|
|
} dhcp_client_add_del_args_t;
|
|
|
|
|
|
2017-10-24 01:32:41 -04:00
|
|
|
extern dhcp_client_main_t dhcp_client_main;
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
#define EVENT_DHCP_CLIENT_WAKEUP 1
|
|
|
|
|
|
2017-12-08 18:06:52 +05:30
|
|
|
int dhcp_client_for_us (u32 bi0,
|
|
|
|
|
vlib_buffer_t * b0,
|
|
|
|
|
ip4_header_t * ip0,
|
|
|
|
|
udp_header_t * u0, dhcp_header_t * dh0);
|
2015-12-08 15:45:58 -07:00
|
|
|
|
2018-05-16 04:12:18 -07:00
|
|
|
/**
|
|
|
|
|
* Add/Delete DHCP clients
|
|
|
|
|
*/
|
|
|
|
|
extern int dhcp_client_config (u32 is_add,
|
|
|
|
|
u32 client_index,
|
|
|
|
|
vlib_main_t * vm,
|
|
|
|
|
u32 sw_if_index,
|
|
|
|
|
u8 * hostname,
|
|
|
|
|
u8 * client_id,
|
|
|
|
|
dhcp_event_cb_t event_callback,
|
2019-07-19 14:01:02 +00:00
|
|
|
u8 set_broadcast_flag,
|
|
|
|
|
ip_dscp_t dscp, u32 pid);
|
2018-05-16 04:12:18 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* callback function for clients walking the DHCP client configurations
|
|
|
|
|
*
|
|
|
|
|
* @param client The client being visitsed
|
|
|
|
|
* @param data The data passed during the call to 'walk'
|
|
|
|
|
* @return !0 to continue walking 0 to stop.
|
|
|
|
|
*/
|
|
|
|
|
typedef int (*dhcp_client_walk_cb_t) (const dhcp_client_t * client,
|
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Walk (visit each) DHCP client configuration
|
|
|
|
|
*
|
|
|
|
|
* @param cb The callback function invoked as each client is visited
|
|
|
|
|
* @param ctx Context data passed back to the client in the invocation of
|
|
|
|
|
* the callback.
|
|
|
|
|
*/
|
|
|
|
|
extern void dhcp_client_walk (dhcp_client_walk_cb_t cb, void *ctx);
|
2015-12-08 15:45:58 -07:00
|
|
|
|
|
|
|
|
#endif /* included_dhcp_client_h */
|
2017-12-08 18:06:52 +05:30
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* fd.io coding-style-patch-verification: ON
|
|
|
|
|
*
|
|
|
|
|
* Local Variables:
|
|
|
|
|
* eval: (c-set-style "gnu")
|
|
|
|
|
* End:
|
|
|
|
|
*/
|