in_var.h revision 79821
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 3450477Speter * $FreeBSD: head/sys/netinet/in_var.h 79821 2001-07-17 10:30:21Z ru $ 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 */ 5860938Sjake 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 8355205Speter#ifdef _KERNEL 8460938Sjakeextern 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{ \ 9779821Sru struct in_ifaddr *ia; \ 981541Srgrimes\ 9979821Sru TAILQ_FOREACH(ia, &in_ifaddrhead, ia_link) \ 10079821Sru if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \ 10179821Sru break; \ 1021541Srgrimes (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \ 1031541Srgrimes} 1041541Srgrimes 1051541Srgrimes/* 1061541Srgrimes * Macro for finding the internet address structure (in_ifaddr) corresponding 1071541Srgrimes * to a given interface (ifnet structure). 1081541Srgrimes */ 1091541Srgrimes#define IFP_TO_IA(ifp, ia) \ 1101541Srgrimes /* struct ifnet *ifp; */ \ 1111541Srgrimes /* struct in_ifaddr *ia; */ \ 1121541Srgrimes{ \ 11371998Sphk for ((ia) = TAILQ_FIRST(&in_ifaddrhead); \ 1141541Srgrimes (ia) != NULL && (ia)->ia_ifp != (ifp); \ 11571998Sphk (ia) = TAILQ_NEXT((ia), ia_link)) \ 1161541Srgrimes continue; \ 1171541Srgrimes} 1181541Srgrimes#endif 1191541Srgrimes 1201541Srgrimes/* 1212531Swollman * This information should be part of the ifnet structure but we don't wish 1222531Swollman * to change that - as it might break a number of things 1232531Swollman */ 1242531Swollman 1252531Swollmanstruct router_info { 12614622Sfenner struct ifnet *rti_ifp; 12714622Sfenner int rti_type; /* type of router which is querier on this interface */ 12814622Sfenner int rti_time; /* # of slow timeouts since last old query */ 12914622Sfenner struct router_info *rti_next; 1302531Swollman}; 1312531Swollman 1322531Swollman/* 1331541Srgrimes * Internet multicast address structure. There is one of these for each IP 1341541Srgrimes * multicast group to which this host belongs on a given network interface. 13521666Swollman * For every entry on the interface's if_multiaddrs list which represents 13621666Swollman * an IP multicast group, there is one of these structures. They are also 13721666Swollman * kept on a system-wide list to make it easier to keep our legacy IGMP code 13821666Swollman * compatible with the rest of the world (see IN_FIRST_MULTI et al, below). 1391541Srgrimes */ 1401541Srgrimesstruct in_multi { 14160938Sjake LIST_ENTRY(in_multi) inm_link; /* queue macro glue */ 14221666Swollman struct in_addr inm_addr; /* IP multicast address, convenience */ 1431541Srgrimes struct ifnet *inm_ifp; /* back pointer to ifnet */ 14421666Swollman struct ifmultiaddr *inm_ifma; /* back pointer to ifmultiaddr */ 1451541Srgrimes u_int inm_timer; /* IGMP membership report timer */ 1462531Swollman u_int inm_state; /* state of the membership */ 1472531Swollman struct router_info *inm_rti; /* router info*/ 1481541Srgrimes}; 1491541Srgrimes 15055205Speter#ifdef _KERNEL 15144078Sdfr 15244078Sdfr#ifdef SYSCTL_DECL 15344078SdfrSYSCTL_DECL(_net_inet_ip); 15444078SdfrSYSCTL_DECL(_net_inet_raw); 15544078Sdfr#endif 15644078Sdfr 15760938Sjakeextern LIST_HEAD(in_multihead, in_multi) in_multihead; 15821666Swollman 1591541Srgrimes/* 1601541Srgrimes * Structure used by macros below to remember position when stepping through 1611541Srgrimes * all of the in_multi records. 1621541Srgrimes */ 1631541Srgrimesstruct in_multistep { 1641541Srgrimes struct in_multi *i_inm; 1651541Srgrimes}; 1661541Srgrimes 1671541Srgrimes/* 1681541Srgrimes * Macro for looking up the in_multi record for a given IP multicast address 16921666Swollman * on a given interface. If no matching record is found, "inm" is set null. 1701541Srgrimes */ 1711541Srgrimes#define IN_LOOKUP_MULTI(addr, ifp, inm) \ 1721541Srgrimes /* struct in_addr addr; */ \ 1731541Srgrimes /* struct ifnet *ifp; */ \ 1741541Srgrimes /* struct in_multi *inm; */ \ 17520407Swollmando { \ 17679821Sru struct ifmultiaddr *ifma; \ 1771541Srgrimes\ 17872084Sphk TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) { \ 17921666Swollman if (ifma->ifma_addr->sa_family == AF_INET \ 18021929Swollman && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \ 18121666Swollman (addr).s_addr) \ 18221666Swollman break; \ 18321666Swollman } \ 18421666Swollman (inm) = ifma ? ifma->ifma_protospec : 0; \ 18520407Swollman} while(0) 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; */ \ 19720407Swollmando { \ 1981541Srgrimes if (((inm) = (step).i_inm) != NULL) \ 19971998Sphk (step).i_inm = LIST_NEXT((step).i_inm, inm_link); \ 20020407Swollman} while(0) 2011541Srgrimes 2021541Srgrimes#define IN_FIRST_MULTI(step, inm) \ 2031541Srgrimes /* struct in_multistep step; */ \ 2041541Srgrimes /* struct in_multi *inm; */ \ 20520407Swollmando { \ 20671998Sphk (step).i_inm = LIST_FIRST(&in_multihead); \ 2071541Srgrimes IN_NEXT_MULTI((step), (inm)); \ 20820407Swollman} while(0) 2091541Srgrimes 21036192Sdgstruct route; 2111541Srgrimesstruct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *)); 2121549Srgrimesvoid in_delmulti __P((struct in_multi *)); 21336735Sdfrint in_control __P((struct socket *, u_long, caddr_t, struct ifnet *, 21425201Swollman struct proc *)); 21512933Swollmanvoid in_rtqdrain __P((void)); 21613929Swollmanvoid ip_input __P((struct mbuf *)); 21776469Sruint in_ifadown __P((struct ifaddr *ifa, int)); 21822672Swollmanvoid in_ifscrub __P((struct ifnet *, struct in_ifaddr *)); 21936192Sdgint ipflow_fastforward __P((struct mbuf *)); 22036192Sdgvoid ipflow_create __P((const struct route *, struct mbuf *)); 22136192Sdgvoid ipflow_slowtimo __P((void)); 2222169Spaul 22355205Speter#endif /* _KERNEL */ 22410939Swollman 22552904Sshin/* INET6 stuff */ 22652904Sshin#include <netinet6/in6_var.h> 22752904Sshin 22810939Swollman#endif /* _NETINET_IN_VAR_H_ */ 229