#include <nat/nat.h>
#include <nat/nat_det.h>
#include <nat/nat64.h>
+#include <nat/dslite.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
-#include <vlibsocket/api.h>
+
#include <nat/nat_msg_enum.h>
#include <vnet/fib/fib_table.h>
memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_SNAT_INTERFACE_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (i->sw_if_index);
- rmp->is_inside = i->is_inside;
+ rmp->is_inside = nat_interface_is_inside (i);
rmp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
ntohs (VL_API_SNAT_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (i->sw_if_index);
rmp->context = context;
- rmp->is_inside = i->is_inside;
+ rmp->is_inside = nat_interface_is_inside (i);
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
snat_user_t *u;
u32 session_index, head_index, elt_index;
dlist_elt_t *head, *elt;
+ ip4_header_t ip;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
return;
clib_memcpy (&ukey.addr, mp->ip_address, 4);
+ ip.src_address.as_u32 = ukey.addr.as_u32;
ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
key.key = ukey.as_u64;
- if (!clib_bihash_search_8_8 (&sm->worker_by_in, &key, &value))
- tsm = vec_elt_at_index (sm->per_thread_data, value.value);
+ if (sm->num_workers)
+ tsm =
+ vec_elt_at_index (sm->per_thread_data,
+ sm->worker_in2out_cb (&ip, ukey.fib_index));
else
tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
- if (clib_bihash_search_8_8 (&sm->user_hash, &key, &value))
+ if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
return;
u = pool_elt_at_index (tsm->users, value.value);
if (!u->nsessions && !u->nstaticsessions)
memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (i->sw_if_index);
- rmp->is_inside = i->is_inside;
+ rmp->is_inside = (nat_interface_is_inside (i)
+ && nat_interface_is_outside (i)) ? 2 :
+ nat_interface_is_inside (i);
rmp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
ntohs (VL_API_NAT44_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (i->sw_if_index);
rmp->context = context;
- rmp->is_inside = i->is_inside;
+ rmp->is_inside = nat_interface_is_inside (i);
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
snat_user_t *u;
u32 session_index, head_index, elt_index;
dlist_elt_t *head, *elt;
+ ip4_header_t ip;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
return;
clib_memcpy (&ukey.addr, mp->ip_address, 4);
+ ip.src_address.as_u32 = ukey.addr.as_u32;
ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
key.key = ukey.as_u64;
- if (!clib_bihash_search_8_8 (&sm->worker_by_in, &key, &value))
- tsm = vec_elt_at_index (sm->per_thread_data, value.value);
+ if (sm->num_workers)
+ tsm =
+ vec_elt_at_index (sm->per_thread_data,
+ sm->worker_in2out_cb (&ip, ukey.fib_index));
else
tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
- if (clib_bihash_search_8_8 (&sm->user_hash, &key, &value))
+ if (clib_bihash_search_8_8 (&tsm->user_hash, &key, &value))
return;
u = pool_elt_at_index (tsm->users, value.value);
if (!u->nsessions && !u->nstaticsessions)
FINISH;
}
+static void
+vl_api_nat44_del_session_t_handler (vl_api_nat44_del_session_t * mp)
+{
+ snat_main_t *sm = &snat_main;
+ vl_api_nat44_del_session_reply_t *rmp;
+ ip4_address_t addr;
+ u16 port;
+ u32 vrf_id;
+ int rv = 0;
+ snat_protocol_t proto;
+
+ memcpy (&addr.as_u8, mp->address, 4);
+ port = clib_net_to_host_u16 (mp->port);
+ vrf_id = clib_net_to_host_u32 (mp->vrf_id);
+ proto = ip_proto_to_snat_proto (mp->protocol);
+
+ rv = nat44_del_session (sm, &addr, port, proto, vrf_id, mp->is_in);
+
+ REPLY_MACRO (VL_API_NAT44_DEL_SESSION_REPLY);
+}
+
+static void *
+vl_api_nat44_del_session_t_print (vl_api_nat44_del_session_t * mp,
+ void *handle)
+{
+ u8 *s;
+
+ s = format (0, "SCRIPT: nat44_add_del_static_mapping ");
+ s = format (s, "addr %U port %d protocol %d vrf_id %d is_in %d",
+ format_ip4_address, mp->address,
+ clib_net_to_host_u16 (mp->port),
+ mp->protocol, clib_net_to_host_u32 (mp->vrf_id), mp->is_in);
+
+ FINISH;
+}
+
/*******************************/
/*** Deterministic NAT (CGN) ***/
/*******************************/
memset (rmp, 0, sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_NAT64_INTERFACE_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (i->sw_if_index);
- rmp->is_inside = i->is_inside;
+ rmp->is_inside = (nat_interface_is_inside (i)
+ && nat_interface_is_outside (i)) ? 2 :
+ nat_interface_is_inside (i);
rmp->context = ctx->context;
vl_msg_api_send_shmem (ctx->q, (u8 *) & rmp);
FINISH;
}
+/***************/
+/*** DS-Lite ***/
+/***************/
+
+static void
+vl_api_dslite_set_aftr_addr_t_handler (vl_api_dslite_set_aftr_addr_t * mp)
+{
+ vl_api_dslite_set_aftr_addr_reply_t *rmp;
+ snat_main_t *sm = &snat_main;
+ dslite_main_t *dm = &dslite_main;
+ int rv = 0;
+ ip6_address_t ip6_addr;
+
+ memcpy (&ip6_addr.as_u8, mp->ip6_addr, 16);
+
+ rv = dslite_set_aftr_ip6_addr (dm, &ip6_addr);
+
+ REPLY_MACRO (VL_API_DSLITE_SET_AFTR_ADDR_REPLY);
+}
+
+static void *
+vl_api_dslite_set_aftr_addr_t_print (vl_api_dslite_set_aftr_addr_t * mp,
+ void *handle)
+{
+ u8 *s;
+
+ s = format (0, "SCRIPT: dslite_set_aftr_addr ");
+ s = format (s, "ip6_addr %U ip4_addr %U\n",
+ format_ip6_address, mp->ip6_addr,
+ format_ip4_address, mp->ip4_addr);
+
+ FINISH;
+}
+
+static void
+ vl_api_dslite_add_del_pool_addr_range_t_handler
+ (vl_api_dslite_add_del_pool_addr_range_t * mp)
+{
+ vl_api_dslite_add_del_pool_addr_range_reply_t *rmp;
+ snat_main_t *sm = &snat_main;
+ dslite_main_t *dm = &dslite_main;
+ int rv = 0;
+ ip4_address_t this_addr;
+ u32 start_host_order, end_host_order;
+ int i, count;
+ u32 *tmp;
+
+ tmp = (u32 *) mp->start_addr;
+ start_host_order = clib_host_to_net_u32 (tmp[0]);
+ tmp = (u32 *) mp->end_addr;
+ end_host_order = clib_host_to_net_u32 (tmp[0]);
+
+ count = (end_host_order - start_host_order) + 1;
+ memcpy (&this_addr.as_u8, mp->start_addr, 4);
+
+ for (i = 0; i < count; i++)
+ {
+ if ((rv = dslite_add_del_pool_addr (dm, &this_addr, mp->is_add)))
+ goto send_reply;
+
+ increment_v4_address (&this_addr);
+ }
+
+send_reply:
+ REPLY_MACRO (VL_API_DSLITE_ADD_DEL_POOL_ADDR_RANGE_REPLY);
+}
+
+static void *vl_api_dslite_add_del_pool_addr_range_t_print
+ (vl_api_dslite_add_del_pool_addr_range_t * mp, void *handle)
+{
+ u8 *s;
+
+ s = format (0, "SCRIPT: dslite_add_del_pool_addr_range ");
+ s = format (s, "%U - %U\n",
+ format_ip4_address, mp->start_addr,
+ format_ip4_address, mp->end_addr);
+
+ FINISH;
+}
+
+
/* List of message types that this plugin understands */
#define foreach_snat_plugin_api_msg \
_(SNAT_ADD_ADDRESS_RANGE, snat_add_address_range) \
nat44_interface_output_feature_dump) \
_(NAT44_ADD_DEL_LB_STATIC_MAPPING, nat44_add_del_lb_static_mapping) \
_(NAT44_LB_STATIC_MAPPING_DUMP, nat44_lb_static_mapping_dump) \
+_(NAT44_DEL_SESSION, nat44_del_session) \
_(NAT_DET_ADD_DEL_MAP, nat_det_add_del_map) \
_(NAT_DET_FORWARD, nat_det_forward) \
_(NAT_DET_REVERSE, nat_det_reverse) \
_(NAT64_GET_TIMEOUTS, nat64_get_timeouts) \
_(NAT64_ST_DUMP, nat64_st_dump) \
_(NAT64_ADD_DEL_PREFIX, nat64_add_del_prefix) \
-_(NAT64_PREFIX_DUMP, nat64_prefix_dump)
+_(NAT64_PREFIX_DUMP, nat64_prefix_dump) \
+_(DSLITE_ADD_DEL_POOL_ADDR_RANGE, dslite_add_del_pool_addr_range) \
+_(DSLITE_SET_AFTR_ADDR, dslite_set_aftr_addr)
/* Set up the API message handling tables */
static clib_error_t *