View | Details | Raw Unified | Return to bug 157645
Collapse All | Expand All

(-)bird/Makefile (-3 / +15 lines)
Lines 7-12 Link Here
7
7
8
PORTNAME=	bird
8
PORTNAME=	bird
9
PORTVERSION=	1.3.1
9
PORTVERSION=	1.3.1
10
PORTREVISION=	1
10
CATEGORIES=	net
11
CATEGORIES=	net
11
MASTER_SITES=	ftp://bird.network.cz/pub/bird/
12
MASTER_SITES=	ftp://bird.network.cz/pub/bird/
12
13
Lines 18-24 Link Here
18
GNU_CONFIGURE=	yes
19
GNU_CONFIGURE=	yes
19
20
20
OPTIONS=	FIBS		"Enable multiple fib support" Off \
21
OPTIONS=	FIBS		"Enable multiple fib support" Off \
21
		LEARN_FIX	"Support multiple routing daemons" Off
22
		CONFIG_INCLUDES	"Permit config 'include' keyword" Off
22
23
23
MAKE_JOBS_UNSAFE=	yes
24
MAKE_JOBS_UNSAFE=	yes
24
25
Lines 30-42 Link Here
30
EXTRA_PATCHES+=	${FILESDIR}/fibs.diff
31
EXTRA_PATCHES+=	${FILESDIR}/fibs.diff
31
.endif
32
.endif
32
33
33
.if defined(WITH_LEARN_FIX)
34
.if defined(WITH_CONFIG_INCLUDES)
34
EXTRA_PATCHES+=	${FILESDIR}/learn-krt-sock.c
35
EXTRA_PATCHES+=	${FILESDIR}/config_includes.diff
35
.endif
36
.endif
36
37
37
post-install:
38
post-install:
38
	@if [ ! -f ${PREFIX}/etc/bird.conf ]; then \
39
	@if [ ! -f ${PREFIX}/etc/bird.conf ]; then \
39
		${CP} -p ${PREFIX}/etc/bird.conf.example ${PREFIX}/etc/bird.conf ; \
40
		${CP} -p ${PREFIX}/etc/bird.conf.example ${PREFIX}/etc/bird.conf ; \
41
		${CHMOD} 0640 ${PREFIX}/etc/bird.conf ; \
40
	fi
42
	fi
43
.if defined(WITH_FIBS)
44
	@${ECHO_MSG}
45
	@${ECHO_MSG} =====================================================================
46
	@${ECHO_MSG}
47
	@${ECHO_MSG} "        WARNING: Please take a look on kern/134931"
48
	@${ECHO_MSG} "        WARNING: before using multiple fibs in production!"
49
	@${ECHO_MSG}
50
	@${ECHO_MSG} =====================================================================
51
	@${ECHO_MSG}
52
.endif
41
53
42
.include <bsd.port.post.mk>
54
.include <bsd.port.post.mk>
(-)bird/files/config_includes.diff (+302 lines)
Line 0 Link Here
1
Index: conf/conf.c
2
===================================================================
3
--- conf/conf.c	(revision 4873)
4
+++ conf/conf.c	(revision 4875)
5
@@ -108,7 +108,7 @@
6
   cfg_mem = c->mem;
7
   if (setjmp(conf_jmpbuf))
8
     return 0;
9
-  cf_lex_init(0);
10
+  cf_lex_init(c, 0);
11
   sysdep_preconfig(c);
12
   protos_preconfig(c);
13
   rt_preconfig(c);
14
@@ -138,7 +138,7 @@
15
   cfg_mem = c->mem;
16
   if (setjmp(conf_jmpbuf))
17
     return 0;
18
-  cf_lex_init(1);
19
+  cf_lex_init(c, 1);
20
   cf_parse();
21
   return 1;
22
 }
23
@@ -356,6 +356,7 @@
24
     strcpy(buf, "<bug: error message too long>");
25
   new_config->err_msg = cfg_strdup(buf);
26
   new_config->err_lino = conf_lino;
27
+  new_config->err_fname = conf_fname;
28
   longjmp(conf_jmpbuf, 1);
29
 }
30
 
31
Index: conf/cf-lex.l
32
===================================================================
33
--- conf/cf-lex.l	(revision 4873)
34
+++ conf/cf-lex.l	(revision 4875)
35
@@ -30,6 +30,9 @@
36
 #include <errno.h>
37
 #include <stdlib.h>
38
 #include <stdarg.h>
39
+#include <unistd.h>
40
+#include <fcntl.h>
41
+#include <libgen.h>
42
 
43
 #define PARSER 1
44
 
45
@@ -64,18 +67,36 @@
46
 static struct sym_scope *conf_this_scope;
47
 
48
 int conf_lino;
49
+char conf_fname[255];
50
+int conf_fd;
51
 
52
+char conf_base[255];
53
+
54
 static int cf_hash(byte *c);
55
 static struct symbol *cf_find_sym(byte *c, unsigned int h0);
56
 
57
 linpool *cfg_mem;
58
 
59
-int (*cf_read_hook)(byte *buf, unsigned int max);
60
+int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
61
 
62
-#define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max);
63
-#define YY_NO_UNPUT
64
+#define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max, STACK(conf_fd));
65
 #define YY_FATAL_ERROR(msg) cf_error(msg)
66
 
67
+#define MAX_INCLUDE_DEPTH	42
68
+struct include_file_stack {
69
+	YY_BUFFER_STATE	stack; /* Internal lexer state */
70
+	unsigned int	conf_lino; /* Current file lineno (at include) */
71
+	char		conf_fname[255]; /* Current file name */
72
+	int		conf_fd; /* Current file descriptor */
73
+};
74
+
75
+static struct include_file_stack ifs[MAX_INCLUDE_DEPTH];
76
+static int ifs_ind; /* Current stack depth */
77
+#define STACK(x)	ifs[ifs_ind].x
78
+
79
+static void dispatch_include(void);
80
+static int check_eof(void);
81
+
82
 %}
83
 
84
 %option noyywrap
85
@@ -90,9 +111,12 @@
86
 XIGIT [0-9a-fA-F]
87
 ALNUM [a-zA-Z_0-9]
88
 WHITE [ \t]
89
+include   ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
90
 
91
 %%
92
 
93
+{include} { dispatch_include(); }
94
+
95
 {DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+ {
96
 #ifdef IPV6
97
   if (ipv4_pton_u32(yytext, &cf_lval.i32))
98
@@ -184,7 +208,7 @@
99
 
100
 ["][^"\n]*\n	cf_error("Unterminated string");
101
 
102
-<INITIAL,COMMENT><<EOF>>	return END;
103
+<INITIAL,COMMENT><<EOF>>	{ if (check_eof()) return END; }
104
 
105
 {WHITE}+
106
 
107
@@ -220,7 +244,67 @@
108
 
109
 %%
110
 
111
+/* Open included file with properly swapped buffers */
112
+static void
113
+dispatch_include(void)
114
+{
115
+	char *fname, *p = NULL, full_name[255];
116
+	int fd;
117
+
118
+	if ((fname = strchr(yytext, '"')) != NULL) {
119
+		if ((p = strchr(++fname, '"')) != NULL)
120
+			*p = '\0';
121
+
122
+		if (*fname == '/')
123
+			snprintf(full_name, sizeof(full_name), "%s", fname);
124
+		else
125
+			snprintf(full_name, sizeof(full_name), "%s/%s", conf_base, fname);
126
+
127
+		if (ifs_ind >= MAX_INCLUDE_DEPTH)
128
+			cf_error("Max include depth (%d) reached on file %s", MAX_INCLUDE_DEPTH, fname);
129
+
130
+		if ((fd = open(full_name, O_RDONLY)) == -1)
131
+			cf_error("Error opening included file %s", full_name);
132
+
133
+		/* Save current stack */
134
+		STACK(conf_lino) = conf_lino;
135
+		STACK(stack) = YY_CURRENT_BUFFER;
136
+		/* Prepare new stack */
137
+		ifs_ind++;
138
+		STACK(conf_lino) = 1;
139
+		strcpy(STACK(conf_fname), fname); /* XXX: strlcpy should be here */
140
+		STACK(conf_fd) = fd;
141
+		/* Export to global variables */
142
+		conf_lino = STACK(conf_lino);
143
+		conf_fd = STACK(conf_fd);
144
+		strcpy(conf_fname, STACK(conf_fname));
145
+
146
+		yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
147
+	}
148
+}
149
+
150
 static int
151
+check_eof(void)
152
+{
153
+	if (ifs_ind > 0)
154
+		close(STACK(conf_fd));
155
+	if (--ifs_ind < 0) {
156
+		/* EOF in main config file */
157
+		ifs_ind = 0;
158
+		conf_lino = 1;
159
+		return 1;
160
+	}
161
+
162
+	/* switch buffer */
163
+	conf_lino = STACK(conf_lino);
164
+	conf_fd = STACK(conf_fd);
165
+	strcpy(conf_fname, STACK(conf_fname));
166
+	yy_delete_buffer(YY_CURRENT_BUFFER);
167
+	yy_switch_to_buffer(STACK(stack));
168
+	return 0;
169
+}
170
+
171
+static int
172
 cf_hash(byte *c)
173
 {
174
   unsigned int h = 13;
175
@@ -363,11 +447,28 @@
176
  * parsing of a new input.
177
  */
178
 void
179
-cf_lex_init(int is_cli)
180
+cf_lex_init(struct config *c, int is_cli)
181
 {
182
   if (!kw_hash_inited)
183
     cf_lex_init_kh();
184
   conf_lino = 1;
185
+  /* Zero stack */
186
+  memset(ifs, 0, sizeof(ifs));
187
+  memset(conf_base, 0, sizeof(conf_base));
188
+  ifs_ind = 0;
189
+  if (!is_cli) {
190
+    /* Fill in level 0 */
191
+    STACK(conf_lino) = 1;
192
+    STACK(conf_fd) = c->file_fd;
193
+    strcpy(STACK(conf_fname), c->file_name);
194
+    /* Save config directory path */
195
+    strcpy(conf_base, dirname(STACK(conf_fname)));
196
+  }
197
+  /* Export to global variables */
198
+  conf_lino = STACK(conf_lino);
199
+  conf_fd = STACK(conf_fd);
200
+  strcpy(conf_fname, STACK(conf_fname));
201
+
202
   yyrestart(NULL);
203
   if (is_cli)
204
     BEGIN(CLI);
205
Index: conf/conf.h
206
===================================================================
207
--- conf/conf.h	(revision 4873)
208
+++ conf/conf.h	(revision 4875)
209
@@ -38,7 +38,9 @@
210
   int cli_debug;			/* Tracing of CLI connections and commands */
211
   char *err_msg;			/* Parser error message */
212
   int err_lino;				/* Line containing error */
213
+  char *err_fname;			/* File name containing error */
214
   char *file_name;			/* Name of configuration file */
215
+  int file_fd;				/* Config file descriptor */
216
   struct symbol **sym_hash;		/* Lexer: symbol hash table */
217
   struct symbol **sym_fallback;		/* Lexer: fallback symbol hash table */
218
   int obstacle_count;			/* Number of items blocking freeing of this config */
219
@@ -83,7 +85,7 @@
220
 
221
 /* Lexer */
222
 
223
-extern int (*cf_read_hook)(byte *buf, unsigned int max);
224
+extern int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
225
 
226
 struct symbol {
227
   struct symbol *next;
228
@@ -107,9 +109,10 @@
229
 #define SYM_VARIABLE 0x100	/* 0x100-0x1ff are variable types */
230
 
231
 extern int conf_lino;
232
+extern char conf_fname[255];
233
 
234
 int cf_lex(void);
235
-void cf_lex_init(int is_cli);
236
+void cf_lex_init(struct config *c, int is_cli);
237
 struct symbol *cf_find_symbol(byte *c);
238
 struct symbol *cf_default_name(char *template, int *counter);
239
 struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def);
240
Index: doc/bird.conf.example
241
===================================================================
242
--- doc/bird.conf.example	(revision 4873)
243
+++ doc/bird.conf.example	(revision 4875)
244
@@ -22,6 +22,9 @@
245
 #	else reject;
246
 #}
247
 
248
+# Write more filters in included config file(s):
249
+#include "filters.conf";
250
+
251
 #filter sink { reject; }
252
 #filter okay { accept; }
253
 
254
Index: sysdep/unix/main.c
255
===================================================================
256
--- sysdep/unix/main.c	(revision 4873)
257
+++ sysdep/unix/main.c	(revision 4875)
258
@@ -122,13 +122,12 @@
259
 #endif // PATH_IPROUTE_DIR
260
 
261
 
262
-static int conf_fd;
263
 static char *config_name = PATH_CONFIG;
264
 
265
 static int
266
-cf_read(byte *dest, unsigned int len)
267
+cf_read(byte *dest, unsigned int len, int fd)
268
 {
269
-  int l = read(conf_fd, dest, len);
270
+  int l = read(fd, dest, len);
271
   if (l < 0)
272
     cf_error("Read error");
273
   return l;
274
@@ -158,15 +157,15 @@
275
 unix_read_config(struct config **cp, char *name)
276
 {
277
   struct config *conf = config_alloc(name);
278
-  int ret;
279
+  int ret, fd;
280
 
281
   *cp = conf;
282
-  conf_fd = open(name, O_RDONLY);
283
-  if (conf_fd < 0)
284
+  if ((fd = open(name, O_RDONLY)) == -1)
285
     return 0;
286
+  conf->file_fd = fd;
287
   cf_read_hook = cf_read;
288
   ret = config_parse(conf);
289
-  close(conf_fd);
290
+  close(fd);
291
   return ret;
292
 }
293
 
294
@@ -178,7 +177,7 @@
295
   if (!unix_read_config(&conf, config_name))
296
     {
297
       if (conf->err_msg)
298
-	die("%s, line %d: %s", config_name, conf->err_lino, conf->err_msg);
299
+	die("%s, line %d: %s", conf->err_fname, conf->err_lino, conf->err_msg);
300
       else
301
 	die("Unable to open configuration file %s: %m", config_name);
302
     }
(-)bird/files/fibs.diff (-42 / +209 lines)
Lines 1-14 Link Here
1
diff -urN sysdep/bsd/Modules sysdep/bsd/Modules
1
Index: sysdep/unix/krt.h
2
--- sysdep/bsd/Modules	2011-03-31 12:29:42.000000000 +0400
2
===================================================================
3
+++ sysdep/bsd/Modules	2011-05-10 12:04:30.643950460 +0400
3
--- sysdep/unix/krt.h	(revision 4869)
4
@@ -4,3 +4,4 @@
4
+++ sysdep/unix/krt.h	(working copy)
5
 krt-set.h
5
@@ -67,6 +67,7 @@
6
 krt-sock.c
6
 #ifdef CONFIG_ALL_TABLES_AT_ONCE
7
 krt-sock.h
7
   node instance_node;		/* Node in krt instance list */
8
+fib.Y
8
 #endif
9
diff -urN sysdep/bsd/fib.Y sysdep/bsd/fib.Y
9
+  int rt_sock;			/* Routing socket descriptor */
10
--- sysdep/bsd/fib.Y	1970-01-01 03:00:00.000000000 +0300
10
   int initialized;		/* First scan has already been finished */
11
+++ sysdep/bsd/fib.Y	2011-05-10 12:04:05.724272679 +0400
11
 };
12
 
13
Index: sysdep/bsd/krt-sock.h
14
===================================================================
15
--- sysdep/bsd/krt-sock.h	(revision 4869)
16
+++ sysdep/bsd/krt-sock.h	(working copy)
17
@@ -42,5 +42,8 @@
18
 
19
 static inline int krt_set_params_same(struct krt_set_params *o UNUSED, struct krt_set_params *n UNUSED) { return 1; }
20
 void krt_read_msg(struct proto *p, struct ks_msg *msg, int scan);
21
+int max_fib_num(void);
22
+int my_fib_get(void);
23
+int my_fib_set(int fib);
24
 
25
 #endif
26
Index: sysdep/bsd/fib.Y
27
===================================================================
28
--- sysdep/bsd/fib.Y	(revision 0)
29
+++ sysdep/bsd/fib.Y	(revision 0)
12
@@ -0,0 +1,29 @@
30
@@ -0,0 +1,29 @@
13
+/*
31
+/*
14
+ *	BIRD -- FreeBSD rtsock configuration
32
+ *	BIRD -- FreeBSD rtsock configuration
Lines 30-36 Link Here
30
+
48
+
31
+rtsock_item:
49
+rtsock_item:
32
+   KERNEL TABLE expr {
50
+   KERNEL TABLE expr {
33
+	if ($3 <= 0 || $3 >= max_fib_num())
51
+	if ($3 < 0 || $3 >= max_fib_num())
34
+	  cf_error("Kernel routing table number out of range");
52
+	  cf_error("Kernel routing table number out of range");
35
+	THIS_KRT->scan.table_id = $3;
53
+	THIS_KRT->scan.table_id = $3;
36
+   }
54
+   }
Lines 39-47 Link Here
39
+CF_CODE
57
+CF_CODE
40
+
58
+
41
+CF_END
59
+CF_END
42
diff -urN sysdep/bsd/krt-scan.h sysdep/bsd/krt-scan.h
60
Index: sysdep/bsd/Modules
43
--- sysdep/bsd/krt-scan.h	2011-03-31 12:29:42.000000000 +0400
61
===================================================================
44
+++ sysdep/bsd/krt-scan.h	2011-05-10 11:58:54.812942887 +0400
62
--- sysdep/bsd/Modules	(revision 4869)
63
+++ sysdep/bsd/Modules	(working copy)
64
@@ -4,3 +4,4 @@
65
 krt-set.h
66
 krt-sock.c
67
 krt-sock.h
68
+fib.Y
69
Index: sysdep/bsd/krt-scan.h
70
===================================================================
71
--- sysdep/bsd/krt-scan.h	(revision 4869)
72
+++ sysdep/bsd/krt-scan.h	(working copy)
45
@@ -10,6 +10,7 @@
73
@@ -10,6 +10,7 @@
46
 #define _BIRD_KRT_SCAN_H_
74
 #define _BIRD_KRT_SCAN_H_
47
 
75
 
Lines 50-59 Link Here
50
 };
78
 };
51
 
79
 
52
 struct krt_scan_status {
80
 struct krt_scan_status {
53
diff -urN sysdep/bsd/krt-sock.c sysdep/bsd/krt-sock.c
81
Index: sysdep/bsd/krt-sock.c
54
--- sysdep/bsd/krt-sock.c	2011-05-02 12:13:18.000000000 +0400
82
===================================================================
55
+++ sysdep/bsd/krt-sock.c	2011-05-10 12:25:22.075267568 +0400
83
--- sysdep/bsd/krt-sock.c	(revision 4869)
56
@@ -53,6 +53,21 @@
84
+++ sysdep/bsd/krt-sock.c	(working copy)
85
@@ -33,8 +33,6 @@
86
 #include "lib/string.h"
87
 #include "lib/socket.h"
88
 
89
-int rt_sock = 0;
90
-
91
 int
92
 krt_capable(rte *e)
93
 {
94
@@ -53,6 +51,49 @@
57
      );
95
      );
58
 }
96
 }
59
 
97
 
Lines 68-108 Link Here
68
+    return 1;
106
+    return 1;
69
+  }
107
+  }
70
+
108
+
71
+  log(L_TRACE "Max fibs: %d\n", fibs);
109
+  //log(L_TRACE "Max fibs: %d", fibs);
72
+  return fibs;
110
+  return fibs;
73
+}
111
+}
74
+
112
+
113
+int
114
+my_fib_get()
115
+{
116
+  int fib = 0;
117
+  size_t fib_len = sizeof(fib);
118
+  if (sysctlbyname("net.my_fibnum", &fib, &fib_len, NULL, 0) == -1)
119
+  {
120
+    log(L_ERR "KRT: unable to get fib number, assuming 0. error: %s", strerror(errno));
121
+    return 0;
122
+  }
123
+
124
+  return fib;
125
+}
126
+
127
+int
128
+my_fib_set(int fib)
129
+{
130
+  int old_fib = my_fib_get();
131
+
132
+  if ((fib != old_fib) && (setfib(fib) == -1))
133
+  {
134
+    log(L_ERR "KRT: setfib(%d) failed: %s", fib, strerror(errno));
135
+    die("Cannot set fib for kernel socket");
136
+  }
137
+
138
+  return old_fib;
139
+}
140
+
75
 #define ROUNDUP(a) \
141
 #define ROUNDUP(a) \
76
         ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
142
         ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
77
 
143
 
78
@@ -219,6 +234,7 @@
144
@@ -69,7 +110,7 @@
145
     body += l;}
146
 
147
 static void
148
-krt_sock_send(int cmd, rte *e)
149
+krt_sock_send(struct krt_proto *p, int cmd, rte *e)
150
 {
151
   net *net = e->net;
152
   rta *a = e->attrs;
153
@@ -180,23 +221,23 @@
154
   l = body - (char *)&msg;
155
   msg.rtm.rtm_msglen = l;
156
 
157
-  if ((l = write(rt_sock, (char *)&msg, l)) < 0) {
158
+  if ((l = write(p->rt_sock, (char *)&msg, l)) < 0) {
159
     log(L_ERR "KRT: Error sending route %I/%d to kernel", net->n.prefix, net->n.pxlen);
160
   }
161
 }
162
 
163
 void
164
-krt_set_notify(struct krt_proto *p UNUSED, net *net, rte *new, rte *old)
165
+krt_set_notify(struct krt_proto *p, net *net, rte *new, rte *old)
166
 {
167
   if (old)
168
     {
169
       DBG("krt_remove_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
170
-      krt_sock_send(RTM_DELETE, old);
171
+      krt_sock_send(p, RTM_DELETE, old);
172
     }
173
   if (new)
174
     {
175
       DBG("krt_add_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
176
-      krt_sock_send(RTM_ADD, new);
177
+      krt_sock_send(p, RTM_ADD, new);
178
     }
179
 }
180
 
181
@@ -218,25 +259,34 @@
182
 krt_set_start(struct krt_proto *x, int first UNUSED)
79
 {
183
 {
80
   sock *sk_rt;
184
   sock *sk_rt;
81
   static int ks_open_tried = 0;
185
-  static int ks_open_tried = 0;
82
+  int fib = 0;
186
+  struct krt_config *c;
187
+  int fib = 0, old_fib = 0;
188
 
189
-  if (ks_open_tried)
190
-    return;
191
+  if (!strcmp(x->p.proto->name, "Kernel"))
192
+  {
193
+    c = (struct krt_config *)x->p.cf;
194
+    fib = c->scan.table_id;
83
 
195
 
84
   if (ks_open_tried)
196
-  ks_open_tried = 1;
85
     return;
197
+    DBG("KRT: Opening kernel route socket to fib %d\n", fib);
86
@@ -230,6 +246,16 @@
198
+    if (x->p.debug & D_ROUTES)
87
   if( (rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0)
199
+      log(L_TRACE "Opening route socket to fib %d", fib);
200
 
201
-  DBG("KRT: Opening kernel socket\n");
202
-
203
-  if( (rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0)
204
+    old_fib = my_fib_set(fib);
205
+  }
206
+  
207
+  if( (x->rt_sock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0)
88
     die("Cannot open kernel socket for routes");
208
     die("Cannot open kernel socket for routes");
89
 
209
 
90
+  fib = ((struct krt_config *)x)->scan.table_id;
210
   sk_rt = sk_new(krt_pool);
91
+  log(L_TRACE "KRT: Setting fib %d", fib);
211
   sk_rt->type = SK_MAGIC;
92
+
212
   sk_rt->rx_hook = krt_set_hook;
213
-  sk_rt->fd = rt_sock;
214
+  sk_rt->fd = x->rt_sock;
215
   sk_rt->data = x;
216
   if (sk_open(sk_rt))
217
     bug("krt-sock: sk_open failed");
93
+
218
+
94
+  if ((fib != 0) && (setsockopt(rt_sock, SOL_SOCKET, SO_SETFIB, &fib, sizeof(fib)) == -1))
219
+  /* Rollback fib */
220
+  my_fib_set(old_fib);
221
 }
222
 
223
 #define SKIP(ARG...) do { DBG("KRT: Ignoring route - " ARG); return; } while(0)
224
@@ -624,6 +674,8 @@
225
   size_t obl, needed;
226
   struct ks_msg *m;
227
   int retries = 3;
228
+  struct krt_config *c;
229
+  int fib = 0, old_fib = 0;
230
 
231
   mib[0] = CTL_NET;
232
   mib[1] = PF_ROUTE;
233
@@ -632,6 +684,17 @@
234
   mib[4] = cmd;
235
   mib[5] = 0;
236
 
237
+  if (!strcmp(p->proto->name, "Kernel"))
95
+  {
238
+  {
96
+    log(L_ERR "KRT: setsockopt() failed for socket %d: %s", rt_sock, strerror(errno));
239
+    c = (struct krt_config *)p->cf;
97
+    die("Cannot set fib for kernel socket");
240
+    fib = c->scan.table_id;
241
+
242
+    DBG("KRT: Setting fib to %d for route dump\n", fib);
243
+    if (p->debug & D_ROUTES)
244
+      log(L_TRACE "Setting fib to %d for route dump", fib);
245
+
246
+    old_fib = my_fib_set(fib);
98
+  }
247
+  }
248
  try:
249
   if (sysctl(mib, 6 , NULL , &needed, NULL, 0) < 0)
250
     die("krt_sysctl_scan 1: %m");
251
@@ -656,6 +719,7 @@
252
 	goto try;
253
 
254
       log(L_ERR "KRT: Route scan failed");
255
+      my_fib_set(old_fib);
256
       return;
257
     }
258
     die("krt_sysctl_scan 2: %m");
259
@@ -666,6 +730,8 @@
260
     m = (struct ks_msg *)next;
261
     krt_read_msg(p, m, 1);
262
   }
99
+
263
+
100
   sk_rt = sk_new(krt_pool);
264
+  my_fib_set(old_fib);
101
   sk_rt->type = SK_MAGIC;
265
 }
102
   sk_rt->rx_hook = krt_set_hook;
266
 
103
diff -urN sysdep/cf/bsd-v6.h sysdep/cf/bsd-v6.h
267
 static byte *krt_buffer = NULL;
104
--- sysdep/cf/bsd-v6.h	2011-03-31 12:29:42.000000000 +0400
268
Index: sysdep/cf/bsd-v6.h
105
+++ sysdep/cf/bsd-v6.h	2011-05-10 11:19:01.394166479 +0400
269
===================================================================
270
--- sysdep/cf/bsd-v6.h	(revision 4869)
271
+++ sysdep/cf/bsd-v6.h	(working copy)
106
@@ -10,7 +10,7 @@
272
@@ -10,7 +10,7 @@
107
 
273
 
108
 #define CONFIG_AUTO_ROUTES
274
 #define CONFIG_AUTO_ROUTES
Lines 112-120 Link Here
112
 
278
 
113
 #undef CONFIG_UNIX_IFACE
279
 #undef CONFIG_UNIX_IFACE
114
 #undef CONFIG_UNIX_SET
280
 #undef CONFIG_UNIX_SET
115
diff -urN sysdep/cf/bsd.h sysdep/cf/bsd.h
281
Index: sysdep/cf/bsd.h
116
--- sysdep/cf/bsd.h	2011-03-31 12:29:42.000000000 +0400
282
===================================================================
117
+++ sysdep/cf/bsd.h	2011-05-10 11:19:01.398182352 +0400
283
--- sysdep/cf/bsd.h	(revision 4869)
284
+++ sysdep/cf/bsd.h	(working copy)
118
@@ -8,7 +8,7 @@
285
@@ -8,7 +8,7 @@
119
 
286
 
120
 #define CONFIG_AUTO_ROUTES
287
 #define CONFIG_AUTO_ROUTES
(-)bird/files/learn-krt-sock.c (-11 lines)
Lines 1-11 Link Here
1
--- sysdep/bsd/krt-sock.c.orig	2011-05-11 10:41:35.432219356 +0400
2
+++ sysdep/bsd/krt-sock.c	2011-05-11 10:42:02.483875083 +0400
3
@@ -320,7 +320,7 @@
4
   if ((flags & RTF_GATEWAY) && ipa_zero(igate))
5
     { log(L_ERR "%s (%I/%d) - missing gateway", errmsg, idst, pxlen); return; }
6
 
7
-  u32 self_mask = RTF_PROTO1;
8
+  u32 self_mask = 0;
9
   u32 alien_mask = RTF_STATIC | RTF_PROTO1 | RTF_GATEWAY;
10
 
11
 #ifdef RTF_PROTO2
(-)bird/files/patch-bgp-packet.c (+11 lines)
Line 0 Link Here
1
--- proto/bgp/packets.c
2
+++ proto/bgp/packets.c
3
@@ -862,7 +862,7 @@ bgp_do_rx_update(struct bgp_conn *conn,
4
   if (conn->state != BS_ESTABLISHED)	/* fatal error during decoding */
5
     return;
6
 
7
-  if (a0 && bgp_set_next_hop(p, a0))
8
+  if (a0 && nlri_len && bgp_set_next_hop(p, a0))
9
     a = rta_lookup(a0);
10
 
11
   while (nlri_len)

Return to bug 157645