source: packages/net/olsrd/patches/150-olsrd_quagga_backport.patch @ 19192

Last change on this file since 19192 was 19192, checked in by jow, 6 years ago

[packages] olsrd: update to v0.5.6-r8

File size: 118.6 KB
  • lib/quagga/Makefile

    a b  
    4040PLUGIN_NAME =   olsrd_quagga 
    4141PLUGIN_VER =    0.2.2 
    4242 
    43 TOPDIR= ../.. 
     43TOPDIR = ../.. 
    4444include $(TOPDIR)/Makefile.inc 
    4545 
    46 #CPPFLAGS +=-DMY_DEBUG  
    4746CFLAGS += -g 
    4847CPPFLAGS +=-DUSE_UNIX_DOMAIN_SOCKET 
    4948 
    50 #uncomment the following line only if you are sure what you're doing, it will  
    51 #probably break things!  
    52 # CPPFLAGS +=-DZEBRA_HEADER_MARKER=255  
    53  
    5449ifeq ($(OS),win32) 
     50 
    5551default_target install clean: 
    56         @echo "**** Quagga not supportet on Windows (so it would be pointless to build the Quagga Plugin)" 
     52        @echo "*** Quagga not supported on Windows (so it would be pointless to build the Quagga plugin)" 
     53 
    5754else 
     55 
    5856default_target: $(PLUGIN_FULLNAME) 
    5957 
    6058$(PLUGIN_FULLNAME): $(OBJS) version-script.txt 
     
    6664 
    6765clean: 
    6866                rm -f $(OBJS) $(SRCS:%.c=%.d) $(PLUGIN_FULLNAME) 
     67 
    6968endif 
  • new file lib/quagga/patches/quagga-0.98.6.diff

    - +  
     1diff -Nur quagga-0.98.6/bgpd/bgp_vty.c quagga-0.98.6.patched/bgpd/bgp_vty.c 
     2--- quagga-0.98.6/bgpd/bgp_vty.c        2006-03-30 18:12:25.000000000 +0200 
     3+++ quagga-0.98.6.patched/bgpd/bgp_vty.c        2007-12-30 14:18:22.000000000 +0200 
     4@@ -3,6 +3,9 @@ 
     5  
     6 This file is part of GNU Zebra. 
     7  
     8+This file was modified from the original on 30/12/2007 
     9+by Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     10+ 
     11 GNU Zebra is free software; you can redistribute it and/or modify it 
     12 under the terms of the GNU General Public License as published by the 
     13 Free Software Foundation; either version 2, or (at your option) any 
     14@@ -7793,8 +7796,12 @@ 
     15        return ZEBRA_ROUTE_STATIC; 
     16       else if (strncmp (str, "r", 1) == 0) 
     17        return ZEBRA_ROUTE_RIP; 
     18-      else if (strncmp (str, "o", 1) == 0) 
     19+      else if (strncmp (str, "ol", 2) == 0) 
     20+       return ZEBRA_ROUTE_OLSR; 
     21+      else if (strncmp (str, "os", 2) == 0) 
     22        return ZEBRA_ROUTE_OSPF; 
     23+      else if (strncmp (str, "ba", 2) == 0) 
     24+       return ZEBRA_ROUTE_BATMAN; 
     25     } 
     26   if (afi == AFI_IP6) 
     27     { 
     28@@ -7806,21 +7813,28 @@ 
     29        return ZEBRA_ROUTE_STATIC; 
     30       else if (strncmp (str, "r", 1) == 0) 
     31        return ZEBRA_ROUTE_RIPNG; 
     32-      else if (strncmp (str, "o", 1) == 0) 
     33+      else if (strncmp (str, "os", 2) == 0) 
     34        return ZEBRA_ROUTE_OSPF6; 
     35+      else if (strncmp (str, "ol", 2) == 0) 
     36+       return ZEBRA_ROUTE_OLSR; 
     37+      else if (strncmp (str, "ba", 2) == 0) 
     38+       return ZEBRA_ROUTE_BATMAN; 
     39     } 
     40   return 0; 
     41 } 
     42  
     43 DEFUN (bgp_redistribute_ipv4, 
     44        bgp_redistribute_ipv4_cmd, 
     45-       "redistribute (connected|kernel|ospf|rip|static)", 
     46+       "redistribute (connected|kernel|ospf|rip|static|olsr|batman)", 
     47        "Redistribute information from another routing protocol\n" 
     48        "Connected\n" 
     49        "Kernel routes\n" 
     50        "Open Shurtest Path First (OSPF)\n" 
     51        "Routing Information Protocol (RIP)\n" 
     52-       "Static routes\n") 
     53+       "Static routes\n" 
     54+       "Optimized Link State Routing (OLSR)\n" 
     55+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     56+       ) 
     57 { 
     58   int type; 
     59  
     60@@ -7835,13 +7849,15 @@ 
     61  
     62 DEFUN (bgp_redistribute_ipv4_rmap, 
     63        bgp_redistribute_ipv4_rmap_cmd, 
     64-       "redistribute (connected|kernel|ospf|rip|static) route-map WORD", 
     65+       "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD", 
     66        "Redistribute information from another routing protocol\n" 
     67        "Connected\n" 
     68        "Kernel routes\n" 
     69        "Open Shurtest Path First (OSPF)\n" 
     70        "Routing Information Protocol (RIP)\n" 
     71        "Static routes\n" 
     72+       "Optimized Link State Routing (OLSR)\n" 
     73+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     74        "Route map reference\n" 
     75        "Pointer to route-map entries\n") 
     76 { 
     77@@ -7860,13 +7876,15 @@ 
     78  
     79 DEFUN (bgp_redistribute_ipv4_metric, 
     80        bgp_redistribute_ipv4_metric_cmd, 
     81-       "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>", 
     82+       "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>", 
     83        "Redistribute information from another routing protocol\n" 
     84        "Connected\n" 
     85        "Kernel routes\n" 
     86        "Open Shurtest Path First (OSPF)\n" 
     87        "Routing Information Protocol (RIP)\n" 
     88        "Static routes\n" 
     89+       "Optimized Link State Routing (OLSR)\n" 
     90+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     91        "Metric for redistributed routes\n" 
     92        "Default metric\n") 
     93 { 
     94@@ -7887,13 +7905,15 @@ 
     95  
     96 DEFUN (bgp_redistribute_ipv4_rmap_metric, 
     97        bgp_redistribute_ipv4_rmap_metric_cmd, 
     98-       "redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>", 
     99+       "redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>", 
     100        "Redistribute information from another routing protocol\n" 
     101        "Connected\n" 
     102        "Kernel routes\n" 
     103        "Open Shurtest Path First (OSPF)\n" 
     104        "Routing Information Protocol (RIP)\n" 
     105        "Static routes\n" 
     106+       "Optimized Link State Routing (OLSR)\n" 
     107+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     108        "Route map reference\n" 
     109        "Pointer to route-map entries\n" 
     110        "Metric for redistributed routes\n" 
     111@@ -7917,13 +7937,15 @@ 
     112  
     113 DEFUN (bgp_redistribute_ipv4_metric_rmap, 
     114        bgp_redistribute_ipv4_metric_rmap_cmd, 
     115-       "redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD", 
     116+       "redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD", 
     117        "Redistribute information from another routing protocol\n" 
     118        "Connected\n" 
     119        "Kernel routes\n" 
     120        "Open Shurtest Path First (OSPF)\n" 
     121        "Routing Information Protocol (RIP)\n" 
     122        "Static routes\n" 
     123+       "Optimized Link State Routing (OLSR)\n" 
     124+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     125        "Metric for redistributed routes\n" 
     126        "Default metric\n" 
     127        "Route map reference\n" 
     128@@ -7947,14 +7969,17 @@ 
     129  
     130 DEFUN (no_bgp_redistribute_ipv4, 
     131        no_bgp_redistribute_ipv4_cmd, 
     132-       "no redistribute (connected|kernel|ospf|rip|static)", 
     133+       "no redistribute (connected|kernel|ospf|rip|static|olsr|batman)", 
     134        NO_STR 
     135        "Redistribute information from another routing protocol\n" 
     136        "Connected\n" 
     137        "Kernel routes\n" 
     138        "Open Shurtest Path First (OSPF)\n" 
     139        "Routing Information Protocol (RIP)\n" 
     140-       "Static routes\n") 
     141+       "Static routes\n" 
     142+       "Optimized Link State Routing (OLSR)\n" 
     143+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     144+       ) 
     145 { 
     146   int type; 
     147  
     148@@ -7970,7 +7995,7 @@ 
     149  
     150 DEFUN (no_bgp_redistribute_ipv4_rmap, 
     151        no_bgp_redistribute_ipv4_rmap_cmd, 
     152-       "no redistribute (connected|kernel|ospf|rip|static) route-map WORD", 
     153+       "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD", 
     154        NO_STR 
     155        "Redistribute information from another routing protocol\n" 
     156        "Connected\n" 
     157@@ -7978,6 +8003,8 @@ 
     158        "Open Shurtest Path First (OSPF)\n" 
     159        "Routing Information Protocol (RIP)\n" 
     160        "Static routes\n" 
     161+       "Optimized Link State Routing (OLSR)\n" 
     162+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     163        "Route map reference\n" 
     164        "Pointer to route-map entries\n") 
     165 { 
     166@@ -7996,7 +8023,7 @@ 
     167  
     168 DEFUN (no_bgp_redistribute_ipv4_metric, 
     169        no_bgp_redistribute_ipv4_metric_cmd, 
     170-       "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295>", 
     171+       "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295>", 
     172        NO_STR 
     173        "Redistribute information from another routing protocol\n" 
     174        "Connected\n" 
     175@@ -8004,6 +8031,8 @@ 
     176        "Open Shurtest Path First (OSPF)\n" 
     177        "Routing Information Protocol (RIP)\n" 
     178        "Static routes\n" 
     179+       "Optimized Link State Routing (OLSR)\n" 
     180+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     181        "Metric for redistributed routes\n" 
     182        "Default metric\n") 
     183 { 
     184@@ -8022,7 +8051,7 @@ 
     185  
     186 DEFUN (no_bgp_redistribute_ipv4_rmap_metric, 
     187        no_bgp_redistribute_ipv4_rmap_metric_cmd, 
     188-       "no redistribute (connected|kernel|ospf|rip|static) route-map WORD metric <0-4294967295>", 
     189+       "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) route-map WORD metric <0-4294967295>", 
     190        NO_STR 
     191        "Redistribute information from another routing protocol\n" 
     192        "Connected\n" 
     193@@ -8030,6 +8059,8 @@ 
     194        "Open Shurtest Path First (OSPF)\n" 
     195        "Routing Information Protocol (RIP)\n" 
     196        "Static routes\n" 
     197+       "Optimized Link State Routing (OLSR)\n" 
     198+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     199        "Route map reference\n" 
     200        "Pointer to route-map entries\n" 
     201        "Metric for redistributed routes\n" 
     202@@ -8051,7 +8082,7 @@ 
     203  
     204 ALIAS (no_bgp_redistribute_ipv4_rmap_metric, 
     205        no_bgp_redistribute_ipv4_metric_rmap_cmd, 
     206-       "no redistribute (connected|kernel|ospf|rip|static) metric <0-4294967295> route-map WORD", 
     207+       "no redistribute (connected|kernel|ospf|rip|static|olsr|batman) metric <0-4294967295> route-map WORD", 
     208        NO_STR 
     209        "Redistribute information from another routing protocol\n" 
     210        "Connected\n" 
     211@@ -8059,6 +8090,8 @@ 
     212        "Open Shurtest Path First (OSPF)\n" 
     213        "Routing Information Protocol (RIP)\n" 
     214        "Static routes\n" 
     215+       "Optimized Link State Routing (OLSR)\n" 
     216+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     217        "Metric for redistributed routes\n" 
     218        "Default metric\n" 
     219        "Route map reference\n" 
     220@@ -8067,13 +8100,16 @@ 
     221 #ifdef HAVE_IPV6 
     222 DEFUN (bgp_redistribute_ipv6, 
     223        bgp_redistribute_ipv6_cmd, 
     224-       "redistribute (connected|kernel|ospf6|ripng|static)", 
     225+       "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)", 
     226        "Redistribute information from another routing protocol\n" 
     227        "Connected\n" 
     228        "Kernel routes\n" 
     229        "Open Shurtest Path First (OSPFv3)\n" 
     230        "Routing Information Protocol (RIPng)\n" 
     231-       "Static routes\n") 
     232+       "Static routes\n" 
     233+       "Optimized Link State Routing (OLSR)\n" 
     234+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     235+       ) 
     236 { 
     237   int type; 
     238  
     239@@ -8089,13 +8125,15 @@ 
     240  
     241 DEFUN (bgp_redistribute_ipv6_rmap, 
     242        bgp_redistribute_ipv6_rmap_cmd, 
     243-       "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD", 
     244+       "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD", 
     245        "Redistribute information from another routing protocol\n" 
     246        "Connected\n" 
     247        "Kernel routes\n" 
     248        "Open Shurtest Path First (OSPFv3)\n" 
     249        "Routing Information Protocol (RIPng)\n" 
     250        "Static routes\n" 
     251+       "Optimized Link State Routing (OLSR)\n" 
     252+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     253        "Route map reference\n" 
     254        "Pointer to route-map entries\n") 
     255 { 
     256@@ -8114,13 +8152,15 @@ 
     257  
     258 DEFUN (bgp_redistribute_ipv6_metric, 
     259        bgp_redistribute_ipv6_metric_cmd, 
     260-       "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>", 
     261+       "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>", 
     262        "Redistribute information from another routing protocol\n" 
     263        "Connected\n" 
     264        "Kernel routes\n" 
     265        "Open Shurtest Path First (OSPFv3)\n" 
     266        "Routing Information Protocol (RIPng)\n" 
     267        "Static routes\n" 
     268+       "Optimized Link State Routing (OLSR)\n" 
     269+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     270        "Metric for redistributed routes\n" 
     271        "Default metric\n") 
     272 { 
     273@@ -8141,13 +8181,15 @@ 
     274  
     275 DEFUN (bgp_redistribute_ipv6_rmap_metric, 
     276        bgp_redistribute_ipv6_rmap_metric_cmd, 
     277-       "redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>", 
     278+       "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>", 
     279        "Redistribute information from another routing protocol\n" 
     280        "Connected\n" 
     281        "Kernel routes\n" 
     282        "Open Shurtest Path First (OSPFv3)\n" 
     283        "Routing Information Protocol (RIPng)\n" 
     284        "Static routes\n" 
     285+       "Optimized Link State Routing (OLSR)\n" 
     286+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     287        "Route map reference\n" 
     288        "Pointer to route-map entries\n" 
     289        "Metric for redistributed routes\n" 
     290@@ -8171,13 +8213,15 @@ 
     291  
     292 DEFUN (bgp_redistribute_ipv6_metric_rmap, 
     293        bgp_redistribute_ipv6_metric_rmap_cmd, 
     294-       "redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD", 
     295+       "redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD", 
     296        "Redistribute information from another routing protocol\n" 
     297        "Connected\n" 
     298        "Kernel routes\n" 
     299        "Open Shurtest Path First (OSPFv3)\n" 
     300        "Routing Information Protocol (RIPng)\n" 
     301        "Static routes\n" 
     302+       "Optimized Link State Routing (OLSR)\n" 
     303+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     304        "Metric for redistributed routes\n" 
     305        "Default metric\n" 
     306        "Route map reference\n" 
     307@@ -8201,14 +8245,17 @@ 
     308  
     309 DEFUN (no_bgp_redistribute_ipv6, 
     310        no_bgp_redistribute_ipv6_cmd, 
     311-       "no redistribute (connected|kernel|ospf6|ripng|static)", 
     312+       "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman)", 
     313        NO_STR 
     314        "Redistribute information from another routing protocol\n" 
     315        "Connected\n" 
     316        "Kernel routes\n" 
     317        "Open Shurtest Path First (OSPFv3)\n" 
     318        "Routing Information Protocol (RIPng)\n" 
     319-       "Static routes\n") 
     320+       "Static routes\n" 
     321+       "Optimized Link State Routing (OLSR)\n" 
     322+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     323+      ) 
     324 { 
     325   int type; 
     326  
     327@@ -8224,7 +8271,7 @@ 
     328  
     329 DEFUN (no_bgp_redistribute_ipv6_rmap, 
     330        no_bgp_redistribute_ipv6_rmap_cmd, 
     331-       "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD", 
     332+       "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD", 
     333        NO_STR 
     334        "Redistribute information from another routing protocol\n" 
     335        "Connected\n" 
     336@@ -8232,6 +8279,8 @@ 
     337        "Open Shurtest Path First (OSPFv3)\n" 
     338        "Routing Information Protocol (RIPng)\n" 
     339        "Static routes\n" 
     340+       "Optimized Link State Routing (OLSR)\n" 
     341+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     342        "Route map reference\n" 
     343        "Pointer to route-map entries\n") 
     344 { 
     345@@ -8250,7 +8299,7 @@ 
     346  
     347 DEFUN (no_bgp_redistribute_ipv6_metric, 
     348        no_bgp_redistribute_ipv6_metric_cmd, 
     349-       "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295>", 
     350+       "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295>", 
     351        NO_STR 
     352        "Redistribute information from another routing protocol\n" 
     353        "Connected\n" 
     354@@ -8258,6 +8307,8 @@ 
     355        "Open Shurtest Path First (OSPFv3)\n" 
     356        "Routing Information Protocol (RIPng)\n" 
     357        "Static routes\n" 
     358+       "Optimized Link State Routing (OLSR)\n" 
     359+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     360        "Metric for redistributed routes\n" 
     361        "Default metric\n") 
     362 { 
     363@@ -8276,7 +8327,7 @@ 
     364  
     365 DEFUN (no_bgp_redistribute_ipv6_rmap_metric, 
     366        no_bgp_redistribute_ipv6_rmap_metric_cmd, 
     367-       "no redistribute (connected|kernel|ospf6|ripng|static) route-map WORD metric <0-4294967295>", 
     368+       "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) route-map WORD metric <0-4294967295>", 
     369        NO_STR 
     370        "Redistribute information from another routing protocol\n" 
     371        "Connected\n" 
     372@@ -8284,6 +8335,8 @@ 
     373        "Open Shurtest Path First (OSPFv3)\n" 
     374        "Routing Information Protocol (RIPng)\n" 
     375        "Static routes\n" 
     376+       "Optimized Link State Routing (OLSR)\n" 
     377+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     378        "Route map reference\n" 
     379        "Pointer to route-map entries\n" 
     380        "Metric for redistributed routes\n" 
     381@@ -8305,7 +8358,7 @@ 
     382  
     383 ALIAS (no_bgp_redistribute_ipv6_rmap_metric, 
     384        no_bgp_redistribute_ipv6_metric_rmap_cmd, 
     385-       "no redistribute (connected|kernel|ospf6|ripng|static) metric <0-4294967295> route-map WORD", 
     386+       "no redistribute (connected|kernel|ospf6|ripng|static|olsr|batman) metric <0-4294967295> route-map WORD", 
     387        NO_STR 
     388        "Redistribute information from another routing protocol\n" 
     389        "Connected\n" 
     390@@ -8313,6 +8366,8 @@ 
     391        "Open Shurtest Path First (OSPFv3)\n" 
     392        "Routing Information Protocol (RIPng)\n" 
     393        "Static routes\n" 
     394+       "Optimized Link State Routing (OLSR)\n" 
     395+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     396        "Metric for redistributed routes\n" 
     397        "Default metric\n" 
     398        "Route map reference\n" 
     399@@ -8325,7 +8380,7 @@ 
     400 { 
     401   int i; 
     402   const char *str[] = { "system", "kernel", "connected", "static", "rip", 
     403-                 "ripng", "ospf", "ospf6", "isis", "bgp"}; 
     404+                 "ripng", "ospf", "ospf6", "isis", "bgp", "hsls", "olsr", "batman"}; 
     405  
     406   /* Unicast redistribution only.  */ 
     407   if (safi != SAFI_UNICAST) 
     408diff -Nur quagga-0.98.6/lib/zebra.h quagga-0.98.6.patched/lib/zebra.h 
     409--- quagga-0.98.6/lib/zebra.h   2005-06-15 14:54:18.000000000 +0300 
     410+++ quagga-0.98.6.patched/lib/zebra.h   2007-12-30 14:18:22.000000000 +0200 
     411@@ -3,6 +3,9 @@ 
     412  
     413 This file is part of GNU Zebra. 
     414  
     415+This file was modified from the original on 30/12/2007 
     416+by Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     417+ 
     418 GNU Zebra is free software; you can redistribute it and/or modify it 
     419 under the terms of the GNU General Public License as published by the 
     420 Free Software Foundation; either version 2, or (at your option) any 
     421@@ -378,7 +381,9 @@ 
     422 #define ZEBRA_ROUTE_ISIS                 8 
     423 #define ZEBRA_ROUTE_BGP                  9 
     424 #define ZEBRA_ROUTE_HSLS                10 
     425-#define ZEBRA_ROUTE_MAX                  11 
     426+#define ZEBRA_ROUTE_OLSR                11 
     427+#define ZEBRA_ROUTE_BATMAN              12 
     428+#define ZEBRA_ROUTE_MAX                  13 
     429  
     430 /* Zebra's family types. */ 
     431 #define ZEBRA_FAMILY_IPV4                1 
     432diff -Nur quagga-0.98.6/ospfd/ospf_vty.c quagga-0.98.6.patched/ospfd/ospf_vty.c 
     433--- quagga-0.98.6/ospfd/ospf_vty.c      2006-03-30 17:41:20.000000000 +0200 
     434+++ quagga-0.98.6.patched/ospfd/ospf_vty.c      2007-12-30 14:18:22.000000000 +0200 
     435@@ -3,6 +3,9 @@ 
     436  * 
     437  * This file is part of GNU Zebra. 
     438  * 
     439+ * This file was modified from the original on 30/12/2007 
     440+ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     441+ * 
     442  * GNU Zebra is free software; you can redistribute it and/or modify it 
     443  * under the terms of the GNU General Public License as published by the 
     444  * Free Software Foundation; either version 2, or (at your option) any 
     445@@ -106,11 +109,15 @@ 
     446     *source = ZEBRA_ROUTE_STATIC; 
     447   else if (strncmp (str, "r", 1) == 0) 
     448     *source = ZEBRA_ROUTE_RIP; 
     449-  else if (strncmp (str, "b", 1) == 0) 
     450+  else if (strncmp (str, "bg", 2) == 0) 
     451     *source = ZEBRA_ROUTE_BGP; 
     452+  else if (strncmp (str, "ol", 2) == 0) 
     453+    *source = ZEBRA_ROUTE_OLSR; 
     454+  else if (strncmp (str, "ba", 2) == 0) 
     455+    *source = ZEBRA_ROUTE_BATMAN; 
     456   else 
     457     return 0; 
     458- 
     459 
     460   return 1; 
     461 } 
     462  
     463@@ -5302,13 +5309,15 @@ 
     464  
    0465 
     466 DEFUN (ospf_redistribute_source_metric_type, 
     467        ospf_redistribute_source_metric_type_routemap_cmd, 
     468-       "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2) route-map WORD", 
     469+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2) route-map WORD", 
     470        "Redistribute information from another routing protocol\n" 
     471        "Kernel routes\n" 
     472        "Connected\n" 
     473        "Static routes\n" 
     474        "Routing Information Protocol (RIP)\n" 
     475        "Border Gateway Protocol (BGP)\n" 
     476+       "Optimized Link State Routing (OLSR)\n" 
     477+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     478        "Metric for redistributed routes\n" 
     479        "OSPF default metric\n" 
     480        "OSPF exterior metric type for redistributed routes\n" 
     481@@ -5346,13 +5355,15 @@ 
     482  
     483 ALIAS (ospf_redistribute_source_metric_type, 
     484        ospf_redistribute_source_metric_type_cmd, 
     485-       "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> metric-type (1|2)", 
     486+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> metric-type (1|2)", 
     487        "Redistribute information from another routing protocol\n" 
     488        "Kernel routes\n" 
     489        "Connected\n" 
     490        "Static routes\n" 
     491        "Routing Information Protocol (RIP)\n" 
     492        "Border Gateway Protocol (BGP)\n" 
     493+       "Optimized Link State Routing (OLSR)\n" 
     494+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     495        "Metric for redistributed routes\n" 
     496        "OSPF default metric\n" 
     497        "OSPF exterior metric type for redistributed routes\n" 
     498@@ -5361,25 +5372,29 @@ 
     499  
     500 ALIAS (ospf_redistribute_source_metric_type, 
     501        ospf_redistribute_source_metric_cmd, 
     502-       "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214>", 
     503+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214>", 
     504        "Redistribute information from another routing protocol\n" 
     505        "Kernel routes\n" 
     506        "Connected\n" 
     507        "Static routes\n" 
     508        "Routing Information Protocol (RIP)\n" 
     509        "Border Gateway Protocol (BGP)\n" 
     510+       "Optimized Link State Routing (OLSR)\n" 
     511+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     512        "Metric for redistributed routes\n" 
     513        "OSPF default metric\n") 
     514  
     515 DEFUN (ospf_redistribute_source_type_metric, 
     516        ospf_redistribute_source_type_metric_routemap_cmd, 
     517-       "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214> route-map WORD", 
     518+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214> route-map WORD", 
     519        "Redistribute information from another routing protocol\n" 
     520        "Kernel routes\n" 
     521        "Connected\n" 
     522        "Static routes\n" 
     523        "Routing Information Protocol (RIP)\n" 
     524        "Border Gateway Protocol (BGP)\n" 
     525+       "Optimized Link State Routing (OLSR)\n" 
     526+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     527        "OSPF exterior metric type for redistributed routes\n" 
     528        "Set OSPF External Type 1 metrics\n" 
     529        "Set OSPF External Type 2 metrics\n" 
     530@@ -5417,13 +5432,15 @@ 
     531  
     532 ALIAS (ospf_redistribute_source_type_metric, 
     533        ospf_redistribute_source_type_metric_cmd, 
     534-       "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) metric <0-16777214>", 
     535+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) metric <0-16777214>", 
     536        "Redistribute information from another routing protocol\n" 
     537        "Kernel routes\n" 
     538        "Connected\n" 
     539        "Static routes\n" 
     540        "Routing Information Protocol (RIP)\n" 
     541        "Border Gateway Protocol (BGP)\n" 
     542+       "Optimized Link State Routing (OLSR)\n" 
     543+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     544        "OSPF exterior metric type for redistributed routes\n" 
     545        "Set OSPF External Type 1 metrics\n" 
     546        "Set OSPF External Type 2 metrics\n" 
     547@@ -5432,7 +5449,7 @@ 
     548  
     549 ALIAS (ospf_redistribute_source_type_metric, 
     550        ospf_redistribute_source_type_cmd, 
     551-       "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2)", 
     552+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2)", 
     553        "Redistribute information from another routing protocol\n" 
     554        "Kernel routes\n" 
     555        "Connected\n" 
     556@@ -5440,28 +5457,35 @@ 
     557        "Routing Information Protocol (RIP)\n" 
     558        "Border Gateway Protocol (BGP)\n" 
     559        "OSPF exterior metric type for redistributed routes\n" 
     560+       "Optimized Link State Routing (OLSR)\n" 
     561+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     562        "Set OSPF External Type 1 metrics\n" 
     563        "Set OSPF External Type 2 metrics\n") 
     564  
     565 ALIAS (ospf_redistribute_source_type_metric, 
     566        ospf_redistribute_source_cmd, 
     567-       "redistribute (kernel|connected|static|rip|bgp)", 
     568+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman)", 
     569        "Redistribute information from another routing protocol\n" 
     570        "Kernel routes\n" 
     571        "Connected\n" 
     572        "Static routes\n" 
     573        "Routing Information Protocol (RIP)\n" 
     574-       "Border Gateway Protocol (BGP)\n") 
     575+       "Border Gateway Protocol (BGP)\n" 
     576+       "Optimized Link State Routing (OLSR)\n" 
     577+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     578+       ) 
     579  
     580 DEFUN (ospf_redistribute_source_metric_routemap, 
     581        ospf_redistribute_source_metric_routemap_cmd, 
     582-       "redistribute (kernel|connected|static|rip|bgp) metric <0-16777214> route-map WORD", 
     583+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric <0-16777214> route-map WORD", 
     584        "Redistribute information from another routing protocol\n" 
     585        "Kernel routes\n" 
     586        "Connected\n" 
     587        "Static routes\n" 
     588        "Routing Information Protocol (RIP)\n" 
     589        "Border Gateway Protocol (BGP)\n" 
     590+       "Optimized Link State Routing (OLSR)\n" 
     591+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     592        "Metric for redistributed routes\n" 
     593        "OSPF default metric\n" 
     594        "Route map reference\n" 
     595@@ -5490,13 +5514,15 @@ 
     596  
     597 DEFUN (ospf_redistribute_source_type_routemap, 
     598        ospf_redistribute_source_type_routemap_cmd, 
     599-       "redistribute (kernel|connected|static|rip|bgp) metric-type (1|2) route-map WORD", 
     600+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) metric-type (1|2) route-map WORD", 
     601        "Redistribute information from another routing protocol\n" 
     602        "Kernel routes\n" 
     603        "Connected\n" 
     604        "Static routes\n" 
     605        "Routing Information Protocol (RIP)\n" 
     606        "Border Gateway Protocol (BGP)\n" 
     607+       "Optimized Link State Routing (OLSR)\n" 
     608+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     609        "OSPF exterior metric type for redistributed routes\n" 
     610        "Set OSPF External Type 1 metrics\n" 
     611        "Set OSPF External Type 2 metrics\n" 
     612@@ -5526,13 +5552,15 @@ 
     613  
     614 DEFUN (ospf_redistribute_source_routemap, 
     615        ospf_redistribute_source_routemap_cmd, 
     616-       "redistribute (kernel|connected|static|rip|bgp) route-map WORD", 
     617+       "redistribute (kernel|connected|static|rip|bgp|olsr|batman) route-map WORD", 
     618        "Redistribute information from another routing protocol\n" 
     619        "Kernel routes\n" 
     620        "Connected\n" 
     621        "Static routes\n" 
     622        "Routing Information Protocol (RIP)\n" 
     623        "Border Gateway Protocol (BGP)\n" 
     624+       "Optimized Link State Routing (OLSR)\n" 
     625+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     626        "Route map reference\n" 
     627        "Pointer to route-map entries\n") 
     628 { 
     629@@ -5553,14 +5581,17 @@ 
     630  
     631 DEFUN (no_ospf_redistribute_source, 
     632        no_ospf_redistribute_source_cmd, 
     633-       "no redistribute (kernel|connected|static|rip|bgp)", 
     634+       "no redistribute (kernel|connected|static|rip|bgp|olsr|batman)", 
     635        NO_STR 
     636        "Redistribute information from another routing protocol\n" 
     637        "Kernel routes\n" 
     638        "Connected\n" 
     639        "Static routes\n" 
     640        "Routing Information Protocol (RIP)\n" 
     641-       "Border Gateway Protocol (BGP)\n") 
     642+       "Border Gateway Protocol (BGP)\n" 
     643+       "Optimized Link State Routing (OLSR)\n" 
     644+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     645+       ) 
     646 { 
     647   struct ospf *ospf = vty->index; 
     648   int source; 
     649@@ -5574,7 +5605,7 @@ 
     650  
     651 DEFUN (ospf_distribute_list_out, 
     652        ospf_distribute_list_out_cmd, 
     653-       "distribute-list WORD out (kernel|connected|static|rip|bgp)", 
     654+       "distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)", 
     655        "Filter networks in routing updates\n" 
     656        "Access-list name\n" 
     657        OUT_STR 
     658@@ -5582,7 +5613,10 @@ 
     659        "Connected\n" 
     660        "Static routes\n" 
     661        "Routing Information Protocol (RIP)\n" 
     662-       "Border Gateway Protocol (BGP)\n") 
     663+       "Border Gateway Protocol (BGP)\n" 
     664+       "Optimized Link State Routing (OLSR)\n" 
     665+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     666+) 
     667 { 
     668   struct ospf *ospf = vty->index; 
     669   int source; 
     670@@ -5596,7 +5630,7 @@ 
     671  
     672 DEFUN (no_ospf_distribute_list_out, 
     673        no_ospf_distribute_list_out_cmd, 
     674-       "no distribute-list WORD out (kernel|connected|static|rip|bgp)", 
     675+       "no distribute-list WORD out (kernel|connected|static|rip|bgp|olsr|batman)", 
     676        NO_STR 
     677        "Filter networks in routing updates\n" 
     678        "Access-list name\n" 
     679@@ -5605,7 +5639,10 @@ 
     680        "Connected\n" 
     681        "Static routes\n" 
     682        "Routing Information Protocol (RIP)\n" 
     683-       "Border Gateway Protocol (BGP)\n") 
     684+       "Border Gateway Protocol (BGP)\n" 
     685+       "Optimized Link State Routing (OLSR)\n" 
     686+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     687+) 
     688 { 
     689   struct ospf *ospf = vty->index; 
     690   int source; 
     691@@ -7121,7 +7158,8 @@ 
     692  
     693  
    1694 
     695 const char *distribute_str[] = { "system", "kernel", "connected", "static", 
     696-                               "rip", "ripng", "ospf", "ospf6", "isis", "bgp"}; 
     697+                               "rip", "ripng", "ospf", "ospf6", "isis", "bgp", 
     698+                               "hsls","olsr","batman"}; 
     699 int 
     700 config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf) 
     701 { 
     702diff -Nur quagga-0.98.6/zebra/redistribute.c quagga-0.98.6.patched/zebra/redistribute.c 
     703--- quagga-0.98.6/zebra/redistribute.c  2005-06-15 14:54:51.000000000 +0300 
     704+++ quagga-0.98.6.patched/zebra/redistribute.c  2007-12-30 14:18:22.000000000 +0200 
     705@@ -3,6 +3,9 @@ 
     706  * 
     707  * This file is part of GNU Zebra. 
     708  * 
     709+ * This file was modified from the original on 30/12/2007 
     710+ * by Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     711+ * 
     712  * GNU Zebra is free software; you can redistribute it and/or modify it 
     713  * under the terms of the GNU General Public License as published by the 
     714  * Free Software Foundation; either version 2, or (at your option) any 
     715@@ -253,6 +256,8 @@ 
     716     case ZEBRA_ROUTE_OSPF: 
     717     case ZEBRA_ROUTE_OSPF6: 
     718     case ZEBRA_ROUTE_BGP: 
     719+    case ZEBRA_ROUTE_OLSR: 
     720+    case ZEBRA_ROUTE_BATMAN: 
     721       if (! client->redist[type]) 
     722        { 
     723          client->redist[type] = 1; 
     724@@ -281,6 +286,8 @@ 
     725     case ZEBRA_ROUTE_OSPF: 
     726     case ZEBRA_ROUTE_OSPF6: 
     727     case ZEBRA_ROUTE_BGP: 
     728+    case ZEBRA_ROUTE_OLSR: 
     729+    case ZEBRA_ROUTE_BATMAN: 
     730       client->redist[type] = 0; 
     731       break; 
     732     default: 
     733diff -Nur quagga-0.98.6/zebra/zebra_vty.c quagga-0.98.6.patched/zebra/zebra_vty.c 
     734--- quagga-0.98.6/zebra/zebra_vty.c     2004-12-18 18:03:29.000000000 +0200 
     735+++ quagga-0.98.6.patched/zebra/zebra_vty.c     2007-12-30 14:25:48.000000000 +0200 
     736@@ -53,6 +53,10 @@ 
     737       return "isis"; 
     738     case ZEBRA_ROUTE_BGP: 
     739       return "bgp"; 
     740+    case ZEBRA_ROUTE_OLSR: 
     741+      return "olsr"; 
     742+    case ZEBRA_ROUTE_BATMAN: 
     743+      return "batman"; 
     744     default: 
     745       return "unknown"; 
     746     } 
     747@@ -84,6 +88,12 @@ 
     748       return 'I'; 
     749     case ZEBRA_ROUTE_BGP: 
     750       return 'B'; 
     751+    case ZEBRA_ROUTE_HSLS: 
     752+      return 'H'; 
     753+    case ZEBRA_ROUTE_OLSR: 
     754+      return 'L'; 
     755+    case ZEBRA_ROUTE_BATMAN: 
     756+      return 'M'; 
     757     default: 
     758       return '?'; 
     759     } 
     760@@ -755,8 +765,8 @@ 
     761 } 
     762  
     763 #define SHOW_ROUTE_V4_HEADER "Codes: K - kernel route, C - connected, " \ 
     764-  "S - static, R - RIP, O - OSPF,%s       I - ISIS, B - BGP, " \ 
     765-  "> - selected route, * - FIB route%s%s" 
     766+  "S - static, R - RIP, O - OSPF,%s       I - ISIS, B - BGP, H - HSLS, " \ 
     767+  "L - OLSR, M - BATMAN, > - selected route, * - FIB route%s%s" 
     768  
     769 DEFUN (show_ip_route, 
     770        show_ip_route_cmd, 
     771@@ -874,7 +884,7 @@ 
     772  
     773 DEFUN (show_ip_route_protocol, 
     774        show_ip_route_protocol_cmd, 
     775-       "show ip route (bgp|connected|isis|kernel|ospf|rip|static)", 
     776+       "show ip route (bgp|connected|isis|kernel|ospf|rip|olsr|batman|static)", 
     777        SHOW_STR 
     778        IP_STR 
     779        "IP routing table\n" 
     780@@ -884,6 +894,8 @@ 
     781        "Kernel\n" 
     782        "Open Shortest Path First (OSPF)\n" 
     783        "Routing Information Protocol (RIP)\n" 
     784+       "Optimized Link State Routing (OLSR)\n" 
     785+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     786        "Static routes\n") 
     787 { 
     788   int type; 
     789@@ -892,13 +904,13 @@ 
     790   struct rib *rib; 
     791   int first = 1; 
     792  
     793-  if (strncmp (argv[0], "b", 1) == 0) 
     794+  if (strncmp (argv[0], "bg", 2) == 0) 
     795     type = ZEBRA_ROUTE_BGP; 
     796   else if (strncmp (argv[0], "c", 1) == 0) 
     797     type = ZEBRA_ROUTE_CONNECT; 
     798   else if (strncmp (argv[0], "k", 1) ==0) 
     799     type = ZEBRA_ROUTE_KERNEL; 
     800-  else if (strncmp (argv[0], "o", 1) == 0) 
     801+  else if (strncmp (argv[0], "os", 2) == 0) 
     802     type = ZEBRA_ROUTE_OSPF; 
     803   else if (strncmp (argv[0], "i", 1) == 0) 
     804     type = ZEBRA_ROUTE_ISIS; 
     805@@ -906,6 +918,10 @@ 
     806     type = ZEBRA_ROUTE_RIP; 
     807   else if (strncmp (argv[0], "s", 1) == 0) 
     808     type = ZEBRA_ROUTE_STATIC; 
     809+  else if (strncmp (argv[0], "ol", 2) == 0) 
     810+    type = ZEBRA_ROUTE_OLSR; 
     811+  else if (strncmp (argv[0], "ba", 2) == 0) 
     812+    type = ZEBRA_ROUTE_BATMAN; 
     813   else  
     814     { 
     815       vty_out (vty, "Unknown route type%s", VTY_NEWLINE); 
     816@@ -1732,7 +1748,7 @@ 
     817  
     818 DEFUN (show_ipv6_route_protocol, 
     819        show_ipv6_route_protocol_cmd, 
     820-       "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|static)", 
     821+       "show ipv6 route (bgp|connected|isis|kernel|ospf6|ripng|olsr|batman|static)", 
     822        SHOW_STR 
     823        IP_STR 
     824        "IP routing table\n" 
     825@@ -1742,6 +1758,8 @@ 
     826        "Kernel\n" 
     827        "Open Shortest Path First (OSPFv3)\n" 
     828        "Routing Information Protocol (RIPng)\n" 
     829+       "Optimized Link State Routing (OLSR)\n" 
     830+       "Better Approach to Mobile Ad-Hoc Networking (BATMAN)\n" 
     831        "Static routes\n") 
     832 { 
     833   int type; 
     834@@ -1750,13 +1768,13 @@ 
     835   struct rib *rib; 
     836   int first = 1; 
     837  
     838-  if (strncmp (argv[0], "b", 1) == 0) 
     839+  if (strncmp (argv[0], "bg", 2) == 0) 
     840     type = ZEBRA_ROUTE_BGP; 
     841   else if (strncmp (argv[0], "c", 1) == 0) 
     842     type = ZEBRA_ROUTE_CONNECT; 
     843   else if (strncmp (argv[0], "k", 1) ==0) 
     844     type = ZEBRA_ROUTE_KERNEL; 
     845-  else if (strncmp (argv[0], "o", 1) == 0) 
     846+  else if (strncmp (argv[0], "os", 2) == 0) 
     847     type = ZEBRA_ROUTE_OSPF6; 
     848   else if (strncmp (argv[0], "i", 1) == 0) 
     849     type = ZEBRA_ROUTE_ISIS; 
     850@@ -1764,7 +1782,11 @@ 
     851     type = ZEBRA_ROUTE_RIPNG; 
     852   else if (strncmp (argv[0], "s", 1) == 0) 
     853     type = ZEBRA_ROUTE_STATIC; 
     854-  else  
     855+  else if (strncmp (argv[0], "ol", 2) == 0) 
     856+     type = ZEBRA_ROUTE_OLSR; 
     857+  else if (strncmp (argv[0], "ba", 2) == 0) 
     858+     type = ZEBRA_ROUTE_BATMAN; 
     859+  else 
     860     { 
  • lib/quagga/README_QUAGGA

    +       vty_out (vty, "Unknown route type%s", VTY_NEWLINE);
    +       return CMD_WARNING;
    a b  
    11--------------------------------------------------------------------- 
    22QUAGGA PLUGIN FOR OLSRD 
    33by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de> 
     4 
     5addittions by:  Sven-Ola Tuecke <sven-ola-aet-gmx.de> 
     6                Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
    47--------------------------------------------------------------------- 
    58 
    6 This is the Quagga Plugin for the OLSRD.  
    7 It allowes olsrd to redistribute from various quagga-protocols  
     9This is the Quagga Plugin for OLSRd.  
     10It allows olsrd to redistribute from various quagga-protocols  
    811as well as to export olsr-routes to quagga so that they can be 
    912redistributed by the quagga-routing-daemons. 
    1013 
    11 Note Sven-Ola: You also need a source distribution of quagga-0.98.5 
    12 or quagga-0.98.6 (that is the current stable). The quagga source tree  
    13 needs to be patched with quagga-0.98.6-olsr.diff, compiled and installed 
    14 via 'make install'. Because many people will otherwise have compile 
    15 probs, I've added 2 include files in lib/quagga/src/quagga. If you 
    16 want to use another version of quagga, make sure to remove these 
    17 before you compile the olsrd_quagga plugin. 
     14You also need a source distribution of quagga-0.98.5 or quagga-0.98.6 
     15(that is the current stable). The quagga source tree needs to be 
     16patched with quagga-0.98.6.diff, compiled and installed via 
     17'make install'. 
    1818 
    1919--------------------------------------------------------------------- 
    2020PLUGIN PARAMETERS (PlParam) 
     
    2727        May be used more then once 
    2828 
    2929PlParam "ExportRoutes" "<only/both>" 
    30         exportes olsr-routes to quagga or to both, quagga and kernel 
     30        exports olsr-routes to quagga or to both, quagga and kernel 
    3131        no routes are exported to quagga (normal behaviour) if not set. 
    3232 
    33 PlParam "LocalPref" "true" 
     33PlParam "LocalPref" "<true/false>" 
    3434        sets the Zebra SELECTED-flag on the routes exported to zebra 
    3535        which means these routes are prefered in any case. 
    3636 
    3737PlParam "Distance" "0-255" 
    38         allowes to set the administrative distance to routes exported  
    39         to Zebra. 
     38        allows to set the administrative distance to routes exported  
     39        to zebra. 
    4040         
    4141--------------------------------------------------------------------- 
    4242SAMPLE CONFIG 
    4343--------------------------------------------------------------------- 
    4444 
    45 add in /etc/olsrd.conf: 
     45add in /usr/local/etc/olsrd.conf: 
    4646 
    4747LoadPlugin "olsrd_quagga.so.0.2.2" 
    4848{ 
     
    5555 
    5656 
    5757--------------------------------------------------------------------- 
    58 EOF / 8.5.2006 
     58EOF / 29.12.2008 
  • lib/quagga/src/olsrd_plugin.c

    a b  
     1/* 
     2 * OLSRd Quagga plugin 
     3 * 
     4 * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de> 
     5 * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     6 * 
     7 * This program is free software; you can redistribute it and/or modify 
     8 * it under the terms of the GNU General Public License version 2 as 
     9 * published by the Free Software Foundation or - at your option - under 
     10 * the terms of the GNU General Public Licence version 2 but can be 
     11 * linked to any BSD-Licenced Software with public available sourcecode 
     12 * 
     13 */ 
     14 
     15/* ------------------------------------------------------------------------- 
     16 * File               : olsrd_plugin.c 
     17 * Description        : functions to setup plugin 
     18 * ------------------------------------------------------------------------- */ 
    119 
    2 /*************************************************************************** 
    3  projekt              : olsrd-quagga 
    4  file                 : olsrd_plugin.c 
    5  usage                : olsrd-plugin-handler-stuff 
    6  copyright            : (C) 2006 by Immo 'FaUl' Wehrenberg 
    7  e-mail               : immo@chaostreff-dortmund.de 
    8  ***************************************************************************/ 
    9  
    10 /*************************************************************************** 
    11  *                                                                         * 
    12  *   This program is free software; you can redistribute it and/or modify  * 
    13  *   it under the terms of the GNU General Public License version 2 as     * 
    14  *   published by the Free Software Foundation.                            * 
    15  *                                                                         * 
    16  ***************************************************************************/ 
    1720 
    1821#include <stdio.h> 
    1922#include <string.h> 
     
    2427#include "scheduler.h" 
    2528#include "defs.h" 
    2629#include "quagga.h" 
    27 #include "kernel_routes.h" 
    2830#include "net_olsr.h" 
    2931 
    3032#define PLUGIN_NAME    "OLSRD quagga plugin" 
     
    4143static set_plugin_parameter set_distance; 
    4244static set_plugin_parameter set_localpref; 
    4345 
    44 static export_route_function orig_addroute_function; 
    45 static export_route_function orig_delroute_function; 
    4646 
    47 int 
    48 olsrd_plugin_interface_version(void) 
    49 { 
     47int olsrd_plugin_interface_version (void) { 
    5048  return PLUGIN_INTERFACE_VERSION; 
    5149} 
    5250 
    5351static const struct olsrd_plugin_parameters plugin_parameters[] = { 
    54   {.name = "redistribute",.set_plugin_parameter = &set_redistribute,}, 
    55   {.name = "ExportRoutes",.set_plugin_parameter = &set_exportroutes,}, 
    56   {.name = "Distance",.set_plugin_parameter = &set_distance,}, 
    57   {.name = "LocalPref",.set_plugin_parameter = &set_localpref,}, 
     52  { .name = "redistribute", .set_plugin_parameter = &set_redistribute, }, 
     53  { .name = "ExportRoutes", .set_plugin_parameter = &set_exportroutes, }, 
     54  { .name = "Distance",     .set_plugin_parameter = &set_distance,     }, 
     55  { .name = "LocalPref",    .set_plugin_parameter = &set_localpref,    }, 
    5856}; 
    5957 
    60 void 
    61 olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size) 
    62 { 
     58void olsrd_get_plugin_parameters (const struct olsrd_plugin_parameters **params, 
     59                                  int *size) { 
    6360  *params = plugin_parameters; 
    64   *size = sizeof plugin_parameters / sizeof *plugin_parameters; 
     61  *size = ARRAYSIZE(plugin_parameters); 
    6562} 
    6663 
    67 static int 
    68 set_redistribute(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) 
    69 { 
    70   const char *zebra_route_types[] = { "system", "kernel", "connect", 
    71     "static", "rip", "ripng", "ospf", 
    72     "ospf6", "isis", "bgp", "hsls" 
    73   }; 
     64static int set_redistribute (const char *value, 
     65                             void *data __attribute__((unused)), 
     66                             set_plugin_parameter_addon addon __attribute__((unused))) { 
     67  const char *zebra_route_types[] = {"system","kernel","connect", 
     68                                              "static","rip","ripng","ospf", 
     69                                              "ospf6","isis","bgp","hsls"}; 
    7470  unsigned int i; 
    7571 
    7672  for (i = 0; i < ARRAYSIZE(zebra_route_types); i++) { 
    77     if (!strcmp(value, zebra_route_types[i])) { 
    78       zebra_redistribute(i); 
    79       return 0; 
    80     } 
     73    if (!strcmp(value, zebra_route_types[i])) 
     74      if (zebra_redistribute (i)) return 1; 
    8175  } 
    82   return 1; 
     76 
     77  return 0; 
    8378} 
    8479 
    85 static int 
    86 set_exportroutes(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) 
    87 { 
     80static int set_exportroutes (const char *value, 
     81                             void *data __attribute__((unused)), 
     82                             set_plugin_parameter_addon addon __attribute__((unused))) { 
    8883  if (!strcmp(value, "only")) { 
    89     orig_addroute_function = NULL; 
    90     orig_delroute_function = NULL; 
    91     olsr_addroute_function = zebra_add_olsr_v4_route; 
    92     olsr_delroute_function = zebra_del_olsr_v4_route; 
     84    olsr_addroute_function = zebra_add_route; 
     85    olsr_delroute_function = zebra_del_route; 
    9386    zebra_export_routes(1); 
    94   } else if (!strcmp(value, "additional")) { 
    95     orig_addroute_function = olsr_addroute_function; 
    96     orig_delroute_function = olsr_delroute_function; 
    97     olsr_addroute_function = zebra_add_olsr_v4_route; 
    98     olsr_delroute_function = zebra_del_olsr_v4_route; 
     87  } 
     88  else if (!strcmp(value, "additional")) { 
     89    olsr_addroute_function = zebra_add_route; 
     90    olsr_delroute_function = zebra_del_route; 
    9991    zebra_export_routes(1); 
    100   } else 
    101     zebra_export_routes(0); 
     92  } 
     93  else zebra_export_routes(0); 
    10294  return 0; 
    10395} 
    10496 
    105 static int 
    106 set_distance(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) 
    107 { 
     97static int set_distance(const char *value, void *data __attribute__((unused)), 
     98                        set_plugin_parameter_addon addon __attribute__((unused))) { 
    10899  int distance; 
    109100 
    110   if (set_plugin_int(value, &distance, addon)) 
    111     return 1; 
    112   if (distance < 0 || distance > 255) 
    113     return 1; 
     101  if (set_plugin_int(value, &distance, addon)) return 1; 
     102  if (distance < 0 || distance > 255) return 1; 
    114103  zebra_olsr_distance(distance); 
    115104  return 0; 
    116105} 
    117106 
    118 static int 
    119 set_localpref(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))) 
    120 { 
     107static int set_localpref(const char *value, void *data __attribute__((unused)), 
     108                         set_plugin_parameter_addon addon __attribute__((unused))) { 
    121109  int b; 
    122110 
    123   if (set_plugin_boolean(value, &b, addon)) 
    124     return 1; 
    125   if (b) 
    126     zebra_olsr_localpref(); 
     111  if (set_plugin_boolean(value, &b, addon)) return 1; 
     112  if (b) zebra_olsr_localpref(); 
    127113  return 0; 
    128114} 
    129115 
    130 int 
    131 olsrd_plugin_init(void) 
    132 { 
    133   if (olsr_cnf->ip_version != AF_INET) { 
    134     fputs("see the source - ipv6 so far not supported\n", stderr); 
     116 
     117int olsrd_plugin_init(void) { 
     118  if(olsr_cnf->ip_version != AF_INET) { 
     119    fputs("see the source - ipv6 so far not supported\n" ,stderr); 
    135120    return 1; 
    136121  } 
    137122 
    138   olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, &zebra_check, NULL, 0); 
     123  olsr_start_timer(1 * MSEC_PER_SEC, 0, OLSR_TIMER_PERIODIC, 
     124                   &zebra_parse, NULL, 0); 
    139125 
    140126  return 0; 
    141127} 
    142128 
    143 static void 
    144 my_init(void) 
    145 { 
     129static void my_init(void) { 
    146130  init_zebra(); 
    147131} 
    148132 
    149 static void 
    150 my_fini(void) 
    151 { 
     133static void my_fini(void) { 
    152134  zebra_cleanup(); 
    153135} 
    154136 
    155 /* 
    156  * Local Variables: 
    157  * c-basic-offset: 2 
    158  * indent-tabs-mode: nil 
    159  * End: 
    160  */ 
  • deleted file lib/quagga/src/quagga/zassert.h

    + -  
    1  
    2 /* 
    3  */ 
    4  
    5 #ifndef _QUAGGA_ASSERT_H 
    6 #define _QUAGGA_ASSERT_H 
    7  
    8 extern void _zlog_assert_failed(const char *assertion, const char *file, unsigned int line, const char *function) 
    9   __attribute__ ((noreturn)); 
    10  
    11 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 
    12 #define __ASSERT_FUNCTION    __func__ 
    13 #elif defined(__GNUC__) 
    14 #define __ASSERT_FUNCTION    __FUNCTION__ 
    15 #else 
    16 #define __ASSERT_FUNCTION    NULL 
    17 #endif 
    18  
    19 #define zassert(EX) ((void)((EX) ?  0 : \ 
    20                             (_zlog_assert_failed(#EX, __FILE__, __LINE__, \ 
    21                                                  __ASSERT_FUNCTION), 0))) 
    22  
    23 #undef assert 
    24 #define assert(EX) zassert(EX) 
    25  
    26 #endif /* _QUAGGA_ASSERT_H */ 
    27  
    28 /* 
    29  * Local Variables: 
    30  * c-basic-offset: 2 
    31  * indent-tabs-mode: nil 
    32  * End: 
    33  */ 
  • deleted file lib/quagga/src/quagga/zebra.h

    + -  
    1  
    2 /* Zebra common header. 
    3    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro 
    4  
    5 This file is part of GNU Zebra. 
    6  
    7 GNU Zebra is free software; you can redistribute it and/or modify it 
    8 under the terms of the GNU General Public License as published by the 
    9 Free Software Foundation; either version 2, or (at your option) any 
    10 later version. 
    11  
    12 GNU Zebra is distributed in the hope that it will be useful, but 
    13 WITHOUT ANY WARRANTY; without even the implied warranty of 
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
    15 General Public License for more details. 
    16  
    17 You should have received a copy of the GNU General Public License 
    18 along with GNU Zebra; see the file COPYING.  If not, write to the Free 
    19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
    20 02111-1307, USA.  */ 
    21  
    22 #ifndef _ZEBRA_H 
    23 #define _ZEBRA_H 
    24  
    25 #ifdef HAVE_CONFIG_H 
    26 #include "config.h" 
    27 #endif /* HAVE_CONFIG_H */ 
    28  
    29 #ifdef SUNOS_5 
    30 #define _XPG4_2 
    31 #define __EXTENSIONS__ 
    32 typedef unsigned int u_int32_t; 
    33 typedef unsigned short u_int16_t; 
    34 typedef unsigned char u_int8_t; 
    35 #endif /* SUNOS_5 */ 
    36  
    37 #ifndef HAVE_SOCKLEN_T 
    38 typedef int socklen_t; 
    39 #endif /* HAVE_SOCKLEN_T */ 
    40  
    41 #include <unistd.h> 
    42 #include <stdio.h> 
    43 #include <stdlib.h> 
    44 #include <ctype.h> 
    45 #include <errno.h> 
    46 #include <fcntl.h> 
    47 #include <signal.h> 
    48 #include <string.h> 
    49 #include <pwd.h> 
    50 #include <grp.h> 
    51 #ifdef HAVE_STROPTS_H 
    52 #include <stropts.h> 
    53 #endif /* HAVE_STROPTS_H */ 
    54 #include <sys/fcntl.h> 
    55 #ifdef HAVE_SYS_SELECT_H 
    56 #include <sys/select.h> 
    57 #endif /* HAVE_SYS_SELECT_H */ 
    58 #include <sys/stat.h> 
    59 #include <sys/time.h> 
    60 #include <sys/types.h> 
    61 #include <sys/param.h> 
    62 #ifdef HAVE_SYS_SYSCTL_H 
    63 #include <sys/sysctl.h> 
    64 #endif /* HAVE_SYS_SYSCTL_H */ 
    65 #include <sys/ioctl.h> 
    66 #ifdef HAVE_SYS_CONF_H 
    67 #include <sys/conf.h> 
    68 #endif /* HAVE_SYS_CONF_H */ 
    69 #ifdef HAVE_SYS_KSYM_H 
    70 #include <sys/ksym.h> 
    71 #endif /* HAVE_SYS_KSYM_H */ 
    72 #include <syslog.h> 
    73 #include <time.h> 
    74 #include <sys/uio.h> 
    75 #include <sys/utsname.h> 
    76 #ifdef HAVE_RUSAGE 
    77 #include <sys/resource.h> 
    78 #endif /* HAVE_RUSAGE */ 
    79 #ifdef HAVE_LIMITS_H 
    80 #include <limits.h> 
    81 #endif /* HAVE_LIMITS_H */ 
    82  
    83 /* machine dependent includes */ 
    84 #ifdef SUNOS_5 
    85 #include <strings.h> 
    86 #endif /* SUNOS_5 */ 
    87  
    88 /* machine dependent includes */ 
    89 #ifdef HAVE_LINUX_VERSION_H 
    90 #include <linux/version.h> 
    91 #endif /* HAVE_LINUX_VERSION_H */ 
    92  
    93 #ifdef HAVE_ASM_TYPES_H 
    94 #include <asm/types.h> 
    95 #endif /* HAVE_ASM_TYPES_H */ 
    96  
    97 /* misc include group */ 
    98 #include <stdarg.h> 
    99 #if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 
    100  
    101 /* Not C99; do we need to define va_copy? */ 
    102 #ifndef va_copy 
    103 #ifdef __va_copy 
    104 #define va_copy(DST,SRC) __va_copy(DST,SRC) 
    105 #else 
    106  
    107 /* Now we are desperate; this should work on many typical platforms. 
    108    But this is slightly dangerous, because the standard does not require 
    109    va_copy to be a macro. */ 
    110 #define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list)) 
    111 #warning "Not C99 and no va_copy macro available, falling back to memcpy" 
    112 #endif /* __va_copy */ 
    113 #endif /* !va_copy */ 
    114 #endif /* !C99 */ 
    115  
    116 #ifdef HAVE_LCAPS 
    117 #include <sys/capability.h> 
    118 #include <sys/prctl.h> 
    119 #endif /* HAVE_LCAPS */ 
    120  
    121 /* network include group */ 
    122  
    123 #include <sys/socket.h> 
    124  
    125 #ifdef HAVE_SYS_SOCKIO_H 
    126 #include <sys/sockio.h> 
    127 #endif /* HAVE_SYS_SOCKIO_H */ 
    128  
    129 #ifdef HAVE_NETINET_IN_H 
    130 #include <netinet/in.h> 
    131 #endif /* HAVE_NETINET_IN_H */ 
    132 #include <netinet/in_systm.h> 
    133 #include <netinet/ip.h> 
    134 #include <netinet/tcp.h> 
    135  
    136 #ifdef HAVE_NET_NETOPT_H 
    137 #include <net/netopt.h> 
    138 #endif /* HAVE_NET_NETOPT_H */ 
    139  
    140 #include <net/if.h> 
    141  
    142 #ifdef HAVE_NET_IF_DL_H 
    143 #include <net/if_dl.h> 
    144 #endif /* HAVE_NET_IF_DL_H */ 
    145  
    146 #ifdef HAVE_NET_IF_VAR_H 
    147 #include <net/if_var.h> 
    148 #endif /* HAVE_NET_IF_VAR_H */ 
    149  
    150 #ifdef HAVE_NET_ROUTE_H 
    151 #include <net/route.h> 
    152 #endif /* HAVE_NET_ROUTE_H */ 
    153  
    154 #ifdef HAVE_NETLINK 
    155 #include <linux/netlink.h> 
    156 #include <linux/rtnetlink.h> 
    157 #else 
    158 #define RT_TABLE_MAIN           0 
    159 #endif /* HAVE_NETLINK */ 
    160  
    161 #ifdef HAVE_NETDB_H 
    162 #include <netdb.h> 
    163 #endif /* HAVE_NETDB_H */ 
    164  
    165 #include <arpa/inet.h> 
    166 #include <arpa/telnet.h> 
    167  
    168 #ifdef HAVE_INET_ND_H 
    169 #include <inet/nd.h> 
    170 #endif /* HAVE_INET_ND_H */ 
    171  
    172 #ifdef HAVE_NETINET_IN_VAR_H 
    173 #include <netinet/in_var.h> 
    174 #endif /* HAVE_NETINET_IN_VAR_H */ 
    175  
    176 #ifdef HAVE_NETINET6_IN6_VAR_H 
    177 #include <netinet6/in6_var.h> 
    178 #endif /* HAVE_NETINET6_IN6_VAR_H */ 
    179  
    180 #ifdef HAVE_NETINET_IN6_VAR_H 
    181 #include <netinet/in6_var.h> 
    182 #endif /* HAVE_NETINET_IN6_VAR_H */ 
    183  
    184 #ifdef HAVE_NETINET6_IN_H 
    185 #include <netinet6/in.h> 
    186 #endif /* HAVE_NETINET6_IN_H */ 
    187  
    188 #ifdef HAVE_NETINET6_IP6_H 
    189 #include <netinet6/ip6.h> 
    190 #endif /* HAVE_NETINET6_IP6_H */ 
    191  
    192 #ifdef HAVE_NETINET_ICMP6_H 
    193 #include <netinet/icmp6.h> 
    194 #endif /* HAVE_NETINET_ICMP6_H */ 
    195  
    196 #ifdef HAVE_NETINET6_ND6_H 
    197 #include <netinet6/nd6.h> 
    198 #endif /* HAVE_NETINET6_ND6_H */ 
    199  
    200 /* Some systems do not define UINT32_MAX */ 
    201 #ifndef UINT32_MAX 
    202 #define UINT32_MAX 0xFFFFFFFFU 
    203 #endif /* UINT32_MAX */ 
    204  
    205 #ifdef HAVE_LIBUTIL_H 
    206 #include <libutil.h> 
    207 #endif /* HAVE_LIBUTIL_H */ 
    208  
    209 #ifdef HAVE_GLIBC_BACKTRACE 
    210 #include <execinfo.h> 
    211 #endif /* HAVE_GLIBC_BACKTRACE */ 
    212  
    213 #ifdef BSDI_NRL 
    214  
    215 #ifdef HAVE_NETINET6_IN6_H 
    216 #include <netinet6/in6.h> 
    217 #endif /* HAVE_NETINET6_IN6_H */ 
    218  
    219 #ifdef NRL 
    220 #include <netinet6/in6.h> 
    221 #endif /* NRL */ 
    222  
    223 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL 
    224  
    225 #endif /* BSDI_NRL */ 
    226  
    227 /* Local includes: */ 
    228 #if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL)) 
    229 #define __attribute__(x) 
    230 #endif /* !__GNUC__ || VTYSH_EXTRACT_PL */ 
    231  
    232 #include "zassert.h" 
    233  
    234 #ifdef HAVE_BROKEN_CMSG_FIRSTHDR 
    235  
    236 /* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>; 
    237    please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */ 
    238  
    239 /* Check that msg_controllen is large enough. */ 
    240 #define ZCMSG_FIRSTHDR(mhdr) \ 
    241   (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) ? \ 
    242    CMSG_FIRSTHDR(mhdr) : (struct cmsghdr *)NULL) 
    243  
    244 #warning "CMSG_FIRSTHDR is broken on this platform, using a workaround" 
    245  
    246 #else /* HAVE_BROKEN_CMSG_FIRSTHDR */ 
    247 #define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M) 
    248 #endif /* HAVE_BROKEN_CMSG_FIRSTHDR */ 
    249  
    250 /* 
    251  * RFC 3542 defines several macros for using struct cmsghdr. 
    252  * Here, we define those that are not present 
    253  */ 
    254  
    255 /* 
    256  * Internal defines, for use only in this file. 
    257  * These are likely wrong on other than ILP32 machines, so warn. 
    258  */ 
    259 #ifndef _CMSG_DATA_ALIGN 
    260 #define _CMSG_DATA_ALIGN(n)           (((n) + 3) & ~3) 
    261 #endif /* _CMSG_DATA_ALIGN */ 
    262  
    263 #ifndef _CMSG_HDR_ALIGN 
    264 #define _CMSG_HDR_ALIGN(n)            (((n) + 3) & ~3) 
    265 #endif /* _CMSG_HDR_ALIGN */ 
    266  
    267 /* 
    268  * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that 
    269  * version. 
    270  */ 
    271 #ifndef CMSG_SPACE 
    272 #define CMSG_SPACE(l)       (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + \ 
    273                               _CMSG_HDR_ALIGN(l)) 
    274 #warning "assuming 4-byte alignment for CMSG_SPACE" 
    275 #endif /* CMSG_SPACE */ 
    276  
    277 #ifndef CMSG_LEN 
    278 #define CMSG_LEN(l)         (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l)) 
    279 #warning "assuming 4-byte alignment for CMSG_LEN" 
    280 #endif /* CMSG_LEN */ 
    281  
    282 /*  The definition of struct in_pktinfo is missing in old version of 
    283     GLIBC 2.1 (Redhat 6.1).  */ 
    284 #if defined (GNU_LINUX) && ! defined (HAVE_INPKTINFO) 
    285 struct in_pktinfo { 
    286   int ipi_ifindex; 
    287   struct in_addr ipi_spec_dst; 
    288   struct in_addr ipi_addr; 
    289 }; 
    290 #endif 
    291  
    292 /* 
    293  * OSPF Fragmentation / fragmented writes 
    294  * 
    295  * ospfd can support writing fragmented packets, for cases where 
    296  * kernel will not fragment IP_HDRINCL and/or multicast destined 
    297  * packets (ie TTBOMK all kernels, BSD, SunOS, Linux). However, 
    298  * SunOS, probably BSD too, clobber the user supplied IP ID and IP 
    299  * flags fields, hence user-space fragmentation will not work. 
    300  * Only Linux is known to leave IP header unmolested. 
    301  * Further, fragmentation really should be done the kernel, which already 
    302  * supports it, and which avoids nasty IP ID state problems. 
    303  * 
    304  * Fragmentation of OSPF packets can be required on networks with router 
    305  * with many many interfaces active in one area, or on networks with links 
    306  * with low MTUs. 
    307  */ 
    308 #ifdef GNU_LINUX 
    309 #define WANT_OSPF_WRITE_FRAGMENT 
    310 #endif 
    311  
    312 /* 
    313  * IP_HDRINCL / struct ip byte order 
    314  * 
    315  * Linux: network byte order 
    316  * *BSD: network, except for length and offset. (cf Stevens) 
    317  * SunOS: nominally as per BSD. but bug: network order on LE. 
    318  * OpenBSD: network byte order, apart from older versions which are as per 
    319  *          *BSD 
    320  */ 
    321 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\ 
    322    || (defined(__OpenBSD__) && (OpenBSD < 200311)) \ 
    323    || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN)) 
    324 #define HAVE_IP_HDRINCL_BSD_ORDER 
    325 #endif 
    326  
    327 /* MAX / MIN are not commonly defined, but useful */ 
    328 #ifndef MAX 
    329 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 
    330 #endif 
    331 #ifndef MIN 
    332 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 
    333 #endif 
    334  
    335 /* For old definition. */ 
    336 #ifndef IN6_ARE_ADDR_EQUAL 
    337 #define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL 
    338 #endif /* IN6_ARE_ADDR_EQUAL */ 
    339  
    340 /* Zebra message types. */ 
    341 #define ZEBRA_INTERFACE_ADD                1 
    342 #define ZEBRA_INTERFACE_DELETE             2 
    343 #define ZEBRA_INTERFACE_ADDRESS_ADD        3 
    344 #define ZEBRA_INTERFACE_ADDRESS_DELETE     4 
    345 #define ZEBRA_INTERFACE_UP                 5 
    346 #define ZEBRA_INTERFACE_DOWN               6 
    347 #define ZEBRA_IPV4_ROUTE_ADD               7 
    348 #define ZEBRA_IPV4_ROUTE_DELETE            8 
    349 #define ZEBRA_IPV6_ROUTE_ADD               9 
    350 #define ZEBRA_IPV6_ROUTE_DELETE           10 
    351 #define ZEBRA_REDISTRIBUTE_ADD            11 
    352 #define ZEBRA_REDISTRIBUTE_DELETE         12 
    353 #define ZEBRA_REDISTRIBUTE_DEFAULT_ADD    13 
    354 #define ZEBRA_REDISTRIBUTE_DEFAULT_DELETE 14 
    355 #define ZEBRA_IPV4_NEXTHOP_LOOKUP         15 
    356 #define ZEBRA_IPV6_NEXTHOP_LOOKUP         16 
    357 #define ZEBRA_IPV4_IMPORT_LOOKUP          17 
    358 #define ZEBRA_IPV6_IMPORT_LOOKUP          18 
    359 #define ZEBRA_INTERFACE_RENAME            19 
    360 #define ZEBRA_ROUTER_ID_ADD               20 
    361 #define ZEBRA_ROUTER_ID_DELETE            21 
    362 #define ZEBRA_ROUTER_ID_UPDATE            22 
    363 #define ZEBRA_MESSAGE_MAX                 23 
    364  
    365 /* Zebra route's types. */ 
    366 #define ZEBRA_ROUTE_SYSTEM               0 
    367 #define ZEBRA_ROUTE_KERNEL               1 
    368 #define ZEBRA_ROUTE_CONNECT              2 
    369 #define ZEBRA_ROUTE_STATIC               3 
    370 #define ZEBRA_ROUTE_RIP                  4 
    371 #define ZEBRA_ROUTE_RIPNG                5 
    372 #define ZEBRA_ROUTE_OSPF                 6 
    373 #define ZEBRA_ROUTE_OSPF6                7 
    374 #define ZEBRA_ROUTE_ISIS                 8 
    375 #define ZEBRA_ROUTE_BGP                  9 
    376 #define ZEBRA_ROUTE_HSLS                 10 
    377 #define ZEBRA_ROUTE_OLSR                 11 
    378 #define ZEBRA_ROUTE_MAX                  12 
    379  
    380 /* Zebra's family types. */ 
    381 #define ZEBRA_FAMILY_IPV4                1 
    382 #define ZEBRA_FAMILY_IPV6                2 
    383 #define ZEBRA_FAMILY_MAX                 3 
    384  
    385 /* Error codes of zebra. */ 
    386 #define ZEBRA_ERR_RTEXIST               -1 
    387 #define ZEBRA_ERR_RTUNREACH             -2 
    388 #define ZEBRA_ERR_EPERM                 -3 
    389 #define ZEBRA_ERR_RTNOEXIST             -4 
    390  
    391 /* Zebra message flags */ 
    392 #define ZEBRA_FLAG_INTERNAL           0x01 
    393 #define ZEBRA_FLAG_SELFROUTE          0x02 
    394 #define ZEBRA_FLAG_BLACKHOLE          0x04 
    395 #define ZEBRA_FLAG_IBGP               0x08 
    396 #define ZEBRA_FLAG_SELECTED           0x10 
    397 #define ZEBRA_FLAG_CHANGED            0x20 
    398 #define ZEBRA_FLAG_STATIC             0x40 
    399 #define ZEBRA_FLAG_REJECT             0x80 
    400  
    401 /* Zebra nexthop flags. */ 
    402 #define ZEBRA_NEXTHOP_IFINDEX            1 
    403 #define ZEBRA_NEXTHOP_IFNAME             2 
    404 #define ZEBRA_NEXTHOP_IPV4               3 
    405 #define ZEBRA_NEXTHOP_IPV4_IFINDEX       4 
    406 #define ZEBRA_NEXTHOP_IPV4_IFNAME        5 
    407 #define ZEBRA_NEXTHOP_IPV6               6 
    408 #define ZEBRA_NEXTHOP_IPV6_IFINDEX       7 
    409 #define ZEBRA_NEXTHOP_IPV6_IFNAME        8 
    410 #define ZEBRA_NEXTHOP_BLACKHOLE          9 
    411  
    412 #ifndef INADDR_LOOPBACK 
    413 #define INADDR_LOOPBACK 0x7f000001      /* Internet address 127.0.0.1.  */ 
    414 #endif 
    415  
    416 /* Address family numbers from RFC1700. */ 
    417 #define AFI_IP                    1 
    418 #define AFI_IP6                   2 
    419 #define AFI_MAX                   3 
    420  
    421 /* Subsequent Address Family Identifier. */ 
    422 #define SAFI_UNICAST              1 
    423 #define SAFI_MULTICAST            2 
    424 #define SAFI_UNICAST_MULTICAST    3 
    425 #define SAFI_MPLS_VPN             4 
    426 #define SAFI_MAX                  5 
    427  
    428 /* Filter direction.  */ 
    429 #define FILTER_IN                 0 
    430 #define FILTER_OUT                1 
    431 #define FILTER_MAX                2 
    432  
    433 /* Default Administrative Distance of each protocol. */ 
    434 #define ZEBRA_KERNEL_DISTANCE_DEFAULT      0 
    435 #define ZEBRA_CONNECT_DISTANCE_DEFAULT     0 
    436 #define ZEBRA_STATIC_DISTANCE_DEFAULT      1 
    437 #define ZEBRA_RIP_DISTANCE_DEFAULT       120 
    438 #define ZEBRA_RIPNG_DISTANCE_DEFAULT     120 
    439 #define ZEBRA_OSPF_DISTANCE_DEFAULT      110 
    440 #define ZEBRA_OSPF6_DISTANCE_DEFAULT     110 
    441 #define ZEBRA_ISIS_DISTANCE_DEFAULT      115 
    442 #define ZEBRA_IBGP_DISTANCE_DEFAULT      200 
    443 #define ZEBRA_EBGP_DISTANCE_DEFAULT       20 
    444  
    445 /* Flag manipulation macros. */ 
    446 #define CHECK_FLAG(V,F)      ((V) & (F)) 
    447 #define SET_FLAG(V,F)        (V) = (V) | (F) 
    448 #define UNSET_FLAG(V,F)      (V) = (V) & ~(F) 
    449  
    450 /* AFI and SAFI type. */ 
    451 typedef u_int16_t afi_t; 
    452 typedef u_int8_t safi_t; 
    453  
    454 /* Zebra types. */ 
    455 typedef u_int16_t zebra_size_t; 
    456 typedef u_int8_t zebra_command_t; 
    457  
    458 /* FIFO -- first in first out structure and macros.  */ 
    459 struct fifo { 
    460   struct fifo *next; 
    461   struct fifo *prev; 
    462 }; 
    463  
    464 #define FIFO_INIT(F)                                  \ 
    465   do {                                                \ 
    466     struct fifo *Xfifo = (struct fifo *)(F);          \ 
    467     Xfifo->next = Xfifo->prev = Xfifo;                \ 
    468   } while (0) 
    469  
    470 #define FIFO_ADD(F,N)                                 \ 
    471   do {                                                \ 
    472     struct fifo *Xfifo = (struct fifo *)(F);          \ 
    473     struct fifo *Xnode = (struct fifo *)(N);          \ 
    474     Xnode->next = Xfifo;                              \ 
    475     Xnode->prev = Xfifo->prev;                        \ 
    476     Xfifo->prev = Xfifo->prev->next = Xnode;          \ 
    477   } while (0) 
    478  
    479 #define FIFO_DEL(N)                                   \ 
    480   do {                                                \ 
    481     struct fifo *Xnode = (struct fifo *)(N);          \ 
    482     Xnode->prev->next = Xnode->next;                  \ 
    483     Xnode->next->prev = Xnode->prev;                  \ 
    484   } while (0) 
    485  
    486 #define FIFO_HEAD(F)                                  \ 
    487   ((((struct fifo *)(F))->next == (struct fifo *)(F)) \ 
    488   ? NULL : (F)->next) 
    489  
    490 #define FIFO_EMPTY(F)                                 \ 
    491   (((struct fifo *)(F))->next == (struct fifo *)(F)) 
    492  
    493 #define FIFO_TOP(F)                                   \ 
    494   (FIFO_EMPTY(F) ? NULL : ((struct fifo *)(F))->next) 
    495  
    496 #endif /* _ZEBRA_H */ 
    497  
    498 /* 
    499  * Local Variables: 
    500  * c-basic-offset: 2 
    501  * indent-tabs-mode: nil 
    502  * End: 
    503  */ 
  • lib/quagga/src/quagga.c

    a b  
     1/* 
     2 * OLSRd Quagga plugin 
     3 * 
     4 * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de> 
     5 * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     6 * 
     7 * This program is free software; you can redistribute it and/or modify 
     8 * it under the terms of the GNU General Public License version 2 as 
     9 * published by the Free Software Foundation or - at your option - under 
     10 * the terms of the GNU General Public Licence version 2 but can be 
     11 * linked to any BSD-Licenced Software with public available sourcecode 
     12 * 
     13 */ 
    114 
    2 /*************************************************************************** 
    3  projekt              : olsrd-quagga 
    4  file                 : quagga.c 
    5  usage                : communication with the zebra-daemon 
    6  copyright            : (C) 2006 by Immo 'FaUl' Wehrenberg 
    7  e-mail               : immo@chaostreff-dortmund.de 
    8  ***************************************************************************/ 
    9  
    10 /*************************************************************************** 
    11  *                                                                         * 
    12  *   This program is free software; you can redistribute it and/or modify  * 
    13  *   it under the terms of the GNU General Public License version 2 as     * 
    14  *   published by the Free Software Foundation.                            * 
    15  *                                                                         * 
    16  ***************************************************************************/ 
     15/* ------------------------------------------------------------------------- 
     16 * File               : quagga.c 
     17 * Description        : functions to interface to the zebra daemon 
     18 * ------------------------------------------------------------------------- */ 
    1719 
    18 #ifdef MY_DEBUG 
    19 #include <stdio.h> 
    20 #endif 
    2120 
    2221#define HAVE_SOCKLEN_T 
    2322 
     23#include "quagga.h" 
     24#include "olsr.h" /* olsr_exit 
     25                     olsr_malloc */ 
     26#include "log.h" /* olsr_syslog */ 
     27 
    2428#include <stdint.h> 
     29#include <stdlib.h> 
     30#include <unistd.h> 
     31#include <string.h> 
     32#include <fcntl.h> 
     33#include <errno.h> 
    2534#include <sys/types.h> 
    2635#include <sys/socket.h> 
    2736#include <netinet/in.h> 
    28 #include <fcntl.h> 
    29 #include <unistd.h> 
    30  
    31 #include "quagga.h" 
    32 #include "olsr.h" 
    33 #include "log.h" 
    34 #include "defs.h" 
    35 #include "routing_table.h" 
    36  
     37#include <arpa/inet.h> 
    3738#ifdef USE_UNIX_DOMAIN_SOCKET 
    3839#include <sys/un.h> 
    39 #define ZEBRA_SOCKET "/var/run/quagga/zserv.api" 
    4040#endif 
    4141 
    42 #define ZEBRA_IPV4_ROUTE_ADD            7 
    43 #define ZEBRA_IPV4_ROUTE_DELETE         8 
    44 #define ZEBRA_REDISTRIBUTE_ADD          11 
    45 #define ZEBRA_REDISTRIBUTE_DELETE       12 
    46 #define ZEBRA_MESSAGE_MAX               23 
    47  
    48 #define ZEBRA_ROUTE_OLSR                11 
    49 #define ZEBRA_ROUTE_MAX                 12 
    50  
    51 #define ZEBRA_FLAG_SELECTED             0x10 
    52  
    53 #define ZEBRA_NEXTHOP_IPV4              3 
    54 #define ZEBRA_NEXTHOP_IPV4_IFINDEX      4 
    55  
    56 #define ZAPI_MESSAGE_NEXTHOP  0x01 
    57 #define ZAPI_MESSAGE_IFINDEX  0x02 
    58 #define ZAPI_MESSAGE_DISTANCE 0x04 
    59 #define ZAPI_MESSAGE_METRIC   0x08 
    60  
    61 #define BUFSIZE 1024 
    62  
    63 #define STATUS_CONNECTED 1 
    64 #define OPTION_EXPORT 1 
    6542 
     43/* prototypes intern */ 
    6644static struct { 
    67   char status;                         // internal status 
    68   char options;                        // internal options 
    69   int sock;                            // Socket to zebra... 
     45  char status; // internal status 
     46  char options; // internal options 
     47  int sock; // Socket to zebra... 
    7048  char redistribute[ZEBRA_ROUTE_MAX]; 
    7149  char distance; 
    7250  char flags; 
    73   struct ipv4_route *v4_rt;            // routes currently exportet to zebra 
     51  struct zebra_route *v4_rt; // routes currently exportet to zebra 
    7452} zebra; 
    7553 
    76 /* prototypes intern */ 
    77 static unsigned char *try_read(ssize_t *); 
    78 static unsigned char *zebra_route_packet(struct ipv4_route r, ssize_t *); 
    79 static int parse_interface_add(unsigned char *, size_t); 
    80 static int parse_interface_delete(unsigned char *, size_t); 
    81 static int parse_interface_up(unsigned char *, size_t); 
    82 static int parse_interface_down(unsigned char *, size_t); 
    83 static int parse_interface_address_add(unsigned char *, size_t); 
    84 static int parse_interface_address_delete(unsigned char *, size_t); 
    85 static int parse_ipv4_route(unsigned char *, size_t, struct ipv4_route *); 
    86 static int ipv4_route_add(unsigned char *, size_t); 
    87 static int ipv4_route_delete(unsigned char *, size_t); 
    88 static int parse_ipv6_route_add(unsigned char *, size_t); 
    89 static void zebra_reconnect(void); 
    90 static void zebra_connect(void); 
    91  
    92 static void free_ipv4_route(struct ipv4_route); 
    93  
    94 /* 
    95 static void update_olsr_zebra_routes (struct ipv4_route*, struct ipv4_route*); 
    96 static struct ipv4_route *zebra_create_ipv4_route_table_entry (uint32_t, 
    97                                                                uint32_t, 
    98                                                                uint32_t); 
    99 static struct ipv4_route *zebra_create_ipv4_route_table (void); 
    100 static void zebra_free_ipv4_route_table (struct ipv4_route*); 
    101 */ 
    102  
    103 /*static uint8_t masktoprefixlen (uint32_t);*/ 
    104  
    105 #ifdef MY_DEBUG 
    106 static void 
    107 dump_ipv4_route(struct ipv4_route r, char *c) 
    108 { 
    109   int i = 0, x = 0; 
    110  
    111   puts(c); 
    112   printf("type: %d\n", r.type); 
    113   puts("flags:"); 
    114   printf("  Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no"); 
    115   printf("  Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no"); 
    116   printf("  Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no"); 
    117   printf("  IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no"); 
    118   printf("  Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no"); 
    119   printf("  Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no"); 
    120   printf("  static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no"); 
    121   printf("  reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no"); 
    122   puts("message:"); 
    123   printf("  nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no"); 
    124   printf("  ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no"); 
    125   printf("  distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no"); 
    126   printf("  metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no"); 
    127   printf("Prefixlen: %d\n", r.prefixlen); 
    128   printf("Prefix: %d", (unsigned char)r.prefix); 
    129   c = (char *)&r.prefix; 
    130   while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0))) 
    131     printf(".%d", (unsigned char)*(c + i)); 
    132   while (i++ < 4) 
    133     printf(".0"); 
    134   puts(""); 
    135   i = 0; 
    136   if (r.message & ZAPI_MESSAGE_NEXTHOP) { 
    137     printf("nexthop-count: %d\n", r.nh_count); 
    138     while (i++ < r.nh_count) { 
    139       if (r.nexthops[i].type == ZEBRA_NEXTHOP_IPV4) { 
    140         c = (unsigned char *)&r.nexthops[i].payload.v4; 
    141         printf("Nexthop %d: %d", i, (unsigned char)*c); 
    142         while (++x < 4) { 
    143           printf(".%d", (unsigned char)c[x]); 
    144         } 
    145         puts(""); 
    146       } 
    147     } 
    148     i = 0; 
    149   } 
    150   if (r.message & ZAPI_MESSAGE_IFINDEX) { 
    151  
    152     printf("index-number: %d\n", r.ind_num); 
    153     while (i++ < r.ind_num) 
    154       printf("Index: %d: %d\n", i, r.index[i]); 
    155     i = 0; 
    156     if (r.message & ZAPI_MESSAGE_DISTANCE) 
    157       printf("Distance: %d\n", r.distance); 
    158     if (r.message & ZAPI_MESSAGE_METRIC) 
    159       printf("Metric: %d\n", r.metric); 
    160     puts("\n"); 
    161   } 
    162 } 
     54static void *my_realloc (void *, size_t, const char *); 
     55static void zebra_connect (void); 
     56static unsigned char *try_read (ssize_t *); 
     57static int zebra_send_command (unsigned char *); 
     58static unsigned char* zebra_route_packet (uint16_t, struct zebra_route *); 
     59static unsigned char *zebra_redistribute_packet (unsigned char, unsigned char); 
     60static struct zebra_route *zebra_parse_route (unsigned char *); 
     61#if 0 
     62static void zebra_reconnect (void); 
    16363#endif 
     64static void free_ipv4_route (struct zebra_route *); 
     65 
    16466 
    165 void * 
    166 my_realloc(void *buf, size_t s, const char *c) 
    167 { 
    168   buf = realloc(buf, s); 
     67static void *my_realloc (void *buf, size_t s, const char *c) { 
     68  buf = realloc (buf, s); 
    16969  if (!buf) { 
    170     OLSR_PRINTF(1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno)); 
     70    OLSR_PRINTF (1, "(QUAGGA) OUT OF MEMORY: %s\n", strerror(errno)); 
    17171    olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n"); 
    17272    olsr_exit(c, EXIT_FAILURE); 
    17373  } 
    17474  return buf; 
    17575} 
    17676 
    177 void 
    178 init_zebra(void) 
    179 { 
     77 
     78void init_zebra (void) { 
    18079  zebra_connect(); 
    181   if (!(zebra.status & STATUS_CONNECTED)) 
    182     olsr_exit("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?", EXIT_FAILURE); 
     80  if (!(zebra.status&STATUS_CONNECTED)) 
     81    olsr_exit ("(QUAGGA) AIIIII, could not connect to zebra! is zebra running?", 
     82               EXIT_FAILURE); 
    18383} 
    18484 
    185 void 
    186 zebra_cleanup(void) 
    187 { 
     85 
     86void zebra_cleanup (void) { 
    18887  int i; 
    18988  struct rt_entry *tmp; 
    19089 
    19190  if (zebra.options & OPTION_EXPORT) { 
    19291    OLSR_FOR_ALL_RT_ENTRIES(tmp) { 
    193       zebra_del_olsr_v4_route(tmp); 
    194     } 
    195     OLSR_FOR_ALL_RT_ENTRIES_END(tmp); 
     92      zebra_del_route(tmp); 
     93    } OLSR_FOR_ALL_RT_ENTRIES_END(tmp); 
    19694  } 
    19795 
    19896  for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
    199     if (zebra.redistribute[i]) 
    200       zebra_disable_redistribute(i + 1); 
     97    if (zebra.redistribute[i]) zebra_disable_redistribute(i); 
    20198} 
    20299 
    203 static void 
    204 zebra_reconnect(void) 
    205 { 
     100 
     101#if 0 
     102static void zebra_reconnect (void) { 
    206103  struct rt_entry *tmp; 
    207104  int i; 
    208105 
    209106  zebra_connect(); 
    210   if (!(zebra.status & STATUS_CONNECTED)) 
    211     return;                     // try again next time 
     107  if (!(zebra.status & STATUS_CONNECTED)) return; // try again next time 
    212108 
    213109  if (zebra.options & OPTION_EXPORT) { 
    214110    OLSR_FOR_ALL_RT_ENTRIES(tmp) { 
    215       zebra_add_olsr_v4_route(tmp); 
    216     } 
    217     OLSR_FOR_ALL_RT_ENTRIES_END(tmp); 
     111      zebra_add_route (tmp); 
     112    } OLSR_FOR_ALL_RT_ENTRIES_END(tmp); 
    218113  } 
    219114 
    220115  for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
    221     if (zebra.redistribute[i]) 
    222       zebra_redistribute(i + 1); 
     116    if (zebra.redistribute[i]) zebra_redistribute(i + 1); 
    223117  /* Zebra sends us all routes of type it knows after 
    224118     zebra_redistribute(type) */ 
    225119} 
     120#endif 
     121 
    226122 
    227123/* Connect to the zebra-daemon, returns a socket */ 
    228 static void 
    229 zebra_connect(void) 
    230 { 
     124static void zebra_connect (void) { 
    231125 
    232126  int ret; 
    233127 
    234128#ifndef USE_UNIX_DOMAIN_SOCKET 
    235129  struct sockaddr_in i; 
    236   if (close(zebra.sock) < 0) 
    237     olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE); 
     130  if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE); 
     131 
    238132 
    239   zebra.sock = socket(AF_INET, SOCK_STREAM, 0); 
     133  zebra.sock = socket (AF_INET,SOCK_STREAM, 0); 
    240134#else 
    241135  struct sockaddr_un i; 
    242   if (close(zebra.sock) < 0) 
    243     olsr_exit("(QUAGGA) Could not close socket!", EXIT_FAILURE); 
     136  if (close (zebra.sock) < 0) olsr_exit ("(QUAGGA) Could not close socket!", EXIT_FAILURE); 
    244137 
    245   zebra.sock = socket(AF_UNIX, SOCK_STREAM, 0); 
     138  zebra.sock = socket (AF_UNIX,SOCK_STREAM, 0); 
    246139#endif 
    247140 
    248   if (zebra.sock < 0) 
     141  if (zebra.sock <0 ) 
    249142    olsr_exit("(QUAGGA) Could not create socket!", EXIT_FAILURE); 
    250143 
    251   memset(&i, 0, sizeof i); 
     144  memset (&i, 0, sizeof i); 
    252145#ifndef USE_UNIX_DOMAIN_SOCKET 
    253146  i.sin_family = AF_INET; 
    254   i.sin_port = htons(ZEBRA_PORT); 
    255   i.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
     147  i.sin_port = htons (ZEBRA_PORT); 
     148  i.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 
    256149#else 
    257150  i.sun_family = AF_UNIX; 
    258   strscpy(i.sun_path, ZEBRA_SOCKET, sizeof(i.sun_path)); 
     151  strcpy (i.sun_path, ZEBRA_SOCKET); 
    259152#endif 
    260153 
    261   ret = connect(zebra.sock, (struct sockaddr *)&i, sizeof i); 
    262   if (ret < 0) 
    263     zebra.status &= ~STATUS_CONNECTED; 
    264   else 
    265     zebra.status |= STATUS_CONNECTED; 
     154  ret = connect (zebra.sock, (struct sockaddr *)&i, sizeof i); 
     155  if  (ret < 0) zebra.status &= ~STATUS_CONNECTED; 
     156  else zebra.status |= STATUS_CONNECTED; 
    266157} 
    267158 
     159 
    268160/* Sends a command to zebra, command is 
    269161   the command defined in zebra.h, options is the packet-payload, 
    270162   optlen the length, of the payload */ 
    271 unsigned char 
    272 zebra_send_command(unsigned char command, unsigned char *options, int optlen) 
    273 { 
     163static int zebra_send_command (unsigned char *options) { 
    274164 
    275   char *p, *pnt; 
     165  unsigned char *pnt; 
    276166  uint16_t len; 
    277167  int ret; 
    278168 
    279 #ifdef ZEBRA_HEADER_MARKER 
    280   uint16_t cmd; 
    281   uint16_t length = optlen + 6;        /* length of option + command + packet_length + 
    282                                           marker + zserv-version */ 
    283 #else 
    284   uint16_t length = optlen + 3;        // length of option + command + packet_length 
    285 #endif 
    286  
    287   if (!(zebra.status & STATUS_CONNECTED)) 
    288     return 0; 
    289  
    290   p = olsr_malloc(length, "zebra_send_command"); 
    291   pnt = p; 
    292  
    293   len = htons(length); 
     169  if (!(zebra.status & STATUS_CONNECTED)) return 0; 
    294170 
    295   memcpy(p, &len, 2); 
     171  pnt = options; 
     172  memcpy (&len, pnt, 2); 
    296173 
    297 #ifdef ZEBRA_HEADER_MARKER 
    298   p[2] = ZEBRA_HEADER_MARKER; 
    299   p[3] = ZSERV_VERSION; 
    300   cmd = htons(command); 
    301   memcpy(p + 4, &cmd, 2); 
    302 #else 
    303   p[2] = command; 
    304 #endif 
    305   memcpy(p + length - optlen, options, optlen); 
    306  
    307   errno = 0; 
     174  len = ntohs(len); 
    308175 
    309176  do { 
    310     ret = write(zebra.sock, p, length); 
     177    ret = write (zebra.sock, pnt, len); 
    311178    if (ret < 0) { 
    312       if (errno == EINTR) { 
    313         errno = 0; 
    314         continue; 
    315       } else { 
    316         olsr_printf(1, "(QUAGGA) Disconnected from zebra\n"); 
    317         zebra.status &= ~STATUS_CONNECTED; 
    318         free(pnt); 
    319         return -1; 
     179      if ((errno == EINTR) || (errno == EAGAIN)) { 
     180        errno = 0; 
     181        ret = 0; 
     182        continue; 
     183      } 
     184      else { 
     185        OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n"); 
     186        zebra.status &= ~STATUS_CONNECTED; 
     187        free (options); 
     188        return -1; 
    320189      } 
    321190    } 
    322     p = p + ret; 
    323   } 
    324   while ((length -= ret)); 
    325   free(pnt); 
     191    pnt = pnt+ret; 
     192  } while ((len -= ret)); 
     193  free (options); 
    326194  return 0; 
    327195} 
    328196 
     197 
    329198/* Creates a Route-Packet-Payload, needs address, netmask, nexthop, 
    330199   distance, and a pointer of an size_t */ 
    331 static unsigned char * 
    332 zebra_route_packet(struct ipv4_route r, ssize_t * optlen) 
    333 { 
     200static unsigned char* zebra_route_packet (uint16_t cmd, struct zebra_route *r) { 
    334201 
    335202  int count; 
     203  uint8_t len; 
     204  uint16_t size; 
     205  uint32_t ind, metric; 
    336206 
    337207  unsigned char *cmdopt, *t; 
    338   *optlen = 4;                  // first: type, flags, message, prefixlen 
    339   *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0);       // + prefix 
    340   if (r.message & ZAPI_MESSAGE_NEXTHOP) { 
    341     if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) { 
    342       *optlen += (sizeof r.nexthops->payload.v4 + sizeof r.nexthops->type) * r.nh_count + 1; 
    343     } else if (r.nexthops->type == 0) 
    344       *optlen += 5; 
    345   } 
    346   if (r.message & ZAPI_MESSAGE_IFINDEX) 
    347     *optlen += r.ind_num * sizeof *r.index + 1; 
    348   if (r.message & ZAPI_MESSAGE_DISTANCE) 
    349     (*optlen)++; 
    350   if (r.message & ZAPI_MESSAGE_METRIC) 
    351     *optlen += sizeof r.metric; 
    352  
    353   cmdopt = olsr_malloc(*optlen, "zebra add_v4_route"); 
    354  
    355   t = cmdopt; 
    356   *t++ = r.type; 
    357   *t++ = r.flags; 
    358   *t++ = r.message; 
    359   *t++ = r.prefixlen; 
    360   for (count = 0; count < r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); count++) { 
    361     *t++ = *((char *)&r.prefix + count);        /* this is so sick!! */ 
    362   } 
    363  
    364   if (r.message & ZAPI_MESSAGE_NEXTHOP) { 
    365     *t++ = r.nh_count; 
    366     *t++ = r.nexthops->type; 
    367     if (r.nexthops->type == ZEBRA_NEXTHOP_IPV4 || r.nexthops->type == ZEBRA_NEXTHOP_IPV4_IFINDEX) { 
    368       for (count = 0; count != r.nh_count; count++) { 
    369         memcpy(t, &r.nexthops[count].payload.v4, sizeof r.nexthops->payload.v4); 
    370         t += sizeof r.nexthops->payload.v4; 
    371       } 
    372     } else if (r.nexthops->type == 0) { 
    373       *t++ = 0; 
    374       *t++ = 0; 
    375       *t++ = 0; 
    376     } 
    377   } 
    378   if (r.message & ZAPI_MESSAGE_IFINDEX) { 
    379     *t++ = r.ind_num; 
    380     memcpy(t, r.index, sizeof *r.index * r.ind_num); 
    381     t += sizeof r.index * r.ind_num; 
    382   } 
    383   if (r.message & ZAPI_MESSAGE_DISTANCE) 
    384     *t++ = r.distance; 
    385   if (r.message & ZAPI_MESSAGE_METRIC) { 
    386     memcpy(t, &r.metric, sizeof r.metric); 
    387     t += sizeof r.metric; 
    388   } 
    389   return cmdopt; 
    390 } 
    391208 
    392 /* adds a route to zebra-daemon */ 
    393 int 
    394 zebra_add_v4_route(const struct ipv4_route r) 
    395 { 
    396  
    397   unsigned char *cmdopt; 
    398   ssize_t optlen; 
    399   int retval; 
     209  cmdopt = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra add_v4_route"); 
    400210 
    401   cmdopt = zebra_route_packet(r, &optlen); 
     211  t = &cmdopt[2]; 
     212  *t++ = cmd; 
     213  *t++ = r->type; 
     214  *t++ = r->flags; 
     215  *t++ = r->message; 
     216  *t++ = r->prefixlen; 
     217  len = (r->prefixlen + 7) / 8; 
     218  memcpy (t, &r->prefix.v4.s_addr, len); 
     219  t = t + len; 
    402220 
    403   retval = zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen); 
    404   free(cmdopt); 
    405   return retval; 
     221  if (r->message & ZAPI_MESSAGE_NEXTHOP) { 
     222    *t++ = r->nexthop_num + r->ifindex_num; 
     223     
     224      for (count = 0; count < r->nexthop_num; count++) 
     225        { 
     226          *t++ = ZEBRA_NEXTHOP_IPV4; 
     227          memcpy (t, &r->nexthop[count].v4.s_addr, 
     228                  sizeof r->nexthop[count].v4.s_addr); 
     229          t += sizeof r->nexthop[count].v4.s_addr; 
     230        } 
     231      for (count = 0; count < r->ifindex_num; count++) 
     232        { 
     233          *t++ = ZEBRA_NEXTHOP_IFINDEX; 
     234          ind = htonl(r->ifindex[count]); 
     235          memcpy (t, &ind, sizeof ind); 
     236          t += sizeof ind; 
     237        } 
     238    } 
     239  if ((r->message & ZAPI_MESSAGE_DISTANCE) > 0) 
     240    *t++ = r->distance; 
     241  if ((r->message & ZAPI_MESSAGE_METRIC) > 0) 
     242    { 
     243      metric = htonl (r->metric); 
     244      memcpy (t, &metric, sizeof metric); 
     245      t += sizeof metric; 
     246    } 
     247  size = htons (t - cmdopt); 
     248  memcpy (cmdopt, &size, 2); 
    406249 
     250  return cmdopt; 
    407251} 
    408252 
    409 /* deletes a route from the zebra-daemon */ 
    410 int 
    411 zebra_delete_v4_route(struct ipv4_route r) 
    412 { 
    413  
    414   unsigned char *cmdopt; 
    415   ssize_t optlen; 
    416   int retval; 
    417  
    418   cmdopt = zebra_route_packet(r, &optlen); 
    419  
    420   retval = zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen); 
    421   free(cmdopt); 
    422  
    423   return retval; 
    424  
    425 } 
    426253 
    427254/* Check wether there is data from zebra aviable */ 
    428 void 
    429 zebra_check(void *foo __attribute__ ((unused))) 
    430 { 
     255void zebra_parse (void* foo __attribute__((unused))) { 
    431256  unsigned char *data, *f; 
    432   ssize_t len, ret; 
     257  unsigned char command; 
     258  uint16_t length; 
     259  ssize_t len; 
     260  struct zebra_route *route; 
    433261 
    434262  if (!(zebra.status & STATUS_CONNECTED)) { 
    435     zebra_reconnect(); 
     263//    zebra_reconnect(); 
    436264    return; 
    437265  } 
    438   data = try_read(&len); 
     266  data = try_read (&len); 
    439267  if (data) { 
    440268    f = data; 
    441269    do { 
    442       ret = zebra_parse_packet(f, len); 
    443       if (!ret)                 // something wired happened 
    444         olsr_exit("(QUAGGA) Zero message length??? ", EXIT_FAILURE); 
    445       f += ret; 
    446     } 
    447     while ((f - data) < len); 
    448     free(data); 
     270      memcpy (&length, f, sizeof length); 
     271      length = ntohs (length); 
     272      if (!length) // something wired happened 
     273        olsr_exit ("(QUAGGA) Zero message length??? ", EXIT_FAILURE); 
     274      command = f[2]; 
     275      switch (command) { 
     276        case ZEBRA_IPV4_ROUTE_ADD: 
     277          route = zebra_parse_route(f); 
     278          ip_prefix_list_add(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen); 
     279          free_ipv4_route (route); 
     280          free (route); 
     281          break; 
     282        case ZEBRA_IPV4_ROUTE_DELETE: 
     283          route = zebra_parse_route(f); 
     284          ip_prefix_list_remove(&olsr_cnf->hna_entries, &route->prefix, route->prefixlen); 
     285          free_ipv4_route (route); 
     286          free (route); 
     287          break; 
     288        default: 
     289          break; 
     290      } 
     291      f += length; 
     292    } while ((f - data) < len); 
     293    free (data); 
    449294  } 
    450295} 
    451296 
     297 
    452298// tries to read a packet from zebra_socket 
    453299// if there is something to read - make sure to read whole packages 
    454 static unsigned char * 
    455 try_read(ssize_t * len) 
    456 { 
    457   unsigned char *buf = NULL; 
    458   ssize_t ret = 0, bsize = 0; 
    459   uint16_t length = 0, l = 0; 
    460   int sockstate; 
    461  
    462   *len = 0; 
    463  
    464   sockstate = fcntl(zebra.sock, F_GETFL, 0); 
    465   fcntl(zebra.sock, F_SETFL, sockstate | O_NONBLOCK); 
     300static unsigned char *try_read (ssize_t *size) { 
     301  unsigned char *buf; 
     302  ssize_t bytes, bufsize; 
     303  uint16_t length, offset; 
     304  int sockstatus; 
     305 
     306  /* initialize variables */ 
     307  buf = NULL; 
     308  offset = 0; 
     309  *size = 0; 
     310  bufsize = 0; 
     311 
     312  /* save socket status and set non-blocking for read */ 
     313  sockstatus = fcntl (zebra.sock, F_GETFL); 
     314  fcntl (zebra.sock, F_SETFL, sockstatus|O_NONBLOCK); 
    466315 
     316  /* read whole packages */ 
    467317  do { 
    468     if (*len == bsize) { 
    469       bsize += BUFSIZE; 
    470       buf = my_realloc(buf, bsize, "Zebra try_read"); 
     318 
     319  /* (re)allocate buffer */ 
     320    if (*size == bufsize) { 
     321      bufsize += BUFSIZE; 
     322      buf = my_realloc (buf, bufsize, "Zebra try_read"); 
    471323    } 
    472     ret = read(zebra.sock, buf + l, bsize - l); 
    473     if (!ret) {                 // nothing more to read, packet is broken, discard! 
    474       free(buf); 
     324 
     325  /* read from socket */ 
     326    bytes = read (zebra.sock, buf + *size, bufsize - *size); 
     327  /* handle broken packet */ 
     328    if (!bytes) { 
     329      free (buf); 
    475330      return NULL; 
    476331    } 
    477  
    478     if (ret < 0) { 
    479       if (errno != EAGAIN) {    // oops - we got disconnected 
    480         olsr_printf(1, "(QUAGGA) Disconnected from zebra\n"); 
     332  /* handle no data available */ 
     333    if (bytes < 0) { 
     334  /* handle disconnect */ 
     335      if (errno != EAGAIN) { // oops - we got disconnected 
     336        OLSR_PRINTF (1, "(QUAGGA) Disconnected from zebra\n"); 
    481337        zebra.status &= ~STATUS_CONNECTED; 
    482338      } 
    483       free(buf); 
     339      free (buf); 
    484340      return NULL; 
    485341    } 
    486342 
    487     *len += ret; 
    488     while ((*len - l) > length) { 
    489       l += length; 
    490       memcpy(&length, buf + l, 2); 
    491       length = ntohs(length); 
    492     } 
    493     if (((*len) - l) == length) 
    494       break;                    // GOT FULL PACKAGE!! 
    495     if (*len < l) { 
    496       fcntl(zebra.sock, F_SETFL, sockstate); 
    497       continue; 
    498     } 
    499   } 
    500   while (1); 
    501  
    502   fcntl(zebra.sock, F_SETFL, sockstate); 
    503   return buf; 
    504 } 
    505  
    506 /* Parse a packet recived from zebra */ 
    507 int 
    508 zebra_parse_packet(unsigned char *packet, ssize_t maxlen) 
    509 { 
    510  
    511   uint16_t command; 
    512   int skip; 
    513  
    514   /* Array of functions */ 
    515   int (*foo[ZEBRA_MESSAGE_MAX]) (unsigned char *, size_t) = { 
    516   parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up, 
    517       parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add}; 
    518  
    519   uint16_t length; 
    520   int ret; 
    521  
    522 #ifdef MY_DEBUG 
    523   puts("DEBUG: zebra_parse_packet"); 
    524 #endif 
    525  
    526   memcpy(&length, packet, 2); 
    527   length = ntohs(length); 
    528  
    529   if (maxlen < length) { 
    530     olsr_printf(1, "(QUAGGA) maxlen = %lu, packet_length = %d\n", (unsigned long)maxlen, length); 
    531     olsr_exit("(QUAGGA) programmer is an idiot", EXIT_FAILURE); 
    532   } 
    533 #ifdef ZEBRA_HEADER_MARKER 
    534   if (packet[2] == 255) {       // found header marker!! 
    535     //packet[3] == ZSERV_VERSION: FIXME: HANDLE THIS! 
    536     memcpy(&command, packet + 4, sizeof command);       // two bytes command now! 
    537     command = ntohs(command) - 1; 
    538     skip = 6; 
    539   } 
    540 #else 
    541   command = packet[2] - 1; 
    542   skip = 3; 
    543 #endif 
    544  
    545   if (command < ZEBRA_MESSAGE_MAX && foo[command]) { 
    546     if (!(ret = foo[command] (packet + skip, length - skip))) 
    547       return length; 
    548     else 
    549       olsr_printf(1, "(QUAGGA) Parse error: %d\n", ret); 
    550   } else 
    551     olsr_printf(1, "(QUAGGA) Unknown packet type: %d\n", packet[2]); 
    552  
    553   olsr_printf(1, "(Quagga) RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE"); 
    554  
    555   return length; 
    556 } 
    557  
    558 static int 
    559 parse_interface_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    560 { 
    561   //todo 
    562   return 0; 
    563 } 
    564  
    565 static int 
    566 parse_interface_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    567 { 
    568   //todo 
    569   return 0; 
    570 } 
    571  
    572 static int 
    573 parse_interface_address_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    574 { 
    575  
    576   //todo 
    577   return 0; 
    578 } 
    579  
    580 static int 
    581 parse_interface_up(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    582 { 
     343    *size += bytes; 
    583344 
    584   //todo 
    585   return 0; 
    586 } 
     345  /* detect zebra packet fragmentation */ 
     346    do { 
     347      memcpy (&length, buf + offset, sizeof length); 
     348      length = ntohs (length); 
     349      offset += length; 
     350    } while (*size >= (ssize_t) (offset + sizeof length)); 
     351  /* set blocking socket on fragmented packet */ 
     352    if (*size != offset) 
     353      fcntl (zebra.sock, F_SETFL, sockstatus); 
     354  
     355  } while (*size != offset); 
    587356 
    588 static int 
    589 parse_interface_down(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    590 { 
     357  /* restore socket status */ 
     358  fcntl (zebra.sock, F_SETFL, sockstatus); 
    591359 
    592   //todo 
    593   return 0; 
     360  return buf; 
    594361} 
    595362 
    596 static int 
    597 parse_interface_address_delete(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    598 { 
    599   //todo 
    600   return 0; 
    601 } 
    602363 
    603364/* Parse an ipv4-route-packet recived from zebra 
    604365 */ 
    605 static int 
    606 parse_ipv4_route(unsigned char *opt, size_t len, struct ipv4_route *r) 
    607 { 
     366static struct zebra_route *zebra_parse_route (unsigned char *opt) { 
     367   
     368  struct zebra_route *r; 
    608369  int c; 
    609  
    610   if (len < 4) 
    611     return -1; 
    612  
    613   r->type = *opt++; 
    614   r->flags = *opt++; 
    615   r->message = *opt++; 
    616   r->prefixlen = *opt++; 
    617   len -= 4; 
    618   r->prefix = 0; 
    619  
    620   if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0)) 
    621     return -1; 
    622  
    623   memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0)); 
    624   opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0); 
     370  size_t size; 
     371  uint16_t length; 
     372  unsigned char *pnt; 
     373       
     374  memcpy (&length, opt, sizeof length); 
     375  length = ntohs (length); 
     376   
     377  r = olsr_malloc (sizeof *r , "zebra_parse_route"); 
     378  pnt = &opt[3]; 
     379  r->type = *pnt++; 
     380  r->flags = *pnt++; 
     381  r->message = *pnt++; 
     382  r->prefixlen = *pnt++; 
     383  r->prefix.v4.s_addr = 0; 
     384 
     385  size = (r->prefixlen + 7) / 8; 
     386  memcpy (&r->prefix.v4.s_addr, pnt, size); 
     387  pnt += size; 
    625388 
    626389  if (r->message & ZAPI_MESSAGE_NEXTHOP) { 
    627     if (len < 1) 
    628       return -1; 
    629     r->nh_count = *opt++; 
    630     len--; 
    631     if (len < (sizeof(uint32_t) + 1) * r->nh_count) 
    632       return -1; 
    633     r->nexthops = 
    634       olsr_malloc((sizeof r->nexthops->type + sizeof r->nexthops->payload) * r->nh_count, "quagga: parse_ipv4_route_add"); 
    635     for (c = 0; c < r->nh_count; c++) { 
    636       r->nexthops[c].type = *opt++; 
    637       memcpy(&r->nexthops[c].payload.v4, opt, sizeof(uint32_t)); 
    638       opt += sizeof(uint32_t); 
    639       len -= sizeof(uint32_t) + 1; 
     390    r->nexthop_num = *pnt++; 
     391    r->nexthop = olsr_malloc ((sizeof *r->nexthop) * r->nexthop_num, 
     392        "quagga: zebra_parse_route"); 
     393    for (c = 0; c < r->nexthop_num; c++) { 
     394      memcpy (&r->nexthop[c].v4.s_addr, pnt, sizeof r->nexthop[c].v4.s_addr); 
     395      pnt += sizeof r->nexthop[c].v4.s_addr; 
    640396    } 
    641397  } 
    642398 
    643399  if (r->message & ZAPI_MESSAGE_IFINDEX) { 
    644     if (len < 1) 
    645       return -1; 
    646     r->ind_num = *opt++; 
    647     if (len < sizeof(uint32_t) * r->ind_num) 
    648       return -1; 
    649     r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add"); 
    650     memcpy(r->index, opt, r->ind_num * sizeof(uint32_t)); 
    651     opt += sizeof(uint32_t) * r->ind_num; 
    652     len -= sizeof(uint32_t) * r->ind_num; 
     400    r->ifindex_num = *pnt++; 
     401    r->ifindex = olsr_malloc (sizeof (uint32_t) * r->ifindex_num, 
     402                            "quagga: zebra_parse_route"); 
     403    for (c = 0; c < r->ifindex_num; c++) { 
     404      memcpy (&r->ifindex[c], pnt, sizeof r->ifindex[c]); 
     405      r->ifindex[c] = ntohl (r->ifindex[c]); 
     406      pnt += sizeof r->ifindex[c]; 
     407    } 
    653408  } 
    654409 
    655410  if (r->message & ZAPI_MESSAGE_DISTANCE) { 
    656     if (len < 1) 
    657       return -1; 
    658     r->distance = *opt++; 
    659     len--; 
     411    r->distance = *pnt++; 
    660412  } 
    661413 
    662   if (r->message & ZAPI_MESSAGE_METRIC) { 
    663     if (len < sizeof(uint32_t)) 
    664       return -1; 
    665     memcpy(&r->metric, opt, sizeof(uint32_t)); 
    666   } 
     414// Quagga v0.98.6 BUG workaround: metric is always sent by zebra 
     415// even without ZAPI_MESSAGE_METRIC message. 
     416//  if (r.message & ZAPI_MESSAGE_METRIC) { 
     417    memcpy (&r->metric, pnt, sizeof (uint32_t)); 
     418    r->metric = ntohl (r->metric); 
     419      pnt += sizeof r->metric; 
     420//  } 
     421     
     422    if (pnt - opt != length) { olsr_exit ("(QUAGGA) length does not match ??? ", EXIT_FAILURE); 
     423     } 
    667424 
    668   return 0; 
     425  return r; 
    669426} 
    670427 
    671 static int 
    672 ipv4_route_add(unsigned char *opt, size_t len) 
    673 { 
    674428 
    675   struct ipv4_route r; 
    676   int f; 
     429static unsigned char *zebra_redistribute_packet (unsigned char cmd, unsigned char type) { 
     430  unsigned char *data, *pnt; 
     431  uint16_t size; 
    677432 
    678   f = parse_ipv4_route(opt, len, &r); 
    679   if (f < 0) 
    680     return f; 
     433  data = olsr_malloc (ZEBRA_MAX_PACKET_SIZ , "zebra_redistribute_packet"); 
    681434 
    682   return add_hna4_route(r); 
    683 } 
    684  
    685 static int 
    686 ipv4_route_delete(unsigned char *opt, size_t len) 
    687 { 
    688   struct ipv4_route r; 
    689   int f; 
    690  
    691   f = parse_ipv4_route(opt, len, &r); 
    692   if (f < 0) 
    693     return f; 
    694  
    695   return delete_hna4_route(r); 
     435  pnt = &data[2]; 
     436  *pnt++ = cmd; 
     437  *pnt++ = type; 
     438  size = htons (pnt - data); 
     439  memcpy (data, &size, 2); 
    696440 
     441  return data; 
    697442} 
    698443 
    699 static int 
    700 parse_ipv6_route_add(unsigned char *opt __attribute__ ((unused)), size_t len __attribute__ ((unused))) 
    701 { 
    702   //todo 
    703   return 0; 
    704 } 
    705444 
    706445/* start redistribution FROM zebra */ 
    707 int 
    708 zebra_redistribute(unsigned char type) 
    709 { 
    710  
    711   if (type > ZEBRA_ROUTE_MAX) 
    712     return -1; 
    713   zebra.redistribute[type - 1] = 1; 
    714  
    715   return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1); 
    716  
    717 } 
    718  
    719 /* end redistribution FROM zebra */ 
    720 int 
    721 zebra_disable_redistribute(unsigned char type) 
    722 { 
    723  
    724   if (type > ZEBRA_ROUTE_MAX) 
    725     return -1; 
    726   zebra.redistribute[type - 1] = 0; 
     446int zebra_redistribute (unsigned char type) { 
    727447 
    728   return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1); 
     448      if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_ADD, type)) < 0) 
     449        olsr_exit("(QUAGGA) could not send redistribute add command", EXIT_FAILURE); 
    729450 
    730 } 
     451  if (type > ZEBRA_ROUTE_MAX-1) return -1; 
     452  zebra.redistribute[type] = 1; 
    731453 
    732 int 
    733 add_hna4_route(struct ipv4_route r) 
    734 { 
    735   union olsr_ip_addr net; 
    736  
    737 #ifdef MY_DEBUG 
    738   dump_ipv4_route(r, "add_hna4_route"); 
    739 #endif 
    740  
    741   net.v4.s_addr = r.prefix; 
    742  
    743   ip_prefix_list_add(&olsr_cnf->hna_entries, &net, r.prefixlen); 
    744   free_ipv4_route(r); 
    745454  return 0; 
     455 
    746456} 
    747457 
    748 int 
    749 delete_hna4_route(struct ipv4_route r) 
    750 { 
    751458 
    752   union olsr_ip_addr net; 
     459/* end redistribution FROM zebra */ 
     460int zebra_disable_redistribute (unsigned char type) { 
    753461 
    754 #ifdef MY_DEBUG 
    755   dump_ipv4_route(r, "delete_hna4_route"); 
    756 #endif 
     462      if (zebra_send_command(zebra_redistribute_packet (ZEBRA_REDISTRIBUTE_DELETE, type)) < 0) 
     463        olsr_exit("(QUAGGA) could not send redistribute delete command", EXIT_FAILURE); 
    757464 
    758   net.v4.s_addr = r.prefix; 
     465  if (type > ZEBRA_ROUTE_MAX-1) return -1; 
     466  zebra.redistribute[type] = 0; 
    759467 
    760   ip_prefix_list_remove(&olsr_cnf->hna_entries, &net, r.prefixlen) ? 0 : -1; 
    761   free_ipv4_route(r); 
    762468  return 0; 
    763469 
    764470} 
    765471 
    766 static void 
    767 free_ipv4_route(struct ipv4_route r) 
    768 { 
    769  
    770   if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num) 
    771     free(r.index); 
    772   if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count) 
    773     free(r.nexthops); 
    774  
    775 } 
    776  
    777 /* 
    778 static uint8_t masktoprefixlen (uint32_t mask) { 
    779  
    780   uint8_t prefixlen = 0; 
    781472 
    782   mask = htonl (mask); 
     473static void free_ipv4_route (struct zebra_route *r) { 
    783474 
    784   if (mask) while (mask << ++prefixlen && prefixlen < 32); 
    785  
    786   return prefixlen; 
     475  if(r->ifindex_num) free(r->ifindex); 
     476  if(r->nexthop_num) free(r->nexthop); 
    787477 
    788478} 
    789 */ 
    790479 
    791 int 
    792 zebra_add_olsr_v4_route(const struct rt_entry *r) 
    793 { 
    794480 
    795   struct ipv4_route route; 
     481int zebra_add_route (const struct rt_entry *r) { 
     482 
     483  struct zebra_route route; 
    796484  int retval; 
    797485 
    798   route.index = NULL; 
    799   route.distance = 0; 
    800   route.type = ZEBRA_ROUTE_OLSR;        // OLSR 
    801   route.message = ZAPI_MESSAGE_METRIC; 
     486  route.type = ZEBRA_ROUTE_OLSR; 
    802487  route.flags = zebra.flags; 
     488  route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC; 
    803489  route.prefixlen = r->rt_dst.prefix_len; 
    804   route.prefix = r->rt_dst.prefix.v4.s_addr; 
    805   if ((r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) { 
    806     route.message |= ZAPI_MESSAGE_IFINDEX | ZAPI_MESSAGE_NEXTHOP; 
    807     route.ind_num = 1; 
    808     route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route"); 
    809     *route.index = htonl(r->rt_best->rtp_nexthop.iif_index); 
    810     route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route"); 
    811     route.nh_count = 1; 
    812     route.nexthops->type = 0; 
    813   } else { 
    814     route.message |= ZAPI_MESSAGE_NEXTHOP; 
    815     route.nh_count = 1; 
    816     route.nexthops = 
    817       olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route"); 
    818     route.nexthops->type = ZEBRA_NEXTHOP_IPV4; 
    819     route.nexthops->payload.v4 = r->rt_best->rtp_nexthop.gateway.v4.s_addr; 
     490  route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr; 
     491  route.ifindex_num = 0; 
     492  route.ifindex = NULL; 
     493  route.nexthop_num = 0; 
     494  route.nexthop = NULL; 
     495 
     496  if (r->rt_best->rtp_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && 
     497       route.prefixlen == 32) { 
     498    return 0;                   /* Quagga BUG workaround: don't add routes with destination = gateway 
     499                                   see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */ 
     500    route.ifindex_num++; 
     501    route.ifindex = olsr_malloc (sizeof *route.ifindex, 
     502                               "zebra_add_route"); 
     503    *route.ifindex = r->rt_best->rtp_nexthop.iif_index; 
     504  } 
     505  else { 
     506    route.nexthop_num++; 
     507    route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_add_route"); 
     508    route.nexthop->v4.s_addr = r->rt_best->rtp_nexthop.gateway.v4.s_addr; 
    820509  } 
    821510 
    822511  route.metric = r->rt_best->rtp_metric.hops; 
    823   route.metric = htonl(route.metric); 
    824512 
    825513  if (zebra.distance) { 
    826514    route.message |= ZAPI_MESSAGE_DISTANCE; 
    827515    route.distance = zebra.distance; 
    828516  } 
    829517 
    830   retval = zebra_add_v4_route(route); 
    831   free_ipv4_route(route); 
     518  retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_ADD, &route)); 
    832519  return retval; 
     520 
    833521} 
    834522 
    835 int 
    836 zebra_del_olsr_v4_route(const struct rt_entry *r) 
    837 { 
     523int zebra_del_route (const struct rt_entry *r) { 
    838524 
    839   struct ipv4_route route; 
     525  struct zebra_route route; 
    840526  int retval; 
    841   route.index = NULL; 
    842   route.distance = 0; 
    843   route.type = ZEBRA_ROUTE_OLSR;        // OLSR 
    844   route.message = ZAPI_MESSAGE_METRIC; 
     527 
     528  route.type = ZEBRA_ROUTE_OLSR; 
    845529  route.flags = zebra.flags; 
     530  route.message = ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_METRIC; 
    846531  route.prefixlen = r->rt_dst.prefix_len; 
    847   route.prefix = r->rt_dst.prefix.v4.s_addr; 
    848   if ((r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && route.prefixlen == 32)) { 
    849     route.message |= ZAPI_MESSAGE_IFINDEX; 
    850     route.ind_num = 1; 
    851     route.index = olsr_malloc(sizeof *route.index, "zebra_add_olsr_v4_route"); 
    852     *route.index = htonl(r->rt_nexthop.iif_index); 
    853     route.nexthops = olsr_malloc(sizeof route.nexthops->type + sizeof route.nexthops->payload, "zebra_add_olsr_v4_route"); 
    854     route.nh_count = 1; 
    855     route.nexthops->type = 0; 
    856   } else { 
    857     route.message |= ZAPI_MESSAGE_NEXTHOP; 
    858     route.nh_count = 1; 
    859     route.nexthops = 
    860       olsr_malloc(route.nh_count * (sizeof route.nexthops->type + sizeof route.nexthops->payload), "zebra_add_olsr_v4_route"); 
    861     route.nexthops->type = ZEBRA_NEXTHOP_IPV4; 
    862     route.nexthops->payload.v4 = r->rt_nexthop.gateway.v4.s_addr; 
     532  route.prefix.v4.s_addr = r->rt_dst.prefix.v4.s_addr; 
     533  route.ifindex_num = 0; 
     534  route.ifindex = NULL; 
     535  route.nexthop_num = 0; 
     536  route.nexthop = NULL; 
     537 
     538  if (r->rt_nexthop.gateway.v4.s_addr == r->rt_dst.prefix.v4.s_addr && 
     539       route.prefixlen == 32){ 
     540    return 0;                   /* Quagga BUG workaround: don't delete routes with destination = gateway 
     541                                   see http://lists.olsr.org/pipermail/olsr-users/2006-June/001726.html */ 
     542    route.ifindex_num++; 
     543    route.ifindex = olsr_malloc (sizeof *route.ifindex, 
     544                               "zebra_del_route"); 
     545    *route.ifindex = r->rt_nexthop.iif_index; 
     546  } 
     547  else { 
     548    route.nexthop_num++; 
     549    route.nexthop = olsr_malloc (sizeof *route.nexthop, "zebra_del_route"); 
     550    route.nexthop->v4.s_addr = r->rt_nexthop.gateway.v4.s_addr; 
    863551  } 
     552 
    864553  route.metric = 0; 
    865554 
    866555  if (zebra.distance) { 
     
    868557    route.distance = zebra.distance; 
    869558  } 
    870559 
    871   retval = zebra_delete_v4_route(route); 
    872560 
    873   free_ipv4_route(route); 
     561  retval = zebra_send_command (zebra_route_packet (ZEBRA_IPV4_ROUTE_DELETE, &route)); 
    874562  return retval; 
     563 
    875564} 
    876565 
    877 void 
    878 zebra_olsr_distance(unsigned char dist) 
    879 { 
     566void zebra_olsr_distance (unsigned char dist) { 
    880567  zebra.distance = dist; 
    881568} 
    882569 
    883 void 
    884 zebra_olsr_localpref(void) 
    885 { 
     570void zebra_olsr_localpref (void) { 
    886571  zebra.flags &= ZEBRA_FLAG_SELECTED; 
    887572} 
    888573 
    889 void 
    890 zebra_export_routes(unsigned char t) 
    891 { 
     574void zebra_export_routes (unsigned char t) { 
    892575  if (t) 
    893576    zebra.options |= OPTION_EXPORT; 
    894577  else 
    895578    zebra.options &= ~OPTION_EXPORT; 
    896579} 
    897  
    898 /* 
    899  * Local Variables: 
    900  * c-basic-offset: 2 
    901  * indent-tabs-mode: nil 
    902  * End: 
    903  */ 
  • lib/quagga/src/quagga.h

    a b  
     1/* 
     2 * OLSRd Quagga plugin 
     3 * 
     4 * Copyright (C) 2006-2008 Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de> 
     5 * Copyright (C) 2007-2008 Vasilis Tsiligiannis <acinonyxs@yahoo.gr> 
     6 * 
     7 * This program is free software; you can redistribute it and/or modify 
     8 * it under the terms of the GNU General Public License version 2 as 
     9 * published by the Free Software Foundation or - at your option - under 
     10 * the terms of the GNU General Public Licence version 2 but can be 
     11 * linked to any BSD-Licenced Software with public available sourcecode 
     12 * 
     13 */ 
     14 
     15/* ------------------------------------------------------------------------- 
     16 * File               : quagga.h 
     17 * Description        : header file for quagga.c 
     18 * ------------------------------------------------------------------------- */ 
    119 
    2 /*************************************************************************** 
    3  projekt              : olsrd-quagga 
    4  file                 : quagga.h 
    5  usage                : header for quagga.c 
    6  copyright            : (C) 2006 by Immo 'FaUl' Wehrenberg 
    7  e-mail               : immo@chaostreff-dortmund.de 
    8  ***************************************************************************/ 
    9  
    10 /*************************************************************************** 
    11  *                                                                         * 
    12  *   This program is free software; you can redistribute it and/or modify  * 
    13  *   it under the terms of the GNU General Public License version 2 as     * 
    14  *   published by the Free Software Foundation.                            * 
    15  *                                                                         * 
    16  ***************************************************************************/ 
     20 
     21#include "routing_table.h" /* rt_entry */ 
     22#include "olsr_types.h" /* olsr_ip_addr */ 
    1723 
    1824#include <stdint.h> 
    19 #include <stdio.h> 
    2025#include <stdlib.h> 
    21 #include "routing_table.h" 
     26 
    2227#define HAVE_SOCKLEN_T 
    2328 
     29/* Zebra port */ 
    2430#ifndef ZEBRA_PORT 
    2531#define ZEBRA_PORT 2600 
    2632#endif 
    2733 
     34/* Zebra version */ 
    2835#ifdef ZEBRA_HEADER_MARKER 
    2936#ifndef ZSERV_VERSION 
    3037#define ZSERV_VERSION 1 
    3138#endif 
    3239#endif 
    3340 
    34 struct ipv4_route { 
    35   uint8_t type; 
    36   uint8_t flags; 
    37   uint8_t message; 
    38   uint8_t prefixlen; 
    39   uint32_t prefix; 
    40   uint8_t nh_count; 
    41   struct { 
    42     uint8_t type; 
    43     union { 
    44       uint32_t v4; 
    45     } payload; 
    46   } *nexthops; 
    47   uint8_t ind_num; 
    48   uint32_t *index; 
     41/* Zebra socket */ 
     42#define ZEBRA_SOCKET "/var/run/quagga/zserv.api" 
     43 
     44/* Zebra packet size */ 
     45#define ZEBRA_MAX_PACKET_SIZ          4096 
     46 
     47/* Zebra message types */ 
     48#define ZEBRA_IPV4_ROUTE_ADD            7 
     49#define ZEBRA_IPV4_ROUTE_DELETE         8 
     50#define ZEBRA_REDISTRIBUTE_ADD          11 
     51#define ZEBRA_REDISTRIBUTE_DELETE       12 
     52#define ZEBRA_MESSAGE_MAX               23 
     53 
     54/* Zebra route types */ 
     55#define ZEBRA_ROUTE_OLSR                11 
     56#define ZEBRA_ROUTE_MAX                 13 
     57 
     58/* Zebra flags */ 
     59#define ZEBRA_FLAG_SELECTED             0x10 
     60 
     61/* Zebra nexthop flags */ 
     62#define ZEBRA_NEXTHOP_IFINDEX           1 
     63#define ZEBRA_NEXTHOP_IPV4              3 
     64 
     65/* Zebra message flags */ 
     66#define ZAPI_MESSAGE_NEXTHOP  0x01 
     67#define ZAPI_MESSAGE_IFINDEX  0x02 
     68#define ZAPI_MESSAGE_DISTANCE 0x04 
     69#define ZAPI_MESSAGE_METRIC   0x08 
     70 
     71/* Buffer size */ 
     72#define BUFSIZE 1024 
     73 
     74/* Quagga plugin flags */ 
     75#define STATUS_CONNECTED 1 
     76#define OPTION_EXPORT 1 
     77 
     78 
     79struct zebra_route { 
     80  unsigned char type; 
     81  unsigned char flags; 
     82  unsigned char message; 
     83  unsigned char prefixlen; 
     84  union olsr_ip_addr prefix; 
     85  unsigned char nexthop_num; 
     86  union olsr_ip_addr *nexthop; 
     87  unsigned char ifindex_num; 
     88  uint32_t *ifindex; 
    4989  uint32_t metric; 
    5090  uint8_t distance; 
    51   struct ipv4_route *next; 
    5291}; 
    5392 
    54 void init_zebra(void); 
    55 void zebra_cleanup(void); 
    56 unsigned char zebra_send_command(unsigned char, unsigned char *, int); 
    57 int zebra_add_v4_route(const struct ipv4_route r); 
    58 int zebra_delete_v4_route(const struct ipv4_route r); 
    59 void zebra_check(void *); 
    60 int zebra_parse_packet(unsigned char *, ssize_t); 
    61 int zebra_redistribute(unsigned char); 
    62 int zebra_disable_redistribute(unsigned char); 
    63 int add_hna4_route(struct ipv4_route); 
    64 int delete_hna4_route(struct ipv4_route); 
    65 void *my_realloc(void *, size_t, const char *); 
    66 int zebra_add_olsr_v4_route(const struct rt_entry *); 
    67 int zebra_del_olsr_v4_route(const struct rt_entry *); 
    68 void zebra_olsr_localpref(void); 
    69 void zebra_olsr_distance(unsigned char); 
     93void init_zebra (void); 
     94void zebra_cleanup (void); 
     95void zebra_parse (void*); 
     96int zebra_redistribute (unsigned char); 
     97int zebra_disable_redistribute (unsigned char); 
     98int zebra_add_route (const struct rt_entry *); 
     99int zebra_del_route (const struct rt_entry *); 
     100void zebra_olsr_localpref (void); 
     101void zebra_olsr_distance (unsigned char); 
    70102void zebra_export_routes(unsigned char); 
    71  
    72 /* 
    73  * Local Variables: 
    74  * c-basic-offset: 2 
    75  * indent-tabs-mode: nil 
    76  * End: 
    77  */ 
  • deleted file lib/quagga/test/foo.c

    + -  
    1 #include "quagga.h" 
    2  
    3 int 
    4 main(void) 
    5 { 
    6  
    7   init_zebra(); 
    8   zebra_redistribute(2); 
    9   //  zebra_redistribute (1); 
    10   while (!sleep(1)) 
    11     zebra_check(); 
    12   return 0; 
    13 } 
    14  
    15 /* 
    16  * Local Variables: 
    17  * c-basic-offset: 2 
    18  * indent-tabs-mode: nil 
    19  * End: 
    20  */ 
  • deleted file lib/quagga/test/foo.pl

    + -  
    1 #!/usr/bin/perl 
    2  
    3 use IO::Socket; 
    4  
    5 $command = 11; # 11 = redistribute_add , 13 = redistribute_default_add 
    6  
    7 $proto = 2; # connected  
    8  
    9 $remote = IO::Socket::INET->new (Proto => "tcp", 
    10                                  PeerAddr => "127.0.0.1", 
    11                                  PeerPort => "2600", 
    12                                  ); 
    13 $remote->autoflush (1); 
    14 #print $remote pack ("nc", 3, 13); 
    15 print $remote pack ("nc",3,1); 
    16 print $remote pack ("ncc", 4,$command,2); 
    17 print $remote pack ("ncccccNcNcNN", 25, 7, 10, 16, 11, 25, 0xc0a80206, 0, 0, 1, 5, 1); 
    18 print <$remote>; 
    19 close $remote 
  • deleted file lib/quagga/test/quagga.try1.c

    + -  
    1  
    2 /* 
    3  *  (C) 2006 by Immo 'FaUl' Wehrenberg <immo@chaostreff-dortmund.de> 
    4  * 
    5  *  This code is covered by the GPLv2 
    6  * 
    7  */ 
    8  
    9 #include <stdint.h> 
    10 #ifdef MY_DEBUG 
    11 #include <stdio.h> 
    12 #endif 
    13 #include <sys/types.h> 
    14 #include <sys/socket.h> 
    15 #include <netinet/in.h> 
    16 #define HAVE_SOCKLEN_T 
    17 #include <quagga/zebra.h> 
    18 #include "quagga.h" 
    19  
    20 #ifdef OLSR_PLUGIN 
    21 #include "olsr.h" 
    22 #include "log.h" 
    23 #include "defs.h" 
    24 #include "local_hna_set.h" 
    25 #endif 
    26  
    27 #define ZAPI_MESSAGE_NEXTHOP  0x01 
    28 #define ZAPI_MESSAGE_IFINDEX  0x02 
    29 #define ZAPI_MESSAGE_DISTANCE 0x04 
    30 #define ZAPI_MESSAGE_METRIC   0x08 
    31  
    32 #define STATUS_CONNECTED 1 
    33 #define BUFSIZE 1024 
    34 static char status = 0; 
    35  
    36 static int zsock;                      // Socket to zebra... 
    37 struct ipv4_route *quagga_routes = 0;  // routes currently exportet to zebra 
    38  
    39 /* prototypes ntern */ 
    40 static char *try_read(ssize_t *); 
    41 static char *zebra_route_packet(struct ipv4_route r, ssize_t *); 
    42 static int parse_interface_add(char *, size_t); 
    43 static int parse_interface_delete(char *, size_t); 
    44 static int parse_interface_up(char *, size_t); 
    45 static int parse_interface_down(char *, size_t); 
    46 static int parse_interface_address_add(char *, size_t); 
    47 static int parse_interface_address_delete(char *, size_t); 
    48 static int parse_ipv4_route(char *, size_t, struct ipv4_route *); 
    49 static int ipv4_route_add(char *, size_t); 
    50 static int ipv4_route_delete(char *, size_t); 
    51 static int parse_ipv6_route_add(char *, size_t); 
    52 static uint32_t prefixlentomask(uint8_t); 
    53 static void free_ipv4_route(struct ipv4_route); 
    54 static void update_olsr_zebra_routes(struct ipv4_route *, struct ipv4_route *); 
    55 static struct ipv4_route *zebra_create_ipv4_route_table_entry(uint32_t, uint32_t, uint32_t); 
    56 static struct ipv4_route *zebra_create_ipv4_route_table(void); 
    57 static void zebra_free_ipv4_route_table(struct ipv4_route *); 
    58 static uint8_t masktoprefixlen(uint32_t); 
    59  
    60 #ifdef MY_DEBUG 
    61 static void 
    62 dump_ipv4_route(struct ipv4_route r, char *c) 
    63 { 
    64   int i = 0, x = 0; 
    65  
    66   puts(c); 
    67   printf("type: %d\n", r.type); 
    68   puts("flags:"); 
    69   printf("  Internal: %s\n", r.flags & ZEBRA_FLAG_INTERNAL ? "yes" : "no"); 
    70   printf("  Selfroute %s\n", r.flags & ZEBRA_FLAG_SELFROUTE ? "yes" : "no"); 
    71   printf("  Blackhole %s\n", r.flags & ZEBRA_FLAG_BLACKHOLE ? "yes" : "no"); 
    72   printf("  IBGP: %s\n", r.flags & ZEBRA_FLAG_IBGP ? "yes" : "no"); 
    73   printf("  Selected: %s\n", r.flags & ZEBRA_FLAG_SELECTED ? "yes" : "no"); 
    74   printf("  Changed: %s\n", r.flags & ZEBRA_FLAG_CHANGED ? "yes" : "no"); 
    75   printf("  static: %s\n", r.flags & ZEBRA_FLAG_STATIC ? "yes" : "no"); 
    76   printf("  reject: %s\n", r.flags & ZEBRA_FLAG_REJECT ? "yes" : "no"); 
    77   puts("message:"); 
    78   printf("  nexthop: %s\n", r.message & ZAPI_MESSAGE_NEXTHOP ? "yes" : "no"); 
    79   printf("  ifindex: %s\n", r.message & ZAPI_MESSAGE_IFINDEX ? "yes" : "no"); 
    80   printf("  distance: %s\n", r.message & ZAPI_MESSAGE_DISTANCE ? "yes" : "no"); 
    81   printf("  metric: %s\n", r.message & ZAPI_MESSAGE_METRIC ? "yes" : "no"); 
    82   printf("Prefixlen: %d\n", r.prefixlen); 
    83   printf("Prefix: %d", (unsigned char)r.prefix); 
    84   c = (char *)&r.prefix; 
    85   while (++i < (r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0))) 
    86     printf(".%d", (unsigned char)*(c + i)); 
    87   while (i++ < 4) 
    88     printf(".0"); 
    89   puts(""); 
    90   i = 0; 
    91   if (r.message & ZAPI_MESSAGE_NEXTHOP) { 
    92  
    93     printf("nexthop-count: %d\n", r.nh_count); 
    94     while (i++ < r.nh_count) { 
    95       c = (unsigned char *)&r.nexthops[i]; 
    96       printf("Nexthop %d: %d", i, (unsigned char)*c); 
    97       while (++x < 4) { 
    98         printf(".%d", (unsigned char)c[x]); 
    99       } 
    100       puts(""); 
    101     } 
    102     i = 0; 
    103   } 
    104   if (r.message & ZAPI_MESSAGE_IFINDEX) { 
    105  
    106     printf("index-number: %d\n", r.ind_num); 
    107     while (i++ < r.ind_num) 
    108       printf("Index: %d: %d\n", i, r.index[i]); 
    109     i = 0; 
    110     if (r.message & ZAPI_MESSAGE_DISTANCE) 
    111       printf("Distance: %d\n", r.distance); 
    112     if (r.message & ZAPI_MESSAGE_METRIC) 
    113       printf("Metric: %d\n", r.metric); 
    114     puts("\n"); 
    115   } 
    116 } 
    117 #endif 
    118  
    119 void * 
    120 my_realloc(void *buf, size_t s, const char *c) 
    121 { 
    122   buf = realloc(buf, s); 
    123   if (!buf) { 
    124 #ifdef OLSR_PLUGIN 
    125     OLSR_PRINTF(1, "OUT OF MEMORY: %s\n", strerror(errno)); 
    126     olsr_syslog(OLSR_LOG_ERR, "olsrd: out of memory!: %m\n"); 
    127     olsr_exit(c, EXIT_FAILURE); 
    128 #else 
    129     exit(EXIT_FAILURE); 
    130 #endif 
    131   } 
    132   return buf; 
    133 } 
    134  
    135 #ifndef OLSR_PLUGIN 
    136 void * 
    137 olsr_malloc(size_t f, const char *c) 
    138 { 
    139   void *v = malloc(f); 
    140   return v; 
    141 } 
    142 #endif 
    143  
    144 /* Connect to the zebra-daemon, returns a socket */ 
    145 int 
    146 init_zebra() 
    147 { 
    148   struct sockaddr_in i; 
    149   int ret; 
    150  
    151   zsock = socket(AF_INET, SOCK_STREAM, 0); 
    152   if (zsock < 0)                // TODO: Could not create socket 
    153     return -1; 
    154   memset(&i, 0, sizeof i); 
    155   i.sin_family = AF_INET; 
    156   i.sin_port = htons(ZEBRA_PORT); 
    157   //  i.sin_len = sizeof i; 
    158   i.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
    159  
    160   ret = connect(zsock, (struct sockaddr *)&i, sizeof i); 
    161   if (ret < 0) { 
    162     close(zsock); 
    163     return -1; 
    164   } 
    165   status |= STATUS_CONNECTED; 
    166   return zsock; 
    167 } 
    168  
    169 /* Sends a command to zebra, command is 
    170    the command defined in zebra.h, options is the packet-payload, 
    171    optlen the length, of the payload */ 
    172 char 
    173 zebra_send_command(unsigned char command, char *options, int optlen) 
    174 { 
    175  
    176   char *p = olsr_malloc(optlen + 3, "zebra send_command"); 
    177   uint16_t length = optlen + 3;        // length of option + command + packet_length 
    178  
    179   int ret; 
    180  
    181   uint16_t len = htons(length); 
    182   memcpy(p, &len, 2); 
    183   p[2] = command; 
    184   memcpy(p + 3, options, optlen); 
    185  
    186   do { 
    187     ret = write(zsock, p, length); 
    188     if (ret < 0) { 
    189       if (errno == EINTR) 
    190         continue; 
    191     } else 
    192       return -1; 
    193     p = p + ret; 
    194   } 
    195   while ((length -= ret)); 
    196  
    197   return 0; 
    198 } 
    199  
    200 /* Creates a Route-Packet-Payload, needs address, netmask, nexthop, 
    201    distance, and a pointer of an size_t */ 
    202 static char * 
    203 zebra_route_packet(struct ipv4_route r, ssize_t * optlen) 
    204 { 
    205  
    206   char *cmdopt, *t; 
    207   *optlen = 9;                  // first: type, flags, message, prefixlen, nexthop number, nexthop) 
    208   *optlen += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); 
    209  
    210   cmdopt = olsr_malloc(*optlen, "zebra add_v4_route"); 
    211   t = cmdopt; 
    212   *t++ = 10;                    // Type: olsr 
    213   *t++ = r.flags;               // flags 
    214   *t++ = r.message;             // message: contains nexthop 
    215   *t++ = r.prefixlen; 
    216   memcpy(t, &r.prefix, r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0)); 
    217   *t += r.prefixlen / 8 + (r.prefixlen % 8 ? 1 : 0); 
    218   *t++ = r.nh_count; 
    219   memcpy(t, r.nexthops, r.nh_count * sizeof *r.nexthops); 
    220   return cmdopt; 
    221 } 
    222  
    223 /* adds a route to zebra-daemon (needs socket from zebra, 
    224    address = prefix of the route 
    225    mask = netmask of the route 
    226    nexthop = nexthop of the route 
    227    distance = distance-value of the route 
    228 */ 
    229 int 
    230 zebra_add_v4_route(struct ipv4_route r) 
    231 { 
    232  
    233   char *cmdopt; 
    234   ssize_t optlen; 
    235  
    236   cmdopt = zebra_route_packet(r, &optlen); 
    237  
    238   puts("DEBUG: zebra_route_packet returned"); 
    239  
    240   return zebra_send_command(ZEBRA_IPV4_ROUTE_ADD, cmdopt, optlen); 
    241  
    242 } 
    243  
    244 /* deletes a route from the zebra-daemon ( 
    245    needs socket from zebra, 
    246    address = prefix of the route 
    247    mask = netmask of the route 
    248    nexthop = nexthop of the route 
    249    distance = distance-value of the route 
    250 */ 
    251 int 
    252 zebra_delete_v4_route(struct ipv4_route r) 
    253 { 
    254  
    255   char *cmdopt; 
    256   ssize_t optlen; 
    257  
    258   cmdopt = zebra_route_packet(r, &optlen); 
    259  
    260   return zebra_send_command(ZEBRA_IPV4_ROUTE_DELETE, cmdopt, optlen); 
    261  
    262 } 
    263  
    264 /* Check wether there is data from zebra aviable */ 
    265 void 
    266 zebra_check(void *foo) 
    267 { 
    268   char *data, *f; 
    269   ssize_t len, ret; 
    270  
    271   if (!status & STATUS_CONNECTED) { 
    272   } 
    273   data = try_read(&len); 
    274   if (data) { 
    275     f = data; 
    276     do { 
    277       ret = zebra_parse_packet(f, len); 
    278       if (!ret) {               //something wired happened 
    279         puts("DEBUG: IIIIIIIIIIRGS"); 
    280         exit(EXIT_FAILURE); 
    281       } 
    282       f += ret; 
    283     } 
    284     while ((f - data) < len); 
    285     free(data); 
    286   } 
    287 } 
    288  
    289 // tries to read a packet from zebra_socket 
    290 // if there is something to read - make sure to read whole packages 
    291 static char * 
    292 try_read(ssize_t * len) 
    293 { 
    294   char *buf = NULL; 
    295   ssize_t ret = 0, bsize = 0; 
    296   uint16_t length = 0, l = 0; 
    297   int sockstate; 
    298  
    299   *len = 0; 
    300  
    301   sockstate = fcntl(zsock, F_GETFL, 0); 
    302   fcntl(zsock, F_SETFL, sockstate | O_NONBLOCK); 
    303  
    304   do { 
    305     if (*len == bsize) { 
    306       bsize += BUFSIZE; 
    307       buf = my_realloc(buf, bsize, "Zebra try_read"); 
    308     } 
    309     ret = read(zsock, buf + l, bsize - l); 
    310     if (ret <= 0) { 
    311       if (errno == EAGAIN) { 
    312         errno = 0; 
    313       } else { 
    314         // TODO: errorhandling 
    315         ; 
    316       } 
    317       free(buf); 
    318       return NULL; 
    319     } 
    320     *len += ret; 
    321  
    322     while ((*len - l) > length) { 
    323       //      printf ("DEBUG: *len -l > length - %d - %d > %d\n", *len, l, length); 
    324       l += length; 
    325       memcpy(&length, buf + l, 2); 
    326       length = ntohs(length); 
    327     } 
    328     //    printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length); 
    329     if (((*len) - l) == length) 
    330       break;                    // GOT FULL PACKAGE!! 
    331     if (*len < l) { 
    332       //      printf ("DEBUG: *len, l, length: %d,%d,%d\n", *len, l, length); 
    333       fcntl(zsock, F_SETFL, sockstate); 
    334       continue; 
    335     } 
    336   } 
    337   while (1); 
    338  
    339   fcntl(zsock, F_SETFL, sockstate); 
    340   return buf; 
    341 } 
    342  
    343 /* Parse a packet recived from zebra */ 
    344 int 
    345 zebra_parse_packet(char *packet, ssize_t maxlen) 
    346 { 
    347  
    348   /* Array of functions */ 
    349   int (*foo[ZEBRA_MESSAGE_MAX]) (char *, size_t) = { 
    350   parse_interface_add, parse_interface_delete, parse_interface_address_add, parse_interface_address_delete, parse_interface_up, 
    351       parse_interface_down, ipv4_route_add, ipv4_route_delete, parse_ipv6_route_add}; 
    352  
    353   puts("DEBUG: zebra_parse_packet"); 
    354   uint16_t length; 
    355  
    356   int ret; 
    357   memcpy(&length, packet, 2); 
    358   length = ntohs(length); 
    359  
    360   if (maxlen < length) { 
    361     puts("Error: programmer is an idiot"); 
    362     printf("DEBUG: maxlen = %d, packet_length = %d\n", maxlen, length); 
    363     return maxlen; 
    364   } 
    365  
    366   if (packet[2] - 1 < ZEBRA_MESSAGE_MAX && foo[packet[2] - 1]) { 
    367     if (!(ret = foo[packet[2] - 1] (packet + 3, length - 3))) 
    368       return length; 
    369     else 
    370       printf("DEBUG: Parse error: %d\n", ret); 
    371   } else 
    372     printf("Unknown packet type: %d\n", packet[2]); 
    373  
    374   puts("Quagga: RECIVED PACKET FROM ZEBRA THAT I CAN'T PARSE"); 
    375  
    376   return length; 
    377 } 
    378  
    379 static int 
    380 parse_interface_add(char *opt, size_t len) 
    381 { 
    382   //todo 
    383   return 0; 
    384 } 
    385  
    386 static int 
    387 parse_interface_delete(char *opt, size_t len) 
    388 { 
    389   //todo 
    390   return 0; 
    391 } 
    392  
    393 static int 
    394 parse_interface_address_add(char *opt, size_t len) 
    395 { 
    396  
    397   //todo 
    398   return 0; 
    399 } 
    400  
    401 static int 
    402 parse_interface_up(char *opt, size_t len) 
    403 { 
    404  
    405   //todo 
    406   return 0; 
    407 } 
    408  
    409 static int 
    410 parse_interface_down(char *opt, size_t len) 
    411 { 
    412  
    413   //todo 
    414   return 0; 
    415 } 
    416  
    417 static int 
    418 parse_interface_address_delete(char *opt, size_t len) 
    419 { 
    420   //todo 
    421   return 0; 
    422 } 
    423  
    424 /* Parse an ipv4-route-packet recived from zebra 
    425  */ 
    426 static int 
    427 parse_ipv4_route(char *opt, size_t len, struct ipv4_route *r) 
    428 { 
    429   //  puts ("DEBUG: parse_ipv4_route"); 
    430   if (len < 4) 
    431     return -1; 
    432  
    433   r->type = *opt++; 
    434   r->flags = *opt++; 
    435   r->message = *opt++; 
    436   r->prefixlen = *opt++; 
    437   len -= 4; 
    438   r->prefix = 0; 
    439  
    440   if ((int)len < r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0)) 
    441     return -1; 
    442  
    443   memcpy(&r->prefix, opt, r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0)); 
    444   opt += r->prefixlen / 8 + (r->prefixlen % 8 ? 1 : 0); 
    445  
    446   if (r->message & ZAPI_MESSAGE_NEXTHOP) { 
    447     if (len < 1) 
    448       return -1; 
    449     r->nh_count = *opt++; 
    450     if (len < sizeof(uint32_t) * r->nh_count) 
    451       return -1; 
    452     r->nexthops = olsr_malloc(sizeof(uint32_t) * r->nh_count, "quagga: parse_ipv4_route_add"); 
    453     memcpy(r->nexthops, opt, sizeof(uint32_t) * r->nh_count); 
    454     opt += sizeof(uint32_t) * r->nh_count; 
    455     len -= sizeof(uint32_t) * r->nh_count + 1; 
    456   } 
    457  
    458   if (r->message & ZAPI_MESSAGE_IFINDEX) { 
    459     if (len < 1) 
    460       return -2; 
    461     r->ind_num = *opt++; 
    462     if (len < sizeof(uint32_t) * r->ind_num) 
    463       return -3; 
    464     r->index = olsr_malloc(sizeof(uint32_t) * r->ind_num, "quagga: parse_ipv4_route_add"); 
    465     memcpy(r->index, opt, r->ind_num * sizeof(uint32_t)); 
    466     opt += sizeof(uint32_t) * r->ind_num; 
    467     len -= sizeof(uint32_t) * r->ind_num; 
    468   } 
    469  
    470   if (r->message & ZAPI_MESSAGE_DISTANCE) 
    471     // todo 
    472     ; 
    473  
    474   if (r->message & ZAPI_MESSAGE_METRIC) { 
    475     if (len < sizeof(uint32_t)) 
    476       return -4; 
    477     memcpy(&r->metric, opt, sizeof(uint32_t)); 
    478   } 
    479  
    480   return 0; 
    481 } 
    482  
    483 static int 
    484 ipv4_route_add(char *opt, size_t len) 
    485 { 
    486  
    487   struct ipv4_route r; 
    488   int f; 
    489  
    490   //  puts ("DEBUG: ipv4_route_add"); 
    491  
    492   f = parse_ipv4_route(opt, len, &r); 
    493   if (f < 0) { 
    494     printf("parse-error: %d\n", f); 
    495     return f; 
    496   } 
    497  
    498   add_hna4_route(r); 
    499   return 0; 
    500 } 
    501  
    502 static int 
    503 ipv4_route_delete(char *opt, size_t len) 
    504 { 
    505   struct ipv4_route r; 
    506   int f; 
    507  
    508   f = parse_ipv4_route(opt, len, &r); 
    509   if (f < 0) 
    510     return f; 
    511  
    512   return delete_hna4_route(r); 
    513   // OK, now delete that foo 
    514  
    515 } 
    516  
    517 static int 
    518 parse_ipv6_route_add(char *opt, size_t len) 
    519 { 
    520   //todo 
    521   return 0; 
    522 } 
    523  
    524 /* start redistribution FROM zebra */ 
    525 int 
    526 zebra_redistribute(unsigned char type) 
    527 { 
    528  
    529   return zebra_send_command(ZEBRA_REDISTRIBUTE_ADD, &type, 1); 
    530  
    531 } 
    532  
    533 /* end redistribution FROM zebra */ 
    534 int 
    535 zebra_disable_redistribute(unsigned char type) 
    536 { 
    537  
    538   return zebra_send_command(ZEBRA_REDISTRIBUTE_DELETE, &type, 1); 
    539  
    540 } 
    541  
    542 static uint32_t 
    543 prefixlentomask(uint8_t prefix) 
    544 { 
    545   uint32_t mask; 
    546   mask = prefix_to_netmask4(prefix); 
    547   mask = ntohl(mask); 
    548   return mask; 
    549 } 
    550  
    551 int 
    552 add_hna4_route(struct ipv4_route r) 
    553 { 
    554   union olsr_ip_addr net, mask; 
    555  
    556 #ifdef MY_DEBUG 
    557   dump_ipv4_route(r, "add_hna4_route"); 
    558 #endif 
    559  
    560   mask.v4 = prefixlentomask(r.prefixlen); 
    561   net.v4 = r.prefix; 
    562  
    563 #ifdef OLSR_PLUGIN 
    564   add_local_hna4_entry(&net, &mask); 
    565 #endif 
    566   free_ipv4_route(r); 
    567   return 0; 
    568 } 
    569  
    570 int 
    571 delete_hna4_route(struct ipv4_route r) 
    572 { 
    573  
    574   union olsr_ip_addr net, mask; 
    575  
    576 #ifdef MY_DEBUG 
    577   dump_ipv4_route(r, "delete_hna4_route"); 
    578 #endif 
    579  
    580   mask.v4 = prefixlentomask(r.prefixlen); 
    581   net.v4 = r.prefix; 
    582  
    583 #ifdef OLSR_PLUGIN 
    584   return remove_local_hna4_entry(&net, &mask) ? 0 : -1; 
    585 #endif 
    586  
    587   free_ipv4_route(r); 
    588   return 0; 
    589  
    590 } 
    591  
    592 static void 
    593 free_ipv4_route(struct ipv4_route r) 
    594 { 
    595  
    596   if (r.message & ZAPI_MESSAGE_IFINDEX && r.ind_num) 
    597     free(r.index); 
    598   if (r.message & ZAPI_MESSAGE_NEXTHOP && r.nh_count) 
    599     free(r.nexthops); 
    600  
    601 } 
    602  
    603 void 
    604 zebra_clear_routes(void) 
    605 { 
    606  
    607   struct ipv4_route *t; 
    608  
    609   t = quagga_routes; 
    610   while (t) { 
    611     zebra_delete_v4_route(*t); 
    612     t = t->next; 
    613   } 
    614   zebra_free_ipv4_route_table(quagga_routes); 
    615  
    616   quagga_routes = NULL; 
    617 } 
    618  
    619 void 
    620 zebra_update_hna(void *f) 
    621 { 
    622  
    623   struct ipv4_route *a = zebra_create_ipv4_route_table(); 
    624   update_olsr_zebra_routes(a, quagga_routes); 
    625   zebra_free_ipv4_route_table(quagga_routes); 
    626  
    627   quagga_routes = a; 
    628  
    629 } 
    630  
    631 static struct ipv4_route * 
    632 zebra_create_ipv4_route_table(void) 
    633 { 
    634  
    635   struct ipv4_route *r = 0, *t = 0 /* make compiler happy */ ; 
    636   int i; 
    637   struct hna_entry *e; 
    638   struct hna_net *n; 
    639  
    640   for (i = 0; i < HASHSIZE; i++) { 
    641     e = hna_set[i].next; 
    642     for (; e != &hna_set[i]; e = e->next) { 
    643       n = e->networks.next; 
    644       for (; n != &e->networks; n = n->next) { 
    645         if (!r) { 
    646           r = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4); 
    647           t = r; 
    648         } else { 
    649           t->next = zebra_create_ipv4_route_table_entry(n->A_network_addr.v4, n->A_netmask.v4, e->A_gateway_addr.v4); 
    650           t = t->next; 
    651         } 
    652       } 
    653     } 
    654   } 
    655  
    656   return r; 
    657  
    658 } 
    659  
    660 static struct ipv4_route * 
    661 zebra_create_ipv4_route_table_entry(uint32_t addr, uint32_t mask, uint32_t gw) 
    662 { 
    663  
    664   struct ipv4_route *r; 
    665  
    666   r = olsr_malloc(sizeof *r, "zebra_create_ipv4_route_table_entry"); 
    667   memset(r, 0, sizeof *r); 
    668   r->prefix = addr; 
    669   r->prefixlen = masktoprefixlen(mask); 
    670   r->message |= ZAPI_MESSAGE_NEXTHOP; 
    671   r->nh_count = 1; 
    672   r->nexthops = olsr_malloc(sizeof(uint32_t), "zebra_create_ipv4_route_table_entry"); 
    673   *r->nexthops = gw; 
    674   r->next = NULL; 
    675  
    676   return r; 
    677 } 
    678  
    679 static uint8_t 
    680 masktoprefixlen(uint32_t mask) 
    681 { 
    682  
    683   uint8_t prefixlen = 0; 
    684 while (mask & (1 << ++prefixlen && prefixlen < 32); return prefixlen;} 
    685  
    686        static void update_olsr_zebra_routes(struct ipv4_route *a, struct ipv4_route *r) { 
    687  
    688        struct ipv4_route * t; if (!r) { 
    689        puts("no quagga_routing_table aviable"); for (; a; a = a->next) { 
    690        dump_ipv4_route(*a, "adding this route"); 
    691        //      zebra_add_v4_route(*r); 
    692        } 
    693        return;} 
    694  
    695        while (a) { 
    696        for (t = r; t; t = t->next) { 
    697        if (a->prefix == t->prefix) if (a->prefixlen == t->prefixlen) if (*a->nexthops == *t->nexthops) { 
    698        goto foo;} 
    699        } 
    700        dump_ipv4_route(*a, "adding this route"); 
    701        //zebra_add_v4_route(*a); 
    702   foo: 
    703        a = a->next;} 
    704  
    705        while (r) { 
    706        for (t = a; t; t = t->next) { 
    707        if (r->prefix == t->prefix) if (r->prefixlen == t->prefixlen) if (*r->nexthops == *t->nexthops) { 
    708        goto bar;} 
    709        } 
    710        dump_ipv4_route(*r, "deleting this route"); 
    711        //zebra_delete_v4_route(*r); 
    712   bar: 
    713        r = r->next;} 
    714  
    715        } 
    716  
    717        static void zebra_free_ipv4_route_table(struct ipv4_route *r) { 
    718        struct ipv4_route * n; if (!r) return; while ((n = r->next)) { 
    719        if (r->message & ZAPI_MESSAGE_NEXTHOP) free(r->nexthops); if (r->message & ZAPI_MESSAGE_IFINDEX) free(r->index); free(r); 
    720        r = n;} 
    721        } 
    722  
    723 /* 
    724  * Local Variables: 
    725  * c-basic-offset: 2 
    726  * indent-tabs-mode: nil 
    727  * End: 
    728  */ 
Note: See TracBrowser for help on using the repository browser.