X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat44-ed%2Fnat44_ed_api.c;h=e9c11c0ea5b960f1c78bf01ecd5f3c82da966007;hb=f059a3452;hp=22737ad7e56bfa91c7332b59c572f8bdc470e86d;hpb=3a5bd85476311d4ad2b0cbbca3f98d53f13a3afb;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 22737ad7e56..e9c11c0ea5b 100644 --- a/src/plugins/nat/nat44-ed/nat44_ed_api.c +++ b/src/plugins/nat/nat44-ed/nat44_ed_api.c @@ -303,9 +303,13 @@ static void for (i = 0; i < count; i++) { if (is_add) - rv = snat_add_address (sm, &this_addr, vrf_id, twice_nat); + { + rv = nat44_ed_add_address (&this_addr, vrf_id, twice_nat); + } else - rv = snat_del_address (sm, this_addr, 0, twice_nat); + { + rv = nat44_ed_del_address (this_addr, 0, twice_nat); + } if (rv) goto send_reply; @@ -364,22 +368,27 @@ static void vl_api_nat44_interface_add_del_feature_t_handler (vl_api_nat44_interface_add_del_feature_t * mp) { - snat_main_t *sm = &snat_main; vl_api_nat44_interface_add_del_feature_reply_t *rmp; - u32 sw_if_index = ntohl (mp->sw_if_index); - u8 is_del; + snat_main_t *sm = &snat_main; + u32 sw_if_index; + u8 is_inside; int rv = 0; - is_del = !mp->is_add; - VALIDATE_SW_IF_INDEX (mp); - rv = - snat_interface_add_del (sw_if_index, mp->flags & NAT_API_IS_INSIDE, - is_del); + is_inside = mp->flags & NAT_API_IS_INSIDE; + sw_if_index = ntohl (mp->sw_if_index); - BAD_SW_IF_INDEX_LABEL; + if (mp->is_add) + { + rv = nat44_ed_add_interface (sw_if_index, is_inside); + } + else + { + rv = nat44_ed_del_interface (sw_if_index, is_inside); + } + BAD_SW_IF_INDEX_LABEL; REPLY_MACRO (VL_API_NAT44_INTERFACE_ADD_DEL_FEATURE_REPLY); } @@ -395,9 +404,9 @@ send_nat44_interface_details (snat_interface_t * i, rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_DETAILS + sm->msg_id_base); rmp->sw_if_index = ntohl (i->sw_if_index); - if (nat_interface_is_inside (i)) + if (nat44_ed_is_interface_inside (i)) rmp->flags |= NAT_API_IS_INSIDE; - if (nat_interface_is_outside (i)) + if (nat44_ed_is_interface_outside (i)) rmp->flags |= NAT_API_IS_OUTSIDE; rmp->context = context; @@ -426,16 +435,23 @@ static void vl_api_nat44_interface_add_del_output_feature_t_handler (vl_api_nat44_interface_add_del_output_feature_t * mp) { - snat_main_t *sm = &snat_main; vl_api_nat44_interface_add_del_output_feature_reply_t *rmp; - u32 sw_if_index = ntohl (mp->sw_if_index); + snat_main_t *sm = &snat_main; + u32 sw_if_index; int rv = 0; VALIDATE_SW_IF_INDEX (mp); - rv = snat_interface_add_del_output_feature (sw_if_index, - mp->flags & NAT_API_IS_INSIDE, - !mp->is_add); + 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_INTERFACE_ADD_DEL_OUTPUT_FEATURE_REPLY); @@ -456,7 +472,7 @@ send_nat44_interface_output_feature_details (snat_interface_t * i, rmp->sw_if_index = ntohl (i->sw_if_index); rmp->context = context; - if (nat_interface_is_inside (i)) + if (nat44_ed_is_interface_inside (i)) rmp->flags |= NAT_API_IS_INSIDE; vl_api_send_msg (reg, (u8 *) rmp); @@ -484,43 +500,73 @@ static void vl_api_nat44_add_del_static_mapping_t_handler (vl_api_nat44_add_del_static_mapping_t * mp) { - snat_main_t *sm = &snat_main; vl_api_nat44_add_del_static_mapping_reply_t *rmp; - ip4_address_t local_addr, external_addr, pool_addr = { 0 }; - u16 local_port = 0, external_port = 0; - u32 vrf_id, external_sw_if_index; - twice_nat_type_t twice_nat = TWICE_NAT_DISABLED; + + snat_main_t *sm = &snat_main; int rv = 0; - nat_protocol_t proto; + + ip4_address_t l_addr, e_addr, pool_addr = { 0 }; + u32 sw_if_index, flags = 0, vrf_id; + u16 l_port = 0, e_port = 0; + nat_protocol_t proto = 0; u8 *tag = 0; - memcpy (&local_addr.as_u8, mp->local_ip_address, 4); - memcpy (&external_addr.as_u8, mp->external_ip_address, 4); + memcpy (&l_addr.as_u8, mp->local_ip_address, 4); - if (!(mp->flags & NAT_API_IS_ADDR_ONLY)) + if (mp->flags & NAT_API_IS_ADDR_ONLY) { - local_port = mp->local_port; - external_port = mp->external_port; + flags |= NAT_SM_FLAG_ADDR_ONLY; + } + else + { + l_port = mp->local_port; + e_port = mp->external_port; + proto = ip_proto_to_nat_proto (mp->protocol); } - - vrf_id = clib_net_to_host_u32 (mp->vrf_id); - external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index); - proto = ip_proto_to_nat_proto (mp->protocol); if (mp->flags & NAT_API_IS_TWICE_NAT) - twice_nat = TWICE_NAT; - else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT) - twice_nat = TWICE_NAT_SELF; - mp->tag[sizeof (mp->tag) - 1] = 0; - tag = format (0, "%s", mp->tag); - vec_terminate_c_string (tag); - - rv = snat_add_static_mapping ( - local_addr, external_addr, local_port, external_port, vrf_id, - mp->flags & NAT_API_IS_ADDR_ONLY, external_sw_if_index, proto, mp->is_add, - twice_nat, mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, 0, pool_addr, 0); - vec_free (tag); + { + flags |= NAT_SM_FLAG_TWICE_NAT; + } + + if (mp->flags & NAT_API_IS_SELF_TWICE_NAT) + { + flags |= NAT_SM_FLAG_SELF_TWICE_NAT; + } + + if (mp->flags & NAT_API_IS_OUT2IN_ONLY) + { + flags |= NAT_SM_FLAG_OUT2IN_ONLY; + } + + sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index); + if (sw_if_index != ~0) + { + flags |= NAT_SM_FLAG_SWITCH_ADDRESS; + } + else + { + memcpy (&e_addr.as_u8, mp->external_ip_address, 4); + } + vrf_id = clib_net_to_host_u32 (mp->vrf_id); + + if (mp->is_add) + { + mp->tag[sizeof (mp->tag) - 1] = 0; + tag = format (0, "%s", mp->tag); + vec_terminate_c_string (tag); + + rv = nat44_ed_add_static_mapping (l_addr, e_addr, l_port, e_port, proto, + vrf_id, sw_if_index, flags, pool_addr, + tag); + vec_free (tag); + } + else + { + rv = nat44_ed_del_static_mapping (l_addr, e_addr, l_port, e_port, proto, + vrf_id, sw_if_index, flags); + } REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_REPLY); } @@ -528,47 +574,79 @@ static void vl_api_nat44_add_del_static_mapping_v2_t_handler (vl_api_nat44_add_del_static_mapping_v2_t * mp) { - snat_main_t *sm = &snat_main; vl_api_nat44_add_del_static_mapping_v2_reply_t *rmp; - ip4_address_t local_addr, external_addr, pool_addr; - u16 local_port = 0, external_port = 0; - u32 vrf_id, external_sw_if_index; - twice_nat_type_t twice_nat = TWICE_NAT_DISABLED; + + snat_main_t *sm = &snat_main; int rv = 0; + + ip4_address_t l_addr, e_addr, pool_addr; + u32 sw_if_index, flags = 0, vrf_id; + u16 l_port = 0, e_port = 0; nat_protocol_t proto; u8 *tag = 0; + memcpy (&l_addr.as_u8, mp->local_ip_address, 4); memcpy (&pool_addr.as_u8, mp->pool_ip_address, 4); - memcpy (&local_addr.as_u8, mp->local_ip_address, 4); - memcpy (&external_addr.as_u8, mp->external_ip_address, 4); - if (!(mp->flags & NAT_API_IS_ADDR_ONLY)) + if (pool_addr.as_u32 != 0) { - local_port = mp->local_port; - external_port = mp->external_port; + flags |= NAT_SM_FLAG_EXACT_ADDRESS; } - vrf_id = clib_net_to_host_u32 (mp->vrf_id); - external_sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index); - proto = ip_proto_to_nat_proto (mp->protocol); + if (mp->flags & NAT_API_IS_ADDR_ONLY) + { + flags |= NAT_SM_FLAG_ADDR_ONLY; + } + else + { + l_port = mp->local_port; + e_port = mp->external_port; + } if (mp->flags & NAT_API_IS_TWICE_NAT) - twice_nat = TWICE_NAT; - else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT) - twice_nat = TWICE_NAT_SELF; - mp->tag[sizeof (mp->tag) - 1] = 0; - tag = format (0, "%s", mp->tag); - vec_terminate_c_string (tag); - - rv = snat_add_static_mapping (local_addr, external_addr, local_port, - external_port, vrf_id, - mp->flags & NAT_API_IS_ADDR_ONLY, - external_sw_if_index, proto, - mp->is_add, twice_nat, - mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, 0, - pool_addr, mp->match_pool); - vec_free (tag); + { + flags |= NAT_SM_FLAG_TWICE_NAT; + } + + if (mp->flags & NAT_API_IS_SELF_TWICE_NAT) + { + flags |= NAT_SM_FLAG_SELF_TWICE_NAT; + } + + if (mp->flags & NAT_API_IS_OUT2IN_ONLY) + { + flags |= NAT_SM_FLAG_OUT2IN_ONLY; + } + sw_if_index = clib_net_to_host_u32 (mp->external_sw_if_index); + if (sw_if_index) + { + flags |= NAT_SM_FLAG_SWITCH_ADDRESS; + } + else + { + memcpy (&e_addr.as_u8, mp->external_ip_address, 4); + } + + proto = ip_proto_to_nat_proto (mp->protocol); + vrf_id = clib_net_to_host_u32 (mp->vrf_id); + + if (mp->is_add) + { + mp->tag[sizeof (mp->tag) - 1] = 0; + tag = format (0, "%s", mp->tag); + vec_terminate_c_string (tag); + + rv = nat44_ed_add_static_mapping (l_addr, e_addr, l_port, e_port, proto, + vrf_id, sw_if_index, flags, pool_addr, + tag); + vec_free (tag); + } + else + { + rv = nat44_ed_del_static_mapping (l_addr, e_addr, l_port, e_port, proto, + vrf_id, sw_if_index, flags); + } REPLY_MACRO (VL_API_NAT44_ADD_DEL_STATIC_MAPPING_V2_REPLY); } @@ -591,15 +669,24 @@ send_nat44_static_mapping_details (snat_static_mapping_t * m, rmp->vrf_id = htonl (m->vrf_id); rmp->context = context; - if (m->twice_nat == TWICE_NAT) - rmp->flags |= NAT_API_IS_TWICE_NAT; - else if (m->twice_nat == TWICE_NAT_SELF) - rmp->flags |= NAT_API_IS_SELF_TWICE_NAT; + // convert these in new api + + if (is_sm_self_twice_nat (m->flags)) + { + rmp->flags |= NAT_API_IS_SELF_TWICE_NAT; + } + + if (is_sm_out2in_only (m->flags)) + { + rmp->flags |= NAT_API_IS_OUT2IN_ONLY; + } - if (is_out2in_only_static_mapping (m)) - rmp->flags |= NAT_API_IS_OUT2IN_ONLY; + if (is_sm_twice_nat (m->flags)) + { + rmp->flags |= NAT_API_IS_TWICE_NAT; + } - if (is_addr_only_static_mapping (m)) + if (is_sm_addr_only (m->flags)) { rmp->flags |= NAT_API_IS_ADDR_ONLY; } @@ -668,8 +755,8 @@ vl_api_nat44_static_mapping_dump_t_handler (vl_api_nat44_static_mapping_dump_t pool_foreach (m, sm->static_mappings) { - if (!is_identity_static_mapping(m) && !is_lb_static_mapping (m)) - send_nat44_static_mapping_details (m, reg, mp->context); + if (!is_sm_identity_nat (m->flags) && !is_sm_lb (m->flags)) + send_nat44_static_mapping_details (m, reg, mp->context); } for (j = 0; j < vec_len (sm->to_resolve); j++) @@ -684,36 +771,56 @@ static void vl_api_nat44_add_del_identity_mapping_t_handler (vl_api_nat44_add_del_identity_mapping_t * mp) { - snat_main_t *sm = &snat_main; vl_api_nat44_add_del_identity_mapping_reply_t *rmp; + + snat_main_t *sm = &snat_main; + int rv = 0; + ip4_address_t addr, pool_addr = { 0 }; + u32 sw_if_index, flags, vrf_id; + nat_protocol_t proto = 0; u16 port = 0; - u32 vrf_id, sw_if_index; - int rv = 0; - nat_protocol_t proto = NAT_PROTOCOL_OTHER; u8 *tag = 0; - if (!(mp->flags & NAT_API_IS_ADDR_ONLY)) + flags = NAT_SM_FLAG_IDENTITY_NAT; + + if (mp->flags & NAT_API_IS_ADDR_ONLY) + { + flags |= NAT_SM_FLAG_ADDR_ONLY; + } + else { port = mp->port; proto = ip_proto_to_nat_proto (mp->protocol); } - vrf_id = clib_net_to_host_u32 (mp->vrf_id); + sw_if_index = clib_net_to_host_u32 (mp->sw_if_index); if (sw_if_index != ~0) - addr.as_u32 = 0; + { + flags |= NAT_SM_FLAG_SWITCH_ADDRESS; + } else - memcpy (&addr.as_u8, mp->ip_address, 4); - mp->tag[sizeof (mp->tag) - 1] = 0; - tag = format (0, "%s", mp->tag); - vec_terminate_c_string (tag); - - rv = - snat_add_static_mapping (addr, addr, port, port, vrf_id, - mp->flags & NAT_API_IS_ADDR_ONLY, sw_if_index, - proto, mp->is_add, 0, 0, tag, 1, pool_addr, 0); - vec_free (tag); + { + memcpy (&addr.as_u8, mp->ip_address, 4); + } + vrf_id = clib_net_to_host_u32 (mp->vrf_id); + + if (mp->is_add) + { + mp->tag[sizeof (mp->tag) - 1] = 0; + tag = format (0, "%s", mp->tag); + vec_terminate_c_string (tag); + + rv = nat44_ed_add_static_mapping (addr, addr, port, port, proto, vrf_id, + sw_if_index, flags, pool_addr, tag); + vec_free (tag); + } + else + { + rv = nat44_ed_del_static_mapping (addr, addr, port, port, proto, vrf_id, + sw_if_index, flags); + } REPLY_MACRO (VL_API_NAT44_ADD_DEL_IDENTITY_MAPPING_REPLY); } @@ -730,7 +837,7 @@ send_nat44_identity_mapping_details (snat_static_mapping_t * m, int index, rmp->_vl_msg_id = ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base); - if (is_addr_only_static_mapping (m)) + if (is_sm_addr_only (m->flags)) rmp->flags |= NAT_API_IS_ADDR_ONLY; clib_memcpy (rmp->ip_address, &(m->local_addr), 4); @@ -787,15 +894,15 @@ static void return; pool_foreach (m, sm->static_mappings) - { - if (is_identity_static_mapping(m) && !is_lb_static_mapping (m)) - { - pool_foreach_index (j, m->locals) - { - send_nat44_identity_mapping_details (m, j, reg, mp->context); - } - } - } + { + if (is_sm_identity_nat (m->flags) && !is_sm_lb (m->flags)) + { + pool_foreach_index (j, m->locals) + { + send_nat44_identity_mapping_details (m, j, reg, mp->context); + } + } + } for (j = 0; j < vec_len (sm->to_resolve); j++) { @@ -812,8 +919,8 @@ static void snat_main_t *sm = &snat_main; vl_api_nat44_add_del_interface_addr_reply_t *rmp; u32 sw_if_index = ntohl (mp->sw_if_index); + u8 twice_nat; int rv = 0; - u8 is_del; if (sm->static_mapping_only) { @@ -821,12 +928,18 @@ static void goto send_reply; } - is_del = !mp->is_add; - VALIDATE_SW_IF_INDEX (mp); - rv = snat_add_interface_address (sm, sw_if_index, is_del, - mp->flags & NAT_API_IS_TWICE_NAT); + twice_nat = mp->flags & NAT_API_IS_TWICE_NAT; + + if (mp->is_add) + { + rv = nat44_ed_add_interface_address (sw_if_index, twice_nat); + } + else + { + rv = nat44_ed_del_interface_address (sw_if_index, twice_nat); + } BAD_SW_IF_INDEX_LABEL; @@ -905,12 +1018,12 @@ vl_api_nat44_add_del_lb_static_mapping_t_handler ( { snat_main_t *sm = &snat_main; vl_api_nat44_add_del_lb_static_mapping_reply_t *rmp; - twice_nat_type_t twice_nat = TWICE_NAT_DISABLED; - int rv = 0; nat44_lb_addr_port_t *locals = 0; ip4_address_t e_addr; nat_protocol_t proto; + u32 flags = 0; u8 *tag = 0; + int rv = 0; locals = unformat_nat44_lb_addr_port (mp->locals, clib_net_to_host_u32 (mp->local_num)); @@ -918,17 +1031,34 @@ vl_api_nat44_add_del_lb_static_mapping_t_handler ( proto = ip_proto_to_nat_proto (mp->protocol); if (mp->flags & NAT_API_IS_TWICE_NAT) - twice_nat = TWICE_NAT; + { + flags |= NAT_SM_FLAG_TWICE_NAT; + } else if (mp->flags & NAT_API_IS_SELF_TWICE_NAT) - twice_nat = TWICE_NAT_SELF; - mp->tag[sizeof (mp->tag) - 1] = 0; - tag = format (0, "%s", mp->tag); - vec_terminate_c_string (tag); + { + flags |= NAT_SM_FLAG_SELF_TWICE_NAT; + } + + if (mp->flags & NAT_API_IS_OUT2IN_ONLY) + { + flags |= NAT_SM_FLAG_OUT2IN_ONLY; + } + + if (mp->is_add) + { + mp->tag[sizeof (mp->tag) - 1] = 0; + tag = format (0, "%s", mp->tag); + vec_terminate_c_string (tag); - rv = nat44_add_del_lb_static_mapping ( - e_addr, mp->external_port, proto, locals, mp->is_add, twice_nat, - mp->flags & NAT_API_IS_OUT2IN_ONLY, tag, - clib_net_to_host_u32 (mp->affinity)); + rv = nat44_ed_add_lb_static_mapping ( + e_addr, mp->external_port, proto, locals, flags, tag, + clib_net_to_host_u32 (mp->affinity)); + } + else + { + rv = nat44_ed_del_lb_static_mapping (e_addr, mp->external_port, proto, + flags); + } vec_free (locals); vec_free (tag); @@ -949,7 +1079,7 @@ vl_api_nat44_lb_static_mapping_add_del_local_t_handler ( clib_memcpy (&l_addr, mp->local.addr, 4); proto = ip_proto_to_nat_proto (mp->protocol); - rv = nat44_lb_static_mapping_add_del_local ( + rv = nat44_ed_add_del_lb_static_mapping_local ( e_addr, mp->external_port, l_addr, mp->local.port, proto, clib_net_to_host_u32 (mp->local.vrf_id), mp->local.probability, mp->is_add); @@ -978,12 +1108,21 @@ send_nat44_lb_static_mapping_details (snat_static_mapping_t *m, rmp->protocol = nat_proto_to_ip_proto (m->proto); rmp->context = context; - if (m->twice_nat == TWICE_NAT) - rmp->flags |= NAT_API_IS_TWICE_NAT; - else if (m->twice_nat == TWICE_NAT_SELF) - rmp->flags |= NAT_API_IS_SELF_TWICE_NAT; - if (is_out2in_only_static_mapping (m)) - rmp->flags |= NAT_API_IS_OUT2IN_ONLY; + if (is_sm_self_twice_nat (m->flags)) + { + rmp->flags |= NAT_API_IS_SELF_TWICE_NAT; + } + + if (is_sm_out2in_only (m->flags)) + { + rmp->flags |= NAT_API_IS_OUT2IN_ONLY; + } + + if (is_sm_twice_nat (m->flags)) + { + rmp->flags |= NAT_API_IS_TWICE_NAT; + } + if (m->tag) strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag)); @@ -1016,7 +1155,7 @@ vl_api_nat44_lb_static_mapping_dump_t_handler ( pool_foreach (m, sm->static_mappings) { - if (is_lb_static_mapping (m)) + if (is_sm_lb (m->flags)) send_nat44_lb_static_mapping_details (m, reg, mp->context); } } @@ -1040,7 +1179,7 @@ vl_api_nat44_del_session_t_handler (vl_api_nat44_del_session_t *mp) is_in = mp->flags & NAT_API_IS_INSIDE; - rv = nat44_del_ed_session (sm, &addr, port, &eh_addr, eh_port, mp->protocol, + rv = nat44_ed_del_session (sm, &addr, port, &eh_addr, eh_port, mp->protocol, vrf_id, is_in); REPLY_MACRO (VL_API_NAT44_DEL_SESSION_REPLY); @@ -1186,9 +1325,7 @@ vl_api_nat44_plugin_enable_disable_t_handler ( if (mp->enable) { - if (!(mp->flags & NAT44_API_IS_ENDPOINT_DEPENDENT) || - (mp->flags & NAT44_API_IS_OUT2IN_DPO) || mp->users || - mp->user_sessions) + if (mp->users || mp->user_sessions) { rv = VNET_API_ERROR_UNSUPPORTED; } @@ -1388,7 +1525,7 @@ nat_ed_user_create_helper (user_create_helper_t *uch, snat_session_t *s) { u = pool_elt_at_index (uch->users, value.value); } - if (snat_is_session_static (s)) + if (nat44_ed_is_session_static (s)) { ++u->nstaticsessions; } @@ -1471,14 +1608,13 @@ send_nat44_user_session_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); @@ -1496,16 +1632,13 @@ send_nat44_user_session_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 (is_twice_nat_session (s)) + if (nat44_ed_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; } - } vl_api_send_msg (reg, (u8 *) rmp); } @@ -1543,6 +1676,99 @@ vl_api_nat44_user_session_dump_t_handler (vl_api_nat44_user_session_dump_t * } } +static void +send_nat44_user_session_v2_details (snat_session_t *s, + vl_api_registration_t *reg, u32 context) +{ + vl_api_nat44_user_session_v2_details_t *rmp; + snat_main_t *sm = &snat_main; + u64 now = vlib_time_now (sm->vnet_main->vlib_main); + u64 sess_timeout_time = 0; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = + ntohs (VL_API_NAT44_USER_SESSION_V2_DETAILS + sm->msg_id_base); + 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)) + rmp->flags |= NAT_API_IS_STATIC; + + if (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->last_heard = clib_host_to_net_u64 ((u64) s->last_heard); + rmp->total_bytes = clib_host_to_net_u64 (s->total_bytes); + rmp->total_pkts = ntohl (s->total_pkts); + rmp->context = context; + if (snat_is_unk_proto_session (s)) + { + rmp->outside_port = 0; + rmp->inside_port = 0; + rmp->protocol = ntohs (s->in2out.port); + } + else + { + rmp->outside_port = s->out2in.port; + 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 (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; + } + } + + sess_timeout_time = s->last_heard + (f64) nat_session_get_timeout ( + &sm->timeouts, s->nat_proto, s->state); + rmp->is_timed_out = (now >= sess_timeout_time); + + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_nat44_user_session_v2_dump_t_handler ( + vl_api_nat44_user_session_v2_dump_t *mp) +{ + snat_main_per_thread_data_t *tsm; + snat_main_t *sm = &snat_main; + vl_api_registration_t *reg; + snat_user_key_t ukey; + snat_session_t *s; + ip4_header_t ip; + + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + 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)); + if (sm->num_workers > 1) + tsm = vec_elt_at_index ( + sm->per_thread_data, + nat44_ed_get_in2out_worker_index (0, &ip, ukey.fib_index, 0)); + else + tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers); + + pool_foreach (s, tsm->sessions) + { + if (s->in2out.addr.as_u32 == ukey.addr.as_u32) + { + send_nat44_user_session_v2_details (s, reg, mp->context); + } + } +} + /* API definitions */ #include #include