人é¡ã¯å¤§è¢è£ã§ãããç§ã«ã¯å³ããã£ãã¨ãã話ã
IPv6 対å¿ã®ããã°ã©ã ã¨ã¯ï¼
ãããã¨ããã«æ¸ããã¦ããã®ã§çç¥ã以ä¸ã®è¨äºãªã©ãåèã«ã©ããã
æçã«ã¾ã¨ããã¨
gethostbyname(3)
ã§ã¯ãªãgetaddrinfo(3)
ã使ã£ã¦åå解決ããaccept(2)
ãgetpeername(2)
ã§è¿ãã¢ãã¬ã¹æ å ±ã¯struct sockaddr_storage
ã«æ ¼ç´ããlisten
ããã½ã±ããã¯AF_INET6
æå®ã§ä½ã㨠IPv4/v6 両対å¿ã«ãªã
ã·ã³ãã«ã§ããããããã¾ã§ã¯ã
è½ã¨ãç©´ï¼ï¼ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹
IPv6 ã®ã¢ãã¬ã¹ä½ç³»ã¯ IPv4 ã¨ããªãç°ãªãã¾ããæãããã®ããªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ã§ãã
ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ã¯ã«ã¼ãã£ã³ã°ãããªãã®ã§ããªã³ã¯ï¼âL2ãããã¯ã¼ã¯ï¼å ã§ä¸æã§ããããããã°è¯ããã®ã§ãã ãã¹ã¦ã®ã¤ã³ã¿ãã§ã¼ã¹ã¯èªåçã« MAC ã¢ãã¬ã¹ããçæããããªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ãæã£ã¦ãã¾ãã ãã®ãããåä¸ã®ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ãè¤æ°åããã¹ããæã¤å ´åãããã¾ãï¼VLANãããªãã¸ãªã©ã§ï¼ã
ããã§ãã©ã®ãªã³ã¯ã®ãã¼ã«ã«ã¢ãã¬ã¹ããæå®ããããããªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ã®å¾ãã«ã¯ %eth0
ã®ããã«ã¹ã³ã¼ããæå®ãããã¨ãã§ãã¾ãããããªæãã
fe80::fcff:ffff:fead:beaf%eth1
ãã¦ãIPv4 ã¢ãã¬ã¹æååã®è§£æã«ã¯ inet_aton(3)
ã使ã£ã¦ãããã¨ã§ããããIPv6 ã¢ãã¬ã¹åãã«ã¯ inet_pton(3)
ãç¨æããã¦ãã¾ãã
ã¨ããããinet_pton
ã¯ãã®ã¹ã³ã¼ãä»ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ã解éã§ãã¾ããããããã IPv6 ã¢ãã¬ã¹ãæ ¼ç´ãã struct in6_addr
ã® 128 bit ã§ã¯ã¹ã³ã¼ãèå¥åã¯æ ¼ç´ã§ããªãã®ã§ãã
ã©ããããã¨ããã¨ãgetaddrinfo
ã使ãã¾ããgetaddrinfo
ãè¿ã struct sockaddr_in6
ã¯ä»¥ä¸ã®ãããªæ§é ä½ã§ãã
struct sockaddr_in6 { sa_family_t sin6_family; /* AF_INET6 */ in_port_t sin6_port; /* port number */ uint32_t sin6_flowinfo; /* IPv6 flow information */ struct in6_addr sin6_addr; /* IPv6 address */ uint32_t sin6_scope_id; /* Scope ID (new in 2.4) */ };
ãã® sin6_scope_id
ããªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ãæå±ãããªã³ã¯ã示ã ID ã«ãªã£ã¦ãã¾ãï¼é常㯠0ï¼ã
ãã¨ãã°èªãã¹ãããã IPv6 ã¢ãã¬ã¹ãæã£ã¦ãããå¤å®ããã«ã¯ãsin6_addr
ã®æ¯è¼ã«å ãã¦ãsin6_scope_id
ã®æ¯è¼ãå¿
è¦ã«ãªãã¾ãã以ä¸ã«å®è£
ä¾ãæãã¾ãã
è½ã¨ãç©´ï¼ï¼DNS AAAA ã¬ã³ã¼ã
ä¸ã®ä¸ã® DNS ãµã¼ãã¼ã«ã¯ãåå¨ããªãã¬ã³ã¼ãã¸ã®åãåãããåã«æ¨ã¦ããã®ãããããã§ã(1, 2)ãIPv6 ã¢ãã¬ã¹ã¯ DNS ã® AAAA ã¬ã³ã¼ããåãåãããããã§ãããAAAA ã¬ã³ã¼ããæããªããã¹ãåããã®ãããªåé¡ã®ãã DNS ãµã¼ãã¼ã«åãåãããã¨ã¿ã¤ã ã¢ã¦ãã¾ã§æ°ç§å¾ ãããããã¨ã«ãªãã¾ãã
ãããã¢ããªã±ã¼ã·ã§ã³å´ã§åé¿ããã«ã¯ãIPv4 ã¢ãã¬ã¹ãåªå çã«åãåããã¾ãããã以ä¸ã«å®è£ ä¾ãæãã¾ãã
è½ã¨ãç©´ï¼ï¼Ubuntu 12.04 ç¹æã®åé¡
(è¨æ£: 2014-08-26 18:06 Ubuntu 12.04 ã®åé¡ã§ãããUbuntu 14.04 ã§ã¯ãããã®å 容ãæ¹åãããåé¡ã¯çºçããªãããã§ãã)
æè¿ã® Linux ã¯ããã©ã«ã㧠IPv6 ãæå¹åããã¦ãã¾ããIPv6 ãæå¹ã ã¨ãåè¿°ã®ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ãèªåçã«åã¤ã³ã¿ãã§ã¼ã¹ã«è¨å®ããã¾ãã
ãã¦ãgetaddrinfo
ã§æ¥ç¶å
ãã¹ãã®ã¢ãã¬ã¹ãåãåãããéã«ãAI_ADDRCONFIG
ã¨ãããªãã·ã§ã³ãæå®ã§ãã¾ãã以ä¸ã«èª¬æãå¼ç¨ãã¾ãããèªãã¹ãã IPv4(v6) ã¢ãã¬ã¹ããã£ã¦ããå ´åã®ã¿æ¥ç¶å
ã® IPv4(v6) ã¢ãã¬ã¹ãè¿ãã¦ãããæé©åã®ããã®ãªãã·ã§ã³ã§ãã
If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses
are returned in the list pointed to by res only if the local system has
at least one IPv4 address configured, and IPv6 addresses are returned
only if the local system has at least one IPv6 address configured. The
loopback address is not considered for this case as valid as a
configured address.
IPv6 ãæå¹ãªç¶æ
ã§ã¯ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ãè¨å®ãããã®ã§ãAI_ADDRCONFIG
ãæå®ãã¦ã IPv6 ã¢ãã¬ã¹ã常ã«è¿ããã¨ããæåã«ãªãããã§ãã
ã¨ããããã®ç¶æ ã§ãåè¿°ã®ããã¦ãªã DNS ãµã¼ãã¼ã使ãããªãã㤠IPv4 ãåªå ãã¦åãåããã対çããã¦ããªãã¢ããªã±ã¼ã·ã§ã³ã¯ DNS ã« AAAA ã¬ã³ã¼ããåãåããã¦ãã¾ããã¿ã¤ã ã¢ã¦ãã¾ã§æ°ç§å¾ ããããã¨ããä¸å ·åãçºçããããã§ãã
ãã®ç¾è±¡ã«å¯¾å¿ããããã«ãUbuntu 12.04 ã® glibc ã«ã¯ä»¥ä¸ã®ããã(debian/patches/any/local-ipv6-lookup.diff)ãé©ç¨ããã¦ãã¾ãã (Ubuntu 14.04 ã® local-ipv6-lookup.diff ã¯æ¹åããã¦ãã¾ãã)
--- sysdeps/unix/sysv/linux/check_pf.c~ 2010-04-15 16:09:03.661086635 +0200 +++ sysdeps/unix/sysv/linux/check_pf.c 2010-04-15 17:50:08.401085393 +0200 @@ -178,7 +178,8 @@ } else { - if (!IN6_IS_ADDR_LOOPBACK (address)) + if (!IN6_IS_ADDR_LOOPBACK (address) + && !IN6_IS_ADDR_LINKLOCAL(address)) seen_ipv6 = true; } }
ãã®ãããã®å¹æã¯ãAI_ADDRCONFIG
ãæå®ããã¦ã㦠IPv6 ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ãå©ç¨ã§ããç¶æ
ã§ãã£ã¦ããIPv6 ã®åãåãããããªãããã«ãã ã¯ã ã®ãã®ã§ããããã§ããå®éã«ã¯ AAAA åãåãããææ¢ããã ãã§ãªããIPv6 ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹æååã®è§£æã¾ã§ææ¢ãã¦ãã¾ãã¾ãã
ã©ããããã¨ãã¨ããã¨ãUbuntu 12.04 ã§ãªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ã ã使ã£ã¦éä¿¡ããã¢ããªãä½ãå ´åãgetaddrinfo
ã« AI_ADDRCONFIG
ãã©ã°ãä»ãã¦ããã¨ããªã³ã¯ãã¼ã«ã«ã¢ãã¬ã¹ã®åãåããã«å¤±æãã¦éä¿¡ãã§ããªãã®ã§ãããªãã¨ãããã¨ã§ãããã
対å¿æ¹æ³ã¨ãã¦ã¯ AI_ADDRCONFIG
ãä»ããªãããã«ããã°ã¨ããããåé¿ã§ãã¾ãã
ã¾ã¨ã
IPv6 è¦å´ãããã©ããã¤æ®åãããã§ãããããããã¾ãã