FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip46_address.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-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 included_ip46_address_h
17 #define included_ip46_address_h
18 
19 #include <vnet/ip/ip6_packet.h>
20 #include <vnet/ip/ip4_packet.h>
21 
22 typedef enum
23 {
28 } ip46_type_t;
29 
30 #define IP46_N_TYPES (IP46_TYPE_IP6+2)
31 
32 #define FOREACH_IP46_TYPE(_type) \
33  for (_type = IP46_TYPE_IP4; _type <= IP46_TYPE_IP6; _type++)
34 
35 extern u8 *format_ip46_type (u8 * s, va_list * args);
36 
37 /* *INDENT-OFF* */
38 typedef CLIB_PACKED (union ip46_address_t_ {
39  struct {
40  u32 pad[3];
42  };
43  ip6_address_t ip6;
44  u8 as_u8[16];
45  u64 as_u64[2];
46 }) ip46_address_t;
47 /* *INDENT-ON* */
48 
49 
51 
52 #define ip46_address_initializer {{{ 0 }}}
53 
55 ip46_address_is_ip4 (const ip46_address_t * ip46)
56 {
57  return (((ip46)->pad[0] | (ip46)->pad[1] | (ip46)->pad[2]) == 0);
58 }
59 
60 always_inline void
61 ip46_address_mask_ip4 (ip46_address_t * ip46)
62 {
63  ((ip46)->pad[0] = (ip46)->pad[1] = (ip46)->pad[2] = 0);
64 }
65 
66 always_inline void
67 ip46_address_set_ip4 (ip46_address_t * ip46, const ip4_address_t * ip)
68 {
69  ip46_address_mask_ip4 (ip46);
70  ip46->ip4 = *ip;
71 }
72 
73 always_inline void
74 ip46_address_reset (ip46_address_t * ip46)
75 {
76  ip46->as_u64[0] = ip46->as_u64[1] = 0;
77 }
78 
79 always_inline int
80 ip46_address_cmp (const ip46_address_t * ip46_1,
81  const ip46_address_t * ip46_2)
82 {
83  return (memcmp (ip46_1, ip46_2, sizeof (*ip46_1)));
84 }
85 
87 ip46_address_is_zero (const ip46_address_t * ip46)
88 {
89  return (ip46->as_u64[0] == 0 && ip46->as_u64[1] == 0);
90 }
91 
93 ip46_address_is_equal (const ip46_address_t * ip46_1,
94  const ip46_address_t * ip46_2)
95 {
96  return ((ip46_1->as_u64[0] == ip46_2->as_u64[0]) &&
97  (ip46_1->as_u64[1] == ip46_2->as_u64[1]));
98 }
99 
102  const ip4_address_t * ip4_2)
103 {
104  return (ip4_1->as_u32 == ip4_2->as_u32);
105 }
106 
108 ip46_address_is_equal_v4 (const ip46_address_t * ip46,
109  const ip4_address_t * ip4)
110 {
111  return (ip46->ip4.as_u32 == ip4->as_u32);
112 }
113 
115 ip46_address_is_equal_v6 (const ip46_address_t * ip46,
116  const ip6_address_t * ip6)
117 {
118  return ((ip46->ip6.as_u64[0] == ip6->as_u64[0]) &&
119  (ip46->ip6.as_u64[1] == ip6->as_u64[1]));
120 }
121 
123 ip46_address_copy (ip46_address_t * dst, const ip46_address_t * src)
124 {
125  dst->as_u64[0] = src->as_u64[0];
126  dst->as_u64[1] = src->as_u64[1];
127 }
128 
130 ip46_address_set_ip6 (ip46_address_t * dst, const ip6_address_t * src)
131 {
132  dst->as_u64[0] = src->as_u64[0];
133  dst->as_u64[1] = src->as_u64[1];
134 }
135 
136 always_inline ip46_address_t
138 {
139  ip46_address_t ip;
140  if (is_ipv6)
141  ip.ip6 = *((ip6_address_t *) buf);
142  else
144  return ip;
145 }
146 
148 ip46_address_get_type (const ip46_address_t * ip)
149 {
151 }
152 
154 ip46_address_is_multicast (const ip46_address_t * a)
155 {
156  return ip46_address_is_ip4 (a) ? ip4_address_is_multicast (&a->ip4) :
157  ip6_address_is_multicast (&a->ip6);
158 }
159 
160 extern void ip4_address_increment (ip4_address_t * i);
161 extern void ip6_address_increment (ip6_address_t * i);
162 extern void ip46_address_increment (ip46_type_t type, ip46_address_t * ip);
163 
164 #endif /* included_ip46_address_h */
165 
166 /*
167  * fd.io coding-style-patch-verification: ON
168  *
169  * Local Variables:
170  * eval: (c-set-style "gnu")
171  * End:
172  */
ip6_address_increment
void ip6_address_increment(ip6_address_t *i)
Definition: ip46_address.c:45
ip46_address_mask_ip4
static void ip46_address_mask_ip4(ip46_address_t *ip46)
Definition: ip46_address.h:61
is_ipv6
bool is_ipv6
Definition: dhcp.api:202
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
ip46_address_is_multicast
static uword ip46_address_is_multicast(const ip46_address_t *a)
Definition: ip46_address.h:154
ip46_address_set_ip4
static void ip46_address_set_ip4(ip46_address_t *ip46, const ip4_address_t *ip)
Definition: ip46_address.h:67
ip46_address_reset
static void ip46_address_reset(ip46_address_t *ip46)
Definition: ip46_address.h:74
ip46_address_set_ip6
static_always_inline void ip46_address_set_ip6(ip46_address_t *dst, const ip6_address_t *src)
Definition: ip46_address.h:130
ip46_address_cmp
static int ip46_address_cmp(const ip46_address_t *ip46_1, const ip46_address_t *ip46_2)
Definition: ip46_address.h:80
ip46_address_is_ip4
static u8 ip46_address_is_ip4(const ip46_address_t *ip46)
Definition: ip46_address.h:55
IP46_TYPE_IP4
@ IP46_TYPE_IP4
Definition: ip46_address.h:26
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
ip4_address_is_equal
static_always_inline int ip4_address_is_equal(const ip4_address_t *ip4_1, const ip4_address_t *ip4_2)
Definition: ip46_address.h:101
ip46_address_increment
void ip46_address_increment(ip46_type_t type, ip46_address_t *ip)
Definition: ip46_address.c:61
ip46_address_get_type
static ip46_type_t ip46_address_get_type(const ip46_address_t *ip)
Definition: ip46_address.h:148
ip6_packet.h
ip4_address_is_multicast
static uword ip4_address_is_multicast(const ip4_address_t *a)
Definition: ip4_packet.h:446
ip6_address_is_multicast
static uword ip6_address_is_multicast(const ip6_address_t *a)
Definition: ip6_packet.h:121
ip46_address_is_equal
static u8 ip46_address_is_equal(const ip46_address_t *ip46_1, const ip46_address_t *ip46_2)
Definition: ip46_address.h:93
ip46_address_is_equal_v6
static_always_inline int ip46_address_is_equal_v6(const ip46_address_t *ip46, const ip6_address_t *ip6)
Definition: ip46_address.h:115
static_always_inline
#define static_always_inline
Definition: clib.h:112
ip4_address_increment
void ip4_address_increment(ip4_address_t *i)
Definition: ip46_address.c:37
uword
u64 uword
Definition: types.h:112
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
IP46_TYPE_IP6
@ IP46_TYPE_IP6
Definition: ip46_address.h:27
IP46_TYPE_BOTH
@ IP46_TYPE_BOTH
Definition: ip46_address.h:25
ip46_address_copy
static_always_inline void ip46_address_copy(ip46_address_t *dst, const ip46_address_t *src)
Definition: ip46_address.h:123
ip46_address_is_zero
static u8 ip46_address_is_zero(const ip46_address_t *ip46)
Definition: ip46_address.h:87
ip4_packet.h
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
format_ip46_type
u8 * format_ip46_type(u8 *s, va_list *args)
Definition: ip46_address.c:19
u64
unsigned long u64
Definition: types.h:89
format_ip46_address
format_function_t format_ip46_address
Definition: ip46_address.h:50
buf
u64 buf
Definition: application.c:493
u32
unsigned int u32
Definition: types.h:88
ip6
vl_api_ip6_address_t ip6
Definition: one.api:424
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
CLIB_PACKED
typedef CLIB_PACKED(union ip46_address_t_ { struct { u32 pad[3];ip4_address_t ip4;};ip6_address_t ip6;u8 as_u8[16];u64 as_u64[2];}) ip46_address_t
as_u64
u64 as_u64
Definition: bihash_doc.h:63
to_ip46
static ip46_address_t to_ip46(u32 is_ipv6, u8 *buf)
Definition: ip46_address.h:137
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:544
ip
vl_api_address_t ip
Definition: l2.api:558
ip46_type_t
ip46_type_t
Definition: ip46_address.h:22
IP46_TYPE_ANY
@ IP46_TYPE_ANY
Definition: ip46_address.h:24
pad
u8 pad[3]
log2 (size of the packing page block)
Definition: bihash_doc.h:61
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ip46_address_is_equal_v4
static_always_inline int ip46_address_is_equal_v4(const ip46_address_t *ip46, const ip4_address_t *ip4)
Definition: ip46_address.h:108