in_var.h revision 44078
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 3444078Sdfr * $Id: in_var.h,v 1.29 1998/06/07 17:12:14 dfr 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 4421666Swollman * is allocated for each Internet address on an interface. 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 */ 5820407Swollman TAILQ_ENTRY(in_ifaddr) ia_link; /* tailq macro glue */ 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 */ 631541Srgrimes}; 641541Srgrimes 651541Srgrimesstruct in_aliasreq { 661541Srgrimes char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 671541Srgrimes struct sockaddr_in ifra_addr; 681541Srgrimes struct sockaddr_in ifra_broadaddr; 691541Srgrimes#define ifra_dstaddr ifra_broadaddr 701541Srgrimes struct sockaddr_in ifra_mask; 711541Srgrimes}; 721541Srgrimes/* 731541Srgrimes * Given a pointer to an in_ifaddr (ifaddr), 741541Srgrimes * return a pointer to the addr as a sockaddr_in. 751541Srgrimes */ 763865Sswallace#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr)) 773865Sswallace#define IA_DSTSIN(ia) (&(((struct in_ifaddr *)(ia))->ia_dstaddr)) 781541Srgrimes 791541Srgrimes#define IN_LNAOF(in, ifa) \ 801541Srgrimes ((ntohl((in).s_addr) & ~((struct in_ifaddr *)(ifa)->ia_subnetmask)) 811541Srgrimes 828876Srgrimes 831541Srgrimes#ifdef KERNEL 8420407Swollmanextern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead; 851541Srgrimesextern struct ifqueue ipintrq; /* ip packet input queue */ 867090Sbdeextern struct in_addr zeroin_addr; 877090Sbdeextern u_char inetctlerrmap[]; 881541Srgrimes 891541Srgrimes/* 901541Srgrimes * Macro for finding the interface (ifnet structure) corresponding to one 911541Srgrimes * of our IP addresses. 921541Srgrimes */ 931541Srgrimes#define INADDR_TO_IFP(addr, ifp) \ 941541Srgrimes /* struct in_addr addr; */ \ 951541Srgrimes /* struct ifnet *ifp; */ \ 961541Srgrimes{ \ 971541Srgrimes register struct in_ifaddr *ia; \ 981541Srgrimes\ 9920407Swollman for (ia = in_ifaddrhead.tqh_first; \ 1003865Sswallace ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \ 1013865Sswallace IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \ 10220407Swollman ia = ia->ia_link.tqe_next) \ 1031541Srgrimes continue; \ 10413200Swollman if (ia == NULL) \ 10520407Swollman for (ia = in_ifaddrhead.tqh_first; \ 10613200Swollman ia != NULL; \ 10720407Swollman ia = ia->ia_link.tqe_next) \ 10813200Swollman if (ia->ia_ifp->if_flags & IFF_POINTOPOINT && \ 10913357Sdg IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \ 11013200Swollman break; \ 1111541Srgrimes (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \ 1121541Srgrimes} 1131541Srgrimes 1141541Srgrimes/* 1151541Srgrimes * Macro for finding the internet address structure (in_ifaddr) corresponding 1161541Srgrimes * to a given interface (ifnet structure). 1171541Srgrimes */ 1181541Srgrimes#define IFP_TO_IA(ifp, ia) \ 1191541Srgrimes /* struct ifnet *ifp; */ \ 1201541Srgrimes /* struct in_ifaddr *ia; */ \ 1211541Srgrimes{ \ 12220407Swollman for ((ia) = in_ifaddrhead.tqh_first; \ 1231541Srgrimes (ia) != NULL && (ia)->ia_ifp != (ifp); \ 12420407Swollman (ia) = (ia)->ia_link.tqe_next) \ 1251541Srgrimes continue; \ 1261541Srgrimes} 1271541Srgrimes#endif 1281541Srgrimes 1291541Srgrimes/* 1302531Swollman * This information should be part of the ifnet structure but we don't wish 1312531Swollman * to change that - as it might break a number of things 1322531Swollman */ 1332531Swollman 1342531Swollmanstruct router_info { 13514622Sfenner struct ifnet *rti_ifp; 13614622Sfenner int rti_type; /* type of router which is querier on this interface */ 13714622Sfenner int rti_time; /* # of slow timeouts since last old query */ 13814622Sfenner struct router_info *rti_next; 1392531Swollman}; 1402531Swollman 1412531Swollman/* 1421541Srgrimes * Internet multicast address structure. There is one of these for each IP 1431541Srgrimes * multicast group to which this host belongs on a given network interface. 14421666Swollman * For every entry on the interface's if_multiaddrs list which represents 14521666Swollman * an IP multicast group, there is one of these structures. They are also 14621666Swollman * kept on a system-wide list to make it easier to keep our legacy IGMP code 14721666Swollman * compatible with the rest of the world (see IN_FIRST_MULTI et al, below). 1481541Srgrimes */ 1491541Srgrimesstruct in_multi { 15021666Swollman LIST_ENTRY(in_multi) inm_link; /* queue macro glue */ 15121666Swollman struct in_addr inm_addr; /* IP multicast address, convenience */ 1521541Srgrimes struct ifnet *inm_ifp; /* back pointer to ifnet */ 15321666Swollman struct ifmultiaddr *inm_ifma; /* back pointer to ifmultiaddr */ 1541541Srgrimes u_int inm_timer; /* IGMP membership report timer */ 1552531Swollman u_int inm_state; /* state of the membership */ 1562531Swollman struct router_info *inm_rti; /* router info*/ 1571541Srgrimes}; 1581541Srgrimes 1591541Srgrimes#ifdef KERNEL 16044078Sdfr 16144078Sdfr#ifdef SYSCTL_DECL 16244078SdfrSYSCTL_DECL(_net_inet_ip); 16344078SdfrSYSCTL_DECL(_net_inet_raw); 16444078Sdfr#endif 16544078Sdfr 16621666Swollmanextern LIST_HEAD(in_multihead, in_multi) in_multihead; 16721666Swollman 1681541Srgrimes/* 1691541Srgrimes * Structure used by macros below to remember position when stepping through 1701541Srgrimes * all of the in_multi records. 1711541Srgrimes */ 1721541Srgrimesstruct in_multistep { 1731541Srgrimes struct in_multi *i_inm; 1741541Srgrimes}; 1751541Srgrimes 1761541Srgrimes/* 1771541Srgrimes * Macro for looking up the in_multi record for a given IP multicast address 17821666Swollman * on a given interface. If no matching record is found, "inm" is set null. 1791541Srgrimes */ 1801541Srgrimes#define IN_LOOKUP_MULTI(addr, ifp, inm) \ 1811541Srgrimes /* struct in_addr addr; */ \ 1821541Srgrimes /* struct ifnet *ifp; */ \ 1831541Srgrimes /* struct in_multi *inm; */ \ 18420407Swollmando { \ 18521666Swollman register struct ifmultiaddr *ifma; \ 1861541Srgrimes\ 18721666Swollman for (ifma = (ifp)->if_multiaddrs.lh_first; ifma; \ 18821666Swollman ifma = ifma->ifma_link.le_next) { \ 18921666Swollman if (ifma->ifma_addr->sa_family == AF_INET \ 19021929Swollman && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \ 19121666Swollman (addr).s_addr) \ 19221666Swollman break; \ 19321666Swollman } \ 19421666Swollman (inm) = ifma ? ifma->ifma_protospec : 0; \ 19520407Swollman} while(0) 1961541Srgrimes 1971541Srgrimes/* 1981541Srgrimes * Macro to step through all of the in_multi records, one at a time. 1991541Srgrimes * The current position is remembered in "step", which the caller must 2001541Srgrimes * provide. IN_FIRST_MULTI(), below, must be called to initialize "step" 2011541Srgrimes * and get the first record. Both macros return a NULL "inm" when there 2021541Srgrimes * are no remaining records. 2031541Srgrimes */ 2041541Srgrimes#define IN_NEXT_MULTI(step, inm) \ 2051541Srgrimes /* struct in_multistep step; */ \ 2061541Srgrimes /* struct in_multi *inm; */ \ 20720407Swollmando { \ 2081541Srgrimes if (((inm) = (step).i_inm) != NULL) \ 20921666Swollman (step).i_inm = (step).i_inm->inm_link.le_next; \ 21020407Swollman} while(0) 2111541Srgrimes 2121541Srgrimes#define IN_FIRST_MULTI(step, inm) \ 2131541Srgrimes /* struct in_multistep step; */ \ 2141541Srgrimes /* struct in_multi *inm; */ \ 21520407Swollmando { \ 21621666Swollman (step).i_inm = in_multihead.lh_first; \ 2171541Srgrimes IN_NEXT_MULTI((step), (inm)); \ 21820407Swollman} while(0) 2191541Srgrimes 22036192Sdgstruct route; 2211541Srgrimesstruct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *)); 2221549Srgrimesvoid in_delmulti __P((struct in_multi *)); 22336735Sdfrint in_control __P((struct socket *, u_long, caddr_t, struct ifnet *, 22425201Swollman struct proc *)); 22512933Swollmanvoid in_rtqdrain __P((void)); 22613929Swollmanvoid ip_input __P((struct mbuf *)); 22722672Swollmanint in_ifadown __P((struct ifaddr *ifa)); 22822672Swollmanvoid in_ifscrub __P((struct ifnet *, struct in_ifaddr *)); 22936192Sdgint ipflow_fastforward __P((struct mbuf *)); 23036192Sdgvoid ipflow_create __P((const struct route *, struct mbuf *)); 23136192Sdgvoid ipflow_slowtimo __P((void)); 2322169Spaul 23310939Swollman#endif /* KERNEL */ 23410939Swollman 23510939Swollman#endif /* _NETINET_IN_VAR_H_ */ 236