[olsr-dev] plugin-interface to kernel-route-exporter

Immo 'FaUl' Wehrenberg (spam-protected)
Thu Apr 20 14:17:25 CEST 2006


Hi,

I'm currently working on an olsr-quagga-plugin which integrates olsrd
into quagga.

In Quagga, all routes are exported to the zebra-daemon and the daemon
exportes them to the kernel.=20

The attached patch addes an interface to the olsrd to "register/unregister=
=20
functions" to expor routes. It works much like the=20
olsr_parser_add_function()/olsr_parser_del_function() interface and is
not only necessary for allowing a plugin to integrate the olsrd into=20
quagga but may also allow easier host emulation as well as creating=20
various plugins that need route-information.

I would like to see it into the mainline-source of the olsrd.

TIA

FaUl
-- 
"Überhaupt, was für eine Einstellung zur Bildung ist denn das?  Kinder
sollen in der Schule auf das Leben vorbereitet werden, nicht auf das
Werbefernsehen, wo auch alles negative weggefiltert wird."
[Felix von Leitner in doc über Webfilter]
-------------- next part --------------
diff -ru olsrd-0.4.10/src/main.c olsrd-0.4.10-routehandler/src/main.c
--- olsrd-0.4.10/src/main.c	2005-09-29 07:53:34.000000000 +0200
+++ olsrd-0.4.10-routehandler/src/main.c	2006-04-18 20:04:43.313296250 +0200
@@ -280,6 +280,9 @@
   /* Initialize parser */
   olsr_init_parser();
 
+  /* Initialize route-exporter */
+  olsr_init_export_route();
+
   /* Initialize message sequencnumber */
   init_msg_seqno();
 
diff -ru olsrd-0.4.10/src/process_routes.c olsrd-0.4.10-routehandler/src/process_routes.c
--- olsrd-0.4.10/src/process_routes.c	2005-05-30 15:13:38.000000000 +0200
+++ olsrd-0.4.10-routehandler/src/process_routes.c	2006-04-18 22:10:27.129290250 +0200
@@ -3,6 +3,9 @@
  * Copyright (c) 2004, Andreas Tønnesen((spam-protected))
  * All rights reserved.
  *
+ * export_route_entry interface added by Immo 'FaUl Wehrenberg 
+ * <(spam-protected)>
+ *
  * Redistribution and use in source and binary forms, with or without 
  * modification, are permitted provided that the following conditions 
  * are met:
@@ -39,7 +42,6 @@
  * $Id: process_routes.c,v 1.27 2005/05/30 13:13:38 kattemat Exp $
  */
 
-
 #include "defs.h"
 #include "olsr.h"
 #include "log.h"
@@ -51,10 +53,162 @@
 #define strerror(x) StrError(x)
 #endif
 
+struct export_route_entry
+{
+  olsr_u8_t type;       /* AF_INET/AF_INET6 */
+  int (*function)(struct rt_entry*);
+  struct export_route_entry *next;
+};
+
+
+static struct export_route_entry *add_routes;
+static struct export_route_entry *del_routes;
+
 
 struct rt_entry old_routes[HASHSIZE];
 struct rt_entry old_hna[HASHSIZE];
 
+void 
+olsr_addroute_add_function(int (*function)(struct rt_entry*), olsr_u8_t type) 
+{
+  struct export_route_entry *tmp;
+  tmp = olsr_malloc(sizeof *tmp, "olsr_addroute_add_function");
+  tmp->type = type;
+  tmp->function = function;
+  tmp->next = add_routes;
+  add_routes = tmp;
+}
+
+void 
+olsr_delroute_add_function(int (*function) (struct rt_entry*), olsr_u8_t type)
+{
+  struct export_route_entry *tmp;
+  tmp = olsr_malloc(sizeof *tmp, "olsr_delroute_add_function");
+  tmp->type = type;
+  tmp->function = function;
+  tmp->next = del_routes;
+  del_routes = tmp;
+}
+
+
+int 
+olsr_addroute_remove_function(int (*function) (struct rt_entry*), olsr_u8_t type)
+{
+  struct export_route_entry *tmp, *prev = NULL /* Make compiler happy */; 
+  tmp = add_routes;
+  while (tmp) 
+    {
+      if (function == tmp->function && type == tmp->type) 
+	{
+	  if (tmp == add_routes) 
+	    {
+	      add_routes = add_routes->next;
+	      free (tmp);
+	      return 1;
+	    }
+	  else 
+	    {
+	      prev->next = tmp->next;
+	      free (tmp);
+	      return 1;
+	    }
+	}
+      prev = tmp;
+      tmp = tmp->next;
+    }
+  return 0;
+}
+
+int
+olsr_delroute_remove_function(int (*function) (struct rt_entry*), olsr_u8_t type)
+{
+  struct export_route_entry *tmp, *prev = NULL /* Make compiler happy */;
+  tmp = del_routes;
+  while (tmp) 
+    {
+      if (function == tmp->function && type == tmp->type) 
+	{
+	  if (tmp == del_routes) 
+	    {
+	      del_routes = del_routes->next;
+	      free (tmp);
+	      return 1;
+	    }
+	  else 
+	    {
+	      prev->next = tmp->next;
+	      free (tmp);
+	      return 1; 
+	    }
+	}
+      prev = tmp;
+      tmp = tmp->next;
+    }
+  return 0;
+}
+
+void 
+olsr_init_export_route() 
+{
+  olsr_addroute_add_function(&olsr_ioctl_add_route, AF_INET);
+  olsr_addroute_add_function(&olsr_ioctl_add_route6, AF_INET6);
+  olsr_delroute_add_function(&olsr_ioctl_del_route, AF_INET);
+  olsr_delroute_add_function(&olsr_ioctl_del_route6, AF_INET6);
+}
+
+int
+olsr_export_add_route (struct rt_entry *e) 
+{
+  int retval = 0;
+  struct export_route_entry *tmp;
+  for (tmp = add_routes; tmp; tmp = tmp->next)
+    {
+      if (tmp->type == AF_INET)
+	retval = tmp->function(e);
+    }
+  return retval;
+}
+
+int
+olsr_export_add_route6 (struct rt_entry *e) 
+{
+  int retval = 0;
+  struct export_route_entry *tmp;
+  for (tmp = add_routes; tmp; tmp = tmp->next)
+    {
+      if (tmp->type == AF_INET6)
+	retval = tmp->function(e);
+    }
+  return retval;
+}
+
+int
+olsr_export_del_route (struct rt_entry *e) 
+{
+  int retval = 0;
+  struct export_route_entry *tmp;
+  for (tmp = del_routes; tmp; tmp = tmp->next)
+    {
+      if (tmp->type == AF_INET)
+	retval = tmp->function(e);
+    }
+  return retval;
+}
+
+int
+olsr_export_del_route6 (struct rt_entry *e) 
+{
+  int retval = 0;
+  struct export_route_entry *tmp;
+  for (tmp = del_routes; tmp; tmp = tmp->next)
+    {
+      if (tmp->type == AF_INET6)
+	retval = tmp->function(e);
+    }
+  return retval;
+}
+
+
 
 int
 olsr_init_old_table()
@@ -348,9 +502,9 @@
 		    if(!olsr_cnf->host_emul)
 		      {
 			if(olsr_cnf->ip_version == AF_INET)
-			  error = olsr_ioctl_del_route(destination_ptr->destination);
+			  error = olsr_export_del_route(destination_ptr->destination);
 			else
-			  error = olsr_ioctl_del_route6(destination_ptr->destination);
+			  error = olsr_export_del_route6(destination_ptr->destination);
 			
 			if(error < 0)
 			  {
@@ -436,9 +590,9 @@
 		if(!olsr_cnf->host_emul)
 		  {
 		    if(olsr_cnf->ip_version == AF_INET)
-		      error=olsr_ioctl_add_route(destination_kernel->destination);
+		      error=olsr_export_add_route(destination_kernel->destination);
 		    else
-		      error=olsr_ioctl_add_route6(destination_kernel->destination);
+		      error=olsr_export_add_route6(destination_kernel->destination);
 		    
 		    if(error < 0)
 		      {
diff -ru olsrd-0.4.10/src/process_routes.h olsrd-0.4.10-routehandler/src/process_routes.h
--- olsrd-0.4.10/src/process_routes.h	2005-05-29 14:47:45.000000000 +0200
+++ olsrd-0.4.10-routehandler/src/process_routes.h	2006-04-18 20:53:10.711532250 +0200
@@ -50,6 +50,34 @@
 extern struct rt_entry old_routes[HASHSIZE];
 extern struct rt_entry old_hna[HASHSIZE];
 
+void
+olsr_init_export_route(void);
+
+void
+olsr_addroute_add_function(int (*)(struct rt_entry*), olsr_u8_t);
+
+int
+olsr_addroute_remove_function(int (*)(struct rt_entry*), olsr_u8_t);
+
+void
+olsr_delroute_add_function(int (*)(struct rt_entry*), olsr_u8_t);
+
+int
+olsr_delroute_remove_function(int (*)(struct rt_entry*), olsr_u8_t);
+
+int
+olsr_export_add_route (struct rt_entry*); 
+
+int
+olsr_export_del_route (struct rt_entry*); 
+
+int
+olsr_export_add_route6 (struct rt_entry*); 
+
+int
+olsr_export_del_route6 (struct rt_entry*); 
+
+
 int
 olsr_init_old_table(void);
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.olsr.org/pipermail/olsr-dev/attachments/20060420/3dd493f2/attachment.sig>


More information about the Olsr-dev mailing list