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