FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
fib_sas.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 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 /**
17  * @brief FIB Source Address selection
18  *
19  * Use the FIB for source address selection on an interface
20  */
21 
22 #include <vnet/fib/fib_sas.h>
23 #include <vnet/adj/adj_glean.h>
24 #include <vnet/ip/ip6_link.h>
25 
26 
27 bool
30  const ip46_address_t *dst,
31  ip46_address_t *src)
32 {
33  switch (af)
34  {
35  case AF_IP4:
36  if (dst)
37  return (fib_sas4_get(sw_if_index, &dst->ip4, &src->ip4));
38  else
39  return (fib_sas4_get(sw_if_index, NULL, &src->ip4));
40  case AF_IP6:
41  if (dst)
42  return (fib_sas6_get(sw_if_index, &dst->ip6, &src->ip6));
43  else
44  return (fib_sas6_get(sw_if_index, NULL, &src->ip6));
45  }
46  return (false);
47 }
48 
49 bool
51  const ip4_address_t *dst,
53 {
54  ip46_address_t d_tmp, *d_tmpp = NULL;
55  const ip46_address_t *s_tmp;
57 
58  if (dst)
59  {
60  d_tmpp = &d_tmp;
61  d_tmp.ip4 = *dst;
62  }
63 
64  /*
65  * If the interface is unnumbered then use the IP interface
66  */
68 
70  sw_if_index = swif->unnumbered_sw_if_index;
71 
72  /*
73  * get the source address from the glean adjacency
74  */
76 
77  if (NULL != s_tmp)
78  {
79  src->as_u32 = s_tmp->ip4.as_u32;
80  return (true);
81  }
82 
83  return (false);
84 }
85 
86 bool
88  const ip6_address_t *dst,
89  ip6_address_t *src)
90 {
91  ip46_address_t d_tmp, *d_tmpp = NULL;
92  const ip46_address_t *s_tmp;
93 
94  if (dst)
95  {
96  d_tmpp = &d_tmp;
97  d_tmp.ip6 = *dst;
98  }
99 
100  /*
101  * if the dst is v6 and link local, use the source link local
102  */
104  {
106  return (true);
107  }
108 
109  /*
110  * get the source address from the glean adjacency
111  */
113 
114  if (NULL != s_tmp)
115  {
116  ip6_address_copy(src, &s_tmp->ip6);
117  return (true);
118  }
119 
120  return (false);
121 }
ip6_address_is_link_local_unicast
static uword ip6_address_is_link_local_unicast(const ip6_address_t *a)
Definition: ip6_packet.h:253
adj_glean_get_src
const ip46_address_t * adj_glean_get_src(fib_protocol_t proto, u32 sw_if_index, const ip46_address_t *nh)
Return the source address from the glean.
Definition: adj_glean.c:257
vnet_sw_interface_t
Definition: interface.h:868
AF_IP4
@ AF_IP4
Definition: ip_types.h:23
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
VNET_SW_INTERFACE_FLAG_UNNUMBERED
@ VNET_SW_INTERFACE_FLAG_UNNUMBERED
Definition: interface.h:850
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
fib_sas6_get
bool fib_sas6_get(u32 sw_if_index, const ip6_address_t *dst, ip6_address_t *src)
Get an IPv6 Source address to use in a packet being sent out an interface.
Definition: fib_sas.c:87
ip6_address_copy
static void ip6_address_copy(ip6_address_t *dst, const ip6_address_t *src)
Definition: ip6_packet.h:127
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
fib_sas.h
fib_sas4_get
bool fib_sas4_get(u32 sw_if_index, const ip4_address_t *dst, ip4_address_t *src)
Get an IPv4 Source address to use in a packet being sent out an interface.
Definition: fib_sas.c:50
u32
unsigned int u32
Definition: types.h:88
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
AF_IP6
@ AF_IP6
Definition: ip_types.h:24
adj_glean.h
fib_sas_get
bool fib_sas_get(u32 sw_if_index, ip_address_family_t af, const ip46_address_t *dst, ip46_address_t *src)
FIB Source Address selection.
Definition: fib_sas.c:28
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip_address_family_t
enum ip_address_family_t_ ip_address_family_t
swif
u32 swif
Definition: interface_output.c:1078