X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat_test.c;h=0371ec485538fbaadffccddcfb8f406d1773b285;hb=bed1421b9f1b3643d93384084972337b596aec73;hp=c5a96d3f7dbd2707df9765102753b1b17acf49c6;hpb=72c419cc9e2e4749bed64c45cf1bca318a16ea70;p=vpp.git diff --git a/src/plugins/nat/nat_test.c b/src/plugins/nat/nat_test.c index c5a96d3f7db..0371ec48553 100644 --- a/src/plugins/nat/nat_test.c +++ b/src/plugins/nat/nat_test.c @@ -69,7 +69,7 @@ _(nat_set_workers_reply) \ _(nat44_add_del_interface_addr_reply) \ _(nat_ipfix_enable_disable_reply) \ _(nat_det_add_del_map_reply) \ -_(nat_det_set_timeouts_reply) \ +_(nat_set_timeouts_reply) \ _(nat_det_close_session_out_reply) \ _(nat_det_close_session_in_reply) @@ -118,8 +118,8 @@ _(NAT_DET_ADD_DEL_MAP_REPLY, nat_det_add_del_map_reply) \ _(NAT_DET_FORWARD_REPLY, nat_det_forward_reply) \ _(NAT_DET_REVERSE_REPLY, nat_det_reverse_reply) \ _(NAT_DET_MAP_DETAILS, nat_det_map_details) \ -_(NAT_DET_SET_TIMEOUTS_REPLY, nat_det_set_timeouts_reply) \ -_(NAT_DET_GET_TIMEOUTS_REPLY, nat_det_get_timeouts_reply) \ +_(NAT_SET_TIMEOUTS_REPLY, nat_set_timeouts_reply) \ +_(NAT_GET_TIMEOUTS_REPLY, nat_get_timeouts_reply) \ _(NAT_DET_CLOSE_SESSION_OUT_REPLY, \ nat_det_close_session_out_reply) \ _(NAT_DET_CLOSE_SESSION_IN_REPLY, \ @@ -221,7 +221,8 @@ static int api_nat44_interface_add_del_feature (vat_main_t * vam) M(NAT44_INTERFACE_ADD_DEL_FEATURE, mp); mp->sw_if_index = ntohl(sw_if_index); mp->is_add = is_add; - mp->is_inside = is_inside; + if (is_inside) + mp->flags |= NAT_API_IS_INSIDE; S(mp); W (ret); @@ -291,8 +292,11 @@ static int api_nat44_add_del_static_mapping(vat_main_t * vam) } M(NAT44_ADD_DEL_STATIC_MAPPING, mp); + mp->is_add = is_add; - mp->addr_only = addr_only; + if (addr_only) + mp->flags |= NAT_API_IS_ADDR_ONLY; + mp->local_port = ntohs ((u16) local_port); mp->external_port = ntohs ((u16) external_port); mp->external_sw_if_index = ntohl (sw_if_index); @@ -327,20 +331,21 @@ static void vl_api_nat44_static_mapping_details_t_handler { snat_test_main_t * sm = &snat_test_main; vat_main_t *vam = sm->vat_main; + nat_config_flags_t flags = (nat_config_flags_t) mp->flags; - if (mp->addr_only && mp->external_sw_if_index != ~0) + if (flags & NAT_API_IS_ADDR_ONLY && mp->external_sw_if_index != ~0) fformat (vam->ofp, "%15U%6s%15d%6s%11d%6d\n", format_ip4_address, &mp->local_ip_address, "", ntohl (mp->external_sw_if_index), "", ntohl (mp->vrf_id), mp->protocol); - else if (mp->addr_only && mp->external_sw_if_index == ~0) + else if (flags & NAT_API_IS_ADDR_ONLY && mp->external_sw_if_index == ~0) fformat (vam->ofp, "%15U%6s%15U%6s%11d%6d\n", format_ip4_address, &mp->local_ip_address, "", format_ip4_address, &mp->external_ip_address, "", ntohl (mp->vrf_id), mp->protocol); - else if (!mp->addr_only && mp->external_sw_if_index != ~0) + else if (!(flags & NAT_API_IS_ADDR_ONLY) && mp->external_sw_if_index != ~0) fformat (vam->ofp, "%15U%6d%15d%6d%11d%6d\n", format_ip4_address, &mp->local_ip_address, ntohs (mp->local_port), @@ -469,11 +474,19 @@ static int api_nat44_address_dump(vat_main_t * vam) static void vl_api_nat44_interface_details_t_handler (vl_api_nat44_interface_details_t *mp) { + nat_config_flags_t flags = (nat_config_flags_t) mp->flags; snat_test_main_t * sm = &snat_test_main; vat_main_t *vam = sm->vat_main; - fformat (vam->ofp, "sw_if_index %d %s\n", ntohl (mp->sw_if_index), - mp->is_inside ? "in" : "out"); + if ((flags & NAT_API_IS_INSIDE) && (flags & NAT_API_IS_OUTSIDE)) + { + fformat (vam->ofp, "sw_if_index %d in & out\n", ntohl (mp->sw_if_index)); + } + else + { + fformat (vam->ofp, "sw_if_index %d %s\n", ntohl (mp->sw_if_index), + flags & NAT_API_IS_INSIDE ? "in" : "out"); + } } static int api_nat44_interface_dump(vat_main_t * vam) @@ -590,6 +603,7 @@ static int api_nat44_add_del_interface_addr (vat_main_t * vam) M(NAT44_ADD_DEL_INTERFACE_ADDR, mp); mp->sw_if_index = ntohl(sw_if_index); + mp->is_add = is_add; S(mp); @@ -671,7 +685,7 @@ static void vl_api_nat44_user_session_details_t_handler fformat(vam->ofp, "%s session %U:%d to %U:%d protocol id %d " "total packets %d total bytes %lld\n", - mp->is_static ? "static" : "dynamic", + mp->flags & NAT_API_IS_STATIC ? "static" : "dynamic", format_ip4_address, mp->inside_ip_address, ntohs(mp->inside_port), format_ip4_address, mp->outside_ip_address, ntohs(mp->outside_port), ntohs(mp->protocol), ntohl(mp->total_pkts), @@ -707,7 +721,7 @@ static int api_nat44_user_session_dump(vat_main_t * vam) /* Use a control ping for synchronization */ M(NAT_CONTROL_PING, mp_ping); - memset(mp->ip_address, 0, 16); + clib_memset(mp->ip_address, 0, 16); clib_memcpy(mp->ip_address, &addr, 4); mp->vrf_id = htonl(vrf_id); S(mp_ping); @@ -904,10 +918,10 @@ static int api_nat_det_map_dump(vat_main_t * vam) return ret; } -static int api_nat_det_set_timeouts (vat_main_t * vam) +static int api_nat_set_timeouts (vat_main_t * vam) { unformat_input_t * i = vam->input; - vl_api_nat_det_set_timeouts_t * mp; + vl_api_nat_set_timeouts_t * mp; u32 udp = SNAT_UDP_TIMEOUT; u32 tcp_established = SNAT_TCP_ESTABLISHED_TIMEOUT; u32 tcp_transitory = SNAT_TCP_TRANSITORY_TIMEOUT; @@ -928,7 +942,7 @@ static int api_nat_det_set_timeouts (vat_main_t * vam) return -99; } - M(NAT_DET_SET_TIMEOUTS, mp); + M(NAT_SET_TIMEOUTS, mp); mp->udp = htonl(udp); mp->tcp_established = htonl(tcp_established); mp->tcp_transitory = htonl(tcp_transitory); @@ -939,8 +953,8 @@ static int api_nat_det_set_timeouts (vat_main_t * vam) return ret; } -static void vl_api_nat_det_get_timeouts_reply_t_handler - (vl_api_nat_det_get_timeouts_reply_t *mp) +static void vl_api_nat_get_timeouts_reply_t_handler + (vl_api_nat_get_timeouts_reply_t *mp) { snat_test_main_t * sm = &snat_test_main; vat_main_t *vam = sm->vat_main; @@ -959,18 +973,18 @@ static void vl_api_nat_det_get_timeouts_reply_t_handler vam->result_ready = 1; } -static int api_nat_det_get_timeouts(vat_main_t * vam) +static int api_nat_get_timeouts(vat_main_t * vam) { - vl_api_nat_det_get_timeouts_t * mp; + vl_api_nat_get_timeouts_t * mp; int ret; if (vam->json_output) { - clib_warning ("JSON output not supported for nat_show_config"); + clib_warning ("JSON output not supported for nat_get_timeouts"); return -99; } - M(NAT_DET_GET_TIMEOUTS, mp); + M(NAT_GET_TIMEOUTS, mp); S(mp); W (ret); return ret; @@ -1110,9 +1124,9 @@ _(nat_det_add_del_map, "in / out " \ _(nat_det_forward, "") \ _(nat_det_reverse, " ") \ _(nat_det_map_dump, "") \ -_(nat_det_set_timeouts, "[udp | tcp_established | " \ +_(nat_set_timeouts, "[udp | tcp_established | " \ "tcp_transitory | icmp ]") \ -_(nat_det_get_timeouts, "") \ +_(nat_get_timeouts, "") \ _(nat_det_close_session_out, ": " \ ":") \ _(nat_det_close_session_in, ": " \