26 #define foreach_dhcp_sent_packet_stat \ 27 _(DISCOVER, "DHCP discover packets sent") \ 28 _(OFFER, "DHCP offer packets sent") \ 29 _(REQUEST, "DHCP request packets sent") \ 30 _(ACK, "DHCP ack packets sent") 32 #define foreach_dhcp_error_counter \ 33 _(NOT_FOR_US, "DHCP packets for other hosts, dropped") \ 34 _(NAK, "DHCP nak packets received") \ 35 _(NON_OFFER_DISCOVER, "DHCP non-offer packets in discover state") \ 36 _(ODDBALL, "DHCP non-ack, non-offer packets received") \ 37 _(BOUND, "DHCP bind success") 41 #define _(sym,str) DHCP_STAT_##sym, 49 #define _(sym,string) string, 52 "DHCP unknown packets sent",
95 "ip4-dhcp-client-detect",
100 if (c->
state == DHCP_BOUND)
113 .fp_addr.ip4.as_u32 = 0x0,
116 ip46_address_t
nh = {
136 ip46_address_t
dst = {
167 u8 dhcp_message_type = 0;
191 DHCP_STAT_NOT_FOR_US, 1);
203 while (o->
option != 0xFF &&
209 dhcp_message_type = o->
data[0];
214 u32 lease_time_in_seconds =
226 u32 lease_renew_time_in_seconds =
279 DHCP_STAT_NON_OFFER_DISCOVER, 1);
285 c->
state = DHCP_REQUEST;
291 (
u8 *) & client_id,
sizeof (
uword));
301 if (c->
state == DHCP_BOUND)
308 "ip4-dhcp-client-detect",
314 c->
state = DHCP_DISCOVER;
330 DHCP_STAT_NON_OFFER_DISCOVER, 1);
331 clib_warning (
"sw_if_index %d state %U message type %d",
333 c->
state, dhcp_message_type);
339 (
u8 *) c,
sizeof (*c));
341 c->
state = DHCP_BOUND;
377 u16 udp_length, ip_length;
432 clib_memset (ip, 0,
sizeof (*ip) +
sizeof (*udp) +
sizeof (*dhcp));
448 b->
flags |= VNET_BUFFER_F_QOS_DATA_VALID;
463 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client);
464 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server);
475 if (is_broadcast == 0)
502 *o2 = clib_host_to_net_u16 (1152);
570 ip->
length = clib_host_to_net_u16 (ip_length);
573 udp_length = ip_length - (
sizeof (*ip));
574 udp->
length = clib_host_to_net_u16 (udp_length);
578 #define _(a,b) case DHCP_PACKET_##a: {counter_index = DHCP_STAT_##a; break;} 601 "ip4-dhcp-client-detect",
628 c->
state = DHCP_DISCOVER;
655 "ip4-dhcp-client-detect",
675 .fp_addr.ip4.as_u32 = 0x0,
678 ip46_address_t
nh = {
690 c->
state = DHCP_DISCOVER;
717 if (now < c->next_transmit)
757 uword *event_data = 0;
773 for (i = 0; i <
vec_len (event_data); i++)
781 timeout = dhcp_client_sm (now, timeout,
782 (uword) (c - dcm->clients));
801 .name =
"dhcp-client-process",
802 .process_log2_n_stack_bytes = 16,
812 char *str =
"BOGUS!";
826 s =
format (s,
"%s", str);
835 int verbose = va_arg (*va,
int);
847 s =
format (s,
"addr %U/%d gw %U",
857 s =
format (s,
"no address\n");
864 "\n lease: lifetime:%d renewal-interval:%d expires:%.2f (now:%.2f)",
871 format (s,
"\n adjacencies:[unicast:%d broadcast:%d]", c->
ai_ucast,
893 else if (
unformat (input,
"verbose"))
899 if (sw_if_index != ~0)
912 vlib_cli_output (vm,
"%U",
913 format_dhcp_client, dcm,
923 .path =
"show dhcp client",
924 .short_help =
"show dhcp client [intfc <intfc>][verbose]",
939 .fp_addr.ip4.as_u32 = 0x0,
946 return VNET_API_ERROR_INVALID_VALUE;
953 c->
state = DHCP_DISCOVER;
986 "ip4-dhcp-client-detect",
999 ip46_address_t
nh = {
1090 case VNET_API_ERROR_INVALID_VALUE:
1097 clib_warning (
"dhcp client already enabled on intf_idx %d",
1100 clib_warning (
"dhcp client not enabled on on intf_idx %d",
1136 u8 sw_if_index_set = 0;
1137 u8 set_broadcast_flag = 1;
1146 sw_if_index_set = 1;
1147 else if (
unformat (input,
"hostname %v", &hostname))
1151 else if (
unformat (input,
"broadcast", &set_broadcast_flag))
1157 if (sw_if_index_set == 0)
1206 case VNET_API_ERROR_INVALID_VALUE:
1230 .path =
"set dhcp client",
1231 .short_help =
"set dhcp client [del] intfc <interface> [hostname <name>]",
static u8 * format_dhcp_client(u8 *s, va_list *va)
u8 client_detect_feature_enabled
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
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, dpo_proto_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_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Add one path to an entry (aka route) in the FIB.
#define hash_set(h, key, value)
static void dhcp_client_addr_callback(dhcp_client_t *c)
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)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
static void send_dhcp_pkt(dhcp_client_main_t *dcm, dhcp_client_t *c, dhcp_packet_type_t type, int is_broadcast)
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 void dhcp_client_release_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
static int dhcp_discover_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
u16 current_length
Nbytes between current data and the end of this buffer.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static u64 clib_cpu_time_now(void)
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
void dhcp_client_walk(dhcp_client_walk_cb_t cb, void *ctx)
Walk (visit each) DHCP client configuration.
void vlib_cli_output(struct vlib_main_t *vm, char *fmt,...)
unformat_function_t unformat_vnet_sw_interface
static int dhcp_request_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
static u8 * format_dhcp_client_state(u8 *s, va_list *va)
dhcp_event_cb_t event_callback
dhcp_client_state_t state
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 char * dhcp_client_process_stat_strings[]
format_function_t format_vnet_sw_if_index_name
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
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, u8 set_broadcast_flag, ip_dscp_t dscp, u32 pid)
Add/Delete DHCP clients.
#define clib_memcpy(d, s, n)
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
static vlib_node_registration_t dhcp_client_process_node
(constructor) VLIB_REGISTER_NODE (dhcp_client_process_node)
u32 lease_renewal_interval
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vl_api_interface_index_t sw_if_index
#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...
dhcp_event_cb_t event_callback
vnet_hw_interface_flags_t flags
static uword dhcp_client_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Aggregrate type for a prefix.
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
#define clib_error_return(e, args...)
static int dhcp_bound_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
vhost_vring_state_t state
u16 fp_len
The mask length.
static const u8 * vnet_sw_interface_get_hw_address(vnet_main_t *vnm, u32 sw_if_index)
vlib_node_registration_t ip4_arp_node
(constructor) VLIB_REGISTER_NODE (ip4_arp_node)
vl_api_fib_path_type_t type
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)
ip4_address_t leased_address
static void dhcp_client_acquire_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
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)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static f64 dhcp_client_sm(f64 now, f64 timeout, uword pool_index)
void(* dhcp_event_cb_t)(u32 client_index, const struct dhcp_client_t_ *client)
Callback function for DHCP complete events.
#define pool_put(P, E)
Free an object E in pool P.
vnet_sw_interface_flags_t flags
dhcp_client_main_t dhcp_client_main
u8 client_hardware_address[6]
static u32 counter_index(vlib_main_t *vm, vlib_error_t e)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static clib_error_t * show_dhcp_client_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
This packet matches an "incomplete adjacency" and packets need to be passed to ARP to find rewrite st...
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t ip4_rewrite_node
(constructor) VLIB_REGISTER_NODE (ip4_rewrite_node)
static_always_inline uword vlib_get_thread_index(void)
ip4_address_t * domain_server_address
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
static void dhcp_client_proc_callback(uword *client_index)
#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
enum ip_dscp_t_ ip_dscp_t
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, dpo_proto_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.
#define DHCP_FLAG_BROADCAST
ip4_address_t router_address
static vlib_main_t * vlib_get_main(void)
struct _vlib_node_registration vlib_node_registration_t
int(* dhcp_client_walk_cb_t)(const dhcp_client_t *client, void *data)
callback function for clients walking the DHCP client configurations
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
ip_lookup_next_t lookup_next_index
Next hop after ip4-lookup.
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
void dhcp_maybe_register_udp_ports(dhcp_port_reg_flags_t ports)
Register the dhcp client and/or server ports, if not already done.
uword * client_by_sw_if_index
int dhcp_client_add_del(dhcp_client_add_del_args_t *a)
static u32 random_u32(u32 *seed)
32-bit random number generator
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
#define vec_foreach(var, vec)
Vector iterator.
static uword count_set_bits(uword x)
static clib_error_t * dhcp_client_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
ip4_address_t dhcp_server
#define foreach_dhcp_sent_packet_stat
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
const ip46_address_t ADJ_BCAST_ADDR
The special broadcast address (to construct a broadcast adjacency.
#define foreach_dhcp_error_counter
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
static uword pool_elts(void *v)
Number of active elements in a pool.