X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat44-ed%2Fnat44_ed_api.c;h=ad00d11052bb1ed21d0c5c7cf9257c1eaf62fd2a;hb=23a15b34e410def81d4bb3e2c8f28f118b59dc5a;hp=e9c11c0ea5b960f1c78bf01ecd5f3c82da966007;hpb=f059a3452c285ec57a75c7b1ede5052244be4e5d;p=vpp.git diff --git a/src/plugins/nat/nat44-ed/nat44_ed_api.c b/src/plugins/nat/nat44-ed/nat44_ed_api.c index e9c11c0ea5b..ad00d11052b 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed_api.c +++ b/src/plugins/nat/nat44-ed/nat44_ed_api.c @@ -426,9 +426,50 @@ vl_api_nat44_interface_dump_t_handler (vl_api_nat44_interface_dump_t * mp) return; pool_foreach (i, sm->interfaces) - { - send_nat44_interface_details(i, reg, mp->context); - } + { + send_nat44_interface_details (i, reg, mp->context); + } +} + +static_always_inline int +add_del_dummy_output_interface (u32 sw_if_index, u8 is_inside, u8 is_add) +{ + snat_main_t *sm = &snat_main; + snat_interface_t *i; + int rv = 1; + + pool_foreach (i, sm->output_feature_dummy_interfaces) + { + if (i->sw_if_index == sw_if_index) + { + if (!is_add) + { + pool_put (sm->output_feature_dummy_interfaces, i); + rv = 0; + } + goto done; + } + } + + if (is_add) + { + pool_get (sm->output_feature_dummy_interfaces, i); + i->sw_if_index = sw_if_index; + + if (is_inside) + { + i->flags |= NAT_INTERFACE_FLAG_IS_INSIDE; + } + else + { + i->flags |= NAT_INTERFACE_FLAG_IS_OUTSIDE; + } + + rv = 0; + } + +done: + return rv; } static void @@ -444,13 +485,20 @@ static void sw_if_index = ntohl (mp->sw_if_index); - if (mp->is_add) - { - rv = nat44_ed_add_output_interface (sw_if_index); - } - else + // register all interfaces in the dummy structure + rv = add_del_dummy_output_interface ( + sw_if_index, mp->flags & NAT_API_IS_INSIDE, mp->is_add); + + if (!(mp->flags & NAT_API_IS_INSIDE)) { - rv = nat44_ed_del_output_interface (sw_if_index); + if (mp->is_add) + { + rv = nat44_ed_add_output_interface (sw_if_index); + } + else + { + rv = nat44_ed_del_output_interface (sw_if_index); + } } BAD_SW_IF_INDEX_LABEL; @@ -473,7 +521,9 @@ send_nat44_interface_output_feature_details (snat_interface_t * i, rmp->context = context; if (nat44_ed_is_interface_inside (i)) - rmp->flags |= NAT_API_IS_INSIDE; + { + rmp->flags |= NAT_API_IS_INSIDE; + } vl_api_send_msg (reg, (u8 *) rmp); } @@ -490,10 +540,80 @@ static void if (!reg) return; - pool_foreach (i, sm->output_feature_interfaces) - { - send_nat44_interface_output_feature_details (i, reg, mp->context); - } + pool_foreach (i, sm->output_feature_dummy_interfaces) + { + send_nat44_interface_output_feature_details (i, reg, mp->context); + } +} + +static void +vl_api_nat44_ed_add_del_output_interface_t_handler ( + vl_api_nat44_ed_add_del_output_interface_t *mp) +{ + vl_api_nat44_ed_add_del_output_interface_reply_t *rmp; + snat_main_t *sm = &snat_main; + u32 sw_if_index; + int rv = 0; + + VALIDATE_SW_IF_INDEX (mp); + + sw_if_index = ntohl (mp->sw_if_index); + + if (mp->is_add) + { + rv = nat44_ed_add_output_interface (sw_if_index); + } + else + { + rv = nat44_ed_del_output_interface (sw_if_index); + } + + BAD_SW_IF_INDEX_LABEL; + REPLY_MACRO (VL_API_NAT44_ED_ADD_DEL_OUTPUT_INTERFACE_REPLY); +} + +#define vl_endianfun +#include +#undef vl_endianfun +static void +send_nat44_ed_output_interface_details (u32 index, vl_api_registration_t *rp, + u32 context) +{ + snat_main_t *sm = &snat_main; + vl_api_nat44_ed_output_interface_details_t *rmp; + snat_interface_t *i = + pool_elt_at_index (sm->output_feature_interfaces, index); + + /* Make sure every field is initiated (or don't skip the clib_memset()) */ + REPLY_MACRO_DETAILS4 ( + VL_API_NAT44_ED_OUTPUT_INTERFACE_DETAILS, rp, context, ({ + rmp->sw_if_index = i->sw_if_index; + + /* Endian hack until apigen registers _details + * endian functions */ + vl_api_nat44_ed_output_interface_details_t_endian (rmp); + rmp->_vl_msg_id = htons (rmp->_vl_msg_id); + rmp->context = htonl (rmp->context); + })); +} + +static void +vl_api_nat44_ed_output_interface_get_t_handler ( + vl_api_nat44_ed_output_interface_get_t *mp) +{ + vl_api_nat44_ed_output_interface_get_reply_t *rmp; + snat_main_t *sm = &snat_main; + i32 rv = 0; + + if (pool_elts (sm->output_feature_interfaces) == 0) + { + REPLY_MACRO (VL_API_NAT44_ED_OUTPUT_INTERFACE_GET_REPLY); + return; + } + + REPLY_AND_DETAILS_MACRO ( + VL_API_NAT44_ED_OUTPUT_INTERFACE_GET_REPLY, sm->output_feature_interfaces, + ({ send_nat44_ed_output_interface_details (cursor, rp, mp->context); })); } static void @@ -1692,14 +1812,13 @@ send_nat44_user_session_v2_details (snat_session_t *s, clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4); clib_memcpy (rmp->inside_ip_address, (&s->in2out.addr), 4); - if (snat_is_session_static (s)) + if (nat44_ed_is_session_static (s)) rmp->flags |= NAT_API_IS_STATIC; - if (is_twice_nat_session (s)) + if (nat44_ed_is_twice_nat_session (s)) rmp->flags |= NAT_API_IS_TWICE_NAT; - if (is_ed_session (s) || is_fwd_bypass_session (s)) - rmp->flags |= NAT_API_IS_EXT_HOST_VALID; + rmp->flags |= NAT_API_IS_EXT_HOST_VALID; rmp->last_heard = clib_host_to_net_u64 ((u64) s->last_heard); rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes); @@ -1717,15 +1836,12 @@ send_nat44_user_session_v2_details (snat_session_t *s, rmp->inside_port = s->in2out.port; rmp->protocol = ntohs (nat_proto_to_ip_proto (s->nat_proto)); } - if (is_ed_session (s) || is_fwd_bypass_session (s)) + clib_memcpy (rmp->ext_host_address, &s->ext_host_addr, 4); + rmp->ext_host_port = s->ext_host_port; + if (nat44_ed_is_twice_nat_session (s)) { - clib_memcpy (rmp->ext_host_address, &s->ext_host_addr, 4); - rmp->ext_host_port = s->ext_host_port; - if (is_twice_nat_session (s)) - { - clib_memcpy (rmp->ext_host_nat_address, &s->ext_host_nat_addr, 4); - rmp->ext_host_nat_port = s->ext_host_nat_port; - } + clib_memcpy (rmp->ext_host_nat_address, &s->ext_host_nat_addr, 4); + rmp->ext_host_nat_port = s->ext_host_nat_port; } sess_timeout_time = s->last_heard + (f64) nat_session_get_timeout (