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