76 u8 dhcp_message_type = 0;
101 while (o->
option != 0xFF &&
107 dhcp_message_type = o->
data[0];
112 u32 lease_time_in_seconds =
123 u32 lease_renew_time_in_seconds =
169 clib_warning (
"sw_if_index %d state %U message type %d",
171 c->
state, dhcp_message_type);
176 c->
state = DHCP_REQUEST;
188 clib_warning (
"sw_if_index %d state %U message type %d",
190 c->
state, dhcp_message_type);
195 if (c->
state == DHCP_REQUEST)
209 .fp_addr.ip4.as_u32 = 0x0,
245 c->
state = DHCP_BOUND;
280 u16 udp_length, ip_length;
331 memset (ip, 0,
sizeof (*ip) +
sizeof (*udp) +
sizeof (*dhcp));
349 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client);
350 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server);
356 if (is_broadcast == 0)
381 *o2 = clib_host_to_net_u16 (1152);
441 ip->
length = clib_host_to_net_u16(ip_length);
444 udp_length = ip_length - (
sizeof (*ip));
445 udp->
length = clib_host_to_net_u16 (udp_length);
477 c->
state = DHCP_DISCOVER;
509 .fp_addr.ip4.as_u32 = 0x0,
512 ip46_address_t nh = {
530 c->
state = DHCP_DISCOVER;
556 if (now < c->next_transmit)
597 uword * event_data = 0;
613 for (i = 0; i <
vec_len (event_data); i++)
620 timeout = dhcp_client_sm (now, timeout,
621 (uword)(c - dcm->clients));
638 .name =
"dhcp-client-process",
639 .process_log2_n_stack_bytes = 16,
645 char * str =
"BOGUS!";
659 s =
format (s,
"%s", str);
667 int verbose = va_arg (*va,
int);
674 s =
format (s,
"addr %U/%d gw %U\n",
678 s =
format (s,
"no address\n");
682 s =
format (s,
"retry count %d, next xmt %.2f",
696 u32 sw_if_index = ~0;
705 else if (
unformat (input,
"verbose"))
711 if (sw_if_index != ~0)
723 vlib_cli_output (vm,
"%U", format_dhcp_client, dcm, c, verbose);
730 .path =
"show dhcp client",
731 .short_help =
"show dhcp client [intfc <intfc>][verbose]",
745 .fp_addr.ip4.as_u32 = 0xffffffff,
751 .fp_addr.ip4.as_u32 = 0x0,
758 return VNET_API_ERROR_INVALID_VALUE;
763 memset (c, 0,
sizeof (*c));
764 c->
state = DHCP_DISCOVER;
807 ip46_address_t nh = {
841 void * event_callback,
847 memset (a, 0,
sizeof (*a));
895 case VNET_API_ERROR_INVALID_VALUE:
902 clib_warning (
"dhcp client already enabled on intf_idx %d",
905 clib_warning (
"dhcp client not enabled on on intf_idx %d",
925 u8 sw_if_index_set = 0;
936 else if (
unformat (input,
"hostname %v", &hostname))
944 if (sw_if_index_set == 0)
947 memset (a, 0,
sizeof (*a));
992 case VNET_API_ERROR_INVALID_VALUE:
1015 .path =
"set dhcp client",
1016 .short_help =
"set dhcp client [del] intfc <interface> [hostname <name>]",
1027 dcm->
seed = 0xdeaddabe;
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
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
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
#define hash_unset(h, key)
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
vnet_main_t * vnet_get_main(void)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static f64 vlib_time_now(vlib_main_t *vm)
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
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
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_protocol_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_route_path_flags_t path_flags)
remove one path to an entry (aka route) in the FIB.
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
unformat_function_t unformat_vnet_sw_interface
#define VNET_HW_INTERFACE_FLAG_LINK_UP
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
static void dhcp_client_acquire_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
format_function_t format_vnet_sw_if_index_name
int dhcp_client_add_del(dhcp_client_add_del_args_t *a)
static vlib_node_registration_t dhcp_client_process_node
(constructor) VLIB_REGISTER_NODE (dhcp_client_process_node)
#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)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a 'special' entry from the FIB.
static void dhcp_client_release_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Aggregrate type for a prefix.
#define clib_error_return(e, args...)
static uword dhcp_client_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
u16 fp_len
The mask length.
fib_node_index_t fib_table_entry_path_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_protocol_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Add one path to an entry (aka route) in the FIB.
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)
Returns pointer to element at given index.
void ip4_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
u16 current_length
Nbytes between current data and the end of this buffer.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define pool_put(P, E)
Free an object E in pool P.
u8 * vnet_build_rewrite_for_sw_interface(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a 'special' entry to the FIB.
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_warning(format, args...)
#define clib_memcpy(a, b, c)
dhcp_client_state_t state
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#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)
#define DHCP_FLAG_BROADCAST
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
ip4_address_t dhcp_server
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
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 u32 random_u32(u32 *seed)
32-bit random number generator
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
static uword count_set_bits(uword x)
ip4_address_t router_address
static clib_error_t * dhcp_client_init(vlib_main_t *vm)
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
ip4_address_t leased_address
static u16 ip4_header_checksum(ip4_header_t *i)
static uword pool_elts(void *v)
Number of active elements in a pool.