FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ip6_nd_inline.h
Go to the documentation of this file.
1 /*
2  *
3  * ip6_nd_inline.h: ip6 neighbor discovery inline
4  *
5  * Copyright (c) 2021 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __IP6_ND_INLINE_H__
20 #define __IP6_ND_INLINE_H__
21 
22 #include <vnet/ethernet/ethernet.h>
23 #include <vnet/ip/icmp46_packet.h>
24 #include <vnet/ip/ip6.h>
25 
26 typedef enum
27 {
32 
36  icmp6_neighbor_solicitation_or_advertisement_header_t *icmp6_nsa,
37  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
38  *icmp6_nd_ell_addr,
39  u32 sw_if_index0)
40 {
41  vnet_main_t *vnm = vnet_get_main ();
42  vnet_sw_interface_t *sw_if;
43  ethernet_interface_t *eth_if;
44  ethernet_header_t *eth;
45  int bogus_length;
46 
47  /* dst address is either source address or the all-nodes mcast addr */
49  ip6_h->dst_address = ip6_h->src_address;
50  else
52  IP6_MULTICAST_SCOPE_link_local,
53  IP6_MULTICAST_GROUP_ID_all_hosts);
54 
55  ip6_h->src_address = icmp6_nsa->target_address;
56  ip6_h->hop_limit = 255;
57  icmp6_nsa->icmp.type = ICMP6_neighbor_advertisement;
58 
59  sw_if = vnet_get_sup_sw_interface (vnm, sw_if_index0);
62  if (eth_if && icmp6_nd_ell_addr)
63  {
64  clib_memcpy (icmp6_nd_ell_addr->ethernet_address, &eth_if->address, 6);
65  icmp6_nd_ell_addr->header.type =
66  ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address;
67  }
68 
69  icmp6_nsa->advertisement_flags =
70  clib_host_to_net_u32 (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
72 
73  icmp6_nsa->icmp.checksum = 0;
74  icmp6_nsa->icmp.checksum =
75  ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6_h, &bogus_length);
76  ASSERT (bogus_length == 0);
77 
78  /* Reuse current MAC header, copy SMAC to DMAC and
79  * interface MAC to SMAC */
81  eth = vlib_buffer_get_current (b);
82  clib_memcpy (eth->dst_address, eth->src_address, 6);
83  if (eth_if)
84  clib_memcpy (eth->src_address, &eth_if->address, 6);
85 
86  /* Setup input and output sw_if_index for packet */
87  ASSERT (vnet_buffer (b)->sw_if_index[VLIB_RX] == sw_if_index0);
88  vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index0;
89  vnet_buffer (b)->sw_if_index[VLIB_RX] =
91 }
92 
93 #endif /* included_ip6_nd_inline_h */
94 
95 /*
96  * fd.io coding-style-patch-verification: ON
97  *
98  * Local Variables:
99  * eval: (c-set-style "gnu")
100  * End:
101  */
vnet_sw_interface_t::type
vnet_sw_interface_type_t type
Definition: interface.h:871
ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE
vnet_sw_interface_t
Definition: interface.h:869
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:1096
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
icmp6_neighbor_solicitation_or_advertisement_next_t
icmp6_neighbor_solicitation_or_advertisement_next_t
Definition: ip6_nd_inline.h:26
ethernet_header_t::dst_address
u8 dst_address[6]
Definition: packet.h:55
ethernet_header_t::src_address
u8 src_address[6]
Definition: packet.h:56
ip6_header_t::hop_limit
u8 hop_limit
Definition: ip6_packet.h:307
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
ip6_address_is_unspecified
static uword ip6_address_is_unspecified(const ip6_address_t *a)
Definition: ip6_packet.h:237
ethernet.h
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
static_always_inline
#define static_always_inline
Definition: clib.h:112
ethernet_buffer_header_size
#define ethernet_buffer_header_size(b)
Determine the size of the Ethernet headers of the current frame in the buffer.
Definition: ethernet.h:453
ethernet_header_t
Definition: packet.h:52
ethernet_interface
Definition: ethernet.h:146
ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY
@ ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY
Definition: ip6_nd_inline.h:29
ip6_header_t::dst_address
ip6_address_t dst_address
Definition: ip6_packet.h:310
ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
#define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED
ethernet_get_interface
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
Definition: interface.c:982
icmp6_send_neighbor_advertisement
static_always_inline void icmp6_send_neighbor_advertisement(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_h, icmp6_neighbor_solicitation_or_advertisement_header_t *icmp6_nsa, icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *icmp6_nd_ell_addr, u32 sw_if_index0)
Definition: ip6_nd_inline.h:34
ip6_set_reserved_multicast_address
static void ip6_set_reserved_multicast_address(ip6_address_t *a, ip6_multicast_address_scope_t scope, u16 id)
Definition: ip6_packet.h:134
vnet_main_t
Definition: vnet.h:76
vnet_main_t::local_interface_sw_if_index
u32 local_interface_sw_if_index
Definition: vnet.h:79
ethernet_main
ethernet_main_t ethernet_main
Definition: init.c:45
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
ICMP6_NEIGHBOR_SOLICITATION_N_NEXT
@ ICMP6_NEIGHBOR_SOLICITATION_N_NEXT
Definition: ip6_nd_inline.h:30
ip6_header_t
Definition: ip6_packet.h:294
vnet_main
vnet_main_t vnet_main
Definition: misc.c:43
ip6_header_t::src_address
ip6_address_t src_address
Definition: ip6_packet.h:310
vlib_main_t
Definition: main.h:102
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
icmp46_packet.h
vnet_sw_interface_t::hw_if_index
u32 hw_if_index
Definition: interface.h:887
VNET_SW_INTERFACE_TYPE_HARDWARE
@ VNET_SW_INTERFACE_TYPE_HARDWARE
Definition: interface.h:764
vnet_get_sup_sw_interface
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:81
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip6.h
ethernet_interface::address
ethernet_interface_address_t address
Definition: ethernet.h:173
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
@ ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP
Definition: ip6_nd_inline.h:28
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111