]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.h
[0.99] Bump version to 0.99.6
[mirror_frr.git] / lib / if.h
CommitLineData
718e3744 1/* Interface related header.
2 Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation; either version 2, or (at your
9option) any later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#ifndef _ZEBRA_IF_H
22#define _ZEBRA_IF_H
23
24#include "linklist.h"
25
26/*
27 Interface name length.
28
29 Linux define value in /usr/include/linux/if.h.
30 #define IFNAMSIZ 16
31
32 FreeBSD define value in /usr/include/net/if.h.
33 #define IFNAMSIZ 16
34*/
35
36#define INTERFACE_NAMSIZ 20
37#define INTERFACE_HWADDR_MAX 20
38
718e3744 39#ifdef HAVE_PROC_NET_DEV
40struct if_stats
41{
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;
54
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;
68};
69#endif /* HAVE_PROC_NET_DEV */
70
71/* Interface structure */
72struct interface
73{
d2fc8896 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.
80 */
718e3744 81 char name[INTERFACE_NAMSIZ + 1];
82
d2fc8896 83 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
84 deleted interfaces). */
718e3744 85 unsigned int ifindex;
d2fc8896 86#define IFINDEX_INTERNAL 0
718e3744 87
88 /* Zebra internal interface status */
89 u_char status;
90#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
91#define ZEBRA_INTERFACE_SUB (1 << 1)
2e3b2e47 92#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
718e3744 93
94 /* Interface flags. */
c77d4546 95 uint64_t flags;
718e3744 96
97 /* Interface metric */
98 int metric;
99
100 /* Interface MTU. */
c9eca01b 101 unsigned int mtu; /* IPv4 MTU */
102 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
718e3744 103
104 /* Hardware address. */
105#ifdef HAVE_SOCKADDR_DL
106 struct sockaddr_dl sdl;
107#else
108 unsigned short hw_type;
109 u_char hw_addr[INTERFACE_HWADDR_MAX];
110 int hw_addr_len;
111#endif /* HAVE_SOCKADDR_DL */
112
113 /* interface bandwidth, kbits */
114 unsigned int bandwidth;
115
116 /* description of the interface. */
117 char *desc;
118
119 /* Distribute list. */
120 void *distribute_in;
121 void *distribute_out;
122
123 /* Connected address list. */
52dc7ee6 124 struct list *connected;
718e3744 125
126 /* Daemon specific interface data pointer. */
127 void *info;
128
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 */
136};
137
138/* Connected address structure. */
139struct connected
140{
141 /* Attached interface. */
142 struct interface *ifp;
143
144 /* Flags for configuration. */
145 u_char conf;
146#define ZEBRA_IFC_REAL (1 << 0)
147#define ZEBRA_IFC_CONFIGURED (1 << 1)
9c37851e
AS
148 /*
149 The ZEBRA_IFC_REAL flag should be set if and only if this address
150 exists in the kernel.
151 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
152 was configured by the user from inside quagga.
153 */
718e3744 154
155 /* Flags for connected address. */
156 u_char flags;
157#define ZEBRA_IFA_SECONDARY (1 << 0)
158
159 /* Address of connected network. */
160 struct prefix *address;
3fb9cd6e 161 struct prefix *destination; /* broadcast or peer address; may be NULL */
718e3744 162
163 /* Label for Linux 2.2.X and upper. */
164 char *label;
165};
166
3fb9cd6e 167/* Given an IPV4 struct connected, this macro determines whether a /32
168 peer address has been supplied (i.e. there is no subnet assigned) */
169#define CONNECTED_DEST_HOST(C) \
170 ((C)->destination && ((C)->address->prefixlen == IPV4_MAX_PREFIXLEN))
171
172/* Given an IPV4 struct connected, this macro determins whether it is
173 a point-to-point link with a /32 peer address (i.e. there
174 is no dedicated subnet for the PtP link) */
175#define CONNECTED_POINTOPOINT_HOST(C) \
176 (((C)->ifp->flags & IFF_POINTOPOINT) && CONNECTED_DEST_HOST(C))
177
718e3744 178/* Interface hook sort. */
179#define IF_NEW_HOOK 0
180#define IF_DELETE_HOOK 1
181
182/* There are some interface flags which are only supported by some
183 operating system. */
184
185#ifndef IFF_NOTRAILERS
186#define IFF_NOTRAILERS 0x0
187#endif /* IFF_NOTRAILERS */
188#ifndef IFF_OACTIVE
189#define IFF_OACTIVE 0x0
190#endif /* IFF_OACTIVE */
191#ifndef IFF_SIMPLEX
192#define IFF_SIMPLEX 0x0
193#endif /* IFF_SIMPLEX */
194#ifndef IFF_LINK0
195#define IFF_LINK0 0x0
196#endif /* IFF_LINK0 */
197#ifndef IFF_LINK1
198#define IFF_LINK1 0x0
199#endif /* IFF_LINK1 */
200#ifndef IFF_LINK2
201#define IFF_LINK2 0x0
202#endif /* IFF_LINK2 */
4ba9b924 203#ifndef IFF_NOXMIT
204#define IFF_NOXMIT 0x0
205#endif /* IFF_NOXMIT */
206#ifndef IFF_NORTEXCH
207#define IFF_NORTEXCH 0x0
208#endif /* IFF_NORTEXCH */
209#ifndef IFF_IPV4
210#define IFF_IPV4 0x0
211#endif /* IFF_IPV4 */
212#ifndef IFF_IPV6
213#define IFF_IPV6 0x0
214#endif /* IFF_IPV6 */
215#ifndef IFF_VIRTUAL
216#define IFF_VIRTUAL 0x0
217#endif /* IFF_VIRTUAL */
718e3744 218
219/* Prototypes. */
8cc4198f 220extern int if_cmp_func (struct interface *, struct interface *);
221extern struct interface *if_create (const char *name, int namelen);
222extern struct interface *if_lookup_by_index (unsigned int);
223extern struct interface *if_lookup_exact_address (struct in_addr);
224extern struct interface *if_lookup_address (struct in_addr);
a349198f 225
08dbfb69 226/* These 2 functions are to be used when the ifname argument is terminated
227 by a '\0' character: */
8cc4198f 228extern struct interface *if_lookup_by_name (const char *ifname);
229extern struct interface *if_get_by_name (const char *ifname);
08dbfb69 230
231/* For these 2 functions, the namelen argument should be the precise length
232 of the ifname string (not counting any optional trailing '\0' character).
233 In most cases, strnlen should be used to calculate the namelen value. */
234extern struct interface *if_lookup_by_name_len(const char *ifname,
a349198f 235 size_t namelen);
08dbfb69 236extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
a349198f 237
238
d2fc8896 239/* Delete the interface, but do not free the structure, and leave it in the
240 interface list. It is often advisable to leave the pseudo interface
241 structure because there may be configuration information attached. */
242extern void if_delete_retain (struct interface *);
243
244/* Delete and free the interface structure: calls if_delete_retain and then
245 deletes it from the interface list and frees the structure. */
246extern void if_delete (struct interface *);
247
8cc4198f 248extern int if_is_up (struct interface *);
249extern int if_is_running (struct interface *);
250extern int if_is_operative (struct interface *);
251extern int if_is_loopback (struct interface *);
252extern int if_is_broadcast (struct interface *);
253extern int if_is_pointopoint (struct interface *);
254extern int if_is_multicast (struct interface *);
255extern void if_add_hook (int, int (*)(struct interface *));
256extern void if_init (void);
257extern void if_dump_all (void);
847947f2 258extern const char *if_flag_dump(unsigned long);
718e3744 259
d2fc8896 260/* Please use ifindex2ifname instead of if_indextoname where possible;
261 ifindex2ifname uses internal interface info, whereas if_indextoname must
262 make a system call. */
8cc4198f 263extern const char *ifindex2ifname (unsigned int);
d2fc8896 264
265/* Please use ifname2ifindex instead of if_nametoindex where possible;
266 ifname2ifindex uses internal interface info, whereas if_nametoindex must
267 make a system call. */
268extern unsigned int ifname2ifindex(const char *ifname);
269
718e3744 270/* Connected address functions. */
8cc4198f 271extern struct connected *connected_new (void);
272extern void connected_free (struct connected *);
273extern void connected_add (struct interface *, struct connected *);
274extern struct connected *connected_add_by_prefix (struct interface *,
4a7aac1b 275 struct prefix *,
276 struct prefix *);
8cc4198f 277extern struct connected *connected_delete_by_prefix (struct interface *,
4a7aac1b 278 struct prefix *);
8cc4198f 279extern struct connected *connected_lookup_address (struct interface *,
4a7aac1b 280 struct in_addr);
718e3744 281
282#ifndef HAVE_IF_NAMETOINDEX
8cc4198f 283extern unsigned int if_nametoindex (const char *);
718e3744 284#endif
285#ifndef HAVE_IF_INDEXTONAME
8cc4198f 286extern char *if_indextoname (unsigned int, char *);
718e3744 287#endif
288
289/* Exported variables. */
52dc7ee6 290extern struct list *iflist;
718e3744 291extern struct cmd_element interface_desc_cmd;
292extern struct cmd_element no_interface_desc_cmd;
293extern struct cmd_element interface_cmd;
32d2463c 294extern struct cmd_element no_interface_cmd;
718e3744 295extern struct cmd_element interface_pseudo_cmd;
296extern struct cmd_element no_interface_pseudo_cmd;
478ccfd6 297extern struct cmd_element show_address_cmd;
718e3744 298
299#endif /* _ZEBRA_IF_H */