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 name length.
29 Linux define value in /usr/include/linux/if.h.
32 FreeBSD define value in /usr/include/net/if.h.
36 #define INTERFACE_NAMSIZ 20
37 #define INTERFACE_HWADDR_MAX 20
39 #ifdef HAVE_PROC_NET_DEV
42 unsigned long rx_packets
; /* total packets received */
43 unsigned long tx_packets
; /* total packets transmitted */
44 unsigned long rx_bytes
; /* total bytes received */
45 unsigned long tx_bytes
; /* total bytes transmitted */
46 unsigned long rx_errors
; /* bad packets received */
47 unsigned long tx_errors
; /* packet transmit problems */
48 unsigned long rx_dropped
; /* no space in linux buffers */
49 unsigned long tx_dropped
; /* no space available in linux */
50 unsigned long rx_multicast
; /* multicast packets received */
51 unsigned long rx_compressed
;
52 unsigned long tx_compressed
;
53 unsigned long collisions
;
55 /* detailed rx_errors: */
56 unsigned long rx_length_errors
;
57 unsigned long rx_over_errors
; /* receiver ring buff overflow */
58 unsigned long rx_crc_errors
; /* recved pkt with crc error */
59 unsigned long rx_frame_errors
; /* recv'd frame alignment error */
60 unsigned long rx_fifo_errors
; /* recv'r fifo overrun */
61 unsigned long rx_missed_errors
; /* receiver missed packet */
62 /* detailed tx_errors */
63 unsigned long tx_aborted_errors
;
64 unsigned long tx_carrier_errors
;
65 unsigned long tx_fifo_errors
;
66 unsigned long tx_heartbeat_errors
;
67 unsigned long tx_window_errors
;
69 #endif /* HAVE_PROC_NET_DEV */
71 /* Interface structure */
74 /* Interface name. This should probably never be changed after the
75 interface is created, because the configuration info for this interface
76 is associated with this structure. For that reason, the interface
77 should also never be deleted (to avoid losing configuration info).
78 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
79 interface does not exist in the kernel.
81 char name
[INTERFACE_NAMSIZ
+ 1];
83 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
84 deleted interfaces). */
86 #define IFINDEX_INTERNAL 0
88 /* Zebra internal interface status */
90 #define ZEBRA_INTERFACE_ACTIVE (1 << 0)
91 #define ZEBRA_INTERFACE_SUB (1 << 1)
92 #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
94 /* Interface flags. */
97 /* Interface metric */
101 unsigned int mtu
; /* IPv4 MTU */
102 unsigned int mtu6
; /* IPv6 MTU - probably, but not neccessarily same as mtu */
104 /* Hardware address. */
105 #ifdef HAVE_STRUCT_SOCKADDR_DL
107 /* note that sdl_storage is never accessed, it only exists to make space.
108 * all actual uses refer to sdl - but use sizeof(sdl_storage)! this fits
109 * best with C aliasing rules. */
110 struct sockaddr_dl sdl
;
111 struct sockaddr_storage sdl_storage
;
114 unsigned short hw_type
;
115 u_char hw_addr
[INTERFACE_HWADDR_MAX
];
117 #endif /* HAVE_STRUCT_SOCKADDR_DL */
119 /* interface bandwidth, kbits */
120 unsigned int bandwidth
;
122 /* description of the interface. */
125 /* Distribute list. */
127 void *distribute_out
;
129 /* Connected address list. */
130 struct list
*connected
;
132 /* Neighbor connected address list. */
133 struct list
*nbr_connected
;
135 /* Daemon specific interface data pointer. */
138 char ptm_enable
; /* Should we look at ptm_status ? */
141 /* Statistics fileds. */
142 #ifdef HAVE_PROC_NET_DEV
143 struct if_stats stats
;
144 #endif /* HAVE_PROC_NET_DEV */
145 #ifdef HAVE_NET_RT_IFLIST
146 struct if_data stats
;
147 #endif /* HAVE_NET_RT_IFLIST */
152 /* Connected address structure. */
155 /* Attached interface. */
156 struct interface
*ifp
;
158 /* Flags for configuration. */
160 #define ZEBRA_IFC_REAL (1 << 0)
161 #define ZEBRA_IFC_CONFIGURED (1 << 1)
162 #define ZEBRA_IFC_QUEUED (1 << 2)
164 The ZEBRA_IFC_REAL flag should be set if and only if this address
165 exists in the kernel and is actually usable. (A case where it exists but
166 is not yet usable would be IPv6 with DAD)
167 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
168 was configured by the user from inside quagga.
169 The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
170 in the kernel. It may and should be set although the address might not be
171 usable yet. (compare with ZEBRA_IFC_REAL)
174 /* Flags for connected address. */
176 #define ZEBRA_IFA_SECONDARY (1 << 0)
177 #define ZEBRA_IFA_PEER (1 << 1)
178 #define ZEBRA_IFA_UNNUMBERED (1 << 2)
179 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
180 a peer address has been configured. If this flag is set,
181 the destination field must contain the peer address.
182 Otherwise, if this flag is not set, the destination address
183 will either contain a broadcast address or be NULL.
186 /* Address of connected network. */
187 struct prefix
*address
;
189 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
190 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
191 struct prefix
*destination
;
193 /* A list of unnumbered IFCs borrowing the address from me */
194 struct list
*unnumbered
;
196 /* Pointer to the anchor IFC if I'm unnumbered */
197 struct connected
*anchor
;
199 /* Label for Linux 2.2.X and upper. */
203 /* Nbr Connected address structure. */
206 /* Attached interface. */
207 struct interface
*ifp
;
209 /* Address of connected network. */
210 struct prefix
*address
;
213 /* Does the destination field contain a peer address? */
214 #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
216 /* Prefix to insert into the RIB */
217 #define CONNECTED_PREFIX(C) \
218 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
220 /* Identifying address. We guess that if there's a peer address, but the
221 local address is in the same prefix, then the local address may be unique. */
222 #define CONNECTED_ID(C) \
223 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
224 (C)->destination : (C)->address)
226 /* Interface hook sort. */
227 #define IF_NEW_HOOK 0
228 #define IF_DELETE_HOOK 1
230 /* There are some interface flags which are only supported by some
233 #ifndef IFF_NOTRAILERS
234 #define IFF_NOTRAILERS 0x0
235 #endif /* IFF_NOTRAILERS */
237 #define IFF_OACTIVE 0x0
238 #endif /* IFF_OACTIVE */
240 #define IFF_SIMPLEX 0x0
241 #endif /* IFF_SIMPLEX */
243 #define IFF_LINK0 0x0
244 #endif /* IFF_LINK0 */
246 #define IFF_LINK1 0x0
247 #endif /* IFF_LINK1 */
249 #define IFF_LINK2 0x0
250 #endif /* IFF_LINK2 */
252 #define IFF_NOXMIT 0x0
253 #endif /* IFF_NOXMIT */
255 #define IFF_NORTEXCH 0x0
256 #endif /* IFF_NORTEXCH */
259 #endif /* IFF_IPV4 */
262 #endif /* IFF_IPV6 */
264 #define IFF_VIRTUAL 0x0
265 #endif /* IFF_VIRTUAL */
268 extern int if_cmp_func (struct interface
*, struct interface
*);
269 extern struct interface
*if_create (const char *name
, int namelen
);
270 extern struct interface
*if_lookup_by_index (unsigned int);
271 extern struct interface
*if_lookup_exact_address (void *matchaddr
, int family
);
272 extern struct interface
*if_lookup_address (void *matchaddr
, int family
);
273 extern struct interface
*if_lookup_prefix (struct prefix
*prefix
);
274 extern struct connected
*if_anchor_lookup_by_address (struct in_addr src
);
276 extern struct interface
*if_create_vrf (const char *name
, int namelen
,
278 extern struct interface
*if_lookup_by_index_vrf (unsigned int,
280 extern struct interface
*if_lookup_exact_address_vrf (void *matchaddr
, int family
,
282 extern struct interface
*if_lookup_address_vrf (void *matchaddr
, int family
,
284 extern struct interface
*if_lookup_prefix_vrf (struct prefix
*prefix
,
287 /* These 2 functions are to be used when the ifname argument is terminated
288 by a '\0' character: */
289 extern struct interface
*if_lookup_by_name (const char *ifname
);
290 extern struct interface
*if_get_by_name (const char *ifname
);
292 extern struct interface
*if_lookup_by_name_vrf (const char *ifname
,
294 extern struct interface
*if_get_by_name_vrf (const char *ifname
,
297 /* For these 2 functions, the namelen argument should be the precise length
298 of the ifname string (not counting any optional trailing '\0' character).
299 In most cases, strnlen should be used to calculate the namelen value. */
300 extern struct interface
*if_lookup_by_name_len(const char *ifname
,
302 extern struct interface
*if_get_by_name_len(const char *ifname
,size_t namelen
);
304 extern struct interface
*if_lookup_by_name_len_vrf(const char *ifname
,
305 size_t namelen
, vrf_id_t vrf_id
);
306 extern struct interface
*if_get_by_name_len_vrf(const char *ifname
,
307 size_t namelen
, vrf_id_t vrf_id
);
310 /* Delete the interface, but do not free the structure, and leave it in the
311 interface list. It is often advisable to leave the pseudo interface
312 structure because there may be configuration information attached. */
313 extern void if_delete_retain (struct interface
*);
315 /* Delete and free the interface structure: calls if_delete_retain and then
316 deletes it from the interface list and frees the structure. */
317 extern void if_delete (struct interface
*);
319 extern int if_is_up (struct interface
*);
320 extern int if_is_running (struct interface
*);
321 extern int if_is_operative (struct interface
*);
322 extern int if_is_no_ptm_operative (struct interface
*);
323 extern int if_is_loopback (struct interface
*);
324 extern int if_is_broadcast (struct interface
*);
325 extern int if_is_pointopoint (struct interface
*);
326 extern int if_is_multicast (struct interface
*);
327 extern void if_add_hook (int, int (*)(struct interface
*));
328 extern void if_init (vrf_id_t
, struct list
**);
329 extern void if_terminate (vrf_id_t
, struct list
**);
330 extern void if_dump_all (void);
331 extern const char *if_flag_dump(unsigned long);
333 /* Please use ifindex2ifname instead of if_indextoname where possible;
334 ifindex2ifname uses internal interface info, whereas if_indextoname must
335 make a system call. */
336 extern const char *ifindex2ifname (unsigned int);
337 extern const char *ifindex2ifname_vrf (unsigned int, vrf_id_t vrf_id
);
339 /* Please use ifname2ifindex instead of if_nametoindex where possible;
340 ifname2ifindex uses internal interface info, whereas if_nametoindex must
341 make a system call. */
342 extern unsigned int ifname2ifindex(const char *ifname
);
343 extern unsigned int ifname2ifindex_vrf(const char *ifname
, vrf_id_t vrf_id
);
345 /* Connected address functions. */
346 extern struct connected
*connected_new (void);
347 extern void connected_free (struct connected
*);
348 extern void connected_add (struct interface
*, struct connected
*);
349 extern struct connected
*connected_add_by_prefix (struct interface
*,
352 extern struct connected
*connected_delete_by_prefix (struct interface
*,
354 extern struct connected
*connected_lookup_address (struct interface
*,
356 extern struct nbr_connected
*nbr_connected_new (void);
357 extern void nbr_connected_free (struct nbr_connected
*);
358 struct nbr_connected
*nbr_connected_check (struct interface
*, struct prefix
*);
360 #ifndef HAVE_IF_NAMETOINDEX
361 extern unsigned int if_nametoindex (const char *);
363 #ifndef HAVE_IF_INDEXTONAME
364 extern char *if_indextoname (unsigned int, char *);
367 /* Exported variables. */
368 extern struct list
*iflist
;
369 extern struct cmd_element interface_desc_cmd
;
370 extern struct cmd_element no_interface_desc_cmd
;
371 extern struct cmd_element interface_cmd
;
372 extern struct cmd_element no_interface_cmd
;
373 extern struct cmd_element interface_vrf_cmd
;
374 extern struct cmd_element no_interface_vrf_cmd
;
375 extern struct cmd_element interface_pseudo_cmd
;
376 extern struct cmd_element no_interface_pseudo_cmd
;
377 extern struct cmd_element show_address_cmd
;
378 extern struct cmd_element show_address_vrf_cmd
;
379 extern struct cmd_element show_address_vrf_all_cmd
;
381 #endif /* _ZEBRA_IF_H */