]> git.proxmox.com Git - mirror_frr.git/blame - zebra/interface.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / zebra / interface.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
b9368db9 2
718e3744 3/* Interface function header.
4 * Copyright (C) 1999 Kunihiro Ishiguro
718e3744 5 */
6
5b73a671 7#ifndef _ZEBRA_INTERFACE_H
8#define _ZEBRA_INTERFACE_H
9
10#include "redistribute.h"
12f6fb97 11#include "vrf.h"
2eb27eec 12#include "hook.h"
ce5160c0 13#include "bitfield.h"
ca776988 14
6675513d 15#include "zebra/zebra_l2.h"
efde4f25 16#include "zebra/zebra_l2_bridge_if.h"
5948f013 17#include "zebra/zebra_nhg_private.h"
c36e442c 18#include "zebra/zebra_router.h"
7ca9c407 19#include "zebra/rtadv.h"
6675513d 20
51e94aa7
EDP
21#ifdef __cplusplus
22extern "C" {
23#endif
24
e63831f1
DS
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
718e3744 29
ce5160c0
AK
30#define IF_VLAN_BITMAP_MAX 4096
31
6675513d 32/* Zebra interface type - ones of interest. */
e6f2bec0 33enum zebra_iftype {
7a38782a
DL
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*/
0e4864ea 40 ZEBRA_IF_VETH, /* VETH interface*/
b9368db9
DD
41 ZEBRA_IF_BOND, /* Bond */
42 ZEBRA_IF_BOND_SLAVE, /* Bond */
077c07cc 43 ZEBRA_IF_GRE, /* GRE interface */
e6f2bec0 44};
6675513d 45
46/* Zebra "slave" interface type */
a81982fa 47enum zebra_slave_iftype {
d62a17ae 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 */
b9368db9 51 ZEBRA_IF_SLAVE_BOND, /* Bond member */
d62a17ae 52 ZEBRA_IF_SLAVE_OTHER, /* Something else - e.g., bond slave */
a81982fa 53};
6675513d 54
2eb27eec
DL
55struct irdp_interface;
56
ce5160c0
AK
57/* Ethernet segment info used for setting up EVPN multihoming */
58struct zebra_evpn_es;
59struct zebra_es_if_info {
325d694b 60 /* type-3 esi config */
ce5160c0
AK
61 struct ethaddr sysmac;
62 uint32_t lid; /* local-id; has to be unique per-ES-sysmac */
325d694b
AK
63
64 esi_t esi;
65
1103c5c6 66 uint16_t df_pref;
00a7710c
AK
67 uint8_t flags;
68#define ZIF_CFG_ES_FLAG_BYPASS (1 << 0)
69
ce5160c0
AK
70 struct zebra_evpn_es *es; /* local ES */
71};
72
c36e442c
AK
73enum 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 */
00a7710c 81 ZIF_FLAG_PROTODOWN = (1 << 2),
71ef5cbb
SW
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),
00a7710c
AK
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 */
71ef5cbb 91 ZIF_FLAG_LACP_BYPASS = (1 << 5)
c36e442c
AK
92};
93
ddfea8a2 94#define ZEBRA_IF_IS_PROTODOWN(zif) ((zif)->flags & ZIF_FLAG_PROTODOWN)
0dcd8506 95#define ZEBRA_IF_IS_PROTODOWN_ONLY_EXTERNAL(zif) \
ddfea8a2 96 ((zif)->protodown_rc == ZEBRA_PROTODOWN_EXTERNAL)
0dcd8506 97
c0ce4875
MS
98/* Mem type for zif desc */
99DECLARE_MTYPE(ZIF_DESC);
100
718e3744 101/* `zebra' daemon local interface structure. */
d62a17ae 102struct zebra_if {
ce5160c0
AK
103 /* back pointer to the interface */
104 struct interface *ifp;
105
c36e442c
AK
106 enum zebra_if_flags flags;
107
d62a17ae 108 /* Shutdown configuration. */
d7c0a89a 109 uint8_t shutdown;
718e3744 110
d62a17ae 111 /* Multicast configuration. */
d7c0a89a 112 uint8_t multicast;
718e3744 113
b6beb700
MS
114 /* MPLS status. */
115 bool mpls;
116
3689905d 117 /* Linkdown status */
d53dc9bd 118 bool linkdown, linkdownv6;
3689905d 119
4c84aa5e 120 /* Is Multicast Forwarding on? */
d53dc9bd 121 bool v4mcast_on, v6mcast_on;
4c84aa5e 122
d62a17ae 123 /* Router advertise configuration. */
d7c0a89a 124 uint8_t rtadv_enable;
718e3744 125
d62a17ae 126 /* Installed addresses chains tree. */
127 struct route_table *ipv4_subnets;
eef1fe11 128
fe593b78 129 /* Nexthops pointing to this interface */
602fea61
SW
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 */
37c6708b 136 struct nhg_connected_tree_head nhg_dependents;
602fea61 137
d62a17ae 138 /* Information about up/down changes */
139 unsigned int up_count;
e36f61b5 140 char up_last[FRR_TIMESTAMP_LEN];
d62a17ae 141 unsigned int down_count;
e36f61b5 142 char down_last[FRR_TIMESTAMP_LEN];
55ce4d3a 143
d62a17ae 144 struct rtadvconf rtadv;
145 unsigned int ra_sent, ra_rcvd;
ca776988 146
2eb27eec 147 struct irdp_interface *irdp;
ca776988 148
8ccc7e80 149#ifdef HAVE_STRUCT_SOCKADDR_DL
d62a17ae 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 };
8ccc7e80
TT
159#endif
160
d62a17ae 161 /* ptm enable configuration */
d7c0a89a 162 uint8_t ptm_enable;
6675513d 163
d62a17ae 164 /* Zebra interface and "slave" interface type */
e6f2bec0 165 enum zebra_iftype zif_type;
a81982fa 166 enum zebra_slave_iftype zif_slave_type;
6675513d 167
d62a17ae 168 /* Additional L2 info, depends on zif_type */
169 union zebra_l2if_info l2info;
6675513d 170
d62a17ae 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;
6675513d 176
b9368db9 177 struct zebra_l2info_bondslave bondslave_info;
c36e442c 178 struct zebra_l2info_bond bond_info;
b9368db9 179
ce5160c0
AK
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
c36e442c
AK
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 */
5d414138 192 uint32_t protodown_rc;
c36e442c 193
8b07f173
AK
194 /* list of zebra_mac entries using this interface as destination */
195 struct list *mac_list;
196
d62a17ae 197 /* Link fields - for sub-interfaces. */
198 ifindex_t link_ifindex;
199 struct interface *link;
dc7b3cae 200
fbc83b9a 201 uint8_t speed_update_count;
dc7b3cae 202 struct thread *speed_update;
20089ae2
DS
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;
ee98d1f1 209 char neigh_mac[6];
20089ae2 210 struct in6_addr v6_2_v4_ll_addr6;
ba5165ec
DS
211
212 /* The description of the interface */
213 char *desc;
718e3744 214};
215
996c9314 216DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
8451921b 217 (vty, ifp));
996c9314 218DECLARE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp),
8451921b 219 (vty, ifp));
2eb27eec 220
d62a17ae 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
1a98c087
MK
233#define IS_ZEBRA_IF_MACVLAN(ifp) \
234 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_MACVLAN)
235
0e4864ea
PG
236#define IS_ZEBRA_IF_VETH(ifp) \
237 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VETH)
238
c36e442c
AK
239#define IS_ZEBRA_IF_BOND(ifp) \
240 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BOND)
241
077c07cc
PG
242#define IS_ZEBRA_IF_GRE(ifp) \
243 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_GRE)
244
0e4864ea 245#define IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) \
d62a17ae 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
b9368db9
DD
252#define IS_ZEBRA_IF_BOND_SLAVE(ifp) \
253 (((struct zebra_if *)(ifp->info))->zif_slave_type \
254 == ZEBRA_IF_SLAVE_BOND)
255
05f7f5db
DS
256extern void zebra_if_init(void);
257
d7c0a89a 258extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, uint32_t);
d62a17ae 259extern struct interface *if_lookup_by_name_per_ns(struct zebra_ns *,
260 const char *);
261extern struct interface *if_link_per_ns(struct zebra_ns *, struct interface *);
262extern const char *ifindex2ifname_per_ns(struct zebra_ns *, unsigned int);
263
264extern void if_unlink_per_ns(struct interface *);
ee98d1f1
DS
265extern void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *fip,
266 char mac[6],
267 struct in6_addr *address,
268 int add);
d62a17ae 269extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp,
270 struct in6_addr *address,
271 int add);
272extern void if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(struct interface *ifp);
d0438da6 273extern void if_delete_update(struct interface **ifp);
d62a17ae 274extern void if_add_update(struct interface *ifp);
8b48cdb9 275extern void if_up(struct interface *ifp, bool install_connected);
d62a17ae 276extern void if_down(struct interface *);
277extern void if_refresh(struct interface *);
278extern void if_flags_update(struct interface *, uint64_t);
279extern int if_subnet_add(struct interface *, struct connected *);
280extern int if_subnet_delete(struct interface *, struct connected *);
281extern int ipv6_address_configured(struct interface *ifp);
282extern void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id);
680c278f
PG
283extern void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
284 ns_id_t ns_id);
357b150d 285extern void zebra_if_update_all_links(struct zebra_ns *zns);
321c80d6
SW
286/**
287 * Directly update entire protodown & reason code bitfield.
288 */
289extern int zebra_if_update_protodown_rc(struct interface *ifp, bool new_down,
290 uint32_t new_protodown_rc);
15833261
LS
291
292extern void cli_show_legacy_admin_group(struct vty *vty,
293 const struct lyd_node *dnode,
294 bool show_defaults);
295extern void cli_show_affinity_mode(struct vty *vty,
296 const struct lyd_node *dnode,
297 bool show_defaults);
298extern void cli_show_affinity(struct vty *vty, const struct lyd_node *dnode,
299 bool show_defaults);
300
321c80d6
SW
301/**
302 * Set protodown with single reason.
303 */
5d414138
SW
304extern int zebra_if_set_protodown(struct interface *ifp, bool down,
305 enum protodown_reasons new_reason);
09268680
CS
306extern int if_ip_address_install(struct interface *ifp, struct prefix *prefix,
307 const char *label, struct prefix *pp);
308extern int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix,
309 const char *label);
310extern int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix);
311extern int if_shutdown(struct interface *ifp);
312extern int if_no_shutdown(struct interface *ifp);
313extern int if_multicast_set(struct interface *ifp);
314extern int if_multicast_unset(struct interface *ifp);
315extern int if_linkdetect(struct interface *ifp, bool detect);
316extern void if_addr_wakeup(struct interface *ifp);
d62a17ae 317
fe593b78
SW
318/* Nexthop group connected functions */
319extern void if_nhg_dependents_add(struct interface *ifp,
320 struct nhg_hash_entry *nhe);
321extern void if_nhg_dependents_del(struct interface *ifp,
322 struct nhg_hash_entry *nhe);
323extern unsigned int if_nhg_dependents_count(const struct interface *ifp);
324extern bool if_nhg_dependents_is_empty(const struct interface *ifp);
602fea61 325
d62a17ae 326extern void vrf_add_update(struct vrf *vrfp);
c36e442c
AK
327extern void zebra_l2_map_slave_to_bond(struct zebra_if *zif, vrf_id_t vrf);
328extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif);
5d414138
SW
329extern const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf,
330 uint32_t pd_buf_len);
331void zebra_if_dplane_result(struct zebra_dplane_ctx *ctx);
12f6fb97 332
718e3744 333#ifdef HAVE_PROC_NET_DEV
d62a17ae 334extern void ifstat_update_proc(void);
718e3744 335#endif /* HAVE_PROC_NET_DEV */
336#ifdef HAVE_NET_RT_IFLIST
d62a17ae 337extern void ifstat_update_sysctl(void);
718e3744 338
339#endif /* HAVE_NET_RT_IFLIST */
340#ifdef HAVE_PROC_NET_DEV
d62a17ae 341extern int interface_list_proc(void);
718e3744 342#endif /* HAVE_PROC_NET_DEV */
343#ifdef HAVE_PROC_NET_IF_INET6
d62a17ae 344extern int ifaddr_proc_ipv6(void);
718e3744 345#endif /* HAVE_PROC_NET_IF_INET6 */
346
51e94aa7
EDP
347#ifdef __cplusplus
348}
349#endif
350
5b73a671 351#endif /* _ZEBRA_INTERFACE_H */