blob: 2116e12ebe3ca727deb0a1c0a1c9243e93fe6d36 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
paul718e3742002-12-13 20:15:29 +000039#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{
ajsd2fc8892005-04-02 18:38:43 +000074 /* 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 */
paul718e3742002-12-13 20:15:29 +000081 char name[INTERFACE_NAMSIZ + 1];
82
ajsd2fc8892005-04-02 18:38:43 +000083 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
84 deleted interfaces). */
paul718e3742002-12-13 20:15:29 +000085 unsigned int ifindex;
ajsd2fc8892005-04-02 18:38:43 +000086#define IFINDEX_INTERNAL 0
paul718e3742002-12-13 20:15:29 +000087
88 /* Zebra internal interface status */
89 u_char status;
90#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
91#define ZEBRA_INTERFACE_SUB (1 << 1)
paul2e3b2e42002-12-13 21:03:13 +000092#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
paul718e3742002-12-13 20:15:29 +000093
94 /* Interface flags. */
paulc77d4542006-01-11 01:59:04 +000095 uint64_t flags;
paul718e3742002-12-13 20:15:29 +000096
97 /* Interface metric */
98 int metric;
99
100 /* Interface MTU. */
paulc9eca012004-10-11 11:28:44 +0000101 unsigned int mtu; /* IPv4 MTU */
102 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
paul718e3742002-12-13 20:15:29 +0000103
104 /* Hardware address. */
Paul Jakma6f0e3f62007-05-10 02:38:51 +0000105#ifdef HAVE_STRUCT_SOCKADDR_DL
David Lamparterca3ccd82012-09-26 14:52:39 +0200106 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 };
paul718e3742002-12-13 20:15:29 +0000113#else
114 unsigned short hw_type;
115 u_char hw_addr[INTERFACE_HWADDR_MAX];
116 int hw_addr_len;
Paul Jakma6f0e3f62007-05-10 02:38:51 +0000117#endif /* HAVE_STRUCT_SOCKADDR_DL */
paul718e3742002-12-13 20:15:29 +0000118
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. */
hasso52dc7ee2004-09-23 19:18:23 +0000130 struct list *connected;
paul718e3742002-12-13 20:15:29 +0000131
132 /* Daemon specific interface data pointer. */
133 void *info;
134
135 /* Statistics fileds. */
136#ifdef HAVE_PROC_NET_DEV
137 struct if_stats stats;
138#endif /* HAVE_PROC_NET_DEV */
139#ifdef HAVE_NET_RT_IFLIST
140 struct if_data stats;
141#endif /* HAVE_NET_RT_IFLIST */
142};
143
144/* Connected address structure. */
145struct connected
146{
147 /* Attached interface. */
148 struct interface *ifp;
149
150 /* Flags for configuration. */
151 u_char conf;
152#define ZEBRA_IFC_REAL (1 << 0)
153#define ZEBRA_IFC_CONFIGURED (1 << 1)
Andrew J. Schorr9c378512006-05-21 04:04:49 +0000154 /*
155 The ZEBRA_IFC_REAL flag should be set if and only if this address
156 exists in the kernel.
157 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
158 was configured by the user from inside quagga.
159 */
paul718e3742002-12-13 20:15:29 +0000160
161 /* Flags for connected address. */
162 u_char flags;
Andrew J. Schorre4529632006-12-12 19:18:21 +0000163#define ZEBRA_IFA_SECONDARY (1 << 0)
164#define ZEBRA_IFA_PEER (1 << 1)
165 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
166 a peer address has been configured. If this flag is set,
167 the destination field must contain the peer address.
168 Otherwise, if this flag is not set, the destination address
169 will either contain a broadcast address or be NULL.
170 */
paul718e3742002-12-13 20:15:29 +0000171
172 /* Address of connected network. */
173 struct prefix *address;
Andrew J. Schorre4529632006-12-12 19:18:21 +0000174
175 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
176 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
177 struct prefix *destination;
paul718e3742002-12-13 20:15:29 +0000178
179 /* Label for Linux 2.2.X and upper. */
180 char *label;
181};
182
Andrew J. Schorre4529632006-12-12 19:18:21 +0000183/* Does the destination field contain a peer address? */
184#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
hasso3fb9cd62004-10-19 19:44:43 +0000185
Andrew J. Schorre4529632006-12-12 19:18:21 +0000186/* Prefix to insert into the RIB */
187#define CONNECTED_PREFIX(C) \
188 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
189
190/* Identifying address. We guess that if there's a peer address, but the
191 local address is in the same prefix, then the local address may be unique. */
192#define CONNECTED_ID(C) \
193 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
194 (C)->destination : (C)->address)
hasso3fb9cd62004-10-19 19:44:43 +0000195
paul718e3742002-12-13 20:15:29 +0000196/* Interface hook sort. */
197#define IF_NEW_HOOK 0
198#define IF_DELETE_HOOK 1
199
200/* There are some interface flags which are only supported by some
201 operating system. */
202
203#ifndef IFF_NOTRAILERS
204#define IFF_NOTRAILERS 0x0
205#endif /* IFF_NOTRAILERS */
206#ifndef IFF_OACTIVE
207#define IFF_OACTIVE 0x0
208#endif /* IFF_OACTIVE */
209#ifndef IFF_SIMPLEX
210#define IFF_SIMPLEX 0x0
211#endif /* IFF_SIMPLEX */
212#ifndef IFF_LINK0
213#define IFF_LINK0 0x0
214#endif /* IFF_LINK0 */
215#ifndef IFF_LINK1
216#define IFF_LINK1 0x0
217#endif /* IFF_LINK1 */
218#ifndef IFF_LINK2
219#define IFF_LINK2 0x0
220#endif /* IFF_LINK2 */
paul4ba9b922004-12-21 22:34:58 +0000221#ifndef IFF_NOXMIT
222#define IFF_NOXMIT 0x0
223#endif /* IFF_NOXMIT */
224#ifndef IFF_NORTEXCH
225#define IFF_NORTEXCH 0x0
226#endif /* IFF_NORTEXCH */
227#ifndef IFF_IPV4
228#define IFF_IPV4 0x0
229#endif /* IFF_IPV4 */
230#ifndef IFF_IPV6
231#define IFF_IPV6 0x0
232#endif /* IFF_IPV6 */
233#ifndef IFF_VIRTUAL
234#define IFF_VIRTUAL 0x0
235#endif /* IFF_VIRTUAL */
paul718e3742002-12-13 20:15:29 +0000236
237/* Prototypes. */
paul8cc41982005-05-06 21:25:49 +0000238extern int if_cmp_func (struct interface *, struct interface *);
239extern struct interface *if_create (const char *name, int namelen);
240extern struct interface *if_lookup_by_index (unsigned int);
241extern struct interface *if_lookup_exact_address (struct in_addr);
242extern struct interface *if_lookup_address (struct in_addr);
ajsa3491982005-04-02 22:50:38 +0000243
ajs08dbfb62005-04-03 03:40:52 +0000244/* These 2 functions are to be used when the ifname argument is terminated
245 by a '\0' character: */
paul8cc41982005-05-06 21:25:49 +0000246extern struct interface *if_lookup_by_name (const char *ifname);
247extern struct interface *if_get_by_name (const char *ifname);
ajsd2fc8892005-04-02 18:38:43 +0000248
ajs08dbfb62005-04-03 03:40:52 +0000249/* For these 2 functions, the namelen argument should be the precise length
250 of the ifname string (not counting any optional trailing '\0' character).
251 In most cases, strnlen should be used to calculate the namelen value. */
252extern struct interface *if_lookup_by_name_len(const char *ifname,
ajsa3491982005-04-02 22:50:38 +0000253 size_t namelen);
ajs08dbfb62005-04-03 03:40:52 +0000254extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
ajsa3491982005-04-02 22:50:38 +0000255
256
ajsd2fc8892005-04-02 18:38:43 +0000257/* Delete the interface, but do not free the structure, and leave it in the
258 interface list. It is often advisable to leave the pseudo interface
259 structure because there may be configuration information attached. */
260extern void if_delete_retain (struct interface *);
261
262/* Delete and free the interface structure: calls if_delete_retain and then
263 deletes it from the interface list and frees the structure. */
264extern void if_delete (struct interface *);
265
paul8cc41982005-05-06 21:25:49 +0000266extern int if_is_up (struct interface *);
267extern int if_is_running (struct interface *);
268extern int if_is_operative (struct interface *);
269extern int if_is_loopback (struct interface *);
270extern int if_is_broadcast (struct interface *);
271extern int if_is_pointopoint (struct interface *);
272extern int if_is_multicast (struct interface *);
273extern void if_add_hook (int, int (*)(struct interface *));
274extern void if_init (void);
Tom Goff4bd045d2010-11-10 13:00:54 -0800275extern void if_terminate (void);
paul8cc41982005-05-06 21:25:49 +0000276extern void if_dump_all (void);
ajs847947f2005-02-02 18:38:48 +0000277extern const char *if_flag_dump(unsigned long);
paul718e3742002-12-13 20:15:29 +0000278
ajsd2fc8892005-04-02 18:38:43 +0000279/* Please use ifindex2ifname instead of if_indextoname where possible;
280 ifindex2ifname uses internal interface info, whereas if_indextoname must
281 make a system call. */
paul8cc41982005-05-06 21:25:49 +0000282extern const char *ifindex2ifname (unsigned int);
ajsd2fc8892005-04-02 18:38:43 +0000283
284/* Please use ifname2ifindex instead of if_nametoindex where possible;
285 ifname2ifindex uses internal interface info, whereas if_nametoindex must
286 make a system call. */
287extern unsigned int ifname2ifindex(const char *ifname);
288
paul718e3742002-12-13 20:15:29 +0000289/* Connected address functions. */
paul8cc41982005-05-06 21:25:49 +0000290extern struct connected *connected_new (void);
291extern void connected_free (struct connected *);
292extern void connected_add (struct interface *, struct connected *);
293extern struct connected *connected_add_by_prefix (struct interface *,
paul4a7aac12004-05-08 05:00:31 +0000294 struct prefix *,
295 struct prefix *);
paul8cc41982005-05-06 21:25:49 +0000296extern struct connected *connected_delete_by_prefix (struct interface *,
paul4a7aac12004-05-08 05:00:31 +0000297 struct prefix *);
paul8cc41982005-05-06 21:25:49 +0000298extern struct connected *connected_lookup_address (struct interface *,
paul4a7aac12004-05-08 05:00:31 +0000299 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000300
301#ifndef HAVE_IF_NAMETOINDEX
paul8cc41982005-05-06 21:25:49 +0000302extern unsigned int if_nametoindex (const char *);
paul718e3742002-12-13 20:15:29 +0000303#endif
304#ifndef HAVE_IF_INDEXTONAME
paul8cc41982005-05-06 21:25:49 +0000305extern char *if_indextoname (unsigned int, char *);
paul718e3742002-12-13 20:15:29 +0000306#endif
307
308/* Exported variables. */
hasso52dc7ee2004-09-23 19:18:23 +0000309extern struct list *iflist;
paul718e3742002-12-13 20:15:29 +0000310extern struct cmd_element interface_desc_cmd;
311extern struct cmd_element no_interface_desc_cmd;
312extern struct cmd_element interface_cmd;
paul32d24632003-05-23 09:25:20 +0000313extern struct cmd_element no_interface_cmd;
paul718e3742002-12-13 20:15:29 +0000314extern struct cmd_element interface_pseudo_cmd;
315extern struct cmd_element no_interface_pseudo_cmd;
Paul Jakma478ccfd2006-03-06 18:18:37 +0000316extern struct cmd_element show_address_cmd;
paul718e3742002-12-13 20:15:29 +0000317
318#endif /* _ZEBRA_IF_H */