FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ip_interface.h
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  * @file
18  * @brief IP prefix management on interfaces
19  */
20 
21 #ifndef included_ip_interface_h
22 #define included_ip_interface_h
23 
24 #include <vnet/ip/lookup.h>
25 
28  void *address,
29  u32 address_length,
30  u32 * result_index);
32  vnet_main_t * vnm,
33  u32 addr_index, void *address,
34  u32 address_length, u32 sw_if_index);
36 void ip_interface_address_mark (void);
37 void ip_interface_address_sweep (void);
39  void *addr_fib, u32 address_length);
40 u8 ip_interface_has_address (u32 sw_if_index, ip46_address_t * ip, u8 is_ip4);
41 
42 always_inline void *
45 {
46  return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key);
47 }
48 
51 {
53  return p ? pool_elt_at_index (lm->if_prefix_pool, p[0]) : 0;
54 }
55 
56 /* *INDENT-OFF* */
57 #define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
58 do { \
59  vnet_main_t *_vnm = vnet_get_main(); \
60  u32 _sw_if_index = sw_if_index; \
61  vnet_sw_interface_t *_swif; \
62  _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \
63  \
64  /* \
65  * Loop => honor unnumbered interface addressing. \
66  */ \
67  if (_swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \
68  { \
69  if (loop) \
70  _sw_if_index = _swif->unnumbered_sw_if_index; \
71  else \
72  /* the interface is unnumbered, by the caller does not want \
73  * unnumbered interfaces considered/honoured */ \
74  break; \
75  } \
76  u32 _ia = ((vec_len((lm)->if_address_pool_index_by_sw_if_index) \
77  > (_sw_if_index)) ? \
78  vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \
79  (_sw_if_index)) : \
80  (u32)~0); \
81  ip_interface_address_t * _a; \
82  while (_ia != ~0) \
83  { \
84  _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \
85  _ia = _a->next_this_sw_interface; \
86  (a) = _a; \
87  body; \
88  } \
89 } while (0)
90 /* *INDENT-ON* */
91 
92 #endif /* included_ip_interface_h */
93 
94 /*
95  * fd.io coding-style-patch-verification: ON
96  *
97  * Local Variables:
98  * eval: (c-set-style "gnu")
99  * End:
100  */
ip_lookup_main_t::if_prefix_pool
ip_interface_prefix_t * if_prefix_pool
Pool of prefixes containing addresses assigned to interfaces.
Definition: lookup.h:134
ip_lookup_main_t::prefix_to_if_prefix_index
mhash_t prefix_to_if_prefix_index
Hash table mapping prefix to index in interface prefix pool.
Definition: lookup.h:137
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
ip_interface_address_mark
void ip_interface_address_mark(void)
Definition: ip_interface.c:229
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
mhash_key_to_mem
static void * mhash_key_to_mem(mhash_t *h, uword key)
Definition: mhash.h:90
mhash_get
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
ip_interface_prefix_t
Definition: lookup.h:77
ip_interface_address_del
clib_error_t * ip_interface_address_del(ip_lookup_main_t *lm, vnet_main_t *vnm, u32 addr_index, void *address, u32 address_length, u32 sw_if_index)
Definition: ip_interface.c:94
ip_lookup_main_t::address_to_if_address_index
mhash_t address_to_if_address_index
Hash table mapping address to index in interface address pool.
Definition: lookup.h:127
ip_interface_address_add
clib_error_t * ip_interface_address_add(ip_lookup_main_t *lm, u32 sw_if_index, void *address, u32 address_length, u32 *result_index)
Definition: ip_interface.c:36
uword
u64 uword
Definition: types.h:112
ip_get_interface_prefix
static ip_interface_prefix_t * ip_get_interface_prefix(ip_lookup_main_t *lm, ip_interface_prefix_key_t *k)
Definition: ip_interface.h:50
address
manual_print typedef address
Definition: ip_types.api:96
ip_interface_prefix_key_t
Definition: lookup.h:70
ip_interface_address_find
u32 ip_interface_address_find(ip_lookup_main_t *lm, void *addr_fib, u32 address_length)
Definition: ip_interface.c:24
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
u32
unsigned int u32
Definition: types.h:88
ip_interface_get_first_ip
void * ip_interface_get_first_ip(u32 sw_if_index, u8 is_ip4)
Definition: ip_interface.c:174
ip_lookup_main_t
Definition: lookup.h:121
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
a
a
Definition: bitmap.h:525
ip
vl_api_address_t ip
Definition: l2.api:558
lookup.h
ip_interface_address_sweep
void ip_interface_address_sweep(void)
Definition: ip_interface.c:289
ip_interface_address_t
Definition: lookup.h:89
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip_interface_has_address
u8 ip_interface_has_address(u32 sw_if_index, ip46_address_t *ip, u8 is_ip4)
Definition: ip_interface.c:140