]>
Commit | Line | Data |
---|---|---|
1 | /* Interface related header. | |
2 | Copyright (C) 1997, 98, 99 Kunihiro Ishiguro | |
3 | ||
4 | This file is part of GNU Zebra. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
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 | ||
39 | #ifdef HAVE_PROC_NET_DEV | |
40 | struct 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 */ | |
72 | struct interface | |
73 | { | |
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 | */ | |
81 | char name[INTERFACE_NAMSIZ + 1]; | |
82 | ||
83 | /* Interface index (should be IFINDEX_INTERNAL for non-kernel or | |
84 | deleted interfaces). */ | |
85 | unsigned int ifindex; | |
86 | #define IFINDEX_INTERNAL 0 | |
87 | ||
88 | /* Zebra internal interface status */ | |
89 | u_char status; | |
90 | #define ZEBRA_INTERFACE_ACTIVE (1 << 0) | |
91 | #define ZEBRA_INTERFACE_SUB (1 << 1) | |
92 | #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2) | |
93 | ||
94 | /* Interface flags. */ | |
95 | uint64_t flags; | |
96 | ||
97 | /* Interface metric */ | |
98 | int metric; | |
99 | ||
100 | /* Interface MTU. */ | |
101 | unsigned int mtu; /* IPv4 MTU */ | |
102 | unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */ | |
103 | ||
104 | /* Hardware address. */ | |
105 | #ifdef HAVE_STRUCT_SOCKADDR_DL | |
106 | union { | |
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; | |
112 | }; | |
113 | #else | |
114 | unsigned short hw_type; | |
115 | u_char hw_addr[INTERFACE_HWADDR_MAX]; | |
116 | int hw_addr_len; | |
117 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ | |
118 | ||
119 | /* interface bandwidth, kbits */ | |
120 | unsigned int bandwidth; | |
121 | ||
122 | /* description of the interface. */ | |
123 | char *desc; | |
124 | ||
125 | /* Distribute list. */ | |
126 | void *distribute_in; | |
127 | void *distribute_out; | |
128 | ||
129 | /* Connected address list. */ | |
130 | struct list *connected; | |
131 | ||
132 | /* Neighbor connected address list. */ | |
133 | struct list *nbr_connected; | |
134 | ||
135 | /* Daemon specific interface data pointer. */ | |
136 | void *info; | |
137 | ||
138 | /* Statistics fileds. */ | |
139 | #ifdef HAVE_PROC_NET_DEV | |
140 | struct if_stats stats; | |
141 | #endif /* HAVE_PROC_NET_DEV */ | |
142 | #ifdef HAVE_NET_RT_IFLIST | |
143 | struct if_data stats; | |
144 | #endif /* HAVE_NET_RT_IFLIST */ | |
145 | }; | |
146 | ||
147 | /* Connected address structure. */ | |
148 | struct connected | |
149 | { | |
150 | /* Attached interface. */ | |
151 | struct interface *ifp; | |
152 | ||
153 | /* Flags for configuration. */ | |
154 | u_char conf; | |
155 | #define ZEBRA_IFC_REAL (1 << 0) | |
156 | #define ZEBRA_IFC_CONFIGURED (1 << 1) | |
157 | #define ZEBRA_IFC_QUEUED (1 << 2) | |
158 | /* | |
159 | The ZEBRA_IFC_REAL flag should be set if and only if this address | |
160 | exists in the kernel and is actually usable. (A case where it exists but | |
161 | is not yet usable would be IPv6 with DAD) | |
162 | The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address | |
163 | was configured by the user from inside quagga. | |
164 | The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists | |
165 | in the kernel. It may and should be set although the address might not be | |
166 | usable yet. (compare with ZEBRA_IFC_REAL) | |
167 | */ | |
168 | ||
169 | /* Flags for connected address. */ | |
170 | u_char flags; | |
171 | #define ZEBRA_IFA_SECONDARY (1 << 0) | |
172 | #define ZEBRA_IFA_PEER (1 << 1) | |
173 | /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if | |
174 | a peer address has been configured. If this flag is set, | |
175 | the destination field must contain the peer address. | |
176 | Otherwise, if this flag is not set, the destination address | |
177 | will either contain a broadcast address or be NULL. | |
178 | */ | |
179 | ||
180 | /* Address of connected network. */ | |
181 | struct prefix *address; | |
182 | ||
183 | /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set. | |
184 | Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */ | |
185 | struct prefix *destination; | |
186 | ||
187 | /* Label for Linux 2.2.X and upper. */ | |
188 | char *label; | |
189 | }; | |
190 | ||
191 | /* Nbr Connected address structure. */ | |
192 | struct nbr_connected | |
193 | { | |
194 | /* Attached interface. */ | |
195 | struct interface *ifp; | |
196 | ||
197 | /* Address of connected network. */ | |
198 | struct prefix *address; | |
199 | }; | |
200 | ||
201 | /* Does the destination field contain a peer address? */ | |
202 | #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER) | |
203 | ||
204 | /* Prefix to insert into the RIB */ | |
205 | #define CONNECTED_PREFIX(C) \ | |
206 | (CONNECTED_PEER(C) ? (C)->destination : (C)->address) | |
207 | ||
208 | /* Identifying address. We guess that if there's a peer address, but the | |
209 | local address is in the same prefix, then the local address may be unique. */ | |
210 | #define CONNECTED_ID(C) \ | |
211 | ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\ | |
212 | (C)->destination : (C)->address) | |
213 | ||
214 | /* Interface hook sort. */ | |
215 | #define IF_NEW_HOOK 0 | |
216 | #define IF_DELETE_HOOK 1 | |
217 | ||
218 | /* There are some interface flags which are only supported by some | |
219 | operating system. */ | |
220 | ||
221 | #ifndef IFF_NOTRAILERS | |
222 | #define IFF_NOTRAILERS 0x0 | |
223 | #endif /* IFF_NOTRAILERS */ | |
224 | #ifndef IFF_OACTIVE | |
225 | #define IFF_OACTIVE 0x0 | |
226 | #endif /* IFF_OACTIVE */ | |
227 | #ifndef IFF_SIMPLEX | |
228 | #define IFF_SIMPLEX 0x0 | |
229 | #endif /* IFF_SIMPLEX */ | |
230 | #ifndef IFF_LINK0 | |
231 | #define IFF_LINK0 0x0 | |
232 | #endif /* IFF_LINK0 */ | |
233 | #ifndef IFF_LINK1 | |
234 | #define IFF_LINK1 0x0 | |
235 | #endif /* IFF_LINK1 */ | |
236 | #ifndef IFF_LINK2 | |
237 | #define IFF_LINK2 0x0 | |
238 | #endif /* IFF_LINK2 */ | |
239 | #ifndef IFF_NOXMIT | |
240 | #define IFF_NOXMIT 0x0 | |
241 | #endif /* IFF_NOXMIT */ | |
242 | #ifndef IFF_NORTEXCH | |
243 | #define IFF_NORTEXCH 0x0 | |
244 | #endif /* IFF_NORTEXCH */ | |
245 | #ifndef IFF_IPV4 | |
246 | #define IFF_IPV4 0x0 | |
247 | #endif /* IFF_IPV4 */ | |
248 | #ifndef IFF_IPV6 | |
249 | #define IFF_IPV6 0x0 | |
250 | #endif /* IFF_IPV6 */ | |
251 | #ifndef IFF_VIRTUAL | |
252 | #define IFF_VIRTUAL 0x0 | |
253 | #endif /* IFF_VIRTUAL */ | |
254 | ||
255 | /* Prototypes. */ | |
256 | extern int if_cmp_func (struct interface *, struct interface *); | |
257 | extern struct interface *if_create (const char *name, int namelen); | |
258 | extern struct interface *if_lookup_by_index (unsigned int); | |
259 | extern struct interface *if_lookup_exact_address (struct in_addr); | |
260 | extern struct interface *if_lookup_address (struct in_addr); | |
261 | extern struct interface *if_lookup_prefix (struct prefix *prefix); | |
262 | ||
263 | /* These 2 functions are to be used when the ifname argument is terminated | |
264 | by a '\0' character: */ | |
265 | extern struct interface *if_lookup_by_name (const char *ifname); | |
266 | extern struct interface *if_get_by_name (const char *ifname); | |
267 | ||
268 | /* For these 2 functions, the namelen argument should be the precise length | |
269 | of the ifname string (not counting any optional trailing '\0' character). | |
270 | In most cases, strnlen should be used to calculate the namelen value. */ | |
271 | extern struct interface *if_lookup_by_name_len(const char *ifname, | |
272 | size_t namelen); | |
273 | extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen); | |
274 | ||
275 | ||
276 | /* Delete the interface, but do not free the structure, and leave it in the | |
277 | interface list. It is often advisable to leave the pseudo interface | |
278 | structure because there may be configuration information attached. */ | |
279 | extern void if_delete_retain (struct interface *); | |
280 | ||
281 | /* Delete and free the interface structure: calls if_delete_retain and then | |
282 | deletes it from the interface list and frees the structure. */ | |
283 | extern void if_delete (struct interface *); | |
284 | ||
285 | extern int if_is_up (struct interface *); | |
286 | extern int if_is_running (struct interface *); | |
287 | extern int if_is_operative (struct interface *); | |
288 | extern int if_is_loopback (struct interface *); | |
289 | extern int if_is_broadcast (struct interface *); | |
290 | extern int if_is_pointopoint (struct interface *); | |
291 | extern int if_is_multicast (struct interface *); | |
292 | extern void if_add_hook (int, int (*)(struct interface *)); | |
293 | extern void if_init (void); | |
294 | extern void if_terminate (void); | |
295 | extern void if_dump_all (void); | |
296 | extern const char *if_flag_dump(unsigned long); | |
297 | ||
298 | /* Please use ifindex2ifname instead of if_indextoname where possible; | |
299 | ifindex2ifname uses internal interface info, whereas if_indextoname must | |
300 | make a system call. */ | |
301 | extern const char *ifindex2ifname (unsigned int); | |
302 | ||
303 | /* Please use ifname2ifindex instead of if_nametoindex where possible; | |
304 | ifname2ifindex uses internal interface info, whereas if_nametoindex must | |
305 | make a system call. */ | |
306 | extern unsigned int ifname2ifindex(const char *ifname); | |
307 | ||
308 | /* Connected address functions. */ | |
309 | extern struct connected *connected_new (void); | |
310 | extern void connected_free (struct connected *); | |
311 | extern void connected_add (struct interface *, struct connected *); | |
312 | extern struct connected *connected_add_by_prefix (struct interface *, | |
313 | struct prefix *, | |
314 | struct prefix *); | |
315 | extern struct connected *connected_delete_by_prefix (struct interface *, | |
316 | struct prefix *); | |
317 | extern struct connected *connected_lookup_address (struct interface *, | |
318 | struct in_addr); | |
319 | extern struct nbr_connected *nbr_connected_new (void); | |
320 | extern void nbr_connected_free (struct nbr_connected *); | |
321 | struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *); | |
322 | ||
323 | #ifndef HAVE_IF_NAMETOINDEX | |
324 | extern unsigned int if_nametoindex (const char *); | |
325 | #endif | |
326 | #ifndef HAVE_IF_INDEXTONAME | |
327 | extern char *if_indextoname (unsigned int, char *); | |
328 | #endif | |
329 | ||
330 | /* Exported variables. */ | |
331 | extern struct list *iflist; | |
332 | extern struct cmd_element interface_desc_cmd; | |
333 | extern struct cmd_element no_interface_desc_cmd; | |
334 | extern struct cmd_element interface_cmd; | |
335 | extern struct cmd_element no_interface_cmd; | |
336 | extern struct cmd_element interface_pseudo_cmd; | |
337 | extern struct cmd_element no_interface_pseudo_cmd; | |
338 | extern struct cmd_element show_address_cmd; | |
339 | ||
340 | #endif /* _ZEBRA_IF_H */ |