FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
nat.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 /**
16  * @file NAT plugin global declarations
17  */
18 #ifndef __included_nat_h__
19 #define __included_nat_h__
20 
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/ip/icmp46_packet.h>
25 #include <vnet/api_errno.h>
26 #include <vppinfra/elog.h>
27 #include <vppinfra/bihash_8_8.h>
28 #include <vppinfra/bihash_16_8.h>
29 #include <vppinfra/dlist.h>
30 #include <vppinfra/error.h>
31 #include <vlibapi/api.h>
32 #include <vlib/log.h>
33 
34 /* default session timeouts */
35 #define SNAT_UDP_TIMEOUT 300
36 #define SNAT_TCP_TRANSITORY_TIMEOUT 240
37 #define SNAT_TCP_ESTABLISHED_TIMEOUT 7440
38 #define SNAT_ICMP_TIMEOUT 60
39 
40 /* number of worker handoff frame queue elements */
41 #define NAT_FQ_NELTS 64
42 
43 /* NAT buffer flags */
44 #define SNAT_FLAG_HAIRPINNING (1 << 0)
45 
46 typedef struct
47 {
50 
51 typedef enum
52 {
66 } nat_next_t;
67 
68 typedef struct
69 {
72 
73 #define nat_buffer_opaque(b) \
74  ((nat_buffer_opaque_t *)((vnet_buffer_opaque2_t *)b->opaque2)->__unused2)
75 
76 /*
77 STATIC_ASSERT (sizeof (nat_buffer_opaque_t) <=
78  STRUCT_SIZE_OF (vnet_buffer_opaque_t, unused),
79  "Custom meta-data too large for vnet_buffer_opaque_t");
80 
81 #define nat_buffer_opaque(b) \
82  ((nat_buffer_opaque_t *)((u8 *)((b)->opaque) + \
83  STRUCT_OFFSET_OF (vnet_buffer_opaque_t, unused)))*/
84 
85 /* session key (4-tuple) */
86 typedef struct
87 {
88  union
89  {
90  struct
91  {
94  u16 protocol:3, fib_index:13;
95  };
97  };
99 
100 /* endpoint-dependent session key (6-tuple) */
101 typedef struct
102 {
103  union
104  {
105  struct
106  {
109  u32 proto:8, fib_index:24;
112  };
114  };
116 
117 /* deterministic session outside key */
118 typedef struct
119 {
120  union
121  {
122  struct
123  {
127  };
129  };
131 
132 /* user (internal host) key */
133 typedef struct
134 {
135  union
136  {
137  struct
138  {
141  };
143  };
145 
146 typedef struct
147 {
152 
153 /* NAT API Configuration flags */
154 #define foreach_nat_config_flag \
155  _(0x01, IS_TWICE_NAT) \
156  _(0x02, IS_SELF_TWICE_NAT) \
157  _(0x04, IS_OUT2IN_ONLY) \
158  _(0x08, IS_ADDR_ONLY) \
159  _(0x10, IS_OUTSIDE) \
160  _(0x20, IS_INSIDE) \
161  _(0x40, IS_STATIC) \
162  _(0x80, IS_EXT_HOST_VALID) \
163 
165 {
166 #define _(n,f) NAT_API_##f = n,
168 #undef _
170 
171 /* External address and port allocation modes */
172 #define foreach_nat_addr_and_port_alloc_alg \
173  _(0, DEFAULT, "default") \
174  _(1, MAPE, "map-e") \
175  _(2, RANGE, "port-range")
176 
177 typedef enum
178 {
179 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v,
181 #undef _
183 
184 
185 /* Supported L4 protocols */
186 #define foreach_snat_protocol \
187  _(UDP, 0, udp, "udp") \
188  _(TCP, 1, tcp, "tcp") \
189  _(ICMP, 2, icmp, "icmp")
190 
191 typedef enum
192 {
193 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i,
195 #undef _
197 
198 
199 /* Session state */
200 #define foreach_snat_session_state \
201  _(0, UNKNOWN, "unknown") \
202  _(1, UDP_ACTIVE, "udp-active") \
203  _(2, TCP_SYN_SENT, "tcp-syn-sent") \
204  _(3, TCP_ESTABLISHED, "tcp-established") \
205  _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
206  _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
207  _(6, TCP_CLOSING, "tcp-closing") \
208  _(7, TCP_LAST_ACK, "tcp-last-ack") \
209  _(8, TCP_CLOSED, "tcp-closed") \
210  _(9, ICMP_ACTIVE, "icmp-active")
211 
212 typedef enum
213 {
214 #define _(v, N, s) SNAT_SESSION_##N = v,
216 #undef _
218 
219 #define foreach_nat_in2out_ed_error \
220 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
221 _(IN2OUT_PACKETS, "good in2out packets processed") \
222 _(OUT_OF_PORTS, "out of ports") \
223 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
224 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
225 _(DROP_FRAGMENT, "drop fragment") \
226 _(MAX_REASS, "maximum reassemblies exceeded") \
227 _(MAX_FRAG, "maximum fragments per reassembly exceeded")\
228 _(NON_SYN, "non-SYN packet try to create session") \
229 _(TCP_PACKETS, "TCP packets") \
230 _(UDP_PACKETS, "UDP packets") \
231 _(ICMP_PACKETS, "ICMP packets") \
232 _(OTHER_PACKETS, "other protocol packets") \
233 _(FRAGMENTS, "fragments") \
234 _(CACHED_FRAGMENTS, "cached fragments") \
235 _(PROCESSED_FRAGMENTS, "processed fragments")
236 
237 typedef enum
238 {
239 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
241 #undef _
244 
245 #define foreach_nat_out2in_ed_error \
246 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
247 _(OUT2IN_PACKETS, "good out2in packets processed") \
248 _(OUT_OF_PORTS, "out of ports") \
249 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
250 _(NO_TRANSLATION, "no translation") \
251 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
252 _(DROP_FRAGMENT, "drop fragment") \
253 _(MAX_REASS, "maximum reassemblies exceeded") \
254 _(MAX_FRAG, "maximum fragments per reassembly exceeded")\
255 _(NON_SYN, "non-SYN packet try to create session") \
256 _(TCP_PACKETS, "TCP packets") \
257 _(UDP_PACKETS, "UDP packets") \
258 _(ICMP_PACKETS, "ICMP packets") \
259 _(OTHER_PACKETS, "other protocol packets") \
260 _(FRAGMENTS, "fragments") \
261 _(CACHED_FRAGMENTS, "cached fragments") \
262 _(PROCESSED_FRAGMENTS, "processed fragments")
263 
264 typedef enum
265 {
266 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
268 #undef _
271 
272 
273 /* Endpoint dependent TCP session state */
274 #define NAT44_SES_I2O_FIN 1
275 #define NAT44_SES_O2I_FIN 2
276 #define NAT44_SES_I2O_FIN_ACK 4
277 #define NAT44_SES_O2I_FIN_ACK 8
278 #define NAT44_SES_I2O_SYN 16
279 #define NAT44_SES_O2I_SYN 32
280 #define NAT44_SES_RST 64
281 
282 /* Session flags */
283 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1
284 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO 2
285 #define SNAT_SESSION_FLAG_LOAD_BALANCING 4
286 #define SNAT_SESSION_FLAG_TWICE_NAT 8
287 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT 16
288 #define SNAT_SESSION_FLAG_FWD_BYPASS 32
289 #define SNAT_SESSION_FLAG_AFFINITY 64
290 #define SNAT_SESSION_FLAG_OUTPUT_FEATURE 128
291 
292 /* NAT interface flags */
293 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
294 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
295 
296 /* Static mapping flags */
297 #define NAT_STATIC_MAPPING_FLAG_ADDR_ONLY 1
298 #define NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY 2
299 #define NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT 4
300 #define NAT_STATIC_MAPPING_FLAG_LB 8
301 
302 /* *INDENT-OFF* */
303 typedef CLIB_PACKED(struct
304 {
305  /* Outside network key */
306  snat_session_key_t out2in;
307 
308  /* Inside network key */
309  snat_session_key_t in2out;
310 
311  /* Flags */
312  u32 flags;
313 
314  /* Per-user translations */
315  u32 per_user_index;
316  u32 per_user_list_head_index;
317 
318  /* Last heard timer */
319  f64 last_heard;
320 
321  /* Last HA refresh */
322  f64 ha_last_refreshed;
323 
324  /* Counters */
325  u64 total_bytes;
326  u32 total_pkts;
327 
328  /* External host address and port */
329  ip4_address_t ext_host_addr;
330  u16 ext_host_port;
331 
332  /* External host address and port after translation */
333  ip4_address_t ext_host_nat_addr;
334  u16 ext_host_nat_port;
335 
336  /* TCP session state */
337  u8 state;
338  u32 i2o_fin_seq;
339  u32 o2i_fin_seq;
340 
341  /* user index */
342  u32 user_index;
343 }) snat_session_t;
344 /* *INDENT-ON* */
345 
346 
347 typedef struct
348 {
354 } snat_user_t;
355 
356 typedef struct
357 {
360 /* *INDENT-OFF* */
361 #define _(N, i, n, s) \
362  u16 busy_##n##_ports; \
363  u16 * busy_##n##_ports_per_thread; \
364  uword * busy_##n##_port_bitmap;
366 #undef _
367 /* *INDENT-ON* */
368 } snat_address_t;
369 
370 typedef struct
371 {
375 
376 typedef struct
377 {
378  /* Inside network port */
380  /* Outside network address and port */
382  /* Session state */
384  /* Expire timeout */
387 
388 typedef struct
389 {
390  /* inside IP address range */
393  /* outside IP address range */
396  /* inside IP addresses / outside IP addresses */
398  /* number of ports available to internal host */
400  /* session counter */
402  /* vector of sessions */
405 
406 typedef struct
407 {
408  /* backend IP address */
410  /* backend port number */
412  /* probability of the backend to be randomly matched */
415  /* backend FIB table */
419 
420 typedef enum
421 {
422  /* twice-nat disabled */
424  /* twice-nat enabled */
426  /* twice-nat only when src IP equals dst IP after translation */
429 
430 typedef enum
431 {
432  /* no load-balancing */
434  /* load-balancing */
436  /* load-balancing with affinity */
438 } lb_nat_type_t;
439 
440 typedef struct
441 {
442  /* local IP address */
444  /* external IP address */
446  /* local port */
448  /* external port */
450  /* is twice-nat */
451  twice_nat_type_t twice_nat;
452  /* local FIB table */
455  /* protocol */
456  snat_protocol_t proto;
457  /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
459  /* worker threads used by backends/local host */
461  /* opaque string tag */
462  u8 *tag;
463  /* backends for load-balancing mode */
465  /* affinity per service lis */
467  /* flags */
470 
471 typedef struct
472 {
476 
477 typedef struct
478 {
484  snat_protocol_t proto;
488  int is_add;
491  u8 *tag;
493 
494 typedef struct
495 {
496  /* Main lookup tables */
497  clib_bihash_8_8_t out2in;
498  clib_bihash_8_8_t in2out;
499 
500  /* Endpoint dependent sessions lookup tables */
501  clib_bihash_16_8_t out2in_ed;
502  clib_bihash_16_8_t in2out_ed;
503 
504  /* Find-a-user => src address lookup */
505  clib_bihash_8_8_t user_hash;
506 
507  /* User pool */
509 
510  /* Session pool */
511  snat_session_t *sessions;
512 
513  /* Pool of doubly-linked list elements */
515 
516  /* NAT thread index */
518 
519  /* real thread index */
522 
523 struct snat_main_s;
524 
525 /* ICMP session match function */
527  vlib_node_runtime_t * node,
528  u32 thread_index,
529  vlib_buffer_t * b0,
530  ip4_header_t * ip0, u8 * p_proto,
531  snat_session_key_t * p_value,
532  u8 * p_dont_translate, void *d,
533  void *e);
534 
535 /* Return worker thread index for given packet */
537  u32 rx_fib_index, u8 is_output);
538 
539 /* NAT address and port allacotaion function */
540 typedef int (nat_alloc_out_addr_and_port_function_t) (snat_address_t *
541  addresses,
542  u32 fib_index,
543  u32 thread_index,
544  snat_session_key_t * k,
546  u32 snat_thread_index);
547 
548 typedef struct snat_main_s
549 {
550  /* ICMP session match functions */
553 
554  /* Thread settings */
562 
563  /* Per thread data */
565 
566  /* Find a static mapping by local */
567  clib_bihash_8_8_t static_mapping_by_local;
568 
569  /* Find a static mapping by external */
570  clib_bihash_8_8_t static_mapping_by_external;
571 
572  /* Static mapping pool */
574 
575  /* Interface pool */
578 
579  /* Vector of outside addresses */
580  snat_address_t *addresses;
581  /* Address and port allocation function */
583  /* Address and port allocation type */
584  nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg;
585  /* Port set parameters (MAP-E) */
589  /* Port range parameters */
592 
593  /* vector of outside fibs */
595 
596  /* Vector of twice NAT addresses for extenal hosts */
597  snat_address_t *twice_nat_addresses;
598 
599  /* sw_if_indices whose intfc addresses should be auto-added */
602 
603  /* vector of interface address static mappings to resolve. */
605 
606  /* Randomize port allocation order */
608 
609  /* Worker handoff frame-queue index */
613 
614  /* node indexes */
616 
617  /* handoff fq nodes */
621 
622  /* respect feature arc nodes */
625 
643 
650 
651 
652  /* Deterministic NAT mappings */
654 
655  /* If forwarding is enabled */
657 
658  /* Config parameters */
674 
675  /* values of various timeouts */
680 
681  /* TCP MSS clamping */
684 
685  /* counters/gauges */
688 
689  /* API message ID base */
691 
692  /* log class */
694  /* logging level */
696 
697  /* convenience */
703 } snat_main_t;
704 
705 typedef struct
706 {
710 
711 typedef struct
712 {
716 
717 extern snat_main_t snat_main;
718 
719 // nat pre ed next_node feature classification
723 
744 
745 /* format functions */
756 /* unformat functions */
758 
759 /** \brief Check if SNAT session is created from static mapping.
760  @param s SNAT session
761  @return 1 if SNAT session is created from static mapping otherwise 0
762 */
763 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
764 
765 /** \brief Check if SNAT session for unknown protocol.
766  @param s SNAT session
767  @return 1 if SNAT session for unknown protocol otherwise 0
768 */
769 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
770 
771 /** \brief Check if NAT session is twice NAT.
772  @param s NAT session
773  @return 1 if NAT session is twice NAT
774 */
775 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
776 
777 /** \brief Check if NAT session is load-balancing.
778  @param s NAT session
779  @return 1 if NAT session is load-balancing
780 */
781 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
782 
783 /** \brief Check if NAT session is forwarding bypass.
784  @param s NAT session
785  @return 1 if NAT session is load-balancing
786 */
787 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
788 
789 /** \brief Check if NAT session is endpoint dependent.
790  @param s NAT session
791  @return 1 if NAT session is endpoint dependent
792 */
793 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
794 
795 /** \brief Check if NAT session has affinity record.
796  @param s NAT session
797  @return 1 if NAT session has affinity record
798 */
799 #define is_affinity_sessions(s) (s->flags & SNAT_SESSION_FLAG_AFFINITY)
800 
801 /** \brief Check if NAT interface is inside.
802  @param i NAT interfce
803  @return 1 if inside interface
804 */
805 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
806 
807 /** \brief Check if NAT interface is outside.
808  @param i NAT interfce
809  @return 1 if outside interface
810 */
811 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
812 
813 /** \brief Check if NAT44 endpoint-dependent TCP session is closed.
814  @param s NAT session
815  @return 1 if session is closed
816 */
817 #define nat44_is_ses_closed(s) s->state == 0xf
818 
819 /** \brief Check if NAT static mapping is address only (1:1NAT).
820  @param sm NAT static mapping
821  @return 1 if 1:1NAT, 0 if 1:1NAPT
822 */
823 #define is_addr_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_ADDR_ONLY)
824 
825 /** \brief Check if NAT static mapping match only out2in direction.
826  @param sm NAT static mapping
827  @return 1 if rule match only out2in direction
828 */
829 #define is_out2in_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY)
830 
831 /** \brief Check if NAT static mapping is identity NAT.
832  @param sm NAT static mapping
833  @return 1 if identity NAT
834 */
835 #define is_identity_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT)
836 
837 /** \brief Check if NAT static mapping is load-balancing.
838  @param sm NAT static mapping
839  @return 1 if load-balancing
840 */
841 #define is_lb_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_LB)
842 
843 /** \brief Check if client initiating TCP connection (received SYN from client)
844  @param t TCP header
845  @return 1 if client initiating TCP connection
846 */
847 #define tcp_is_init(t) ((t->flags & TCP_FLAG_SYN) && !(t->flags & TCP_FLAG_ACK))
848 
849 /* logging */
850 #define nat_log_err(...) \
851  vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
852 #define nat_log_warn(...) \
853  vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
854 #define nat_log_notice(...) \
855  vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
856 #define nat_log_info(...) \
857  vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
858 #define nat_log_debug(...)\
859  vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
860 
861 /* NAT API Logging Levels */
862 #define foreach_nat_log_level \
863  _(0x00, LOG_NONE) \
864  _(0x01, LOG_ERROR) \
865  _(0x02, LOG_WARNING) \
866  _(0x03, LOG_NOTICE) \
867  _(0x04, LOG_INFO) \
868  _(0x05, LOG_DEBUG)
869 
870 typedef enum nat_log_level_t_
871 {
872 #define _(n,f) SNAT_##f = n,
874 #undef _
876 
877 #define nat_elog(_level, _str) \
878 do \
879  { \
880  snat_main_t *sm = &snat_main; \
881  if (PREDICT_FALSE (sm->log_level >= _level)) \
882  { \
883  ELOG_TYPE_DECLARE (e) = \
884  { \
885  .format = "nat-msg " _str, \
886  .format_args = "", \
887  }; \
888  ELOG_DATA (&sm->vlib_main->elog_main, e); \
889  } \
890  } while (0);
891 
892 #define nat_elog_addr(_level, _str, _addr) \
893 do \
894  { \
895  if (PREDICT_FALSE (sm->log_level >= _level)) \
896  { \
897  ELOG_TYPE_DECLARE (e) = \
898  { \
899  .format = "nat-msg " _str " %d.%d.%d.%d", \
900  .format_args = "i1i1i1i1", \
901  }; \
902  CLIB_PACKED(struct \
903  { \
904  u8 oct1; \
905  u8 oct2; \
906  u8 oct3; \
907  u8 oct4; \
908  }) *ed; \
909  ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
910  ed->oct4 = _addr >> 24; \
911  ed->oct3 = _addr >> 16; \
912  ed->oct2 = _addr >> 8; \
913  ed->oct1 = _addr; \
914  } \
915  } while (0);
916 
917 #define nat_elog_debug_handoff(_str, _tid, _fib, _src, _dst) \
918 do \
919  { \
920  if (PREDICT_FALSE (sm->log_level >= SNAT_LOG_DEBUG)) \
921  { \
922  ELOG_TYPE_DECLARE (e) = \
923  { \
924  .format = "nat-msg " _str " ip src: %d.%d.%d.%d dst: %d.%d.%d.%d" \
925  " tid from: %d to: %d fib: %d", \
926  .format_args = "i1i1i1i1i1i1i1i1i4i4i4", \
927  }; \
928  CLIB_PACKED(struct \
929  { \
930  u8 src_oct1; \
931  u8 src_oct2; \
932  u8 src_oct3; \
933  u8 src_oct4; \
934  u8 dst_oct1; \
935  u8 dst_oct2; \
936  u8 dst_oct3; \
937  u8 dst_oct4; \
938  u32 ftid; \
939  u32 ttid; \
940  u32 fib; \
941  }) *ed; \
942  ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
943  ed->src_oct1 = _src >> 24; \
944  ed->src_oct2 = _src >> 16; \
945  ed->src_oct3 = _src >> 8; \
946  ed->src_oct4 = _src; \
947  ed->dst_oct1 = _dst >> 24; \
948  ed->dst_oct2 = _dst >> 16; \
949  ed->dst_oct3 = _dst >> 8; \
950  ed->dst_oct4 = _dst; \
951  ed->ftid = vlib_get_thread_index (); \
952  ed->ttid = _tid; \
953  ed->fib = _fib; \
954  } \
955  } while (0);
956 
957 #define nat_elog_debug_handoff_v2(_str, _prt, _fib, _src, _dst) \
958 do \
959  { \
960  if (PREDICT_FALSE (sm->log_level >= SNAT_LOG_DEBUG)) \
961  { \
962  ELOG_TYPE_DECLARE (e) = \
963  { \
964  .format = "nat-msg " _str " ip_src:%d.%d.%d.%d ip_dst:%d.%d.%d.%d" \
965  " tid:%d prt:%d fib:%d", \
966  .format_args = "i1i1i1i1i1i1i1i1i4i4i4", \
967  }; \
968  CLIB_PACKED(struct \
969  { \
970  u8 src_oct1; \
971  u8 src_oct2; \
972  u8 src_oct3; \
973  u8 src_oct4; \
974  u8 dst_oct1; \
975  u8 dst_oct2; \
976  u8 dst_oct3; \
977  u8 dst_oct4; \
978  u32 tid; \
979  u32 prt; \
980  u32 fib; \
981  }) *ed; \
982  ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
983  ed->src_oct1 = _src >> 24; \
984  ed->src_oct2 = _src >> 16; \
985  ed->src_oct3 = _src >> 8; \
986  ed->src_oct4 = _src; \
987  ed->dst_oct1 = _dst >> 24; \
988  ed->dst_oct2 = _dst >> 16; \
989  ed->dst_oct3 = _dst >> 8; \
990  ed->dst_oct4 = _dst; \
991  ed->tid = vlib_get_thread_index (); \
992  ed->prt = _prt; \
993  ed->fib = _fib; \
994  } \
995  } while (0);
996 
997 #define nat_elog_X1(_level, _fmt, _arg, _val1) \
998 do \
999  { \
1000  snat_main_t *sm = &snat_main; \
1001  if (PREDICT_FALSE (sm->log_level >= _level)) \
1002  { \
1003  ELOG_TYPE_DECLARE (e) = \
1004  { \
1005  .format = "nat-msg " _fmt, \
1006  .format_args = _arg, \
1007  }; \
1008  CLIB_PACKED(struct \
1009  { \
1010  typeof (_val1) val1; \
1011  }) *ed; \
1012  ed = ELOG_DATA (&sm->vlib_main->elog_main, e); \
1013  ed->val1 = _val1; \
1014  } \
1015  } while (0);
1016 
1017 #define nat_elog_notice(nat_elog_str) \
1018  nat_elog(SNAT_LOG_INFO, "[notice] " nat_elog_str)
1019 #define nat_elog_warn(nat_elog_str) \
1020  nat_elog(SNAT_LOG_WARNING, "[warning] " nat_elog_str)
1021 #define nat_elog_err(nat_elog_str) \
1022  nat_elog(SNAT_LOG_ERROR, "[error] " nat_elog_str)
1023 #define nat_elog_debug(nat_elog_str) \
1024  nat_elog(SNAT_LOG_DEBUG, "[debug] " nat_elog_str)
1025 #define nat_elog_info(nat_elog_str) \
1026  nat_elog(SNAT_LOG_INFO, "[info] " nat_elog_str)
1027 
1028 #define nat_elog_notice_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
1029  nat_elog_X1(SNAT_LOG_NOTICE, "[notice] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
1030 #define nat_elog_warn_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
1031  nat_elog_X1(SNAT_LOG_WARNING, "[warning] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
1032 #define nat_elog_err_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
1033  nat_elog_X1(SNAT_LOG_ERROR, "[error] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
1034 #define nat_elog_debug_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
1035  nat_elog_X1(SNAT_LOG_DEBUG, "[debug] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
1036 #define nat_elog_info_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
1037  nat_elog_X1(SNAT_LOG_INFO, "[info] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
1038 
1039 /* ICMP session match functions */
1041  u32 thread_index, vlib_buffer_t * b0,
1042  ip4_header_t * ip0, u8 * p_proto,
1043  snat_session_key_t * p_value,
1044  u8 * p_dont_translate, void *d, void *e);
1046  u32 thread_index, vlib_buffer_t * b0,
1047  ip4_header_t * ip0, u8 * p_proto,
1048  snat_session_key_t * p_value,
1049  u8 * p_dont_translate, void *d, void *e);
1051  u32 thread_index, vlib_buffer_t * b0,
1052  ip4_header_t * ip0, u8 * p_proto,
1053  snat_session_key_t * p_value,
1054  u8 * p_dont_translate, void *d, void *e);
1056  u32 thread_index, vlib_buffer_t * b0,
1057  ip4_header_t * ip0, u8 * p_proto,
1058  snat_session_key_t * p_value,
1059  u8 * p_dont_translate, void *d, void *e);
1060 
1061 /* ICMP deterministic NAT session match functions */
1063  u32 thread_index, vlib_buffer_t * b0,
1064  ip4_header_t * ip0, u8 * p_proto,
1065  snat_session_key_t * p_value,
1066  u8 * p_dont_translate, void *d, void *e);
1068  u32 thread_index, vlib_buffer_t * b0,
1069  ip4_header_t * ip0, u8 * p_proto,
1070  snat_session_key_t * p_value,
1071  u8 * p_dont_translate, void *d, void *e);
1072 
1073 /* ICMP endpoint-dependent session match functions */
1075  u32 thread_index, vlib_buffer_t * b0,
1076  ip4_header_t * ip0, u8 * p_proto,
1077  snat_session_key_t * p_value,
1078  u8 * p_dont_translate, void *d, void *e);
1080  u32 thread_index, vlib_buffer_t * b0,
1081  ip4_header_t * ip0, u8 * p_proto,
1082  snat_session_key_t * p_value,
1083  u8 * p_dont_translate, void *d, void *e);
1084 
1086  icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
1087  vlib_node_runtime_t * node, u32 next0, u32 thread_index,
1088  void *d, void *e);
1089 
1091  icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
1092  vlib_node_runtime_t * node, u32 next0, u32 thread_index,
1093  void *d, void *e);
1094 
1095 /* hairpinning functions */
1097  ip4_header_t * ip0, icmp46_header_t * icmp0,
1098  int is_ed);
1100  ip4_header_t * ip);
1102  ip4_header_t * ip);
1104  ip4_header_t * ip0, udp_header_t * udp0,
1105  tcp_header_t * tcp0, u32 proto0, int is_ed);
1107  ip4_header_t * ip0, u16 sport, u16 dport,
1108  u32 proto0, int is_ed);
1109 
1110 /* Call back functions for clib_bihash_add_or_overwrite_stale */
1115 
1116 /**
1117  * @brief Increment IPv4 address
1118  */
1120 
1121 /**
1122  * @brief Add external address to NAT44 pool
1123  *
1124  * @param addr IPv4 address
1125  * @param vrf_id VRF id of tenant, ~0 means independent of VRF
1126  * @param twice_nat 1 if twice NAT address
1127  *
1128  * @return 0 on success, non-zero value otherwise
1129  */
1130 int snat_add_address (snat_main_t * sm, ip4_address_t * addr, u32 vrf_id,
1131  u8 twice_nat);
1132 
1133 /**
1134  * @brief Delete external address from NAT44 pool
1135  *
1136  * @param addr IPv4 address
1137  * @param delete_sm 1 if delete static mapping using address
1138  * @param twice_nat 1 if twice NAT address
1139  *
1140  * @return 0 on success, non-zero value otherwise
1141  */
1142 int snat_del_address (snat_main_t * sm, ip4_address_t addr, u8 delete_sm,
1143  u8 twice_nat);
1144 
1145 /**
1146  * @brief Add/delete external address to FIB DPO (out2in DPO mode)
1147  *
1148  * @param addr IPv4 address
1149  * @param is_add 1 = add, 0 = delete
1150  *
1151  * @return 0 on success, non-zero value otherwise
1152  */
1154 
1155 /**
1156  * @brief Add/delete NAT44 static mapping
1157  *
1158  * @param l_addr local IPv4 address
1159  * @param e_addr external IPv4 address
1160  * @param l_port local port number
1161  * @param e_port external port number
1162  * @param vrf_id local VRF ID
1163  * @param addr_only 1 = 1:1NAT, 0 = 1:1NAPT
1164  * @param sw_if_index use interface address as external IPv4 address
1165  * @param proto L4 protocol
1166  * @param is_add 1 = add, 0 = delete
1167  * @param twice_nat twice-nat mode
1168  * @param out2in_only if 1 rule match only out2in direction
1169  * @param tag opaque string tag
1170  * @param identity_nat identity NAT
1171  *
1172  * @return 0 on success, non-zero value otherwise
1173  */
1175  u16 l_port, u16 e_port, u32 vrf_id,
1176  int addr_only, u32 sw_if_index,
1177  snat_protocol_t proto, int is_add,
1178  twice_nat_type_t twice_nat, u8 out2in_only,
1179  u8 * tag, u8 identity_nat);
1180 
1181 /**
1182  * @brief Add/delete static mapping with load-balancing (multiple backends)
1183  *
1184  * @param e_addr external IPv4 address
1185  * @param e_port external port number
1186  * @param proto L4 protocol
1187  * @param locals list of local backends
1188  * @param is_add 1 = add, 0 = delete
1189  * @param twice_nat twice-nat mode
1190  * @param out2in_only if 1 rule match only out2in direction
1191  * @param tag opaque string tag
1192  * @param affinity 0 = disabled, otherwise client IP affinity sticky time
1193  *
1194  * @return 0 on success, non-zero value otherwise
1195  */
1197  snat_protocol_t proto,
1198  nat44_lb_addr_port_t * locals, u8 is_add,
1199  twice_nat_type_t twice_nat,
1200  u8 out2in_only, u8 * tag, u32 affinity);
1201 
1203  ip4_address_t l_addr, u16 l_port,
1204  snat_protocol_t proto, u32 vrf_id,
1205  u8 probability, u8 is_add);
1206 
1208 
1209 /**
1210  * @brief Set NAT plugin workers
1211  *
1212  * @param bitmap NAT workers bitmap
1213  *
1214  * @return 0 on success, non-zero value otherwise
1215  */
1216 int snat_set_workers (uword * bitmap);
1217 
1218 /**
1219  * @brief Enable/disable NAT44 feature on the interface
1220  *
1221  * @param sw_if_index software index of the interface
1222  * @param is_inside 1 = inside, 0 = outside
1223  * @param is_del 1 = delete, 0 = add
1224  *
1225  * @return 0 on success, non-zero value otherwise
1226  */
1227 int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del);
1228 
1229 /**
1230  * @brief Enable/disable NAT44 output feature on the interface (postrouting NAT)
1231  *
1232  * @param sw_if_index software index of the interface
1233  * @param is_inside 1 = inside, 0 = outside
1234  * @param is_del 1 = delete, 0 = add
1235  *
1236  * @return 0 on success, non-zero value otherwise
1237  */
1239  int is_del);
1240 
1241 /**
1242  * @brief Add/delete NAT44 pool address from specific interfce
1243  *
1244  * @param sw_if_index software index of the interface
1245  * @param is_del 1 = delete, 0 = add
1246  * @param twice_nat 1 = twice NAT address for extenal hosts
1247  *
1248  * @return 0 on success, non-zero value otherwise
1249  */
1250 int snat_add_interface_address (snat_main_t * sm, u32 sw_if_index, int is_del,
1251  u8 twice_nat);
1252 
1253 /**
1254  * @brief Delete NAT44 session
1255  *
1256  * @param addr IPv4 address
1257  * @param port L4 port number
1258  * @param proto L4 protocol
1259  * @param vrf_id VRF ID
1260  * @param is_in 1 = inside network address and port pair, 0 = outside
1261  *
1262  * @return 0 on success, non-zero value otherwise
1263  */
1265  snat_protocol_t proto, u32 vrf_id, int is_in);
1266 
1267 /**
1268  * @brief Delete NAT44 endpoint-dependent session
1269  *
1270  * @param addr IPv4 address
1271  * @param port L4 port number
1272  * @param proto L4 protocol
1273  * @param vrf_id VRF ID
1274  * @param is_in 1 = inside network address and port pair, 0 = outside
1275  *
1276  * @return 0 on success, non-zero value otherwise
1277  */
1279  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
1280  u32 vrf_id, int is_in);
1281 
1282 /**
1283  * @brief Free NAT44 session data (lookup keys, external addrres port)
1284  *
1285  * @param s NAT session
1286  * @param thread_index thread index
1287  * @param is_ha is HA event
1288  */
1289 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
1290  u32 thread_index, u8 is_ha);
1291 
1292 /**
1293  * @brief Find or create NAT user
1294  *
1295  * @param addr IPv4 address
1296  * @param fib_index FIB table index
1297  * @param thread_index thread index
1298  *
1299  * @return NAT user data structure on success otherwise zero value
1300  */
1302  u32 fib_index, u32 thread_index);
1303 
1304 /**
1305  * @brief Allocate new NAT session or recycle last used
1306  *
1307  * @param u NAT user
1308  * @param thread_index thread index
1309  *
1310  * @return session data structure on success otherwise zero value
1311  */
1312 snat_session_t *nat_session_alloc_or_recycle (snat_main_t * sm,
1313  snat_user_t * u,
1314  u32 thread_index, f64 now);
1315 
1316 /**
1317  * @brief Allocate NAT endpoint-dependent session
1318  *
1319  * @param u NAT user
1320  * @param thread_index thread index
1321  *
1322  * @return session data structure on success otherwise zero value
1323  */
1324 snat_session_t *nat_ed_session_alloc (snat_main_t * sm, snat_user_t * u,
1325  u32 thread_index, f64 now);
1326 
1327 /**
1328  * @brief Set address and port assignment algorithm for MAP-E CE
1329  *
1330  * @param psid Port Set Identifier value
1331  * @param psid_offset number of offset bits
1332  * @param psid_length length of PSID
1333  */
1335  u16 psid_length);
1336 
1337 /**
1338  * @brief Set address and port assignment algorithm for port range
1339  *
1340  * @param start_port beginning of the port range
1341  * @param end_port end of the port range
1342  */
1344 
1345 /**
1346  * @brief Set address and port assignment algorithm to default/standard
1347  */
1349 
1350 /**
1351  * @brief Free outside address and port pair
1352  *
1353  * @param addresses vector of outside addresses
1354  * @param thread_index thread index
1355  * @param k address, port and protocol
1356  */
1357 void snat_free_outside_address_and_port (snat_address_t * addresses,
1358  u32 thread_index,
1359  snat_session_key_t * k);
1360 
1361 /**
1362  * @brief Alloc outside address and port
1363  *
1364  * @param addresses vector of outside addresses
1365  * @param fib_index FIB table index
1366  * @param thread_index thread index
1367  * @param k allocated address and port pair
1368  * @param port_per_thread number of ports per threead
1369  * @param snat_thread_index NAT thread index
1370  *
1371  * @return 0 on success, non-zero value otherwise
1372  */
1373 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
1374  u32 fib_index,
1375  u32 thread_index,
1376  snat_session_key_t * k,
1377  u16 port_per_thread,
1378  u32 snat_thread_index);
1379 
1380 /**
1381  * @brief Match NAT44 static mapping.
1382  *
1383  * @param match address and port to match
1384  * @param mapping external/local address and port of the matched mapping
1385  * @param by_external if 0 match by local address otherwise match by external
1386  * address
1387  * @param is_addr_only 1 if matched mapping is address only
1388  * @param twice_nat matched mapping is twice NAT type
1389  * @param lb 1 if matched mapping is load-balanced
1390  * @param ext_host_addr external host address
1391  *
1392  * @returns 0 if match found otherwise 1.
1393  */
1395  snat_session_key_t match,
1396  snat_session_key_t * mapping,
1397  u8 by_external,
1398  u8 * is_addr_only,
1399  twice_nat_type_t * twice_nat,
1400  lb_nat_type_t * lb,
1401  ip4_address_t * ext_host_addr,
1402  u8 * is_identity_nat);
1403 
1404 /**
1405  * @brief Add/del NAT address to FIB.
1406  *
1407  * Add the external NAT address to the FIB as receive entries. This ensures
1408  * that VPP will reply to ARP for this address and we don't need to enable
1409  * proxy ARP on the outside interface.
1410  *
1411  * @param addr IPv4 address
1412  * @param plen address prefix length
1413  * @param sw_if_index software index of the outside interface
1414  * @param is_add 0 = delete, 1 = add.
1415  */
1417  u8 p_len, u32 sw_if_index, int is_add);
1418 
1419 /*
1420  * Why is this here? Because we don't need to touch this layer to
1421  * simply reply to an icmp. We need to change id to a unique
1422  * value to NAT an echo request/reply.
1423  */
1424 
1425 typedef struct
1426 {
1430 
1431 typedef struct
1432 {
1435 
1436 #endif /* __included_nat_h__ */
1437 
1438 /*
1439  * fd.io coding-style-patch-verification: ON
1440  *
1441  * Local Variables:
1442  * eval: (c-set-style "gnu")
1443  * End:
1444  */
ip4_address_t external_addr
Definition: nat.h:445
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Delete external address from NAT44 pool.
Definition: nat.c:1640
u32 user_memory_size
Definition: nat.h:668
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:3584
#define foreach_nat_addr_and_port_alloc_alg
Definition: nat.h:172
nat_outside_fib_t * outside_fibs
Definition: nat.h:594
vlib_node_registration_t nat_default_node
(constructor) VLIB_REGISTER_NODE (nat_default_node)
Definition: nat.c:4313
vlib_node_registration_t snat_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_src_node)
nat_addr_and_port_alloc_alg_t
Definition: nat.h:177
u32 sessions_per_user_list_head_index
Definition: nat.h:351
u32 flags
Definition: vhost_user.h:141
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 feature on the interface.
Definition: nat.c:1754
u16 ext_host_port
Definition: nat.h:125
u32 icmp_out2in(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, u32 thread_index, void *d, void *e)
Definition: out2in.c:518
u32 hairpin_dst_node_index
Definition: nat.h:645
u32 ed_hairpinning_node_index
Definition: nat.h:647
a
Definition: bitmap.h:538
u32 icmp_timeout
Definition: nat.h:679
u32 fq_in2out_output_index
Definition: nat.h:611
u16 start_port
Definition: nat.h:590
u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
u32 ed_out2in_node_index
Definition: nat.h:638
u64 as_u64
Definition: bihash_doc.h:63
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
Allocate new NAT session or recycle last used.
Definition: nat.c:370
u32 nsessions
Definition: nat.h:352
#define foreach_snat_session_state
Definition: nat.h:200
unsigned long u64
Definition: types.h:89
ip4_address_t addr
Definition: nat.h:409
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Add/delete NAT44 pool address from specific interfce.
Definition: nat.c:4119
enum nat_log_level_t_ nat_log_level_t
snat_protocol_t proto
Definition: nat.h:456
u16 port_per_thread
Definition: nat.h:560
u32 ed_in2out_reass_node_index
Definition: nat.h:634
u32 nstaticsessions
Definition: nat.h:353
u32 ed_out2in_slowpath_node_index
Definition: nat.h:639
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: out2in.c:325
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
Definition: in2out_ed.c:2022
format_function_t format_det_map_ses
Definition: nat.h:750
#define foreach_nat_in2out_ed_error
Definition: nat.h:219
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
int nat44_i2o_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
Definition: in2out_ed.c:68
vlib_node_registration_t nat44_ed_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_src_node)
u32 fib_index
Definition: nat.h:350
format_function_t format_snat_static_mapping
Definition: nat.h:747
format_function_t format_snat_key
Definition: nat.h:751
snat_det_map_t * det_maps
Definition: nat.h:653
nat_log_level_t_
Definition: nat.h:870
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat.h:582
u32 num_snat_thread
Definition: nat.h:561
#define foreach_snat_protocol
Definition: nat.h:186
dlist_elt_t * list_pool
Definition: nat.h:514
u8 in_plen
Definition: nat.h:392
struct _tcp_header tcp_header_t
int snat_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, udp_header_t *udp0, tcp_header_t *tcp0, u32 proto0, int is_ed)
vhost_vring_addr_t addr
Definition: vhost_user.h:147
unsigned char u8
Definition: types.h:56
u8 deterministic
Definition: nat.h:661
u32 icmp_match_out2in_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: out2in_ed.c:438
u32 handoff_in2out_index
Definition: nat.h:619
u16 l_port
Definition: nat.h:110
nat44_lb_addr_port_t * locals
Definition: nat.h:464
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
Definition: nat.c:2161
u32 user_buckets
Definition: nat.h:667
double f64
Definition: types.h:142
clib_bihash_8_8_t user_hash
Definition: nat.h:505
u32 cached_sw_if_index
Definition: nat.h:713
u32 next_index
Definition: nat.h:70
void nat_set_alloc_addr_and_port_mape(u16 psid, u16 psid_offset, u16 psid_length)
Set address and port assignment algorithm for MAP-E CE.
Definition: nat.c:4274
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
u32 max_translations_per_user
Definition: nat.h:669
clib_bihash_8_8_t in2out
Definition: nat.h:498
Definition: nat.h:65
u32 in2out_reass_node_index
Definition: nat.h:631
u32 in2out_output_node_index
Definition: nat.h:627
u32 ed_in2out_node_index
Definition: nat.h:632
u32 vlib_log_class_t
Definition: vlib.h:51
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
u16 r_port
Definition: nat.h:111
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
Definition: out2in.c:1362
ip4_address_t ext_host_addr
Definition: nat.h:124
u32 det_in2out_node_index
Definition: nat.h:641
u32 translation_buckets
Definition: nat.h:664
lb_nat_type_t
Definition: nat.h:430
ip4_address_t addr
Definition: nat.h:349
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Add external address to NAT44 pool.
Definition: nat.c:552
ip4_main_t * ip4_main
Definition: nat.h:700
vhost_vring_state_t state
Definition: vhost_user.h:146
unsigned int u32
Definition: types.h:88
A collection of simple counters.
Definition: counter.h:57
vlib_node_registration_t snat_in2out_output_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_node)
Definition: in2out.c:1630
ip4_address_t local_addr
Definition: nat.h:443
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
snat_protocol_t proto
Definition: nat.h:484
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
Definition: out2in.c:1900
twice_nat_type_t twice_nat
Definition: nat.h:451
u32 max_translations
Definition: nat.h:666
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:601
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
Definition: out2in_ed.c:1947
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
u32 fib_index
Definition: nat.h:372
u16 mss_value_net
Definition: nat.h:683
u32 handoff_in2out_output_index
Definition: nat.h:620
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat.h:584
#define foreach_nat_out2in_ed_error
Definition: nat.h:245
clib_bihash_16_8_t out2in_ed
Definition: nat.h:501
snat_det_session_t * sessions
Definition: nat.h:403
u16 mss_clamping
Definition: nat.h:682
vlib_main_t * vlib_main
Definition: nat.h:698
unsigned short u16
Definition: types.h:57
u32 pre_in2out_node_index
Definition: nat.h:624
u16 protocol
Definition: nat.h:94
u8 out2in_dpo
Definition: nat.h:662
snat_static_mapping_t * static_mappings
Definition: nat.h:573
u32 inside_fib_index
Definition: nat.h:673
u32 udp_timeout
Definition: nat.h:676
u8 static_mapping_only
Definition: nat.h:659
int nat44_del_ed_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Delete NAT44 endpoint-dependent session.
Definition: nat.c:4230
vlib_node_registration_t nat44_ed_out2in_worker_handoff_node
nat_next_t
Definition: nat.h:51
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external addrres port)
Definition: nat.c:189
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
Definition: nat.c:4297
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, snat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
Definition: nat.c:1456
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
Definition: nat.c:524
u32 hairpin_src_node_index
Definition: nat.h:646
clib_bihash_8_8_t static_mapping_by_external
Definition: nat.h:570
u16 port
Definition: punt.api:40
u32 in2out_slowpath_output_node_index
Definition: nat.h:630
u8 psid_offset
Definition: nat.h:586
struct snat_main_s snat_main_t
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:233
u32 handoff_out2in_index
Definition: nat.h:618
api_main_t * api_main
Definition: nat.h:702
u8 out_plen
Definition: nat.h:395
u8 psid_length
Definition: nat.h:587
u32 refcount
Definition: nat.h:373
vnet_main_t * vnet_main
Definition: nat.h:699
u32 inside_vrf_id
Definition: nat.h:672
vlib_node_registration_t nat44_ed_in2out_worker_handoff_node
Definition: nat.h:435
u32 snat_icmp_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, int is_ed)
u8 log_level
Definition: nat.h:695
u32 fq_out2in_index
Definition: nat.h:612
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
int nat44_o2i_is_idle_session_cb(clib_bihash_kv_8_8_t *kv, void *arg)
Definition: out2in.c:116
snat_interface_t * output_feature_interfaces
Definition: nat.h:577
u16 src_port
Definition: nat.h:1433
u32 pre_out2in_node_index
Definition: nat.h:623
u32 ed_hairpin_src_node_index
Definition: nat.h:649
int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, snat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat)
Add/delete NAT44 static mapping.
Definition: nat.c:688
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
snat_main_t snat_main
Definition: nat.c:39
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
snat_session_state_t
Definition: nat.h:212
snat_user_t * users
Definition: nat.h:508
u32 random_seed
Definition: nat.h:607
u32 ed_out2in_reass_node_index
Definition: nat.h:640
clib_bihash_8_8_t out2in
Definition: nat.h:497
int nat44_o2i_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
Definition: out2in_ed.c:91
vlib_main_t * vm
Definition: buffer.c:323
u32 outside_vrf_id
Definition: nat.h:670
ip4_address_t l_addr
Definition: nat.h:107
u8 static_mapping_connection_tracking
Definition: nat.h:660
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:558
u16 end_port
Definition: nat.h:591
format_function_t format_snat_static_map_to_resolve
Definition: nat.h:748
u32 ed_in2out_slowpath_node_index
Definition: nat.h:633
u32 error_node_index
Definition: nat.h:615
u32 sharing_ratio
Definition: nat.h:397
ip4_address_t out_addr
Definition: nat.h:394
u16 psid
Definition: nat.h:588
u32 outside_fib_index
Definition: nat.h:671
format_function_t format_nat_addr_and_port_alloc_alg
Definition: nat.h:754
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat)
Match NAT44 static mapping.
Definition: nat.c:2548
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:33
ip4_address_t addr
Definition: nat.h:92
u32 ed_hairpin_dst_node_index
Definition: nat.h:648
u32 sw_if_index
Definition: nat.h:473
#define foreach_nat_config_flag
Definition: nat.h:154
snat_user_t * nat_user_get_or_create(snat_main_t *sm, ip4_address_t *addr, u32 fib_index, u32 thread_index)
Find or create NAT user.
Definition: nat.c:323
void increment_v4_address(ip4_address_t *a)
Increment IPv4 address.
Definition: nat.c:636
nat_out2in_ed_error_t
Definition: nat.h:264
u32 tcp_transitory_timeout
Definition: nat.h:678
ip4_address_t r_addr
Definition: nat.h:108
u32 * auto_add_sw_if_indices
Definition: nat.h:600
u32 in2out_fast_node_index
Definition: nat.h:628
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
Definition: nat.c:2906
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: in2out.c:458
u32 num_workers
Definition: nat.h:555
Definition: nat.h:425
unformat_function_t unformat_snat_protocol
Definition: nat.h:757
u32 first_worker_index
Definition: nat.h:556
u32 det_out2in_node_index
Definition: nat.h:642
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k)
Free outside address and port pair.
Definition: nat.c:2474
snat_get_worker_function_t * worker_out2in_cb
Definition: nat.h:559
ip4_address_t l_addr
Definition: nat.h:479
u32 in2out_slowpath_node_index
Definition: nat.h:629
snat_icmp_match_function_t * icmp_match_out2in_cb
Definition: nat.h:552
IPv4 main type.
Definition: ip4.h:105
vlib_log_class_t log_class
Definition: nat.h:693
u64 as_u64
Definition: nat.h:142
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
ip4_address_t addr
Definition: nat.h:139
ip4_address_t in_addr
Definition: nat.h:391
u32 fq_in2out_index
Definition: nat.h:610
u32 out2in_node_index
Definition: nat.h:635
format_function_t format_snat_protocol
Definition: nat.h:753
u32() snat_get_worker_function_t(ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
Definition: nat.h:536
ip4_address_t addr
Definition: nat.h:358
snat_address_t * twice_nat_addresses
Definition: nat.h:597
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
Definition: out2in.c:455
format_function_t format_snat_session
Definition: nat.h:749
u32 out2in_reass_node_index
Definition: nat.h:637
struct _vlib_node_registration vlib_node_registration_t
Definition: nat.h:433
format_function_t format_nat44_reass_trace
Definition: nat.h:755
vlib_node_registration_t nat44_ed_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_dst_node)
vlib_simple_counter_main_t total_users
Definition: nat.h:686
void nat_hairpinning_sm_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
vl_api_address_t ip
Definition: l2.api:489
format_function_t format_static_mapping_key
Definition: nat.h:752
twice_nat_type_t
Definition: nat.h:420
u32 hairpinning_node_index
Definition: nat.h:644
u16 msg_id_base
Definition: nat.h:690
vlib_node_registration_t nat_pre_in2out_node
(constructor) VLIB_REGISTER_NODE (nat_pre_in2out_node)
Definition: in2out_ed.c:2152
u16 ports_per_host
Definition: nat.h:399
VLIB buffer representation.
Definition: buffer.h:102
u32 * workers
Definition: nat.h:557
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:564
int nat44_i2o_is_idle_session_cb(clib_bihash_kv_8_8_t *kv, void *arg)
Definition: in2out.c:197
u32 icmp_match_in2out_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: in2out_ed.c:512
snat_protocol_t
Definition: nat.h:191
snat_det_out_key_t out
Definition: nat.h:381
u32 affinity_per_service_list_head_index
Definition: nat.h:466
u32 fib_index
Definition: nat.h:140
snat_address_t * addresses
Definition: nat.h:580
u32 out2in_fast_node_index
Definition: nat.h:636
void nat_set_alloc_addr_and_port_range(u16 start_port, u16 end_port)
Set address and port assignment algorithm for port range.
Definition: nat.c:4286
u32 in2out_node_index
Definition: nat.h:626
format_function_t format_snat_user
Definition: nat.h:746
snat_static_map_resolve_t * to_resolve
Definition: nat.h:604
typedef CLIB_PACKED(struct { snat_session_key_t out2in;snat_session_key_t in2out;u32 flags;u32 per_user_index;u32 per_user_list_head_index;f64 last_heard;f64 ha_last_refreshed;u64 total_bytes;u32 total_pkts;ip4_address_t ext_host_addr;u16 ext_host_port;ip4_address_t ext_host_nat_addr;u16 ext_host_nat_port;u8 state;u32 i2o_fin_seq;u32 o2i_fin_seq;u32 user_index;}) snat_session_t
void nat44_ed_hairpinning_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, snat_protocol_t proto, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u32 affinity)
Add/delete static mapping with load-balancing (multiple backends)
Definition: nat.c:1179
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
Definition: in2out.c:2207
nat_config_flags_t_
Definition: nat.h:164
u8 forwarding_enabled
Definition: nat.h:656
u32 translation_memory_size
Definition: nat.h:665
int snat_alloc_outside_address_and_port(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
Alloc outside address and port.
Definition: nat.c:2707
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 output feature on the interface (postrouting NAT)
Definition: nat.c:2006
u32 ses_num
Definition: nat.h:401
u32 icmp_in2out(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, u32 thread_index, void *d, void *e)
Definition: in2out.c:648
enum nat_config_flags_t_ nat_config_flags_t
vlib_node_registration_t nat44_ed_in2out_output_worker_handoff_node
clib_bihash_16_8_t in2out_ed
Definition: nat.h:502
u8 endpoint_dependent
Definition: nat.h:663
u16 dst_port
Definition: udp.api:42
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
Definition: in2out.c:1597
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
Definition: in2out_ed.c:2042
vlib_simple_counter_main_t total_sessions
Definition: nat.h:687
ip_lookup_main_t * ip4_lookup_main
Definition: nat.h:701
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
Definition: in2out.c:577
snat_session_t * sessions
Definition: nat.h:511
u32 cached_ip4_address
Definition: nat.h:714
snat_icmp_match_function_t * icmp_match_in2out_cb
Definition: nat.h:551
#define foreach_nat_log_level
Definition: nat.h:862
snat_session_t * nat_ed_session_alloc(snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
Allocate NAT endpoint-dependent session.
Definition: nat.c:445
u32() snat_icmp_match_function_t(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: nat.h:526
clib_bihash_8_8_t static_mapping_by_local
Definition: nat.h:567
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, snat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44 session.
Definition: nat.c:4187
u32 fib_index
Definition: nat.h:359
nat_in2out_ed_error_t
Definition: nat.h:237
void nat44_reass_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, u16 sport, u16 dport, u32 proto0, int is_ed)
snat_interface_t * interfaces
Definition: nat.h:576
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
vlib_node_registration_t nat_pre_out2in_node
(constructor) VLIB_REGISTER_NODE (nat_pre_out2in_node)
Definition: out2in_ed.c:2016
u32 tcp_established_timeout
Definition: nat.h:677
int() nat_alloc_out_addr_and_port_function_t(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
Definition: nat.h:540