]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.h
lib, zebra: unify link layer type and hardware address handling
[mirror_frr.git] / lib / if.h
CommitLineData
718e3744 1/* 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
b892f1dd 24#include "zebra.h"
718e3744 25#include "linklist.h"
26
8ccc7e80
TT
27/* Interface link-layer type, if known. Derived from:
28 *
29 * net/if_arp.h on various platforms - Linux especially.
30 * http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
31 *
32 * Some of the more obviously defunct technologies left out.
33 */
34enum zebra_link_type {
35 ZEBRA_LLT_UNKNOWN = 0,
36 ZEBRA_LLT_ETHER,
37 ZEBRA_LLT_EETHER,
38 ZEBRA_LLT_AX25,
39 ZEBRA_LLT_PRONET,
40 ZEBRA_LLT_IEEE802,
41 ZEBRA_LLT_ARCNET,
42 ZEBRA_LLT_APPLETLK,
43 ZEBRA_LLT_DLCI,
44 ZEBRA_LLT_ATM,
45 ZEBRA_LLT_METRICOM,
46 ZEBRA_LLT_IEEE1394,
47 ZEBRA_LLT_EUI64,
48 ZEBRA_LLT_INFINIBAND,
49 ZEBRA_LLT_SLIP,
50 ZEBRA_LLT_CSLIP,
51 ZEBRA_LLT_SLIP6,
52 ZEBRA_LLT_CSLIP6,
53 ZEBRA_LLT_RSRVD,
54 ZEBRA_LLT_ADAPT,
55 ZEBRA_LLT_ROSE,
56 ZEBRA_LLT_X25,
57 ZEBRA_LLT_PPP,
58 ZEBRA_LLT_CHDLC,
59 ZEBRA_LLT_LAPB,
60 ZEBRA_LLT_RAWHDLC,
61 ZEBRA_LLT_IPIP,
62 ZEBRA_LLT_IPIP6,
63 ZEBRA_LLT_FRAD,
64 ZEBRA_LLT_SKIP,
65 ZEBRA_LLT_LOOPBACK,
66 ZEBRA_LLT_LOCALTLK,
67 ZEBRA_LLT_FDDI,
68 ZEBRA_LLT_SIT,
69 ZEBRA_LLT_IPDDP,
70 ZEBRA_LLT_IPGRE,
71 ZEBRA_LLT_IP6GRE,
72 ZEBRA_LLT_PIMREG,
73 ZEBRA_LLT_HIPPI,
74 ZEBRA_LLT_ECONET,
75 ZEBRA_LLT_IRDA,
76 ZEBRA_LLT_FCPP,
77 ZEBRA_LLT_FCAL,
78 ZEBRA_LLT_FCPL,
79 ZEBRA_LLT_FCFABRIC,
80 ZEBRA_LLT_IEEE802_TR,
81 ZEBRA_LLT_IEEE80211,
82 ZEBRA_LLT_IEEE80211_RADIOTAP,
83 ZEBRA_LLT_IEEE802154,
84 ZEBRA_LLT_IEEE802154_PHY,
85};
86
718e3744 87/*
88 Interface name length.
89
90 Linux define value in /usr/include/linux/if.h.
91 #define IFNAMSIZ 16
92
93 FreeBSD define value in /usr/include/net/if.h.
94 #define IFNAMSIZ 16
95*/
96
97#define INTERFACE_NAMSIZ 20
98#define INTERFACE_HWADDR_MAX 20
99
b892f1dd
PJ
100typedef signed int ifindex_t;
101
718e3744 102#ifdef HAVE_PROC_NET_DEV
103struct if_stats
104{
105 unsigned long rx_packets; /* total packets received */
106 unsigned long tx_packets; /* total packets transmitted */
107 unsigned long rx_bytes; /* total bytes received */
108 unsigned long tx_bytes; /* total bytes transmitted */
109 unsigned long rx_errors; /* bad packets received */
110 unsigned long tx_errors; /* packet transmit problems */
111 unsigned long rx_dropped; /* no space in linux buffers */
112 unsigned long tx_dropped; /* no space available in linux */
113 unsigned long rx_multicast; /* multicast packets received */
114 unsigned long rx_compressed;
115 unsigned long tx_compressed;
116 unsigned long collisions;
117
118 /* detailed rx_errors: */
119 unsigned long rx_length_errors;
120 unsigned long rx_over_errors; /* receiver ring buff overflow */
121 unsigned long rx_crc_errors; /* recved pkt with crc error */
122 unsigned long rx_frame_errors; /* recv'd frame alignment error */
123 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
124 unsigned long rx_missed_errors; /* receiver missed packet */
125 /* detailed tx_errors */
126 unsigned long tx_aborted_errors;
127 unsigned long tx_carrier_errors;
128 unsigned long tx_fifo_errors;
129 unsigned long tx_heartbeat_errors;
130 unsigned long tx_window_errors;
131};
132#endif /* HAVE_PROC_NET_DEV */
133
134/* Interface structure */
135struct interface
136{
d2fc8896 137 /* Interface name. This should probably never be changed after the
138 interface is created, because the configuration info for this interface
139 is associated with this structure. For that reason, the interface
140 should also never be deleted (to avoid losing configuration info).
141 To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
142 interface does not exist in the kernel.
143 */
718e3744 144 char name[INTERFACE_NAMSIZ + 1];
145
d2fc8896 146 /* Interface index (should be IFINDEX_INTERNAL for non-kernel or
147 deleted interfaces). */
b892f1dd 148 ifindex_t ifindex;
d2fc8896 149#define IFINDEX_INTERNAL 0
b892f1dd 150#define IFINDEX_DELETED INT_MAX
718e3744 151
152 /* Zebra internal interface status */
153 u_char status;
154#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
155#define ZEBRA_INTERFACE_SUB (1 << 1)
2e3b2e47 156#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
c23af4d3 157#define ZEBRA_INTERFACE_VRF_LOOPBACK (1 << 3)
525c1839 158
718e3744 159 /* Interface flags. */
c77d4546 160 uint64_t flags;
718e3744 161
162 /* Interface metric */
163 int metric;
164
165 /* Interface MTU. */
c9eca01b 166 unsigned int mtu; /* IPv4 MTU */
167 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
718e3744 168
8ccc7e80
TT
169 /* Link-layer information and hardware address */
170 enum zebra_link_type ll_type;
718e3744 171 u_char hw_addr[INTERFACE_HWADDR_MAX];
172 int hw_addr_len;
718e3744 173
174 /* interface bandwidth, kbits */
175 unsigned int bandwidth;
176
177 /* description of the interface. */
178 char *desc;
179
180 /* Distribute list. */
181 void *distribute_in;
182 void *distribute_out;
183
184 /* Connected address list. */
52dc7ee6 185 struct list *connected;
718e3744 186
a80beece
DS
187 /* Neighbor connected address list. */
188 struct list *nbr_connected;
189
718e3744 190 /* Daemon specific interface data pointer. */
191 void *info;
192
244c1cdc
DS
193 char ptm_enable; /* Should we look at ptm_status ? */
194 char ptm_status;
195
718e3744 196 /* Statistics fileds. */
197#ifdef HAVE_PROC_NET_DEV
198 struct if_stats stats;
199#endif /* HAVE_PROC_NET_DEV */
200#ifdef HAVE_NET_RT_IFLIST
201 struct if_data stats;
202#endif /* HAVE_NET_RT_IFLIST */
3968dbf8 203
f93e3f69 204 struct route_node *node;
3968dbf8 205 vrf_id_t vrf_id;
718e3744 206};
207
208/* Connected address structure. */
209struct connected
210{
211 /* Attached interface. */
212 struct interface *ifp;
213
214 /* Flags for configuration. */
215 u_char conf;
216#define ZEBRA_IFC_REAL (1 << 0)
217#define ZEBRA_IFC_CONFIGURED (1 << 1)
f7f740fe 218#define ZEBRA_IFC_QUEUED (1 << 2)
9c37851e
AS
219 /*
220 The ZEBRA_IFC_REAL flag should be set if and only if this address
f7f740fe
CF
221 exists in the kernel and is actually usable. (A case where it exists but
222 is not yet usable would be IPv6 with DAD)
9c37851e
AS
223 The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
224 was configured by the user from inside quagga.
f7f740fe
CF
225 The ZEBRA_IFC_QUEUED flag should be set if and only if the address exists
226 in the kernel. It may and should be set although the address might not be
227 usable yet. (compare with ZEBRA_IFC_REAL)
9c37851e 228 */
718e3744 229
230 /* Flags for connected address. */
231 u_char flags;
e4529636
AS
232#define ZEBRA_IFA_SECONDARY (1 << 0)
233#define ZEBRA_IFA_PEER (1 << 1)
525c1839 234#define ZEBRA_IFA_UNNUMBERED (1 << 2)
e4529636
AS
235 /* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
236 a peer address has been configured. If this flag is set,
237 the destination field must contain the peer address.
238 Otherwise, if this flag is not set, the destination address
239 will either contain a broadcast address or be NULL.
240 */
718e3744 241
242 /* Address of connected network. */
243 struct prefix *address;
e4529636
AS
244
245 /* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
246 Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
247 struct prefix *destination;
718e3744 248
249 /* Label for Linux 2.2.X and upper. */
250 char *label;
251};
252
a80beece
DS
253/* Nbr Connected address structure. */
254struct nbr_connected
255{
256 /* Attached interface. */
257 struct interface *ifp;
258
259 /* Address of connected network. */
260 struct prefix *address;
261};
262
e4529636
AS
263/* Does the destination field contain a peer address? */
264#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
265
266/* Prefix to insert into the RIB */
267#define CONNECTED_PREFIX(C) \
268 (CONNECTED_PEER(C) ? (C)->destination : (C)->address)
3fb9cd6e 269
e4529636
AS
270/* Identifying address. We guess that if there's a peer address, but the
271 local address is in the same prefix, then the local address may be unique. */
272#define CONNECTED_ID(C) \
273 ((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
274 (C)->destination : (C)->address)
3fb9cd6e 275
718e3744 276/* Interface hook sort. */
277#define IF_NEW_HOOK 0
278#define IF_DELETE_HOOK 1
279
280/* There are some interface flags which are only supported by some
281 operating system. */
282
283#ifndef IFF_NOTRAILERS
284#define IFF_NOTRAILERS 0x0
285#endif /* IFF_NOTRAILERS */
286#ifndef IFF_OACTIVE
287#define IFF_OACTIVE 0x0
288#endif /* IFF_OACTIVE */
289#ifndef IFF_SIMPLEX
290#define IFF_SIMPLEX 0x0
291#endif /* IFF_SIMPLEX */
292#ifndef IFF_LINK0
293#define IFF_LINK0 0x0
294#endif /* IFF_LINK0 */
295#ifndef IFF_LINK1
296#define IFF_LINK1 0x0
297#endif /* IFF_LINK1 */
298#ifndef IFF_LINK2
299#define IFF_LINK2 0x0
300#endif /* IFF_LINK2 */
4ba9b924 301#ifndef IFF_NOXMIT
302#define IFF_NOXMIT 0x0
303#endif /* IFF_NOXMIT */
304#ifndef IFF_NORTEXCH
305#define IFF_NORTEXCH 0x0
306#endif /* IFF_NORTEXCH */
307#ifndef IFF_IPV4
308#define IFF_IPV4 0x0
309#endif /* IFF_IPV4 */
310#ifndef IFF_IPV6
311#define IFF_IPV6 0x0
312#endif /* IFF_IPV6 */
313#ifndef IFF_VIRTUAL
314#define IFF_VIRTUAL 0x0
315#endif /* IFF_VIRTUAL */
718e3744 316
317/* Prototypes. */
974fc9d2 318extern int if_cmp_name_func (char *, char *);
8cc4198f 319extern struct interface *if_create (const char *name, int namelen);
b892f1dd 320extern struct interface *if_lookup_by_index (ifindex_t);
0aabccc0
DD
321extern struct interface *if_lookup_exact_address (void *matchaddr, int family);
322extern struct interface *if_lookup_address (void *matchaddr, int family);
b81e97a8 323extern struct interface *if_lookup_prefix (struct prefix *prefix);
a349198f 324
f93e3f69
DS
325extern void if_update_vrf (struct interface *, const char *name, int namelen,
326 vrf_id_t vrf_id);
8736158a
FL
327extern struct interface *if_create_vrf (const char *name, int namelen,
328 vrf_id_t vrf_id);
b892f1dd 329extern struct interface *if_lookup_by_index_vrf (ifindex_t, vrf_id_t vrf_id);
8736158a
FL
330extern struct interface *if_lookup_exact_address_vrf (void *matchaddr, int family,
331 vrf_id_t vrf_id);
332extern struct interface *if_lookup_address_vrf (void *matchaddr, int family,
333 vrf_id_t vrf_id);
334extern struct interface *if_lookup_prefix_vrf (struct prefix *prefix,
335 vrf_id_t vrf_id);
336
08dbfb69 337/* These 2 functions are to be used when the ifname argument is terminated
338 by a '\0' character: */
8cc4198f 339extern struct interface *if_lookup_by_name (const char *ifname);
340extern struct interface *if_get_by_name (const char *ifname);
08dbfb69 341
f8962871 342extern struct interface *if_lookup_by_name_all_vrf (const char *ifname);
8736158a
FL
343extern struct interface *if_lookup_by_name_vrf (const char *ifname,
344 vrf_id_t vrf_id);
345extern struct interface *if_get_by_name_vrf (const char *ifname,
346 vrf_id_t vrf_id);
347
08dbfb69 348/* For these 2 functions, the namelen argument should be the precise length
349 of the ifname string (not counting any optional trailing '\0' character).
350 In most cases, strnlen should be used to calculate the namelen value. */
351extern struct interface *if_lookup_by_name_len(const char *ifname,
8736158a
FL
352 size_t namelen);
353extern struct interface *if_get_by_name_len(const char *ifname,size_t namelen);
354
355extern struct interface *if_lookup_by_name_len_vrf(const char *ifname,
356 size_t namelen, vrf_id_t vrf_id);
357extern struct interface *if_get_by_name_len_vrf(const char *ifname,
85f9da7f 358 size_t namelen, vrf_id_t vrf_id, int vty);
a349198f 359
360
d2fc8896 361/* Delete the interface, but do not free the structure, and leave it in the
362 interface list. It is often advisable to leave the pseudo interface
363 structure because there may be configuration information attached. */
364extern void if_delete_retain (struct interface *);
365
366/* Delete and free the interface structure: calls if_delete_retain and then
367 deletes it from the interface list and frees the structure. */
368extern void if_delete (struct interface *);
369
8cc4198f 370extern int if_is_up (struct interface *);
371extern int if_is_running (struct interface *);
372extern int if_is_operative (struct interface *);
244c1cdc 373extern int if_is_no_ptm_operative (struct interface *);
8cc4198f 374extern int if_is_loopback (struct interface *);
375extern int if_is_broadcast (struct interface *);
376extern int if_is_pointopoint (struct interface *);
377extern int if_is_multicast (struct interface *);
378extern void if_add_hook (int, int (*)(struct interface *));
b2d7c082
DS
379extern void if_init (struct list **);
380extern void if_terminate (struct list **);
8cc4198f 381extern void if_dump_all (void);
847947f2 382extern const char *if_flag_dump(unsigned long);
8ccc7e80 383extern const char *if_link_type_str (enum zebra_link_type);
718e3744 384
d2fc8896 385/* Please use ifindex2ifname instead of if_indextoname where possible;
386 ifindex2ifname uses internal interface info, whereas if_indextoname must
387 make a system call. */
b892f1dd
PJ
388extern const char *ifindex2ifname (ifindex_t);
389extern const char *ifindex2ifname_vrf (ifindex_t, vrf_id_t vrf_id);
d2fc8896 390
391/* Please use ifname2ifindex instead of if_nametoindex where possible;
392 ifname2ifindex uses internal interface info, whereas if_nametoindex must
393 make a system call. */
b892f1dd
PJ
394extern ifindex_t ifname2ifindex(const char *ifname);
395extern ifindex_t ifname2ifindex_vrf(const char *ifname, vrf_id_t vrf_id);
d2fc8896 396
718e3744 397/* Connected address functions. */
8cc4198f 398extern struct connected *connected_new (void);
399extern void connected_free (struct connected *);
400extern void connected_add (struct interface *, struct connected *);
401extern struct connected *connected_add_by_prefix (struct interface *,
4a7aac1b 402 struct prefix *,
403 struct prefix *);
8cc4198f 404extern struct connected *connected_delete_by_prefix (struct interface *,
4a7aac1b 405 struct prefix *);
bd40c341
DS
406extern struct connected *connected_lookup_prefix (struct interface *,
407 struct prefix *);
38485402
DS
408extern struct connected *connected_lookup_prefix_exact (struct interface *,
409 struct prefix *);
a80beece
DS
410extern struct nbr_connected *nbr_connected_new (void);
411extern void nbr_connected_free (struct nbr_connected *);
412struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *);
718e3744 413
414#ifndef HAVE_IF_NAMETOINDEX
b892f1dd 415extern ifindex_t if_nametoindex (const char *);
718e3744 416#endif
417#ifndef HAVE_IF_INDEXTONAME
b892f1dd 418extern char *if_indextoname (ifindex_t, char *);
718e3744 419#endif
420
421/* Exported variables. */
718e3744 422extern struct cmd_element interface_desc_cmd;
423extern struct cmd_element no_interface_desc_cmd;
424extern struct cmd_element interface_cmd;
32d2463c 425extern struct cmd_element no_interface_cmd;
cd2a8a42
FL
426extern struct cmd_element interface_vrf_cmd;
427extern struct cmd_element no_interface_vrf_cmd;
718e3744 428extern struct cmd_element interface_pseudo_cmd;
429extern struct cmd_element no_interface_pseudo_cmd;
478ccfd6 430extern struct cmd_element show_address_cmd;
8736158a
FL
431extern struct cmd_element show_address_vrf_cmd;
432extern struct cmd_element show_address_vrf_all_cmd;
f93e3f69
DS
433extern struct cmd_element vrf_cmd;
434extern struct cmd_element no_vrf_cmd;
718e3744 435
436#endif /* _ZEBRA_IF_H */