1*23158Smckusick /* 2*23158Smckusick * Copyright (c) 1980 Regents of the University of California. 3*23158Smckusick * All rights reserved. The Berkeley software License Agreement 4*23158Smckusick * specifies the terms and conditions for redistribution. 5*23158Smckusick * 6*23158Smckusick * @(#)if.h 6.7 (Berkeley) 06/08/85 7*23158Smckusick */ 84945Swnj 94945Swnj /* 105104Swnj * Structures defining a network interface, providing a packet 115104Swnj * transport mechanism (ala level 0 of the PUP protocols). 125104Swnj * 135104Swnj * Each interface accepts output datagrams of a specified maximum 145104Swnj * length, and provides higher level routines with input datagrams 155104Swnj * received from its medium. 165104Swnj * 175104Swnj * Output occurs when the routine if_output is called, with three parameters: 186333Ssam * (*ifp->if_output)(ifp, m, dst) 196333Ssam * Here m is the mbuf chain to be sent and dst is the destination address. 206333Ssam * The output routine encapsulates the supplied datagram if necessary, 216333Ssam * and then transmits it on its medium. 225104Swnj * 235104Swnj * On input, each interface unwraps the data received by it, and either 245104Swnj * places it on the input queue of a internetwork datagram routine 255104Swnj * and posts the associated software interrupt, or passes the datagram to a raw 265104Swnj * packet input routine. 275104Swnj * 286333Ssam * Routines exist for locating interfaces by their addresses 295104Swnj * or for locating a interface on a certain network, as well as more general 305104Swnj * routing and gateway routines maintaining information used to locate 316333Ssam * interfaces. These routines live in the files if.c and route.c 325083Swnj */ 335083Swnj 345083Swnj /* 355083Swnj * Structure defining a queue for a network interface. 364945Swnj * 374945Swnj * (Would like to call this struct ``if'', but C isn't PL/1.) 384945Swnj */ 394945Swnj struct ifnet { 405171Swnj char *if_name; /* name, e.g. ``en'' or ``lo'' */ 414945Swnj short if_unit; /* sub-unit for lower level driver */ 424945Swnj short if_mtu; /* maximum transmission unit */ 436333Ssam short if_flags; /* up/down, broadcast, etc. */ 447264Ssam short if_timer; /* time 'til if_watchdog called */ 4518408Skarels struct ifaddr *if_addrlist; /* linked list of addresses per if */ 465104Swnj struct ifqueue { 475104Swnj struct mbuf *ifq_head; 485104Swnj struct mbuf *ifq_tail; 496207Swnj int ifq_len; 506207Swnj int ifq_maxlen; 516207Swnj int ifq_drops; 525104Swnj } if_snd; /* output queue */ 535104Swnj /* procedure handles */ 545104Swnj int (*if_init)(); /* init routine */ 555083Swnj int (*if_output)(); /* output routine */ 5613049Ssam int (*if_ioctl)(); /* ioctl routine */ 578972Sroot int (*if_reset)(); /* bus reset routine */ 587264Ssam int (*if_watchdog)(); /* timer routine */ 595104Swnj /* generic interface statistics */ 605171Swnj int if_ipackets; /* packets received on interface */ 615171Swnj int if_ierrors; /* input errors on interface */ 625171Swnj int if_opackets; /* packets sent on interface */ 635171Swnj int if_oerrors; /* output errors on interface */ 645104Swnj int if_collisions; /* collisions on csma interfaces */ 655104Swnj /* end statistics */ 664951Swnj struct ifnet *if_next; 674945Swnj }; 684945Swnj 696333Ssam #define IFF_UP 0x1 /* interface is up */ 706333Ssam #define IFF_BROADCAST 0x2 /* broadcast address valid */ 716333Ssam #define IFF_DEBUG 0x4 /* turn on debugging */ 7218408Skarels /* was IFF_ROUTE 0x8 /* routing entry installed */ 736924Swnj #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 7413049Ssam #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 7513053Ssam #define IFF_RUNNING 0x40 /* resources allocated */ 7614866Ssam #define IFF_NOARP 0x80 /* no address resolution protocol */ 7718408Skarels /* flags set internally only: */ 7818408Skarels #define IFF_CANTCHANGE (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING) 796333Ssam 805104Swnj /* 815104Swnj * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 825104Swnj * input routines have queues of messages stored on ifqueue structures 835104Swnj * (defined above). Entries are added to and deleted from these structures 845104Swnj * by these macros, which should be called with ipl raised to splimp(). 855104Swnj */ 866207Swnj #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 876207Swnj #define IF_DROP(ifq) ((ifq)->ifq_drops++) 885083Swnj #define IF_ENQUEUE(ifq, m) { \ 895083Swnj (m)->m_act = 0; \ 905083Swnj if ((ifq)->ifq_tail == 0) \ 915160Swnj (ifq)->ifq_head = m; \ 925083Swnj else \ 935083Swnj (ifq)->ifq_tail->m_act = m; \ 945160Swnj (ifq)->ifq_tail = m; \ 956207Swnj (ifq)->ifq_len++; \ 965083Swnj } 975613Swnj #define IF_PREPEND(ifq, m) { \ 985613Swnj (m)->m_act = (ifq)->ifq_head; \ 996087Sroot if ((ifq)->ifq_tail == 0) \ 1006087Sroot (ifq)->ifq_tail = (m); \ 1015613Swnj (ifq)->ifq_head = (m); \ 1026207Swnj (ifq)->ifq_len++; \ 1035613Swnj } 1045083Swnj #define IF_DEQUEUE(ifq, m) { \ 1055083Swnj (m) = (ifq)->ifq_head; \ 1065083Swnj if (m) { \ 1075083Swnj if (((ifq)->ifq_head = (m)->m_act) == 0) \ 1085083Swnj (ifq)->ifq_tail = 0; \ 1095083Swnj (m)->m_act = 0; \ 1106207Swnj (ifq)->ifq_len--; \ 1115083Swnj } \ 1125083Swnj } 1134945Swnj 1146207Swnj #define IFQ_MAXLEN 50 1157264Ssam #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 1166207Swnj 11711576Ssam /* 11818408Skarels * The ifaddr structure contains information about one address 11918408Skarels * of an interface. They are maintained by the different address families, 12018408Skarels * are allocated and attached when an address is set, and are linked 12118408Skarels * together so all addresses for an interface can be located. 12218408Skarels */ 12318408Skarels struct ifaddr { 12418408Skarels struct sockaddr ifa_addr; /* address of interface */ 12518408Skarels union { 12618408Skarels struct sockaddr ifu_broadaddr; 12718408Skarels struct sockaddr ifu_dstaddr; 12818408Skarels } ifa_ifu; 12918408Skarels #define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */ 13018408Skarels #define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of p-to-p link */ 13118408Skarels struct ifnet *ifa_ifp; /* back-pointer to interface */ 13218408Skarels struct ifaddr *ifa_next; /* next address for interface */ 13318408Skarels }; 13418408Skarels 13518408Skarels /* 13613049Ssam * Interface request structure used for socket 13713049Ssam * ioctl's. All interface ioctl's must have parameter 13813049Ssam * definitions which begin with ifr_name. The 13913049Ssam * remainder may be interface specific. 14011576Ssam */ 14111576Ssam struct ifreq { 14213049Ssam #define IFNAMSIZ 16 14313049Ssam char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 14411576Ssam union { 14511576Ssam struct sockaddr ifru_addr; 14611576Ssam struct sockaddr ifru_dstaddr; 14716387Skarels struct sockaddr ifru_broadaddr; 14811576Ssam short ifru_flags; 14913049Ssam caddr_t ifru_data; 15011576Ssam } ifr_ifru; 15111576Ssam #define ifr_addr ifr_ifru.ifru_addr /* address */ 15211576Ssam #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 15316387Skarels #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 15411576Ssam #define ifr_flags ifr_ifru.ifru_flags /* flags */ 15513049Ssam #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 15611576Ssam }; 15711576Ssam 15811576Ssam /* 15911576Ssam * Structure used in SIOCGIFCONF request. 16011576Ssam * Used to retrieve interface configuration 16111576Ssam * for machine (useful for programs which 16211576Ssam * must know all networks accessible). 16311576Ssam */ 16411576Ssam struct ifconf { 16511576Ssam int ifc_len; /* size of associated buffer */ 16611576Ssam union { 16711576Ssam caddr_t ifcu_buf; 16811576Ssam struct ifreq *ifcu_req; 16911576Ssam } ifc_ifcu; 17011576Ssam #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 17111576Ssam #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 17211576Ssam }; 17311576Ssam 17416209Skarels /* 17516209Skarels * ARP ioctl request 17616209Skarels */ 17716209Skarels struct arpreq { 17816209Skarels struct sockaddr arp_pa; /* protocol address */ 17916209Skarels struct sockaddr arp_ha; /* hardware address */ 18016209Skarels int arp_flags; /* flags */ 18116209Skarels }; 18216209Skarels /* arp_flags and at_flags field values */ 18316209Skarels #define ATF_INUSE 1 /* entry in use */ 18416209Skarels #define ATF_COM 2 /* completed entry (enaddr valid) */ 18516209Skarels #define ATF_PERM 4 /* permanent entry */ 18616209Skarels #define ATF_PUBL 8 /* publish entry (respond for other host) */ 18716209Skarels 1884945Swnj #ifdef KERNEL 1895083Swnj #ifdef INET 1905083Swnj struct ifqueue ipintrq; /* ip packet input queue */ 1915083Swnj #endif 1926333Ssam struct ifqueue rawintrq; /* raw packet input queue */ 1934945Swnj struct ifnet *ifnet; 19418408Skarels struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet(), *ifa_ifwithaf(); 1954945Swnj #endif 196