1 /* $OpenBSD: in_var.h,v 1.34 2014/03/27 10:39:23 mpi Exp $ */ 2 /* $NetBSD: in_var.h,v 1.16 1996/02/13 23:42:15 christos Exp $ */ 3 4 /* 5 * Copyright (c) 1985, 1986, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)in_var.h 8.1 (Berkeley) 6/10/93 33 */ 34 35 #ifndef _NETINET_IN_VAR_H_ 36 #define _NETINET_IN_VAR_H_ 37 38 #include <sys/queue.h> 39 40 #ifdef _KERNEL 41 /* 42 * Interface address, Internet version. One of these structures 43 * is allocated for each interface with an Internet address. 44 * The ifaddr structure contains the protocol-independent part 45 * of the structure and is assumed to be first. 46 */ 47 struct in_ifaddr { 48 struct ifaddr ia_ifa; /* protocol-independent info */ 49 #define ia_ifp ia_ifa.ifa_ifp 50 #define ia_flags ia_ifa.ifa_flags 51 /* ia_net{,mask} in host order */ 52 u_int32_t ia_net; /* network number of interface */ 53 u_int32_t ia_netmask; /* mask of net part */ 54 TAILQ_ENTRY(in_ifaddr) ia_list; /* list of internet addresses */ 55 struct sockaddr_in ia_addr; /* reserve space for interface name */ 56 struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */ 57 #define ia_broadaddr ia_dstaddr 58 struct sockaddr_in ia_sockmask; /* reserve space for general netmask */ 59 struct in_multi *ia_allhosts; /* multicast address record for 60 the allhosts multicast group */ 61 }; 62 #endif 63 64 struct in_aliasreq { 65 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 66 union { 67 struct sockaddr_in ifrau_addr; 68 int ifrau_align; 69 } ifra_ifrau; 70 #ifndef ifra_addr 71 #define ifra_addr ifra_ifrau.ifrau_addr 72 #endif 73 struct sockaddr_in ifra_dstaddr; 74 #define ifra_broadaddr ifra_dstaddr 75 struct sockaddr_in ifra_mask; 76 }; 77 78 79 #ifdef _KERNEL 80 TAILQ_HEAD(in_ifaddrhead, in_ifaddr); 81 extern struct in_ifaddrhead in_ifaddr; 82 83 /* 84 * Macro for finding the internet address structure (in_ifaddr) corresponding 85 * to a given interface (ifnet structure). 86 */ 87 #define IFP_TO_IA(ifp, ia) \ 88 /* struct ifnet *ifp; */ \ 89 /* struct in_ifaddr *ia; */ \ 90 do { \ 91 struct ifaddr *ifa; \ 92 TAILQ_FOREACH(ifa, &(ifp)->if_addrlist, ifa_list) { \ 93 if (ifa->ifa_addr->sa_family == AF_INET) \ 94 break; \ 95 } \ 96 (ia) = ifatoia(ifa); \ 97 } while (/* CONSTCOND */ 0) 98 #endif 99 100 /* 101 * Per-interface router version information. 102 */ 103 struct router_info { 104 struct ifnet *rti_ifp; 105 int rti_type; /* type of router on this interface */ 106 int rti_age; /* time since last v1 query */ 107 struct router_info *rti_next; 108 }; 109 110 #ifdef _KERNEL 111 /* 112 * Internet multicast address structure. There is one of these for each IP 113 * multicast group to which this host belongs on a given network interface. 114 */ 115 struct in_multi { 116 struct ifmaddr inm_ifma; /* Protocol-independent info */ 117 #define inm_refcnt inm_ifma.ifma_refcnt 118 #define inm_ifidx inm_ifma.ifma_ifidx 119 120 struct sockaddr_in inm_sin; /* IPv4 multicast address */ 121 #define inm_addr inm_sin.sin_addr 122 123 u_int inm_state; /* state of membership */ 124 u_int inm_timer; /* IGMP membership report timer */ 125 126 struct router_info *inm_rti; /* router version info */ 127 }; 128 129 static __inline struct in_multi * 130 ifmatoinm(struct ifmaddr *ifma) 131 { 132 return ((struct in_multi *)(ifma)); 133 } 134 135 /* 136 * Macro for looking up the in_multi record for a given IP multicast 137 * address on a given interface. If no matching record is found, "inm" 138 * returns NULL. 139 */ 140 #define IN_LOOKUP_MULTI(addr, ifp, inm) \ 141 /* struct in_addr addr; */ \ 142 /* struct ifnet *ifp; */ \ 143 /* struct in_multi *inm; */ \ 144 do { \ 145 struct ifmaddr *ifma; \ 146 \ 147 (inm) = NULL; \ 148 TAILQ_FOREACH(ifma, &(ifp)->if_maddrlist, ifma_list) \ 149 if (ifma->ifma_addr->sa_family == AF_INET && \ 150 ifmatoinm(ifma)->inm_addr.s_addr == (addr).s_addr) {\ 151 (inm) = ifmatoinm(ifma); \ 152 break; \ 153 } \ 154 } while (/* CONSTCOND */ 0) 155 156 int in_ifinit(struct ifnet *, 157 struct in_ifaddr *, struct sockaddr_in *, int); 158 struct in_multi *in_addmulti(struct in_addr *, struct ifnet *); 159 void in_delmulti(struct in_multi *); 160 void in_ifscrub(struct ifnet *, struct in_ifaddr *); 161 int in_control(struct socket *, u_long, caddr_t, struct ifnet *); 162 #endif 163 164 #endif /* _NETINET_IN_VAR_H_ */ 165