22 void __attribute__((weak))
24 u32 sw_if_index,
u8 *next_hop_addr)
66 VNET_L3_PACKET_TYPE_IP4,
90 u8 dhcp_message_type = 0;
115 while (o->
option != 0xFF &&
121 dhcp_message_type = o->
data[0];
126 u32 lease_time_in_seconds =
137 u32 lease_renew_time_in_seconds =
183 clib_warning (
"sw_if_index %d state %U message type %d",
185 c->
state, dhcp_message_type);
190 c->
state = DHCP_REQUEST;
202 clib_warning (
"sw_if_index %d state %U message type %d",
204 c->
state, dhcp_message_type);
209 if (c->
state == DHCP_REQUEST)
239 c->
state = DHCP_BOUND;
274 u16 udp_length, ip_length;
325 memset (ip, 0,
sizeof (*ip) +
sizeof (*udp) +
sizeof (*dhcp));
343 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client);
344 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server);
350 if (is_broadcast == 0)
375 *o2 = clib_host_to_net_u16 (1152);
435 ip->
length = clib_host_to_net_u16(ip_length);
438 udp_length = ip_length - (
sizeof (*ip));
439 udp->
length = clib_host_to_net_u16 (udp_length);
471 c->
state = DHCP_DISCOVER;
506 c->
state = DHCP_DISCOVER;
532 if (now < c->next_transmit)
573 uword * event_data = 0;
589 for (i = 0; i <
vec_len (event_data); i++)
596 timeout = dhcp_client_sm (now, timeout,
597 (uword)(c - dcm->clients));
614 .name =
"dhcp-client-process",
615 .process_log2_n_stack_bytes = 16,
621 char * str =
"BOGUS!";
635 s =
format (s,
"%s", str);
643 int verbose = va_arg (*va,
int);
650 s =
format (s,
"addr %U/%d gw %U\n",
654 s =
format (s,
"no address\n");
658 s =
format (s,
"retry count %d, next xmt %.2f",
672 u32 sw_if_index = ~0;
681 else if (
unformat (input,
"verbose"))
687 if (sw_if_index != ~0)
699 vlib_cli_output (vm,
"%U", format_dhcp_client, dcm, c, verbose);
706 .path =
"show dhcp client",
707 .short_help =
"show dhcp client [intfc <intfc>][verbose]",
722 return VNET_API_ERROR_INVALID_VALUE;
727 memset (c, 0,
sizeof (*c));
728 c->
state = DHCP_DISCOVER;
770 void * event_callback,
776 memset (a, 0,
sizeof (*a));
824 case VNET_API_ERROR_INVALID_VALUE:
831 clib_warning (
"dhcp client already enabled on intf_idx %d",
834 clib_warning (
"dhcp client not enabled on on intf_idx %d",
854 u8 sw_if_index_set = 0;
865 else if (
unformat (input,
"hostname %v", &hostname))
873 if (sw_if_index_set == 0)
876 memset (a, 0,
sizeof (*a));
921 case VNET_API_ERROR_INVALID_VALUE:
944 .path =
"set dhcp client",
945 .short_help =
"set dhcp client [del] intfc <interface> [hostname <name>]",
956 dcm->
seed = 0xdeaddabe;
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
static int dhcp_discover_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
always_inline uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
#define hash_unset(h, key)
static void(BVT(clib_bihash)*h, BVT(clib_bihash_value)*v)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
#define DHCP_FLAG_BROADCAST
always_inline vnet_hw_interface_class_t * vnet_get_hw_interface_class(vnet_main_t *vnm, u32 hw_class_index)
static u8 * format_dhcp_client(u8 *s, va_list *va)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct _vlib_node_registration vlib_node_registration_t
always_inline void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
unformat_function_t unformat_vnet_sw_interface
#define VNET_HW_INTERFACE_FLAG_LINK_UP
static void dhcp_client_acquire_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
format_function_t format_vnet_sw_if_index_name
always_inline void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
int dhcp_client_add_del(dhcp_client_add_del_args_t *a)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
vnet_main_t * vnet_get_main(void)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define pool_foreach(VAR, POOL, BODY)
#define VLIB_INIT_FUNCTION(x)
static void dhcp_client_release_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
always_inline uword pool_elts(void *v)
always_inline uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define clib_warning(format, args...)
static uword dhcp_client_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
always_inline u32 random_u32(u32 *seed)
32-bit random number generator
always_inline void * vlib_frame_vector_args(vlib_frame_t *f)
void api_config_default_ip_route(u8 is_ipv6, u8 is_add, u32 vrf_id, u32 sw_if_index, u8 *next_hop_addr)
always_inline uword count_set_bits(uword x)
clib_error_t * ip4_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 is_del)
#define pool_elt_at_index(p, i)
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
u16 current_length
Nbytes between current data and the end of this buffer.
always_inline f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
always_inline u16 ip4_header_checksum(ip4_header_t *i)
static void send_dhcp_pkt(dhcp_client_main_t *dcm, dhcp_client_t *c, dhcp_packet_type_t type, int is_broadcast)
static f64 dhcp_client_sm(f64 now, f64 timeout, uword pool_index)
#define vec_free(V)
Free vector's memory (no header).
#define clib_memcpy(a, b, c)
static vlib_node_registration_t dhcp_client_process_node
(constructor) VLIB_REGISTER_NODE (dhcp_client_process_node)
always_inline vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
dhcp_client_state_t state
#define pool_is_free_index(P, I)
always_inline vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define VLIB_CLI_COMMAND(x,...)
#define EVENT_DHCP_CLIENT_WAKEUP
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
u32 lease_renewal_interval
vhost_vring_state_t state
int dhcp_client_config(vlib_main_t *vm, u32 sw_if_index, u8 *hostname, u32 is_add, u32 client_index, void *event_callback, u32 pid)
static void set_l2_rewrite(dhcp_client_main_t *dcm, dhcp_client_t *c)
u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
struct _vnet_hw_interface_class vnet_hw_interface_class_t
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
always_inline vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
ip4_address_t dhcp_server
static int dhcp_bound_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
uword * client_by_sw_if_index
static int dhcp_request_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
static clib_error_t * show_dhcp_client_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u8 * format_dhcp_client_state(u8 *s, va_list *va)
static clib_error_t * dhcp_client_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VLIB_REGISTER_NODE(x,...)
dhcp_client_main_t dhcp_client_main
always_inline f64 vlib_time_now(vlib_main_t *vm)
ip4_address_t router_address
static clib_error_t * dhcp_client_init(vlib_main_t *vm)
#define clib_error_return(e, args...)
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
ip4_address_t leased_address