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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 DECLARE_MTYPE(CONNECTED_LABEL
)
33 /* Interface link-layer type, if known. Derived from:
35 * net/if_arp.h on various platforms - Linux especially.
36 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
38 * Some of the more obviously defunct technologies left out.
40 enum zebra_link_type
{
41 ZEBRA_LLT_UNKNOWN
= 0,
88 ZEBRA_LLT_IEEE80211_RADIOTAP
,
90 ZEBRA_LLT_IEEE802154_PHY
,
94 Interface name length.
96 Linux define value in /usr/include/linux/if.h.
99 FreeBSD define value in /usr/include/net/if.h.
103 #define INTERFACE_NAMSIZ 20
104 #define INTERFACE_HWADDR_MAX 20
106 typedef signed int ifindex_t
;
108 #ifdef HAVE_PROC_NET_DEV
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
;
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
;
137 #endif /* HAVE_PROC_NET_DEV */
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
145 #define DEFAULT_BANDWIDTH 10000
146 #define MAX_CLASS_TYPE 8
147 #define MAX_PKT_LOSS 50.331642
150 * Link Parameters Status:
152 * different from 0: set
154 #define LP_UNSET 0x0000
155 #define LP_TE_METRIC 0x0001
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
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)
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)
177 /* Link Parameters for Traffic Engineering */
178 struct if_link_params
{
179 u_int32_t lp_status
; /* Status of Link Parameters: */
180 u_int32_t te_metric
; /* Traffic Engineering metric */
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
186 u_int32_t admin_grp
; /* Administrative group */
187 u_int32_t rmt_as
; /* Remote AS number */
188 struct in_addr rmt_ip
; /* Remote IP address */
189 u_int32_t av_delay
; /* Link Average Delay */
190 u_int32_t min_delay
; /* Link Min Delay */
191 u_int32_t max_delay
; /* Link Max Delay */
192 u_int32_t delay_var
; /* Link Delay Variation */
193 float pkt_loss
; /* Link Packet Loss */
194 float res_bw
; /* Residual Bandwidth */
195 float ava_bw
; /* Available Bandwidth */
196 float use_bw
; /* Utilized Bandwidth */
199 #define INTERFACE_LINK_PARAMS_SIZE sizeof(struct if_link_params)
200 #define HAS_LINK_PARAMS(ifp) ((ifp)->link_params != NULL)
202 /* Interface structure */
204 RB_ENTRY(interface
) name_entry
, index_entry
;
206 /* Interface name. This should probably never be changed after the
207 interface is created, because the configuration info for this
209 is associated with this structure. For that reason, the interface
210 should also never be deleted (to avoid losing configuration info).
211 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
212 interface does not exist in the kernel.
214 char name
[INTERFACE_NAMSIZ
];
216 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
218 WARNING: the ifindex needs to be changed using the if_set_index()
219 function. Failure to respect this will cause corruption in the data
220 structure used to store the interfaces and if_lookup_by_index() will
221 not work as expected.
224 #define IFINDEX_INTERNAL 0
226 /* Zebra internal interface status */
228 #define ZEBRA_INTERFACE_ACTIVE (1 << 0)
229 #define ZEBRA_INTERFACE_SUB (1 << 1)
230 #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
231 #define ZEBRA_INTERFACE_VRF_LOOPBACK (1 << 3)
233 /* Interface flags. */
236 /* Interface metric */
239 /* Interface Speed in Mb/s */
243 unsigned int mtu
; /* IPv4 MTU */
245 mtu6
; /* IPv6 MTU - probably, but not neccessarily same as mtu
248 /* Link-layer information and hardware address */
249 enum zebra_link_type ll_type
;
250 u_char hw_addr
[INTERFACE_HWADDR_MAX
];
253 /* interface bandwidth, kbits */
254 unsigned int bandwidth
;
256 /* Link parameters for Traffic Engineering */
257 struct if_link_params
*link_params
;
259 /* description of the interface. */
262 /* Distribute list. */
264 void *distribute_out
;
266 /* Connected address list. */
267 struct list
*connected
;
269 /* Neighbor connected address list. */
270 struct list
*nbr_connected
;
272 /* Daemon specific interface data pointer. */
275 char ptm_enable
; /* Should we look at ptm_status ? */
278 /* Statistics fileds. */
279 #ifdef HAVE_PROC_NET_DEV
280 struct if_stats stats
;
281 #endif /* HAVE_PROC_NET_DEV */
282 #ifdef HAVE_NET_RT_IFLIST
283 struct if_data stats
;
284 #endif /* HAVE_NET_RT_IFLIST */
286 struct route_node
*node
;
291 RB_HEAD(if_name_head
, interface
);
292 RB_PROTOTYPE(if_name_head
, interface
, name_entry
, if_cmp_func
);
293 RB_HEAD(if_index_head
, interface
);
294 RB_PROTOTYPE(if_index_head
, interface
, index_entry
, if_cmp_func
);
295 DECLARE_QOBJ_TYPE(interface
)
297 #define IFNAME_RB_INSERT(vrf, ifp) \
298 if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp))) \
300 "%s(%s): corruption detected -- interface with this " \
301 "name exists already in VRF %u!", \
302 __func__, (ifp)->name, (ifp)->vrf_id);
304 #define IFNAME_RB_REMOVE(vrf, ifp) \
305 if (RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)) == NULL) \
307 "%s(%s): corruption detected -- interface with this " \
308 "name doesn't exist in VRF %u!", \
309 __func__, (ifp)->name, (ifp)->vrf_id);
311 #define IFINDEX_RB_INSERT(vrf, ifp) \
312 if (RB_INSERT(if_index_head, &vrf->ifaces_by_index, (ifp))) \
314 "%s(%u): corruption detected -- interface with this " \
315 "ifindex exists already in VRF %u!", \
316 __func__, (ifp)->ifindex, (ifp)->vrf_id);
318 #define IFINDEX_RB_REMOVE(vrf, ifp) \
319 if (RB_REMOVE(if_index_head, &vrf->ifaces_by_index, (ifp)) == NULL) \
321 "%s(%u): corruption detected -- interface with this " \
322 "ifindex doesn't exist in VRF %u!", \
323 __func__, (ifp)->ifindex, (ifp)->vrf_id);
325 #define FOR_ALL_INTERFACES(vrf, ifp) \
327 RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name)
329 #define FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) \
330 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected))
332 /* called from the library code whenever interfaces are created/deleted
333 * note: interfaces may not be fully realized at that point; also they
334 * may not exist in the system (ifindex = IFINDEX_INTERNAL)
336 * priority values are important here, daemons should be at 0 while modules
337 * can use 1000+ so they run after the daemon has initialised daemon-specific
340 DECLARE_HOOK(if_add
, (struct interface
*ifp
), (ifp
))
341 DECLARE_KOOH(if_del
, (struct interface
*ifp
), (ifp
))
343 /* Connected address structure. */
345 /* Attached interface. */
346 struct interface
*ifp
;
348 /* Flags for configuration. */
350 #define ZEBRA_IFC_REAL (1 << 0)
351 #define ZEBRA_IFC_CONFIGURED (1 << 1)
352 #define ZEBRA_IFC_QUEUED (1 << 2)
354 The ZEBRA_IFC_REAL flag should be set if and only if this address
355 exists in the kernel and is actually usable. (A case where it exists
357 is not yet usable would be IPv6 with DAD)
358 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this
360 was configured by the user from inside quagga.
361 The ZEBRA_IFC_QUEUED flag should be set if and only if the address
363 in the kernel. It may and should be set although the address might
365 usable yet. (compare with ZEBRA_IFC_REAL)
368 /* Flags for connected address. */
370 #define ZEBRA_IFA_SECONDARY (1 << 0)
371 #define ZEBRA_IFA_PEER (1 << 1)
372 #define ZEBRA_IFA_UNNUMBERED (1 << 2)
373 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
374 a peer address has been configured. If this flag is set,
375 the destination field must contain the peer address.
376 Otherwise, if this flag is not set, the destination address
377 will either contain a broadcast address or be NULL.
380 /* Address of connected network. */
381 struct prefix
*address
;
383 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is
385 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
386 struct prefix
*destination
;
388 /* Label for Linux 2.2.X and upper. */
392 /* Nbr Connected address structure. */
393 struct nbr_connected
{
394 /* Attached interface. */
395 struct interface
*ifp
;
397 /* Address of connected network. */
398 struct prefix
*address
;
401 /* Does the destination field contain a peer address? */
402 #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
404 /* Prefix to insert into the RIB */
405 #define CONNECTED_PREFIX(C) \
406 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
408 /* Identifying address. We guess that if there's a peer address, but the
409 local address is in the same prefix, then the local address may be unique. */
410 #define CONNECTED_ID(C) \
411 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) \
415 /* There are some interface flags which are only supported by some
418 #ifndef IFF_NOTRAILERS
419 #define IFF_NOTRAILERS 0x0
420 #endif /* IFF_NOTRAILERS */
422 #define IFF_OACTIVE 0x0
423 #endif /* IFF_OACTIVE */
425 #define IFF_SIMPLEX 0x0
426 #endif /* IFF_SIMPLEX */
428 #define IFF_LINK0 0x0
429 #endif /* IFF_LINK0 */
431 #define IFF_LINK1 0x0
432 #endif /* IFF_LINK1 */
434 #define IFF_LINK2 0x0
435 #endif /* IFF_LINK2 */
437 #define IFF_NOXMIT 0x0
438 #endif /* IFF_NOXMIT */
440 #define IFF_NORTEXCH 0x0
441 #endif /* IFF_NORTEXCH */
444 #endif /* IFF_IPV4 */
447 #endif /* IFF_IPV6 */
449 #define IFF_VIRTUAL 0x0
450 #endif /* IFF_VIRTUAL */
453 extern int if_cmp_name_func(char *, char *);
456 * Passing in VRF_UNKNOWN is a valid thing to do, unless we
457 * are creating a new interface.
459 * This is useful for vrf route-leaking. So more than anything
460 * else think before you use VRF_UNKNOWN
462 extern void if_update_to_new_vrf(struct interface
*, vrf_id_t vrf_id
);
463 extern struct interface
*if_create(const char *name
, vrf_id_t vrf_id
);
464 extern struct interface
*if_lookup_by_index(ifindex_t
, vrf_id_t vrf_id
);
465 extern struct interface
*if_lookup_exact_address(void *matchaddr
, int family
,
467 extern struct connected
*if_lookup_address(void *matchaddr
, int family
,
469 extern struct interface
*if_lookup_prefix(struct prefix
*prefix
,
472 /* These 3 functions are to be used when the ifname argument is terminated
473 by a '\0' character: */
474 extern struct interface
*if_lookup_by_name_all_vrf(const char *ifname
);
475 extern struct interface
*if_lookup_by_name(const char *ifname
, vrf_id_t vrf_id
);
476 extern struct interface
*if_get_by_name(const char *ifname
, vrf_id_t vrf_id
,
478 extern void if_set_index(struct interface
*ifp
, ifindex_t ifindex
);
480 /* Delete the interface, but do not free the structure, and leave it in the
481 interface list. It is often advisable to leave the pseudo interface
482 structure because there may be configuration information attached. */
483 extern void if_delete_retain(struct interface
*);
485 /* Delete and free the interface structure: calls if_delete_retain and then
486 deletes it from the interface list and frees the structure. */
487 extern void if_delete(struct interface
*);
489 extern int if_is_up(struct interface
*);
490 extern int if_is_running(struct interface
*);
491 extern int if_is_operative(struct interface
*);
492 extern int if_is_no_ptm_operative(struct interface
*);
493 extern int if_is_loopback(struct interface
*);
494 extern int if_is_broadcast(struct interface
*);
495 extern int if_is_pointopoint(struct interface
*);
496 extern int if_is_multicast(struct interface
*);
497 extern void if_cmd_init(void);
499 extern void if_terminate(struct vrf
*vrf
);
500 extern void if_dump_all(void);
501 extern const char *if_flag_dump(unsigned long);
502 extern const char *if_link_type_str(enum zebra_link_type
);
504 /* Please use ifindex2ifname instead of if_indextoname where possible;
505 ifindex2ifname uses internal interface info, whereas if_indextoname must
506 make a system call. */
507 extern const char *ifindex2ifname(ifindex_t
, vrf_id_t vrf_id
);
509 /* Please use ifname2ifindex instead of if_nametoindex where possible;
510 ifname2ifindex uses internal interface info, whereas if_nametoindex must
511 make a system call. */
512 extern ifindex_t
ifname2ifindex(const char *ifname
, vrf_id_t vrf_id
);
514 /* Connected address functions. */
515 extern struct connected
*connected_new(void);
516 extern void connected_free(struct connected
*);
517 extern void connected_add(struct interface
*, struct connected
*);
518 extern struct connected
*
519 connected_add_by_prefix(struct interface
*, struct prefix
*, struct prefix
*);
520 extern struct connected
*connected_delete_by_prefix(struct interface
*,
522 extern struct connected
*connected_lookup_prefix(struct interface
*,
524 extern struct connected
*connected_lookup_prefix_exact(struct interface
*,
526 extern struct nbr_connected
*nbr_connected_new(void);
527 extern void nbr_connected_free(struct nbr_connected
*);
528 struct nbr_connected
*nbr_connected_check(struct interface
*, struct prefix
*);
530 /* link parameters */
531 struct if_link_params
*if_link_params_get(struct interface
*);
532 void if_link_params_free(struct interface
*);
534 #endif /* _ZEBRA_IF_H */