dhcp: fix unicast pkts, clean up state machine
Nominally a bug-fix cherry-pick, but completely manual. Closer to a full feature backport minus binary api changes. Send dhcp unicast packets to ip4-lookup. Otherwise, these packets won't reach a dhcp server on a different subnet. Do an immediate client scan after processing wakeup events. Calculate the next process wakeup time by scanning all clients. Increase maximum (idle, no-clients-configured) timeout to 1000 seconds. Reduce log spew. Type: fix Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I3d10cd4c353298ed0b19e7e30887dc1d8d07b19e (cherry picked from commit c54162981cdd41d65ed283df36955007552ddffe)
This commit is contained in:
@ -26,6 +26,7 @@
|
||||
#include <vlibmemory/socket_client.h>
|
||||
|
||||
void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
|
||||
void vl_api_force_rpc_call_main_thread (void *fp, u8 * data, u32 data_length);
|
||||
u16 vl_client_get_first_plugin_msg_id (const char *plugin_name);
|
||||
void vl_api_send_pending_rpc_requests (vlib_main_t * vm);
|
||||
u8 *vl_api_serialize_message_table (api_main_t * am, u8 * vector);
|
||||
|
@ -890,6 +890,7 @@ list(APPEND VNET_API_FILES lisp-gpe/lisp_gpe.api)
|
||||
##############################################################################
|
||||
list(APPEND VNET_SOURCES
|
||||
dhcp/client.c
|
||||
dhcp/dhcp4_packet.c
|
||||
dhcp/dhcp_client_detect.c
|
||||
dhcp/dhcp6_client_common_dp.c
|
||||
dhcp/dhcp6_pd_client_dp.c
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -42,6 +42,24 @@ struct dhcp_client_t_;
|
||||
typedef void (*dhcp_event_cb_t) (u32 client_index,
|
||||
const struct dhcp_client_t_ * client);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
typedef struct dhcp_client_t_
|
||||
{
|
||||
dhcp_client_state_t state;
|
||||
@ -59,11 +77,16 @@ typedef struct dhcp_client_t_
|
||||
/* DHCP transaction ID, a random number */
|
||||
u32 transaction_id;
|
||||
|
||||
/* leased address, other learned info DHCP */
|
||||
ip4_address_t leased_address; /* from your_ip_address field */
|
||||
ip4_address_t dhcp_server;
|
||||
u32 subnet_mask_width; /* option 1 */
|
||||
ip4_address_t router_address; /* option 3 */
|
||||
/**
|
||||
* 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;
|
||||
|
||||
ip4_address_t *domain_server_address; /* option 6 */
|
||||
u32 lease_renewal_interval; /* option 51 */
|
||||
u32 lease_lifetime; /* option 59 */
|
||||
@ -85,8 +108,6 @@ typedef struct dhcp_client_t_
|
||||
u8 client_hardware_address[6];
|
||||
u8 client_detect_feature_enabled;
|
||||
|
||||
/* the unicast adjacency for the DHCP server */
|
||||
adj_index_t ai_ucast;
|
||||
/* the broadcast adjacency on the link */
|
||||
adj_index_t ai_bcast;
|
||||
/* IP DSCP to set in sent packets */
|
||||
@ -102,6 +123,9 @@ typedef struct
|
||||
uword *client_by_sw_if_index;
|
||||
u32 seed;
|
||||
|
||||
/* ip4-lookup node index */
|
||||
u32 ip4_lookup_node_index;
|
||||
|
||||
/* convenience */
|
||||
vlib_main_t *vlib_main;
|
||||
vnet_main_t *vnet_main;
|
||||
|
122
src/vnet/dhcp/dhcp4_packet.c
Normal file
122
src/vnet/dhcp/dhcp4_packet.c
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* dhcp4_packet.c: dhcp packet format functions
|
||||
*
|
||||
* Copyright (c) 2013 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.
|
||||
*/
|
||||
|
||||
#include <vnet/dhcp/dhcp4_packet.h>
|
||||
#include <vnet/ip/format.h>
|
||||
|
||||
u8 *
|
||||
format_dhcp_packet_type (u8 * s, va_list * args)
|
||||
{
|
||||
dhcp_packet_type_t pt = va_arg (*args, dhcp_packet_type_t);
|
||||
|
||||
switch (pt)
|
||||
{
|
||||
case DHCP_PACKET_DISCOVER:
|
||||
s = format (s, "discover");
|
||||
break;
|
||||
case DHCP_PACKET_OFFER:
|
||||
s = format (s, "offer");
|
||||
break;
|
||||
case DHCP_PACKET_REQUEST:
|
||||
s = format (s, "request");
|
||||
break;
|
||||
case DHCP_PACKET_ACK:
|
||||
s = format (s, "ack");
|
||||
break;
|
||||
case DHCP_PACKET_NAK:
|
||||
s = format (s, "nack");
|
||||
break;
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
||||
u8 *
|
||||
format_dhcp_header (u8 * s, va_list * args)
|
||||
{
|
||||
dhcp_header_t *d = va_arg (*args, dhcp_header_t *);
|
||||
u32 max_bytes = va_arg (*args, u32);
|
||||
dhcp_option_t *o;
|
||||
u32 tmp;
|
||||
|
||||
s = format (s, "opcode:%s", (d->opcode == 1 ? "request" : "reply"));
|
||||
s = format (s, " hw[type:%d addr-len:%d addr:%U]",
|
||||
d->hardware_type, d->hardware_address_length,
|
||||
format_hex_bytes, d->client_hardware_address,
|
||||
d->hardware_address_length);
|
||||
s = format (s, " hops%d", d->hops);
|
||||
s = format (s, " transaction-ID:0x%x", d->transaction_identifier);
|
||||
s = format (s, " seconds:%d", d->seconds);
|
||||
s = format (s, " flags:0x%x", d->flags);
|
||||
s = format (s, " client:%U", format_ip4_address, &d->client_ip_address);
|
||||
s = format (s, " your:%U", format_ip4_address, &d->your_ip_address);
|
||||
s = format (s, " server:%U", format_ip4_address, &d->server_ip_address);
|
||||
s = format (s, " gateway:%U", format_ip4_address, &d->gateway_ip_address);
|
||||
s = format (s, " cookie:%U", format_ip4_address, &d->magic_cookie);
|
||||
|
||||
o = (dhcp_option_t *) d->options;
|
||||
|
||||
while (o->option != 0xFF /* end of options */ &&
|
||||
(u8 *) o < (u8 *) d + max_bytes)
|
||||
{
|
||||
switch (o->option)
|
||||
{
|
||||
case 53: /* dhcp message type */
|
||||
tmp = o->data[0];
|
||||
s =
|
||||
format (s, ", option-53: type:%U", format_dhcp_packet_type, tmp);
|
||||
break;
|
||||
case 54: /* dhcp server address */
|
||||
s = format (s, ", option-54: server:%U",
|
||||
format_ip4_address, &o->data_as_u32[0]);
|
||||
break;
|
||||
case 58: /* lease renew time in seconds */
|
||||
s = format (s, ", option-58: renewal:%d",
|
||||
clib_host_to_net_u32 (o->data_as_u32[0]));
|
||||
break;
|
||||
case 1: /* subnet mask */
|
||||
s = format (s, ", option-1: subnet-mask:%d",
|
||||
clib_host_to_net_u32 (o->data_as_u32[0]));
|
||||
break;
|
||||
case 3: /* router address */
|
||||
s = format (s, ", option-3: router:%U",
|
||||
format_ip4_address, &o->data_as_u32[0]);
|
||||
break;
|
||||
case 6: /* domain server address */
|
||||
s = format (s, ", option-6: domian-server:%U",
|
||||
format_hex_bytes, o->data, o->length);
|
||||
break;
|
||||
case 12: /* hostname */
|
||||
s = format (s, ", option-12: hostname:%U",
|
||||
format_hex_bytes, o->data, o->length);
|
||||
break;
|
||||
default:
|
||||
tmp = o->option;
|
||||
s = format (s, " option-%d: skipped", tmp);
|
||||
break;
|
||||
}
|
||||
o = (dhcp_option_t *) (((u8 *) o) + (o->length + 2));
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
||||
/*
|
||||
* fd.io coding-style-patch-verification: ON
|
||||
*
|
||||
* Local Variables:
|
||||
* eval: (c-set-style "gnu")
|
||||
* End:
|
||||
*/
|
@ -51,6 +51,8 @@ typedef struct
|
||||
dhcp_option_t options[0];
|
||||
} dhcp_header_t;
|
||||
|
||||
extern u8 *format_dhcp_header (u8 * s, va_list * args);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DHCP_PACKET_DISCOVER = 1,
|
||||
@ -60,6 +62,8 @@ typedef enum
|
||||
DHCP_PACKET_NAK,
|
||||
} dhcp_packet_type_t;
|
||||
|
||||
extern u8 *format_dhcp_packet_type (u8 * s, va_list * args);
|
||||
|
||||
typedef enum dhcp_packet_option_t_
|
||||
{
|
||||
DHCP_PACKET_OPTION_MSG_TYPE = 53,
|
||||
|
@ -228,10 +228,12 @@ dhcp_client_lease_encode (vl_api_dhcp_lease_t * lease,
|
||||
clib_memcpy (&lease->hostname, client->hostname, len);
|
||||
lease->hostname[len] = 0;
|
||||
|
||||
lease->mask_width = client->subnet_mask_width;
|
||||
clib_memcpy (&lease->host_address[0], (u8 *) & client->leased_address,
|
||||
lease->mask_width = client->installed.subnet_mask_width;
|
||||
clib_memcpy (&lease->host_address[0],
|
||||
(u8 *) & client->installed.leased_address,
|
||||
sizeof (ip4_address_t));
|
||||
clib_memcpy (&lease->router_address[0], (u8 *) & client->router_address,
|
||||
clib_memcpy (&lease->router_address[0],
|
||||
(u8 *) & client->installed.router_address,
|
||||
sizeof (ip4_address_t));
|
||||
|
||||
lease->count = vec_len (client->domain_server_address);
|
||||
|
@ -242,6 +242,7 @@ class TestDHCP(VppTestCase):
|
||||
self.verify_dhcp_msg_type(pkt, "discover")
|
||||
self.verify_dhcp_has_option(pkt, "hostname", hostname)
|
||||
if client_id:
|
||||
client_id = '\x00' + client_id
|
||||
self.verify_dhcp_has_option(pkt, "client_id", client_id)
|
||||
bootp = pkt[BOOTP]
|
||||
self.assertEqual(bootp.ciaddr, "0.0.0.0")
|
||||
|
Reference in New Issue
Block a user