summaryrefslogtreecommitdiffstats
path: root/sysdep
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2011-04-28 00:31:37 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2011-04-28 00:31:37 +0200
commitacc93efd4c754cc995ee8edf52ce0bc45511062e (patch)
tree9e96b4b3b0801444d683770c5155acd27474d026 /sysdep
parent73272f04af40484b72451f541a986da996b0da58 (diff)
downloadbird-acc93efd4c754cc995ee8edf52ce0bc45511062e.tar
bird-acc93efd4c754cc995ee8edf52ce0bc45511062e.zip
Use constants from /etc/iproute2/rt_* files.
Diffstat (limited to 'sysdep')
-rw-r--r--sysdep/unix/main.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 732c916..fd921ac 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -62,6 +62,66 @@ async_dump(void)
* Reading the Configuration
*/
+#ifdef PATH_IPROUTE_DIR
+
+static inline void
+add_num_const(char *name, int val)
+{
+ struct symbol *s = cf_find_symbol(name);
+ s->class = SYM_NUMBER;
+ s->def = NULL;
+ s->aux = val;
+}
+
+/* the code of read_iproute_table() is based on
+ rtnl_tab_initialize() from iproute2 package */
+static void
+read_iproute_table(char *file, char *prefix, int max)
+{
+ char buf[512], namebuf[512];
+ char *name;
+ int val;
+ FILE *fp;
+
+ strcpy(namebuf, prefix);
+ name = namebuf + strlen(prefix);
+
+ fp = fopen(file, "r");
+ if (!fp)
+ return;
+
+ while (fgets(buf, sizeof(buf), fp))
+ {
+ char *p = buf;
+
+ while (*p == ' ' || *p == '\t')
+ p++;
+
+ if (*p == '#' || *p == '\n' || *p == 0)
+ continue;
+
+ if (sscanf(p, "0x%x %s\n", &val, name) != 2 &&
+ sscanf(p, "0x%x %s #", &val, name) != 2 &&
+ sscanf(p, "%d %s\n", &val, name) != 2 &&
+ sscanf(p, "%d %s #", &val, name) != 2)
+ continue;
+
+ if (val < 0 || val > max)
+ continue;
+
+ for(p = name; *p; p++)
+ if ((*p < 'a' || *p > 'z') && (*p < '0' || *p > '9') && (*p != '_'))
+ *p = '_';
+
+ add_num_const(namebuf, val);
+ }
+
+ fclose(fp);
+}
+
+#endif // PATH_IPROUTE_DIR
+
+
static int conf_fd;
static char *config_name = PATH_CONFIG;
@@ -78,6 +138,13 @@ void
sysdep_preconfig(struct config *c)
{
init_list(&c->logfiles);
+
+#ifdef PATH_IPROUTE_DIR
+ // read_iproute_table(PATH_IPROUTE_DIR "/rt_protos", "ipp_", 256);
+ read_iproute_table(PATH_IPROUTE_DIR "/rt_realms", "ipr_", 256);
+ read_iproute_table(PATH_IPROUTE_DIR "/rt_scopes", "ips_", 256);
+ read_iproute_table(PATH_IPROUTE_DIR "/rt_tables", "ipt_", 256);
+#endif
}
int