X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Fnat%2Fnat_api.c;h=378e7abe8710b360d4b6e3fbafa3b21565e9c048;hb=b7b929931a07fbb27b43d5cd105f366c3e29807e;hp=2994f8001f4aea58e815414817080327c6454262;hpb=5d28c7afbc0abd172d0053768b2ebe37b7a6c348;p=vpp.git diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c index 2994f8001f4..378e7abe871 100644 --- a/src/plugins/nat/nat_api.c +++ b/src/plugins/nat/nat_api.c @@ -202,11 +202,11 @@ send_nat_worker_details (u32 worker_index, vl_api_registration_t * reg, vlib_worker_threads + worker_index + sm->first_worker_index; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT_WORKER_DETAILS + sm->msg_id_base); rmp->context = context; rmp->worker_index = htonl (worker_index); - rmp->lcore_id = htonl (w->lcore_id); + rmp->lcore_id = htonl (w->cpu_id); strncpy ((char *) rmp->name, (char *) w->name, ARRAY_LEN (rmp->name) - 1); vl_api_send_msg (reg, (u8 *) rmp); @@ -350,7 +350,7 @@ nat_ip4_reass_walk_api (nat_reass_ip4_t * reass, void *arg) nat_api_walk_ctx_t *ctx = arg; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base); rmp->context = ctx->context; clib_memcpy (rmp->src_addr, &(reass->key.src), 4); @@ -373,7 +373,7 @@ nat_ip6_reass_walk_api (nat_reass_ip6_t * reass, void *arg) nat_api_walk_ctx_t *ctx = arg; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT_REASS_DETAILS + sm->msg_id_base); rmp->context = ctx->context; clib_memcpy (rmp->src_addr, &(reass->key.src), 16); @@ -573,6 +573,63 @@ static void *vl_api_nat_get_addr_and_port_alloc_alg_t_print FINISH; } +static void +vl_api_nat_set_mss_clamping_t_handler (vl_api_nat_set_mss_clamping_t * mp) +{ + snat_main_t *sm = &snat_main; + vl_api_nat_set_mss_clamping_reply_t *rmp; + int rv = 0; + + if (mp->enable) + { + sm->mss_clamping = ntohs (mp->mss_value); + sm->mss_value_net = mp->mss_value; + } + else + sm->mss_clamping = 0; + + REPLY_MACRO (VL_API_NAT_SET_MSS_CLAMPING_REPLY); +} + +static void * +vl_api_nat_set_mss_clamping_t_print (vl_api_nat_set_mss_clamping_t * mp, + void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: nat_set_mss_clamping enable %d mss_value %d\n", + mp->enable, ntohs (mp->mss_value)); + + FINISH; +} + +static void +vl_api_nat_get_mss_clamping_t_handler (vl_api_nat_get_mss_clamping_t * mp) +{ + snat_main_t *sm = &snat_main; + vl_api_nat_get_mss_clamping_reply_t *rmp; + int rv = 0; + + /* *INDENT-OFF* */ + REPLY_MACRO2 (VL_API_NAT_GET_MSS_CLAMPING_REPLY, + ({ + rmp->enable = sm->mss_clamping ? 1 : 0; + rmp->mss_value = htons (sm->mss_clamping); + })) + /* *INDENT-ON* */ +} + +static void * +vl_api_nat_get_mss_clamping_t_print (vl_api_nat_get_mss_clamping_t * mp, + void *handle) +{ + u8 *s; + + s = format (0, "SCRIPT: nat_get_mss_clamping"); + + FINISH; +} + /*************/ /*** NAT44 ***/ /*************/ @@ -661,7 +718,7 @@ send_nat44_address_details (snat_address_t * a, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_ADDRESS_DETAILS + sm->msg_id_base); clib_memcpy (rmp->ip_address, &(a->addr), 4); if (a->fib_index != ~0) @@ -750,7 +807,7 @@ send_nat44_interface_details (snat_interface_t * i, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_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 = (nat_interface_is_inside (i) @@ -839,7 +896,7 @@ send_nat44_interface_output_feature_details (snat_interface_t * i, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_OUTPUT_FEATURE_DETAILS + sm->msg_id_base); rmp->sw_if_index = ntohl (i->sw_if_index); @@ -923,7 +980,7 @@ static void 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, - twice_nat, mp->out2in_only, tag); + twice_nat, mp->out2in_only, tag, 0); vec_free (tag); @@ -967,10 +1024,10 @@ send_nat44_static_mapping_details (snat_static_mapping_t * m, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base); - rmp->addr_only = m->addr_only; + rmp->addr_only = is_addr_only_static_mapping (m); clib_memcpy (rmp->local_ip_address, &(m->local_addr), 4); clib_memcpy (rmp->external_ip_address, &(m->external_addr), 4); rmp->external_sw_if_index = ~0; @@ -980,8 +1037,8 @@ send_nat44_static_mapping_details (snat_static_mapping_t * m, rmp->twice_nat = 1; else if (m->twice_nat == TWICE_NAT_SELF) rmp->self_twice_nat = 1; - rmp->out2in_only = m->out2in_only; - if (m->addr_only == 0) + rmp->out2in_only = is_out2in_only_static_mapping (m); + if (rmp->addr_only == 0) { rmp->protocol = snat_proto_to_ip_proto (m->proto); rmp->external_port = htons (m->external_port); @@ -1002,7 +1059,7 @@ send_nat44_static_map_resolve_details (snat_static_map_resolve_t * m, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_STATIC_MAPPING_DETAILS + sm->msg_id_base); rmp->addr_only = m->addr_only; @@ -1043,9 +1100,7 @@ vl_api_nat44_static_mapping_dump_t_handler (vl_api_nat44_static_mapping_dump_t /* *INDENT-OFF* */ pool_foreach (m, sm->static_mappings, ({ - if (!vec_len (m->locals) && - ((m->local_port != m->external_port) - || (m->local_addr.as_u32 != m->external_addr.as_u32))) + if (!is_identity_static_mapping(m) && !is_lb_static_mapping (m)) send_nat44_static_mapping_details (m, reg, mp->context); })); /* *INDENT-ON* */ @@ -1053,7 +1108,7 @@ vl_api_nat44_static_mapping_dump_t_handler (vl_api_nat44_static_mapping_dump_t for (j = 0; j < vec_len (sm->to_resolve); j++) { rp = sm->to_resolve + j; - if (rp->l_addr.as_u32 != 0) + if (!rp->identity_nat) send_nat44_static_map_resolve_details (rp, reg, mp->context); } } @@ -1105,7 +1160,7 @@ static void rv = snat_add_static_mapping (addr, addr, port, port, vrf_id, mp->addr_only, - sw_if_index, proto, mp->is_add, 0, 0, tag); + sw_if_index, proto, mp->is_add, 0, 0, tag, 1); vec_free (tag); @@ -1126,31 +1181,31 @@ static void *vl_api_nat44_add_del_identity_mapping_t_print if (mp->addr_only == 0) s = - format (s, "protocol %d port %d", mp->protocol, + format (s, " protocol %d port %d", mp->protocol, clib_net_to_host_u16 (mp->port)); if (mp->vrf_id != ~0) - s = format (s, "vrf %d", clib_net_to_host_u32 (mp->vrf_id)); + s = format (s, " vrf %d", clib_net_to_host_u32 (mp->vrf_id)); FINISH; } static void -send_nat44_identity_mapping_details (snat_static_mapping_t * m, +send_nat44_identity_mapping_details (snat_static_mapping_t * m, int index, vl_api_registration_t * reg, u32 context) { vl_api_nat44_identity_mapping_details_t *rmp; snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base); - rmp->addr_only = m->addr_only; + rmp->addr_only = is_addr_only_static_mapping (m); clib_memcpy (rmp->ip_address, &(m->local_addr), 4); rmp->port = htons (m->local_port); rmp->sw_if_index = ~0; - rmp->vrf_id = htonl (m->vrf_id); + rmp->vrf_id = htonl (m->locals[index].vrf_id); rmp->protocol = snat_proto_to_ip_proto (m->proto); rmp->context = context; if (m->tag) @@ -1168,7 +1223,7 @@ send_nat44_identity_map_resolve_details (snat_static_map_resolve_t * m, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_IDENTITY_MAPPING_DETAILS + sm->msg_id_base); rmp->addr_only = m->addr_only; @@ -1203,16 +1258,18 @@ static void /* *INDENT-OFF* */ pool_foreach (m, sm->static_mappings, ({ - if (!vec_len (m->locals) && (m->local_port == m->external_port) - && (m->local_addr.as_u32 == m->external_addr.as_u32)) - send_nat44_identity_mapping_details (m, reg, mp->context); + if (is_identity_static_mapping(m) && !is_lb_static_mapping (m)) + { + for (j = 0; j < vec_len (m->locals); j++) + send_nat44_identity_mapping_details (m, j, reg, mp->context); + } })); /* *INDENT-ON* */ for (j = 0; j < vec_len (sm->to_resolve); j++) { rp = sm->to_resolve + j; - if (rp->l_addr.as_u32 == 0) + if (rp->identity_nat) send_nat44_identity_map_resolve_details (rp, reg, mp->context); } } @@ -1274,7 +1331,7 @@ send_nat44_interface_addr_details (u32 sw_if_index, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_INTERFACE_ADDR_DETAILS + sm->msg_id_base); rmp->sw_if_index = ntohl (sw_if_index); @@ -1327,7 +1384,7 @@ send_nat44_user_details (snat_user_t * u, vl_api_registration_t * reg, ip4_main_t *im = &ip4_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_USER_DETAILS + sm->msg_id_base); if (!pool_is_free_index (im->fibs, u->fib_index)) @@ -1388,7 +1445,7 @@ send_nat44_user_session_details (snat_session_t * s, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_USER_SESSION_DETAILS + sm->msg_id_base); clib_memcpy (rmp->outside_ip_address, (&s->out2in.addr), 4); @@ -1507,7 +1564,7 @@ unformat_nat44_lb_addr_port (vl_api_nat44_lb_addr_port_t * addr_port_pairs, for (i = 0; i < addr_port_pair_num; i++) { ap = &addr_port_pairs[i]; - memset (&lb_addr_port, 0, sizeof (lb_addr_port)); + clib_memset (&lb_addr_port, 0, sizeof (lb_addr_port)); clib_memcpy (&lb_addr_port.addr, ap->addr, 4); lb_addr_port.port = clib_net_to_host_u16 (ap->port); lb_addr_port.probability = ap->probability; @@ -1587,7 +1644,7 @@ send_nat44_lb_static_mapping_details (snat_static_mapping_t * m, rmp = vl_msg_api_alloc (sizeof (*rmp) + (vec_len (m->locals) * sizeof (nat44_lb_addr_port_t))); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_LB_STATIC_MAPPING_DETAILS + sm->msg_id_base); @@ -1599,7 +1656,7 @@ send_nat44_lb_static_mapping_details (snat_static_mapping_t * m, rmp->twice_nat = 1; else if (m->twice_nat == TWICE_NAT_SELF) rmp->self_twice_nat = 1; - rmp->out2in_only = m->out2in_only; + rmp->out2in_only = is_out2in_only_static_mapping (m); if (m->tag) strncpy ((char *) rmp->tag, (char *) m->tag, vec_len (m->tag)); @@ -1635,7 +1692,7 @@ static void /* *INDENT-OFF* */ pool_foreach (m, sm->static_mappings, ({ - if (vec_len(m->locals)) + if (is_lb_static_mapping(m)) send_nat44_lb_static_mapping_details (m, reg, mp->context); })); /* *INDENT-ON* */ @@ -1768,7 +1825,7 @@ static void return; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT44_FORWARDING_IS_ENABLED_REPLY + sm->msg_id_base); rmp->context = mp->context; @@ -1925,7 +1982,7 @@ send_reply: REPLY_MACRO2 (VL_API_NAT_DET_REVERSE_REPLY, ({ rmp->is_nat44 = 1; - memset (rmp->in_addr, 0, 16); + clib_memset (rmp->in_addr, 0, 16); clib_memcpy (rmp->in_addr, &in_addr, 4); })) /* *INDENT-ON* */ @@ -1951,7 +2008,7 @@ sent_nat_det_map_details (snat_det_map_t * m, vl_api_registration_t * reg, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT_DET_MAP_DETAILS + sm->msg_id_base); rmp->is_nat44 = 1; clib_memcpy (rmp->in_addr, &m->in_addr, 4); @@ -2122,7 +2179,7 @@ send_nat_det_session_details (snat_det_session_t * s, snat_main_t *sm = &snat_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT_DET_SESSION_DETAILS + sm->msg_id_base); rmp->in_port = s->in_port; clib_memcpy (rmp->ext_addr, &s->out.ext_host_addr, 4); @@ -2154,7 +2211,7 @@ vl_api_nat_det_session_dump_t_handler (vl_api_nat_det_session_dump_t * mp) if (!mp->is_nat44) return; - memset (&empty_ses, 0, sizeof (empty_ses)); + clib_memset (&empty_ses, 0, sizeof (empty_ses)); clib_memcpy (&user_addr, mp->user_addr, 4); dm = snat_det_map_by_user (sm, &user_addr); if (!dm) @@ -2250,7 +2307,7 @@ nat64_api_pool_walk (snat_address_t * a, void *arg) nat64_api_walk_ctx_t *ctx = arg; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT64_POOL_ADDR_DETAILS + sm->msg_id_base); clib_memcpy (rmp->address, &(a->addr), 4); if (a->fib_index != ~0) @@ -2338,7 +2395,7 @@ nat64_api_interface_walk (snat_interface_t * i, void *arg) nat64_api_walk_ctx_t *ctx = arg; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_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 = (nat_interface_is_inside (i) @@ -2432,7 +2489,7 @@ nat64_api_bib_walk (nat64_db_bib_entry_t * bibe, void *arg) return -1; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT64_BIB_DETAILS + sm->msg_id_base); rmp->context = ctx->context; clib_memcpy (rmp->i_addr, &(bibe->in_addr), 16); @@ -2499,7 +2556,7 @@ nat64_api_st_walk (nat64_db_st_entry_t * ste, void *arg) return -1; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT64_ST_DETAILS + sm->msg_id_base); rmp->context = ctx->context; clib_memcpy (rmp->il_addr, &(bibe->in_addr), 16); @@ -2589,7 +2646,7 @@ nat64_api_prefix_walk (nat64_prefix_t * p, void *arg) nat64_api_walk_ctx_t *ctx = arg; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT64_PREFIX_DETAILS + sm->msg_id_base); clib_memcpy (rmp->prefix, &(p->prefix), 16); rmp->prefix_len = p->plen; @@ -2830,7 +2887,7 @@ send_dslite_address_details (snat_address_t * ap, rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_DSLITE_ADDRESS_DETAILS + sm->msg_id_base); clib_memcpy (rmp->ip_address, &(ap->addr), 4); @@ -2968,7 +3025,7 @@ nat66_api_interface_walk (snat_interface_t * i, void *arg) nat66_api_walk_ctx_t *ctx = arg; rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT66_INTERFACE_DETAILS + sm->msg_id_base); rmp->sw_if_index = ntohl (i->sw_if_index); rmp->is_inside = nat_interface_is_inside (i); @@ -3024,7 +3081,7 @@ nat66_api_static_mapping_walk (nat66_static_mapping_t * m, void *arg) vlib_get_combined_counter (&nm->session_counters, m - nm->sm, &vc); rmp = vl_msg_api_alloc (sizeof (*rmp)); - memset (rmp, 0, sizeof (*rmp)); + clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT66_STATIC_MAPPING_DETAILS + sm->msg_id_base); clib_memcpy (rmp->local_ip_address, &m->l_addr, 16); @@ -3083,6 +3140,8 @@ _(NAT_SET_TIMEOUTS, nat_set_timeouts) \ _(NAT_GET_TIMEOUTS, nat_get_timeouts) \ _(NAT_SET_ADDR_AND_PORT_ALLOC_ALG, nat_set_addr_and_port_alloc_alg) \ _(NAT_GET_ADDR_AND_PORT_ALLOC_ALG, nat_get_addr_and_port_alloc_alg) \ +_(NAT_SET_MSS_CLAMPING, nat_set_mss_clamping) \ +_(NAT_GET_MSS_CLAMPING, nat_get_mss_clamping) \ _(NAT44_ADD_DEL_ADDRESS_RANGE, nat44_add_del_address_range) \ _(NAT44_INTERFACE_ADD_DEL_FEATURE, nat44_interface_add_del_feature) \ _(NAT44_ADD_DEL_STATIC_MAPPING, nat44_add_del_static_mapping) \