ipsec: IPSec protection for multi-point tunnel interfaces
[vpp.git] / src / vnet / ip / ip_types.h
1 /*
2  * Copyright (c) 2019 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 #ifndef __IP_TYPES_H__
17 #define __IP_TYPES_H__
18
19 #include <vnet/fib/fib_types.h>
20
21 typedef enum ip_address_family_t_
22 {
23   AF_IP4,
24   AF_IP6,
25 } ip_address_family_t;
26
27 extern uword unformat_ip_address_family (unformat_input_t * input,
28                                          va_list * args);
29 extern u8 *format_ip_address_family (u8 * s, va_list * args);
30
31 #define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
32   for (_af = AF_IP4; _af <= AF_IP6; _af++)
33
34 #define u8_ptr_add(ptr, index) (((u8 *)ptr) + index)
35 #define u16_net_add(u, val) clib_host_to_net_u16(clib_net_to_host_u16(u) + (val))
36
37 /* *INDENT-OFF* */
38 typedef struct ip_address
39 {
40   union
41   {
42     ip4_address_t v4;
43     ip6_address_t v6;
44   } ip;
45   ip_address_family_t version;
46 } __clib_packed ip_address_t;
47 /* *INDENT-ON* */
48
49 #define IP_ADDRESS_V4_ALL_0S {.ip.v4.as_u32 = 0, .version = AF_IP4}
50 #define IP_ADDRESS_V6_ALL_0S {.ip.v4.as_u32 = 0, .version = AF_IP6}
51
52 #define ip_addr_addr(_a) (_a)->ip
53 #define ip_addr_v4(_a) (_a)->ip.v4
54 #define ip_addr_v6(_a) (_a)->ip.v6
55 #define ip_addr_version(_a) (_a)->version
56
57 extern bool ip_address_is_zero (const ip_address_t * ip);
58 extern int ip_address_cmp (const ip_address_t * ip1,
59                            const ip_address_t * ip2);
60 extern void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
61 extern void ip_address_copy_addr (void *dst, const ip_address_t * src);
62 extern void ip_address_set (ip_address_t * dst, const void *src, u8 version);
63 extern u16 ip_address_size (const ip_address_t * a);
64 extern u16 ip_version_to_size (u8 ver);
65 extern u8 *format_ip_address (u8 * s, va_list * args);
66 extern uword unformat_ip_address (unformat_input_t * input, va_list * args);
67 extern fib_protocol_t ip_address_to_46 (const ip_address_t * addr,
68                                         ip46_address_t * a);
69 extern void ip_address_from_46 (const ip46_address_t * a,
70                                 fib_protocol_t fproto, ip_address_t * addr);
71
72 /* *INDENT-OFF* */
73 typedef struct ip_prefix
74 {
75   ip_address_t addr;
76   u8 len;
77 } __clib_packed ip_prefix_t;
78 /* *INDENT-ON* */
79
80 #define ip_prefix_addr(_a) (_a)->addr
81 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
82 #define ip_prefix_len(_a) (_a)->len
83 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
84 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
85
86 extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
87 extern void ip_prefix_normalize (ip_prefix_t * a);
88
89 extern void ip_address_to_fib_prefix (const ip_address_t * addr,
90                                       fib_prefix_t * prefix);
91 extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
92                                      fib_prefix_t * fibp);
93 extern u8 *format_ip_prefix (u8 * s, va_list * args);
94 extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
95
96 #endif /* __IP_TYPES_H__ */
97
98 /*
99  * fd.io coding-style-patch-verification: ON
100  *
101  * Local Variables:
102  * eval: (c-set-style "gnu")
103  * End:
104  */