]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / if.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/* Interface related header.
896014f4 3 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
896014f4 4 */
718e3744 5
6#ifndef _ZEBRA_IF_H
7#define _ZEBRA_IF_H
8
b892f1dd 9#include "zebra.h"
718e3744 10#include "linklist.h"
4a1ab8e4 11#include "memory.h"
e80e7cce 12#include "qobj.h"
ce19a04a 13#include "hook.h"
15833261 14#include "admin_group.h"
4a1ab8e4 15
5e244469
RW
16#ifdef __cplusplus
17extern "C" {
18#endif
19
bf8d3d6a 20DECLARE_MTYPE(CONNECTED_LABEL);
718e3744 21
8ccc7e80
TT
22/* Interface link-layer type, if known. Derived from:
23 *
24 * net/if_arp.h on various platforms - Linux especially.
25 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
26 *
27 * Some of the more obviously defunct technologies left out.
28 */
29enum zebra_link_type {
d62a17ae 30 ZEBRA_LLT_UNKNOWN = 0,
31 ZEBRA_LLT_ETHER,
32 ZEBRA_LLT_EETHER,
33 ZEBRA_LLT_AX25,
34 ZEBRA_LLT_PRONET,
35 ZEBRA_LLT_IEEE802,
36 ZEBRA_LLT_ARCNET,
37 ZEBRA_LLT_APPLETLK,
38 ZEBRA_LLT_DLCI,
39 ZEBRA_LLT_ATM,
40 ZEBRA_LLT_METRICOM,
41 ZEBRA_LLT_IEEE1394,
42 ZEBRA_LLT_EUI64,
43 ZEBRA_LLT_INFINIBAND,
44 ZEBRA_LLT_SLIP,
45 ZEBRA_LLT_CSLIP,
46 ZEBRA_LLT_SLIP6,
47 ZEBRA_LLT_CSLIP6,
48 ZEBRA_LLT_RSRVD,
49 ZEBRA_LLT_ADAPT,
50 ZEBRA_LLT_ROSE,
51 ZEBRA_LLT_X25,
52 ZEBRA_LLT_PPP,
53 ZEBRA_LLT_CHDLC,
54 ZEBRA_LLT_LAPB,
55 ZEBRA_LLT_RAWHDLC,
56 ZEBRA_LLT_IPIP,
57 ZEBRA_LLT_IPIP6,
58 ZEBRA_LLT_FRAD,
59 ZEBRA_LLT_SKIP,
60 ZEBRA_LLT_LOOPBACK,
61 ZEBRA_LLT_LOCALTLK,
62 ZEBRA_LLT_FDDI,
63 ZEBRA_LLT_SIT,
64 ZEBRA_LLT_IPDDP,
65 ZEBRA_LLT_IPGRE,
66 ZEBRA_LLT_IP6GRE,
67 ZEBRA_LLT_PIMREG,
68 ZEBRA_LLT_HIPPI,
69 ZEBRA_LLT_ECONET,
70 ZEBRA_LLT_IRDA,
71 ZEBRA_LLT_FCPP,
72 ZEBRA_LLT_FCAL,
73 ZEBRA_LLT_FCPL,
74 ZEBRA_LLT_FCFABRIC,
75 ZEBRA_LLT_IEEE802_TR,
76 ZEBRA_LLT_IEEE80211,
77 ZEBRA_LLT_IEEE80211_RADIOTAP,
78 ZEBRA_LLT_IEEE802154,
79 ZEBRA_LLT_IEEE802154_PHY,
8ccc7e80
TT
80};
81
718e3744 82/*
83 Interface name length.
84
85 Linux define value in /usr/include/linux/if.h.
86 #define IFNAMSIZ 16
87
88 FreeBSD define value in /usr/include/net/if.h.
89 #define IFNAMSIZ 16
90*/
91
79378e4d 92#define INTERFACE_NAMSIZ IFNAMSIZ
718e3744 93#define INTERFACE_HWADDR_MAX 20
94
b892f1dd
PJ
95typedef signed int ifindex_t;
96
718e3744 97#ifdef HAVE_PROC_NET_DEV
d62a17ae 98struct if_stats {
99 unsigned long rx_packets; /* total packets received */
100 unsigned long tx_packets; /* total packets transmitted */
101 unsigned long rx_bytes; /* total bytes received */
102 unsigned long tx_bytes; /* total bytes transmitted */
103 unsigned long rx_errors; /* bad packets received */
104 unsigned long tx_errors; /* packet transmit problems */
105 unsigned long rx_dropped; /* no space in linux buffers */
106 unsigned long tx_dropped; /* no space available in linux */
107 unsigned long rx_multicast; /* multicast packets received */
108 unsigned long rx_compressed;
109 unsigned long tx_compressed;
110 unsigned long collisions;
111
112 /* detailed rx_errors: */
113 unsigned long rx_length_errors;
114 unsigned long rx_over_errors; /* receiver ring buff overflow */
115 unsigned long rx_crc_errors; /* recved pkt with crc error */
116 unsigned long rx_frame_errors; /* recv'd frame alignment error */
117 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
118 unsigned long rx_missed_errors; /* receiver missed packet */
119 /* detailed tx_errors */
120 unsigned long tx_aborted_errors;
121 unsigned long tx_carrier_errors;
122 unsigned long tx_fifo_errors;
123 unsigned long tx_heartbeat_errors;
124 unsigned long tx_window_errors;
718e3744 125};
126#endif /* HAVE_PROC_NET_DEV */
127
16f1b9ee 128/* Here are "non-official" architectural constants. */
81e7bb3d 129#define TE_EXT_MASK 0x00FFFFFF
16f1b9ee
OD
130#define TE_EXT_ANORMAL 0x80000000
131#define LOSS_PRECISION 0.000003
d5a313e0 132/* TE_MEGA_BIT and TE_BYTE are utilized to convert TE bandwidth */
5eb567ed 133#define TE_MEGA_BIT 1000000
16f1b9ee 134#define TE_BYTE 8
d5a313e0
LS
135/* Default TE bandwidth when no value in config.
136 * The value is in Mbps (will be multiplied by TE_BYTE)
137 */
138#define DEFAULT_BANDWIDTH 10
16f1b9ee
OD
139#define MAX_CLASS_TYPE 8
140#define MAX_PKT_LOSS 50.331642
141
15833261
LS
142enum affinity_mode {
143 /* RFC7308 Extended Administrative group */
144 AFFINITY_MODE_EXTENDED = 0,
145 /* RFC3630/RFC5305/RFC5329 Administrative group */
146 AFFINITY_MODE_STANDARD = 1,
147 /* Standard and Extended Administrative group */
148 AFFINITY_MODE_BOTH = 2,
149};
150
daf0a4d2
OD
151/*
152 * Link Parameters Status:
153 * equal to 0: unset
154 * different from 0: set
155 */
16f1b9ee 156#define LP_UNSET 0x0000
daf0a4d2 157#define LP_TE_METRIC 0x0001
16f1b9ee
OD
158#define LP_MAX_BW 0x0002
159#define LP_MAX_RSV_BW 0x0004
160#define LP_UNRSV_BW 0x0008
161#define LP_ADM_GRP 0x0010
162#define LP_RMT_AS 0x0020
163#define LP_DELAY 0x0040
164#define LP_MM_DELAY 0x0080
165#define LP_DELAY_VAR 0x0100
166#define LP_PKT_LOSS 0x0200
167#define LP_RES_BW 0x0400
168#define LP_AVA_BW 0x0800
169#define LP_USE_BW 0x1000
15833261 170#define LP_EXTEND_ADM_GRP 0x2000
16f1b9ee
OD
171
172#define IS_PARAM_UNSET(lp, st) !(lp->lp_status & st)
173#define IS_PARAM_SET(lp, st) (lp->lp_status & st)
174#define IS_LINK_PARAMS_SET(lp) (lp->lp_status != LP_UNSET)
175
176#define SET_PARAM(lp, st) (lp->lp_status) |= (st)
177#define UNSET_PARAM(lp, st) (lp->lp_status) &= ~(st)
178#define RESET_LINK_PARAM(lp) (lp->lp_status = LP_UNSET)
179
15833261
LS
180/* Link Parameters for Traffic Engineering
181 * Do not forget to update if_link_params_copy()
182 * and if_link_params_cmp() when updating the structure
183 */
16f1b9ee 184struct if_link_params {
d7c0a89a
QY
185 uint32_t lp_status; /* Status of Link Parameters: */
186 uint32_t te_metric; /* Traffic Engineering metric */
d62a17ae 187 float default_bw;
188 float max_bw; /* Maximum Bandwidth */
189 float max_rsv_bw; /* Maximum Reservable Bandwidth */
190 float unrsv_bw[MAX_CLASS_TYPE]; /* Unreserved Bandwidth per Class Type
191 (8) */
15833261
LS
192 uint32_t admin_grp; /* RFC5305/RFC5329 Administrative group */
193 struct admin_group ext_admin_grp; /* RFC7308 Extended Admin group */
d7c0a89a 194 uint32_t rmt_as; /* Remote AS number */
d62a17ae 195 struct in_addr rmt_ip; /* Remote IP address */
d7c0a89a
QY
196 uint32_t av_delay; /* Link Average Delay */
197 uint32_t min_delay; /* Link Min Delay */
198 uint32_t max_delay; /* Link Max Delay */
199 uint32_t delay_var; /* Link Delay Variation */
d62a17ae 200 float pkt_loss; /* Link Packet Loss */
201 float res_bw; /* Residual Bandwidth */
202 float ava_bw; /* Available Bandwidth */
203 float use_bw; /* Utilized Bandwidth */
16f1b9ee
OD
204};
205
206#define INTERFACE_LINK_PARAMS_SIZE sizeof(struct if_link_params)
207#define HAS_LINK_PARAMS(ifp) ((ifp)->link_params != NULL)
208
718e3744 209/* Interface structure */
d62a17ae 210struct interface {
ff880b78 211 RB_ENTRY(interface) name_entry, index_entry;
f4e14fdb 212
d62a17ae 213 /* Interface name. This should probably never be changed after the
214 interface is created, because the configuration info for this
215 interface
216 is associated with this structure. For that reason, the interface
217 should also never be deleted (to avoid losing configuration info).
218 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
219 interface does not exist in the kernel.
220 */
bcc24579 221 char name[INTERFACE_NAMSIZ];
d62a17ae 222
223 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
ff880b78
RW
224 deleted interfaces).
225 WARNING: the ifindex needs to be changed using the if_set_index()
226 function. Failure to respect this will cause corruption in the data
227 structure used to store the interfaces and if_lookup_by_index() will
228 not work as expected.
229 */
d62a17ae 230 ifindex_t ifindex;
e7ff0253
DS
231 ifindex_t oldifindex;
232
53e60e5c
QY
233 /*
234 * ifindex of parent interface, if any
235 */
236 ifindex_t link_ifindex;
d2fc8896 237#define IFINDEX_INTERNAL 0
718e3744 238
d62a17ae 239 /* Zebra internal interface status */
d7c0a89a 240 uint8_t status;
718e3744 241#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
242#define ZEBRA_INTERFACE_SUB (1 << 1)
2e3b2e47 243#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
c23af4d3 244#define ZEBRA_INTERFACE_VRF_LOOPBACK (1 << 3)
525c1839 245
d62a17ae 246 /* Interface flags. */
247 uint64_t flags;
718e3744 248
d62a17ae 249 /* Interface metric */
250 uint32_t metric;
718e3744 251
d62a17ae 252 /* Interface Speed in Mb/s */
253 uint32_t speed;
2d7f0d76 254
d62a17ae 255 /* Interface MTU. */
256 unsigned int mtu; /* IPv4 MTU */
257 unsigned int
214d8a60 258 mtu6; /* IPv6 MTU - probably, but not necessarily same as mtu
259 */
718e3744 260
d62a17ae 261 /* Link-layer information and hardware address */
262 enum zebra_link_type ll_type;
d7c0a89a 263 uint8_t hw_addr[INTERFACE_HWADDR_MAX];
d62a17ae 264 int hw_addr_len;
718e3744 265
d62a17ae 266 /* interface bandwidth, kbits */
267 unsigned int bandwidth;
16f1b9ee 268
d62a17ae 269 /* Link parameters for Traffic Engineering */
270 struct if_link_params *link_params;
718e3744 271
d62a17ae 272 /* description of the interface. */
273 char *desc;
718e3744 274
d62a17ae 275 /* Distribute list. */
276 void *distribute_in;
277 void *distribute_out;
718e3744 278
d62a17ae 279 /* Connected address list. */
280 struct list *connected;
a80beece 281
d62a17ae 282 /* Neighbor connected address list. */
283 struct list *nbr_connected;
718e3744 284
d62a17ae 285 /* Daemon specific interface data pointer. */
286 void *info;
244c1cdc 287
d62a17ae 288 char ptm_enable; /* Should we look at ptm_status ? */
289 char ptm_status;
290
291/* Statistics fileds. */
718e3744 292#ifdef HAVE_PROC_NET_DEV
d62a17ae 293 struct if_stats stats;
294#endif /* HAVE_PROC_NET_DEV */
718e3744 295#ifdef HAVE_NET_RT_IFLIST
d62a17ae 296 struct if_data stats;
718e3744 297#endif /* HAVE_NET_RT_IFLIST */
3968dbf8 298
d62a17ae 299 struct route_node *node;
f60a1188
IR
300
301 struct vrf *vrf;
e80e7cce 302
1d311a05
DS
303 /*
304 * Has the end users entered `interface XXXX` from the cli in some
305 * fashion?
306 */
307 bool configured;
308
96244aca 309 QOBJ_FIELDS;
718e3744 310};
0c74bbe0 311
f4e14fdb 312RB_HEAD(if_name_head, interface);
f3dd45d1 313RB_PROTOTYPE(if_name_head, interface, name_entry, if_cmp_func)
ff880b78 314RB_HEAD(if_index_head, interface);
db8d54b0 315RB_PROTOTYPE(if_index_head, interface, index_entry, if_cmp_index_func)
96244aca 316DECLARE_QOBJ_TYPE(interface);
718e3744 317
096f7609 318#define IFNAME_RB_INSERT(v, ifp) \
67f81586
QY
319 ({ \
320 struct interface *_iz = \
096f7609 321 RB_INSERT(if_name_head, &v->ifaces_by_name, (ifp)); \
67f81586
QY
322 if (_iz) \
323 flog_err( \
324 EC_LIB_INTERFACE, \
325 "%s(%s): corruption detected -- interface with this " \
096f7609
IR
326 "name exists already in VRF %s!", \
327 __func__, (ifp)->name, (ifp)->vrf->name); \
67f81586
QY
328 _iz; \
329 })
330
096f7609 331#define IFNAME_RB_REMOVE(v, ifp) \
67f81586
QY
332 ({ \
333 struct interface *_iz = \
096f7609 334 RB_REMOVE(if_name_head, &v->ifaces_by_name, (ifp)); \
67f81586
QY
335 if (_iz == NULL) \
336 flog_err( \
337 EC_LIB_INTERFACE, \
338 "%s(%s): corruption detected -- interface with this " \
096f7609
IR
339 "name doesn't exist in VRF %s!", \
340 __func__, (ifp)->name, (ifp)->vrf->name); \
67f81586
QY
341 _iz; \
342 })
343
344
096f7609 345#define IFINDEX_RB_INSERT(v, ifp) \
67f81586 346 ({ \
096f7609
IR
347 struct interface *_iz = \
348 RB_INSERT(if_index_head, &v->ifaces_by_index, (ifp)); \
67f81586
QY
349 if (_iz) \
350 flog_err( \
351 EC_LIB_INTERFACE, \
352 "%s(%u): corruption detected -- interface with this " \
096f7609
IR
353 "ifindex exists already in VRF %s!", \
354 __func__, (ifp)->ifindex, (ifp)->vrf->name); \
67f81586
QY
355 _iz; \
356 })
357
096f7609 358#define IFINDEX_RB_REMOVE(v, ifp) \
67f81586 359 ({ \
096f7609
IR
360 struct interface *_iz = \
361 RB_REMOVE(if_index_head, &v->ifaces_by_index, (ifp)); \
67f81586
QY
362 if (_iz == NULL) \
363 flog_err( \
364 EC_LIB_INTERFACE, \
365 "%s(%u): corruption detected -- interface with this " \
096f7609
IR
366 "ifindex doesn't exist in VRF %s!", \
367 __func__, (ifp)->ifindex, (ifp)->vrf->name); \
67f81586
QY
368 _iz; \
369 })
ff880b78 370
451fda4f
RW
371#define FOR_ALL_INTERFACES(vrf, ifp) \
372 if (vrf) \
373 RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name)
374
375#define FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) \
376 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected))
377
ce19a04a
DL
378/* called from the library code whenever interfaces are created/deleted
379 * note: interfaces may not be fully realized at that point; also they
380 * may not exist in the system (ifindex = IFINDEX_INTERNAL)
381 *
382 * priority values are important here, daemons should be at 0 while modules
383 * can use 1000+ so they run after the daemon has initialised daemon-specific
384 * interface data
385 */
8451921b
DL
386DECLARE_HOOK(if_add, (struct interface * ifp), (ifp));
387DECLARE_KOOH(if_del, (struct interface * ifp), (ifp));
ce19a04a 388
cde1af84
AK
389#define METRIC_MAX (~0)
390
718e3744 391/* Connected address structure. */
d62a17ae 392struct connected {
393 /* Attached interface. */
394 struct interface *ifp;
718e3744 395
d62a17ae 396 /* Flags for configuration. */
d7c0a89a 397 uint8_t conf;
718e3744 398#define ZEBRA_IFC_REAL (1 << 0)
399#define ZEBRA_IFC_CONFIGURED (1 << 1)
f7f740fe 400#define ZEBRA_IFC_QUEUED (1 << 2)
e3d901f8 401#define ZEBRA_IFC_DOWN (1 << 3)
d62a17ae 402 /*
403 The ZEBRA_IFC_REAL flag should be set if and only if this address
404 exists in the kernel and is actually usable. (A case where it exists
b72aae2e 405 but is not yet usable would be IPv6 with DAD)
d62a17ae 406 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this
b72aae2e 407 address was configured by the user from inside frr.
d62a17ae 408 The ZEBRA_IFC_QUEUED flag should be set if and only if the address
b72aae2e
DS
409 exists in the kernel. It may and should be set although the
410 address might not be usable yet. (compare with ZEBRA_IFC_REAL)
e3d901f8
MS
411 The ZEBRA_IFC_DOWN flag is used to record that an address is
412 present, but down/unavailable.
d62a17ae 413 */
414
415 /* Flags for connected address. */
d7c0a89a 416 uint8_t flags;
e4529636
AS
417#define ZEBRA_IFA_SECONDARY (1 << 0)
418#define ZEBRA_IFA_PEER (1 << 1)
525c1839 419#define ZEBRA_IFA_UNNUMBERED (1 << 2)
d62a17ae 420 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
421 a peer address has been configured. If this flag is set,
422 the destination field must contain the peer address.
d62a17ae 423 */
424
425 /* Address of connected network. */
426 struct prefix *address;
427
0f3af738 428 /* Peer address, if ZEBRA_IFA_PEER is set, otherwise NULL */
d62a17ae 429 struct prefix *destination;
430
431 /* Label for Linux 2.2.X and upper. */
432 char *label;
cde1af84
AK
433
434 /*
435 * Used for setting the connected route's cost. If the metric
436 * here is set to METRIC_MAX the connected route falls back to
437 * "struct interface"
438 */
439 uint32_t metric;
718e3744 440};
441
a80beece 442/* Nbr Connected address structure. */
d62a17ae 443struct nbr_connected {
444 /* Attached interface. */
445 struct interface *ifp;
a80beece 446
d62a17ae 447 /* Address of connected network. */
448 struct prefix *address;
a80beece
DS
449};
450
e4529636
AS
451/* Does the destination field contain a peer address? */
452#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
453
454/* Prefix to insert into the RIB */
d62a17ae 455#define CONNECTED_PREFIX(C) \
e4529636 456 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
3fb9cd6e 457
e4529636
AS
458/* Identifying address. We guess that if there's a peer address, but the
459 local address is in the same prefix, then the local address may be unique. */
d62a17ae 460#define CONNECTED_ID(C) \
461 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) \
462 ? (C)->destination \
463 : (C)->address)
3fb9cd6e 464
718e3744 465/* There are some interface flags which are only supported by some
466 operating system. */
467
468#ifndef IFF_NOTRAILERS
469#define IFF_NOTRAILERS 0x0
470#endif /* IFF_NOTRAILERS */
471#ifndef IFF_OACTIVE
472#define IFF_OACTIVE 0x0
473#endif /* IFF_OACTIVE */
474#ifndef IFF_SIMPLEX
475#define IFF_SIMPLEX 0x0
476#endif /* IFF_SIMPLEX */
477#ifndef IFF_LINK0
478#define IFF_LINK0 0x0
479#endif /* IFF_LINK0 */
480#ifndef IFF_LINK1
481#define IFF_LINK1 0x0
482#endif /* IFF_LINK1 */
483#ifndef IFF_LINK2
484#define IFF_LINK2 0x0
485#endif /* IFF_LINK2 */
4ba9b924 486#ifndef IFF_NOXMIT
487#define IFF_NOXMIT 0x0
488#endif /* IFF_NOXMIT */
489#ifndef IFF_NORTEXCH
490#define IFF_NORTEXCH 0x0
491#endif /* IFF_NORTEXCH */
492#ifndef IFF_IPV4
493#define IFF_IPV4 0x0
494#endif /* IFF_IPV4 */
495#ifndef IFF_IPV6
496#define IFF_IPV6 0x0
497#endif /* IFF_IPV6 */
498#ifndef IFF_VIRTUAL
499#define IFF_VIRTUAL 0x0
500#endif /* IFF_VIRTUAL */
718e3744 501
502/* Prototypes. */
36de6e0e 503extern int if_cmp_name_func(const char *p1, const char *p2);
d62a17ae 504
14fcc65c
DS
505/*
506 * Passing in VRF_UNKNOWN is a valid thing to do, unless we
507 * are creating a new interface.
508 *
509 * This is useful for vrf route-leaking. So more than anything
510 * else think before you use VRF_UNKNOWN
511 */
a36898e7 512extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id);
d5c65bf1 513
d62a17ae 514extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
0760a74d
PR
515extern struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex,
516 vrf_id_t vrf_id);
1e9044be 517extern struct interface *if_lookup_address_local(const void *matchaddr,
0b700537
RW
518 int family, vrf_id_t vrf_id);
519extern struct connected *if_lookup_address(const void *matchaddr, int family,
d62a17ae 520 vrf_id_t vrf_id);
0b700537 521extern struct interface *if_lookup_prefix(const struct prefix *prefix,
d62a17ae 522 vrf_id_t vrf_id);
dad18a2f
QY
523size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
524 struct interface ***result, vrf_id_t vrf_id);
8736158a 525
1e9044be
DL
526static inline bool if_address_is_local(const void *matchaddr, int family,
527 vrf_id_t vrf_id)
528{
529 return if_lookup_address_local(matchaddr, family, vrf_id) != NULL;
530}
531
a2719d0e 532struct vrf;
a2719d0e 533extern struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf);
a36898e7 534extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id);
b2cfd204 535extern struct interface *if_get_vrf_loopback(vrf_id_t vrf_id);
f60a1188
IR
536extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id,
537 const char *vrf_name);
bd23c840 538
d5c65bf1 539/* Sets the index and adds to index list */
67f81586 540extern int if_set_index(struct interface *ifp, ifindex_t ifindex);
a349198f 541
d2fc8896 542/* Delete the interface, but do not free the structure, and leave it in the
d62a17ae 543 interface list. It is often advisable to leave the pseudo interface
d2fc8896 544 structure because there may be configuration information attached. */
d62a17ae 545extern void if_delete_retain(struct interface *);
d2fc8896 546
547/* Delete and free the interface structure: calls if_delete_retain and then
548 deletes it from the interface list and frees the structure. */
f609709a 549extern void if_delete(struct interface **ifp);
d62a17ae 550
6339042c
MS
551extern int if_is_up(const struct interface *ifp);
552extern int if_is_running(const struct interface *ifp);
553extern int if_is_operative(const struct interface *ifp);
554extern int if_is_no_ptm_operative(const struct interface *ifp);
608c8870 555extern int if_is_loopback_exact(const struct interface *ifp);
6339042c 556extern int if_is_vrf(const struct interface *ifp);
608c8870 557extern bool if_is_loopback(const struct interface *ifp);
6339042c
MS
558extern int if_is_broadcast(const struct interface *ifp);
559extern int if_is_pointopoint(const struct interface *ifp);
560extern int if_is_multicast(const struct interface *ifp);
f4e14fdb 561extern void if_terminate(struct vrf *vrf);
d62a17ae 562extern void if_dump_all(void);
847947f2 563extern const char *if_flag_dump(unsigned long);
d62a17ae 564extern const char *if_link_type_str(enum zebra_link_type);
718e3744 565
d2fc8896 566/* Please use ifindex2ifname instead of if_indextoname where possible;
567 ifindex2ifname uses internal interface info, whereas if_indextoname must
568 make a system call. */
d62a17ae 569extern const char *ifindex2ifname(ifindex_t, vrf_id_t vrf_id);
d2fc8896 570
571/* Please use ifname2ifindex instead of if_nametoindex where possible;
572 ifname2ifindex uses internal interface info, whereas if_nametoindex must
573 make a system call. */
128c2be2 574extern ifindex_t ifname2ifindex(const char *ifname, vrf_id_t vrf_id);
d2fc8896 575
718e3744 576/* Connected address functions. */
d62a17ae 577extern struct connected *connected_new(void);
721c0857 578extern void connected_free(struct connected **connected);
d62a17ae 579extern void connected_add(struct interface *, struct connected *);
580extern struct connected *
581connected_add_by_prefix(struct interface *, struct prefix *, struct prefix *);
582extern struct connected *connected_delete_by_prefix(struct interface *,
583 struct prefix *);
584extern struct connected *connected_lookup_prefix(struct interface *,
0b700537 585 const struct prefix *);
d62a17ae 586extern struct connected *connected_lookup_prefix_exact(struct interface *,
0b700537 587 const struct prefix *);
457ea8d4 588extern unsigned int connected_count_by_family(struct interface *, int family);
d62a17ae 589extern struct nbr_connected *nbr_connected_new(void);
590extern void nbr_connected_free(struct nbr_connected *);
591struct nbr_connected *nbr_connected_check(struct interface *, struct prefix *);
667179ca 592struct connected *connected_get_linklocal(struct interface *ifp);
718e3744 593
16f1b9ee 594/* link parameters */
15833261
LS
595bool if_link_params_cmp(struct if_link_params *iflp1,
596 struct if_link_params *iflp2);
597void if_link_params_copy(struct if_link_params *dst,
598 struct if_link_params *src);
d62a17ae 599struct if_link_params *if_link_params_get(struct interface *);
2e2dc4f0
LS
600struct if_link_params *if_link_params_enable(struct interface *ifp);
601struct if_link_params *if_link_params_init(struct interface *ifp);
d62a17ae 602void if_link_params_free(struct interface *);
16f1b9ee 603
a4bed468 604/* Northbound. */
9da01b0b 605struct vty;
788a036f
IR
606extern void if_vty_config_start(struct vty *vty, struct interface *ifp);
607extern void if_vty_config_end(struct vty *vty);
9da01b0b 608extern void if_cmd_init(int (*config_write)(struct vty *));
104fd767 609extern void if_cmd_init_default(void);
138c5a74
DS
610extern void if_zapi_callbacks(int (*create)(struct interface *ifp),
611 int (*up)(struct interface *ifp),
612 int (*down)(struct interface *ifp),
613 int (*destroy)(struct interface *ifp));
614
ef7bd2a3 615extern void if_new_via_zapi(struct interface *ifp);
ddbf3e60 616extern void if_up_via_zapi(struct interface *ifp);
b0b69e59 617extern void if_down_via_zapi(struct interface *ifp);
3c3c3252 618extern void if_destroy_via_zapi(struct interface *ifp);
ef7bd2a3 619
a4bed468
RW
620extern const struct frr_yang_module_info frr_interface_info;
621
5e244469
RW
622#ifdef __cplusplus
623}
624#endif
625
718e3744 626#endif /* _ZEBRA_IF_H */