blob: 7afb2ae9e0be51c937fbeaad60642702cd698c93 [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. */
paulc9eca012004-10-11 11:28:44 +000097 unsigned int mtu; /* IPv4 MTU */
98 unsigned 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;
hasso3fb9cd62004-10-19 19:44:43 +0000151 struct prefix *destination; /* broadcast or peer address; may be NULL */
paul718e3742002-12-13 20:15:29 +0000152
153 /* Label for Linux 2.2.X and upper. */
154 char *label;
155};
156
hasso3fb9cd62004-10-19 19:44:43 +0000157/* Given an IPV4 struct connected, this macro determines whether a /32
158 peer address has been supplied (i.e. there is no subnet assigned) */
159#define CONNECTED_DEST_HOST(C) \
160 ((C)->destination && ((C)->address->prefixlen == IPV4_MAX_PREFIXLEN))
161
162/* Given an IPV4 struct connected, this macro determins whether it is
163 a point-to-point link with a /32 peer address (i.e. there
164 is no dedicated subnet for the PtP link) */
165#define CONNECTED_POINTOPOINT_HOST(C) \
166 (((C)->ifp->flags & IFF_POINTOPOINT) && CONNECTED_DEST_HOST(C))
167
paul718e3742002-12-13 20:15:29 +0000168/* Interface hook sort. */
169#define IF_NEW_HOOK 0
170#define IF_DELETE_HOOK 1
171
172/* There are some interface flags which are only supported by some
173 operating system. */
174
175#ifndef IFF_NOTRAILERS
176#define IFF_NOTRAILERS 0x0
177#endif /* IFF_NOTRAILERS */
178#ifndef IFF_OACTIVE
179#define IFF_OACTIVE 0x0
180#endif /* IFF_OACTIVE */
181#ifndef IFF_SIMPLEX
182#define IFF_SIMPLEX 0x0
183#endif /* IFF_SIMPLEX */
184#ifndef IFF_LINK0
185#define IFF_LINK0 0x0
186#endif /* IFF_LINK0 */
187#ifndef IFF_LINK1
188#define IFF_LINK1 0x0
189#endif /* IFF_LINK1 */
190#ifndef IFF_LINK2
191#define IFF_LINK2 0x0
192#endif /* IFF_LINK2 */
193
194/* Prototypes. */
paul106d2fd2003-08-01 00:24:13 +0000195int if_cmp_func (struct interface *, struct interface *);
paul718e3742002-12-13 20:15:29 +0000196struct interface *if_new (void);
paul9035efa2004-10-10 11:56:56 +0000197struct interface *if_create (const char *name, int namelen);
paul718e3742002-12-13 20:15:29 +0000198struct interface *if_lookup_by_index (unsigned int);
paul9035efa2004-10-10 11:56:56 +0000199struct interface *if_lookup_by_name (const char *);
paul718e3742002-12-13 20:15:29 +0000200struct interface *if_lookup_exact_address (struct in_addr);
201struct interface *if_lookup_address (struct in_addr);
paul9035efa2004-10-10 11:56:56 +0000202struct interface *if_get_by_name (const char *);
paul718e3742002-12-13 20:15:29 +0000203void if_delete (struct interface *);
204int if_is_up (struct interface *);
paul2e3b2e42002-12-13 21:03:13 +0000205int if_is_running (struct interface *);
206int if_is_operative (struct interface *);
paul718e3742002-12-13 20:15:29 +0000207int if_is_loopback (struct interface *);
208int if_is_broadcast (struct interface *);
209int if_is_pointopoint (struct interface *);
210int if_is_multicast (struct interface *);
211void if_add_hook (int, int (*)(struct interface *));
212void if_init ();
213void if_dump_all ();
214char *ifindex2ifname (unsigned int);
215
216/* Connected address functions. */
217struct connected *connected_new ();
218void connected_free (struct connected *);
219void connected_add (struct interface *, struct connected *);
paul4a7aac12004-05-08 05:00:31 +0000220struct connected *connected_add_by_prefix (struct interface *,
221 struct prefix *,
222 struct prefix *);
223struct connected *connected_delete_by_prefix (struct interface *,
224 struct prefix *);
225struct connected *connected_lookup_address (struct interface *,
226 struct in_addr);
paul718e3742002-12-13 20:15:29 +0000227
228#ifndef HAVE_IF_NAMETOINDEX
229unsigned int if_nametoindex (const char *);
230#endif
231#ifndef HAVE_IF_INDEXTONAME
232char *if_indextoname (unsigned int, char *);
233#endif
234
235/* Exported variables. */
hasso52dc7ee2004-09-23 19:18:23 +0000236extern struct list *iflist;
paul718e3742002-12-13 20:15:29 +0000237extern struct cmd_element interface_desc_cmd;
238extern struct cmd_element no_interface_desc_cmd;
239extern struct cmd_element interface_cmd;
paul32d24632003-05-23 09:25:20 +0000240extern struct cmd_element no_interface_cmd;
paul718e3742002-12-13 20:15:29 +0000241extern struct cmd_element interface_pseudo_cmd;
242extern struct cmd_element no_interface_pseudo_cmd;
243
244#endif /* _ZEBRA_IF_H */