123158Smckusick /* 2*39182Ssklower * Copyright (c) 1982, 1986, 1989 Regents of the University of California. 333183Sbostic * All rights reserved. 423158Smckusick * 533183Sbostic * Redistribution and use in source and binary forms are permitted 634844Sbostic * provided that the above copyright notice and this paragraph are 734844Sbostic * duplicated in all such forms and that any documentation, 834844Sbostic * advertising materials, and other materials related to such 934844Sbostic * distribution and use acknowledge that the software was developed 1034844Sbostic * by the University of California, Berkeley. The name of the 1134844Sbostic * University may not be used to endorse or promote products derived 1234844Sbostic * from this software without specific prior written permission. 1334844Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434844Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534844Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1633183Sbostic * 17*39182Ssklower * @(#)if.h 7.6 (Berkeley) 09/20/89 1823158Smckusick */ 194945Swnj 204945Swnj /* 215104Swnj * Structures defining a network interface, providing a packet 225104Swnj * transport mechanism (ala level 0 of the PUP protocols). 235104Swnj * 245104Swnj * Each interface accepts output datagrams of a specified maximum 255104Swnj * length, and provides higher level routines with input datagrams 265104Swnj * received from its medium. 275104Swnj * 285104Swnj * Output occurs when the routine if_output is called, with three parameters: 296333Ssam * (*ifp->if_output)(ifp, m, dst) 306333Ssam * Here m is the mbuf chain to be sent and dst is the destination address. 316333Ssam * The output routine encapsulates the supplied datagram if necessary, 326333Ssam * and then transmits it on its medium. 335104Swnj * 345104Swnj * On input, each interface unwraps the data received by it, and either 355104Swnj * places it on the input queue of a internetwork datagram routine 365104Swnj * and posts the associated software interrupt, or passes the datagram to a raw 375104Swnj * packet input routine. 385104Swnj * 396333Ssam * Routines exist for locating interfaces by their addresses 405104Swnj * or for locating a interface on a certain network, as well as more general 415104Swnj * routing and gateway routines maintaining information used to locate 426333Ssam * interfaces. These routines live in the files if.c and route.c 435083Swnj */ 44*39182Ssklower #ifndef _TIME_ /* XXX fast fix for SNMP, going away soon */ 45*39182Ssklower #ifdef KERNEL 46*39182Ssklower #include "../sys/time.h" 47*39182Ssklower #else 48*39182Ssklower #include <sys/time.h> 49*39182Ssklower #endif 50*39182Ssklower #endif 515083Swnj 525083Swnj /* 535083Swnj * Structure defining a queue for a network interface. 544945Swnj * 554945Swnj * (Would like to call this struct ``if'', but C isn't PL/1.) 564945Swnj */ 57*39182Ssklower 584945Swnj struct ifnet { 595171Swnj char *if_name; /* name, e.g. ``en'' or ``lo'' */ 604945Swnj short if_unit; /* sub-unit for lower level driver */ 614945Swnj short if_mtu; /* maximum transmission unit */ 626333Ssam short if_flags; /* up/down, broadcast, etc. */ 637264Ssam short if_timer; /* time 'til if_watchdog called */ 6426092Skarels int if_metric; /* routing metric (external only) */ 6518408Skarels struct ifaddr *if_addrlist; /* linked list of addresses per if */ 665104Swnj struct ifqueue { 675104Swnj struct mbuf *ifq_head; 685104Swnj struct mbuf *ifq_tail; 696207Swnj int ifq_len; 706207Swnj int ifq_maxlen; 716207Swnj int ifq_drops; 725104Swnj } if_snd; /* output queue */ 735104Swnj /* procedure handles */ 745104Swnj int (*if_init)(); /* init routine */ 7535795Skarels int (*if_output)(); /* output routine (enqueue) */ 7635795Skarels int (*if_start)(); /* initiate output routine */ 7735795Skarels int (*if_done)(); /* output complete routine */ 7813049Ssam int (*if_ioctl)(); /* ioctl routine */ 798972Sroot int (*if_reset)(); /* bus reset routine */ 807264Ssam int (*if_watchdog)(); /* timer routine */ 815104Swnj /* generic interface statistics */ 825171Swnj int if_ipackets; /* packets received on interface */ 835171Swnj int if_ierrors; /* input errors on interface */ 845171Swnj int if_opackets; /* packets sent on interface */ 855171Swnj int if_oerrors; /* output errors on interface */ 865104Swnj int if_collisions; /* collisions on csma interfaces */ 875104Swnj /* end statistics */ 884951Swnj struct ifnet *if_next; 8937472Ssklower u_char if_type; /* ethernet, tokenring, etc */ 9037472Ssklower u_char if_addrlen; /* media address length */ 9137472Ssklower u_char if_hdrlen; /* media header length */ 92*39182Ssklower /* more statistics here to avoid recompiling netstat */ 93*39182Ssklower struct timeval if_lastchange; /* last updated */ 94*39182Ssklower int if_ibytes; /* total number of octets received */ 95*39182Ssklower int if_obytes; /* total number of octets sent */ 96*39182Ssklower int if_imcasts; /* packets received via multicast */ 97*39182Ssklower int if_omcasts; /* packets sent via multicast */ 98*39182Ssklower int if_iqdrops; /* dropped on input, this interface */ 99*39182Ssklower int if_noproto; /* destined for unsupported protocol */ 100*39182Ssklower int if_baudrate; /* linespeed */ 1014945Swnj }; 1024945Swnj 1036333Ssam #define IFF_UP 0x1 /* interface is up */ 1046333Ssam #define IFF_BROADCAST 0x2 /* broadcast address valid */ 1056333Ssam #define IFF_DEBUG 0x4 /* turn on debugging */ 10626092Skarels #define IFF_LOOPBACK 0x8 /* is a loopback net */ 1076924Swnj #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 10813049Ssam #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 10913053Ssam #define IFF_RUNNING 0x40 /* resources allocated */ 11014866Ssam #define IFF_NOARP 0x80 /* no address resolution protocol */ 11128153Skarels /* next two not supported now, but reserved: */ 11228153Skarels #define IFF_PROMISC 0x100 /* receive all packets */ 11328153Skarels #define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 11435795Skarels #define IFF_OACTIVE 0x400 /* transmission in progress */ 11535795Skarels #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ 11635795Skarels 11726092Skarels /* flags set internally only: */ 11835795Skarels #define IFF_CANTCHANGE (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE) 1196333Ssam 1205104Swnj /* 1215104Swnj * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 1225104Swnj * input routines have queues of messages stored on ifqueue structures 1235104Swnj * (defined above). Entries are added to and deleted from these structures 1245104Swnj * by these macros, which should be called with ipl raised to splimp(). 1255104Swnj */ 1266207Swnj #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 1276207Swnj #define IF_DROP(ifq) ((ifq)->ifq_drops++) 1285083Swnj #define IF_ENQUEUE(ifq, m) { \ 1295083Swnj (m)->m_act = 0; \ 1305083Swnj if ((ifq)->ifq_tail == 0) \ 1315160Swnj (ifq)->ifq_head = m; \ 1325083Swnj else \ 1335083Swnj (ifq)->ifq_tail->m_act = m; \ 1345160Swnj (ifq)->ifq_tail = m; \ 1356207Swnj (ifq)->ifq_len++; \ 1365083Swnj } 1375613Swnj #define IF_PREPEND(ifq, m) { \ 1385613Swnj (m)->m_act = (ifq)->ifq_head; \ 1396087Sroot if ((ifq)->ifq_tail == 0) \ 1406087Sroot (ifq)->ifq_tail = (m); \ 1415613Swnj (ifq)->ifq_head = (m); \ 1426207Swnj (ifq)->ifq_len++; \ 1435613Swnj } 1445083Swnj #define IF_DEQUEUE(ifq, m) { \ 1455083Swnj (m) = (ifq)->ifq_head; \ 1465083Swnj if (m) { \ 1475083Swnj if (((ifq)->ifq_head = (m)->m_act) == 0) \ 1485083Swnj (ifq)->ifq_tail = 0; \ 1495083Swnj (m)->m_act = 0; \ 1506207Swnj (ifq)->ifq_len--; \ 1515083Swnj } \ 1525083Swnj } 1534945Swnj 1546207Swnj #define IFQ_MAXLEN 50 1557264Ssam #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 1566207Swnj 15711576Ssam /* 15818408Skarels * The ifaddr structure contains information about one address 15918408Skarels * of an interface. They are maintained by the different address families, 16018408Skarels * are allocated and attached when an address is set, and are linked 16118408Skarels * together so all addresses for an interface can be located. 16218408Skarels */ 16318408Skarels struct ifaddr { 16437472Ssklower struct sockaddr *ifa_addr; /* address of interface */ 16537472Ssklower struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 16637472Ssklower #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 16737472Ssklower struct sockaddr *ifa_netmask; /* used to determine subnet */ 16818408Skarels struct ifnet *ifa_ifp; /* back-pointer to interface */ 16918408Skarels struct ifaddr *ifa_next; /* next address for interface */ 17018408Skarels }; 17118408Skarels /* 17213049Ssam * Interface request structure used for socket 17313049Ssam * ioctl's. All interface ioctl's must have parameter 17413049Ssam * definitions which begin with ifr_name. The 17513049Ssam * remainder may be interface specific. 17611576Ssam */ 17711576Ssam struct ifreq { 17813049Ssam #define IFNAMSIZ 16 17913049Ssam char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 18011576Ssam union { 18111576Ssam struct sockaddr ifru_addr; 18211576Ssam struct sockaddr ifru_dstaddr; 18316387Skarels struct sockaddr ifru_broadaddr; 18411576Ssam short ifru_flags; 18526092Skarels int ifru_metric; 18613049Ssam caddr_t ifru_data; 18711576Ssam } ifr_ifru; 18811576Ssam #define ifr_addr ifr_ifru.ifru_addr /* address */ 18911576Ssam #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 19016387Skarels #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 19111576Ssam #define ifr_flags ifr_ifru.ifru_flags /* flags */ 19226092Skarels #define ifr_metric ifr_ifru.ifru_metric /* metric */ 19313049Ssam #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 19411576Ssam }; 19511576Ssam 19637472Ssklower struct ifaliasreq { 19737472Ssklower char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 19837472Ssklower struct sockaddr ifra_addr; 19937472Ssklower struct sockaddr ifra_broadaddr; 20037472Ssklower struct sockaddr ifra_mask; 20137472Ssklower }; 20237472Ssklower 20311576Ssam /* 20411576Ssam * Structure used in SIOCGIFCONF request. 20511576Ssam * Used to retrieve interface configuration 20611576Ssam * for machine (useful for programs which 20711576Ssam * must know all networks accessible). 20811576Ssam */ 20911576Ssam struct ifconf { 21011576Ssam int ifc_len; /* size of associated buffer */ 21111576Ssam union { 21211576Ssam caddr_t ifcu_buf; 21311576Ssam struct ifreq *ifcu_req; 21411576Ssam } ifc_ifcu; 21511576Ssam #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 21611576Ssam #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 21711576Ssam }; 21811576Ssam 2194945Swnj #ifdef KERNEL 22025971Skarels #include "../net/if_arp.h" 2216333Ssam struct ifqueue rawintrq; /* raw packet input queue */ 2224945Swnj struct ifnet *ifnet; 22328943Skarels struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet(); 22427197Skarels struct ifaddr *ifa_ifwithdstaddr(); 22525971Skarels #else KERNEL 22625971Skarels #include <net/if_arp.h> 22725971Skarels #endif KERNEL 228