xref: /csrg-svn/sys/net/if.h (revision 7161)
1 /*	if.h	4.14	82/06/13	*/
2 
3 /*
4  * Structures defining a network interface, providing a packet
5  * transport mechanism (ala level 0 of the PUP protocols).
6  *
7  * Each interface accepts output datagrams of a specified maximum
8  * length, and provides higher level routines with input datagrams
9  * received from its medium.
10  *
11  * Output occurs when the routine if_output is called, with three parameters:
12  *	(*ifp->if_output)(ifp, m, dst)
13  * Here m is the mbuf chain to be sent and dst is the destination address.
14  * The output routine encapsulates the supplied datagram if necessary,
15  * and then transmits it on its medium.
16  *
17  * On input, each interface unwraps the data received by it, and either
18  * places it on the input queue of a internetwork datagram routine
19  * and posts the associated software interrupt, or passes the datagram to a raw
20  * packet input routine.
21  *
22  * Routines exist for locating interfaces by their addresses
23  * or for locating a interface on a certain network, as well as more general
24  * routing and gateway routines maintaining information used to locate
25  * interfaces.  These routines live in the files if.c and route.c
26  */
27 
28 /*
29  * Structure defining a queue for a network interface.
30  *
31  * (Would like to call this struct ``if'', but C isn't PL/1.)
32  *
33  * EVENTUALLY PURGE if_net AND if_host FROM STRUCTURE
34  */
35 struct ifnet {
36 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
37 	short	if_unit;		/* sub-unit for lower level driver */
38 	short	if_mtu;			/* maximum transmission unit */
39 	int	if_net;			/* network number of interface */
40 	short	if_flags;		/* up/down, broadcast, etc. */
41 	int	if_host[2];		/* local net host number */
42 	struct	sockaddr if_addr;	/* address of interface */
43 	union {
44 		struct	sockaddr ifu_broadaddr;
45 		struct	sockaddr ifu_dstaddr;
46 	} if_ifu;
47 #define	if_broadaddr	if_ifu.ifu_broadaddr	/* broadcast address */
48 #define	if_dstaddr	if_ifu.ifu_dstaddr	/* other end of p-to-p link */
49 	struct	ifqueue {
50 		struct	mbuf *ifq_head;
51 		struct	mbuf *ifq_tail;
52 		int	ifq_len;
53 		int	ifq_maxlen;
54 		int	ifq_drops;
55 	} if_snd;			/* output queue */
56 /* procedure handles */
57 	int	(*if_init)();		/* init routine */
58 	int	(*if_output)();		/* output routine */
59 	int	(*if_ubareset)();	/* uba reset routine */
60 /* generic interface statistics */
61 	int	if_ipackets;		/* packets received on interface */
62 	int	if_ierrors;		/* input errors on interface */
63 	int	if_opackets;		/* packets sent on interface */
64 	int	if_oerrors;		/* output errors on interface */
65 	int	if_collisions;		/* collisions on csma interfaces */
66 /* end statistics */
67 	struct	ifnet *if_next;
68 };
69 
70 #define	IFF_UP		0x1		/* interface is up */
71 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
72 #define	IFF_DEBUG	0x4		/* turn on debugging */
73 #define	IFF_ROUTE	0x8		/* routing entry installed */
74 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
75 
76 /*
77  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
78  * input routines have queues of messages stored on ifqueue structures
79  * (defined above).  Entries are added to and deleted from these structures
80  * by these macros, which should be called with ipl raised to splimp().
81  */
82 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
83 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
84 #define	IF_ENQUEUE(ifq, m) { \
85 	(m)->m_act = 0; \
86 	if ((ifq)->ifq_tail == 0) \
87 		(ifq)->ifq_head = m; \
88 	else \
89 		(ifq)->ifq_tail->m_act = m; \
90 	(ifq)->ifq_tail = m; \
91 	(ifq)->ifq_len++; \
92 }
93 #define	IF_PREPEND(ifq, m) { \
94 	(m)->m_act = (ifq)->ifq_head; \
95 	if ((ifq)->ifq_tail == 0) \
96 		(ifq)->ifq_tail = (m); \
97 	(ifq)->ifq_head = (m); \
98 	(ifq)->ifq_len++; \
99 }
100 #define	IF_DEQUEUE(ifq, m) { \
101 	(m) = (ifq)->ifq_head; \
102 	if (m) { \
103 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
104 			(ifq)->ifq_tail = 0; \
105 		(m)->m_act = 0; \
106 		(ifq)->ifq_len--; \
107 	} \
108 }
109 
110 #define	IFQ_MAXLEN	50
111 
112 #ifdef KERNEL
113 #ifdef INET
114 struct	ifqueue	ipintrq;		/* ip packet input queue */
115 #endif
116 struct	ifqueue rawintrq;		/* raw packet input queue */
117 struct	ifnet *ifnet;
118 struct	ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf();
119 struct	ifnet *if_ifonnetof();
120 struct	in_addr if_makeaddr();
121 #endif
122