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