Code Review
/
vpp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
NAT: Twice NAT44 (VPP-969)
[vpp.git]
/
src
/
plugins
/
nat
/
nat_api.c
diff --git
a/src/plugins/nat/nat_api.c
b/src/plugins/nat/nat_api.c
index
3c58097
..
5071609
100644
(file)
--- a/
src/plugins/nat/nat_api.c
+++ b/
src/plugins/nat/nat_api.c
@@
-435,9
+435,9
@@
static void
for (i = 0; i < count; i++)
{
if (mp->is_add)
for (i = 0; i < count; i++)
{
if (mp->is_add)
- snat_add_address (sm, &this_addr, vrf_id);
+ snat_add_address (sm, &this_addr, vrf_id
, mp->twice_nat
);
else
else
- rv = snat_del_address (sm, this_addr, 0);
+ rv = snat_del_address (sm, this_addr, 0
, mp->twice_nat
);
if (rv)
goto send_reply;
if (rv)
goto send_reply;
@@
-460,12
+460,14
@@
static void *vl_api_nat44_add_del_address_range_t_print
{
s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
}
{
s = format (s, " - %U ", format_ip4_address, mp->last_ip_address);
}
+ s = format (s, "twice_nat %d ", mp->twice_nat);
FINISH;
}
static void
send_nat44_address_details (snat_address_t * a,
FINISH;
}
static void
send_nat44_address_details (snat_address_t * a,
- unix_shared_memory_queue_t * q, u32 context)
+ unix_shared_memory_queue_t * q, u32 context,
+ u8 twice_nat)
{
vl_api_nat44_address_details_t *rmp;
snat_main_t *sm = &snat_main;
{
vl_api_nat44_address_details_t *rmp;
snat_main_t *sm = &snat_main;
@@
-481,6
+483,7
@@
send_nat44_address_details (snat_address_t * a,
}
else
rmp->vrf_id = ~0;
}
else
rmp->vrf_id = ~0;
+ rmp->twice_nat = twice_nat;
rmp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
rmp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
@@
-499,7
+502,9
@@
vl_api_nat44_address_dump_t_handler (vl_api_nat44_address_dump_t * mp)
/* *INDENT-OFF* */
vec_foreach (a, sm->addresses)
/* *INDENT-OFF* */
vec_foreach (a, sm->addresses)
- send_nat44_address_details (a, q, mp->context);
+ send_nat44_address_details (a, q, mp->context, 0);
+ vec_foreach (a, sm->twice_nat_addresses)
+ send_nat44_address_details (a, q, mp->context, 1);
/* *INDENT-ON* */
}
/* *INDENT-ON* */
}
@@
-702,7
+707,8
@@
static void
rv = snat_add_static_mapping (local_addr, external_addr, local_port,
external_port, vrf_id, mp->addr_only,
rv = snat_add_static_mapping (local_addr, external_addr, local_port,
external_port, vrf_id, mp->addr_only,
- external_sw_if_index, proto, mp->is_add);
+ external_sw_if_index, proto, mp->is_add,
+ mp->twice_nat);
REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY);
}
REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY);
}
@@
-723,6
+729,8
@@
static void *vl_api_nat44_add_del_static_mapping_t_print
clib_net_to_host_u16 (mp->local_port),
clib_net_to_host_u16 (mp->external_port));
clib_net_to_host_u16 (mp->local_port),
clib_net_to_host_u16 (mp->external_port));
+ s = format (s, "twice_nat %d ", mp->twice_nat);
+
if (mp->vrf_id != ~0)
s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
if (mp->vrf_id != ~0)
s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id));
@@
-753,6
+761,7
@@
send_nat44_static_mapping_details (snat_static_mapping_t * m,
rmp->vrf_id = htonl (m->vrf_id);
rmp->protocol = snat_proto_to_ip_proto (m->proto);
rmp->context = context;
rmp->vrf_id = htonl (m->vrf_id);
rmp->protocol = snat_proto_to_ip_proto (m->proto);
rmp->context = context;
+ rmp->twice_nat = m->twice_nat;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
@@
-777,6
+786,7
@@
send_nat44_static_map_resolve_details (snat_static_map_resolve_t * m,
rmp->vrf_id = htonl (m->vrf_id);
rmp->protocol = snat_proto_to_ip_proto (m->proto);
rmp->context = context;
rmp->vrf_id = htonl (m->vrf_id);
rmp->protocol = snat_proto_to_ip_proto (m->proto);
rmp->context = context;
+ rmp->twice_nat = m->twice_nat;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
vl_msg_api_send_shmem (q, (u8 *) & rmp);
}
@@
-849,7
+859,7
@@
static void
rv =
snat_add_static_mapping (addr, addr, port, port, vrf_id, mp->addr_only,
rv =
snat_add_static_mapping (addr, addr, port, port, vrf_id, mp->addr_only,
- sw_if_index, proto, mp->is_add);
+ sw_if_index, proto, mp->is_add
, 0
);
REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY);
}
REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY);
}
@@
-973,7
+983,7
@@
static void
VALIDATE_SW_IF_INDEX (mp);
VALIDATE_SW_IF_INDEX (mp);
- rv = snat_add_interface_address (sm, sw_if_index, is_del);
+ rv = snat_add_interface_address (sm, sw_if_index, is_del
, mp->twice_nat
);
BAD_SW_IF_INDEX_LABEL;
BAD_SW_IF_INDEX_LABEL;
@@
-986,9
+996,9
@@
static void *vl_api_nat44_add_del_interface_addr_t_print
u8 *s;
s = format (0, "SCRIPT: nat44_add_del_interface_addr ");
u8 *s;
s = format (0, "SCRIPT: nat44_add_del_interface_addr ");
- s = format (s, "sw_if_index %d %s",
+ s = format (s, "sw_if_index %d
twice_nat %d
%s",
clib_host_to_net_u32 (mp->sw_if_index),
clib_host_to_net_u32 (mp->sw_if_index),
- mp->is_add ? "" : "del");
+ mp->
twice_nat, mp->
is_add ? "" : "del");
FINISH;
}
FINISH;
}
@@
-996,7
+1006,7
@@
static void *vl_api_nat44_add_del_interface_addr_t_print
static void
send_nat44_interface_addr_details (u32 sw_if_index,
unix_shared_memory_queue_t * q,
static void
send_nat44_interface_addr_details (u32 sw_if_index,
unix_shared_memory_queue_t * q,
- u32 context)
+ u32 context
, u8 twice_nat
)
{
vl_api_nat44_interface_addr_details_t *rmp;
snat_main_t *sm = &snat_main;
{
vl_api_nat44_interface_addr_details_t *rmp;
snat_main_t *sm = &snat_main;
@@
-1006,6
+1016,7
@@
send_nat44_interface_addr_details (u32 sw_if_index,
rmp->_vl_msg_id =
ntohs (VL_API_NAT44_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (sw_if_index);
rmp->_vl_msg_id =
ntohs (VL_API_NAT44_INTERFACE_ADDR_DETAILS + sm->msg_id_base);
rmp->sw_if_index = ntohl (sw_if_index);
+ rmp->twice_nat = twice_nat;
rmp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
rmp->context = context;
vl_msg_api_send_shmem (q, (u8 *) & rmp);
@@
-1025,7
+1036,9
@@
vl_api_nat44_interface_addr_dump_t_handler (vl_api_nat44_interface_addr_dump_t
/* *INDENT-OFF* */
vec_foreach (i, sm->auto_add_sw_if_indices)
/* *INDENT-OFF* */
vec_foreach (i, sm->auto_add_sw_if_indices)
- send_nat44_interface_addr_details(*i, q, mp->context);
+ send_nat44_interface_addr_details(*i, q, mp->context, 0);
+ vec_foreach (i, sm->auto_add_sw_if_indices_twice_nat)
+ send_nat44_interface_addr_details(*i, q, mp->context, 1);
/* *INDENT-ON* */
}
/* *INDENT-ON* */
}
@@
-1231,7
+1244,7
@@
static void
nat44_add_del_lb_static_mapping (e_addr,
clib_net_to_host_u16 (mp->external_port),
proto, clib_net_to_host_u32 (mp->vrf_id),
nat44_add_del_lb_static_mapping (e_addr,
clib_net_to_host_u16 (mp->external_port),
proto, clib_net_to_host_u32 (mp->vrf_id),
- locals, mp->is_add);
+ locals, mp->is_add
, mp->twice_nat
);
vec_free (locals);
vec_free (locals);
@@
-1244,7
+1257,7
@@
static void *vl_api_nat44_add_del_lb_static_mapping_t_print
u8 *s;
s = format (0, "SCRIPT: nat44_add_del_lb_static_mapping ");
u8 *s;
s = format (0, "SCRIPT: nat44_add_del_lb_static_mapping ");
- s = format (s, "is_add %d
\n", mp->is_add
);
+ s = format (s, "is_add %d
twice_nat %d", mp->is_add, mp->twice_nat
);
FINISH;
}
FINISH;
}
@@
-1271,6
+1284,7
@@
send_nat44_lb_static_mapping_details (snat_static_mapping_t * m,
rmp->protocol = snat_proto_to_ip_proto (m->proto);
rmp->vrf_id = ntohl (m->vrf_id);
rmp->context = context;
rmp->protocol = snat_proto_to_ip_proto (m->proto);
rmp->vrf_id = ntohl (m->vrf_id);
rmp->context = context;
+ rmp->twice_nat = m->twice_nat;
locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
vec_foreach (ap, m->locals)
locals = (vl_api_nat44_lb_addr_port_t *) rmp->locals;
vec_foreach (ap, m->locals)
@@
-1776,7
+1790,6
@@
static void
{
vl_api_nat64_add_del_pool_addr_range_reply_t *rmp;
snat_main_t *sm = &snat_main;
{
vl_api_nat64_add_del_pool_addr_range_reply_t *rmp;
snat_main_t *sm = &snat_main;
- nat64_main_t *nm = &nat64_main;
int rv = 0;
ip4_address_t this_addr;
u32 start_host_order, end_host_order;
int rv = 0;
ip4_address_t this_addr;
u32 start_host_order, end_host_order;
@@
-1784,12
+1797,6
@@
static void
int i, count;
u32 *tmp;
int i, count;
u32 *tmp;
- if (nm->is_disabled)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto send_reply;
- }
-
tmp = (u32 *) mp->start_addr;
start_host_order = clib_host_to_net_u32 (tmp[0]);
tmp = (u32 *) mp->end_addr;
tmp = (u32 *) mp->start_addr;
start_host_order = clib_host_to_net_u32 (tmp[0]);
tmp = (u32 *) mp->end_addr;
@@
-1831,6
+1838,7
@@
typedef struct nat64_api_walk_ctx_t_
{
unix_shared_memory_queue_t *q;
u32 context;
{
unix_shared_memory_queue_t *q;
u32 context;
+ nat64_db_t *db;
} nat64_api_walk_ctx_t;
static int
} nat64_api_walk_ctx_t;
static int
@@
-1864,10
+1872,6
@@
static void
vl_api_nat64_pool_addr_dump_t_handler (vl_api_nat64_pool_addr_dump_t * mp)
{
unix_shared_memory_queue_t *q;
vl_api_nat64_pool_addr_dump_t_handler (vl_api_nat64_pool_addr_dump_t * mp)
{
unix_shared_memory_queue_t *q;
- nat64_main_t *nm = &nat64_main;
-
- if (nm->is_disabled)
- return;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
@@
-1897,16
+1901,9
@@
vl_api_nat64_add_del_interface_t_handler (vl_api_nat64_add_del_interface_t *
mp)
{
snat_main_t *sm = &snat_main;
mp)
{
snat_main_t *sm = &snat_main;
- nat64_main_t *nm = &nat64_main;
vl_api_nat64_add_del_interface_reply_t *rmp;
int rv = 0;
vl_api_nat64_add_del_interface_reply_t *rmp;
int rv = 0;
- if (nm->is_disabled)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto send_reply;
- }
-
VALIDATE_SW_IF_INDEX (mp);
rv =
VALIDATE_SW_IF_INDEX (mp);
rv =
@@
-1915,7
+1912,6
@@
vl_api_nat64_add_del_interface_t_handler (vl_api_nat64_add_del_interface_t *
BAD_SW_IF_INDEX_LABEL;
BAD_SW_IF_INDEX_LABEL;
-send_reply:
REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_REPLY);
}
REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_REPLY);
}
@@
-1958,10
+1954,6
@@
static void
vl_api_nat64_interface_dump_t_handler (vl_api_nat64_interface_dump_t * mp)
{
unix_shared_memory_queue_t *q;
vl_api_nat64_interface_dump_t_handler (vl_api_nat64_interface_dump_t * mp)
{
unix_shared_memory_queue_t *q;
- nat64_main_t *nm = &nat64_main;
-
- if (nm->is_disabled)
- return;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
@@
-1991,18
+1983,11
@@
static void
(vl_api_nat64_add_del_static_bib_t * mp)
{
snat_main_t *sm = &snat_main;
(vl_api_nat64_add_del_static_bib_t * mp)
{
snat_main_t *sm = &snat_main;
- nat64_main_t *nm = &nat64_main;
vl_api_nat64_add_del_static_bib_reply_t *rmp;
ip6_address_t in_addr;
ip4_address_t out_addr;
int rv = 0;
vl_api_nat64_add_del_static_bib_reply_t *rmp;
ip6_address_t in_addr;
ip4_address_t out_addr;
int rv = 0;
- if (nm->is_disabled)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto send_reply;
- }
-
memcpy (&in_addr.as_u8, mp->i_addr, 16);
memcpy (&out_addr.as_u8, mp->o_addr, 4);
memcpy (&in_addr.as_u8, mp->i_addr, 16);
memcpy (&out_addr.as_u8, mp->o_addr, 4);
@@
-2014,7
+1999,6
@@
static void
clib_net_to_host_u32 (mp->vrf_id),
mp->is_add);
clib_net_to_host_u32 (mp->vrf_id),
mp->is_add);
-send_reply:
REPLY_MACRO (VL_API_NAT64_ADD_DEL_STATIC_BIB_REPLY);
}
REPLY_MACRO (VL_API_NAT64_ADD_DEL_STATIC_BIB_REPLY);
}
@@
-2069,9
+2053,7
@@
vl_api_nat64_bib_dump_t_handler (vl_api_nat64_bib_dump_t * mp)
{
unix_shared_memory_queue_t *q;
nat64_main_t *nm = &nat64_main;
{
unix_shared_memory_queue_t *q;
nat64_main_t *nm = &nat64_main;
-
- if (nm->is_disabled)
- return;
+ nat64_db_t *db;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
@@
-2082,7
+2064,10
@@
vl_api_nat64_bib_dump_t_handler (vl_api_nat64_bib_dump_t * mp)
.context = mp->context,
};
.context = mp->context,
};
- nat64_db_bib_walk (&nm->db, mp->proto, nat64_api_bib_walk, &ctx);
+ /* *INDENT-OFF* */
+ vec_foreach (db, nm->db)
+ nat64_db_bib_walk (db, mp->proto, nat64_api_bib_walk, &ctx);
+ /* *INDENT-ON* */
}
static void *
}
static void *
@@
-2099,16
+2084,9
@@
static void
vl_api_nat64_set_timeouts_t_handler (vl_api_nat64_set_timeouts_t * mp)
{
snat_main_t *sm = &snat_main;
vl_api_nat64_set_timeouts_t_handler (vl_api_nat64_set_timeouts_t * mp)
{
snat_main_t *sm = &snat_main;
- nat64_main_t *nm = &nat64_main;
vl_api_nat64_set_timeouts_reply_t *rmp;
int rv = 0;
vl_api_nat64_set_timeouts_reply_t *rmp;
int rv = 0;
- if (nm->is_disabled)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto send_reply;
- }
-
rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
if (rv)
goto send_reply;
rv = nat64_set_icmp_timeout (ntohl (mp->icmp));
if (rv)
goto send_reply;
@@
-2142,13
+2120,9
@@
static void
vl_api_nat64_get_timeouts_t_handler (vl_api_nat64_get_timeouts_t * mp)
{
snat_main_t *sm = &snat_main;
vl_api_nat64_get_timeouts_t_handler (vl_api_nat64_get_timeouts_t * mp)
{
snat_main_t *sm = &snat_main;
- nat64_main_t *nm = &nat64_main;
vl_api_nat64_get_timeouts_reply_t *rmp;
int rv = 0;
vl_api_nat64_get_timeouts_reply_t *rmp;
int rv = 0;
- if (nm->is_disabled)
- return;
-
/* *INDENT-OFF* */
REPLY_MACRO2 (VL_API_NAT64_GET_TIMEOUTS_REPLY,
({
/* *INDENT-OFF* */
REPLY_MACRO2 (VL_API_NAT64_GET_TIMEOUTS_REPLY,
({
@@
-2177,11
+2151,10
@@
nat64_api_st_walk (nat64_db_st_entry_t * ste, void *arg)
vl_api_nat64_st_details_t *rmp;
snat_main_t *sm = &snat_main;
nat64_api_walk_ctx_t *ctx = arg;
vl_api_nat64_st_details_t *rmp;
snat_main_t *sm = &snat_main;
nat64_api_walk_ctx_t *ctx = arg;
- nat64_main_t *nm = &nat64_main;
nat64_db_bib_entry_t *bibe;
fib_table_t *fib;
nat64_db_bib_entry_t *bibe;
fib_table_t *fib;
- bibe = nat64_db_bib_entry_by_index (
&nm
->db, ste->proto, ste->bibe_index);
+ bibe = nat64_db_bib_entry_by_index (
ctx
->db, ste->proto, ste->bibe_index);
if (!bibe)
return -1;
if (!bibe)
return -1;
@@
-2213,9
+2186,7
@@
vl_api_nat64_st_dump_t_handler (vl_api_nat64_st_dump_t * mp)
{
unix_shared_memory_queue_t *q;
nat64_main_t *nm = &nat64_main;
{
unix_shared_memory_queue_t *q;
nat64_main_t *nm = &nat64_main;
-
- if (nm->is_disabled)
- return;
+ nat64_db_t *db;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
@@
-2226,7
+2197,13
@@
vl_api_nat64_st_dump_t_handler (vl_api_nat64_st_dump_t * mp)
.context = mp->context,
};
.context = mp->context,
};
- nat64_db_st_walk (&nm->db, mp->proto, nat64_api_st_walk, &ctx);
+ /* *INDENT-OFF* */
+ vec_foreach (db, nm->db)
+ {
+ ctx.db = db;
+ nat64_db_st_walk (db, mp->proto, nat64_api_st_walk, &ctx);
+ }
+ /* *INDENT-ON* */
}
static void *
}
static void *
@@
-2244,22
+2221,14
@@
vl_api_nat64_add_del_prefix_t_handler (vl_api_nat64_add_del_prefix_t * mp)
{
vl_api_nat64_add_del_prefix_reply_t *rmp;
snat_main_t *sm = &snat_main;
{
vl_api_nat64_add_del_prefix_reply_t *rmp;
snat_main_t *sm = &snat_main;
- nat64_main_t *nm = &nat64_main;
ip6_address_t prefix;
int rv = 0;
ip6_address_t prefix;
int rv = 0;
- if (nm->is_disabled)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto send_reply;
- }
-
memcpy (&prefix.as_u8, mp->prefix, 16);
rv =
nat64_add_del_prefix (&prefix, mp->prefix_len,
clib_net_to_host_u32 (mp->vrf_id), mp->is_add);
memcpy (&prefix.as_u8, mp->prefix, 16);
rv =
nat64_add_del_prefix (&prefix, mp->prefix_len,
clib_net_to_host_u32 (mp->vrf_id), mp->is_add);
-send_reply:
REPLY_MACRO (VL_API_NAT64_ADD_DEL_PREFIX_REPLY);
}
REPLY_MACRO (VL_API_NAT64_ADD_DEL_PREFIX_REPLY);
}
@@
-2300,10
+2269,6
@@
static void
vl_api_nat64_prefix_dump_t_handler (vl_api_nat64_prefix_dump_t * mp)
{
unix_shared_memory_queue_t *q;
vl_api_nat64_prefix_dump_t_handler (vl_api_nat64_prefix_dump_t * mp)
{
unix_shared_memory_queue_t *q;
- nat64_main_t *nm = &nat64_main;
-
- if (nm->is_disabled)
- return;
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
q = vl_api_client_index_to_input_queue (mp->client_index);
if (q == 0)
@@
-2332,24
+2297,17
@@
static void
vl_api_nat64_add_del_interface_addr_t_handler
(vl_api_nat64_add_del_interface_addr_t * mp)
{
vl_api_nat64_add_del_interface_addr_t_handler
(vl_api_nat64_add_del_interface_addr_t * mp)
{
- nat64_main_t *nm = &nat64_main;
snat_main_t *sm = &snat_main;
vl_api_nat64_add_del_interface_addr_reply_t *rmp;
u32 sw_if_index = ntohl (mp->sw_if_index);
int rv = 0;
snat_main_t *sm = &snat_main;
vl_api_nat64_add_del_interface_addr_reply_t *rmp;
u32 sw_if_index = ntohl (mp->sw_if_index);
int rv = 0;
- if (nm->is_disabled)
- {
- rv = VNET_API_ERROR_FEATURE_DISABLED;
- goto send_reply;
- }
-
VALIDATE_SW_IF_INDEX (mp);
rv = nat64_add_interface_address (sw_if_index, mp->is_add);
BAD_SW_IF_INDEX_LABEL;
VALIDATE_SW_IF_INDEX (mp);
rv = nat64_add_interface_address (sw_if_index, mp->is_add);
BAD_SW_IF_INDEX_LABEL;
-send_reply:
+
REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_ADDR_REPLY);
}
REPLY_MACRO (VL_API_NAT64_ADD_DEL_INTERFACE_ADDR_REPLY);
}