]> git.proxmox.com Git - mirror_frr.git/blob - zebra/interface.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / zebra / interface.h
1
2 /* Interface function header.
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_INTERFACE_H
23 #define _ZEBRA_INTERFACE_H
24
25 #include "redistribute.h"
26 #include "vrf.h"
27 #include "hook.h"
28 #include "bitfield.h"
29
30 #include "zebra/zebra_l2.h"
31 #include "zebra/zebra_l2_bridge_if.h"
32 #include "zebra/zebra_nhg_private.h"
33 #include "zebra/zebra_router.h"
34 #include "zebra/rtadv.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /* For interface configuration. */
41 #define IF_ZEBRA_DATA_UNSPEC 0
42 #define IF_ZEBRA_DATA_ON 1
43 #define IF_ZEBRA_DATA_OFF 2
44
45 #define IF_VLAN_BITMAP_MAX 4096
46
47 /* Zebra interface type - ones of interest. */
48 enum zebra_iftype {
49 ZEBRA_IF_OTHER = 0, /* Anything else */
50 ZEBRA_IF_VXLAN, /* VxLAN interface */
51 ZEBRA_IF_VRF, /* VRF device */
52 ZEBRA_IF_BRIDGE, /* bridge device */
53 ZEBRA_IF_VLAN, /* VLAN sub-interface */
54 ZEBRA_IF_MACVLAN, /* MAC VLAN interface*/
55 ZEBRA_IF_VETH, /* VETH interface*/
56 ZEBRA_IF_BOND, /* Bond */
57 ZEBRA_IF_BOND_SLAVE, /* Bond */
58 ZEBRA_IF_GRE, /* GRE interface */
59 };
60
61 /* Zebra "slave" interface type */
62 enum zebra_slave_iftype {
63 ZEBRA_IF_SLAVE_NONE, /* Not a slave */
64 ZEBRA_IF_SLAVE_VRF, /* Member of a VRF */
65 ZEBRA_IF_SLAVE_BRIDGE, /* Member of a bridge */
66 ZEBRA_IF_SLAVE_BOND, /* Bond member */
67 ZEBRA_IF_SLAVE_OTHER, /* Something else - e.g., bond slave */
68 };
69
70 struct irdp_interface;
71
72 /* Ethernet segment info used for setting up EVPN multihoming */
73 struct zebra_evpn_es;
74 struct zebra_es_if_info {
75 /* type-3 esi config */
76 struct ethaddr sysmac;
77 uint32_t lid; /* local-id; has to be unique per-ES-sysmac */
78
79 esi_t esi;
80
81 uint16_t df_pref;
82 uint8_t flags;
83 #define ZIF_CFG_ES_FLAG_BYPASS (1 << 0)
84
85 struct zebra_evpn_es *es; /* local ES */
86 };
87
88 enum zebra_if_flags {
89 /* device has been configured as an uplink for
90 * EVPN multihoming
91 */
92 ZIF_FLAG_EVPN_MH_UPLINK = (1 << 0),
93 ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP = (1 << 1),
94
95 /* Dataplane protodown-on */
96 ZIF_FLAG_PROTODOWN = (1 << 2),
97 /* Dataplane protodown-on Queued to the dplane */
98 ZIF_FLAG_SET_PROTODOWN = (1 << 3),
99 /* Dataplane protodown-off Queued to the dplane */
100 ZIF_FLAG_UNSET_PROTODOWN = (1 << 4),
101
102 /* LACP bypass state is set by the dataplane on a bond member
103 * and inherited by the bond (if one or more bond members are in
104 * a bypass state the bond is placed in a bypass state)
105 */
106 ZIF_FLAG_LACP_BYPASS = (1 << 5)
107 };
108
109 #define ZEBRA_IF_IS_PROTODOWN(zif) ((zif)->flags & ZIF_FLAG_PROTODOWN)
110 #define ZEBRA_IF_IS_PROTODOWN_ONLY_EXTERNAL(zif) \
111 ((zif)->protodown_rc == ZEBRA_PROTODOWN_EXTERNAL)
112
113 /* Mem type for zif desc */
114 DECLARE_MTYPE(ZIF_DESC);
115
116 /* `zebra' daemon local interface structure. */
117 struct zebra_if {
118 /* back pointer to the interface */
119 struct interface *ifp;
120
121 enum zebra_if_flags flags;
122
123 /* Shutdown configuration. */
124 uint8_t shutdown;
125
126 /* Multicast configuration. */
127 uint8_t multicast;
128
129 /* MPLS status. */
130 bool mpls;
131
132 /* Linkdown status */
133 bool linkdown, linkdownv6;
134
135 /* Is Multicast Forwarding on? */
136 bool v4mcast_on, v6mcast_on;
137
138 /* Router advertise configuration. */
139 uint8_t rtadv_enable;
140
141 /* Installed addresses chains tree. */
142 struct route_table *ipv4_subnets;
143
144 /* Nexthops pointing to this interface */
145 /**
146 * Any nexthop that we get should have an
147 * interface. When an interface goes down,
148 * we will use this list to update the nexthops
149 * pointing to it with that info.
150 */
151 struct nhg_connected_tree_head nhg_dependents;
152
153 /* Information about up/down changes */
154 unsigned int up_count;
155 char up_last[FRR_TIMESTAMP_LEN];
156 unsigned int down_count;
157 char down_last[FRR_TIMESTAMP_LEN];
158
159 struct rtadvconf rtadv;
160 unsigned int ra_sent, ra_rcvd;
161
162 struct irdp_interface *irdp;
163
164 #ifdef HAVE_STRUCT_SOCKADDR_DL
165 union {
166 /* note that sdl_storage is never accessed, it only exists to
167 * make space.
168 * all actual uses refer to sdl - but use sizeof(sdl_storage)!
169 * this fits
170 * best with C aliasing rules. */
171 struct sockaddr_dl sdl;
172 struct sockaddr_storage sdl_storage;
173 };
174 #endif
175
176 /* ptm enable configuration */
177 uint8_t ptm_enable;
178
179 /* Zebra interface and "slave" interface type */
180 enum zebra_iftype zif_type;
181 enum zebra_slave_iftype zif_slave_type;
182
183 /* Additional L2 info, depends on zif_type */
184 union zebra_l2if_info l2info;
185
186 /* For members of a bridge, link to bridge. */
187 /* Note: If additional fields become necessary, this can be modified to
188 * be a pointer to a dynamically allocd struct.
189 */
190 struct zebra_l2info_brslave brslave_info;
191
192 struct zebra_l2info_bondslave bondslave_info;
193 struct zebra_l2info_bond bond_info;
194
195 /* ethernet segment */
196 struct zebra_es_if_info es_info;
197
198 /* bitmap of vlans associated with this interface */
199 bitfield_t vlan_bitmap;
200
201 /* An interface can be error-disabled if a protocol (such as EVPN or
202 * VRRP) detects a problem with keeping it operationally-up.
203 * If any of the protodown bits are set protodown-on is programmed
204 * in the dataplane. This results in a carrier/L1 down on the
205 * physical device.
206 */
207 uint32_t protodown_rc;
208
209 /* list of zebra_mac entries using this interface as destination */
210 struct list *mac_list;
211
212 /* Link fields - for sub-interfaces. */
213 ifindex_t link_ifindex;
214 struct interface *link;
215
216 uint8_t speed_update_count;
217 struct thread *speed_update;
218
219 /*
220 * Does this interface have a v6 to v4 ll neighbor entry
221 * for bgp unnumbered?
222 */
223 bool v6_2_v4_ll_neigh_entry;
224 char neigh_mac[6];
225 struct in6_addr v6_2_v4_ll_addr6;
226
227 /* The description of the interface */
228 char *desc;
229 };
230
231 DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
232 (vty, ifp));
233 DECLARE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
234 (vty, ifp));
235
236 #define IS_ZEBRA_IF_VRF(ifp) \
237 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VRF)
238
239 #define IS_ZEBRA_IF_BRIDGE(ifp) \
240 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BRIDGE)
241
242 #define IS_ZEBRA_IF_VLAN(ifp) \
243 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VLAN)
244
245 #define IS_ZEBRA_IF_VXLAN(ifp) \
246 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VXLAN)
247
248 #define IS_ZEBRA_IF_MACVLAN(ifp) \
249 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_MACVLAN)
250
251 #define IS_ZEBRA_IF_VETH(ifp) \
252 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VETH)
253
254 #define IS_ZEBRA_IF_BOND(ifp) \
255 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BOND)
256
257 #define IS_ZEBRA_IF_GRE(ifp) \
258 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_GRE)
259
260 #define IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) \
261 (((struct zebra_if *)(ifp->info))->zif_slave_type \
262 == ZEBRA_IF_SLAVE_BRIDGE)
263
264 #define IS_ZEBRA_IF_VRF_SLAVE(ifp) \
265 (((struct zebra_if *)(ifp->info))->zif_slave_type == ZEBRA_IF_SLAVE_VRF)
266
267 #define IS_ZEBRA_IF_BOND_SLAVE(ifp) \
268 (((struct zebra_if *)(ifp->info))->zif_slave_type \
269 == ZEBRA_IF_SLAVE_BOND)
270
271 extern void zebra_if_init(void);
272
273 extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, uint32_t);
274 extern struct interface *if_lookup_by_name_per_ns(struct zebra_ns *,
275 const char *);
276 extern struct interface *if_link_per_ns(struct zebra_ns *, struct interface *);
277 extern const char *ifindex2ifname_per_ns(struct zebra_ns *, unsigned int);
278
279 extern void if_unlink_per_ns(struct interface *);
280 extern void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *fip,
281 char mac[6],
282 struct in6_addr *address,
283 int add);
284 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp,
285 struct in6_addr *address,
286 int add);
287 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp);
288 extern void if_delete_update(struct interface **ifp);
289 extern void if_add_update(struct interface *ifp);
290 extern void if_up(struct interface *ifp, bool install_connected);
291 extern void if_down(struct interface *);
292 extern void if_refresh(struct interface *);
293 extern void if_flags_update(struct interface *, uint64_t);
294 extern int if_subnet_add(struct interface *, struct connected *);
295 extern int if_subnet_delete(struct interface *, struct connected *);
296 extern int ipv6_address_configured(struct interface *ifp);
297 extern void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id);
298 extern void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
299 ns_id_t ns_id);
300 extern void zebra_if_update_all_links(struct zebra_ns *zns);
301 /**
302 * Directly update entire protodown & reason code bitfield.
303 */
304 extern int zebra_if_update_protodown_rc(struct interface *ifp, bool new_down,
305 uint32_t new_protodown_rc);
306
307 extern void cli_show_legacy_admin_group(struct vty *vty,
308 const struct lyd_node *dnode,
309 bool show_defaults);
310 extern void cli_show_affinity_mode(struct vty *vty,
311 const struct lyd_node *dnode,
312 bool show_defaults);
313 extern void cli_show_affinity(struct vty *vty, const struct lyd_node *dnode,
314 bool show_defaults);
315
316 /**
317 * Set protodown with single reason.
318 */
319 extern int zebra_if_set_protodown(struct interface *ifp, bool down,
320 enum protodown_reasons new_reason);
321 extern int if_ip_address_install(struct interface *ifp, struct prefix *prefix,
322 const char *label, struct prefix *pp);
323 extern int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix,
324 const char *label);
325 extern int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix);
326 extern int if_shutdown(struct interface *ifp);
327 extern int if_no_shutdown(struct interface *ifp);
328 extern int if_multicast_set(struct interface *ifp);
329 extern int if_multicast_unset(struct interface *ifp);
330 extern int if_linkdetect(struct interface *ifp, bool detect);
331 extern void if_addr_wakeup(struct interface *ifp);
332
333 /* Nexthop group connected functions */
334 extern void if_nhg_dependents_add(struct interface *ifp,
335 struct nhg_hash_entry *nhe);
336 extern void if_nhg_dependents_del(struct interface *ifp,
337 struct nhg_hash_entry *nhe);
338 extern unsigned int if_nhg_dependents_count(const struct interface *ifp);
339 extern bool if_nhg_dependents_is_empty(const struct interface *ifp);
340
341 extern void vrf_add_update(struct vrf *vrfp);
342 extern void zebra_l2_map_slave_to_bond(struct zebra_if *zif, vrf_id_t vrf);
343 extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif);
344 extern const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf,
345 uint32_t pd_buf_len);
346 void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx);
347
348 #ifdef HAVE_PROC_NET_DEV
349 extern void ifstat_update_proc(void);
350 #endif /* HAVE_PROC_NET_DEV */
351 #ifdef HAVE_NET_RT_IFLIST
352 extern void ifstat_update_sysctl(void);
353
354 #endif /* HAVE_NET_RT_IFLIST */
355 #ifdef HAVE_PROC_NET_DEV
356 extern int interface_list_proc(void);
357 #endif /* HAVE_PROC_NET_DEV */
358 #ifdef HAVE_PROC_NET_IF_INET6
359 extern int ifaddr_proc_ipv6(void);
360 #endif /* HAVE_PROC_NET_IF_INET6 */
361
362 #ifdef __cplusplus
363 }
364 #endif
365
366 #endif /* _ZEBRA_INTERFACE_H */