]> git.proxmox.com Git - mirror_frr.git/blob - lib/if.h
*: use an ifindex_t type, defined in lib/if.h, for ifindex values
[mirror_frr.git] / lib / if.h
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 "zebra.h"
25 #include "linklist.h"
26
27 /*
28 Interface name length.
29
30 Linux define value in /usr/include/linux/if.h.
31 #define IFNAMSIZ 16
32
33 FreeBSD define value in /usr/include/net/if.h.
34 #define IFNAMSIZ 16
35 */
36
37 #define INTERFACE_NAMSIZ 20
38 #define INTERFACE_HWADDR_MAX 20
39
40 typedef signed int ifindex_t;
41
42 #ifdef HAVE_PROC_NET_DEV
43 struct if_stats
44 {
45 unsigned long rx_packets; /* total packets received */
46 unsigned long tx_packets; /* total packets transmitted */
47 unsigned long rx_bytes; /* total bytes received */
48 unsigned long tx_bytes; /* total bytes transmitted */
49 unsigned long rx_errors; /* bad packets received */
50 unsigned long tx_errors; /* packet transmit problems */
51 unsigned long rx_dropped; /* no space in linux buffers */
52 unsigned long tx_dropped; /* no space available in linux */
53 unsigned long rx_multicast; /* multicast packets received */
54 unsigned long rx_compressed;
55 unsigned long tx_compressed;
56 unsigned long collisions;
57
58 /* detailed rx_errors: */
59 unsigned long rx_length_errors;
60 unsigned long rx_over_errors; /* receiver ring buff overflow */
61 unsigned long rx_crc_errors; /* recved pkt with crc error */
62 unsigned long rx_frame_errors; /* recv'd frame alignment error */
63 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
64 unsigned long rx_missed_errors; /* receiver missed packet */
65 /* detailed tx_errors */
66 unsigned long tx_aborted_errors;
67 unsigned long tx_carrier_errors;
68 unsigned long tx_fifo_errors;
69 unsigned long tx_heartbeat_errors;
70 unsigned long tx_window_errors;
71 };
72 #endif /* HAVE_PROC_NET_DEV */
73
74 /* Interface structure */
75 struct interface
76 {
77 /* Interface name. This should probably never be changed after the
78 interface is created, because the configuration info for this interface
79 is associated with this structure. For that reason, the interface
80 should also never be deleted (to avoid losing configuration info).
81 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
82 interface does not exist in the kernel.
83 */
84 char name[INTERFACE_NAMSIZ + 1];
85
86 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
87 deleted interfaces). */
88 ifindex_t ifindex;
89 #define IFINDEX_INTERNAL 0
90 #define IFINDEX_DELETED INT_MAX
91
92 /* Zebra internal interface status */
93 u_char status;
94 #define ZEBRA_INTERFACE_ACTIVE (1 << 0)
95 #define ZEBRA_INTERFACE_SUB (1 << 1)
96 #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
97 #define ZEBRA_INTERFACE_VRF_LOOPBACK (1 << 3)
98
99 /* Interface flags. */
100 uint64_t flags;
101
102 /* Interface metric */
103 int metric;
104
105 /* Interface MTU. */
106 unsigned int mtu; /* IPv4 MTU */
107 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
108
109 /* Hardware address. */
110 #ifdef HAVE_STRUCT_SOCKADDR_DL
111 union {
112 /* note that sdl_storage is never accessed, it only exists to make space.
113 * all actual uses refer to sdl - but use sizeof(sdl_storage)! this fits
114 * best with C aliasing rules. */
115 struct sockaddr_dl sdl;
116 struct sockaddr_storage sdl_storage;
117 };
118 #else
119 unsigned short hw_type;
120 u_char hw_addr[INTERFACE_HWADDR_MAX];
121 int hw_addr_len;
122 #endif /* HAVE_STRUCT_SOCKADDR_DL */
123
124 /* interface bandwidth, kbits */
125 unsigned int bandwidth;
126
127 /* description of the interface. */
128 char *desc;
129
130 /* Distribute list. */
131 void *distribute_in;
132 void *distribute_out;
133
134 /* Connected address list. */
135 struct list *connected;
136
137 /* Neighbor connected address list. */
138 struct list *nbr_connected;
139
140 /* Daemon specific interface data pointer. */
141 void *info;
142
143 char ptm_enable; /* Should we look at ptm_status ? */
144 char ptm_status;
145
146 /* Statistics fileds. */
147 #ifdef HAVE_PROC_NET_DEV
148 struct if_stats stats;
149 #endif /* HAVE_PROC_NET_DEV */
150 #ifdef HAVE_NET_RT_IFLIST
151 struct if_data stats;
152 #endif /* HAVE_NET_RT_IFLIST */
153
154 struct route_node *node;
155 vrf_id_t vrf_id;
156 };
157
158 /* Connected address structure. */
159 struct connected
160 {
161 /* Attached interface. */
162 struct interface *ifp;
163
164 /* Flags for configuration. */
165 u_char conf;
166 #define ZEBRA_IFC_REAL (1 << 0)
167 #define ZEBRA_IFC_CONFIGURED (1 << 1)
168 #define ZEBRA_IFC_QUEUED (1 << 2)
169 /*
170 The ZEBRA_IFC_REAL flag should be set if and only if this address
171 exists in the kernel and is actually usable. (A case where it exists but
172 is not yet usable would be IPv6 with DAD)
173 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
174 was configured by the user from inside quagga.
175 The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
176 in the kernel. It may and should be set although the address might not be
177 usable yet. (compare with ZEBRA_IFC_REAL)
178 */
179
180 /* Flags for connected address. */
181 u_char flags;
182 #define ZEBRA_IFA_SECONDARY (1 << 0)
183 #define ZEBRA_IFA_PEER (1 << 1)
184 #define ZEBRA_IFA_UNNUMBERED (1 << 2)
185 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
186 a peer address has been configured. If this flag is set,
187 the destination field must contain the peer address.
188 Otherwise, if this flag is not set, the destination address
189 will either contain a broadcast address or be NULL.
190 */
191
192 /* Address of connected network. */
193 struct prefix *address;
194
195 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
196 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
197 struct prefix *destination;
198
199 /* Label for Linux 2.2.X and upper. */
200 char *label;
201 };
202
203 /* Nbr Connected address structure. */
204 struct nbr_connected
205 {
206 /* Attached interface. */
207 struct interface *ifp;
208
209 /* Address of connected network. */
210 struct prefix *address;
211 };
212
213 /* Does the destination field contain a peer address? */
214 #define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
215
216 /* Prefix to insert into the RIB */
217 #define CONNECTED_PREFIX(C) \
218 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
219
220 /* Identifying address. We guess that if there's a peer address, but the
221 local address is in the same prefix, then the local address may be unique. */
222 #define CONNECTED_ID(C) \
223 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
224 (C)->destination : (C)->address)
225
226 /* Interface hook sort. */
227 #define IF_NEW_HOOK 0
228 #define IF_DELETE_HOOK 1
229
230 /* There are some interface flags which are only supported by some
231 operating system. */
232
233 #ifndef IFF_NOTRAILERS
234 #define IFF_NOTRAILERS 0x0
235 #endif /* IFF_NOTRAILERS */
236 #ifndef IFF_OACTIVE
237 #define IFF_OACTIVE 0x0
238 #endif /* IFF_OACTIVE */
239 #ifndef IFF_SIMPLEX
240 #define IFF_SIMPLEX 0x0
241 #endif /* IFF_SIMPLEX */
242 #ifndef IFF_LINK0
243 #define IFF_LINK0 0x0
244 #endif /* IFF_LINK0 */
245 #ifndef IFF_LINK1
246 #define IFF_LINK1 0x0
247 #endif /* IFF_LINK1 */
248 #ifndef IFF_LINK2
249 #define IFF_LINK2 0x0
250 #endif /* IFF_LINK2 */
251 #ifndef IFF_NOXMIT
252 #define IFF_NOXMIT 0x0
253 #endif /* IFF_NOXMIT */
254 #ifndef IFF_NORTEXCH
255 #define IFF_NORTEXCH 0x0
256 #endif /* IFF_NORTEXCH */
257 #ifndef IFF_IPV4
258 #define IFF_IPV4 0x0
259 #endif /* IFF_IPV4 */
260 #ifndef IFF_IPV6
261 #define IFF_IPV6 0x0
262 #endif /* IFF_IPV6 */
263 #ifndef IFF_VIRTUAL
264 #define IFF_VIRTUAL 0x0
265 #endif /* IFF_VIRTUAL */
266
267 /* Prototypes. */
268 extern int if_cmp_name_func (char *, char *);
269 extern struct interface *if_create (const char *name, int namelen);
270 extern struct interface *if_lookup_by_index (ifindex_t);
271 extern struct interface *if_lookup_exact_address (void *matchaddr, int family);
272 extern struct interface *if_lookup_address (void *matchaddr, int family);
273 extern struct interface *if_lookup_prefix (struct prefix *prefix);
274
275 extern void if_update_vrf (struct interface *, const char *name, int namelen,
276 vrf_id_t vrf_id);
277 extern struct interface *if_create_vrf (const char *name, int namelen,
278 vrf_id_t vrf_id);
279 extern struct interface *if_lookup_by_index_vrf (ifindex_t, vrf_id_t vrf_id);
280 extern struct interface *if_lookup_exact_address_vrf (void *matchaddr, int family,
281 vrf_id_t vrf_id);
282 extern struct interface *if_lookup_address_vrf (void *matchaddr, int family,
283 vrf_id_t vrf_id);
284 extern struct interface *if_lookup_prefix_vrf (struct prefix *prefix,
285 vrf_id_t vrf_id);
286
287 /* These 2 functions are to be used when the ifname argument is terminated
288 by a '\0' character: */
289 extern struct interface *if_lookup_by_name (const char *ifname);
290 extern struct interface *if_get_by_name (const char *ifname);
291
292 extern struct interface *if_lookup_by_name_all_vrf (const char *ifname);
293 extern struct interface *if_lookup_by_name_vrf (const char *ifname,
294 vrf_id_t vrf_id);
295 extern struct interface *if_get_by_name_vrf (const char *ifname,
296 vrf_id_t vrf_id);
297
298 /* For these 2 functions, the namelen argument should be the precise length
299 of the ifname string (not counting any optional trailing '\0' character).
300 In most cases, strnlen should be used to calculate the namelen value. */
301 extern struct interface *if_lookup_by_name_len(const char *ifname,
302 size_t namelen);
303 extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen);
304
305 extern struct interface *if_lookup_by_name_len_vrf(const char *ifname,
306 size_t namelen, vrf_id_t vrf_id);
307 extern struct interface *if_get_by_name_len_vrf(const char *ifname,
308 size_t namelen, vrf_id_t vrf_id, int vty);
309
310
311 /* Delete the interface, but do not free the structure, and leave it in the
312 interface list. It is often advisable to leave the pseudo interface
313 structure because there may be configuration information attached. */
314 extern void if_delete_retain (struct interface *);
315
316 /* Delete and free the interface structure: calls if_delete_retain and then
317 deletes it from the interface list and frees the structure. */
318 extern void if_delete (struct interface *);
319
320 extern int if_is_up (struct interface *);
321 extern int if_is_running (struct interface *);
322 extern int if_is_operative (struct interface *);
323 extern int if_is_no_ptm_operative (struct interface *);
324 extern int if_is_loopback (struct interface *);
325 extern int if_is_broadcast (struct interface *);
326 extern int if_is_pointopoint (struct interface *);
327 extern int if_is_multicast (struct interface *);
328 extern void if_add_hook (int, int (*)(struct interface *));
329 extern void if_init (struct list **);
330 extern void if_terminate (struct list **);
331 extern void if_dump_all (void);
332 extern const char *if_flag_dump(unsigned long);
333
334 /* Please use ifindex2ifname instead of if_indextoname where possible;
335 ifindex2ifname uses internal interface info, whereas if_indextoname must
336 make a system call. */
337 extern const char *ifindex2ifname (ifindex_t);
338 extern const char *ifindex2ifname_vrf (ifindex_t, vrf_id_t vrf_id);
339
340 /* Please use ifname2ifindex instead of if_nametoindex where possible;
341 ifname2ifindex uses internal interface info, whereas if_nametoindex must
342 make a system call. */
343 extern ifindex_t ifname2ifindex(const char *ifname);
344 extern ifindex_t ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id);
345
346 /* Connected address functions. */
347 extern struct connected *connected_new (void);
348 extern void connected_free (struct connected *);
349 extern void connected_add (struct interface *, struct connected *);
350 extern struct connected *connected_add_by_prefix (struct interface *,
351 struct prefix *,
352 struct prefix *);
353 extern struct connected *connected_delete_by_prefix (struct interface *,
354 struct prefix *);
355 extern struct connected *connected_lookup_prefix (struct interface *,
356 struct prefix *);
357 extern struct connected *connected_lookup_prefix_exact (struct interface *,
358 struct prefix *);
359 extern struct nbr_connected *nbr_connected_new (void);
360 extern void nbr_connected_free (struct nbr_connected *);
361 struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *);
362
363 #ifndef HAVE_IF_NAMETOINDEX
364 extern ifindex_t if_nametoindex (const char *);
365 #endif
366 #ifndef HAVE_IF_INDEXTONAME
367 extern char *if_indextoname (ifindex_t, char *);
368 #endif
369
370 /* Exported variables. */
371 extern struct cmd_element interface_desc_cmd;
372 extern struct cmd_element no_interface_desc_cmd;
373 extern struct cmd_element interface_cmd;
374 extern struct cmd_element no_interface_cmd;
375 extern struct cmd_element interface_vrf_cmd;
376 extern struct cmd_element no_interface_vrf_cmd;
377 extern struct cmd_element interface_pseudo_cmd;
378 extern struct cmd_element no_interface_pseudo_cmd;
379 extern struct cmd_element show_address_cmd;
380 extern struct cmd_element show_address_vrf_cmd;
381 extern struct cmd_element show_address_vrf_all_cmd;
382 extern struct cmd_element vrf_cmd;
383 extern struct cmd_element no_vrf_cmd;
384
385 #endif /* _ZEBRA_IF_H */