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_SOCKADDR_DL
106
struct sockaddr_dl sdl;
108
unsigned short hw_type;
109
u_char hw_addr[INTERFACE_HWADDR_MAX];
111
#endif /* HAVE_SOCKADDR_DL */
113
/* interface bandwidth, kbits */
114
unsigned int bandwidth;
116
/* description of the interface. */
119
/* Distribute list. */
121
void *distribute_out;
123
/* Connected address list. */
124
struct list *connected;
126
/* Daemon specific interface data pointer. */
129
/* Statistics fileds. */
130
#ifdef HAVE_PROC_NET_DEV
131
struct if_stats stats;
132
#endif /* HAVE_PROC_NET_DEV */
133
#ifdef HAVE_NET_RT_IFLIST
134
struct if_data stats;
135
#endif /* HAVE_NET_RT_IFLIST */
138
/* Connected address structure. */
141
/* Attached interface. */
142
struct interface *ifp;
144
/* Flags for configuration. */
146
#define ZEBRA_IFC_REAL (1 << 0)
147
#define ZEBRA_IFC_CONFIGURED (1 << 1)
149
/* Flags for connected address. */
151
#define ZEBRA_IFA_SECONDARY (1 << 0)
153
/* Address of connected network. */
154
struct prefix *address;
155
struct prefix *destination; /* broadcast or peer address; may be NULL */
157
/* Label for Linux 2.2.X and upper. */
161
/* Given an IPV4 struct connected, this macro determines whether a /32
162
peer address has been supplied (i.e. there is no subnet assigned) */
163
#define CONNECTED_DEST_HOST(C) \
164
((C)->destination && ((C)->address->prefixlen == IPV4_MAX_PREFIXLEN))
166
/* Given an IPV4 struct connected, this macro determins whether it is
167
a point-to-point link with a /32 peer address (i.e. there
168
is no dedicated subnet for the PtP link) */
169
#define CONNECTED_POINTOPOINT_HOST(C) \
170
(((C)->ifp->flags & IFF_POINTOPOINT) && CONNECTED_DEST_HOST(C))
172
/* Interface hook sort. */
173
#define IF_NEW_HOOK 0
174
#define IF_DELETE_HOOK 1
176
/* There are some interface flags which are only supported by some
179
#ifndef IFF_NOTRAILERS
180
#define IFF_NOTRAILERS 0x0
181
#endif /* IFF_NOTRAILERS */
183
#define IFF_OACTIVE 0x0
184
#endif /* IFF_OACTIVE */
186
#define IFF_SIMPLEX 0x0
187
#endif /* IFF_SIMPLEX */
189
#define IFF_LINK0 0x0
190
#endif /* IFF_LINK0 */
192
#define IFF_LINK1 0x0
193
#endif /* IFF_LINK1 */
195
#define IFF_LINK2 0x0
196
#endif /* IFF_LINK2 */
198
#define IFF_NOXMIT 0x0
199
#endif /* IFF_NOXMIT */
201
#define IFF_NORTEXCH 0x0
202
#endif /* IFF_NORTEXCH */
205
#endif /* IFF_IPV4 */
208
#endif /* IFF_IPV6 */
210
#define IFF_VIRTUAL 0x0
211
#endif /* IFF_VIRTUAL */
214
int if_cmp_func (struct interface *, struct interface *);
215
struct interface *if_create (const char *name, int namelen);
216
struct interface *if_lookup_by_index (unsigned int);
217
struct interface *if_lookup_exact_address (struct in_addr);
218
struct interface *if_lookup_address (struct in_addr);
220
/* These 2 functions are to be used when the ifname argument is terminated
221
by a '\0' character: */
222
struct interface *if_lookup_by_name (const char *ifname);
223
struct interface *if_get_by_name (const char *ifname);
225
/* For these 2 functions, the namelen argument should be the precise length
226
of the ifname string (not counting any optional trailing '\0' character).
227
In most cases, strnlen should be used to calculate the namelen value. */
228
extern struct interface *if_lookup_by_name_len(const char *ifname,
230
extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
233
/* Delete the interface, but do not free the structure, and leave it in the
234
interface list. It is often advisable to leave the pseudo interface
235
structure because there may be configuration information attached. */
236
extern void if_delete_retain (struct interface *);
238
/* Delete and free the interface structure: calls if_delete_retain and then
239
deletes it from the interface list and frees the structure. */
240
extern void if_delete (struct interface *);
242
int if_is_up (struct interface *);
243
int if_is_running (struct interface *);
244
int if_is_operative (struct interface *);
245
int if_is_loopback (struct interface *);
246
int if_is_broadcast (struct interface *);
247
int if_is_pointopoint (struct interface *);
248
int if_is_multicast (struct interface *);
249
void if_add_hook (int, int (*)(struct interface *));
252
extern const char *if_flag_dump(unsigned long);
254
/* Please use ifindex2ifname instead of if_indextoname where possible;
255
ifindex2ifname uses internal interface info, whereas if_indextoname must
256
make a system call. */
257
extern char *ifindex2ifname (unsigned int);
259
/* Please use ifname2ifindex instead of if_nametoindex where possible;
260
ifname2ifindex uses internal interface info, whereas if_nametoindex must
261
make a system call. */
262
extern unsigned int ifname2ifindex(const char *ifname);
264
/* Connected address functions. */
265
struct connected *connected_new ();
266
void connected_free (struct connected *);
267
void connected_add (struct interface *, struct connected *);
268
struct connected *connected_add_by_prefix (struct interface *,
271
struct connected *connected_delete_by_prefix (struct interface *,
273
struct connected *connected_lookup_address (struct interface *,
276
#ifndef HAVE_IF_NAMETOINDEX
277
unsigned int if_nametoindex (const char *);
279
#ifndef HAVE_IF_INDEXTONAME
280
char *if_indextoname (unsigned int, char *);
283
/* Exported variables. */
284
extern struct list *iflist;
285
extern struct cmd_element interface_desc_cmd;
286
extern struct cmd_element no_interface_desc_cmd;
287
extern struct cmd_element interface_cmd;
288
extern struct cmd_element no_interface_cmd;
289
extern struct cmd_element interface_pseudo_cmd;
290
extern struct cmd_element no_interface_pseudo_cmd;
292
#endif /* _ZEBRA_IF_H */