misc/157001: [PATCH] net/bird: add multiple fibs support
Alexander V. Chernikov
melifaro at ipfw.ru
Fri May 13 10:40:04 UTC 2011
>Number: 157001
>Category: misc
>Synopsis: [PATCH] net/bird: add multiple fibs support
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri May 13 10:40:03 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Alexander V. Chernikov
>Release: FreeBSD 8.2-STABLE
>Organization:
JSC "Meganet"
>Environment:
FreeBSD silicium.meganet.ru 8.2-STABLE FreeBSD 8.2-STABLE #1: Mon Apr 18 18:22:06 MSD 2011 root at silicium.meganet.ru:/usr/obj/usr/src/sys/ROUTER amd64
>Description:
Changelog:
* Add FIBS option enabling multiple fibs support
* Add LEARN_FIX option enabling simultaneous operation of different routing software
* Update to 1.3.1
fibs.diff:
this patch shouldn't be taken into upstream, our routing protocol (rtsock) should be changed to support multiple fibs via single socket. However, for "here and now" situation this patch can be placed into a port.
learn-krt-sock.c:
by default, bird considers IFF_FLAG1 routes (e.g. all dynamic installed, for example, by quagga) as own incorrectly installed routes and deletes them. This is default behavior for all *BSD systems since rtsock doesn't support some kind of installer identification (caller process pid). This patch makes bird consider all such routes as any other (non-directly connected) kernel routes.
Problems can arise if used with "persist" kernel option (bird will not delete such routes after restart and IGP link-up)
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
diff -urN net/bird/Makefile net/bird.new/Makefile
--- net/bird/Makefile 2011-04-12 21:52:18.000000000 +0400
+++ net/bird.new/Makefile 2011-05-13 12:59:07.639973965 +0400
@@ -6,7 +6,7 @@
#
PORTNAME= bird
-PORTVERSION= 1.3.0
+PORTVERSION= 1.3.1
CATEGORIES= net
MASTER_SITES= ftp://bird.network.cz/pub/bird/
@@ -17,13 +17,26 @@
USE_GMAKE= yes
GNU_CONFIGURE= yes
+OPTIONS= FIBS "Enable multiple fib support" Off \
+ LEARN_FIX "Support multiple routing daemons" Off
+
MAKE_JOBS_UNSAFE= yes
USE_RC_SUBR= bird
+.include <bsd.port.pre.mk>
+
+.if defined(WITH_FIBS)
+EXTRA_PATCHES+= ${FILESDIR}/fibs.diff
+.endif
+
+.if defined(WITH_LEARN_FIX)
+EXTRA_PATCHES+= ${FILESDIR}/learn-krt-sock.c
+.endif
+
post-install:
@if [ ! -f ${PREFIX}/etc/bird.conf ]; then \
${CP} -p ${PREFIX}/etc/bird.conf.example ${PREFIX}/etc/bird.conf ; \
fi
-.include <bsd.port.mk>
+.include <bsd.port.post.mk>
diff -urN net/bird/distinfo net/bird.new/distinfo
--- net/bird/distinfo 2011-04-12 21:52:18.000000000 +0400
+++ net/bird.new/distinfo 2011-05-10 13:32:38.378103543 +0400
@@ -1,2 +1,2 @@
-SHA256 (bird-1.3.0.tar.gz) = ff90e3ee115a83e2b03a57095132923f66e1fca874dcca7a908075b6c2dc84b3
-SIZE (bird-1.3.0.tar.gz) = 735100
+SHA256 (bird-1.3.1.tar.gz) = 848be209aba6a1a85ae0ed6192710f8bcc2f1257068191fe2959398cdec01afb
+SIZE (bird-1.3.1.tar.gz) = 826422
diff -urN net/bird/files/fibs.diff net/bird.new/files/fibs.diff
--- net/bird/files/fibs.diff 1970-01-01 03:00:00.000000000 +0300
+++ net/bird.new/files/fibs.diff 2011-05-10 13:32:09.407955382 +0400
@@ -0,0 +1,126 @@
+diff -urN sysdep/bsd/Modules sysdep/bsd/Modules
+--- sysdep/bsd/Modules 2011-03-31 12:29:42.000000000 +0400
++++ sysdep/bsd/Modules 2011-05-10 12:04:30.643950460 +0400
+@@ -4,3 +4,4 @@
+ krt-set.h
+ krt-sock.c
+ krt-sock.h
++fib.Y
+diff -urN sysdep/bsd/fib.Y sysdep/bsd/fib.Y
+--- sysdep/bsd/fib.Y 1970-01-01 03:00:00.000000000 +0300
++++ sysdep/bsd/fib.Y 2011-05-10 12:04:05.724272679 +0400
+@@ -0,0 +1,29 @@
++/*
++ * BIRD -- FreeBSD rtsock configuration
++ *
++ * (c) 2011 Alexander V. Chernikov
++ *
++ * Can be freely distributed and used under the terms of the GNU GPL.
++ */
++
++CF_HDR
++
++CF_DECLS
++
++CF_KEYWORDS(ASYNC, KERNEL, TABLE, KRT_PREFSRC, KRT_REALM)
++
++CF_GRAMMAR
++
++CF_ADDTO(kern_proto, kern_proto rtsock_item ';')
++
++rtsock_item:
++ KERNEL TABLE expr {
++ if ($3 <= 0 || $3 >= max_fib_num())
++ cf_error("Kernel routing table number out of range");
++ THIS_KRT->scan.table_id = $3;
++ }
++ ;
++
++CF_CODE
++
++CF_END
+diff -urN sysdep/bsd/krt-scan.h sysdep/bsd/krt-scan.h
+--- sysdep/bsd/krt-scan.h 2011-03-31 12:29:42.000000000 +0400
++++ sysdep/bsd/krt-scan.h 2011-05-10 11:58:54.812942887 +0400
+@@ -10,6 +10,7 @@
+ #define _BIRD_KRT_SCAN_H_
+
+ struct krt_scan_params {
++ int table_id; /* Kernel table ID we sync with */
+ };
+
+ struct krt_scan_status {
+diff -urN sysdep/bsd/krt-sock.c sysdep/bsd/krt-sock.c
+--- sysdep/bsd/krt-sock.c 2011-05-02 12:13:18.000000000 +0400
++++ sysdep/bsd/krt-sock.c 2011-05-10 12:25:22.075267568 +0400
+@@ -53,6 +53,21 @@
+ );
+ }
+
++int
++max_fib_num()
++{
++ int fibs = 1;
++ size_t fibs_len = sizeof(fibs);
++ if (sysctlbyname("net.fibs", &fibs, &fibs_len, NULL, 0) == -1)
++ {
++ log(L_ERR "KRT: unable to get fib number, assuming 1. error: %s", strerror(errno));
++ return 1;
++ }
++
++ log(L_TRACE "Max fibs: %d\n", fibs);
++ return fibs;
++}
++
+ #define ROUNDUP(a) \
+ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+
+@@ -219,6 +234,7 @@
+ {
+ sock *sk_rt;
+ static int ks_open_tried = 0;
++ int fib = 0;
+
+ if (ks_open_tried)
+ return;
+@@ -230,6 +246,16 @@
+ if( (rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0)
+ die("Cannot open kernel socket for routes");
+
++ fib = ((struct krt_config *)x)->scan.table_id;
++ log(L_TRACE "KRT: Setting fib %d", fib);
++
++
++ if ((fib != 0) && (setsockopt(rt_sock, SOL_SOCKET, SO_SETFIB, &fib, sizeof(fib)) == -1))
++ {
++ log(L_ERR "KRT: setsockopt() failed for socket %d: %s", rt_sock, strerror(errno));
++ die("Cannot set fib for kernel socket");
++ }
++
+ sk_rt = sk_new(krt_pool);
+ sk_rt->type = SK_MAGIC;
+ sk_rt->rx_hook = krt_set_hook;
+diff -urN sysdep/cf/bsd-v6.h sysdep/cf/bsd-v6.h
+--- sysdep/cf/bsd-v6.h 2011-03-31 12:29:42.000000000 +0400
++++ sysdep/cf/bsd-v6.h 2011-05-10 11:19:01.394166479 +0400
+@@ -10,7 +10,7 @@
+
+ #define CONFIG_AUTO_ROUTES
+ #define CONFIG_SELF_CONSCIOUS
+-#undef CONFIG_MULTIPLE_TABLES
++#define CONFIG_MULTIPLE_TABLES
+
+ #undef CONFIG_UNIX_IFACE
+ #undef CONFIG_UNIX_SET
+diff -urN sysdep/cf/bsd.h sysdep/cf/bsd.h
+--- sysdep/cf/bsd.h 2011-03-31 12:29:42.000000000 +0400
++++ sysdep/cf/bsd.h 2011-05-10 11:19:01.398182352 +0400
+@@ -8,7 +8,7 @@
+
+ #define CONFIG_AUTO_ROUTES
+ #define CONFIG_SELF_CONSCIOUS
+-#undef CONFIG_MULTIPLE_TABLES
++#define CONFIG_MULTIPLE_TABLES
+
+ #undef CONFIG_UNIX_IFACE
+ #undef CONFIG_UNIX_SET
diff -urN net/bird/files/learn-krt-sock.c net/bird.new/files/learn-krt-sock.c
--- net/bird/files/learn-krt-sock.c 1970-01-01 03:00:00.000000000 +0300
+++ net/bird.new/files/learn-krt-sock.c 2011-05-11 10:43:24.587310296 +0400
@@ -0,0 +1,11 @@
+--- sysdep/bsd/krt-sock.c.orig 2011-05-11 10:41:35.432219356 +0400
++++ sysdep/bsd/krt-sock.c 2011-05-11 10:42:02.483875083 +0400
+@@ -320,7 +320,7 @@
+ if ((flags & RTF_GATEWAY) && ipa_zero(igate))
+ { log(L_ERR "%s (%I/%d) - missing gateway", errmsg, idst, pxlen); return; }
+
+- u32 self_mask = RTF_PROTO1;
++ u32 self_mask = 0;
+ u32 alien_mask = RTF_STATIC | RTF_PROTO1 | RTF_GATEWAY;
+
+ #ifdef RTF_PROTO2
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list