[313] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
| 5 | * Tomakomai National College of Technology, JAPAN
|
---|
| 6 | *
|
---|
| 7 | * ä¸è¨èä½æ¨©è
|
---|
| 8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 9 | * ã«ãã£ã¦å
|
---|
| 10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 13 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 19 | * ç¨ã§ããå½¢ã§åé
|
---|
| 20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 22 | * è
|
---|
| 23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
| 28 | * (a) åé
|
---|
| 29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 35 | 責ãããã¨ï¼
|
---|
| 36 | *
|
---|
| 37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 38 | ã
|
---|
| 39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 42 | *
|
---|
| 43 | * @(#) $Id: in6_subr.c 313 2017-07-23 04:50:32Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
---|
| 48 | * All rights reserved.
|
---|
| 49 | *
|
---|
| 50 | * Redistribution and use in source and binary forms, with or without
|
---|
| 51 | * modification, are permitted provided that the following conditions
|
---|
| 52 | * are met:
|
---|
| 53 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 54 | * notice, this list of conditions and the following disclaimer.
|
---|
| 55 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 56 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 57 | * documentation and/or other materials provided with the distribution.
|
---|
| 58 | * 3. Neither the name of the project nor the names of its contributors
|
---|
| 59 | * may be used to endorse or promote products derived from this software
|
---|
| 60 | * without specific prior written permission.
|
---|
| 61 | *
|
---|
| 62 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 63 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 64 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 65 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
---|
| 66 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 67 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 68 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 69 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 70 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 71 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 72 | * SUCH DAMAGE.
|
---|
| 73 | */
|
---|
| 74 |
|
---|
| 75 | /*
|
---|
| 76 | * Copyright (c) 1985, 1986, 1993
|
---|
| 77 | * The Regents of the University of California. All rights reserved.
|
---|
| 78 | *
|
---|
| 79 | * Redistribution and use in source and binary forms, with or without
|
---|
| 80 | * modification, are permitted provided that the following conditions
|
---|
| 81 | * are met:
|
---|
| 82 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 83 | * notice, this list of conditions and the following disclaimer.
|
---|
| 84 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 85 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 86 | * documentation and/or other materials provided with the distribution.
|
---|
| 87 | * 3. All advertising materials mentioning features or use of this software
|
---|
| 88 | * must display the following acknowledgement:
|
---|
| 89 | * This product includes software developed by the University of
|
---|
| 90 | * California, Berkeley and its contributors.
|
---|
| 91 | * 4. Neither the name of the University nor the names of its contributors
|
---|
| 92 | * may be used to endorse or promote products derived from this software
|
---|
| 93 | * without specific prior written permission.
|
---|
| 94 | *
|
---|
| 95 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 96 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 97 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 98 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
| 99 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 100 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 101 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 102 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 103 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 104 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 105 | * SUCH DAMAGE.
|
---|
| 106 | */
|
---|
| 107 |
|
---|
| 108 | #include <string.h>
|
---|
| 109 |
|
---|
| 110 | #ifdef TARGET_KERNEL_ASP
|
---|
| 111 |
|
---|
| 112 | #include <kernel.h>
|
---|
| 113 | #include <sil.h>
|
---|
| 114 | #include "kernel_cfg.h"
|
---|
| 115 |
|
---|
| 116 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 117 |
|
---|
| 118 | #ifdef TARGET_KERNEL_JSP
|
---|
| 119 |
|
---|
| 120 | #include <s_services.h>
|
---|
| 121 | #include <t_services.h>
|
---|
| 122 | #include "kernel_id.h"
|
---|
| 123 | #include "tinet_id.h"
|
---|
| 124 |
|
---|
| 125 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 126 |
|
---|
| 127 | #include <tinet_defs.h>
|
---|
| 128 | #include <tinet_config.h>
|
---|
| 129 |
|
---|
| 130 | #include <net/if.h>
|
---|
| 131 | #include <net/if_loop.h>
|
---|
| 132 | #include <net/if_ppp.h>
|
---|
| 133 | #include <net/ethernet.h>
|
---|
| 134 | #include <net/if_arp.h>
|
---|
| 135 | #include <net/net.h>
|
---|
| 136 | #include <net/net_endian.h>
|
---|
| 137 | #include <net/net_var.h>
|
---|
| 138 | #include <net/net_buf.h>
|
---|
| 139 | #include <net/net_timer.h>
|
---|
| 140 |
|
---|
| 141 | #include <netinet/in.h>
|
---|
| 142 | #include <netinet/in_var.h>
|
---|
| 143 | #include <netinet/ip.h>
|
---|
| 144 | #include <netinet/ip_var.h>
|
---|
| 145 |
|
---|
| 146 | #include <netinet6/nd6.h>
|
---|
| 147 | #include <netinet6/ah.h>
|
---|
| 148 |
|
---|
| 149 | #include <net/if_var.h>
|
---|
| 150 |
|
---|
| 151 | /*
|
---|
| 152 | * in6_make_ipv4mapped -- IPv4 å°å½±ã¢ãã¬ã¹ãçæããã
|
---|
| 153 | *
|
---|
| 154 | * 注æ:
|
---|
| 155 | * src ã¯ãã¹ããã¤ããªã¼ãã¼
|
---|
| 156 | *
|
---|
| 157 | */
|
---|
| 158 |
|
---|
| 159 | T_IN6_ADDR *
|
---|
| 160 | in6_make_ipv4mapped (T_IN6_ADDR *dst, T_IN4_ADDR src)
|
---|
| 161 | {
|
---|
| 162 | dst->s6_addr32[0] = ULONG_C(0x00000000);
|
---|
| 163 | dst->s6_addr32[1] = ULONG_C(0x00000000);
|
---|
| 164 | dst->s6_addr32[2] = IPV6_ADDR_INT32_0000FFFF;
|
---|
| 165 | dst->s6_addr32[3] = htonl(src);
|
---|
| 166 |
|
---|
| 167 | return dst;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | #ifdef _IP6_CFG
|
---|
| 171 |
|
---|
| 172 | #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0
|
---|
| 173 |
|
---|
| 174 | /*
|
---|
| 175 | * in6_rtinit -- ã«ã¼ãã£ã³ã°è¡¨ãåæåããã
|
---|
| 176 | */
|
---|
| 177 |
|
---|
| 178 | void
|
---|
| 179 | in6_rtinit (void)
|
---|
| 180 | {
|
---|
| 181 | int_t ix;
|
---|
| 182 |
|
---|
| 183 | for (ix = 0; ix < NUM_IN6_STATIC_ROUTE_ENTRY; ix ++)
|
---|
| 184 | routing6_tbl[ix].flags = IN_RTF_DEFINED;
|
---|
| 185 |
|
---|
| 186 | for ( ; ix < NUM_IN6_ROUTE_ENTRY; ix ++)
|
---|
| 187 | routing6_tbl[ix].flags = 0;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | /*
|
---|
| 191 | * in6_rtnewentry -- æ°ããã¨ã³ããªãç²å¾ããã
|
---|
| 192 | */
|
---|
| 193 |
|
---|
| 194 | T_IN6_RTENTRY *
|
---|
| 195 | in6_rtnewentry (uint8_t flags, uint32_t tmo)
|
---|
| 196 | {
|
---|
| 197 | SYSTIM now;
|
---|
| 198 | T_IN6_RTENTRY *rt, *frt = NULL;
|
---|
| 199 | int_t ix;
|
---|
| 200 |
|
---|
| 201 | /* 空ãã¨ã³ããªãæ¢ãã*/
|
---|
| 202 | for (ix = NUM_IN6_STATIC_ROUTE_ENTRY; ix < NUM_IN6_ROUTE_ENTRY; ix ++) {
|
---|
| 203 | rt = &routing6_tbl[ix];
|
---|
| 204 | if ((routing6_tbl[ix].flags & IN_RTF_DEFINED) == 0) {
|
---|
| 205 | frt = rt;
|
---|
| 206 | break;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | /* expire ã®åä½ã¯ [s]ã*/
|
---|
| 211 | syscall(get_tim(&now));
|
---|
| 212 | now /= SYSTIM_HZ;
|
---|
| 213 |
|
---|
| 214 | if (frt == NULL) {
|
---|
| 215 | /* 空ãããªããã°ãæå¹æéããã£ã¨ãçãã¨ã³ããªã空ãã«ããã*/
|
---|
| 216 | T_IN6_RTENTRY *srt = NULL;
|
---|
| 217 | int_t diff, sdiff = INT_MAX;
|
---|
| 218 |
|
---|
| 219 | syscall(wai_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 220 | for (ix = NUM_IN6_STATIC_ROUTE_ENTRY; ix < NUM_IN6_ROUTE_ENTRY; ix ++) {
|
---|
| 221 | rt = &routing6_tbl[ix];
|
---|
| 222 | diff = (int_t)(rt->expire - now);
|
---|
| 223 | if (diff <= 0) { /* rt->expire <= now */
|
---|
| 224 | /* æ¢ã«ãæå¹æéãéãã¦ããã*/
|
---|
| 225 | frt = rt;
|
---|
| 226 | break;
|
---|
| 227 | }
|
---|
| 228 | else if (diff < sdiff) {
|
---|
| 229 | srt = rt;
|
---|
| 230 | sdiff = diff;
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 | if (frt == NULL)
|
---|
| 234 | frt = srt;
|
---|
| 235 | frt->flags = 0;
|
---|
| 236 | syscall(sig_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | frt->flags = (uint8_t)(flags | IN_RTF_DEFINED);
|
---|
| 240 | frt->expire = now + tmo / SYSTIM_HZ;
|
---|
| 241 | return frt;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | /*
|
---|
| 245 | * in6_rttimer -- ã«ã¼ãã£ã³ã°è¡¨ã®ç®¡çã¿ã¤ãã¼
|
---|
| 246 | */
|
---|
| 247 |
|
---|
| 248 | void
|
---|
| 249 | in6_rttimer (void)
|
---|
| 250 | {
|
---|
| 251 | SYSTIM now;
|
---|
| 252 | int_t ix;
|
---|
| 253 |
|
---|
| 254 | /* expire ã®åä½ã¯ [s]ã*/
|
---|
| 255 | syscall(get_tim(&now));
|
---|
| 256 | now /= SYSTIM_HZ;
|
---|
| 257 |
|
---|
| 258 | syscall(wai_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 259 | for (ix = NUM_IN6_STATIC_ROUTE_ENTRY; ix < NUM_IN6_ROUTE_ENTRY; ix ++)
|
---|
| 260 | if ((routing6_tbl[ix].flags & IN_RTF_DEFINED) &&
|
---|
| 261 | (int_t)(routing6_tbl[ix].expire - now) <= 0)
|
---|
| 262 | routing6_tbl[ix].flags = 0;
|
---|
| 263 | syscall(sig_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | #endif /* of #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
| 267 |
|
---|
| 268 | #if NUM_IN6_HOSTCACHE_ENTRY > 0
|
---|
| 269 |
|
---|
| 270 | /*
|
---|
| 271 | * ãã¹ããã£ãã·ã¥
|
---|
| 272 | */
|
---|
| 273 |
|
---|
| 274 | static T_IN6_HOSTCACHE_ENTRY in6_hostcache[NUM_IN6_HOSTCACHE_ENTRY];
|
---|
| 275 |
|
---|
| 276 | #endif /* of #if NUM_IN6_HOSTCACHE_ENTRY > 0 */
|
---|
| 277 |
|
---|
| 278 | /*
|
---|
| 279 | * in6_lookup_ifaddr -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã«å²ãå½ã¦ããã¦ããã¢ãã¬ã¹ãæ¢ç´¢ããã
|
---|
| 280 | */
|
---|
| 281 |
|
---|
| 282 | T_IN6_IFADDR *
|
---|
| 283 | in6_lookup_ifaddr (T_IFNET *ifp, const T_IN6_ADDR *addr)
|
---|
| 284 | {
|
---|
| 285 | int_t ix;
|
---|
| 286 |
|
---|
| 287 | for (ix = NUM_IN6_IFADDR_ENTRY; ix -- > 0; ) {
|
---|
| 288 | if ((ifp->in6_ifaddrs[ix].flags & IN6_IFF_DEFINED) &&
|
---|
| 289 | IN6_ARE_ADDR_EQUAL(addr, &ifp->in6_ifaddrs[ix].addr))
|
---|
| 290 | return &ifp->in6_ifaddrs[ix];
|
---|
| 291 | }
|
---|
| 292 | return NULL;
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | /*
|
---|
| 296 | * in6_lookup_multi -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ãã«ããã£ã¹ãã¢ãã¬ã¹ãæ¤ç´¢ããã
|
---|
| 297 | */
|
---|
| 298 |
|
---|
| 299 | bool_t
|
---|
| 300 | in6_lookup_multi (T_IFNET *ifp, const T_IN6_ADDR *maddr)
|
---|
| 301 | {
|
---|
| 302 | int_t ix;
|
---|
| 303 |
|
---|
| 304 | for (ix = MAX_IN6_MADDR_CNT; ix -- > 0; )
|
---|
| 305 | if (IN6_ARE_ADDR_EQUAL(maddr, &ifp->in6_maddrs[ix]))
|
---|
| 306 | return true;
|
---|
| 307 | return false;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | /*
|
---|
| 311 | * in6_set_header -- IPv6 ããããè¨å®ããã
|
---|
| 312 | */
|
---|
| 313 |
|
---|
| 314 | ER
|
---|
| 315 | in6_set_header (T_NET_BUF *nbuf, uint_t len,
|
---|
| 316 | const T_IN6_ADDR *dstaddr, const T_IN6_ADDR *srcaddr,
|
---|
| 317 | uint8_t next, uint8_t hlim)
|
---|
| 318 | {
|
---|
| 319 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 320 | T_IP6_HDR *ip6h;
|
---|
| 321 | T_IN6_IFADDR *ia;
|
---|
| 322 |
|
---|
| 323 | /*
|
---|
| 324 | * å®å
|
---|
| 325 | ã¢ãã¬ã¹ã«ãµããããéä¿¡å
|
---|
| 326 | ã¢ãã¬ã¹ãã
|
---|
| 327 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããæ¢ç´¢ãã¦å©ç¨ããã
|
---|
| 328 | */
|
---|
| 329 | if (srcaddr == NULL || !IN6_IS_ADDR_UNSPECIFIED(srcaddr))
|
---|
| 330 | ;
|
---|
| 331 | else if ((ia = in6_ifawithifp(ifp, dstaddr)) == NULL)
|
---|
| 332 | return E_SYS;
|
---|
| 333 | else
|
---|
| 334 | srcaddr = &ia->addr;
|
---|
| 335 |
|
---|
| 336 | /* IPv6 ããããè¨å®ããã*/
|
---|
| 337 | ip6h = GET_IP6_HDR(nbuf);
|
---|
| 338 | ip6h->vcf = htonl(IP6_MAKE_VCF(IPV6_VERSION, 0));
|
---|
| 339 | ip6h->plen = htons(len);
|
---|
| 340 | ip6h->next = next;
|
---|
| 341 | ip6h->hlim = hlim;
|
---|
| 342 |
|
---|
| 343 | if (dstaddr == NULL)
|
---|
| 344 | memset(&ip6h->dst, 0, sizeof(T_IN6_ADDR));
|
---|
| 345 | else
|
---|
| 346 | ip6h->dst = *dstaddr;
|
---|
| 347 |
|
---|
| 348 | if (srcaddr == NULL)
|
---|
| 349 | memset(&ip6h->src, 0, sizeof(T_IN6_ADDR));
|
---|
| 350 | else
|
---|
| 351 | ip6h->src = *srcaddr;
|
---|
| 352 |
|
---|
| 353 | return E_OK;
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | /*
|
---|
| 357 | * in6_get_datagram -- IPv6 ãã¼ã¿ã°ã©ã ãç²å¾ããããããè¨å®ããã
|
---|
| 358 | */
|
---|
| 359 |
|
---|
| 360 | ER
|
---|
| 361 | in6_get_datagram (T_NET_BUF **nbuf, uint_t len, uint_t maxlen,
|
---|
| 362 | const T_IN6_ADDR *dstaddr, const T_IN6_ADDR *srcaddr,
|
---|
| 363 | uint8_t next, uint8_t hlim, ATR nbatr, TMO tmout)
|
---|
| 364 | {
|
---|
| 365 | ER error;
|
---|
| 366 | uint_t align;
|
---|
| 367 |
|
---|
| 368 | /* ãã¼ã¿é·ã¯ 4 ãªã¯ãããå¢çã«èª¿æ´ããã */
|
---|
| 369 | align = (len + 3) >> 2 << 2;
|
---|
| 370 |
|
---|
| 371 | /* ãããã¯ã¼ã¯ãããã¡ãç²å¾ããã */
|
---|
| 372 | if ((error = tget_net_buf_ex(nbuf, IF_IP6_HDR_SIZE + align,
|
---|
| 373 | IF_IP6_HDR_SIZE + maxlen, nbatr, tmout)) != E_OK)
|
---|
| 374 | return error;
|
---|
| 375 |
|
---|
| 376 | /*
|
---|
| 377 | * ãã大ããªãµã¤ãºã®ãããã¯ã¼ã¯ãããã¡ãç²å¾ããå ´åã®ã¿é·ãã調æ´ããã
|
---|
| 378 | * ããå°ããªãµã¤ãºã®ãããã¯ã¼ã¯ãããã¡ã®ç²å¾ã¯ãéä¿¡ã¦ã£ã³ããããã¡ã®
|
---|
| 379 | * çã³ãã¼æ©è½ã§ä½¿ç¨ãããå®éã«éä¿¡ããã¾ã§ããã¼ã¿ãµã¤ãºã¯æ±ºå®ã§ããªãã
|
---|
| 380 | */
|
---|
| 381 | if ((nbatr & NBA_SEARCH_ASCENT) != 0)
|
---|
| 382 | (*nbuf)->len = IF_IP6_HDR_SIZE + len;
|
---|
| 383 |
|
---|
| 384 | /* IPv6 ããããè¨å®ããã*/
|
---|
| 385 | if ((error = in6_set_header(*nbuf, len, dstaddr, srcaddr, next, hlim)) != E_OK)
|
---|
| 386 | return error;
|
---|
| 387 |
|
---|
| 388 | /* 4 ãªã¯ãããå¢çã¾ã§ããã£ã³ã°ã§åããã*/
|
---|
| 389 | if (align > len)
|
---|
| 390 | memset(GET_IP6_SDU(*nbuf) + len, 0, align - len);
|
---|
| 391 |
|
---|
| 392 | return E_OK;
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | /*
|
---|
| 396 | * in6_get_maxnum_ifaddr -- ã¤ã³ã¿ãã§ã¼ã¹ã«è¨å®å¯è½ãªæ大ã¢ãã¬ã¹æ°ãè¿ãã
|
---|
| 397 | */
|
---|
| 398 |
|
---|
| 399 | uint_t
|
---|
| 400 | in6_get_maxnum_ifaddr (void)
|
---|
| 401 | {
|
---|
| 402 | return NUM_IN6_IFADDR_ENTRY;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | /*
|
---|
| 406 | * in6_get_ifaddr -- ã¤ã³ã¿ãã§ã¼ã¹ã«è¨å®ããã¦ããã¢ãã¬ã¹ãè¿ãã
|
---|
| 407 | */
|
---|
| 408 |
|
---|
| 409 | const T_IN6_ADDR *
|
---|
| 410 | in6_get_ifaddr (int_t index)
|
---|
| 411 | {
|
---|
| 412 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 413 |
|
---|
| 414 | if (index < NUM_IN6_IFADDR_ENTRY &&
|
---|
| 415 | (ifp->in6_ifaddrs[index].flags & IN6_IFF_DEFINED))
|
---|
| 416 | return &ifp->in6_ifaddrs[index].addr;
|
---|
| 417 | else
|
---|
| 418 | return NULL;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | /*
|
---|
| 422 | * ipv62str -- IPv6 ã¢ãã¬ã¹ãæååã«å¤æããã
|
---|
| 423 | */
|
---|
| 424 |
|
---|
| 425 | char *
|
---|
| 426 | ipv62str (char *buf, const T_IN6_ADDR *p_addr)
|
---|
| 427 | {
|
---|
| 428 | static char addr_sbuf[NUM_IPV6ADDR_STR_BUFF][sizeof("0123:4567:89ab:cdef:0123:4567:255.255.255.255")];
|
---|
| 429 | static int_t bix = NUM_IPV6ADDR_STR_BUFF;
|
---|
| 430 |
|
---|
| 431 | bool_t omit = false, zero = false;
|
---|
| 432 | char *start;
|
---|
| 433 | int_t ix, len6;
|
---|
| 434 |
|
---|
| 435 | if (buf == NULL) {
|
---|
| 436 | syscall(wai_sem(SEM_IP2STR_BUFF_LOCK));
|
---|
| 437 | buf = addr_sbuf[-- bix];
|
---|
| 438 | if (bix <= 0)
|
---|
| 439 | bix = NUM_IPV6ADDR_STR_BUFF;
|
---|
| 440 | syscall(sig_sem(SEM_IP2STR_BUFF_LOCK));
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | start = buf;
|
---|
| 444 | if (p_addr == NULL || IN6_IS_ADDR_UNSPECIFIED(p_addr)) {
|
---|
| 445 | *buf ++ = '0';
|
---|
| 446 | *buf ++ = ':';
|
---|
| 447 | *buf ++ = ':';
|
---|
| 448 | *buf ++ = '0';
|
---|
| 449 | }
|
---|
| 450 | else {
|
---|
| 451 | if (IN6_IS_ADDR_V4MAPPED(p_addr))
|
---|
| 452 | len6 = sizeof(T_IN6_ADDR) / 2 - 2;
|
---|
| 453 | else
|
---|
| 454 | len6 = sizeof(T_IN6_ADDR) / 2;
|
---|
| 455 | for (ix = 0; ix < len6; ix ++) {
|
---|
| 456 | if (omit) {
|
---|
| 457 | buf += convert_hexdigit(buf, ntohs(p_addr->s6_addr16[ix]), 16, 0, ' ');
|
---|
| 458 | if (ix < 7)
|
---|
| 459 | *buf ++ = ':';
|
---|
| 460 | }
|
---|
| 461 | else if (ix > 0 && ix < 7 && p_addr->s6_addr16[ix] == 0)
|
---|
| 462 | zero = true;
|
---|
| 463 | else {
|
---|
| 464 | if (zero) {
|
---|
| 465 | omit = true;
|
---|
| 466 | *buf ++ = ':';
|
---|
| 467 | }
|
---|
| 468 | buf += convert_hexdigit(buf, ntohs(p_addr->s6_addr16[ix]), 16, 0, ' ');
|
---|
| 469 | if (ix < 7)
|
---|
| 470 | *buf ++ = ':';
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | if (len6 == sizeof(T_IN6_ADDR) / 2 - 2) {
|
---|
| 475 | T_IN4_ADDR ipv4addr;
|
---|
| 476 |
|
---|
| 477 | ipv4addr = ntohl(p_addr->s6_addr32[3]);
|
---|
| 478 | buf += convert_hexdigit(buf, (uint_t)((ipv4addr >> 24) & 0xff), 10, 0, ' ');
|
---|
| 479 | *(buf ++) = '.';
|
---|
| 480 | buf += convert_hexdigit(buf, (uint_t)((ipv4addr >> 16) & 0xff), 10, 0, ' ');
|
---|
| 481 | *(buf ++) = '.';
|
---|
| 482 | buf += convert_hexdigit(buf, (uint_t)((ipv4addr >> 8) & 0xff), 10, 0, ' ');
|
---|
| 483 | *(buf ++) = '.';
|
---|
| 484 | buf += convert_hexdigit(buf, (uint_t)((ipv4addr ) & 0xff), 10, 0, ' ');
|
---|
| 485 | }
|
---|
| 486 | }
|
---|
| 487 | *buf = '\0';
|
---|
| 488 | return start;
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | /*
|
---|
| 492 | * in6_cksum -- IPv6 ã®ãã©ã³ã¹ãã¼ã層ãããã®ãã§ãã¯ãµã ãè¨ç®ããã
|
---|
| 493 | *
|
---|
| 494 | * 注æ: æ»ãå¤ã¯ãããã¯ã¼ã¯ãã¤ããªã¼ã
|
---|
| 495 | */
|
---|
| 496 |
|
---|
| 497 | uint16_t
|
---|
| 498 | in6_cksum (T_NET_BUF *nbuf, uint8_t proto, uint_t off, uint_t len)
|
---|
| 499 | {
|
---|
| 500 | uint32_t sum;
|
---|
| 501 | uint_t align;
|
---|
| 502 |
|
---|
| 503 | /* 4 ãªã¯ãããå¢çã®ãã¼ã¿é· */
|
---|
| 504 | align = (len + 3) >> 2 << 2;
|
---|
| 505 |
|
---|
| 506 | /* 4 ãªã¯ãããå¢çã¾ã§ããã£ã³ã°ã§åããã*/
|
---|
| 507 | if (align > len)
|
---|
| 508 | memset((uint8_t*)nbuf->buf + off + len, 0, align - len);
|
---|
| 509 |
|
---|
| 510 | sum = in_cksum_sum(nbuf->buf + off, align)
|
---|
| 511 | + in_cksum_sum(&GET_IP6_HDR(nbuf)->src, sizeof(T_IN6_ADDR) * 2)
|
---|
| 512 | + len + proto;
|
---|
| 513 | sum = in_cksum_carry(sum);
|
---|
| 514 |
|
---|
| 515 | return ~htons((uint16_t)sum);
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | /*
|
---|
| 519 | * get_ip6_hdr_size -- æ¡å¼µããããå«ãã IPv6 ãããé·ãè¿ãã
|
---|
| 520 | */
|
---|
| 521 |
|
---|
| 522 | uint_t
|
---|
| 523 | get_ip6_hdr_size (T_NET_BUF *nbuf)
|
---|
| 524 | {
|
---|
| 525 | T_IP6_HDR *iph = GET_IP6_HDR(nbuf);
|
---|
| 526 | uint_t size = IP6_HDR_SIZE, hsize;
|
---|
| 527 | uint8_t curr = iph->next, next;
|
---|
| 528 | uint8_t *hdr = ((uint8_t *)iph) + IP6_HDR_SIZE;
|
---|
| 529 |
|
---|
| 530 | while (1) {
|
---|
| 531 | next = *hdr;
|
---|
| 532 | if (curr ==IPPROTO_NONE) /* 次ãããç¡ã */
|
---|
| 533 | break;
|
---|
| 534 | else if (curr == IPPROTO_FRAGMENT) /* æçå */
|
---|
| 535 | hsize = sizeof(T_IP6_FRAG_HDR);
|
---|
| 536 | else if (curr == IPPROTO_AH) /* IPv6 èªè¨¼ */
|
---|
| 537 | hsize = (((T_IP6_AH_HDR *)hdr)->len + 2) * 4;
|
---|
| 538 | else if (curr == IPPROTO_HOPOPTS || /* ä¸ç¶ç¹ (Hop-by-Hop) ãªãã·ã§ã³ */
|
---|
| 539 | curr == IPPROTO_DSTOPTS || /* IPv6 çµç¹ãªãã·ã§ã³ */
|
---|
| 540 | curr == IPPROTO_ROUTING) /* çµè·¯å¶å¾¡ */
|
---|
| 541 | hsize = (((T_IP6_EXT_HDR *)hdr)->len + 1) * 8;
|
---|
| 542 | else
|
---|
| 543 | break;
|
---|
| 544 | size += hsize;
|
---|
| 545 | hdr += hsize;
|
---|
| 546 | curr = next;
|
---|
| 547 | }
|
---|
| 548 | return size;
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | /*
|
---|
| 552 | * in6_plen2pmask -- ãã¬ãã£ãã¯ã¹é·ãããã¹ã¯ãçæããã
|
---|
| 553 | */
|
---|
| 554 |
|
---|
| 555 | void
|
---|
| 556 | in6_plen2pmask (T_IN6_ADDR *mask, uint_t prefix_len)
|
---|
| 557 | {
|
---|
| 558 | uint8_t *ptr, bit;
|
---|
| 559 |
|
---|
| 560 | memset(mask->s6_addr + prefix_len / 8, 0, (128 - prefix_len + 7) / 8);
|
---|
| 561 | for (ptr = mask->s6_addr; prefix_len > 0; ptr ++) {
|
---|
| 562 | for (bit = 0x80; bit && (prefix_len > 0); prefix_len --) {
|
---|
| 563 | *ptr |= bit;
|
---|
| 564 | bit >>= 1;
|
---|
| 565 | }
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | /*
|
---|
| 570 | * in6_rtalloc -- ã«ã¼ãã£ã³ã°è¡¨ãæ¢ç´¢ããã
|
---|
| 571 | */
|
---|
| 572 |
|
---|
| 573 | const T_IN6_ADDR *
|
---|
| 574 | in6_rtalloc (T_IFNET *ifp, const T_IN6_ADDR *dst)
|
---|
| 575 | {
|
---|
| 576 | if (IN6_IS_ADDR_LINKLOCAL(dst) || IN6_IS_ADDR_MULTICAST(dst))
|
---|
| 577 | return dst;
|
---|
| 578 | else {
|
---|
| 579 | T_IN6_IFADDR *ia;
|
---|
| 580 | SYSTIM now;
|
---|
| 581 | int_t ix;
|
---|
| 582 |
|
---|
| 583 | /*
|
---|
| 584 | * ãµã¤ããã¼ã«ã«ã¢ãã¬ã¹ãéç´å¯è½ï¼ã°ãã¼ãã«ï¼ã¢ãã¬ã¹ã®å ´åã¯ã
|
---|
| 585 | * åä¸ãªã³ã¯å
|
---|
| 586 | ã®ãã¼ãã§ãããããã§ãã¯ããã
|
---|
| 587 | */
|
---|
| 588 |
|
---|
| 589 | syscall(get_tim(&now));
|
---|
| 590 | now /= SYSTIM_HZ;
|
---|
| 591 |
|
---|
| 592 | /* æ¨å¥¨æå¹æéå
|
---|
| 593 | ã®ã¢ãã¬ã¹ãæ¢ç´¢ããã*/
|
---|
| 594 | for (ix = NUM_IN6_IFADDR_ENTRY; ix -- > 0; ) {
|
---|
| 595 | ia = &ifp->in6_ifaddrs[ix];
|
---|
| 596 | if (IFA6_IS_READY(ia) &&
|
---|
| 597 | in6_are_prefix_equal(dst, &ia->addr, ia->prefix_len) &&
|
---|
| 598 | (int32_t)(ia->lifetime.preferred - now) > 0) {
|
---|
| 599 | /* ia->lifetime.preferred > now */
|
---|
| 600 | return dst;
|
---|
| 601 | }
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | /* æå¹æéå
|
---|
| 605 | ã®ã¢ãã¬ã¹ãæ¢ç´¢ããã*/
|
---|
| 606 | for (ix = NUM_IN6_IFADDR_ENTRY; ix -- > 0; ) {
|
---|
| 607 | ia = &ifp->in6_ifaddrs[ix];
|
---|
| 608 | if (IFA6_IS_READY(ia) &&
|
---|
| 609 | in6_are_prefix_equal(dst, &ia->addr, ia->prefix_len) &&
|
---|
| 610 | (int32_t)(ia->lifetime.expire - now) > 0)
|
---|
| 611 | /* ia->lifetime.expire > now */
|
---|
| 612 | return dst;
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | /*
|
---|
| 616 | * ãã¬ãã£ãã¯ã¹ãæ¢ç´¢ããã
|
---|
| 617 | */
|
---|
| 618 | if (nd6_onlink_prefix_lookup (dst) != NULL)
|
---|
| 619 | return dst;
|
---|
| 620 |
|
---|
| 621 | /*
|
---|
| 622 | * éççµè·¯è¡¨ãæ¢ç´¢ããã
|
---|
| 623 | */
|
---|
| 624 |
|
---|
| 625 | #if NUM_IN6_ROUTE_ENTRY > 0
|
---|
| 626 |
|
---|
| 627 | syscall(wai_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 628 | for (ix = NUM_IN6_ROUTE_ENTRY; ix --; ) {
|
---|
| 629 | if ((routing6_tbl[ix].flags & IN_RTF_DEFINED) &&
|
---|
| 630 | in6_are_prefix_equal(dst, &routing6_tbl[ix].target,
|
---|
| 631 | routing6_tbl[ix].prefix_len)) {
|
---|
| 632 |
|
---|
| 633 | /*
|
---|
| 634 | * åãç´ãã«ããã¨ã³ããªã¯ãæå¹æéãåããæå»ã延é·ããã
|
---|
| 635 | * expire ã®åä½ã¯ [s]ã
|
---|
| 636 | * TMO_IN_REDIRECT ã®åä½ã¯ [ms]ã
|
---|
| 637 | */
|
---|
| 638 | if (ix > NUM_IN6_STATIC_ROUTE_ENTRY) {
|
---|
| 639 | SYSTIM now;
|
---|
| 640 |
|
---|
| 641 | syscall(get_tim(&now));
|
---|
| 642 | routing6_tbl[ix].expire = now / SYSTIM_HZ + TMO_IN_REDIRECT / 1000;
|
---|
| 643 | }
|
---|
| 644 |
|
---|
| 645 | syscall(sig_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 646 | return &routing6_tbl[ix].gateway;
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 | syscall(sig_sem(SEM_IN6_ROUTING_TBL));
|
---|
| 650 |
|
---|
| 651 | #endif /* of #if NUM_IN6_ROUTE_ENTRY > 0 */
|
---|
| 652 |
|
---|
| 653 | /*
|
---|
| 654 | * ãã£ãã©ã«ãã«ã¼ã¿ã»ãªã¹ããæ¢ç´¢ããã
|
---|
| 655 | */
|
---|
| 656 | return nd6_router_lookup();
|
---|
| 657 | }
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0
|
---|
| 661 |
|
---|
| 662 | /*
|
---|
| 663 | * in6_gateway_lookup -- ã«ã¼ãã£ã³ã°è¡¨ã®ã«ã¼ã¿ãæ¢ç´¢ããã
|
---|
| 664 | */
|
---|
| 665 |
|
---|
| 666 | T_IN6_RTENTRY *
|
---|
| 667 | in6_gateway_lookup (const T_IN6_ADDR *gw)
|
---|
| 668 | {
|
---|
| 669 | int_t ix;
|
---|
| 670 |
|
---|
| 671 | for (ix = NUM_IN6_ROUTE_ENTRY; ix --; )
|
---|
| 672 | if ((routing6_tbl[ix].flags & IN_RTF_DEFINED) &&
|
---|
| 673 | IN6_ARE_ADDR_EQUAL(&routing6_tbl[ix].gateway, gw))
|
---|
| 674 | return &routing6_tbl[ix];
|
---|
| 675 | return NULL;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | /*
|
---|
| 679 | * in6_rtredirect -- ã«ã¼ãã£ã³ã°è¡¨ã«ã¨ã³ããªãç»é²ããã
|
---|
| 680 | *
|
---|
| 681 | * 注æ: å¼æ° tmo ã®åä½ã¯ [ms]ã
|
---|
| 682 | */
|
---|
| 683 |
|
---|
| 684 | void
|
---|
| 685 | in6_rtredirect (const T_IN6_ADDR *gateway, const T_IN6_ADDR *target, uint_t prefix_len, uint8_t flags, uint32_t tmo)
|
---|
| 686 | {
|
---|
| 687 | T_IN6_RTENTRY *frt;
|
---|
| 688 |
|
---|
| 689 | frt = in6_rtnewentry(flags, tmo);
|
---|
| 690 | frt->gateway = *gateway;
|
---|
| 691 | frt->target = *target;
|
---|
| 692 | frt->prefix_len = prefix_len;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | #endif /* of #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
| 696 |
|
---|
| 697 | #if NUM_IN6_HOSTCACHE_ENTRY > 0
|
---|
| 698 |
|
---|
| 699 | /*
|
---|
| 700 | * in6_hostcache_lookup -- IPv6 ãã¹ããã£ãã·ã¥ãæ¢ç´¢ããã
|
---|
| 701 | */
|
---|
| 702 |
|
---|
| 703 | static T_IN6_HOSTCACHE_ENTRY*
|
---|
| 704 | in6_hostcache_lookup (const T_IN6_ADDR *dst)
|
---|
| 705 | {
|
---|
| 706 | int_t ix;
|
---|
| 707 |
|
---|
| 708 | for (ix = NUM_IN6_HOSTCACHE_ENTRY; ix -- > 0; ) {
|
---|
| 709 | if (IN6_ARE_ADDR_EQUAL(dst, &in6_hostcache[ix].dst))
|
---|
| 710 | return &in6_hostcache[ix];
|
---|
| 711 | }
|
---|
| 712 | return NULL;
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | /*
|
---|
| 716 | * in6_hostcache_update -- IPv6 ãã¹ããã£ãã·ã¥ãæ´æ°ããã
|
---|
| 717 | */
|
---|
| 718 |
|
---|
| 719 | void
|
---|
| 720 | in6_hostcache_update (T_IN6_ADDR *dst, uint32_t mtu)
|
---|
| 721 | {
|
---|
| 722 | T_IN6_HOSTCACHE_ENTRY *hc;
|
---|
| 723 | SYSTIM now, old;
|
---|
| 724 | int_t ix, oix;
|
---|
| 725 |
|
---|
| 726 | syscall(get_tim(&now));
|
---|
| 727 |
|
---|
| 728 | /* æ¢ã«ç»é²ããã¦ãããæ¢ç´¢ããã*/
|
---|
| 729 | if ((hc = in6_hostcache_lookup (dst)) == NULL) {
|
---|
| 730 |
|
---|
| 731 | /* 空ãã®ãã¹ããã£ãã·ã¥ãæ¢ãã*/
|
---|
| 732 | for (ix = NUM_IN6_HOSTCACHE_ENTRY; ix -- > 0; ) {
|
---|
| 733 | if (IN6_IS_HOSTCACHE_FREE(&in6_hostcache[ix]))
|
---|
| 734 | break;
|
---|
| 735 | }
|
---|
| 736 |
|
---|
| 737 | if (ix < 0) {
|
---|
| 738 | /*
|
---|
| 739 | * 空ããç¡ãæã¯ãæå¹æéã®åããæéãã
|
---|
| 740 | * æãçããã¹ããã£ãã·ã¥ãç½®æããã
|
---|
| 741 | */
|
---|
| 742 | old = now - 1;
|
---|
| 743 | oix = 0;
|
---|
| 744 | for (ix = NUM_IN6_HOSTCACHE_ENTRY; ix -- > 0; ) {
|
---|
| 745 | hc = &in6_hostcache[ix];
|
---|
| 746 | if (IN6_IS_HOSTCACHE_BUSY(hc) && (int32_t)(hc->expire - old) < 0) {
|
---|
| 747 | /* hc->expire < old */
|
---|
| 748 | oix = ix;
|
---|
| 749 | old = hc->expire;
|
---|
| 750 | }
|
---|
| 751 | }
|
---|
| 752 | ix = oix;
|
---|
| 753 | }
|
---|
| 754 | hc = &in6_hostcache[ix];
|
---|
| 755 | }
|
---|
| 756 | else if (mtu > hc->mtu &&
|
---|
| 757 | (int32_t)(hc->expire - now) >= (IN6_HOSTCACHE_EXPIRE - IN6_HOSTCACHE_INCREASE)) {
|
---|
| 758 |
|
---|
| 759 | /*
|
---|
| 760 | * æ¢ã«ç»é²ããã¦ãã¦ãæ°ãã MTU ããç»é²ããã¦ãã MTU ãã大ããã¨ãã
|
---|
| 761 | * IN6_HOSTCACHE_INCREASEï¼æ¨å¥¨ 10 åï¼éã¯æ´æ°ããªãã
|
---|
| 762 | */
|
---|
| 763 | return;
|
---|
| 764 | }
|
---|
| 765 | hc->dst = *dst;
|
---|
| 766 | hc->expire = now + IN6_HOSTCACHE_EXPIRE;
|
---|
| 767 | hc->mtu = mtu;
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | /*
|
---|
| 771 | * in6_hostcache_getmtu -- IPv6 ãã¹ããã£ãã·ã¥ããã MTU ãåå¾ããã
|
---|
| 772 | *
|
---|
| 773 | * æ»ãå¤ã 0 ã§ããã°ããã¹ããã£ãã·ã¥ã«ç»é²ããã¦ããªãã
|
---|
| 774 | */
|
---|
| 775 |
|
---|
| 776 | uint32_t
|
---|
| 777 | in6_hostcache_getmtu (const T_IN6_ADDR *dst)
|
---|
| 778 | {
|
---|
| 779 | T_IN6_HOSTCACHE_ENTRY *hc;
|
---|
| 780 |
|
---|
| 781 | /* æ¢ã«ç»é²ããã¦ãããæ¢ç´¢ããã*/
|
---|
| 782 | if ((hc = in6_hostcache_lookup(dst)) == NULL)
|
---|
| 783 | return 0;
|
---|
| 784 | else
|
---|
| 785 | return hc->mtu;
|
---|
| 786 | }
|
---|
| 787 |
|
---|
| 788 | /*
|
---|
| 789 | * in6_hostcache_timer -- IPv6 ãã¹ããã£ãã·ã¥æ´æ°ã¿ã¤ãã¼
|
---|
| 790 | *
|
---|
| 791 | * 1ç§å¨æã§èµ·åãããã
|
---|
| 792 | */
|
---|
| 793 |
|
---|
| 794 | static void
|
---|
| 795 | in6_hostcache_timer (void)
|
---|
| 796 | {
|
---|
| 797 | static int_t interval = IN6_HOSTCACHE_PRUNE / SYSTIM_HZ;
|
---|
| 798 |
|
---|
| 799 | SYSTIM now;
|
---|
| 800 |
|
---|
| 801 | interval --;
|
---|
| 802 | if (interval <= 0) {
|
---|
| 803 | syscall(get_tim(&now));
|
---|
| 804 | interval = IN6_HOSTCACHE_PRUNE / SYSTIM_HZ;
|
---|
| 805 | }
|
---|
| 806 | }
|
---|
| 807 |
|
---|
| 808 | #endif /* of #if NUM_IN6_HOSTCACHE_ENTRY > 0 */
|
---|
| 809 |
|
---|
| 810 | /*
|
---|
| 811 | * in6_timer -- IPv6 å
|
---|
| 812 | ±éã¿ã¤ãã¼
|
---|
| 813 | *
|
---|
| 814 | * 1ç§å¨æã§èµ·åãããã
|
---|
| 815 | */
|
---|
| 816 |
|
---|
| 817 | static void
|
---|
| 818 | in6_timer (void)
|
---|
| 819 | {
|
---|
| 820 | #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0
|
---|
| 821 |
|
---|
| 822 | in6_rttimer();
|
---|
| 823 |
|
---|
| 824 | #endif /* of #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
| 825 |
|
---|
| 826 | #ifdef IP6_CFG_FRAGMENT
|
---|
| 827 |
|
---|
| 828 | frag6_timer();
|
---|
| 829 |
|
---|
| 830 | #endif /* of #ifdef IP6_CFG_FRAGMENT */
|
---|
| 831 |
|
---|
| 832 | #if NUM_IN6_HOSTCACHE_ENTRY > 0
|
---|
| 833 |
|
---|
| 834 | in6_hostcache_timer();
|
---|
| 835 |
|
---|
| 836 | #endif /* of #if NUM_IN6_HOSTCACHE_ENTRY > 0 */
|
---|
| 837 |
|
---|
| 838 | timeout((callout_func)in6_timer, NULL, IN_TIMER_TMO);
|
---|
| 839 | }
|
---|
| 840 |
|
---|
| 841 | /*
|
---|
| 842 | * in6_init -- IPv6 å
|
---|
| 843 | ±éæ©è½ãåæåããã
|
---|
| 844 | */
|
---|
| 845 |
|
---|
| 846 | void
|
---|
| 847 | in6_init (void)
|
---|
| 848 | {
|
---|
| 849 | #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0
|
---|
| 850 |
|
---|
| 851 | in6_rtinit();
|
---|
| 852 |
|
---|
| 853 | #endif /* of #if NUM_IN6_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
| 854 |
|
---|
| 855 | timeout((callout_func)nd6_timer, NULL, ND6_TIMER_TMO);
|
---|
| 856 | timeout((callout_func)in6_timer, NULL, IN_TIMER_TMO);
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | /*
|
---|
| 860 | * in6_is_dstaddr_accept -- å®å
|
---|
| 861 | ã¢ãã¬ã¹ã¨ãã¦æ£ããããã§ãã¯ããã
|
---|
| 862 | */
|
---|
| 863 |
|
---|
| 864 | bool_t
|
---|
| 865 | in6_is_dstaddr_accept (const T_IN6_ADDR *myaddr, const T_IN6_ADDR *dstaddr)
|
---|
| 866 | {
|
---|
| 867 | if (IN6_IS_ADDR_UNSPECIFIED(myaddr))
|
---|
| 868 | return in6_lookup_ifaddr(IF_GET_IFNET(), dstaddr) != NULL;
|
---|
| 869 | else
|
---|
| 870 | return IN6_ARE_ADDR_EQUAL(dstaddr, myaddr);
|
---|
| 871 | }
|
---|
| 872 |
|
---|
| 873 | #if defined(DHCP6_CLI_CFG)
|
---|
| 874 |
|
---|
| 875 | /*
|
---|
| 876 | * in6_add_ifaddr -- ã¤ã³ã¿ãã§ã¼ã¹ã« IPv6 ã¢ãã¬ã¹ãè¨å®ããã
|
---|
| 877 | *
|
---|
| 878 | * vltime 㨠pltime ã®åä½ã¯[s]
|
---|
| 879 | */
|
---|
| 880 |
|
---|
| 881 | static ER
|
---|
| 882 | in6_add_ifaddr (T_IN6_ADDR *addr, uint_t prefix_len,
|
---|
| 883 | uint32_t vltime, uint32_t pltime)
|
---|
| 884 | {
|
---|
| 885 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 886 | T_IN6_IFADDR *ia = NULL;
|
---|
| 887 | int_t ix;
|
---|
| 888 |
|
---|
| 889 | /* 空ãã®ã¨ã³ããªã¼ãæ¢ãã*/
|
---|
| 890 | ix = 0;
|
---|
| 891 | while (true) {
|
---|
| 892 | ia = in6ifa_ifpwithix(ifp, ix ++);
|
---|
| 893 |
|
---|
| 894 | /* 空ããç¡ããã°ã¨ã©ã¼ */
|
---|
| 895 | if (ia == NULL)
|
---|
| 896 | return E_OBJ;
|
---|
| 897 |
|
---|
| 898 | if ((ia->flags & IN6_IFF_DEFINED) == 0)
|
---|
| 899 | break;
|
---|
| 900 | }
|
---|
| 901 |
|
---|
| 902 | /* ç»é²ããã*/
|
---|
| 903 | return in6_update_ifa(ifp, ia, addr, prefix_len, vltime, pltime,
|
---|
| 904 | IN6_RTR_IX_UNREACH, ND6_PREFIX_IX_INVALID, 0);
|
---|
| 905 | }
|
---|
| 906 |
|
---|
| 907 | /*
|
---|
| 908 | * in6_upd_ifaddr -- ã¤ã³ã¿ãã§ã¼ã¹ã«è¨å®ããã¦ãã IPv6 ã¢ãã¬ã¹ãæ´æ°ããã
|
---|
| 909 | *
|
---|
| 910 | * ç»é²ããã¦ããªããã°ã追å ããã
|
---|
| 911 | * vltime 㨠pltime ã®åä½ã¯[s]
|
---|
| 912 | */
|
---|
| 913 |
|
---|
| 914 | ER
|
---|
| 915 | in6_upd_ifaddr (T_IN6_ADDR *addr, uint_t prefix_len,
|
---|
| 916 | uint32_t vltime, uint32_t pltime)
|
---|
| 917 | {
|
---|
| 918 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 919 | T_IN6_IFADDR *ia;
|
---|
| 920 | int_t ix;
|
---|
| 921 |
|
---|
| 922 | /*
|
---|
| 923 | * ã¢ãã¬ã¹ãä¸è´ããã¨ã³ããªã¼ãæ¢ãã
|
---|
| 924 | * ç¡ããã°ç»é²ããã
|
---|
| 925 | */
|
---|
| 926 | if ((ix = in6_addr2ifaix(addr)) == IPV6_IFADDR_IX_INVALID)
|
---|
| 927 | return in6_add_ifaddr(addr, prefix_len, vltime, pltime);
|
---|
| 928 |
|
---|
| 929 | /*
|
---|
| 930 | * ã¤ã³ããã¯ã¹çªå·ãããã¨ã³ããªã¼ã«å¤æããã
|
---|
| 931 | * ã¨ã©ã¼ã«ãªããªãã¯ãã§ãããã確èªããã
|
---|
| 932 | */
|
---|
| 933 | if ((ia = in6ifa_ifpwithix (ifp, ix)) == NULL)
|
---|
| 934 | return E_OBJ;
|
---|
| 935 |
|
---|
| 936 | /* æ´æ°ããã*/
|
---|
| 937 | return in6_update_ifa(ifp, ia, addr, prefix_len, vltime, pltime,
|
---|
| 938 | IN6_RTR_IX_UNREACH, ND6_PREFIX_IX_INVALID, 0);
|
---|
| 939 | }
|
---|
| 940 |
|
---|
| 941 | /*
|
---|
| 942 | * in6_del_ifaddr -- ã¤ã³ã¿ãã§ã¼ã¹ã«è¨å®ããã¦ãã IPv6 ã¢ãã¬ã¹ãåé¤ããã
|
---|
| 943 | */
|
---|
| 944 |
|
---|
| 945 | ER
|
---|
| 946 | in6_del_ifaddr (T_IN6_ADDR *addr)
|
---|
| 947 | {
|
---|
| 948 | T_IFNET *ifp = IF_GET_IFNET();
|
---|
| 949 | int_t ix;
|
---|
| 950 |
|
---|
| 951 | /* ã¢ãã¬ã¹ãä¸è´ããã¨ã³ããªã¼ãæ¢ãã*/
|
---|
| 952 | if ((ix = in6_addr2ifaix(addr)) != IPV6_IFADDR_IX_INVALID) {
|
---|
| 953 |
|
---|
| 954 | /* ã¨ã³ããªã¼ãç¡å¹ã«ããã*/
|
---|
| 955 | ifp->in6_ifaddrs[ix].flags &= ~IN6_IFF_DEFINED;
|
---|
| 956 | return E_OK;
|
---|
| 957 | }
|
---|
| 958 | return E_PAR;
|
---|
| 959 | }
|
---|
| 960 |
|
---|
| 961 | #endif /* of #if defined(DHCP6_CLI_CFG) */
|
---|
| 962 |
|
---|
| 963 | #endif /* of #ifdef _IP6_CFG */
|
---|