Line 0
Link Here
|
|
|
1 |
diff -urN sysdep/bsd/Modules sysdep/bsd/Modules |
2 |
--- sysdep/bsd/Modules 2011-03-31 12:29:42.000000000 +0400 |
3 |
+++ sysdep/bsd/Modules 2011-05-10 12:04:30.643950460 +0400 |
4 |
@@ -4,3 +4,4 @@ |
5 |
krt-set.h |
6 |
krt-sock.c |
7 |
krt-sock.h |
8 |
+fib.Y |
9 |
diff -urN sysdep/bsd/fib.Y sysdep/bsd/fib.Y |
10 |
--- sysdep/bsd/fib.Y 1970-01-01 03:00:00.000000000 +0300 |
11 |
+++ sysdep/bsd/fib.Y 2011-05-10 12:04:05.724272679 +0400 |
12 |
@@ -0,0 +1,29 @@ |
13 |
+/* |
14 |
+ * BIRD -- FreeBSD rtsock configuration |
15 |
+ * |
16 |
+ * (c) 2011 Alexander V. Chernikov |
17 |
+ * |
18 |
+ * Can be freely distributed and used under the terms of the GNU GPL. |
19 |
+ */ |
20 |
+ |
21 |
+CF_HDR |
22 |
+ |
23 |
+CF_DECLS |
24 |
+ |
25 |
+CF_KEYWORDS(ASYNC, KERNEL, TABLE, KRT_PREFSRC, KRT_REALM) |
26 |
+ |
27 |
+CF_GRAMMAR |
28 |
+ |
29 |
+CF_ADDTO(kern_proto, kern_proto rtsock_item ';') |
30 |
+ |
31 |
+rtsock_item: |
32 |
+ KERNEL TABLE expr { |
33 |
+ if ($3 <= 0 || $3 >= max_fib_num()) |
34 |
+ cf_error("Kernel routing table number out of range"); |
35 |
+ THIS_KRT->scan.table_id = $3; |
36 |
+ } |
37 |
+ ; |
38 |
+ |
39 |
+CF_CODE |
40 |
+ |
41 |
+CF_END |
42 |
diff -urN sysdep/bsd/krt-scan.h sysdep/bsd/krt-scan.h |
43 |
--- sysdep/bsd/krt-scan.h 2011-03-31 12:29:42.000000000 +0400 |
44 |
+++ sysdep/bsd/krt-scan.h 2011-05-10 11:58:54.812942887 +0400 |
45 |
@@ -10,6 +10,7 @@ |
46 |
#define _BIRD_KRT_SCAN_H_ |
47 |
|
48 |
struct krt_scan_params { |
49 |
+ int table_id; /* Kernel table ID we sync with */ |
50 |
}; |
51 |
|
52 |
struct krt_scan_status { |
53 |
diff -urN sysdep/bsd/krt-sock.c sysdep/bsd/krt-sock.c |
54 |
--- sysdep/bsd/krt-sock.c 2011-05-02 12:13:18.000000000 +0400 |
55 |
+++ sysdep/bsd/krt-sock.c 2011-05-10 12:25:22.075267568 +0400 |
56 |
@@ -53,6 +53,21 @@ |
57 |
); |
58 |
} |
59 |
|
60 |
+int |
61 |
+max_fib_num() |
62 |
+{ |
63 |
+ int fibs = 1; |
64 |
+ size_t fibs_len = sizeof(fibs); |
65 |
+ if (sysctlbyname("net.fibs", &fibs, &fibs_len, NULL, 0) == -1) |
66 |
+ { |
67 |
+ log(L_ERR "KRT: unable to get fib number, assuming 1. error: %s", strerror(errno)); |
68 |
+ return 1; |
69 |
+ } |
70 |
+ |
71 |
+ log(L_TRACE "Max fibs: %d\n", fibs); |
72 |
+ return fibs; |
73 |
+} |
74 |
+ |
75 |
#define ROUNDUP(a) \ |
76 |
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) |
77 |
|
78 |
@@ -219,6 +234,7 @@ |
79 |
{ |
80 |
sock *sk_rt; |
81 |
static int ks_open_tried = 0; |
82 |
+ int fib = 0; |
83 |
|
84 |
if (ks_open_tried) |
85 |
return; |
86 |
@@ -230,6 +246,16 @@ |
87 |
if( (rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0) |
88 |
die("Cannot open kernel socket for routes"); |
89 |
|
90 |
+ fib = ((struct krt_config *)x)->scan.table_id; |
91 |
+ log(L_TRACE "KRT: Setting fib %d", fib); |
92 |
+ |
93 |
+ |
94 |
+ if ((fib != 0) && (setsockopt(rt_sock, SOL_SOCKET, SO_SETFIB, &fib, sizeof(fib)) == -1)) |
95 |
+ { |
96 |
+ log(L_ERR "KRT: setsockopt() failed for socket %d: %s", rt_sock, strerror(errno)); |
97 |
+ die("Cannot set fib for kernel socket"); |
98 |
+ } |
99 |
+ |
100 |
sk_rt = sk_new(krt_pool); |
101 |
sk_rt->type = SK_MAGIC; |
102 |
sk_rt->rx_hook = krt_set_hook; |
103 |
diff -urN sysdep/cf/bsd-v6.h sysdep/cf/bsd-v6.h |
104 |
--- sysdep/cf/bsd-v6.h 2011-03-31 12:29:42.000000000 +0400 |
105 |
+++ sysdep/cf/bsd-v6.h 2011-05-10 11:19:01.394166479 +0400 |
106 |
@@ -10,7 +10,7 @@ |
107 |
|
108 |
#define CONFIG_AUTO_ROUTES |
109 |
#define CONFIG_SELF_CONSCIOUS |
110 |
-#undef CONFIG_MULTIPLE_TABLES |
111 |
+#define CONFIG_MULTIPLE_TABLES |
112 |
|
113 |
#undef CONFIG_UNIX_IFACE |
114 |
#undef CONFIG_UNIX_SET |
115 |
diff -urN sysdep/cf/bsd.h sysdep/cf/bsd.h |
116 |
--- sysdep/cf/bsd.h 2011-03-31 12:29:42.000000000 +0400 |
117 |
+++ sysdep/cf/bsd.h 2011-05-10 11:19:01.398182352 +0400 |
118 |
@@ -8,7 +8,7 @@ |
119 |
|
120 |
#define CONFIG_AUTO_ROUTES |
121 |
#define CONFIG_SELF_CONSCIOUS |
122 |
-#undef CONFIG_MULTIPLE_TABLES |
123 |
+#define CONFIG_MULTIPLE_TABLES |
124 |
|
125 |
#undef CONFIG_UNIX_IFACE |
126 |
#undef CONFIG_UNIX_SET |