FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip6.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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  * ip/ip6.h: ip6 main include file
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_ip_ip6_h
41 #define included_ip_ip6_h
42 
43 #include <stdbool.h>
44 
45 #include <vlib/buffer.h>
46 
47 #include <vnet/ip/ip6_packet.h>
48 #include <vnet/ip/ip46_address.h>
50 #include <vnet/ip/lookup.h>
51 #include <vnet/ip/ip_interface.h>
52 #include <vnet/ip/ip_flow_hash.h>
53 
54 typedef struct
55 {
56  ip6_address_t addr;
60 
61 typedef struct
62 {
63  /* required for pool_get_aligned. */
64  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
65 
66  /* Table ID (hash key) for this FIB. */
68 
69  /* Index into FIB vector. */
71 } ip6_fib_t;
72 
73 typedef struct ip6_mfib_t
74 {
75  /* required for pool_get_aligned. */
76  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
77 
78  /* Table ID (hash key) for this FIB. */
80 
81  /* Index into FIB vector. */
83 } ip6_mfib_t;
84 
85 struct ip6_main_t;
86 
88  (struct ip6_main_t * im,
89  uword opaque,
91  ip6_address_t * address,
92  u32 address_length, u32 if_address_index, u32 is_del);
93 
94 typedef struct
95 {
99 
100 typedef void (ip6_table_bind_function_t)
101  (struct ip6_main_t * im,
102  uword opaque, u32 sw_if_index, u32 new_fib_index, u32 old_fib_index);
103 
104 typedef struct
105 {
109 
110 typedef struct ip6_main_t
111 {
113 
114  /* Pool of FIBs. */
116 
117  /* Pool of V6 FIBs. */
119 
120  /** Vector of MFIBs. */
122 
123  /* Network byte orders subnet mask for each prefix length */
124  ip6_address_t fib_masks[129];
125 
126  /* Table index indexed by software interface. */
128 
129  /** Table index indexed by software interface. */
131 
132  /* IP6 enabled count by software interface */
134 
135  /* Hash table mapping table id to fib index.
136  ID space is not necessarily dense; index space is dense. */
138 
139  /** Hash table mapping table id to multicast fib index.
140  ID space is not necessarily dense; index space is dense. */
142 
143  /* Hash table mapping interface rewrite adjacency index by sw if index. */
145 
146  /* Functions to call when interface address changes. */
149 
150  /** Functions to call when interface to table biding changes. */
152 
153  /* Seed for Jenkins hash used to compute ip6 flow hash. */
155 
156  struct
157  {
158  /* TTL to use for host generated packets. */
160 
161  u8 pad[3];
162  } host_config;
163 
164  /* HBH processing enabled? */
166 } ip6_main_t;
167 
168 #define ND_THROTTLE_BITS 512
169 
170 /* Global ip6 main structure. */
171 extern ip6_main_t ip6_main;
172 
173 /* Global ip6 input node. Errors get attached to ip6 input node. */
182 
183 extern void ip6_forward_next_trace (vlib_main_t * vm,
186  vlib_rx_or_tx_t which_adj_index);
187 
190  const ip6_address_t * key,
191  const ip6_address_t * dest, uword dest_length)
192 {
193  int i;
194  for (i = 0; i < ARRAY_LEN (key->as_uword); i++)
195  {
196  if ((key->as_uword[i] ^ dest->as_uword[i]) & im->
197  fib_masks[dest_length].as_uword[i])
198  return 0;
199  }
200  return 1;
201 }
202 
205  ip6_address_t * key,
207 {
208  ip6_address_t *a = ip_interface_address_get_address (&im->lookup_main, ia);
210 }
211 
212 /* As above but allows for unaligned destinations (e.g. works right from IP header of packet). */
215  ip6_address_t * key,
216  ip6_address_t * dest,
217  uword dest_length)
218 {
219  int i;
220  for (i = 0; i < ARRAY_LEN (key->as_uword); i++)
221  {
222  if ((clib_mem_unaligned (&key->as_uword[i], uword) ^ dest->as_uword[i])
223  & im->fib_masks[dest_length].as_uword[i])
224  return 0;
225  }
226  return 1;
227 }
228 
229 /* Find interface address which matches destination. */
230 always_inline ip6_address_t *
232  const ip6_address_t * dst,
235  result_ia)
236 {
237  ip_lookup_main_t *lm = &im->lookup_main;
239  ip6_address_t *result = 0;
240 
241  /* *INDENT-OFF* */
243  1 /* honor unnumbered */,
244  ({
245  ip6_address_t * a = ip_interface_address_get_address (lm, ia);
247  {
248  result = a;
249  break;
250  }
251  }));
252  /* *INDENT-ON* */
253  if (result_ia)
254  *result_ia = result ? ia : 0;
255  return result;
256 }
257 
260  ip6_address_t * address,
261  u32 address_length, u32 is_del);
263 
264 /**
265  * @brief get first IPv6 interface address
266  */
268 
269 int ip6_address_compare (ip6_address_t * a1, ip6_address_t * a2);
270 
271 uword
273  u16 dst_port, u32 next_node_index);
274 
276  ip6_header_t * ip0,
277  int *bogus_lengthp);
278 
282 
284 
285 u8 *format_ip6_forward_next_trace (u8 * s, va_list * args);
286 
288 
289 void ip6_punt_policer_add_del (u8 is_add, u32 policer_index);
290 void ip6_punt_redirect_add (u32 rx_sw_if_index,
291  u32 tx_sw_if_index, ip46_address_t * nh);
292 void ip6_punt_redirect_add_paths (u32 rx_sw_if_index,
294 void ip6_punt_redirect_del (u32 rx_sw_if_index);
295 
297  u32 table_index);
299 
300 u8 *format_ip6_hop_by_hop_ext_hdr (u8 * s, va_list * args);
301 /*
302  * Hop-by-Hop handling
303  */
304 typedef struct
305 {
306  /* Array of function pointers to HBH option handling routines */
307  int (*options[256]) (vlib_buffer_t * b, ip6_header_t * ip,
309  u8 *(*trace[256]) (u8 * s, ip6_hop_by_hop_option_t * opt);
312 
314 
315 int ip6_hbh_register_option (u8 option,
316  int options (vlib_buffer_t * b,
317  ip6_header_t * ip,
319  u8 * trace (u8 * s,
320  ip6_hop_by_hop_option_t * opt));
321 int ip6_hbh_unregister_option (u8 option);
323 
326 {
327  u32 fib_index, sw_if_index;
328  sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
329  fib_index = vnet_buffer (b)->sw_if_index[VLIB_TX];
330  return (fib_index == (u32) ~ 0) ?
332 }
333 #endif /* included_ip_ip6_h */
334 
335 /*
336  * fd.io coding-style-patch-verification: ON
337  *
338  * Local Variables:
339  * eval: (c-set-style "gnu")
340  * End:
341  */
ip6_local_hop_by_hop_register_protocol
void ip6_local_hop_by_hop_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_hop_by_hop.c:1116
im
vnet_interface_main_t * im
Definition: interface_output.c:395
ip6_punt_node
vlib_node_registration_t ip6_punt_node
(constructor) VLIB_REGISTER_NODE (ip6_punt_node)
Definition: ip6_punt_drop.c:160
trace
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: vlib_api_cli.c:899
ip_interface_address_get_address
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: ip_interface.h:43
ip6_tcp_udp_icmp_validate_checksum
u32 ip6_tcp_udp_icmp_validate_checksum(vlib_main_t *vm, vlib_buffer_t *p0)
Definition: ip6_forward.c:1163
ip6_mfib_t::table_id
u32 table_id
Definition: ip6.h:79
foreach_ip_interface_address
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: ip_interface.h:57
dst_port
vl_api_ip_port_and_mask_t dst_port
Definition: flow_types.api:92
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
ip6_punt_redirect_add
void ip6_punt_redirect_add(u32 rx_sw_if_index, u32 tx_sw_if_index, ip46_address_t *nh)
Definition: ip6_punt_drop.c:309
ip6_punt_redirect_del
void ip6_punt_redirect_del(u32 rx_sw_if_index)
Definition: ip6_punt_drop.c:339
ip6_tcp_udp_icmp_compute_checksum
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
Definition: ip6_forward.c:1098
buffer.h
ip6_interface_address_matching_destination
static ip6_address_t * ip6_interface_address_matching_destination(ip6_main_t *im, const ip6_address_t *dst, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip6.h:231
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
next
u16 * next
Definition: nat44_ei_out2in.c:718
ip_interface_address_t::address_length
u16 address_length
Definition: lookup.h:98
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip6_fib_t::table_id
u32 table_id
Definition: ip6.h:67
serialize_function_t
void() serialize_function_t(serialize_main_t *m, va_list *va)
Definition: serialize.h:168
ip6_hop_by_hop_main
ip6_hop_by_hop_main_t ip6_hop_by_hop_main
Definition: ip6_forward.c:2252
paths
paths
Definition: map.api:460
ip6_main_t::interface_route_adj_index_by_sw_if_index
uword * interface_route_adj_index_by_sw_if_index
Definition: ip6.h:144
u16
unsigned short u16
Definition: types.h:57
ip6_main_t::flow_hash_seed
u32 flow_hash_seed
Definition: ip6.h:154
ip6_hop_by_hop_packet.h
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
ip6_fib_t::index
u32 index
Definition: ip6.h:70
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
node_index
node node_index
Definition: interface_output.c:420
ip6_mfib_t
struct ip6_mfib_t ip6_mfib_t
ip6_hop_by_hop_option_t
Definition: ip6_hop_by_hop_packet.h:29
vlib_frame_t
Definition: node.h:372
ip6_lookup_node
vlib_node_registration_t ip6_lookup_node
(constructor) VLIB_REGISTER_NODE (ip6_lookup_node)
Definition: ip6_forward.c:741
ip6_main_t
struct ip6_main_t ip6_main_t
mfib_table_t_
A protocol Independent IP multicast FIB table.
Definition: mfib_table.h:71
unserialize_vnet_ip6_main
serialize_function_t unserialize_vnet_ip6_main
Definition: ip6.h:283
key
typedef key
Definition: ipsec_types.api:88
ip6_packet.h
vec_elt
#define vec_elt(v, i)
Get vector value at index i.
Definition: vec_bootstrap.h:210
ip6_destination_matches_route
static uword ip6_destination_matches_route(const ip6_main_t *im, const ip6_address_t *key, const ip6_address_t *dest, uword dest_length)
Definition: ip6.h:189
ip6_hbh_register_option
int ip6_hbh_register_option(u8 option, int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt), u8 *trace(u8 *s, ip6_hop_by_hop_option_t *opt))
Definition: ip6_forward.c:2731
fib_table_t_
A protocol Independent FIB table.
Definition: fib_table.h:71
ip6_add_del_interface_address
clib_error_t * ip6_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 is_del)
Definition: ip6_forward.c:297
ip_flow_hash.h
ip6_glean_node
vlib_node_registration_t ip6_glean_node
(constructor) VLIB_REGISTER_NODE (ip6_glean_node)
Definition: ip6_neighbor.c:268
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
ip6_fib_key_t::vrf_index
u32 vrf_index
Definition: ip6.h:58
ip6_add_del_interface_address_callback_t
Definition: ip6.h:94
ip6_main_t::v6_fibs
ip6_fib_t * v6_fibs
Definition: ip6.h:118
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
ip6_punt_policer_add_del
void ip6_punt_policer_add_del(u8 is_add, u32 policer_index)
Definition: ip6_punt_drop.c:186
ip6_main_t::add_del_interface_address_callbacks
ip6_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Definition: ip6.h:148
ip6_fib_key_t::dst_address_length
u32 dst_address_length
Definition: ip6.h:57
ip6_rewrite_node
vlib_node_registration_t ip6_rewrite_node
(constructor) VLIB_REGISTER_NODE (ip6_rewrite_node)
Definition: ip6_forward.c:2207
ip6_mfib_t::CLIB_CACHE_LINE_ALIGN_MARK
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
ip6_rewrite_mcast_node
vlib_node_registration_t ip6_rewrite_mcast_node
(constructor) VLIB_REGISTER_NODE (ip6_rewrite_mcast_node)
Definition: ip6_forward.c:2229
uword
u64 uword
Definition: types.h:112
tx_sw_if_index
vl_api_interface_index_t tx_sw_if_index
Definition: ip.api:548
ip6_address_compare
int ip6_address_compare(ip6_address_t *a1, ip6_address_t *a2)
Definition: ip46_cli.c:60
vlib_rx_or_tx_t
vlib_rx_or_tx_t
Definition: defs.h:44
ip6_main_t::table_bind_callbacks
ip6_table_bind_callback_t * table_bind_callbacks
Functions to call when interface to table biding changes.
Definition: ip6.h:151
ip6_main_t::mfibs
struct mfib_table_t_ * mfibs
Vector of MFIBs.
Definition: ip6.h:121
clib_mem_unaligned
#define clib_mem_unaligned(pointer, type)
Definition: types.h:155
ip6_main_t::mfib_index_by_table_id
uword * mfib_index_by_table_id
Hash table mapping table id to multicast fib index.
Definition: ip6.h:141
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
ip6_table_bind_callback_t::function_opaque
uword function_opaque
Definition: ip6.h:107
ip6_discover_neighbor_node
vlib_node_registration_t ip6_discover_neighbor_node
(constructor) VLIB_REGISTER_NODE (ip6_discover_neighbor_node)
Definition: ip6_neighbor.c:283
ip6_main_t::fib_index_by_sw_if_index
u32 * fib_index_by_sw_if_index
Definition: ip6.h:127
address
manual_print typedef address
Definition: ip_types.api:96
ip6_main_t::fibs
struct fib_table_t_ * fibs
Definition: ip6.h:115
ip6_fib_t
Definition: ip6.h:61
nh
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
ip6_rewrite_local_node
vlib_node_registration_t ip6_rewrite_local_node
ip6_fib_key_t
Definition: ip6.h:54
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
ip6_table_bind_callback_t
Definition: ip6.h:104
ip6_main_t::host_config
struct ip6_main_t::@383 host_config
ip46_address.h
ip6_mfib_t::index
u32 index
Definition: ip6.h:82
ip6_punt_redirect_add_paths
void ip6_punt_redirect_add_paths(u32 rx_sw_if_index, fib_route_path_t *paths)
Definition: ip6_punt_drop.c:329
ip6_input_node
vlib_node_registration_t ip6_input_node
(constructor) VLIB_REGISTER_NODE (ip6_input_node)
Definition: ip6_input.c:230
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
ip6_main_t::pad
u8 pad[3]
Definition: ip6.h:161
ip6_interface_first_address
ip6_address_t * ip6_interface_first_address(ip6_main_t *im, u32 sw_if_index)
get first IPv6 interface address
Definition: ip6_forward.c:278
ip6_udp_register_listener
uword ip6_udp_register_listener(vlib_main_t *vm, u16 dst_port, u32 next_node_index)
ip6_unregister_protocol
void ip6_unregister_protocol(u32 protocol)
Definition: ip6_forward.c:1691
serialize_vnet_ip6_main
serialize_function_t serialize_vnet_ip6_main
Definition: ip6.h:283
ip6_main_t::mfib_index_by_sw_if_index
u32 * mfib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip6.h:130
u32
unsigned int u32
Definition: types.h:88
options
static struct option options[]
Definition: main.c:52
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
ip6_main_t::fib_masks
ip6_address_t fib_masks[129]
Definition: ip6.h:124
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
ip6_add_del_interface_address_callback_t::function_opaque
uword function_opaque
Definition: ip6.h:97
ip6_destination_matches_interface
static uword ip6_destination_matches_interface(ip6_main_t *im, ip6_address_t *key, ip_interface_address_t *ia)
Definition: ip6.h:204
ip6_unaligned_destination_matches_route
static uword ip6_unaligned_destination_matches_route(ip6_main_t *im, ip6_address_t *key, ip6_address_t *dest, uword dest_length)
Definition: ip6.h:214
ip6_mfib_t
Definition: ip6.h:73
ip6_sw_interface_enable_disable
void ip6_sw_interface_enable_disable(u32 sw_if_index, u32 is_enable)
Definition: ip6_forward.c:239
ip6_hop_by_hop_main_t::next_override
uword next_override
Definition: ip6.h:310
ip6_main_t::lookup_main
ip_lookup_main_t lookup_main
Definition: ip6.h:112
ip6_add_del_interface_address_function_t
void() ip6_add_del_interface_address_function_t(struct ip6_main_t *im, uword opaque, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 if_address_index, u32 is_del)
Definition: ip6.h:88
ip6_main_t::ip_enabled_by_sw_if_index
u8 * ip_enabled_by_sw_if_index
Definition: ip6.h:133
ip6_header_t
Definition: ip6_packet.h:294
ip6_main_t
Definition: ip6.h:110
ip6_table_bind_function_t
void() ip6_table_bind_function_t(struct ip6_main_t *im, uword opaque, u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
Definition: ip6.h:101
ip6_hop_by_hop_main_t
Definition: ip6.h:304
ip_lookup_main_t
Definition: lookup.h:121
ip_interface.h
IP prefix management on interfaces.
ip6_fib_key_t::addr
ip6_address_t addr
Definition: ip6.h:56
vlib_main_t
Definition: main.h:102
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:544
ip
vl_api_address_t ip
Definition: l2.api:558
lookup.h
ip6_midchain_node
vlib_node_registration_t ip6_midchain_node
(constructor) VLIB_REGISTER_NODE (ip6_midchain_node)
Definition: ip6_forward.c:2199
vnet_set_ip6_classify_intfc
int vnet_set_ip6_classify_intfc(vlib_main_t *vm, u32 sw_if_index, u32 table_index)
Definition: ip6_forward.c:3018
ip6_register_protocol
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1679
ip6_hbh_unregister_option
int ip6_hbh_unregister_option(u8 option)
Definition: ip6_forward.c:2755
ip_interface_address_t
Definition: lookup.h:89
ip6_hbh_set_next_override
void ip6_hbh_set_next_override(uword next)
Definition: ip6_forward.c:2723
ip6_main_t::ttl
u8 ttl
Definition: ip6.h:159
vlib_node_runtime_t
Definition: node.h:454
ip6_main_t::hbh_enabled
u8 hbh_enabled
Definition: ip6.h:165
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2787
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
vlib_buffer_get_ip6_fib_index
static u32 vlib_buffer_get_ip6_fib_index(vlib_buffer_t *b)
Definition: ip6.h:325
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
ip6_forward_next_trace
void ip6_forward_next_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, vlib_rx_or_tx_t which_adj_index)
Definition: ip6_forward.c:1006
format_ip6_forward_next_trace
u8 * format_ip6_forward_next_trace(u8 *s, va_list *args)
Definition: ip6_forward.c:951
format_ip6_hop_by_hop_ext_hdr
u8 * format_ip6_hop_by_hop_ext_hdr(u8 *s, va_list *args)
Definition: ip6_forward.c:2291
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
ip6_main_t::fib_index_by_table_id
uword * fib_index_by_table_id
Definition: ip6.h:137