blob: 9ffe74cfbf5045a8715e19af81b44f367cdfde45 [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. */
97 int mtu;
98
99 /* Hardware address. */
100#ifdef HAVE_SOCKADDR_DL
101 struct sockaddr_dl sdl;
102#else
103 unsigned short hw_type;
104 u_char hw_addr[INTERFACE_HWADDR_MAX];
105 int hw_addr_len;
106#endif /* HAVE_SOCKADDR_DL */
107
108 /* interface bandwidth, kbits */
109 unsigned int bandwidth;
110
111 /* description of the interface. */
112 char *desc;
113
114 /* Distribute list. */
115 void *distribute_in;
116 void *distribute_out;
117
118 /* Connected address list. */
119 list connected;
120
121 /* Daemon specific interface data pointer. */
122 void *info;
123
124 /* Statistics fileds. */
125#ifdef HAVE_PROC_NET_DEV
126 struct if_stats stats;
127#endif /* HAVE_PROC_NET_DEV */
128#ifdef HAVE_NET_RT_IFLIST
129 struct if_data stats;
130#endif /* HAVE_NET_RT_IFLIST */
131};
132
133/* Connected address structure. */
134struct connected
135{
136 /* Attached interface. */
137 struct interface *ifp;
138
139 /* Flags for configuration. */
140 u_char conf;
141#define ZEBRA_IFC_REAL (1 << 0)
142#define ZEBRA_IFC_CONFIGURED (1 << 1)
143
144 /* Flags for connected address. */
145 u_char flags;
146#define ZEBRA_IFA_SECONDARY (1 << 0)
147
148 /* Address of connected network. */
149 struct prefix *address;
150 struct prefix *destination;
151
152 /* Label for Linux 2.2.X and upper. */
153 char *label;
154};
155
156/* Interface hook sort. */
157#define IF_NEW_HOOK 0
158#define IF_DELETE_HOOK 1
159
160/* There are some interface flags which are only supported by some
161 operating system. */
162
163#ifndef IFF_NOTRAILERS
164#define IFF_NOTRAILERS 0x0
165#endif /* IFF_NOTRAILERS */
166#ifndef IFF_OACTIVE
167#define IFF_OACTIVE 0x0
168#endif /* IFF_OACTIVE */
169#ifndef IFF_SIMPLEX
170#define IFF_SIMPLEX 0x0
171#endif /* IFF_SIMPLEX */
172#ifndef IFF_LINK0
173#define IFF_LINK0 0x0
174#endif /* IFF_LINK0 */
175#ifndef IFF_LINK1
176#define IFF_LINK1 0x0
177#endif /* IFF_LINK1 */
178#ifndef IFF_LINK2
179#define IFF_LINK2 0x0
180#endif /* IFF_LINK2 */
181
182/* Prototypes. */
183struct interface *if_new (void);
paul592c8142003-06-06 23:24:55 +0000184struct interface *if_create (void);
paul718e3742002-12-13 20:15:29 +0000185struct interface *if_lookup_by_index (unsigned int);
186struct interface *if_lookup_by_name (char *);
187struct interface *if_lookup_exact_address (struct in_addr);
188struct interface *if_lookup_address (struct in_addr);
189struct interface *if_get_by_name (char *);
190void if_delete (struct interface *);
191int if_is_up (struct interface *);
paul2e3b2e42002-12-13 21:03:13 +0000192int if_is_running (struct interface *);
193int if_is_operative (struct interface *);
paul718e3742002-12-13 20:15:29 +0000194int if_is_loopback (struct interface *);
195int if_is_broadcast (struct interface *);
196int if_is_pointopoint (struct interface *);
197int if_is_multicast (struct interface *);
198void if_add_hook (int, int (*)(struct interface *));
199void if_init ();
200void if_dump_all ();
201char *ifindex2ifname (unsigned int);
202
203/* Connected address functions. */
204struct connected *connected_new ();
205void connected_free (struct connected *);
206void connected_add (struct interface *, struct connected *);
207struct connected *connected_delete_by_prefix (struct interface *, struct prefix *);
paul727d1042002-12-13 20:50:29 +0000208struct connected *connected_lookup_address (struct interface *, struct in_addr);
paul718e3742002-12-13 20:15:29 +0000209int ifc_pointopoint (struct connected *);
210
211#ifndef HAVE_IF_NAMETOINDEX
212unsigned int if_nametoindex (const char *);
213#endif
214#ifndef HAVE_IF_INDEXTONAME
215char *if_indextoname (unsigned int, char *);
216#endif
217
218/* Exported variables. */
219extern list iflist;
220extern struct cmd_element interface_desc_cmd;
221extern struct cmd_element no_interface_desc_cmd;
222extern struct cmd_element interface_cmd;
paul32d24632003-05-23 09:25:20 +0000223extern struct cmd_element no_interface_cmd;
paul718e3742002-12-13 20:15:29 +0000224extern struct cmd_element interface_pseudo_cmd;
225extern struct cmd_element no_interface_pseudo_cmd;
226
227#endif /* _ZEBRA_IF_H */