routing code now operational
[unix-history] / usr / src / sys / net / if.h
CommitLineData
f6311fb6 1/* if.h 4.12 82/03/30 */
665ce890
BJ
2
3/*
f1b2fa5b
BJ
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:
ee787340
SL
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.
f1b2fa5b
BJ
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 *
ee787340 22 * Routines exist for locating interfaces by their addresses
f1b2fa5b
BJ
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
ee787340 25 * interfaces. These routines live in the files if.c and route.c
8a13b737 26 */
8a13b737
BJ
27
28/*
29 * Structure defining a queue for a network interface.
665ce890
BJ
30 *
31 * (Would like to call this struct ``if'', but C isn't PL/1.)
32 */
33struct ifnet {
b454c3ea 34 char *if_name; /* name, e.g. ``en'' or ``lo'' */
665ce890 35 short if_unit; /* sub-unit for lower level driver */
665ce890
BJ
36 short if_mtu; /* maximum transmission unit */
37 short if_net; /* network number of interface */
ee787340 38 short if_flags; /* up/down, broadcast, etc. */
8a13b737 39 int if_host[2]; /* local net host number */
ee787340
SL
40 struct sockaddr if_addr; /* internet address of interface */
41 struct sockaddr if_broadaddr; /* broadcast address of interface */
f1b2fa5b
BJ
42 struct ifqueue {
43 struct mbuf *ifq_head;
44 struct mbuf *ifq_tail;
1e977657
BJ
45 int ifq_len;
46 int ifq_maxlen;
47 int ifq_drops;
f1b2fa5b
BJ
48 } if_snd; /* output queue */
49/* procedure handles */
50 int (*if_init)(); /* init routine */
8a13b737
BJ
51 int (*if_output)(); /* output routine */
52 int (*if_ubareset)(); /* uba reset routine */
f1b2fa5b 53/* generic interface statistics */
b454c3ea
BJ
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 */
f1b2fa5b 58 int if_collisions; /* collisions on csma interfaces */
f1b2fa5b 59/* end statistics */
4ad99bae 60 struct ifnet *if_next;
665ce890
BJ
61};
62
ee787340
SL
63#define IFF_UP 0x1 /* interface is up */
64#define IFF_BROADCAST 0x2 /* broadcast address valid */
65#define IFF_DEBUG 0x4 /* turn on debugging */
f6311fb6 66#define IFF_ROUTE 0x8 /* routine entry installed */
ee787340 67
f1b2fa5b
BJ
68/*
69 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
70 * input routines have queues of messages stored on ifqueue structures
71 * (defined above). Entries are added to and deleted from these structures
72 * by these macros, which should be called with ipl raised to splimp().
73 */
1e977657
BJ
74#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
75#define IF_DROP(ifq) ((ifq)->ifq_drops++)
8a13b737
BJ
76#define IF_ENQUEUE(ifq, m) { \
77 (m)->m_act = 0; \
78 if ((ifq)->ifq_tail == 0) \
405c9168 79 (ifq)->ifq_head = m; \
8a13b737
BJ
80 else \
81 (ifq)->ifq_tail->m_act = m; \
405c9168 82 (ifq)->ifq_tail = m; \
1e977657 83 (ifq)->ifq_len++; \
8a13b737 84}
e740a894
BJ
85#define IF_PREPEND(ifq, m) { \
86 (m)->m_act = (ifq)->ifq_head; \
1dd55890
BJ
87 if ((ifq)->ifq_tail == 0) \
88 (ifq)->ifq_tail = (m); \
e740a894 89 (ifq)->ifq_head = (m); \
1e977657 90 (ifq)->ifq_len++; \
e740a894 91}
8a13b737
BJ
92#define IF_DEQUEUE(ifq, m) { \
93 (m) = (ifq)->ifq_head; \
94 if (m) { \
95 if (((ifq)->ifq_head = (m)->m_act) == 0) \
96 (ifq)->ifq_tail = 0; \
97 (m)->m_act = 0; \
1e977657 98 (ifq)->ifq_len--; \
8a13b737
BJ
99 } \
100}
665ce890 101
1e977657
BJ
102#define IFQ_MAXLEN 50
103
665ce890 104#ifdef KERNEL
8a13b737
BJ
105#ifdef INET
106struct ifqueue ipintrq; /* ip packet input queue */
107#endif
ee787340 108struct ifqueue rawintrq; /* raw packet input queue */
665ce890 109struct ifnet *ifnet;
ee787340
SL
110struct ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf();
111struct ifnet *if_ifonnetof();
f1b2fa5b 112struct in_addr if_makeaddr();
665ce890 113#endif