xref: /original-bsd/sys/net/if.h (revision f662c168)
1 /*	if.h	4.10	82/03/19	*/
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, pf)
13  * Here m is the mbuf chain to be sent and pf is the protocol family
14  * of the internetwork datagram format in which the data is wrapped
15  * (e.g. PF_PUP or PF_INET).  The output routine encapsulates the
16  * supplied datagram if necessary, and then transmits it on its medium.
17  *
18  * On input, each interface unwraps the data received by it, and either
19  * places it on the input queue of a internetwork datagram routine
20  * and posts the associated software interrupt, or passes the datagram to a raw
21  * packet input routine.
22  *
23  * Routines exist for locating interfaces by their internet addresses
24  * or for locating a interface on a certain network, as well as more general
25  * routing and gateway routines maintaining information used to locate
26  * interfaces.  These routines live in the files if.c and ip_ggp.c.
27  */
28 
29 /*
30  * Structure defining a queue for a network interface.
31  *
32  * (Would like to call this struct ``if'', but C isn't PL/1.)
33  */
34 struct ifnet {
35 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
36 	short	if_unit;		/* sub-unit for lower level driver */
37 	short	if_mtu;			/* maximum transmission unit */
38 	short	if_net;			/* network number of interface */
39 	int	if_host[2];		/* local net host number */
40 	struct	in_addr if_addr;	/* internet address of interface */
41 	struct	in_addr if_broadaddr;	/* broadcast address of interface */
42 	struct	ifqueue {
43 		struct	mbuf *ifq_head;
44 		struct	mbuf *ifq_tail;
45 		int	ifq_len;
46 		int	ifq_maxlen;
47 		int	ifq_drops;
48 	} if_snd;			/* output queue */
49 /* procedure handles */
50 	int	(*if_init)();		/* init routine */
51 	int	(*if_output)();		/* output routine */
52 	int	(*if_ubareset)();	/* uba reset routine */
53 /* generic interface statistics */
54 	int	if_ipackets;		/* packets received on interface */
55 	int	if_ierrors;		/* input errors on interface */
56 	int	if_opackets;		/* packets sent on interface */
57 	int	if_oerrors;		/* output errors on interface */
58 	int	if_collisions;		/* collisions on csma interfaces */
59 /* end statistics */
60 	struct	ifnet *if_next;
61 };
62 
63 /*
64  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
65  * input routines have queues of messages stored on ifqueue structures
66  * (defined above).  Entries are added to and deleted from these structures
67  * by these macros, which should be called with ipl raised to splimp().
68  */
69 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
70 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
71 #define	IF_ENQUEUE(ifq, m) { \
72 	(m)->m_act = 0; \
73 	if ((ifq)->ifq_tail == 0) \
74 		(ifq)->ifq_head = m; \
75 	else \
76 		(ifq)->ifq_tail->m_act = m; \
77 	(ifq)->ifq_tail = m; \
78 	(ifq)->ifq_len++; \
79 }
80 #define	IF_PREPEND(ifq, m) { \
81 	(m)->m_act = (ifq)->ifq_head; \
82 	if ((ifq)->ifq_tail == 0) \
83 		(ifq)->ifq_tail = (m); \
84 	(ifq)->ifq_head = (m); \
85 	(ifq)->ifq_len++; \
86 }
87 #define	IF_DEQUEUE(ifq, m) { \
88 	(m) = (ifq)->ifq_head; \
89 	if (m) { \
90 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
91 			(ifq)->ifq_tail = 0; \
92 		(m)->m_act = 0; \
93 		(ifq)->ifq_len--; \
94 	} \
95 }
96 
97 #define	IFQ_MAXLEN	50
98 
99 #ifdef KERNEL
100 struct	ifqueue rawintrq;		/* raw packet input queue */
101 #ifdef INET
102 struct	ifqueue	ipintrq;		/* ip packet input queue */
103 #endif
104 struct	ifnet *ifnet;
105 struct	ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor();
106 struct	in_addr if_makeaddr();
107 #endif
108