10Sstevel@tonic-gate /* 2*12016SGirish.Moodalbail@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate */ 50Sstevel@tonic-gate 60Sstevel@tonic-gate /* 70Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 90Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 100Sstevel@tonic-gate */ 110Sstevel@tonic-gate 12722Smuffin #ifndef _net_if_h 13722Smuffin #define _net_if_h 140Sstevel@tonic-gate 150Sstevel@tonic-gate /* 160Sstevel@tonic-gate * Structures defining a network interface, providing a packet 170Sstevel@tonic-gate * transport mechanism (ala level 0 of the PUP protocols). 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * Each interface accepts output datagrams of a specified maximum 200Sstevel@tonic-gate * length, and provides higher level routines with input datagrams 210Sstevel@tonic-gate * received from its medium. 220Sstevel@tonic-gate * 230Sstevel@tonic-gate * Output occurs when the routine if_output is called, with three parameters: 240Sstevel@tonic-gate * (*ifp->if_output)(ifp, m, dst) 250Sstevel@tonic-gate * Here m is the mbuf chain to be sent and dst is the destination address. 260Sstevel@tonic-gate * The output routine encapsulates the supplied datagram if necessary, 270Sstevel@tonic-gate * and then transmits it on its medium. 280Sstevel@tonic-gate * 290Sstevel@tonic-gate * On input, each interface unwraps the data received by it, and either 300Sstevel@tonic-gate * places it on the input queue of a internetwork datagram routine 310Sstevel@tonic-gate * and posts the associated software interrupt, or passes the datagram to a raw 320Sstevel@tonic-gate * packet input routine. 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * Routines exist for locating interfaces by their addresses 350Sstevel@tonic-gate * or for locating a interface on a certain network, as well as more general 360Sstevel@tonic-gate * routing and gateway routines maintaining information used to locate 370Sstevel@tonic-gate * interfaces. These routines live in the files if.c and route.c 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * Structure defining a queue for a network interface. 420Sstevel@tonic-gate * 430Sstevel@tonic-gate * (Would like to call this struct ``if'', but C isn't PL/1.) 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate struct ifnet { 460Sstevel@tonic-gate char *if_name; /* name, e.g. ``en'' or ``lo'' */ 470Sstevel@tonic-gate short if_unit; /* sub-unit for lower level driver */ 480Sstevel@tonic-gate short if_mtu; /* maximum transmission unit */ 490Sstevel@tonic-gate short if_flags; /* up/down, broadcast, etc. */ 500Sstevel@tonic-gate short if_timer; /* time 'til if_watchdog called */ 510Sstevel@tonic-gate u_short if_promisc; /* net # of requests for promisc mode */ 520Sstevel@tonic-gate int if_metric; /* routing metric (external only) */ 530Sstevel@tonic-gate struct ifaddr *if_addrlist; /* linked list of addresses per if */ 540Sstevel@tonic-gate struct ifqueue { 550Sstevel@tonic-gate struct mbuf *ifq_head; 560Sstevel@tonic-gate struct mbuf *ifq_tail; 570Sstevel@tonic-gate int ifq_len; 580Sstevel@tonic-gate int ifq_maxlen; 590Sstevel@tonic-gate int ifq_drops; 600Sstevel@tonic-gate } if_snd; /* output queue */ 610Sstevel@tonic-gate /* procedure handles */ 620Sstevel@tonic-gate int (*if_init)(); /* init routine */ 630Sstevel@tonic-gate int (*if_output)(); /* output routine */ 640Sstevel@tonic-gate int (*if_ioctl)(); /* ioctl routine */ 650Sstevel@tonic-gate int (*if_reset)(); /* bus reset routine */ 660Sstevel@tonic-gate int (*if_watchdog)(); /* timer routine */ 670Sstevel@tonic-gate /* generic interface statistics */ 680Sstevel@tonic-gate int if_ipackets; /* packets received on interface */ 690Sstevel@tonic-gate int if_ierrors; /* input errors on interface */ 700Sstevel@tonic-gate int if_opackets; /* packets sent on interface */ 710Sstevel@tonic-gate int if_oerrors; /* output errors on interface */ 720Sstevel@tonic-gate int if_collisions; /* collisions on csma interfaces */ 730Sstevel@tonic-gate /* end statistics */ 740Sstevel@tonic-gate struct ifnet *if_next; 750Sstevel@tonic-gate struct ifnet *if_upper; /* next layer up */ 760Sstevel@tonic-gate struct ifnet *if_lower; /* next layer down */ 770Sstevel@tonic-gate int (*if_input)(); /* input routine */ 780Sstevel@tonic-gate int (*if_ctlin)(); /* control input routine */ 790Sstevel@tonic-gate int (*if_ctlout)(); /* control output routine */ 800Sstevel@tonic-gate #ifdef sun 810Sstevel@tonic-gate struct map *if_memmap; /* rmap for interface specific memory */ 820Sstevel@tonic-gate #endif 830Sstevel@tonic-gate }; 840Sstevel@tonic-gate 850Sstevel@tonic-gate #define IFF_UP 0x1 /* interface is up */ 860Sstevel@tonic-gate #define IFF_BROADCAST 0x2 /* broadcast address valid */ 870Sstevel@tonic-gate #define IFF_DEBUG 0x4 /* turn on debugging */ 880Sstevel@tonic-gate #define IFF_LOOPBACK 0x8 /* is a loopback net */ 890Sstevel@tonic-gate #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 900Sstevel@tonic-gate #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 910Sstevel@tonic-gate #define IFF_RUNNING 0x40 /* resources allocated */ 920Sstevel@tonic-gate #define IFF_NOARP 0x80 /* no address resolution protocol */ 930Sstevel@tonic-gate #define IFF_PROMISC 0x100 /* receive all packets */ 940Sstevel@tonic-gate #define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 95*12016SGirish.Moodalbail@Sun.COM #define IFF_PRIVATE 0x8000 /* do not advertise */ 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* flags set internally only: */ 980Sstevel@tonic-gate #define IFF_CANTCHANGE \ 990Sstevel@tonic-gate (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING | IFF_PROMISC) 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 1030Sstevel@tonic-gate * input routines have queues of messages stored on ifqueue structures 1040Sstevel@tonic-gate * (defined above). Entries are added to and deleted from these structures 1050Sstevel@tonic-gate * by these macros, which should be called with ipl raised to splimp(). 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 1080Sstevel@tonic-gate #define IF_DROP(ifq) ((ifq)->ifq_drops++) 1090Sstevel@tonic-gate #define IF_ENQUEUE(ifq, m) { \ 1100Sstevel@tonic-gate (m)->m_act = 0; \ 1110Sstevel@tonic-gate if ((ifq)->ifq_tail == 0) \ 1120Sstevel@tonic-gate (ifq)->ifq_head = m; \ 1130Sstevel@tonic-gate else \ 1140Sstevel@tonic-gate (ifq)->ifq_tail->m_act = m; \ 1150Sstevel@tonic-gate (ifq)->ifq_tail = m; \ 1160Sstevel@tonic-gate (ifq)->ifq_len++; \ 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate #define IF_PREPEND(ifq, m) { \ 1190Sstevel@tonic-gate (m)->m_act = (ifq)->ifq_head; \ 1200Sstevel@tonic-gate if ((ifq)->ifq_tail == 0) \ 1210Sstevel@tonic-gate (ifq)->ifq_tail = (m); \ 1220Sstevel@tonic-gate (ifq)->ifq_head = (m); \ 1230Sstevel@tonic-gate (ifq)->ifq_len++; \ 1240Sstevel@tonic-gate } 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * Packets destined for level-1 protocol input routines 1270Sstevel@tonic-gate * have a pointer to the receiving interface prepended to the data. 1280Sstevel@tonic-gate * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet. 1290Sstevel@tonic-gate * IF_ADJ should be used otherwise to adjust for its presence. 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate #define IF_ADJ(m) { \ 132*12016SGirish.Moodalbail@Sun.COM (m)->m_off += sizeof (struct ifnet *); \ 133*12016SGirish.Moodalbail@Sun.COM (m)->m_len -= sizeof (struct ifnet *); \ 1340Sstevel@tonic-gate if ((m)->m_len == 0) { \ 1350Sstevel@tonic-gate struct mbuf *n; \ 1360Sstevel@tonic-gate MFREE((m), n); \ 1370Sstevel@tonic-gate (m) = n; \ 1380Sstevel@tonic-gate } \ 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate #define IF_DEQUEUEIF(ifq, m, ifp) { \ 1410Sstevel@tonic-gate (m) = (ifq)->ifq_head; \ 1420Sstevel@tonic-gate if (m) { \ 1430Sstevel@tonic-gate if (((ifq)->ifq_head = (m)->m_act) == 0) \ 1440Sstevel@tonic-gate (ifq)->ifq_tail = 0; \ 1450Sstevel@tonic-gate (m)->m_act = 0; \ 1460Sstevel@tonic-gate (ifq)->ifq_len--; \ 1470Sstevel@tonic-gate (ifp) = *(mtod((m), struct ifnet **)); \ 1480Sstevel@tonic-gate IF_ADJ(m); \ 1490Sstevel@tonic-gate } \ 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate #define IF_DEQUEUE(ifq, m) { \ 1520Sstevel@tonic-gate (m) = (ifq)->ifq_head; \ 1530Sstevel@tonic-gate if (m) { \ 1540Sstevel@tonic-gate if (((ifq)->ifq_head = (m)->m_act) == 0) \ 1550Sstevel@tonic-gate (ifq)->ifq_tail = 0; \ 1560Sstevel@tonic-gate (m)->m_act = 0; \ 1570Sstevel@tonic-gate (ifq)->ifq_len--; \ 1580Sstevel@tonic-gate } \ 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #define IFQ_MAXLEN 50 1620Sstevel@tonic-gate #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* 1650Sstevel@tonic-gate * The ifaddr structure contains information about one address 1660Sstevel@tonic-gate * of an interface. They are maintained by the different address families, 1670Sstevel@tonic-gate * are allocated and attached when an address is set, and are linked 1680Sstevel@tonic-gate * together so all addresses for an interface can be located. 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate struct ifaddr { 1710Sstevel@tonic-gate struct sockaddr ifa_addr; /* address of interface */ 1720Sstevel@tonic-gate union { 1730Sstevel@tonic-gate struct sockaddr ifu_broadaddr; 1740Sstevel@tonic-gate struct sockaddr ifu_dstaddr; 1750Sstevel@tonic-gate } ifa_ifu; 176*12016SGirish.Moodalbail@Sun.COM #ifndef ifa_broadaddr 1770Sstevel@tonic-gate #define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */ 178*12016SGirish.Moodalbail@Sun.COM #endif 179*12016SGirish.Moodalbail@Sun.COM #ifndef ifa_dstaddr 1800Sstevel@tonic-gate #define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of p-to-p link */ 181*12016SGirish.Moodalbail@Sun.COM #endif 1820Sstevel@tonic-gate struct ifnet *ifa_ifp; /* back-pointer to interface */ 1830Sstevel@tonic-gate struct ifaddr *ifa_next; /* next address for interface */ 1840Sstevel@tonic-gate }; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate /* 1870Sstevel@tonic-gate * Interface request structure used for socket 1880Sstevel@tonic-gate * ioctl's. All interface ioctl's must have parameter 1890Sstevel@tonic-gate * definitions which begin with ifr_name. The 1900Sstevel@tonic-gate * remainder may be interface specific. 1910Sstevel@tonic-gate */ 1920Sstevel@tonic-gate struct ifreq { 1930Sstevel@tonic-gate #define IFNAMSIZ 16 1940Sstevel@tonic-gate char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 1950Sstevel@tonic-gate union { 1960Sstevel@tonic-gate struct sockaddr ifru_addr; 1970Sstevel@tonic-gate struct sockaddr ifru_dstaddr; 1980Sstevel@tonic-gate char ifru_oname[IFNAMSIZ]; /* other if name */ 1990Sstevel@tonic-gate struct sockaddr ifru_broadaddr; 2000Sstevel@tonic-gate short ifru_flags; 2010Sstevel@tonic-gate int ifru_metric; 2020Sstevel@tonic-gate char ifru_data[1]; /* interface dependent data */ 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* Struct for FDDI ioctl's */ 2050Sstevel@tonic-gate struct ifr_dnld_reqs { 2060Sstevel@tonic-gate caddr_t v_addr; 2070Sstevel@tonic-gate caddr_t m_addr; 2080Sstevel@tonic-gate caddr_t ex_addr; 2090Sstevel@tonic-gate u_int size; 2100Sstevel@tonic-gate } ifru_dnld_req; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* Struct for FDDI stats */ 2130Sstevel@tonic-gate struct ifr_fddi_stats { 2140Sstevel@tonic-gate u_int stat_size; 2150Sstevel@tonic-gate caddr_t fddi_stats; 2160Sstevel@tonic-gate } ifru_fddi_stat; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate struct ifr_netmapents { 2190Sstevel@tonic-gate u_int map_ent_size, /* size of netmap structure */ 2200Sstevel@tonic-gate entry_number; /* index into netmap list */ 2210Sstevel@tonic-gate caddr_t fddi_map_ent; /* pointer to user structure */ 2220Sstevel@tonic-gate } ifru_netmapent; 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate /* Field for generic ioctl for fddi */ 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate struct ifr_fddi_gen_struct { 2270Sstevel@tonic-gate int ifru_fddi_gioctl; /* field for gen ioctl */ 228*12016SGirish.Moodalbail@Sun.COM caddr_t ifru_fddi_gaddr; /* Generic ptr to a field */ 2290Sstevel@tonic-gate } ifru_fddi_gstruct; 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate } ifr_ifru; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate #define ifr_addr ifr_ifru.ifru_addr /* address */ 2340Sstevel@tonic-gate #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 2350Sstevel@tonic-gate #define ifr_oname ifr_ifru.ifru_oname /* other if name */ 2360Sstevel@tonic-gate #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 2370Sstevel@tonic-gate #define ifr_flags ifr_ifru.ifru_flags /* flags */ 2380Sstevel@tonic-gate #define ifr_metric ifr_ifru.ifru_metric /* metric */ 2390Sstevel@tonic-gate #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate /* FDDI specific */ 242*12016SGirish.Moodalbail@Sun.COM #define ifr_dnld_req ifr_ifru.ifru_dnld_req 243*12016SGirish.Moodalbail@Sun.COM #define ifr_fddi_stat ifr_ifru.ifru_fddi_stat 244*12016SGirish.Moodalbail@Sun.COM #define ifr_fddi_netmap ifr_ifru.ifru_netmapent /* FDDI network map entries */ 245*12016SGirish.Moodalbail@Sun.COM #define ifr_fddi_gstruct ifr_ifru.ifru_fddi_gstruct 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate }; 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* 2500Sstevel@tonic-gate * Structure used in SIOCGIFCONF request. 2510Sstevel@tonic-gate * Used to retrieve interface configuration 2520Sstevel@tonic-gate * for machine (useful for programs which 2530Sstevel@tonic-gate * must know all networks accessible). 2540Sstevel@tonic-gate */ 2550Sstevel@tonic-gate struct ifconf { 2560Sstevel@tonic-gate int ifc_len; /* size of associated buffer */ 2570Sstevel@tonic-gate union { 2580Sstevel@tonic-gate caddr_t ifcu_buf; 2590Sstevel@tonic-gate struct ifreq *ifcu_req; 2600Sstevel@tonic-gate } ifc_ifcu; 2610Sstevel@tonic-gate #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 2620Sstevel@tonic-gate #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 2630Sstevel@tonic-gate }; 2640Sstevel@tonic-gate 265722Smuffin #endif /* !_net_if_h */ 266