FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
nat44_ed.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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.c
17  * NAT plugin global declarations
18  */
19 #ifndef __included_nat44_ed_h__
20 #define __included_nat44_ed_h__
21 
22 #include <vnet/vnet.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/ip/icmp46_packet.h>
26 #include <vnet/api_errno.h>
27 #include <vnet/fib/fib_source.h>
28 #include <vppinfra/elog.h>
29 #include <vppinfra/bihash_8_8.h>
30 #include <vppinfra/bihash_16_8.h>
31 #include <vppinfra/dlist.h>
32 #include <vppinfra/error.h>
33 #include <vlibapi/api.h>
34 
35 #include <nat/lib/lib.h>
36 #include <nat/lib/inlines.h>
37 
38 /* default number of worker handoff frame queue elements */
39 #define NAT_FQ_NELTS_DEFAULT 64
40 
41 /* NAT buffer flags */
42 #define SNAT_FLAG_HAIRPINNING (1 << 0)
43 
44 /* NAT44 API Configuration flags */
45 #define foreach_nat44_config_flag \
46  _(0x00, IS_ENDPOINT_INDEPENDENT) \
47  _(0x01, IS_ENDPOINT_DEPENDENT) \
48  _(0x02, IS_STATIC_MAPPING_ONLY) \
49  _(0x04, IS_CONNECTION_TRACKING) \
50  _(0x08, IS_OUT2IN_DPO)
51 
53 {
54 #define _(n,f) NAT44_API_##f = n,
56 #undef _
58 
59 typedef struct
60 {
61  /* nat44 plugin features */
64 
67 
68  /* maximum number of sessions */
70 
72 
73 typedef enum
74 {
86 } nat_next_t;
87 
88 typedef struct
89 {
93 
94 /* External address and port allocation modes */
95 #define foreach_nat_addr_and_port_alloc_alg \
96  _(0, DEFAULT, "default") \
97  _(1, MAPE, "map-e") \
98  _(2, RANGE, "port-range")
99 
100 typedef enum
101 {
102 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v,
104 #undef _
106 
107 /* Session state */
108 #define foreach_snat_session_state \
109  _(0, UNKNOWN, "unknown") \
110  _(1, UDP_ACTIVE, "udp-active") \
111  _(2, TCP_SYN_SENT, "tcp-syn-sent") \
112  _(3, TCP_ESTABLISHED, "tcp-established") \
113  _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
114  _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
115  _(6, TCP_CLOSING, "tcp-closing") \
116  _(7, TCP_LAST_ACK, "tcp-last-ack") \
117  _(8, TCP_CLOSED, "tcp-closed") \
118  _(9, ICMP_ACTIVE, "icmp-active")
119 
120 typedef enum
121 {
122 #define _(v, N, s) SNAT_SESSION_##N = v,
124 #undef _
126 
127 #define foreach_nat_in2out_ed_error \
128 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \
129 _(OUT_OF_PORTS, "out of ports") \
130 _(BAD_ICMP_TYPE, "unsupported ICMP type") \
131 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
132 _(NON_SYN, "non-SYN packet try to create session") \
133 _(TCP_CLOSED, "drops due to TCP in transitory timeout")
134 
135 typedef enum
136 {
137 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
139 #undef _
142 
143 #define foreach_nat_out2in_ed_error \
144  _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
145  _ (OUT_OF_PORTS, "out of ports") \
146  _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
147  _ (NO_TRANSLATION, "no translation") \
148  _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
149  _ (NON_SYN, "non-SYN packet try to create session") \
150  _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
151  _ (HASH_ADD_FAILED, "hash table add failed")
152 
153 typedef enum
154 {
155 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
157 #undef _
160 
161 
162 /* Endpoint dependent TCP session state */
163 #define NAT44_SES_I2O_FIN 1
164 #define NAT44_SES_O2I_FIN 2
165 #define NAT44_SES_I2O_FIN_ACK 4
166 #define NAT44_SES_O2I_FIN_ACK 8
167 #define NAT44_SES_I2O_SYN 16
168 #define NAT44_SES_O2I_SYN 32
169 #define NAT44_SES_RST 64
170 
171 /* Session flags */
172 #define SNAT_SESSION_FLAG_STATIC_MAPPING (1 << 0)
173 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO (1 << 1)
174 #define SNAT_SESSION_FLAG_LOAD_BALANCING (1 << 2)
175 #define SNAT_SESSION_FLAG_TWICE_NAT (1 << 3)
176 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT (1 << 4)
177 #define SNAT_SESSION_FLAG_FWD_BYPASS (1 << 5)
178 #define SNAT_SESSION_FLAG_AFFINITY (1 << 6)
179 #define SNAT_SESSION_FLAG_EXACT_ADDRESS (1 << 7)
180 #define SNAT_SESSION_FLAG_HAIRPINNING (1 << 8)
181 
182 /* NAT interface flags */
183 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
184 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
185 
186 /* Static mapping flags */
187 #define NAT_STATIC_MAPPING_FLAG_ADDR_ONLY 1
188 #define NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY 2
189 #define NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT 4
190 #define NAT_STATIC_MAPPING_FLAG_LB 8
191 #define NAT_STATIC_MAPPING_FLAG_EXACT_ADDRESS 16
192 
193 typedef CLIB_PACKED(struct
194 {
195  // number of sessions in this vrf
196  u32 ses_count;
197 
198  u32 rx_fib_index;
199  u32 tx_fib_index;
200 
201  // is this vrf expired
202  u8 expired;
203 }) per_vrf_sessions_t;
204 
205 typedef union
206 {
207  struct
208  {
210  u16 sport; // ICMP id for ICMP case
214  };
216  u64x2u as_u128;
217 } nat_6t_t;
218 
219 STATIC_ASSERT_SIZEOF (nat_6t_t, 2 * sizeof (u64));
220 
221 typedef struct
222 {
223 #define NAT_FLOW_OP_SADDR_REWRITE (1 << 1)
224 #define NAT_FLOW_OP_SPORT_REWRITE (1 << 2)
225 #define NAT_FLOW_OP_DADDR_REWRITE (1 << 3)
226 #define NAT_FLOW_OP_DPORT_REWRITE (1 << 4)
227 #define NAT_FLOW_OP_ICMP_ID_REWRITE (1 << 5)
228 #define NAT_FLOW_OP_TXFIB_REWRITE (1 << 6)
229  int ops;
231  struct
232  {
239  } rewrite;
242 } nat_6t_flow_t;
243 
244 void nat44_ed_forwarding_enable_disable (u8 is_enable);
245 
246 always_inline void
248 {
250  f->rewrite.saddr.as_u32 = saddr;
251 }
252 
253 always_inline void
255 {
257  f->rewrite.daddr.as_u32 = daddr;
258 }
259 
260 always_inline void
262 {
264  f->rewrite.sport = sport;
265 }
266 
267 always_inline void
269 {
271  f->rewrite.dport = dport;
272 }
273 
274 always_inline void
276 {
278  f->rewrite.fib_index = tx_fib_index;
279 }
280 
281 always_inline void
283 {
285  f->rewrite.icmp_id = id;
286 }
287 
288 typedef CLIB_PACKED(struct
289 {
290  /* Outside network tuple */
291  struct
292  {
294  u32 fib_index;
295  u16 port;
296  } out2in;
297 
298  /* Inside network tuple */
299  struct
300  {
302  u32 fib_index;
303  u16 port;
304  } in2out;
305 
306  nat_protocol_t nat_proto;
307 
308  nat_6t_flow_t i2o;
309  nat_6t_flow_t o2i;
310 
311  /* Flags */
312  u32 flags;
313 
314  /* head of LRU list in which this session is tracked */
315  u32 lru_head_index;
316  /* index in global LRU list */
317  u32 lru_index;
318  f64 last_lru_update;
319 
320  /* Last heard timer */
321  f64 last_heard;
322 
323  /* Last HA refresh */
324  f64 ha_last_refreshed;
325 
326  /* Counters */
327  u64 total_bytes;
328  u32 total_pkts;
329 
330  /* External host address and port */
331  ip4_address_t ext_host_addr;
332  u16 ext_host_port;
333 
334  /* External host address and port after translation */
335  ip4_address_t ext_host_nat_addr;
336  u16 ext_host_nat_port;
337 
338  /* TCP session state */
339  u8 state;
340  u32 i2o_fin_seq;
341  u32 o2i_fin_seq;
342  u64 tcp_closed_timestamp;
343 
344  /* per vrf sessions index */
345  u32 per_vrf_sessions_index;
346 
348 }) snat_session_t;
349 
350 typedef struct
351 {
354 #define _(N, i, n, s) \
355  u32 busy_##n##_ports; \
356  u32 * busy_##n##_ports_per_thread; \
357  u32 busy_##n##_port_refcounts[65535];
359 #undef _
361 
362 typedef struct
363 {
366 } nat_fib_t;
367 
368 typedef struct
369 {
373 
374 typedef struct
375 {
376  /* backend IP address */
378  /* backend port number */
380  /* probability of the backend to be randomly matched */
383  /* backend FIB table */
387 
388 typedef enum
389 {
390  /* twice-nat disabled */
392  /* twice-nat enabled */
394  /* twice-nat only when src IP equals dst IP after translation */
397 
398 typedef enum
399 {
400  /* no load-balancing */
402  /* load-balancing */
404  /* load-balancing with affinity */
406 } lb_nat_type_t;
407 
408 typedef struct
409 {
410  /* prefered pool address */
412  /* local IP address */
414  /* external IP address */
416  /* local port */
418  /* external port */
420  /* is twice-nat */
422  /* local FIB table */
425  /* protocol */
427  /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
429  /* worker threads used by backends/local host */
431  /* opaque string tag */
432  u8 *tag;
433  /* backends for load-balancing mode */
435  /* affinity per service lis */
437  /* flags */
440 
441 typedef struct
442 {
446 
447 typedef struct
448 {
461  int exact;
462  u8 *tag;
464 
465 typedef struct
466 {
467  /* Session pool */
468  snat_session_t *sessions;
469 
470  /* Pool of doubly-linked list elements */
472 
473  /* LRU session list - head is stale, tail is fresh */
480 
481  /* NAT thread index */
483 
484  /* real thread index */
486 
487  per_vrf_sessions_t *per_vrf_sessions_vec;
488 
490 
491 struct snat_main_s;
492 
494  u32 rx_fib_index, u8 is_output);
496  u32 rx_fib_index, u8 is_output);
497 
498 /* Return worker thread index for given packet */
499 /* NAT address and port allocation function */
501  addresses,
502  u32 fib_index,
506  u16 * port,
508  u32 snat_thread_index);
509 
510 typedef struct snat_main_s
511 {
512  /* Thread settings */
517 
518  /* Per thread data */
520 
521  /* Find a static mapping by local */
522  clib_bihash_8_8_t static_mapping_by_local;
523 
524  /* Find a static mapping by external */
525  clib_bihash_8_8_t static_mapping_by_external;
526 
527  /* Static mapping pool */
529 
530  /* Endpoint independent lookup tables */
531  clib_bihash_8_8_t in2out;
532  clib_bihash_8_8_t out2in;
533 
534  /* Endpoint dependent lookup table */
535  clib_bihash_16_8_t flow_hash;
536 
537  /* Interface pool */
540 
541  /* Vector of outside addresses */
543  /* Address and port allocation function */
545  /* Address and port allocation type */
547  /* Port set parameters (MAP-E) */
551  /* Port range parameters */
554 
555  /* vector of fibs */
557 
558  /* vector of outside fibs */
560 
561  /* Vector of twice NAT addresses for external hosts */
563 
564  /* sw_if_indices whose intfc addresses should be auto-added */
567 
568  /* vector of interface address static mappings to resolve. */
570 
571  /* Randomize port allocation order */
573 
574  /* Worker handoff frame-queue index */
578 
582 
584  //nat44_config_t cconfig;
585 
586  /* If forwarding is enabled */
588 
589  /* static mapping config */
592 
593  /* Is translation memory size calculated or user defined */
595 
599 
604 
606 
607  /* TCP MSS clamping */
609 
610  /* counters */
612  u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
613  stats */
614 
615 #define _(x) vlib_simple_counter_main_t x;
616  struct
617  {
618  struct
619  {
620  struct
621  {
623  } in2out;
624 
625  struct
626  {
628  } out2in;
629  } fastpath;
630 
631  struct
632  {
633  struct
634  {
636  } in2out;
637 
638  struct
639  {
641  } out2in;
642  } slowpath;
643 
645  } counters;
646 #undef _
647 
648  /* API message ID base */
650 
651  /* log class */
653  /* logging level */
655 
656  /* convenience */
660 
663 
664  /* pat - dynamic mapping enabled or conneciton tracking */
666 
667  /* number of worker handoff frame queue elements */
669 
670  /* nat44 plugin enabled */
672 
674 
675 } snat_main_t;
676 
677 typedef struct
678 {
682 
683 typedef struct
684 {
688 
689 extern snat_main_t snat_main;
690 
691 // nat pre ed next_node feature classification
695 
705 
708 
709 /* format functions */
717 /* unformat functions */
719 
720 /** \brief Check if SNAT session is created from static mapping.
721  @param s SNAT session
722  @return 1 if SNAT session is created from static mapping otherwise 0
723 */
724 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
725 
726 /** \brief Check if SNAT session for unknown protocol.
727  @param s SNAT session
728  @return 1 if SNAT session for unknown protocol otherwise 0
729 */
730 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
731 
732 /** \brief Check if NAT session is twice NAT.
733  @param s NAT session
734  @return 1 if NAT session is twice NAT
735 */
736 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
737 
738 /** \brief Check if NAT session is load-balancing.
739  @param s NAT session
740  @return 1 if NAT session is load-balancing
741 */
742 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
743 
744 /** \brief Check if NAT session is forwarding bypass.
745  @param s NAT session
746  @return 1 if NAT session is load-balancing
747 */
748 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
749 
750 /** \brief Check if NAT session is endpoint dependent.
751  @param s NAT session
752  @return 1 if NAT session is endpoint dependent
753 */
754 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
755 
756 /** \brief Check if NAT session has affinity record.
757  @param s NAT session
758  @return 1 if NAT session has affinity record
759 */
760 #define is_affinity_sessions(s) (s->flags & SNAT_SESSION_FLAG_AFFINITY)
761 
762 /** \brief Check if exact pool address should be used.
763  @param s SNAT session
764  @return 1 if exact pool address or 0
765 */
766 #define is_exact_address_session(s) (s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS)
767 
768 /** \brief Check if NAT interface is inside.
769  @param i NAT interface
770  @return 1 if inside interface
771 */
772 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
773 
774 /** \brief Check if NAT interface is outside.
775  @param i NAT interface
776  @return 1 if outside interface
777 */
778 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
779 
780 /** \brief Check if NAT44 endpoint-dependent TCP session is closed.
781  @param s NAT session
782  @return 1 if session is closed
783 */
784 #define nat44_is_ses_closed(s) s->state == 0xf
785 
786 /** \brief Check if NAT static mapping is address only (1:1NAT).
787  @param sm NAT static mapping
788  @return 1 if 1:1NAT, 0 if 1:1NAPT
789 */
790 #define is_addr_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_ADDR_ONLY)
791 
792 /** \brief Check if NAT static mapping match only out2in direction.
793  @param sm NAT static mapping
794  @return 1 if rule match only out2in direction
795 */
796 #define is_out2in_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY)
797 
798 /** \brief Check if NAT static mapping is identity NAT.
799  @param sm NAT static mapping
800  @return 1 if identity NAT
801 */
802 #define is_identity_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT)
803 
804 /** \brief Check if NAT static mapping is load-balancing.
805  @param sm NAT static mapping
806  @return 1 if load-balancing
807 */
808 #define is_lb_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_LB)
809 
810 /** \brief Check if exact pool address should be used.
811  @param s SNAT session
812  @return 1 if exact pool address or 0
813 */
814 #define is_exact_address(s) (s->flags & NAT_STATIC_MAPPING_FLAG_EXACT_ADDRESS)
815 
816 /** \brief Check if client initiating TCP connection (received SYN from client)
817  @param t TCP header
818  @return 1 if client initiating TCP connection
819 */
820 always_inline bool
822 {
823  return (f & TCP_FLAG_SYN) && !(f & TCP_FLAG_ACK);
824 }
825 
826 /* logging */
827 #define nat_log_err(...) \
828  vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
829 #define nat_log_warn(...) \
830  vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
831 #define nat_log_notice(...) \
832  vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
833 #define nat_log_info(...) \
834  vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
835 #define nat_log_debug(...)\
836  vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
837 
838 /**
839  * @brief Enable NAT44 plugin
840  *
841  * @param c nat44_config_t
842  *
843  * @return 0 on success, non-zero value otherwise
844  */
846 
847 /**
848  * @brief Disable NAT44 plugin
849  *
850  * @return 0 on success, non-zero value otherwise
851  */
852 int nat44_plugin_disable ();
853 
854 /**
855  * @brief Add external address to NAT44 pool
856  *
857  * @param sm snat global configuration data
858  * @param addr IPv4 address
859  * @param vrf_id VRF id of tenant, ~0 means independent of VRF
860  * @param twice_nat 1 if twice NAT address
861  *
862  * @return 0 on success, non-zero value otherwise
863  */
865  u8 twice_nat);
866 
867 /**
868  * @brief Delete external address from NAT44 pool
869  *
870  * @param sm snat global configuration data
871  * @param addr IPv4 address
872  * @param delete_sm 1 if delete static mapping using address
873  * @param twice_nat 1 if twice NAT address
874  *
875  * @return 0 on success, non-zero value otherwise
876  */
877 int snat_del_address (snat_main_t * sm, ip4_address_t addr, u8 delete_sm,
878  u8 twice_nat);
879 
880 /**
881  * @brief Add/delete external address to FIB DPO (out2in DPO mode)
882  *
883  * @param addr IPv4 address
884  * @param is_add 1 = add, 0 = delete
885  *
886  * @return 0 on success, non-zero value otherwise
887  */
889 
890 /**
891  * @brief Add/delete NAT44 static mapping
892  *
893  * @param l_addr local IPv4 address
894  * @param e_addr external IPv4 address
895  * @param l_port local port number
896  * @param e_port external port number
897  * @param vrf_id local VRF ID
898  * @param addr_only 1 = 1:1NAT, 0 = 1:1NAPT
899  * @param sw_if_index use interface address as external IPv4 address
900  * @param proto L4 protocol
901  * @param is_add 1 = add, 0 = delete
902  * @param twice_nat twice-nat mode
903  * @param out2in_only if 1 rule match only out2in direction
904  * @param tag opaque string tag
905  * @param identity_nat identity NAT
906  * @param pool_addr pool IPv4 address
907  * @param exact 1 = exact pool address
908  *
909  * @return 0 on success, non-zero value otherwise
910  */
912  u16 l_port, u16 e_port, u32 vrf_id,
913  int addr_only, u32 sw_if_index,
914  nat_protocol_t proto, int is_add,
915  twice_nat_type_t twice_nat, u8 out2in_only,
916  u8 * tag, u8 identity_nat,
917  ip4_address_t pool_addr, int exact);
918 
919 /**
920  * @brief Add/delete static mapping with load-balancing (multiple backends)
921  *
922  * @param e_addr external IPv4 address
923  * @param e_port external port number
924  * @param proto L4 protocol
925  * @param locals list of local backends
926  * @param is_add 1 = add, 0 = delete
927  * @param twice_nat twice-nat mode
928  * @param out2in_only if 1 rule match only out2in direction
929  * @param tag opaque string tag
930  * @param affinity 0 = disabled, otherwise client IP affinity sticky time
931  *
932  * @return 0 on success, non-zero value otherwise
933  */
936  nat44_lb_addr_port_t * locals, u8 is_add,
937  twice_nat_type_t twice_nat,
938  u8 out2in_only, u8 * tag, u32 affinity);
939 
941  ip4_address_t l_addr, u16 l_port,
943  u8 probability, u8 is_add);
944 
946 
947 /**
948  * @brief Set NAT plugin workers
949  *
950  * @param bitmap NAT workers bitmap
951  *
952  * @return 0 on success, non-zero value otherwise
953  */
954 int snat_set_workers (uword * bitmap);
955 
956 /**
957  * @brief Enable/disable NAT44 feature on the interface
958  *
959  * @param sw_if_index software index of the interface
960  * @param is_inside 1 = inside, 0 = outside
961  * @param is_del 1 = delete, 0 = add
962  *
963  * @return 0 on success, non-zero value otherwise
964  */
965 int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del);
966 
967 /**
968  * @brief Enable/disable NAT44 output feature on the interface (postrouting NAT)
969  *
970  * @param sw_if_index software index of the interface
971  * @param is_inside 1 = inside, 0 = outside
972  * @param is_del 1 = delete, 0 = add
973  *
974  * @return 0 on success, non-zero value otherwise
975  */
977  int is_del);
978 
979 /**
980  * @brief Add/delete NAT44 pool address from specific interface
981  *
982  * @param sw_if_index software index of the interface
983  * @param is_del 1 = delete, 0 = add
984  * @param twice_nat 1 = twice NAT address for external hosts
985  *
986  * @return 0 on success, non-zero value otherwise
987  */
989  u8 twice_nat);
990 
991 /**
992  * @brief Delete NAT44 endpoint-dependent session
993  *
994  * @param sm snat global configuration data
995  * @param addr IPv4 address
996  * @param port L4 port number
997  * @param proto L4 protocol
998  * @param vrf_id VRF ID
999  * @param is_in 1 = inside network address and port pair, 0 = outside
1000  *
1001  * @return 0 on success, non-zero value otherwise
1002  */
1004  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
1005  u32 vrf_id, int is_in);
1006 
1007 /**
1008  * @brief Free NAT44 session data (lookup keys, external address port)
1009  *
1010  * @param sm snat global configuration data
1011  * @param s NAT session
1012  * @param thread_index thread index
1013  * @param is_ha is HA event
1014  */
1015 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
1016  u32 thread_index, u8 is_ha);
1017 
1018 /**
1019  * @brief Set NAT44 session limit (session limit, vrf id)
1020  *
1021  * @param session_limit Session limit
1022  * @param vrf_id VRF id
1023  * @return 0 on success, non-zero value otherwise
1024  */
1025 int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
1026 
1027 /**
1028  * @brief Update NAT44 session limit flushing all data (session limit, vrf id)
1029  *
1030  * @param session_limit Session limit
1031  * @param vrf_id VRF id
1032  * @return 0 on success, non-zero value otherwise
1033  */
1034 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
1035 
1036 /**
1037  * @brief Free outside address and port pair
1038  *
1039  * @param addresses vector of outside addresses
1040  * @param thread_index thread index
1041  * @param key address, port and protocol
1042  */
1043 void
1045  u32 thread_index,
1046  ip4_address_t * addr,
1048 
1049 void expire_per_vrf_sessions (u32 fib_index);
1050 
1051 /**
1052  * @brief Match NAT44 static mapping.
1053  *
1054  * @param key address and port to match
1055  * @param addr external/local address of the matched mapping
1056  * @param port port of the matched mapping
1057  * @param fib_index fib index of the matched mapping
1058  * @param by_external if 0 match by local address otherwise match by external
1059  * address
1060  * @param is_addr_only 1 if matched mapping is address only
1061  * @param twice_nat matched mapping is twice NAT type
1062  * @param lb 1 if matched mapping is load-balanced
1063  * @param ext_host_addr external host address
1064  * @param is_identity_nat 1 if indentity mapping
1065  * @param out if !=0 set to pointer of the mapping structure
1066  *
1067  * @returns 0 if match found otherwise 1.
1068  */
1070  vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port,
1071  u32 match_fib_index, nat_protocol_t match_protocol,
1072  ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index,
1073  u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat,
1074  lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat,
1075  snat_static_mapping_t **out);
1076 
1077 /**
1078  * @brief Add/del NAT address to FIB.
1079  *
1080  * Add the external NAT address to the FIB as receive entries. This ensures
1081  * that VPP will reply to ARP for this address and we don't need to enable
1082  * proxy ARP on the outside interface.
1083  *
1084  * @param addr IPv4 address
1085  * @param plen address prefix length
1086  * @param sw_if_index software index of the outside interface
1087  * @param is_add 0 = delete, 1 = add.
1088  */
1090  u8 p_len, u32 sw_if_index, int is_add);
1091 
1092 #if 0
1093 void
1094 nat_ha_sadd_ed_cb (ip4_address_t * in_addr, u16 in_port,
1095  ip4_address_t * out_addr, u16 out_port,
1096  ip4_address_t * eh_addr, u16 eh_port,
1097  ip4_address_t * ehn_addr, u16 ehn_port, u8 proto,
1098  u32 fib_index, u16 flags, u32 thread_index);
1099 
1100 void
1101 nat_ha_sdel_ed_cb (ip4_address_t * out_addr, u16 out_port,
1102  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
1103  u32 fib_index, u32 ti);
1104 
1105 void
1106 nat_ha_sref_ed_cb (ip4_address_t * out_addr, u16 out_port,
1107  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
1108  u32 fib_index, u32 total_pkts, u64 total_bytes,
1109  u32 thread_index);
1110 #endif
1111 
1115 
1116 /*
1117  * Why is this here? Because we don't need to touch this layer to
1118  * simply reply to an icmp. We need to change id to a unique
1119  * value to NAT an echo request/reply.
1120  */
1121 
1122 typedef struct
1123 {
1124  u16 identifier;
1125  u16 sequence;
1127 
1128 typedef struct
1129 {
1132 
1133 u32 get_thread_idx_by_port (u16 e_port);
1134 
1135 u8 *format_static_mapping_kvp (u8 *s, va_list *args);
1136 
1137 u8 *format_session_kvp (u8 *s, va_list *args);
1138 
1140 
1141 void nat44_addresses_free (snat_address_t **addresses);
1142 
1143 void nat44_ed_sessions_clear ();
1144 
1145 int nat44_ed_set_frame_queue_nelts (u32 frame_queue_nelts);
1146 
1147 typedef enum
1148 {
1153 
1157  int is_output_feature);
1158 
1160 
1164 
1165 #endif /* __included_nat44_ed_h__ */
1166 /*
1167  * fd.io coding-style-patch-verification: ON
1168  *
1169  * Local Variables:
1170  * eval: (c-set-style "gnu")
1171  * End:
1172  */
snat_main_s::to_resolve
snat_static_map_resolve_t * to_resolve
Definition: nat44_ed.h:569
fib_source.h
lib.h
NAT port/address allocation lib.
snat_main_s::port_per_thread
u16 port_per_thread
Definition: nat44_ed.h:516
snat_add_address
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: nat44_ed.c:320
snat_main_s::ip4_lookup_main
ip_lookup_main_t * ip4_lookup_main
Definition: nat44_ed.h:659
nat_6t_t::proto
u8 proto
Definition: nat44_ed.h:213
unformat_nat_protocol
unformat_function_t unformat_nat_protocol
Definition: nat44_ed.h:718
snat_main_per_thread_data_t::unk_proto_lru_head_index
u32 unk_proto_lru_head_index
Definition: nat44_ed.h:479
nat_fib_t::fib_index
u32 fib_index
Definition: nat44_ed.h:364
tcp_flags_is_init
static bool tcp_flags_is_init(u8 f)
Check if client initiating TCP connection (received SYN from client)
Definition: nat44_ed.h:821
nat_6t_flow_saddr_rewrite_set
static void nat_6t_flow_saddr_rewrite_set(nat_6t_flow_t *f, u32 saddr)
Definition: nat44_ed.h:247
snat_in2out_output_worker_handoff_node
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
Definition: nat44_ed_handoff.c:318
nat44_config_flags_t
enum nat44_config_flags_t_ nat44_config_flags_t
snat_static_mapping_t::locals
nat44_lb_addr_port_t * locals
Definition: nat44_ed.h:434
snat_main_s::in2out_output_node_index
u32 in2out_output_node_index
Definition: nat44_ed.h:581
snat_main_s::outside_vrf_id
u32 outside_vrf_id
Definition: nat44_ed.h:600
snat_main_s::counters
struct snat_main_s::@736 counters
snat_main_s::psid_length
u8 psid_length
Definition: nat44_ed.h:549
snat_main_s::static_mappings
snat_static_mapping_t * static_mappings
Definition: nat44_ed.h:528
snat_main_s::end_port
u16 end_port
Definition: nat44_ed.h:553
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
nat_6t_flow_buf_translate
nat_translation_error_e nat_6t_flow_buf_translate(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip, nat_6t_flow_t *f, nat_protocol_t proto, int is_output_feature)
Definition: nat44_ed.c:3424
snat_main_s::twice_nat_addresses
snat_address_t * twice_nat_addresses
Definition: nat44_ed.h:562
nat44_config_t::sessions
u32 sessions
Definition: nat44_ed.h:69
dst_port
vl_api_ip_port_and_mask_t dst_port
Definition: flow_types.api:92
nat44_lb_addr_port_t::addr
ip4_address_t addr
Definition: nat44_ed.h:377
format_nat_protocol
format_function_t format_nat_protocol
Definition: nat44_ed.h:715
bihash_8_8.h
nat_outside_fib_t
Definition: nat44_ed.h:368
snat_main_s::total_sessions
vlib_simple_counter_main_t total_sessions
Definition: nat44_ed.h:611
snat_main_s::ip4_main
ip4_main_t * ip4_main
Definition: nat44_ed.h:658
nat_6t_flow_t::saddr
ip4_address_t saddr
Definition: nat44_ed.h:233
nat44_plugin_disable
int nat44_plugin_disable()
Disable NAT44 plugin.
Definition: nat44_ed.c:2179
LB_NAT
@ LB_NAT
Definition: nat44_ed.h:403
nat_free_session_data
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 address port)
Definition: nat44_ed.c:231
format_snat_key
format_function_t format_snat_key
Definition: nat44_ed.h:713
snat_static_mapping_t::vrf_id
u32 vrf_id
Definition: nat44_ed.h:423
snat_main_s::slowpath
struct snat_main_s::@736::@738 slowpath
nat_calc_bihash_buckets
u32 nat_calc_bihash_buckets(u32 n_elts)
Definition: lib.h:122
nat_pre_trace_t::arc_next_index
u32 arc_next_index
Definition: nat44_ed.h:91
snat_main_s::fib_src_hi
fib_source_t fib_src_hi
Definition: nat44_ed.h:661
elog.h
nat_fib_src_low
fib_source_t nat_fib_src_low
snat_main_s::vnet_main
vnet_main_t * vnet_main
Definition: nat44_ed.h:673
snat_main_per_thread_data_t::udp_lru_head_index
u32 udp_lru_head_index
Definition: nat44_ed.h:477
snat_static_mapping_match
int snat_static_mapping_match(vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port, u32 match_fib_index, nat_protocol_t match_protocol, ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index, 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, snat_static_mapping_t **out)
Match NAT44 static mapping.
Definition: nat44_ed.c:2354
snat_main_per_thread_data_t::lru_pool
dlist_elt_t * lru_pool
Definition: nat44_ed.h:474
f
vlib_frame_t * f
Definition: interface_output.c:1080
snat_main_s::translation_memory_size_set
u8 translation_memory_size_set
Definition: nat44_ed.h:594
nat_outside_fib_t::refcount
u32 refcount
Definition: nat44_ed.h:371
NAT_OUT2IN_ED_N_ERROR
@ NAT_OUT2IN_ED_N_ERROR
Definition: nat44_ed.h:158
format_nat_addr_and_port_alloc_alg
format_function_t format_nat_addr_and_port_alloc_alg
Definition: nat44_ed.h:716
vlib_log_class_t
u32 vlib_log_class_t
Definition: vlib.h:52
NAT_NEXT_IN2OUT_CLASSIFY
@ NAT_NEXT_IN2OUT_CLASSIFY
Definition: nat44_ed.h:83
snat_main_s::start_port
u16 start_port
Definition: nat44_ed.h:552
snat_main_s::translation_buckets
u32 translation_buckets
Definition: nat44_ed.h:596
nat44_api_hookup
clib_error_t * nat44_api_hookup(vlib_main_t *vm)
Definition: nat44_ed_api.c:1552
foreach_nat44_config_flag
#define foreach_nat44_config_flag
Definition: nat44_ed.h:45
nat_6t_t::dport
u16 dport
Definition: nat44_ed.h:211
nat_timeouts_t
Definition: lib.h:76
NAT_FLOW_OP_TXFIB_REWRITE
#define NAT_FLOW_OP_TXFIB_REWRITE
Definition: nat44_ed.h:228
nat_6t_flow_t
Definition: nat44_ed.h:221
snat_set_workers
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
Definition: nat44_ed.c:1759
nat_protocol_t
nat_protocol_t
Definition: lib.h:63
lb_nat_type_t
lb_nat_type_t
Definition: nat44_ed.h:398
snat_main_per_thread_data_t::snat_thread_index
u32 snat_thread_index
Definition: nat44_ed.h:482
snat_out2in_node
vlib_node_registration_t snat_out2in_node
snat_main_s::interfaces
snat_interface_t * interfaces
Definition: nat44_ed.h:538
snat_in2out_node
vlib_node_registration_t snat_in2out_node
nat_6t_flow_t::match
nat_6t_t match
Definition: nat44_ed.h:230
dlist.h
snat_static_map_resolve_t::l_port
u16 l_port
Definition: nat44_ed.h:451
AFFINITY_LB_NAT
@ AFFINITY_LB_NAT
Definition: nat44_ed.h:405
snat_main_s::out2in_node_index
u32 out2in_node_index
Definition: nat44_ed.h:579
probability
u8 probability
Definition: nat44_ed.api:1052
snat_main_s::log_class
vlib_log_class_t log_class
Definition: nat44_ed.h:652
nat_in2out_ed_error_t
nat_in2out_ed_error_t
Definition: nat44_ed.h:135
u16
unsigned short u16
Definition: types.h:57
nat_6t_t::as_u128
u64x2u as_u128
Definition: nat44_ed.h:216
snat_static_mapping_t::tag
u8 * tag
Definition: nat44_ed.h:432
nat_6t_flow_t::fib_index
u32 fib_index
Definition: nat44_ed.h:236
snat_main_t
struct snat_main_s snat_main_t
snat_runtime_t::cached_sw_if_index
u32 cached_sw_if_index
Definition: nat44_ed.h:685
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
snat_static_map_resolve_t::pool_addr
ip4_address_t pool_addr
Definition: nat44_ed.h:450
api.h
snat_main_s::workers
u32 * workers
Definition: nat44_ed.h:515
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
snat_main_s::psid
u16 psid
Definition: nat44_ed.h:550
port
u16 port
Definition: lb_types.api:73
NAT_NEXT_IN2OUT_ED_SLOW_PATH
@ NAT_NEXT_IN2OUT_ED_SLOW_PATH
Definition: nat44_ed.h:78
nat_6t_flow_daddr_rewrite_set
static void nat_6t_flow_daddr_rewrite_set(nat_6t_flow_t *f, u32 daddr)
Definition: nat44_ed.h:254
nat_6t_flow_t::proto
u8 proto
Definition: nat44_ed.h:237
snat_static_mapping_t::proto
nat_protocol_t proto
Definition: nat44_ed.h:426
snat_main_s::timeouts
nat_timeouts_t timeouts
Definition: nat44_ed.h:605
nat44_lb_addr_port_t::port
u16 port
Definition: nat44_ed.h:379
snat_static_mapping_t::local_addr
ip4_address_t local_addr
Definition: nat44_ed.h:413
snat_main_s::addresses
snat_address_t * addresses
Definition: nat44_ed.h:542
snat_add_static_mapping
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, nat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat, ip4_address_t pool_addr, int exact)
Add/delete NAT44 static mapping.
Definition: nat44_ed.c:484
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
nat_6t_flow_t::ops
int ops
Definition: nat44_ed.h:229
CLIB_PACKED
typedef CLIB_PACKED(struct { u32 ses_count;u32 rx_fib_index;u32 tx_fib_index;u8 expired;}) per_vrf_sessions_t
snat_main_s::static_mapping_by_external
clib_bihash_8_8_t static_mapping_by_external
Definition: nat44_ed.h:525
nat_outside_fib_t::fib_index
u32 fib_index
Definition: nat44_ed.h:370
nat_6t_l3_l4_csum_calc
void nat_6t_l3_l4_csum_calc(nat_6t_flow_t *f)
Definition: nat44_ed.c:3205
snat_free_outside_address_and_port
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, ip4_address_t *addr, u16 port, nat_protocol_t protocol)
Free outside address and port pair.
Definition: nat44_ed.c:2280
format_snat_static_mapping
format_function_t format_snat_static_mapping
Definition: nat44_ed.h:710
snat_main_s::psid_offset
u8 psid_offset
Definition: nat44_ed.h:548
TWICE_NAT_DISABLED
@ TWICE_NAT_DISABLED
Definition: nat44_ed.h:391
snat_static_mapping_t::flags
u32 flags
Definition: nat44_ed.h:438
format_static_mapping_key
format_function_t format_static_mapping_key
Definition: nat44_ed.h:714
ip4_header_t
Definition: ip4_packet.h:87
ethernet.h
nat_pre_in2out_node
vlib_node_registration_t nat_pre_in2out_node
(constructor) VLIB_REGISTER_NODE (nat_pre_in2out_node)
Definition: nat44_ed_in2out.c:1624
snat_main_s::log_level
u8 log_level
Definition: nat44_ed.h:654
format_session_kvp
u8 * format_session_kvp(u8 *s, va_list *args)
Definition: nat44_ed.c:186
snat_main_s::outside_fib_index
u32 outside_fib_index
Definition: nat44_ed.h:601
snat_main_s::forwarding_enabled
u8 forwarding_enabled
Definition: nat44_ed.h:587
TCP_FLAG_SYN
#define TCP_FLAG_SYN
Definition: fa_node.h:13
nat_6t_t::fib_index
u32 fib_index
Definition: nat44_ed.h:212
get_thread_idx_by_port
u32 get_thread_idx_by_port(u16 e_port)
Definition: nat44_ed.c:426
nat44_ed_get_out2in_worker_index
u32 nat44_ed_get_out2in_worker_index(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
Definition: nat44_ed.c:2606
sport
u16 sport
Definition: pnat.api:43
snat_main_per_thread_data_t::icmp_lru_head_index
u32 icmp_lru_head_index
Definition: nat44_ed.h:478
nat44_ed_in2out_output_node
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
Definition: nat44_ed_in2out.c:1538
nat_next_t
nat_next_t
Definition: nat44_ed.h:73
snat_main_s::addr_and_port_alloc_alg
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat44_ed.h:546
snat_address_t
Definition: nat44_ed.h:350
foreach_nat_protocol
@ foreach_nat_protocol
Definition: lib.h:66
snat_main_s::pat
u8 pat
Definition: nat44_ed.h:665
snat_static_map_resolve_t::flags
u32 flags
Definition: nat44_ed.h:456
ti
u32 ti
Definition: interface_output.c:405
snat_out2in_worker_handoff_node
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
Definition: nat44_ed_handoff.c:337
nat44_del_ed_session
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: nat44_ed.c:3144
NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH
@ NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH
Definition: nat44_ed.h:80
nat_addr_and_port_alloc_alg_t
nat_addr_and_port_alloc_alg_t
Definition: nat44_ed.h:100
snat_main_s::per_thread_data
snat_main_per_thread_data_t * per_thread_data
Definition: nat44_ed.h:519
nat44_ed_forwarding_enable_disable
void nat44_ed_forwarding_enable_disable(u8 is_enable)
Definition: nat44_ed.c:2246
error.h
snat_main_s::rconfig
nat44_config_t rconfig
Definition: nat44_ed.h:583
NAT_NEXT_ICMP_ERROR
@ NAT_NEXT_ICMP_ERROR
Definition: nat44_ed.h:76
snat_main_s::flow_hash
clib_bihash_16_8_t flow_hash
Definition: nat44_ed.h:535
NAT_NEXT_IN2OUT_ED_FAST_PATH
@ NAT_NEXT_IN2OUT_ED_FAST_PATH
Definition: nat44_ed.h:77
snat_main_s::first_worker_index
u32 first_worker_index
Definition: nat44_ed.h:514
nat44_lb_addr_port_t::probability
u8 probability
Definition: nat44_ed.h:381
snat_main_per_thread_data_t::per_vrf_sessions_vec
per_vrf_sessions_t * per_vrf_sessions_vec
Definition: nat44_ed.h:487
twice_nat_type_t
twice_nat_type_t
Definition: nat44_ed.h:388
NAT_FLOW_OP_DADDR_REWRITE
#define NAT_FLOW_OP_DADDR_REWRITE
Definition: nat44_ed.h:225
NAT_NEXT_OUT2IN_ED_FAST_PATH
@ NAT_NEXT_OUT2IN_ED_FAST_PATH
Definition: nat44_ed.h:81
snat_main_s::outside_fibs
nat_outside_fib_t * outside_fibs
Definition: nat44_ed.h:559
nat44_ed_sessions_clear
void nat44_ed_sessions_clear()
Definition: nat44_ed.c:2909
nat44_config_t::inside_vrf
u32 inside_vrf
Definition: nat44_ed.h:65
snat_static_mapping_t::affinity_per_service_list_head_index
u32 affinity_per_service_list_head_index
Definition: nat44_ed.h:436
nat44_update_session_limit
int nat44_update_session_limit(u32 session_limit, u32 vrf_id)
Update NAT44 session limit flushing all data (session limit, vrf id)
Definition: nat44_ed.c:2789
foreach_snat_session_state
#define foreach_snat_session_state
Definition: nat44_ed.h:108
snat_in2out_worker_handoff_node
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
Definition: nat44_ed_handoff.c:298
nat_out2in_ed_error_t
nat_out2in_ed_error_t
Definition: nat44_ed.h:153
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
expire_per_vrf_sessions
void expire_per_vrf_sessions(u32 fib_index)
Definition: nat44_ed.c:1340
format_static_mapping_kvp
u8 * format_static_mapping_kvp(u8 *s, va_list *args)
Definition: nat44_ed.c:198
NAT_FLOW_OP_ICMP_ID_REWRITE
#define NAT_FLOW_OP_ICMP_ID_REWRITE
Definition: nat44_ed.h:227
uword
u64 uword
Definition: types.h:112
nat_6t_flow_t::l4_csum_delta
uword l4_csum_delta
Definition: nat44_ed.h:241
snat_main_per_thread_data_t::thread_index
u32 thread_index
Definition: nat44_ed.h:485
tcp_udp_header_t
Definition: nat44_ei.h:93
snat_main_s::fq_in2out_output_index
u32 fq_in2out_output_index
Definition: nat44_ed.h:576
snat_main_s::fq_out2in_index
u32 fq_out2in_index
Definition: nat44_ed.h:577
TWICE_NAT_SELF
@ TWICE_NAT_SELF
Definition: nat44_ed.h:395
nat44_lb_static_mapping_add_del_local
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, nat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
Definition: nat44_ed.c:1084
snat_main_s::fq_in2out_index
u32 fq_in2out_index
Definition: nat44_ed.h:575
src_port
vl_api_ip_port_and_mask_t src_port
Definition: flow_types.api:91
snat_static_mapping_t::workers
u32 * workers
Definition: nat44_ed.h:430
f64
double f64
Definition: types.h:142
snat_add_interface_address
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 interface.
Definition: nat44_ed.c:3076
nat_6t_t
Definition: nat44_ed.h:205
nat_6t_flow_icmp_id_rewrite_set
static void nat_6t_flow_icmp_id_rewrite_set(nat_6t_flow_t *f, u16 id)
Definition: nat44_ed.h:282
dlist_elt_t
Definition: dlist.h:28
nat44_ed_get_in2out_worker_index
u32 nat44_ed_get_in2out_worker_index(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
Definition: nat44_ed.c:2503
nat44_lb_addr_port_t
Definition: nat44_ed.h:374
snat_static_mapping_t::external_port
u16 external_port
Definition: nat44_ed.h:419
format_snat_static_map_to_resolve
format_function_t format_snat_static_map_to_resolve
Definition: nat44_ed.h:711
snat_main_s::fib_src_low
fib_source_t fib_src_low
Definition: nat44_ed.h:662
snat_main_s::fastpath
struct snat_main_s::@736::@737 fastpath
snat_static_map_resolve_t::addr_only
int addr_only
Definition: nat44_ed.h:457
snat_static_map_resolve_t::tag
u8 * tag
Definition: nat44_ed.h:462
ip4_address_t
Definition: ip4_packet.h:50
snat_static_mapping_t::twice_nat
twice_nat_type_t twice_nat
Definition: nat44_ed.h:421
inlines.h
snat_main_s
Definition: nat44_ed.h:510
snat_main_per_thread_data_t::sessions
snat_session_t * sessions
Definition: nat44_ed.h:468
NAT_ED_TRNSL_ERR_FLOW_MISMATCH
@ NAT_ED_TRNSL_ERR_FLOW_MISMATCH
Definition: nat44_ed.h:1151
snat_static_map_resolve_t::twice_nat
int twice_nat
Definition: nat44_ed.h:458
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
nat44_ed_out2in_node
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
Definition: nat44_ed_out2in.c:1403
nat44_add_del_address_dpo
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
STATIC_ASSERT_SIZEOF
STATIC_ASSERT_SIZEOF(nat_6t_t, 2 *sizeof(u64))
nat44_config_flags_t_
nat44_config_flags_t_
Definition: nat44_ed.h:52
nat_pre_trace_t::next_index
u32 next_index
Definition: nat44_ed.h:90
NAT_N_NEXT
@ NAT_N_NEXT
Definition: nat44_ed.h:85
nat_set_outside_address_and_port
int nat_set_outside_address_and_port(snat_address_t *addresses, u32 thread_index, ip4_address_t addr, u16 port, nat_protocol_t protocol)
Definition: nat44_ed.c:2317
snat_static_map_resolve_t::identity_nat
int identity_nat
Definition: nat44_ed.h:460
foreach_nat_in2out_ed_error
#define foreach_nat_in2out_ed_error
Definition: nat44_ed.h:127
nat44_lb_addr_port_t::fib_index
u32 fib_index
Definition: nat44_ed.h:385
nat_6t_flow_t::dport
u16 dport
Definition: nat44_ed.h:235
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
snat_main_s::fibs
nat_fib_t * fibs
Definition: nat44_ed.h:556
snat_main_per_thread_data_t::list_pool
dlist_elt_t * list_pool
Definition: nat44_ed.h:471
id
u8 id[64]
Definition: dhcp.api:160
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
nat44_lb_addr_port_t::prefix
u8 prefix
Definition: nat44_ed.h:382
format_nat_ed_translation_error
format_function_t format_nat_ed_translation_error
Definition: nat44_ed.h:1161
snat_main_per_thread_data_t::tcp_trans_lru_head_index
u32 tcp_trans_lru_head_index
Definition: nat44_ed.h:475
vnet_main_t
Definition: vnet.h:76
snat_main_s::msg_id_base
u16 msg_id_base
Definition: nat44_ed.h:649
nat_default_node
vlib_node_registration_t nat_default_node
(constructor) VLIB_REGISTER_NODE (nat_default_node)
Definition: nat44_ed.c:3183
nat44_is_idle_session_ctx_t
Definition: nat44_ed.h:677
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
snat_main_s::frame_queue_nelts
u32 frame_queue_nelts
Definition: nat44_ed.h:668
NAT_FLOW_OP_DPORT_REWRITE
#define NAT_FLOW_OP_DPORT_REWRITE
Definition: nat44_ed.h:226
snat_main_s::max_translations_per_fib
u32 * max_translations_per_fib
Definition: nat44_ed.h:598
NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH
@ NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH
Definition: nat44_ed.h:79
nat_6t_flow_t::sport
u16 sport
Definition: nat44_ed.h:234
nat44_set_session_limit
int nat44_set_session_limit(u32 session_limit, u32 vrf_id)
Set NAT44 session limit (session limit, vrf id)
Definition: nat44_ed.c:2770
nat44_config_t
Definition: nat44_ed.h:59
nat44_lb_addr_port_t::vrf_id
u32 vrf_id
Definition: nat44_ed.h:384
u64
unsigned long u64
Definition: types.h:89
nat_6t_flow_sport_rewrite_set
static void nat_6t_flow_sport_rewrite_set(nat_6t_flow_t *f, u32 sport)
Definition: nat44_ed.h:261
TWICE_NAT
@ TWICE_NAT
Definition: nat44_ed.h:393
snat_interface_add_del
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 feature on the interface.
Definition: nat44_ed.c:1397
snat_interface_t::flags
u8 flags
Definition: nat44_ed.h:444
dport
u16 dport
Definition: pnat.api:44
ip.h
u32
unsigned int u32
Definition: types.h:88
snat_static_mapping_t::fib_index
u32 fib_index
Definition: nat44_ed.h:424
snat_static_mapping_t::pool_addr
ip4_address_t pool_addr
Definition: nat44_ed.h:411
nat44_ed_set_frame_queue_nelts
int nat44_ed_set_frame_queue_nelts(u32 frame_queue_nelts)
Definition: nat44_ed.c:1785
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
nat_fib_t
Definition: nat44_ed.h:362
snat_main_s::max_cfg_sessions_gauge
u32 max_cfg_sessions_gauge
Definition: nat44_ed.h:612
nat44_config_t::static_mapping_only
u8 static_mapping_only
Definition: nat44_ed.h:62
snat_main_s::auto_add_sw_if_indices
u32 * auto_add_sw_if_indices
Definition: nat44_ed.h:565
snat_main_s::mss_clamping
u16 mss_clamping
Definition: nat44_ed.h:608
NAT_FLOW_OP_SADDR_REWRITE
#define NAT_FLOW_OP_SADDR_REWRITE
Definition: nat44_ed.h:223
snat_main_s::static_mapping_by_local
clib_bihash_8_8_t static_mapping_by_local
Definition: nat44_ed.h:522
format_ed_session_kvp
format_function_t format_ed_session_kvp
Definition: nat44_ed.h:1163
snat_main_s::max_translations_per_thread
u32 max_translations_per_thread
Definition: nat44_ed.h:597
as_u64
u64 as_u64
Definition: bihash_doc.h:63
snat_runtime_t
Definition: nat44_ed.h:683
unformat_function_t
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:225
snat_static_map_resolve_t::vrf_id
u32 vrf_id
Definition: nat44_ed.h:454
nat_6t_flow_t::icmp_id
u16 icmp_id
Definition: nat44_ed.h:238
snat_del_address
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: nat44_ed.c:1224
NAT_NEXT_DROP
@ NAT_NEXT_DROP
Definition: nat44_ed.h:75
snat_main_s::inside_vrf_id
u32 inside_vrf_id
Definition: nat44_ed.h:602
bihash_16_8.h
NAT_NEXT_OUT2IN_ED_SLOW_PATH
@ NAT_NEXT_OUT2IN_ED_SLOW_PATH
Definition: nat44_ed.h:82
format_nat_6t_flow
format_function_t format_nat_6t_flow
Definition: nat44_ed.h:1162
icmp_echo_header_t
Definition: nat44_ei.h:87
ip_lookup_main_t
Definition: lookup.h:121
nat_pre_trace_t
Definition: nat44_ed.h:88
snat_main_s::inside_fib_index
u32 inside_fib_index
Definition: nat44_ed.h:603
snat_main_s::foreach_nat_counter
foreach_nat_counter
Definition: nat44_ed.h:622
vlib_main_t
Definition: main.h:102
snat_static_map_resolve_t::proto
nat_protocol_t proto
Definition: nat44_ed.h:455
snat_static_map_resolve_t::sw_if_index
u32 sw_if_index
Definition: nat44_ed.h:453
nat44_is_idle_session_ctx_t::now
f64 now
Definition: nat44_ed.h:680
nat_fib_src_hi
fib_source_t nat_fib_src_hi
Definition: dslite.c:22
NAT_NEXT_OUT2IN_CLASSIFY
@ NAT_NEXT_OUT2IN_CLASSIFY
Definition: nat44_ed.h:84
nat44_plugin_enable
int nat44_plugin_enable(nat44_config_t c)
Enable NAT44 plugin.
Definition: nat44_ed.c:2099
vlib_simple_counter_main_t
A collection of simple counters.
Definition: counter.h:57
snat_static_map_resolve_t::out2in_only
int out2in_only
Definition: nat44_ed.h:459
nat_pre_out2in_node
vlib_node_registration_t nat_pre_out2in_node
(constructor) VLIB_REGISTER_NODE (nat_pre_out2in_node)
Definition: nat44_ed_out2in.c:1454
TCP_FLAG_ACK
#define TCP_FLAG_ACK
Definition: fa_node.h:16
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
NAT_IN2OUT_ED_N_ERROR
@ NAT_IN2OUT_ED_N_ERROR
Definition: nat44_ed.h:140
ip
vl_api_address_t ip
Definition: l2.api:558
snat_main_s::num_workers
u32 num_workers
Definition: nat44_ed.h:513
snat_main_s::hairpinning
vlib_simple_counter_main_t hairpinning
Definition: nat44_ed.h:644
icmp46_packet.h
NO_LB_NAT
@ NO_LB_NAT
Definition: nat44_ed.h:401
snat_interface_t
Definition: nat44_ed.h:441
snat_address_t::fib_index
u32 fib_index
Definition: nat44_ed.h:353
snat_main
snat_main_t snat_main
Definition: nat44_ed.c:41
foreach_nat_addr_and_port_alloc_alg
#define foreach_nat_addr_and_port_alloc_alg
Definition: nat44_ed.h:95
snat_static_mapping_t::external_addr
ip4_address_t external_addr
Definition: nat44_ed.h:415
NAT_FLOW_OP_SPORT_REWRITE
#define NAT_FLOW_OP_SPORT_REWRITE
Definition: nat44_ed.h:224
foreach_nat_out2in_ed_error
#define foreach_nat_out2in_ed_error
Definition: nat44_ed.h:143
nat44_config_t::connection_tracking
u8 connection_tracking
Definition: nat44_ed.h:63
snat_main_s::out2in
clib_bihash_8_8_t out2in
Definition: nat44_ed.h:532
fib_source_t
enum fib_source_t_ fib_source_t
The different sources that can create a route.
snat_interface_t::sw_if_index
u32 sw_if_index
Definition: nat44_ed.h:443
snat_main_s::alloc_addr_and_port
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat44_ed.h:544
snat_static_mapping_t
Definition: nat44_ed.h:408
vrf_id
u32 vrf_id
Definition: nat44_ed.api:1053
nat_6t_t::saddr
ip4_address_t saddr
Definition: nat44_ed.h:209
nat44_config_t::outside_vrf
u32 outside_vrf
Definition: nat44_ed.h:66
nat44_ed_in2out_node
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
Definition: nat44_ed_in2out.c:1513
snat_static_map_resolve_t
Definition: nat44_ed.h:447
snat_in2out_output_node
vlib_node_registration_t snat_in2out_output_node
nat_6t_flow_t::l3_csum_delta
uword l3_csum_delta
Definition: nat44_ed.h:240
snat_address_t::addr
ip4_address_t addr
Definition: nat44_ed.h:352
vnet.h
snat_main_per_thread_data_t
Definition: nat44_ed.h:465
api_errno.h
nat_translation_error_e
nat_translation_error_e
Definition: nat44_ed.h:1147
nat_6t_t::sport
u16 sport
Definition: nat44_ed.h:210
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
ip4_main_t
IPv4 main type.
Definition: ip4.h:107
snat_static_mapping_t::local_port
u16 local_port
Definition: nat44_ed.h:417
snat_static_mapping_t::affinity
u32 affinity
Definition: nat44_ed.h:428
nat44_is_idle_session_ctx_t::thread_index
u32 thread_index
Definition: nat44_ed.h:679
snat_main_per_thread_data_t::tcp_estab_lru_head_index
u32 tcp_estab_lru_head_index
Definition: nat44_ed.h:476
snat_main_s::static_mapping_only
u8 static_mapping_only
Definition: nat44_ed.h:590
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
rewrite
rewrite
Definition: pnat.api:158
snat_static_map_resolve_t::e_port
u16 e_port
Definition: nat44_ed.h:452
snat_runtime_t::cached_ip4_address
u32 cached_ip4_address
Definition: nat44_ed.h:686
nat44_addresses_free
void nat44_addresses_free(snat_address_t **addresses)
Definition: nat44_ed.c:2164
NAT_ED_TRNSL_ERR_SUCCESS
@ NAT_ED_TRNSL_ERR_SUCCESS
Definition: nat44_ed.h:1149
nat_6t_flow_dport_rewrite_set
static void nat_6t_flow_dport_rewrite_set(nat_6t_flow_t *f, u32 dport)
Definition: nat44_ed.h:268
nat44_add_del_lb_static_mapping
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, nat_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: nat44_ed.c:856
NAT_ED_TRNSL_ERR_TRANSLATION_FAILED
@ NAT_ED_TRNSL_ERR_TRANSLATION_FAILED
Definition: nat44_ed.h:1150
snat_add_del_addr_to_fib
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: nat44_ed.c:291
nat_alloc_out_addr_and_port_function_t
int() nat_alloc_out_addr_and_port_function_t(snat_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 snat_thread_index)
Definition: nat44_ed.h:500
snat_static_map_resolve_t::l_addr
ip4_address_t l_addr
Definition: nat44_ed.h:449
snat_main_s::static_mapping_connection_tracking
u8 static_mapping_connection_tracking
Definition: nat44_ed.h:591
nat_fib_t::ref_count
u32 ref_count
Definition: nat44_ed.h:365
snat_main_s::in2out_node_index
u32 in2out_node_index
Definition: nat44_ed.h:580
snat_interface_add_del_output_feature
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: nat44_ed.c:1595
snat_main_s::auto_add_sw_if_indices_twice_nat
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat44_ed.h:566
format_snat_session
format_function_t format_snat_session
Definition: nat44_ed.h:712
snat_main_s::api_main
api_main_t * api_main
Definition: nat44_ed.h:657
snat_session_state_t
snat_session_state_t
Definition: nat44_ed.h:120
snat_main_s::enabled
u8 enabled
Definition: nat44_ed.h:671
snat_main_s::random_seed
u32 random_seed
Definition: nat44_ed.h:572
snat_main_s::in2out
clib_bihash_8_8_t in2out
Definition: nat44_ed.h:531
nat_6t_flow_txfib_rewrite_set
static void nat_6t_flow_txfib_rewrite_set(nat_6t_flow_t *f, u32 tx_fib_index)
Definition: nat44_ed.h:275
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
snat_static_map_resolve_t::exact
int exact
Definition: nat44_ed.h:461
snat_main_s::output_feature_interfaces
snat_interface_t * output_feature_interfaces
Definition: nat44_ed.h:539
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105