FD.io VPP  v21.10.1-2-g0a485f517
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 
30  va_list * args);
31 extern u8 *format_ip_address_family (u8 * s, va_list * args);
32 
33 #define FOR_EACH_IP_ADDRESS_FAMILY(_af) \
34  for (_af = AF_IP4; _af <= AF_IP6; _af++)
35 
39  fp);
40 
42 {
45 } __clib_packed ip_sub_address_family_t;
46 
47 #define N_SAFI (SAFI_MULTICAST+1)
48 
50  va_list * args);
51 extern u8 *format_ip_sub_address_family (u8 * s, va_list * args);
52 
53 #define FOR_EACH_IP_ADDRESS_SUB_FAMILY(_safi) \
54  for (_safi = SAFI_UNICAST; _safi <= SAFI_MULTICAST; _safi++)
55 
56 #define u8_ptr_add(ptr, index) (((u8 *)ptr) + index)
57 #define u16_net_add(u, val) clib_host_to_net_u16(clib_net_to_host_u16(u) + (val))
58 
59 /**
60  * Locations in the IP switch path where features can be applied
61  */
62 #define foreach_ip_feature_location \
63  _(INPUT, "input") \
64  _(OUTPUT, "output") \
65  _(LOCAL, "local") \
66  _(PUNT, "punt") \
67  _(DROP, "drop") \
68 
70 {
71 #define _(a,b) IP_FEATURE_##a,
73 #undef _
74 } __clib_packed ip_feature_location_t;
75 
76 #define N_IP_FEATURE_LOCATIONS (IP_FEATURE_DROP+1)
77 
78 /* *INDENT-OFF* */
79 typedef struct ip_address
80 {
81  ip46_address_t ip;
83 } __clib_packed ip_address_t;
84 /* *INDENT-ON* */
85 
86 #define IP_ADDRESS_V4_ALL_0S {.ip.ip4.as_u32 = 0, .version = AF_IP4}
87 #define IP_ADDRESS_V6_ALL_0S {.ip.ip6.as_u64 = {0, 0}, .version = AF_IP6}
88 #define ip_address_initializer IP_ADDRESS_V6_ALL_0S
89 
90 #define ip_addr_46(_a) (_a)->ip
91 #define ip_addr_v4(_a) (_a)->ip.ip4
92 #define ip_addr_v6(_a) (_a)->ip.ip6
93 #define ip_addr_version(_a) (_a)->version
94 
95 extern u8 *ip_addr_bytes (ip_address_t * ip);
96 
97 extern bool ip_address_is_zero (const ip_address_t * ip);
98 extern int ip_address_cmp (const ip_address_t * ip1,
99  const ip_address_t * ip2);
100 extern void ip_address_copy (ip_address_t * dst, const ip_address_t * src);
101 extern void ip_address_copy_addr (void *dst, const ip_address_t * src);
102 extern void ip_address_set (ip_address_t *dst, const void *src,
104 extern u16 ip_address_size (const ip_address_t * a);
106 extern u8 *format_ip_address (u8 * s, va_list * args);
107 extern uword unformat_ip_address (unformat_input_t * input, va_list * args);
109  ip46_address_t * a);
110 extern void ip_address_from_46 (const ip46_address_t * a,
111  fib_protocol_t fproto, ip_address_t * addr);
112 extern void ip_address_increment (ip_address_t * ip);
113 extern void ip_address_reset (ip_address_t * ip);
114 
115 /* *INDENT-OFF* */
116 typedef struct ip_prefix
117 {
120 } __clib_packed ip_prefix_t;
121 /* *INDENT-ON* */
122 
123 #define ip_prefix_addr(_a) (_a)->addr
124 #define ip_prefix_version(_a) ip_addr_version(&ip_prefix_addr(_a))
125 #define ip_prefix_len(_a) (_a)->len
126 #define ip_prefix_v4(_a) ip_addr_v4(&ip_prefix_addr(_a))
127 #define ip_prefix_v6(_a) ip_addr_v6(&ip_prefix_addr(_a))
128 
129 extern int ip_prefix_cmp (ip_prefix_t * p1, ip_prefix_t * p2);
130 extern void ip_prefix_normalize (ip_prefix_t * a);
131 
132 extern void ip_address_to_fib_prefix (const ip_address_t * addr,
133  fib_prefix_t * prefix);
134 extern void ip_prefix_to_fib_prefix (const ip_prefix_t * ipp,
135  fib_prefix_t * fibp);
136 extern u8 *format_ip_prefix (u8 * s, va_list * args);
137 extern uword unformat_ip_prefix (unformat_input_t * input, va_list * args);
138 
139 extern bool ip_prefix_validate (const ip_prefix_t * ip);
140 extern void ip4_address_normalize (ip4_address_t * ip4, u8 preflen);
141 extern void ip6_address_normalize (ip6_address_t * ip6, u8 preflen);
142 extern void ip4_preflen_to_mask (u8 pref_len, ip4_address_t * ip);
145  ip4_address_t * res);
146 extern void ip6_prefix_max_address_host_order (ip6_address_t * ip, u8 plen,
147  ip6_address_t * res);
148 extern void ip6_preflen_to_mask (u8 pref_len, ip6_address_t * mask);
149 extern u32 ip6_mask_to_preflen (ip6_address_t * mask);
150 
151 #endif /* __IP_TYPES_H__ */
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
ip_address_family_to_fib_proto
fib_protocol_t ip_address_family_to_fib_proto(ip_address_family_t af)
Definition: ip_types.c:223
ip_version_to_size
u16 ip_version_to_size(ip_address_family_t af)
Definition: ip_types.c:178
ip_address
Definition: ip_types.h:79
ip6_preflen_to_mask
void ip6_preflen_to_mask(u8 pref_len, ip6_address_t *mask)
Definition: ip_types.c:517
ip_prefix_to_fib_prefix
void ip_prefix_to_fib_prefix(const ip_prefix_t *ipp, fib_prefix_t *fibp)
convert from a LISP to a FIB prefix
Definition: ip_types.c:410
ip_prefix_validate
bool ip_prefix_validate(const ip_prefix_t *ip)
Definition: ip_types.c:447
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
ip6_address_normalize
void ip6_address_normalize(ip6_address_t *ip6, u8 preflen)
Definition: ip_types.c:471
ip_prefix
Definition: ip_types.h:116
ip4_preflen_to_mask
void ip4_preflen_to_mask(u8 pref_len, ip4_address_t *ip)
Definition: ip_types.c:491
ip_prefix_t
struct ip_prefix ip_prefix_t
ip_address_from_46
void ip_address_from_46(const ip46_address_t *a, fib_protocol_t fproto, ip_address_t *addr)
Definition: ip_types.c:259
u16
unsigned short u16
Definition: types.h:57
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
SAFI_UNICAST
@ SAFI_UNICAST
Definition: ip_types.h:43
unformat_ip_address_family
uword unformat_ip_address_family(unformat_input_t *input, va_list *args)
Definition: ip.c:231
ip_address_family_from_fib_proto
ip_address_family_t ip_address_family_from_fib_proto(fib_protocol_t fp)
Definition: ip_types.c:237
unformat_input_t
struct _unformat_input_t unformat_input_t
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
unformat_ip_prefix
uword unformat_ip_prefix(unformat_input_t *input, va_list *args)
Definition: ip_types.c:64
format_ip_prefix
u8 * format_ip_prefix(u8 *s, va_list *args)
Definition: ip_types.c:56
ip_prefix::len
u8 len
Definition: ip_types.h:119
ip_prefix_normalize
void ip_prefix_normalize(ip_prefix_t *a)
Definition: ip_types.c:357
format_ip_sub_address_family
u8 * format_ip_sub_address_family(u8 *s, va_list *args)
Definition: ip.c:251
unformat_ip_address
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: ip_types.c:41
ip_address::version
ip_address_family_t version
Definition: ip_types.h:82
ip4_mask_to_preflen
u32 ip4_mask_to_preflen(ip4_address_t *mask)
Definition: ip_types.c:500
ip4_prefix_max_address_host_order
void ip4_prefix_max_address_host_order(ip4_address_t *ip, u8 plen, ip4_address_t *res)
Definition: ip_types.c:508
fib_types.h
ip_address_t
struct ip_address ip_address_t
ip_address_cmp
int ip_address_cmp(const ip_address_t *ip1, const ip_address_t *ip2)
Definition: ip_types.c:117
ip6_prefix_max_address_host_order
void ip6_prefix_max_address_host_order(ip6_address_t *ip, u8 plen, ip6_address_t *res)
Definition: ip_types.c:539
uword
u64 uword
Definition: types.h:112
ip_address_family_t_
ip_address_family_t_
Definition: ip_types.h:21
ip_address_copy_addr
void ip_address_copy_addr(void *dst, const ip_address_t *src)
Definition: ip_types.c:164
ip_address_to_46
fib_protocol_t ip_address_to_46(const ip_address_t *addr, ip46_address_t *a)
Definition: ip_types.c:252
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
src
vl_api_address_t src
Definition: gre.api:54
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
ip_address_size
u16 ip_address_size(const ip_address_t *a)
Definition: ip_types.c:87
ip4_address_t
Definition: ip4_packet.h:50
ip_address_set
void ip_address_set(ip_address_t *dst, const void *src, ip_address_family_t version)
Definition: ip_types.c:207
ip_addr_bytes
u8 * ip_addr_bytes(ip_address_t *ip)
Definition: ip_types.c:149
ip_address_is_zero
bool ip_address_is_zero(const ip_address_t *ip)
Definition: ip_types.c:102
ip_address_family_to_link_type
vnet_link_t ip_address_family_to_link_type(ip_address_family_t af)
Definition: ip_types.c:193
format_ip_address
u8 * format_ip_address(u8 *s, va_list *args)
Definition: ip_types.c:21
ip_prefix::addr
ip_address_t addr
Definition: ip_types.h:118
version
option version
Definition: sample.api:19
ip_feature_location_t_
ip_feature_location_t_
Definition: ip_types.h:69
u32
unsigned int u32
Definition: types.h:88
af
vl_api_address_family_t af
Definition: ip.api:619
ip6
vl_api_ip6_address_t ip6
Definition: one.api:424
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
ip6_mask_to_preflen
u32 ip6_mask_to_preflen(ip6_address_t *mask)
Definition: ip_types.c:562
AF_IP6
@ AF_IP6
Definition: ip_types.h:24
ip_address_copy
void ip_address_copy(ip_address_t *dst, const ip_address_t *src)
Definition: ip_types.c:133
ip_address_reset
void ip_address_reset(ip_address_t *ip)
Definition: ip_types.c:298
vnet_link_t
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
unformat_ip_sub_address_family
uword unformat_ip_sub_address_family(unformat_input_t *input, va_list *args)
Definition: ip.c:267
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
ip
vl_api_address_t ip
Definition: l2.api:558
ip_sub_address_family_t
enum ip_sub_address_family_t_ ip_sub_address_family_t
ip_address::ip
ip46_address_t ip
Definition: ip_types.h:81
ip4_address_normalize
void ip4_address_normalize(ip4_address_t *ip4, u8 preflen)
Definition: ip_types.c:461
format_ip_address_family
u8 * format_ip_address_family(u8 *s, va_list *args)
Definition: ip.c:215
ip_sub_address_family_t_
ip_sub_address_family_t_
Definition: ip_types.h:41
ip_feature_location_t
enum ip_feature_location_t_ ip_feature_location_t
SAFI_MULTICAST
@ SAFI_MULTICAST
Definition: ip_types.h:44
ip_address_increment
void ip_address_increment(ip_address_t *ip)
Definition: ip_types.c:291
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
foreach_ip_feature_location
#define foreach_ip_feature_location
Locations in the IP switch path where features can be applied.
Definition: ip_types.h:62
prefix
vl_api_prefix_t prefix
Definition: ip.api:175
ip_address_to_fib_prefix
void ip_address_to_fib_prefix(const ip_address_t *addr, fib_prefix_t *prefix)
convert from a IP address to a FIB prefix
Definition: ip_types.c:270
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t
ip_prefix_cmp
int ip_prefix_cmp(ip_prefix_t *p1, ip_prefix_t *p2)
Definition: ip_types.c:383