blob: 0cb2202a7c612cc30f6d4ef405c5b3b41fec3b04 [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
Timo Teräs954c7d62016-01-15 17:36:33 +020026/* Interface link-layer type, if known. Derived from:
27 *
28 * net/if_arp.h on various platforms - Linux especially.
29 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
30 *
31 * Some of the more obviously defunct technologies left out.
32 */
33enum zebra_link_type {
34 ZEBRA_LLT_UNKNOWN = 0,
35 ZEBRA_LLT_ETHER,
36 ZEBRA_LLT_EETHER,
37 ZEBRA_LLT_AX25,
38 ZEBRA_LLT_PRONET,
39 ZEBRA_LLT_IEEE802,
40 ZEBRA_LLT_ARCNET,
41 ZEBRA_LLT_APPLETLK,
42 ZEBRA_LLT_DLCI,
43 ZEBRA_LLT_ATM,
44 ZEBRA_LLT_METRICOM,
45 ZEBRA_LLT_IEEE1394,
46 ZEBRA_LLT_EUI64,
47 ZEBRA_LLT_INFINIBAND,
48 ZEBRA_LLT_SLIP,
49 ZEBRA_LLT_CSLIP,
50 ZEBRA_LLT_SLIP6,
51 ZEBRA_LLT_CSLIP6,
52 ZEBRA_LLT_RSRVD,
53 ZEBRA_LLT_ADAPT,
54 ZEBRA_LLT_ROSE,
55 ZEBRA_LLT_X25,
56 ZEBRA_LLT_PPP,
57 ZEBRA_LLT_CHDLC,
58 ZEBRA_LLT_LAPB,
59 ZEBRA_LLT_RAWHDLC,
60 ZEBRA_LLT_IPIP,
61 ZEBRA_LLT_IPIP6,
62 ZEBRA_LLT_FRAD,
63 ZEBRA_LLT_SKIP,
64 ZEBRA_LLT_LOOPBACK,
65 ZEBRA_LLT_LOCALTLK,
66 ZEBRA_LLT_FDDI,
67 ZEBRA_LLT_SIT,
68 ZEBRA_LLT_IPDDP,
69 ZEBRA_LLT_IPGRE,
70 ZEBRA_LLT_IP6GRE,
71 ZEBRA_LLT_PIMREG,
72 ZEBRA_LLT_HIPPI,
73 ZEBRA_LLT_ECONET,
74 ZEBRA_LLT_IRDA,
75 ZEBRA_LLT_FCPP,
76 ZEBRA_LLT_FCAL,
77 ZEBRA_LLT_FCPL,
78 ZEBRA_LLT_FCFABRIC,
79 ZEBRA_LLT_IEEE802_TR,
80 ZEBRA_LLT_IEEE80211,
81 ZEBRA_LLT_IEEE80211_RADIOTAP,
82 ZEBRA_LLT_IEEE802154,
83 ZEBRA_LLT_IEEE802154_PHY,
84};
85
paul718e3742002-12-13 20:15:29 +000086/*
87 Interface name length.
88
89 Linux define value in /usr/include/linux/if.h.
90 #define IFNAMSIZ 16
91
92 FreeBSD define value in /usr/include/net/if.h.
93 #define IFNAMSIZ 16
94*/
95
96#define INTERFACE_NAMSIZ 20
97#define INTERFACE_HWADDR_MAX 20
98
paul718e3742002-12-13 20:15:29 +000099#ifdef HAVE_PROC_NET_DEV
100struct if_stats
101{
102 unsigned long rx_packets; /* total packets received */
103 unsigned long tx_packets; /* total packets transmitted */
104 unsigned long rx_bytes; /* total bytes received */
105 unsigned long tx_bytes; /* total bytes transmitted */
106 unsigned long rx_errors; /* bad packets received */
107 unsigned long tx_errors; /* packet transmit problems */
108 unsigned long rx_dropped; /* no space in linux buffers */
109 unsigned long tx_dropped; /* no space available in linux */
110 unsigned long rx_multicast; /* multicast packets received */
111 unsigned long rx_compressed;
112 unsigned long tx_compressed;
113 unsigned long collisions;
114
115 /* detailed rx_errors: */
116 unsigned long rx_length_errors;
117 unsigned long rx_over_errors; /* receiver ring buff overflow */
118 unsigned long rx_crc_errors; /* recved pkt with crc error */
119 unsigned long rx_frame_errors; /* recv'd frame alignment error */
120 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
121 unsigned long rx_missed_errors; /* receiver missed packet */
122 /* detailed tx_errors */
123 unsigned long tx_aborted_errors;
124 unsigned long tx_carrier_errors;
125 unsigned long tx_fifo_errors;
126 unsigned long tx_heartbeat_errors;
127 unsigned long tx_window_errors;
128};
129#endif /* HAVE_PROC_NET_DEV */
130
131/* Interface structure */
132struct interface
133{
ajsd2fc8892005-04-02 18:38:43 +0000134 /* Interface name. This should probably never be changed after the
135 interface is created, because the configuration info for this interface
136 is associated with this structure. For that reason, the interface
137 should also never be deleted (to avoid losing configuration info).
138 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
139 interface does not exist in the kernel.
140 */
paul718e3742002-12-13 20:15:29 +0000141 char name[INTERFACE_NAMSIZ + 1];
142
ajsd2fc8892005-04-02 18:38:43 +0000143 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
144 deleted interfaces). */
paul718e3742002-12-13 20:15:29 +0000145 unsigned int ifindex;
ajsd2fc8892005-04-02 18:38:43 +0000146#define IFINDEX_INTERNAL 0
paul718e3742002-12-13 20:15:29 +0000147
148 /* Zebra internal interface status */
149 u_char status;
150#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
151#define ZEBRA_INTERFACE_SUB (1 << 1)
paul2e3b2e42002-12-13 21:03:13 +0000152#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
paul718e3742002-12-13 20:15:29 +0000153
154 /* Interface flags. */
paulc77d4542006-01-11 01:59:04 +0000155 uint64_t flags;
paul718e3742002-12-13 20:15:29 +0000156
157 /* Interface metric */
158 int metric;
159
160 /* Interface MTU. */
paulc9eca012004-10-11 11:28:44 +0000161 unsigned int mtu; /* IPv4 MTU */
162 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
paul718e3742002-12-13 20:15:29 +0000163
Timo Teräs954c7d62016-01-15 17:36:33 +0200164 /* Link-layer information and hardware address */
165 enum zebra_link_type ll_type;
paul718e3742002-12-13 20:15:29 +0000166 u_char hw_addr[INTERFACE_HWADDR_MAX];
167 int hw_addr_len;
paul718e3742002-12-13 20:15:29 +0000168
169 /* interface bandwidth, kbits */
170 unsigned int bandwidth;
171
172 /* description of the interface. */
173 char *desc;
174
175 /* Distribute list. */
176 void *distribute_in;
177 void *distribute_out;
178
179 /* Connected address list. */
hasso52dc7ee2004-09-23 19:18:23 +0000180 struct list *connected;
paul718e3742002-12-13 20:15:29 +0000181
182 /* Daemon specific interface data pointer. */
183 void *info;
184
185 /* Statistics fileds. */
186#ifdef HAVE_PROC_NET_DEV
187 struct if_stats stats;
188#endif /* HAVE_PROC_NET_DEV */
189#ifdef HAVE_NET_RT_IFLIST
190 struct if_data stats;
191#endif /* HAVE_NET_RT_IFLIST */
Feng Lu2fc97f62015-05-22 11:39:57 +0200192
193 vrf_id_t vrf_id;
paul718e3742002-12-13 20:15:29 +0000194};
195
196/* Connected address structure. */
197struct connected
198{
199 /* Attached interface. */
200 struct interface *ifp;
201
202 /* Flags for configuration. */
203 u_char conf;
204#define ZEBRA_IFC_REAL (1 << 0)
205#define ZEBRA_IFC_CONFIGURED (1 << 1)
Christian Frankef7f740f2013-01-24 14:04:48 +0000206#define ZEBRA_IFC_QUEUED (1 << 2)
Andrew J. Schorr9c378512006-05-21 04:04:49 +0000207 /*
208 The ZEBRA_IFC_REAL flag should be set if and only if this address
Christian Frankef7f740f2013-01-24 14:04:48 +0000209 exists in the kernel and is actually usable. (A case where it exists but
210 is not yet usable would be IPv6 with DAD)
Andrew J. Schorr9c378512006-05-21 04:04:49 +0000211 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
212 was configured by the user from inside quagga.
Christian Frankef7f740f2013-01-24 14:04:48 +0000213 The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
214 in the kernel. It may and should be set although the address might not be
215 usable yet. (compare with ZEBRA_IFC_REAL)
Andrew J. Schorr9c378512006-05-21 04:04:49 +0000216 */
paul718e3742002-12-13 20:15:29 +0000217
218 /* Flags for connected address. */
219 u_char flags;
Andrew J. Schorre4529632006-12-12 19:18:21 +0000220#define ZEBRA_IFA_SECONDARY (1 << 0)
221#define ZEBRA_IFA_PEER (1 << 1)
222 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
223 a peer address has been configured. If this flag is set,
224 the destination field must contain the peer address.
225 Otherwise, if this flag is not set, the destination address
226 will either contain a broadcast address or be NULL.
227 */
paul718e3742002-12-13 20:15:29 +0000228
229 /* Address of connected network. */
230 struct prefix *address;
Andrew J. Schorre4529632006-12-12 19:18:21 +0000231
232 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
233 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
234 struct prefix *destination;
paul718e3742002-12-13 20:15:29 +0000235
236 /* Label for Linux 2.2.X and upper. */
237 char *label;
238};
239
Andrew J. Schorre4529632006-12-12 19:18:21 +0000240/* Does the destination field contain a peer address? */
241#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
hasso3fb9cd62004-10-19 19:44:43 +0000242
Andrew J. Schorre4529632006-12-12 19:18:21 +0000243/* Prefix to insert into the RIB */
244#define CONNECTED_PREFIX(C) \
245 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
246
247/* Identifying address. We guess that if there's a peer address, but the
248 local address is in the same prefix, then the local address may be unique. */
249#define CONNECTED_ID(C) \
250 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
251 (C)->destination : (C)->address)
hasso3fb9cd62004-10-19 19:44:43 +0000252
paul718e3742002-12-13 20:15:29 +0000253/* Interface hook sort. */
254#define IF_NEW_HOOK 0
255#define IF_DELETE_HOOK 1
256
257/* There are some interface flags which are only supported by some
258 operating system. */
259
260#ifndef IFF_NOTRAILERS
261#define IFF_NOTRAILERS 0x0
262#endif /* IFF_NOTRAILERS */
263#ifndef IFF_OACTIVE
264#define IFF_OACTIVE 0x0
265#endif /* IFF_OACTIVE */
266#ifndef IFF_SIMPLEX
267#define IFF_SIMPLEX 0x0
268#endif /* IFF_SIMPLEX */
269#ifndef IFF_LINK0
270#define IFF_LINK0 0x0
271#endif /* IFF_LINK0 */
272#ifndef IFF_LINK1
273#define IFF_LINK1 0x0
274#endif /* IFF_LINK1 */
275#ifndef IFF_LINK2
276#define IFF_LINK2 0x0
277#endif /* IFF_LINK2 */
paul4ba9b922004-12-21 22:34:58 +0000278#ifndef IFF_NOXMIT
279#define IFF_NOXMIT 0x0
280#endif /* IFF_NOXMIT */
281#ifndef IFF_NORTEXCH
282#define IFF_NORTEXCH 0x0
283#endif /* IFF_NORTEXCH */
284#ifndef IFF_IPV4
285#define IFF_IPV4 0x0
286#endif /* IFF_IPV4 */
287#ifndef IFF_IPV6
288#define IFF_IPV6 0x0
289#endif /* IFF_IPV6 */
290#ifndef IFF_VIRTUAL
291#define IFF_VIRTUAL 0x0
292#endif /* IFF_VIRTUAL */
paul718e3742002-12-13 20:15:29 +0000293
294/* Prototypes. */
paul8cc41982005-05-06 21:25:49 +0000295extern int if_cmp_func (struct interface *, struct interface *);
296extern struct interface *if_create (const char *name, int namelen);
297extern struct interface *if_lookup_by_index (unsigned int);
298extern struct interface *if_lookup_exact_address (struct in_addr);
299extern struct interface *if_lookup_address (struct in_addr);
Dinesh Duttb81e97a2013-08-24 07:55:50 +0000300extern struct interface *if_lookup_prefix (struct prefix *prefix);
ajsa3491982005-04-02 22:50:38 +0000301
Feng Lu5a5702f2015-05-22 11:39:59 +0200302extern struct interface *if_create_vrf (const char *name, int namelen,
303 vrf_id_t vrf_id);
304extern struct interface *if_lookup_by_index_vrf (unsigned int,
305 vrf_id_t vrf_id);
306extern struct interface *if_lookup_exact_address_vrf (struct in_addr,
307 vrf_id_t vrf_id);
308extern struct interface *if_lookup_address_vrf (struct in_addr,
309 vrf_id_t vrf_id);
310extern struct interface *if_lookup_prefix_vrf (struct prefix *prefix,
311 vrf_id_t vrf_id);
312
ajs08dbfb62005-04-03 03:40:52 +0000313/* These 2 functions are to be used when the ifname argument is terminated
314 by a '\0' character: */
paul8cc41982005-05-06 21:25:49 +0000315extern struct interface *if_lookup_by_name (const char *ifname);
316extern struct interface *if_get_by_name (const char *ifname);
ajsd2fc8892005-04-02 18:38:43 +0000317
Feng Lu5a5702f2015-05-22 11:39:59 +0200318extern struct interface *if_lookup_by_name_vrf (const char *ifname,
319 vrf_id_t vrf_id);
320extern struct interface *if_get_by_name_vrf (const char *ifname,
321 vrf_id_t vrf_id);
322
ajs08dbfb62005-04-03 03:40:52 +0000323/* For these 2 functions, the namelen argument should be the precise length
324 of the ifname string (not counting any optional trailing '\0' character).
325 In most cases, strnlen should be used to calculate the namelen value. */
326extern struct interface *if_lookup_by_name_len(const char *ifname,
Feng Lu5a5702f2015-05-22 11:39:59 +0200327 size_t namelen);
328extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen);
329
330extern struct interface *if_lookup_by_name_len_vrf(const char *ifname,
331 size_t namelen, vrf_id_t vrf_id);
332extern struct interface *if_get_by_name_len_vrf(const char *ifname,
333 size_t namelen, vrf_id_t vrf_id);
ajsa3491982005-04-02 22:50:38 +0000334
335
ajsd2fc8892005-04-02 18:38:43 +0000336/* Delete the interface, but do not free the structure, and leave it in the
337 interface list. It is often advisable to leave the pseudo interface
338 structure because there may be configuration information attached. */
339extern void if_delete_retain (struct interface *);
340
341/* Delete and free the interface structure: calls if_delete_retain and then
342 deletes it from the interface list and frees the structure. */
343extern void if_delete (struct interface *);
344
paul8cc41982005-05-06 21:25:49 +0000345extern int if_is_up (struct interface *);
346extern int if_is_running (struct interface *);
347extern int if_is_operative (struct interface *);
348extern int if_is_loopback (struct interface *);
349extern int if_is_broadcast (struct interface *);
350extern int if_is_pointopoint (struct interface *);
351extern int if_is_multicast (struct interface *);
352extern void if_add_hook (int, int (*)(struct interface *));
Feng Lu5a5702f2015-05-22 11:39:59 +0200353extern void if_init (vrf_id_t, struct list **);
354extern void if_terminate (vrf_id_t, struct list **);
paul8cc41982005-05-06 21:25:49 +0000355extern void if_dump_all (void);
ajs847947f2005-02-02 18:38:48 +0000356extern const char *if_flag_dump(unsigned long);
Timo Teräs954c7d62016-01-15 17:36:33 +0200357extern const char *if_link_type_str (enum zebra_link_type);
paul718e3742002-12-13 20:15:29 +0000358
ajsd2fc8892005-04-02 18:38:43 +0000359/* Please use ifindex2ifname instead of if_indextoname where possible;
360 ifindex2ifname uses internal interface info, whereas if_indextoname must
361 make a system call. */
paul8cc41982005-05-06 21:25:49 +0000362extern const char *ifindex2ifname (unsigned int);
Feng Lu5a5702f2015-05-22 11:39:59 +0200363extern const char *ifindex2ifname_vrf (unsigned int, vrf_id_t vrf_id);
ajsd2fc8892005-04-02 18:38:43 +0000364
365/* Please use ifname2ifindex instead of if_nametoindex where possible;
366 ifname2ifindex uses internal interface info, whereas if_nametoindex must
367 make a system call. */
368extern unsigned int ifname2ifindex(const char *ifname);
Feng Lu5a5702f2015-05-22 11:39:59 +0200369extern unsigned int ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id);
ajsd2fc8892005-04-02 18:38:43 +0000370
paul718e3742002-12-13 20:15:29 +0000371/* Connected address functions. */
paul8cc41982005-05-06 21:25:49 +0000372extern struct connected *connected_new (void);
373extern void connected_free (struct connected *);
374extern void connected_add (struct interface *, struct connected *);
375extern struct connected *connected_add_by_prefix (struct interface *,
paul4a7aac12004-05-08 05:00:31 +0000376 struct prefix *,
377 struct prefix *);
paul8cc41982005-05-06 21:25:49 +0000378extern struct connected *connected_delete_by_prefix (struct interface *,
paul4a7aac12004-05-08 05:00:31 +0000379 struct prefix *);
paul8cc41982005-05-06 21:25:49 +0000380extern struct connected *connected_lookup_address (struct interface *,
paul4a7aac12004-05-08 05:00:31 +0000381 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000382
383#ifndef HAVE_IF_NAMETOINDEX
paul8cc41982005-05-06 21:25:49 +0000384extern unsigned int if_nametoindex (const char *);
paul718e3742002-12-13 20:15:29 +0000385#endif
386#ifndef HAVE_IF_INDEXTONAME
paul8cc41982005-05-06 21:25:49 +0000387extern char *if_indextoname (unsigned int, char *);
paul718e3742002-12-13 20:15:29 +0000388#endif
389
390/* Exported variables. */
hasso52dc7ee2004-09-23 19:18:23 +0000391extern struct list *iflist;
paul718e3742002-12-13 20:15:29 +0000392extern struct cmd_element interface_desc_cmd;
393extern struct cmd_element no_interface_desc_cmd;
394extern struct cmd_element interface_cmd;
paul32d24632003-05-23 09:25:20 +0000395extern struct cmd_element no_interface_cmd;
Feng Lu471ea392015-05-22 11:40:00 +0200396extern struct cmd_element interface_vrf_cmd;
397extern struct cmd_element no_interface_vrf_cmd;
paul718e3742002-12-13 20:15:29 +0000398extern struct cmd_element interface_pseudo_cmd;
399extern struct cmd_element no_interface_pseudo_cmd;
Paul Jakma478ccfd2006-03-06 18:18:37 +0000400extern struct cmd_element show_address_cmd;
Feng Lu5a5702f2015-05-22 11:39:59 +0200401extern struct cmd_element show_address_vrf_cmd;
402extern struct cmd_element show_address_vrf_all_cmd;
paul718e3742002-12-13 20:15:29 +0000403
404#endif /* _ZEBRA_IF_H */