summaryrefslogtreecommitdiffstats
path: root/src/vnet/dhcp
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2019-10-01 11:30:56 +0200
committerOle Trøan <otroan@employees.org>2019-10-03 10:07:21 +0000
commit103ba6ba9ecd1d65bcbd3bb4edc115beb9ee7671 (patch)
treeeca605b6a3860425958b501b9eb215f8ac84326c /src/vnet/dhcp
parentd6d50cebde647f9a5ee7251a7fef977506f315d7 (diff)
dhcp: API cleanup
Use consistent API types. Type: fix Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com> Change-Id: Ia63d920788add2584060a240321acced7a471640
Diffstat (limited to 'src/vnet/dhcp')
-rw-r--r--src/vnet/dhcp/dhcp.api122
-rw-r--r--src/vnet/dhcp/dhcp6_ia_na_client_cp.c4
-rw-r--r--src/vnet/dhcp/dhcp6_ia_na_client_dp.c7
-rw-r--r--src/vnet/dhcp/dhcp6_pd_client_cp.c14
-rw-r--r--src/vnet/dhcp/dhcp6_pd_client_dp.c11
-rw-r--r--src/vnet/dhcp/dhcp_api.c44
6 files changed, 116 insertions, 86 deletions
diff --git a/src/vnet/dhcp/dhcp.api b/src/vnet/dhcp/dhcp.api
index c84b3639103..f3fef5135f1 100644
--- a/src/vnet/dhcp/dhcp.api
+++ b/src/vnet/dhcp/dhcp.api
@@ -13,16 +13,47 @@
* limitations under the License.
*/
-option version = "2.0.1";
+option version = "3.0.1";
+import "vnet/interface_types.api";
import "vnet/ip/ip_types.api";
+import "vnet/ethernet/ethernet_types.api";
+
+enum vss_type {
+ VSS_TYPE_API_ASCII = 0,
+ VSS_TYPE_API_VPN_ID = 1,
+ VSS_TYPE_API_INVALID = 123,
+ VSS_TYPE_API_DEFAULT = 255,
+};
+
+enum dhcp_client_state {
+ DHCP_CLIENT_STATE_API_DISCOVER,
+ DHCP_CLIENT_STATE_API_REQUEST,
+ DHCP_CLIENT_STATE_API_BOUND,
+};
+
+enum dhcpv6_msg_type
+{
+ DHCPV6_MSG_API_SOLICIT = 1,
+ DHCPV6_MSG_API_ADVERTISE = 2,
+ DHCPV6_MSG_API_REQUEST = 3,
+ DHCPV6_MSG_API_CONFIRM = 4,
+ DHCPV6_MSG_API_RENEW = 5,
+ DHCPV6_MSG_API_REBIND = 6,
+ DHCPV6_MSG_API_REPLY = 7,
+ DHCPV6_MSG_API_RELEASE = 8,
+ DHCPV6_MSG_API_DECLINE = 9,
+ DHCPV6_MSG_API_RECONFIGURE = 10,
+ DHCPV6_MSG_API_INFORMATION_REQUEST = 11,
+ DHCPV6_MSG_API_RELAY_FORW = 12,
+ DHCPV6_MSG_API_RELAY_REPL = 13,
+};
/** \brief DHCP Proxy config add / del request
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param rx_vrf_id - Rx/interface vrf id
@param server_vrf_id - server vrf id
- @param if_ipv6 - ipv6 if non-zero, else ipv4
@param is_add - add the config if non-zero, else delete
@param insert_circuit_id - option82 suboption 1 fib number
@param dhcp_server[] - server address
@@ -34,10 +65,9 @@ autoreply define dhcp_proxy_config
u32 context;
u32 rx_vrf_id;
u32 server_vrf_id;
- u8 is_ipv6;
- u8 is_add;
- u8 dhcp_server[16];
- u8 dhcp_src_address[16];
+ bool is_add;
+ vl_api_address_t dhcp_server;
+ vl_api_address_t dhcp_src_address;
};
/** \brief DHCP Proxy set / unset vss request
@@ -46,7 +76,7 @@ autoreply define dhcp_proxy_config
@param tbl_id - table id
@vss_type - 0: use ASCI vpn_id; 1: use oui/vpn_index; 255: global vpn
@vpn_ascii - null terminated ASCII VPN ID up to 128 characters
- @param oui - first part of rfc2685 vpn id, 3 bytes oui
+ @param oui - first part of rfc2685 vpn id, 3 bytes oui
@param vpn_index - second part of rfc2685 vpn id, 4 bytes vpn index
@param is_ipv6 - ip6 if non-zero, else ip4
@param is_add - set vss if non-zero, else delete
@@ -56,12 +86,12 @@ autoreply define dhcp_proxy_set_vss
u32 client_index;
u32 context;
u32 tbl_id;
- u8 vss_type;
- u8 vpn_ascii_id[129];
+ vl_api_vss_type_t vss_type;
+ string vpn_ascii_id[129];
u32 oui;
u32 vpn_index;
- u8 is_ipv6;
- u8 is_add;
+ bool is_ipv6;
+ bool is_add;
};
/** \brief DHCP Client config data
@@ -77,11 +107,11 @@ autoreply define dhcp_proxy_set_vss
*/
typedef dhcp_client
{
- u32 sw_if_index;
- u8 hostname[64];
+ vl_api_interface_index_t sw_if_index;
+ string hostname[64];
u8 id[64];
- u8 want_dhcp_event;
- u8 set_broadcast_flag;
+ bool want_dhcp_event;
+ bool set_broadcast_flag;
vl_api_ip_dscp_t dscp;
u32 pid;
};
@@ -96,7 +126,7 @@ autoreply define dhcp_client_config
{
u32 client_index;
u32 context;
- u8 is_add;
+ bool is_add;
vl_api_dhcp_client_t client;
};
@@ -105,12 +135,12 @@ autoreply define dhcp_client_config
*/
typedef domain_server
{
- u8 address[16];
+ vl_api_address_t address;
};
/** \brief Data learned by the client during the DHCP process
@param sw_if_index - the interface on which the client is configured
- @param state - the state of the lease (see dhcp_client_state_t)
+ @param state - the state of the lease
@param is_ipv6 - if non-zero the address is ipv6, else ipv4
@param mask_width - The length of the subnet mask assigned
@param host_address - Host IP address
@@ -119,14 +149,14 @@ typedef domain_server
*/
typedef dhcp_lease
{
- u32 sw_if_index;
- u8 state;
- u8 hostname[64];
- u8 is_ipv6;
+ vl_api_interface_index_t sw_if_index;
+ vl_api_dhcp_client_state_t state;
+ bool is_ipv6;
+ string hostname[64];
u8 mask_width;
- u8 host_address[16];
- u8 router_address[16];
- u8 host_mac[6];
+ vl_api_address_t host_address;
+ vl_api_address_t router_address;
+ vl_api_mac_address_t host_mac;
u8 count;
vl_api_domain_server_t domain_server[count];
};
@@ -174,13 +204,13 @@ define dhcp_proxy_dump
{
u32 client_index;
u32 context;
- u8 is_ip6;
+ bool is_ip6;
};
typedef dhcp_server
{
u32 server_vrf_id;
- u8 dhcp_server[16];
+ vl_api_address_t dhcp_server;
};
/** \brief Tell client about a DHCP completion event
@@ -192,10 +222,10 @@ manual_endian manual_print define dhcp_proxy_details
u32 rx_vrf_id;
u32 vss_oui;
u32 vss_fib_id;
- u8 vss_type;
- u8 vss_vpn_ascii_id[129];
- u8 is_ipv6;
- u8 dhcp_src_address[16];
+ vl_api_vss_type_t vss_type;
+ bool is_ipv6;
+ string vss_vpn_ascii_id[129];
+ vl_api_address_t dhcp_src_address;
u8 count;
vl_api_dhcp_server_t servers[count];
};
@@ -220,7 +250,7 @@ autoreply define dhcp6_clients_enable_disable
{
u32 client_index;
u32 context;
- u8 enable;
+ bool enable;
};
/** \brief Struct representing DHCPv6 address
@@ -230,21 +260,19 @@ autoreply define dhcp6_clients_enable_disable
*/
typedef dhcp6_address_info
{
- u8 address[16];
+ vl_api_ip6_address_t address;
u32 valid_time;
u32 preferred_time;
};
/** \brief Struct representing DHCPv6 PD prefix
@param prefix - prefix
- @param prefix_length - prefix length
@param valid_time - valid lifetime
@param preferred_time - preferred lifetime
*/
typedef dhcp6_pd_prefix_info
{
- u8 prefix[16];
- u8 prefix_length;
+ vl_api_ip6_prefix_t prefix;
u32 valid_time;
u32 preferred_time;
};
@@ -274,14 +302,14 @@ autoreply define dhcp6_send_client_message
{
u32 client_index;
u32 context;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
u32 irt;
u32 mrt;
u32 mrc;
u32 mrd;
- u8 stop;
- u8 msg_type;
+ bool stop;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u32 n_addresses;
@@ -313,14 +341,14 @@ autoreply define dhcp6_pd_send_client_message
{
u32 client_index;
u32 context;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
u32 irt;
u32 mrt;
u32 mrc;
u32 mrd;
- u8 stop;
- u8 msg_type;
+ bool stop;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u32 n_prefixes;
@@ -361,7 +389,7 @@ autoreply define want_dhcp6_pd_reply_events
{
u32 client_index;
u32 context;
- u8 enable_disable;
+ bool enable_disable;
u32 pid;
};
@@ -384,9 +412,9 @@ define dhcp6_reply_event
{
u32 client_index;
u32 pid;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
- u8 msg_type;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u16 inner_status_code;
@@ -415,9 +443,9 @@ define dhcp6_pd_reply_event
{
u32 client_index;
u32 pid;
- u32 sw_if_index;
+ vl_api_interface_index_t sw_if_index;
u32 server_index;
- u8 msg_type;
+ vl_api_dhcpv6_msg_type_t msg_type;
u32 T1;
u32 T2;
u16 inner_status_code;
diff --git a/src/vnet/dhcp/dhcp6_ia_na_client_cp.c b/src/vnet/dhcp/dhcp6_ia_na_client_cp.c
index ad0ca8e3e93..e440805d707 100644
--- a/src/vnet/dhcp/dhcp6_ia_na_client_cp.c
+++ b/src/vnet/dhcp/dhcp6_ia_na_client_cp.c
@@ -214,7 +214,7 @@ dhcp6_reply_event_handler (vl_api_dhcp6_reply_event_t * mp)
inner_status_code = ntohs (mp->inner_status_code);
status_code = ntohs (mp->status_code);
- if (mp->msg_type == DHCPV6_MSG_ADVERTISE
+ if (mp->msg_type == DHCPV6_MSG_API_ADVERTISE
&& client_state->server_index == ~0)
{
address_info_t *address_list = 0, *address_info;
@@ -246,7 +246,7 @@ dhcp6_reply_event_handler (vl_api_dhcp6_reply_event_t * mp)
vec_free (address_list);
}
- if (mp->msg_type != DHCPV6_MSG_REPLY)
+ if (mp->msg_type != DHCPV6_MSG_API_REPLY)
return 0;
if (!client_state->rebinding && client_state->server_index != server_index)
diff --git a/src/vnet/dhcp/dhcp6_ia_na_client_dp.c b/src/vnet/dhcp/dhcp6_ia_na_client_dp.c
index 5f940c33687..f49017b0236 100644
--- a/src/vnet/dhcp/dhcp6_ia_na_client_dp.c
+++ b/src/vnet/dhcp/dhcp6_ia_na_client_dp.c
@@ -25,6 +25,7 @@
#include <vlibmemory/api.h>
#include <vnet/dhcp/dhcp6_ia_na_client_dp.h>
#include <vnet/dhcp/dhcp6_client_common_dp.h>
+#include <vnet/ip/ip_types_api.h>
#include <vnet/vnet_msg_enum.h>
@@ -454,7 +455,7 @@ void
params.mrt = ntohl (mp->mrt);
params.mrc = ntohl (mp->mrc);
params.mrd = ntohl (mp->mrd);
- params.msg_type = mp->msg_type;
+ params.msg_type = ntohl (mp->msg_type);
params.T1 = ntohl (mp->T1);
params.T2 = ntohl (mp->T2);
n_addresses = ntohl (mp->n_addresses);
@@ -467,7 +468,7 @@ void
dhcp6_send_client_message_params_address_t *addr = &params.addresses[i];
addr->preferred_lt = ntohl (ai->preferred_time);
addr->valid_lt = ntohl (ai->valid_time);
- memcpy (addr->address.as_u8, ai->address, 16);
+ ip6_address_decode (ai->address, &addr->address);
}
dhcp6_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop, &params);
@@ -535,7 +536,7 @@ dhcp6_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
for (j = 0; j < vec_len (events[i].addresses); j++)
{
dhcp6_address_info_t *info = &events[i].addresses[j];
- memcpy (address->address, &info->address, 16);
+ ip6_address_encode (&info->address, address->address);
address->valid_time = htonl (info->valid_time);
address->preferred_time = htonl (info->preferred_time);
address++;
diff --git a/src/vnet/dhcp/dhcp6_pd_client_cp.c b/src/vnet/dhcp/dhcp6_pd_client_cp.c
index a157b16d491..804f62a79e7 100644
--- a/src/vnet/dhcp/dhcp6_pd_client_cp.c
+++ b/src/vnet/dhcp/dhcp6_pd_client_cp.c
@@ -323,7 +323,7 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
inner_status_code = ntohs (mp->inner_status_code);
status_code = ntohs (mp->status_code);
- if (mp->msg_type == DHCPV6_MSG_ADVERTISE
+ if (mp->msg_type == DHCPV6_MSG_API_ADVERTISE
&& client_state->server_index == ~0)
{
prefix_info_t *prefix_list = 0, *prefix_info;
@@ -341,8 +341,8 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
for (i = 0; i < n_prefixes; i++)
{
api_prefix = &mp->prefixes[i];
- prefix = (ip6_address_t *) api_prefix->prefix;
- prefix_length = api_prefix->prefix_length;
+ prefix = (ip6_address_t *) api_prefix->prefix.address;
+ prefix_length = api_prefix->prefix.len;
prefix_info = &prefix_list[i];
prefix_info->prefix = *prefix;
@@ -358,7 +358,7 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
vec_free (prefix_list);
}
- if (mp->msg_type != DHCPV6_MSG_REPLY)
+ if (mp->msg_type != DHCPV6_MSG_API_REPLY)
return 0;
if (!client_state->rebinding && client_state->server_index != server_index)
@@ -398,15 +398,15 @@ dhcp6_pd_reply_event_handler (vl_api_dhcp6_pd_reply_event_t * mp)
api_prefix = &mp->prefixes[i];
- prefix = (ip6_address_t *) api_prefix->prefix;
- prefix_length = api_prefix->prefix_length;
+ prefix = (ip6_address_t *) api_prefix->prefix.address;
+ prefix_length = api_prefix->prefix.len;
if (ip6_address_is_link_local_unicast (prefix))
continue;
valid_time = ntohl (api_prefix->valid_time);
preferred_time = ntohl (api_prefix->preferred_time);
- prefix_length = api_prefix->prefix_length;
+ prefix_length = api_prefix->prefix.len;
if (preferred_time > valid_time)
continue;
diff --git a/src/vnet/dhcp/dhcp6_pd_client_dp.c b/src/vnet/dhcp/dhcp6_pd_client_dp.c
index c1bf5f8844f..c665b17281a 100644
--- a/src/vnet/dhcp/dhcp6_pd_client_dp.c
+++ b/src/vnet/dhcp/dhcp6_pd_client_dp.c
@@ -25,6 +25,7 @@
#include <vlibmemory/api.h>
#include <vnet/dhcp/dhcp6_pd_client_dp.h>
#include <vnet/dhcp/dhcp6_client_common_dp.h>
+#include <vnet/ip/ip_types_api.h>
#include <vnet/vnet_msg_enum.h>
@@ -457,7 +458,7 @@ void
params.mrt = ntohl (mp->mrt);
params.mrc = ntohl (mp->mrc);
params.mrd = ntohl (mp->mrd);
- params.msg_type = mp->msg_type;
+ params.msg_type = ntohl (mp->msg_type);
params.T1 = ntohl (mp->T1);
params.T2 = ntohl (mp->T2);
n_prefixes = ntohl (mp->n_prefixes);
@@ -471,8 +472,8 @@ void
&params.prefixes[i];
pref->preferred_lt = ntohl (pi->preferred_time);
pref->valid_lt = ntohl (pi->valid_time);
- memcpy (pref->prefix.as_u8, pi->prefix, 16);
- pref->prefix_length = pi->prefix_length;
+ ip6_address_decode (pi->prefix.address, &pref->prefix);
+ pref->prefix_length = pi->prefix.len;
}
dhcp6_pd_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop,
@@ -542,8 +543,8 @@ dhcp6_pd_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
for (j = 0; j < vec_len (events[i].prefixes); j++)
{
dhcp6_prefix_info_t *info = &events[i].prefixes[j];
- memcpy (prefix->prefix, &info->prefix, 16);
- prefix->prefix_length = info->prefix_length;
+ ip6_address_encode (&info->prefix, prefix->prefix.address);
+ prefix->prefix.len = info->prefix_length;
prefix->valid_time = htonl (info->valid_time);
prefix->preferred_time = htonl (info->preferred_time);
prefix++;
diff --git a/src/vnet/dhcp/dhcp_api.c b/src/vnet/dhcp/dhcp_api.c
index 7935ad8ba01..252f2df7d6b 100644
--- a/src/vnet/dhcp/dhcp_api.c
+++ b/src/vnet/dhcp/dhcp_api.c
@@ -73,8 +73,8 @@ vl_api_dhcp_proxy_set_vss_t_handler (vl_api_dhcp_proxy_set_vss_t * mp)
vpn_ascii_id = format (0, "%s", mp->vpn_ascii_id);
rv =
dhcp_proxy_set_vss ((mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4),
- ntohl (mp->tbl_id), mp->vss_type, vpn_ascii_id,
- ntohl (mp->oui), ntohl (mp->vpn_index),
+ ntohl (mp->tbl_id), ntohl (mp->vss_type),
+ vpn_ascii_id, ntohl (mp->oui), ntohl (mp->vpn_index),
mp->is_add == 0);
REPLY_MACRO (VL_API_DHCP_PROXY_SET_VSS_REPLY);
@@ -88,12 +88,18 @@ static void vl_api_dhcp_proxy_config_t_handler
ip46_address_t src, server;
int rv = -1;
- if (mp->is_ipv6)
+ if (mp->dhcp_src_address.af != mp->dhcp_server.af)
{
- clib_memcpy (&src.ip6, mp->dhcp_src_address, sizeof (src.ip6));
- clib_memcpy (&server.ip6, mp->dhcp_server, sizeof (server.ip6));
+ rv = VNET_API_ERROR_INVALID_ARGUMENT;
+ goto reply;
+ }
- rv = dhcp6_proxy_set_server (&server,
+ ip_address_decode (&mp->dhcp_src_address, &src);
+ ip_address_decode (&mp->dhcp_server, &server);
+
+ if (mp->dhcp_src_address.af == ADDRESS_IP4)
+ {
+ rv = dhcp4_proxy_set_server (&server,
&src,
(u32) ntohl (mp->rx_vrf_id),
(u32) ntohl (mp->server_vrf_id),
@@ -101,20 +107,14 @@ static void vl_api_dhcp_proxy_config_t_handler
}
else
{
- ip46_address_reset (&src);
- ip46_address_reset (&server);
-
- clib_memcpy (&src.ip4, mp->dhcp_src_address, sizeof (src.ip4));
- clib_memcpy (&server.ip4, mp->dhcp_server, sizeof (server.ip4));
-
- rv = dhcp4_proxy_set_server (&server,
+ rv = dhcp6_proxy_set_server (&server,
&src,
(u32) ntohl (mp->rx_vrf_id),
(u32) ntohl (mp->server_vrf_id),
(int) (mp->is_add == 0));
}
-
+reply:
REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
}
@@ -162,7 +162,7 @@ dhcp_send_details (fib_protocol_t proto,
if (vss)
{
- mp->vss_type = vss->vss_type;
+ mp->vss_type = ntohl (vss->vss_type);
if (vss->vss_type == VSS_TYPE_ASCII)
{
u32 id_len = vec_len (vss->vpn_ascii_id);
@@ -193,23 +193,23 @@ dhcp_send_details (fib_protocol_t proto,
if (mp->is_ipv6)
{
- memcpy (v_server->dhcp_server, &server->dhcp_server.ip6, 16);
+ memcpy (&v_server->dhcp_server.un, &server->dhcp_server.ip6, 16);
}
else
{
/* put the address in the first bytes */
- memcpy (v_server->dhcp_server, &server->dhcp_server.ip4, 4);
+ memcpy (&v_server->dhcp_server.un, &server->dhcp_server.ip4, 4);
}
}
if (mp->is_ipv6)
{
- memcpy (mp->dhcp_src_address, &proxy->dhcp_src_address.ip6, 16);
+ memcpy (&mp->dhcp_src_address.un, &proxy->dhcp_src_address.ip6, 16);
}
else
{
/* put the address in the first bytes */
- memcpy (mp->dhcp_src_address, &proxy->dhcp_src_address.ip4, 4);
+ memcpy (&mp->dhcp_src_address.un, &proxy->dhcp_src_address.ip4, 4);
}
vl_api_send_msg (reg, (u8 *) mp);
}
@@ -223,15 +223,15 @@ dhcp_client_lease_encode (vl_api_dhcp_lease_t * lease,
lease->is_ipv6 = 0; // only support IPv6 clients
lease->sw_if_index = ntohl (client->sw_if_index);
- lease->state = client->state;
+ lease->state = ntohl (client->state);
len = clib_min (sizeof (lease->hostname) - 1, vec_len (client->hostname));
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,
+ clib_memcpy (&lease->host_address.un, (u8 *) & client->leased_address,
sizeof (ip4_address_t));
- clib_memcpy (&lease->router_address[0], (u8 *) & client->router_address,
+ clib_memcpy (&lease->router_address.un, (u8 *) & client->router_address,
sizeof (ip4_address_t));
lease->count = vec_len (client->domain_server_address);