diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/aspath.c gated-R3_5/src/aspath.c
--- gated-pub-ipv6-snapshot-0399/src/aspath.c	Sat Mar 27 09:31:26 1999
+++ gated-R3_5/src/aspath.c	Sat Mar 27 11:01:52 1999
@@ -122,7 +122,9 @@
     int num_allocated;
 } path_size_list[] = {
 	{ 32,	0,	0 },
-	{ 64,	0,	0 }
+	{ 64,	0,	0 },
+	{ 96,	0,	0 },
+	{ 128,	0,	0 }
 };
 
 #define	NUMPATHSIZES	(sizeof (path_size_list)/sizeof (struct path_size_list))
@@ -153,7 +155,7 @@
       ^ (asp)->path_attr_len) & PATHHASHMASK)
 
 static as_path *path_list[PATHHASHSIZE] = { 0 };
-static int path_list_members = 0;	/* number of paths we know about */
+static u_int path_list_members = 0;	/* number of paths we know about */
 
 /*
  * Macros for scanning the AS paths we have.
@@ -421,7 +423,7 @@
 		pa->path_aggr_len,
 		(pa->path_size > 0)
 		? path_size_list[pa->path_size - 1].len
-		: (pa->path_len + pa->path_seg_len + pa->path_attr_len));
+		: (pa->path_alloc_size));
 	cp = PATH_PTR(pa);
 	fprintf(fd, "\tPath: ");
 	if (pa->path_local_as) {
@@ -558,6 +560,19 @@
 		fprintf(fd, " %02x", *cp++);
 	    fprintf(fd, "\n");
 	}
+#ifdef  APATH_DEBUG
+	if ((pa->path_size > 0
+	     && path_size_list[pa->path_size - 1 ].len - sizeof (as_path))
+	    || (pa->path_alloc_size > 0
+		&& pa->path_alloc_size - sizeof (as_path))) {
+	    cp = PATH_PTR(pa);
+	    fprintf(fd, "\t\tPath Dump: ");
+	    for (i = 0; i < (pa->path_size ? (int)(path_size_list[pa->path_size - 1].len - sizeof (as_path)) : (int) (pa->path_alloc_size - sizeof (as_path))); i++) {
+		fprintf(fd, "0x%02x ", *cp++);
+	    }
+	    fprintf(fd, "\n");
+	}
+#endif
     }
 
     /*
@@ -928,12 +943,12 @@
 	    break;
 
 	case PA4_TYPE_AGGREGATOR:
-	    if (len != 2 && len != 6) {
+	    if (len != 2 && len != PA4_LEN_AGGREGATOR) {
 		break;
 	    }
 	    i = (*cp++) << 8;
 	    i |= *cp++;
-	    if (len == 6) {
+	    if (len == PA4_LEN_AGGREGATOR) {
 	        sockclear_in(&addr);
 		bpattr = (byte *) &sock2ip(&addr);
 		*bpattr++ = *cp++;
@@ -986,10 +1001,32 @@
             trace_only_tf(trp,
                           0,
                           (NULL));
+	    defprint = 0;
             break;
 
+	case PA4_TYPE_ORIGINATOR_ID:
+            if (version == PATH_VERSION_2OR3
+		|| len != PA4_LEN_ORIGINATOR_ID) {
+                break;
+            }
+	    sockclear_in(&addr);
+	    bpattr = (byte *) &sock2ip(&addr);
+	    *bpattr++ = *cp++;
+	    *bpattr++ = *cp++;
+	    *bpattr++ = *cp++;
+	    *bpattr++ = *cp++;
+	    trace_only_tf(trp,
+			  0,
+			  ("%sflags 0x%02x code OriginatorID(%d): %A",
+			   comment,
+			   flags,
+			   code,
+			   &addr));
+	    defprint = 0;
+	    break;
+
         case PA4_TYPE_DPA:
-            if (version == PATH_VERSION_2OR3 || len != 6) {
+            if (version == PATH_VERSION_2OR3 || len != PA4_LEN_DPA) {
                 break;
             }
             i = (*cp++) << 8;
@@ -1006,6 +1043,7 @@
                            code,
                            i,
                            metric));
+	    defprint = 0;
             break;
 
 #ifdef  PROTO_INET6
@@ -1031,6 +1069,7 @@
                            code));
             i = (*cp++) << 8;
             i |= *cp++;
+	    tracef(" length(%d)", len);
             if (i == 2)
                 tracef(" family(IPv6)");
             else {
@@ -1043,7 +1082,6 @@
 	    tracef(" subfamily(%d)", i);
 	    tracef(" nexthop");
             switch (metric = (int) *cp++) { /* Length of Next Hop */
-            /* %%%%% this code is suspect revisit later wfswfs  */
             case 32:
                 sockclear_in6(&addr);
                 bpattr = (byte *) &sock2in6(&addr);
@@ -1213,7 +1251,7 @@
 	}
     }
 
-    assert(n_local_as < PATH_N_LOCAL_AS);
+    assert((size_t) n_local_as < PATH_N_LOCAL_AS);
     if (i < n_local_as) {
 	register int j = n_local_as;
 
@@ -1307,7 +1345,7 @@
 	    /*
 	     * Must copy the old info to the end of the new list.
 	     */
-	    assert(n_as_all < PATH_N_LOCAL_AS);
+	    assert((size_t) n_as_all < PATH_N_LOCAL_AS);
 	    as_local_info[n_as_all] = old_as_local_info[j];
 	    old_as_local_info[j++].asl_found = n_as_all++;
 	    changed_bits++;
@@ -1424,7 +1462,7 @@
     if (!task_create(path_task)) {
 	task_quit(EINVAL);
     }
-    for (i = 0; i < NUMPATHSIZES; i++) {
+    for (i = 0; i < (int) NUMPATHSIZES; i++) {
 	if (path_size_list[i].block_indx == NULL) {
 	    path_size_list[i].block_indx = 
 	      task_block_init((size_t) (path_size_list[i].len + sizeof (as_path)), "as_path");
@@ -1443,8 +1481,8 @@
     register as_path *asp;
     register int ps;
 
-    for (ps = 0; ps < NUMPATHSIZES; ps++) {
-	if (path_size_list[ps].len >= length) {
+    for (ps = 0; ps < (int) NUMPATHSIZES; ps++) {
+	if ((size_t) path_size_list[ps].len >= length) {
 	    /*
 	     * Got one of the standard sizes.  Get it and fill
 	     * the size in.
@@ -1462,6 +1500,7 @@
     asp = (as_path *) task_mem_calloc(path_task,
 				      1,
 				      (sizeof (as_path) + length));
+    asp->path_alloc_size = length;
     path_num_mallocs++;
     return asp;
 }
@@ -1490,7 +1529,7 @@
 
 /*
  * path_unlink - free a path structure which may have be obtained from
- *	       the task_block stuff or may have been malloc'd.
+ *	         the task_block stuff or may have been malloc'd.
  */
 void
 aspath_unlink __PF1(pathp, register as_path *)
@@ -1514,14 +1553,15 @@
 
 /*
  * path_find - search for an existing path in the table which matches
- *   the argument.  If found, free the argument path and return the
- *   linked one instead.  A path which has been found by path_find()
- *   should always be the one returned by path_rt_link() or path_rt_build().
+ *             the argument.  If found, free the argument path and
+ *             return the * linked one instead.  A path which has been
+ *             found by path_find() * should always be the one
+ *             returned by path_rt_link() or path_rt_build().
  */
 as_path *
 aspath_find __PF1(pathp, register as_path *)
 {
-    register as_path *asp;
+    register as_path *asp = NULL;
 
     if (pathp->path_refcount == 0) {
 	PATH_FIND_PATH(pathp, asp);
@@ -1647,17 +1687,16 @@
  *		      Do it.
  */
 static void
-aspath_insert_attr __PF6(asp, as_path *,
+aspath_insert_attr __PF5(asp, as_path *,
 			 newflags, u_int,
 			 newcode, u_int,
 			 newlen, size_t,
-			 datap, byte *,
-			 api, as_path_info *)
+			 datap, byte *)
 {
     register byte *bp, *bpend;
     register byte *bpattr;
     size_t len;
-    u_int flags, code;
+    u_int flags, code = 0;
 
     /*
      * Find where to insert the attribute.
@@ -1667,10 +1706,6 @@
     bpend = bp + asp->path_attr_len;
     while (bp < bpend) {
 	GET_PATH_ATTR(flags, code, len, bp);
-#ifdef  PROTO_INET6
-        if ((code == PA4_TYPE_MPREACHNLRI) || (code == PA4_TYPE_MPUNRNLRI))
-            code |= PA4_MP_BUMP;
-#endif  /* PROTO_INET6 */
 	if (code > newcode) {
 	    break;
 	}
@@ -1688,37 +1723,13 @@
 	while (bpend > bpattr) {
 	    *(--bp) = *(--bpend);
 	}
-#ifdef PROTO_INET6
-        switch (code & PA4_MP_MASK) {
-	case PA4_TYPE_MPREACHNLRI:
-	    api->api_mpreach_nlri = bp;
-	    break;
-	case PA4_TYPE_MPUNRNLRI:
-	    api->api_mpunreach_nlri = bp;
-	    break;
-	default:
-	}
-#endif /* PROTO_INET6 */
     }
 
     /*
      * By now, one way or another, bpend points to the place to insert
      * this.  Copy it in.
      */
-#ifdef PROTO_INET6
-    PATH_PUT_ATTR(newflags, newcode & PA4_MP_MASK, newlen, bpend);
-    switch (newcode & PA4_MP_MASK) {
-    case PA4_TYPE_MPREACHNLRI:
-        api->api_mpreach_nlri = bpattr;
-	break;
-    case PA4_TYPE_MPUNRNLRI:
-        api->api_mpunreach_nlri = bpattr;
-	break;
-    default:
-    }
-#else  /* PROTO_INET6 */
     PATH_PUT_ATTR(newflags, newcode, newlen, bpend);
-#endif /* PROTO_INET6 */
     bpattr = datap;
     while (bpend < bp) {
 	*bpend++ = *bpattr++;
@@ -1744,17 +1755,20 @@
     register byte *bp, *bpend;
     register byte *ap;
     register as_path *asp;
-    register byte *bpattr;
+    register byte *bpattr = NULL;
     u_int flags;
     size_t len;
-    u_int code, lastcode;
+    size_t remainlen;
+    u_int code = 0, lastcode;
     int is_aggr = 0;
     byte received[ATTR_BITARRAY_SIZE];
     static byte missing_attr;
     as_path *nasp;
 #ifdef  PROTO_INET6
-    int mpreachlen;
-    int mpunreachlen;
+    static byte mpreach_buffer[ASPATHMAXSIZE];
+    static byte mpunreach_buffer[ASPATHMAXSIZE];
+    size_t mpreachlen;
+    size_t mpunreachlen;
 #endif  /* PROTO_INET6 */
 
     /*
@@ -1775,8 +1789,8 @@
      */
     api->api_flags = 0;
 #ifdef  PROTO_INET6
-    api->api_mpunreach_nlri = 0;
-    api->api_mpreach_nlri = 0;
+    api->api_mpunreach_nlri = NULL;
+    api->api_mpreach_nlri = NULL;
     if (nlrilen) {
 	mpreachlen = PA4_LEN_MPREACHNLRI_OLD;
 	mpunreachlen = PA4_LEN_MPUNRNLRI_OLD;
@@ -1786,6 +1800,7 @@
     }
 #endif  /* PROTO_INET6 */
     lastcode = 0;
+    remainlen = buflen;
 
     /*
      * Initialize received array
@@ -1848,11 +1863,11 @@
 	GET_PATH_ATTR(flags, code, len, bp);
 
 	/*
-	 * XXX If there is insufficient data in the packet for the
-	 * length given, return an error.
+	 * If the attribute length is larger than total attribute
+	 * length, return an error.
 	 */
-	if ((bpend - bp) < len) {
-	    PA_RETURN_ERROR(PA_ERR_MALFORMED, NULL) ;
+	if (buflen < len) {
+	    PA_RETURN_ERROR(PA_ERR_LENGTH, bpattr) ;
 	}
 
 	/*
@@ -1951,7 +1966,7 @@
 		pp = bp;
 		lastsegtype = PA_PATH_NOTSETORSEQ;
 		nas = nseg = 0;
-		while ((pp - bp) < len) {
+		while ((size_t) (pp - bp) < len) {
 		    segtype = (u_short)(*pp++);
 		    seglen = (u_short)(*pp++);
 
@@ -1962,7 +1977,7 @@
 		     */
 		    pp += seglen << 1;
 		    if ((segtype != PA_PATH_SET && segtype != PA_PATH_SEQ)
-		      || (pp - bp) > len) {
+		      || (size_t) (pp - bp) > len) {
 			PA_RETURN_ERROR(PA_ERR_ASPATH, NULL) ;
 		    }
 
@@ -2048,8 +2063,9 @@
 			byte *segstart;
 
 			/*
-			 * XXX This is a load of horse hockey (then again the BGP4
-			 * AS path is a load of horse hockey ).  Rethink later.
+			 * XXX This is a load of horse hockey (then
+			 * again the BGP4 AS path is a load of horse
+			 * hockey ).  Rethink later.
 			 */
 			*segp++ = ((u_short)seglen) | PATH_AS_SET;
 			lastsegtype = PA_PATH_SET;
@@ -2104,7 +2120,7 @@
 		    register int i;
 
 		    len >>= 1;
-		    for (i = 0; i < len; i++) {
+		    for (i = 0; i < (int) len; i++) {
 		        *ap++ = *bp++;
 		        *ap++ = *bp++;
 		    }
@@ -2118,7 +2134,7 @@
 		    ap += len + PA4_LEN_SEGMENT;
 		    len >>= 1;
 		    pp = PATH_PTR(asp);
-		    for (i = 0; i < len; i++) {
+		    for (i = 0; i < (int) len; i++) {
 		        *pp++ = *bp++;
 		        *pp++ = *bp++;
 		    }
@@ -2266,8 +2282,11 @@
 		PA_RETURN_ERROR(PA_ERR_LENGTH, bpattr) ;
 		break;
 	    }
-            api->api_mpreach_nlri = ap;
-            code |= PA4_MP_BUMP;
+	    bpattr = mpreach_buffer;
+	    PATH_PUT_ATTR(flags, code, len, bpattr);
+	    bcopy(bp, bpattr, len);
+	    bp += len;
+            api->api_mpreach_nlri = mpreach_buffer;
             goto do_optional;
 
         case PA4_TYPE_MPUNRNLRI:
@@ -2286,8 +2305,11 @@
                 PA_RETURN_ERROR(PA_ERR_LENGTH, bpattr) ;
                 break;
             }
-            api->api_mpunreach_nlri = ap;
-            code |= PA4_MP_BUMP;
+	    bpattr = mpunreach_buffer;
+	    PATH_PUT_ATTR(flags, code, len, bpattr);
+	    bcopy(bp, bpattr, len);
+	    bp += len;
+            api->api_mpunreach_nlri = mpunreach_buffer;
             goto do_optional;
 #endif  /* PROTO_INET6 */
 
@@ -2318,18 +2340,26 @@
 		is_aggr = 0;
 	    }
 	    if (code > lastcode) {		/* fast path */
-		asp->path_attr_len += PATH_ATTR_LEN(len);
 #ifdef PROTO_INET6
-		PATH_PUT_ATTR(flags, code & PA4_MP_MASK, len, ap);
+		if (code != PA4_TYPE_MPREACHNLRI
+		    && code != PA4_TYPE_MPUNRNLRI) {
+		    asp->path_attr_len += PATH_ATTR_LEN(len);
+		    PATH_PUT_ATTR(flags, code, len, ap);
+		    while (len-- > 0) {
+			*ap++ = *bp++;
+		    }
+		    lastcode = code;
+		}
 #else
+		asp->path_attr_len += PATH_ATTR_LEN(len);
 		PATH_PUT_ATTR(flags, code, len, ap);
-#endif
 		while (len-- > 0) {
 		    *ap++ = *bp++;
 		}
 		lastcode = code;
+#endif
 	    } else {
-		aspath_insert_attr(asp, flags, code, len, bp, api);
+		aspath_insert_attr(asp, flags, code, len, bp);
 		bp += len;
 		ap += PATH_ATTR_LEN(len);
 	    }
@@ -2421,33 +2451,6 @@
     } else {
 	asp = nasp;
     }
-#ifdef  PROTO_INET6
-    /*
-     * Try to get pointers to multi-protocol attributes
-     */
-    if ((bp = api->api_mpreach_nlri)) {
-        while (bp < ap) {
-            bpattr = bp;
-            GET_PATH_ATTR(flags, code, len, bp);
-            if (code == PA4_TYPE_MPREACHNLRI)
-                break;
-            bp += len;
-        }
-        assert(code == PA4_TYPE_MPREACHNLRI);
-        api->api_mpreach_nlri = bpattr;
-    }
-    if ((bp = api->api_mpunreach_nlri)) {
-        while (bp < ap) {
-            bpattr = bp;
-            GET_PATH_ATTR(flags, code, len, bp);
-            if (code == PA4_TYPE_MPUNRNLRI)
-                break;
-            bp += len;
-        }
-        assert(code == PA4_TYPE_MPUNRNLRI);
-        api->api_mpunreach_nlri = bpattr;
-    }
-#endif  /* PROTO_INET6 */
     return asp;
 
     /*
@@ -2463,9 +2466,10 @@
 
 
 /*
- * path_format - format a set of version 2/3 path attributes into an outgoing
- *   message.  This routine is responsible for ensuring that the AS path is
- *   updated appropriately in the outgoing message.
+ * path_format - format a set of version 2/3 path attributes into an
+ *               outgoing message.  This routine is responsible for
+ *               ensuring that the AS path is updated appropriately in
+ *               the outgoing message.
  */
 byte *
 aspath_format __PF5(myas, as_t,
@@ -2532,10 +2536,11 @@
 	*cp++ = asp->path_origin;
 
 	/*
-	 * AS path.  We've got to compute the length once we've massaged
-	 * the thing, so figure out what we need to do now.  We add an
-	 * AS to the path for every local AS bit set in path_local_as, except
-	 * for the bit which corresponds to myas.
+	 * AS path.  We've got to compute the length once we've
+	 * massaged the thing, so figure out what we need to do now.
+	 * We add an AS to the path for every local AS bit set in
+	 * path_local_as, except for the bit which corresponds to
+	 * myas.
 	 */
 	len = asp->path_len;
 	if (las) {
@@ -2635,9 +2640,10 @@
 
 
 /*
- * path_format_v4 - format a set of version 4 path attributes into an outgoing
- *   message.  This routine is responsible for ensuring that the AS path is
- *   updated appropriately in the outgoing message.
+ * path_format_v4 - format a set of version 4 path attributes into an
+ *                  outgoing message.  This routine is responsible for
+ *                  ensuring that the AS path is updated appropriately
+ *                  in the outgoing message.
  */
 byte *
 aspath_format_v4 __PF5(myas, as_t,
@@ -2751,12 +2757,12 @@
      * adds to the length.
      */
     if (!BIT_TEST(asip->api_flags, APIF_INTERNAL)) {
-	len += PA_LEN_AS;
+	len += PA_LEN_AS * asip->api_as_count;
 	if (first_sequence_length == 0) {
-	    len += PA4_LEN_SEGMENT;
-	    first_sequence_length = 1;
+	    len += PA4_LEN_SEGMENT * asip->api_as_count;
+	    first_sequence_length = asip->api_as_count;
 	} else {
-	    first_sequence_length++;
+	    first_sequence_length += asip->api_as_count;
 	}
     }
 
@@ -2778,8 +2784,11 @@
 	*cp++ = PA_PATH_SEQ;
 	*cp++ = (byte)first_sequence_length;
 	if (!BIT_TEST(asip->api_flags, APIF_INTERNAL)) {
+	  int i = asip->api_as_count;
+	  while (i--) {
 	    PATH_PUT_AS(myas, cp);
 	    first_sequence_length--;
+	  }
 	}
 	if (first_sequence_length && add_path_as) {
 	    PATH_PUT_AS(add_path_as, cp);
@@ -2810,7 +2819,7 @@
     if (first_sequence_length > 0) {
 	assert(len > 0);
 	seglen = PATH_SEG_LEN(*segp);
-	assert(PATH_ISSEQUENCE(*segp) && seglen >= first_sequence_length);
+	assert(PATH_ISSEQUENCE(*segp) && seglen >= (u_int)first_sequence_length);
 	seglen -= first_sequence_length;
 	do {
 	    *cp++ = *pp++;
@@ -3466,6 +3475,8 @@
     plen = ((byte *)ap) - ((byte *)apstart);
     asp = aspath_alloc(plen);
     buf_asp->path_size = asp->path_size;
+    if (!buf_asp->path_size)
+	buf_asp->path_alloc_size = plen;
     bcopy((void_t) buf_asp, (void_t) asp, (plen + sizeof(as_path)));
     asp->path_hash = PATHHASH(asp);
     asp = aspath_find(asp);
@@ -3669,7 +3680,7 @@
      * route.  If we find it we have some work to do.
      */
     if (asp) {
-	ASPATH_ALLOC(asp);
+	asp = aspath_find(asp);
 	aspath_rt_link(rt, asp);
 #if	defined(PROTO_BGP) && defined(PROTO_OSPF)
 	if (gwp->gw_proto == RTPROTO_BGP
@@ -3710,8 +3721,8 @@
     case RTPROTO_OSPF_ASE:
 	/*
 	 * We'll need to check out the tag.  Fetch it from the OSPF
-	 * data base.  This is a crock of horse hockey, I wish the tag definitions
-	 * were closer to real life.
+	 * data base.  This is a crock of horse hockey, I wish the tag
+	 * definitions were closer to real life.
 	 */
         {
 	    u_long tag = PATH_GET_OSPF_TAG(rt);
@@ -3740,8 +3751,10 @@
 		    if (PATH_OSPF_ISCOMPLETE(tag)) {
 #ifdef	PROTO_BGP
 			/*
-			 *  The tag says that we need to wait for the IBGP route to get the
-			 *  path info.  So look for a valid IBGP route with the same router ID
+			 *  The tag says that we need to wait for the
+			 *  IBGP route to get the path info.  So look
+			 *  for a valid IBGP route with the same
+			 *  router ID
 			 */
 			rt_entry *rt1;
 			u_long adv_rtr = ORT_ADVRTR(rt);
@@ -3762,8 +3775,8 @@
 			} RT_ALLRT_END(rt1, rt->rt_head) ;
 
 			/*
-			 * Couldn't find a good route, when the IBGP route arrives it will
-			 * fill in the pointer.
+			 * Couldn't find a good route, when the IBGP
+			 * route arrives it will fill in the pointer.
 			 */
 #endif	/* PROTO_BGP */
 			return;
@@ -3890,8 +3903,9 @@
 
 
 /*
- * path_prefer - determine which route is preferred based on their AS paths.
- *   Return <0 if the first, >0 if the second, and == 0 if they are the same.
+ * path_prefer - determine which route is preferred based on their AS
+ *               paths. Return <0 if the first, >0 if the second, and
+ *               == 0 if they are the same.
  */
 int
 aspath_prefer __PF2(rt1, rt_entry *,
@@ -4448,12 +4462,11 @@
 }
 
 size_t
-aspath_zap_mp_attr __PF4(asp, as_path *,
-                         asip, as_path_info *,
+aspath_zap_mp_attr __PF3(asip, as_path_info *,
                          attrlen, size_t,
                          type, int)
 {
-    register byte *bp, *cp, *cpend;
+    register byte *cp, *cpend;
     register size_t len;
     u_int flags, code;
 
@@ -4475,21 +4488,17 @@
 
     cpend = cp;
     GET_PATH_ATTR(flags, code, len, cpend);
-    cpend += len;
 
     len = PATH_ATTR_LEN(len);
 
-    bp = PATH_ATTR_PTR(asp);
-    bp += asp->path_attr_len;
-
     /* Should not happen ?! */
-    if ((len > attrlen) || (len != (cpend - cp)) || (cpend != bp)) {
+    assert(len);
+    assert(len <= attrlen);
+    if (len > attrlen) {
         return (0);
     }
 
-    asp->path_attr_len -= len;
-
-    return (attrlen - len);
+    return (len);
 }
 
 #endif  /* defined(PROTO_INET6) || defined(PROTO_BGP4MP) */
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/aspath.h gated-R3_5/src/aspath.h
--- gated-pub-ipv6-snapshot-0399/src/aspath.h	Sat Mar 27 09:31:28 1999
+++ gated-R3_5/src/aspath.h	Sat Mar 27 10:58:09 1999
@@ -127,6 +127,9 @@
  *
  */
 
+/*
+ * The specfication of COMMUNITY Attribute value.
+ */
 #define AS_COMM_MIN		0
 #define	AS_COMM_MAX		10		/* maximum of 10 ASs */
 #define AS_COMM_LIMIT		AS_COMM_MIN, AS_COMM_MAX
@@ -149,6 +152,7 @@
     byte path_size;		/* index into size list, 0 if malloc */
     byte path_flags;		/* flags (local aggregate, atomic aggregate) */
     byte path_origin;		/* path origin type (BGP, IGP, XX) */
+    u_int32 path_alloc_size;	/* real malloc size, 0 if using index into size list */
     u_int16 path_aggr_len;	/* Length of aggregator attribute, if any */
     u_int16 path_len;		/* length of the AS path */
     u_int16 path_seg_len;	/* length of segment descriptors */
@@ -256,13 +260,12 @@
      && ((asp1)->path_attr_len == (asp2)->path_attr_len) \
      && ((asp1)->path_aggr_len == (asp2)->path_aggr_len) \
      && ((asp1)->path_local_as == (asp2)->path_local_as) \
-     && ((asp1)->path_aggr_len == (asp2)->path_aggr_len) \
      && ((asp1)->path_flags == (asp2)->path_flags) \
      && ((((asp1)->path_len + (asp1)->path_seg_len \
        + (asp1)->path_attr_len) == 0) \
      || (bcmp((caddr_t) PATH_PTR((asp1)), (caddr_t) PATH_PTR((asp2)), \
-	      (size_t)((asp1)->path_len+(asp1)->path_seg_len \
-		+(asp1)->path_attr_len)) == 0)))
+	      (size_t)((asp1)->path_len + (asp1)->path_seg_len \
+		+ (asp1)->path_attr_len)) == 0)) )
 
 /*
  * The size of the path hash index.  asp->path_hash above will be a value
@@ -281,6 +284,7 @@
     metric_t api_metric;
     metric_t api_localpref;
     u_int32 api_localid;
+    u_int32 api_as_count;
 #ifdef	PROTO_INET6
     byte *api_mpunreach_nlri;
     byte *api_mpreach_nlri;
@@ -407,6 +411,7 @@
 #define PA4_LEN_COMM_MIN	4
 #define PA4_LEN_COMM_AS		4	        /* length of Communities */ 
 #define PA4_LEN_COMM_MAX	4*AS_COMM_MAX	/* total length of COMsM */ 
+#define PA4_LEN_ORIGINATOR_ID	4
 #define PA4_LEN_DPA             6
 #if defined(PROTO_INET6)
 #define PA4_LEN_MPREACHNLRI_OLD	7 /* length for old draft */
@@ -770,8 +775,7 @@
 
 PROTOTYPE(aspath_zap_mp_attr,
           size_t,
-          (as_path *,
-           as_path_info *,
+          (as_path_info *,
            size_t,
            int));
 
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp.h gated-R3_5/src/bgp.h
--- gated-pub-ipv6-snapshot-0399/src/bgp.h	Sat Mar 27 09:31:39 1999
+++ gated-R3_5/src/bgp.h	Mon Mar 29 23:05:02 1999
@@ -228,6 +228,7 @@
     time_t	bgpc_rto_time;
     u_int	bgpc_setpref;
     int		bgpc_ttl;
+    u_int32	bgpc_as_count;
 } ;
 
 
@@ -619,6 +620,7 @@
 #define	bgp_rto_time		bgp_conf.bgpc_rto_time
 #define	bgp_setpref		bgp_conf.bgpc_setpref
 #define	bgp_ttl			bgp_conf.bgpc_ttl
+#define bgp_as_count		bgp_conf.bgpc_as_count
 
 #define	bgp_type		bgp_group->bgpg_type
 
@@ -786,6 +788,7 @@
 #define	bgpg_rto_time		bgpg_conf.bgpc_rto_time
 #define	bgpg_setpref		bgpg_conf.bgpc_setpref
 #define	bgpg_ttl		bgpg_conf.bgpc_ttl
+#define bgpg_as_count		bgpg_conf.bgpc_as_count
 
     /* Group index/bitmask allocation data */
     u_short	bgpg_idx_maxalloc;	/* highest bit number allocated */
@@ -904,6 +907,7 @@
 #define BGPO_NEXTHOPSELF	0x2000000 /* always send own address as next hop */
 #define BGPO_INTERFACE		0x4000000 /* Our local interface was specified */
 #define BGPO_NLRILENGTH		0x8000000 /* bgp4+ old style packet format */
+#define BGPO_AS_COUNT		0x10000000        /* Stuff our AS into the path multiple times */
 
 /* Group options */
 #define BGPGO_METRIC_OUT	0x01	/* Use an outbound metric */
@@ -934,7 +938,7 @@
 #define BGPGO_NEXTHOPSELF	0x2000000 /* always send own address as next hop */
 #define BGPGO_INTERFACE		0x4000000 /* Our local interface was specified */
 #define BGPGO_NLRILENGTH	0x8000000 /* bgp4+ old style packet format */
-
+#define BGPGO_AS_COUNT		0x10000000        /* Stuff our AS into the path multiple times */
 
 /*
  * Variables in bgp_init.c
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp4mp.c gated-R3_5/src/bgp4mp.c
--- gated-pub-ipv6-snapshot-0399/src/bgp4mp.c	Sat Mar 27 09:31:47 1999
+++ gated-R3_5/src/bgp4mp.c	Mon Mar 29 23:05:02 1999
@@ -181,10 +181,10 @@
 bgp4mp_set_open_auth __PF2(bap, bgpAuthinfo *,
 			   cp, byte *)
 {
-	/*
-	 * Only type 0 defined so far.  Don't need to add anything.
-	 */
-	return cp;
+    /*
+     * Only type 0 defined so far.  Don't need to add anything.
+     */
+    return cp;
 }
 
 /*
@@ -465,8 +465,8 @@
 
 	case BGP_OPEN:
 	    /*
-	     * An Open message.  We have to deal with both version 2 and version
-	     * 3/4 Open messages here.
+	     * An Open message.  We have to deal with both version 2
+	     * and version 3/4 Open messages here.
 	     */
 	    {
 		int version;
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp4mp.h gated-R3_5/src/bgp4mp.h
--- gated-pub-ipv6-snapshot-0399/src/bgp4mp.h	Sat Mar 27 09:31:56 1999
+++ gated-R3_5/src/bgp4mp.h	Mon Mar 29 23:05:02 1999
@@ -87,18 +87,20 @@
     bvalue_t bgpm_metric;
     bvalue_t bgpm_localpref;
     bvalue_t bgpm_tag;
+    bvalue_t bgpm_ascount;
     union {
 	bvalue_t bgpm_MA_alltypes;
 	struct {
 	    btype_t bgpm_MT_metric;
 	    btype_t bgpm_MT_localpref;
 	    btype_t bgpm_MT_tag;
-	    btype_t bgpm_MT_unused;
+	    btype_t bgpm_MT_ascount;
 	} bgpm_MA_types;
     } bgpm_M_types;
 #define	bgpm_tmetric	bgpm_M_types.bgpm_MA_types.bgpm_MT_metric
 #define	bgpm_tlocalpref	bgpm_M_types.bgpm_MA_types.bgpm_MT_localpref
 #define	bgpm_ttag	bgpm_M_types.bgpm_MA_types.bgpm_MT_tag
+#define	bgpm_tascount	bgpm_M_types.bgpm_MA_types.bgpm_MT_ascount
 #define	bgpm_types	bgpm_M_types.bgpm_MA_alltypes
 } bgp_metrics6;
 
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp4mp_init.c gated-R3_5/src/bgp4mp_init.c
--- gated-pub-ipv6-snapshot-0399/src/bgp4mp_init.c	Sat Mar 27 09:32:11 1999
+++ gated-R3_5/src/bgp4mp_init.c	Mon Mar 29 23:05:02 1999
@@ -147,6 +147,7 @@
 PROTOTYPE(bgp4mp_set_peer_if, static if_addr *, (bgpPeer *, int));
 PROTOTYPE(bgp4mp_get_peer_if, static if_addr *, (task *));
 PROTOTYPE(bgp4mp_ifachange, static void, (task *, if_addr *));
+PROTOTYPE(bgp4mp_select_srcaddr, static sockaddr_un *, (bgpPeer *));
 
 /*
  * Pretty-printing info
@@ -204,6 +205,7 @@
     {BGPO_NEXTHOPSELF, "NextHopSelf"},
     {BGPO_INTERFACE, "LclInferface"},
     {BGPO_NLRILENGTH, "NLRILength"},
+    {BGPO_AS_COUNT, "ASCount"},
     {0}
 };
 
@@ -2044,7 +2046,7 @@
     task *tp = bnp->bgp_task;
     int bgp_socket;
     if_addr *ifap;
-#ifdef  PROTO_INET6
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
     sockaddr_un *myaddr = 0;
 #endif
 
@@ -2081,44 +2083,35 @@
 	(void) bgp4mp_set_peer_if(bnp, 0);
     }
     if (bnp->bgp_ifap != NULL || bnp->bgp_lcladdr != NULL) {
-    	if ((bnp->bgp_ifap != NULL && !BIT_TEST(bnp->bgp_options, BGPO_GATEWAY))
-	    || (bnp->bgp_ifap != NULL
-		&& BIT_TEST(bnp->bgp_options, BGPO_GATEWAY)
-		&& inet6_scope_of(bnp->bgp_ifap->ifa_addr_local)
-		!= INET6_SCOPE_LINKLOCAL)) {
-	    bnp->bgp_myaddr = sockdup(bnp->bgp_ifap->ifa_addr_local);
-    	} else if (bnp->bgp_lcladdr != NULL) {
-	    bnp->bgp_myaddr = sockdup(bnp->bgp_lcladdr->ifae_addr);
-	}
-	if (bnp->bgp_group->bgpg_type != BGPG_INTERNAL_RT) {
-#ifdef  PROTO_INET6
-	    myaddr = sockdup(bnp->bgp_myaddr);
-	    if (socktype(bnp->bgp_myaddr) == AF_INET6
-		&& inet6_scope_of(bnp->bgp_myaddr) == INET6_SCOPE_LINKLOCAL)
-		PUT_IFINDEX_ADDR6(sock2in6(myaddr), htons(bnp->bgp_ifap->ifa_link->ifl_index));
-	    if (task_addr_local(tp, myaddr)) {
+	if((bnp->bgp_myaddr = bgp4mp_select_srcaddr(bnp)) == NULL)
+	    return;
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
+	myaddr = sockdup(bnp->bgp_myaddr);
+	if (socktype(bnp->bgp_myaddr) == AF_INET6
+	    && inet6_scope_of(bnp->bgp_myaddr) == INET6_SCOPE_LINKLOCAL)
+	    PUT_IFINDEX_ADDR6(sock2in6(myaddr), htons(bnp->bgp_ifap->ifa_link->ifl_index));
+	if (task_addr_local(tp, myaddr)) {
 #else
-	    if (task_addr_local(tp, bnp->bgp_myaddr)) {
+	if (task_addr_local(tp, bnp->bgp_myaddr)) {
 #endif
-		if (errno == EADDRNOTAVAIL) {
-		    trace_log_tf(bnp->bgp_trace_options,
-				 0,
-				 LOG_WARNING,
-				 ("bgp4+_connect_start: peer %s local address %A unavailable, connection failed",
-				  bnp->bgp_name,
-				  bnp->bgp_myaddr));
-		    bnp->bgp_connect_failed++;
-		    bgp4mp_peer_close(bnp, BGPEVENT_OPENFAIL);
-#ifdef  PROTO_INET6
-		    sockfree(myaddr);
+	    if (errno == EADDRNOTAVAIL) {
+		trace_log_tf(bnp->bgp_trace_options,
+			     0,
+			     LOG_WARNING,
+			     ("bgp4+_connect_start: peer %s local address %A unavailable, connection failed",
+			      bnp->bgp_name,
+			      bnp->bgp_myaddr));
+		bnp->bgp_connect_failed++;
+		bgp4mp_peer_close(bnp, BGPEVENT_OPENFAIL);
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
+		sockfree(myaddr);
 #endif
-		    return;
-		}
-		task_quit(errno);
+		return;
 	    }
+	    task_quit(errno);
 	}
-   }
-#ifdef  PROTO_INET6
+    }
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
     if (myaddr)
 	sockfree(myaddr);
 #endif
@@ -2894,6 +2887,43 @@
 }
 #endif /* PROTO_INET6 && IPV6_PKTOPTIONS */
 
+#ifdef PROTO_INET6
+/*
+ * bgp4mp_select_srcaddr - select connection source address.
+ *                         1. if ifap is avaliable and it's address scope
+ *                         is non-linklocal, connection source is it's address.
+ *                         2. if lcladdr option was specified, connection
+ *                         source is it's address.
+ *                         3. ifap is avaliable, it's address scope is
+ *                         non-linklocal and lcladdr option was specified,
+ *                         search globale scoped address(same interfaces).
+ */
+static sockaddr_un *
+bgp4mp_select_srcaddr(bnp)
+bgpPeer *bnp;
+{
+    sockaddr_un *srcaddr = NULL;
+    if_addr *ifapg;
+
+    if ((bnp->bgp_ifap != NULL && !BIT_TEST(bnp->bgp_options, BGPO_GATEWAY))
+	|| (bnp->bgp_ifap != NULL && BIT_TEST(bnp->bgp_options, BGPO_GATEWAY)
+	    && inet6_scope_of(bnp->bgp_ifap->ifa_addr_local)
+	    != INET6_SCOPE_LINKLOCAL)) {
+	    srcaddr = sockdup(bnp->bgp_ifap->ifa_addr_local);
+    } else if (bnp->bgp_lcladdr != NULL) {
+	srcaddr = sockdup(bnp->bgp_lcladdr->ifae_addr);
+    } else if (bnp->bgp_ifap != NULL
+	       && BIT_TEST(bnp->bgp_options, BGPO_GATEWAY)
+	       && inet6_scope_of(bnp->bgp_ifap->ifa_addr_local)
+	       == INET6_SCOPE_LINKLOCAL) {
+	if ((ifapg = if_withindex(bnp->bgp_ifap->ifa_link->ifl_index,
+				  INET6_SCOPE_GLOBAL)) != NULL)
+	    srcaddr = ifapg->ifa_addr_local;
+    }
+    return srcaddr;
+}
+#endif /* PROTO_INET6 */
+
 /*
  *	Group and peer location routines
  */
@@ -4620,6 +4650,7 @@
     bgp->bgpg_preference = bgp4mp_default_preference;
     bgp->bgpg_preference2 = bgp4mp_default_preference2;
     bgp->bgpg_localpref = bgp4mp_default_localpref;
+    bgp->bgpg_as_count = 1;
 
     return (bgp);
 }
@@ -4661,6 +4692,10 @@
 	      (u_int)bgp->bgpg_peer_as);
 	    return (bgpPeerGroup *)NULL;
 	}
+	if (BIT_TEST(bgp->bgpg_options, BGPO_AS_COUNT)) {
+	  (void) sprintf(errstr, "as_count only makes sense with external peers");
+	  return (bgpPeerGroup *)NULL;
+	}
     } else if (bgp->bgpg_type == BGPG_EXTERNAL) {
 	if (bgp->bgpg_local_as == bgp->bgpg_peer_as) {
 	    (void) sprintf(errstr,
@@ -4899,6 +4934,10 @@
 		return (bgpPeer *) 0;
 	    }
 	}
+	if (BIT_TEST(bnp->bgp_options, BGPO_AS_COUNT)) {
+	  (void) sprintf(errstr, "as_count only makes sense with external peers");
+	  return (bgpPeer *) NULL;
+	}
     } else {			/* EXTERNAL Peer */
         if (BIT_TEST(bnp->bgp_options, BGPO_IGNORELOCALPREF)) {
 	    (void) sprintf(errstr,
@@ -4970,7 +5009,10 @@
 	|| (obnp->bgp_gateway != NULL && !sockaddrcmp_in6(bnp->bgp_gateway, obnp->bgp_gateway))
 	|| (obnp->bgp_interface == NULL && bnp->bgp_interface != NULL)
 	|| (obnp->bgp_interface != NULL && bnp->bgp_interface == NULL)
-	|| (obnp->bgp_interface != NULL && !sockaddrcmp(bnp->bgp_interface->ifae_addr, obnp->bgp_interface->ifae_addr))) {
+	|| (obnp->bgp_interface != NULL && !sockaddrcmp(bnp->bgp_interface->ifae_addr, obnp->bgp_interface->ifae_addr))
+	|| (BIT_TEST(obnp->bgp_options, BGPO_AS_COUNT) !=
+	    BIT_TEST(bnp->bgp_options, BGPO_AS_COUNT))
+	|| (obnp->bgp_as_count != bnp->bgp_as_count)) {
 	bgp4mp_peer_add(bgp, bnp);
 	return (bnp);
     }
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp4mp_rt.c gated-R3_5/src/bgp4mp_rt.c
--- gated-pub-ipv6-snapshot-0399/src/bgp4mp_rt.c	Sat Mar 27 09:32:44 1999
+++ gated-R3_5/src/bgp4mp_rt.c	Mon Mar 29 23:05:03 1999
@@ -159,9 +159,9 @@
  */
 
 /*
- * task_block pointers for the allocation of bgp_rti_entry's, bgp_rto_entry6's,
- * bgpg_rto_entry6's and bgp_asp_list6 entries.  These are initialized by
- * bgp_rt_init().
+ * task_block pointers for the allocation of bgp_rti_entry's,
+ * bgp_rto_entry6's, bgpg_rto_entry6's and bgp_asp_list6 entries.
+ * These are initialized by bgp_rt_init().
  */
 static block_t	bgp_rti_block = (block_t) 0;
 static block_t	bgp_rto_block = (block_t) 0;
@@ -224,10 +224,9 @@
 
 /*
  * Outgoing message data.  We build message packets in the following
- * non-local memory.  As we currently build version 2/3 and version 4
- * packets separately we use the same storage, though the names
- * referencing it are separate in case I decide to do this differently
- * later.
+ * non-local memory.  As we currently build version version 4 packets
+ * separately we use the same storage, though the names referencing it
+ * are separate in case I decide to do this differently later.
  *
  * The macroes add a new route to the appropriate message, while
  * subroutines build the headers and actually transmit the packet.
@@ -235,7 +234,7 @@
 #define	send_message		((byte *)task_send_buffer)
 static byte *send_hdr_start;		/* points at start of attributes */
 static byte *send_hdr_end;		/* points past end of attributes */
-static byte *send_next_route;	/* points where next route should go */
+static byte *send_next_route;		/* points where next route should go */
 static byte *send_next_hop;		/* where the next hop goes */
 
 static byte *send_hdr_next;		/* points at start of
@@ -263,9 +262,9 @@
     ((send_next_route-send_message) \
       > (BGPMAXV4SENDPKTSIZE- MP_ATTR_LEN(mpunreachlen, len, bitcount)))
 
-#define	CHECK_MP_REACH_PKT_FULL(len, bitcount) \
+#define	CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bitcount) \
     ((send_next_route-send_message) \
-      > (BGPMAXV4SENDPKTSIZE- MP_ATTR_LEN(0, len, bitcount)))
+      > (BGPMAXV4SENDPKTSIZE- MP_ATTR_LEN(mpreachlen, len, bitcount)))
 
 /* Don't bother trying to stuff the last 200 bytes */
 #define	SEND_MESSAGE_WASTE	200
@@ -369,7 +368,7 @@
  * for the common structure fairly cheap.
  */
 
-static bgp_metrics_node6 bgp_metrics_node_none = { { 0 } };	/* common case? */
+static bgp_metrics_node6 bgp_metrics_node_none = { { 0 } }; /* common case? */
 #define	bgp_metrics_none	(&(bgp_metrics_node_none.bgpmn_metrics))
 
 static bgp_metrics_node6 *bgp_metrics_node_tree = (bgp_metrics_node6 *) 0;
@@ -412,7 +411,9 @@
       && ((bgp_metrics6 *)(m1))->bgpm_localpref \
 	== ((bgp_metrics6 *)(m2))->bgpm_localpref \
       && ((bgp_metrics6 *)(m1))->bgpm_tag \
-	== ((bgp_metrics6 *)(m2))->bgpm_tag)))
+	== ((bgp_metrics6 *)(m2))->bgpm_tag \
+      && ((bgp_metrics6 *)(m1))->bgpm_ascount \
+	== ((bgp_metrics6 *)(m2))->bgpm_ascount)))
 
 #define	BGP_NO_METRICS(m) \
     (IN6_IS_ADDR_UNSPECIFIED(&((m)->bgpm_nexthop)) \
@@ -1595,18 +1596,32 @@
 		    /*
 		     * Put the local address in the packet.
 		     */
-		    SEND_PUT_NH_ADDR6(bnp->bgp_myaddr, send_next_hop);
+		    if (BIT_TEST(bnp->bgp_options, BGPO_LCLADDR)
+			&& bnp->bgp_lcladdr != NULL)
+			SEND_PUT_NH_ADDR6(bnp->bgp_lcladdr->ifae_addr,
+					  send_next_hop);
+		    else
+			SEND_PUT_NH_ADDR6(bnp->bgp_myaddr, send_next_hop);
 		    break;
 		case SEND_NEXTHOP_PEERIF:
 		    if (nexthop && ifap == bnp->bgp_ifap) {
 			SEND_PUT_NEXTHOP6(nexthop, send_next_hop);
+		    } else if (BIT_TEST(bnp->bgp_options, BGPO_LCLADDR)
+			       && bnp->bgp_lcladdr != NULL) {
+			SEND_PUT_NH_ADDR6(bnp->bgp_lcladdr->ifae_addr,
+					  send_next_hop);
 		    } else {
 			SEND_PUT_NH_ADDR6(bnp->bgp_myaddr, send_next_hop);
 		    }
 		    break;
 		case SEND_NEXTHOP_LIST:
 		    if (!nexthop) {
-			SEND_PUT_NH_ADDR6(bnp->bgp_myaddr, send_next_hop);
+			if (BIT_TEST(bnp->bgp_options, BGPO_LCLADDR)
+			    && bnp->bgp_lcladdr != NULL)
+			    SEND_PUT_NH_ADDR6(bnp->bgp_lcladdr->ifae_addr,
+					      send_next_hop);
+			else 
+			    SEND_PUT_NH_ADDR6(bnp->bgp_myaddr, send_next_hop);
 		    }
 		    break;
 		default:
@@ -1700,9 +1715,9 @@
     register rt_entry *rt;
     bgp_rto_entry6 *rtop_next;
     bgp_adv_entry6 *entp;
-    int bclen;
+    size_t bclen;
     size_t len = 0;
-    int mpunreachlen;
+    size_t mpunreachlen;
 
     /*
      * Count multi-protocol unreachable if there are any.
@@ -1782,7 +1797,7 @@
     register rt_entry *rt;
     bgp_rto_entry6 *rtop_next;
     bgp_adv_entry6 *entp;
-    int bclen;
+    size_t bclen;
     u_int rtbit = bnp->bgp_task->task_rtbit;
 
     /*
@@ -1833,7 +1848,8 @@
  *				multi-protocol reachable prefixes attribute
  */
 static int
-bgp4mp_rt_send_peer_reach_estimate __PF5(len, size_t,
+bgp4mp_rt_send_peer_reach_estimate __PF6(bnp, bgpPeer *,
+					 len, size_t,
 					 isflash, int,
 					 rtop, bgp_rto_entry6 *,
 					 rtop_last, bgp_rto_entry6 **,
@@ -1843,15 +1859,20 @@
     bgp_rto_entry6 *rtop_next;
     bgp_adv_entry6 *entp;
     bgp_metrics6 *mets = rtop->bgpo_new_metrics;
-    int bclen;
+    size_t bclen;
+    size_t mpreachlen;
 
     /*
      * First route in always in it
      */
+    if (BIT_TEST(bnp->bgp_options, BGPGO_NLRILENGTH))
+	mpreachlen = PA4_LEN_MPREACHNLRI_OLD;
+    else
+	mpreachlen = PA4_LEN_MPREACHNLRI;
     entp = rtop->bgpo_advrt;
     rt = entp->bgpe_rt;
     bclen = inet6_prefix_mask(rt->rt_dest_mask);
-    if (CHECK_MP_REACH_PKT_FULL(len, bclen)) {
+    if (CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bclen)) {
 	return 0;
     }
     len += BGP_BITCOUNT_LEN + BGP_PREFIX_LEN(bclen);
@@ -1891,7 +1912,7 @@
 	 */
 	bclen = inet6_prefix_mask(rt->rt_dest_mask);
 
-	if (CHECK_MP_REACH_PKT_FULL(len, bclen)) {
+	if (CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bclen)) {
 	    *rtop_last = rtop;
 	    return len;
 	}
@@ -2053,6 +2074,9 @@
 	aspath_flags |= APIF_LOCALID|APIF_NEXTHOP;
 	api.api_localid = bnp->bgp_out_id;
     }
+
+    api.api_as_count = bnp->bgp_as_count;
+
     /* Fake nexthop, use router ID ? */
     sockclear_in(&nhaddr);
     sock2ip(&nhaddr) = bnp->bgp_out_id;
@@ -2156,6 +2180,13 @@
 		BIT_SET(api.api_flags, APIF_METRIC);
 		api.api_metric = mets->bgpm_metric;
 	    }
+
+	    if (mets->bgpm_tascount) {
+		api.api_as_count = mets->bgpm_ascount;
+	    } else {
+		api.api_as_count = bnp->bgp_as_count;
+	    }
+
 	    /*
 	     * Done that, now set up the path attribute header.  If
 	     * this is version 4 we may need to flush out the
@@ -2208,7 +2239,7 @@
 		    alen = aspath_mp_reach_estimate_len(&api, 0);
 
 		len = bgp4mp_rt_send_peer_reach_estimate(
-		    	alen, isflash, rtop,
+		    	bnp, alen, isflash, rtop,
 			&rtop_check_next, &sendnextflash);
 
 		if (len == 0) {
@@ -2552,7 +2583,9 @@
     bgp_adv_entry6 *entp;
     int nexthoptype;
     bgp_metrics6 *his_metrics;
-    int bclen, res;
+    int res;
+    size_t mpreachlen;
+    size_t bclen;
 
     switch (bgp->bgpg_type) {
     default:
@@ -2569,6 +2602,11 @@
 	break;
     }
 
+    if (BIT_TEST(bnp->bgp_options, BGPGO_NLRILENGTH))
+	mpreachlen = PA4_LEN_MPREACHNLRI_OLD;
+    else
+	mpreachlen = PA4_LEN_MPREACHNLRI;
+
     /*
      * First route in always in it
      */
@@ -2576,7 +2614,7 @@
     rt = entp->bgpe_rt;
     his_metrics = entp->bgpe_metrics;
     bclen = inet6_prefix_mask(rt->rt_dest_mask);
-    if (CHECK_MP_REACH_PKT_FULL(len, bclen)) {
+    if (CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bclen)) {
 	return 0;
     }
     len += BGP_BITCOUNT_LEN + BGP_PREFIX_LEN(bclen);
@@ -2666,7 +2704,7 @@
 	 */
 	bclen = inet6_prefix_mask(rt->rt_dest_mask);
 
-	if (CHECK_MP_REACH_PKT_FULL(len, bclen)) {
+	if (CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bclen)) {
 	    *rtop_last = rtop;
 	    return len;
 	}
@@ -3167,7 +3205,8 @@
 	    res = 0;
 	    sockclear_bgp6(&mynexthop);
 
-	    if (!IN6_IS_ADDR_UNSPECIFIED(&his_metrics->bgpm_nexthop)) {
+	    if (!IN6_IS_ADDR_UNSPECIFIED(&his_metrics->bgpm_nexthop)
+		&& !BIT_TEST(bnp->bgp_options, BGPO_NEXTHOPSELF)) {
 		if (nexthoptype == SEND_NEXTHOP_LIST) {
 		    res = 1;
 		} else {
@@ -3181,11 +3220,17 @@
 	    if (res) {
 		thisnexthop = &his_metrics->bgpm_nexthop;
 		sock2in6(&mynexthop) = *thisnexthop;
+	    } else if (BIT_TEST(bnp->bgp_options, BGPO_LCLADDR)
+		       && bnp->bgp_lcladdr != NULL) {
+		thisnexthop = (bgp_nexthop6 *) 0;
+		sock2in6(&mynexthop) = sock2in6(bnp->bgp_lcladdr->ifae_addr);
+		thisnexthop = &sock2in6(&mynexthop);
 	    } else {
 		thisnexthop = (bgp_nexthop6 *) 0;
 		sock2in6(&mynexthop) = sock2in6(bnp->bgp_myaddr);
 		if (bgp6_share_if(&mynexthop, bnp->bgp_addr, bnp->bgp_ifap))
 		    bgp6_fill_ll(&mynexthop, bnp->bgp_ifap);
+		thisnexthop = &sock2in6(&mynexthop);
 	    }
 	    api.api_nexthop = &mynexthop;
 
@@ -3600,15 +3645,20 @@
     int len_bits = bgp->bgpg_idx_size;
     bgp_metrics6 *his_metrics;
     int bclen, res;
+    size_t mpreachlen;
 
     /*
      * First route in always in it
      */
+    if (BIT_TEST(bgp->bgpg_options, BGPGO_NLRILENGTH))
+	mpreachlen = PA4_LEN_MPREACHNLRI_OLD;
+    else
+	mpreachlen = PA4_LEN_MPREACHNLRI;
     entp = rtop->bgpgo_advrt;
     rt = entp->bgpe_rt;
     his_metrics = entp->bgpe_metrics;
     bclen = inet6_prefix_mask(rt->rt_dest_mask);
-    if (CHECK_MP_REACH_PKT_FULL(len, bclen)) {
+    if (CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bclen)) {
 	return 0;
     }
     len += BGP_BITCOUNT_LEN + BGP_PREFIX_LEN(bclen);
@@ -3670,7 +3720,7 @@
 	 */
 	bclen = inet6_prefix_mask(rt->rt_dest_mask);
 
-	if (CHECK_MP_REACH_PKT_FULL(len, bclen)) {
+	if (CHECK_MP_REACH_PKT_FULL(mpreachlen, len, bclen)) {
 	    *rtop_last = rtop;
 	    return len;
 	}
@@ -5772,6 +5822,8 @@
      * If we have a new info entry remaining, free it.
      */
     if (ninfop) {
+	if (ninfop->bgp_info_asp)
+	    aspath_free(ninfop->bgp_info_asp);
 	BRT_INFO_FREE_FAST(bgp, ninfop);
     }
 
@@ -6061,6 +6113,15 @@
 		mymetrics.bgpm_nexthop = sock2in6(RT_ROUTER(new_rt));
 	    }
 
+
+	    /*
+	     * Determine the AS count (AS prepend)
+	     */
+	    if (results.res_ascount) {
+		mymetrics.bgpm_tascount = BGPM_HAS_VALUE;
+		mymetrics.bgpm_ascount = results.res_ascount;
+	    }
+
 	    /*
 	     * Find the metrics
 	     */
@@ -6398,7 +6459,8 @@
 	if (&(bnp->bgp_asp_queue)) {
 	    BGP_RTQ_INIT(&(bnp->bgp_asp_queue));
 	}
-	if (brto && brto->bgpo_prev && brto->bgpo_next) {
+	if (brto && brto->bgpo_prev && brto->bgpo_next
+	    && (brto->bgpo_prev == brto && brto->bgpo_next == brto)) {
 	    BGP_RTO_UNLINK(brto);
 	}
 #endif /* BGP_FLASH_DEBUG */
@@ -7005,7 +7067,7 @@
 	    trace_log_tp(tp,
 			 0,
 			 LOG_ERR,
-			 ("bgp4+_recv_update: peer %s UPDATE unreachable multi-protocol prefix length %d too long",
+			 ("bgp4+_recv_unreach: peer %s UPDATE unreachable multi-protocol prefix length %d too long",
 			  bnp->bgp_name,
 			  bitlen));
 	    bgp4mp_send_notify_none(bnp, BGP_ERR_UPDATE, BGP_ERRUPD_BADNET);
@@ -7015,7 +7077,7 @@
 	    trace_log_tp(tp,
 			 0,
 			 LOG_ERR,
-			 ("bgp4+_recv_update: peer %s UPDATE prefix length %d exceeds unreachable multi-protocol prefix data remaining (%d bytes)",
+			 ("bgp4+_recv_unreach: peer %s UPDATE prefix length %d exceeds unreachable multi-protocol prefix data remaining (%d bytes)",
 			  bnp->bgp_name,
 			  bitlen,
 			  (cpend - cp)));
@@ -7033,34 +7095,42 @@
 	    trace_log_tp(tp,
 			 0,
 			 LOG_WARNING,
-			 ("bgp4+_recv_update: peer %s UPDATE ignoring invalid unreachable multi-protocol route %A/%d (%d of %d)",
+			 ("bgp4+_recv_unreach: peer %s UPDATE invalid unreachable multi-protocol route %A/%d (%d of %d), ignoring",
 			  bnp->bgp_name,
 			  &dest,
 			  bitlen,
 			  (cpend - cp),
 			  (cpstart - cp)));
+	    sockfree(maskaddr);
 	    continue;
 #else  /* !BGP4MP_BADNET_IGNORE */
+#ifdef NORMALLIZE_BGP4MP_ROUTE
+	    bcopy(maskaddr, &dest, socksize(maskaddr));
+	    sockfree(maskaddr);
+#else
 	    trace_log_tp(tp,
 			 0,
 			 LOG_ERR,
-			 ("bgp4+_recv_update: peer %s update included invalid unreachable multi-protocol route %A/%d (%d of %d)",
+			 ("bgp4+_recv_unreach: peer %s update included invalid unreachable multi-protocol route %A/%d (%d of %d)",
 			  bnp->bgp_name,
 			  &dest,
 			  bitlen,
 			  (cpend - cp),
 			  (cpend - cpstart)));
+	    sockfree(maskaddr);
 	    bgp4mp_send_notify_none(bnp, BGP_ERR_UPDATE, BGP_ERRUPD_BADNET);
 	    return (0);
+#endif
 #endif /* BGP4MP_BADNET_IGNORE */
 	} else {
 	    trace_tp(tp,
 		     TR_NORMAL,
 		     0,
-		     ("bgp4+_recv_update: peer %s DELETE %A/%d",
+		     ("bgp4+_recv_unreach: peer %s DELETE %A/%d",
 		      bnp->bgp_name,
 		      &dest,
 		      bitlen));
+	    sockfree(maskaddr);
 	}
 
 	/*
@@ -7084,7 +7154,7 @@
 		trace_log_tp(tp,
 			     0,
 			     LOG_WARNING,
-			     ("bgp4+_recv_update: peer %s unreachable multi-protocol route %A/%d not sent by him (%d of %d)",
+			     ("bgp4+_recv_unreach: peer %s unreachable multi-protocol route %A/%d not sent by him (%d of %d)",
 			      bnp->bgp_name,
 			      &dest,
 			      bitlen,
@@ -7096,7 +7166,7 @@
 		trace_log_tp(tp,
 			     0,
 			     LOG_WARNING,
-			     ("bgp4+_recv_update: peer %s multi-protocol route %A/%d already deleted!",
+			     ("bgp4+_recv_unreach: peer %s multi-protocol route %A/%d already deleted!",
 			      bnp->bgp_name,
 			      &dest,
 			      bitlen));
@@ -7118,14 +7188,14 @@
  */
 static int
 bgp4mp_recv_reach __PF9(tp, task *,
-			 asp, as_path *,
-			 api, as_path_info *,
-			 rtparms, rt_parms *,
-			 routes_in, u_int *,
-			 defpref, pref_t,
-			 nouse, int,
-			 noinstall, int,
-			 bsp, bgp_sync6 *)
+			asp, as_path *,
+			api, as_path_info *,
+			rtparms, rt_parms *,
+			routes_in, u_int *,
+			defpref, pref_t,
+			nouse, int,
+			noinstall, int,
+			bsp, bgp_sync6 *)
 {
     register bgpPeer *bnp = (bgpPeer *)tp->task_data;
     register byte *cpstart, *cp, *cpend;
@@ -7229,7 +7299,7 @@
 #endif /* PROTO_INET6 */
 
 #ifdef PROTO_INET6
-	socksize(&nexthop) = sizeof(nexthop.in6); /* XXX */
+    socksize(&nexthop) = sizeof(nexthop.in6); /* XXX */
 #endif
     cp += len;
 
@@ -7271,7 +7341,7 @@
 	    trace_log_tp(tp,
 			 0,
 			 LOG_ERR,
-			 ("bgp4+_recv_update: peer %s UPDATE multi-protocol prefix length %d too long",
+			 ("bgp4+_recv_reach: peer %s UPDATE multi-protocol prefix length %d too long",
 			  bnp->bgp_name,
 			  bitlen));
 	    bgp4mp_send_notify_none(bnp, BGP_ERR_UPDATE, BGP_ERRUPD_BADNET);
@@ -7281,7 +7351,7 @@
 	    trace_log_tp(tp,
 			 0,
 			 LOG_ERR,
-			 ("bgp4+_recv_update: peer %s UPDATE multi-protocol prefix length %d exceeds prefix data remaining (%d bytes)",
+			 ("bgp4+_recv_reach: peer %s UPDATE multi-protocol prefix length %d exceeds prefix data remaining (%d bytes)",
 			  bnp->bgp_name,
 			  bitlen,
 			  (cpend - cp)));
@@ -7301,35 +7371,43 @@
 	    trace_log_tp(tp,
 			 0,
 			 LOG_WARNING,
-			 ("bgp4+_recv_update: peer %s update included invalid multi-protocol route %A/%d (%d of %d) ignoring",
+			 ("bgp4+_recv_reach: peer %s update included invalid multi-protocol route %A/%d (%d of %d), ignoring",
 			  bnp->bgp_name,
 			  &dest,
 			  bitlen,
 			  (cpend - cp),
 			  (cpend - cpstart)));
 	     nouse = noinstall = 1;
+	     sockfree(maskaddr);
 #else  /* !BGP4MP_BADNET_IGNORE */
+#ifdef NORMALLIZE_BGP4MP_ROUTE
+	    bcopy(maskaddr, &dest, socksize(maskaddr));
+	    sockfree(maskaddr);
+#else
 	    trace_log_tp(tp,
 			 0,
 			 LOG_ERR,
-			 ("bgp4+_recv_update: peer %s update included invalid multi-protocol route %A/%d (%d of %d)",
+			 ("bgp4+_recv_reach: peer %s update included invalid multi-protocol route %A/%d (%d of %d)",
 			  bnp->bgp_name,
 			  &dest,
 			  bitlen,
 			  (cpend - cp),
 			  (cpend - cpstart)));
+	    sockfree(maskaddr);
 	    bgp4mp_send_notify_none(bnp, BGP_ERR_UPDATE, BGP_ERRUPD_BADNET);
 	    return (0);
+#endif
 #endif /* BGP4MP_BADNET_IGNORE */
 	} else {
 	    trace_tp(tp,
 		     TR_NORMAL,
 		     0,
-		     ("bgp4+_recv_update: peer %s ADD %A/%d via %A",
+		     ("bgp4+_recv_reach: peer %s ADD %A/%d via %A",
 		      bnp->bgp_name,
 		      &dest,
 		      bitlen,
 		      &nexthop));
+	    sockfree(maskaddr);
 	}
 
 	/*
@@ -7377,14 +7455,14 @@
 	if (!nouse && !nousenet) {
 	    rtparms->rtp_preference = defpref;
 	    nousenet = !import(&dest,
-				rtparms->rtp_dest_mask,
-				bnp->bgp_import,
-				bgp4mp_import_aspath_list,
-				(adv_entry *)0,
-				&rtparms->rtp_preference,
-				&rtparms->rtp_precedence,
-				bnp->bgp_ifap,
-				(void_t) asp);
+			       rtparms->rtp_dest_mask,
+			       bnp->bgp_import,
+			       bgp4mp_import_aspath_list,
+			       (adv_entry *)0,
+			       &rtparms->rtp_preference,
+			       &rtparms->rtp_precedence,
+			       bnp->bgp_ifap,
+			       (void_t) asp);
 	}
 
 	if (nousenet && BIT_TEST(bnp->bgp_options, BGPO_KEEPNONE)) {
@@ -7912,22 +7990,22 @@
 		goto deadduck;
 	    }
 
-	    if (api.api_mpunreach_nlri != 0)
+	    if (api.api_mpunreach_nlri != NULL)
 		has_mp_attr++;
-	    if (api.api_mpreach_nlri != 0)
+	    if (api.api_mpreach_nlri != NULL)
 		has_mp_attr++;
 
-	    if (api.api_mpunreach_nlri != 0) {
+	    if (api.api_mpunreach_nlri != NULL) {
 		if (!bgp4mp_recv_unreach(tp, attrlen, asp, &api, &routes_in,
 					 bsp)) {
 		    goto deadduck;
 		}
-		unreachlen = aspath_zap_mp_attr(asp, &api,
+		unreachlen = aspath_zap_mp_attr(&api,
 						attrlen, PA4_TYPE_MPUNRNLRI);
-		api.api_mpunreach_nlri = 0;
+		api.api_mpunreach_nlri = NULL;
 		has_mp_attr--;
 
-		if ((attrlen = unreachlen) == 0) {
+		if (unreachlen == 0) {
 		    if (cp != cpend) {
 			trace_log_tp(tp,
 				     0,
@@ -7945,7 +8023,7 @@
 	    /*
 	     * If the next hop wasn't included, complain about this.
 	     */
-	    if (api.api_mpreach_nlri != 0 && routelen
+	    if (api.api_mpreach_nlri != NULL && routelen
 		&& !BIT_TEST(api.api_flags, APIF_NEXTHOP)) {
 		trace_log_tp(tp,
 			     0,
@@ -7959,6 +8037,7 @@
 
 	    rtparms.rtp_metric = rtparms.rtp_metric2 = BGP_METRIC_NONE;
 
+	    /* checking LOCAL_PERF included */
 	    if (BGP_GROUP_EXTERNAL(bgp)) {
 		if (BIT_TEST(api.api_flags, APIF_LOCALPREF)) {
 		    trace_log_tp(tp,
@@ -7967,7 +8046,7 @@
 				 ("bgp4+_recv_update: external peer %s UPDATE included LOCALPREF attribute",
 				  bnp->bgp_name));
 		}
-	    } else {
+	    } else {		/* Internal peer */
 		if ((has_mp_attr || routelen)
 		    && !BIT_TEST(api.api_flags, APIF_LOCALPREF)) {
 		    trace_log_tp(tp,
@@ -8003,7 +8082,7 @@
 	     * fussy about path attributes in this case and we can gain
 	     * a bit of speed processing these.
 	     */
-	    if ((api.api_mpreach_nlri == 0) && (routelen == 0)) {
+	    if ((api.api_mpreach_nlri == NULL) && (routelen == 0)) {
 		trace_log_tp(tp,
 			     0,
 			     LOG_WARNING,
@@ -8013,9 +8092,9 @@
 		int hasasout, nouse;
 		int noinstall = 0;
 
-		if (api.api_mpreach_nlri != 0) {
-		    (void) aspath_zap_mp_attr(asp, &api,
-					attrlen, PA4_TYPE_MPREACHNLRI);
+		if (api.api_mpreach_nlri != NULL) {
+		    (void) aspath_zap_mp_attr(&api, attrlen,
+					      PA4_TYPE_MPREACHNLRI);
 		}
 
 		/*
@@ -8351,13 +8430,13 @@
 			}
 		    }
 		}	/* end of while (cp < cpend) */
-		if (api.api_mpreach_nlri != 0) {
+		if (api.api_mpreach_nlri != NULL) {
 		    if (!bgp4mp_recv_reach(tp, asp, &api, &rtparms,
 					   &routes_in, defpref, nouse,
 					   noinstall, bsp)) {
 			goto deadduck;
 		    }
-		    api.api_mpreach_nlri = 0;
+		    api.api_mpreach_nlri = NULL;
 		    has_mp_attr--;
 		}
 		assert(has_mp_attr == 0);
@@ -8590,7 +8669,8 @@
 
 /*
  * bgp4mp_rt_peer_init - initialize the route queues for a peer.  This
- * allocates the AS path hash array and makes sure the pointers are zeroed.
+ *                       allocates the AS path hash array and makes
+ *                       sure the pointers are zeroed.
  */
 static void
 bgp4mp_rt_peer_init __PF1(bnp, bgpPeer *)
@@ -9369,10 +9449,10 @@
     bnp->bgp_rto_next_time = (time_t) 0;
 }
 
-
 /*
- * bgp4mp_rt_send_init - initialize the peer by allocating a routing bit,
- *   if necessary, and sending an initial blast of routes.
+ * bgp4mp_rt_send_init - initialize the peer by allocating a routing
+ *                       bit, if necessary, and sending an initial
+ *                       blast of routes.
  */
 void
 bgp4mp_rt_send_init __PF1(bnp, bgpPeer *)
@@ -9457,7 +9537,7 @@
 	}
 	BIT_RESET(bnp->bgp_flags, BGPF_INITIALIZING);
 	if (res == 0) {
-	bgp4mp_set_write(bnp);
+	    bgp4mp_set_write(bnp);
 	} else if (bgp->bgpg_type != BGPG_EXTERNAL) {
 	    bgp4mp_rt_sync(bnp);
 	}
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp_init.c gated-R3_5/src/bgp_init.c
--- gated-pub-ipv6-snapshot-0399/src/bgp_init.c	Sat Mar 27 09:33:07 1999
+++ gated-R3_5/src/bgp_init.c	Sat Mar 27 11:28:39 1999
@@ -221,6 +221,7 @@
     {BGPO_IGNOREFIRSTASHOP, "IgnoreFirstASHop"},
     {BGPO_IGNORELOCALPREF, "IgnoreLocalPref"},
     {BGPO_SETNEXTHOPPEER, "SetNextHopPeer"},
+    {BGPO_AS_COUNT, "ASCount"},
     {0}
 };
 
@@ -4483,6 +4484,7 @@
     bgp->bgpg_preference = bgp_default_preference;
     bgp->bgpg_preference2 = bgp_default_preference2;
     bgp->bgpg_localpref = bgp_default_localpref;
+    bgp->bgpg_as_count = 1;
 
     return (bgp);
 }
@@ -4532,6 +4534,10 @@
   "internal BGP peers associated with an IGP must run at version 3 or better");
 	    return (bgpPeerGroup *)NULL;
 	}
+	if (BIT_TEST(bgp->bgpg_options, BGPO_AS_COUNT)) {
+	  (void) sprintf(errstr, "as_count only makes sense with external peers");
+	  return (bgpPeerGroup *)NULL;
+	}
     } else if (bgp->bgpg_type == BGPG_EXTERNAL) {
 	if (bgp->bgpg_local_as == bgp->bgpg_peer_as) {
 	    (void) sprintf(errstr,
@@ -4746,6 +4752,10 @@
 		 return (bgpPeer *) 0;
 	     }
 	 }
+	if (BIT_TEST(bnp->bgp_options, BGPO_AS_COUNT)) {
+	  (void) sprintf(errstr, "as_count only makes sense with external peers");
+	  return (bgpPeer *) NULL;
+	}
     } else {			/* EXTERNAL Peer */
         if (BIT_TEST(bnp->bgp_options, BGPO_SETNEXTHOPPEER)) {
 	    (void) sprintf(errstr,
@@ -4809,7 +4819,10 @@
 	|| (obnp->bgp_gateway != NULL
 	    && !sockaddrcmp_in(bnp->bgp_gateway, obnp->bgp_gateway))
 	|| (BIT_TEST(obnp->bgp_options, BGPO_SETNEXTHOPPEER) !=
-            BIT_TEST(bnp->bgp_options, BGPO_SETNEXTHOPPEER))) {
+            BIT_TEST(bnp->bgp_options, BGPO_SETNEXTHOPPEER))
+	|| (BIT_TEST(obnp->bgp_options, BGPO_AS_COUNT) !=
+	    BIT_TEST(bnp->bgp_options, BGPO_AS_COUNT))
+	|| (obnp->bgp_as_count != bnp->bgp_as_count)) {
 	bgp_peer_add(bgp, bnp);
 	return (bnp);
     }
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp_mib.c gated-R3_5/src/bgp_mib.c
--- gated-pub-ipv6-snapshot-0399/src/bgp_mib.c	Sat Mar 27 09:33:10 1999
+++ gated-R3_5/src/bgp_mib.c	Sat Mar 27 11:28:42 1999
@@ -5,11 +5,6 @@
  */
 
 /*
- * BGP4+ alpha && IPv6 
- * TONEv1 - advapi02 
- */
-
-/*
  * ------------------------------------------------------------------------
  * 
  * Copyright (c) 1996, 1997, 1998 The Regents of the University of Michigan
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/bgp_rt.c gated-R3_5/src/bgp_rt.c
--- gated-pub-ipv6-snapshot-0399/src/bgp_rt.c	Sat Mar 27 09:33:34 1999
+++ gated-R3_5/src/bgp_rt.c	Sat Mar 27 11:28:45 1999
@@ -1919,6 +1919,8 @@
 	api.api_localid = bnp->bgp_out_id;
     }
 
+    api.api_as_count = bnp->bgp_as_count;
+
     /*
      * Initialize nhaddr in case we need it.
      */
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/configs/kame_bsdi gated-R3_5/src/configs/kame_bsdi
--- gated-pub-ipv6-snapshot-0399/src/configs/kame_bsdi	Thu Jan  1 09:00:00 1970
+++ gated-R3_5/src/configs/kame_bsdi	Tue Mar 30 11:11:29 1999
@@ -0,0 +1,70 @@
+#
+#	apache,v 1.1.2.4 1995/05/01 16:25:19 jch Exp
+#
+#	Configuration for BSD/OS 3.1 + KAME
+#					by  Toshio Shimojou
+#
+
+bindir	/usr/local/v6/bin
+sbindir	/usr/local/v6/sbin
+mandir	/usr/local/v6/man
+mantype	bsd44
+
+signal_h	/usr/include/sys/signal.h
+
+cc	shlicc2
+
+cwflags -W -Wall -Wno-unused -Wno-comment -Wno-implicit -Wnested-externs -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Winline
+cflags  -pipe -g -O
+
+#ldflags -lkvm -L/usr/contrib/isode/lib -lisnmp -lisode
+ldflags -lkvm -L/usr/local/v6/lib -linet6 -lc
+
+lex	lex
+lflags	-p -Cfe
+yacc	yacc
+yflags	-d -v
+
+mkdep	mkdep -flag -MM
+
+options GDCCORENAME=""core.%s""
+options	INCLUDE_UNISTD INCLUDE_PATHS GID_T=gid_t
+options	POSIX_SIGNALS HAVE_WAITPID
+options	VARIABLE_MASKS SOCKET_LENGTHS SOCKADDR_DL INCLUDE_IF_DL
+options	KRT_RTREAD_KINFO KRT_IFREAD_KINFO KRT_RT_SOCK USE_SYSCTL KRT_RT_NOCHANGE
+options KRT_LLADDR_NONE KRT_SYMBOLS_SYSCTL KVM_TYPE_BSD44 KSYM_VERSION=VRS_SYM
+options KRT_SOCKET_TYPE="PF_ROUTE, SOCK_RAW, AF_UNSPEC"
+options GDC_RESOURCE
+#options	RT_N_MULTIPATH=4
+#options YYDEBUG TEST_ASMATCH TIME_ASMATCH
+# > (Max Port 194 + Bgp_Peer + ospf + kernal + aggregate + etc) / 32 
+# (256 bits) = 8
+options RTBIT_SIZE=4
+options INET6
+options BGP4MP_BADNET_IGNORE
+options BGP_ROUTE_SELECT
+options NORMALLIZE_RIPNG_ROUTE
+options RT_FLASH_DEBUG
+#options USE_ZLIB
+options HAVE_RCVDSTADDR
+options IPV6_NETINET6
+# for debug options
+options BGP_FLASH_DEBUG
+
+path_dump	/var/tmp/%s_dump
+path_dumpdir	/var/tmp
+path_pid	/var/run/%s.pid
+path_version	/var/run/%s.version
+path_unix	/bsd
+
+protocols	bgp bgp4mp icmp rip ripng icmpv6
+#protocols	bgp bgp4mp icmp rip ripng icmpv6 pimv6
+#protocols	bgp icmp rip ospf rdisc bgp4mp
+
+gdc_group	wheel
+
+#isode_snmpi	/usr/contrib/isode/bin/snmpi
+
+#isode_mosy	/usr/contrib/isode/bin/mosy
+
+#isode_snmp_include	/usr/contrib/isode/include/snmp
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/configs/kame_freebsd gated-R3_5/src/configs/kame_freebsd
--- gated-pub-ipv6-snapshot-0399/src/configs/kame_freebsd	Thu Jan  1 09:00:00 1970
+++ gated-R3_5/src/configs/kame_freebsd	Tue Mar 30 11:11:29 1999
@@ -0,0 +1,70 @@
+#
+#	apache,v 1.1.2.4 1995/05/01 16:25:19 jch Exp
+#
+#	Configuration for FreeBSD 2.2.8 + KAME
+#					by  Toshio Shimojou
+#
+
+bindir	/usr/local/v6/bin
+sbindir	/usr/local/v6/sbin
+mandir	/usr/local/v6/man
+mantype	bsd44
+
+signal_h	/usr/include/sys/signal.h
+
+cc	cc
+
+cwflags -W -Wall -Wno-unused -Wno-comment -Wno-implicit -Wnested-externs -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -Wmissing-prototypes -Winline
+cflags  -pipe -g -O
+
+#ldflags -lkvm -L/usr/contrib/isode/lib -lisnmp -lisode
+ldflags -lkvm -L/usr/local/v6/lib -linet6 -lc
+
+lex	lex
+lflags	-p -Cfe
+yacc	yacc
+yflags	-d -v
+
+mkdep	mkdep -flag -MM
+
+options GDCCORENAME=""core.%s""
+options	INCLUDE_UNISTD INCLUDE_PATHS GID_T=gid_t
+options	POSIX_SIGNALS HAVE_WAITPID
+options	VARIABLE_MASKS SOCKET_LENGTHS SOCKADDR_DL INCLUDE_IF_DL
+options	KRT_RTREAD_KINFO KRT_IFREAD_KINFO KRT_RT_SOCK USE_SYSCTL
+options KRT_LLADDR_NONE KRT_SYMBOLS_SYSCTL KVM_TYPE_BSD44 KSYM_VERSION=VRS_SYM
+options KRT_SOCKET_TYPE="PF_ROUTE, SOCK_RAW, AF_UNSPEC"
+options GDC_RESOURCE
+#options	RT_N_MULTIPATH=4
+#options YYDEBUG TEST_ASMATCH TIME_ASMATCH
+# > (Max Port 194 + Bgp_Peer + ospf + kernal + aggregate + etc) / 32 
+# (256 bits) = 8
+options RTBIT_SIZE=4
+options INET6
+options BGP4MP_BADNET_IGNORE
+options BGP_ROUTE_SELECT
+options NORMALLIZE_RIPNG_ROUTE
+options RT_FLASH_DEBUG
+#options USE_ZLIB
+options HAVE_RCVDSTADDR
+options IPV6_NETINET6
+# for debug options
+options BGP_FLASH_DEBUG
+
+path_dump	/var/tmp/%s_dump
+path_dumpdir	/var/tmp
+path_pid	/var/run/%s.pid
+path_version	/var/run/%s.version
+path_unix	/kernel
+
+protocols	bgp bgp4mp icmp rip ripng icmpv6
+#protocols	bgp bgp4mp icmp rip ripng icmpv6 pimv6
+#protocols	bgp icmp rip ospf rdisc bgp4mp
+
+gdc_group	wheel
+
+#isode_snmpi	/usr/contrib/isode/bin/snmpi
+
+#isode_mosy	/usr/contrib/isode/bin/mosy
+
+#isode_snmp_include	/usr/contrib/isode/include/snmp
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/configs/merit.inria-netbsd gated-R3_5/src/configs/merit.inria-netbsd
--- gated-pub-ipv6-snapshot-0399/src/configs/merit.inria-netbsd	Sat Mar 27 10:08:45 1999
+++ gated-R3_5/src/configs/merit.inria-netbsd	Tue Mar 16 11:18:52 1999
@@ -39,8 +39,7 @@
 # > (Max Port 194 + Bgp_Peer + ospf + kernal + aggregate + etc) / 32 
 # (256 bits) = 8
 options RTBIT_SIZE=4
-options DRAFT926
-options BGP4MP_BADNET_IGNORE NEED_MLD6_HDR IPV6_NETINET HAVE_BCOPY IPV6_MULTI_IF 
+options BGP4MP_BADNET_IGNORE NEED_MLD6_HDR IPV6_NETINET
 
 path_dump	/var/tmp/%s_dump
 path_dumpdir	/var/tmp
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/icmpv6.c gated-R3_5/src/icmpv6.c
--- gated-pub-ipv6-snapshot-0399/src/icmpv6.c	Sat Mar 27 09:34:48 1999
+++ gated-R3_5/src/icmpv6.c	Mon Mar 29 23:05:05 1999
@@ -739,17 +739,15 @@
 	case MLD6_LISTENER_QUERY:
 	case MLD6_LISTENER_REPORT:
 	case MLD6_LISTENER_DONE:
+	    mld6 = (struct mld6_hdr *)icmp;
+	    tracef(" group %A",
+		   sockbuild_in6(0, (byte *) &mld6->mld6_addr));
 #else
 	case ICMP6_MEMBERSHIP_QUERY:
 	case ICMP6_MEMBERSHIP_REPORT:
 	case ICMP6_MEMBERSHIP_REDUCTION :
 #endif
-#ifdef 0
-	    mld6 = (struct mld6_hdr *)icmp;
-	    tracef(" group %A",
-		   sockbuild_in6(0, (byte *) &mld6->mld6_addr));
 	    break;
-#endif
 	case ND_ROUTER_SOLICIT:
 	    break;
 
@@ -776,7 +774,7 @@
 		   ntohs(icmp->icmp6_id),
 		   ntohs(icmp->icmp6_seq));
 	}
-#if 0
+#if 0				/* XXX shimojou */
 	if (do_dest) {
 	    tracef(" dest %A protocol %s(%u)",
 		   sockbuild_in6(0, (byte *) &icmp->icmp6_ip.ip6_dst),
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/icmpv6.h gated-R3_5/src/icmpv6.h
--- gated-pub-ipv6-snapshot-0399/src/icmpv6.h	Sat Mar 27 09:34:49 1999
+++ gated-R3_5/src/icmpv6.h	Mon Mar 29 23:05:05 1999
@@ -89,7 +89,6 @@
 		    struct icmp6_hdr *,
 		    size_t));
 
-
 /* Tracing */
 
 #define	TR_ICMPV6_DETAIL_REDIRECT	TR_DETAIL_1
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/if.c gated-R3_5/src/if.c
--- gated-pub-ipv6-snapshot-0399/src/if.c	Sat Mar 27 09:34:56 1999
+++ gated-R3_5/src/if.c	Mon Mar 29 23:05:05 1999
@@ -157,8 +157,8 @@
 
 
 /*
- * Find the interface with specified address.  Matches the destination address
- * of P2P interfaces.
+ * Find the interface with specified address.  Matches the destination
+ * address of P2P interfaces. 
  */
 if_info *
 ifi_withaddr __PF3(addr, sockaddr_un *,
@@ -186,8 +186,8 @@
 }
 
 /*
- * Find the interface with the specified address.  Matches the local address
- * of P2P interfaces
+ * Find the interface with the specified address.  Matches the local
+ * address of P2P interfaces
  */
 if_info *
 ifi_withlcladdr __PF3(addr, sockaddr_un *,
@@ -216,7 +216,8 @@
 
 
 /*
- * Find the POINTOPOINT or LOOPBACK interface with the specified address.
+ * Find the POINTOPOINT or LOOPBACK interface with the specified
+ * address.
  */
 if_info *
 ifi_withdstaddr __PF2(addr, sockaddr_un *,
@@ -274,7 +275,10 @@
 
 	    if (!ifi_maybe ||
 		mask_refines(ifi->ifi_netmask, ifi_maybe->ifi_netmask)) {
-		/* This is the only mask or is more specific than the last one */
+		/*
+		 * This is the only mask or is more specific than the
+		 * last one
+		 */
 		ifi_maybe = ifi;
 	    }
 	}
@@ -287,9 +291,9 @@
 
 
 /*
- * Find the interface for the specified gateway.  First try to find a P2P interface
- * with the specified address, then find out if we are on the attached network of
- * any multi-access interfaces.
+ * Find the interface for the specified gateway.  First try to find a
+ * P2P interface with the specified address, then find out if we are
+ * on the attached network of any multi-access interfaces.
  */
 if_info *
 ifi_withdst __PF2(dstaddr, sockaddr_un *,
@@ -443,7 +447,8 @@
 #endif /* PROTO_INET6 */
 
 /*
- * Find the interface with the specified local address or net/subnet address
+ * Find the interface with the specified local address or net/subnet
+ * address
  */
 int
 if_myaddr __PF3(ifap, if_addr *,
@@ -1578,7 +1583,10 @@
 	/* Reset the refresh indication */
 	BIT_RESET(ifl->ifl_change, IFC_REFRESH);
 
-	/* Display a message and notify the protocols if something has changed */
+	/*
+	 * Display a message and notify the protocols if something has
+         * changed
+	 */
 	if (ifl->ifl_change != IFC_NOCHANGE) {
 	    int pri = BIT_TEST(task_state, TASKS_INIT|TASKS_TEST) ? 0 : LOG_INFO;
 
@@ -1925,11 +1933,12 @@
 	    network = (sockaddr_un *) 0;
 	    ifi->ifi_netmask = inet_mask_host;
 	} else if (BIT_TEST(ifi->ifi_state, IFS_POINTOPOINT)) {
-	    /* If the netmask looks valid we keep it so protocols */
-	    /* that do not pass masks will be able to use it to */
-	    /* determine which subnets they can send.  The subnet */
-	    /* is always left as zero though */
-
+	    /*
+	     * If the netmask looks valid we keep it so protocols that
+	     * do not pass masks will be able to use it to determine
+	     * which subnets they can send.  The subnet is always left
+	     * as zero though
+	     */
 	    if (ifi->ifi_netmask == inet_mask_natural(ifi->ifi_addr)
 		|| ifi->ifi_netmask == inet_mask_host) {
 		/* Mask is not valid, assume host mask */
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/include.h gated-R3_5/src/include.h
--- gated-pub-ipv6-snapshot-0399/src/include.h	Sat Mar 27 09:35:08 1999
+++ gated-R3_5/src/include.h	Mon Mar 29 23:05:06 1999
@@ -198,21 +198,21 @@
 # if defined(IPV6_NETINET)
 #  include <netinet/ip6_var.h>
 #  include <arpa/inet.h>
+#  if defined(HITACHI_INET6)
+#   include <netinet/in6_systm.h>
+#  endif
 #  include <netinet/ip6.h>
-#  ifdef INCLUDE_UDP
-#   include <netinet/udp6_var.h>
-#  endif /* INCLUDE_UDP */
 # endif /* IPV6_NETINET */
 
-#  ifdef IPV6_NETINET6
-#   include <netinet6/in6.h> 
-#   include <netinet6/ip6_var.h> 
-#   include <arpa/inet.h>
-#   include <netinet6/in6_systm.h>  
-#   include <netinet6/ip6.h>
-#   ifdef INCLUDE_UDP
-#    include <netinet6/udp6_var.h>
-#   endif /* INCLUDE_UDP */
+# ifdef IPV6_NETINET6
+#  include <netinet6/in6.h> 
+#  include <netinet6/ip6_var.h> 
+#  include <arpa/inet.h>
+#  include <netinet6/in6_systm.h>  
+#  include <netinet6/ip6.h>
+#  ifdef INCLUDE_UDP
+#   include <netinet6/udp6_var.h>
+#  endif /* INCLUDE_UDP */
 #  endif /* IPV6_NETINET6  */
 
 # define ascii2addr(family, ascii, addr) inet_pton(family, ascii, addr)
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/inet6.c gated-R3_5/src/inet6.c
--- gated-pub-ipv6-snapshot-0399/src/inet6.c	Sat Mar 27 09:35:17 1999
+++ gated-R3_5/src/inet6.c	Sat Mar 27 11:41:02 1999
@@ -227,7 +227,6 @@
     }
 }
 
-#if	defined(PROTO_INET6)
 byte
 inet6_scope_of __PF1(addr, sockaddr_un *)
 {
@@ -279,7 +278,6 @@
 
     return ret;
 }
-#endif /* PROTO_INET6 */
 
 /*
  *	Reinit
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/inet6.h gated-R3_5/src/inet6.h
--- gated-pub-ipv6-snapshot-0399/src/inet6.h	Sat Mar 27 09:35:21 1999
+++ gated-R3_5/src/inet6.h	Mon Mar 29 23:05:06 1999
@@ -145,9 +145,6 @@
 			  && ((a).s6_addr32[3] == (b).s6_addr32[3]))
 #endif /* SHIN */
 
-
-
-#ifdef PROTO_INET6
 #ifndef IS_ANYADDR6
 #define IS_ANYADDR6(a) IN6_IS_ADDR_UNSPECIFIED(&(a))
 #endif
@@ -157,10 +154,16 @@
 #ifndef IS_MULTIADDR6
 #define IS_MULTIADDR6(a) IN6_IS_ADDR_MULTICAST(a)
 #endif
+#ifndef IN6_ARE_ADDR_EQUAL
+#define IN6_ARE_ADDR_EQUAL(a, b) \
+        ( ((a)->s6_addr32[0] == (b)->s6_addr32[0])\
+        &&((a)->s6_addr32[1] == (b)->s6_addr32[1])\
+        &&((a)->s6_addr32[2] == (b)->s6_addr32[2])\
+        &&((a)->s6_addr32[3] == (b)->s6_addr32[3]) )
+#endif /* !IN6_ARE_ADDR_EQUAL */
 #ifndef SAME_ADDR6
 #define SAME_ADDR6(a,b) IN6_ARE_ADDR_EQUAL(&(a), &(b))
 #endif
-
 #define PUT_IFINDEX_ADDR6(a, index)  \
 		  {  \
 			u_int16 lla_index = (index); \
@@ -168,19 +171,6 @@
 		 	(a).s6_addr[2] = *lptr++; \
 	         	(a).s6_addr[3] = *lptr; }  
 
-#endif /* PROTO_INET6 */
-
-#ifdef PROTO_INET6
-#ifndef IN6_ARE_ADDR_EQUAL
-#define IN6_ARE_ADDR_EQUAL(a, b) \
-	( ((a)->s6_addr32[0] == (b)->s6_addr32[0])\
-	&&((a)->s6_addr32[1] == (b)->s6_addr32[1])\
-	&&((a)->s6_addr32[2] == (b)->s6_addr32[2])\
-	&&((a)->s6_addr32[3] == (b)->s6_addr32[3]) )
-#endif /* !IN6_ARE_ADDR_EQUAL */
-#endif /* PROTO_INET6 */
-
-#ifdef 0
 #ifdef	SUNOS5_0
 #define IS_ANYADDR6(a) (((a).s6_addr[0] == 0) \
 			&& ((a).s6_addr[1] == 0) \
@@ -191,8 +181,6 @@
 			  && ((a).s6_addr[2] == (b).s6_addr[2]) \
 			  && ((a).s6_addr[3] == (b).s6_addr[3]))
 #endif	/* SUNOS5_0 */
-#endif
-
 
 /* macros to select IPv6 address given pointer to a struct sockaddr */
 
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/krt.c gated-R3_5/src/krt.c
--- gated-pub-ipv6-snapshot-0399/src/krt.c	Sat Mar 27 09:57:32 1999
+++ gated-R3_5/src/krt.c	Mon Mar 29 23:05:06 1999
@@ -2833,7 +2833,7 @@
 	&& (!BIT_TEST(rth->rth_state, RTS_ONLIST)
 	    || BIT_TEST(task_state, TASKS_INIT))) {
 	if (BIT_TEST(rt->rt_state, KRT_RTS_NO_NEXTHOP)) {
-	    if (no_nexthop_bits == (rt->rt_state & KRT_RTS_NO_NEXTHOP)) {
+	    if (no_nexthop_bits == (int)(rt->rt_state & KRT_RTS_NO_NEXTHOP)) {
 		match = 1;
 	    }
 #if	RT_N_MULTIPATH > 1
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/krt_ipv6multi_rtsock.c gated-R3_5/src/krt_ipv6multi_rtsock.c
--- gated-pub-ipv6-snapshot-0399/src/krt_ipv6multi_rtsock.c	Sat Mar 27 09:58:05 1999
+++ gated-R3_5/src/krt_ipv6multi_rtsock.c	Mon Mar 29 23:05:08 1999
@@ -292,7 +292,7 @@
     rtp->rtm_addrs = 0;
     rtp->rtm_type = RTM_GET;
     rtp->rtm_version = RTM_VERSION;
-    rtp->rtm_flags = RTF_MULTICAST | RTF_HOST;
+    rtp->rtm_flags = RTF_UP | RTF_HOST | RTF_GATEWAY;
 
     size += socksize(&dst);
     size += socksize(&src);
@@ -379,7 +379,7 @@
     rtp->rtm_addrs = 0;
     rtp->rtm_type = RTM_GET;
     rtp->rtm_version = RTM_VERSION;
-    rtp->rtm_flags = RTF_MULTICAST | RTF_HOST;
+    rtp->rtm_flags = RTF_UP | RTF_HOST | RTF_GATEWAY;
 
     size += socksize(&dst);
     size += socksize(&src);
@@ -456,8 +456,9 @@
 
 	return;
     }
-    BIT_SET(flags, RTF_MULTICAST);
+    BIT_SET(flags, RTF_UP);
     BIT_SET(flags, RTF_HOST);
+    BIT_SET(flags, RTF_GATEWAY);
 
     /*
      * count number of unique downstream interfaces
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/krt_rt_sock.c gated-R3_5/src/krt_rt_sock.c
--- gated-pub-ipv6-snapshot-0399/src/krt_rt_sock.c	Sat Mar 27 09:58:43 1999
+++ gated-R3_5/src/krt_rt_sock.c	Mon Mar 29 23:05:10 1999
@@ -811,7 +811,7 @@
 	/* Interace address */
 
 	ifi.ifi_addr_local = sockdup(ap);
-#ifdef  PROTO_INET6
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
 	if (ifi.ifi_addr_local && socktype(ifi.ifi_addr_local) == AF_INET6
 	    && inet6_scope_of(ifi.ifi_addr_local) == INET6_SCOPE_LINKLOCAL) {
 	    PUT_IFINDEX_ADDR6(sock2in6(ifi.ifi_addr_local), 0);
@@ -827,7 +827,7 @@
 
 	if (p2p) {
 	    ifi.ifi_addr = sockdup(ap);
-#ifdef  PROTO_INET6
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
 	    if (ifi.ifi_addr && socktype(ifi.ifi_addr) == AF_INET6
 		&& inet6_scope_of(ifi.ifi_addr) == INET6_SCOPE_LINKLOCAL) {
 		PUT_IFINDEX_ADDR6(sock2in6(ifi.ifi_addr), 0);
@@ -835,7 +835,7 @@
 #endif
 	} else {
 	    ifi.ifi_addr_broadcast = sockdup(ap);
-#ifdef  PROTO_INET6
+#if defined(PROTO_INET6) && !defined(HITACHI_INET6)
 	    if (ifi.ifi_addr_broadcast
 		&& socktype(ifi.ifi_addr_broadcast) == AF_INET6
 		&& inet6_scope_of(ifi.ifi_addr_broadcast)
@@ -1014,7 +1014,7 @@
 					 (byte *) 0,
 					 0), (int *) 0);
 	  size += unix_socksize((struct sockaddr *)s_ifp);
-#ifdef  PROTO_INET6
+#ifndef HITACHI_INET6
 	  PUT_IFINDEX_ADDR6(((struct sockaddr_in6 *)s_router)->sin6_addr, htons(iflink->ifl_index));
 #endif
       }	
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/krt_symbols_sysctl.c gated-R3_5/src/krt_symbols_sysctl.c
--- gated-pub-ipv6-snapshot-0399/src/krt_symbols_sysctl.c	Sat Mar 27 09:59:04 1999
+++ gated-R3_5/src/krt_symbols_sysctl.c	Mon Mar 29 23:05:11 1999
@@ -5,11 +5,6 @@
  */
 
 /*
- * BGP4+ alpha && IPv6 ( HITACHI_INET6 )
- * TONEv1 - advapi02 
- */
-
-/*
  * ------------------------------------------------------------------------
  * 
  * Copyright (c) 1996, 1997, 1998 The Regents of the University of Michigan
@@ -82,7 +77,7 @@
 #ifdef	PROTO_INET
 #include "inet.h"
 #endif	/* PROTO_INET */
-#ifdef PROTO_INET6 /* HITACHI_INET6 */
+#ifdef PROTO_INET6
 #include "inet6.h"
 #endif /* PROTO_INET6 */
 #include "krt.h"
@@ -157,16 +152,19 @@
     }
 #endif	/* PROTO_INET */
 
-#ifdef PROTO_INET6 /* HITACHI_INET6 */
+#ifdef PROTO_INET6
     name[0] = CTL_NET;
     name[1] = PF_INET6;
     name[2] = 0; /* IPPROTO_IPV6 */
-#ifdef IPV6_NETINET
-#define IP6CTL_FORWARDING 1
-    name[3] = IP6CTL_FORWARDING;
+#ifndef IPV6CTL_FORWARDING
+#ifdef IP6CTL_FORWARDING
+#define IPV6CTL_FORWARDING IP6CTL_FORWARDING
 #else
-    name[3] = IPV6CTL_FORWARDING; 
+#define IPV6CTL_FORWARDING 1
 #endif
+#endif
+    name[3] = IPV6CTL_FORWARDING;
+
     len = sizeof value;
     if (sysctl(name, 4, (void *) &value, &len, (void *) 0, 0) < 0) {
         trace_log_tp(tp,
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/lexer.l gated-R3_5/src/lexer.l
--- gated-pub-ipv6-snapshot-0399/src/lexer.l	Sat Mar 27 09:58:15 1999
+++ gated-R3_5/src/lexer.l	Mon Mar 29 23:05:11 1999
@@ -6,11 +6,6 @@
  */
 
 /*
- * BGP4+ alpha && IPv6 ( HITACHI_INET6 )
- * TONEv1 - advapi02 
- */
-
-/*
  * ------------------------------------------------------------------------
  * 
  * Copyright (c) 1996, 1997 The Regents of the University of Michigan
@@ -519,7 +514,7 @@
 			return L_USEC;
 		}
 <CONFIG>{ipv6addr}	{
-#ifdef PROTO_INET6 /* HITACHI_INET6 */
+#ifdef PROTO_INET6
 			register char *cp;
 			register byte *dp;
 
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/parse.c gated-R3_5/src/parse.c
--- gated-pub-ipv6-snapshot-0399/src/parse.c	Sat Mar 27 10:00:45 1999
+++ gated-R3_5/src/parse.c	Mon Mar 29 23:05:12 1999
@@ -365,6 +365,11 @@
     KWE(T_AS, "autonomous-system"),
     KWE(T_AS, "autonomoussystem"),
 #endif	/* T_AS */
+#ifdef T_ASCOUNT
+    KWE(T_ASCOUNT, "as_count"),
+    KWE(T_ASCOUNT, "as-count"),
+    KWE(T_ASCOUNT, "ascount"),
+#endif /* T_ASCOUNT */
 #ifdef	T_ASPATH
     KWE(T_ASPATH,	"as-path"),
     KWE(T_ASPATH,	"aspath"),
@@ -562,11 +567,12 @@
 #ifdef	T_ICMP
     KWE(T_ICMP, "icmp"),
 #endif	/* T_ICMP */
-#if 0 /* HITACHI_INET6 */
-#ifdef T_ICMPV6
-	KWE(T_ICMPV6, "icmpv6"),
-#endif
-#endif
+#ifdef	T_ICMPV6
+    KWE(T_ICMPV6, "icmpv6"),
+#endif	/* T_ICMPV6 */
+#ifdef	T_ID
+    KWE(T_ID, "id"),
+#endif	/* T_ID */
 #ifdef	T_IDPR
     KWE(T_IDPR, "idpr"),
 #endif	/* T_IDPR */
@@ -589,7 +595,7 @@
     KWE(T_IGNORELOCALPREF, "ignore-localpref"),
     KWE(T_IGNORELOCALPREF, "ignorelocalpref"),
     KWE(T_IGNORELOCALPREF, "ignore-local-pref"),
-#endif  /* T_SETLOCALPREF */
+#endif  /* T_IGNORELOCALPREF */
 #ifdef	T_IGP
     KWE(T_IGP,	"igp"),
 #endif	/* T_IGP */
@@ -794,12 +800,6 @@
     KWE(T_NEIGHBOR, "neighbour"),
     KWE(T_NEIGHBOR, "peer"),
 #endif	/* T_NEIGHBOR */
-#if 0 /* HITACHI_INET6 */
-#ifdef T_NEIGHBORDISCOVERY
-	KWE(T_NEIGHBORDISCOVERY, "neighbor-discovery"),
-	KWE(T_NEIGHBORDISCOVERY, "neighbordiscovery"),
-#endif
-#endif
 #ifdef	T_NEIGHBORID
     KWE(T_NEIGHBORID, "neighborid"),
     KWE(T_NEIGHBORID, "neighbourid"),
@@ -2035,7 +2035,7 @@
  *	the current state
  */
 int
-parse_new_state __PF1(state, int)
+parse_new_state __PF1(state, u_int)
 {
     static const bits states[] = {
         { PS_INITIAL,	"initial" },
@@ -2250,10 +2250,11 @@
  *	Set metric for each element in list that does not have one
  */
 adv_entry *
-parse_adv_propagate_metric __PF6(list, adv_entry *,
+parse_adv_propagate_metric __PF7(list, adv_entry *,
 				 proto, proto_t,
 				 metric, pmet_t *,
 				 metric2, pmet_t *,
+				 ascount, u_int,
 				 state, int,
 				 advlist, adv_entry *)
 {
@@ -2279,6 +2280,9 @@
 	        BIT_SET(adv->adv_flag, ADVFOT_METRIC);
 	        adv->adv_result.res_metric = metric->metric;
 	    }
+	    if (ascount) {
+		adv->adv_result.res_ascount = ascount;
+	    };
 	}
     } ADV_LIST_END(list, adv) ;
 
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/parse.h gated-R3_5/src/parse.h
--- gated-pub-ipv6-snapshot-0399/src/parse.h	Sat Mar 27 10:00:46 1999
+++ gated-R3_5/src/parse.h	Mon Mar 29 23:05:12 1999
@@ -5,11 +5,6 @@
  */
 
 /*
- * BGP4+ alpha && IPv6 
- * TONEv1 - advapi02 
- */
-
-/*
  * ------------------------------------------------------------------------
  * 
  * Copyright (c) 1996, 1997, 1998 The Regents of the University of Michigan
@@ -98,6 +93,7 @@
 #define	LIMIT_NATURAL		0, (u_int) -1
 #define	LIMIT_MINUTES		0, 59
 #define	LIMIT_SECONDS		0, 59
+#define LIMIT_ASCOUNT		1, 25
 
 #define	FI_MAX	10			/* Maxiumum %include nesting level */
 
@@ -186,7 +182,7 @@
 	  sockaddr_un *,
 	  (char *,
 	   char *));			/* Lookup a string as a host name */
-#ifdef PROTO_INET6		
+#ifdef PROTO_INET6
 PROTOTYPE(parse_addr6_hostname,
           sockaddr_un *,
           (char *,
@@ -207,7 +203,7 @@
 	   flag_t));			/* Set flag in gw_entry for each element in list */
 PROTOTYPE(parse_new_state,
 	  int,
-	  (int));			/* Switch to a new state if it is a logical progression */
+	  (u_int));			/* Switch to a new state if it is a logical progression */
 								/* from the current state */
 PROTOTYPE(parse_metric_check,
 	  int,
@@ -227,6 +223,7 @@
 	   proto_t,
 	   pmet_t *,
 	   pmet_t *,
+	   u_int,
 	   int,
 	   adv_entry *));			/* Set metric in list for elements without metrics */
 PROTOTYPE(parse_adv_propagate_preference,
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/parser.y gated-R3_5/src/parser.y
--- gated-pub-ipv6-snapshot-0399/src/parser.y	Sat Mar 27 10:02:32 1999
+++ gated-R3_5/src/parser.y	Mon Mar 29 23:05:12 1999
@@ -2,7 +2,7 @@
 /*
  * Public Release 3
  * 
- * $Id: parser.y,v 1.16.2.2 1999/01/28 17:46:19 wfs Exp $
+ * $Id: parser.y,v 1.14.2.12 1999/03/29 14:05:12 shimojou Exp $
  */
 
 /*
@@ -230,6 +230,7 @@
     time_t	time;
     utime_t	utime;
     as_t	as;
+    u_int	ascount;
     proto_t	proto;
     pmet_t	metric;
     pref_t	pref;
@@ -248,6 +249,7 @@
     struct {
 	pmet_t metric;
         pmet_t metric2;
+	u_int ascount;
         int state;
 	adv_entry *adv;
     } metric_adv ;
@@ -309,7 +311,7 @@
 %type	<time>		mark_time    
 
 /* BGP and EGP */
-%token	<num>		T_PEERAS T_LOCALAS T_NEIGHBOR T_GROUP
+%token	<num>		T_PEERAS T_LOCALAS T_NEIGHBOR T_GROUP T_ASCOUNT
 %token	<num>		T_NOGENDEFAULT T_VERSION
 %token	<num>		T_ACQUIRE T_TTL
 @BEGIN:	PROTO_INET
@@ -591,6 +593,7 @@
 %type	<num>		neg_number number		/* A decimal, hex, or octet string number */
 %type	<hex>		byte_string			/* A L_HEXSTRING or L_OCTETSTRING */
 %type	<metric>	metric metric_option metric2 metric2_option
+%type	<ascount>	ascount_option
 %type   <metric_adv>    metric_restrict_option
 %type	<time>		time
 %token	<num>		L_USEC
@@ -627,6 +630,7 @@
 %type	<metric>	precedence_option
 %type	<ifae>		interface_local    
 %type	<sockaddr>	interface_addr addr host mask
+%type   <num>		as_count
 @BEGIN:	PROTO_INET
 %token	<num>		T_INET    
 %type	<in_addr>	in_addr
@@ -636,7 +640,7 @@
 %type	<dm>		aggregate_dest_inet
 %type	<dm>		martian_inet
 %type	<adv>		martian_list_inet
-%type	<sockaddr>	default_gateway_option_inet default_gateway_option_inet6
+%type	<sockaddr>	default_gateway_option_inet
 %type	<gwp>		gateway_inet
 %type	<adv>	 	gateway_list_inet aggregate_list_inet aggregate_proto_inet
 %type	<proto>		aggregate_protos_inet
@@ -650,6 +654,7 @@
 %type	<adv>		martian_list_inet6
 %type	<gwp>		gateway_inet6
 %type	<adv>		gateway_list_inet6 aggregate_list_inet6 aggregate_proto_inet6
+%type	<sockaddr>	default_gateway_option_inet6
 %type	<proto>		aggregate_protos_inet6
 @END:	PROTO_INET6
 @BEGIN:	PROTO_ISO
@@ -5058,6 +5063,11 @@
 			    bcp->bgpc_local_as = $2;
 			    aslocal_set($2, 0);
 			}
+		| T_ASCOUNT as_count
+			{
+			    BIT_SET(bcp->bgpc_options, BGPO_AS_COUNT);
+			    bcp->bgpc_as_count = $2;
+			}
 		| T_NOGENDEFAULT
 			{
 			    BIT_SET(bcp->bgpc_options, BGPO_NOGENDEFAULT);
@@ -7530,7 +7540,7 @@
 			     *	for the specified protocol.
 			     */
 
-			    (void) parse_adv_propagate_metric($4, $3.proto, &$5.metric, &$5.metric2, $5.state, $5.adv);
+			    (void) parse_adv_propagate_metric($4, $3.proto, &$5.metric, &$5.metric2, 0, $5.state, $5.adv);
 
 			    switch ($4->adv_flag & ADVF_TYPE) {
 			    case ADVFT_GW:
@@ -7596,6 +7606,10 @@
 				    BIT_SET(adv->adv_flag, ADVFOT_METRIC2);
 				    adv->adv_result.res_metric2 = $7.metric2.metric;
 				}
+				if ($7.ascount) {
+				    BIT_SET(adv->adv_flag, ADVFOT_ASCOUNT);
+				    adv->adv_result.res_ascount = $7.ascount;
+				}
 			    }
 
 			    if (!parse_adv_as($4.export_list, adv)) {
@@ -7611,7 +7625,7 @@
 			     *  for the specified protocol.
 			     */
 
-			    (void) parse_adv_propagate_metric($5, $4.proto, &$6.metric, &$6.metric2, $6.state, $6.adv);
+			    (void) parse_adv_propagate_metric($5, $4.proto, &$6.metric, &$6.metric2, $6.ascount, $6.state, $6.adv);
 
 			    switch ($5->adv_flag & ADVF_TYPE) {
 			    case ADVFT_GW:
@@ -8682,12 +8696,16 @@
 
 			    $$ = adv_alloc(ADVFT_DM, (proto_t) 0);
 			    $$->adv_dm = $3;
-			    if (PARSE_METRIC_ISSET(&$4)) {
-				if (PARSE_METRIC_ISRESTRICT(&$4)) {
-				    BIT_SET($$->adv_flag, ADVF_NO);
-				} else {
+			    if (PARSE_METRIC_ISRESTRICT(&$4)) {
+			        BIT_SET($$->adv_flag, ADVF_NO);
+			    } else {
+			        if (PARSE_METRIC_ISSET(&$4.metric)) {
 				    BIT_SET($$->adv_flag, ADVFOT_PREFERENCE);
-				    $$->adv_result.res_preference = $4.metric;
+				    $$->adv_result.res_preference = $4.metric.metric;
+				}
+				if (PARSE_METRIC2_ISSET(&$4.metric2)) {
+				    BIT_SET($$->adv_flag, ADVFOT_PRECEDENCE);
+				    $$->adv_result.res_precedence = $4.metric2.metric;
 				}
 			    }
 			}
@@ -8822,13 +8840,13 @@
 
 prop_source_iso	: T_PROTO prop_direct interface_list_option prop_metric_option_iso
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			}
     /* Static routes */
 		| T_PROTO prop_static interface_list_option prop_metric_option_iso
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -8840,6 +8858,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -8847,7 +8866,7 @@
     /* Kernel static routes (routing socket) */
 		| T_PROTO prop_kernel interface_list_option prop_metric_option_iso
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -8860,6 +8879,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -8928,10 +8948,16 @@
 			    $$ = adv_alloc(ADVFT_DM, (proto_t) 0);
 			    $$->adv_dm = $3;
 			    if (PARSE_METRIC_ISRESTRICT(&$4)) {
-				BIT_SET($$->adv_flag, ADVF_NO);
-			    } else if (PARSE_METRIC_ISSET(&$4)) {
-				$$->adv_result.res_metric = $4.metric;
-				BIT_SET($$->adv_flag, ADVFOT_METRIC);
+			        BIT_SET($$->adv_flag, ADVF_NO);
+			    } else {
+			        if (PARSE_METRIC_ISSET(&$4.metric)) {
+				    $$->adv_result.res_metric = $4.metric.metric;
+				    BIT_SET($$->adv_flag, ADVFOT_METRIC);
+				}
+				if (PARSE_METRIC2_ISSET(&$4.metric2)) {
+				    $$->adv_result.res_metric2 = $4.metric2.metric;
+				    BIT_SET($$->adv_flag, ADVFOT_METRIC2);
+				}
 			    }
 			}
 		;
@@ -8976,13 +9002,13 @@
     /* Interfaces */
 		: T_PROTO prop_direct interface_list_option prop_metric_option_inet
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			}
     /* Static routes */
 		| T_PROTO prop_static interface_list_option prop_metric_option_inet
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -8994,6 +9020,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9001,7 +9028,7 @@
     /* Kernel static routes (routing socket) */
 		| T_PROTO prop_kernel interface_list_option prop_metric_option_inet
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -9011,8 +9038,9 @@
 			    $$ = parse_adv_propagate_metric(adv_alloc(ADVFT_ANY | ADVF_FIRST,
 								      (proto_t) 0),
 							    $2,
-							    &$3.metric
-,							    &$3.metric2,
+							    &$3.metric,
+							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9025,6 +9053,7 @@
 							    $2,
 							    &$5.metric
 ,							    &$5.metric2,
+							    0,
 							    $5.state,
 							    $5.adv);
 			    $$->adv_as = $4;
@@ -9040,6 +9069,7 @@
 							    $2,
 							    &$4.metric,
 							    &$4.metric2,
+							    0,
 							    $4.state,
 							    $4.adv);
 			    $$->adv_aspath = $3;
@@ -9054,6 +9084,7 @@
 							    $2,
 							    &$5.metric,
 							    &$5.metric2,
+							    0,
 							    $5.state,
 							    $5.adv);
 			    $$->adv_tag = $4.metric;
@@ -9065,7 +9096,7 @@
     /* RIP Imports */
 		| T_PROTO rip_prop_init interface_gateway_list prop_metric_option_inet
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, 0, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -9079,6 +9110,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9090,6 +9122,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9104,6 +9137,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9118,6 +9152,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    0,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9133,12 +9168,13 @@
 			    PARSE_METRIC_RESTRICT(&$$);
 			    $$.adv = (adv_entry *) 0;
 			}
-		| metric_option metric2_option '{' prop_source_list_inet6 '}'
+		| metric_option metric2_option ascount_option '{' prop_source_list_inet6 '}'
 			{
 			    $$.state = PARSE_METRICS_UNSET;
 			    $$.metric = $1;
 			    $$.metric2 = $2;
-			    $$.adv = $4;
+			    $$.ascount = $3;
+			    $$.adv = $5;
 			}
 		;
 
@@ -9164,13 +9200,13 @@
 	/* Interfaces */
 		: T_PROTO prop_direct interface_list_option prop_metric_option_inet6
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.ascount, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			}
 	/* Static routes */
 		| T_PROTO prop_static interface_list_option prop_metric_option_inet6
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.ascount, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -9182,6 +9218,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    $3.ascount,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9189,7 +9226,7 @@
 	/* Kernel static routes (routing socket) */
 		| T_PROTO prop_kernel interface_list_option prop_metric_option_inet6
 			{
-			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+			    $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.ascount, $4.state, $4.adv);
 			    parse_proto = (proto_t) 0;
 			    parse_gwlist = (gw_entry **) 0;
 			}
@@ -9201,6 +9238,7 @@
 							    $2,
 							    &$3.metric,
 							    &$3.metric2,
+							    $3.ascount,
 							    $3.state,
 							    $3.adv);
 			    parse_proto = (proto_t) 0;
@@ -9213,6 +9251,7 @@
 							    $2,
 							    &$5.metric,
 							    &$5.metric2,
+							    $5.ascount,
 							    $5.state,
 							    $5.adv);
 			    $$->adv_as = $4;
@@ -9228,6 +9267,7 @@
 							    $2,
 							    &$4.metric,
 							    &$4.metric2,
+							    $4.ascount,
 							    $4.state,
 							    $4.adv);
 			    $$->adv_as = $3;
@@ -9242,6 +9282,7 @@
 							    $2,
 							    &$5.metric,
 							    &$5.metric2,
+							    $5.ascount,
 							    $5.state,
 							    $5.adv);
 			    $$->adv_tag = $4.metric;
@@ -9253,7 +9294,7 @@
     /* RIPng Imports */
 		| T_PROTO ripng_prop_init interface_gateway_list prop_metric_option_inet6
 			{
-                            $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.state, $4.adv);
+                            $$ = parse_adv_propagate_metric($3, $2, &$4.metric, &$4.metric2, $4.ascount, $4.state, $4.adv);
                             parse_proto = (proto_t) 0;
                             parse_gwlist = (gw_entry **) 0;
                         }
@@ -9266,12 +9307,13 @@
 			    PARSE_METRIC_RESTRICT(&$$);
 			    $$.adv = (adv_entry *) 0;
 			}
-		| metric_option metric2_option prop_restrict_list_option_inet6
+		| metric_option metric2_option ascount_option prop_restrict_list_option_inet6
 			{
 			    $$.state = PARSE_METRICS_UNSET;
 			    $$.metric = $1;
 			    $$.metric2 = $2;
-			    $$.adv = $3;
+			    $$.ascount = $3;
+			    $$.adv = $4;
 			}
 		;
 
@@ -9332,6 +9374,10 @@
 				    $$->adv_result.res_metric2 = $4.metric2.metric;
 				    BIT_SET($$->adv_flag, ADVFOT_METRIC2);
 				}
+				if ($4.ascount) {
+				    $$->adv_result.res_ascount = $4.ascount;
+				    BIT_SET($$->adv_flag, ADVFOT_ASCOUNT);
+				}
 			    }
 			}
 		;
@@ -10574,13 +10620,25 @@
 			    $$ = $2;
 			}
 		;
+
+
+ascount_option  : /* Empty */
+			{
+			    $$ = 0;
+			}
+		| T_ASCOUNT as_count
+			{
+			    $$ = $2;
+			}
+		;
 		
 metric_restrict_option
-                : metric_option metric2_option
+                : metric_option metric2_option ascount_option
 			{
 			    $$.state = PARSE_METRICS_UNSET;
 			    $$.metric = $1;
 			    $$.metric2 = $2;
+			    $$.ascount = $3;
 			}
 		| T_RESTRICT
 			{
@@ -10837,6 +10895,18 @@
 			    $$ = $1;
 			}
 		;
+
+as_count	: L_NUMBER
+			{
+			    if (parse_limit_check("as_count",
+						  (u_int) $1,
+						  LIMIT_ASCOUNT)) {
+			      PARSE_ERROR;
+			    }
+			    $$ = $1;
+			}
+		;
+
 
 @BEGIN:	PARSE_ASLIST
 as_list		: as
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/policy.c gated-R3_5/src/policy.c
--- gated-pub-ipv6-snapshot-0399/src/policy.c	Sat Mar 27 10:03:10 1999
+++ gated-R3_5/src/policy.c	Mon Mar 29 23:05:13 1999
@@ -1368,6 +1368,15 @@
 		result->res_metric2 = list->adv_result.res_metric2;
 	    }
 
+	    /* Set AS count */
+	    if (adv && BIT_TEST(adv->adv_flag, ADVFOT_ASCOUNT)) {
+		result->res_ascount = adv->adv_result.res_ascount;
+	    } else if (BIT_TEST(sublist->adv_flag, ADVFOT_ASCOUNT)) {
+		result->res_ascount = sublist->adv_result.res_ascount;
+	    } else if (BIT_TEST(list->adv_flag, ADVFOT_ASCOUNT)) {
+		result->res_ascount = list->adv_result.res_ascount;
+	    }
+
 	    /* Set flag */
 	    if (adv && BIT_TEST(adv->adv_flag, ADVFOT_FLAG)) {
 		result->res_flag = adv->adv_result.res_flag;
@@ -1798,6 +1807,11 @@
 		(void) fprintf(fd, "  precedence %d\n",
 			       adv->adv_result.res_precedence);
 		break;
+
+	    case ADVFOT_ASCOUNT:
+		(void) fprintf(fd, "  ascount %d\n",
+			       adv->adv_result.res_ascount);
+		break;
 	    }
 	}
 
@@ -2027,6 +2041,10 @@
 				       list->adv_result.res_preference);
 		    }
 		}
+		if (list->adv_flag & ADVFOT_ASCOUNT) {
+		    (void) fprintf(fd, "  ascount %d\n",
+				   list->adv_result.res_ascount);
+		}
 	    }
 	}
     }
@@ -2051,6 +2069,18 @@
 			       list->adv_result.res_metric);
 		lower++;
 	    }
+	    if (BIT_TEST(list->adv_flag, ADVFOT_METRIC2)) {
+		(void) fprintf(fd, "%.*sMetric %d:\n",
+			       level, policy_tabs,
+			       list->adv_result.res_metric);
+		lower++;
+	    }
+	    if (BIT_TEST(list->adv_flag, ADVFOT_ASCOUNT)) {
+		(void) fprintf(fd, "%.*sASCount %d:\n",
+			       level, policy_tabs,
+			       list->adv_result.res_ascount);
+		lower++;
+	    }
 	    adv = list->adv_list;
 	    if (adv) {
 		do {
@@ -2099,11 +2129,23 @@
 	if (BIT_TEST(list->adv_flag, ADVF_NO)) {
 	    (void) fprintf(fd, "%.*sRestrict\n",
 			   level, policy_tabs);
-	} else if (BIT_TEST(list->adv_flag, ADVFOT_METRIC)) {
-	    (void) fprintf(fd, "%.*sMetric %d:\n",
-			   level, policy_tabs,
-			   list->adv_result.res_metric);
+	} else {
 	    level++;
+	    if (BIT_TEST(list->adv_flag, ADVFOT_METRIC)) {
+		(void) fprintf(fd, "%.*sMetric %d:\n",
+			       level, policy_tabs,
+			       list->adv_result.res_metric);
+	    }
+	    if (BIT_TEST(list->adv_flag, ADVFOT_METRIC2)) {
+		(void) fprintf(fd, "%.*sMetric2 %d:\n",
+			       level, policy_tabs,
+			       list->adv_result.res_metric2);
+	    }
+	    if (BIT_TEST(list->adv_flag, ADVFOT_ASCOUNT)) {
+		(void) fprintf(fd, "%.*sASCount %d:\n",
+			       level, policy_tabs,
+			       list->adv_result.res_ascount);
+	    }
 	}
 	control_export_list_dump(fd, level, list);
 	level--;
@@ -2363,6 +2405,11 @@
 				   " preference %d",
 				   list->adv_result.res_preference);
 		}
+	    }
+	    if (BIT_TEST(list->adv_flag, ADVFOT_ASCOUNT)) {
+		(void) fprintf(fd,
+			       " ascount %d",
+			       list->adv_result.res_ascount);
 	    }
 
 	    /* and end the line */
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/policy.h gated-R3_5/src/policy.h
--- gated-pub-ipv6-snapshot-0399/src/policy.h	Sat Mar 27 10:03:13 1999
+++ gated-R3_5/src/policy.h	Mon Mar 29 23:05:14 1999
@@ -272,6 +272,12 @@
     } res_u3;
 #define	res_precedence	res_u3.resu_precedence
 #define	res_void2	res_u3.resu_void
+    union {
+	u_int32		resu_ascount;
+	void_t		resu_void;
+    } res_u4;
+#define	res_ascount	res_u4.resu_ascount
+#define	res_void3	res_u4.resu_void
     flag_t	res_flag;
 } adv_results;
 
@@ -367,6 +373,7 @@
 #define	ADVFOT_FLAG		BIT(0x040)	/* Result Flag option */
 #define	ADVFOT_CONFIG		BIT(0x080)	/* Config structure */
 #define	ADVFOT_PRECEDENCE	BIT(0x100)	/* Result Precedence option */
+#define	ADVFOT_ASCOUNT		BIT(0x400)	/* Result Precedence option */
 
 #define	ADVF_NO			BIT(0x1000)	/* Negative (i.e. noannounce, nolisten, nopropogate) */
 #define	ADVF_FIRST		BIT(0x2000)	/* First entry in a sequence (of gateways or interfaces) */
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/rip.c gated-R3_5/src/rip.c
--- gated-pub-ipv6-snapshot-0399/src/rip.c	Sat Mar 27 10:03:38 1999
+++ gated-R3_5/src/rip.c	Mon Mar 29 23:05:14 1999
@@ -3582,9 +3582,6 @@
 	    rip_task = task_alloc("RIP",
 				  TASKPRI_PROTO,
 				  rip_trace_options);
-#ifdef PROTO_INET6		/* HITACHI_INET6 */
-	    rip_task->task_rtfamily = AF_INET;
-#endif
 	    if (!inet_udpcksum) {
 		trace_log_tp(rip_task,
 			     0,
@@ -3603,6 +3600,9 @@
 	    rip_task->task_addr = sockdup(inet_addr_any);
 	    sock2port(rip_task->task_addr) = rip_port;
 	    rip_task->task_rtproto = RTPROTO_RIP;
+#ifdef PROTO_INET6
+	    rip_task->task_rtfamily = AF_INET;
+#endif
 	    task_set_recv(rip_task, rip_recv);
 	    task_set_cleanup(rip_task, rip_cleanup);
 	    task_set_reinit(rip_task, rip_reinit);
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/ripng.h gated-R3_5/src/ripng.h
--- gated-pub-ipv6-snapshot-0399/src/ripng.h	Sat Mar 27 10:03:49 1999
+++ gated-R3_5/src/ripng.h	Mon Mar 29 23:05:15 1999
@@ -70,11 +70,11 @@
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-extern metric_t ripng_default_tag;
 extern flag_t ripng_flags;		/* Option flags */
 extern trace *ripng_trace_options;	/* RIPng tracing configuration */
 extern const bits ripng_trace_types[];	/* List of RIPng specific trace flags */
 extern metric_t ripng_default_metric;	/* Default metric to use when propogating */
+extern metric_t ripng_default_tag;	/* Default tag to use when propogating */
 extern int ripng_n_trusted;		/* Number of Trusted RIPng gateways */
 extern metric_t ripng_preference;	/* Preference for RIP routes */
 extern gw_entry *ripng_gw_list;		/* List of RIPng gateways */
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/ripng_recv.c gated-R3_5/src/ripng_recv.c
--- gated-pub-ipv6-snapshot-0399/src/ripng_recv.c	Sat Mar 27 10:03:57 1999
+++ gated-R3_5/src/ripng_recv.c	Mon Mar 29 23:05:15 1999
@@ -319,6 +319,7 @@
 
 		for(; (void_t)rte < limit; rte++) {
 		    rt_entry *rt;
+		    sockaddr_un *maskaddr;
 
 		    if (rte->ripng_metric == RIPNG_METRIC_NEXTHOP) {
 			sockaddr_un *nexthop;
@@ -328,10 +329,8 @@
 			nexthop = sockbuild_in6(0, (byte *)&nhe->ripng_nexthop);
 			if (IN6_IS_ADDR_UNSPECIFIED(&sock2in6(nexthop))
                             || (inet6_scope_of(nexthop) != INET6_SCOPE_LINKLOCAL)) {
- 			    sockfree(router);
 			    router = srcrouter;
                         } else {
-			    sockfree(router);
 			    router = nexthop;
                         }
 #undef nhe
@@ -362,13 +361,12 @@
 				      task_recv_srcaddr));
 			continue;
 		    }
-		    rtparms.rtp_metric = rte->ripng_metric;
 
 		    /*
 		     * Now add hop count to metric and use infinitu if
                      *  the result is greater than infinity
 		     */
-                    rtparms.rtp_metric = MIN(rtparms.rtp_metric + (ips ? ips->ips_metric_in : 1), RIPNG_METRIC_UNREACHABLE);
+                    rtparms.rtp_metric = MIN(rte->ripng_metric + (ips ? ips->ips_metric_in : 1), RIPNG_METRIC_UNREACHABLE);
 
 		    rtparms.rtp_state = RTS_INTERIOR;
 
@@ -384,6 +382,26 @@
 			continue;
 		    }
 		    rtparms.rtp_dest_mask = inet6_masks[rte->ripng_prefixlen];
+
+		    /* Should reject bad routes */
+		    maskaddr = sockdup(rtparms.rtp_dest);
+		    sockaddrmask_in6(maskaddr, rtparms.rtp_dest_mask);
+		    if (!sockaddrcmp_in6(rtparms.rtp_dest, maskaddr)) {
+#ifdef  NORMALLIZE_RIPNG_ROUTE
+			bcopy(maskaddr, rtparms.rtp_dest, socksize(maskaddr));
+#else
+			trace_log_tp(tp,
+				     0,
+				     LOG_WARNING,
+				     ("ripng_recv: invalid route %A/%d from %#A",
+				      rtparms.rtp_dest,
+				      rte->ripng_prefixlen,
+				      task_recv_srcaddr));
+			sockfree(maskaddr);
+			continue;
+#endif
+		    }
+		    sockfree(maskaddr);
 
 		    rtparms.rtp_router = router;
 		    rtparms.rtp_ifap = task_recv_interface;
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/ripng_send.c gated-R3_5/src/ripng_send.c
--- gated-pub-ipv6-snapshot-0399/src/ripng_send.c	Sat Mar 27 10:03:59 1999
+++ gated-R3_5/src/ripng_send.c	Mon Mar 29 23:05:15 1999
@@ -104,19 +104,20 @@
 	/* Multicast sends fail if MSG_DONTROUTE is set */
 	BIT_RESET(flags, MSG_DONTROUTE);
 
-#ifdef IPV6_MULTI_IF
+#if defined(IPV6_MULTICAST_IF)  && !defined(HITACHI_INET6)
 	(void) task_set_option(tp,
 			       TASKOPTION_MULTI_IF,
 			       ifap);
-#endif /* IPV6_MULTI_IF */
+#endif /* IPV6_MULTICAST_IF */
 
 	/* fall through */
       default:
-#ifdef IPV6_SEND_MESSAGE
+        /* HITACHI's multicast implementaion buggy. */
+#if defined(IPV6_MULTICAST_IF) && !defined(HITACHI_INET6)
+	  rc = task_send_packet(tp, (void_t) msg, size, flags, addr);
+#else  /* !IPV6_MULTICAST_IF */
         rc = task_send_message(tp, (void_t) msg, size, flags, addr, ifap);
-#else  /* !IPV6_SEND_MESSAGE */
-	rc = task_send_packet(tp, (void_t) msg, size, flags, addr);
-#endif /* IPV6_SEND_MESSAGE */
+#endif /* IPV6_MULTICAST_IF */
 	break;
 
 #ifdef IPV6_PKTINFO
@@ -206,7 +207,7 @@
 			next_hop = *tlp->target_src;
 		    }
 		    rte++;                 
-                }   
+                }
             }
 #endif
 
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/rt_static.c gated-R3_5/src/rt_static.c
--- gated-pub-ipv6-snapshot-0399/src/rt_static.c	Sat Mar 27 10:04:24 1999
+++ gated-R3_5/src/rt_static.c	Mon Mar 29 23:05:16 1999
@@ -77,6 +77,9 @@
 #ifdef	PROTO_INET
 #include "inet.h"
 #endif	/* PROTO_INET */
+#ifdef	PROTO_INET6
+#include "inet6.h"
+#endif	/* PROTO_INET6 */
 #ifdef	PROTO_ISO
 #include "iso.h"
 #endif	/* PROTO_ISO */
@@ -603,7 +606,7 @@
                      IF_ADDR(ifap) {
                          if (BIT_TEST(ifap->ifa_state, IFS_UP)
                              && if_policy_match(ifap, rtsp->rts_intfs)) {
-#ifdef        P2P_RT_REMOTE
+#ifdef  P2P_RT_REMOTE
                             if (BIT_TEST(ifap->ifa_state, IFS_POINTOPOINT)) {
                                 /* A network route to a P2P interface */
                                 /* may end up pointing at the wrong */
@@ -619,8 +622,13 @@
                             }
 #else /* P2P_RT_REMOTE */
                             rtp->rtp_router = ifap->ifa_addr_local;
-#endif        /* P2P_RT_REMOTE */
+#endif /* P2P_RT_REMOTE */
                             ifaps[0] = ifap;
+#ifdef  PROTO_INET6
+			    if (socktype(rtp->rtp_router) == AF_INET6
+				&& IN6_IS_ADDR_LINKLOCAL(&sock2in6(rtp->rtp_router)))
+				rtp->rtp_ifap = ifap;
+#endif
                             j++;
                             break;
                         }
@@ -661,9 +669,10 @@
                                                 rtp->rtp_tag,
                                                 rtp->rtp_preference,
                                                 (pref_t) 0,
-                                                rtp->rtp_n_gw, rtp->rtp_routers,
+                                                rtp->rtp_n_gw,
+						rtp->rtp_routers,
 #ifdef  PROTO_INET6
-						(if_addr **) 0,
+						rtp->rtp_ifaps,
 #endif
                                                 rtp->rtp_asp,
 						(metric_t) 0)) {
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/rt_table.c gated-R3_5/src/rt_table.c
--- gated-pub-ipv6-snapshot-0399/src/rt_table.c	Sat Mar 27 10:04:42 1999
+++ gated-R3_5/src/rt_table.c	Mon Mar 29 23:05:16 1999
@@ -148,7 +148,6 @@
     {RTPROTO_NDP,	"NDP"},
     {RTPROTO_RIPNG,	"RIPng"},
     {RTPROTO_OSPFV6,	"OSPFV6"},
-    {RTPROTO_ICMPV6,    "ICMPV6"},
     {RTPROTO_OSPFV6_ASE,"OSPFV6_ASE"},
     {RTPROTO_PIMV6,	"PIMV6"},
 #endif
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/sockaddr.h gated-R3_5/src/sockaddr.h
--- gated-pub-ipv6-snapshot-0399/src/sockaddr.h	Sat Mar 27 10:06:22 1999
+++ gated-R3_5/src/sockaddr.h	Mon Mar 29 23:05:16 1999
@@ -5,11 +5,6 @@
  */
 
 /*
- * BGP4+ alpha && IPv6 
- * TONEv1 - advapi02 
- */
-
-/*
  * ------------------------------------------------------------------------
  * 
  * Copyright (c) 1996, 1997, 1998 The Regents of the University of Michigan
@@ -98,7 +93,7 @@
 	struct in_addr gin_addr;
     } in;
 #endif	/* PROTO_INET */
-#ifdef  PROTO_INET6 
+#ifdef  PROTO_INET6
     /* IPv6 address. */
     struct {
         byte    gin6_len;
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/task.c gated-R3_5/src/task.c
--- gated-pub-ipv6-snapshot-0399/src/task.c	Sat Mar 27 10:06:48 1999
+++ gated-R3_5/src/task.c	Mon Mar 29 23:05:17 1999
@@ -2764,13 +2764,6 @@
 	goto Log;
     }
 
-    if (!ifap) {
-        log = TR_ALL;
-	errmsg = ": no specified if_addr";
-	rc = len;
-	goto Log;
-    }
-
     if (BIT_TEST(task_state, TASKS_NOSEND)) {
 	log = TR_ALL;
 	errmsg = ": packet transmission disabled";
@@ -2792,12 +2785,12 @@
     mh.msg_name = (caddr_t *) name;
     mh.msg_namelen = namelen;
     mh.msg_flags  = 0;
-    ifindex = ifap->ifa_link->ifl_index;
 
-    if (!ifindex) {
+    if (!ifap || !ifap->ifa_link->ifl_index) {
         mh.msg_control = NULL;
 	mh.msg_controllen = 0;
     } else {
+        ifindex = ifap->ifa_link->ifl_index;
         bzero((caddr_t *) cmsgbuf, sizeof (cmsgbuf));
 	cmh = (struct cmsghdr *) cmsgbuf;
 	mh.msg_control = (caddr_t) cmh;
@@ -2807,12 +2800,8 @@
 	cmh->cmsg_level = IPPROTO_IPV6;
 	cmh->cmsg_type = IPV6_PKTINFO;
 	pi = (struct in6_pktinfo *) CMSG_DATA(cmh);
-#ifdef HAVE_BCOPY
-	bcopy((caddr_t *)&ifap->ifa_addr->in6.gin6_addr, (caddr_t *)&pi->ipi6_addr, sizeof (pi->ipi6_addr));
-#else  /* HAVE_BCOPY */
 	bzero((caddr_t *)&pi->ipi6_addr, sizeof (pi->ipi6_addr));
-#endif
-	pi->ipi6_ifindex = htonl(ifindex);
+	pi->ipi6_ifindex = ifindex;
     }
 
     while ((rc = sendmsg(tp->task_socket,
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/unix.h gated-R3_5/src/unix.h
--- gated-pub-ipv6-snapshot-0399/src/unix.h	Sat Mar 27 10:07:02 1999
+++ gated-R3_5/src/unix.h	Mon Mar 29 23:05:17 1999
@@ -361,5 +361,3 @@
 PROTOTYPE(getenv,
 	  extern char *,
 	  (const char *));
-
-
diff -u -r -N -x hitachiv6 -x hitachi_ipv6 -x hitachi.bsdi.3.0 -x .cvsignore -x TODO -x CVS -x ChangeLog gated-pub-ipv6-snapshot-0399/src/util/Makefile.template gated-R3_5/src/util/Makefile.template
--- gated-pub-ipv6-snapshot-0399/src/util/Makefile.template	Sat Mar 27 10:09:12 1999
+++ gated-R3_5/src/util/Makefile.template	Mon Mar 29 23:05:21 1999
@@ -435,25 +435,11 @@
 #  Build the gdc program
 #
 #
-
-install:: ${DESTDIR}${BINDIR}/${GDC}
-
 ${GDC}:	${G_OBJS} ${LIBGATED}
 	@echo 'Linking:	${GDC}'
 	@${CC} ${CFLAGS} ${CWFLAGS} ${IFLAGS} ${G_OBJS} -o ${GDC} ${LDFLAGS} ${LIBGATED} ${LDOTHERS} \
 		&& ${SIZE} ${GDC}
 
-${DESTDIR}${BINDIR}/${GDC}:	${GDC}
-	-@${TOUCH} /tmp/$$ ; ${CHGRP} ${GDC_GROUP} /tmp/$$ \
-			     && ${CHOWN} ${GDC_USER} /tmp/$$ ; \
-		if [ $$? -eq 0 ]; then \
-	       	   MODES="-m ${GDC_MODE} -o ${GDC_USER} -g ${GDC_GROUP}" ; \
-		else \
-			MODES= ; \
-		fi ; \
-		( set -x ; ${INSTALL} ${INSTALLFLAGS} $${MODES} ${GDC} ${DESTDIR}${BINDIR}/${GDC} ) ; \
-		${RM} -f /tmp/$$
-
 all::	${GDC}
 
 lint::
@@ -462,17 +448,29 @@
 clean::
 	-${RM} -f core.${GDC} ${GDC} ${G_OBJS} linterrs.${GDC}
 
+install:: ${DESTDIR}${BINDIR}/${GDC}
+
 man::	${G_MANS}
 
 install-man::	inst-man ${G_MANS}
 	MANDIR=${MANDIR} ./inst-man -${MANTYPE} ${G_MANS}
 
+${DESTDIR}${BINDIR}/${GDC}:	${GDC}
+	-@${TOUCH} /tmp/$$ ; ${CHGRP} ${GDC_GROUP} /tmp/$$ \
+			     && ${CHOWN} ${GDC_USER} /tmp/$$ ; \
+		if [ $$? -eq 0 ]; then \
+	       	   MODES="-m ${GDC_MODE} -o ${GDC_USER} -g ${GDC_GROUP}" ; \
+		else \
+			MODES= ; \
+		fi ; \
+		( set -x ; ${INSTALL} ${INSTALLFLAGS} $${MODES} ${GDC} ${DESTDIR}${BINDIR}/${GDC} ) ; \
+		${RM} -f /tmp/$$
 
 
 #
 #	Build the emacs TAGS file
 #
-
+#
 tags:	TAGS
 
 TAGS:	${SRCS} ${HDRS}
