in6_var.h revision 1.4
1/* $NetBSD: in6_var.h,v 1.4 1999/07/22 03:59:42 itojun Exp $ */ 2 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the project nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32/* 33 * Copyright (c) 1985, 1986, 1993 34 * The Regents of the University of California. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by the University of 47 * California, Berkeley and its contributors. 48 * 4. Neither the name of the University nor the names of its contributors 49 * may be used to endorse or promote products derived from this software 50 * without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * SUCH DAMAGE. 63 * 64 * @(#)in_var.h 8.1 (Berkeley) 6/10/93 65 */ 66 67#ifndef _NETINET6_IN6_VAR_H_ 68#define _NETINET6_IN6_VAR_H_ 69 70/* 71 * Interface address, Internet version. One of these structures 72 * is allocated for each interface with an Internet address. 73 * The ifaddr structure contains the protocol-independent part 74 * of the structure and is assumed to be first. 75 */ 76 77/* 78 * pltime/vltime are just for future reference (required to implements 2 79 * hour rule for hosts). they should never be modified by nd6_timeout or 80 * anywhere else. 81 * userland -> kernel: accept pltime/vltime 82 * kernel -> userland: throuw up everything 83 * in kernel: modify preferred/expire only 84 */ 85struct in6_addrlifetime { 86 time_t ia6t_expire; /* valid lifetime expiration time */ 87 time_t ia6t_preferred; /* preferred lifetime expiration time */ 88 u_int32_t ia6t_vltime; /* valid lifetime */ 89 u_int32_t ia6t_pltime; /* prefix lifetime */ 90}; 91 92struct in6_ifaddr { 93 struct ifaddr ia_ifa; /* protocol-independent info */ 94#define ia_ifp ia_ifa.ifa_ifp 95#define ia_flags ia_ifa.ifa_flags 96 struct sockaddr_in6 ia_addr; /* interface address */ 97 struct sockaddr_in6 ia_net; /* network number of interface */ 98 struct sockaddr_in6 ia_dstaddr; /* space for destination addr */ 99 struct sockaddr_in6 ia_prefixmask; /* prefix mask */ 100 u_int32_t ia_plen; /* prefix length */ 101 struct in6_ifaddr *ia_next; /* next in6 list of IP6 addresses */ 102 LIST_HEAD(in6_multihead, in6_multi) ia6_multiaddrs; 103 /* list of multicast addresses */ 104 int ia6_flags; 105 106 struct in6_addrlifetime ia6_lifetime; /* NULL = infty */ 107}; 108 109struct in6_ifreq { 110 char ifr_name[IFNAMSIZ]; 111 union { 112 struct sockaddr_in6 ifru_addr; 113 struct sockaddr_in6 ifru_dstaddr; 114 short ifru_flags; 115 int ifru_flags6; 116 int ifru_metric; 117 caddr_t ifru_data; 118 struct in6_addrlifetime ifru_lifetime; 119 } ifr_ifru; 120}; 121 122struct in6_aliasreq { 123 char ifra_name[IFNAMSIZ]; 124 struct sockaddr_in6 ifra_addr; 125 struct sockaddr_in6 ifra_dstaddr; 126 struct sockaddr_in6 ifra_prefixmask; 127 int ifra_flags; 128 struct in6_addrlifetime ifra_lifetime; 129}; 130 131/* 132 * prefix related flags passed between kernel(NDP related part) and 133 * user land command(ifconfig) and daemon(rtadvd). 134 */ 135struct in6_prflags { 136 struct prf_ra { 137 u_char onlink : 1; 138 u_char autonomous : 1; 139 u_char reserved : 6; 140 } prf_ra; 141 u_char prf_reserved1; 142 u_short prf_reserved2; 143 /* want to put this on 4byte offset */ 144 struct prf_rr { 145 u_char decrvalid : 1; 146 u_char decrprefd : 1; 147 u_char reserved : 6; 148 } prf_rr; 149 u_char prf_reserved3; 150 u_short prf_reserved4; 151}; 152 153struct in6_prefixreq { 154 char ipr_name[IFNAMSIZ]; 155 u_char ipr_origin; 156 u_char ipr_plen; 157 u_int32_t ipr_vltime; 158 u_int32_t ipr_pltime; 159 struct in6_prflags ipr_flags; 160 struct sockaddr_in6 ipr_prefix; 161}; 162 163#define PR_ORIG_RA 0 164#define PR_ORIG_RR 1 165#define PR_ORIG_STATIC 2 166 167#define ipr_raf_onlink ipr_flags.prf_ra.onlink 168#define ipr_raf_auto ipr_flags.prf_ra.autonomous 169 170#define ipr_statef_onlink ipr_flags.prf_state.onlink 171 172#define ipr_rrf_decrvalid ipr_flags.prf_rr.decrvalid 173#define ipr_rrf_decrprefd ipr_flags.prf_rr.decrprefd 174 175struct in6_rrenumreq { 176 char irr_name[IFNAMSIZ]; 177 u_char irr_origin; 178 u_char irr_m_len; /* match len for matchprefix */ 179 u_char irr_m_minlen; /* minlen for matching prefix */ 180 u_char irr_m_maxlen; /* maxlen for matching prefix */ 181 u_char irr_u_uselen; /* uselen for adding prefix */ 182 u_char irr_u_keeplen; /* keeplen from matching prefix */ 183 struct irr_raflagmask { 184 u_char onlink : 1; 185 u_char autonomous : 1; 186 u_char reserved : 6; 187 } irr_raflagmask; 188 u_int32_t irr_vltime; 189 u_int32_t irr_pltime; 190 struct in6_prflags irr_flags; 191 struct sockaddr_in6 irr_matchprefix; 192 struct sockaddr_in6 irr_useprefix; 193}; 194 195#define irr_raf_mask_onlink irr_raflagmask.onlink 196#define irr_raf_mask_auto irr_raflagmask.autonomous 197#define irr_raf_mask_reserved irr_raflagmask.reserved 198 199#define irr_raf_onlink irr_flags.prf_ra.onlink 200#define irr_raf_auto irr_flags.prf_ra.autonomous 201 202#define irr_statef_onlink irr_flags.prf_state.onlink 203 204#define irr_rrf irr_flags.prf_rr 205#define irr_rrf_decrvalid irr_flags.prf_rr.decrvalid 206#define irr_rrf_decrprefd irr_flags.prf_rr.decrprefd 207 208/* 209 * Given a pointer to an in6_ifaddr (ifaddr), 210 * return a pointer to the addr as a sockaddr_in6 211 */ 212#define IA6_IN6(ia) (&(((struct in6_ifaddr *)(ia))->ia_addr.sin6_addr)) 213#define IA6_DSTIN6(ia) (&(((struct in6_ifaddr *)(ia))->ia_dstaddr.sin6_addr)) 214#define IA6_MASKIN6(ia) (&(((struct in6_ifaddr *)(ia))->ia_prefixmask.sin6_addr)) 215#define IA6_SIN6(ia) (&(((struct in6_ifaddr *)(ia))->ia_addr)) 216#define IA6_DSTSIN6(ia) (&(((struct in6_ifaddr *)(ia))->ia_dstaddr)) 217#define IFA_IN6(x) (((struct sockaddr_in6 *)((x)->ifa_addr))->sin6_addr) 218 219#define IFPR_IN6(x) (((struct sockaddr_in6 *)((x)->ifpr_prefix))->sin6_addr) 220 221#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \ 222 (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \ 223 (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \ 224 (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \ 225 (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 ) 226 227#define SIOCSIFADDR_IN6 _IOW('i', 12, struct in6_ifreq) 228#define SIOCGIFADDR_IN6 _IOWR('i', 33, struct in6_ifreq) 229#define SIOCSIFDSTADDR_IN6 _IOW('i', 14, struct in6_ifreq) 230#define SIOCGIFDSTADDR_IN6 _IOWR('i', 34, struct in6_ifreq) 231#define SIOCSIFNETMASK_IN6 _IOW('i', 22, struct in6_ifreq) 232#define SIOCGIFNETMASK_IN6 _IOWR('i', 37, struct in6_ifreq) 233 234#define SIOCDIFADDR_IN6 _IOW('i', 25, struct in6_ifreq) 235#define SIOCAIFADDR_IN6 _IOW('i', 26, struct in6_aliasreq) 236 237#define SIOCSIFPHYADDR_IN6 _IOW('i', 70, struct in6_aliasreq) 238#define SIOCGIFPSRCADDR_IN6 _IOWR('i', 71, struct in6_ifreq) 239#define SIOCGIFPDSTADDR_IN6 _IOWR('i', 72, struct in6_ifreq) 240 241#define SIOCGIFAFLAG_IN6 _IOWR('i', 73, struct in6_ifreq) 242 243#define SIOCGDRLST_IN6 _IOWR('i', 74, struct in6_drlist) 244#define SIOCGPRLST_IN6 _IOWR('i', 75, struct in6_prlist) 245#define SIOCGIFINFO_IN6 _IOWR('i', 76, struct in6_ndireq) 246#define SIOCSNDFLUSH_IN6 _IOWR('i', 77, struct in6_ifreq) 247#define SIOCGNBRINFO_IN6 _IOWR('i', 78, struct in6_nbrinfo) 248#define SIOCSPFXFLUSH_IN6 _IOWR('i', 79, struct in6_ifreq) 249#define SIOCSRTRFLUSH_IN6 _IOWR('i', 80, struct in6_ifreq) 250 251#define SIOCGIFALIFETIME_IN6 _IOWR('i', 81, struct in6_ifreq) 252#define SIOCSIFALIFETIME_IN6 _IOWR('i', 82, struct in6_ifreq) 253 254#define SIOCSIFPREFIX_IN6 _IOW('i', 100, struct in6_prefixreq) /* set */ 255#define SIOCGIFPREFIX_IN6 _IOWR('i', 101, struct in6_prefixreq) /* get */ 256#define SIOCDIFPREFIX_IN6 _IOW('i', 102, struct in6_prefixreq) /* del */ 257#define SIOCAIFPREFIX_IN6 _IOW('i', 103, struct in6_rrenumreq) /* add */ 258#define SIOCCIFPREFIX_IN6 _IOW('i', 104, \ 259 struct in6_rrenumreq) /* change */ 260#define SIOCSGIFPREFIX_IN6 _IOW('i', 105, \ 261 struct in6_rrenumreq) /* set global */ 262 263#define SIOCGETSGCNT_IN6 _IOWR('u', 106, \ 264 struct sioc_sg_req6) /* get s,g pkt cnt */ 265#define SIOCGETMIFCNT_IN6 _IOWR('u', 107, \ 266 struct sioc_mif_req6) /* get pkt cnt per if */ 267 268#define IN6_IFF_ANYCAST 0x01 /* anycast address */ 269#define IN6_IFF_TENTATIVE 0x02 /* tentative address */ 270#define IN6_IFF_DUPLICATED 0x04 /* DAD detected duplicate */ 271#define IN6_IFF_DETACHED 0x08 /* may be detached from the link */ 272#define IN6_IFF_DEPRECATED 0x10 /* deprecated address */ 273 274/* do not input/output */ 275#define IN6_IFF_NOTREADY (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED) 276 277#ifdef _KERNEL 278extern struct in6_ifaddr *in6_ifaddr; 279extern struct ifqueue ip6intrq; /* IP6 packet input queue */ 280extern struct in6_addr zeroin6_addr; 281extern u_char inet6ctlerrmap[]; 282extern unsigned long in6_maxmtu; 283#if defined(__FreeBSD__) && __FreeBSD__ >= 3 284#ifdef MALLOC_DECLARE 285MALLOC_DECLARE(M_IPMADDR); 286#endif /* MALLOC_DECLARE */ 287#endif 288 289/* 290 * Macro for finding the internet address structure (in6_ifaddr) corresponding 291 * to a given interface (ifnet structure). 292 */ 293#define IFP_TO_IA6(ifp, ia) \ 294/* struct ifnet *ifp; */ \ 295/* struct in6_ifaddr *ia; */ \ 296{ \ 297 struct ifaddr *ifa; \ 298 for (ifa = (ifp)->if_addrlist.tqh_first; ifa; ifa = ifa->ifa_list.tqe_next) { \ 299 if (!ifa->ifa_addr) \ 300 continue; \ 301 if (ifa->ifa_addr->sa_family == AF_INET6) \ 302 break; \ 303 } \ 304 (ia) = (struct in6_ifaddr *)ifa; \ 305} 306#endif /* _KERNEL */ 307 308/* 309 * Multi-cast membership entry. One for each group/ifp that a PCB 310 * belongs to. 311 */ 312struct in6_multi_mship { 313 struct in6_multi *i6mm_maddr; /* Multicast address pointer */ 314 LIST_ENTRY(in6_multi_mship) i6mm_chain; /* multicast options chain */ 315}; 316 317struct in6_multi { 318 LIST_ENTRY(in6_multi) in6m_entry; /* list glue */ 319 struct in6_addr in6m_addr; /* IP6 multicast address */ 320 struct ifnet *in6m_ifp; /* back pointer to ifnet */ 321 struct in6_ifaddr *in6m_ia; /* back pointer to in6_ifaddr */ 322 u_int in6m_refcount; /* # membership claims by sockets */ 323 u_int in6m_state; /* state of the membership */ 324 u_int in6m_timer; /* MLD6 listener report timer */ 325}; 326 327#ifdef _KERNEL 328/* 329 * Structure used by macros below to remember position when stepping through 330 * all of eht in6_multi records. 331 */ 332struct in6_multistep { 333 struct in6_ifaddr *i_ia; 334 struct in6_multi *i_in6m; 335}; 336 337/* 338 * Macros for looking up the in6_multi record for a given IP6 multicast 339 * address on a given interface. If no matching record is found, "in6m" 340 * returns NLL. 341 */ 342 343#define IN6_LOOKUP_MULTI(addr, ifp, in6m) \ 344/* struct in6_addr addr; */ \ 345/* struct ifnet *ifp; */ \ 346/* struct in6_multi *in6m; */ \ 347{ \ 348 register struct in6_ifaddr *ia; \ 349 \ 350 IFP_TO_IA6((ifp), ia); \ 351 if (ia == NULL) \ 352 (in6m) = NULL; \ 353 else \ 354 for ((in6m) = ia->ia6_multiaddrs.lh_first; \ 355 (in6m) != NULL && \ 356 !IN6_ARE_ADDR_EQUAL(&(in6m)->in6m_addr, &(addr)); \ 357 (in6m) = in6m->in6m_entry.le_next) \ 358 continue; \ 359} 360 361/* 362 * Macro to step through all of the in6_multi records, one at a time. 363 * The current position is remembered in "step", which the caller must 364 * provide. IN6_FIRST_MULTI(), below, must be called to initialize "step" 365 * and get the first record. Both macros return a NULL "in6m" when there 366 * are no remaining records. 367 */ 368#define IN6_NEXT_MULTI(step, in6m) \ 369/* struct in6_multistep step; */ \ 370/* struct in6_multi *in6m; */ \ 371{ \ 372 if (((in6m) = (step).i_in6m) != NULL) \ 373 (step).i_in6m = (in6m)->in6m_entry.le_next; \ 374 else \ 375 while ((step).i_ia != NULL) { \ 376 (in6m) = (step).i_ia->ia6_multiaddrs.lh_first; \ 377 (step).i_ia = (step).i_ia->ia_next; \ 378 if ((in6m) != NULL) { \ 379 (step).i_in6m = (in6m)->in6m_entry.le_next; \ 380 break; \ 381 } \ 382 } \ 383} 384 385#define IN6_FIRST_MULTI(step, in6m) \ 386/* struct in6_multistep step; */ \ 387/* struct in6_multi *in6m */ \ 388{ \ 389 (step).i_ia = in6_ifaddr; \ 390 (step).i_in6m = NULL; \ 391 IN6_NEXT_MULTI((step), (in6m)); \ 392} 393 394int in6_ifinit __P((struct ifnet *, 395 struct in6_ifaddr *, struct sockaddr_in6 *, int)); 396struct in6_multi *in6_addmulti __P((struct in6_addr *, struct ifnet *, 397 int *)); 398void in6_delmulti __P((struct in6_multi *)); 399void in6_ifscrub __P((struct ifnet *, struct in6_ifaddr *)); 400extern int in6_mask2len __P((struct in6_addr *)); 401extern void in6_len2mask __P((struct in6_addr *, int)); 402#if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3) 403int in6_control __P((struct socket *, 404 u_long, caddr_t, struct ifnet *, struct proc *)); 405#else 406int in6_control __P((struct socket *, u_long, caddr_t, struct ifnet *)); 407#endif 408void in6_savemkludge __P((struct in6_ifaddr *)); 409void in6_setmaxmtu __P((void)); 410void in6_restoremkludge __P((struct in6_ifaddr *, struct ifnet *)); 411struct in6_ifaddr *in6ifa_ifpforlinklocal __P((struct ifnet *)); 412struct in6_ifaddr *in6ifa_ifpwithaddr __P((struct ifnet *, 413 struct in6_addr *)); 414char *ip6_sprintf __P((struct in6_addr *)); 415int in6_matchlen __P((struct in6_addr *, struct in6_addr *)); 416int in6_prefix_ioctl __P((u_long cmd, caddr_t data, struct ifnet *ifp)); 417#endif /* _KERNEL */ 418 419#endif /* _NETINET6_IN6_VAR_H_ */ 420