1*5d5fbe79SDavid van Moolenbroek /** 2*5d5fbe79SDavid van Moolenbroek * @file 3*5d5fbe79SDavid van Moolenbroek * 4*5d5fbe79SDavid van Moolenbroek * IPv6 address scopes, zones, and scoping policy. 5*5d5fbe79SDavid van Moolenbroek * 6*5d5fbe79SDavid van Moolenbroek * This header provides the means to implement support for IPv6 address scopes, 7*5d5fbe79SDavid van Moolenbroek * as per RFC 4007. An address scope can be either global or more constrained. 8*5d5fbe79SDavid van Moolenbroek * In lwIP, we say that an address "has a scope" or "is scoped" when its scope 9*5d5fbe79SDavid van Moolenbroek * is constrained, in which case the address is meaningful only in a specific 10*5d5fbe79SDavid van Moolenbroek * "zone." For unicast addresses, only link-local addresses have a scope; in 11*5d5fbe79SDavid van Moolenbroek * that case, the scope is the link. For multicast addresses, there are various 12*5d5fbe79SDavid van Moolenbroek * scopes defined by RFC 4007 and others. For any constrained scope, a system 13*5d5fbe79SDavid van Moolenbroek * must establish a (potentially one-to-many) mapping between zones and local 14*5d5fbe79SDavid van Moolenbroek * interfaces. For example, a link-local address is valid on only one link (its 15*5d5fbe79SDavid van Moolenbroek * zone). That link may be attached to one or more local interfaces. The 16*5d5fbe79SDavid van Moolenbroek * decisions on which scopes are constrained and the mapping between zones and 17*5d5fbe79SDavid van Moolenbroek * interfaces is together what we refer to as the "scoping policy" - more on 18*5d5fbe79SDavid van Moolenbroek * this in a bit. 19*5d5fbe79SDavid van Moolenbroek * 20*5d5fbe79SDavid van Moolenbroek * In lwIP, each IPv6 address has an associated zone index. This zone index may 21*5d5fbe79SDavid van Moolenbroek * be set to "no zone" (IP6_NO_ZONE, 0) or an actual zone. We say that an 22*5d5fbe79SDavid van Moolenbroek * address "has a zone" or "is zoned" when its zone index is *not* set to "no 23*5d5fbe79SDavid van Moolenbroek * zone." In lwIP, in principle, each address should be "properly zoned," which 24*5d5fbe79SDavid van Moolenbroek * means that if the address has a zone if and only if has a scope. As such, it 25*5d5fbe79SDavid van Moolenbroek * is a rule that an unscoped (e.g., global) address must never have a zone. 26*5d5fbe79SDavid van Moolenbroek * Even though one could argue that there is always one zone even for global 27*5d5fbe79SDavid van Moolenbroek * scopes, this rule exists for implementation simplicity. Violation of the 28*5d5fbe79SDavid van Moolenbroek * rule will trigger assertions or otherwise result in undesired behavior. 29*5d5fbe79SDavid van Moolenbroek * 30*5d5fbe79SDavid van Moolenbroek * Backward compatibility prevents us from requiring that applications always 31*5d5fbe79SDavid van Moolenbroek * provide properly zoned addresses. We do enforce the rule that the in the 32*5d5fbe79SDavid van Moolenbroek * lwIP link layer (everything below netif->output_ip6() and in particular ND6) 33*5d5fbe79SDavid van Moolenbroek * *all* addresses are properly zoned. Thus, on the output paths down the 34*5d5fbe79SDavid van Moolenbroek * stack, various places deal with the case of addresses that lack a zone. 35*5d5fbe79SDavid van Moolenbroek * Some of them are best-effort for efficiency (e.g. the PCB bind and connect 36*5d5fbe79SDavid van Moolenbroek * API calls' attempts to add missing zones); ultimately the IPv6 output 37*5d5fbe79SDavid van Moolenbroek * handler (@ref ip6_output_if_src) will set a zone if necessary. 38*5d5fbe79SDavid van Moolenbroek * 39*5d5fbe79SDavid van Moolenbroek * Aside from dealing with scoped addresses lacking a zone, a proper IPv6 40*5d5fbe79SDavid van Moolenbroek * implementation must also ensure that a packet with a scoped source and/or 41*5d5fbe79SDavid van Moolenbroek * destination address does not leave its zone. This is currently implemented 42*5d5fbe79SDavid van Moolenbroek * in the input and forward functions. However, for output, these checks are 43*5d5fbe79SDavid van Moolenbroek * deliberately omitted in order to keep the implementation lightweight. The 44*5d5fbe79SDavid van Moolenbroek * routing algorithm in @ref ip6_route will take decisions such that it will 45*5d5fbe79SDavid van Moolenbroek * not cause zone violations unless the application sets bad addresses, though. 46*5d5fbe79SDavid van Moolenbroek * 47*5d5fbe79SDavid van Moolenbroek * In terms of scoping policy, lwIP implements the default policy from RFC 4007 48*5d5fbe79SDavid van Moolenbroek * using macros in this file. This policy considers link-local unicast 49*5d5fbe79SDavid van Moolenbroek * addresses and (only) interface-local and link-local multicast addresses as 50*5d5fbe79SDavid van Moolenbroek * having a scope. For all these addresses, the zone is equal to the interface. 51*5d5fbe79SDavid van Moolenbroek * As shown below in this file, it is possible to implement a custom policy. 52*5d5fbe79SDavid van Moolenbroek */ 53*5d5fbe79SDavid van Moolenbroek 54*5d5fbe79SDavid van Moolenbroek /* 55*5d5fbe79SDavid van Moolenbroek * Copyright (c) 2017 The MINIX 3 Project. 56*5d5fbe79SDavid van Moolenbroek * All rights reserved. 57*5d5fbe79SDavid van Moolenbroek * 58*5d5fbe79SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without modification, 59*5d5fbe79SDavid van Moolenbroek * are permitted provided that the following conditions are met: 60*5d5fbe79SDavid van Moolenbroek * 61*5d5fbe79SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright notice, 62*5d5fbe79SDavid van Moolenbroek * this list of conditions and the following disclaimer. 63*5d5fbe79SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright notice, 64*5d5fbe79SDavid van Moolenbroek * this list of conditions and the following disclaimer in the documentation 65*5d5fbe79SDavid van Moolenbroek * and/or other materials provided with the distribution. 66*5d5fbe79SDavid van Moolenbroek * 3. The name of the author may not be used to endorse or promote products 67*5d5fbe79SDavid van Moolenbroek * derived from this software without specific prior written permission. 68*5d5fbe79SDavid van Moolenbroek * 69*5d5fbe79SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 70*5d5fbe79SDavid van Moolenbroek * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 71*5d5fbe79SDavid van Moolenbroek * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 72*5d5fbe79SDavid van Moolenbroek * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 73*5d5fbe79SDavid van Moolenbroek * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 74*5d5fbe79SDavid van Moolenbroek * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 75*5d5fbe79SDavid van Moolenbroek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 76*5d5fbe79SDavid van Moolenbroek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 77*5d5fbe79SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 78*5d5fbe79SDavid van Moolenbroek * OF SUCH DAMAGE. 79*5d5fbe79SDavid van Moolenbroek * 80*5d5fbe79SDavid van Moolenbroek * This file is part of the lwIP TCP/IP stack. 81*5d5fbe79SDavid van Moolenbroek * 82*5d5fbe79SDavid van Moolenbroek * Author: David van Moolenbroek <david@minix3.org> 83*5d5fbe79SDavid van Moolenbroek * 84*5d5fbe79SDavid van Moolenbroek */ 85*5d5fbe79SDavid van Moolenbroek #ifndef LWIP_HDR_IP6_ZONE_H 86*5d5fbe79SDavid van Moolenbroek #define LWIP_HDR_IP6_ZONE_H 87*5d5fbe79SDavid van Moolenbroek 88*5d5fbe79SDavid van Moolenbroek /** 89*5d5fbe79SDavid van Moolenbroek * @defgroup ip6_zones IPv6 Zones 90*5d5fbe79SDavid van Moolenbroek * @ingroup ip6 91*5d5fbe79SDavid van Moolenbroek * @{ 92*5d5fbe79SDavid van Moolenbroek */ 93*5d5fbe79SDavid van Moolenbroek 94*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ 95*5d5fbe79SDavid van Moolenbroek 96*5d5fbe79SDavid van Moolenbroek /** Identifier for "no zone". */ 97*5d5fbe79SDavid van Moolenbroek #define IP6_NO_ZONE 0 98*5d5fbe79SDavid van Moolenbroek 99*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6_SCOPES 100*5d5fbe79SDavid van Moolenbroek 101*5d5fbe79SDavid van Moolenbroek /** Zone initializer for static IPv6 address initialization, including comma. */ 102*5d5fbe79SDavid van Moolenbroek #define IPADDR6_ZONE_INIT , IP6_NO_ZONE 103*5d5fbe79SDavid van Moolenbroek 104*5d5fbe79SDavid van Moolenbroek /** Return the zone index of the given IPv6 address; possibly "no zone". */ 105*5d5fbe79SDavid van Moolenbroek #define ip6_addr_zone(ip6addr) ((ip6addr)->zone) 106*5d5fbe79SDavid van Moolenbroek 107*5d5fbe79SDavid van Moolenbroek /** Does the given IPv6 address have a zone set? (0/1) */ 108*5d5fbe79SDavid van Moolenbroek #define ip6_addr_has_zone(ip6addr) (ip6_addr_zone(ip6addr) != IP6_NO_ZONE) 109*5d5fbe79SDavid van Moolenbroek 110*5d5fbe79SDavid van Moolenbroek /** Set the zone field of an IPv6 address to a particular value. */ 111*5d5fbe79SDavid van Moolenbroek #define ip6_addr_set_zone(ip6addr, zone_idx) ((ip6addr)->zone = (zone_idx)) 112*5d5fbe79SDavid van Moolenbroek 113*5d5fbe79SDavid van Moolenbroek /** Clear the zone field of an IPv6 address, setting it to "no zone". */ 114*5d5fbe79SDavid van Moolenbroek #define ip6_addr_clear_zone(ip6addr) ((ip6addr)->zone = IP6_NO_ZONE) 115*5d5fbe79SDavid van Moolenbroek 116*5d5fbe79SDavid van Moolenbroek /** Copy the zone field from the second IPv6 address to the first one. */ 117*5d5fbe79SDavid van Moolenbroek #define ip6_addr_copy_zone(ip6addr1, ip6addr2) ((ip6addr1).zone = (ip6addr2).zone) 118*5d5fbe79SDavid van Moolenbroek 119*5d5fbe79SDavid van Moolenbroek /** Is the zone field of the given IPv6 address equal to the given zone index? (0/1) */ 120*5d5fbe79SDavid van Moolenbroek #define ip6_addr_equals_zone(ip6addr, zone_idx) ((ip6addr)->zone == (zone_idx)) 121*5d5fbe79SDavid van Moolenbroek 122*5d5fbe79SDavid van Moolenbroek /** Are the zone fields of the given IPv6 addresses equal? (0/1) 123*5d5fbe79SDavid van Moolenbroek * This macro must only be used on IPv6 addresses of the same scope. */ 124*5d5fbe79SDavid van Moolenbroek #define ip6_addr_cmp_zone(ip6addr1, ip6addr2) ((ip6addr1)->zone == (ip6addr2)->zone) 125*5d5fbe79SDavid van Moolenbroek 126*5d5fbe79SDavid van Moolenbroek /** Symbolic constants for the 'type' parameters in some of the macros. 127*5d5fbe79SDavid van Moolenbroek * These exist for efficiency only, allowing the macros to avoid certain tests 128*5d5fbe79SDavid van Moolenbroek * when the address is known not to be of a certain type. Dead code elimination 129*5d5fbe79SDavid van Moolenbroek * will do the rest. IP6_MULTICAST is supported but currently not optimized. 130*5d5fbe79SDavid van Moolenbroek * @see ip6_addr_has_scope, ip6_addr_assign_zone, ip6_addr_lacks_zone. 131*5d5fbe79SDavid van Moolenbroek */ 132*5d5fbe79SDavid van Moolenbroek enum lwip_ipv6_scope_type 133*5d5fbe79SDavid van Moolenbroek { 134*5d5fbe79SDavid van Moolenbroek /** Unknown */ 135*5d5fbe79SDavid van Moolenbroek IP6_UNKNOWN = 0, 136*5d5fbe79SDavid van Moolenbroek /** Unicast */ 137*5d5fbe79SDavid van Moolenbroek IP6_UNICAST = 1, 138*5d5fbe79SDavid van Moolenbroek /** Multicast */ 139*5d5fbe79SDavid van Moolenbroek IP6_MULTICAST = 2 140*5d5fbe79SDavid van Moolenbroek }; 141*5d5fbe79SDavid van Moolenbroek 142*5d5fbe79SDavid van Moolenbroek /** IPV6_CUSTOM_SCOPES: together, the following three macro definitions, 143*5d5fbe79SDavid van Moolenbroek * @ref ip6_addr_has_scope, @ref ip6_addr_assign_zone, and 144*5d5fbe79SDavid van Moolenbroek * @ref ip6_addr_test_zone, completely define the lwIP scoping policy. 145*5d5fbe79SDavid van Moolenbroek * The definitions below implement the default policy from RFC 4007 Sec. 6. 146*5d5fbe79SDavid van Moolenbroek * Should an implementation desire to implement a different policy, it can 147*5d5fbe79SDavid van Moolenbroek * define IPV6_CUSTOM_SCOPES to 1 and supply its own definitions for the three 148*5d5fbe79SDavid van Moolenbroek * macros instead. 149*5d5fbe79SDavid van Moolenbroek */ 150*5d5fbe79SDavid van Moolenbroek #ifndef IPV6_CUSTOM_SCOPES 151*5d5fbe79SDavid van Moolenbroek #define IPV6_CUSTOM_SCOPES 0 152*5d5fbe79SDavid van Moolenbroek #endif /* !IPV6_CUSTOM_SCOPES */ 153*5d5fbe79SDavid van Moolenbroek 154*5d5fbe79SDavid van Moolenbroek #if !IPV6_CUSTOM_SCOPES 155*5d5fbe79SDavid van Moolenbroek 156*5d5fbe79SDavid van Moolenbroek /** 157*5d5fbe79SDavid van Moolenbroek * Determine whether an IPv6 address has a constrained scope, and as such is 158*5d5fbe79SDavid van Moolenbroek * meaningful only if accompanied by a zone index to identify the scope's zone. 159*5d5fbe79SDavid van Moolenbroek * The given address type may be used to eliminate at compile time certain 160*5d5fbe79SDavid van Moolenbroek * checks that will evaluate to false at run time anyway. 161*5d5fbe79SDavid van Moolenbroek * 162*5d5fbe79SDavid van Moolenbroek * This default implementation follows the default model of RFC 4007, where 163*5d5fbe79SDavid van Moolenbroek * only interface-local and link-local scopes are defined. 164*5d5fbe79SDavid van Moolenbroek * 165*5d5fbe79SDavid van Moolenbroek * Even though the unicast loopback address does have an implied link-local 166*5d5fbe79SDavid van Moolenbroek * scope, in this implementation it does not have an explicitly assigned zone 167*5d5fbe79SDavid van Moolenbroek * index. As such it should not be tested for in this macro. 168*5d5fbe79SDavid van Moolenbroek * 169*5d5fbe79SDavid van Moolenbroek * @param ip6addr the IPv6 address (const); only its address part is examined. 170*5d5fbe79SDavid van Moolenbroek * @param type address type; see @ref lwip_ipv6_scope_type. 171*5d5fbe79SDavid van Moolenbroek * @return 1 if the address has a constrained scope, 0 if it does not. 172*5d5fbe79SDavid van Moolenbroek */ 173*5d5fbe79SDavid van Moolenbroek #define ip6_addr_has_scope(ip6addr, type) \ 174*5d5fbe79SDavid van Moolenbroek (ip6_addr_islinklocal(ip6addr) || (((type) != IP6_UNICAST) && \ 175*5d5fbe79SDavid van Moolenbroek (ip6_addr_ismulticast_iflocal(ip6addr) || \ 176*5d5fbe79SDavid van Moolenbroek ip6_addr_ismulticast_linklocal(ip6addr)))) 177*5d5fbe79SDavid van Moolenbroek 178*5d5fbe79SDavid van Moolenbroek /** 179*5d5fbe79SDavid van Moolenbroek * Assign a zone index to an IPv6 address, based on a network interface. If the 180*5d5fbe79SDavid van Moolenbroek * given address has a scope, the assigned zone index is that scope's zone of 181*5d5fbe79SDavid van Moolenbroek * the given netif; otherwise, the assigned zone index is "no zone". 182*5d5fbe79SDavid van Moolenbroek * 183*5d5fbe79SDavid van Moolenbroek * This default implementation follows the default model of RFC 4007, where 184*5d5fbe79SDavid van Moolenbroek * only interface-local and link-local scopes are defined, and the zone index 185*5d5fbe79SDavid van Moolenbroek * of both of those scopes always equals the index of the network interface. 186*5d5fbe79SDavid van Moolenbroek * As such, this default implementation need not distinguish between different 187*5d5fbe79SDavid van Moolenbroek * constrained scopes when assigning the zone. 188*5d5fbe79SDavid van Moolenbroek * 189*5d5fbe79SDavid van Moolenbroek * @param ip6addr the IPv6 address; its address part is examined, and its zone 190*5d5fbe79SDavid van Moolenbroek * index is assigned. 191*5d5fbe79SDavid van Moolenbroek * @param type address type; see @ref lwip_ipv6_scope_type. 192*5d5fbe79SDavid van Moolenbroek * @param netif the network interface (const). 193*5d5fbe79SDavid van Moolenbroek */ 194*5d5fbe79SDavid van Moolenbroek #define ip6_addr_assign_zone(ip6addr, type, netif) \ 195*5d5fbe79SDavid van Moolenbroek (ip6_addr_set_zone((ip6addr), \ 196*5d5fbe79SDavid van Moolenbroek ip6_addr_has_scope((ip6addr), (type)) ? netif_get_index(netif) : 0)) 197*5d5fbe79SDavid van Moolenbroek 198*5d5fbe79SDavid van Moolenbroek /** 199*5d5fbe79SDavid van Moolenbroek * Test whether an IPv6 address is "zone-compatible" with a network interface. 200*5d5fbe79SDavid van Moolenbroek * That is, test whether the network interface is part of the zone associated 201*5d5fbe79SDavid van Moolenbroek * with the address. For efficiency, this macro is only ever called if the 202*5d5fbe79SDavid van Moolenbroek * given address is either scoped or zoned, and thus, it need not test this. 203*5d5fbe79SDavid van Moolenbroek * If an address is scoped but not zoned, or zoned and not scoped, it is 204*5d5fbe79SDavid van Moolenbroek * considered not zone-compatible with any netif. 205*5d5fbe79SDavid van Moolenbroek * 206*5d5fbe79SDavid van Moolenbroek * This default implementation follows the default model of RFC 4007, where 207*5d5fbe79SDavid van Moolenbroek * only interface-local and link-local scopes are defined, and the zone index 208*5d5fbe79SDavid van Moolenbroek * of both of those scopes always equals the index of the network interface. 209*5d5fbe79SDavid van Moolenbroek * As such, there is always only one matching netif for a specific zone index, 210*5d5fbe79SDavid van Moolenbroek * but all call sites of this macro currently support multiple matching netifs 211*5d5fbe79SDavid van Moolenbroek * as well (at no additional expense in the common case). 212*5d5fbe79SDavid van Moolenbroek * 213*5d5fbe79SDavid van Moolenbroek * @param ip6addr the IPv6 address (const). 214*5d5fbe79SDavid van Moolenbroek * @param netif the network interface (const). 215*5d5fbe79SDavid van Moolenbroek * @return 1 if the address is scope-compatible with the netif, 0 if not. 216*5d5fbe79SDavid van Moolenbroek */ 217*5d5fbe79SDavid van Moolenbroek #define ip6_addr_test_zone(ip6addr, netif) \ 218*5d5fbe79SDavid van Moolenbroek (ip6_addr_equals_zone((ip6addr), netif_get_index(netif))) 219*5d5fbe79SDavid van Moolenbroek 220*5d5fbe79SDavid van Moolenbroek #endif /* !IPV6_CUSTOM_SCOPES */ 221*5d5fbe79SDavid van Moolenbroek 222*5d5fbe79SDavid van Moolenbroek /** Does the given IPv6 address have a scope, and as such should also have a 223*5d5fbe79SDavid van Moolenbroek * zone to be meaningful, but does not actually have a zone? (0/1) */ 224*5d5fbe79SDavid van Moolenbroek #define ip6_addr_lacks_zone(ip6addr, type) \ 225*5d5fbe79SDavid van Moolenbroek (!ip6_addr_has_zone(ip6addr) && ip6_addr_has_scope((ip6addr), (type))) 226*5d5fbe79SDavid van Moolenbroek 227*5d5fbe79SDavid van Moolenbroek /** 228*5d5fbe79SDavid van Moolenbroek * Try to select a zone for a scoped address that does not yet have a zone. 229*5d5fbe79SDavid van Moolenbroek * Called from PCB bind and connect routines, for two reasons: 1) to save on 230*5d5fbe79SDavid van Moolenbroek * this (relatively expensive) selection for every individual packet route 231*5d5fbe79SDavid van Moolenbroek * operation and 2) to allow the application to obtain the selected zone from 232*5d5fbe79SDavid van Moolenbroek * the PCB as is customary for e.g. getsockname/getpeername BSD socket calls. 233*5d5fbe79SDavid van Moolenbroek * 234*5d5fbe79SDavid van Moolenbroek * Ideally, callers would always supply a properly zoned address, in which case 235*5d5fbe79SDavid van Moolenbroek * this function would not be needed. It exists both for compatibility with the 236*5d5fbe79SDavid van Moolenbroek * BSD socket API (which accepts zoneless destination addresses) and for 237*5d5fbe79SDavid van Moolenbroek * backward compatibility with pre-scoping lwIP code. 238*5d5fbe79SDavid van Moolenbroek * 239*5d5fbe79SDavid van Moolenbroek * It may be impossible to select a zone, e.g. if there are no netifs. In that 240*5d5fbe79SDavid van Moolenbroek * case, the address's zone field will be left as is. 241*5d5fbe79SDavid van Moolenbroek * 242*5d5fbe79SDavid van Moolenbroek * @param dest the IPv6 address for which to select and set a zone. 243*5d5fbe79SDavid van Moolenbroek * @param src source IPv6 address (const); may be equal to dest. 244*5d5fbe79SDavid van Moolenbroek */ 245*5d5fbe79SDavid van Moolenbroek #define ip6_addr_select_zone(dest, src) do { struct netif *selected_netif; \ 246*5d5fbe79SDavid van Moolenbroek selected_netif = ip6_route((src), (dest)); \ 247*5d5fbe79SDavid van Moolenbroek if (selected_netif != NULL) { \ 248*5d5fbe79SDavid van Moolenbroek ip6_addr_assign_zone((dest), IP6_UNKNOWN, selected_netif); \ 249*5d5fbe79SDavid van Moolenbroek } } while (0) 250*5d5fbe79SDavid van Moolenbroek 251*5d5fbe79SDavid van Moolenbroek /** 252*5d5fbe79SDavid van Moolenbroek * @} 253*5d5fbe79SDavid van Moolenbroek */ 254*5d5fbe79SDavid van Moolenbroek 255*5d5fbe79SDavid van Moolenbroek #else /* LWIP_IPV6_SCOPES */ 256*5d5fbe79SDavid van Moolenbroek 257*5d5fbe79SDavid van Moolenbroek #define IPADDR6_ZONE_INIT 258*5d5fbe79SDavid van Moolenbroek #define ip6_addr_zone(ip6addr) (IP6_NO_ZONE) 259*5d5fbe79SDavid van Moolenbroek #define ip6_addr_has_zone(ip6addr) (0) 260*5d5fbe79SDavid van Moolenbroek #define ip6_addr_set_zone(ip6addr, zone_idx) 261*5d5fbe79SDavid van Moolenbroek #define ip6_addr_clear_zone(ip6addr) 262*5d5fbe79SDavid van Moolenbroek #define ip6_addr_copy_zone(ip6addr1, ip6addr2) 263*5d5fbe79SDavid van Moolenbroek #define ip6_addr_equals_zone(ip6addr, zone_idx) (1) 264*5d5fbe79SDavid van Moolenbroek #define ip6_addr_cmp_zone(ip6addr1, ip6addr2) (1) 265*5d5fbe79SDavid van Moolenbroek #define IPV6_CUSTOM_SCOPES 0 266*5d5fbe79SDavid van Moolenbroek #define ip6_addr_has_scope(ip6addr, type) (0) 267*5d5fbe79SDavid van Moolenbroek #define ip6_addr_assign_zone(ip6addr, type, netif) 268*5d5fbe79SDavid van Moolenbroek #define ip6_addr_test_zone(ip6addr, netif) (1) 269*5d5fbe79SDavid van Moolenbroek #define ip6_addr_lacks_zone(ip6addr, type) (0) 270*5d5fbe79SDavid van Moolenbroek #define ip6_addr_select_zone(ip6addr, src) 271*5d5fbe79SDavid van Moolenbroek 272*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6_SCOPES */ 273*5d5fbe79SDavid van Moolenbroek 274*5d5fbe79SDavid van Moolenbroek #if LWIP_IPV6_SCOPES && LWIP_IPV6_SCOPES_DEBUG 275*5d5fbe79SDavid van Moolenbroek 276*5d5fbe79SDavid van Moolenbroek /** Verify that the given IPv6 address is properly zoned. */ 277*5d5fbe79SDavid van Moolenbroek #define IP6_ADDR_ZONECHECK(ip6addr) LWIP_ASSERT("IPv6 zone check failed", \ 278*5d5fbe79SDavid van Moolenbroek ip6_addr_has_scope(ip6addr, IP6_UNKNOWN) == ip6_addr_has_zone(ip6addr)) 279*5d5fbe79SDavid van Moolenbroek 280*5d5fbe79SDavid van Moolenbroek /** Verify that the given IPv6 address is properly zoned for the given netif. */ 281*5d5fbe79SDavid van Moolenbroek #define IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif) LWIP_ASSERT("IPv6 netif zone check failed", \ 282*5d5fbe79SDavid van Moolenbroek ip6_addr_has_scope(ip6addr, IP6_UNKNOWN) ? \ 283*5d5fbe79SDavid van Moolenbroek (ip6_addr_has_zone(ip6addr) && \ 284*5d5fbe79SDavid van Moolenbroek (((netif) == NULL) || ip6_addr_test_zone((ip6addr), (netif)))) : \ 285*5d5fbe79SDavid van Moolenbroek !ip6_addr_has_zone(ip6addr)) 286*5d5fbe79SDavid van Moolenbroek 287*5d5fbe79SDavid van Moolenbroek #else /* LWIP_IPV6_SCOPES && LWIP_IPV6_SCOPES_DEBUG */ 288*5d5fbe79SDavid van Moolenbroek 289*5d5fbe79SDavid van Moolenbroek #define IP6_ADDR_ZONECHECK(ip6addr) 290*5d5fbe79SDavid van Moolenbroek #define IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif) 291*5d5fbe79SDavid van Moolenbroek 292*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6_SCOPES && LWIP_IPV6_SCOPES_DEBUG */ 293*5d5fbe79SDavid van Moolenbroek 294*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_IPV6 */ 295*5d5fbe79SDavid van Moolenbroek 296*5d5fbe79SDavid van Moolenbroek #endif /* LWIP_HDR_IP6_ADDR_H */ 297