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 extern uword unformat_ip_address_family (unformat_input_t * input,
29 extern u8 *format_ip_address_family (u8 * s, va_list * args);
31 #define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
32 for (_af = AF_IP4; _af <= AF_IP6; _af++)
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))
38 typedef struct ip_address
45 ip_address_family_t version;
46 } __clib_packed ip_address_t;
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
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);
67 typedef struct ip_prefix
71 } __clib_packed ip_prefix_t;
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))
80 extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
81 extern void ip_prefix_normalize (ip_prefix_t * a);
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,
87 extern u8 *format_ip_prefix (u8 * s, va_list * args);
88 extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
90 #endif /* __IP_TYPES_H__ */
93 * fd.io coding-style-patch-verification: ON
96 * eval: (c-set-style "gnu")