summaryrefslogtreecommitdiff
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
parent73272f04af40484b72451f541a986da996b0da58 (diff)
Use constants from /etc/iproute2/rt_* files.
-rw-r--r--configure.in15
-rw-r--r--doc/bird.sgml6
-rw-r--r--sysdep/unix/main.c67
-rw-r--r--tools/Makefile.in1
4 files changed, 87 insertions, 2 deletions
diff --git a/configure.in b/configure.in
index 230b57b4..46a6ecd9 100644
--- a/configure.in
+++ b/configure.in
@@ -13,6 +13,7 @@ AC_ARG_ENABLE(ipv6,[ --enable-ipv6 enable building of IPv6 version (d
AC_ARG_WITH(sysconfig,[ --with-sysconfig=FILE use specified BIRD system configuration file])
AC_ARG_WITH(protocols,[ --with-protocols=LIST include specified routing protocols (default: all)],,[with_protocols="all"])
AC_ARG_WITH(sysinclude,[ --with-sysinclude=PATH search for system includes on specified place])
+AC_ARG_WITH(iproutedir,[ --with-iproutedir=PATH path to iproute2 config files (default: /etc/iproute2)],[given_iproutedir="yes"])
AC_ARG_VAR([FLEX], [location of the Flex program])
AC_ARG_VAR([BISON], [location of the Bison program])
AC_ARG_VAR([M4], [location of the M4 program])
@@ -105,12 +106,14 @@ elif test -f sysconfig.h ; then
else
case "$ip:$host_os" in
ipv4:linux*) BIRD_CHECK_LINUX_VERSION
+ default_iproutedir="/etc/iproute2"
case $bird_cv_sys_linux_version in
1.*|2.0.*) sysdesc=linux-20 ;;
*) sysdesc=linux-22 ;;
esac
;;
ipv6:linux*) BIRD_CHECK_LINUX_VERSION
+ default_iproutedir="/etc/iproute2"
case $bird_cv_sys_linux_version in
1.*|2.0.*) AC_MSG_ERROR([This version of Linux doesn't support IPv6.]) ;;
*) sysdesc=linux-v6 ;;
@@ -154,6 +157,15 @@ sysdep_dirs="`sed <$sysdesc '/^Link: /!d;s/^Link: \(.*\)$/\1/' | tr '\012' ' '`
AC_MSG_RESULT($sysdep_dirs)
AC_SUBST(sysdep_dirs)
+if test "$with_iproutedir" = no ; then with_iproutedir= ; fi
+
+if test -n "$given_iproutedir"
+then iproutedir=$with_iproutedir
+else iproutedir=$default_iproutedir
+fi
+
+AC_SUBST(iproutedir)
+
AC_MSG_CHECKING([protocols])
protocols=`echo "$with_protocols" | sed 's/,/ /g'`
if test "$protocols" = no ; then protocols= ; fi
@@ -234,11 +246,14 @@ $srcdir/tools/mergedirs $srcdir $srcdir_rel $objdir $sysdep_dirs]],
AC_CONFIG_FILES($makefiles)
AC_OUTPUT
+rm -f $objdir/sysdep/paths.h
+
cat >&AC_FD_MSG <<EOF
BIRD was configured with the following options:
Source directory: $srcdir
Object directory: $objdir
+ Iproute2 directory: $iproutedir
System configuration: $sysdesc
Debugging: $enable_debug
Routing protocols: $protocols
diff --git a/doc/bird.sgml b/doc/bird.sgml
index b35f4944..31b2c03f 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -266,8 +266,10 @@ protocol rip {
about configuring protocols in their own chapters. You can run more than one instance of
most protocols (like RIP or BGP). By default, no instances are configured.
- <tag>define <m/constant/ = (<m/expression/)|<m/number/|<m/IP address/</tag> Define a constant. You can use it later in every place
- you could use a simple integer or an IP address.
+ <tag>define <m/constant/ = (<m/expression/)|<m/number/|<m/IP address/</tag>
+ Define a constant. You can use it later in every place you could use a simple integer or an IP address.
+ Besides, there are some predefined numeric constants based on /etc/iproute2/rt_* files.
+ A list of defined constants can be seen (together with other symbols) using 'show symbols' command.
<tag>router id <m/IPv4 address/</tag> Set BIRD's router ID. It's a world-wide unique identification of your router, usually one of router's IPv4 addresses. Default: in IPv4 version, the lowest IP address of a non-loopback interface. In IPv6 version, this option is mandatory.
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 732c9169..fd921ace 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
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 99ae2251..556eba5f 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -50,6 +50,7 @@ sysdep/paths.h:
echo >sysdep/paths.h "/* Generated by Makefile, don't edit manually! */"
echo >>sysdep/paths.h "#define PATH_CONFIG_DIR \"$(sysconfdir)\""
echo >>sysdep/paths.h "#define PATH_CONTROL_SOCKET_DIR \"$(localstatedir)/run\""
+ if test -n "@iproutedir@" ; then echo >>sysdep/paths.h "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi
tags:
cd $(srcdir) ; etags -lc `find $(static-dirs) $(addprefix $(objdir)/,$(dynamic-dirs)) $(client-dirs) -name *.[chY]`