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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __IP_TYPES_H__
17 #define __IP_TYPES_H__
19 #include <vnet/fib/fib_types.h>
21 typedef enum ip_address_family_t_
25 } ip_address_family_t;
27 #define N_AF (AF_IP6+1)
29 extern uword unformat_ip_address_family (unformat_input_t * input,
31 extern u8 *format_ip_address_family (u8 * s, va_list * args);
33 #define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
34 for (_af = AF_IP4; _af <= AF_IP6; _af++)
36 #define u8_ptr_add(ptr, index) (((u8 *)ptr) + index)
37 #define u16_net_add(u, val) clib_host_to_net_u16(clib_net_to_host_u16(u) + (val))
40 typedef struct ip_address
47 ip_address_family_t version;
48 } __clib_packed ip_address_t;
51 #define IP_ADDRESS_V4_ALL_0S {.ip.v4.as_u32 = 0, .version = AF_IP4}
52 #define IP_ADDRESS_V6_ALL_0S {.ip.v4.as_u32 = 0, .version = AF_IP6}
54 #define ip_addr_addr(_a) (_a)->ip
55 #define ip_addr_v4(_a) (_a)->ip.v4
56 #define ip_addr_v6(_a) (_a)->ip.v6
57 #define ip_addr_version(_a) (_a)->version
59 extern bool ip_address_is_zero (const ip_address_t * ip);
60 extern int ip_address_cmp (const ip_address_t * ip1,
61 const ip_address_t * ip2);
62 extern void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
63 extern void ip_address_copy_addr (void *dst, const ip_address_t * src);
64 extern void ip_address_set (ip_address_t * dst, const void *src, u8 version);
65 extern u16 ip_address_size (const ip_address_t * a);
66 extern u16 ip_version_to_size (u8 ver);
67 extern u8 *format_ip_address (u8 * s, va_list * args);
68 extern uword unformat_ip_address (unformat_input_t * input, va_list * args);
69 extern fib_protocol_t ip_address_to_46 (const ip_address_t * addr,
71 extern void ip_address_from_46 (const ip46_address_t * a,
72 fib_protocol_t fproto, ip_address_t * addr);
75 typedef struct ip_prefix
79 } __clib_packed ip_prefix_t;
82 #define ip_prefix_addr(_a) (_a)->addr
83 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
84 #define ip_prefix_len(_a) (_a)->len
85 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
86 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
88 extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
89 extern void ip_prefix_normalize (ip_prefix_t * a);
91 extern void ip_address_to_fib_prefix (const ip_address_t * addr,
92 fib_prefix_t * prefix);
93 extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
95 extern u8 *format_ip_prefix (u8 * s, va_list * args);
96 extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
98 #endif /* __IP_TYPES_H__ */
101 * fd.io coding-style-patch-verification: ON
104 * eval: (c-set-style "gnu")