1 /* if.h 6.6 85/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, 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 struct ifnet { 34 char *if_name; /* name, e.g. ``en'' or ``lo'' */ 35 short if_unit; /* sub-unit for lower level driver */ 36 short if_mtu; /* maximum transmission unit */ 37 short if_flags; /* up/down, broadcast, etc. */ 38 short if_timer; /* time 'til if_watchdog called */ 39 struct ifaddr *if_addrlist; /* linked list of addresses per if */ 40 struct ifqueue { 41 struct mbuf *ifq_head; 42 struct mbuf *ifq_tail; 43 int ifq_len; 44 int ifq_maxlen; 45 int ifq_drops; 46 } if_snd; /* output queue */ 47 /* procedure handles */ 48 int (*if_init)(); /* init routine */ 49 int (*if_output)(); /* output routine */ 50 int (*if_ioctl)(); /* ioctl routine */ 51 int (*if_reset)(); /* bus reset routine */ 52 int (*if_watchdog)(); /* timer 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 #define IFF_UP 0x1 /* interface is up */ 64 #define IFF_BROADCAST 0x2 /* broadcast address valid */ 65 #define IFF_DEBUG 0x4 /* turn on debugging */ 66 /* was IFF_ROUTE 0x8 /* routing entry installed */ 67 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 68 #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 69 #define IFF_RUNNING 0x40 /* resources allocated */ 70 #define IFF_NOARP 0x80 /* no address resolution protocol */ 71 /* flags set internally only: */ 72 #define IFF_CANTCHANGE (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING) 73 74 /* 75 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 76 * input routines have queues of messages stored on ifqueue structures 77 * (defined above). Entries are added to and deleted from these structures 78 * by these macros, which should be called with ipl raised to splimp(). 79 */ 80 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 81 #define IF_DROP(ifq) ((ifq)->ifq_drops++) 82 #define IF_ENQUEUE(ifq, m) { \ 83 (m)->m_act = 0; \ 84 if ((ifq)->ifq_tail == 0) \ 85 (ifq)->ifq_head = m; \ 86 else \ 87 (ifq)->ifq_tail->m_act = m; \ 88 (ifq)->ifq_tail = m; \ 89 (ifq)->ifq_len++; \ 90 } 91 #define IF_PREPEND(ifq, m) { \ 92 (m)->m_act = (ifq)->ifq_head; \ 93 if ((ifq)->ifq_tail == 0) \ 94 (ifq)->ifq_tail = (m); \ 95 (ifq)->ifq_head = (m); \ 96 (ifq)->ifq_len++; \ 97 } 98 #define IF_DEQUEUE(ifq, m) { \ 99 (m) = (ifq)->ifq_head; \ 100 if (m) { \ 101 if (((ifq)->ifq_head = (m)->m_act) == 0) \ 102 (ifq)->ifq_tail = 0; \ 103 (m)->m_act = 0; \ 104 (ifq)->ifq_len--; \ 105 } \ 106 } 107 108 #define IFQ_MAXLEN 50 109 #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 110 111 /* 112 * The ifaddr structure contains information about one address 113 * of an interface. They are maintained by the different address families, 114 * are allocated and attached when an address is set, and are linked 115 * together so all addresses for an interface can be located. 116 */ 117 struct ifaddr { 118 struct sockaddr ifa_addr; /* address of interface */ 119 union { 120 struct sockaddr ifu_broadaddr; 121 struct sockaddr ifu_dstaddr; 122 } ifa_ifu; 123 #define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */ 124 #define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of p-to-p link */ 125 struct ifnet *ifa_ifp; /* back-pointer to interface */ 126 struct ifaddr *ifa_next; /* next address for interface */ 127 }; 128 129 /* 130 * Interface request structure used for socket 131 * ioctl's. All interface ioctl's must have parameter 132 * definitions which begin with ifr_name. The 133 * remainder may be interface specific. 134 */ 135 struct ifreq { 136 #define IFNAMSIZ 16 137 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 138 union { 139 struct sockaddr ifru_addr; 140 struct sockaddr ifru_dstaddr; 141 struct sockaddr ifru_broadaddr; 142 short ifru_flags; 143 caddr_t ifru_data; 144 } ifr_ifru; 145 #define ifr_addr ifr_ifru.ifru_addr /* address */ 146 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 147 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 148 #define ifr_flags ifr_ifru.ifru_flags /* flags */ 149 #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 150 }; 151 152 /* 153 * Structure used in SIOCGIFCONF request. 154 * Used to retrieve interface configuration 155 * for machine (useful for programs which 156 * must know all networks accessible). 157 */ 158 struct ifconf { 159 int ifc_len; /* size of associated buffer */ 160 union { 161 caddr_t ifcu_buf; 162 struct ifreq *ifcu_req; 163 } ifc_ifcu; 164 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 165 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 166 }; 167 168 /* 169 * ARP ioctl request 170 */ 171 struct arpreq { 172 struct sockaddr arp_pa; /* protocol address */ 173 struct sockaddr arp_ha; /* hardware address */ 174 int arp_flags; /* flags */ 175 }; 176 /* arp_flags and at_flags field values */ 177 #define ATF_INUSE 1 /* entry in use */ 178 #define ATF_COM 2 /* completed entry (enaddr valid) */ 179 #define ATF_PERM 4 /* permanent entry */ 180 #define ATF_PUBL 8 /* publish entry (respond for other host) */ 181 182 #ifdef KERNEL 183 #ifdef INET 184 struct ifqueue ipintrq; /* ip packet input queue */ 185 #endif 186 struct ifqueue rawintrq; /* raw packet input queue */ 187 struct ifnet *ifnet; 188 struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet(), *ifa_ifwithaf(); 189 #endif 190