1/* $OpenBSD: in6_var.h,v 1.80 2024/05/13 01:15:53 jsg Exp $ */ 2/* $KAME: in6_var.h,v 1.55 2001/02/16 12:49:45 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * 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 project 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 PROJECT 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 PROJECT 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 33/* 34 * Copyright (c) 1985, 1986, 1993 35 * The Regents of the University of California. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. Neither the name of the University nor the names of its contributors 46 * may be used to endorse or promote products derived from this software 47 * without specific prior written permission. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * @(#)in_var.h 8.1 (Berkeley) 6/10/93 62 */ 63 64#ifndef _NETINET6_IN6_VAR_H_ 65#define _NETINET6_IN6_VAR_H_ 66 67/* 68 * Interface address, Internet version. One of these structures 69 * is allocated for each interface with an Internet address. 70 * The ifaddr structure contains the protocol-independent part 71 * of the structure and is assumed to be first. 72 */ 73 74/* 75 * pltime/vltime are just for future reference (required to implements 2 76 * hour rule for hosts). they should never be modified by nd6_timeout or 77 * anywhere else. 78 * userland -> kernel: accept pltime/vltime 79 * kernel -> userland: throw up everything 80 * in kernel: modify preferred/expire only 81 */ 82struct in6_addrlifetime { 83 time_t ia6t_expire; /* valid lifetime expiration time */ 84 time_t ia6t_preferred; /* preferred lifetime expiration time */ 85 u_int32_t ia6t_vltime; /* valid lifetime */ 86 u_int32_t ia6t_pltime; /* prefix lifetime */ 87}; 88 89#ifdef _KERNEL 90struct in6_ifaddr { 91 struct ifaddr ia_ifa; /* protocol-independent info */ 92#define ia_ifp ia_ifa.ifa_ifp 93#define ia_flags ia_ifa.ifa_flags 94 95 struct sockaddr_in6 ia_addr; /* interface address */ 96 struct sockaddr_in6 ia_gwaddr; /* router we learned address from */ 97 struct sockaddr_in6 ia_dstaddr; /* space for destination addr */ 98 struct sockaddr_in6 ia_prefixmask; /* prefix mask */ 99 TAILQ_ENTRY(in6_ifaddr) ia_list; /* list of IP6 addresses */ 100 int ia6_flags; 101 102 struct in6_addrlifetime ia6_lifetime; 103 time_t ia6_updatetime; 104 105 /* multicast addresses joined from the kernel */ 106 LIST_HEAD(, in6_multi_mship) ia6_memberships; 107}; 108#endif /* _KERNEL */ 109 110/* 111 * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12). 112 */ 113struct in6_ifstat { 114 u_int64_t ifs6_in_receive; /* # of total input datagram */ 115 u_int64_t ifs6_in_hdrerr; /* # of datagrams with invalid hdr */ 116 u_int64_t ifs6_in_toobig; /* # of datagrams exceeded MTU */ 117 u_int64_t ifs6_in_noroute; /* # of datagrams with no route */ 118 u_int64_t ifs6_in_addrerr; /* # of datagrams with invalid dst */ 119 u_int64_t ifs6_in_protounknown; /* # of datagrams with unknown proto */ 120 /* NOTE: increment on final dst if */ 121 u_int64_t ifs6_in_truncated; /* # of truncated datagrams */ 122 u_int64_t ifs6_in_discard; /* # of discarded datagrams */ 123 /* NOTE: fragment timeout is not here */ 124 u_int64_t ifs6_in_deliver; /* # of datagrams delivered to ULP */ 125 /* NOTE: increment on final dst if */ 126 u_int64_t ifs6_out_forward; /* # of datagrams forwarded */ 127 /* NOTE: increment on outgoing if */ 128 u_int64_t ifs6_out_request; /* # of outgoing datagrams from ULP */ 129 /* NOTE: does not include forwards */ 130 u_int64_t ifs6_out_discard; /* # of discarded datagrams */ 131 u_int64_t ifs6_out_fragok; /* # of datagrams fragmented */ 132 u_int64_t ifs6_out_fragfail; /* # of datagrams failed on fragment */ 133 u_int64_t ifs6_out_fragcreat; /* # of fragment datagrams */ 134 /* NOTE: this is # after fragment */ 135 u_int64_t ifs6_reass_reqd; /* # of incoming fragmented packets */ 136 /* NOTE: increment on final dst if */ 137 u_int64_t ifs6_reass_ok; /* # of reassembled packets */ 138 /* NOTE: this is # after reass */ 139 /* NOTE: increment on final dst if */ 140 u_int64_t ifs6_reass_fail; /* # of reass failures */ 141 /* NOTE: may not be packet count */ 142 /* NOTE: increment on final dst if */ 143 u_int64_t ifs6_in_mcast; /* # of inbound multicast datagrams */ 144 u_int64_t ifs6_out_mcast; /* # of outbound multicast datagrams */ 145}; 146 147/* 148 * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry. 149 * XXX: I'm not sure if this file is the right place for this structure... 150 */ 151struct icmp6_ifstat { 152 /* 153 * Input statistics 154 */ 155 /* ipv6IfIcmpInMsgs, total # of input messages */ 156 u_int64_t ifs6_in_msg; 157 /* ipv6IfIcmpInErrors, # of input error messages */ 158 u_int64_t ifs6_in_error; 159 /* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */ 160 u_int64_t ifs6_in_dstunreach; 161 /* ipv6IfIcmpInAdminProhibs, # of input administratively prohibited errs */ 162 u_int64_t ifs6_in_adminprohib; 163 /* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */ 164 u_int64_t ifs6_in_timeexceed; 165 /* ipv6IfIcmpInParmProblems, # of input parameter problem errors */ 166 u_int64_t ifs6_in_paramprob; 167 /* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */ 168 u_int64_t ifs6_in_pkttoobig; 169 /* ipv6IfIcmpInEchos, # of input echo requests */ 170 u_int64_t ifs6_in_echo; 171 /* ipv6IfIcmpInEchoReplies, # of input echo replies */ 172 u_int64_t ifs6_in_echoreply; 173 /* ipv6IfIcmpInRouterSolicits, # of input router solicitations */ 174 u_int64_t ifs6_in_routersolicit; 175 /* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */ 176 u_int64_t ifs6_in_routeradvert; 177 /* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */ 178 u_int64_t ifs6_in_neighborsolicit; 179 /* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advertisements */ 180 u_int64_t ifs6_in_neighboradvert; 181 /* ipv6IfIcmpInRedirects, # of input redirects */ 182 u_int64_t ifs6_in_redirect; 183 /* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */ 184 u_int64_t ifs6_in_mldquery; 185 /* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */ 186 u_int64_t ifs6_in_mldreport; 187 /* ipv6IfIcmpInGroupMembReductions, # of input MLD done */ 188 u_int64_t ifs6_in_mlddone; 189 190 /* 191 * Output statistics. We should solve unresolved routing problem... 192 */ 193 /* ipv6IfIcmpOutMsgs, total # of output messages */ 194 u_int64_t ifs6_out_msg; 195 /* ipv6IfIcmpOutErrors, # of output error messages */ 196 u_int64_t ifs6_out_error; 197 /* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */ 198 u_int64_t ifs6_out_dstunreach; 199 /* ipv6IfIcmpOutAdminProhibs, # of output administratively prohibited errs */ 200 u_int64_t ifs6_out_adminprohib; 201 /* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */ 202 u_int64_t ifs6_out_timeexceed; 203 /* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */ 204 u_int64_t ifs6_out_paramprob; 205 /* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */ 206 u_int64_t ifs6_out_pkttoobig; 207 /* ipv6IfIcmpOutEchos, # of output echo requests */ 208 u_int64_t ifs6_out_echo; 209 /* ipv6IfIcmpOutEchoReplies, # of output echo replies */ 210 u_int64_t ifs6_out_echoreply; 211 /* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */ 212 u_int64_t ifs6_out_routersolicit; 213 /* ipv6IfIcmpOutRouterAdvertisements, # of output router advertisements */ 214 u_int64_t ifs6_out_routeradvert; 215 /* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */ 216 u_int64_t ifs6_out_neighborsolicit; 217 /* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advertisements */ 218 u_int64_t ifs6_out_neighboradvert; 219 /* ipv6IfIcmpOutRedirects, # of output redirects */ 220 u_int64_t ifs6_out_redirect; 221 /* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */ 222 u_int64_t ifs6_out_mldquery; 223 /* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */ 224 u_int64_t ifs6_out_mldreport; 225 /* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */ 226 u_int64_t ifs6_out_mlddone; 227}; 228 229struct in6_ifreq { 230 char ifr_name[IFNAMSIZ]; 231 union { 232 struct sockaddr_in6 ifru_addr; 233 struct sockaddr_in6 ifru_dstaddr; 234 short ifru_flags; 235 int ifru_flags6; 236 int ifru_metric; 237 caddr_t ifru_data; 238 struct in6_addrlifetime ifru_lifetime; 239 struct in6_ifstat ifru_stat; 240 struct icmp6_ifstat ifru_icmp6stat; 241 } ifr_ifru; 242}; 243 244struct in6_aliasreq { 245 char ifra_name[IFNAMSIZ]; 246 union { 247 struct sockaddr_in6 ifrau_addr; 248 int ifrau_align; 249 } ifra_ifrau; 250#ifndef ifra_addr 251#define ifra_addr ifra_ifrau.ifrau_addr 252#endif 253 struct sockaddr_in6 ifra_dstaddr; 254 struct sockaddr_in6 ifra_prefixmask; 255 int ifra_flags; 256 struct in6_addrlifetime ifra_lifetime; 257}; 258 259/* 260 * Given a pointer to an in6_ifaddr (ifaddr), 261 * return a pointer to the addr as a sockaddr_in6 262 */ 263#define IA6_IN6(ia) (&((ia)->ia_addr.sin6_addr)) 264#define IA6_DSTIN6(ia) (&((ia)->ia_dstaddr.sin6_addr)) 265#define IA6_MASKIN6(ia) (&((ia)->ia_prefixmask.sin6_addr)) 266#define IA6_SIN6(ia) (&((ia)->ia_addr)) 267#define IA6_DSTSIN6(ia) (&((ia)->ia_dstaddr)) 268#define IFA_IN6(x) (&((struct sockaddr_in6 *)((x)->ifa_addr))->sin6_addr) 269#define IFA_DSTIN6(x) (&((struct sockaddr_in6 *)((x)->ifa_dstaddr))->sin6_addr) 270 271#define SIOCDIFADDR_IN6 _IOW('i', 25, struct in6_ifreq) 272#define SIOCAIFADDR_IN6 _IOW('i', 26, struct in6_aliasreq) 273 274#define SIOCGIFDSTADDR_IN6 _IOWR('i', 34, struct in6_ifreq) 275#define SIOCGIFNETMASK_IN6 _IOWR('i', 37, struct in6_ifreq) 276 277#define SIOCGIFAFLAG_IN6 _IOWR('i', 73, struct in6_ifreq) 278 279#define SIOCGIFINFO_IN6 _IOWR('i', 108, struct in6_ndireq) 280#define SIOCGNBRINFO_IN6 _IOWR('i', 78, struct in6_nbrinfo) 281 282#define SIOCGIFALIFETIME_IN6 _IOWR('i', 81, struct in6_ifreq) 283 284#define SIOCGETSGCNT_IN6 _IOWR('u', 106, struct sioc_sg_req6) 285#define SIOCGETMIFCNT_IN6 _IOWR('u', 107, struct sioc_mif_req6) 286 287#define IN6_IFF_ANYCAST 0x01 /* anycast address */ 288#define IN6_IFF_TENTATIVE 0x02 /* tentative address */ 289#define IN6_IFF_DUPLICATED 0x04 /* DAD detected duplicate */ 290#define IN6_IFF_DETACHED 0x08 /* may be detached from the link */ 291#define IN6_IFF_DEPRECATED 0x10 /* deprecated address */ 292#define IN6_IFF_AUTOCONF 0x40 /* autoconfigurable address. */ 293#define IN6_IFF_TEMPORARY 0x80 /* RFC 4941 temporary address */ 294 295#ifdef _KERNEL 296#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \ 297 (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \ 298 (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \ 299 (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \ 300 (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 ) 301 302#define IN6_ARE_SCOPE_CMP(a,b) ((a)-(b)) 303#define IN6_ARE_SCOPE_EQUAL(a,b) ((a)==(b)) 304 305/* 306 * Multi-cast membership entry. One for each group/ifp that a PCB 307 * belongs to. 308 */ 309struct in6_multi_mship { 310 struct in6_multi *i6mm_maddr; /* Multicast address pointer */ 311 LIST_ENTRY(in6_multi_mship) i6mm_chain; /* multicast options chain */ 312}; 313 314struct in6_multi { 315 struct ifmaddr in6m_ifma; /* Protocol-independent info */ 316#define in6m_refcnt in6m_ifma.ifma_refcnt 317#define in6m_ifidx in6m_ifma.ifma_ifidx 318 319 struct sockaddr_in6 in6m_sin; /* IPv6 multicast address */ 320#define in6m_addr in6m_sin.sin6_addr 321 322 u_int in6m_state; /* state of membership */ 323 u_int in6m_timer; /* MLD6 membership report timer */ 324}; 325 326static __inline struct in6_multi * 327ifmatoin6m(struct ifmaddr *ifma) 328{ 329 return ((struct in6_multi *)(ifma)); 330} 331 332/* 333 * Macros for looking up the in6_multi record for a given IP6 multicast 334 * address on a given interface. If no matching record is found, "in6m" 335 * returns NULL. 336 */ 337#define IN6_LOOKUP_MULTI(addr, ifp, in6m) \ 338 /* struct in6_addr addr; */ \ 339 /* struct ifnet *ifp; */ \ 340 /* struct in6_multi *in6m; */ \ 341do { \ 342 struct ifmaddr *ifma; \ 343 \ 344 (in6m) = NULL; \ 345 TAILQ_FOREACH(ifma, &(ifp)->if_maddrlist, ifma_list) \ 346 if (ifma->ifma_addr->sa_family == AF_INET6 && \ 347 IN6_ARE_ADDR_EQUAL(&ifmatoin6m(ifma)->in6m_addr, \ 348 &(addr))) { \ 349 (in6m) = ifmatoin6m(ifma); \ 350 break; \ 351 } \ 352} while (/* CONSTCOND */ 0) 353 354struct in6_multi *in6_addmulti(struct in6_addr *, struct ifnet *, int *); 355void in6_delmulti(struct in6_multi *); 356int in6_hasmulti(struct in6_addr *, struct ifnet *); 357struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *, int *); 358void in6_leavegroup(struct in6_multi_mship *); 359int in6_control(struct socket *, u_long, caddr_t, struct ifnet *); 360int in6_ioctl(u_long, caddr_t, struct ifnet *, int); 361int in6_update_ifa(struct ifnet *, struct in6_aliasreq *, 362 struct in6_ifaddr *); 363void in6_purgeaddr(struct ifaddr *); 364int in6if_do_dad(struct ifnet *); 365struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); 366struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); 367int in6_addr2scopeid(unsigned int, struct in6_addr *); 368int in6_matchlen(struct in6_addr *, struct in6_addr *); 369void in6_prefixlen2mask(struct in6_addr *, int); 370#endif /* _KERNEL */ 371 372#endif /* _NETINET6_IN6_VAR_H_ */ 373