[Babel-users] Kernel metrics/route redistribution

Juliusz Chroboczek Juliusz.Chroboczek at pps.jussieu.fr
Tue Nov 2 00:15:06 UTC 2010


>> Ah.  You want the Babel network to be non-convex.  Ouch.

> I think a) giving each network disjoint sets of prefixes and b) making
> sure Babel never sees re-announcements from itself simplifies the
> problem to the point where it's workable.

The attached *completely* *untested* patch implements the two new
features that you've asked for:

 - specifying "inherit" instead of a metric in a redistribute statement
   causes the Babel metric to be 256 times the kernel priority;
 - specifying "-k inherit" on the command line causes the kernel
   priority of routes installed by Babel to be 1/256 of the Babel metric
   (rounded up).

Once again -- it's completely untested.  Even if it works, it will most
certainly cause transitory routing loops; and unless you're careful, it
will cause persistent routing loops.

This patch is not committed into the Babel tree.  If you confirm that
your idea works (and manage to convince me), I'll consider making
a cleaner version for inclusion in Babel.

                                        Juliusz
diff -rN -u old-babeld/babeld.c new-babeld/babeld.c
--- old-babeld/babeld.c	2010-11-02 01:04:16.961302822 +0100
+++ new-babeld/babeld.c	2010-11-02 01:04:16.985299783 +0100
@@ -167,9 +167,13 @@
                 goto usage;
             break;
         case 'k':
-            kernel_metric = atoi(optarg);
-            if(kernel_metric < 0 || kernel_metric > 0xFFFF)
-                goto usage;
+            if(strcmp(optarg, "inherit") == 0) {
+                kernel_metric = METRIC_INHERIT;
+            } else {
+                kernel_metric = atoi(optarg);
+                if(kernel_metric < 0 || kernel_metric > 0xFFFF)
+                    goto usage;
+            }
             break;
         case 'A':
             allow_duplicates = atoi(optarg);
diff -rN -u old-babeld/config.c new-babeld/config.c
--- old-babeld/config.c	2010-11-02 01:04:16.965300034 +0100
+++ new-babeld/config.c	2010-11-02 01:04:16.989300348 +0100
@@ -349,6 +349,8 @@
             if(metric <= 0 || metric > INFINITY)
                 goto error;
             filter->result = metric;
+        } else if(strcmp(token, "inherit") == 0) {
+            filter->result = METRIC_INHERIT;
         } else {
             goto error;
         }
@@ -675,7 +677,7 @@
 {
     int res;
     res = do_filter(input_filters, id, prefix, plen, neigh, ifindex, 0);
-    if(res < 0)
+    if(res < 0 || res == METRIC_INHERIT)
         res = 0;
     return res;
 }
@@ -686,7 +688,7 @@
 {
     int res;
     res = do_filter(output_filters, id, prefix, plen, NULL, ifindex, 0);
-    if(res < 0)
+    if(res < 0 || res == METRIC_INHERIT)
         res = 0;
     return res;
 }
diff -rN -u old-babeld/config.h new-babeld/config.h
--- old-babeld/config.h	2010-11-02 01:04:16.965300034 +0100
+++ new-babeld/config.h	2010-11-02 01:04:16.989300348 +0100
@@ -20,6 +20,8 @@
 THE SOFTWARE.
 */
 
+#define METRIC_INHERIT (INFINITY + 1)
+
 struct filter {
     int af;
     char *ifname;
diff -rN -u old-babeld/route.c new-babeld/route.c
--- old-babeld/route.c	2010-11-02 01:04:16.981299219 +0100
+++ new-babeld/route.c	2010-11-02 01:04:16.989300348 +0100
@@ -148,7 +148,13 @@
 static int
 metric_to_kernel(int metric)
 {
-    return metric < INFINITY ? kernel_metric : KERNEL_INFINITY;
+    if(metric >= INFINITY)
+        return KERNEL_INFINITY;
+
+    if(kernel_metric == METRIC_INHERIT)
+        return (metric + 255) / 256;
+    else
+        return kernel_metric;
 }
 
 void
diff -rN -u old-babeld/xroute.c new-babeld/xroute.c
--- old-babeld/xroute.c	2010-11-02 01:04:16.985299783 +0100
+++ new-babeld/xroute.c	2010-11-02 01:04:16.993302030 +0100
@@ -162,16 +162,18 @@
         export = 0;
         metric = redistribute_filter(xroutes[i].prefix, xroutes[i].plen,
                                      xroutes[i].ifindex, xroutes[i].proto);
-        if(metric < INFINITY && metric == xroutes[i].metric) {
+        if((metric < INFINITY && metric == xroutes[i].metric) ||
+           metric == METRIC_INHERIT) {
             for(j = 0; j < numroutes; j++) {
                 if(xroutes[i].plen == routes[j].plen &&
                    memcmp(xroutes[i].prefix, routes[j].prefix, 16) == 0 &&
                    xroutes[i].ifindex == routes[j].ifindex &&
                    xroutes[i].proto == routes[j].proto) {
-                    if(metric < INFINITY) {
+                    if(metric < INFINITY ||
+                       (metric == METRIC_INHERIT &&
+                        xroutes[i].metric == routes[j].metric * 256))
                         export = 1;
                         break;
-                    }
                 }
             }
         }
@@ -202,6 +204,8 @@
             continue;
         metric = redistribute_filter(routes[i].prefix, routes[i].plen,
                                      routes[i].ifindex, routes[i].proto);
+        if(metric == METRIC_INHERIT)
+            metric = routes[i].metric * 256;
         if(metric < INFINITY) {
             rc = add_xroute(routes[i].prefix, routes[i].plen,
                             metric, routes[i].ifindex, routes[i].proto);



More information about the Babel-users mailing list