1 /* Interface related header.
2 Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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.
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.
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. */
27 /* Interface link-layer type, if known. Derived from:
29 * net/if_arp.h on various platforms - Linux especially.
30 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
32 * Some of the more obviously defunct technologies left out.
34 enum zebra_link_type {
35 ZEBRA_LLT_UNKNOWN = 0,
82 ZEBRA_LLT_IEEE80211_RADIOTAP,
84 ZEBRA_LLT_IEEE802154_PHY,
88 Interface name length.
90 Linux define value in /usr/include/linux/if.h.
93 FreeBSD define value in /usr/include/net/if.h.
97 #define INTERFACE_NAMSIZ 20
98 #define INTERFACE_HWADDR_MAX 20
100 typedef signed int ifindex_t;
102 #ifdef HAVE_PROC_NET_DEV
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;
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;
132 #endif /* HAVE_PROC_NET_DEV */
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
140 #define DEFAULT_BANDWIDTH 10000
141 #define MAX_CLASS_TYPE 8
142 #define MAX_PKT_LOSS 50.331642
144 /* Link Parameters Status: 0: unset, 1: set, */
145 #define LP_UNSET 0x0000
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
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)
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)
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 */
188 #define INTERFACE_LINK_PARAMS_SIZE sizeof(struct if_link_params)
189 #define HAS_LINK_PARAMS(ifp) ((ifp)->link_params != NULL)
191 /* Interface structure */
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.
201 char name[INTERFACE_NAMSIZ + 1];
203 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
204 deleted interfaces). */
206 #define IFINDEX_INTERNAL 0
208 /* Zebra internal interface status */
210 #define ZEBRA_INTERFACE_ACTIVE (1 << 0)
211 #define ZEBRA_INTERFACE_SUB (1 << 1)
212 #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
214 /* Interface flags. */
217 /* Interface metric */
221 unsigned int mtu; /* IPv4 MTU */
222 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
224 /* Link-layer information and hardware address */
225 enum zebra_link_type ll_type;
226 u_char hw_addr[INTERFACE_HWADDR_MAX];
229 /* interface bandwidth, kbits */
230 unsigned int bandwidth;
232 /* Link parameters for Traffic Engineering */
233 struct if_link_params *link_params;
235 /* description of the interface. */
238 /* Distribute list. */
240 void *distribute_out;
242 /* Connected address list. */
243 struct list *connected;
245 /* Daemon specific interface data pointer. */
248 /* Statistics fileds. */
249 #ifdef HAVE_PROC_NET_DEV
250 struct if_stats stats;
251 #endif /* HAVE_PROC_NET_DEV */
252 #ifdef HAVE_NET_RT_IFLIST
253 struct if_data stats;
254 #endif /* HAVE_NET_RT_IFLIST */
259 /* Connected address structure. */
262 /* Attached interface. */
263 struct interface *ifp;
265 /* Flags for configuration. */
267 #define ZEBRA_IFC_REAL (1 << 0)
268 #define ZEBRA_IFC_CONFIGURED (1 << 1)
269 #define ZEBRA_IFC_QUEUED (1 << 2)
271 The ZEBRA_IFC_REAL flag should be set if and only if this address
272 exists in the kernel and is actually usable. (A case where it exists but
273 is not yet usable would be IPv6 with DAD)
274 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
275 was configured by the user from inside quagga.
276 The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
277 in the kernel. It may and should be set although the address might not be
278 usable yet. (compare with ZEBRA_IFC_REAL)
281 /* Flags for connected address. */
283 #define ZEBRA_IFA_SECONDARY (1 << 0)
284 #define ZEBRA_IFA_PEER (1 << 1)
285 #define ZEBRA_IFA_UNNUMBERED (1 << 2)
286 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
287 a peer address has been configured. If this flag is set,
288 the destination field must contain the peer address.
289 Otherwise, if this flag is not set, the destination address
290 will either contain a broadcast address or be NULL.
293 /* Address of connected network. */
294 struct prefix *address;
296 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
297 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
298 struct prefix *destination;
300 /* Label for Linux 2.2.X and upper. */
304 /* Does the destination field contain a peer address? */
305 #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
307 /* Prefix to insert into the RIB */
308 #define CONNECTED_PREFIX(C) \
309 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
311 /* Identifying address. We guess that if there's a peer address, but the
312 local address is in the same prefix, then the local address may be unique. */
313 #define CONNECTED_ID(C) \
314 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
315 (C)->destination : (C)->address)
317 /* Interface hook sort. */
318 #define IF_NEW_HOOK 0
319 #define IF_DELETE_HOOK 1
321 /* There are some interface flags which are only supported by some
324 #ifndef IFF_NOTRAILERS
325 #define IFF_NOTRAILERS 0x0
326 #endif /* IFF_NOTRAILERS */
328 #define IFF_OACTIVE 0x0
329 #endif /* IFF_OACTIVE */
331 #define IFF_SIMPLEX 0x0
332 #endif /* IFF_SIMPLEX */
334 #define IFF_LINK0 0x0
335 #endif /* IFF_LINK0 */
337 #define IFF_LINK1 0x0
338 #endif /* IFF_LINK1 */
340 #define IFF_LINK2 0x0
341 #endif /* IFF_LINK2 */
343 #define IFF_NOXMIT 0x0
344 #endif /* IFF_NOXMIT */
346 #define IFF_NORTEXCH 0x0
347 #endif /* IFF_NORTEXCH */
350 #endif /* IFF_IPV4 */
353 #endif /* IFF_IPV6 */
355 #define IFF_VIRTUAL 0x0
356 #endif /* IFF_VIRTUAL */
359 extern int if_cmp_func (struct interface *, struct interface *);
360 extern struct interface *if_create (const char *name, int namelen);
361 extern struct interface *if_lookup_by_index (ifindex_t);
362 extern struct interface *if_lookup_exact_address (struct in_addr);
363 extern struct interface *if_lookup_address (struct in_addr);
364 extern struct interface *if_lookup_prefix (struct prefix *prefix);
366 extern struct interface *if_create_vrf (const char *name, int namelen,
368 extern struct interface *if_lookup_by_index_vrf (ifindex_t, vrf_id_t vrf_id);
369 extern struct interface *if_lookup_exact_address_vrf (struct in_addr,
371 extern struct interface *if_lookup_address_vrf (struct in_addr,
373 extern struct interface *if_lookup_prefix_vrf (struct prefix *prefix,
376 /* These 2 functions are to be used when the ifname argument is terminated
377 by a '\0' character: */
378 extern struct interface *if_lookup_by_name (const char *ifname);
379 extern struct interface *if_get_by_name (const char *ifname);
381 extern struct interface *if_lookup_by_name_vrf (const char *ifname,
383 extern struct interface *if_get_by_name_vrf (const char *ifname,
386 /* For these 2 functions, the namelen argument should be the precise length
387 of the ifname string (not counting any optional trailing '\0' character).
388 In most cases, strnlen should be used to calculate the namelen value. */
389 extern struct interface *if_lookup_by_name_len(const char *ifname,
391 extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen);
393 extern struct interface *if_lookup_by_name_len_vrf(const char *ifname,
394 size_t namelen, vrf_id_t vrf_id);
395 extern struct interface *if_get_by_name_len_vrf(const char *ifname,
396 size_t namelen, vrf_id_t vrf_id);
399 /* Delete the interface, but do not free the structure, and leave it in the
400 interface list. It is often advisable to leave the pseudo interface
401 structure because there may be configuration information attached. */
402 extern void if_delete_retain (struct interface *);
404 /* Delete and free the interface structure: calls if_delete_retain and then
405 deletes it from the interface list and frees the structure. */
406 extern void if_delete (struct interface *);
408 extern int if_is_up (struct interface *);
409 extern int if_is_running (struct interface *);
410 extern int if_is_operative (struct interface *);
411 extern int if_is_loopback (struct interface *);
412 extern int if_is_broadcast (struct interface *);
413 extern int if_is_pointopoint (struct interface *);
414 extern int if_is_multicast (struct interface *);
415 extern void if_add_hook (int, int (*)(struct interface *));
416 extern void if_init (vrf_id_t, struct list **);
417 extern void if_terminate (vrf_id_t, struct list **);
418 extern void if_dump_all (void);
419 extern const char *if_flag_dump(unsigned long);
420 extern const char *if_link_type_str (enum zebra_link_type);
422 /* Please use ifindex2ifname instead of if_indextoname where possible;
423 ifindex2ifname uses internal interface info, whereas if_indextoname must
424 make a system call. */
425 extern const char *ifindex2ifname (ifindex_t);
426 extern const char *ifindex2ifname_vrf (ifindex_t, vrf_id_t vrf_id);
428 /* Please use ifname2ifindex instead of if_nametoindex where possible;
429 ifname2ifindex uses internal interface info, whereas if_nametoindex must
430 make a system call. */
431 extern ifindex_t ifname2ifindex(const char *ifname);
432 extern ifindex_t ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id);
434 /* Connected address functions. */
435 extern struct connected *connected_new (void);
436 extern void connected_free (struct connected *);
437 extern void connected_add (struct interface *, struct connected *);
438 extern struct connected *connected_add_by_prefix (struct interface *,
441 extern struct connected *connected_delete_by_prefix (struct interface *,
443 extern struct connected *connected_lookup_address (struct interface *,
446 #ifndef HAVE_IF_NAMETOINDEX
447 extern ifindex_t if_nametoindex (const char *);
449 #ifndef HAVE_IF_INDEXTONAME
450 extern char *if_indextoname (ifindex_t, char *);
453 /* link parameters */
454 struct if_link_params *if_link_params_get (struct interface *);
455 void if_link_params_free (struct interface *);
457 /* Exported variables. */
458 extern struct list *iflist;
459 extern struct cmd_element interface_desc_cmd;
460 extern struct cmd_element no_interface_desc_cmd;
461 extern struct cmd_element interface_cmd;
462 extern struct cmd_element no_interface_cmd;
463 extern struct cmd_element interface_vrf_cmd;
464 extern struct cmd_element no_interface_vrf_cmd;
465 extern struct cmd_element interface_pseudo_cmd;
466 extern struct cmd_element no_interface_pseudo_cmd;
467 extern struct cmd_element show_address_cmd;
468 extern struct cmd_element show_address_vrf_cmd;
469 extern struct cmd_element show_address_vrf_all_cmd;
471 #endif /* _ZEBRA_IF_H */