FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
ip_types.h
Go to the documentation of this file.
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 
22 {
25 } __clib_packed ip_address_family_t;
26 
27 #define N_AF (AF_IP6+1)
28 
29 #define N_AF (AF_IP6+1)
30 
32  va_list * args);
33 extern u8 *format_ip_address_family (u8 * s, va_list * args);
34 
35 #define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
36  for (_af = AF_IP4; _af <= AF_IP6; _af++)
37 
41  fp);
42 
43 #define u8_ptr_add(ptr, index) (((u8 *)ptr) + index)
44 #define u16_net_add(u, val) clib_host_to_net_u16(clib_net_to_host_u16(u) + (val))
45 
46 /* *INDENT-OFF* */
47 typedef struct ip_address
48 {
49  ip46_address_t ip;
51 } __clib_packed ip_address_t;
52 /* *INDENT-ON* */
53 
54 #define IP_ADDRESS_V4_ALL_0S {.ip.ip4.as_u32 = 0, .version = AF_IP4}
55 #define IP_ADDRESS_V6_ALL_0S {.ip.ip6.as_u64 = {0, 0}, .version = AF_IP6}
56 
57 #define ip_addr_46(_a) (_a)->ip
58 #define ip_addr_v4(_a) (_a)->ip.ip4
59 #define ip_addr_v6(_a) (_a)->ip.ip6
60 #define ip_addr_version(_a) (_a)->version
61 
62 extern u8 *ip_addr_bytes (ip_address_t * ip);
63 
64 extern bool ip_address_is_zero (const ip_address_t * ip);
65 extern int ip_address_cmp (const ip_address_t * ip1,
66  const ip_address_t * ip2);
67 extern void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
68 extern void ip_address_copy_addr (void *dst, const ip_address_t * src);
69 extern void ip_address_set (ip_address_t * dst, const void *src, u8 version);
70 extern u16 ip_address_size (const ip_address_t * a);
72 extern u8 *format_ip_address (u8 * s, va_list * args);
73 extern uword unformat_ip_address (unformat_input_t * input, va_list * args);
75  ip46_address_t * a);
76 extern void ip_address_from_46 (const ip46_address_t * a,
77  fib_protocol_t fproto, ip_address_t * addr);
78 
79 /* *INDENT-OFF* */
80 typedef struct ip_prefix
81 {
84 } __clib_packed ip_prefix_t;
85 /* *INDENT-ON* */
86 
87 #define ip_prefix_addr(_a) (_a)->addr
88 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
89 #define ip_prefix_len(_a) (_a)->len
90 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
91 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
92 
93 extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
94 extern void ip_prefix_normalize (ip_prefix_t * a);
95 
96 extern void ip_address_to_fib_prefix (const ip_address_t * addr,
98 extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
99  fib_prefix_t * fibp);
100 extern u8 *format_ip_prefix (u8 * s, va_list * args);
101 extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
102 
103 extern bool ip_prefix_validate (const ip_prefix_t * ip);
104 extern void ip4_address_normalize (ip4_address_t * ip4, u8 preflen);
105 extern void ip6_address_normalize (ip6_address_t * ip6, u8 preflen);
106 extern void ip4_preflen_to_mask (u8 pref_len, ip4_address_t * ip);
107 extern u32 ip4_mask_to_preflen (ip4_address_t * mask);
109  ip4_address_t * res);
110 extern void ip6_prefix_max_address_host_order (ip6_address_t * ip, u8 plen,
111  ip6_address_t * res);
112 extern void ip6_preflen_to_mask (u8 pref_len, ip6_address_t * mask);
113 extern u32 ip6_mask_to_preflen (ip6_address_t * mask);
114 
115 #endif /* __IP_TYPES_H__ */
116 
117 /*
118  * fd.io coding-style-patch-verification: ON
119  *
120  * Local Variables:
121  * eval: (c-set-style "gnu")
122  * End:
123  */
void ip_address_to_fib_prefix(const ip_address_t *addr, fib_prefix_t *prefix)
convert from a LISP address to a FIB prefix
Definition: control.c:130
u8 * format_ip_address(u8 *s, va_list *args)
Definition: ip_types.c:21
u16 ip_version_to_size(ip_address_family_t af)
Definition: ip_types.c:175
struct ip_address ip_address_t
int ip_address_cmp(const ip_address_t *ip1, const ip_address_t *ip2)
Definition: ip_types.c:114
u16 ip_address_size(const ip_address_t *a)
Definition: ip_types.c:84
a
Definition: bitmap.h:538
void ip4_address_normalize(ip4_address_t *ip4, u8 preflen)
Definition: ip_types.c:411
fib_protocol_t ip_address_family_to_fib_proto(ip_address_family_t af)
Definition: ip_types.c:221
fib_protocol_t ip_address_to_46(const ip_address_t *addr, ip46_address_t *a)
Definition: ip_types.c:250
u8 len
Definition: ip_types.h:83
ip46_address_t ip
Definition: ip_types.h:49
u32 ip4_mask_to_preflen(ip4_address_t *mask)
Definition: ip_types.c:450
vl_api_address_t src
Definition: gre.api:54
vl_api_prefix_t prefix
Definition: ip.api:144
void ip_address_from_46(const ip46_address_t *a, fib_protocol_t fproto, ip_address_t *addr)
Definition: ip_types.c:257
void ip4_prefix_max_address_host_order(ip4_address_t *ip, u8 plen, ip4_address_t *res)
Definition: ip_types.c:458
vhost_vring_addr_t addr
Definition: vhost_user.h:254
bool ip_address_is_zero(const ip_address_t *ip)
Definition: ip_types.c:99
int ip_prefix_cmp(ip_prefix_t *p1, ip_prefix_t *p2)
Definition: ip_types.c:344
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u8 * format_ip_address_family(u8 *s, va_list *args)
Definition: ip.c:100
vl_api_ip6_address_t ip6
Definition: one.api:424
void ip6_prefix_max_address_host_order(ip6_address_t *ip, u8 plen, ip6_address_t *res)
Definition: ip_types.c:489
Aggregate type for a prefix.
Definition: fib_types.h:203
struct ip_prefix ip_prefix_t
void ip6_address_normalize(ip6_address_t *ip6, u8 preflen)
Definition: ip_types.c:421
void ip_address_copy_addr(void *dst, const ip_address_t *src)
Definition: ip_types.c:161
unsigned int u32
Definition: types.h:88
void ip6_preflen_to_mask(u8 pref_len, ip6_address_t *mask)
Definition: ip_types.c:467
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
bool ip_prefix_validate(const ip_prefix_t *ip)
Definition: ip_types.c:397
vl_api_ip4_address_t ip4
Definition: one.api:376
vl_api_address_t dst
Definition: gre.api:55
void ip4_preflen_to_mask(u8 pref_len, ip4_address_t *ip)
Definition: ip_types.c:441
uword unformat_ip_address_family(unformat_input_t *input, va_list *args)
Definition: ip.c:116
uword unformat_ip_prefix(unformat_input_t *input, va_list *args)
Definition: ip_types.c:64
u8 * ip_addr_bytes(ip_address_t *ip)
Definition: ip_types.c:146
void ip_prefix_to_fib_prefix(const ip_prefix_t *ipp, fib_prefix_t *fibp)
convert from a LISP to a FIB prefix
Definition: control.c:154
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
ip_address_family_t version
Definition: ip_types.h:50
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: ip_types.c:41
ip_address_t addr
Definition: ip_types.h:82
enum ip_address_family_t_ ip_address_family_t
void ip_address_set(ip_address_t *dst, const void *src, u8 version)
Definition: ip_types.c:205
void ip_prefix_normalize(ip_prefix_t *a)
Definition: ip_types.c:318
u64 uword
Definition: types.h:112
ip_address_family_t ip_address_family_from_fib_proto(fib_protocol_t fp)
Definition: ip_types.c:235
ip_address_family_t_
Definition: ip_types.h:21
void ip_address_copy(ip_address_t *dst, const ip_address_t *src)
Definition: ip_types.c:130
u32 ip6_mask_to_preflen(ip6_address_t *mask)
Definition: ip_types.c:512
u8 * format_ip_prefix(u8 *s, va_list *args)
Definition: ip_types.c:56
vnet_link_t ip_address_family_to_link_type(ip_address_family_t af)
Definition: ip_types.c:190