]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.h
2005-04-02 Paul Jakma <paul@dishone.st>
[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
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)
2e3b2e47 88#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
718e3744 89
90 /* Interface flags. */
91 unsigned long flags;
92
93 /* Interface metric */
94 int metric;
95
96 /* Interface MTU. */
c9eca01b 97 unsigned int mtu; /* IPv4 MTU */
98 unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
718e3744 99
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. */
52dc7ee6 120 struct list *connected;
718e3744 121
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;
3fb9cd6e 151 struct prefix *destination; /* broadcast or peer address; may be NULL */
718e3744 152
153 /* Label for Linux 2.2.X and upper. */
154 char *label;
155};
156
3fb9cd6e 157/* 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
718e3744 168/* 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 */
4ba9b924 193#ifndef IFF_NOXMIT
194#define IFF_NOXMIT 0x0
195#endif /* IFF_NOXMIT */
196#ifndef IFF_NORTEXCH
197#define IFF_NORTEXCH 0x0
198#endif /* IFF_NORTEXCH */
199#ifndef IFF_IPV4
200#define IFF_IPV4 0x0
201#endif /* IFF_IPV4 */
202#ifndef IFF_IPV6
203#define IFF_IPV6 0x0
204#endif /* IFF_IPV6 */
205#ifndef IFF_VIRTUAL
206#define IFF_VIRTUAL 0x0
207#endif /* IFF_VIRTUAL */
718e3744 208
209/* Prototypes. */
106d2fd5 210int if_cmp_func (struct interface *, struct interface *);
718e3744 211struct interface *if_new (void);
9035efaa 212struct interface *if_create (const char *name, int namelen);
718e3744 213struct interface *if_lookup_by_index (unsigned int);
9035efaa 214struct interface *if_lookup_by_name (const char *);
718e3744 215struct interface *if_lookup_exact_address (struct in_addr);
216struct interface *if_lookup_address (struct in_addr);
9035efaa 217struct interface *if_get_by_name (const char *);
718e3744 218void if_delete (struct interface *);
219int if_is_up (struct interface *);
2e3b2e47 220int if_is_running (struct interface *);
221int if_is_operative (struct interface *);
718e3744 222int if_is_loopback (struct interface *);
223int if_is_broadcast (struct interface *);
224int if_is_pointopoint (struct interface *);
225int if_is_multicast (struct interface *);
226void if_add_hook (int, int (*)(struct interface *));
227void if_init ();
228void if_dump_all ();
229char *ifindex2ifname (unsigned int);
847947f2 230extern const char *if_flag_dump(unsigned long);
718e3744 231
232/* Connected address functions. */
233struct connected *connected_new ();
234void connected_free (struct connected *);
235void connected_add (struct interface *, struct connected *);
4a7aac1b 236struct connected *connected_add_by_prefix (struct interface *,
237 struct prefix *,
238 struct prefix *);
239struct connected *connected_delete_by_prefix (struct interface *,
240 struct prefix *);
241struct connected *connected_lookup_address (struct interface *,
242 struct in_addr);
718e3744 243
244#ifndef HAVE_IF_NAMETOINDEX
245unsigned int if_nametoindex (const char *);
246#endif
247#ifndef HAVE_IF_INDEXTONAME
248char *if_indextoname (unsigned int, char *);
249#endif
250
251/* Exported variables. */
52dc7ee6 252extern struct list *iflist;
718e3744 253extern struct cmd_element interface_desc_cmd;
254extern struct cmd_element no_interface_desc_cmd;
255extern struct cmd_element interface_cmd;
32d2463c 256extern struct cmd_element no_interface_cmd;
718e3744 257extern struct cmd_element interface_pseudo_cmd;
258extern struct cmd_element no_interface_pseudo_cmd;
259
260#endif /* _ZEBRA_IF_H */