1999-07-01 12:12:45 +04:00
|
|
|
/* $NetBSD: in_var.h,v 1.35 1999/07/01 08:12:50 itojun Exp $ */
|
1998-12-19 05:46:12 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Public Access Networks Corporation ("Panix"). It was developed under
|
|
|
|
* contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-05-13 10:02:48 +04:00
|
|
|
* Copyright (c) 1985, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-01-05 13:31:44 +03:00
|
|
|
* @(#)in_var.h 8.2 (Berkeley) 1/9/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1998-02-10 04:26:19 +03:00
|
|
|
#ifndef _NETINET_IN_VAR_H_
|
|
|
|
#define _NETINET_IN_VAR_H_
|
|
|
|
|
1995-06-12 04:46:47 +04:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Interface address, Internet version. One of these structures
|
|
|
|
* is allocated for each interface with an Internet address.
|
|
|
|
* The ifaddr structure contains the protocol-independent part
|
|
|
|
* of the structure and is assumed to be first.
|
|
|
|
*/
|
|
|
|
struct in_ifaddr {
|
|
|
|
struct ifaddr ia_ifa; /* protocol-independent info */
|
|
|
|
#define ia_ifp ia_ifa.ifa_ifp
|
1994-05-13 10:02:48 +04:00
|
|
|
#define ia_flags ia_ifa.ifa_flags
|
1993-03-21 12:45:37 +03:00
|
|
|
/* ia_{,sub}net{,mask} in host order */
|
1995-04-13 10:25:36 +04:00
|
|
|
u_int32_t ia_net; /* network number of interface */
|
|
|
|
u_int32_t ia_netmask; /* mask of net part */
|
|
|
|
u_int32_t ia_subnet; /* subnet number, including net */
|
|
|
|
u_int32_t ia_subnetmask; /* mask of subnet part */
|
1993-03-21 12:45:37 +03:00
|
|
|
struct in_addr ia_netbroadcast; /* to recognize net broadcasts */
|
1998-02-13 21:21:38 +03:00
|
|
|
LIST_ENTRY(in_ifaddr) ia_hash; /* entry in bucket of inet addresses */
|
1995-06-12 04:46:47 +04:00
|
|
|
TAILQ_ENTRY(in_ifaddr) ia_list; /* list of internet addresses */
|
1993-03-21 12:45:37 +03:00
|
|
|
struct sockaddr_in ia_addr; /* reserve space for interface name */
|
1995-04-13 10:25:36 +04:00
|
|
|
struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */
|
1993-03-21 12:45:37 +03:00
|
|
|
#define ia_broadaddr ia_dstaddr
|
|
|
|
struct sockaddr_in ia_sockmask; /* reserve space for general netmask */
|
1995-06-12 04:46:47 +04:00
|
|
|
LIST_HEAD(, in_multi) ia_multiaddrs; /* list of multicast addresses */
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct in_aliasreq {
|
|
|
|
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
|
|
|
struct sockaddr_in ifra_addr;
|
1995-06-04 09:58:20 +04:00
|
|
|
struct sockaddr_in ifra_dstaddr;
|
|
|
|
#define ifra_broadaddr ifra_dstaddr
|
1993-03-21 12:45:37 +03:00
|
|
|
struct sockaddr_in ifra_mask;
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Given a pointer to an in_ifaddr (ifaddr),
|
|
|
|
* return a pointer to the addr as a sockaddr_in.
|
|
|
|
*/
|
|
|
|
#define IA_SIN(ia) (&(((struct in_ifaddr *)(ia))->ia_addr))
|
|
|
|
|
1994-05-13 10:02:48 +04:00
|
|
|
|
1995-03-30 01:57:43 +04:00
|
|
|
#ifdef _KERNEL
|
1998-02-13 21:21:38 +03:00
|
|
|
#ifndef IN_IFADDR_HASH_SIZE
|
1998-07-29 09:18:54 +04:00
|
|
|
#define IN_IFADDR_HASH_SIZE 509 /* 61, 127, 251, 509, 1021, 2039 are good */
|
1998-02-13 21:21:38 +03:00
|
|
|
#endif
|
|
|
|
|
1998-07-16 10:45:09 +04:00
|
|
|
/*
|
|
|
|
* This is a bit unconventional, and wastes a little bit of space, but
|
|
|
|
* because we want a very even hash function we don't use & in_ifaddrhash
|
|
|
|
* here, but rather % the hash size, which should obviously be prime.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IN_IFADDR_HASH(x) in_ifaddrhashtbl[(u_long)(x) % IN_IFADDR_HASH_SIZE]
|
1998-02-13 21:21:38 +03:00
|
|
|
|
|
|
|
u_long in_ifaddrhash; /* size of hash table - 1 */
|
|
|
|
int in_ifaddrentries; /* total number of addrs */
|
|
|
|
LIST_HEAD(in_ifaddrhashhead, in_ifaddr); /* Type of the hash head */
|
|
|
|
TAILQ_HEAD(in_ifaddrhead, in_ifaddr); /* Type of the list head */
|
|
|
|
|
|
|
|
extern struct in_ifaddrhashhead *in_ifaddrhashtbl; /* Hash table head */
|
|
|
|
extern struct in_ifaddrhead in_ifaddr; /* List head (in ip_input) */
|
|
|
|
|
1994-05-13 10:02:48 +04:00
|
|
|
extern struct ifqueue ipintrq; /* ip packet input queue */
|
1999-07-01 12:12:45 +04:00
|
|
|
extern int inetctlerrmap[];
|
1994-05-13 10:02:48 +04:00
|
|
|
void in_socktrim __P((struct sockaddr_in *));
|
|
|
|
|
1993-04-19 07:45:34 +04:00
|
|
|
|
1998-02-13 21:21:38 +03:00
|
|
|
/*
|
|
|
|
* Macro for finding whether an internet address (in_addr) belongs to one
|
|
|
|
* of our interfaces (in_ifaddr). NULL if the address isn't ours.
|
1999-05-04 02:12:44 +04:00
|
|
|
*
|
|
|
|
* Note that even if we find an interface with the address we're looking
|
|
|
|
* for, we should skip that interface if it is not up.
|
1998-02-13 21:21:38 +03:00
|
|
|
*/
|
|
|
|
#define INADDR_TO_IA(addr, ia) \
|
|
|
|
/* struct in_addr addr; */ \
|
|
|
|
/* struct in_ifaddr *ia; */ \
|
|
|
|
{ \
|
|
|
|
for (ia = IN_IFADDR_HASH((addr).s_addr).lh_first; \
|
1999-05-16 23:33:27 +04:00
|
|
|
ia != NULL; \
|
|
|
|
ia = ia->ia_hash.le_next) { \
|
|
|
|
if (in_hosteq(ia->ia_addr.sin_addr, (addr)) && \
|
|
|
|
(ia->ia_ifp->if_flags & IFF_UP) != 0) \
|
|
|
|
break; \
|
|
|
|
} \
|
1998-02-13 21:21:38 +03:00
|
|
|
}
|
|
|
|
|
1998-07-02 15:39:56 +04:00
|
|
|
/*
|
|
|
|
* Macro for finding the next in_ifaddr structure with the same internet
|
|
|
|
* address as ia. Call only with a valid ia pointer.
|
|
|
|
* Will set ia to NULL if none found.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NEXT_IA_WITH_SAME_ADDR(ia) \
|
|
|
|
/* struct in_ifaddr *ia; */ \
|
|
|
|
{ \
|
|
|
|
struct in_addr addr; \
|
|
|
|
addr = ia->ia_addr.sin_addr; \
|
|
|
|
do { \
|
|
|
|
ia = ia->ia_hash.le_next; \
|
1998-08-14 10:57:54 +04:00
|
|
|
} while ((ia != NULL) && !in_hosteq(ia->ia_addr.sin_addr, addr)); \
|
1998-07-02 15:39:56 +04:00
|
|
|
}
|
|
|
|
|
1993-12-09 02:48:05 +03:00
|
|
|
/*
|
|
|
|
* Macro for finding the interface (ifnet structure) corresponding to one
|
|
|
|
* of our IP addresses.
|
|
|
|
*/
|
1994-05-13 10:02:48 +04:00
|
|
|
#define INADDR_TO_IFP(addr, ifp) \
|
1993-12-09 02:48:05 +03:00
|
|
|
/* struct in_addr addr; */ \
|
|
|
|
/* struct ifnet *ifp; */ \
|
|
|
|
{ \
|
|
|
|
register struct in_ifaddr *ia; \
|
|
|
|
\
|
1998-02-13 21:21:38 +03:00
|
|
|
INADDR_TO_IA(addr, ia); \
|
1993-12-09 02:48:05 +03:00
|
|
|
(ifp) = (ia == NULL) ? NULL : ia->ia_ifp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-02-13 21:21:38 +03:00
|
|
|
* Macro for finding an internet address structure (in_ifaddr) corresponding
|
1993-12-09 02:48:05 +03:00
|
|
|
* to a given interface (ifnet structure).
|
|
|
|
*/
|
1994-05-13 10:02:48 +04:00
|
|
|
#define IFP_TO_IA(ifp, ia) \
|
1993-12-09 02:48:05 +03:00
|
|
|
/* struct ifnet *ifp; */ \
|
|
|
|
/* struct in_ifaddr *ia; */ \
|
|
|
|
{ \
|
1998-02-13 21:21:38 +03:00
|
|
|
register struct ifaddr *ifa; \
|
|
|
|
\
|
|
|
|
for (ifa = (ifp)->if_addrlist.tqh_first; \
|
|
|
|
ifa != NULL && ifa->ifa_addr->sa_family != AF_INET; \
|
|
|
|
ifa = ifa->ifa_list.tqe_next) \
|
1993-12-09 02:48:05 +03:00
|
|
|
continue; \
|
1998-02-13 21:21:38 +03:00
|
|
|
(ia) = ifatoia(ifa); \
|
1993-12-09 02:48:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-05-31 10:08:17 +04:00
|
|
|
/*
|
|
|
|
* Per-interface router version information.
|
|
|
|
*/
|
|
|
|
struct router_info {
|
|
|
|
struct ifnet *rti_ifp;
|
|
|
|
int rti_type; /* type of router on this interface */
|
|
|
|
int rti_age; /* time since last v1 query */
|
|
|
|
struct router_info *rti_next;
|
|
|
|
};
|
|
|
|
|
1993-12-09 02:48:05 +03:00
|
|
|
/*
|
|
|
|
* Internet multicast address structure. There is one of these for each IP
|
|
|
|
* multicast group to which this host belongs on a given network interface.
|
|
|
|
* They are kept in a linked list, rooted in the interface's in_ifaddr
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
struct in_multi {
|
|
|
|
struct in_addr inm_addr; /* IP multicast address */
|
|
|
|
struct ifnet *inm_ifp; /* back pointer to ifnet */
|
|
|
|
struct in_ifaddr *inm_ia; /* back pointer to in_ifaddr */
|
|
|
|
u_int inm_refcount; /* no. membership claims by sockets */
|
|
|
|
u_int inm_timer; /* IGMP membership report timer */
|
1995-06-12 04:46:47 +04:00
|
|
|
LIST_ENTRY(in_multi) inm_list; /* list of multicast addresses */
|
1995-05-31 10:08:17 +04:00
|
|
|
u_int inm_state; /* state of membership */
|
|
|
|
struct router_info *inm_rti; /* router version info */
|
1993-12-09 02:48:05 +03:00
|
|
|
};
|
|
|
|
|
1995-03-27 00:23:52 +04:00
|
|
|
#ifdef _KERNEL
|
1993-12-09 02:48:05 +03:00
|
|
|
/*
|
|
|
|
* Structure used by macros below to remember position when stepping through
|
|
|
|
* all of the in_multi records.
|
|
|
|
*/
|
|
|
|
struct in_multistep {
|
|
|
|
struct in_ifaddr *i_ia;
|
|
|
|
struct in_multi *i_inm;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro for looking up the in_multi record for a given IP multicast address
|
|
|
|
* on a given interface. If no matching record is found, "inm" returns NULL.
|
|
|
|
*/
|
1994-05-13 10:02:48 +04:00
|
|
|
#define IN_LOOKUP_MULTI(addr, ifp, inm) \
|
1993-12-09 02:48:05 +03:00
|
|
|
/* struct in_addr addr; */ \
|
|
|
|
/* struct ifnet *ifp; */ \
|
|
|
|
/* struct in_multi *inm; */ \
|
|
|
|
{ \
|
|
|
|
register struct in_ifaddr *ia; \
|
|
|
|
\
|
1998-02-13 21:21:38 +03:00
|
|
|
IFP_TO_IA((ifp), ia); /* multicast */ \
|
1993-12-09 02:48:05 +03:00
|
|
|
if (ia == NULL) \
|
|
|
|
(inm) = NULL; \
|
|
|
|
else \
|
1995-06-12 04:46:47 +04:00
|
|
|
for ((inm) = ia->ia_multiaddrs.lh_first; \
|
1998-02-13 21:21:38 +03:00
|
|
|
(inm) != NULL && !in_hosteq((inm)->inm_addr, (addr)); \
|
1995-06-12 04:46:47 +04:00
|
|
|
(inm) = inm->inm_list.le_next) \
|
1993-12-09 02:48:05 +03:00
|
|
|
continue; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macro to step through all of the in_multi records, one at a time.
|
|
|
|
* The current position is remembered in "step", which the caller must
|
|
|
|
* provide. IN_FIRST_MULTI(), below, must be called to initialize "step"
|
|
|
|
* and get the first record. Both macros return a NULL "inm" when there
|
|
|
|
* are no remaining records.
|
|
|
|
*/
|
1994-05-13 10:02:48 +04:00
|
|
|
#define IN_NEXT_MULTI(step, inm) \
|
1993-12-09 02:48:05 +03:00
|
|
|
/* struct in_multistep step; */ \
|
|
|
|
/* struct in_multi *inm; */ \
|
|
|
|
{ \
|
|
|
|
if (((inm) = (step).i_inm) != NULL) \
|
1995-06-12 04:46:47 +04:00
|
|
|
(step).i_inm = (inm)->inm_list.le_next; \
|
1993-12-09 02:48:05 +03:00
|
|
|
else \
|
|
|
|
while ((step).i_ia != NULL) { \
|
1995-06-12 04:46:47 +04:00
|
|
|
(inm) = (step).i_ia->ia_multiaddrs.lh_first; \
|
|
|
|
(step).i_ia = (step).i_ia->ia_list.tqe_next; \
|
1993-12-09 02:48:05 +03:00
|
|
|
if ((inm) != NULL) { \
|
1995-06-12 04:46:47 +04:00
|
|
|
(step).i_inm = (inm)->inm_list.le_next; \
|
1993-12-09 02:48:05 +03:00
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
1994-05-13 10:02:48 +04:00
|
|
|
#define IN_FIRST_MULTI(step, inm) \
|
1993-12-09 02:48:05 +03:00
|
|
|
/* struct in_multistep step; */ \
|
|
|
|
/* struct in_multi *inm; */ \
|
|
|
|
{ \
|
1995-06-12 04:46:47 +04:00
|
|
|
(step).i_ia = in_ifaddr.tqh_first; \
|
1993-12-09 02:48:05 +03:00
|
|
|
(step).i_inm = NULL; \
|
|
|
|
IN_NEXT_MULTI((step), (inm)); \
|
|
|
|
}
|
|
|
|
|
1994-05-13 10:02:48 +04:00
|
|
|
int in_ifinit __P((struct ifnet *,
|
|
|
|
struct in_ifaddr *, struct sockaddr_in *, int));
|
|
|
|
struct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
|
1996-02-14 02:40:59 +03:00
|
|
|
void in_delmulti __P((struct in_multi *));
|
1994-05-13 10:02:48 +04:00
|
|
|
void in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
|
1998-05-29 19:34:24 +04:00
|
|
|
void in_setmaxmtu __P((void));
|
|
|
|
const char *in_fmtaddr __P((struct in_addr));
|
1996-05-22 17:54:55 +04:00
|
|
|
int in_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
|
|
|
|
struct proc *));
|
1999-07-01 12:12:45 +04:00
|
|
|
void ip_input __P((struct mbuf *));
|
1998-04-30 01:37:52 +04:00
|
|
|
int ipflow_fastforward __P((struct mbuf *));
|
1999-07-01 12:12:45 +04:00
|
|
|
|
1993-12-09 02:48:05 +03:00
|
|
|
#endif
|
1998-02-10 04:26:19 +03:00
|
|
|
|
1999-07-01 12:12:45 +04:00
|
|
|
/* INET6 stuff */
|
|
|
|
#include <netinet6/in6_var.h>
|
|
|
|
|
1998-02-10 04:26:19 +03:00
|
|
|
#endif /* _NETINET_IN_VAR_H_ */
|