xref: /titanic_50/usr/src/lib/libbc/inc/include/net/if.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1982, 1986 Regents of the University of California.
8  * All rights reserved.  The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #ifndef _net_if_h
13 #define	_net_if_h
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /*
18  * Structures defining a network interface, providing a packet
19  * transport mechanism (ala level 0 of the PUP protocols).
20  *
21  * Each interface accepts output datagrams of a specified maximum
22  * length, and provides higher level routines with input datagrams
23  * received from its medium.
24  *
25  * Output occurs when the routine if_output is called, with three parameters:
26  *	(*ifp->if_output)(ifp, m, dst)
27  * Here m is the mbuf chain to be sent and dst is the destination address.
28  * The output routine encapsulates the supplied datagram if necessary,
29  * and then transmits it on its medium.
30  *
31  * On input, each interface unwraps the data received by it, and either
32  * places it on the input queue of a internetwork datagram routine
33  * and posts the associated software interrupt, or passes the datagram to a raw
34  * packet input routine.
35  *
36  * Routines exist for locating interfaces by their addresses
37  * or for locating a interface on a certain network, as well as more general
38  * routing and gateway routines maintaining information used to locate
39  * interfaces.  These routines live in the files if.c and route.c
40  */
41 
42 /*
43  * Structure defining a queue for a network interface.
44  *
45  * (Would like to call this struct ``if'', but C isn't PL/1.)
46  */
47 struct ifnet {
48 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
49 	short	if_unit;		/* sub-unit for lower level driver */
50 	short	if_mtu;			/* maximum transmission unit */
51 	short	if_flags;		/* up/down, broadcast, etc. */
52 	short	if_timer;		/* time 'til if_watchdog called */
53 	u_short	if_promisc;		/* net # of requests for promisc mode */
54 	int	if_metric;		/* routing metric (external only) */
55 	struct	ifaddr *if_addrlist;	/* linked list of addresses per if */
56 	struct	ifqueue {
57 		struct	mbuf *ifq_head;
58 		struct	mbuf *ifq_tail;
59 		int	ifq_len;
60 		int	ifq_maxlen;
61 		int	ifq_drops;
62 	} if_snd;			/* output queue */
63 /* procedure handles */
64 	int	(*if_init)();		/* init routine */
65 	int	(*if_output)();		/* output routine */
66 	int	(*if_ioctl)();		/* ioctl routine */
67 	int	(*if_reset)();		/* bus reset routine */
68 	int	(*if_watchdog)();	/* timer routine */
69 /* generic interface statistics */
70 	int	if_ipackets;		/* packets received on interface */
71 	int	if_ierrors;		/* input errors on interface */
72 	int	if_opackets;		/* packets sent on interface */
73 	int	if_oerrors;		/* output errors on interface */
74 	int	if_collisions;		/* collisions on csma interfaces */
75 /* end statistics */
76 	struct	ifnet *if_next;
77 	struct	ifnet *if_upper;	/* next layer up */
78 	struct	ifnet *if_lower;	/* next layer down */
79 	int	(*if_input)();		/* input routine */
80 	int	(*if_ctlin)();		/* control input routine */
81 	int	(*if_ctlout)();		/* control output routine */
82 #ifdef sun
83 	struct map *if_memmap;		/* rmap for interface specific memory */
84 #endif
85 };
86 
87 #define	IFF_UP		0x1		/* interface is up */
88 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
89 #define	IFF_DEBUG	0x4		/* turn on debugging */
90 #define	IFF_LOOPBACK	0x8		/* is a loopback net */
91 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
92 #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
93 #define	IFF_RUNNING	0x40		/* resources allocated */
94 #define	IFF_NOARP	0x80		/* no address resolution protocol */
95 #define	IFF_PROMISC	0x100		/* receive all packets */
96 #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
97 #define IFF_PRIVATE	0x8000		/* do not advertise */
98 
99 /* flags set internally only: */
100 #define	IFF_CANTCHANGE \
101 		(IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING | IFF_PROMISC)
102 
103 /*
104  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
105  * input routines have queues of messages stored on ifqueue structures
106  * (defined above).  Entries are added to and deleted from these structures
107  * by these macros, which should be called with ipl raised to splimp().
108  */
109 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
110 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
111 #define	IF_ENQUEUE(ifq, m) { \
112 	(m)->m_act = 0; \
113 	if ((ifq)->ifq_tail == 0) \
114 		(ifq)->ifq_head = m; \
115 	else \
116 		(ifq)->ifq_tail->m_act = m; \
117 	(ifq)->ifq_tail = m; \
118 	(ifq)->ifq_len++; \
119 }
120 #define	IF_PREPEND(ifq, m) { \
121 	(m)->m_act = (ifq)->ifq_head; \
122 	if ((ifq)->ifq_tail == 0) \
123 		(ifq)->ifq_tail = (m); \
124 	(ifq)->ifq_head = (m); \
125 	(ifq)->ifq_len++; \
126 }
127 /*
128  * Packets destined for level-1 protocol input routines
129  * have a pointer to the receiving interface prepended to the data.
130  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
131  * IF_ADJ should be used otherwise to adjust for its presence.
132  */
133 #define	IF_ADJ(m) { \
134 	(m)->m_off += sizeof(struct ifnet *); \
135 	(m)->m_len -= sizeof(struct ifnet *); \
136 	if ((m)->m_len == 0) { \
137 		struct mbuf *n; \
138 		MFREE((m), n); \
139 		(m) = n; \
140 	} \
141 }
142 #define	IF_DEQUEUEIF(ifq, m, ifp) { \
143 	(m) = (ifq)->ifq_head; \
144 	if (m) { \
145 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
146 			(ifq)->ifq_tail = 0; \
147 		(m)->m_act = 0; \
148 		(ifq)->ifq_len--; \
149 		(ifp) = *(mtod((m), struct ifnet **)); \
150 		IF_ADJ(m); \
151 	} \
152 }
153 #define	IF_DEQUEUE(ifq, m) { \
154 	(m) = (ifq)->ifq_head; \
155 	if (m) { \
156 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
157 			(ifq)->ifq_tail = 0; \
158 		(m)->m_act = 0; \
159 		(ifq)->ifq_len--; \
160 	} \
161 }
162 
163 #define	IFQ_MAXLEN	50
164 #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
165 
166 /*
167  * The ifaddr structure contains information about one address
168  * of an interface.  They are maintained by the different address families,
169  * are allocated and attached when an address is set, and are linked
170  * together so all addresses for an interface can be located.
171  */
172 struct ifaddr {
173 	struct	sockaddr ifa_addr;	/* address of interface */
174 	union {
175 		struct	sockaddr ifu_broadaddr;
176 		struct	sockaddr ifu_dstaddr;
177 	} ifa_ifu;
178 #define	ifa_broadaddr	ifa_ifu.ifu_broadaddr	/* broadcast address */
179 #define	ifa_dstaddr	ifa_ifu.ifu_dstaddr	/* other end of p-to-p link */
180 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
181 	struct	ifaddr *ifa_next;	/* next address for interface */
182 };
183 
184 /*
185  * Interface request structure used for socket
186  * ioctl's.  All interface ioctl's must have parameter
187  * definitions which begin with ifr_name.  The
188  * remainder may be interface specific.
189  */
190 struct	ifreq {
191 #define	IFNAMSIZ	16
192 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
193 	union {
194 		struct	sockaddr ifru_addr;
195 		struct	sockaddr ifru_dstaddr;
196 		char	ifru_oname[IFNAMSIZ];	/* other if name */
197 		struct	sockaddr ifru_broadaddr;
198 		short	ifru_flags;
199 		int	ifru_metric;
200 		char	ifru_data[1];		/* interface dependent data */
201 
202 		/* Struct for FDDI ioctl's */
203 		struct ifr_dnld_reqs {
204 			caddr_t	v_addr;
205 			caddr_t	m_addr;
206 			caddr_t	ex_addr;
207 			u_int	size;
208 		} ifru_dnld_req;
209 
210 		/* Struct for FDDI stats */
211 		struct ifr_fddi_stats {
212 			u_int	stat_size;
213 			caddr_t	fddi_stats;
214 		} ifru_fddi_stat;
215 
216 		struct ifr_netmapents {
217 			u_int	map_ent_size,	/* size of netmap structure */
218 				entry_number;	/* index into netmap list */
219 			caddr_t	fddi_map_ent;	/* pointer to user structure */
220 		} ifru_netmapent;
221 
222 		/* Field for generic ioctl for fddi */
223 
224 		struct ifr_fddi_gen_struct {
225 			int	ifru_fddi_gioctl; /* field for gen ioctl */
226 			caddr_t ifru_fddi_gaddr ; /* Generic ptr to a field */
227 		} ifru_fddi_gstruct;
228 
229 	} ifr_ifru;
230 
231 #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
232 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
233 #define	ifr_oname	ifr_ifru.ifru_oname	/* other if name */
234 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
235 #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
236 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
237 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
238 
239 /* FDDI specific */
240 #define ifr_dnld_req	ifr_ifru.ifru_dnld_req
241 #define ifr_fddi_stat	ifr_ifru.ifru_fddi_stat
242 #define ifr_fddi_netmap	ifr_ifru.ifru_netmapent	/* FDDI network map entries */
243 #define ifr_fddi_gstruct ifr_ifru.ifru_fddi_gstruct
244 
245 };
246 
247 /*
248  * Structure used in SIOCGIFCONF request.
249  * Used to retrieve interface configuration
250  * for machine (useful for programs which
251  * must know all networks accessible).
252  */
253 struct	ifconf {
254 	int	ifc_len;		/* size of associated buffer */
255 	union {
256 		caddr_t	ifcu_buf;
257 		struct	ifreq *ifcu_req;
258 	} ifc_ifcu;
259 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
260 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
261 };
262 
263 #endif /* !_net_if_h */
264