diff -Nur olsrd-0.5.0/lib/quagga/quagga-0.98.6-olsr.diff olsrd-0.5.0-patched/lib/quagga/quagga-0.98.6-olsr.diff
--- olsrd-0.5.0/lib/quagga/quagga-0.98.6-olsr.diff	2007-01-31 14:43:09.000000000 +0200
+++ olsrd-0.5.0-patched/lib/quagga/quagga-0.98.6-olsr.diff	2007-04-05 02:23:18.000000000 +0300
@@ -1,6 +1,6 @@
-diff -Nur quagga-0.98.6.orig/bgpd/bgp_vty.c quagga-0.98.6/bgpd/bgp_vty.c
---- quagga-0.98.6.orig/bgpd/bgp_vty.c	2006-03-30 18:12:25.000000000 +0200
-+++ quagga-0.98.6/bgpd/bgp_vty.c	2006-12-02 10:52:14.000000000 +0100
+diff -Nur quagga-0.98.6/bgpd/bgp_vty.c quagga-0.98.6-patched/bgpd/bgp_vty.c
+--- quagga-0.98.6/bgpd/bgp_vty.c	2006-03-30 19:12:25.000000000 +0300
++++ quagga-0.98.6-patched/bgpd/bgp_vty.c	2007-04-05 01:26:42.000000000 +0300
 @@ -7793,7 +7793,9 @@
  	return ZEBRA_ROUTE_STATIC;
        else if (strncmp (str, "r", 1) == 0)
@@ -12,7 +12,7 @@
  	return ZEBRA_ROUTE_OSPF;
      }
    if (afi == AFI_IP6)
-@@ -7806,20 +7808,23 @@
+@@ -7806,21 +7808,25 @@
  	return ZEBRA_ROUTE_STATIC;
        else if (strncmp (str, "r", 1) == 0)
  	return ZEBRA_ROUTE_RIPNG;
@@ -34,11 +34,14 @@
         "Kernel routes\n"
         "Open Shurtest Path First (OSPF)\n"
         "Routing Information Protocol (RIP)\n"
+-       "Static routes\n")
++       "Static routes\n"
 +       "Optimized Link State Routing (OLSR)\n"
-        "Static routes\n")
++       )
  {
    int type;
-@@ -7835,13 +7840,14 @@
+ 
+@@ -7835,13 +7841,14 @@
  
  DEFUN (bgp_redistribute_ipv4_rmap,
         bgp_redistribute_ipv4_rmap_cmd,
@@ -54,7 +57,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n")
  {
-@@ -7860,13 +7866,14 @@
+@@ -7860,13 +7867,14 @@
  
  DEFUN (bgp_redistribute_ipv4_metric,
         bgp_redistribute_ipv4_metric_cmd,
@@ -70,7 +73,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n")
  {
-@@ -7887,13 +7894,14 @@
+@@ -7887,13 +7895,14 @@
  
  DEFUN (bgp_redistribute_ipv4_rmap_metric,
         bgp_redistribute_ipv4_rmap_metric_cmd,
@@ -86,7 +89,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n"
         "Metric for redistributed routes\n"
-@@ -7917,13 +7925,14 @@
+@@ -7917,13 +7926,14 @@
  
  DEFUN (bgp_redistribute_ipv4_metric_rmap,
         bgp_redistribute_ipv4_metric_rmap_cmd,
@@ -102,7 +105,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n"
         "Route map reference\n"
-@@ -7947,14 +7956,16 @@
+@@ -7947,14 +7957,16 @@
  
  DEFUN (no_bgp_redistribute_ipv4,
         no_bgp_redistribute_ipv4_cmd,
@@ -121,7 +124,7 @@
  {
    int type;
  
-@@ -7970,7 +7981,7 @@
+@@ -7970,7 +7982,7 @@
  
  DEFUN (no_bgp_redistribute_ipv4_rmap,
         no_bgp_redistribute_ipv4_rmap_cmd,
@@ -130,7 +133,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -7978,6 +7989,7 @@
+@@ -7978,6 +7990,7 @@
         "Open Shurtest Path First (OSPF)\n"
         "Routing Information Protocol (RIP)\n"
         "Static routes\n"
@@ -138,7 +141,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n")
  {
-@@ -7996,7 +8008,7 @@
+@@ -7996,7 +8009,7 @@
  
  DEFUN (no_bgp_redistribute_ipv4_metric,
         no_bgp_redistribute_ipv4_metric_cmd,
@@ -147,7 +150,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8004,6 +8016,7 @@
+@@ -8004,6 +8017,7 @@
         "Open Shurtest Path First (OSPF)\n"
         "Routing Information Protocol (RIP)\n"
         "Static routes\n"
@@ -155,7 +158,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n")
  {
-@@ -8022,7 +8035,7 @@
+@@ -8022,7 +8036,7 @@
  
  DEFUN (no_bgp_redistribute_ipv4_rmap_metric,
         no_bgp_redistribute_ipv4_rmap_metric_cmd,
@@ -164,7 +167,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8030,6 +8043,7 @@
+@@ -8030,6 +8044,7 @@
         "Open Shurtest Path First (OSPF)\n"
         "Routing Information Protocol (RIP)\n"
         "Static routes\n"
@@ -172,7 +175,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n"
         "Metric for redistributed routes\n"
-@@ -8051,7 +8065,7 @@
+@@ -8051,7 +8066,7 @@
  
  ALIAS (no_bgp_redistribute_ipv4_rmap_metric,
         no_bgp_redistribute_ipv4_metric_rmap_cmd,
@@ -181,7 +184,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8059,6 +8073,7 @@
+@@ -8059,6 +8074,7 @@
         "Open Shurtest Path First (OSPF)\n"
         "Routing Information Protocol (RIP)\n"
         "Static routes\n"
@@ -189,7 +192,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n"
         "Route map reference\n"
-@@ -8067,13 +8082,15 @@
+@@ -8067,13 +8083,15 @@
  #ifdef HAVE_IPV6
  DEFUN (bgp_redistribute_ipv6,
         bgp_redistribute_ipv6_cmd,
@@ -207,7 +210,7 @@
  {
    int type;
  
-@@ -8089,13 +8106,14 @@
+@@ -8089,13 +8107,14 @@
  
  DEFUN (bgp_redistribute_ipv6_rmap,
         bgp_redistribute_ipv6_rmap_cmd,
@@ -223,7 +226,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n")
  {
-@@ -8114,13 +8132,14 @@
+@@ -8114,13 +8133,14 @@
  
  DEFUN (bgp_redistribute_ipv6_metric,
         bgp_redistribute_ipv6_metric_cmd,
@@ -239,12 +242,12 @@
         "Metric for redistributed routes\n"
         "Default metric\n")
  {
-@@ -8141,13 +8160,14 @@
+@@ -8141,13 +8161,14 @@
  
  DEFUN (bgp_redistribute_ipv6_rmap_metric,
         bgp_redistribute_ipv6_rmap_metric_cmd,
 -       "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>",
-+       "redistribute (connected|kernel|ospf6|ripng|static|ols) route-map WORD metric <0-4294967295>",
++       "redistribute (connected|kernel|ospf6|ripng|static|olsr) route-map WORD metric <0-4294967295>",
         "Redistribute information from another routing protocol\n"
         "Connected\n"
         "Kernel routes\n"
@@ -255,7 +258,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n"
         "Metric for redistributed routes\n"
-@@ -8171,13 +8191,14 @@
+@@ -8171,13 +8192,14 @@
  
  DEFUN (bgp_redistribute_ipv6_metric_rmap,
         bgp_redistribute_ipv6_metric_rmap_cmd,
@@ -271,7 +274,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n"
         "Route map reference\n"
-@@ -8201,14 +8222,16 @@
+@@ -8201,14 +8223,16 @@
  
  DEFUN (no_bgp_redistribute_ipv6,
         no_bgp_redistribute_ipv6_cmd,
@@ -290,7 +293,7 @@
  {
    int type;
  
-@@ -8224,7 +8247,7 @@
+@@ -8224,7 +8248,7 @@
  
  DEFUN (no_bgp_redistribute_ipv6_rmap,
         no_bgp_redistribute_ipv6_rmap_cmd,
@@ -299,7 +302,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8232,6 +8255,7 @@
+@@ -8232,6 +8256,7 @@
         "Open Shurtest Path First (OSPFv3)\n"
         "Routing Information Protocol (RIPng)\n"
         "Static routes\n"
@@ -307,7 +310,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n")
  {
-@@ -8250,7 +8274,7 @@
+@@ -8250,7 +8275,7 @@
  
  DEFUN (no_bgp_redistribute_ipv6_metric,
         no_bgp_redistribute_ipv6_metric_cmd,
@@ -316,7 +319,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8258,6 +8282,7 @@
+@@ -8258,6 +8283,7 @@
         "Open Shurtest Path First (OSPFv3)\n"
         "Routing Information Protocol (RIPng)\n"
         "Static routes\n"
@@ -324,7 +327,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n")
  {
-@@ -8276,7 +8301,7 @@
+@@ -8276,7 +8302,7 @@
  
  DEFUN (no_bgp_redistribute_ipv6_rmap_metric,
         no_bgp_redistribute_ipv6_rmap_metric_cmd,
@@ -333,7 +336,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8284,6 +8309,7 @@
+@@ -8284,6 +8310,7 @@
         "Open Shurtest Path First (OSPFv3)\n"
         "Routing Information Protocol (RIPng)\n"
         "Static routes\n"
@@ -341,7 +344,7 @@
         "Route map reference\n"
         "Pointer to route-map entries\n"
         "Metric for redistributed routes\n"
-@@ -8305,7 +8331,7 @@
+@@ -8305,7 +8332,7 @@
  
  ALIAS (no_bgp_redistribute_ipv6_rmap_metric,
         no_bgp_redistribute_ipv6_metric_rmap_cmd,
@@ -350,7 +353,7 @@
         NO_STR
         "Redistribute information from another routing protocol\n"
         "Connected\n"
-@@ -8313,6 +8339,7 @@
+@@ -8313,6 +8340,7 @@
         "Open Shurtest Path First (OSPFv3)\n"
         "Routing Information Protocol (RIPng)\n"
         "Static routes\n"
@@ -358,7 +361,7 @@
         "Metric for redistributed routes\n"
         "Default metric\n"
         "Route map reference\n"
-@@ -8325,7 +8352,7 @@
+@@ -8325,7 +8353,7 @@
  {
    int i;
    const char *str[] = { "system", "kernel", "connected", "static", "rip",
@@ -367,9 +370,9 @@
  
    /* Unicast redistribution only.  */
    if (safi != SAFI_UNICAST)
-diff -Nur quagga-0.98.6.orig/lib/zebra.h quagga-0.98.6/lib/zebra.h
---- quagga-0.98.6.orig/lib/zebra.h	2005-06-15 13:54:18.000000000 +0200
-+++ quagga-0.98.6/lib/zebra.h	2006-12-02 10:48:51.000000000 +0100
+diff -Nur quagga-0.98.6/lib/zebra.h quagga-0.98.6-patched/lib/zebra.h
+--- quagga-0.98.6/lib/zebra.h	2005-06-15 14:54:18.000000000 +0300
++++ quagga-0.98.6-patched/lib/zebra.h	2007-04-05 01:23:59.000000000 +0300
 @@ -378,7 +378,8 @@
  #define ZEBRA_ROUTE_ISIS                 8
  #define ZEBRA_ROUTE_BGP                  9
@@ -380,9 +383,9 @@
  
  /* Zebra's family types. */
  #define ZEBRA_FAMILY_IPV4                1
-diff -Nur quagga-0.98.6.orig/ospfd/ospf_vty.c quagga-0.98.6/ospfd/ospf_vty.c
---- quagga-0.98.6.orig/ospfd/ospf_vty.c	2006-03-30 17:41:20.000000000 +0200
-+++ quagga-0.98.6/ospfd/ospf_vty.c	2006-12-02 10:48:51.000000000 +0100
+diff -Nur quagga-0.98.6/ospfd/ospf_vty.c quagga-0.98.6-patched/ospfd/ospf_vty.c
+--- quagga-0.98.6/ospfd/ospf_vty.c	2006-03-30 18:41:20.000000000 +0300
++++ quagga-0.98.6-patched/ospfd/ospf_vty.c	2007-04-05 01:23:59.000000000 +0300
 @@ -108,9 +108,11 @@
      *source = ZEBRA_ROUTE_RIP;
    else if (strncmp (str, "b", 1) == 0)
@@ -609,9 +612,28 @@
  int
  config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
  {
-diff -Nur quagga-0.98.6.orig/zebra/zebra_vty.c quagga-0.98.6/zebra/zebra_vty.c
---- quagga-0.98.6.orig/zebra/zebra_vty.c	2004-12-18 17:03:29.000000000 +0100
-+++ quagga-0.98.6/zebra/zebra_vty.c	2006-12-02 10:49:45.000000000 +0100
+diff -Nur quagga-0.98.6/zebra/redistribute.c quagga-0.98.6-patched/zebra/redistribute.c
+--- quagga-0.98.6/zebra/redistribute.c	2005-06-15 14:54:51.000000000 +0300
++++ quagga-0.98.6-patched/zebra/redistribute.c	2007-04-05 01:27:23.000000000 +0300
+@@ -253,6 +253,7 @@
+     case ZEBRA_ROUTE_OSPF:
+     case ZEBRA_ROUTE_OSPF6:
+     case ZEBRA_ROUTE_BGP:
++    case ZEBRA_ROUTE_OLSR:
+       if (! client->redist[type])
+ 	{
+ 	  client->redist[type] = 1;
+@@ -281,6 +282,7 @@
+     case ZEBRA_ROUTE_OSPF:
+     case ZEBRA_ROUTE_OSPF6:
+     case ZEBRA_ROUTE_BGP:
++    case ZEBRA_ROUTE_OLSR:
+       client->redist[type] = 0;
+       break;
+     default:
+diff -Nur quagga-0.98.6/zebra/zebra_vty.c quagga-0.98.6-patched/zebra/zebra_vty.c
+--- quagga-0.98.6/zebra/zebra_vty.c	2004-12-18 18:03:29.000000000 +0200
++++ quagga-0.98.6-patched/zebra/zebra_vty.c	2007-04-05 01:23:59.000000000 +0300
 @@ -53,6 +53,8 @@
        return "isis";
      case ZEBRA_ROUTE_BGP:
diff -Nur olsrd-0.5.0/lib/quagga/src/olsrd_plugin.c olsrd-0.5.0-patched/lib/quagga/src/olsrd_plugin.c
--- olsrd-0.5.0/lib/quagga/src/olsrd_plugin.c	2007-03-12 01:26:06.000000000 +0200
+++ olsrd-0.5.0-patched/lib/quagga/src/olsrd_plugin.c	2007-04-05 02:25:07.000000000 +0300
@@ -3,6 +3,7 @@
  file                 : olsrd_plugin.c  
  usage                : olsrd-plugin-handler-stuff 
  copyright            : (C) 2006 by Immo 'FaUl' Wehrenberg
+ modified by          : Vassilis T. <acinonyxs@yahoo.gr>
  e-mail               : immo@chaostreff-dortmund.de
  ***************************************************************************/
 
@@ -61,13 +62,16 @@
 	puts ("AIII, could not remove the kernel route deleter");
       olsr_addroute_add_function(&zebra_add_olsr_v4_route, AF_INET);
       olsr_delroute_add_function(&zebra_del_olsr_v4_route, AF_INET);
+      zebra_export = 1;
       return 1;
     }
     else if (!strcmp(value, "additional")) {
       olsr_addroute_add_function(&zebra_add_olsr_v4_route, AF_INET);
       olsr_delroute_add_function(&zebra_del_olsr_v4_route, AF_INET);
+      zebra_export = 1;
       return 1;
     }
+    else zebra_export = 0;
   }
   else if (!strcmp(key, "Distance")) {
     unsigned int distance = atoi (value);
@@ -89,7 +93,7 @@
 
 int olsrd_plugin_init() {
   if(olsr_cnf->ip_version != AF_INET) {
-    fputs("see the source - ipv6 so far not supportet\n" ,stderr);
+    fputs("see the source - ipv6 so far not supported\n" ,stderr);
     return 1;
   }
 
diff -Nur olsrd-0.5.0/lib/quagga/src/quagga/zassert.h olsrd-0.5.0-patched/lib/quagga/src/quagga/zassert.h
--- olsrd-0.5.0/lib/quagga/src/quagga/zassert.h	2007-01-31 14:38:26.000000000 +0200
+++ olsrd-0.5.0-patched/lib/quagga/src/quagga/zassert.h	2007-04-05 02:23:18.000000000 +0300
@@ -1,5 +1,5 @@
 /*
- * $Id: zassert.h,v 1.1 2007/01/31 12:38:26 bernd67 Exp $
+ * $Id: zassert.h,v 1.2 2004/12/03 18:01:04 ajs Exp $
  */
 
 #ifndef _QUAGGA_ASSERT_H
diff -Nur olsrd-0.5.0/lib/quagga/src/quagga.c olsrd-0.5.0-patched/lib/quagga/src/quagga.c
--- olsrd-0.5.0/lib/quagga/src/quagga.c	2007-03-12 01:26:06.000000000 +0200
+++ olsrd-0.5.0-patched/lib/quagga/src/quagga.c	2007-04-05 02:28:57.000000000 +0300
@@ -3,6 +3,7 @@
  file                 : quagga.c  
  usage                : communication with the zebra-daemon 
  copyright            : (C) 2006 by Immo 'FaUl' Wehrenberg
+ modified by          : Vassilis T. <acinonyxs@yahoo.gr>
  e-mail               : immo@chaostreff-dortmund.de
  ***************************************************************************/
 
@@ -70,10 +71,8 @@
 static int ipv4_route_add (char *, size_t);
 static int ipv4_route_delete (char *, size_t);
 static int parse_ipv6_route_add (char*, size_t);
-static int zebra_reconnect (void);
-static int zebra_connect (void);
-static int add_v4_route_status (struct ipv4_route r);
-static int del_v4_route_status (struct ipv4_route r);
+static void zebra_reconnect (void);
+static void zebra_connect (void);
 static uint32_t prefixlentomask (uint8_t);
 static void free_ipv4_route (struct ipv4_route);
 static void update_olsr_zebra_routes (struct ipv4_route*, struct ipv4_route*);
@@ -147,114 +146,61 @@
 void *my_realloc (void *buf, size_t s, const char *c) {
   buf = realloc (buf, s);
   if (!buf) {
-    OLSR_PRINTF (1, "OUT OF MEMORY: %s\n", strerror(errno));
-    olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n");
+    OLSR_PRINTF (1, "(QUAGGA) Out of memory: %s\n", strerror(errno));
+    olsr_syslog(OLSR_LOG_ERR, "olsrd: Out of memory!: %m\n");
     olsr_exit(c, EXIT_FAILURE);
   }
   return buf;
 }
 
-int init_zebra () {
-  if (zebra_connect() < 0 || !(zebra.status&STATUS_CONNECTED)) {
-    olsr_exit ("AIIIII, could not connect to zebra! is zebra running?", 
+void init_zebra (void) {
+  zebra_connect ();
+  if (!(zebra.status & STATUS_CONNECTED))
+    olsr_exit ("(QUAGGA) AIIIII, could not connect to zebra! Is zebra running?", 
 	       EXIT_FAILURE);
-  }
-}
-
-
-static int zebra_reconnect (void) {
-  struct ipv4_route *tmp;
-  int i;
-
-  if (zebra_connect() < 0 || !(zebra.status&STATUS_CONNECTED)) 
-    // log: zebra-reconnect failed
-    ;
-  for (i = 0; ZEBRA_ROUTE_MAX - 1; i++)
-    if (zebra.redistribute[i]) zebra_redistribute(i + 1);
-
-  for (tmp = zebra.v4_rt; tmp; tmp = tmp->next)
-    zebra_add_v4_route(*tmp);
-}
-
-
-static int add_v4_route_status (struct ipv4_route r) {
-
-  struct ipv4_route *tmp = olsr_malloc (sizeof r, "quagga_v4_route_status");
-  memcpy (tmp, &r, sizeof r);
-
-  if (r.message & ZAPI_MESSAGE_NEXTHOP) {
-    tmp->nexthops = olsr_malloc (r.nh_count * sizeof tmp->nexthops, 
-				 "quagga_v4_route_status");
-    memcpy (tmp->nexthops, &r.nexthops, sizeof *r.nexthops);
-  }
-
-  if (r.message & ZAPI_MESSAGE_IFINDEX) {
-    tmp->index = olsr_malloc (r.ind_num * sizeof *tmp->index, 
-			      "quagga_v4_route_status");
-    memcpy (tmp->index, &r.index, r.ind_num * sizeof *tmp->index);
-  }
-
-  tmp->next = zebra.v4_rt;
-  zebra.v4_rt = tmp;
-
-  return 0;
-
 }
 
 
-static int cmp_v4_route (struct ipv4_route a, struct ipv4_route b) {
-  if (a.type != b.type) return 1;
-  if (a.flags != b.flags) return 1;
-  if (a.message != b.message) return 1;
-  if (a.prefixlen != b.prefixlen) return 1;
-  if (a.message & ZAPI_MESSAGE_NEXTHOP) {
-    if (a.nh_count != b.nh_count) return 1;
-    if (memcmp (a.nexthops, b.nexthops, a.nh_count * sizeof *b.nexthops)) 
-      return 1;
-  }
-  if (a.message & ZAPI_MESSAGE_IFINDEX) {
-    if (a.ind_num != b.ind_num) return 1;
-    if (memcpy (a.index, b.index, a.ind_num * sizeof *a.index)) return 1;
-  }
-  if (a.message & ZAPI_MESSAGE_DISTANCE) 
-    if (a.distance != b.distance) return 1;
-  if (a.message & ZAPI_MESSAGE_METRIC)
-    if (a.metric != b.metric) return 1;
-  return 0;
-}
+static void zebra_reconnect (void) {
 
-static int del_v4_route_status (struct ipv4_route r) {
+  int indx;
+  struct rt_entry *route;
 
-  struct ipv4_route *tmp, *prv = 0;
+  zebra_connect ();
+  if (zebra.status & STATUS_CONNECTED) {
+    if (zebra_export) {
 
-  for (tmp = zebra.v4_rt; tmp; tmp = tmp->next) {
-    if (!cmp_v4_route(*tmp, r)) {
-      if (prv) prv->next = tmp->next;
+      for(indx = 0;indx < HASHSIZE;indx++)
+        for(route = routingtable[indx].next;
+            route != &routingtable[indx];
+	    route = route->next)
+              zebra_add_olsr_v4_route (route);
 
-      free_ipv4_route(*tmp);
-      free (tmp);
+      for(indx = 0;indx < HASHSIZE;indx++)
+        for(route = hna_routes[indx].next;
+            route != &hna_routes[indx];
+	    route = route->next)
+              zebra_add_olsr_v4_route (route);
+    }
 
-      return 0;
+    /* TODO: Redistribute routes from zebra on reconnection */
 
-    }
-    prv = tmp;
   }
-
-  return 1;
 }
 
 
 /* Connect to the zebra-daemon, returns a socket */
-static int zebra_connect (void) {
+static void zebra_connect (void) {
+
+  if (close (zebra.sock) < 0) 
+    olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE);
 
 #ifndef USE_UNIX_DOMAIN_SOCKET
   struct sockaddr_in i;
-  close (zebra.sock);
 
   zebra.sock = socket (AF_INET,SOCK_STREAM, 0);
 #else
   struct sockaddr_un i;
-  close (zebra.sock);
 
   zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0);
 #endif
@@ -262,7 +208,7 @@
   int ret;
 
   if (zebra.sock <0 )
-    olsr_exit("could not create socket!", EXIT_FAILURE);
+    olsr_exit("(QUAGGA) Could not create socket!", EXIT_FAILURE);
   
   memset (&i, 0, sizeof i);
 #ifndef USE_UNIX_DOMAIN_SOCKET
@@ -276,10 +222,12 @@
 
   ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i);
   if  (ret < 0) {
-    close (zebra.sock);
+    zebra.status &= ~STATUS_CONNECTED;
   }
-  else zebra.status |= STATUS_CONNECTED;
-  return zebra.sock;
+  else {
+    zebra.status |= STATUS_CONNECTED;
+  }
+  return;
 }
 
     
@@ -288,17 +236,21 @@
    optlen the length, of the payload */
 char zebra_send_command (unsigned char command, char * options, int optlen) {
 
+  if (!(zebra.status & STATUS_CONNECTED)) {
+    return 0;
+  }
 #ifdef ZEBRA_HEADER_MARKER
-  char *p = olsr_malloc (optlen + 6, "zebra_send_command");
+  char *pnt = olsr_malloc (optlen + 6, "zebra_send_command");
   uint16_t length = optlen + 6; /* length of option + command + packet_length +
 				   marker + zserv-version */
   uint16_t cmd;
 #else
-  char *p = olsr_malloc (optlen + 3, "zebra_send_command");
+  char *pnt = olsr_malloc (optlen + 3, "zebra_send_command");
   uint16_t length = optlen + 3;  // length of option + command + packet_length
 #endif
   
   int ret;
+  char *p = pnt;
   
   uint16_t len = htons(length);
   memcpy (p, &len, 2);
@@ -320,16 +272,18 @@
     ret = write (zebra.sock, p, length);
     if (ret < 0) {
       if (errno == EINTR) {
-	errno = 0;
 	continue;
       }
       else {
+        olsr_printf (1, "(QUAGGA) Disconnected from zebra\n");
 	zebra.status &= ~STATUS_CONNECTED;
+        free (pnt);
 	return -1;
       }
     }
     p = p+ret;
   } while ((length -= ret));
+  free (pnt);
 
   return 0;
 }
@@ -440,16 +394,16 @@
   ssize_t len, ret;
 
   if (!(zebra.status & STATUS_CONNECTED)) {
-    if (!zebra_reconnect()) return;
+    zebra_reconnect ();
+    return;
   }
   data = try_read (&len);
   if (data) {
     f = data;
     do {
       ret = zebra_parse_packet (f, len);
-      if (!ret) {//something wired happened
-	puts ("DEBUG: IIIIIIIIIIRGS");
-	exit (EXIT_FAILURE);
+      if (!ret) {
+	olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE);
       }
       f += ret;
     } while ((f - data) < len);
@@ -478,15 +432,9 @@
     }
     ret = read (zebra.sock, buf + l, bsize - l);
     if (ret <= 0) {
-      if (errno == EAGAIN) {
-	errno = 0;
-      }
-      else {
-	olsr_printf(1, "OOPS, something realy wired happened:"
-		    "read returned %s\n", strerror(errno));
-	errno = 0;
-	zebra.status &= ~STATUS_CONNECTED;
-	return 0;
+      if (!((ret < 0) && (errno == EAGAIN))) {
+        olsr_printf (1, "(QUAGGA) Disconnected from zebra\n");
+        zebra.status &= ~STATUS_CONNECTED;
       }
       free (buf);
       return NULL;
@@ -536,20 +484,19 @@
   length = ntohs (length);
   
   if (maxlen < length) {
-    puts("Error: programmer is an idiot");
-    printf ("DEBUG: maxlen = %d, packet_length = %d\n", maxlen, length);
-    return maxlen;
+    olsr_printf (1, "(QUAGGA) maxlen = %d, packet_length = %d\n", maxlen, length);
+    olsr_exit ("(QUAGGA) Programmer is an idiot", EXIT_FAILURE);
   }
 
   if (packet[2] - 1 < ZEBRA_MESSAGE_MAX && foo[packet[2] - 1]) { 
     if (!(ret = foo[packet[2] - 1] (packet + 3, length - 3))) 
       return length;
-    else printf ("DEBUG: Parse error: %d\n", ret);
+    else olsr_printf (1, "(QUAGGA) Parse error: %d\n", ret);
   }
   else
-    printf ("Unknown packet type: %d\n", packet[2]);
+    olsr_printf (1, "(QUAGGA) Unknown packet type: %d\n", packet[2]);
 
-  puts ("Quagga: RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE");
+  olsr_printf (1, "(QUAGGA) Received packet could not be parsed");
 
   return length;
 }
@@ -659,13 +606,9 @@
   int f;
     
   f = parse_ipv4_route (opt, len, &r);
-  if (f < 0) {
-    printf ("parse-error: %d\n",f);
-    return f;
-  }
+  if (f < 0) return f;
   
-  add_hna4_route (r);
-  return 0;
+  return add_hna4_route (r);
 }
 
 static int ipv4_route_delete (char *opt, size_t len) {
@@ -810,7 +753,6 @@
     route.distance = zebra.distance;
   }
 
-  add_v4_route_status (route);
   retval = zebra_add_v4_route(route);
   free_ipv4_route (route);
   return retval;
@@ -856,7 +798,6 @@
   }
 
   retval = zebra_delete_v4_route(route);
-  del_v4_route_status(route);
   free_ipv4_route (route);
   return retval;
 }
diff -Nur olsrd-0.5.0/lib/quagga/src/quagga.h olsrd-0.5.0-patched/lib/quagga/src/quagga.h
--- olsrd-0.5.0/lib/quagga/src/quagga.h	2007-03-12 01:26:06.000000000 +0200
+++ olsrd-0.5.0-patched/lib/quagga/src/quagga.h	2007-04-05 02:25:33.000000000 +0300
@@ -3,6 +3,7 @@
  file                 : quagga.h  
  usage                : header for quagga.c
  copyright            : (C) 2006 by Immo 'FaUl' Wehrenberg
+ modified by          : Vassilis T. <acinonyxs@yahoo.gr>
  e-mail               : immo@chaostreff-dortmund.de
  ***************************************************************************/
 
@@ -51,7 +52,9 @@
   struct ipv4_route *next;
 };
 
-int init_zebra (void);
+int zebra_export;
+
+void init_zebra (void);
 char zebra_send_command (unsigned char, char *, int );
 int zebra_add_v4_route (struct ipv4_route r);
 int zebra_delete_v4_route (struct ipv4_route r);
