summaryrefslogtreecommitdiffstats
path: root/src/vnet
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-02-14 07:28:41 -0800
committerDamjan Marion <dmarion.lists@gmail.com>2017-02-21 22:25:48 +0000
commit20a175a18414c67e38b5ce0709b33fb1df8069c9 (patch)
tree3c06d6c83f62ca84e78d28cefbd8e18c3e37005e /src/vnet
parent2e3677bb2085d4992f74156bdff8fe050ac9de24 (diff)
dhcp: multiple additions
DHCP additions: 1) DHCPv4 will only relay a message back to the client, if the Option82 information is present. So make this the default. 2) It is no longer possible to select via the API to "insert circuit ID" - since this is now default 3) Remove the version 2 API since it's now the same as version 1. 4) Adding the VSS option is now conditional only on the presence of VSS config (not the 'insert' option in the set API) 5) DHCP proxy dump via API Change-Id: Ia7271ba8c1d4dbf34a02c401d268ccfbb1b74f17 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r--src/vnet/dhcp/client.c1
-rw-r--r--src/vnet/dhcp/client.h3
-rw-r--r--src/vnet/dhcp/dhcp.api67
-rw-r--r--src/vnet/dhcp/dhcp_api.c112
-rw-r--r--src/vnet/dhcp/proxy.h33
-rw-r--r--src/vnet/dhcp/proxy_error.def3
-rw-r--r--src/vnet/dhcp/proxy_node.c676
-rw-r--r--src/vnet/dhcpv6/proxy.h19
-rw-r--r--src/vnet/dhcpv6/proxy_node.c513
-rw-r--r--src/vnet/dpo/receive_dpo.c5
10 files changed, 787 insertions, 645 deletions
diff --git a/src/vnet/dhcp/client.c b/src/vnet/dhcp/client.c
index c352e3109ee..8a1a43b3fd4 100644
--- a/src/vnet/dhcp/client.c
+++ b/src/vnet/dhcp/client.c
@@ -13,6 +13,7 @@
* limitations under the License.
*/
#include <vlib/vlib.h>
+#include <vnet/dhcp/client.h>
#include <vnet/dhcp/proxy.h>
#include <vnet/fib/fib_table.h>
diff --git a/src/vnet/dhcp/client.h b/src/vnet/dhcp/client.h
index d15e686b636..a74368cbe07 100644
--- a/src/vnet/dhcp/client.h
+++ b/src/vnet/dhcp/client.h
@@ -19,6 +19,9 @@
#ifndef included_dhcp_client_h
#define included_dhcp_client_h
+#include <vnet/ip/ip.h>
+#include <vnet/dhcp/packet.h>
+
#define foreach_dhcp_client_state \
_(DHCP_DISCOVER) \
_(DHCP_REQUEST) \
diff --git a/src/vnet/dhcp/dhcp.api b/src/vnet/dhcp/dhcp.api
index c228cd04716..8daadd8c77a 100644
--- a/src/vnet/dhcp/dhcp.api
+++ b/src/vnet/dhcp/dhcp.api
@@ -16,7 +16,8 @@
/** \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 vrf_id - vrf id
+ @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
@@ -27,10 +28,10 @@ define dhcp_proxy_config
{
u32 client_index;
u32 context;
- u32 vrf_id;
+ u32 rx_vrf_id;
+ u32 server_vrf_id;
u8 is_ipv6;
u8 is_add;
- u8 insert_circuit_id;
u8 dhcp_server[16];
u8 dhcp_src_address[16];
};
@@ -45,40 +46,6 @@ define dhcp_proxy_config_reply
i32 retval;
};
-/** \brief DHCP Proxy config 2 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 - receive 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
- @param dhcp_src_address[] - <fix this, need details>
-*/
-define dhcp_proxy_config_2
-{
- u32 client_index;
- u32 context;
- u32 rx_vrf_id;
- u32 server_vrf_id;
- u8 is_ipv6;
- u8 is_add;
- u8 insert_circuit_id;
- u8 dhcp_server[16];
- u8 dhcp_src_address[16];
-};
-
-/** \brief DHCP Proxy config 2 add / del response
- @param context - sender context, to match reply w/ request
- @param retval - return code for request
-*/
-define dhcp_proxy_config_2_reply
-{
- u32 context;
- i32 retval;
-};
-
/** \brief DHCP Proxy set / unset vss request
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@@ -159,6 +126,32 @@ define dhcp_compl_event
u8 host_mac[6];
};
+/** \brief Dump DHCP proxy table
+ @param client_index - opaque cookie to identify the sender
+ @param True for IPv6 proxy table
+*/
+define dhcp_proxy_dump
+{
+ u32 client_index;
+ u32 context;
+ u8 is_ip6;
+};
+
+/** \brief Tell client about a DHCP completion event
+ @param client_index - opaque cookie to identify the sender
+*/
+define dhcp_proxy_details
+{
+ u32 context;
+ u32 rx_vrf_id;
+ u32 server_vrf_id;
+ u32 vss_oui;
+ u32 vss_fib_id;
+ u8 is_ipv6;
+ u8 dhcp_server[16];
+ u8 dhcp_src_address[16];
+};
+
/*
* Local Variables:
* eval: (c-set-style "gnu")
diff --git a/src/vnet/dhcp/dhcp_api.c b/src/vnet/dhcp/dhcp_api.c
index 88b32b240f7..ce9039b7557 100644
--- a/src/vnet/dhcp/dhcp_api.c
+++ b/src/vnet/dhcp/dhcp_api.c
@@ -46,7 +46,8 @@
#define foreach_vpe_api_msg \
_(DHCP_PROXY_CONFIG,dhcp_proxy_config) \
-_(DHCP_PROXY_CONFIG_2,dhcp_proxy_config_2) \
+_(DHCP_PROXY_DUMP,dhcp_proxy_dump) \
+_(DHCP_PROXY_DETAILS,dhcp_proxy_details) \
_(DHCP_PROXY_SET_VSS,dhcp_proxy_set_vss) \
_(DHCP_CLIENT_CONFIG, dhcp_client_config)
@@ -58,8 +59,8 @@ dhcpv4_proxy_config (vl_api_dhcp_proxy_config_t * mp)
rv = dhcp_proxy_set_server ((ip4_address_t *) (&mp->dhcp_server),
(ip4_address_t *) (&mp->dhcp_src_address),
- (u32) ntohl (mp->vrf_id),
- (int) mp->insert_circuit_id,
+ (u32) ntohl (mp->rx_vrf_id),
+ (u32) ntohl (mp->server_vrf_id),
(int) (mp->is_add == 0));
REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
@@ -74,44 +75,11 @@ dhcpv6_proxy_config (vl_api_dhcp_proxy_config_t * mp)
rv = dhcpv6_proxy_set_server ((ip6_address_t *) (&mp->dhcp_server),
(ip6_address_t *) (&mp->dhcp_src_address),
- (u32) ntohl (mp->vrf_id),
- (int) mp->insert_circuit_id,
- (int) (mp->is_add == 0));
-
- REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
-}
-
-static void
-dhcpv4_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
-{
- vl_api_dhcp_proxy_config_reply_t *rmp;
- int rv;
-
- rv = dhcp_proxy_set_server_2 ((ip4_address_t *) (&mp->dhcp_server),
- (ip4_address_t *) (&mp->dhcp_src_address),
(u32) ntohl (mp->rx_vrf_id),
(u32) ntohl (mp->server_vrf_id),
- (int) mp->insert_circuit_id,
(int) (mp->is_add == 0));
- REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
-}
-
-
-static void
-dhcpv6_proxy_config_2 (vl_api_dhcp_proxy_config_2_t * mp)
-{
- vl_api_dhcp_proxy_config_reply_t *rmp;
- int rv = -1;
-
- rv = dhcpv6_proxy_set_server_2 ((ip6_address_t *) (&mp->dhcp_server),
- (ip6_address_t *) (&mp->dhcp_src_address),
- (u32) ntohl (mp->rx_vrf_id),
- (u32) ntohl (mp->server_vrf_id),
- (int) mp->insert_circuit_id,
- (int) (mp->is_add == 0));
-
- REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_2_REPLY);
+ REPLY_MACRO (VL_API_DHCP_PROXY_CONFIG_REPLY);
}
@@ -143,6 +111,67 @@ static void vl_api_dhcp_proxy_config_t_handler
dhcpv6_proxy_config (mp);
}
+static void
+vl_api_dhcp_proxy_dump_t_handler (vl_api_dhcp_proxy_dump_t * mp)
+{
+ unix_shared_memory_queue_t *q;
+
+ q = vl_api_client_index_to_input_queue (mp->client_index);
+ if (q == 0)
+ return;
+
+ if (mp->is_ip6 == 0)
+ dhcp_proxy_dump (q, mp->context);
+ else
+ dhcpv6_proxy_dump (q, mp->context);
+}
+
+void
+dhcp_send_details (void *opaque,
+ u32 context,
+ const ip46_address_t * server,
+ const ip46_address_t * src,
+ u32 server_fib_id,
+ u32 rx_fib_id, u32 vss_fib_id, u32 vss_oui)
+{
+ vl_api_dhcp_proxy_details_t *mp;
+ unix_shared_memory_queue_t *q = opaque;
+
+ mp = vl_msg_api_alloc (sizeof (*mp));
+ if (!mp)
+ return;
+ memset (mp, 0, sizeof (*mp));
+ mp->_vl_msg_id = ntohs (VL_API_DHCP_PROXY_DETAILS);
+ mp->context = context;
+
+ mp->rx_vrf_id = htonl (rx_fib_id);
+ mp->server_vrf_id = htonl (server_fib_id);
+ mp->vss_oui = htonl (vss_oui);
+ mp->vss_fib_id = htonl (vss_fib_id);
+
+ mp->is_ipv6 = !ip46_address_is_ip4 (server);
+
+ if (mp->is_ipv6)
+ {
+ memcpy (mp->dhcp_server, server, 16);
+ memcpy (mp->dhcp_src_address, src, 16);
+ }
+ else
+ {
+ /* put the address in the first bytes */
+ memcpy (mp->dhcp_server, &server->ip4, 4);
+ memcpy (mp->dhcp_src_address, &src->ip4, 4);
+ }
+ vl_msg_api_send_shmem (q, (u8 *) & mp);
+}
+
+
+static void
+vl_api_dhcp_proxy_details_t_handler (vl_api_dhcp_proxy_details_t * mp)
+{
+ clib_warning ("BUG");
+}
+
void
dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
u8 is_ipv6, u8 * host_address, u8 * router_address,
@@ -172,15 +201,6 @@ dhcp_compl_event_callback (u32 client_index, u32 pid, u8 * hostname,
vl_msg_api_send_shmem (q, (u8 *) & mp);
}
-static void vl_api_dhcp_proxy_config_2_t_handler
- (vl_api_dhcp_proxy_config_2_t * mp)
-{
- if (mp->is_ipv6 == 0)
- dhcpv4_proxy_config_2 (mp);
- else
- dhcpv6_proxy_config_2 (mp);
-}
-
static void vl_api_dhcp_client_config_t_handler
(vl_api_dhcp_client_config_t * mp)
{
diff --git a/src/vnet/dhcp/proxy.h b/src/vnet/dhcp/proxy.h
index e12c0d001b5..4b115c741ff 100644
--- a/src/vnet/dhcp/proxy.h
+++ b/src/vnet/dhcp/proxy.h
@@ -27,7 +27,6 @@
#include <vnet/pg/pg.h>
#include <vnet/ip/format.h>
#include <vnet/ip/udp.h>
-#include <vnet/dhcp/client.h>
typedef enum {
#define dhcp_proxy_error(n,s) DHCP_PROXY_ERROR_##n,
@@ -49,9 +48,7 @@ typedef union {
typedef struct {
ip4_address_t dhcp_server;
ip4_address_t dhcp_src_address;
- u32 insert_option_82;
u32 server_fib_index;
- u32 valid;
} dhcp_server_t;
typedef struct {
@@ -64,29 +61,39 @@ typedef struct {
/* to drop pkts in server-to-client direction */
u32 error_drop_node_index;
- vss_info *opt82vss;
+ vss_info *vss;
/* hash lookup specific vrf_id -> option 82 vss suboption */
- uword * opt82vss_index_by_vrf_id;
+ u32 *vss_index_by_rx_fib_index;
/* convenience */
- dhcp_client_main_t * dhcp_client_main;
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
} dhcp_proxy_main_t;
-dhcp_proxy_main_t dhcp_proxy_main;
+extern dhcp_proxy_main_t dhcp_proxy_main;
-int dhcp_proxy_set_server (ip4_address_t *addr, ip4_address_t *src_address,
- u32 fib_id, int insert_option_82, int is_del);
+void dhcp_send_details (void *opaque,
+ u32 context,
+ const ip46_address_t *server,
+ const ip46_address_t *src,
+ u32 server_fib_id,
+ u32 rx_fib_id,
+ u32 vss_fib_id,
+ u32 vss_oui);
-int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
- u32 rx_fib_id,
- u32 server_fib_id,
- int insert_option_82, int is_del);
+int dhcp_proxy_set_server (ip4_address_t *addr,
+ ip4_address_t *src_address,
+ u32 fib_id,
+ u32 server_fib_id,
+ int is_del);
int dhcp_proxy_set_option82_vss(u32 vrf_id,
u32 oui,
u32 fib_id,
int is_del);
+
+void dhcp_proxy_dump(void *opaque,
+ u32 context);
+
#endif /* included_dhcp_proxy_h */
diff --git a/src/vnet/dhcp/proxy_error.def b/src/vnet/dhcp/proxy_error.def
index 6aa06eb5120..6d790d732d6 100644
--- a/src/vnet/dhcp/proxy_error.def
+++ b/src/vnet/dhcp/proxy_error.def
@@ -21,7 +21,8 @@ dhcp_proxy_error (RELAY_TO_SERVER, "DHCP packets relayed to the server")
dhcp_proxy_error (RELAY_TO_CLIENT, "DHCP packets relayed to clients")
dhcp_proxy_error (OPTION_82_ERROR, "DHCP failed to insert option 82")
dhcp_proxy_error (NO_OPTION_82, "DHCP option 82 missing")
-dhcp_proxy_error (BAD_OPTION_82, "Bad DHCP option 82 value")
+dhcp_proxy_error (BAD_OPTION_82_ITF, "Bad DHCP option 82 interface value")
+dhcp_proxy_error (BAD_OPTION_82_ADDR, "Bad DHCP option 82 address value")
dhcp_proxy_error (BAD_FIB_ID, "DHCP option 82 fib-id to fib-index map failure")
dhcp_proxy_error (NO_INTERFACE_ADDRESS, "DHCP no interface address")
dhcp_proxy_error (OPTION_82_VSS_NOT_PROCESSED, "DHCP VSS not processed by DHCP server")
diff --git a/src/vnet/dhcp/proxy_node.c b/src/vnet/dhcp/proxy_node.c
index 6a58fcdb185..ab6819fed54 100644
--- a/src/vnet/dhcp/proxy_node.c
+++ b/src/vnet/dhcp/proxy_node.c
@@ -18,6 +18,7 @@
#include <vlib/vlib.h>
#include <vnet/pg/pg.h>
#include <vnet/dhcp/proxy.h>
+#include <vnet/dhcp/client.h>
#include <vnet/fib/ip4_fib.h>
static char * dhcp_proxy_error_strings[] = {
@@ -57,6 +58,8 @@ typedef struct {
vlib_node_registration_t dhcp_proxy_to_server_node;
vlib_node_registration_t dhcp_proxy_to_client_node;
+dhcp_proxy_main_t dhcp_proxy_main;
+
u8 * format_dhcp_proxy_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -94,6 +97,42 @@ u8 * format_dhcp_proxy_header_with_length (u8 * s, va_list * args)
return s;
}
+static inline vss_info *
+dhcp_get_vss_info (dhcp_proxy_main_t *dm,
+ u32 rx_fib_index)
+{
+ vss_info *v;
+
+ if (vec_len(dm->vss_index_by_rx_fib_index) <= rx_fib_index ||
+ dm->vss_index_by_rx_fib_index[rx_fib_index] == ~0)
+ {
+ v = NULL;
+ }
+ else
+ {
+ v = pool_elt_at_index (dm->vss,
+ dm->vss_index_by_rx_fib_index[rx_fib_index]);
+ }
+
+ return (v);
+}
+
+static inline dhcp_server_t *
+dhcp_get_server (dhcp_proxy_main_t *dm,
+ u32 rx_fib_index)
+{
+ dhcp_server_t *s = NULL;
+
+ if (vec_len(dm->dhcp_server_index_by_rx_fib_index) > rx_fib_index &&
+ dm->dhcp_server_index_by_rx_fib_index[rx_fib_index] != ~0)
+ {
+ s = pool_elt_at_index (dm->dhcp_servers,
+ dm->dhcp_server_index_by_rx_fib_index[rx_fib_index]);
+ }
+
+ return (s);
+}
+
static uword
dhcp_proxy_to_server_input (vlib_main_t * vm,
vlib_node_runtime_t * node,
@@ -131,9 +170,12 @@ dhcp_proxy_to_server_input (vlib_main_t * vm,
u32 sw_if_index = 0;
u32 original_sw_if_index = 0;
u8 *end = NULL;
- u32 fib_index, server_index;
+ u32 fib_index;
dhcp_server_t * server;
u32 rx_sw_if_index;
+ dhcp_option_t *o;
+ u32 len = 0;
+ vlib_buffer_free_list_t *fl;
bi0 = from[0];
to_next[0] = bi0;
@@ -166,26 +208,16 @@ dhcp_proxy_to_server_input (vlib_main_t * vm,
rx_sw_if_index = vnet_buffer(b0)->sw_if_index[VLIB_RX];
fib_index = im->fib_index_by_sw_if_index [rx_sw_if_index];
-
- if (fib_index < vec_len(dpm->dhcp_server_index_by_rx_fib_index))
- server_index = dpm->dhcp_server_index_by_rx_fib_index[fib_index];
- else
- server_index = 0;
+ server = dhcp_get_server(dpm, fib_index);
- if (PREDICT_FALSE (pool_is_free_index (dpm->dhcp_servers,
- server_index)))
+ if (PREDICT_FALSE (NULL == server))
{
- no_server:
error0 = DHCP_PROXY_ERROR_NO_SERVER;
next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
pkts_no_server++;
goto do_trace;
}
- server = pool_elt_at_index (dpm->dhcp_servers, server_index);
- if (server->valid == 0)
- goto no_server;
-
vlib_buffer_advance (b0, -(sizeof(*ip0)));
ip0 = vlib_buffer_get_current (b0);
@@ -216,142 +248,131 @@ dhcp_proxy_to_server_input (vlib_main_t * vm,
h0->gateway_ip_address.as_u32 = server->dhcp_src_address.as_u32;
pkts_to_server++;
- if (server->insert_option_82)
- {
- u32 fib_index, fib_id, opt82_fib_id=0, opt82_oui=0;
- ip4_fib_t * fib;
- dhcp_option_t *o = (dhcp_option_t *) h0->options;
- u32 len = 0;
- vlib_buffer_free_list_t *fl;
+ o = (dhcp_option_t *) h0->options;
- fib_index = im->fib_index_by_sw_if_index
- [vnet_buffer(b0)->sw_if_index[VLIB_RX]];
- fib = ip4_fib_get (fib_index);
- fib_id = fib->table_id;
-
- end = b0->data + b0->current_data + b0->current_length;
- /* TLVs are not performance-friendly... */
- while (o->option != 0xFF /* end of options */ && (u8 *)o < end)
- o = (dhcp_option_t *) (((uword) o) + (o->length + 2));
-
- fl = vlib_buffer_get_free_list (vm, b0->free_list_index);
- // start write at (option*)o, some packets have padding
- if (((u8 *)o - (u8 *)b0->data + VPP_DHCP_OPTION82_SIZE) > fl->n_data_bytes)
- {
- next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
- pkts_too_big++;
- goto do_trace;
- }
+ fib_index = im->fib_index_by_sw_if_index
+ [vnet_buffer(b0)->sw_if_index[VLIB_RX]];
+
+ end = b0->data + b0->current_data + b0->current_length;
+ /* TLVs are not performance-friendly... */
+ while (o->option != 0xFF /* end of options */ && (u8 *)o < end)
+ o = (dhcp_option_t *) (((uword) o) + (o->length + 2));
- if ((o->option == 0xFF) && ((u8 *)o <= end))
- {
- vnet_main_t *vnm = vnet_get_main();
- u16 old_l0, new_l0;
- ip4_address_t _ia0, * ia0 = &_ia0;
- uword *p_vss;
- vss_info *vss;
- vnet_sw_interface_t *swif;
- sw_if_index = 0;
- original_sw_if_index = 0;
+ fl = vlib_buffer_get_free_list (vm, b0->free_list_index);
+ // start write at (option*)o, some packets have padding
+ if (((u8 *)o - (u8 *)b0->data + VPP_DHCP_OPTION82_SIZE) > fl->n_data_bytes)
+ {
+ next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
+ pkts_too_big++;
+ goto do_trace;
+ }
+
+ if ((o->option == 0xFF) && ((u8 *)o <= end))
+ {
+ vnet_main_t *vnm = vnet_get_main();
+ u16 old_l0, new_l0;
+ ip4_address_t _ia0, * ia0 = &_ia0;
+ vss_info *vss;
+ vnet_sw_interface_t *swif;
+ sw_if_index = 0;
+ original_sw_if_index = 0;
- original_sw_if_index = sw_if_index =
- vnet_buffer(b0)->sw_if_index[VLIB_RX];
- swif = vnet_get_sw_interface (vnm, sw_if_index);
- if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
- sw_if_index = swif->unnumbered_sw_if_index;
+ original_sw_if_index = sw_if_index =
+ vnet_buffer(b0)->sw_if_index[VLIB_RX];
+ swif = vnet_get_sw_interface (vnm, sw_if_index);
+ if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
+ sw_if_index = swif->unnumbered_sw_if_index;
- p_vss = hash_get (dpm->opt82vss_index_by_vrf_id,
- fib_id);
- if (p_vss)
- {
- vss = pool_elt_at_index (dpm->opt82vss, p_vss[0]);
- opt82_oui = vss->vpn_id.oui;
- opt82_fib_id = vss->vpn_id.fib_id;
- }
- /*
- * Get the first ip4 address on the [client-side]
- * RX interface, if not unnumbered. otherwise use
- * the loopback interface's ip address.
- */
- ia0 = ip4_interface_first_address(&ip4_main, sw_if_index, 0);
+ /*
+ * Get the first ip4 address on the [client-side]
+ * RX interface, if not unnumbered. otherwise use
+ * the loopback interface's ip address.
+ */
+ ia0 = ip4_interface_first_address(&ip4_main, sw_if_index, 0);
- if (ia0 == 0)
- {
- error0 = DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS;
- next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
- pkts_no_interface_address++;
- goto do_trace;
- }
-
- /* Add option 82 */
- o->option = 82; /* option 82 */
- o->length = 12; /* 12 octets to follow */
- o->data[0] = 1; /* suboption 1, circuit ID (=FIB id) */
- o->data[1] = 4; /* length of suboption */
- o->data[2] = (original_sw_if_index >> 24) & 0xFF;
- o->data[3] = (original_sw_if_index >> 16) & 0xFF;
- o->data[4] = (original_sw_if_index >> 8) & 0xFF;
- o->data[5] = (original_sw_if_index >> 0) & 0xFF;
- o->data[6] = 5; /* suboption 5 (client RX intfc address) */
- o->data[7] = 4; /* length 4 */
- o->data[8] = ia0->as_u8[0];
- o->data[9] = ia0->as_u8[1];
- o->data[10] = ia0->as_u8[2];
- o->data[11] = ia0->as_u8[3];
- o->data[12] = 0xFF;
- if (opt82_oui !=0 || opt82_fib_id != 0)
- {
- o->data[12] = 151; /* vss suboption */
- if (255 == opt82_fib_id) {
- o->data[13] = 1; /* length */
- o->data[14] = 255; /* vss option type */
- o->data[15] = 152; /* vss control suboption */
- o->data[16] = 0; /* length */
- /* and a new "end-of-options" option (0xff) */
- o->data[17] = 0xFF;
- o->length += 5;
- } else {
- o->data[13] = 8; /* length */
- o->data[14] = 1; /* vss option type */
- o->data[15] = (opt82_oui >> 16) & 0xff;
- o->data[16] = (opt82_oui >> 8) & 0xff;
- o->data[17] = (opt82_oui ) & 0xff;
- o->data[18] = (opt82_fib_id >> 24) & 0xff;
- o->data[19] = (opt82_fib_id >> 16) & 0xff;
- o->data[20] = (opt82_fib_id >> 8) & 0xff;
- o->data[21] = (opt82_fib_id) & 0xff;
- o->data[22] = 152; /* vss control suboption */
- o->data[23] = 0; /* length */
+ if (ia0 == 0)
+ {
+ error0 = DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS;
+ next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
+ pkts_no_interface_address++;
+ goto do_trace;
+ }
+
+ /* Add option 82 */
+ o->option = 82; /* option 82 */
+ o->length = 12; /* 12 octets to follow */
+ o->data[0] = 1; /* suboption 1, circuit ID (=FIB id) */
+ o->data[1] = 4; /* length of suboption */
+ o->data[2] = (original_sw_if_index >> 24) & 0xFF;
+ o->data[3] = (original_sw_if_index >> 16) & 0xFF;
+ o->data[4] = (original_sw_if_index >> 8) & 0xFF;
+ o->data[5] = (original_sw_if_index >> 0) & 0xFF;
+ o->data[6] = 5; /* suboption 5 (client RX intfc address) */
+ o->data[7] = 4; /* length 4 */
+ o->data[8] = ia0->as_u8[0];
+ o->data[9] = ia0->as_u8[1];
+ o->data[10] = ia0->as_u8[2];
+ o->data[11] = ia0->as_u8[3];
+ o->data[12] = 0xFF;
+
+ vss = dhcp_get_vss_info (dpm, fib_index);
+ if (NULL != vss)
+ {
+ u32 opt82_fib_id=0, opt82_oui=0;
+
+ opt82_oui = vss->vpn_id.oui;
+ opt82_fib_id = vss->vpn_id.fib_id;
+
+ o->data[12] = 151; /* vss suboption */
+ if (255 == opt82_fib_id) {
+ o->data[13] = 1; /* length */
+ o->data[14] = 255; /* vss option type */
+ o->data[15] = 152; /* vss control suboption */
+ o->data[16] = 0; /* length */
+ /* and a new "end-of-options" option (0xff) */
+ o->data[17] = 0xFF;
+ o->length += 5;
+ } else {
+ o->data[13] = 8; /* length */
+ o->data[14] = 1; /* vss option type */
+ o->data[15] = (opt82_oui >> 16) & 0xff;
+ o->data[16] = (opt82_oui >> 8) & 0xff;
+ o->data[17] = (opt82_oui ) & 0xff;
+ o->data[18] = (opt82_fib_id >> 24) & 0xff;
+ o->data[19] = (opt82_fib_id >> 16) & 0xff;
+ o->data[20] = (opt82_fib_id >> 8) & 0xff;
+ o->data[21] = (opt82_fib_id) & 0xff;
+ o->data[22] = 152; /* vss control suboption */
+ o->data[23] = 0; /* length */
- /* and a new "end-of-options" option (0xff) */
- o->data[24] = 0xFF;
- o->length += 12;
- }
+ /* and a new "end-of-options" option (0xff) */
+ o->data[24] = 0xFF;
+ o->length += 12;
}
-
- len = o->length + 3;
- b0->current_length += len;
- /* Fix IP header length and checksum */
- old_l0 = ip0->length;
- new_l0 = clib_net_to_host_u16 (old_l0);
- new_l0 += len;
- new_l0 = clib_host_to_net_u16 (new_l0);
- ip0->length = new_l0;
- sum0 = ip0->checksum;
- sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
- length /* changed member */);
- ip0->checksum = ip_csum_fold (sum0);
-
- /* Fix UDP length */
- new_l0 = clib_net_to_host_u16 (u0->length);
- new_l0 += len;
- u0->length = clib_host_to_net_u16 (new_l0);
- } else {
- vlib_node_increment_counter
- (vm, dhcp_proxy_to_server_node.index,
- DHCP_PROXY_ERROR_OPTION_82_ERROR, 1);
- }
- }
+ }
+
+ len = o->length + 3;
+ b0->current_length += len;
+ /* Fix IP header length and checksum */
+ old_l0 = ip0->length;
+ new_l0 = clib_net_to_host_u16 (old_l0);
+ new_l0 += len;
+ new_l0 = clib_host_to_net_u16 (new_l0);
+ ip0->length = new_l0;
+ sum0 = ip0->checksum;
+ sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
+ length /* changed member */);
+ ip0->checksum = ip_csum_fold (sum0);
+
+ /* Fix UDP length */
+ new_l0 = clib_net_to_host_u16 (u0->length);
+ new_l0 += len;
+ u0->length = clib_host_to_net_u16 (new_l0);
+ } else {
+ vlib_node_increment_counter
+ (vm, dhcp_proxy_to_server_node.index,
+ DHCP_PROXY_ERROR_OPTION_82_ERROR, 1);
+ }
next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
@@ -451,11 +472,13 @@ dhcp_proxy_to_client_input (vlib_main_t * vm,
vnet_sw_interface_t *si0;
u32 error0 = (u32)~0;
vnet_sw_interface_t *swif;
- u32 server_index;
u32 fib_index;
dhcp_server_t * server;
u32 original_sw_if_index = (u32) ~0;
-
+ ip4_address_t relay_addr = {
+ .as_u32 = 0,
+ };
+
bi0 = from[0];
from += 1;
n_left_from -= 1;
@@ -501,13 +524,21 @@ dhcp_proxy_to_client_input (vlib_main_t * vm,
and the sw_if_index */
if (sub->option == 1 && sub->length == 4)
{
- sw_if_index = (o->data[2] << 24)
- | (o->data[3] << 16)
- | (o->data[4] << 8)
- | (o->data[5]);
- } else if (sub->option == 151 &&
- sub->length == 7 &&
- sub->data[0] == 1)
+ sw_if_index = ((sub->data[0] << 24) |
+ (sub->data[1] << 16) |
+ (sub->data[2] << 8) |
+ (sub->data[3]));
+ }
+ else if (sub->option == 5 && sub->length == 4)
+ {
+ relay_addr.as_u8[0] = sub->data[0];
+ relay_addr.as_u8[1] = sub->data[1];
+ relay_addr.as_u8[2] = sub->data[2];
+ relay_addr.as_u8[3] = sub->data[3];
+ }
+ else if (sub->option == 151 &&
+ sub->length == 7 &&
+ sub->data[0] == 1)
vss_exist = 1;
else if (sub->option == 152 && sub->length == 0)
vss_ctrl = 1;
@@ -539,34 +570,27 @@ dhcp_proxy_to_client_input (vlib_main_t * vm,
goto do_trace;
}
+ if (relay_addr.as_u32 == 0)
+ {
+ error0 = DHCP_PROXY_ERROR_BAD_OPTION_82_ADDR;
+ goto drop_packet;
+ }
if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
{
- error0 = DHCP_PROXY_ERROR_BAD_OPTION_82;
+ error0 = DHCP_PROXY_ERROR_BAD_OPTION_82_ITF;
goto drop_packet;
}
fib_index = im->fib_index_by_sw_if_index [sw_if_index];
+ server = dhcp_get_server(dpm, fib_index);
- if (fib_index < vec_len(dpm->dhcp_server_index_by_rx_fib_index))
- server_index = dpm->dhcp_server_index_by_rx_fib_index[fib_index];
- else
- server_index = 0;
-
- if (PREDICT_FALSE (pool_is_free_index (dpm->dhcp_servers,
- server_index)))
- {
- error0 = DHCP_PROXY_ERROR_BAD_OPTION_82;
- goto drop_packet;
- }
-
- server = pool_elt_at_index (dpm->dhcp_servers, server_index);
- if (server->valid == 0)
+ if (PREDICT_FALSE (NULL == server))
{
error0 = DHCP_PROXY_ERROR_NO_SERVER;
goto drop_packet;
}
-
+
if (ip0->src_address.as_u32 != server->dhcp_server.as_u32)
{
error0 = DHCP_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
@@ -587,6 +611,12 @@ dhcp_proxy_to_client_input (vlib_main_t * vm,
goto drop_packet;
}
+ if (relay_addr.as_u32 != ia0->as_u32)
+ {
+ error0 = DHCP_PROXY_ERROR_BAD_YIADDR;
+ goto drop_packet;
+ }
+
u0->checksum = 0;
u0->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcp_to_client);
sum0 = ip0->checksum;
@@ -677,7 +707,7 @@ clib_error_t * dhcp_proxy_init (vlib_main_t * vm)
error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
dm->error_drop_node_index = error_drop_node->index;
- dm->opt82vss_index_by_vrf_id = hash_create (0, sizeof (uword));
+ dm->vss_index_by_rx_fib_index = NULL;
udp_register_dst_port (vm, UDP_DST_PORT_dhcp_to_client,
dhcp_proxy_to_client_node.index, 1 /* is_ip4 */);
@@ -694,15 +724,17 @@ clib_error_t * dhcp_proxy_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (dhcp_proxy_init);
-int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
- u32 rx_fib_id,
- u32 server_fib_id,
- int insert_option_82, int is_del)
+int dhcp_proxy_set_server (ip4_address_t *addr,
+ ip4_address_t *src_address,
+ u32 rx_fib_id,
+ u32 server_fib_id,
+ int is_del)
{
dhcp_proxy_main_t * dpm = &dhcp_proxy_main;
dhcp_server_t * server = 0;
u32 server_index = 0;
u32 rx_fib_index = 0;
+
const fib_prefix_t all_1s =
{
.fp_len = 32,
@@ -719,97 +751,68 @@ int dhcp_proxy_set_server_2 (ip4_address_t *addr, ip4_address_t *src_address,
rx_fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4,
rx_fib_id);
- if (rx_fib_id == 0)
- {
- server = pool_elt_at_index (dpm->dhcp_servers, 0);
-
- if (is_del)
- {
- memset (server, 0, sizeof (*server));
- fib_table_entry_special_remove(rx_fib_index,
- &all_1s,
- FIB_SOURCE_DHCP);
- return 0;
- }
- if (!server->valid)
- fib_table_entry_special_add(rx_fib_index,
- &all_1s,
- FIB_SOURCE_DHCP,
- FIB_ENTRY_FLAG_LOCAL,
- ADJ_INDEX_INVALID);
-
- goto initialize_it;
- }
-
if (is_del)
{
if (rx_fib_index >= vec_len(dpm->dhcp_server_index_by_rx_fib_index))
return VNET_API_ERROR_NO_SUCH_ENTRY;
server_index = dpm->dhcp_server_index_by_rx_fib_index[rx_fib_index];
- ASSERT(server_index > 0);
+
+ if (server_index == ~0)
+ return VNET_API_ERROR_NO_SUCH_ENTRY;
/* Use the default server again. */
- dpm->dhcp_server_index_by_rx_fib_index[rx_fib_index] = 0;
+ dpm->dhcp_server_index_by_rx_fib_index[rx_fib_index] = ~0;
server = pool_elt_at_index (dpm->dhcp_servers, server_index);
- memset (server, 0, sizeof (*server));
- pool_put (dpm->dhcp_servers, server);
fib_table_entry_special_remove(rx_fib_index,
&all_1s,
FIB_SOURCE_DHCP);
+ fib_table_unlock (rx_fib_index,
+ FIB_PROTOCOL_IP4);
+ fib_table_unlock (server->server_fib_index,
+ FIB_PROTOCOL_IP4);
+ memset (server, 0, sizeof (*server));
+ pool_put (dpm->dhcp_servers, server);
return 0;
}
-
- if (rx_fib_index < vec_len(dpm->dhcp_server_index_by_rx_fib_index))
- {
- server_index = dpm->dhcp_server_index_by_rx_fib_index[rx_fib_index];
- if (server_index != 0)
- {
- server = pool_elt_at_index (dpm->dhcp_servers, server_index);
- goto initialize_it;
- }
- }
-
- pool_get (dpm->dhcp_servers, server);
-
- fib_table_entry_special_add(rx_fib_index,
- &all_1s,
- FIB_SOURCE_DHCP,
- FIB_ENTRY_FLAG_LOCAL,
- ADJ_INDEX_INVALID);
-
- initialize_it:
-
-
- server->dhcp_server.as_u32 = addr->as_u32;
- server->server_fib_index =
- fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4,
- server_fib_id);
- server->dhcp_src_address.as_u32 = src_address->as_u32;
- server->insert_option_82 = insert_option_82;
- server->valid = 1;
- if (rx_fib_index)
- {
- vec_validate (dpm->dhcp_server_index_by_rx_fib_index, rx_fib_index);
+ else
+ {
+ vec_validate_init_empty(dpm->dhcp_server_index_by_rx_fib_index,
+ rx_fib_index,
+ ~0);
+
+ pool_get (dpm->dhcp_servers, server);
+
+ server->dhcp_server.as_u32 = addr->as_u32;
+ server->dhcp_src_address.as_u32 = src_address->as_u32;
+
+ fib_table_entry_special_add(rx_fib_index,
+ &all_1s,
+ FIB_SOURCE_DHCP,
+ FIB_ENTRY_FLAG_LOCAL,
+ ADJ_INDEX_INVALID);
+ fib_table_lock (rx_fib_index,
+ FIB_PROTOCOL_IP4);
+
+ server->server_fib_index =
+ fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4,
+ server_fib_id);
+
+ vec_validate_init_empty (dpm->dhcp_server_index_by_rx_fib_index,
+ rx_fib_index,
+ ~0);
dpm->dhcp_server_index_by_rx_fib_index[rx_fib_index] =
- server - dpm->dhcp_servers;
- }
+ server - dpm->dhcp_servers;
+ }
- return 0;
-}
+ fib_table_unlock (rx_fib_index,
+ FIB_PROTOCOL_IP4);
-/* Old API, manipulates the default server (only) */
-int dhcp_proxy_set_server (ip4_address_t *addr, ip4_address_t *src_address,
- u32 fib_id, int insert_option_82, int is_del)
-{
- return dhcp_proxy_set_server_2 (addr, src_address, 0 /* rx_fib_id */,
- fib_id /* server_fib_id */,
- insert_option_82, is_del);
+ return 0;
}
-
static clib_error_t *
dhcp_proxy_set_command_fn (vlib_main_t * vm,
unformat_input_t * input,
@@ -818,7 +821,6 @@ dhcp_proxy_set_command_fn (vlib_main_t * vm,
ip4_address_t server_addr, src_addr;
u32 server_fib_id = 0, rx_fib_id = 0;
int is_del = 0;
- int add_option_82 = 0;
int set_src = 0, set_server = 0;
while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
@@ -833,9 +835,6 @@ dhcp_proxy_set_command_fn (vlib_main_t * vm,
else if (unformat(input, "src-address %U",
unformat_ip4_address, &src_addr))
set_src = 1;
- else if (unformat (input, "add-option-82")
- || unformat (input, "insert-option-82"))
- add_option_82 = 1;
else if (unformat (input, "delete") ||
unformat (input, "del"))
is_del = 1;
@@ -847,8 +846,8 @@ dhcp_proxy_set_command_fn (vlib_main_t * vm,
{
int rv;
- rv = dhcp_proxy_set_server_2 (&server_addr, &src_addr, rx_fib_id,
- server_fib_id, add_option_82, is_del);
+ rv = dhcp_proxy_set_server (&server_addr, &src_addr, rx_fib_id,
+ server_fib_id, is_del);
switch (rv)
{
case 0:
@@ -882,7 +881,7 @@ dhcp_proxy_set_command_fn (vlib_main_t * vm,
VLIB_CLI_COMMAND (dhcp_proxy_set_command, static) = {
.path = "set dhcp proxy",
- .short_help = "set dhcp proxy [del] server <ip-addr> src-address <ip-addr> [add-option-82] [server-fib-id <n>] [rx-fib-id <n>]",
+ .short_help = "set dhcp proxy [del] server <ip-addr> src-address <ip-addr> [server-fib-id <n>] [rx-fib-id <n>]",
.function = dhcp_proxy_set_command_fn,
};
@@ -896,8 +895,8 @@ u8 * format_dhcp_proxy_server (u8 * s, va_list * args)
if (dm == 0)
{
- s = format (s, "%=16s%=16s%=14s%=14s%=20s", "Server", "Src Address",
- "Server FIB", "RX FIB", "Insert Option 82");
+ s = format (s, "%=16s%=16s%=14s%=14s", "Server", "Src Address",
+ "Server FIB", "RX FIB");
return s;
}
@@ -911,11 +910,10 @@ u8 * format_dhcp_proxy_server (u8 * s, va_list * args)
if (rx_fib)
rx_fib_id = rx_fib->table_id;
- s = format (s, "%=16U%=16U%=14u%=14u%=20s",
+ s = format (s, "%=16U%=16U%=14u%=14u",
format_ip4_address, &server->dhcp_server,
format_ip4_address, &server->dhcp_src_address,
- server_fib_id, rx_fib_id,
- server->insert_option_82 ? "yes" : "no");
+ server_fib_id, rx_fib_id);
return s;
}
@@ -925,24 +923,22 @@ dhcp_proxy_show_command_fn (vlib_main_t * vm,
vlib_cli_command_t * cmd)
{
dhcp_proxy_main_t * dpm = &dhcp_proxy_main;
- ip4_main_t * im = &ip4_main;
dhcp_server_t * server;
- u32 server_index;
- int i;
+ u32 server_index, i;
vlib_cli_output (vm, "%U", format_dhcp_proxy_server, 0 /* header line */,
0, 0);
- for (i = 0; i < vec_len (im->fibs); i++)
- {
- if (i < vec_len(dpm->dhcp_server_index_by_rx_fib_index))
- server_index = dpm->dhcp_server_index_by_rx_fib_index[i];
- else
- server_index = 0;
+ vec_foreach_index (i, dpm->dhcp_server_index_by_rx_fib_index)
+ {
+ server_index = dpm->dhcp_server_index_by_rx_fib_index[i];
+ if (~0 == server_index)
+ continue;
+
server = pool_elt_at_index (dpm->dhcp_servers, server_index);
- if (server->valid)
- vlib_cli_output (vm, "%U", format_dhcp_proxy_server, dpm,
- server, i);
+
+ vlib_cli_output (vm, "%U", format_dhcp_proxy_server, dpm,
+ server, i);
}
return 0;
@@ -954,50 +950,104 @@ VLIB_CLI_COMMAND (dhcp_proxy_show_command, static) = {
.function = dhcp_proxy_show_command_fn,
};
+void
+dhcp_proxy_dump (void *opaque,
+ u32 context)
+{
+ dhcp_proxy_main_t * dpm = &dhcp_proxy_main;
+ ip4_fib_t *s_fib, *r_fib;
+ dhcp_server_t * server;
+ u32 server_index, i;
+ vss_info *v;
+
+ vec_foreach_index (i, dpm->dhcp_server_index_by_rx_fib_index)
+ {
+ server_index = dpm->dhcp_server_index_by_rx_fib_index[i];
+ if (~0 == server_index)
+ continue;
+
+ server = pool_elt_at_index (dpm->dhcp_servers, server_index);
+ v = dhcp_get_vss_info(dpm, i);
+
+ ip46_address_t src_addr = {
+ .ip4 = server->dhcp_src_address,
+ };
+ ip46_address_t server_addr = {
+ .ip4 = server->dhcp_server,
+ };
+
+ s_fib = ip4_fib_get(server->server_fib_index);
+ r_fib = ip4_fib_get(i);
+
+ dhcp_send_details(opaque,
+ context,
+ &server_addr,
+ &src_addr,
+ s_fib->table_id,
+ r_fib->table_id,
+ (v ? v->vpn_id.fib_id : 0),
+ (v ? v->vpn_id.oui : 0));
+ }
+}
-int dhcp_proxy_set_option82_vss( u32 vrf_id,
- u32 oui,
- u32 fib_id,
- int is_del)
+int dhcp_proxy_set_option82_vss(u32 tbl_id,
+ u32 oui,
+ u32 fib_id,
+ int is_del)
{
dhcp_proxy_main_t *dm = &dhcp_proxy_main;
- uword *p;
- vss_info *a;
- u32 old_oui=0, old_fib_id=0;
+ vss_info *v = NULL;
+ u32 rx_fib_index;
+ int rc = 0;
- p = hash_get (dm->opt82vss_index_by_vrf_id, vrf_id);
+ rx_fib_index = ip4_fib_table_find_or_create_and_lock(tbl_id);
+ v = dhcp_get_vss_info(dm, rx_fib_index);
- if (p)
- {
- a = pool_elt_at_index (dm->opt82vss, p[0]);
- if (!a)
- return VNET_API_ERROR_NO_SUCH_FIB;
- old_oui = a->vpn_id.oui;
- old_fib_id = a->vpn_id.fib_id;
-
+ if (NULL != v)
+ {
if (is_del)
- {
- if (old_oui == oui &&
- old_fib_id == fib_id)
- {
- pool_put(dm->opt82vss, a);
- hash_unset (dm->opt82vss_index_by_vrf_id, vrf_id);
- return 0;
- }
- else
- return VNET_API_ERROR_NO_SUCH_ENTRY;
- }
- pool_put(dm->opt82vss, a);
- hash_unset (dm->opt82vss_index_by_vrf_id, vrf_id);
- } else if (is_del)
- return VNET_API_ERROR_NO_SUCH_ENTRY;
- pool_get (dm->opt82vss, a);
- memset (a, ~0, sizeof (a[0]));
- a->vpn_id.oui = oui;
- a->vpn_id.fib_id = fib_id;
- hash_set (dm->opt82vss_index_by_vrf_id, vrf_id, a - dm->opt82vss);
+ {
+ /* release the lock held on the table when the VSS
+ * info was created */
+ fib_table_unlock (rx_fib_index,
+ FIB_PROTOCOL_IP4);
+
+ pool_put (dm->vss, v);
+ dm->vss_index_by_rx_fib_index[rx_fib_index] = ~0;
+ }
+ else
+ {
+ /* this is a modify */
+ v->vpn_id.fib_id = fib_id;
+ v->vpn_id.oui = oui;
+ }
+ }
+ else
+ {
+ if (is_del)
+ rc = VNET_API_ERROR_NO_SUCH_ENTRY;
+ else
+ {
+ /* create a new entry */
+ vec_validate_init_empty(dm->vss_index_by_rx_fib_index,
+ rx_fib_index, ~0);
+
+ /* hold a lock on the table whilst the VSS info exist */
+ fib_table_lock (rx_fib_index,
+ FIB_PROTOCOL_IP4);
+
+ pool_get (dm->vss, v);
+ v->vpn_id.fib_id = fib_id;
+ v->vpn_id.oui = oui;
+ dm->vss_index_by_rx_fib_index[rx_fib_index] = v - dm->vss;
+ }
+ }
+
+ /* Release the lock taken during the create_or_lock at the start */
+ fib_table_unlock (rx_fib_index,
+ FIB_PROTOCOL_IP4);
- return 0;
+ return (rc);
}
static clib_error_t *
@@ -1065,20 +1115,20 @@ dhcp_vss_show_command_fn (vlib_main_t * vm,
{
dhcp_proxy_main_t * dm = &dhcp_proxy_main;
+ ip4_fib_t *fib;
+ u32 *fib_index;
vss_info *v;
- u32 oui;
- u32 fib_id;
- u32 tbl_id;
- uword index;
vlib_cli_output (vm, "%=9s%=11s%=12s","Table", "OUI", "VPN-ID");
- hash_foreach (tbl_id, index, dm->opt82vss_index_by_vrf_id,
+ pool_foreach (fib_index, dm->vss_index_by_rx_fib_index,
({
- v = pool_elt_at_index (dm->opt82vss, index);
- oui = v->vpn_id.oui;
- fib_id = v->vpn_id.fib_id;
- vlib_cli_output (vm, "%=9d 0x%08x%=12d",
- tbl_id, oui, fib_id);
+ fib = ip4_fib_get (*fib_index);
+ v = pool_elt_at_index (dm->vss, *fib_index);
+
+ vlib_cli_output (vm, "%=6d%=6d%=12d",
+ fib->table_id,
+ v->vpn_id.oui,
+ v->vpn_id.fib_id);
}));
return 0;
diff --git a/src/vnet/dhcpv6/proxy.h b/src/vnet/dhcpv6/proxy.h
index 9e18913a970..77ced3619c4 100644
--- a/src/vnet/dhcpv6/proxy.h
+++ b/src/vnet/dhcpv6/proxy.h
@@ -48,9 +48,7 @@ typedef union {
typedef struct {
ip6_address_t dhcp6_server;
ip6_address_t dhcp6_src_address;
- u32 insert_vss;
u32 server_fib6_index;
- u32 valid;
} dhcpv6_server_t;
typedef struct {
@@ -70,7 +68,7 @@ typedef struct {
dhcpv6_vss_info *vss;
/* hash lookup specific vrf_id -> VSS vector index*/
- uword *vss_index_by_vrf_id;
+ u32 *vss_index_by_rx_fib_index;
/* convenience */
vlib_main_t * vlib_main;
@@ -79,17 +77,18 @@ typedef struct {
dhcpv6_proxy_main_t dhcpv6_proxy_main;
-int dhcpv6_proxy_set_server (ip6_address_t *addr, ip6_address_t *src_address,
- u32 fib_id, int insert_vss, int is_del);
-
int dhcpv6_proxy_set_vss(u32 tbl_id,
u32 oui,
u32 fib_id,
int is_del);
-int dhcpv6_proxy_set_server_2 (ip6_address_t *addr, ip6_address_t *src_address,
- u32 rx_fib_id,
- u32 server_fib_id,
- int insert_vss, int is_del);
+int dhcpv6_proxy_set_server(ip6_address_t *addr,
+ ip6_address_t *src_address,
+ u32 rx_fib_id,
+ u32 server_fib_id,
+ int is_del);
+
+void dhcpv6_proxy_dump(void *opaque,
+ u32 context);
#endif /* included_dhcpv6_proxy_h */
diff --git a/src/vnet/dhcpv6/proxy_node.c b/src/vnet/dhcpv6/proxy_node.c
index 4137624c5b4..f40798e6c5d 100644
--- a/src/vnet/dhcpv6/proxy_node.c
+++ b/src/vnet/dhcpv6/proxy_node.c
@@ -18,6 +18,7 @@
#include <vlib/vlib.h>
#include <vnet/pg/pg.h>
#include <vnet/dhcpv6/proxy.h>
+#include <vnet/dhcp/proxy.h>
#include <vnet/fib/ip6_fib.h>
#include <vnet/mfib/mfib_table.h>
#include <vnet/mfib/ip6_mfib.h>
@@ -117,6 +118,42 @@ static inline void copy_ip6_address (ip6_address_t *dst, ip6_address_t *src)
dst->as_u64[1] = src->as_u64[1];
}
+static inline dhcpv6_vss_info *
+dhcpv6_get_vss_info (dhcpv6_proxy_main_t *dm,
+ u32 rx_fib_index)
+{
+ dhcpv6_vss_info *v;
+
+ if (vec_len(dm->vss_index_by_rx_fib_index) <= rx_fib_index ||
+ dm->vss_index_by_rx_fib_index[rx_fib_index] == ~0)
+ {
+ v = NULL;
+ }
+ else
+ {
+ v = pool_elt_at_index (dm->vss,
+ dm->vss_index_by_rx_fib_index[rx_fib_index]);
+ }
+
+ return (v);
+}
+
+static inline dhcpv6_server_t *
+dhcpv6_get_server (dhcpv6_proxy_main_t *dm,
+ u32 rx_fib_index)
+{
+ dhcpv6_server_t *s = NULL;
+
+ if (vec_len(dm->dhcp6_server_index_by_rx_fib_index) > rx_fib_index &&
+ dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index] != ~0)
+ {
+ s = pool_elt_at_index (dm->dhcp6_servers,
+ dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index]);
+ }
+
+ return (s);
+}
+
static uword
dhcpv6_proxy_to_server_input (vlib_main_t * vm,
vlib_node_runtime_t * node,
@@ -132,13 +169,10 @@ dhcpv6_proxy_to_server_input (vlib_main_t * vm,
u32 pkts_wrong_msg_type=0;
u32 pkts_too_big=0;
ip6_main_t * im = &ip6_main;
- ip6_fib_t * fib;
ip6_address_t * src;
int bogus_length;
dhcpv6_server_t * server;
u32 rx_fib_idx = 0, server_fib_idx = 0;
- u32 server_idx;
- u32 fib_id1 = 0;
next_index = node->cached_next_index;
@@ -172,12 +206,8 @@ dhcpv6_proxy_to_server_input (vlib_main_t * vm,
ethernet_header_t * e_h0;
u8 client_src_mac[6];
vlib_buffer_free_list_t *fl;
-
- uword *p_vss;
- u32 oui1=0;
dhcpv6_vss_info *vss;
-
bi0 = from[0];
to_next[0] = bi0;
from += 1;
@@ -228,25 +258,15 @@ dhcpv6_proxy_to_server_input (vlib_main_t * vm,
/* Send to DHCPV6 server via the configured FIB */
rx_sw_if_index = sw_if_index = vnet_buffer(b0)->sw_if_index[VLIB_RX];
rx_fib_idx = im->fib_index_by_sw_if_index [rx_sw_if_index];
+ server = dhcpv6_get_server(dpm, rx_fib_idx);
- if (vec_len(dpm->dhcp6_server_index_by_rx_fib_index) <= rx_fib_idx)
- goto no_server;
-
- server_idx = dpm->dhcp6_server_index_by_rx_fib_index[rx_fib_idx];
-
- if (PREDICT_FALSE (pool_is_free_index (dpm->dhcp6_servers,
- server_idx)))
- {
- no_server:
- error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
- next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
- pkts_no_server++;
- goto do_trace;
- }
-
- server = pool_elt_at_index(dpm->dhcp6_servers, server_idx);
- if (server->valid == 0)
- goto no_server;
+ if (PREDICT_FALSE (NULL == server))
+ {
+ error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
+ next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
+ pkts_no_server++;
+ goto do_trace;
+ }
server_fib_idx = server->server_fib6_index;
vnet_buffer(b0)->sw_if_index[VLIB_TX] = server_fib_idx;
@@ -331,19 +351,6 @@ dhcpv6_proxy_to_server_input (vlib_main_t * vm,
id1 = (dhcpv6_int_id_t *) (((uword) ip1) + b0->current_length);
b0->current_length += (sizeof (*id1));
-
- fib = ip6_fib_get (rx_fib_idx);
-
- //TODO: Revisit if hash makes sense here
- p_vss = hash_get (dpm->vss_index_by_vrf_id,
- fib->table_id);
- if (p_vss)
- {
- vss = pool_elt_at_index (dpm->vss, p_vss[0]);
- oui1 = vss->vpn_id.oui;
- fib_id1 = vss->vpn_id.fib_id;
- }
-
id1->opt.option = clib_host_to_net_u16(DHCPV6_OPTION_INTERFACE_ID);
id1->opt.length = clib_host_to_net_u16(sizeof(rx_sw_if_index));
id1->int_idx = clib_host_to_net_u32(rx_sw_if_index);
@@ -360,20 +367,24 @@ dhcpv6_proxy_to_server_input (vlib_main_t * vm,
clib_memcpy(cmac->data, client_src_mac, 6);
u1->length += sizeof(*cmac);
}
- if (server->insert_vss !=0 ) {
+
+ //TODO: Revisit if hash makes sense here
+ vss = dhcpv6_get_vss_info(dpm, rx_fib_idx);
+
+ if (NULL != vss) {
vss1 = (dhcpv6_vss_t *) (((uword) ip1) + b0->current_length);
b0->current_length += (sizeof (*vss1));
vss1->opt.length =clib_host_to_net_u16(sizeof(*vss1) -
sizeof(vss1->opt));
vss1->opt.option = clib_host_to_net_u16(DHCPV6_OPTION_VSS);
vss1->data[0] = 1; // type
- vss1->data[1] = oui1>>16 & 0xff;
- vss1->data[2] = oui1>>8 & 0xff;
- vss1->data[3] = oui1 & 0xff;
- vss1->data[4] = fib_id1>>24 & 0xff;
- vss1->data[5] = fib_id1>>16 & 0xff;
- vss1->data[6] = fib_id1>>8 & 0xff;
- vss1->data[7] = fib_id1 & 0xff;
+ vss1->data[1] = vss->vpn_id.oui >>16 & 0xff;
+ vss1->data[2] = vss->vpn_id.oui >>8 & 0xff;
+ vss1->data[3] = vss->vpn_id.oui & 0xff;
+ vss1->data[4] = vss->vpn_id.fib_id >> 24 & 0xff;
+ vss1->data[5] = vss->vpn_id.fib_id >> 16 & 0xff;
+ vss1->data[6] = vss->vpn_id.fib_id >> 8 & 0xff;
+ vss1->data[7] = vss->vpn_id.fib_id & 0xff;
u1->length += sizeof(*vss1);
}
@@ -524,9 +535,8 @@ dhcpv6_proxy_to_client_input (vlib_main_t * vm,
u16 len = 0;
u8 interface_opt_flag = 0;
u8 relay_msg_opt_flag = 0;
- ip6_fib_t * svr_fib;
ip6_main_t * im = &ip6_main;
- u32 server_fib_idx, svr_fib_id, client_fib_idx, server_idx;
+ u32 server_fib_idx, client_fib_idx;
bi0 = from[0];
from += 1;
@@ -608,31 +618,18 @@ dhcpv6_proxy_to_client_input (vlib_main_t * vm,
vlib_buffer_advance (b0, sizeof(*r0));
client_fib_idx = im->fib_index_by_sw_if_index[sw_if_index];
- if (client_fib_idx < vec_len(dm->dhcp6_server_index_by_rx_fib_index))
- server_idx = dm->dhcp6_server_index_by_rx_fib_index[client_fib_idx];
- else
- server_idx = 0;
-
- if (PREDICT_FALSE (pool_is_free_index (dm->dhcp6_servers, server_idx)))
- {
- error0 = DHCPV6_PROXY_ERROR_WRONG_INTERFACE_ID_OPTION;
- goto drop_packet;
- }
+ server = dhcpv6_get_server(dm, client_fib_idx);
- server = pool_elt_at_index (dm->dhcp6_servers, server_idx);
- if (server->valid == 0)
+ if (NULL == server)
{
error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
goto drop_packet;
}
-
server_fib_idx = im->fib_index_by_sw_if_index
[vnet_buffer(b0)->sw_if_index[VLIB_RX]];
- svr_fib = ip6_fib_get (server_fib_idx);
- svr_fib_id = svr_fib->table_id;
- if (svr_fib_id != server->server_fib6_index ||
+ if (server_fib_idx != server->server_fib6_index ||
ip0->src_address.as_u64[0] != server->dhcp6_server.as_u64[0] ||
ip0->src_address.as_u64[1] != server->dhcp6_server.as_u64[1])
{
@@ -760,7 +757,7 @@ clib_error_t * dhcpv6_proxy_init (vlib_main_t * vm)
error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
dm->error_drop_node_index = error_drop_node->index;
- dm->vss_index_by_vrf_id = hash_create (0, sizeof (uword));
+ dm->vss_index_by_rx_fib_index = NULL;
/* RFC says this is the dhcpv6 server address */
dm->all_dhcpv6_server_address.as_u64[0] = clib_host_to_net_u64 (0xFF05000000000000);
@@ -785,121 +782,138 @@ clib_error_t * dhcpv6_proxy_init (vlib_main_t * vm)
VLIB_INIT_FUNCTION (dhcpv6_proxy_init);
-/* Old API, manipulates a single server (only) shared by all Rx VRFs */
-int dhcpv6_proxy_set_server (ip6_address_t *addr, ip6_address_t *src_address,
- u32 fib_id, int insert_vss, int is_del)
-{
- return dhcpv6_proxy_set_server_2 (addr, src_address,
- 0, fib_id,
- insert_vss, is_del);
-}
-
-int dhcpv6_proxy_set_server_2 (ip6_address_t *addr, ip6_address_t *src_address,
- u32 rx_fib_id, u32 server_fib_id,
- int insert_vss, int is_del)
+int dhcpv6_proxy_set_server (ip6_address_t *addr,
+ ip6_address_t *src_address,
+ u32 rx_fib_id,
+ u32 server_fib_id,
+ int is_del)
{
dhcpv6_proxy_main_t * dm = &dhcpv6_proxy_main;
dhcpv6_server_t * server = 0;
- u32 server_fib_index = 0;
u32 rx_fib_index = 0;
+ int rc = 0;
rx_fib_index = ip6_mfib_table_find_or_create_and_lock(rx_fib_id);
- server_fib_index = ip6_fib_table_find_or_create_and_lock(server_fib_id);
-
- if (is_del)
- {
-
- if (rx_fib_index >= vec_len(dm->dhcp6_server_index_by_rx_fib_index))
- return VNET_API_ERROR_NO_SUCH_ENTRY;
- server_fib_index = dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index];
-
- dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index] = 0;
- server = pool_elt_at_index (dm->dhcp6_servers, server_fib_index);
- memset (server, 0, sizeof (*server));
- pool_put (dm->dhcp6_servers, server);
- return 0;
+ const mfib_prefix_t all_dhcp_servers = {
+ .fp_len = 128,
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_grp_addr = {
+ .ip6 = dm->all_dhcpv6_server_relay_agent_address,
}
+ };
- if (addr->as_u64[0] == 0 &&
- addr->as_u64[1] == 0 )
- return VNET_API_ERROR_INVALID_DST_ADDRESS;
-
- if (src_address->as_u64[0] == 0 &&
- src_address->as_u64[1] == 0)
- return VNET_API_ERROR_INVALID_SRC_ADDRESS;
-
- if (rx_fib_id == 0)
+ if (is_del)
{
- server = pool_elt_at_index (dm->dhcp6_servers, 0);
- if (server->valid)
- goto reconfigure_it;
- else
- goto initialize_it;
- }
+ server = dhcpv6_get_server(dm, rx_fib_index);
- if (rx_fib_index < vec_len(dm->dhcp6_server_index_by_rx_fib_index))
- {
- server_fib_index = dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index];
- if (server_fib_index != 0)
+ if (NULL == server)
{
- server = pool_elt_at_index (dm->dhcp6_servers, server_fib_index);
- goto initialize_it;
+ rc = VNET_API_ERROR_NO_SUCH_ENTRY;
+ goto out;
}
- }
- /*Allocate a new server*/
- pool_get (dm->dhcp6_servers, server);
-
- initialize_it:
- {
- const mfib_prefix_t all_dhcp_servers = {
- .fp_len = 128,
- .fp_proto = FIB_PROTOCOL_IP6,
- .fp_grp_addr = {
- .ip6 = dm->all_dhcpv6_server_relay_agent_address,
- }
- };
- const fib_route_path_t path_for_us = {
- .frp_proto = FIB_PROTOCOL_IP6,
- .frp_addr = zero_addr,
- .frp_sw_if_index = 0xffffffff,
- .frp_fib_index = ~0,
- .frp_weight = 0,
- .frp_flags = FIB_ROUTE_PATH_LOCAL,
- };
- mfib_table_entry_path_update(rx_fib_index,
- &all_dhcp_servers,
- MFIB_SOURCE_DHCP,
- &path_for_us,
- MFIB_ITF_FLAG_FORWARD);
/*
- * Each interface that is enabled in this table, needs to be added
- * as an accepting interface, but this is not easily doable in VPP.
- * So we cheat. Add a flag to the entry that indicates accept form
- * any interface.
- * We will still only accept on v6 enabled interfaces, since the input
- * feature ensures this.
+ * release the locks held on the server fib and rx mfib
*/
- mfib_table_entry_update(rx_fib_index,
+ mfib_table_entry_delete(rx_fib_index,
&all_dhcp_servers,
- MFIB_SOURCE_DHCP,
- MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF);
- }
+ MFIB_SOURCE_DHCP);
+ mfib_table_unlock(rx_fib_index, FIB_PROTOCOL_IP6);
+ fib_table_unlock(server->server_fib6_index, FIB_PROTOCOL_IP6);
-reconfigure_it:
+ dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index] = ~0;
- copy_ip6_address(&server->dhcp6_server, addr);
- copy_ip6_address(&server->dhcp6_src_address, src_address);
- server->server_fib6_index = server_fib_index;
- server->valid = 1;
- server->insert_vss = insert_vss;
+ memset (server, 0, sizeof (*server));
+ pool_put (dm->dhcp6_servers, server);
+ }
+ else
+ {
+ if (addr->as_u64[0] == 0 &&
+ addr->as_u64[1] == 0 )
+ {
+ rc = VNET_API_ERROR_INVALID_DST_ADDRESS;
+ goto out;
+ }
+ if (src_address->as_u64[0] == 0 &&
+ src_address->as_u64[1] == 0)
+ {
+ rc = VNET_API_ERROR_INVALID_SRC_ADDRESS;
+ goto out;
+ }
- vec_validate (dm->dhcp6_server_index_by_rx_fib_index, rx_fib_index);
- dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index] =
- server - dm->dhcp6_servers;
+ server = dhcpv6_get_server(dm, rx_fib_index);
- return 0;
+ if (NULL != server)
+ {
+ /* modify of an existing entry */
+ ip6_fib_t *fib;
+
+ fib = ip6_fib_get(server->server_fib6_index);
+
+ if (fib->table_id != server_fib_id)
+ {
+ /* swap tables */
+ fib_table_unlock(server->server_fib6_index, FIB_PROTOCOL_IP6);
+ server->server_fib6_index =
+ ip6_fib_table_find_or_create_and_lock(server_fib_id);
+ }
+ }
+ else
+ {
+ /* Allocate a new server */
+ pool_get (dm->dhcp6_servers, server);
+
+ vec_validate_init_empty (dm->dhcp6_server_index_by_rx_fib_index,
+ rx_fib_index, ~0);
+ dm->dhcp6_server_index_by_rx_fib_index[rx_fib_index] =
+ server - dm->dhcp6_servers;
+
+ server->server_fib6_index =
+ ip6_fib_table_find_or_create_and_lock(server_fib_id);
+ mfib_table_lock(rx_fib_index, FIB_PROTOCOL_IP6);
+
+ const mfib_prefix_t all_dhcp_servers = {
+ .fp_len = 128,
+ .fp_proto = FIB_PROTOCOL_IP6,
+ .fp_grp_addr = {
+ .ip6 = dm->all_dhcpv6_server_relay_agent_address,
+ }
+ };
+ const fib_route_path_t path_for_us = {
+ .frp_proto = FIB_PROTOCOL_IP6,
+ .frp_addr = zero_addr,
+ .frp_sw_if_index = 0xffffffff,
+ .frp_fib_index = ~0,
+ .frp_weight = 0,
+ .frp_flags = FIB_ROUTE_PATH_LOCAL,
+ };
+ mfib_table_entry_path_update(rx_fib_index,
+ &all_dhcp_servers,
+ MFIB_SOURCE_DHCP,
+ &path_for_us,
+ MFIB_ITF_FLAG_FORWARD);
+ /*
+ * Each interface that is enabled in this table, needs to be added
+ * as an accepting interface, but this is not easily doable in VPP.
+ * So we cheat. Add a flag to the entry that indicates accept form
+ * any interface.
+ * We will still only accept on v6 enabled interfaces, since the
+ * input feature ensures this.
+ */
+ mfib_table_entry_update(rx_fib_index,
+ &all_dhcp_servers,
+ MFIB_SOURCE_DHCP,
+ MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF);
+ }
+ copy_ip6_address(&server->dhcp6_server, addr);
+ copy_ip6_address(&server->dhcp6_src_address, src_address);
+ }
+
+out:
+ mfib_table_unlock(rx_fib_index, FIB_PROTOCOL_IP6);
+
+ return (rc);
}
static clib_error_t *
@@ -910,7 +924,7 @@ dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
ip6_address_t addr, src_addr;
int set_server = 0, set_src_address = 0;
u32 rx_fib_id = 0, server_fib_id = 0;
- int is_del = 0, add_vss = 0;
+ int is_del = 0;
while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
{
@@ -924,9 +938,6 @@ dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
;
else if (unformat (input, "rx-fib-id %d", &rx_fib_id))
;
- else if (unformat (input, "add-vss-option")
- || unformat (input, "insert-option"))
- add_vss = 1;
else if (unformat (input, "delete") ||
unformat (input, "del"))
is_del = 1;
@@ -938,8 +949,8 @@ dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
{
int rv;
- rv = dhcpv6_proxy_set_server_2 (&addr, &src_addr, rx_fib_id,
- server_fib_id, add_vss, is_del);
+ rv = dhcpv6_proxy_set_server (&addr, &src_addr, rx_fib_id,
+ server_fib_id, is_del);
//TODO: Complete the errors
switch (rv)
@@ -962,7 +973,7 @@ dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
VLIB_CLI_COMMAND (dhcpv6_proxy_set_command, static) = {
.path = "set dhcpv6 proxy",
.short_help = "set dhcpv6 proxy [del] server <ipv6-addr> src-address <ipv6-addr> "
- "[add-vss-option] [server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
+ "[server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
.function = dhcpv6_proxy_set_command_fn,
};
@@ -976,8 +987,8 @@ u8 * format_dhcpv6_proxy_server (u8 * s, va_list * args)
if (dm == 0)
{
- s = format (s, "%=40s%=40s%=14s%=14s%=20s", "Server Address", "Source Address",
- "Server FIB", "RX FIB", "Insert VSS Option");
+ s = format (s, "%=40s%=40s%=14s%=14s", "Server Address", "Source Address",
+ "Server FIB", "RX FIB");
return s;
}
@@ -990,11 +1001,10 @@ u8 * format_dhcpv6_proxy_server (u8 * s, va_list * args)
if (rx_fib)
rx_fib_id = rx_fib->table_id;
- s = format (s, "%=40U%=40U%=14u%=14u%=20s",
+ s = format (s, "%=40U%=40U%=14u%=14u",
format_ip6_address, &server->dhcp6_server,
format_ip6_address, &server->dhcp6_src_address,
- server_fib_id, rx_fib_id,
- server->insert_vss ? "yes" : "no");
+ server_fib_id, rx_fib_id);
return s;
}
@@ -1003,25 +1013,25 @@ dhcpv6_proxy_show_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- dhcpv6_proxy_main_t * dm = &dhcpv6_proxy_main;
- ip6_main_t * im = &ip6_main;
+ dhcpv6_proxy_main_t * dpm = &dhcpv6_proxy_main;
int i;
u32 server_index;
dhcpv6_server_t * server;
vlib_cli_output (vm, "%U", format_dhcpv6_proxy_server, 0 /* header line */,
0, 0);
- for (i = 0; i < vec_len (im->fibs); i++)
- {
- if (i < vec_len(dm->dhcp6_server_index_by_rx_fib_index))
- server_index = dm->dhcp6_server_index_by_rx_fib_index[i];
- else
- server_index = 0;
- server = pool_elt_at_index (dm->dhcp6_servers, server_index);
- if (server->valid)
- vlib_cli_output (vm, "%U", format_dhcpv6_proxy_server, dm,
- server, i);
- }
+ vec_foreach_index (i, dpm->dhcp6_server_index_by_rx_fib_index)
+ {
+ server_index = dpm->dhcp6_server_index_by_rx_fib_index[i];
+ if (~0 == server_index)
+ continue;
+
+ server = pool_elt_at_index (dpm->dhcp6_servers, server_index);
+
+ vlib_cli_output (vm, "%U", format_dhcpv6_proxy_server, dpm,
+ server, i);
+ }
+
return 0;
}
@@ -1031,51 +1041,104 @@ VLIB_CLI_COMMAND (dhcpv6_proxy_show_command, static) = {
.function = dhcpv6_proxy_show_command_fn,
};
+void
+dhcpv6_proxy_dump (void *opaque,
+ u32 context)
+{
+ dhcpv6_proxy_main_t * dpm = &dhcpv6_proxy_main;
+ ip6_fib_t *s_fib, *r_fib;
+ dhcpv6_server_t * server;
+ u32 server_index, i;
+ dhcpv6_vss_info *v;
+
+ vec_foreach_index (i, dpm->dhcp6_server_index_by_rx_fib_index)
+ {
+ server_index = dpm->dhcp6_server_index_by_rx_fib_index[i];
+ if (~0 == server_index)
+ continue;
+
+ server = pool_elt_at_index (dpm->dhcp6_servers, server_index);
+ v = dhcpv6_get_vss_info(dpm, i);
+
+ ip46_address_t src_addr = {
+ .ip6 = server->dhcp6_src_address,
+ };
+ ip46_address_t server_addr = {
+ .ip6 = server->dhcp6_server,
+ };
+
+ s_fib = ip6_fib_get(server->server_fib6_index);
+ r_fib = ip6_fib_get(i);
+
+ dhcp_send_details(opaque,
+ context,
+ &server_addr,
+ &src_addr,
+ s_fib->table_id,
+ r_fib->table_id,
+ (v ? v->vpn_id.fib_id : 0),
+ (v ? v->vpn_id.oui : 0));
+ }
+}
+
int dhcpv6_proxy_set_vss(u32 tbl_id,
u32 oui,
u32 fib_id,
int is_del)
{
dhcpv6_proxy_main_t *dm = &dhcpv6_proxy_main;
- u32 old_oui, old_fib_id;
- uword *p;
- dhcpv6_vss_info *v;
+ dhcpv6_vss_info *v = NULL;
+ u32 rx_fib_index;
+ int rc = 0;
- p = hash_get (dm->vss_index_by_vrf_id, tbl_id);
+ rx_fib_index = ip6_fib_table_find_or_create_and_lock(tbl_id);
+ v = dhcpv6_get_vss_info(dm, rx_fib_index);
- if (p) {
- v = pool_elt_at_index (dm->vss, p[0]);
- if (!v)
- return VNET_API_ERROR_NO_SUCH_FIB;
-
- old_oui = v->vpn_id.oui;
- old_fib_id = v->vpn_id.fib_id;
+ if (NULL != v)
+ {
+ if (is_del)
+ {
+ /* release the lock held on the table when the VSS
+ * info was created */
+ fib_table_unlock (rx_fib_index,
+ FIB_PROTOCOL_IP6);
+ pool_put (dm->vss, v);
+ dm->vss_index_by_rx_fib_index[rx_fib_index] = ~0;
+ }
+ else
+ {
+ /* this is a modify */
+ v->vpn_id.fib_id = fib_id;
+ v->vpn_id.oui = oui;
+ }
+ }
+ else
+ {
if (is_del)
+ rc = VNET_API_ERROR_NO_SUCH_ENTRY;
+ else
{
- if (old_oui == oui &&
- old_fib_id == fib_id )
- {
- pool_put(dm->vss, v);
- hash_unset (dm->vss_index_by_vrf_id, tbl_id);
- return 0;
- }
- else
- return VNET_API_ERROR_NO_SUCH_ENTRY;
+ /* create a new entry */
+ vec_validate_init_empty(dm->vss_index_by_rx_fib_index,
+ rx_fib_index, ~0);
+
+ /* hold a lock on the table whilst the VSS info exist */
+ fib_table_lock (rx_fib_index,
+ FIB_PROTOCOL_IP6);
+
+ pool_get (dm->vss, v);
+ v->vpn_id.fib_id = fib_id;
+ v->vpn_id.oui = oui;
+ dm->vss_index_by_rx_fib_index[rx_fib_index] = v - dm->vss;
}
+ }
- pool_put(dm->vss, v);
- hash_unset (dm->vss_index_by_vrf_id, tbl_id);
- } else if (is_del)
- return VNET_API_ERROR_NO_SUCH_ENTRY;
-
- pool_get (dm->vss, v);
- memset (v, ~0, sizeof (*v));
- v->vpn_id.fib_id = fib_id;
- v->vpn_id.oui = oui;
- hash_set (dm->vss_index_by_vrf_id, tbl_id, v - dm->vss);
+ /* Release the lock taken during the create_or_lock at the start */
+ fib_table_unlock (rx_fib_index,
+ FIB_PROTOCOL_IP6);
- return 0;
+ return (rc);
}
@@ -1147,19 +1210,19 @@ dhcpv6_vss_show_command_fn (vlib_main_t * vm,
{
dhcpv6_proxy_main_t * dm = &dhcpv6_proxy_main;
dhcpv6_vss_info *v;
- u32 oui;
- u32 fib_id;
- u32 tbl_id;
- uword index;
+ ip6_fib_t *fib;
+ u32 *fib_index;
vlib_cli_output (vm, "%=6s%=6s%=12s","Table", "OUI", "VPN ID");
- hash_foreach (tbl_id, index, dm->vss_index_by_vrf_id,
+ pool_foreach (fib_index, dm->vss_index_by_rx_fib_index,
({
- v = pool_elt_at_index (dm->vss, index);
- oui = v->vpn_id.oui;
- fib_id = v->vpn_id.fib_id;
- vlib_cli_output (vm, "%=6d%=6d%=12d",
- tbl_id, oui, fib_id);
+ fib = ip6_fib_get (*fib_index);
+ v = pool_elt_at_index (dm->vss, *fib_index);
+
+ vlib_cli_output (vm, "%=6d%=6d%=12d",
+ fib->table_id,
+ v->vpn_id.oui,
+ v->vpn_id.fib_id);
}));
return 0;
diff --git a/src/vnet/dpo/receive_dpo.c b/src/vnet/dpo/receive_dpo.c
index 2b2571c6c83..83e33ed8cf0 100644
--- a/src/vnet/dpo/receive_dpo.c
+++ b/src/vnet/dpo/receive_dpo.c
@@ -102,6 +102,11 @@ format_receive_dpo (u8 *s, va_list *ap)
vnet_main_t * vnm = vnet_get_main();
receive_dpo_t *rd;
+ if (pool_is_free_index(receive_dpo_pool, index))
+ {
+ return (format(s, "dpo-receive DELETED"));
+ }
+
rd = receive_dpo_get(index);
if (~0 != rd->rd_sw_if_index)