[Olsr-dev] ignore Route exists and no such process

Markus Kittenberger (spam-protected)
Sun Dec 21 13:20:16 CET 2008


Hi

I just wrote a simple (but os-independent) plugin for inserting missing
routes into kernel,..

This one is os-independent, and just inserts all routes at a configureable
interval

I also plan another plugin (route_mon) using rtnetlink broadcast messages,
to react immediately on extrenal route deletions,..

while writing the plugin i also patched the linux specific parts of kernel
route processing, handling "File exists" and "No such process" for the
current olsr code completely similar to successful insertions/deletions, and
providing return valöues to distinguish between if needed,..

any comments?

is it ok to push it to tip (together with my plugin, which relies (only for
meaningful syslog/debugoutput) on the new return values of
olsrd_add_route())

curent code of the simple plugin is here 193.238.157.18/~markus/route_check

Markus

diff -r 71bcb86ad5ca src/linux/kernel_routes.c
--- a/src/linux/kernel_routes.c Sat Dec 20 19:24:59 2008 +0100
+++ b/src/linux/kernel_routes.c Sun Dec 21 12:54:56 2008 +0100
@@ -62,6 +62,7 @@
  memcpy(RTA_DATA(rta), data, len);
 }

+/* retrun -1 on error, 0 file exists/no such process and > 0 on successful
change of kernel tables)*/
 static int olsr_netlink_route(const struct rt_entry *rt, uint8_t family,
uint8_t rttable, __u16 cmd)
 {
  int ret = 0;
@@ -131,8 +132,17 @@
  if (NLMSG_ERROR == h->nlmsg_type) {
  if (NLMSG_LENGTH(sizeof(struct nlmsgerr) <= h->nlmsg_len)) {
  const struct nlmsgerr *l_err = (struct nlmsgerr*)NLMSG_DATA(h);
+ /* interprete 17=fileexists as successful! */
  errno = -l_err->error;
- if (0 != errno) {
+ /* report success on already exist */
+ if ((errno == 17) & (cmd == RTM_NEWROUTE)) {
+ ret = 0;
+ }
+ /* report success on No such process*/
+ else if ((errno == 3) & (cmd == RTM_DELROUTE)) {
+ ret = 0;
+ }
+ else if (0 != errno) {
  ret = -1;
  }
diff -r 71bcb86ad5ca src/process_routes.c
--- a/src/process_routes.c Sat Dec 20 19:24:59 2008 +0100
+++ b/src/process_routes.c Sun Dec 21 12:54:56 2008 +0100
@@ -178,9 +178,9 @@
 /**
  * Process a route from the kernel addition list.
  *
- *@return nada
+ *@ return 1 on successfull addition, 0 on file exists, -1 on kernel error,
-2 on no ioctl
  */
-static void
+int16_t
 olsr_add_kernel_route(struct rt_entry *rt)
 {

@@ -191,9 +191,11 @@
  if(error < 0) {
  const char * const err_msg = strerror(errno);
  const char * const routestr = olsr_rtp_to_string(rt->rt_best);
+ /*print error message if different to File Exists (if warn_on_existing is
true)*/
  OLSR_PRINTF(1, "KERN: ERROR adding %s: %s\n", routestr, err_msg);

  olsr_syslog(OLSR_LOG_ERR, "Add route %s: %s", routestr, err_msg);
+ return -1;
  } else {

  /* route addition has suceeded */
@@ -205,7 +207,9 @@
  /* lock the interface such that it does not vanish underneath us */
  lock_interface(rt->rt_nexthop.interface);
  }
+ return error;
  }
+ return -2;
 }

 /**
diff -r 71bcb86ad5ca src/process_routes.h
--- a/src/process_routes.h Sat Dec 20 19:24:59 2008 +0100
+++ b/src/process_routes.h Sun Dec 21 12:54:56 2008 +0100
@@ -56,7 +56,7 @@
 void olsr_update_kernel_routes(void);
 void olsr_delete_all_kernel_routes(void);
 uint8_t olsr_rt_flags(const struct rt_entry *);
-
+int16_t olsr_add_kernel_route(struct rt_entry *);
 #endif

 /*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.olsr.org/pipermail/olsr-dev/attachments/20081221/c74c837a/attachment.html>


More information about the Olsr-dev mailing list