blob: f0474c1bf9a38701c874760645265c78b0df3dd9 [file] [log] [blame]
Neale Ranns59f71132020-04-08 12:19:38 +00001/*
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
26clib_error_t *ip_interface_address_add (ip_lookup_main_t * lm,
27 u32 sw_if_index,
28 void *address,
29 u32 address_length,
30 u32 * result_index);
yedgdbd366b2020-05-14 10:51:53 +080031clib_error_t *ip_interface_address_del (ip_lookup_main_t * lm,
32 vnet_main_t * vnm,
33 u32 addr_index, void *address,
34 u32 address_length, u32 sw_if_index);
Neale Ranns59f71132020-04-08 12:19:38 +000035void *ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4);
36void ip_interface_address_mark (void);
37void ip_interface_address_sweep (void);
38u32 ip_interface_address_find (ip_lookup_main_t * lm,
39 void *addr_fib, u32 address_length);
40u8 ip_interface_has_address (u32 sw_if_index, ip46_address_t * ip, u8 is_ip4);
Stanislav Zaikin3bad8b62022-04-25 19:11:36 +020041walk_rc_t ip_interface_address_mark_one_interface (vnet_main_t *vnm,
42 vnet_sw_interface_t *si,
43 void *ctx);
Neale Ranns59f71132020-04-08 12:19:38 +000044
45always_inline void *
46ip_interface_address_get_address (ip_lookup_main_t * lm,
47 ip_interface_address_t * a)
48{
49 return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key);
50}
51
52always_inline ip_interface_prefix_t *
53ip_get_interface_prefix (ip_lookup_main_t * lm, ip_interface_prefix_key_t * k)
54{
55 uword *p = mhash_get (&lm->prefix_to_if_prefix_index, k);
56 return p ? pool_elt_at_index (lm->if_prefix_pool, p[0]) : 0;
57}
58
59/* *INDENT-OFF* */
60#define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \
61do { \
62 vnet_main_t *_vnm = vnet_get_main(); \
63 u32 _sw_if_index = sw_if_index; \
64 vnet_sw_interface_t *_swif; \
65 _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \
66 \
67 /* \
68 * Loop => honor unnumbered interface addressing. \
69 */ \
70 if (_swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \
71 { \
72 if (loop) \
73 _sw_if_index = _swif->unnumbered_sw_if_index; \
74 else \
75 /* the interface is unnumbered, by the caller does not want \
76 * unnumbered interfaces considered/honoured */ \
77 break; \
78 } \
79 u32 _ia = ((vec_len((lm)->if_address_pool_index_by_sw_if_index) \
80 > (_sw_if_index)) ? \
81 vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \
82 (_sw_if_index)) : \
83 (u32)~0); \
84 ip_interface_address_t * _a; \
85 while (_ia != ~0) \
86 { \
87 _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \
88 _ia = _a->next_this_sw_interface; \
89 (a) = _a; \
90 body; \
91 } \
92} while (0)
93/* *INDENT-ON* */
94
95#endif /* included_ip_interface_h */
96
97/*
98 * fd.io coding-style-patch-verification: ON
99 *
100 * Local Variables:
101 * eval: (c-set-style "gnu")
102 * End:
103 */