]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.h
*: Refactor if_lookup_by_name to be VRF aware
[mirror_frr.git] / lib / if.h
CommitLineData
718e3744 1/* Interface related header.
2 Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation; either version 2, or (at your
9option) any later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#ifndef _ZEBRA_IF_H
22#define _ZEBRA_IF_H
23
b892f1dd 24#include "zebra.h"
718e3744 25#include "linklist.h"
4a1ab8e4 26#include "memory.h"
e80e7cce 27#include "qobj.h"
4a1ab8e4
DL
28
29DECLARE_MTYPE(IF)
30DECLARE_MTYPE(CONNECTED_LABEL)
718e3744 31
8ccc7e80
TT
32/* Interface link-layer type, if known. Derived from:
33 *
34 * net/if_arp.h on various platforms - Linux especially.
35 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
36 *
37 * Some of the more obviously defunct technologies left out.
38 */
39enum zebra_link_type {
40 ZEBRA_LLT_UNKNOWN = 0,
41 ZEBRA_LLT_ETHER,
42 ZEBRA_LLT_EETHER,
43 ZEBRA_LLT_AX25,
44 ZEBRA_LLT_PRONET,
45 ZEBRA_LLT_IEEE802,
46 ZEBRA_LLT_ARCNET,
47 ZEBRA_LLT_APPLETLK,
48 ZEBRA_LLT_DLCI,
49 ZEBRA_LLT_ATM,
50 ZEBRA_LLT_METRICOM,
51 ZEBRA_LLT_IEEE1394,
52 ZEBRA_LLT_EUI64,
53 ZEBRA_LLT_INFINIBAND,
54 ZEBRA_LLT_SLIP,
55 ZEBRA_LLT_CSLIP,
56 ZEBRA_LLT_SLIP6,
57 ZEBRA_LLT_CSLIP6,
58 ZEBRA_LLT_RSRVD,
59 ZEBRA_LLT_ADAPT,
60 ZEBRA_LLT_ROSE,
61 ZEBRA_LLT_X25,
62 ZEBRA_LLT_PPP,
63 ZEBRA_LLT_CHDLC,
64 ZEBRA_LLT_LAPB,
65 ZEBRA_LLT_RAWHDLC,
66 ZEBRA_LLT_IPIP,
67 ZEBRA_LLT_IPIP6,
68 ZEBRA_LLT_FRAD,
69 ZEBRA_LLT_SKIP,
70 ZEBRA_LLT_LOOPBACK,
71 ZEBRA_LLT_LOCALTLK,
72 ZEBRA_LLT_FDDI,
73 ZEBRA_LLT_SIT,
74 ZEBRA_LLT_IPDDP,
75 ZEBRA_LLT_IPGRE,
76 ZEBRA_LLT_IP6GRE,
77 ZEBRA_LLT_PIMREG,
78 ZEBRA_LLT_HIPPI,
79 ZEBRA_LLT_ECONET,
80 ZEBRA_LLT_IRDA,
81 ZEBRA_LLT_FCPP,
82 ZEBRA_LLT_FCAL,
83 ZEBRA_LLT_FCPL,
84 ZEBRA_LLT_FCFABRIC,
85 ZEBRA_LLT_IEEE802_TR,
86 ZEBRA_LLT_IEEE80211,
87 ZEBRA_LLT_IEEE80211_RADIOTAP,
88 ZEBRA_LLT_IEEE802154,
89 ZEBRA_LLT_IEEE802154_PHY,
90};
91
718e3744 92/*
93 Interface name length.
94
95 Linux define value in /usr/include/linux/if.h.
96 #define IFNAMSIZ 16
97
98 FreeBSD define value in /usr/include/net/if.h.
99 #define IFNAMSIZ 16
100*/
101
102#define INTERFACE_NAMSIZ 20
103#define INTERFACE_HWADDR_MAX 20
104
b892f1dd
PJ
105typedef signed int ifindex_t;
106
718e3744 107#ifdef HAVE_PROC_NET_DEV
108struct if_stats
109{
110 unsigned long rx_packets; /* total packets received */
111 unsigned long tx_packets; /* total packets transmitted */
112 unsigned long rx_bytes; /* total bytes received */
113 unsigned long tx_bytes; /* total bytes transmitted */
114 unsigned long rx_errors; /* bad packets received */
115 unsigned long tx_errors; /* packet transmit problems */
116 unsigned long rx_dropped; /* no space in linux buffers */
117 unsigned long tx_dropped; /* no space available in linux */
118 unsigned long rx_multicast; /* multicast packets received */
119 unsigned long rx_compressed;
120 unsigned long tx_compressed;
121 unsigned long collisions;
122
123 /* detailed rx_errors: */
124 unsigned long rx_length_errors;
125 unsigned long rx_over_errors; /* receiver ring buff overflow */
126 unsigned long rx_crc_errors; /* recved pkt with crc error */
127 unsigned long rx_frame_errors; /* recv'd frame alignment error */
128 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
129 unsigned long rx_missed_errors; /* receiver missed packet */
130 /* detailed tx_errors */
131 unsigned long tx_aborted_errors;
132 unsigned long tx_carrier_errors;
133 unsigned long tx_fifo_errors;
134 unsigned long tx_heartbeat_errors;
135 unsigned long tx_window_errors;
136};
137#endif /* HAVE_PROC_NET_DEV */
138
16f1b9ee
OD
139/* Here are "non-official" architectural constants. */
140#define TE_EXT_MASK 0x0FFFFFFF
141#define TE_EXT_ANORMAL 0x80000000
142#define LOSS_PRECISION 0.000003
143#define TE_KILO_BIT 1000
144#define TE_BYTE 8
145#define DEFAULT_BANDWIDTH 10000
146#define MAX_CLASS_TYPE 8
147#define MAX_PKT_LOSS 50.331642
148
daf0a4d2
OD
149/*
150 * Link Parameters Status:
151 * equal to 0: unset
152 * different from 0: set
153 */
16f1b9ee 154#define LP_UNSET 0x0000
daf0a4d2 155#define LP_TE_METRIC 0x0001
16f1b9ee
OD
156#define LP_MAX_BW 0x0002
157#define LP_MAX_RSV_BW 0x0004
158#define LP_UNRSV_BW 0x0008
159#define LP_ADM_GRP 0x0010
160#define LP_RMT_AS 0x0020
161#define LP_DELAY 0x0040
162#define LP_MM_DELAY 0x0080
163#define LP_DELAY_VAR 0x0100
164#define LP_PKT_LOSS 0x0200
165#define LP_RES_BW 0x0400
166#define LP_AVA_BW 0x0800
167#define LP_USE_BW 0x1000
168
169#define IS_PARAM_UNSET(lp, st) !(lp->lp_status & st)
170#define IS_PARAM_SET(lp, st) (lp->lp_status & st)
171#define IS_LINK_PARAMS_SET(lp) (lp->lp_status != LP_UNSET)
172
173#define SET_PARAM(lp, st) (lp->lp_status) |= (st)
174#define UNSET_PARAM(lp, st) (lp->lp_status) &= ~(st)
175#define RESET_LINK_PARAM(lp) (lp->lp_status = LP_UNSET)
176
177/* Link Parameters for Traffic Engineering */
178struct if_link_params {
179 u_int32_t lp_status; /* Status of Link Parameters: */
180 u_int32_t te_metric; /* Traffic Engineering metric */
b6a9e7b4 181 float default_bw;
16f1b9ee
OD
182 float max_bw; /* Maximum Bandwidth */
183 float max_rsv_bw; /* Maximum Reservable Bandwidth */
184 float unrsv_bw[MAX_CLASS_TYPE]; /* Unreserved Bandwidth per Class Type (8) */
185 u_int32_t admin_grp; /* Administrative group */
186 u_int32_t rmt_as; /* Remote AS number */
187 struct in_addr rmt_ip; /* Remote IP address */
188 u_int32_t av_delay; /* Link Average Delay */
189 u_int32_t min_delay; /* Link Min Delay */
190 u_int32_t max_delay; /* Link Max Delay */
191 u_int32_t delay_var; /* Link Delay Variation */
192 float pkt_loss; /* Link Packet Loss */
193 float res_bw; /* Residual Bandwidth */
194 float ava_bw; /* Available Bandwidth */
195 float use_bw; /* Utilized Bandwidth */
196};
197
198#define INTERFACE_LINK_PARAMS_SIZE sizeof(struct if_link_params)
199#define HAS_LINK_PARAMS(ifp) ((ifp)->link_params != NULL)
200
718e3744 201/* Interface structure */
202struct interface
203{
d2fc8896 204 /* Interface name. This should probably never be changed after the
205 interface is created, because the configuration info for this interface
206 is associated with this structure. For that reason, the interface
207 should also never be deleted (to avoid losing configuration info).
208 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
209 interface does not exist in the kernel.
210 */
718e3744 211 char name[INTERFACE_NAMSIZ + 1];
212
d2fc8896 213 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
214 deleted interfaces). */
b892f1dd 215 ifindex_t ifindex;
d2fc8896 216#define IFINDEX_INTERNAL 0
b892f1dd 217#define IFINDEX_DELETED INT_MAX
718e3744 218
219 /* Zebra internal interface status */
220 u_char status;
221#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
222#define ZEBRA_INTERFACE_SUB (1 << 1)
2e3b2e47 223#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
c23af4d3 224#define ZEBRA_INTERFACE_VRF_LOOPBACK (1 << 3)
525c1839 225
718e3744 226 /* Interface flags. */
c77d4546 227 uint64_t flags;
718e3744 228
229 /* Interface metric */
d92c729b 230 uint32_t metric;
718e3744 231
232 /* Interface MTU. */
c9eca01b 233 unsigned int mtu; /* IPv4 MTU */
234 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
718e3744 235
8ccc7e80
TT
236 /* Link-layer information and hardware address */
237 enum zebra_link_type ll_type;
718e3744 238 u_char hw_addr[INTERFACE_HWADDR_MAX];
239 int hw_addr_len;
718e3744 240
241 /* interface bandwidth, kbits */
242 unsigned int bandwidth;
243
16f1b9ee
OD
244 /* Link parameters for Traffic Engineering */
245 struct if_link_params *link_params;
246
718e3744 247 /* description of the interface. */
248 char *desc;
249
250 /* Distribute list. */
251 void *distribute_in;
252 void *distribute_out;
253
254 /* Connected address list. */
52dc7ee6 255 struct list *connected;
718e3744 256
a80beece
DS
257 /* Neighbor connected address list. */
258 struct list *nbr_connected;
259
718e3744 260 /* Daemon specific interface data pointer. */
261 void *info;
262
244c1cdc
DS
263 char ptm_enable; /* Should we look at ptm_status ? */
264 char ptm_status;
265
718e3744 266 /* Statistics fileds. */
267#ifdef HAVE_PROC_NET_DEV
268 struct if_stats stats;
269#endif /* HAVE_PROC_NET_DEV */
270#ifdef HAVE_NET_RT_IFLIST
271 struct if_data stats;
272#endif /* HAVE_NET_RT_IFLIST */
3968dbf8 273
f93e3f69 274 struct route_node *node;
3968dbf8 275 vrf_id_t vrf_id;
e80e7cce
DL
276
277 QOBJ_FIELDS
718e3744 278};
e80e7cce 279DECLARE_QOBJ_TYPE(interface)
718e3744 280
281/* Connected address structure. */
282struct connected
283{
284 /* Attached interface. */
285 struct interface *ifp;
286
287 /* Flags for configuration. */
288 u_char conf;
289#define ZEBRA_IFC_REAL (1 << 0)
290#define ZEBRA_IFC_CONFIGURED (1 << 1)
f7f740fe 291#define ZEBRA_IFC_QUEUED (1 << 2)
9c37851e
AS
292 /*
293 The ZEBRA_IFC_REAL flag should be set if and only if this address
f7f740fe
CF
294 exists in the kernel and is actually usable. (A case where it exists but
295 is not yet usable would be IPv6 with DAD)
9c37851e
AS
296 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
297 was configured by the user from inside quagga.
f7f740fe
CF
298 The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
299 in the kernel. It may and should be set although the address might not be
300 usable yet. (compare with ZEBRA_IFC_REAL)
9c37851e 301 */
718e3744 302
303 /* Flags for connected address. */
304 u_char flags;
e4529636
AS
305#define ZEBRA_IFA_SECONDARY (1 << 0)
306#define ZEBRA_IFA_PEER (1 << 1)
525c1839 307#define ZEBRA_IFA_UNNUMBERED (1 << 2)
e4529636
AS
308 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
309 a peer address has been configured. If this flag is set,
310 the destination field must contain the peer address.
311 Otherwise, if this flag is not set, the destination address
312 will either contain a broadcast address or be NULL.
313 */
718e3744 314
315 /* Address of connected network. */
316 struct prefix *address;
e4529636
AS
317
318 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
319 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
320 struct prefix *destination;
718e3744 321
322 /* Label for Linux 2.2.X and upper. */
323 char *label;
324};
325
a80beece
DS
326/* Nbr Connected address structure. */
327struct nbr_connected
328{
329 /* Attached interface. */
330 struct interface *ifp;
331
332 /* Address of connected network. */
333 struct prefix *address;
334};
335
e4529636
AS
336/* Does the destination field contain a peer address? */
337#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
338
339/* Prefix to insert into the RIB */
340#define CONNECTED_PREFIX(C) \
341 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
3fb9cd6e 342
e4529636
AS
343/* Identifying address. We guess that if there's a peer address, but the
344 local address is in the same prefix, then the local address may be unique. */
345#define CONNECTED_ID(C) \
346 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
347 (C)->destination : (C)->address)
3fb9cd6e 348
718e3744 349/* Interface hook sort. */
350#define IF_NEW_HOOK 0
351#define IF_DELETE_HOOK 1
352
353/* There are some interface flags which are only supported by some
354 operating system. */
355
356#ifndef IFF_NOTRAILERS
357#define IFF_NOTRAILERS 0x0
358#endif /* IFF_NOTRAILERS */
359#ifndef IFF_OACTIVE
360#define IFF_OACTIVE 0x0
361#endif /* IFF_OACTIVE */
362#ifndef IFF_SIMPLEX
363#define IFF_SIMPLEX 0x0
364#endif /* IFF_SIMPLEX */
365#ifndef IFF_LINK0
366#define IFF_LINK0 0x0
367#endif /* IFF_LINK0 */
368#ifndef IFF_LINK1
369#define IFF_LINK1 0x0
370#endif /* IFF_LINK1 */
371#ifndef IFF_LINK2
372#define IFF_LINK2 0x0
373#endif /* IFF_LINK2 */
4ba9b924 374#ifndef IFF_NOXMIT
375#define IFF_NOXMIT 0x0
376#endif /* IFF_NOXMIT */
377#ifndef IFF_NORTEXCH
378#define IFF_NORTEXCH 0x0
379#endif /* IFF_NORTEXCH */
380#ifndef IFF_IPV4
381#define IFF_IPV4 0x0
382#endif /* IFF_IPV4 */
383#ifndef IFF_IPV6
384#define IFF_IPV6 0x0
385#endif /* IFF_IPV6 */
386#ifndef IFF_VIRTUAL
387#define IFF_VIRTUAL 0x0
388#endif /* IFF_VIRTUAL */
718e3744 389
390/* Prototypes. */
974fc9d2 391extern int if_cmp_name_func (char *, char *);
a349198f 392
f93e3f69
DS
393extern void if_update_vrf (struct interface *, const char *name, int namelen,
394 vrf_id_t vrf_id);
4e5266b8
DS
395extern struct interface *if_create (const char *name, int namelen,
396 vrf_id_t vrf_id);
7e2b7603 397extern struct interface *if_lookup_by_index (ifindex_t, vrf_id_t vrf_id);
c5e2cb11 398extern struct interface *if_lookup_exact_address (void *matchaddr, int family,
95af5f13
DS
399 vrf_id_t vrf_id);
400extern struct connected *if_lookup_address (void *matchaddr, int family,
401 vrf_id_t vrf_id);
a90607a4 402extern struct interface *if_lookup_prefix (struct prefix *prefix,
8736158a
FL
403 vrf_id_t vrf_id);
404
08dbfb69 405/* These 2 functions are to be used when the ifname argument is terminated
406 by a '\0' character: */
8cc4198f 407extern struct interface *if_get_by_name (const char *ifname);
08dbfb69 408
f8962871 409extern struct interface *if_lookup_by_name_all_vrf (const char *ifname);
1306c09a
DS
410extern struct interface *if_lookup_by_name (const char *ifname,
411 vrf_id_t vrf_id);
8736158a
FL
412extern struct interface *if_get_by_name_vrf (const char *ifname,
413 vrf_id_t vrf_id);
414
08dbfb69 415/* For these 2 functions, the namelen argument should be the precise length
416 of the ifname string (not counting any optional trailing '\0' character).
417 In most cases, strnlen should be used to calculate the namelen value. */
8736158a
FL
418extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen);
419
fa787f91
DS
420extern struct interface *if_lookup_by_name_len(const char *ifname,
421 size_t namelen, vrf_id_t vrf_id);
8736158a 422extern struct interface *if_get_by_name_len_vrf(const char *ifname,
85f9da7f 423 size_t namelen, vrf_id_t vrf_id, int vty);
a349198f 424
425
d2fc8896 426/* Delete the interface, but do not free the structure, and leave it in the
427 interface list. It is often advisable to leave the pseudo interface
428 structure because there may be configuration information attached. */
429extern void if_delete_retain (struct interface *);
430
431/* Delete and free the interface structure: calls if_delete_retain and then
432 deletes it from the interface list and frees the structure. */
433extern void if_delete (struct interface *);
434
8cc4198f 435extern int if_is_up (struct interface *);
436extern int if_is_running (struct interface *);
437extern int if_is_operative (struct interface *);
244c1cdc 438extern int if_is_no_ptm_operative (struct interface *);
8cc4198f 439extern int if_is_loopback (struct interface *);
440extern int if_is_broadcast (struct interface *);
441extern int if_is_pointopoint (struct interface *);
442extern int if_is_multicast (struct interface *);
443extern void if_add_hook (int, int (*)(struct interface *));
b2d7c082 444extern void if_init (struct list **);
0b84f294 445extern void if_cmd_init (void);
b2d7c082 446extern void if_terminate (struct list **);
8cc4198f 447extern void if_dump_all (void);
847947f2 448extern const char *if_flag_dump(unsigned long);
8ccc7e80 449extern const char *if_link_type_str (enum zebra_link_type);
718e3744 450
d2fc8896 451/* Please use ifindex2ifname instead of if_indextoname where possible;
452 ifindex2ifname uses internal interface info, whereas if_indextoname must
453 make a system call. */
b892f1dd
PJ
454extern const char *ifindex2ifname (ifindex_t);
455extern const char *ifindex2ifname_vrf (ifindex_t, vrf_id_t vrf_id);
d2fc8896 456
457/* Please use ifname2ifindex instead of if_nametoindex where possible;
458 ifname2ifindex uses internal interface info, whereas if_nametoindex must
459 make a system call. */
b892f1dd
PJ
460extern ifindex_t ifname2ifindex(const char *ifname);
461extern ifindex_t ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id);
d2fc8896 462
718e3744 463/* Connected address functions. */
8cc4198f 464extern struct connected *connected_new (void);
465extern void connected_free (struct connected *);
466extern void connected_add (struct interface *, struct connected *);
467extern struct connected *connected_add_by_prefix (struct interface *,
4a7aac1b 468 struct prefix *,
469 struct prefix *);
8cc4198f 470extern struct connected *connected_delete_by_prefix (struct interface *,
4a7aac1b 471 struct prefix *);
bd40c341
DS
472extern struct connected *connected_lookup_prefix (struct interface *,
473 struct prefix *);
38485402
DS
474extern struct connected *connected_lookup_prefix_exact (struct interface *,
475 struct prefix *);
a80beece
DS
476extern struct nbr_connected *nbr_connected_new (void);
477extern void nbr_connected_free (struct nbr_connected *);
478struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *);
718e3744 479
16f1b9ee
OD
480/* link parameters */
481struct if_link_params *if_link_params_get (struct interface *);
482void if_link_params_free (struct interface *);
483
718e3744 484#endif /* _ZEBRA_IF_H */