in_var.h revision 92723
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 92723 2002-03-19 21:25:46Z alfred $ 351541Srgrimes */ 361541Srgrimes 372169Spaul#ifndef _NETINET_IN_VAR_H_ 382169Spaul#define _NETINET_IN_VAR_H_ 392169Spaul 407280Swollman#include <sys/queue.h> 4184102Sjlemon#include <sys/fnv_hash.h> 427280Swollman 431541Srgrimes/* 441541Srgrimes * Interface address, Internet version. One of these structures 4521666Swollman * is allocated for each Internet address on an interface. 461541Srgrimes * The ifaddr structure contains the protocol-independent part 471541Srgrimes * of the structure and is assumed to be first. 481541Srgrimes */ 491541Srgrimesstruct in_ifaddr { 501541Srgrimes struct ifaddr ia_ifa; /* protocol-independent info */ 511541Srgrimes#define ia_ifp ia_ifa.ifa_ifp 521541Srgrimes#define ia_flags ia_ifa.ifa_flags 531541Srgrimes /* ia_{,sub}net{,mask} in host order */ 541541Srgrimes u_long ia_net; /* network number of interface */ 551541Srgrimes u_long ia_netmask; /* mask of net part */ 561541Srgrimes u_long ia_subnet; /* subnet number, including net */ 571541Srgrimes u_long ia_subnetmask; /* mask of subnet part */ 581541Srgrimes struct in_addr ia_netbroadcast; /* to recognize net broadcasts */ 5984102Sjlemon LIST_ENTRY(in_ifaddr) ia_hash; /* entry in bucket of inet addresses */ 6084102Sjlemon TAILQ_ENTRY(in_ifaddr) ia_link; /* list of internet addresses */ 611541Srgrimes struct sockaddr_in ia_addr; /* reserve space for interface name */ 621541Srgrimes struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */ 631541Srgrimes#define ia_broadaddr ia_dstaddr 641541Srgrimes struct sockaddr_in ia_sockmask; /* reserve space for general netmask */ 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 8555205Speter#ifdef _KERNEL 861541Srgrimesextern struct ifqueue ipintrq; /* ip packet input queue */ 877090Sbdeextern struct in_addr zeroin_addr; 887090Sbdeextern u_char inetctlerrmap[]; 891541Srgrimes 9084102Sjlemon/* 9184102Sjlemon * Hash table for IP addresses. 9284102Sjlemon */ 9384102Sjlemonextern LIST_HEAD(in_ifaddrhashhead, in_ifaddr) *in_ifaddrhashtbl; 9484102Sjlemonextern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead; 9584102Sjlemonextern u_long in_ifaddrhmask; /* mask for hash table */ 9684102Sjlemon 9784102Sjlemon#define INADDR_NHASH_LOG2 9 9884102Sjlemon#define INADDR_NHASH (1 << INADDR_NHASH_LOG2) 9984102Sjlemon#define INADDR_HASHVAL(x) fnv_32_buf((&(x)), sizeof(x), FNV1_32_INIT) 10084102Sjlemon#define INADDR_HASH(x) \ 10184102Sjlemon (&in_ifaddrhashtbl[INADDR_HASHVAL(x) & in_ifaddrhmask]) 10284102Sjlemon 10384102Sjlemon 1041541Srgrimes/* 1051541Srgrimes * Macro for finding the interface (ifnet structure) corresponding to one 1061541Srgrimes * of our IP addresses. 1071541Srgrimes */ 1081541Srgrimes#define INADDR_TO_IFP(addr, ifp) \ 1091541Srgrimes /* struct in_addr addr; */ \ 1101541Srgrimes /* struct ifnet *ifp; */ \ 1111541Srgrimes{ \ 11279821Sru struct in_ifaddr *ia; \ 1131541Srgrimes\ 11484109Sjlemon LIST_FOREACH(ia, INADDR_HASH((addr).s_addr), ia_hash) \ 11579821Sru if (IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \ 11679821Sru break; \ 1171541Srgrimes (ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \ 1181541Srgrimes} 1191541Srgrimes 1201541Srgrimes/* 1211541Srgrimes * Macro for finding the internet address structure (in_ifaddr) corresponding 1221541Srgrimes * to a given interface (ifnet structure). 1231541Srgrimes */ 1241541Srgrimes#define IFP_TO_IA(ifp, ia) \ 1251541Srgrimes /* struct ifnet *ifp; */ \ 1261541Srgrimes /* struct in_ifaddr *ia; */ \ 1271541Srgrimes{ \ 12871998Sphk for ((ia) = TAILQ_FIRST(&in_ifaddrhead); \ 1291541Srgrimes (ia) != NULL && (ia)->ia_ifp != (ifp); \ 13071998Sphk (ia) = TAILQ_NEXT((ia), ia_link)) \ 1311541Srgrimes continue; \ 1321541Srgrimes} 1331541Srgrimes#endif 1341541Srgrimes 1351541Srgrimes/* 1362531Swollman * This information should be part of the ifnet structure but we don't wish 1372531Swollman * to change that - as it might break a number of things 1382531Swollman */ 1392531Swollman 1402531Swollmanstruct router_info { 14114622Sfenner struct ifnet *rti_ifp; 14214622Sfenner int rti_type; /* type of router which is querier on this interface */ 14314622Sfenner int rti_time; /* # of slow timeouts since last old query */ 14414622Sfenner struct router_info *rti_next; 1452531Swollman}; 1462531Swollman 1472531Swollman/* 1481541Srgrimes * Internet multicast address structure. There is one of these for each IP 1491541Srgrimes * multicast group to which this host belongs on a given network interface. 15021666Swollman * For every entry on the interface's if_multiaddrs list which represents 15121666Swollman * an IP multicast group, there is one of these structures. They are also 15221666Swollman * kept on a system-wide list to make it easier to keep our legacy IGMP code 15321666Swollman * compatible with the rest of the world (see IN_FIRST_MULTI et al, below). 1541541Srgrimes */ 1551541Srgrimesstruct in_multi { 15660938Sjake LIST_ENTRY(in_multi) inm_link; /* queue macro glue */ 15721666Swollman struct in_addr inm_addr; /* IP multicast address, convenience */ 1581541Srgrimes struct ifnet *inm_ifp; /* back pointer to ifnet */ 15921666Swollman struct ifmultiaddr *inm_ifma; /* back pointer to ifmultiaddr */ 1601541Srgrimes u_int inm_timer; /* IGMP membership report timer */ 1612531Swollman u_int inm_state; /* state of the membership */ 1622531Swollman struct router_info *inm_rti; /* router info*/ 1631541Srgrimes}; 1641541Srgrimes 16555205Speter#ifdef _KERNEL 16644078Sdfr 16744078Sdfr#ifdef SYSCTL_DECL 16844078SdfrSYSCTL_DECL(_net_inet_ip); 16944078SdfrSYSCTL_DECL(_net_inet_raw); 17044078Sdfr#endif 17144078Sdfr 17260938Sjakeextern LIST_HEAD(in_multihead, in_multi) in_multihead; 17321666Swollman 1741541Srgrimes/* 1751541Srgrimes * Structure used by macros below to remember position when stepping through 1761541Srgrimes * all of the in_multi records. 1771541Srgrimes */ 1781541Srgrimesstruct in_multistep { 1791541Srgrimes struct in_multi *i_inm; 1801541Srgrimes}; 1811541Srgrimes 1821541Srgrimes/* 1831541Srgrimes * Macro for looking up the in_multi record for a given IP multicast address 18421666Swollman * on a given interface. If no matching record is found, "inm" is set null. 1851541Srgrimes */ 1861541Srgrimes#define IN_LOOKUP_MULTI(addr, ifp, inm) \ 1871541Srgrimes /* struct in_addr addr; */ \ 1881541Srgrimes /* struct ifnet *ifp; */ \ 1891541Srgrimes /* struct in_multi *inm; */ \ 19020407Swollmando { \ 19179821Sru struct ifmultiaddr *ifma; \ 1921541Srgrimes\ 19372084Sphk TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) { \ 19421666Swollman if (ifma->ifma_addr->sa_family == AF_INET \ 19521929Swollman && ((struct sockaddr_in *)ifma->ifma_addr)->sin_addr.s_addr == \ 19621666Swollman (addr).s_addr) \ 19721666Swollman break; \ 19821666Swollman } \ 19921666Swollman (inm) = ifma ? ifma->ifma_protospec : 0; \ 20020407Swollman} while(0) 2011541Srgrimes 2021541Srgrimes/* 2031541Srgrimes * Macro to step through all of the in_multi records, one at a time. 2041541Srgrimes * The current position is remembered in "step", which the caller must 2051541Srgrimes * provide. IN_FIRST_MULTI(), below, must be called to initialize "step" 2061541Srgrimes * and get the first record. Both macros return a NULL "inm" when there 2071541Srgrimes * are no remaining records. 2081541Srgrimes */ 2091541Srgrimes#define IN_NEXT_MULTI(step, inm) \ 2101541Srgrimes /* struct in_multistep step; */ \ 2111541Srgrimes /* struct in_multi *inm; */ \ 21220407Swollmando { \ 2131541Srgrimes if (((inm) = (step).i_inm) != NULL) \ 21471998Sphk (step).i_inm = LIST_NEXT((step).i_inm, inm_link); \ 21520407Swollman} while(0) 2161541Srgrimes 2171541Srgrimes#define IN_FIRST_MULTI(step, inm) \ 2181541Srgrimes /* struct in_multistep step; */ \ 2191541Srgrimes /* struct in_multi *inm; */ \ 22020407Swollmando { \ 22171998Sphk (step).i_inm = LIST_FIRST(&in_multihead); \ 2221541Srgrimes IN_NEXT_MULTI((step), (inm)); \ 22320407Swollman} while(0) 2241541Srgrimes 22536192Sdgstruct route; 22692723Salfredstruct in_multi *in_addmulti(struct in_addr *, struct ifnet *); 22792723Salfredvoid in_delmulti(struct in_multi *); 22892723Salfredint in_control(struct socket *, u_long, caddr_t, struct ifnet *, 22992723Salfred struct thread *); 23092723Salfredvoid in_rtqdrain(void); 23192723Salfredvoid ip_input(struct mbuf *); 23292723Salfredint in_ifadown(struct ifaddr *ifa, int); 23392723Salfredvoid in_ifscrub(struct ifnet *, struct in_ifaddr *); 23492723Salfredint ipflow_fastforward(struct mbuf *); 23592723Salfredvoid ipflow_create(const struct route *, struct mbuf *); 23692723Salfredvoid ipflow_slowtimo(void); 2372169Spaul 23855205Speter#endif /* _KERNEL */ 23910939Swollman 24052904Sshin/* INET6 stuff */ 24152904Sshin#include <netinet6/in6_var.h> 24252904Sshin 24310939Swollman#endif /* _NETINET_IN_VAR_H_ */ 244