From owner-IPv6-jp@jp.freebsd.org  Sun Jan 23 00:31:09 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id AAA87875;
	Sun, 23 Jan 2000 00:31:09 +0900 (JST)
	(envelope-from owner-IPv6-jp@jp.FreeBSD.org)
Received: from tortoise.jp.freebsd.org (root@tortoise.jp.FreeBSD.ORG [210.157.158.41])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id AAA87870
	for <IPv6-jp@jp.freebsd.org>; Sun, 23 Jan 2000 00:31:08 +0900 (JST)
	(envelope-from ume@mahoroba.org)
Received: from peace.mahoroba.org (IDENT:NcargyrH6uo4EG2x0w4MESCsj2/ntXqZlXuSYbD4ySn301H1kHdmJ2/5/GYA61QS@peace.calm.imasy.or.jp [3ffe:505:2:0:200:f8ff:fe05:3eae])
	by tortoise.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP/IPv6 id AAA21041
	for <IPv6-jp@jp.freebsd.org>; Sun, 23 Jan 2000 00:31:03 +0900 (JST)
	(envelope-from ume@mahoroba.org)
Received: from localhost (IDENT:E6i0H6kJqddL2DqMVahMTcWQWk0N5Tap4Iq240JhAnXZrG9ef2uk4KzS4L2ZPA2u@localhost [::1])
	by peace.mahoroba.org (8.10.0.Beta10/3.7W-peace) with ESMTP id e0MFUwi57663
	for <IPv6-jp@jp.freebsd.org>; Sun, 23 Jan 2000 00:30:58 +0900 (JST)
	(envelope-from ume@mahoroba.org)
Date: Sun, 23 Jan 2000 00:30:58 +0900 (JST)
Message-Id: <200001221530.e0MFUwi57663@peace.mahoroba.org>
To: IPv6-jp@jp.freebsd.org
X-Mailer: Mew version 1.95b3 on Emacs 20.5 / Mule 4.0
 =?iso-2022-jp?B?KBskQjJWMWMbKEIp?=
X-PGP-Public-Key: http://www.imasy.org/~ume/publickey.asc
X-PGP-Fingerprint: 6B 0C 53 FC 5D D0 37 91  05 D0 B3 EF 36 9B 6A BC
X-URL: http://www.imasy.org/~ume/
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Sun_Jan_23_00:30:53_2000_41)--"
Content-Transfer-Encoding: 7bit
From: Hajimu UMEMOTO (=?ISO-2022-JP?B?GyRCR19LXBsoQiA=?=
	=?ISO-2022-JP?B?GyRCSCUbKEI=?=) <ume@mahoroba.org>
X-Dispatcher: imput version 20000105(IM135)
Lines: 91
Reply-To: IPv6-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+990727
X-Sequence: IPv6-jp 513
Subject: [IPv6-jp 513] source address selection via gif
Errors-To: owner-IPv6-jp@jp.freebsd.org
Sender: owner-IPv6-jp@jp.freebsd.org
X-Originator: ume@mahoroba.org

----Next_Part(Sun_Jan_23_00:30:53_2000_41)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

  $BG_K\!w(BIMASY$B$G$9!#(B

  KAME $B$N(B source address selection $B$K$D$$$F<ALd$5$;$F2<$5$$!#(B
  IMPLEMENTATION $B$K!"(B

    1. If the source address is explicitly specified by the user
       (e.g. via the advanced API), the specified address is used.
    2. If there is an address assigned to the outgoing interface
       (which is usually determined by looking up the routing table)
       that has the same scope as the destination address, the address
       is used.
       This is the most typical case.
    3. If there is no address that satisfies the above condition,
       choose a global address assigned to one of the interfaces
       on the sending node.
    4. If there is no address that satisfies the above condition and
       there is no global address on the sending node, choose the
       address associated with the routing table entry for the destination.
       This is the last resort, which may cause scope violation.

$B$H$"$j$^$9!#<B:]!"$3$NDL$j$NF0$-$r$7$F$$$k$H;W$$$^$9!#(B
  outgoing if $B$,(B numbered $B$N>l9g!"(B2. $B$K$h$j(B destination address $B$K1~$8(B
$B$FA*Br$5$l$k$o$1$G$9$,!"(Boutgoing if $B$,(B unnumbered $B$J(B tunnel $B$N>l9g!"(B
3. $B$K$h$j!"0lHLE*$K$O(B NIC $B$K?6$i$l$?:G=i$N(B global address $B$,A*Br$5$l$k(B
$B$3$H$K$J$j!"(Bsource address selection $B$,M-8z$K5!G=$7$^$;$s!#(B
  $B5!G=$5$;$k$?$a$K$O!"(Bnumbered $B$J(B tunnel $B$r;H$$$J$5$$$H$$$&$3$H$J$N$G(B
$B$7$g$&$+!)(B $B$"$k$$$O!"(Brouter $B$H(B end node $B$OJ,$1$F9M$($J$5$$$H$$$&$3$H$J(B
$B$N$G$7$g$&$+!)(B $B$J$K$+$o$1$"$j$N$h$&$J5$$,$7$^$9$N$G!"$=$N?4$,CN$j$?$$(B
$B$G$9!#(B
  $BE:IU$N$h$&$J=$@5$r2C$($k$3$H$G!"(Bgif $B0J30$K?6$i$l$?(B global address $B$+(B
$B$iA*Br$G$-$k$h$&$K$J$k$H;W$$$^$9$,!"$J$<$=$N$h$&$K$J$C$F$$$J$$$N$G$7$g(B
$B$&$+!)(B $B$3$l$8$c%@%a$@$H$$$&2?$+M}M3$,$"$j$=$&$J5$$,$7$^$9!#(B

----Next_Part(Sun_Jan_23_00:30:53_2000_41)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: in6.c.diff
Content-Disposition: attachment; filename="in6.c.diff"

--- kame/kame/sys/netinet6/in6.c.orig	Fri Jan 21 20:05:16 2000
+++ kame/kame/sys/netinet6/in6.c	Sat Jan 22 03:41:04 2000
@@ -1973,7 +1973,12 @@
 	if (besta)
 		return besta;
 
+	besta = NULL;
+	blen = -1;
 	for (ia = in6_ifaddr; ia; ia = ia->ia_next) {
+		if (ia->ia6_ifpr && ia->ia6_ifpr->ifpr_ifp &&
+		    ia->ia6_ifpr->ifpr_ifp->if_type == IFT_GIF)
+			continue;
 		if (IPV6_ADDR_SCOPE_GLOBAL != 
 		    in6_addrscope(&(ia->ia_addr.sin6_addr)))
 			continue;
@@ -1989,8 +1994,20 @@
 				dep[1] = (struct in6_ifaddr *)ifa;
 			continue;
 		}
-		return ia;
+		if (besta) {
+			if (blen == -1)
+				blen = in6_matchlen(&besta->ia_addr.sin6_addr,
+						    dst);
+			tlen = in6_matchlen(&ia->ia_addr.sin6_addr, dst);
+			if (tlen > blen) {
+				blen = tlen;
+				besta = ia;
+			}
+		} else 
+			besta = ia;
 	}
+	if (besta)
+		return besta;
 
 	/* use the last-resort values, that are, deprecated addresses */
 	if (dep[0])

----Next_Part(Sun_Jan_23_00:30:53_2000_41)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Content-Description: My signature

$BG_K\(B $BH%(B $B!w(B $B%$%s%?!<%M%C%H8_=u2q2#IM(B  http://www.imasy.org/~ume/
ume@mahoroba.org  ume@bisd.hitachi.co.jp  ume@jp.FreeBSD.org
$B%W%m%0%i%`$O=q$$$??M$N0U?^$G$O$J$/=q$+$l$?DL$jF0$/(B

----Next_Part(Sun_Jan_23_00:30:53_2000_41)----
