ipip: Unintialized return variable (coverity warning)
[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_addr_addr(_a) (_a)->ip
50 #define ip_addr_v4(_a) (_a)->ip.v4
51 #define ip_addr_v6(_a) (_a)->ip.v6
52 #define ip_addr_version(_a) (_a)->version
53
54 extern int ip_address_cmp (const ip_address_t * ip1,
55                            const ip_address_t * ip2);
56 extern void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
57 extern void ip_address_copy_addr (void *dst, const ip_address_t * src);
58 extern void ip_address_set (ip_address_t * dst, const void *src, u8 version);
59 extern u16 ip_address_size (const ip_address_t * a);
60 extern u16 ip_version_to_size (u8 ver);
61 extern u8 *format_ip_address (u8 * s, va_list * args);
62 extern uword unformat_ip_address (unformat_input_t * input, va_list * args);
63 extern void ip_address_to_46 (const ip_address_t * addr,
64                               ip46_address_t * a, fib_protocol_t * proto);
65
66 /* *INDENT-OFF* */
67 typedef struct ip_prefix
68 {
69   ip_address_t addr;
70   u8 len;
71 } __clib_packed ip_prefix_t;
72 /* *INDENT-ON* */
73
74 #define ip_prefix_addr(_a) (_a)->addr
75 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
76 #define ip_prefix_len(_a) (_a)->len
77 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
78 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
79
80 extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
81 extern void ip_prefix_normalize (ip_prefix_t * a);
82
83 extern void ip_address_to_fib_prefix (const ip_address_t * addr,
84                                       fib_prefix_t * prefix);
85 extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
86                                      fib_prefix_t * fibp);
87 extern u8 *format_ip_prefix (u8 * s, va_list * args);
88 extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
89
90 #endif /* __IP_TYPES_H__ */
91
92 /*
93  * fd.io coding-style-patch-verification: ON
94  *
95  * Local Variables:
96  * eval: (c-set-style "gnu")
97  * End:
98  */