2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * @brief NAT44 endpoint-dependent outside to inside network translation
20 #include <vlib/vlib.h>
21 #include <vnet/vnet.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/udp/udp_local.h>
25 #include <vnet/ethernet/ethernet.h>
26 #include <vnet/fib/ip4_fib.h>
28 #include <nat/lib/ipfix_logging.h>
29 #include <nat/nat_inlines.h>
30 #include <nat/lib/nat_syslog.h>
31 #include <nat/nat44-ei/nat44_ei_inlines.h>
32 #include <nat/nat44-ei/nat44_ei.h>
34 #include <vppinfra/hash.h>
35 #include <vppinfra/error.h>
36 #include <vppinfra/elog.h>
43 } snat_out2in_trace_t;
45 /* packet trace format function */
47 format_snat_out2in_trace (u8 * s, va_list * args)
49 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
50 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
51 snat_out2in_trace_t *t = va_arg (*args, snat_out2in_trace_t *);
55 "NAT44_OUT2IN: sw_if_index %d, next index %d, session index %d",
56 t->sw_if_index, t->next_index, t->session_index);
61 format_snat_out2in_fast_trace (u8 * s, va_list * args)
63 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
64 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
65 snat_out2in_trace_t *t = va_arg (*args, snat_out2in_trace_t *);
67 s = format (s, "NAT44_OUT2IN_FAST: sw_if_index %d, next index %d",
68 t->sw_if_index, t->next_index);
72 #define foreach_snat_out2in_error \
73 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
74 _(OUT_OF_PORTS, "out of ports") \
75 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
76 _(NO_TRANSLATION, "no translation") \
77 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
78 _(CANNOT_CREATE_USER, "cannot create NAT user")
82 #define _(sym,str) SNAT_OUT2IN_ERROR_##sym,
83 foreach_snat_out2in_error
86 } snat_out2in_error_t;
88 static char *snat_out2in_error_strings[] = {
89 #define _(sym,string) string,
90 foreach_snat_out2in_error
96 SNAT_OUT2IN_NEXT_DROP,
97 SNAT_OUT2IN_NEXT_LOOKUP,
98 SNAT_OUT2IN_NEXT_ICMP_ERROR,
100 } snat_out2in_next_t;
102 #ifndef CLIB_MARCH_VARIANT
104 nat44_o2i_is_idle_session_cb (clib_bihash_kv_8_8_t * kv, void *arg)
106 snat_main_t *sm = &snat_main;
107 nat44_is_idle_session_ctx_t *ctx = arg;
109 u64 sess_timeout_time;
110 snat_main_per_thread_data_t *tsm = vec_elt_at_index (sm->per_thread_data,
112 clib_bihash_kv_8_8_t s_kv;
114 s = pool_elt_at_index (tsm->sessions, kv->value);
115 sess_timeout_time = s->last_heard + (f64) nat44_session_get_timeout (sm, s);
116 if (ctx->now >= sess_timeout_time)
118 init_nat_i2o_k (&s_kv, s);
119 if (clib_bihash_add_del_8_8 (&sm->in2out, &s_kv, 0))
120 nat_elog_warn ("out2in key del failed");
122 nat_ipfix_logging_nat44_ses_delete (ctx->thread_index,
123 s->in2out.addr.as_u32,
124 s->out2in.addr.as_u32,
128 s->in2out.fib_index);
130 nat_syslog_nat44_apmdel (s->user_index, s->in2out.fib_index,
131 &s->in2out.addr, s->in2out.port,
132 &s->out2in.addr, s->out2in.port, s->nat_proto);
134 nat_ha_sdel (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
135 s->ext_host_port, s->nat_proto, s->out2in.fib_index,
138 if (!snat_is_session_static (s))
139 snat_free_outside_address_and_port (sm->addresses, ctx->thread_index,
140 &s->out2in.addr, s->out2in.port,
143 nat44_delete_session (sm, s, ctx->thread_index);
152 * @brief Create session for static mapping.
154 * Create NAT session initiated by host from external network with static
157 * @param sm NAT main.
158 * @param b0 Vlib buffer.
159 * @param in2out In2out NAT44 session key.
160 * @param out2in Out2in NAT44 session key.
161 * @param node Vlib node.
163 * @returns SNAT session if successfully created otherwise 0.
165 static inline snat_session_t *
166 create_session_for_static_mapping (snat_main_t * sm,
168 ip4_address_t i2o_addr,
171 ip4_address_t o2i_addr,
174 nat_protocol_t proto,
175 vlib_node_runtime_t * node,
176 u32 thread_index, f64 now)
180 clib_bihash_kv_8_8_t kv0;
183 nat44_is_idle_session_ctx_t ctx0;
185 if (PREDICT_FALSE (nat44_ei_maximum_sessions_exceeded (sm, thread_index)))
187 b0->error = node->errors[SNAT_OUT2IN_ERROR_MAX_SESSIONS_EXCEEDED];
188 nat_elog_notice ("maximum sessions exceeded");
192 ip0 = vlib_buffer_get_current (b0);
193 udp0 = ip4_next_header (ip0);
195 u = nat_user_get_or_create (sm, &i2o_addr, i2o_fib_index, thread_index);
198 b0->error = node->errors[SNAT_OUT2IN_ERROR_CANNOT_CREATE_USER];
202 s = nat_session_alloc_or_recycle (sm, u, thread_index, now);
205 nat44_delete_user_with_no_session (sm, u, thread_index);
206 nat_elog_warn ("create NAT session failed");
210 s->flags |= SNAT_SESSION_FLAG_STATIC_MAPPING;
211 s->ext_host_addr.as_u32 = ip0->src_address.as_u32;
212 s->ext_host_port = udp0->src_port;
213 user_session_increment (sm, u, 1 /* static */ );
214 s->in2out.addr = i2o_addr;
215 s->in2out.port = i2o_port;
216 s->in2out.fib_index = i2o_fib_index;
217 s->out2in.addr = o2i_addr;
218 s->out2in.port = o2i_port;
219 s->out2in.fib_index = o2i_fib_index;
220 s->nat_proto = proto;
222 /* Add to translation hashes */
224 ctx0.thread_index = thread_index;
225 init_nat_i2o_kv (&kv0, s, thread_index,
226 s - sm->per_thread_data[thread_index].sessions);
227 if (clib_bihash_add_or_overwrite_stale_8_8 (
228 &sm->in2out, &kv0, nat44_i2o_is_idle_session_cb, &ctx0))
229 nat_elog_notice ("in2out key add failed");
231 init_nat_o2i_kv (&kv0, s, thread_index,
232 s - sm->per_thread_data[thread_index].sessions);
233 if (clib_bihash_add_or_overwrite_stale_8_8 (
234 &sm->out2in, &kv0, nat44_o2i_is_idle_session_cb, &ctx0))
235 nat_elog_notice ("out2in key add failed");
238 nat_ipfix_logging_nat44_ses_create (thread_index,
239 s->in2out.addr.as_u32,
240 s->out2in.addr.as_u32,
243 s->out2in.port, s->in2out.fib_index);
245 nat_syslog_nat44_apmadd (s->user_index, s->in2out.fib_index,
246 &s->in2out.addr, s->in2out.port, &s->out2in.addr,
247 s->out2in.port, s->nat_proto);
249 nat_ha_sadd (&s->in2out.addr, s->in2out.port, &s->out2in.addr,
250 s->out2in.port, &s->ext_host_addr, s->ext_host_port,
251 &s->ext_host_nat_addr, s->ext_host_nat_port,
252 s->nat_proto, s->in2out.fib_index, s->flags, thread_index, 0);
257 #ifndef CLIB_MARCH_VARIANT
258 static_always_inline snat_out2in_error_t
259 icmp_get_key (vlib_buffer_t * b, ip4_header_t * ip0,
260 ip4_address_t * addr, u16 * port, nat_protocol_t * nat_proto)
262 icmp46_header_t *icmp0;
263 icmp_echo_header_t *echo0, *inner_echo0 = 0;
264 ip4_header_t *inner_ip0;
266 icmp46_header_t *inner_icmp0;
268 icmp0 = (icmp46_header_t *) ip4_next_header (ip0);
269 echo0 = (icmp_echo_header_t *) (icmp0 + 1);
271 if (!icmp_type_is_error_message
272 (vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
274 *nat_proto = NAT_PROTOCOL_ICMP;
275 *addr = ip0->dst_address;
276 *port = vnet_buffer (b)->ip.reass.l4_src_port;
280 inner_ip0 = (ip4_header_t *) (echo0 + 1);
281 l4_header = ip4_next_header (inner_ip0);
282 *nat_proto = ip_proto_to_nat_proto (inner_ip0->protocol);
283 *addr = inner_ip0->src_address;
286 case NAT_PROTOCOL_ICMP:
287 inner_icmp0 = (icmp46_header_t *) l4_header;
288 inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
289 *port = inner_echo0->identifier;
291 case NAT_PROTOCOL_UDP:
292 case NAT_PROTOCOL_TCP:
293 *port = ((tcp_udp_header_t *) l4_header)->src_port;
296 return SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL;
299 return -1; /* success */
303 * Get address and port values to be used for ICMP packet translation
304 * and create session if needed
306 * @param[in,out] sm NAT main
307 * @param[in,out] node NAT node runtime
308 * @param[in] thread_index thread index
309 * @param[in,out] b0 buffer containing packet to be translated
310 * @param[in,out] ip0 ip header
311 * @param[out] p_proto protocol used for matching
312 * @param[out] p_value address and port after NAT translation
313 * @param[out] p_dont_translate if packet should not be translated
314 * @param d optional parameter
315 * @param e optional parameter
318 icmp_match_out2in_slow (snat_main_t * sm, vlib_node_runtime_t * node,
319 u32 thread_index, vlib_buffer_t * b0,
320 ip4_header_t * ip0, ip4_address_t * addr,
321 u16 * port, u32 * fib_index,
322 nat_protocol_t * proto, void *d, void *e,
325 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
327 snat_session_t *s0 = 0;
328 clib_bihash_kv_8_8_t kv0, value0;
333 vlib_main_t *vm = vlib_get_main ();
336 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
337 *fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
341 err = icmp_get_key (b0, ip0, addr, port, proto);
344 b0->error = node->errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
345 next0 = SNAT_OUT2IN_NEXT_DROP;
349 ip4_address_t mapping_addr;
351 u32 mapping_fib_index;
353 init_nat_k (&kv0, *addr, *port, *fib_index, *proto);
354 if (clib_bihash_search_8_8 (&sm->out2in, &kv0, &value0))
356 /* Try to match static mapping by external address and port,
357 destination address and port in packet */
358 if (nat44_ei_static_mapping_match (
359 *addr, *port, *fib_index, *proto, &mapping_addr, &mapping_port,
360 &mapping_fib_index, 1, &is_addr_only, &identity_nat))
362 if (!sm->forwarding_enabled)
364 /* Don't NAT packet aimed at the intfc address */
365 if (PREDICT_FALSE (is_interface_addr (sm, node, sw_if_index0,
366 ip0->dst_address.as_u32)))
371 b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
372 next0 = SNAT_OUT2IN_NEXT_DROP;
383 (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
385 && (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
386 ICMP4_echo_request || !is_addr_only)))
388 b0->error = node->errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
389 next0 = SNAT_OUT2IN_NEXT_DROP;
393 if (PREDICT_FALSE (identity_nat))
398 /* Create session initiated by host from external network */
400 create_session_for_static_mapping (sm, b0, mapping_addr, mapping_port,
401 mapping_fib_index, *addr, *port,
402 *fib_index, *proto, node,
403 thread_index, vlib_time_now (vm));
407 next0 = SNAT_OUT2IN_NEXT_DROP;
414 (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
416 && vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
418 && !icmp_type_is_error_message (vnet_buffer (b0)->ip.
419 reass.icmp_type_or_tcp_flags)))
421 b0->error = node->errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
422 next0 = SNAT_OUT2IN_NEXT_DROP;
426 s0 = pool_elt_at_index (tsm->sessions,
427 nat_value_get_session_index (&value0));
433 *addr = s0->in2out.addr;
434 *port = s0->in2out.port;
435 *fib_index = s0->in2out.fib_index;
438 *(snat_session_t **) d = s0;
443 #ifndef CLIB_MARCH_VARIANT
445 * Get address and port values to be used for ICMP packet translation
447 * @param[in] sm NAT main
448 * @param[in,out] node NAT node runtime
449 * @param[in] thread_index thread index
450 * @param[in,out] b0 buffer containing packet to be translated
451 * @param[in,out] ip0 ip header
452 * @param[out] p_proto protocol used for matching
453 * @param[out] p_value address and port after NAT translation
454 * @param[out] p_dont_translate if packet should not be translated
455 * @param d optional parameter
456 * @param e optional parameter
459 icmp_match_out2in_fast (snat_main_t * sm, vlib_node_runtime_t * node,
460 u32 thread_index, vlib_buffer_t * b0,
461 ip4_header_t * ip0, ip4_address_t * mapping_addr,
462 u16 * mapping_port, u32 * mapping_fib_index,
463 nat_protocol_t * proto, void *d, void *e,
475 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
476 rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
478 err = icmp_get_key (b0, ip0, &addr, &port, proto);
481 b0->error = node->errors[err];
482 next0 = SNAT_OUT2IN_NEXT_DROP;
485 if (nat44_ei_static_mapping_match (addr, port, rx_fib_index0, *proto,
486 mapping_addr, mapping_port,
487 mapping_fib_index, 1, &is_addr_only, 0))
489 /* Don't NAT packet aimed at the intfc address */
490 if (is_interface_addr (sm, node, sw_if_index0, ip0->dst_address.as_u32))
495 b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
496 next0 = SNAT_OUT2IN_NEXT_DROP;
501 (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
502 && (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags !=
503 ICMP4_echo_request || !is_addr_only)
504 && !icmp_type_is_error_message (vnet_buffer (b0)->ip.
505 reass.icmp_type_or_tcp_flags)))
507 b0->error = node->errors[SNAT_OUT2IN_ERROR_BAD_ICMP_TYPE];
508 next0 = SNAT_OUT2IN_NEXT_DROP;
517 #ifndef CLIB_MARCH_VARIANT
519 icmp_out2in (snat_main_t * sm,
522 icmp46_header_t * icmp0,
525 vlib_node_runtime_t * node,
526 u32 next0, u32 thread_index, void *d, void *e)
528 icmp_echo_header_t *echo0, *inner_echo0 = 0;
529 ip4_header_t *inner_ip0 = 0;
531 icmp46_header_t *inner_icmp0;
533 u32 new_addr0, old_addr0;
534 u16 old_id0, new_id0;
538 vlib_main_t *vm = vlib_get_main ();
542 nat_protocol_t proto;
544 echo0 = (icmp_echo_header_t *) (icmp0 + 1);
546 next0_tmp = sm->icmp_match_out2in_cb (sm, node, thread_index, b0, ip0,
547 &addr, &port, &fib_index, &proto,
548 d, e, &dont_translate);
551 if (next0 == SNAT_OUT2IN_NEXT_DROP || dont_translate)
554 if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
557 ip_incremental_checksum_buffer (vm, b0,
559 (u8 *) vlib_buffer_get_current (b0),
560 ntohs (ip0->length) -
561 ip4_header_bytes (ip0), 0);
562 checksum0 = ~ip_csum_fold (sum0);
563 if (checksum0 != 0 && checksum0 != 0xffff)
565 next0 = SNAT_OUT2IN_NEXT_DROP;
570 old_addr0 = ip0->dst_address.as_u32;
571 new_addr0 = ip0->dst_address.as_u32 = addr.as_u32;
572 vnet_buffer (b0)->sw_if_index[VLIB_TX] = fib_index;
574 sum0 = ip0->checksum;
575 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
576 dst_address /* changed member */ );
577 ip0->checksum = ip_csum_fold (sum0);
580 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
582 if (icmp0->checksum == 0)
583 icmp0->checksum = 0xffff;
585 if (!icmp_type_is_error_message (icmp0->type))
588 if (PREDICT_FALSE (new_id0 != echo0->identifier))
590 old_id0 = echo0->identifier;
592 echo0->identifier = new_id0;
594 sum0 = icmp0->checksum;
596 ip_csum_update (sum0, old_id0, new_id0, icmp_echo_header_t,
597 identifier /* changed member */ );
598 icmp0->checksum = ip_csum_fold (sum0);
603 inner_ip0 = (ip4_header_t *) (echo0 + 1);
604 l4_header = ip4_next_header (inner_ip0);
606 if (!ip4_header_checksum_is_valid (inner_ip0))
608 next0 = SNAT_OUT2IN_NEXT_DROP;
612 old_addr0 = inner_ip0->src_address.as_u32;
613 inner_ip0->src_address = addr;
614 new_addr0 = inner_ip0->src_address.as_u32;
616 sum0 = icmp0->checksum;
617 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
618 src_address /* changed member */ );
619 icmp0->checksum = ip_csum_fold (sum0);
623 case NAT_PROTOCOL_ICMP:
624 inner_icmp0 = (icmp46_header_t *) l4_header;
625 inner_echo0 = (icmp_echo_header_t *) (inner_icmp0 + 1);
627 old_id0 = inner_echo0->identifier;
629 inner_echo0->identifier = new_id0;
631 sum0 = icmp0->checksum;
633 ip_csum_update (sum0, old_id0, new_id0, icmp_echo_header_t,
635 icmp0->checksum = ip_csum_fold (sum0);
637 case NAT_PROTOCOL_UDP:
638 case NAT_PROTOCOL_TCP:
639 old_id0 = ((tcp_udp_header_t *) l4_header)->src_port;
641 ((tcp_udp_header_t *) l4_header)->src_port = new_id0;
643 sum0 = icmp0->checksum;
644 sum0 = ip_csum_update (sum0, old_id0, new_id0, tcp_udp_header_t,
646 icmp0->checksum = ip_csum_fold (sum0);
660 icmp_out2in_slow_path (snat_main_t * sm,
663 icmp46_header_t * icmp0,
666 vlib_node_runtime_t * node,
668 u32 thread_index, snat_session_t ** p_s0)
670 vlib_main_t *vm = vlib_get_main ();
672 next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
673 next0, thread_index, p_s0, 0);
674 snat_session_t *s0 = *p_s0;
675 if (PREDICT_TRUE (next0 != SNAT_OUT2IN_NEXT_DROP && s0))
678 nat44_ei_session_update_counters (
679 s0, now, vlib_buffer_length_in_chain (vm, b0), thread_index);
680 /* Per-user LRU list maintenance */
681 nat44_session_update_lru (sm, s0, thread_index);
687 nat_out2in_sm_unknown_proto (snat_main_t * sm,
689 ip4_header_t * ip, u32 rx_fib_index)
691 clib_bihash_kv_8_8_t kv, value;
692 snat_static_mapping_t *m;
693 u32 old_addr, new_addr;
696 init_nat_k (&kv, ip->dst_address, 0, 0, 0);
697 if (clib_bihash_search_8_8 (&sm->static_mapping_by_external, &kv, &value))
700 m = pool_elt_at_index (sm->static_mappings, value.value);
702 old_addr = ip->dst_address.as_u32;
703 new_addr = ip->dst_address.as_u32 = m->local_addr.as_u32;
705 sum = ip_csum_update (sum, old_addr, new_addr, ip4_header_t, dst_address);
706 ip->checksum = ip_csum_fold (sum);
708 vnet_buffer (b)->sw_if_index[VLIB_TX] = m->fib_index;
712 VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
713 vlib_node_runtime_t * node,
714 vlib_frame_t * frame)
716 u32 n_left_from, *from;
717 snat_main_t *sm = &snat_main;
718 f64 now = vlib_time_now (vm);
719 u32 thread_index = vm->thread_index;
720 snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
722 from = vlib_frame_vector_args (frame);
723 n_left_from = frame->n_vectors;
725 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
726 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
727 vlib_get_buffers (vm, from, b, n_left_from);
729 while (n_left_from >= 2)
731 vlib_buffer_t *b0, *b1;
732 u32 next0 = SNAT_OUT2IN_NEXT_LOOKUP;
733 u32 next1 = SNAT_OUT2IN_NEXT_LOOKUP;
734 u32 sw_if_index0, sw_if_index1;
735 ip4_header_t *ip0, *ip1;
736 ip_csum_t sum0, sum1;
737 u32 new_addr0, old_addr0;
738 u16 new_port0, old_port0;
739 u32 new_addr1, old_addr1;
740 u16 new_port1, old_port1;
741 udp_header_t *udp0, *udp1;
742 tcp_header_t *tcp0, *tcp1;
743 icmp46_header_t *icmp0, *icmp1;
744 u32 rx_fib_index0, rx_fib_index1;
746 snat_session_t *s0 = 0, *s1 = 0;
747 clib_bihash_kv_8_8_t kv0, kv1, value0, value1;
748 u8 identity_nat0, identity_nat1;
749 ip4_address_t sm_addr0, sm_addr1;
750 u16 sm_port0, sm_port1;
751 u32 sm_fib_index0, sm_fib_index1;
758 /* Prefetch next iteration. */
759 if (PREDICT_TRUE (n_left_from >= 4))
761 vlib_buffer_t *p2, *p3;
766 vlib_prefetch_buffer_header (p2, LOAD);
767 vlib_prefetch_buffer_header (p3, LOAD);
769 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, LOAD);
770 CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, LOAD);
773 vnet_buffer (b0)->snat.flags = 0;
774 vnet_buffer (b1)->snat.flags = 0;
776 ip0 = vlib_buffer_get_current (b0);
777 udp0 = ip4_next_header (ip0);
778 tcp0 = (tcp_header_t *) udp0;
779 icmp0 = (icmp46_header_t *) udp0;
781 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
782 rx_fib_index0 = vec_elt (sm->ip4_main->fib_index_by_sw_if_index,
785 if (PREDICT_FALSE (ip0->ttl == 1))
787 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
788 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
789 ICMP4_time_exceeded_ttl_exceeded_in_transit,
791 next0 = SNAT_OUT2IN_NEXT_ICMP_ERROR;
795 proto0 = ip_proto_to_nat_proto (ip0->protocol);
797 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
799 if (nat_out2in_sm_unknown_proto (sm, b0, ip0, rx_fib_index0))
801 if (!sm->forwarding_enabled)
804 node->errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
805 next0 = SNAT_OUT2IN_NEXT_DROP;
808 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.other,
809 thread_index, sw_if_index0, 1);
814 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
816 next0 = icmp_out2in_slow_path
817 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
818 next0, now, thread_index, &s0);
819 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.icmp,
820 thread_index, sw_if_index0, 1);
824 init_nat_k (&kv0, ip0->dst_address,
825 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
827 if (clib_bihash_search_8_8 (&sm->out2in, &kv0, &value0))
829 /* Try to match static mapping by external address and port,
830 destination address and port in packet */
831 if (nat44_ei_static_mapping_match (
832 ip0->dst_address, vnet_buffer (b0)->ip.reass.l4_dst_port,
833 rx_fib_index0, proto0, &sm_addr0, &sm_port0, &sm_fib_index0, 1,
837 * Send DHCP packets to the ipv4 stack, or we won't
838 * be able to use dhcp client on the outside interface
841 (proto0 == NAT_PROTOCOL_UDP
842 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
843 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client))))
845 vnet_feature_next (&next0, b0);
849 if (!sm->forwarding_enabled)
851 b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
852 next0 = SNAT_OUT2IN_NEXT_DROP;
857 if (PREDICT_FALSE (identity_nat0))
860 /* Create session initiated by host from external network */
861 s0 = create_session_for_static_mapping (sm, b0,
865 vnet_buffer (b0)->ip.
867 rx_fib_index0, proto0, node,
871 next0 = SNAT_OUT2IN_NEXT_DROP;
876 s0 = pool_elt_at_index (tsm->sessions,
877 nat_value_get_session_index (&value0));
879 old_addr0 = ip0->dst_address.as_u32;
880 ip0->dst_address = s0->in2out.addr;
881 new_addr0 = ip0->dst_address.as_u32;
882 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->in2out.fib_index;
884 sum0 = ip0->checksum;
885 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
886 ip4_header_t, dst_address /* changed member */ );
887 ip0->checksum = ip_csum_fold (sum0);
889 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
891 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
893 old_port0 = vnet_buffer (b0)->ip.reass.l4_dst_port;
894 new_port0 = udp0->dst_port = s0->in2out.port;
895 sum0 = tcp0->checksum;
896 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
898 dst_address /* changed member */ );
900 sum0 = ip_csum_update (sum0, old_port0, new_port0,
901 ip4_header_t /* cheat */ ,
902 length /* changed member */ );
903 tcp0->checksum = ip_csum_fold (sum0);
905 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.tcp,
906 thread_index, sw_if_index0, 1);
910 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
912 old_port0 = vnet_buffer (b0)->ip.reass.l4_dst_port;
913 new_port0 = udp0->dst_port = s0->in2out.port;
914 if (PREDICT_FALSE (udp0->checksum))
916 sum0 = udp0->checksum;
917 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, dst_address /* changed member */
920 ip_csum_update (sum0, old_port0, new_port0,
921 ip4_header_t /* cheat */ ,
922 length /* changed member */ );
923 udp0->checksum = ip_csum_fold (sum0);
926 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.udp,
927 thread_index, sw_if_index0, 1);
931 nat44_ei_session_update_counters (
932 s0, now, vlib_buffer_length_in_chain (vm, b0), thread_index);
933 /* Per-user LRU list maintenance */
934 nat44_session_update_lru (sm, s0, thread_index);
937 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
938 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
940 snat_out2in_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
941 t->sw_if_index = sw_if_index0;
942 t->next_index = next0;
943 t->session_index = ~0;
946 s0 - sm->per_thread_data[thread_index].sessions;
949 if (next0 == SNAT_OUT2IN_NEXT_DROP)
951 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.drops,
952 thread_index, sw_if_index0, 1);
956 ip1 = vlib_buffer_get_current (b1);
957 udp1 = ip4_next_header (ip1);
958 tcp1 = (tcp_header_t *) udp1;
959 icmp1 = (icmp46_header_t *) udp1;
961 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX];
962 rx_fib_index1 = vec_elt (sm->ip4_main->fib_index_by_sw_if_index,
965 if (PREDICT_FALSE (ip1->ttl == 1))
967 vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32) ~ 0;
968 icmp4_error_set_vnet_buffer (b1, ICMP4_time_exceeded,
969 ICMP4_time_exceeded_ttl_exceeded_in_transit,
971 next1 = SNAT_OUT2IN_NEXT_ICMP_ERROR;
975 proto1 = ip_proto_to_nat_proto (ip1->protocol);
977 if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_OTHER))
979 if (nat_out2in_sm_unknown_proto (sm, b1, ip1, rx_fib_index1))
981 if (!sm->forwarding_enabled)
984 node->errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
985 next1 = SNAT_OUT2IN_NEXT_DROP;
988 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.other,
989 thread_index, sw_if_index1, 1);
993 if (PREDICT_FALSE (proto1 == NAT_PROTOCOL_ICMP))
995 next1 = icmp_out2in_slow_path
996 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
997 next1, now, thread_index, &s1);
998 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.icmp,
999 thread_index, sw_if_index1, 1);
1003 init_nat_k (&kv1, ip1->dst_address,
1004 vnet_buffer (b1)->ip.reass.l4_dst_port, rx_fib_index1,
1006 if (clib_bihash_search_8_8 (&sm->out2in, &kv1, &value1))
1008 /* Try to match static mapping by external address and port,
1009 destination address and port in packet */
1010 if (nat44_ei_static_mapping_match (
1011 ip1->dst_address, vnet_buffer (b1)->ip.reass.l4_dst_port,
1012 rx_fib_index1, proto1, &sm_addr1, &sm_port1, &sm_fib_index1, 1,
1016 * Send DHCP packets to the ipv4 stack, or we won't
1017 * be able to use dhcp client on the outside interface
1020 (proto1 == NAT_PROTOCOL_UDP
1021 && (vnet_buffer (b1)->ip.reass.l4_dst_port ==
1022 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client))))
1024 vnet_feature_next (&next1, b1);
1028 if (!sm->forwarding_enabled)
1030 b1->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1031 next1 = SNAT_OUT2IN_NEXT_DROP;
1036 if (PREDICT_FALSE (identity_nat1))
1039 /* Create session initiated by host from external network */
1041 create_session_for_static_mapping (sm, b1, sm_addr1, sm_port1,
1044 vnet_buffer (b1)->ip.
1046 rx_fib_index1, proto1, node,
1050 next1 = SNAT_OUT2IN_NEXT_DROP;
1055 s1 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
1056 nat_value_get_session_index (&value1));
1058 old_addr1 = ip1->dst_address.as_u32;
1059 ip1->dst_address = s1->in2out.addr;
1060 new_addr1 = ip1->dst_address.as_u32;
1061 vnet_buffer (b1)->sw_if_index[VLIB_TX] = s1->in2out.fib_index;
1063 sum1 = ip1->checksum;
1064 sum1 = ip_csum_update (sum1, old_addr1, new_addr1,
1065 ip4_header_t, dst_address /* changed member */ );
1066 ip1->checksum = ip_csum_fold (sum1);
1068 if (PREDICT_TRUE (proto1 == NAT_PROTOCOL_TCP))
1070 if (!vnet_buffer (b1)->ip.reass.is_non_first_fragment)
1072 old_port1 = vnet_buffer (b1)->ip.reass.l4_dst_port;
1073 new_port1 = udp1->dst_port = s1->in2out.port;
1075 sum1 = tcp1->checksum;
1076 sum1 = ip_csum_update (sum1, old_addr1, new_addr1,
1078 dst_address /* changed member */ );
1080 sum1 = ip_csum_update (sum1, old_port1, new_port1,
1081 ip4_header_t /* cheat */ ,
1082 length /* changed member */ );
1083 tcp1->checksum = ip_csum_fold (sum1);
1085 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.tcp,
1086 thread_index, sw_if_index1, 1);
1090 if (!vnet_buffer (b1)->ip.reass.is_non_first_fragment)
1092 old_port1 = vnet_buffer (b1)->ip.reass.l4_dst_port;
1093 new_port1 = udp1->dst_port = s1->in2out.port;
1094 if (PREDICT_FALSE (udp1->checksum))
1097 sum1 = udp1->checksum;
1099 ip_csum_update (sum1, old_addr1, new_addr1,
1101 dst_address /* changed member */ );
1103 ip_csum_update (sum1, old_port1, new_port1,
1104 ip4_header_t /* cheat */ ,
1105 length /* changed member */ );
1106 udp1->checksum = ip_csum_fold (sum1);
1109 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.udp,
1110 thread_index, sw_if_index1, 1);
1114 nat44_ei_session_update_counters (
1115 s1, now, vlib_buffer_length_in_chain (vm, b1), thread_index);
1116 /* Per-user LRU list maintenance */
1117 nat44_session_update_lru (sm, s1, thread_index);
1120 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1121 && (b1->flags & VLIB_BUFFER_IS_TRACED)))
1123 snat_out2in_trace_t *t = vlib_add_trace (vm, node, b1, sizeof (*t));
1124 t->sw_if_index = sw_if_index1;
1125 t->next_index = next1;
1126 t->session_index = ~0;
1129 s1 - sm->per_thread_data[thread_index].sessions;
1132 if (next1 == SNAT_OUT2IN_NEXT_DROP)
1134 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.drops,
1135 thread_index, sw_if_index1, 1);
1144 while (n_left_from > 0)
1147 u32 next0 = SNAT_OUT2IN_NEXT_LOOKUP;
1151 u32 new_addr0, old_addr0;
1152 u16 new_port0, old_port0;
1155 icmp46_header_t *icmp0;
1158 snat_session_t *s0 = 0;
1159 clib_bihash_kv_8_8_t kv0, value0;
1161 ip4_address_t sm_addr0;
1168 vnet_buffer (b0)->snat.flags = 0;
1170 ip0 = vlib_buffer_get_current (b0);
1171 udp0 = ip4_next_header (ip0);
1172 tcp0 = (tcp_header_t *) udp0;
1173 icmp0 = (icmp46_header_t *) udp0;
1175 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1176 rx_fib_index0 = vec_elt (sm->ip4_main->fib_index_by_sw_if_index,
1179 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1181 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1183 if (nat_out2in_sm_unknown_proto (sm, b0, ip0, rx_fib_index0))
1185 if (!sm->forwarding_enabled)
1188 node->errors[SNAT_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
1189 next0 = SNAT_OUT2IN_NEXT_DROP;
1192 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.other,
1193 thread_index, sw_if_index0, 1);
1197 if (PREDICT_FALSE (ip0->ttl == 1))
1199 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1200 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1201 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1203 next0 = SNAT_OUT2IN_NEXT_ICMP_ERROR;
1207 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1209 next0 = icmp_out2in_slow_path
1210 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
1211 next0, now, thread_index, &s0);
1212 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.icmp,
1213 thread_index, sw_if_index0, 1);
1217 init_nat_k (&kv0, ip0->dst_address,
1218 vnet_buffer (b0)->ip.reass.l4_dst_port, rx_fib_index0,
1221 if (clib_bihash_search_8_8 (&sm->out2in, &kv0, &value0))
1223 /* Try to match static mapping by external address and port,
1224 destination address and port in packet */
1225 if (nat44_ei_static_mapping_match (
1226 ip0->dst_address, vnet_buffer (b0)->ip.reass.l4_dst_port,
1227 rx_fib_index0, proto0, &sm_addr0, &sm_port0, &sm_fib_index0, 1,
1231 * Send DHCP packets to the ipv4 stack, or we won't
1232 * be able to use dhcp client on the outside interface
1235 (proto0 == NAT_PROTOCOL_UDP
1236 && (vnet_buffer (b0)->ip.reass.l4_dst_port ==
1237 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client))))
1239 vnet_feature_next (&next0, b0);
1243 if (!sm->forwarding_enabled)
1245 b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1246 next0 = SNAT_OUT2IN_NEXT_DROP;
1251 if (PREDICT_FALSE (identity_nat0))
1254 /* Create session initiated by host from external network */
1255 s0 = create_session_for_static_mapping (sm, b0,
1259 vnet_buffer (b0)->ip.
1261 rx_fib_index0, proto0, node,
1265 next0 = SNAT_OUT2IN_NEXT_DROP;
1270 s0 = pool_elt_at_index (sm->per_thread_data[thread_index].sessions,
1271 nat_value_get_session_index (&value0));
1273 old_addr0 = ip0->dst_address.as_u32;
1274 ip0->dst_address = s0->in2out.addr;
1275 new_addr0 = ip0->dst_address.as_u32;
1276 vnet_buffer (b0)->sw_if_index[VLIB_TX] = s0->in2out.fib_index;
1278 sum0 = ip0->checksum;
1279 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1280 ip4_header_t, dst_address /* changed member */ );
1281 ip0->checksum = ip_csum_fold (sum0);
1283 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1285 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1287 old_port0 = vnet_buffer (b0)->ip.reass.l4_dst_port;
1288 new_port0 = udp0->dst_port = s0->in2out.port;
1290 sum0 = tcp0->checksum;
1291 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1293 dst_address /* changed member */ );
1295 sum0 = ip_csum_update (sum0, old_port0, new_port0,
1296 ip4_header_t /* cheat */ ,
1297 length /* changed member */ );
1298 tcp0->checksum = ip_csum_fold (sum0);
1300 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.tcp,
1301 thread_index, sw_if_index0, 1);
1305 if (!vnet_buffer (b0)->ip.reass.is_non_first_fragment)
1307 old_port0 = vnet_buffer (b0)->ip.reass.l4_dst_port;
1308 new_port0 = udp0->dst_port = s0->in2out.port;
1309 if (PREDICT_FALSE (udp0->checksum))
1311 sum0 = udp0->checksum;
1312 sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t, dst_address /* changed member */
1315 ip_csum_update (sum0, old_port0, new_port0,
1316 ip4_header_t /* cheat */ ,
1317 length /* changed member */ );
1318 udp0->checksum = ip_csum_fold (sum0);
1321 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.udp,
1322 thread_index, sw_if_index0, 1);
1326 nat44_ei_session_update_counters (
1327 s0, now, vlib_buffer_length_in_chain (vm, b0), thread_index);
1328 /* Per-user LRU list maintenance */
1329 nat44_session_update_lru (sm, s0, thread_index);
1332 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1333 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1335 snat_out2in_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
1336 t->sw_if_index = sw_if_index0;
1337 t->next_index = next0;
1338 t->session_index = ~0;
1341 s0 - sm->per_thread_data[thread_index].sessions;
1344 if (next0 == SNAT_OUT2IN_NEXT_DROP)
1346 vlib_increment_simple_counter (&sm->counters.slowpath.out2in.drops,
1347 thread_index, sw_if_index0, 1);
1355 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1358 return frame->n_vectors;
1362 VLIB_REGISTER_NODE (snat_out2in_node) = {
1363 .name = "nat44-out2in",
1364 .vector_size = sizeof (u32),
1365 .format_trace = format_snat_out2in_trace,
1366 .type = VLIB_NODE_TYPE_INTERNAL,
1368 .n_errors = ARRAY_LEN(snat_out2in_error_strings),
1369 .error_strings = snat_out2in_error_strings,
1371 .runtime_data_bytes = sizeof (snat_runtime_t),
1373 .n_next_nodes = SNAT_OUT2IN_N_NEXT,
1375 /* edit / add dispositions here */
1377 [SNAT_OUT2IN_NEXT_DROP] = "error-drop",
1378 [SNAT_OUT2IN_NEXT_LOOKUP] = "ip4-lookup",
1379 [SNAT_OUT2IN_NEXT_ICMP_ERROR] = "ip4-icmp-error",
1384 VLIB_NODE_FN (snat_out2in_fast_node) (vlib_main_t * vm,
1385 vlib_node_runtime_t * node,
1386 vlib_frame_t * frame)
1388 u32 n_left_from, *from;
1389 snat_main_t *sm = &snat_main;
1391 from = vlib_frame_vector_args (frame);
1392 n_left_from = frame->n_vectors;
1394 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
1395 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
1396 vlib_get_buffers (vm, from, b, n_left_from);
1397 while (n_left_from > 0)
1400 u32 next0 = SNAT_OUT2IN_NEXT_DROP;
1404 u32 new_addr0, old_addr0;
1405 u16 new_port0, old_port0;
1408 icmp46_header_t *icmp0;
1411 ip4_address_t sm_addr0;
1418 ip0 = vlib_buffer_get_current (b0);
1419 udp0 = ip4_next_header (ip0);
1420 tcp0 = (tcp_header_t *) udp0;
1421 icmp0 = (icmp46_header_t *) udp0;
1423 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
1424 rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
1426 vnet_feature_next (&next0, b0);
1428 if (PREDICT_FALSE (ip0->ttl == 1))
1430 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
1431 icmp4_error_set_vnet_buffer (b0, ICMP4_time_exceeded,
1432 ICMP4_time_exceeded_ttl_exceeded_in_transit,
1434 next0 = SNAT_OUT2IN_NEXT_ICMP_ERROR;
1438 proto0 = ip_proto_to_nat_proto (ip0->protocol);
1440 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_OTHER))
1443 if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
1445 next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
1446 rx_fib_index0, node, next0, ~0, 0, 0);
1450 if (nat44_ei_static_mapping_match (ip0->dst_address, udp0->dst_port,
1451 rx_fib_index0, proto0, &sm_addr0,
1452 &sm_port0, &sm_fib_index0, 1, 0, 0))
1454 b0->error = node->errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1458 new_addr0 = sm_addr0.as_u32;
1459 new_port0 = sm_port0;
1460 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sm_fib_index0;
1461 old_addr0 = ip0->dst_address.as_u32;
1462 ip0->dst_address.as_u32 = new_addr0;
1464 sum0 = ip0->checksum;
1465 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1466 ip4_header_t, dst_address /* changed member */ );
1467 ip0->checksum = ip_csum_fold (sum0);
1469 if (PREDICT_FALSE (new_port0 != udp0->dst_port))
1471 old_port0 = udp0->dst_port;
1472 udp0->dst_port = new_port0;
1474 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1476 sum0 = tcp0->checksum;
1477 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1479 dst_address /* changed member */ );
1480 sum0 = ip_csum_update (sum0, old_port0, new_port0,
1481 ip4_header_t /* cheat */ ,
1482 length /* changed member */ );
1483 tcp0->checksum = ip_csum_fold (sum0);
1485 else if (udp0->checksum)
1487 sum0 = udp0->checksum;
1488 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1490 dst_address /* changed member */ );
1491 sum0 = ip_csum_update (sum0, old_port0, new_port0,
1492 ip4_header_t /* cheat */ ,
1493 length /* changed member */ );
1494 udp0->checksum = ip_csum_fold (sum0);
1499 if (PREDICT_TRUE (proto0 == NAT_PROTOCOL_TCP))
1501 sum0 = tcp0->checksum;
1502 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1504 dst_address /* changed member */ );
1505 tcp0->checksum = ip_csum_fold (sum0);
1507 else if (udp0->checksum)
1509 sum0 = udp0->checksum;
1510 sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
1512 dst_address /* changed member */ );
1513 udp0->checksum = ip_csum_fold (sum0);
1519 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1520 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1522 snat_out2in_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
1523 t->sw_if_index = sw_if_index0;
1524 t->next_index = next0;
1527 if (next0 == SNAT_OUT2IN_NEXT_DROP)
1529 vlib_increment_simple_counter (&sm->counters.fastpath.out2in.drops,
1530 vm->thread_index, sw_if_index0, 1);
1538 vlib_buffer_enqueue_to_next (vm, node, from, (u16 *) nexts,
1541 return frame->n_vectors;
1545 VLIB_REGISTER_NODE (snat_out2in_fast_node) = {
1546 .name = "nat44-out2in-fast",
1547 .vector_size = sizeof (u32),
1548 .format_trace = format_snat_out2in_fast_trace,
1549 .type = VLIB_NODE_TYPE_INTERNAL,
1551 .n_errors = ARRAY_LEN(snat_out2in_error_strings),
1552 .error_strings = snat_out2in_error_strings,
1554 .runtime_data_bytes = sizeof (snat_runtime_t),
1556 .n_next_nodes = SNAT_OUT2IN_N_NEXT,
1558 /* edit / add dispositions here */
1560 [SNAT_OUT2IN_NEXT_LOOKUP] = "ip4-lookup",
1561 [SNAT_OUT2IN_NEXT_DROP] = "error-drop",
1562 [SNAT_OUT2IN_NEXT_ICMP_ERROR] = "ip4-icmp-error",
1568 * fd.io coding-style-patch-verification: ON
1571 * eval: (c-set-style "gnu")