blob: 47e992c36391964596175d8aeba7e4d0e2e5a79a [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
39/* Internal If indexes start at 0xFFFFFFFF and go down to 1 greater
40 than this */
41#define IFINDEX_INTERNBASE 0x80000000
42
43#ifdef HAVE_PROC_NET_DEV
44struct if_stats
45{
46 unsigned long rx_packets; /* total packets received */
47 unsigned long tx_packets; /* total packets transmitted */
48 unsigned long rx_bytes; /* total bytes received */
49 unsigned long tx_bytes; /* total bytes transmitted */
50 unsigned long rx_errors; /* bad packets received */
51 unsigned long tx_errors; /* packet transmit problems */
52 unsigned long rx_dropped; /* no space in linux buffers */
53 unsigned long tx_dropped; /* no space available in linux */
54 unsigned long rx_multicast; /* multicast packets received */
55 unsigned long rx_compressed;
56 unsigned long tx_compressed;
57 unsigned long collisions;
58
59 /* detailed rx_errors: */
60 unsigned long rx_length_errors;
61 unsigned long rx_over_errors; /* receiver ring buff overflow */
62 unsigned long rx_crc_errors; /* recved pkt with crc error */
63 unsigned long rx_frame_errors; /* recv'd frame alignment error */
64 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
65 unsigned long rx_missed_errors; /* receiver missed packet */
66 /* detailed tx_errors */
67 unsigned long tx_aborted_errors;
68 unsigned long tx_carrier_errors;
69 unsigned long tx_fifo_errors;
70 unsigned long tx_heartbeat_errors;
71 unsigned long tx_window_errors;
72};
73#endif /* HAVE_PROC_NET_DEV */
74
75/* Interface structure */
76struct interface
77{
78 /* Interface name. */
79 char name[INTERFACE_NAMSIZ + 1];
80
81 /* Interface index. */
82 unsigned int ifindex;
83
84 /* Zebra internal interface status */
85 u_char status;
86#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
87#define ZEBRA_INTERFACE_SUB (1 << 1)
paul2e3b2e42002-12-13 21:03:13 +000088#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
paul718e3742002-12-13 20:15:29 +000089
90 /* Interface flags. */
91 unsigned long flags;
92
93 /* Interface metric */
94 int metric;
95
96 /* Interface MTU. */
paul4a7aac12004-05-08 05:00:31 +000097 int mtu; /* IPv4 MTU */
98 int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
paul718e3742002-12-13 20:15:29 +000099
100 /* Hardware address. */
101#ifdef HAVE_SOCKADDR_DL
102 struct sockaddr_dl sdl;
103#else
104 unsigned short hw_type;
105 u_char hw_addr[INTERFACE_HWADDR_MAX];
106 int hw_addr_len;
107#endif /* HAVE_SOCKADDR_DL */
108
109 /* interface bandwidth, kbits */
110 unsigned int bandwidth;
111
112 /* description of the interface. */
113 char *desc;
114
115 /* Distribute list. */
116 void *distribute_in;
117 void *distribute_out;
118
119 /* Connected address list. */
hasso52dc7ee2004-09-23 19:18:23 +0000120 struct list *connected;
paul718e3742002-12-13 20:15:29 +0000121
122 /* Daemon specific interface data pointer. */
123 void *info;
124
125 /* Statistics fileds. */
126#ifdef HAVE_PROC_NET_DEV
127 struct if_stats stats;
128#endif /* HAVE_PROC_NET_DEV */
129#ifdef HAVE_NET_RT_IFLIST
130 struct if_data stats;
131#endif /* HAVE_NET_RT_IFLIST */
132};
133
134/* Connected address structure. */
135struct connected
136{
137 /* Attached interface. */
138 struct interface *ifp;
139
140 /* Flags for configuration. */
141 u_char conf;
142#define ZEBRA_IFC_REAL (1 << 0)
143#define ZEBRA_IFC_CONFIGURED (1 << 1)
144
145 /* Flags for connected address. */
146 u_char flags;
147#define ZEBRA_IFA_SECONDARY (1 << 0)
148
149 /* Address of connected network. */
150 struct prefix *address;
151 struct prefix *destination;
152
153 /* Label for Linux 2.2.X and upper. */
154 char *label;
155};
156
157/* Interface hook sort. */
158#define IF_NEW_HOOK 0
159#define IF_DELETE_HOOK 1
160
161/* There are some interface flags which are only supported by some
162 operating system. */
163
164#ifndef IFF_NOTRAILERS
165#define IFF_NOTRAILERS 0x0
166#endif /* IFF_NOTRAILERS */
167#ifndef IFF_OACTIVE
168#define IFF_OACTIVE 0x0
169#endif /* IFF_OACTIVE */
170#ifndef IFF_SIMPLEX
171#define IFF_SIMPLEX 0x0
172#endif /* IFF_SIMPLEX */
173#ifndef IFF_LINK0
174#define IFF_LINK0 0x0
175#endif /* IFF_LINK0 */
176#ifndef IFF_LINK1
177#define IFF_LINK1 0x0
178#endif /* IFF_LINK1 */
179#ifndef IFF_LINK2
180#define IFF_LINK2 0x0
181#endif /* IFF_LINK2 */
182
183/* Prototypes. */
paul106d2fd2003-08-01 00:24:13 +0000184int if_cmp_func (struct interface *, struct interface *);
paul718e3742002-12-13 20:15:29 +0000185struct interface *if_new (void);
paul106d2fd2003-08-01 00:24:13 +0000186struct interface *if_create (char *name, int namelen);
paul718e3742002-12-13 20:15:29 +0000187struct interface *if_lookup_by_index (unsigned int);
188struct interface *if_lookup_by_name (char *);
189struct interface *if_lookup_exact_address (struct in_addr);
190struct interface *if_lookup_address (struct in_addr);
191struct interface *if_get_by_name (char *);
192void if_delete (struct interface *);
193int if_is_up (struct interface *);
paul2e3b2e42002-12-13 21:03:13 +0000194int if_is_running (struct interface *);
195int if_is_operative (struct interface *);
paul718e3742002-12-13 20:15:29 +0000196int if_is_loopback (struct interface *);
197int if_is_broadcast (struct interface *);
198int if_is_pointopoint (struct interface *);
199int if_is_multicast (struct interface *);
200void if_add_hook (int, int (*)(struct interface *));
201void if_init ();
202void if_dump_all ();
203char *ifindex2ifname (unsigned int);
204
205/* Connected address functions. */
206struct connected *connected_new ();
207void connected_free (struct connected *);
208void connected_add (struct interface *, struct connected *);
paul4a7aac12004-05-08 05:00:31 +0000209struct connected *connected_add_by_prefix (struct interface *,
210 struct prefix *,
211 struct prefix *);
212struct connected *connected_delete_by_prefix (struct interface *,
213 struct prefix *);
214struct connected *connected_lookup_address (struct interface *,
215 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000216
217#ifndef HAVE_IF_NAMETOINDEX
218unsigned int if_nametoindex (const char *);
219#endif
220#ifndef HAVE_IF_INDEXTONAME
221char *if_indextoname (unsigned int, char *);
222#endif
223
224/* Exported variables. */
hasso52dc7ee2004-09-23 19:18:23 +0000225extern struct list *iflist;
paul718e3742002-12-13 20:15:29 +0000226extern struct cmd_element interface_desc_cmd;
227extern struct cmd_element no_interface_desc_cmd;
228extern struct cmd_element interface_cmd;
paul32d24632003-05-23 09:25:20 +0000229extern struct cmd_element no_interface_cmd;
paul718e3742002-12-13 20:15:29 +0000230extern struct cmd_element interface_pseudo_cmd;
231extern struct cmd_element no_interface_pseudo_cmd;
232
233#endif /* _ZEBRA_IF_H */