1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /* Interface function header.
4 * Copyright (C) 1999 Kunihiro Ishiguro
7 #ifndef _ZEBRA_INTERFACE_H
8 #define _ZEBRA_INTERFACE_H
10 #include "redistribute.h"
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"
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
30 #define IF_VLAN_BITMAP_MAX 4096
32 /* Zebra interface type - ones of interest. */
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 */
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 */
55 struct irdp_interface
;
57 /* Ethernet segment info used for setting up EVPN multihoming */
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 */
68 #define ZIF_CFG_ES_FLAG_BYPASS (1 << 0)
70 struct zebra_evpn_es
*es
; /* local ES */
74 /* device has been configured as an uplink for
77 ZIF_FLAG_EVPN_MH_UPLINK
= (1 << 0),
78 ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
= (1 << 1),
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),
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)
91 ZIF_FLAG_LACP_BYPASS
= (1 << 5)
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)
98 /* Mem type for zif desc */
99 DECLARE_MTYPE(ZIF_DESC
);
101 /* `zebra' daemon local interface structure. */
103 /* back pointer to the interface */
104 struct interface
*ifp
;
106 enum zebra_if_flags flags
;
108 /* Shutdown configuration. */
111 /* Multicast configuration. */
117 /* Linkdown status */
118 bool linkdown
, linkdownv6
;
120 /* Is Multicast Forwarding on? */
121 bool v4mcast_on
, v6mcast_on
;
123 /* Router advertise configuration. */
124 uint8_t rtadv_enable
;
126 /* Installed addresses chains tree. */
127 struct route_table
*ipv4_subnets
;
129 /* Nexthops pointing to this interface */
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.
136 struct nhg_connected_tree_head nhg_dependents
;
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
];
144 struct rtadvconf rtadv
;
145 unsigned int ra_sent
, ra_rcvd
;
147 struct irdp_interface
*irdp
;
149 #ifdef HAVE_STRUCT_SOCKADDR_DL
151 /* note that sdl_storage is never accessed, it only exists to
153 * all actual uses refer to sdl - but use sizeof(sdl_storage)!
155 * best with C aliasing rules. */
156 struct sockaddr_dl sdl
;
157 struct sockaddr_storage sdl_storage
;
161 /* ptm enable configuration */
164 /* Zebra interface and "slave" interface type */
165 enum zebra_iftype zif_type
;
166 enum zebra_slave_iftype zif_slave_type
;
168 /* Additional L2 info, depends on zif_type */
169 union zebra_l2if_info l2info
;
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.
175 struct zebra_l2info_brslave brslave_info
;
177 struct zebra_l2info_bondslave bondslave_info
;
178 struct zebra_l2info_bond bond_info
;
180 /* ethernet segment */
181 struct zebra_es_if_info es_info
;
183 /* bitmap of vlans associated with this interface */
184 bitfield_t vlan_bitmap
;
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
192 uint32_t protodown_rc
;
194 /* list of zebra_mac entries using this interface as destination */
195 struct list
*mac_list
;
197 /* Link fields - for sub-interfaces. */
198 ifindex_t link_ifindex
;
199 struct interface
*link
;
201 uint8_t speed_update_count
;
202 struct thread
*speed_update
;
205 * Does this interface have a v6 to v4 ll neighbor entry
206 * for bgp unnumbered?
208 bool v6_2_v4_ll_neigh_entry
;
210 struct in6_addr v6_2_v4_ll_addr6
;
212 /* The description of the interface */
216 DECLARE_HOOK(zebra_if_extra_info
, (struct vty
* vty
, struct interface
*ifp
),
218 DECLARE_HOOK(zebra_if_config_wr
, (struct vty
* vty
, struct interface
*ifp
),
221 #define IS_ZEBRA_IF_VRF(ifp) \
222 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VRF)
224 #define IS_ZEBRA_IF_BRIDGE(ifp) \
225 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BRIDGE)
227 #define IS_ZEBRA_IF_VLAN(ifp) \
228 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VLAN)
230 #define IS_ZEBRA_IF_VXLAN(ifp) \
231 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VXLAN)
233 #define IS_ZEBRA_IF_MACVLAN(ifp) \
234 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_MACVLAN)
236 #define IS_ZEBRA_IF_VETH(ifp) \
237 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_VETH)
239 #define IS_ZEBRA_IF_BOND(ifp) \
240 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_BOND)
242 #define IS_ZEBRA_IF_GRE(ifp) \
243 (((struct zebra_if *)(ifp->info))->zif_type == ZEBRA_IF_GRE)
245 #define IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) \
246 (((struct zebra_if *)(ifp->info))->zif_slave_type \
247 == ZEBRA_IF_SLAVE_BRIDGE)
249 #define IS_ZEBRA_IF_VRF_SLAVE(ifp) \
250 (((struct zebra_if *)(ifp->info))->zif_slave_type == ZEBRA_IF_SLAVE_VRF)
252 #define IS_ZEBRA_IF_BOND_SLAVE(ifp) \
253 (((struct zebra_if *)(ifp->info))->zif_slave_type \
254 == ZEBRA_IF_SLAVE_BOND)
256 extern void zebra_if_init(void);
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
*,
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);
264 extern void if_unlink_per_ns(struct interface
*);
265 extern void if_nbr_mac_to_ipv4ll_neigh_update(struct interface
*fip
,
267 struct in6_addr
*address
,
269 extern void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface
*ifp
,
270 struct in6_addr
*address
,
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
,
285 extern void zebra_if_update_all_links(struct zebra_ns
*zns
);
287 * Directly update entire protodown & reason code bitfield.
289 extern int zebra_if_update_protodown_rc(struct interface
*ifp
, bool new_down
,
290 uint32_t new_protodown_rc
);
292 extern void cli_show_legacy_admin_group(struct vty
*vty
,
293 const struct lyd_node
*dnode
,
295 extern void cli_show_affinity_mode(struct vty
*vty
,
296 const struct lyd_node
*dnode
,
298 extern void cli_show_affinity(struct vty
*vty
, const struct lyd_node
*dnode
,
302 * Set protodown with single reason.
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
,
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
);
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
);
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
);
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);
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 */
351 #endif /* _ZEBRA_INTERFACE_H */