|
|
1.1 root 1: /* if.h 6.2 83/08/28 */
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: */
1.1.1.2 ! root 35: /*
! 36: * Changes to this file:
! 37: * 1/18/86: Add declaration for new routine in if.c - if_ifptop()
! 38: */
! 39:
1.1 root 40: struct ifnet {
41: char *if_name; /* name, e.g. ``en'' or ``lo'' */
42: short if_unit; /* sub-unit for lower level driver */
43: short if_mtu; /* maximum transmission unit */
44: int if_net; /* network number of interface */
45: short if_flags; /* up/down, broadcast, etc. */
46: short if_timer; /* time 'til if_watchdog called */
47: int if_host[2]; /* local net host number */
48: struct sockaddr if_addr; /* address of interface */
49: union {
50: struct sockaddr ifu_broadaddr;
51: struct sockaddr ifu_dstaddr;
52: } if_ifu;
53: #define if_broadaddr if_ifu.ifu_broadaddr /* broadcast address */
54: #define if_dstaddr if_ifu.ifu_dstaddr /* other end of p-to-p link */
55: struct ifqueue {
56: struct mbuf *ifq_head;
57: struct mbuf *ifq_tail;
58: int ifq_len;
59: int ifq_maxlen;
60: int ifq_drops;
61: } if_snd; /* output queue */
62: /* procedure handles */
63: int (*if_init)(); /* init routine */
64: int (*if_output)(); /* output routine */
65: int (*if_ioctl)(); /* ioctl routine */
66: int (*if_reset)(); /* bus reset routine */
67: int (*if_watchdog)(); /* timer routine */
68: /* generic interface statistics */
69: int if_ipackets; /* packets received on interface */
70: int if_ierrors; /* input errors on interface */
71: int if_opackets; /* packets sent on interface */
72: int if_oerrors; /* output errors on interface */
73: int if_collisions; /* collisions on csma interfaces */
74: /* end statistics */
75: struct ifnet *if_next;
76: };
77:
78: #define IFF_UP 0x1 /* interface is up */
79: #define IFF_BROADCAST 0x2 /* broadcast address valid */
80: #define IFF_DEBUG 0x4 /* turn on debugging */
81: #define IFF_ROUTE 0x8 /* routing entry installed */
82: #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
83: #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
84: #define IFF_RUNNING 0x40 /* resources allocated */
85: #define IFF_NOARP 0x80 /* no address resolution protocol */
86:
87: /*
88: * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
89: * input routines have queues of messages stored on ifqueue structures
90: * (defined above). Entries are added to and deleted from these structures
91: * by these macros, which should be called with ipl raised to splimp().
92: */
93: #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
94: #define IF_DROP(ifq) ((ifq)->ifq_drops++)
95: #define IF_ENQUEUE(ifq, m) { \
96: (m)->m_act = 0; \
97: if ((ifq)->ifq_tail == 0) \
98: (ifq)->ifq_head = m; \
99: else \
100: (ifq)->ifq_tail->m_act = m; \
101: (ifq)->ifq_tail = m; \
102: (ifq)->ifq_len++; \
103: }
104: #define IF_PREPEND(ifq, m) { \
105: (m)->m_act = (ifq)->ifq_head; \
106: if ((ifq)->ifq_tail == 0) \
107: (ifq)->ifq_tail = (m); \
108: (ifq)->ifq_head = (m); \
109: (ifq)->ifq_len++; \
110: }
111: #define IF_DEQUEUE(ifq, m) { \
112: (m) = (ifq)->ifq_head; \
113: if (m) { \
114: if (((ifq)->ifq_head = (m)->m_act) == 0) \
115: (ifq)->ifq_tail = 0; \
116: (m)->m_act = 0; \
117: (ifq)->ifq_len--; \
118: } \
119: }
120:
121: #define IFQ_MAXLEN 50
122: #define IFNET_SLOWHZ 1 /* granularity is 1 second */
123:
124: /*
125: * Interface request structure used for socket
126: * ioctl's. All interface ioctl's must have parameter
127: * definitions which begin with ifr_name. The
128: * remainder may be interface specific.
129: */
130: struct ifreq {
131: #define IFNAMSIZ 16
132: char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
133: union {
134: struct sockaddr ifru_addr;
135: struct sockaddr ifru_dstaddr;
136: short ifru_flags;
137: caddr_t ifru_data;
138: } ifr_ifru;
139: #define ifr_addr ifr_ifru.ifru_addr /* address */
140: #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
141: #define ifr_flags ifr_ifru.ifru_flags /* flags */
142: #define ifr_data ifr_ifru.ifru_data /* for use by interface */
143: };
144:
145: /*
146: * Structure used in SIOCGIFCONF request.
147: * Used to retrieve interface configuration
148: * for machine (useful for programs which
149: * must know all networks accessible).
150: */
151: struct ifconf {
152: int ifc_len; /* size of associated buffer */
153: union {
154: caddr_t ifcu_buf;
155: struct ifreq *ifcu_req;
156: } ifc_ifcu;
157: #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
158: #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
159: };
160:
161: #ifdef KERNEL
162: #ifdef INET
163: struct ifqueue ipintrq; /* ip packet input queue */
164: #endif
165: struct ifqueue rawintrq; /* raw packet input queue */
166: struct ifnet *ifnet;
167: struct ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf();
1.1.1.2 ! root 168: struct ifnet *if_ifonnetof(), *if_ifptop();
1.1 root 169: struct in_addr if_makeaddr();
170: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.