1 /* $OpenBSD: in_var.h,v 1.39 2016/06/15 19:39:34 gerhard 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 /* 81 * Macro for finding the internet address structure (in_ifaddr) corresponding 82 * to a given interface (ifnet structure). 83 */ 84 #define IFP_TO_IA(ifp, ia) \ 85 /* struct ifnet *ifp; */ \ 86 /* struct in_ifaddr *ia; */ \ 87 do { \ 88 struct ifaddr *ifa; \ 89 TAILQ_FOREACH(ifa, &(ifp)->if_addrlist, ifa_list) { \ 90 if (ifa->ifa_addr->sa_family == AF_INET) \ 91 break; \ 92 } \ 93 (ia) = ifatoia(ifa); \ 94 } while (/* CONSTCOND */ 0) 95 #endif 96 97 /* 98 * Per-interface router version information. 99 */ 100 struct router_info { 101 unsigned int rti_ifidx; 102 int rti_type; /* type of router on this interface */ 103 int rti_age; /* time since last v1 query */ 104 struct router_info *rti_next; 105 }; 106 107 #ifdef _KERNEL 108 /* 109 * Internet multicast address structure. There is one of these for each IP 110 * multicast group to which this host belongs on a given network interface. 111 */ 112 struct in_multi { 113 struct ifmaddr inm_ifma; /* Protocol-independent info */ 114 #define inm_refcnt inm_ifma.ifma_refcnt 115 #define inm_ifidx inm_ifma.ifma_ifidx 116 117 struct sockaddr_in inm_sin; /* IPv4 multicast address */ 118 #define inm_addr inm_sin.sin_addr 119 120 u_int inm_state; /* state of membership */ 121 u_int inm_timer; /* IGMP membership report timer */ 122 123 struct router_info *inm_rti; /* router version info */ 124 }; 125 126 static __inline struct in_multi * 127 ifmatoinm(struct ifmaddr *ifma) 128 { 129 return ((struct in_multi *)(ifma)); 130 } 131 132 /* 133 * Macro for looking up the in_multi record for a given IP multicast 134 * address on a given interface. If no matching record is found, "inm" 135 * returns NULL. 136 */ 137 #define IN_LOOKUP_MULTI(addr, ifp, inm) \ 138 /* struct in_addr addr; */ \ 139 /* struct ifnet *ifp; */ \ 140 /* struct in_multi *inm; */ \ 141 do { \ 142 struct ifmaddr *ifma; \ 143 \ 144 (inm) = NULL; \ 145 TAILQ_FOREACH(ifma, &(ifp)->if_maddrlist, ifma_list) \ 146 if (ifma->ifma_addr->sa_family == AF_INET && \ 147 ifmatoinm(ifma)->inm_addr.s_addr == (addr).s_addr) {\ 148 (inm) = ifmatoinm(ifma); \ 149 break; \ 150 } \ 151 } while (/* CONSTCOND */ 0) 152 153 int in_ifinit(struct ifnet *, 154 struct in_ifaddr *, struct sockaddr_in *, int); 155 struct in_multi *in_addmulti(struct in_addr *, struct ifnet *); 156 void in_delmulti(struct in_multi *); 157 int in_hasmulti(struct in_addr *, struct ifnet *); 158 void in_ifscrub(struct ifnet *, struct in_ifaddr *); 159 int in_control(struct socket *, u_long, caddr_t, struct ifnet *); 160 int in_ioctl(u_long, caddr_t, struct ifnet *, int); 161 void in_prefixlen2mask(struct in_addr *, int); 162 #endif 163 164 #endif /* _NETINET_IN_VAR_H_ */ 165