added files
[bcm963xx.git] / userapps / opensource / zebra / lib / if.h
1 /* Interface related header.
2    Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
3
4 This file is part of GNU Zebra.
5
6 GNU Zebra is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your
9 option) any later version.
10
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, 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
44 struct 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 */
76 struct 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)
88   
89   /* Interface flags. */
90   unsigned long flags;
91
92   /* Interface metric */
93   int metric;
94
95   /* Interface MTU. */
96   int mtu;
97
98   /* Hardware address. */
99 #ifdef HAVE_SOCKADDR_DL
100   struct sockaddr_dl sdl;
101 #else
102   unsigned short hw_type;
103   u_char hw_addr[INTERFACE_HWADDR_MAX];
104   int hw_addr_len;
105 #endif /* HAVE_SOCKADDR_DL */
106
107   /* interface bandwidth, kbits */
108   unsigned int bandwidth;
109   
110   /* description of the interface. */
111   char *desc;                   
112
113   /* Distribute list. */
114   void *distribute_in;
115   void *distribute_out;
116
117   /* Connected address list. */
118   list connected;
119
120   /* Daemon specific interface data pointer. */
121   void *info;
122
123   /* Statistics fileds. */
124 #ifdef HAVE_PROC_NET_DEV
125   struct if_stats stats;
126 #endif /* HAVE_PROC_NET_DEV */  
127 #ifdef HAVE_NET_RT_IFLIST
128   struct if_data stats;
129 #endif /* HAVE_NET_RT_IFLIST */
130 };
131
132 /* Connected address structure. */
133 struct connected
134 {
135   /* Attached interface. */
136   struct interface *ifp;
137
138   /* Flags for configuration. */
139   u_char conf;
140 #define ZEBRA_IFC_REAL         (1 << 0)
141 #define ZEBRA_IFC_CONFIGURED   (1 << 1)
142
143   /* Flags for connected address. */
144   u_char flags;
145 #define ZEBRA_IFA_SECONDARY   (1 << 0)
146
147   /* Address of connected network. */
148   struct prefix *address;
149   struct prefix *destination;
150
151   /* Label for Linux 2.2.X and upper. */
152   char *label;
153 };
154
155 /* Interface hook sort. */
156 #define IF_NEW_HOOK   0
157 #define IF_DELETE_HOOK 1
158
159 /* There are some interface flags which are only supported by some
160    operating system. */
161
162 #ifndef IFF_NOTRAILERS
163 #define IFF_NOTRAILERS 0x0
164 #endif /* IFF_NOTRAILERS */
165 #ifndef IFF_OACTIVE
166 #define IFF_OACTIVE 0x0
167 #endif /* IFF_OACTIVE */
168 #ifndef IFF_SIMPLEX
169 #define IFF_SIMPLEX 0x0
170 #endif /* IFF_SIMPLEX */
171 #ifndef IFF_LINK0
172 #define IFF_LINK0 0x0
173 #endif /* IFF_LINK0 */
174 #ifndef IFF_LINK1
175 #define IFF_LINK1 0x0
176 #endif /* IFF_LINK1 */
177 #ifndef IFF_LINK2
178 #define IFF_LINK2 0x0
179 #endif /* IFF_LINK2 */
180
181 /* Prototypes. */
182 struct interface *if_new (void);
183 struct interface *if_create (void);
184 struct interface *if_lookup_by_index (unsigned int);
185 struct interface *if_lookup_by_name (char *);
186 struct interface *if_lookup_exact_address (struct in_addr);
187 struct interface *if_lookup_address (struct in_addr);
188 struct interface *if_get_by_name (char *);
189 void if_delete (struct interface *);
190 int if_is_up (struct interface *);
191 int if_is_loopback (struct interface *);
192 int if_is_broadcast (struct interface *);
193 int if_is_pointopoint (struct interface *);
194 int if_is_multicast (struct interface *);
195 void if_add_hook (int, int (*)(struct interface *));
196 void if_init ();
197 void if_dump_all ();
198 char *ifindex2ifname (unsigned int);
199
200 /* Connected address functions. */
201 struct connected *connected_new ();
202 void connected_free (struct connected *);
203 void connected_add (struct interface *, struct connected *);
204 struct connected  *connected_delete_by_prefix (struct interface *, struct prefix *);
205 int ifc_pointopoint (struct connected *);
206
207 #ifndef HAVE_IF_NAMETOINDEX
208 unsigned int if_nametoindex (const char *);
209 #endif
210 #ifndef HAVE_IF_INDEXTONAME
211 char *if_indextoname (unsigned int, char *);
212 #endif
213
214 /* Exported variables. */
215 extern list iflist;
216 extern struct cmd_element interface_desc_cmd;
217 extern struct cmd_element no_interface_desc_cmd;
218 extern struct cmd_element interface_cmd;
219 extern struct cmd_element interface_pseudo_cmd;
220 extern struct cmd_element no_interface_pseudo_cmd;
221
222 #endif /* _ZEBRA_IF_H */