Subversion Repositories SvarDOS

Rev

Rev 616 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*!\file net/if.h
2
 * Network interface data.
3
 */
4
 
5
/*      $NetBSD: if.h,v 1.29 1997/10/02 19:41:57 is Exp $       */
6
 
7
/*
8
 * Copyright (c) 1982, 1986, 1989, 1993
9
 *	The Regents of the University of California.  All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in the
18
 *    documentation and/or other materials provided with the distribution.
19
 * 3. All advertising materials mentioning features or use of this software
20
 *    must display the following acknowledgement:
21
 *	This product includes software developed by the University of
22
 *	California, Berkeley and its contributors.
23
 * 4. Neither the name of the University nor the names of its contributors
24
 *    may be used to endorse or promote products derived from this software
25
 *    without specific prior written permission.
26
 *
27
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37
 * SUCH DAMAGE.
38
 *
39
 *	@(#)if.h	8.1 (Berkeley) 6/10/93
40
 */
41
 
42
#ifndef __NET_IF_H
43
#define __NET_IF_H
44
 
45
#include <sys/queue.h>
46
 
47
/*
48
 * Structures defining a network interface, providing a packet
49
 * transport mechanism (ala level 0 of the PUP protocols).
50
 *
51
 * Each interface accepts output datagrams of a specified maximum
52
 * length, and provides higher level routines with input datagrams
53
 * received from its medium.
54
 *
55
 * Output occurs when the routine if_output is called, with four parameters:
56
 *	(*ifp->if_output)(ifp, m, dst, rt)
57
 * Here m is the mbuf chain to be sent and dst is the destination address.
58
 * The output routine encapsulates the supplied datagram if necessary,
59
 * and then transmits it on its medium.
60
 *
61
 * On input, each interface unwraps the data received by it, and either
62
 * places it on the input queue of a internetwork datagram routine
63
 * and posts the associated software interrupt, or passes the datagram to a raw
64
 * packet input routine.
65
 *
66
 * Routines exist for locating interfaces by their addresses
67
 * or for locating a interface on a certain network, as well as more general
68
 * routing and gateway routines maintaining information used to locate
69
 * interfaces.  These routines live in the files if.c and route.c
70
 */
71
#ifndef __SYS_WTIME_H
72
#include <sys/wtime.h>
73
#endif
74
 
75
struct mbuf;
76
struct rtentry;
77
struct ether_header;
78
struct proc   { int dummy; };
79
struct socket { int dummy; };
80
 
81
/*
82
 * Structure defining statistics and other data kept regarding a network
83
 * interface.
84
 */
85
struct	if_data {
86
	/* generic interface information */
87
	u_char	ifi_type;		/* ethernet, tokenring, etc. */
88
	u_char	ifi_addrlen;		/* media address length */
89
	u_char	ifi_hdrlen;		/* media header length */
90
	u_long	ifi_mtu;		/* maximum transmission unit */
91
	u_long	ifi_metric;		/* routing metric (external only) */
92
	u_long	ifi_baudrate;		/* linespeed */
93
	/* volatile statistics */
94
	u_long	ifi_ipackets;		/* packets received on interface */
95
	u_long	ifi_ierrors;		/* input errors on interface */
96
	u_long	ifi_opackets;		/* packets sent on interface */
97
	u_long	ifi_oerrors;		/* output errors on interface */
98
	u_long	ifi_collisions;		/* collisions on csma interfaces */
99
	u_long	ifi_ibytes;		/* total number of octets received */
100
	u_long	ifi_obytes;		/* total number of octets sent */
101
	u_long	ifi_imcasts;		/* packets received via multicast */
102
	u_long	ifi_omcasts;		/* packets sent via multicast */
103
	u_long	ifi_iqdrops;		/* dropped on input, this interface */
104
	u_long	ifi_noproto;		/* destined for unsupported protocol */
105
        struct  timeval ifi_lastchange; /* last updated */
106
};
107
 
108
/*
109
 * Structure defining a queue for a network interface.
110
 *
111
 * (Would like to call this struct ``if'', but C isn't PL/1.)
112
 */
113
TAILQ_HEAD(ifnet_head, ifnet);          /* the actual queue head */
114
 
115
/*
116
 * Length of interface external name, including terminating '\0'.
117
 * Note: this is the same size as a generic device's external name.
118
 */
119
#define	IFNAMSIZ	16
120
 
121
#ifndef IF_NAMESIZE
122
#define IF_NAMESIZE     IFNAMSIZ
123
#endif
124
 
125
struct ifnet {				/* and the entries */
126
	void	*if_softc;		/* lower-level data for this if */
127
        TAILQ_ENTRY(ifnet) if_list;         /* all struct ifnets are chained */
128
        TAILQ_HEAD(xx, ifaddr) if_addrlist; /* linked list of addresses per if */
129
	char	if_xname[IFNAMSIZ];	/* external name (name + unit) */
130
	int	if_pcount;		/* number of promiscuous listeners */
131
	caddr_t	if_bpf;			/* packet filter structure */
132
	u_short	if_index;		/* numeric abbreviation for this if */
133
	short	if_timer;		/* time 'til if_watchdog called */
134
	short	if_flags;		/* up/down, broadcast, etc. */
135
	short	if__pad1;		/* be nice to m68k ports */
136
	struct	if_data if_data;	/* statistics and other data about if */
137
/* procedure handles */
138
	int	(*if_output)		/* output routine (enqueue) */
139
                (struct ifnet *, struct mbuf *, struct sockaddr *,
140
                 struct rtentry *);
141
	void	(*if_start)		/* initiate output routine */
142
                (struct ifnet *);
143
	int	(*if_ioctl)		/* ioctl routine */
144
                (struct ifnet *, u_long, caddr_t);
145
	int	(*if_reset)		/* XXX bus reset routine */
146
                (struct ifnet *);
147
	void	(*if_watchdog)		/* timer routine */
148
                (struct ifnet *);
149
	struct	ifqueue {
150
                  struct  mbuf *ifq_head;
151
                  struct  mbuf *ifq_tail;
152
                  int     ifq_len;
153
                  int     ifq_maxlen;
154
                  int     ifq_drops;
155
                } if_snd;               /* output queue */
156
	struct	sockaddr_dl *if_sadl;	/* pointer to our sockaddr_dl */
157
	u_int8_t *if_broadcastaddr;	/* linklevel broadcast bytestring */
158
};
159
 
160
#define	if_mtu		if_data.ifi_mtu
161
#define	if_type		if_data.ifi_type
162
#define	if_addrlen	if_data.ifi_addrlen
163
#define	if_hdrlen	if_data.ifi_hdrlen
164
#define	if_metric	if_data.ifi_metric
165
#define	if_baudrate	if_data.ifi_baudrate
166
#define	if_ipackets	if_data.ifi_ipackets
167
#define	if_ierrors	if_data.ifi_ierrors
168
#define	if_opackets	if_data.ifi_opackets
169
#define	if_oerrors	if_data.ifi_oerrors
170
#define	if_collisions	if_data.ifi_collisions
171
#define	if_ibytes	if_data.ifi_ibytes
172
#define	if_obytes	if_data.ifi_obytes
173
#define	if_imcasts	if_data.ifi_imcasts
174
#define	if_omcasts	if_data.ifi_omcasts
175
#define	if_iqdrops	if_data.ifi_iqdrops
176
#define	if_noproto	if_data.ifi_noproto
177
#define	if_lastchange	if_data.ifi_lastchange
178
 
179
#define	IFF_UP		0x1		/* interface is up */
180
#define	IFF_BROADCAST	0x2		/* broadcast address valid */
181
#define	IFF_DEBUG	0x4		/* turn on debugging */
182
#define	IFF_LOOPBACK	0x8		/* is a loopback net */
183
#define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
184
#define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
185
#define	IFF_RUNNING	0x40		/* resources allocated */
186
#define	IFF_NOARP	0x80		/* no address resolution protocol */
187
#define	IFF_PROMISC	0x100		/* receive all packets */
188
#define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
189
#define	IFF_OACTIVE	0x400		/* transmission in progress */
190
#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
191
#define	IFF_LINK0	0x1000		/* per link layer defined bit */
192
#define	IFF_LINK1	0x2000		/* per link layer defined bit */
193
#define	IFF_LINK2	0x4000		/* per link layer defined bit */
194
#define	IFF_MULTICAST	0x8000		/* supports multicast */
195
 
196
/* flags set internally only: */
197
#define	IFF_CANTCHANGE \
198
	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
199
	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
200
 
201
/*
202
 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
203
 * input routines have queues of messages stored on ifqueue structures
204
 * (defined above).  Entries are added to and deleted from these structures
205
 * by these macros, which should be called with ipl raised to splimp().
206
 */
207
#define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
208
#define	IF_DROP(ifq)		((ifq)->ifq_drops++)
209
#define	IF_ENQUEUE(ifq, m) { \
210
	(m)->m_nextpkt = 0; \
211
	if ((ifq)->ifq_tail == 0) \
212
		(ifq)->ifq_head = m; \
213
	else \
214
		(ifq)->ifq_tail->m_nextpkt = m; \
215
	(ifq)->ifq_tail = m; \
216
	(ifq)->ifq_len++; \
217
}
218
#define	IF_PREPEND(ifq, m) { \
219
	(m)->m_nextpkt = (ifq)->ifq_head; \
220
	if ((ifq)->ifq_tail == 0) \
221
		(ifq)->ifq_tail = (m); \
222
	(ifq)->ifq_head = (m); \
223
	(ifq)->ifq_len++; \
224
}
225
#define	IF_DEQUEUE(ifq, m) { \
226
	(m) = (ifq)->ifq_head; \
227
	if (m) { \
228
		if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
229
			(ifq)->ifq_tail = 0; \
230
		(m)->m_nextpkt = 0; \
231
		(ifq)->ifq_len--; \
232
	} \
233
}
234
 
235
#define	IFQ_MAXLEN	50
236
#define	IFNET_SLOWHZ	1		/* granularity is 1 second */
237
 
238
/*
239
 * The ifaddr structure contains information about one address
240
 * of an interface.  They are maintained by the different address families,
241
 * are allocated and attached when an address is set, and are linked
242
 * together so all addresses for an interface can be located.
243
 */
244
struct ifaddr {
245
	struct	sockaddr *ifa_addr;	/* address of interface */
246
	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
247
#define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
248
	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
249
	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
250
        TAILQ_ENTRY(ifaddr) ifa_list;   /* list of addresses for interface */
251
	void	(*ifa_rtrequest)	/* check or clean routes (+ or -)'d */
252
                (int, struct rtentry *, struct sockaddr *);
253
	u_short	ifa_flags;		/* mostly rt_flags for cloning */
254
	short	ifa_refcnt;		/* count of references */
255
	int	ifa_metric;		/* cost of going out this interface */
256
};
257
#define	IFA_ROUTE	RTF_UP		/* route installed */
258
 
259
/*
260
 * Message format for use in obtaining information about interfaces
261
 * from sysctl and the routing socket.
262
 */
263
struct if_msghdr {
264
	u_short	ifm_msglen;	/* to skip over non-understood messages */
265
	u_char	ifm_version;	/* future binary compatability */
266
	u_char	ifm_type;	/* message type */
267
	int	ifm_addrs;	/* like rtm_addrs */
268
	int	ifm_flags;	/* value of if_flags */
269
	u_short	ifm_index;	/* index for associated ifp */
270
	struct	if_data ifm_data;/* statistics and other data about if */
271
};
272
 
273
/*
274
 * Message format for use in obtaining information about interface addresses
275
 * from sysctl and the routing socket.
276
 */
277
struct ifa_msghdr {
278
	u_short	ifam_msglen;	/* to skip over non-understood messages */
279
	u_char	ifam_version;	/* future binary compatability */
280
	u_char	ifam_type;	/* message type */
281
	int	ifam_addrs;	/* like rtm_addrs */
282
	int	ifam_flags;	/* value of ifa_flags */
283
	u_short	ifam_index;	/* index for associated ifp */
284
	int	ifam_metric;	/* value of ifa_metric */
285
};
286
 
287
/*
288
 * Interface request structure used for socket
289
 * ioctl's.  All interface ioctl's must have parameter
290
 * definitions which begin with ifr_name.  The
291
 * remainder may be interface specific.
292
 */
293
struct ifreq {
294
	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
295
	union {
296
		struct	sockaddr ifru_addr;
297
		struct	sockaddr ifru_dstaddr;
298
                struct  sockaddr ifru_hwaddr;
299
		struct	sockaddr ifru_broadaddr;
300
		short	ifru_flags;
301
		int	ifru_metric;
302
		int	ifru_mtu;
303
		caddr_t	ifru_data;
304
	} ifr_ifru;
305
#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
306
#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
307
#define ifr_hwaddr      ifr_ifru.ifru_hwaddr    /* hardware address */
308
#define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
309
#define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
310
#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
311
#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
312
#define	ifr_media	ifr_ifru.ifru_metric	/* media options (overload) */
313
#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
314
};
315
 
316
struct ifaliasreq {
317
	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
318
	struct	sockaddr ifra_addr;
319
	struct	sockaddr ifra_dstaddr;
320
#define	ifra_broadaddr	ifra_dstaddr
321
	struct	sockaddr ifra_mask;
322
};
323
 
324
struct ifmediareq {
325
        char    ifm_name[IFNAMSIZ];     /* if name, e.g. "en0" */
326
        int     ifm_current;            /* current media options */
327
        int     ifm_mask;               /* don't care mask */
328
        int     ifm_status;             /* media status */
329
        int     ifm_active;             /* active options */
330
        int     ifm_count;              /* # entries in ifm_ulist array */
331
        int     *ifm_ulist;             /* media words */
332
};
333
 
334
/*
335
 * Structure used in SIOCGIFCONF request.
336
 * Used to retrieve interface configuration
337
 * for machine (useful for programs which
338
 * must know all networks accessible).
339
 */
340
struct	ifconf {
341
	int	ifc_len;		/* size of associated buffer */
342
	union {
343
		caddr_t	ifcu_buf;
344
		struct	ifreq *ifcu_req;
345
	} ifc_ifcu;
346
#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
347
#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
348
};
349
 
350
#ifndef __NET_IF_ARP_H
351
#include <net/if_arp.h>
352
#endif
353
 
354
#endif