17c478bd9Sstevel@tonic-gate /* 2*6e91bba0SGirish Moodalbail * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate /* 77c478bd9Sstevel@tonic-gate * Copyright (c) 1982, 1986 Regents of the University of California. 87c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 97c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 107c478bd9Sstevel@tonic-gate */ 117c478bd9Sstevel@tonic-gate 127c478bd9Sstevel@tonic-gate #ifndef _net_if_h 137c478bd9Sstevel@tonic-gate #define _net_if_h 147c478bd9Sstevel@tonic-gate 157c478bd9Sstevel@tonic-gate /* 167c478bd9Sstevel@tonic-gate * Structures defining a network interface, providing a packet 177c478bd9Sstevel@tonic-gate * transport mechanism (ala level 0 of the PUP protocols). 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * Each interface accepts output datagrams of a specified maximum 207c478bd9Sstevel@tonic-gate * length, and provides higher level routines with input datagrams 217c478bd9Sstevel@tonic-gate * received from its medium. 227c478bd9Sstevel@tonic-gate * 237c478bd9Sstevel@tonic-gate * Output occurs when the routine if_output is called, with three parameters: 247c478bd9Sstevel@tonic-gate * (*ifp->if_output)(ifp, m, dst) 257c478bd9Sstevel@tonic-gate * Here m is the mbuf chain to be sent and dst is the destination address. 267c478bd9Sstevel@tonic-gate * The output routine encapsulates the supplied datagram if necessary, 277c478bd9Sstevel@tonic-gate * and then transmits it on its medium. 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * On input, each interface unwraps the data received by it, and either 307c478bd9Sstevel@tonic-gate * places it on the input queue of a internetwork datagram routine 317c478bd9Sstevel@tonic-gate * and posts the associated software interrupt, or passes the datagram to a raw 327c478bd9Sstevel@tonic-gate * packet input routine. 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * Routines exist for locating interfaces by their addresses 357c478bd9Sstevel@tonic-gate * or for locating a interface on a certain network, as well as more general 367c478bd9Sstevel@tonic-gate * routing and gateway routines maintaining information used to locate 377c478bd9Sstevel@tonic-gate * interfaces. These routines live in the files if.c and route.c 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * Structure defining a queue for a network interface. 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * (Would like to call this struct ``if'', but C isn't PL/1.) 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate struct ifnet { 467c478bd9Sstevel@tonic-gate char *if_name; /* name, e.g. ``en'' or ``lo'' */ 477c478bd9Sstevel@tonic-gate short if_unit; /* sub-unit for lower level driver */ 487c478bd9Sstevel@tonic-gate short if_mtu; /* maximum transmission unit */ 497c478bd9Sstevel@tonic-gate short if_flags; /* up/down, broadcast, etc. */ 507c478bd9Sstevel@tonic-gate short if_timer; /* time 'til if_watchdog called */ 517c478bd9Sstevel@tonic-gate u_short if_promisc; /* net # of requests for promisc mode */ 527c478bd9Sstevel@tonic-gate int if_metric; /* routing metric (external only) */ 537c478bd9Sstevel@tonic-gate struct ifaddr *if_addrlist; /* linked list of addresses per if */ 547c478bd9Sstevel@tonic-gate struct ifqueue { 557c478bd9Sstevel@tonic-gate struct mbuf *ifq_head; 567c478bd9Sstevel@tonic-gate struct mbuf *ifq_tail; 577c478bd9Sstevel@tonic-gate int ifq_len; 587c478bd9Sstevel@tonic-gate int ifq_maxlen; 597c478bd9Sstevel@tonic-gate int ifq_drops; 607c478bd9Sstevel@tonic-gate } if_snd; /* output queue */ 617c478bd9Sstevel@tonic-gate /* procedure handles */ 627c478bd9Sstevel@tonic-gate int (*if_init)(); /* init routine */ 637c478bd9Sstevel@tonic-gate int (*if_output)(); /* output routine */ 647c478bd9Sstevel@tonic-gate int (*if_ioctl)(); /* ioctl routine */ 657c478bd9Sstevel@tonic-gate int (*if_reset)(); /* bus reset routine */ 667c478bd9Sstevel@tonic-gate int (*if_watchdog)(); /* timer routine */ 677c478bd9Sstevel@tonic-gate /* generic interface statistics */ 687c478bd9Sstevel@tonic-gate int if_ipackets; /* packets received on interface */ 697c478bd9Sstevel@tonic-gate int if_ierrors; /* input errors on interface */ 707c478bd9Sstevel@tonic-gate int if_opackets; /* packets sent on interface */ 717c478bd9Sstevel@tonic-gate int if_oerrors; /* output errors on interface */ 727c478bd9Sstevel@tonic-gate int if_collisions; /* collisions on csma interfaces */ 737c478bd9Sstevel@tonic-gate /* end statistics */ 747c478bd9Sstevel@tonic-gate struct ifnet *if_next; 757c478bd9Sstevel@tonic-gate struct ifnet *if_upper; /* next layer up */ 767c478bd9Sstevel@tonic-gate struct ifnet *if_lower; /* next layer down */ 777c478bd9Sstevel@tonic-gate int (*if_input)(); /* input routine */ 787c478bd9Sstevel@tonic-gate int (*if_ctlin)(); /* control input routine */ 797c478bd9Sstevel@tonic-gate int (*if_ctlout)(); /* control output routine */ 807c478bd9Sstevel@tonic-gate #ifdef sun 817c478bd9Sstevel@tonic-gate struct map *if_memmap; /* rmap for interface specific memory */ 827c478bd9Sstevel@tonic-gate #endif 837c478bd9Sstevel@tonic-gate }; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #define IFF_UP 0x1 /* interface is up */ 867c478bd9Sstevel@tonic-gate #define IFF_BROADCAST 0x2 /* broadcast address valid */ 877c478bd9Sstevel@tonic-gate #define IFF_DEBUG 0x4 /* turn on debugging */ 887c478bd9Sstevel@tonic-gate #define IFF_LOOPBACK 0x8 /* is a loopback net */ 897c478bd9Sstevel@tonic-gate #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 907c478bd9Sstevel@tonic-gate #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 917c478bd9Sstevel@tonic-gate #define IFF_RUNNING 0x40 /* resources allocated */ 927c478bd9Sstevel@tonic-gate #define IFF_NOARP 0x80 /* no address resolution protocol */ 937c478bd9Sstevel@tonic-gate #define IFF_PROMISC 0x100 /* receive all packets */ 947c478bd9Sstevel@tonic-gate #define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 957c478bd9Sstevel@tonic-gate #define IFF_PRIVATE 0x8000 /* do not advertise */ 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* flags set internally only: */ 987c478bd9Sstevel@tonic-gate #define IFF_CANTCHANGE \ 997c478bd9Sstevel@tonic-gate (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING | IFF_PROMISC) 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 1027c478bd9Sstevel@tonic-gate * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 1037c478bd9Sstevel@tonic-gate * input routines have queues of messages stored on ifqueue structures 1047c478bd9Sstevel@tonic-gate * (defined above). Entries are added to and deleted from these structures 1057c478bd9Sstevel@tonic-gate * by these macros, which should be called with ipl raised to splimp(). 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 1087c478bd9Sstevel@tonic-gate #define IF_DROP(ifq) ((ifq)->ifq_drops++) 1097c478bd9Sstevel@tonic-gate #define IF_ENQUEUE(ifq, m) { \ 1107c478bd9Sstevel@tonic-gate (m)->m_act = 0; \ 1117c478bd9Sstevel@tonic-gate if ((ifq)->ifq_tail == 0) \ 1127c478bd9Sstevel@tonic-gate (ifq)->ifq_head = m; \ 1137c478bd9Sstevel@tonic-gate else \ 1147c478bd9Sstevel@tonic-gate (ifq)->ifq_tail->m_act = m; \ 1157c478bd9Sstevel@tonic-gate (ifq)->ifq_tail = m; \ 1167c478bd9Sstevel@tonic-gate (ifq)->ifq_len++; \ 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate #define IF_PREPEND(ifq, m) { \ 1197c478bd9Sstevel@tonic-gate (m)->m_act = (ifq)->ifq_head; \ 1207c478bd9Sstevel@tonic-gate if ((ifq)->ifq_tail == 0) \ 1217c478bd9Sstevel@tonic-gate (ifq)->ifq_tail = (m); \ 1227c478bd9Sstevel@tonic-gate (ifq)->ifq_head = (m); \ 1237c478bd9Sstevel@tonic-gate (ifq)->ifq_len++; \ 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate /* 1267c478bd9Sstevel@tonic-gate * Packets destined for level-1 protocol input routines 1277c478bd9Sstevel@tonic-gate * have a pointer to the receiving interface prepended to the data. 1287c478bd9Sstevel@tonic-gate * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet. 1297c478bd9Sstevel@tonic-gate * IF_ADJ should be used otherwise to adjust for its presence. 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate #define IF_ADJ(m) { \ 1327c478bd9Sstevel@tonic-gate (m)->m_off += sizeof (struct ifnet *); \ 1337c478bd9Sstevel@tonic-gate (m)->m_len -= sizeof (struct ifnet *); \ 1347c478bd9Sstevel@tonic-gate if ((m)->m_len == 0) { \ 1357c478bd9Sstevel@tonic-gate struct mbuf *n; \ 1367c478bd9Sstevel@tonic-gate MFREE((m), n); \ 1377c478bd9Sstevel@tonic-gate (m) = n; \ 1387c478bd9Sstevel@tonic-gate } \ 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate #define IF_DEQUEUEIF(ifq, m, ifp) { \ 1417c478bd9Sstevel@tonic-gate (m) = (ifq)->ifq_head; \ 1427c478bd9Sstevel@tonic-gate if (m) { \ 1437c478bd9Sstevel@tonic-gate if (((ifq)->ifq_head = (m)->m_act) == 0) \ 1447c478bd9Sstevel@tonic-gate (ifq)->ifq_tail = 0; \ 1457c478bd9Sstevel@tonic-gate (m)->m_act = 0; \ 1467c478bd9Sstevel@tonic-gate (ifq)->ifq_len--; \ 1477c478bd9Sstevel@tonic-gate (ifp) = *(mtod((m), struct ifnet **)); \ 1487c478bd9Sstevel@tonic-gate IF_ADJ(m); \ 1497c478bd9Sstevel@tonic-gate } \ 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate #define IF_DEQUEUE(ifq, m) { \ 1527c478bd9Sstevel@tonic-gate (m) = (ifq)->ifq_head; \ 1537c478bd9Sstevel@tonic-gate if (m) { \ 1547c478bd9Sstevel@tonic-gate if (((ifq)->ifq_head = (m)->m_act) == 0) \ 1557c478bd9Sstevel@tonic-gate (ifq)->ifq_tail = 0; \ 1567c478bd9Sstevel@tonic-gate (m)->m_act = 0; \ 1577c478bd9Sstevel@tonic-gate (ifq)->ifq_len--; \ 1587c478bd9Sstevel@tonic-gate } \ 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate #define IFQ_MAXLEN 50 1627c478bd9Sstevel@tonic-gate #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * The ifaddr structure contains information about one address 1667c478bd9Sstevel@tonic-gate * of an interface. They are maintained by the different address families, 1677c478bd9Sstevel@tonic-gate * are allocated and attached when an address is set, and are linked 1687c478bd9Sstevel@tonic-gate * together so all addresses for an interface can be located. 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate struct ifaddr { 1717c478bd9Sstevel@tonic-gate struct sockaddr ifa_addr; /* address of interface */ 1727c478bd9Sstevel@tonic-gate union { 1737c478bd9Sstevel@tonic-gate struct sockaddr ifu_broadaddr; 1747c478bd9Sstevel@tonic-gate struct sockaddr ifu_dstaddr; 1757c478bd9Sstevel@tonic-gate } ifa_ifu; 176*6e91bba0SGirish Moodalbail #ifndef ifa_broadaddr 1777c478bd9Sstevel@tonic-gate #define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */ 178*6e91bba0SGirish Moodalbail #endif 179*6e91bba0SGirish Moodalbail #ifndef ifa_dstaddr 1807c478bd9Sstevel@tonic-gate #define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of p-to-p link */ 181*6e91bba0SGirish Moodalbail #endif 1827c478bd9Sstevel@tonic-gate struct ifnet *ifa_ifp; /* back-pointer to interface */ 1837c478bd9Sstevel@tonic-gate struct ifaddr *ifa_next; /* next address for interface */ 1847c478bd9Sstevel@tonic-gate }; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate /* 1877c478bd9Sstevel@tonic-gate * Interface request structure used for socket 1887c478bd9Sstevel@tonic-gate * ioctl's. All interface ioctl's must have parameter 1897c478bd9Sstevel@tonic-gate * definitions which begin with ifr_name. The 1907c478bd9Sstevel@tonic-gate * remainder may be interface specific. 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate struct ifreq { 1937c478bd9Sstevel@tonic-gate #define IFNAMSIZ 16 1947c478bd9Sstevel@tonic-gate char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 1957c478bd9Sstevel@tonic-gate union { 1967c478bd9Sstevel@tonic-gate struct sockaddr ifru_addr; 1977c478bd9Sstevel@tonic-gate struct sockaddr ifru_dstaddr; 1987c478bd9Sstevel@tonic-gate char ifru_oname[IFNAMSIZ]; /* other if name */ 1997c478bd9Sstevel@tonic-gate struct sockaddr ifru_broadaddr; 2007c478bd9Sstevel@tonic-gate short ifru_flags; 2017c478bd9Sstevel@tonic-gate int ifru_metric; 2027c478bd9Sstevel@tonic-gate char ifru_data[1]; /* interface dependent data */ 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* Struct for FDDI ioctl's */ 2057c478bd9Sstevel@tonic-gate struct ifr_dnld_reqs { 2067c478bd9Sstevel@tonic-gate caddr_t v_addr; 2077c478bd9Sstevel@tonic-gate caddr_t m_addr; 2087c478bd9Sstevel@tonic-gate caddr_t ex_addr; 2097c478bd9Sstevel@tonic-gate u_int size; 2107c478bd9Sstevel@tonic-gate } ifru_dnld_req; 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* Struct for FDDI stats */ 2137c478bd9Sstevel@tonic-gate struct ifr_fddi_stats { 2147c478bd9Sstevel@tonic-gate u_int stat_size; 2157c478bd9Sstevel@tonic-gate caddr_t fddi_stats; 2167c478bd9Sstevel@tonic-gate } ifru_fddi_stat; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate struct ifr_netmapents { 2197c478bd9Sstevel@tonic-gate u_int map_ent_size, /* size of netmap structure */ 2207c478bd9Sstevel@tonic-gate entry_number; /* index into netmap list */ 2217c478bd9Sstevel@tonic-gate caddr_t fddi_map_ent; /* pointer to user structure */ 2227c478bd9Sstevel@tonic-gate } ifru_netmapent; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* Field for generic ioctl for fddi */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate struct ifr_fddi_gen_struct { 2277c478bd9Sstevel@tonic-gate int ifru_fddi_gioctl; /* field for gen ioctl */ 2287c478bd9Sstevel@tonic-gate caddr_t ifru_fddi_gaddr; /* Generic ptr to a field */ 2297c478bd9Sstevel@tonic-gate } ifru_fddi_gstruct; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate } ifr_ifru; 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate #define ifr_addr ifr_ifru.ifru_addr /* address */ 2347c478bd9Sstevel@tonic-gate #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 2357c478bd9Sstevel@tonic-gate #define ifr_oname ifr_ifru.ifru_oname /* other if name */ 2367c478bd9Sstevel@tonic-gate #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 2377c478bd9Sstevel@tonic-gate #define ifr_flags ifr_ifru.ifru_flags /* flags */ 2387c478bd9Sstevel@tonic-gate #define ifr_metric ifr_ifru.ifru_metric /* metric */ 2397c478bd9Sstevel@tonic-gate #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* FDDI specific */ 2427c478bd9Sstevel@tonic-gate #define ifr_dnld_req ifr_ifru.ifru_dnld_req 2437c478bd9Sstevel@tonic-gate #define ifr_fddi_stat ifr_ifru.ifru_fddi_stat 2447c478bd9Sstevel@tonic-gate #define ifr_fddi_netmap ifr_ifru.ifru_netmapent /* FDDI network map entries */ 2457c478bd9Sstevel@tonic-gate #define ifr_fddi_gstruct ifr_ifru.ifru_fddi_gstruct 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate }; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * Structure used in SIOCGIFCONF request. 2517c478bd9Sstevel@tonic-gate * Used to retrieve interface configuration 2527c478bd9Sstevel@tonic-gate * for machine (useful for programs which 2537c478bd9Sstevel@tonic-gate * must know all networks accessible). 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate struct ifconf { 2567c478bd9Sstevel@tonic-gate int ifc_len; /* size of associated buffer */ 2577c478bd9Sstevel@tonic-gate union { 2587c478bd9Sstevel@tonic-gate caddr_t ifcu_buf; 2597c478bd9Sstevel@tonic-gate struct ifreq *ifcu_req; 2607c478bd9Sstevel@tonic-gate } ifc_ifcu; 2617c478bd9Sstevel@tonic-gate #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 2627c478bd9Sstevel@tonic-gate #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 2637c478bd9Sstevel@tonic-gate }; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate #endif /* !_net_if_h */ 266