]>
Commit | Line | Data |
---|---|---|
718e3744 | 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 | ||
718e3744 | 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 | { | |
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) |
525c1839 | 93 | |
718e3744 | 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. */ | |
6f0e3f6e | 105 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
ca3ccd87 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 | }; | |
718e3744 | 113 | #else |
114 | unsigned short hw_type; | |
115 | u_char hw_addr[INTERFACE_HWADDR_MAX]; | |
116 | int hw_addr_len; | |
6f0e3f6e | 117 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
718e3744 | 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. */ | |
52dc7ee6 | 130 | struct list *connected; |
718e3744 | 131 | |
a80beece DS |
132 | /* Neighbor connected address list. */ |
133 | struct list *nbr_connected; | |
134 | ||
718e3744 | 135 | /* Daemon specific interface data pointer. */ |
136 | void *info; | |
137 | ||
244c1cdc DS |
138 | char ptm_enable; /* Should we look at ptm_status ? */ |
139 | char ptm_status; | |
140 | ||
718e3744 | 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 */ | |
148 | }; | |
149 | ||
150 | /* Connected address structure. */ | |
151 | struct connected | |
152 | { | |
153 | /* Attached interface. */ | |
154 | struct interface *ifp; | |
155 | ||
156 | /* Flags for configuration. */ | |
157 | u_char conf; | |
158 | #define ZEBRA_IFC_REAL (1 << 0) | |
159 | #define ZEBRA_IFC_CONFIGURED (1 << 1) | |
f7f740fe | 160 | #define ZEBRA_IFC_QUEUED (1 << 2) |
9c37851e AS |
161 | /* |
162 | The ZEBRA_IFC_REAL flag should be set if and only if this address | |
f7f740fe CF |
163 | exists in the kernel and is actually usable. (A case where it exists but |
164 | is not yet usable would be IPv6 with DAD) | |
9c37851e AS |
165 | The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address |
166 | was configured by the user from inside quagga. | |
f7f740fe CF |
167 | The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists |
168 | in the kernel. It may and should be set although the address might not be | |
169 | usable yet. (compare with ZEBRA_IFC_REAL) | |
9c37851e | 170 | */ |
718e3744 | 171 | |
172 | /* Flags for connected address. */ | |
173 | u_char flags; | |
e4529636 AS |
174 | #define ZEBRA_IFA_SECONDARY (1 << 0) |
175 | #define ZEBRA_IFA_PEER (1 << 1) | |
525c1839 | 176 | #define ZEBRA_IFA_UNNUMBERED (1 << 2) |
e4529636 AS |
177 | /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if |
178 | a peer address has been configured. If this flag is set, | |
179 | the destination field must contain the peer address. | |
180 | Otherwise, if this flag is not set, the destination address | |
181 | will either contain a broadcast address or be NULL. | |
182 | */ | |
718e3744 | 183 | |
184 | /* Address of connected network. */ | |
185 | struct prefix *address; | |
e4529636 AS |
186 | |
187 | /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set. | |
188 | Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */ | |
189 | struct prefix *destination; | |
718e3744 | 190 | |
525c1839 DS |
191 | /* A list of unnumbered IFCs borrowing the address from me */ |
192 | struct list *unnumbered; | |
193 | ||
194 | /* Pointer to the anchor IFC if I'm unnumbered */ | |
195 | struct connected *anchor; | |
196 | ||
718e3744 | 197 | /* Label for Linux 2.2.X and upper. */ |
198 | char *label; | |
199 | }; | |
200 | ||
a80beece DS |
201 | /* Nbr Connected address structure. */ |
202 | struct nbr_connected | |
203 | { | |
204 | /* Attached interface. */ | |
205 | struct interface *ifp; | |
206 | ||
207 | /* Address of connected network. */ | |
208 | struct prefix *address; | |
209 | }; | |
210 | ||
e4529636 AS |
211 | /* Does the destination field contain a peer address? */ |
212 | #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER) | |
213 | ||
214 | /* Prefix to insert into the RIB */ | |
215 | #define CONNECTED_PREFIX(C) \ | |
216 | (CONNECTED_PEER(C) ? (C)->destination : (C)->address) | |
3fb9cd6e | 217 | |
e4529636 AS |
218 | /* Identifying address. We guess that if there's a peer address, but the |
219 | local address is in the same prefix, then the local address may be unique. */ | |
220 | #define CONNECTED_ID(C) \ | |
221 | ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\ | |
222 | (C)->destination : (C)->address) | |
3fb9cd6e | 223 | |
718e3744 | 224 | /* Interface hook sort. */ |
225 | #define IF_NEW_HOOK 0 | |
226 | #define IF_DELETE_HOOK 1 | |
227 | ||
228 | /* There are some interface flags which are only supported by some | |
229 | operating system. */ | |
230 | ||
231 | #ifndef IFF_NOTRAILERS | |
232 | #define IFF_NOTRAILERS 0x0 | |
233 | #endif /* IFF_NOTRAILERS */ | |
234 | #ifndef IFF_OACTIVE | |
235 | #define IFF_OACTIVE 0x0 | |
236 | #endif /* IFF_OACTIVE */ | |
237 | #ifndef IFF_SIMPLEX | |
238 | #define IFF_SIMPLEX 0x0 | |
239 | #endif /* IFF_SIMPLEX */ | |
240 | #ifndef IFF_LINK0 | |
241 | #define IFF_LINK0 0x0 | |
242 | #endif /* IFF_LINK0 */ | |
243 | #ifndef IFF_LINK1 | |
244 | #define IFF_LINK1 0x0 | |
245 | #endif /* IFF_LINK1 */ | |
246 | #ifndef IFF_LINK2 | |
247 | #define IFF_LINK2 0x0 | |
248 | #endif /* IFF_LINK2 */ | |
4ba9b924 | 249 | #ifndef IFF_NOXMIT |
250 | #define IFF_NOXMIT 0x0 | |
251 | #endif /* IFF_NOXMIT */ | |
252 | #ifndef IFF_NORTEXCH | |
253 | #define IFF_NORTEXCH 0x0 | |
254 | #endif /* IFF_NORTEXCH */ | |
255 | #ifndef IFF_IPV4 | |
256 | #define IFF_IPV4 0x0 | |
257 | #endif /* IFF_IPV4 */ | |
258 | #ifndef IFF_IPV6 | |
259 | #define IFF_IPV6 0x0 | |
260 | #endif /* IFF_IPV6 */ | |
261 | #ifndef IFF_VIRTUAL | |
262 | #define IFF_VIRTUAL 0x0 | |
263 | #endif /* IFF_VIRTUAL */ | |
718e3744 | 264 | |
265 | /* Prototypes. */ | |
8cc4198f | 266 | extern int if_cmp_func (struct interface *, struct interface *); |
267 | extern struct interface *if_create (const char *name, int namelen); | |
268 | extern struct interface *if_lookup_by_index (unsigned int); | |
0aabccc0 DD |
269 | extern struct interface *if_lookup_exact_address (void *matchaddr, int family); |
270 | extern struct interface *if_lookup_address (void *matchaddr, int family); | |
b81e97a8 | 271 | extern struct interface *if_lookup_prefix (struct prefix *prefix); |
525c1839 | 272 | extern struct connected *if_anchor_lookup_by_address (struct in_addr src); |
a349198f | 273 | |
08dbfb69 | 274 | /* These 2 functions are to be used when the ifname argument is terminated |
275 | by a '\0' character: */ | |
8cc4198f | 276 | extern struct interface *if_lookup_by_name (const char *ifname); |
277 | extern struct interface *if_get_by_name (const char *ifname); | |
08dbfb69 | 278 | |
279 | /* For these 2 functions, the namelen argument should be the precise length | |
280 | of the ifname string (not counting any optional trailing '\0' character). | |
281 | In most cases, strnlen should be used to calculate the namelen value. */ | |
282 | extern struct interface *if_lookup_by_name_len(const char *ifname, | |
a349198f | 283 | size_t namelen); |
08dbfb69 | 284 | extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen); |
a349198f | 285 | |
286 | ||
d2fc8896 | 287 | /* Delete the interface, but do not free the structure, and leave it in the |
288 | interface list. It is often advisable to leave the pseudo interface | |
289 | structure because there may be configuration information attached. */ | |
290 | extern void if_delete_retain (struct interface *); | |
291 | ||
292 | /* Delete and free the interface structure: calls if_delete_retain and then | |
293 | deletes it from the interface list and frees the structure. */ | |
294 | extern void if_delete (struct interface *); | |
295 | ||
8cc4198f | 296 | extern int if_is_up (struct interface *); |
297 | extern int if_is_running (struct interface *); | |
298 | extern int if_is_operative (struct interface *); | |
244c1cdc | 299 | extern int if_is_no_ptm_operative (struct interface *); |
8cc4198f | 300 | extern int if_is_loopback (struct interface *); |
301 | extern int if_is_broadcast (struct interface *); | |
302 | extern int if_is_pointopoint (struct interface *); | |
303 | extern int if_is_multicast (struct interface *); | |
304 | extern void if_add_hook (int, int (*)(struct interface *)); | |
305 | extern void if_init (void); | |
4bd045d5 | 306 | extern void if_terminate (void); |
8cc4198f | 307 | extern void if_dump_all (void); |
847947f2 | 308 | extern const char *if_flag_dump(unsigned long); |
718e3744 | 309 | |
d2fc8896 | 310 | /* Please use ifindex2ifname instead of if_indextoname where possible; |
311 | ifindex2ifname uses internal interface info, whereas if_indextoname must | |
312 | make a system call. */ | |
8cc4198f | 313 | extern const char *ifindex2ifname (unsigned int); |
d2fc8896 | 314 | |
315 | /* Please use ifname2ifindex instead of if_nametoindex where possible; | |
316 | ifname2ifindex uses internal interface info, whereas if_nametoindex must | |
317 | make a system call. */ | |
318 | extern unsigned int ifname2ifindex(const char *ifname); | |
319 | ||
718e3744 | 320 | /* Connected address functions. */ |
8cc4198f | 321 | extern struct connected *connected_new (void); |
322 | extern void connected_free (struct connected *); | |
323 | extern void connected_add (struct interface *, struct connected *); | |
324 | extern struct connected *connected_add_by_prefix (struct interface *, | |
4a7aac1b | 325 | struct prefix *, |
326 | struct prefix *); | |
8cc4198f | 327 | extern struct connected *connected_delete_by_prefix (struct interface *, |
4a7aac1b | 328 | struct prefix *); |
8cc4198f | 329 | extern struct connected *connected_lookup_address (struct interface *, |
4a7aac1b | 330 | struct in_addr); |
a80beece DS |
331 | extern struct nbr_connected *nbr_connected_new (void); |
332 | extern void nbr_connected_free (struct nbr_connected *); | |
333 | struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *); | |
718e3744 | 334 | |
335 | #ifndef HAVE_IF_NAMETOINDEX | |
8cc4198f | 336 | extern unsigned int if_nametoindex (const char *); |
718e3744 | 337 | #endif |
338 | #ifndef HAVE_IF_INDEXTONAME | |
8cc4198f | 339 | extern char *if_indextoname (unsigned int, char *); |
718e3744 | 340 | #endif |
341 | ||
342 | /* Exported variables. */ | |
52dc7ee6 | 343 | extern struct list *iflist; |
718e3744 | 344 | extern struct cmd_element interface_desc_cmd; |
345 | extern struct cmd_element no_interface_desc_cmd; | |
346 | extern struct cmd_element interface_cmd; | |
32d2463c | 347 | extern struct cmd_element no_interface_cmd; |
718e3744 | 348 | extern struct cmd_element interface_pseudo_cmd; |
349 | extern struct cmd_element no_interface_pseudo_cmd; | |
478ccfd6 | 350 | extern struct cmd_element show_address_cmd; |
718e3744 | 351 | |
352 | #endif /* _ZEBRA_IF_H */ |