]>
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 |
84361d61 | 87 | #define IFINDEX_DELETED UINT_MAX |
718e3744 | 88 | |
89 | /* Zebra internal interface status */ | |
90 | u_char status; | |
91 | #define ZEBRA_INTERFACE_ACTIVE (1 << 0) | |
92 | #define ZEBRA_INTERFACE_SUB (1 << 1) | |
2e3b2e47 | 93 | #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2) |
c23af4d3 | 94 | #define ZEBRA_INTERFACE_VRF_LOOPBACK (1 << 3) |
525c1839 | 95 | |
718e3744 | 96 | /* Interface flags. */ |
c77d4546 | 97 | uint64_t flags; |
718e3744 | 98 | |
99 | /* Interface metric */ | |
100 | int metric; | |
101 | ||
102 | /* Interface MTU. */ | |
c9eca01b | 103 | unsigned int mtu; /* IPv4 MTU */ |
104 | unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */ | |
718e3744 | 105 | |
106 | /* Hardware address. */ | |
6f0e3f6e | 107 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
ca3ccd87 DL |
108 | union { |
109 | /* note that sdl_storage is never accessed, it only exists to make space. | |
110 | * all actual uses refer to sdl - but use sizeof(sdl_storage)! this fits | |
111 | * best with C aliasing rules. */ | |
112 | struct sockaddr_dl sdl; | |
113 | struct sockaddr_storage sdl_storage; | |
114 | }; | |
718e3744 | 115 | #else |
116 | unsigned short hw_type; | |
117 | u_char hw_addr[INTERFACE_HWADDR_MAX]; | |
118 | int hw_addr_len; | |
6f0e3f6e | 119 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
718e3744 | 120 | |
121 | /* interface bandwidth, kbits */ | |
122 | unsigned int bandwidth; | |
123 | ||
124 | /* description of the interface. */ | |
125 | char *desc; | |
126 | ||
127 | /* Distribute list. */ | |
128 | void *distribute_in; | |
129 | void *distribute_out; | |
130 | ||
131 | /* Connected address list. */ | |
52dc7ee6 | 132 | struct list *connected; |
718e3744 | 133 | |
a80beece DS |
134 | /* Neighbor connected address list. */ |
135 | struct list *nbr_connected; | |
136 | ||
718e3744 | 137 | /* Daemon specific interface data pointer. */ |
138 | void *info; | |
139 | ||
244c1cdc DS |
140 | char ptm_enable; /* Should we look at ptm_status ? */ |
141 | char ptm_status; | |
142 | ||
718e3744 | 143 | /* Statistics fileds. */ |
144 | #ifdef HAVE_PROC_NET_DEV | |
145 | struct if_stats stats; | |
146 | #endif /* HAVE_PROC_NET_DEV */ | |
147 | #ifdef HAVE_NET_RT_IFLIST | |
148 | struct if_data stats; | |
149 | #endif /* HAVE_NET_RT_IFLIST */ | |
3968dbf8 | 150 | |
f93e3f69 | 151 | struct route_node *node; |
3968dbf8 | 152 | vrf_id_t vrf_id; |
718e3744 | 153 | }; |
154 | ||
155 | /* Connected address structure. */ | |
156 | struct connected | |
157 | { | |
158 | /* Attached interface. */ | |
159 | struct interface *ifp; | |
160 | ||
161 | /* Flags for configuration. */ | |
162 | u_char conf; | |
163 | #define ZEBRA_IFC_REAL (1 << 0) | |
164 | #define ZEBRA_IFC_CONFIGURED (1 << 1) | |
f7f740fe | 165 | #define ZEBRA_IFC_QUEUED (1 << 2) |
9c37851e AS |
166 | /* |
167 | The ZEBRA_IFC_REAL flag should be set if and only if this address | |
f7f740fe CF |
168 | exists in the kernel and is actually usable. (A case where it exists but |
169 | is not yet usable would be IPv6 with DAD) | |
9c37851e AS |
170 | The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address |
171 | was configured by the user from inside quagga. | |
f7f740fe CF |
172 | The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists |
173 | in the kernel. It may and should be set although the address might not be | |
174 | usable yet. (compare with ZEBRA_IFC_REAL) | |
9c37851e | 175 | */ |
718e3744 | 176 | |
177 | /* Flags for connected address. */ | |
178 | u_char flags; | |
e4529636 AS |
179 | #define ZEBRA_IFA_SECONDARY (1 << 0) |
180 | #define ZEBRA_IFA_PEER (1 << 1) | |
525c1839 | 181 | #define ZEBRA_IFA_UNNUMBERED (1 << 2) |
e4529636 AS |
182 | /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if |
183 | a peer address has been configured. If this flag is set, | |
184 | the destination field must contain the peer address. | |
185 | Otherwise, if this flag is not set, the destination address | |
186 | will either contain a broadcast address or be NULL. | |
187 | */ | |
718e3744 | 188 | |
189 | /* Address of connected network. */ | |
190 | struct prefix *address; | |
e4529636 AS |
191 | |
192 | /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set. | |
193 | Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */ | |
194 | struct prefix *destination; | |
718e3744 | 195 | |
196 | /* Label for Linux 2.2.X and upper. */ | |
197 | char *label; | |
198 | }; | |
199 | ||
a80beece DS |
200 | /* Nbr Connected address structure. */ |
201 | struct nbr_connected | |
202 | { | |
203 | /* Attached interface. */ | |
204 | struct interface *ifp; | |
205 | ||
206 | /* Address of connected network. */ | |
207 | struct prefix *address; | |
208 | }; | |
209 | ||
e4529636 AS |
210 | /* Does the destination field contain a peer address? */ |
211 | #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER) | |
212 | ||
213 | /* Prefix to insert into the RIB */ | |
214 | #define CONNECTED_PREFIX(C) \ | |
215 | (CONNECTED_PEER(C) ? (C)->destination : (C)->address) | |
3fb9cd6e | 216 | |
e4529636 AS |
217 | /* Identifying address. We guess that if there's a peer address, but the |
218 | local address is in the same prefix, then the local address may be unique. */ | |
219 | #define CONNECTED_ID(C) \ | |
220 | ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\ | |
221 | (C)->destination : (C)->address) | |
3fb9cd6e | 222 | |
718e3744 | 223 | /* Interface hook sort. */ |
224 | #define IF_NEW_HOOK 0 | |
225 | #define IF_DELETE_HOOK 1 | |
226 | ||
227 | /* There are some interface flags which are only supported by some | |
228 | operating system. */ | |
229 | ||
230 | #ifndef IFF_NOTRAILERS | |
231 | #define IFF_NOTRAILERS 0x0 | |
232 | #endif /* IFF_NOTRAILERS */ | |
233 | #ifndef IFF_OACTIVE | |
234 | #define IFF_OACTIVE 0x0 | |
235 | #endif /* IFF_OACTIVE */ | |
236 | #ifndef IFF_SIMPLEX | |
237 | #define IFF_SIMPLEX 0x0 | |
238 | #endif /* IFF_SIMPLEX */ | |
239 | #ifndef IFF_LINK0 | |
240 | #define IFF_LINK0 0x0 | |
241 | #endif /* IFF_LINK0 */ | |
242 | #ifndef IFF_LINK1 | |
243 | #define IFF_LINK1 0x0 | |
244 | #endif /* IFF_LINK1 */ | |
245 | #ifndef IFF_LINK2 | |
246 | #define IFF_LINK2 0x0 | |
247 | #endif /* IFF_LINK2 */ | |
4ba9b924 | 248 | #ifndef IFF_NOXMIT |
249 | #define IFF_NOXMIT 0x0 | |
250 | #endif /* IFF_NOXMIT */ | |
251 | #ifndef IFF_NORTEXCH | |
252 | #define IFF_NORTEXCH 0x0 | |
253 | #endif /* IFF_NORTEXCH */ | |
254 | #ifndef IFF_IPV4 | |
255 | #define IFF_IPV4 0x0 | |
256 | #endif /* IFF_IPV4 */ | |
257 | #ifndef IFF_IPV6 | |
258 | #define IFF_IPV6 0x0 | |
259 | #endif /* IFF_IPV6 */ | |
260 | #ifndef IFF_VIRTUAL | |
261 | #define IFF_VIRTUAL 0x0 | |
262 | #endif /* IFF_VIRTUAL */ | |
718e3744 | 263 | |
264 | /* Prototypes. */ | |
8cc4198f | 265 | extern int if_cmp_func (struct interface *, struct interface *); |
266 | extern struct interface *if_create (const char *name, int namelen); | |
267 | extern struct interface *if_lookup_by_index (unsigned int); | |
0aabccc0 DD |
268 | extern struct interface *if_lookup_exact_address (void *matchaddr, int family); |
269 | extern struct interface *if_lookup_address (void *matchaddr, int family); | |
b81e97a8 | 270 | extern struct interface *if_lookup_prefix (struct prefix *prefix); |
a349198f | 271 | |
f93e3f69 DS |
272 | extern void if_update_vrf (struct interface *, const char *name, int namelen, |
273 | vrf_id_t vrf_id); | |
8736158a FL |
274 | extern struct interface *if_create_vrf (const char *name, int namelen, |
275 | vrf_id_t vrf_id); | |
276 | extern struct interface *if_lookup_by_index_vrf (unsigned int, | |
277 | vrf_id_t vrf_id); | |
278 | extern struct interface *if_lookup_exact_address_vrf (void *matchaddr, int family, | |
279 | vrf_id_t vrf_id); | |
280 | extern struct interface *if_lookup_address_vrf (void *matchaddr, int family, | |
281 | vrf_id_t vrf_id); | |
282 | extern struct interface *if_lookup_prefix_vrf (struct prefix *prefix, | |
283 | vrf_id_t vrf_id); | |
284 | ||
08dbfb69 | 285 | /* These 2 functions are to be used when the ifname argument is terminated |
286 | by a '\0' character: */ | |
8cc4198f | 287 | extern struct interface *if_lookup_by_name (const char *ifname); |
288 | extern struct interface *if_get_by_name (const char *ifname); | |
08dbfb69 | 289 | |
f8962871 | 290 | extern struct interface *if_lookup_by_name_all_vrf (const char *ifname); |
8736158a FL |
291 | extern struct interface *if_lookup_by_name_vrf (const char *ifname, |
292 | vrf_id_t vrf_id); | |
293 | extern struct interface *if_get_by_name_vrf (const char *ifname, | |
294 | vrf_id_t vrf_id); | |
295 | ||
08dbfb69 | 296 | /* For these 2 functions, the namelen argument should be the precise length |
297 | of the ifname string (not counting any optional trailing '\0' character). | |
298 | In most cases, strnlen should be used to calculate the namelen value. */ | |
299 | extern struct interface *if_lookup_by_name_len(const char *ifname, | |
8736158a FL |
300 | size_t namelen); |
301 | extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen); | |
302 | ||
303 | extern struct interface *if_lookup_by_name_len_vrf(const char *ifname, | |
304 | size_t namelen, vrf_id_t vrf_id); | |
305 | extern struct interface *if_get_by_name_len_vrf(const char *ifname, | |
85f9da7f | 306 | size_t namelen, vrf_id_t vrf_id, int vty); |
a349198f | 307 | |
308 | ||
d2fc8896 | 309 | /* Delete the interface, but do not free the structure, and leave it in the |
310 | interface list. It is often advisable to leave the pseudo interface | |
311 | structure because there may be configuration information attached. */ | |
312 | extern void if_delete_retain (struct interface *); | |
313 | ||
314 | /* Delete and free the interface structure: calls if_delete_retain and then | |
315 | deletes it from the interface list and frees the structure. */ | |
316 | extern void if_delete (struct interface *); | |
317 | ||
8cc4198f | 318 | extern int if_is_up (struct interface *); |
319 | extern int if_is_running (struct interface *); | |
320 | extern int if_is_operative (struct interface *); | |
244c1cdc | 321 | extern int if_is_no_ptm_operative (struct interface *); |
8cc4198f | 322 | extern int if_is_loopback (struct interface *); |
323 | extern int if_is_broadcast (struct interface *); | |
324 | extern int if_is_pointopoint (struct interface *); | |
325 | extern int if_is_multicast (struct interface *); | |
326 | extern void if_add_hook (int, int (*)(struct interface *)); | |
8736158a FL |
327 | extern void if_init (vrf_id_t, struct list **); |
328 | extern void if_terminate (vrf_id_t, struct list **); | |
8cc4198f | 329 | extern void if_dump_all (void); |
847947f2 | 330 | extern const char *if_flag_dump(unsigned long); |
718e3744 | 331 | |
d2fc8896 | 332 | /* Please use ifindex2ifname instead of if_indextoname where possible; |
333 | ifindex2ifname uses internal interface info, whereas if_indextoname must | |
334 | make a system call. */ | |
8cc4198f | 335 | extern const char *ifindex2ifname (unsigned int); |
8736158a | 336 | extern const char *ifindex2ifname_vrf (unsigned int, vrf_id_t vrf_id); |
d2fc8896 | 337 | |
338 | /* Please use ifname2ifindex instead of if_nametoindex where possible; | |
339 | ifname2ifindex uses internal interface info, whereas if_nametoindex must | |
340 | make a system call. */ | |
341 | extern unsigned int ifname2ifindex(const char *ifname); | |
8736158a | 342 | extern unsigned int ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id); |
d2fc8896 | 343 | |
718e3744 | 344 | /* Connected address functions. */ |
8cc4198f | 345 | extern struct connected *connected_new (void); |
346 | extern void connected_free (struct connected *); | |
347 | extern void connected_add (struct interface *, struct connected *); | |
348 | extern struct connected *connected_add_by_prefix (struct interface *, | |
4a7aac1b | 349 | struct prefix *, |
350 | struct prefix *); | |
8cc4198f | 351 | extern struct connected *connected_delete_by_prefix (struct interface *, |
4a7aac1b | 352 | struct prefix *); |
8cc4198f | 353 | extern struct connected *connected_lookup_address (struct interface *, |
4a7aac1b | 354 | struct in_addr); |
a80beece DS |
355 | extern struct nbr_connected *nbr_connected_new (void); |
356 | extern void nbr_connected_free (struct nbr_connected *); | |
357 | struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *); | |
718e3744 | 358 | |
359 | #ifndef HAVE_IF_NAMETOINDEX | |
8cc4198f | 360 | extern unsigned int if_nametoindex (const char *); |
718e3744 | 361 | #endif |
362 | #ifndef HAVE_IF_INDEXTONAME | |
8cc4198f | 363 | extern char *if_indextoname (unsigned int, char *); |
718e3744 | 364 | #endif |
365 | ||
366 | /* Exported variables. */ | |
52dc7ee6 | 367 | extern struct list *iflist; |
718e3744 | 368 | extern struct cmd_element interface_desc_cmd; |
369 | extern struct cmd_element no_interface_desc_cmd; | |
370 | extern struct cmd_element interface_cmd; | |
32d2463c | 371 | extern struct cmd_element no_interface_cmd; |
cd2a8a42 FL |
372 | extern struct cmd_element interface_vrf_cmd; |
373 | extern struct cmd_element no_interface_vrf_cmd; | |
718e3744 | 374 | extern struct cmd_element interface_pseudo_cmd; |
375 | extern struct cmd_element no_interface_pseudo_cmd; | |
478ccfd6 | 376 | extern struct cmd_element show_address_cmd; |
8736158a FL |
377 | extern struct cmd_element show_address_vrf_cmd; |
378 | extern struct cmd_element show_address_vrf_all_cmd; | |
f93e3f69 DS |
379 | extern struct cmd_element vrf_cmd; |
380 | extern struct cmd_element no_vrf_cmd; | |
718e3744 | 381 | |
382 | #endif /* _ZEBRA_IF_H */ |