in_var.h revision 10939
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1985, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 3310939Swollman * @(#)in_var.h 8.2 (Berkeley) 1/9/95 3410939Swollman * $Id: in_var.h,v 1.10 1995/05/30 08:09:32 rgrimes Exp $ 351541Srgrimes */ 361541Srgrimes 372169Spaul#ifndef _NETINET_IN_VAR_H_ 382169Spaul#define _NETINET_IN_VAR_H_ 392169Spaul 407280Swollman#include <sys/queue.h> 417280Swollman 421541Srgrimes/* 431541Srgrimes * Interface address, Internet version. One of these structures 441541Srgrimes * is allocated for each interface with an Internet address. 451541Srgrimes * The ifaddr structure contains the protocol-independent part 461541Srgrimes * of the structure and is assumed to be first. 471541Srgrimes */ 481541Srgrimesstruct in_ifaddr { 491541Srgrimes struct ifaddr ia_ifa; /* protocol-independent info */ 501541Srgrimes#define ia_ifp ia_ifa.ifa_ifp 511541Srgrimes#define ia_flags ia_ifa.ifa_flags 521541Srgrimes /* ia_{,sub}net{,mask} in host order */ 531541Srgrimes u_long ia_net; /* network number of interface */ 541541Srgrimes u_long ia_netmask; /* mask of net part */ 551541Srgrimes u_long ia_subnet; /* subnet number, including net */ 561541Srgrimes u_long ia_subnetmask; /* mask of subnet part */ 571541Srgrimes struct in_addr ia_netbroadcast; /* to recognize net broadcasts */ 581541Srgrimes struct in_ifaddr *ia_next; /* next in list of internet addresses */ 591541Srgrimes struct sockaddr_in ia_addr; /* reserve space for interface name */ 601541Srgrimes struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */ 611541Srgrimes#define ia_broadaddr ia_dstaddr 621541Srgrimes struct sockaddr_in ia_sockmask; /* reserve space for general netmask */ 638876Srgrimes LIST_HEAD(in_multihead, in_multi) ia_multiaddrs; 647280Swollman /* list of multicast addresses */ 651541Srgrimes}; 661541Srgrimes 671541Srgrimesstruct in_aliasreq { 681541Srgrimes char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 691541Srgrimes struct sockaddr_in ifra_addr; 701541Srgrimes struct sockaddr_in ifra_broadaddr; 711541Srgrimes#define ifra_dstaddr ifra_broadaddr 721541Srgrimes struct sockaddr_in ifra_mask; 731541Srgrimes}; 741541Srgrimes/* 751541Srgrimes * Given a pointer to an in_ifaddr (ifaddr), 761541Srgrimes * return a pointer to the addr as a sockaddr_in. 771541Srgrimes */ 783865Sswallace#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr)) 793865Sswallace#define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr)) 801541Srgrimes 811541Srgrimes#define IN_LNAOF(in, ifa) \ 821541Srgrimes ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask)) 831541Srgrimes 848876Srgrimes 851541Srgrimes#ifdef KERNEL 861541Srgrimesextern struct in_ifaddr *in_ifaddr; 871541Srgrimesextern struct ifqueue ipintrq; /* ip packet input queue */ 887090Sbdeextern struct in_addr zeroin_addr; 897090Sbdeextern u_char inetctlerrmap[]; 907090Sbdeextern int rtq_reallyold; /* XXX */ 917090Sbdeextern int rtq_minreallyold; /* XXX */ 927090Sbdeextern int rtq_toomany; /* XXX */ 931541Srgrimes 941541Srgrimes/* 951541Srgrimes * Macro for finding the interface (ifnet structure) corresponding to one 961541Srgrimes * of our IP addresses. 971541Srgrimes */ 981541Srgrimes#define INADDR_TO_IFP(addr, ifp) \ 991541Srgrimes /* struct in_addr addr; */ \ 1001541Srgrimes /* struct ifnet *ifp; */ \ 1011541Srgrimes{ \ 1021541Srgrimes register struct in_ifaddr *ia; \ 1031541Srgrimes\ 1041541Srgrimes for (ia = in_ifaddr; \ 1053865Sswallace ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \ 1063865Sswallace IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \ 1071541Srgrimes ia = ia->ia_next) \ 1081541Srgrimes continue; \ 1091541Srgrimes (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \ 1101541Srgrimes} 1111541Srgrimes 1121541Srgrimes/* 1131541Srgrimes * Macro for finding the internet address structure (in_ifaddr) corresponding 1141541Srgrimes * to a given interface (ifnet structure). 1151541Srgrimes */ 1161541Srgrimes#define IFP_TO_IA(ifp, ia) \ 1171541Srgrimes /* struct ifnet *ifp; */ \ 1181541Srgrimes /* struct in_ifaddr *ia; */ \ 1191541Srgrimes{ \ 1201541Srgrimes for ((ia) = in_ifaddr; \ 1211541Srgrimes (ia) != NULL && (ia)->ia_ifp != (ifp); \ 1221541Srgrimes (ia) = (ia)->ia_next) \ 1231541Srgrimes continue; \ 1241541Srgrimes} 1251541Srgrimes#endif 1261541Srgrimes 1271541Srgrimes/* 1282531Swollman * This information should be part of the ifnet structure but we don't wish 1292531Swollman * to change that - as it might break a number of things 1302531Swollman */ 1312531Swollman 1322531Swollmanstruct router_info { 1332531Swollman struct ifnet *ifp; 1342531Swollman int type; /* type of router which is querier on this interface */ 1352531Swollman int time; /* # of slow timeouts since last old query */ 1362531Swollman struct router_info *next; 1372531Swollman}; 1382531Swollman 1392531Swollman/* 1401541Srgrimes * Internet multicast address structure. There is one of these for each IP 1411541Srgrimes * multicast group to which this host belongs on a given network interface. 1421541Srgrimes * They are kept in a linked list, rooted in the interface's in_ifaddr 1431541Srgrimes * structure. 1441541Srgrimes */ 1451541Srgrimesstruct in_multi { 1467280Swollman LIST_ENTRY(in_multi) inm_entry; /* list glue */ 1471541Srgrimes struct in_addr inm_addr; /* IP multicast address */ 1481541Srgrimes struct ifnet *inm_ifp; /* back pointer to ifnet */ 1491541Srgrimes struct in_ifaddr *inm_ia; /* back pointer to in_ifaddr */ 1501541Srgrimes u_int inm_refcount; /* no. membership claims by sockets */ 1511541Srgrimes u_int inm_timer; /* IGMP membership report timer */ 1522531Swollman u_int inm_state; /* state of the membership */ 1532531Swollman struct router_info *inm_rti; /* router info*/ 1541541Srgrimes}; 1551541Srgrimes 1561541Srgrimes#ifdef KERNEL 1571541Srgrimes/* 1581541Srgrimes * Structure used by macros below to remember position when stepping through 1591541Srgrimes * all of the in_multi records. 1601541Srgrimes */ 1611541Srgrimesstruct in_multistep { 1621541Srgrimes struct in_ifaddr *i_ia; 1631541Srgrimes struct in_multi *i_inm; 1641541Srgrimes}; 1651541Srgrimes 1661541Srgrimes/* 1671541Srgrimes * Macro for looking up the in_multi record for a given IP multicast address 1681541Srgrimes * on a given interface. If no matching record is found, "inm" returns NULL. 1691541Srgrimes */ 1701541Srgrimes#define IN_LOOKUP_MULTI(addr, ifp, inm) \ 1711541Srgrimes /* struct in_addr addr; */ \ 1721541Srgrimes /* struct ifnet *ifp; */ \ 1731541Srgrimes /* struct in_multi *inm; */ \ 1741541Srgrimes{ \ 1751541Srgrimes register struct in_ifaddr *ia; \ 1761541Srgrimes\ 1771541Srgrimes IFP_TO_IA((ifp), ia); \ 1781541Srgrimes if (ia == NULL) \ 1791541Srgrimes (inm) = NULL; \ 1801541Srgrimes else \ 1817280Swollman for ((inm) = ia->ia_multiaddrs.lh_first; \ 1821541Srgrimes (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr; \ 1837280Swollman (inm) = inm->inm_entry.le_next) \ 1841541Srgrimes continue; \ 1851541Srgrimes} 1861541Srgrimes 1871541Srgrimes/* 1881541Srgrimes * Macro to step through all of the in_multi records, one at a time. 1891541Srgrimes * The current position is remembered in "step", which the caller must 1901541Srgrimes * provide. IN_FIRST_MULTI(), below, must be called to initialize "step" 1911541Srgrimes * and get the first record. Both macros return a NULL "inm" when there 1921541Srgrimes * are no remaining records. 1931541Srgrimes */ 1941541Srgrimes#define IN_NEXT_MULTI(step, inm) \ 1951541Srgrimes /* struct in_multistep step; */ \ 1961541Srgrimes /* struct in_multi *inm; */ \ 1971541Srgrimes{ \ 1981541Srgrimes if (((inm) = (step).i_inm) != NULL) \ 1997280Swollman (step).i_inm = (inm)->inm_entry.le_next; \ 2001541Srgrimes else \ 2011541Srgrimes while ((step).i_ia != NULL) { \ 2027280Swollman (inm) = (step).i_ia->ia_multiaddrs.lh_first; \ 2031541Srgrimes (step).i_ia = (step).i_ia->ia_next; \ 2041541Srgrimes if ((inm) != NULL) { \ 2057280Swollman (step).i_inm = (inm)->inm_entry.le_next; \ 2061541Srgrimes break; \ 2071541Srgrimes } \ 2081541Srgrimes } \ 2091541Srgrimes} 2101541Srgrimes 2111541Srgrimes#define IN_FIRST_MULTI(step, inm) \ 2121541Srgrimes /* struct in_multistep step; */ \ 2131541Srgrimes /* struct in_multi *inm; */ \ 2141541Srgrimes{ \ 2151541Srgrimes (step).i_ia = in_ifaddr; \ 2161541Srgrimes (step).i_inm = NULL; \ 2171541Srgrimes IN_NEXT_MULTI((step), (inm)); \ 2181541Srgrimes} 2191541Srgrimes 2201541Srgrimesint in_ifinit __P((struct ifnet *, 2211541Srgrimes struct in_ifaddr *, struct sockaddr_in *, int)); 2221541Srgrimesstruct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *)); 2231549Srgrimesvoid in_delmulti __P((struct in_multi *)); 2241541Srgrimesvoid in_ifscrub __P((struct ifnet *, struct in_ifaddr *)); 22510939Swollmanint in_control __P((struct socket *, u_long, caddr_t, struct ifnet *)); 2262169Spaul 22710939Swollman#endif /* KERNEL */ 22810939Swollman 22910939Swollman#endif /* _NETINET_IN_VAR_H_ */ 230