FD.io VPP  v19.08-27-gf4dcae4
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 /* session key (4-tuple) */
47 typedef struct
48 {
49  union
50  {
51  struct
52  {
55  u16 protocol:3, fib_index:13;
56  };
58  };
60 
61 /* endpoint-dependent session key (6-tuple) */
62 typedef struct
63 {
64  union
65  {
66  struct
67  {
70  u32 proto:8, fib_index:24;
73  };
74  u64 as_u64[2];
75  };
77 
78 /* deterministic session outside key */
79 typedef struct
80 {
81  union
82  {
83  struct
84  {
88  };
90  };
92 
93 /* user (internal host) key */
94 typedef struct
95 {
96  union
97  {
98  struct
99  {
102  };
104  };
106 
107 typedef struct
108 {
113 
114 /* NAT API Configuration flags */
115 #define foreach_nat_config_flag \
116  _(0x01, IS_TWICE_NAT) \
117  _(0x02, IS_SELF_TWICE_NAT) \
118  _(0x04, IS_OUT2IN_ONLY) \
119  _(0x08, IS_ADDR_ONLY) \
120  _(0x10, IS_OUTSIDE) \
121  _(0x20, IS_INSIDE) \
122  _(0x40, IS_STATIC) \
123  _(0x80, IS_EXT_HOST_VALID) \
124 
126 {
127 #define _(n,f) NAT_API_##f = n,
129 #undef _
131 
132 /* External address and port allocation modes */
133 #define foreach_nat_addr_and_port_alloc_alg \
134  _(0, DEFAULT, "default") \
135  _(1, MAPE, "map-e") \
136  _(2, RANGE, "port-range")
137 
138 typedef enum
139 {
140 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v,
142 #undef _
144 
145 
146 /* Supported L4 protocols */
147 #define foreach_snat_protocol \
148  _(UDP, 0, udp, "udp") \
149  _(TCP, 1, tcp, "tcp") \
150  _(ICMP, 2, icmp, "icmp")
151 
152 typedef enum
153 {
154 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i,
156 #undef _
158 
159 
160 /* Session state */
161 #define foreach_snat_session_state \
162  _(0, UNKNOWN, "unknown") \
163  _(1, UDP_ACTIVE, "udp-active") \
164  _(2, TCP_SYN_SENT, "tcp-syn-sent") \
165  _(3, TCP_ESTABLISHED, "tcp-established") \
166  _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
167  _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
168  _(6, TCP_CLOSING, "tcp-closing") \
169  _(7, TCP_LAST_ACK, "tcp-last-ack") \
170  _(8, TCP_CLOSED, "tcp-closed") \
171  _(9, ICMP_ACTIVE, "icmp-active")
172 
173 typedef enum
174 {
175 #define _(v, N, s) SNAT_SESSION_##N = v,
177 #undef _
179 
180 #define foreach_nat_in2out_ed_error \
181 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
182 _(IN2OUT_PACKETS, "good in2out packets processed") \
183 _(OUT_OF_PORTS, "out of ports") \
184 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
185 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
186 _(DROP_FRAGMENT, "drop fragment") \
187 _(MAX_REASS, "maximum reassemblies exceeded") \
188 _(MAX_FRAG, "maximum fragments per reassembly exceeded")\
189 _(NON_SYN, "non-SYN packet try to create session") \
190 _(TCP_PACKETS, "TCP packets") \
191 _(UDP_PACKETS, "UDP packets") \
192 _(ICMP_PACKETS, "ICMP packets") \
193 _(OTHER_PACKETS, "other protocol packets") \
194 _(FRAGMENTS, "fragments") \
195 _(CACHED_FRAGMENTS, "cached fragments") \
196 _(PROCESSED_FRAGMENTS, "processed fragments")
197 
198 typedef enum
199 {
200 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
202 #undef _
205 
206 #define foreach_nat_out2in_ed_error \
207 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
208 _(OUT2IN_PACKETS, "good out2in packets processed") \
209 _(OUT_OF_PORTS, "out of ports") \
210 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
211 _(NO_TRANSLATION, "no translation") \
212 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
213 _(DROP_FRAGMENT, "drop fragment") \
214 _(MAX_REASS, "maximum reassemblies exceeded") \
215 _(MAX_FRAG, "maximum fragments per reassembly exceeded")\
216 _(NON_SYN, "non-SYN packet try to create session") \
217 _(TCP_PACKETS, "TCP packets") \
218 _(UDP_PACKETS, "UDP packets") \
219 _(ICMP_PACKETS, "ICMP packets") \
220 _(OTHER_PACKETS, "other protocol packets") \
221 _(FRAGMENTS, "fragments") \
222 _(CACHED_FRAGMENTS, "cached fragments") \
223 _(PROCESSED_FRAGMENTS, "processed fragments")
224 
225 typedef enum
226 {
227 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
229 #undef _
232 
233 
234 /* Endpoint dependent TCP session state */
235 #define NAT44_SES_I2O_FIN 1
236 #define NAT44_SES_O2I_FIN 2
237 #define NAT44_SES_I2O_FIN_ACK 4
238 #define NAT44_SES_O2I_FIN_ACK 8
239 #define NAT44_SES_I2O_SYN 16
240 #define NAT44_SES_O2I_SYN 32
241 #define NAT44_SES_RST 64
242 
243 /* Session flags */
244 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1
245 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO 2
246 #define SNAT_SESSION_FLAG_LOAD_BALANCING 4
247 #define SNAT_SESSION_FLAG_TWICE_NAT 8
248 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT 16
249 #define SNAT_SESSION_FLAG_FWD_BYPASS 32
250 #define SNAT_SESSION_FLAG_AFFINITY 64
251 #define SNAT_SESSION_FLAG_OUTPUT_FEATURE 128
252 
253 /* NAT interface flags */
254 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
255 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
256 
257 /* Static mapping flags */
258 #define NAT_STATIC_MAPPING_FLAG_ADDR_ONLY 1
259 #define NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY 2
260 #define NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT 4
261 #define NAT_STATIC_MAPPING_FLAG_LB 8
262 
263 /* *INDENT-OFF* */
264 typedef CLIB_PACKED(struct
265 {
266  /* Outside network key */
267  snat_session_key_t out2in;
268 
269  /* Inside network key */
270  snat_session_key_t in2out;
271 
272  /* Flags */
273  u32 flags;
274 
275  /* Per-user translations */
276  u32 per_user_index;
277  u32 per_user_list_head_index;
278 
279  /* Last heard timer */
280  f64 last_heard;
281 
282  /* Last HA refresh */
283  f64 ha_last_refreshed;
284 
285  /* Counters */
286  u64 total_bytes;
287  u32 total_pkts;
288 
289  /* External host address and port */
290  ip4_address_t ext_host_addr;
291  u16 ext_host_port;
292 
293  /* External host address and port after translation */
294  ip4_address_t ext_host_nat_addr;
295  u16 ext_host_nat_port;
296 
297  /* TCP session state */
298  u8 state;
299  u32 i2o_fin_seq;
300  u32 o2i_fin_seq;
301 
302  /* user index */
303  u32 user_index;
304 }) snat_session_t;
305 /* *INDENT-ON* */
306 
307 
308 typedef struct
309 {
315 } snat_user_t;
316 
317 typedef struct
318 {
321 /* *INDENT-OFF* */
322 #define _(N, i, n, s) \
323  u16 busy_##n##_ports; \
324  u16 * busy_##n##_ports_per_thread; \
325  uword * busy_##n##_port_bitmap;
327 #undef _
328 /* *INDENT-ON* */
329 } snat_address_t;
330 
331 typedef struct
332 {
336 
337 typedef struct
338 {
339  /* Inside network port */
341  /* Outside network address and port */
343  /* Session state */
345  /* Expire timeout */
348 
349 typedef struct
350 {
351  /* inside IP address range */
354  /* outside IP address range */
357  /* inside IP addresses / outside IP addresses */
359  /* number of ports available to internal host */
361  /* session counter */
363  /* vector of sessions */
366 
367 typedef struct
368 {
369  /* backend IP address */
371  /* backend port number */
373  /* probability of the backend to be randomly matched */
376  /* backend FIB table */
380 
381 typedef enum
382 {
383  /* twice-nat disabled */
385  /* twice-nat enabled */
387  /* twice-nat only when src IP equals dst IP after translation */
390 
391 typedef enum
392 {
393  /* no load-balancing */
395  /* load-balancing */
397  /* load-balancing with affinity */
399 } lb_nat_type_t;
400 
401 typedef struct
402 {
403  /* local IP address */
405  /* external IP address */
407  /* local port */
409  /* external port */
411  /* is twice-nat */
412  twice_nat_type_t twice_nat;
413  /* local FIB table */
416  /* protocol */
417  snat_protocol_t proto;
418  /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
420  /* worker threads used by backends/local host */
422  /* opaque string tag */
423  u8 *tag;
424  /* backends for load-balancing mode */
426  /* affinity per service lis */
428  /* flags */
431 
432 typedef struct
433 {
437 
438 typedef struct
439 {
445  snat_protocol_t proto;
449  int is_add;
452  u8 *tag;
454 
455 typedef struct
456 {
457  /* Main lookup tables */
458  clib_bihash_8_8_t out2in;
459  clib_bihash_8_8_t in2out;
460 
461  /* Endpoint dependent sessions lookup tables */
462  clib_bihash_16_8_t out2in_ed;
463  clib_bihash_16_8_t in2out_ed;
464 
465  /* Find-a-user => src address lookup */
466  clib_bihash_8_8_t user_hash;
467 
468  /* User pool */
470 
471  /* Session pool */
472  snat_session_t *sessions;
473 
474  /* Pool of doubly-linked list elements */
476 
477  /* NAT thread index */
479 
480  /* real thread index */
483 
484 struct snat_main_s;
485 
486 /* ICMP session match function */
488  vlib_node_runtime_t * node,
489  u32 thread_index,
490  vlib_buffer_t * b0,
491  ip4_header_t * ip0, u8 * p_proto,
492  snat_session_key_t * p_value,
493  u8 * p_dont_translate, void *d,
494  void *e);
495 
496 /* Return worker thread index for given packet */
498  u32 rx_fib_index, u8 is_output);
499 
500 /* NAT address and port allacotaion function */
501 typedef int (nat_alloc_out_addr_and_port_function_t) (snat_address_t *
502  addresses,
503  u32 fib_index,
504  u32 thread_index,
505  snat_session_key_t * k,
507  u32 snat_thread_index);
508 
509 typedef struct snat_main_s
510 {
511  /* ICMP session match functions */
514 
515  /* Thread settings */
523 
524  /* Per thread data */
526 
527  /* Find a static mapping by local */
528  clib_bihash_8_8_t static_mapping_by_local;
529 
530  /* Find a static mapping by external */
531  clib_bihash_8_8_t static_mapping_by_external;
532 
533  /* Static mapping pool */
535 
536  /* Interface pool */
539 
540  /* Vector of outside addresses */
541  snat_address_t *addresses;
542  /* Address and port allocation function */
544  /* Address and port allocation type */
545  nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg;
546  /* Port set parameters (MAP-E) */
550  /* Port range parameters */
553 
554  /* vector of outside fibs */
556 
557  /* Vector of twice NAT addresses for extenal hosts */
558  snat_address_t *twice_nat_addresses;
559 
560  /* sw_if_indices whose intfc addresses should be auto-added */
563 
564  /* vector of interface address static mappings to resolve. */
566 
567  /* Randomize port allocation order */
569 
570  /* Worker handoff frame-queue index */
574 
575  /* node indexes */
577 
595 
602 
603 
604  /* Deterministic NAT mappings */
606 
607  /* If forwarding is enabled */
609 
610  /* Config parameters */
626 
627  /* values of various timeouts */
632 
633  /* TCP MSS clamping */
636 
637  /* counters/gauges */
640 
641  /* API message ID base */
643 
644  /* log class */
646  /* logging level */
648 
649  /* convenience */
655 } snat_main_t;
656 
657 typedef struct
658 {
662 
663 typedef struct
664 {
668 
669 extern snat_main_t snat_main;
690 
691 /* format functions */
702 /* unformat functions */
704 
705 /** \brief Check if SNAT session is created from static mapping.
706  @param s SNAT session
707  @return 1 if SNAT session is created from static mapping otherwise 0
708 */
709 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
710 
711 /** \brief Check if SNAT session for unknown protocol.
712  @param s SNAT session
713  @return 1 if SNAT session for unknown protocol otherwise 0
714 */
715 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
716 
717 /** \brief Check if NAT session is twice NAT.
718  @param s NAT session
719  @return 1 if NAT session is twice NAT
720 */
721 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
722 
723 /** \brief Check if NAT session is load-balancing.
724  @param s NAT session
725  @return 1 if NAT session is load-balancing
726 */
727 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
728 
729 /** \brief Check if NAT session is forwarding bypass.
730  @param s NAT session
731  @return 1 if NAT session is load-balancing
732 */
733 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
734 
735 /** \brief Check if NAT session is endpoint dependent.
736  @param s NAT session
737  @return 1 if NAT session is endpoint dependent
738 */
739 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
740 
741 /** \brief Check if NAT session has affinity record.
742  @param s NAT session
743  @return 1 if NAT session has affinity record
744 */
745 #define is_affinity_sessions(s) (s->flags & SNAT_SESSION_FLAG_AFFINITY)
746 
747 /** \brief Check if NAT interface is inside.
748  @param i NAT interfce
749  @return 1 if inside interface
750 */
751 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
752 
753 /** \brief Check if NAT interface is outside.
754  @param i NAT interfce
755  @return 1 if outside interface
756 */
757 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
758 
759 /** \brief Check if NAT44 endpoint-dependent TCP session is closed.
760  @param s NAT session
761  @return 1 if session is closed
762 */
763 #define nat44_is_ses_closed(s) s->state == 0xf
764 
765 /** \brief Check if NAT static mapping is address only (1:1NAT).
766  @param sm NAT static mapping
767  @return 1 if 1:1NAT, 0 if 1:1NAPT
768 */
769 #define is_addr_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_ADDR_ONLY)
770 
771 /** \brief Check if NAT static mapping match only out2in direction.
772  @param sm NAT static mapping
773  @return 1 if rule match only out2in direction
774 */
775 #define is_out2in_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY)
776 
777 /** \brief Check if NAT static mapping is identity NAT.
778  @param sm NAT static mapping
779  @return 1 if identity NAT
780 */
781 #define is_identity_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT)
782 
783 /** \brief Check if NAT static mapping is load-balancing.
784  @param sm NAT static mapping
785  @return 1 if load-balancing
786 */
787 #define is_lb_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_LB)
788 
789 /** \brief Check if client initiating TCP connection (received SYN from client)
790  @param t TCP header
791  @return 1 if client initiating TCP connection
792 */
793 #define tcp_is_init(t) ((t->flags & TCP_FLAG_SYN) && !(t->flags & TCP_FLAG_ACK))
794 
795 /* logging */
796 #define nat_log_err(...) \
797  vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
798 #define nat_log_warn(...) \
799  vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
800 #define nat_log_notice(...) \
801  vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
802 #define nat_log_info(...) \
803  vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
804 #define nat_log_debug(...)\
805  vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
806 
807 /* NAT API Logging Levels */
808 #define foreach_nat_log_level \
809  _(0x00, LOG_NONE) \
810  _(0x01, LOG_ERROR) \
811  _(0x02, LOG_WARNING) \
812  _(0x03, LOG_NOTICE) \
813  _(0x04, LOG_INFO) \
814  _(0x05, LOG_DEBUG)
815 
816 typedef enum nat_log_level_t_
817 {
818 #define _(n,f) SNAT_##f = n,
820 #undef _
822 
823 #define nat_elog(_level, _str) \
824 do \
825  { \
826  snat_main_t *sm = &snat_main; \
827  if (PREDICT_FALSE (sm->log_level >= _level)) \
828  { \
829  ELOG_TYPE_DECLARE (e) = \
830  { \
831  .format = "nat-msg " _str, \
832  .format_args = "", \
833  }; \
834  ELOG_DATA (&sm->vlib_main->elog_main, e); \
835  } \
836  } while (0);
837 
838 #define nat_elog_addr(_level, _str, _addr) \
839 do \
840  { \
841  if (PREDICT_FALSE (sm->log_level >= _level)) \
842  { \
843  ELOG_TYPE_DECLARE (e) = \
844  { \
845  .format = "nat-msg " _str " %d.%d.%d.%d", \
846  .format_args = "i1i1i1i1", \
847  }; \
848  CLIB_PACKED(struct \
849  { \
850  u8 oct1; \
851  u8 oct2; \
852  u8 oct3; \
853  u8 oct4; \
854  }) *ed; \
855  ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
856  ed->oct4 = _addr >> 24; \
857  ed->oct3 = _addr >> 16; \
858  ed->oct2 = _addr >> 8; \
859  ed->oct1 = _addr; \
860  } \
861  } while (0);
862 
863 #define nat_elog_debug_handoff(_str, _tid, _fib, _src, _dst) \
864 do \
865  { \
866  if (PREDICT_FALSE (sm->log_level >= SNAT_LOG_DEBUG)) \
867  { \
868  ELOG_TYPE_DECLARE (e) = \
869  { \
870  .format = "nat-msg " _str " ip src: %d.%d.%d.%d dst: %d.%d.%d.%d" \
871  " tid from: %d to: %d fib: %d", \
872  .format_args = "i1i1i1i1i1i1i1i1i4i4i4", \
873  }; \
874  CLIB_PACKED(struct \
875  { \
876  u8 src_oct1; \
877  u8 src_oct2; \
878  u8 src_oct3; \
879  u8 src_oct4; \
880  u8 dst_oct1; \
881  u8 dst_oct2; \
882  u8 dst_oct3; \
883  u8 dst_oct4; \
884  u32 ftid; \
885  u32 ttid; \
886  u32 fib; \
887  }) *ed; \
888  ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
889  ed->src_oct1 = _src >> 24; \
890  ed->src_oct2 = _src >> 16; \
891  ed->src_oct3 = _src >> 8; \
892  ed->src_oct4 = _src; \
893  ed->dst_oct1 = _dst >> 24; \
894  ed->dst_oct2 = _dst >> 16; \
895  ed->dst_oct3 = _dst >> 8; \
896  ed->dst_oct4 = _dst; \
897  ed->ftid = vlib_get_thread_index (); \
898  ed->ttid = _tid; \
899  ed->fib = _fib; \
900  } \
901  } while (0);
902 
903 #define nat_elog_debug_handoff_v2(_str, _prt, _fib, _src, _dst) \
904 do \
905  { \
906  if (PREDICT_FALSE (sm->log_level >= SNAT_LOG_DEBUG)) \
907  { \
908  ELOG_TYPE_DECLARE (e) = \
909  { \
910  .format = "nat-msg " _str " ip_src:%d.%d.%d.%d ip_dst:%d.%d.%d.%d" \
911  " tid:%d prt:%d fib:%d", \
912  .format_args = "i1i1i1i1i1i1i1i1i4i4i4", \
913  }; \
914  CLIB_PACKED(struct \
915  { \
916  u8 src_oct1; \
917  u8 src_oct2; \
918  u8 src_oct3; \
919  u8 src_oct4; \
920  u8 dst_oct1; \
921  u8 dst_oct2; \
922  u8 dst_oct3; \
923  u8 dst_oct4; \
924  u32 tid; \
925  u32 prt; \
926  u32 fib; \
927  }) *ed; \
928  ed = ELOG_DATA (&vlib_global_main.elog_main, e); \
929  ed->src_oct1 = _src >> 24; \
930  ed->src_oct2 = _src >> 16; \
931  ed->src_oct3 = _src >> 8; \
932  ed->src_oct4 = _src; \
933  ed->dst_oct1 = _dst >> 24; \
934  ed->dst_oct2 = _dst >> 16; \
935  ed->dst_oct3 = _dst >> 8; \
936  ed->dst_oct4 = _dst; \
937  ed->tid = vlib_get_thread_index (); \
938  ed->prt = _prt; \
939  ed->fib = _fib; \
940  } \
941  } while (0);
942 
943 #define nat_elog_X1(_level, _fmt, _arg, _val1) \
944 do \
945  { \
946  snat_main_t *sm = &snat_main; \
947  if (PREDICT_FALSE (sm->log_level >= _level)) \
948  { \
949  ELOG_TYPE_DECLARE (e) = \
950  { \
951  .format = "nat-msg " _fmt, \
952  .format_args = _arg, \
953  }; \
954  CLIB_PACKED(struct \
955  { \
956  typeof (_val1) val1; \
957  }) *ed; \
958  ed = ELOG_DATA (&sm->vlib_main->elog_main, e); \
959  ed->val1 = _val1; \
960  } \
961  } while (0);
962 
963 #define nat_elog_notice(nat_elog_str) \
964  nat_elog(SNAT_LOG_INFO, "[notice] " nat_elog_str)
965 #define nat_elog_warn(nat_elog_str) \
966  nat_elog(SNAT_LOG_WARNING, "[warning] " nat_elog_str)
967 #define nat_elog_err(nat_elog_str) \
968  nat_elog(SNAT_LOG_ERROR, "[error] " nat_elog_str)
969 #define nat_elog_debug(nat_elog_str) \
970  nat_elog(SNAT_LOG_DEBUG, "[debug] " nat_elog_str)
971 #define nat_elog_info(nat_elog_str) \
972  nat_elog(SNAT_LOG_INFO, "[info] " nat_elog_str)
973 
974 #define nat_elog_notice_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
975  nat_elog_X1(SNAT_LOG_NOTICE, "[notice] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
976 #define nat_elog_warn_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
977  nat_elog_X1(SNAT_LOG_WARNING, "[warning] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
978 #define nat_elog_err_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
979  nat_elog_X1(SNAT_LOG_ERROR, "[error] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
980 #define nat_elog_debug_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
981  nat_elog_X1(SNAT_LOG_DEBUG, "[debug] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
982 #define nat_elog_info_X1(nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1) \
983  nat_elog_X1(SNAT_LOG_INFO, "[info] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
984 
985 /* ICMP session match functions */
987  u32 thread_index, vlib_buffer_t * b0,
988  ip4_header_t * ip0, u8 * p_proto,
989  snat_session_key_t * p_value,
990  u8 * p_dont_translate, void *d, void *e);
992  u32 thread_index, vlib_buffer_t * b0,
993  ip4_header_t * ip0, u8 * p_proto,
994  snat_session_key_t * p_value,
995  u8 * p_dont_translate, void *d, void *e);
997  u32 thread_index, vlib_buffer_t * b0,
998  ip4_header_t * ip0, u8 * p_proto,
999  snat_session_key_t * p_value,
1000  u8 * p_dont_translate, void *d, void *e);
1002  u32 thread_index, vlib_buffer_t * b0,
1003  ip4_header_t * ip0, u8 * p_proto,
1004  snat_session_key_t * p_value,
1005  u8 * p_dont_translate, void *d, void *e);
1006 
1007 /* ICMP deterministic NAT session match functions */
1009  u32 thread_index, vlib_buffer_t * b0,
1010  ip4_header_t * ip0, u8 * p_proto,
1011  snat_session_key_t * p_value,
1012  u8 * p_dont_translate, void *d, void *e);
1014  u32 thread_index, vlib_buffer_t * b0,
1015  ip4_header_t * ip0, u8 * p_proto,
1016  snat_session_key_t * p_value,
1017  u8 * p_dont_translate, void *d, void *e);
1018 
1019 /* ICMP endpoint-dependent session match functions */
1021  u32 thread_index, vlib_buffer_t * b0,
1022  ip4_header_t * ip0, u8 * p_proto,
1023  snat_session_key_t * p_value,
1024  u8 * p_dont_translate, void *d, void *e);
1026  u32 thread_index, vlib_buffer_t * b0,
1027  ip4_header_t * ip0, u8 * p_proto,
1028  snat_session_key_t * p_value,
1029  u8 * p_dont_translate, void *d, void *e);
1030 
1032  icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
1033  vlib_node_runtime_t * node, u32 next0, u32 thread_index,
1034  void *d, void *e);
1035 
1037  icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
1038  vlib_node_runtime_t * node, u32 next0, u32 thread_index,
1039  void *d, void *e);
1040 
1041 /* hairpinning functions */
1043  ip4_header_t * ip0, icmp46_header_t * icmp0,
1044  int is_ed);
1046  ip4_header_t * ip);
1048  ip4_header_t * ip);
1050  ip4_header_t * ip0, udp_header_t * udp0,
1051  tcp_header_t * tcp0, u32 proto0, int is_ed);
1053  ip4_header_t * ip0, u16 sport, u16 dport,
1054  u32 proto0, int is_ed);
1055 
1056 /* Call back functions for clib_bihash_add_or_overwrite_stale */
1061 
1062 /**
1063  * @brief Increment IPv4 address
1064  */
1066 
1067 /**
1068  * @brief Add external address to NAT44 pool
1069  *
1070  * @param addr IPv4 address
1071  * @param vrf_id VRF id of tenant, ~0 means independent of VRF
1072  * @param twice_nat 1 if twice NAT address
1073  *
1074  * @return 0 on success, non-zero value otherwise
1075  */
1076 int snat_add_address (snat_main_t * sm, ip4_address_t * addr, u32 vrf_id,
1077  u8 twice_nat);
1078 
1079 /**
1080  * @brief Delete external address from NAT44 pool
1081  *
1082  * @param addr IPv4 address
1083  * @param delete_sm 1 if delete static mapping using address
1084  * @param twice_nat 1 if twice NAT address
1085  *
1086  * @return 0 on success, non-zero value otherwise
1087  */
1088 int snat_del_address (snat_main_t * sm, ip4_address_t addr, u8 delete_sm,
1089  u8 twice_nat);
1090 
1091 /**
1092  * @brief Add/delete external address to FIB DPO (out2in DPO mode)
1093  *
1094  * @param addr IPv4 address
1095  * @param is_add 1 = add, 0 = delete
1096  *
1097  * @return 0 on success, non-zero value otherwise
1098  */
1100 
1101 /**
1102  * @brief Add/delete NAT44 static mapping
1103  *
1104  * @param l_addr local IPv4 address
1105  * @param e_addr external IPv4 address
1106  * @param l_port local port number
1107  * @param e_port external port number
1108  * @param vrf_id local VRF ID
1109  * @param addr_only 1 = 1:1NAT, 0 = 1:1NAPT
1110  * @param sw_if_index use interface address as external IPv4 address
1111  * @param proto L4 protocol
1112  * @param is_add 1 = add, 0 = delete
1113  * @param twice_nat twice-nat mode
1114  * @param out2in_only if 1 rule match only out2in direction
1115  * @param tag opaque string tag
1116  * @param identity_nat identity NAT
1117  *
1118  * @return 0 on success, non-zero value otherwise
1119  */
1121  u16 l_port, u16 e_port, u32 vrf_id,
1122  int addr_only, u32 sw_if_index,
1123  snat_protocol_t proto, int is_add,
1124  twice_nat_type_t twice_nat, u8 out2in_only,
1125  u8 * tag, u8 identity_nat);
1126 
1127 /**
1128  * @brief Add/delete static mapping with load-balancing (multiple backends)
1129  *
1130  * @param e_addr external IPv4 address
1131  * @param e_port external port number
1132  * @param proto L4 protocol
1133  * @param locals list of local backends
1134  * @param is_add 1 = add, 0 = delete
1135  * @param twice_nat twice-nat mode
1136  * @param out2in_only if 1 rule match only out2in direction
1137  * @param tag opaque string tag
1138  * @param affinity 0 = disabled, otherwise client IP affinity sticky time
1139  *
1140  * @return 0 on success, non-zero value otherwise
1141  */
1143  snat_protocol_t proto,
1144  nat44_lb_addr_port_t * locals, u8 is_add,
1145  twice_nat_type_t twice_nat,
1146  u8 out2in_only, u8 * tag, u32 affinity);
1147 
1149  ip4_address_t l_addr, u16 l_port,
1150  snat_protocol_t proto, u32 vrf_id,
1151  u8 probability, u8 is_add);
1152 
1154 
1155 /**
1156  * @brief Set NAT plugin workers
1157  *
1158  * @param bitmap NAT workers bitmap
1159  *
1160  * @return 0 on success, non-zero value otherwise
1161  */
1162 int snat_set_workers (uword * bitmap);
1163 
1164 /**
1165  * @brief Enable/disable NAT44 feature on the interface
1166  *
1167  * @param sw_if_index software index of the interface
1168  * @param is_inside 1 = inside, 0 = outside
1169  * @param is_del 1 = delete, 0 = add
1170  *
1171  * @return 0 on success, non-zero value otherwise
1172  */
1173 int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del);
1174 
1175 /**
1176  * @brief Enable/disable NAT44 output feature on the interface (postrouting NAT)
1177  *
1178  * @param sw_if_index software index of the interface
1179  * @param is_inside 1 = inside, 0 = outside
1180  * @param is_del 1 = delete, 0 = add
1181  *
1182  * @return 0 on success, non-zero value otherwise
1183  */
1185  int is_del);
1186 
1187 /**
1188  * @brief Add/delete NAT44 pool address from specific interfce
1189  *
1190  * @param sw_if_index software index of the interface
1191  * @param is_del 1 = delete, 0 = add
1192  * @param twice_nat 1 = twice NAT address for extenal hosts
1193  *
1194  * @return 0 on success, non-zero value otherwise
1195  */
1196 int snat_add_interface_address (snat_main_t * sm, u32 sw_if_index, int is_del,
1197  u8 twice_nat);
1198 
1199 /**
1200  * @brief Delete NAT44 session
1201  *
1202  * @param addr IPv4 address
1203  * @param port L4 port number
1204  * @param proto L4 protocol
1205  * @param vrf_id VRF ID
1206  * @param is_in 1 = inside network address and port pair, 0 = outside
1207  *
1208  * @return 0 on success, non-zero value otherwise
1209  */
1211  snat_protocol_t proto, u32 vrf_id, int is_in);
1212 
1213 /**
1214  * @brief Delete NAT44 endpoint-dependent session
1215  *
1216  * @param addr IPv4 address
1217  * @param port L4 port number
1218  * @param proto L4 protocol
1219  * @param vrf_id VRF ID
1220  * @param is_in 1 = inside network address and port pair, 0 = outside
1221  *
1222  * @return 0 on success, non-zero value otherwise
1223  */
1225  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
1226  u32 vrf_id, int is_in);
1227 
1228 /**
1229  * @brief Free NAT44 session data (lookup keys, external addrres port)
1230  *
1231  * @param s NAT session
1232  * @param thread_index thread index
1233  * @param is_ha is HA event
1234  */
1235 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
1236  u32 thread_index, u8 is_ha);
1237 
1238 /**
1239  * @brief Find or create NAT user
1240  *
1241  * @param addr IPv4 address
1242  * @param fib_index FIB table index
1243  * @param thread_index thread index
1244  *
1245  * @return NAT user data structure on success otherwise zero value
1246  */
1248  u32 fib_index, u32 thread_index);
1249 
1250 /**
1251  * @brief Allocate new NAT session or recycle last used
1252  *
1253  * @param u NAT user
1254  * @param thread_index thread index
1255  *
1256  * @return session data structure on success otherwise zero value
1257  */
1258 snat_session_t *nat_session_alloc_or_recycle (snat_main_t * sm,
1259  snat_user_t * u,
1260  u32 thread_index, f64 now);
1261 
1262 /**
1263  * @brief Allocate NAT endpoint-dependent session
1264  *
1265  * @param u NAT user
1266  * @param thread_index thread index
1267  *
1268  * @return session data structure on success otherwise zero value
1269  */
1270 snat_session_t *nat_ed_session_alloc (snat_main_t * sm, snat_user_t * u,
1271  u32 thread_index, f64 now);
1272 
1273 /**
1274  * @brief Set address and port assignment algorithm for MAP-E CE
1275  *
1276  * @param psid Port Set Identifier value
1277  * @param psid_offset number of offset bits
1278  * @param psid_length length of PSID
1279  */
1281  u16 psid_length);
1282 
1283 /**
1284  * @brief Set address and port assignment algorithm for port range
1285  *
1286  * @param start_port beginning of the port range
1287  * @param end_port end of the port range
1288  */
1290 
1291 /**
1292  * @brief Set address and port assignment algorithm to default/standard
1293  */
1295 
1296 /**
1297  * @brief Free outside address and port pair
1298  *
1299  * @param addresses vector of outside addresses
1300  * @param thread_index thread index
1301  * @param k address, port and protocol
1302  */
1303 void snat_free_outside_address_and_port (snat_address_t * addresses,
1304  u32 thread_index,
1305  snat_session_key_t * k);
1306 
1307 /**
1308  * @brief Alloc outside address and port
1309  *
1310  * @param addresses vector of outside addresses
1311  * @param fib_index FIB table index
1312  * @param thread_index thread index
1313  * @param k allocated address and port pair
1314  * @param port_per_thread number of ports per threead
1315  * @param snat_thread_index NAT thread index
1316  *
1317  * @return 0 on success, non-zero value otherwise
1318  */
1319 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
1320  u32 fib_index,
1321  u32 thread_index,
1322  snat_session_key_t * k,
1323  u16 port_per_thread,
1324  u32 snat_thread_index);
1325 
1326 /**
1327  * @brief Match NAT44 static mapping.
1328  *
1329  * @param match address and port to match
1330  * @param mapping external/local address and port of the matched mapping
1331  * @param by_external if 0 match by local address otherwise match by external
1332  * address
1333  * @param is_addr_only 1 if matched mapping is address only
1334  * @param twice_nat matched mapping is twice NAT type
1335  * @param lb 1 if matched mapping is load-balanced
1336  * @param ext_host_addr external host address
1337  *
1338  * @returns 0 if match found otherwise 1.
1339  */
1341  snat_session_key_t match,
1342  snat_session_key_t * mapping,
1343  u8 by_external,
1344  u8 * is_addr_only,
1345  twice_nat_type_t * twice_nat,
1346  lb_nat_type_t * lb,
1347  ip4_address_t * ext_host_addr,
1348  u8 * is_identity_nat);
1349 
1350 /**
1351  * @brief Add/del NAT address to FIB.
1352  *
1353  * Add the external NAT address to the FIB as receive entries. This ensures
1354  * that VPP will reply to ARP for this address and we don't need to enable
1355  * proxy ARP on the outside interface.
1356  *
1357  * @param addr IPv4 address
1358  * @param plen address prefix length
1359  * @param sw_if_index software index of the outside interface
1360  * @param is_add 0 = delete, 1 = add.
1361  */
1363  u8 p_len, u32 sw_if_index, int is_add);
1364 
1365 /*
1366  * Why is this here? Because we don't need to touch this layer to
1367  * simply reply to an icmp. We need to change id to a unique
1368  * value to NAT an echo request/reply.
1369  */
1370 
1371 typedef struct
1372 {
1376 
1377 typedef struct
1378 {
1381 
1382 #endif /* __included_nat_h__ */
1383 
1384 /*
1385  * fd.io coding-style-patch-verification: ON
1386  *
1387  * Local Variables:
1388  * eval: (c-set-style "gnu")
1389  * End:
1390  */
ip4_address_t external_addr
Definition: nat.h:406
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:1630
u32 user_memory_size
Definition: nat.h:620
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:133
nat_outside_fib_t * outside_fibs
Definition: nat.h:555
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:138
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:233
u32 sessions_per_user_list_head_index
Definition: nat.h:312
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:1744
u16 ext_host_port
Definition: nat.h:86
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:597
u16 out_port
Definition: nat.h:87
u32 ed_hairpinning_node_index
Definition: nat.h:599
a
Definition: bitmap.h:538
u32 icmp_timeout
Definition: nat.h:631
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
u32 fq_in2out_output_index
Definition: nat.h:572
u16 start_port
Definition: nat.h:551
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:590
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:360
u32 nsessions
Definition: nat.h:313
#define foreach_snat_session_state
Definition: nat.h:161
unsigned long u64
Definition: types.h:89
ip4_address_t addr
Definition: nat.h:370
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:4070
enum nat_log_level_t_ nat_log_level_t
snat_protocol_t proto
Definition: nat.h:417
u16 port_per_thread
Definition: nat.h:521
u32 ed_in2out_reass_node_index
Definition: nat.h:586
u32 nstaticsessions
Definition: nat.h:314
u32 ed_out2in_slowpath_node_index
Definition: nat.h:591
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:1595
format_function_t format_det_map_ses
Definition: nat.h:696
#define foreach_nat_in2out_ed_error
Definition: nat.h:180
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:487
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:78
vlib_node_registration_t nat44_ed_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_src_node)
u32 fib_index
Definition: nat.h:311
format_function_t format_snat_static_mapping
Definition: nat.h:693
format_function_t format_snat_key
Definition: nat.h:697
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
snat_det_map_t * det_maps
Definition: nat.h:605
nat_log_level_t_
Definition: nat.h:816
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat.h:543
u32 num_snat_thread
Definition: nat.h:522
#define foreach_snat_protocol
Definition: nat.h:147
dlist_elt_t * list_pool
Definition: nat.h:475
u8 in_plen
Definition: nat.h:353
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:613
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:449
u16 l_port
Definition: nat.h:71
nat44_lb_addr_port_t * locals
Definition: nat.h:425
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
Definition: nat.c:2148
u32 user_buckets
Definition: nat.h:619
double f64
Definition: types.h:142
clib_bihash_8_8_t user_hash
Definition: nat.h:466
u32 cached_sw_if_index
Definition: nat.h:665
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:4225
u32 max_translations_per_user
Definition: nat.h:621
clib_bihash_8_8_t in2out
Definition: nat.h:459
u32 in2out_reass_node_index
Definition: nat.h:583
u32 in2out_output_node_index
Definition: nat.h:579
u32 ed_in2out_node_index
Definition: nat.h:584
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:72
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
Definition: out2in.c:1341
ip4_address_t ext_host_addr
Definition: nat.h:85
u32 det_in2out_node_index
Definition: nat.h:593
u32 translation_buckets
Definition: nat.h:616
lb_nat_type_t
Definition: nat.h:391
ip4_address_t addr
Definition: nat.h:310
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:542
ip4_main_t * ip4_main
Definition: nat.h:652
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:1609
ip4_address_t local_addr
Definition: nat.h:404
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:445
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:1864
twice_nat_type_t twice_nat
Definition: nat.h:412
u32 max_translations
Definition: nat.h:618
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:562
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
Definition: out2in_ed.c:1528
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
u32 fib_index
Definition: nat.h:333
u16 mss_value_net
Definition: nat.h:635
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat.h:545
#define foreach_nat_out2in_ed_error
Definition: nat.h:206
clib_bihash_16_8_t out2in_ed
Definition: nat.h:462
snat_det_session_t * sessions
Definition: nat.h:364
vl_api_ip_proto_t protocol
Definition: punt.api:39
u16 mss_clamping
Definition: nat.h:634
vlib_main_t * vlib_main
Definition: nat.h:650
unsigned short u16
Definition: types.h:57
u8 out2in_dpo
Definition: nat.h:614
snat_static_mapping_t * static_mappings
Definition: nat.h:534
u32 inside_fib_index
Definition: nat.h:625
u32 udp_timeout
Definition: nat.h:628
u8 static_mapping_only
Definition: nat.h:611
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:4181
vlib_node_registration_t nat44_ed_out2in_worker_handoff_node
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:179
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
Definition: nat.c:4248
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:1446
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:514
u32 hairpin_src_node_index
Definition: nat.h:598
clib_bihash_8_8_t static_mapping_by_external
Definition: nat.h:531
u16 port
Definition: punt.api:40
u32 in2out_slowpath_output_node_index
Definition: nat.h:582
u8 psid_offset
Definition: nat.h:547
struct snat_main_s snat_main_t
api_main_t * api_main
Definition: nat.h:654
u8 out_plen
Definition: nat.h:356
u8 psid_length
Definition: nat.h:548
u32 refcount
Definition: nat.h:334
vnet_main_t * vnet_main
Definition: nat.h:651
u32 inside_vrf_id
Definition: nat.h:624
vlib_node_registration_t nat44_ed_in2out_worker_handoff_node
Definition: nat.h:396
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:647
u32 fq_out2in_index
Definition: nat.h:573
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:538
u16 src_port
Definition: nat.h:1379
u32 ed_hairpin_src_node_index
Definition: nat.h:601
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:678
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:173
snat_user_t * users
Definition: nat.h:469
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:501
u32 random_seed
Definition: nat.h:568
u32 ed_out2in_reass_node_index
Definition: nat.h:592
clib_bihash_8_8_t out2in
Definition: nat.h:458
int nat44_o2i_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
Definition: out2in_ed.c:102
vlib_main_t * vm
Definition: buffer.c:312
u32 outside_vrf_id
Definition: nat.h:622
ip4_address_t l_addr
Definition: nat.h:68
u8 static_mapping_connection_tracking
Definition: nat.h:612
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:519
u16 end_port
Definition: nat.h:552
format_function_t format_snat_static_map_to_resolve
Definition: nat.h:694
u32 ed_in2out_slowpath_node_index
Definition: nat.h:585
u32( snat_get_worker_function_t)(ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
Definition: nat.h:497
u32 error_node_index
Definition: nat.h:576
u32 sharing_ratio
Definition: nat.h:358
ip4_address_t out_addr
Definition: nat.h:355
u16 psid
Definition: nat.h:549
u32 outside_fib_index
Definition: nat.h:623
format_function_t format_nat_addr_and_port_alloc_alg
Definition: nat.h:700
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:2512
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:33
ip4_address_t addr
Definition: nat.h:53
u32 ed_hairpin_dst_node_index
Definition: nat.h:600
u32 sw_if_index
Definition: nat.h:434
#define foreach_nat_config_flag
Definition: nat.h:115
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:313
void increment_v4_address(ip4_address_t *a)
Increment IPv4 address.
Definition: nat.c:626
nat_out2in_ed_error_t
Definition: nat.h:225
u32 tcp_transitory_timeout
Definition: nat.h:630
ip4_address_t r_addr
Definition: nat.h:69
u32 * auto_add_sw_if_indices
Definition: nat.h:561
u32 in2out_fast_node_index
Definition: nat.h:580
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:2870
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:516
Definition: nat.h:386
unformat_function_t unformat_snat_protocol
Definition: nat.h:703
u32 first_worker_index
Definition: nat.h:517
u32 det_out2in_node_index
Definition: nat.h:594
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:2438
snat_get_worker_function_t * worker_out2in_cb
Definition: nat.h:520
ip4_address_t l_addr
Definition: nat.h:440
u32 in2out_slowpath_node_index
Definition: nat.h:581
snat_icmp_match_function_t * icmp_match_out2in_cb
Definition: nat.h:513
IPv4 main type.
Definition: ip4.h:105
vlib_log_class_t log_class
Definition: nat.h:645
u64 as_u64
Definition: nat.h:103
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:100
ip4_address_t in_addr
Definition: nat.h:352
u32 fq_in2out_index
Definition: nat.h:571
u32 out2in_node_index
Definition: nat.h:587
format_function_t format_snat_protocol
Definition: nat.h:699
ip4_address_t addr
Definition: nat.h:319
snat_address_t * twice_nat_addresses
Definition: nat.h:558
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:695
u32 out2in_reass_node_index
Definition: nat.h:589
struct _vlib_node_registration vlib_node_registration_t
Definition: nat.h:394
format_function_t format_nat44_reass_trace
Definition: nat.h:701
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:638
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:698
twice_nat_type_t
Definition: nat.h:381
u32 hairpinning_node_index
Definition: nat.h:596
u16 msg_id_base
Definition: nat.h:642
u16 ports_per_host
Definition: nat.h:360
VLIB buffer representation.
Definition: buffer.h:102
u32 * workers
Definition: nat.h:518
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:525
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:522
snat_protocol_t
Definition: nat.h:152
snat_det_out_key_t out
Definition: nat.h:342
u32 affinity_per_service_list_head_index
Definition: nat.h:427
u32 fib_index
Definition: nat.h:101
snat_address_t * addresses
Definition: nat.h:541
u32 out2in_fast_node_index
Definition: nat.h:588
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:4237
u32 in2out_node_index
Definition: nat.h:578
format_function_t format_snat_user
Definition: nat.h:692
snat_static_map_resolve_t * to_resolve
Definition: nat.h:565
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:1169
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:2169
nat_config_flags_t_
Definition: nat.h:125
u8 forwarding_enabled
Definition: nat.h:608
u32 translation_memory_size
Definition: nat.h:617
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:2671
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:1993
u32 ses_num
Definition: nat.h:362
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:463
u8 endpoint_dependent
Definition: nat.h:615
u16 dst_port
Definition: udp.api:42
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
Definition: in2out.c:1576
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
Definition: in2out_ed.c:1622
vlib_simple_counter_main_t total_sessions
Definition: nat.h:639
ip_lookup_main_t * ip4_lookup_main
Definition: nat.h:653
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:472
u32 cached_ip4_address
Definition: nat.h:666
snat_icmp_match_function_t * icmp_match_in2out_cb
Definition: nat.h:512
#define foreach_nat_log_level
Definition: nat.h:808
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:435
clib_bihash_8_8_t static_mapping_by_local
Definition: nat.h:528
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:4138
u32 fib_index
Definition: nat.h:320
nat_in2out_ed_error_t
Definition: nat.h:198
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:537
vl_api_fib_path_nh_proto_t proto
Definition: fib_types.api:125
u32 tcp_established_timeout
Definition: nat.h:629