NAT: add support for configurable port range (VPP-1346)
[vpp.git] / src / plugins / nat / nat.api
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 option version = "4.0.0";
17
18 /**
19  * @file nat.api
20  * @brief VPP control-plane API messages.
21  *
22  * This file defines VPP control-plane API messages which are generally
23  * called through a shared memory interface.
24  */
25
26 /*
27  * Common NAT plugin APIs
28  */
29
30 /** \brief Control ping from client to api server request
31     @param client_index - opaque cookie to identify the sender
32     @param context - sender context, to match reply w/ request
33 */
34 define nat_control_ping
35 {
36   u32 client_index;
37   u32 context;
38 };
39
40 /** \brief Control ping from the client to the server response
41     @param client_index - opaque cookie to identify the sender
42     @param context - sender context, to match reply w/ request
43     @param retval - return code for the request
44     @param vpe_pid - the pid of the vpe, returned by the server
45 */
46 define nat_control_ping_reply
47 {
48   u32 context;
49   i32 retval;
50   u32 client_index;
51   u32 vpe_pid;
52 };
53
54 /** \brief Show NAT plugin startup config
55     @param client_index - opaque cookie to identify the sender
56     @param context - sender context, to match reply w/ request
57 */
58 define nat_show_config
59 {
60   u32 client_index;
61   u32 context;
62 };
63
64 /** \brief Show NAT plugin startup config reply
65     @param context - sender context, to match reply w/ request
66     @param retval - return code for the request
67     @param static_mapping_only - if 1 dynamic translations disabled
68     @param static_mapping_connection_tracking - if 1 create session data
69     @param deterministic - if 1 deterministic mapping
70     @param endpoint_dependent - if 1 endpoint-dependent mode
71     @param out2in_dpo - if 1 out2in dpo mode
72     @param translation_buckets - number of translation hash buckets
73     @param translation_memory_size - translation hash memory size
74     @param user_buckets - number of user hash buckets
75     @param user_memory_size - user hash memory size
76     @param max_translations_per_user - maximum number of translations per user
77     @param outside_vrf_id - outside VRF id
78     @param inside_vrf_id - default inside VRF id
79     @param dslite_ce - if DS-Lite is CE/B4 element, if 0 AFTR elemet
80     @param nat64_bib_buckets - number of NAT64 BIB hash buckets
81     @param nat64_bib_memory_size - memory size of NAT64 BIB hash
82     @param nat64_st_buckets - number of NAT64 session table hash buckets
83     @param nat64_st_memory_size - memory size of NAT64 session table hash
84 */
85 define nat_show_config_reply
86 {
87   u32 context;
88   i32 retval;
89   u8 static_mapping_only;
90   u8 static_mapping_connection_tracking;
91   u8 deterministic;
92   u8 endpoint_dependent;
93   u8 out2in_dpo;
94   u32 translation_buckets;
95   u32 translation_memory_size;
96   u32 user_buckets;
97   u32 user_memory_size;
98   u32 max_translations_per_user;
99   u32 outside_vrf_id;
100   u32 inside_vrf_id;
101   u8 dslite_ce;
102   u32 nat64_bib_buckets;
103   u32 nat64_bib_memory_size;
104   u32 nat64_st_buckets;
105   u32 nat64_st_memory_size;
106 };
107
108 /** \brief Set NAT workers
109     @param client_index - opaque cookie to identify the sender
110     @param context - sender context, to match reply w/ request
111     @param worker_mask - NAT workers mask
112 */
113 autoreply define nat_set_workers {
114   u32 client_index;
115   u32 context;
116   u64 worker_mask;
117 };
118
119 /** \brief Dump NAT workers
120     @param client_index - opaque cookie to identify the sender
121     @param context - sender context, to match reply w/ request
122 */
123 define nat_worker_dump {
124   u32 client_index;
125   u32 context;
126 };
127
128 /** \brief NAT workers details response
129     @param context - sender context, to match reply w/ request
130     @param worker_index - worker index
131     @param lcore_id - lcore ID
132     @param name - worker name
133 */
134 define nat_worker_details {
135   u32 context;
136   u32 worker_index;
137   u32 lcore_id;
138   u8 name[64];
139 };
140
141 /** \brief Enable/disable NAT IPFIX logging
142     @param client_index - opaque cookie to identify the sender
143     @param context - sender context, to match reply w/ request
144     @param domain_id - observation domain ID
145     @param src_port - source port number
146     @param enable - 1 if enable, 0 if disable
147 */
148 autoreply define nat_ipfix_enable_disable {
149   u32 client_index;
150   u32 context;
151   u32 domain_id;
152   u16 src_port;
153   u8 enable;
154 };
155
156 /** \brief Set NAT virtual fragmentation reassembly
157     @param client_index - opaque cookie to identify the sender
158     @param context - sender context, to match reply w/ request
159     @param timeout - reassembly timeout
160     @param max_reass - maximum number of concurrent reassemblies
161     @param max_frag - maximum number of fragmets per reassembly
162     @param drop_frag - if 0 translate fragments, otherwise drop fragments
163     @param is_ip6 - 1 if IPv6, 0 if IPv4
164 */
165 autoreply define nat_set_reass {
166   u32 client_index;
167   u32 context;
168   u32 timeout;
169   u16 max_reass;
170   u8  max_frag;
171   u8  drop_frag;
172   u8  is_ip6;
173 };
174
175 /** \brief Get NAT virtual fragmentation reassembly configuration
176     @param client_index - opaque cookie to identify the sender
177     @param context - sender context, to match reply w/ request
178 */
179 define nat_get_reass {
180   u32 client_index;
181   u32 context;
182 };
183
184 /** \brief Get NAT virtual fragmentation reassembly configuration reply
185     @param context - sender context, to match reply w/ request
186     @param retval - return code
187     @param ip4_timeout - reassembly timeout
188     @param ip4_max_reass - maximum number of concurrent reassemblies
189     @param ip4_max_frag - maximum number of fragmets per reassembly
190     @param ip4_drop_frag - if 0 translate fragments, otherwise drop fragments
191     @param ip6_timeout - reassembly timeout
192     @param ip6_max_reass - maximum number of concurrent reassemblies
193     @param ip6_max_frag - maximum number of fragmets per reassembly
194     @param ip6_drop_frag - if 0 translate fragments, otherwise drop fragments
195 */
196 define nat_get_reass_reply {
197   u32 context;
198   i32 retval;
199   u32 ip4_timeout;
200   u16 ip4_max_reass;
201   u8  ip4_max_frag;
202   u8  ip4_drop_frag;
203   u32 ip6_timeout;
204   u16 ip6_max_reass;
205   u8  ip6_max_frag;
206   u8  ip6_drop_frag;
207 };
208
209 /** \brief Dump NAT virtual fragmentation reassemblies
210     @param client_index - opaque cookie to identify the sender
211     @param context - sender context, to match reply w/ request
212 */
213 define nat_reass_dump {
214   u32 client_index;
215   u32 context;
216 };
217
218 /** \brief NAT virtual fragmentation reassemblies response
219     @param context - sender context, to match reply w/ request
220     @param is_ip4 - 1 if address type is IPv4
221     @param src_addr - source IP address
222     @param dst_addr - destination IP address
223     @param frag_id - fragment ID
224     @param proto - protocol
225     @param frag_n - number of cached fragments
226 */
227 define nat_reass_details {
228   u32 context;
229   u8 is_ip4;
230   u8 src_addr[16];
231   u8 dst_addr[16];
232   u32 frag_id;
233   u8 proto;
234   u8 frag_n;
235 };
236
237 /** \brief Set values of timeouts for NAT sessions (seconds)
238     @param client_index - opaque cookie to identify the sender
239     @param context - sender context, to match reply w/ request
240     @param udp - UDP timeout (default 300sec)
241     @param tcp_established - TCP established timeout (default 7440sec)
242     @param tcp_transitory - TCP transitory timeout (default 240sec)
243     @param icmp - ICMP timeout (default 60sec)
244 */
245 autoreply define nat_set_timeouts {
246   u32 client_index;
247   u32 context;
248   u32 udp;
249   u32 tcp_established;
250   u32 tcp_transitory;
251   u32 icmp;
252 };
253
254 /** \brief Get values of timeouts for NAT sessions (seconds)
255     @param client_index - opaque cookie to identify the sender
256     @param context - sender context, to match reply w/ request
257 */
258 define nat_get_timeouts {
259   u32 client_index;
260   u32 context;
261 };
262
263 /** \brief Get values of timeouts for NAT sessions reply
264     @param context - sender context, to match reply w/ request
265     @param retval - return code
266     @param udp - UDP timeout
267     @param tcp_established - TCP established timeout
268     @param tcp_transitory - TCP transitory timeout
269     @param icmp - ICMP timeout
270 */
271 define nat_get_timeouts_reply {
272   u32 context;
273   i32 retval;
274   u32 udp;
275   u32 tcp_established;
276   u32 tcp_transitory;
277   u32 icmp;
278 };
279
280 /** \brief Set address and port assignment algorithm
281     @param client_index - opaque cookie to identify the sender
282     @param context - sender context, to match reply w/ request
283     @param alg - address and port assignment algorithm:
284                  0 - default, 1 - MAP-E, 2 - port range
285                  (see nat_addr_and_port_alloc_alg_t in nat.h)
286     @param psid_offset - number of offset bits (valid only for MAP-E alg)
287     @param psid_length - length of PSID (valid only for MAP-E alg)
288     @param psid - Port Set Identifier (PSID) value (valid only for MAP-E alg)
289     @param start_port - beginning of the port range
290     @param end_port - end of the port range
291 */
292 autoreply define nat_set_addr_and_port_alloc_alg {
293   u32 client_index;
294   u32 context;
295   u8 alg;
296   u8 psid_offset;
297   u8 psid_length;
298   u16 psid;
299   u16 start_port;
300   u16 end_port;
301 };
302
303 /** \brief Get address and port assignment algorithm
304     @param client_index - opaque cookie to identify the sender
305     @param context - sender context, to match reply w/ request
306 */
307 define nat_get_addr_and_port_alloc_alg {
308   u32 client_index;
309   u32 context;
310 };
311
312 /** \brief Get address and port assignment algorithm reply
313     @param context - sender context, to match reply w/ request
314     @param retval - return code
315     @param alg - address and port assignment algorithm:
316                  0 - default, 1 - MAP-E, 2 - port range
317                  (see nat_addr_and_port_alloc_alg_t in nat.h)
318     @param psid_offset - number of offset bits (valid only for MAP-E alg)
319     @param psid_length - length of PSID (valid only for MAP-E alg)
320     @param psid - Port Set Identifier (PSID) value (valid only for MAP-E alg)
321     @param start_port - beginning of the port range
322     @param end_port - end of the port range
323 */
324 define nat_get_addr_and_port_alloc_alg_reply {
325   u32 context;
326   i32 retval;
327   u8 alg;
328   u8 psid_offset;
329   u8 psid_length;
330   u16 psid;
331   u16 start_port;
332   u16 end_port;
333 };
334
335 /*
336  * NAT44 APIs
337  */
338
339 /** \brief Add/del NAT44 address range
340     @param client_index - opaque cookie to identify the sender
341     @param context - sender context, to match reply w/ request
342     @param first_ip_address - first IPv4 address
343     @param last_ip_address - last IPv4 address
344     @param vrf_id - VRF id of tenant, ~0 means independent of VRF
345     @param twice_nat - twice NAT address range for extenal hosts
346     @param is_add - 1 if add, 0 if delete
347 */
348 autoreply define nat44_add_del_address_range {
349   u32 client_index;
350   u32 context;
351   u8 first_ip_address[4];
352   u8 last_ip_address[4];
353   u32 vrf_id;
354   u8 twice_nat;
355   u8 is_add;
356 };
357
358 /** \brief Dump NAT44 addresses
359     @param client_index - opaque cookie to identify the sender
360     @param context - sender context, to match reply w/ request
361 */
362 define nat44_address_dump {
363   u32 client_index;
364   u32 context;
365 };
366
367 /** \brief NAT44 address details response
368     @param context - sender context, to match reply w/ request
369     @param ip_address - IPv4 address
370     @param twice_nat - twice NAT address range for extenal hosts
371     @param vrf_id - VRF id of tenant, ~0 means independent of VRF
372 */
373 define nat44_address_details {
374   u32 context;
375   u8 ip_address[4];
376   u8 twice_nat;
377   u32 vrf_id;
378 };
379
380 /** \brief Enable/disable NAT44 feature on the interface
381     @param client_index - opaque cookie to identify the sender
382     @param context - sender context, to match reply w/ request
383     @param is_add - 1 if add, 0 if delete
384     @param is_inside - 1 if inside, 0 if outside
385     @param sw_if_index - software index of the interface
386 */
387 autoreply define nat44_interface_add_del_feature {
388   u32 client_index;
389   u32 context;
390   u8 is_add;
391   u8 is_inside;
392   u32 sw_if_index;
393 };
394
395 /** \brief Dump interfaces with NAT44 feature
396     @param client_index - opaque cookie to identify the sender
397     @param context - sender context, to match reply w/ request
398 */
399 define nat44_interface_dump {
400   u32 client_index;
401   u32 context;
402 };
403
404 /** \brief NAT44 interface details response
405     @param context - sender context, to match reply w/ request
406     @param is_inside - 1 if inside, 0 if outside, 2 if inside and outside
407     @param sw_if_index - software index of the interface
408 */
409 define nat44_interface_details {
410   u32 context;
411   u8 is_inside;
412   u32 sw_if_index;
413 };
414
415 /** \brief Enable/disbale NAT44 as an interface output feature (postrouting
416            in2out translation)
417     @param client_index - opaque cookie to identify the sender
418     @param context - sender context, to match reply w/ request
419     @param is_add - 1 if add, 0 if delete
420     @param is_inside - 1 if inside, 0 if outside
421     @param sw_if_index - software index of the interface
422 */
423 autoreply define nat44_interface_add_del_output_feature {
424   u32 client_index;
425   u32 context;
426   u8 is_add;
427   u8 is_inside;
428   u32 sw_if_index;
429 };
430
431 /** \brief Dump interfaces with NAT44 output feature
432     @param client_index - opaque cookie to identify the sender
433     @param context - sender context, to match reply w/ request
434 */
435 define nat44_interface_output_feature_dump {
436   u32 client_index;
437   u32 context;
438 };
439
440 /** \brief NAT44 interface with output feature details response
441     @param context - sender context, to match reply w/ request
442     @param is_inside - 1 if inside, 0 if outside
443     @param sw_if_index - software index of the interface
444 */
445 define nat44_interface_output_feature_details {
446   u32 context;
447   u8 is_inside;
448   u32 sw_if_index;
449 };
450
451 /** \brief Add/delete NAT44 static mapping
452     @param client_index - opaque cookie to identify the sender
453     @param context - sender context, to match reply w/ request
454     @param is_add - 1 if add, 0 if delete
455     @param addr_only - 1 if address only mapping
456     @param local_ip_address - local IPv4 address
457     @param external_ip_address - external IPv4 address
458     @param protocol - IP protocol, used only if addr_only=0
459     @param local_port - local port number, used only if addr_only=0
460     @param external_port - external port number, used only if addr_only=0
461     @param external_sw_if_index - external interface (if set
462                                   external_ip_address is ignored, ~0 means not
463                                   used)
464     @param vfr_id - VRF ID
465     @param twice_nat - if 1 translate external host address and port, only for
466                        1:1 NAPT (addr_only must be 0)
467     @param self_twice_nat - if 1 translate external host address and port
468                             whenever external host address equals
469                             local address of internal host
470     @param out2in_only - if 1 rule match only out2in direction
471     @param tag - opaque string tag
472 */
473 autoreply define nat44_add_del_static_mapping {
474   u32 client_index;
475   u32 context;
476   u8 is_add;
477   u8 addr_only;
478   u8 local_ip_address[4];
479   u8 external_ip_address[4];
480   u8 protocol;
481   u16 local_port;
482   u16 external_port;
483   u32 external_sw_if_index;
484   u32 vrf_id;
485   u8 twice_nat;
486   u8 self_twice_nat;
487   u8 out2in_only;
488   u8 tag[64];
489 };
490
491 /** \brief Dump NAT44 static mappings
492     @param client_index - opaque cookie to identify the sender
493     @param context - sender context, to match reply w/ request
494 */
495 define nat44_static_mapping_dump {
496   u32 client_index;
497   u32 context;
498 };
499
500 /** \brief NAT44 static mapping details response
501     @param context - sender context, to match reply w/ request
502     @param addr_only - 1 if address only mapping
503     @param local_ip_address - local IPv4 address
504     @param external_ip_address - external IPv4 address
505     @param protocol - IP protocol, valid only if addr_only=0
506     @param local_port - local port number, valid only if addr_only=0
507     @param external_port - external port number, valid only if addr_only=0
508     @param external_sw_if_index - external interface
509     @param vfr_id - VRF ID
510     @param twice_nat - if 1 translate external host address and port
511     @param self_twice_nat - if 1 translate external host address and port
512                             whenever external host address equals
513                             local address of internal host
514     @param out2in_only - if 1 rule match only out2in direction
515     @param tag - opaque string tag
516 */
517 define nat44_static_mapping_details {
518   u32 context;
519   u8 addr_only;
520   u8 local_ip_address[4];
521   u8 external_ip_address[4];
522   u8 protocol;
523   u16 local_port;
524   u16 external_port;
525   u32 external_sw_if_index;
526   u32 vrf_id;
527   u8 twice_nat;
528   u8 self_twice_nat;
529   u8 out2in_only;
530   u8 tag[64];
531 };
532
533 /** \brief Add/delete NAT44 identity mapping
534     @param client_index - opaque cookie to identify the sender
535     @param context - sender context, to match reply w/ request
536     @param is_add - 1 if add, 0 if delete
537     @param addr_only - 1 if address only mapping
538     @param ip_address - IPv4 address
539     @param protocol - IP protocol
540     @param port - port number
541     @param sw_if_index - interface (if set ip_address is ignored, ~0 means not
542                                     used)
543     @param vfr_id - VRF ID (if ~0 use default VRF)
544     @param tag - opaque string tag
545 */
546 autoreply define nat44_add_del_identity_mapping {
547   u32 client_index;
548   u32 context;
549   u8 is_add;
550   u8 addr_only;
551   u8 ip_address[4];
552   u8 protocol;
553   u16 port;
554   u32 sw_if_index;
555   u32 vrf_id;
556   u8 tag[64];
557 };
558
559 /** \brief Dump NAT44 identity mappings
560     @param client_index - opaque cookie to identify the sender
561     @param context - sender context, to match reply w/ request
562 */
563 define nat44_identity_mapping_dump {
564   u32 client_index;
565   u32 context;
566 };
567
568 /** \brief NAT44 identity mapping details response
569     @param context - sender context, to match reply w/ request
570     @param addr_only - 1 if address only mapping
571     @param ip_address - IPv4 address
572     @param protocol - IP protocol
573     @param port - port number
574     @param sw_if_index - interface
575     @param vfr_id - VRF ID
576     @param tag - opaque string tag
577 */
578 define nat44_identity_mapping_details {
579   u32 context;
580   u8 addr_only;
581   u8 ip_address[4];
582   u8 protocol;
583   u16 port;
584   u32 sw_if_index;
585   u32 vrf_id;
586   u8 tag[64];
587 };
588
589 /** \brief Add/delete NAT44 pool address from specific interfce
590     @param client_index - opaque cookie to identify the sender
591     @param context - sender context, to match reply w/ request
592     @param is_add - 1 if add, 0 if delete
593     @param twice_nat - twice NAT address for extenal hosts
594     @param sw_if_index - software index of the interface
595 */
596 autoreply define nat44_add_del_interface_addr {
597   u32 client_index;
598   u32 context;
599   u8 is_add;
600   u8 twice_nat;
601   u32 sw_if_index;
602 };
603
604 /** \brief Dump NAT44 pool addresses interfaces
605     @param client_index - opaque cookie to identify the sender
606     @param context - sender context, to match reply w/ request
607 */
608 define nat44_interface_addr_dump {
609   u32 client_index;
610   u32 context;
611 };
612
613 /** \brief NAT44 pool addresses interfaces details response
614     @param context - sender context, to match reply w/ request
615     @param sw_if_index - software index of the interface
616     @param twice_nat - twice NAT address for extenal hosts
617 */
618 define nat44_interface_addr_details {
619   u32 context;
620   u32 sw_if_index;
621   u8 twice_nat;
622 };
623
624 /** \brief Dump NAT44 users
625     @param client_index - opaque cookie to identify the sender
626     @param context - sender context, to match reply w/ request
627 */
628 define nat44_user_dump {
629   u32 client_index;
630   u32 context;
631 };
632
633 /** \brief NAT44 users response
634     @param context - sender context, to match reply w/ request
635     @vrf_id - VRF ID
636     @param ip_adress - IPv4 address
637     @param nsessions - number of dynamic sessions
638     @param nstaticsessions - number of static sessions
639 */
640 define nat44_user_details {
641   u32 context;
642   u32 vrf_id;
643   u8 ip_address[4];
644   u32 nsessions;
645   u32 nstaticsessions;
646 };
647
648 /** \brief NAT44 user's sessions
649     @param client_index - opaque cookie to identify the sender
650     @param context - sender context, to match reply w/ request
651     @param is_ip4 - 1 if address type is IPv4
652     @param user_ip - IP address of the user to dump
653     @param vrf_id - VRF_ID
654 */
655 define nat44_user_session_dump {
656   u32 client_index;
657   u32 context;
658   u8 ip_address[4];
659   u32 vrf_id;
660 };
661
662 /** \brief NAT44 user's sessions response
663     @param context - sender context, to match reply w/ request
664     @param outside_ip_address - outside IPv4 address
665     @param outside_port - outside port
666     @param inside_ip_address - inside IPv4 address
667     @param inside_port - inside port
668     @param protocol - protocol
669     @param is_static - 1 if session is static
670     @param last_heard - last heard timer
671     @param total_bytes - count of bytes sent through session
672     @param total_pkts - count of pakets sent through session
673     @param is_twicenat - 1 if session is twice-nat
674     @param ext_host_valid - 1 if external host address and port are valid
675     @param ext_host_address - external host IPv4 address
676     @param ext_host_port - external host port
677     @param ext_host_nat_address - post-NAT external host IPv4 address (valid
678                                   only if twice-nat session)
679     @param ext_host_nat_port - post-NAT external host port (valid only if
680                                twice-nat session)
681 */
682 define nat44_user_session_details {
683   u32 context;
684   u8 outside_ip_address[4];
685   u16 outside_port;
686   u8 inside_ip_address[4];
687   u16 inside_port;
688   u16 protocol;
689   u8 is_static;
690   u64 last_heard;
691   u64 total_bytes;
692   u32 total_pkts;
693   u8 is_twicenat;
694   u8 ext_host_valid;
695   u8 ext_host_address[4];
696   u16 ext_host_port;
697   u8 ext_host_nat_address[4];
698   u16 ext_host_nat_port;
699 };
700
701 /** \brief NAT44 load-balancing address and port pair
702     @param addr - IPv4 address of the internal node
703     @param port - L4 port number of the internal node
704     @param probability - probability of the internal node to be randomly matched
705 */
706 typeonly manual_endian define nat44_lb_addr_port {
707   u8 addr[4];
708   u16 port;
709   u8 probability;
710   u32 vrf_id;
711 };
712
713 /** \brief Add/delete NAT44 load-balancing static mapping rule
714     @param client_index - opaque cookie to identify the sender
715     @param context - sender context, to match reply w/ request
716     @param is_add - 1 if add, 0 if delete
717     @param external_addr - external IPv4 address of the service
718     @param external_port - external L4 port number of the service
719     @param protocol - IP protocol number of the service
720     @param twice_nat - if 1 translate external host address and port
721     @param self_twice_nat - if 1 translate external host address and port
722                             whenever external host address equals
723                             local address of internal host
724     @param out2in_only - if 1 rule match only out2in direction
725     @param tag - opaque string tag
726     @param affinity - if 0 disabled, otherwise client IP affinity sticky time
727                       in seconds
728     @param local_num - number of local network nodes
729     @param locals - local network nodes
730 */
731 autoreply manual_endian define nat44_add_del_lb_static_mapping {
732   u32 client_index;
733   u32 context;
734   u8 is_add;
735   u8 external_addr[4];
736   u16 external_port;
737   u8 protocol;
738   u8 twice_nat;
739   u8 self_twice_nat;
740   u8 out2in_only;
741   u8 tag[64];
742   u32 affinity;
743   u8 local_num;
744   vl_api_nat44_lb_addr_port_t locals[local_num];
745 };
746
747 /** \brief Dump NAT44 load-balancing static mapping rules
748     @param client_index - opaque cookie to identify the sender
749     @param context - sender context, to match reply w/ request
750 */
751 define nat44_lb_static_mapping_dump {
752   u32 client_index;
753   u32 context;
754 };
755
756 /** \brief NAT44 load-balancing static mapping rule details response
757     @param context - sender context, to match reply w/ request
758     @param is_add - 1 if add, 0 if delete
759     @param external_addr - external IPv4 address of the service
760     @param external_port - external L4 port number of the service
761     @param protocol - IP protocol number of the service
762     @param twice_nat - if 1 translate external host address and port
763     @param self_twice_nat - if 1 translate external host address and port
764                             whenever external host address equals
765                             local address of internal host
766     @param out2in_only - if 1 rule match only out2in direction
767     @param tag - opaque string tag
768     @param affinity - if 0 disabled, otherwise client IP affinity sticky time
769                       in seconds
770     @param local_num - number of local network nodes
771     @param locals - local network nodes
772 */
773 manual_endian define nat44_lb_static_mapping_details {
774   u32 context;
775   u8 external_addr[4];
776   u16 external_port;
777   u8 protocol;
778   u8 twice_nat;
779   u8 self_twice_nat;
780   u8 out2in_only;
781   u8 tag[64];
782   u32 affinity;
783   u8 local_num;
784   vl_api_nat44_lb_addr_port_t locals[local_num];
785 };
786
787 /** \brief Delete NAT44 session
788     @param client_index - opaque cookie to identify the sender
789     @param context - sender context, to match reply w/ request
790     @param is_in - 1 if inside network addres and port pari, 0 if outside
791     @param ip_address - IPv4 address
792     @param protocol - IP protocol
793     @param port - port number
794     @param vfr_id - VRF ID
795     @param ext_host_valid - 1 if external host address and port are valid
796     @param ext_host_address - external host IPv4 address
797     @param ext_host_port - external host port
798 */
799 autoreply define nat44_del_session {
800   u32 client_index;
801   u32 context;
802   u8 is_in;
803   u8 address[4];
804   u8 protocol;
805   u16 port;
806   u32 vrf_id;
807   u8 ext_host_valid;
808   u8 ext_host_address[4];
809   u16 ext_host_port;
810 };
811
812 /** \brief Enable/disable forwarding for NAT44
813     Forward packets which don't match existing translation
814     or static mapping instead of dropping them.
815     @param client_index - opaque cookie to identify the sender
816     @param context - sender context, to match reply w/ request
817     @param enable - 0 for enable, 1 for disable
818 */
819 autoreply define nat44_forwarding_enable_disable {
820   u32 client_index;
821   u32 context;
822   u8 enable;
823 };
824
825 /** \brief Check if forwarding is enabled or disabled
826     @param client_index - opaque cookie to identify the sender
827     @param context - sender context, to match reply w/ request
828 */
829 define nat44_forwarding_is_enabled {
830   u32 client_index;
831   u32 context;
832 };
833
834 /** \brief Response to check if forwarding is enabled or disabled
835     @param context - sender context, to match reply w/ request
836     @param enabled - 1 if enabled, 0 if disabled
837 */
838 define nat44_forwarding_is_enabled_reply {
839   u32 context;
840   u8 enabled;
841 };
842
843
844 /*
845  * Deterministic NAT (CGN) APIs
846  */
847
848 /** \brief Add/delete NAT deterministic mapping
849     @param client_index - opaque cookie to identify the sender
850     @param context - sender context, to match reply w/ request
851     @param is_add - 1 if add, 0 if delete
852     @param is_nat44 - 1 if NAT44
853     @param in_addr - inside IP address
854     @param in_plen - inside IP address prefix length
855     @param out_addr - outside IPv4 address
856     @param out_addr - outside IPv4 address prefix length
857 */
858 autoreply define nat_det_add_del_map {
859   u32 client_index;
860   u32 context;
861   u8 is_add;
862   u8 is_nat44;
863   u8 addr_only;
864   u8 in_addr[16];
865   u8 in_plen;
866   u8 out_addr[4];
867   u8 out_plen;
868 };
869
870 /** \brief Get outside address and port range from inside address
871     @param client_index - opaque cookie to identify the sender
872     @param context - sender context, to match reply w/ request
873     @param is_nat44 - 1 if NAT44
874     @param in_addr - inside IP address
875 */
876 define nat_det_forward {
877   u32 client_index;
878   u32 context;
879   u8 is_nat44;
880   u8 in_addr[16];
881 };
882
883 /** \brief Get outside address and port range from inside address
884     @param context - sender context, to match reply w/ request
885     @param retval - return code
886     @param out_port_lo - outside port range start
887     @param out_port_hi - outside port range end
888     @param out_addr - outside IPv4 address
889 */
890 define nat_det_forward_reply {
891   u32 context;
892   i32 retval;
893   u16 out_port_lo;
894   u16 out_port_hi;
895   u8 out_addr[4];
896 };
897
898 /** \brief Get inside address from outside address and port
899     @param client_index - opaque cookie to identify the sender
900     @param context - sender context, to match reply w/ request
901     @param out_port - outside port
902     @param out_addr - outside IPv4 address
903 */
904 define nat_det_reverse {
905   u32 client_index;
906   u32 context;
907   u16 out_port;
908   u8 out_addr[4];
909 };
910
911 /** \brief Get inside address from outside address and port reply
912     @param context - sender context, to match reply w/ request
913     @param retval - return code
914     @param is_nat44 - 1 if NAT44
915     @param in_addr - inside IP address
916 */
917 define nat_det_reverse_reply {
918   u32 context;
919   i32 retval;
920   u8 is_nat44;
921   u8 in_addr[16];
922 };
923
924 /** \brief Dump NAT deterministic mappings
925     @param client_index - opaque cookie to identify the sender
926     @param context - sender context, to match reply w/ request
927 */
928 define nat_det_map_dump {
929   u32 client_index;
930   u32 context;
931 };
932
933 /** \brief NAT users response
934     @param context - sender context, to match reply w/ request
935     @param is_nat44 - 1 if NAT44
936     @param in_addr - inside IP address
937     @param in_plen - inside IP address prefix length
938     @param out_addr - outside IPv4 address
939     @param out_plen - outside IPv4 address prefix length
940     @param sharing_ratio - outside to inside address sharing ratio
941     @param ports_per_host - number of ports available to a host
942     @param ses_num - number of sessions belonging to this mapping
943 */
944 define nat_det_map_details {
945   u32 context;
946   u8 is_nat44;
947   u8 in_addr[16];
948   u8 in_plen;
949   u8 out_addr[4];
950   u8 out_plen;
951   u32 sharing_ratio;
952   u16 ports_per_host;
953   u32 ses_num;
954 };
955
956 /** \brief Close deterministic NAT session by outside address and port
957     @param client_index - opaque cookie to identify the sender
958     @param context - sender context, to match reply w/ request
959     @param out_addr - outside IPv4 address
960     @param out_port - outside port
961     @param ext_addr - external host IPv4 address
962     @param ext_port - external host port
963 */
964 autoreply define nat_det_close_session_out {
965   u32 client_index;
966   u32 context;
967   u8 out_addr[4];
968   u16 out_port;
969   u8 ext_addr[4];
970   u16 ext_port;
971 };
972
973 /** \brief Close deterministic NAT session by inside address and port
974     @param client_index - opaque cookie to identify the sender
975     @param context - sender context, to match reply w/ request
976     @param is_nat44 - 1 if NAT44
977     @param in_addr - inside IP address
978     @param in_port - inside port
979     @param ext_addr - external host IP address
980     @param ext_port - external host port
981 */
982 autoreply define nat_det_close_session_in {
983   u32 client_index;
984   u32 context;
985   u8 is_nat44;
986   u8 in_addr[16];
987   u16 in_port;
988   u8 ext_addr[16];
989   u16 ext_port;
990 };
991
992 /** \brief Dump determinstic NAT sessions
993     @param client_index - opaque cookie to identify the sender
994     @param context - sender context, to match reply w/ request
995     @param is_nat44 - 1 if NAT44
996     @param user_addr - address of an inside user whose sessions to dump
997 */
998 define nat_det_session_dump {
999   u32 client_index;
1000   u32 context;
1001   u8 is_nat44;
1002   u8 user_addr[16];
1003 };
1004
1005 /** \brief Deterministic NAT sessions reply
1006     @param context - sender context, to match reply w/ request
1007     @param in_port - inside port
1008     @param ext_addr - external host address
1009     @param ext_port - external host port
1010     @param out_port - outside NAT port
1011     @param state - session state
1012     @param expire - session expiration timestamp
1013 */
1014 define nat_det_session_details {
1015   u32 context;
1016   u16 in_port;
1017   u8 ext_addr[4];
1018   u16 ext_port;
1019   u16 out_port;
1020   u8 state;
1021   u32 expire;
1022 };
1023
1024 /*
1025  * NAT64 APIs
1026  */
1027
1028 /** \brief Add/delete address range to NAT64 pool
1029     @param client_index - opaque cookie to identify the sender
1030     @param context - sender context, to match reply w/ request
1031     @param start_addr - start address of the range
1032     @param end_addr - end address of the range
1033     @param vrf_id - VRF id of tenant, ~0 means independent of VRF
1034     @param is_add - 1 if add, 0 if delete
1035 */
1036 autoreply define nat64_add_del_pool_addr_range {
1037   u32 client_index;
1038   u32 context;
1039   u8 start_addr[4];
1040   u8 end_addr[4];
1041   u32 vrf_id;
1042   u8 is_add;
1043 };
1044
1045 /** \brief Dump NAT64 pool addresses
1046     @param client_index - opaque cookie to identify the sender
1047     @param context - sender context, to match reply w/ request
1048 */
1049 define nat64_pool_addr_dump {
1050   u32 client_index;
1051   u32 context;
1052 };
1053
1054 /** \brief NAT64 pool address details response
1055     @param context - sender context, to match reply w/ request
1056     @param address - IPv4 address
1057     @param vfr_id - VRF id of tenant, ~0 means independent of VRF
1058 */
1059 define nat64_pool_addr_details {
1060   u32 context;
1061   u8 address[4];
1062   u32 vrf_id;
1063 };
1064
1065 /** \brief Enable/disable NAT64 feature on the interface
1066     @param client_index - opaque cookie to identify the sender
1067     @param context - sender context, to match reply w/ request
1068     @param sw_if_index - index of the interface
1069     @param is_inside - 1 if inside, 0 if outside
1070     @param is_add - 1 if add, 0 if delete
1071 */
1072 autoreply define nat64_add_del_interface {
1073   u32 client_index;
1074   u32 context;
1075   u32 sw_if_index;
1076   u8 is_inside;
1077   u8 is_add;
1078 };
1079
1080 /** \brief Dump interfaces with NAT64 feature
1081     @param client_index - opaque cookie to identify the sender
1082     @param context - sender context, to match reply w/ request
1083 */
1084 define nat64_interface_dump {
1085   u32 client_index;
1086   u32 context;
1087 };
1088
1089 /** \brief NAT64 interface details response
1090     @param context - sender context, to match reply w/ request
1091     @param is_inside - 1 if inside, 0 if outside
1092     @param sw_if_index - index of the interface
1093 */
1094 define nat64_interface_details {
1095   u32 context;
1096   u8 is_inside;
1097   u32 sw_if_index;
1098 };
1099
1100 /** \brief Add/delete NAT64 static BIB entry
1101     @param client_index - opaque cookie to identify the sender
1102     @param context - sender context, to match reply w/ request
1103     @param i_addr - inside IPv6 address
1104     @param o_addr - outside IPv4 address
1105     @param i_port - inside port number
1106     @param o_port - outside port number
1107     @param vrf_id - VRF id of tenant
1108     @param proto - protocol number
1109     @param is_add - 1 if add, 0 if delete
1110 */
1111  autoreply define nat64_add_del_static_bib {
1112   u32 client_index;
1113   u32 context;
1114   u8 i_addr[16];
1115   u8 o_addr[4];
1116   u16 i_port;
1117   u16 o_port;
1118   u32 vrf_id;
1119   u8 proto;
1120   u8 is_add;
1121 };
1122
1123 /** \brief Dump NAT64 BIB
1124     @param client_index - opaque cookie to identify the sender
1125     @param context - sender context, to match reply w/ request
1126     @param proto - protocol of the BIB: 255 - all BIBs
1127                                         6 - TCP BIB
1128                                         17 - UDP BIB
1129                                         1/58 - ICMP BIB
1130                                         otherwise - "unknown" protocol BIB
1131 */
1132 define nat64_bib_dump {
1133   u32 client_index;
1134   u32 context;
1135   u8 proto;
1136 };
1137
1138 /** \brief NAT64 BIB details response
1139     @param context - sender context, to match reply w/ request
1140     @param i_addr - inside IPv6 address
1141     @param o_addr - outside IPv4 address
1142     @param i_port - inside port number
1143     @param o_port - outside port number
1144     @param vrf_id - VRF id of tenant
1145     @param proto - protocol number
1146     @param is_static - 1 if static BIB entry, 0 if dynamic
1147     @param ses_num - number of sessions associated with the BIB entry
1148 */
1149 define nat64_bib_details {
1150   u32 context;
1151   u8 i_addr[16];
1152   u8 o_addr[4];
1153   u16 i_port;
1154   u16 o_port;
1155   u32 vrf_id;
1156   u8 proto;
1157   u8 is_static;
1158   u32 ses_num;
1159 };
1160
1161 /** \brief Dump NAT64 session table
1162     @param client_index - opaque cookie to identify the sender
1163     @param context - sender context, to match reply w/ request
1164     @param proto - protocol of the session table: 255 - all STs
1165                                                   6 - TCP ST
1166                                                   17 - UDP ST
1167                                                   1/58 - ICMP ST
1168                                                   otherwise - "unknown" proto ST
1169 */
1170 define nat64_st_dump {
1171   u32 client_index;
1172   u32 context;
1173   u8 proto;
1174 };
1175
1176 /** \brief NAT64 session table details response
1177     @param context - sender context, to match reply w/ request
1178     @param il_addr - inside IPv6 address of the local host
1179     @param ol_addr - outside IPv4 address of the local host
1180     @param il_port - inside port number id of the local host/inside ICMP id
1181     @param ol_port - outside port number of the local host/outside ICMP id
1182     @param il_addr - inside IPv6 address of the remote host
1183     @param ol_addr - outside IPv4 address of the remote host
1184     @param l_port - port number of the remote host (not used for ICMP)
1185     @param vrf_id - VRF id of tenant
1186     @param proto - protocol number
1187 */
1188 define nat64_st_details {
1189   u32 context;
1190   u8 il_addr[16];
1191   u8 ol_addr[4];
1192   u16 il_port;
1193   u16 ol_port;
1194   u8 ir_addr[16];
1195   u8 or_addr[4];
1196   u16 r_port;
1197   u32 vrf_id;
1198   u8 proto;
1199 };
1200
1201 /** \brief Add/del NAT64 prefix
1202     @param client_index - opaque cookie to identify the sender
1203     @param context - sender context, to match reply w/ request
1204     @param prefix - NAT64 prefix
1205     @param prefix - NAT64 prefix length
1206     @param vrf_id - VRF id of tenant
1207     @param is_add - 1 if add, 0 if delete
1208 */
1209 autoreply define nat64_add_del_prefix {
1210   u32 client_index;
1211   u32 context;
1212   u8 prefix[16];
1213   u8 prefix_len;
1214   u32 vrf_id;
1215   u8 is_add;
1216 };
1217
1218 /** \brief Dump NAT64 prefix
1219     @param client_index - opaque cookie to identify the sender
1220     @param context - sender context, to match reply w/ request
1221 */
1222 define nat64_prefix_dump {
1223   u32 client_index;
1224   u32 context;
1225 };
1226
1227 /** \brief Dump NAT64 prefix details response
1228     @param context - sender context, to match reply w/ request
1229     @param prefix - NAT64 prefix
1230     @param prefix - NAT64 prefix length
1231     @param vrf_id - VRF id of tenant
1232 */
1233 define nat64_prefix_details {
1234   u32 context;
1235   u8 prefix[16];
1236   u8 prefix_len;
1237   u32 vrf_id;
1238 };
1239
1240 /** \brief Add/delete NAT64 pool address from specific interfce
1241     @param client_index - opaque cookie to identify the sender
1242     @param context - sender context, to match reply w/ request
1243     @param is_add - 1 if add, 0 if delete
1244     @param sw_if_index - software index of the interface
1245 */
1246 autoreply define nat64_add_del_interface_addr {
1247   u32 client_index;
1248   u32 context;
1249   u8 is_add;
1250   u8 is_inside;
1251   u32 sw_if_index;
1252 };
1253
1254
1255 /*
1256  * DS-Lite APIs
1257  */
1258
1259 /** \brief Add/delete address range to DS-Lite pool
1260     @param client_index - opaque cookie to identify the sender
1261     @param context - sender context, to match reply w/ request
1262     @param start_addr - start address of the range
1263     @param end_addr - end address of the range
1264     @param is_add - 1 if add, 0 if delete
1265 */
1266 autoreply define dslite_add_del_pool_addr_range {
1267   u32 client_index;
1268   u32 context;
1269   u8 start_addr[4];
1270   u8 end_addr[4];
1271   u8 is_add;
1272 };
1273
1274 /** \brief Dump DS-Lite addresses
1275     @param client_index - opaque cookie to identify the sender
1276     @param context - sender context, to match reply w/ request
1277 */
1278 define dslite_address_dump {
1279   u32 client_index;
1280   u32 context;
1281 };
1282
1283 /** \brief DS-Lite address details response
1284     @param context - sender context, to match reply w/ request
1285     @param ip_address - IPv4 address
1286 */
1287 define dslite_address_details {
1288   u32 context;
1289   u8 ip_address[4];
1290 };
1291
1292 /** \brief Set AFTR IPv6 and IPv4 addresses
1293     @param client_index - opaque cookie to identify the sender
1294     @param context - sender context, to match reply w/ request
1295     @param ip4_addr - IPv4 address
1296     @param ip6_addr - IP64 address
1297 */
1298 autoreply define dslite_set_aftr_addr {
1299   u32 client_index;
1300   u32 context;
1301   u8 ip4_addr[4];
1302   u8 ip6_addr[16];
1303 };
1304
1305 /** \brief Get AFTR IPv6 and IPv4 addresses
1306     @param client_index - opaque cookie to identify the sender
1307     @param context - sender context, to match reply w/ request
1308 */
1309 define dslite_get_aftr_addr {
1310   u32 client_index;
1311   u32 context;
1312 };
1313
1314 /** \brief Response to get AFTR IPv6 and IPv4 addresses
1315     @param context - sender context, to match reply w/ request
1316     @param retval - return code
1317     @param ip4_addr - IPv4 address
1318     @param ip6_addr - IP64 address
1319 */
1320 define dslite_get_aftr_addr_reply {
1321   u32 context;
1322   i32 retval;
1323   u8 ip4_addr[4];
1324   u8 ip6_addr[16];
1325 };
1326
1327 /** \brief Set B4 IPv6 and IPv4 addresses
1328     @param client_index - opaque cookie to identify the sender
1329     @param context - sender context, to match reply w/ request
1330     @param ip4_addr - IPv4 address
1331     @param ip6_addr - IP64 address
1332 */
1333 autoreply define dslite_set_b4_addr {
1334   u32 client_index;
1335   u32 context;
1336   u8 ip4_addr[4];
1337   u8 ip6_addr[16];
1338 };
1339
1340 /** \brief Get B4 IPv6 and IPv4 addresses
1341     @param client_index - opaque cookie to identify the sender
1342     @param context - sender context, to match reply w/ request
1343 */
1344 define dslite_get_b4_addr {
1345   u32 client_index;
1346   u32 context;
1347 };
1348
1349 /** \brief Response to get B4 IPv6 and IPv4 addresses
1350     @param context - sender context, to match reply w/ request
1351     @param retval - return code
1352     @param ip4_addr - IPv4 address
1353     @param ip6_addr - IP64 address
1354 */
1355 define dslite_get_b4_addr_reply {
1356   u32 context;
1357   i32 retval;
1358   u8 ip4_addr[4];
1359   u8 ip6_addr[16];
1360 };
1361
1362 /*
1363  * NAT66 APIs
1364  */
1365 /** \brief Enable/disable NAT66 feature on the interface
1366     @param client_index - opaque cookie to identify the sender
1367     @param context - sender context, to match reply w/ request
1368     @param is_add - 1 if add, 0 if delete
1369     @param is_inside - 1 if inside, 0 if outside
1370     @param sw_if_index - software index of the interface
1371 */
1372 autoreply define nat66_add_del_interface {
1373   u32 client_index;
1374   u32 context;
1375   u8 is_add;
1376   u8 is_inside;
1377   u32 sw_if_index;
1378 };
1379
1380 /** \brief Dump interfaces with NAT66 feature
1381     @param client_index - opaque cookie to identify the sender
1382     @param context - sender context, to match reply w/ request
1383 */
1384 define nat66_interface_dump {
1385   u32 client_index;
1386   u32 context;
1387 };
1388
1389 /** \brief NAT66 interface details response
1390     @param context - sender context, to match reply w/ request
1391     @param is_inside - 1 if inside, 0 if outside
1392     @param sw_if_index - software index of the interface
1393 */
1394 define nat66_interface_details {
1395   u32 context;
1396   u8 is_inside;
1397   u32 sw_if_index;
1398 };
1399
1400 /** \brief Add/delete 1:1 NAT66
1401     @param client_index - opaque cookie to identify the sender
1402     @param context - sender context, to match reply w/ request
1403     @param is_add - 1 if add, 0 if delete
1404     @param local_ip_address - local IPv6 address
1405     @param external_ip_address - external IPv6 address
1406     @param vrf_id - VRF id of tenant
1407 */
1408 autoreply define nat66_add_del_static_mapping {
1409   u32 client_index;
1410   u32 context;
1411   u8 is_add;
1412   u8 local_ip_address[16];
1413   u8 external_ip_address[16];
1414   u32 vrf_id;
1415 };
1416
1417 /** \brief Dump NAT66 static mappings
1418     @param client_index - opaque cookie to identify the sender
1419     @param context - sender context, to match reply w/ request
1420 */
1421 define nat66_static_mapping_dump {
1422   u32 client_index;
1423   u32 context;
1424 };
1425
1426 /** \brief NAT66 static mapping details response
1427     @param context - sender context, to match reply w/ request
1428     @param local_ip_address - local IPv6 address
1429     @param external_ip_address - external IPv6 address
1430     @param vrf_id - VRF id of tenant
1431     @param total_bytes - count of bytes sent through static mapping
1432     @param total_pkts - count of pakets sent through static mapping
1433 */
1434 define nat66_static_mapping_details {
1435   u32 context;
1436   u8 local_ip_address[16];
1437   u8 external_ip_address[16];
1438   u32 vrf_id;
1439   u64 total_bytes;
1440   u64 total_pkts;
1441 };