* isis_tlv.[ch]: Two new functions - tlv_add_te_is_neighs() and
	  tlv_add_te_ipv4_reachs() to handle TLV's with new metric. None of
	  them handle sub TLVs though for now.
diff --git a/isisd/ChangeLog b/isisd/ChangeLog
index 04f048a..9942150 100644
--- a/isisd/ChangeLog
+++ b/isisd/ChangeLog
@@ -1,5 +1,11 @@
 2005-09-26 Hasso Tepper <hasso at quagga.net>
 
+	* isis_tlv.[ch]: Two new functions - tlv_add_te_is_neighs() and
+	  tlv_add_te_ipv4_reachs() to handle TLV's with new metric. None of
+	  them handle sub TLVs though for now.
+
+2005-09-26 Hasso Tepper <hasso at quagga.net>
+
 	* isis_circuit.[ch]: Some preliminary support for specifying wide
 	  circuit metrics. Needs more thinking though, but should do for now.
 
diff --git a/isisd/isis_tlv.c b/isisd/isis_tlv.c
index 1850e15..f430724 100644
--- a/isisd/isis_tlv.c
+++ b/isisd/isis_tlv.c
@@ -805,6 +805,38 @@
 }
 
 int
+tlv_add_te_is_neighs (struct list *te_is_neighs, struct stream *stream)
+{
+  struct listnode *node, *nnode;
+  struct te_is_neigh *te_is_neigh;
+  u_char value[255];
+  u_char *pos = value;
+  int retval;
+
+  for (ALL_LIST_ELEMENTS (te_is_neighs, node, nnode, te_is_neigh))
+    {
+      /* FIXME: This will be wrong if we are going to add TE sub TLVs. */
+      if (pos - value + IS_NEIGHBOURS_LEN > 255)
+        {
+          retval = add_tlv (TE_IS_NEIGHBOURS, pos - value, value, stream);
+          if (retval != ISIS_OK)
+            return retval;
+          pos = value;
+        }
+      
+      memcpy (pos, te_is_neigh->neigh_id, ISIS_SYS_ID_LEN + 1);
+      pos += ISIS_SYS_ID_LEN + 1;
+      memcpy (pos, te_is_neigh->te_metric, 3);
+      pos += 3;
+      /* Sub TLVs length. */
+      *pos = 0;
+      pos++;
+    }
+
+  return add_tlv (TE_IS_NEIGHBOURS, pos - value, value, stream);
+}
+
+int
 tlv_add_lan_neighs (struct list *lan_neighs, struct stream *stream)
 {
   struct listnode *node, *nnode;
@@ -970,6 +1002,39 @@
   return add_tlv (IPV4_INT_REACHABILITY, pos - value, value, stream);
 }
 
+int
+tlv_add_te_ipv4_reachs (struct list *te_ipv4_reachs, struct stream *stream)
+{
+  struct listnode *node, *nnode;
+  struct te_ipv4_reachability *te_reach;
+  u_char value[255];
+  u_char *pos = value;
+  u_char prefix_size;
+  int retval;
+
+  for (ALL_LIST_ELEMENTS (te_ipv4_reachs, node, nnode, te_reach))
+    {
+      prefix_size = ((((te_reach->control & 0x3F) - 1) >> 3) + 1);
+
+      if (pos - value + (5 + prefix_size) > 255)
+	{
+	  retval =
+	    add_tlv (IPV4_INT_REACHABILITY, pos - value, value, stream);
+	  if (retval != ISIS_OK)
+	    return retval;
+	  pos = value;
+	}
+      *(u_int32_t *) pos = te_reach->te_metric;
+      pos += 4;
+      *pos = te_reach->control;
+      pos++;
+      memcpy (pos, &te_reach->prefix_start, prefix_size);
+      pos += prefix_size;
+    }
+
+  return add_tlv (TE_IPV4_REACHABILITY, pos - value, value, stream);
+}
+
 #ifdef HAVE_IPV6
 int
 tlv_add_ipv6_addrs (struct list *ipv6_addrs, struct stream *stream)
diff --git a/isisd/isis_tlv.h b/isisd/isis_tlv.h
index 035bb63..1dc030e 100644
--- a/isisd/isis_tlv.h
+++ b/isisd/isis_tlv.h
@@ -279,6 +279,7 @@
 int add_tlv (u_char, u_char, u_char *, struct stream *);
 int tlv_add_area_addrs (struct list *area_addrs, struct stream *stream);
 int tlv_add_is_neighs (struct list *is_neighs, struct stream *stream);
+int tlv_add_te_is_neighs (struct list *te_is_neighs, struct stream *stream);
 int tlv_add_lan_neighs (struct list *lan_neighs, struct stream *stream);
 int tlv_add_nlpid (struct nlpids *nlpids, struct stream *stream);
 int tlv_add_checksum (struct checksum *checksum, struct stream *stream);
@@ -289,6 +290,7 @@
 			      struct stream *stream);
 int tlv_add_lsp_entries (struct list *lsps, struct stream *stream);
 int tlv_add_ipv4_reachs (struct list *ipv4_reachs, struct stream *stream);
+int tlv_add_te_ipv4_reachs (struct list *te_ipv4_reachs, struct stream *stream);
 #ifdef HAVE_IPV6
 int tlv_add_ipv6_addrs (struct list *ipv6_addrs, struct stream *stream);
 int tlv_add_ipv6_reachs (struct list *ipv6_reachs, struct stream *stream);