0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

Cleanup in sysdep KRT code, part 2.

Remove support for historic Linux kernels,
merge krt-iface, krt-set and krt-scan stub headers.
This commit is contained in:
Ondrej Zajicek 2012-04-30 22:21:52 +02:00
parent 396dfa9042
commit f1aceff59b
33 changed files with 38 additions and 2224 deletions

17
aclocal.m4 vendored
View File

@ -133,23 +133,6 @@ if test "$bird_cv_struct_ip_mreqn" = yes ; then
fi fi
]) ])
AC_DEFUN(BIRD_CHECK_LINUX_VERSION,
[AC_CACHE_CHECK([Linux kernel version], bird_cv_sys_linux_version, [
AC_REQUIRE_CPP()dnl
cat > conftest.$ac_ext <<EOF
[#]line __oline__ "configure"
#include "confdefs.h"
#include <linux/version.h>
VERSION: UTS_RELEASE
EOF
bird_cv_sys_linux_version=`eval "$ac_cpp conftest.$ac_ext" 2>&AC_FD_CC | sed '/^VERSION/!d;s/^VERSION: "//;s/".*//'`
rm -rf conftest*
if test -z "$bird_cv_sys_linux_version" ; then
AC_MSG_RESULT([unknown])
AC_MSG_ERROR([Cannot determine kernel version])
fi
])])
AC_DEFUN(BIRD_CHECK_GCC_OPTIONS, AC_DEFUN(BIRD_CHECK_GCC_OPTIONS,
[AC_CACHE_VAL(bird_cv_c_option_no_pointer_sign, [ [AC_CACHE_VAL(bird_cv_c_option_no_pointer_sign, [
cat >conftest.c <<EOF cat >conftest.c <<EOF

View File

@ -105,19 +105,11 @@ elif test -f sysconfig.h ; then
sysdesc=sysconfig sysdesc=sysconfig
else else
case "$ip:$host_os" in case "$ip:$host_os" in
ipv4:linux*) BIRD_CHECK_LINUX_VERSION ipv6:linux*) sysdesc=linux-v6
default_iproutedir="/etc/iproute2" 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 ipv4:linux*) sysdesc=linux
default_iproutedir="/etc/iproute2" 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 ;;
esac
;; ;;
ipv6:netbsd*) sysdesc=bsd-v6 ipv6:netbsd*) sysdesc=bsd-v6
CPPFLAGS="$CPPFLAGS -I/usr/pkg/include" CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
@ -180,7 +172,7 @@ AC_MSG_RESULT(ok)
AC_SUBST(protocols) AC_SUBST(protocols)
case $sysdesc in case $sysdesc in
*/linux-22*|*/linux-v6*) */linux*|*/linux-v6*)
AC_CHECK_HEADER(linux/rtnetlink.h,,[AC_MSG_ERROR([Appropriate version of Linux kernel headers not found.])],[ AC_CHECK_HEADER(linux/rtnetlink.h,,[AC_MSG_ERROR([Appropriate version of Linux kernel headers not found.])],[
#include <asm/types.h> #include <asm/types.h>
#include <sys/socket.h> #include <sys/socket.h>

View File

@ -15,7 +15,6 @@
#include "lib/string.h" #include "lib/string.h"
#include "filter/filter.h" #include "filter/filter.h"
// static inline void put_as(byte *data, u32 as) { put_u32(data, as); } // static inline void put_as(byte *data, u32 as) { put_u32(data, as); }
// static inline u32 get_as(byte *data) { return get_u32(data); } // static inline u32 get_as(byte *data) { return get_u32(data); }

View File

@ -1,6 +1,3 @@
krt-scan.h
krt-iface.h
sysio.h
krt-set.h
krt-sock.c krt-sock.c
krt-sock.h krt-sys.h
sysio.h

View File

@ -1,33 +0,0 @@
/*
* BIRD -- Unix Kernel Socket Route Syncer -- Dummy Include File
*
* (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_IFACE_H_
#define _BIRD_KRT_IFACE_H_
/*
* We don't have split iface/scan/set parts. See krt-sock.h.
*/
struct kif_params {
};
struct kif_status {
};
static inline void kif_sys_init(struct kif_proto *p UNUSED) { }
static inline int kif_sys_reconfigure(struct kif_proto *p UNUSED, struct kif_config *n UNUSED, struct kif_config *o UNUSED) { return 1; }
static inline void kif_sys_preconfig(struct config *c UNUSED) { }
static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { }
static inline void kif_sys_init_config(struct kif_config *c UNUSED) { }
static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { }
static inline void kif_sys_io_init(void) { }
#endif

View File

@ -1,30 +0,0 @@
/*
* BIRD -- *BSD Kernel Route Syncer -- Scanning
*
* (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SCAN_H_
#define _BIRD_KRT_SCAN_H_
struct krt_scan_params {
};
struct krt_scan_status {
};
static inline void krt_sys_init(struct krt_proto *p UNUSED) { }
static inline int krt_sys_reconfigure(struct krt_proto *p UNUSED, struct krt_config *n UNUSED, struct krt_config *o UNUSED) { return 1; }
static inline void krt_sys_preconfig(struct config *c UNUSED) { }
static inline void krt_sys_postconfig(struct krt_config *c UNUSED) { }
static inline void krt_sys_init_config(struct krt_config *c UNUSED) { }
static inline void krt_sys_copy_config(struct krt_config *d UNUSED, struct krt_config *s UNUSED) { }
#endif

View File

@ -1,17 +0,0 @@
/*
* BIRD -- Unix Kernel Socket Route Syncer -- Dummy Include File
*
* (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SET_H_
#define _BIRD_KRT_SET_H_
/*
* We don't have split iface/scan/set parts. See krt-sock.h.
*/
#include "lib/krt-sock.h"
#endif

View File

@ -1,23 +0,0 @@
/*
* BIRD -- Unix Kernel Route Syncer -- Setting
*
* (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SOCK_H_
#define _BIRD_KRT_SOCK_H_
struct krt_params {
};
struct krt_status {
};
static inline int krt_set_params_same(struct krt_set_params *o UNUSED, struct krt_set_params *n UNUSED) { return 1; }
static inline void krt_set_copy_params(struct krt_set_params *d UNUSED, struct krt_set_params *s UNUSED) { }
void krt_read_msg(struct proto *p, struct ks_msg *msg, int scan);
#endif

View File

@ -5,19 +5,9 @@ CONFIG_AUTO_ROUTES Device routes are added automagically by the kernel
CONFIG_SELF_CONSCIOUS We're able to recognize whether route was installed by us CONFIG_SELF_CONSCIOUS We're able to recognize whether route was installed by us
CONFIG_MULTIPLE_TABLES The kernel supports multiple routing tables CONFIG_MULTIPLE_TABLES The kernel supports multiple routing tables
CONFIG_ALL_TABLES_AT_ONCE Kernel scanner wants to process all tables at once CONFIG_ALL_TABLES_AT_ONCE Kernel scanner wants to process all tables at once
CONFIG_MC_PROPER_SRC Multicast packets have source address according to socket saddr field CONFIG_MC_PROPER_SRC Multicast packets have source address according to socket saddr field
CONFIG_RESTRICTED_PRIVILEGES Implements restricted privileges using drop_uid()
CONFIG_UNIX_IFACE Use Unix interface scanner
CONFIG_UNIX_SET Use Unix route setting
CONFIG_UNIX_DONTROUTE Use setsockopts DONTROUTE (undef for *BSD)
CONFIG_SKIP_MC_BIND Don't call bind on multicast socket (def for *BSD) CONFIG_SKIP_MC_BIND Don't call bind on multicast socket (def for *BSD)
CONFIG_LINUX_SCAN Use Linux /proc/net/route scanner CONFIG_UNIX_DONTROUTE Use setsockopts DONTROUTE (undef for *BSD)
CONFIG_ALL_MULTICAST krt-iface: All devices support multicasting (i.e., ignore IFF_MULTICAST)
CONFIG_UNNUM_MULTICAST krt-iface: We support multicasts on unnumbered PtP devices
CONFIG_LINUX_MC_MREQN Linux: Use struct mreqn for multicasting
CONFIG_LINUX_MC_MREQ Linux: Use struct mreq
CONFIG_LINUX_MC_MREQ_BIND Linux: Use struct mreq and SO_BINDTODEVICE
CONFIG_RESTRICTED_PRIVILEGES Implements restricted privileges using drop_uid()

View File

@ -10,14 +10,8 @@
#define CONFIG_AUTO_ROUTES #define CONFIG_AUTO_ROUTES
#define CONFIG_SELF_CONSCIOUS #define CONFIG_SELF_CONSCIOUS
#undef CONFIG_MULTIPLE_TABLES
#undef CONFIG_UNIX_IFACE
#undef CONFIG_UNIX_SET
#define CONFIG_SKIP_MC_BIND #define CONFIG_SKIP_MC_BIND
#define CONFIG_ALL_MULTICAST
#define CONFIG_UNNUM_MULTICAST
/* /*
Link: sysdep/unix Link: sysdep/unix

View File

@ -8,15 +8,8 @@
#define CONFIG_AUTO_ROUTES #define CONFIG_AUTO_ROUTES
#define CONFIG_SELF_CONSCIOUS #define CONFIG_SELF_CONSCIOUS
#undef CONFIG_MULTIPLE_TABLES
#undef CONFIG_UNIX_IFACE
#undef CONFIG_UNIX_SET
#undef CONFIG_UNIX_DONTROUTE
#define CONFIG_SKIP_MC_BIND #define CONFIG_SKIP_MC_BIND
#define CONFIG_ALL_MULTICAST
#define CONFIG_UNNUM_MULTICAST
/* /*
Link: sysdep/unix Link: sysdep/unix

View File

@ -1,26 +0,0 @@
/*
* Configuration for Linux 2.0 based systems
*
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#undef CONFIG_AUTO_ROUTES
#undef CONFIG_SELF_CONSCIOUS
#undef CONFIG_MULTIPLE_TABLES
#define CONFIG_UNIX_IFACE
#define CONFIG_UNIX_SET
#define CONFIG_UNIX_DONTROUTE
#undef CONFIG_SKIP_MC_BIND
#define CONFIG_LINUX_SCAN
#define CONFIG_LINUX_MC_MREQ_BIND
#define CONFIG_ALL_MULTICAST
#define CONFIG_UNNUM_MULTICAST
/*
Link: sysdep/linux
Link: sysdep/unix
*/

View File

@ -1,26 +0,0 @@
/*
* Configuration for Linux 2.1/2.2 based systems without Netlink
*
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#define CONFIG_AUTO_ROUTES
#undef CONFIG_SELF_CONSCIOUS
#undef CONFIG_MULTIPLE_TABLES
#define CONFIG_UNIX_IFACE
#define CONFIG_UNIX_SET
#define CONFIG_UNIX_DONTROUTE
#undef CONFIG_SKIP_MC_BIND
#define CONFIG_LINUX_SCAN
#define CONFIG_LINUX_MC_MREQN
#define CONFIG_ALL_MULTICAST
#define CONFIG_UNNUM_MULTICAST
/*
Link: sysdep/linux
Link: sysdep/unix
*/

View File

@ -1,26 +0,0 @@
/*
* Configuration for Linux 2.2 based systems
*
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#define CONFIG_AUTO_ROUTES
#define CONFIG_SELF_CONSCIOUS
#define CONFIG_MULTIPLE_TABLES
#define CONFIG_ALL_TABLES_AT_ONCE
#define CONFIG_MC_PROPER_SRC
#undef CONFIG_SKIP_MC_BIND
#define CONFIG_LINUX_MC_MREQN
#define CONFIG_UNIX_DONTROUTE
#define CONFIG_RESTRICTED_PRIVILEGES
/*
Link: sysdep/linux/netlink
Link: sysdep/linux
Link: sysdep/unix
*/

View File

@ -1,5 +1,5 @@
/* /*
* Configuration for Linux 2.2 based systems running IPv6 * Configuration for Linux based systems running IPv6
* *
* (c) 1998--1999 Martin Mares <mj@ucw.cz> * (c) 1998--1999 Martin Mares <mj@ucw.cz>
* *
@ -9,20 +9,13 @@
#define IPV6 #define IPV6
#define CONFIG_AUTO_ROUTES #define CONFIG_AUTO_ROUTES
#define CONFIG_ALL_MULTICAST
#define CONFIG_SELF_CONSCIOUS #define CONFIG_SELF_CONSCIOUS
/*
* Netlink supports multiple tables, but kernel IPv6 code doesn't, so we
* treat it as a multiple table system with number of tables set to 1.
*/
#define CONFIG_MULTIPLE_TABLES #define CONFIG_MULTIPLE_TABLES
#define CONFIG_ALL_TABLES_AT_ONCE #define CONFIG_ALL_TABLES_AT_ONCE
#define CONFIG_RESTRICTED_PRIVILEGES #define CONFIG_RESTRICTED_PRIVILEGES
/* /*
Link: sysdep/linux/netlink
Link: sysdep/linux Link: sysdep/linux
Link: sysdep/unix Link: sysdep/unix
*/ */

View File

@ -1,6 +1,5 @@
#ifdef CONFIG_LINUX_SCAN krt-sys.h
krt-scan.c netlink.c
krt-scan.h netlink.Y
#endif
sysio.h sysio.h
syspriv.h syspriv.h

View File

@ -1,199 +0,0 @@
/*
* BIRD -- Linux Routing Table Scanning
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <net/route.h>
#undef LOCAL_DEBUG
#include "nest/bird.h"
#include "nest/route.h"
#include "nest/protocol.h"
#include "nest/iface.h"
#include "lib/timer.h"
#include "lib/unix.h"
#include "lib/krt.h"
#include "lib/string.h"
static int krt_scan_fd = -1;
struct iface *
krt_temp_iface(struct krt_proto *p, char *name)
{
struct iface *i;
WALK_LIST(i, p->scan.temp_ifs)
if (!strcmp(i->name, name))
return i;
i = mb_allocz(p->p.pool, sizeof(struct iface));
strcpy(i->name, name);
add_tail(&p->scan.temp_ifs, &i->n);
return i;
}
static void
krt_parse_entry(byte *ent, struct krt_proto *p)
{
u32 dest0, gw0, mask0;
ip_addr dest, gw, mask;
unsigned int flags;
int masklen;
net *net;
byte *iface = ent;
rte *e;
if (sscanf(ent, "%*s\t%x\t%x\t%x\t%*d\t%*d\t%*d\t%x\t", &dest0, &gw0, &flags, &mask0) != 4)
{
log(L_ERR "krt read: unable to parse `%s'", ent);
return;
}
while (*ent != '\t')
ent++;
*ent = 0;
dest = ipa_from_u32(dest0);
ipa_ntoh(dest);
gw = ipa_from_u32(gw0);
ipa_ntoh(gw);
mask = ipa_from_u32(mask0);
ipa_ntoh(mask);
if ((masklen = ipa_mklen(mask)) < 0)
{
log(L_ERR "krt read: invalid netmask %08x", mask0);
return;
}
DBG("Got %I/%d via %I flags %x\n", dest, masklen, gw, flags);
if (!(flags & RTF_UP))
{
DBG("Down.\n");
return;
}
if (flags & RTF_HOST)
masklen = 32;
if (flags & (RTF_DYNAMIC | RTF_MODIFIED)) /* Redirect route */
{
log(L_WARN "krt: Ignoring redirect to %I/%d via %I", dest, masklen, gw);
return;
}
net = net_get(p->p.table, dest, masklen);
rta a = {
.proto = &p->p,
.source = RTS_INHERIT,
.scope = SCOPE_UNIVERSE,
.cast = RTC_UNICAST
};
if (flags & RTF_GATEWAY)
{
neighbor *ng = neigh_find(&p->p, &gw, 0);
if (ng && ng->scope)
a.iface = ng->iface;
else
{
log(L_WARN "Kernel told us to use non-neighbor %I for %I/%d", gw, net->n.prefix, net->n.pxlen);
return;
}
a.dest = RTD_ROUTER;
a.gw = gw;
}
else if (flags & RTF_REJECT)
{
a.dest = RTD_UNREACHABLE;
a.gw = IPA_NONE;
}
else if (isalpha(iface[0]))
{
a.dest = RTD_DEVICE;
a.gw = IPA_NONE;
a.iface = krt_temp_iface(p, iface);
}
else
{
log(L_WARN "Kernel reporting unknown route type to %I/%d", net->n.prefix, net->n.pxlen);
return;
}
e = rte_get_temp(&a);
e->net = net;
e->u.krt.src = KRT_SRC_UNKNOWN;
krt_got_route(p, e);
}
void
krt_scan_fire(struct krt_proto *p)
{
byte buf[32768];
int l, seen_hdr;
if (krt_scan_fd < 0)
{
krt_scan_fd = open("/proc/net/route", O_RDONLY);
if (krt_scan_fd < 0)
die("/proc/net/route: %m");
}
else if (lseek(krt_scan_fd, 0, SEEK_SET) < 0)
{
log(L_ERR "krt seek: %m");
return;
}
seen_hdr = 0;
while ((l = read(krt_scan_fd, buf, sizeof(buf))) > 0)
{
byte *z = buf;
if (l & 127)
{
log(L_ERR "krt read: misaligned entry: l=%d", l);
return;
}
while (l >= 128)
{
if (seen_hdr++)
krt_parse_entry(z, p);
z += 128;
l -= 128;
}
}
if (l < 0)
{
log(L_ERR "krt read: %m");
return;
}
DBG("KRT scan done, seen %d lines\n", seen_hdr);
}
void
krt_scan_construct(struct krt_config *c)
{
}
void
krt_scan_preconfig(struct config *c)
{
}
void
krt_scan_postconfig(struct krt_config *c)
{
}
void
krt_scan_start(struct krt_proto *x, int first)
{
init_list(&x->scan.temp_ifs);
}
void
krt_scan_shutdown(struct krt_proto *x, int last)
{
}

View File

@ -1,21 +0,0 @@
/*
* BIRD -- Linux Kernel Route Syncer -- Scanning
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SCAN_H_
#define _BIRD_KRT_SCAN_H_
struct krt_scan_params {
};
struct krt_scan_status {
list temp_ifs; /* Temporary interfaces */
};
static inline int krt_scan_params_same(struct krt_scan_params *o, struct krt_scan_params *n) { return 1; }
#endif

View File

@ -1,5 +0,0 @@
krt-iface.h
krt-set.h
krt-scan.h
netlink.c
netlink.Y

View File

@ -1,33 +0,0 @@
/*
* BIRD -- Unix Kernel Netlink Interface Syncer -- Dummy Include File
*
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_IFACE_H_
#define _BIRD_KRT_IFACE_H_
/*
* We don't have split iface/scan/set parts. See krt-scan.h.
*/
struct kif_params {
};
struct kif_status {
};
static inline void kif_sys_init(struct kif_proto *p UNUSED) { }
static inline int kif_sys_reconfigure(struct kif_proto *p UNUSED, struct kif_config *n UNUSED, struct kif_config *o UNUSED) { return 1; }
static inline void kif_sys_preconfig(struct config *c UNUSED) { }
static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { }
static inline void kif_sys_init_config(struct kif_config *c UNUSED) { }
static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { }
static inline void kif_sys_io_init(void) { }
#endif

View File

@ -1,30 +0,0 @@
/*
* BIRD -- Linux Kernel Netlink Route Syncer -- Scanning
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SCAN_H_
#define _BIRD_KRT_SCAN_H_
/*
* We don't have split iface/scan/set for Netlink. All options
* and run-time parameters are declared here instead of splitting
* to krt-set.h, krt-iface.h and this file.
*/
#define NL_NUM_TABLES 256
struct krt_params {
int table_id; /* Kernel table ID we sync with */
};
struct krt_status {
};
static inline void krt_sys_init(struct krt_proto *p UNUSED) { }
#endif

View File

@ -1,28 +0,0 @@
/*
* BIRD -- Unix Kernel Netlink Route Syncer -- Dummy Include File
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SET_H_
#define _BIRD_KRT_SET_H_
/*
* We don't have split iface/scan/set parts. See krt-scan.h.
*/
struct krt_set_params {
};
struct krt_set_status {
};
static inline void krt_set_construct(struct krt_config *c UNUSED) { };
static inline void krt_set_start(struct krt_proto *p UNUSED, int first UNUSED) { };
static inline void krt_set_shutdown(struct krt_proto *p UNUSED, int last UNUSED) { };
static inline int krt_set_params_same(struct krt_set_params *o UNUSED, struct krt_set_params *n UNUSED) { return 1; }
static inline void krt_set_copy_params(struct krt_set_params *d UNUSED, struct krt_set_params *s UNUSED) { }
#endif

View File

@ -1,32 +0,0 @@
/*
* BIRD -- Linux Netlink Configuration
*
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
*
* 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 nl_item ';')
nl_item:
KERNEL TABLE expr {
if ($3 <= 0 || $3 >= NL_NUM_TABLES)
cf_error("Kernel routing table number out of range");
THIS_KRT->sys.table_id = $3;
}
;
CF_ADDTO(dynamic_attr, KRT_PREFSRC { $$ = f_new_dynamic_attr(EAF_TYPE_IP_ADDRESS, T_IP, EA_KRT_PREFSRC); })
CF_ADDTO(dynamic_attr, KRT_REALM { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_KRT_REALM); })
CF_CODE
CF_END

File diff suppressed because it is too large Load Diff

View File

@ -57,45 +57,6 @@ get_inaddr(ip_addr *a, struct in_addr *ia)
ipa_ntoh(*a); ipa_ntoh(*a);
} }
/*
* Multicasting in Linux systems is a real mess. Not only different kernels
* have different interfaces, but also different libc's export it in different
* ways. Horrible.
*/
#if defined(CONFIG_LINUX_MC_MREQ) || defined(CONFIG_LINUX_MC_MREQ_BIND)
/*
* Older kernels support only struct mreq which matches interfaces by their
* addresses and thus fails on unnumbered devices. On newer 2.0 kernels
* we can use SO_BINDTODEVICE to circumvent this problem.
*/
#define MREQ_IFA struct in_addr
#define MREQ_GRP struct ip_mreq
static inline void fill_mreq_ifa(struct in_addr *m, struct iface *ifa UNUSED, ip_addr saddr, ip_addr maddr UNUSED)
{
set_inaddr(m, saddr);
}
static inline void fill_mreq_grp(struct ip_mreq *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
{
bzero(m, sizeof(*m));
#ifdef CONFIG_LINUX_MC_MREQ_BIND
m->imr_interface.s_addr = INADDR_ANY;
#else
set_inaddr(&m->imr_interface, saddr);
#endif
set_inaddr(&m->imr_multiaddr, maddr);
}
#endif
#ifdef CONFIG_LINUX_MC_MREQN
/*
* 2.1 and newer kernels use struct mreqn which passes ifindex, so no
* problems with unnumbered devices.
*/
#ifndef HAVE_STRUCT_IP_MREQN #ifndef HAVE_STRUCT_IP_MREQN
/* Several versions of glibc don't define this structure, so we have to do it ourselves */ /* Several versions of glibc don't define this structure, so we have to do it ourselves */
@ -107,24 +68,19 @@ struct ip_mreqn
}; };
#endif #endif
#define MREQ_IFA struct ip_mreqn
#define MREQ_GRP struct ip_mreqn
#define fill_mreq_ifa fill_mreq
#define fill_mreq_grp fill_mreq
static inline void fill_mreq(struct ip_mreqn *m, struct iface *ifa, ip_addr saddr, ip_addr maddr) static inline void fill_mreqn(struct ip_mreqn *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
{ {
bzero(m, sizeof(*m)); bzero(m, sizeof(*m));
m->imr_ifindex = ifa->index; m->imr_ifindex = ifa->index;
set_inaddr(&m->imr_address, saddr); set_inaddr(&m->imr_address, saddr);
set_inaddr(&m->imr_multiaddr, maddr); set_inaddr(&m->imr_multiaddr, maddr);
} }
#endif
static inline char * static inline char *
sysio_setup_multicast(sock *s) sysio_setup_multicast(sock *s)
{ {
MREQ_IFA m; struct ip_mreqn m;
int zero = 0; int zero = 0;
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_LOOP, &zero, sizeof(zero)) < 0) if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_LOOP, &zero, sizeof(zero)) < 0)
@ -134,18 +90,15 @@ sysio_setup_multicast(sock *s)
return "IP_MULTICAST_TTL"; return "IP_MULTICAST_TTL";
/* This defines where should we send _outgoing_ multicasts */ /* This defines where should we send _outgoing_ multicasts */
fill_mreq_ifa(&m, s->iface, s->saddr, IPA_NONE); fill_mreqn(&m, s->iface, s->saddr, IPA_NONE);
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0) if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0)
return "IP_MULTICAST_IF"; return "IP_MULTICAST_IF";
#if defined(CONFIG_LINUX_MC_MREQ_BIND) || defined(CONFIG_LINUX_MC_MREQN) /* Is this necessary? */
{
struct ifreq ifr; struct ifreq ifr;
strcpy(ifr.ifr_name, s->iface->name); strcpy(ifr.ifr_name, s->iface->name);
if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0) if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
return "SO_BINDTODEVICE"; return "SO_BINDTODEVICE";
}
#endif
return NULL; return NULL;
} }
@ -153,10 +106,10 @@ sysio_setup_multicast(sock *s)
static inline char * static inline char *
sysio_join_group(sock *s, ip_addr maddr) sysio_join_group(sock *s, ip_addr maddr)
{ {
MREQ_GRP m; struct ip_mreqn m;
/* And this one sets interface for _receiving_ multicasts from */ /* And this one sets interface for _receiving_ multicasts from */
fill_mreq_grp(&m, s->iface, s->saddr, maddr); fill_mreqn(&m, s->iface, s->saddr, maddr);
if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(m)) < 0) if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(m)) < 0)
return "IP_ADD_MEMBERSHIP"; return "IP_ADD_MEMBERSHIP";
@ -166,10 +119,10 @@ sysio_join_group(sock *s, ip_addr maddr)
static inline char * static inline char *
sysio_leave_group(sock *s, ip_addr maddr) sysio_leave_group(sock *s, ip_addr maddr)
{ {
MREQ_GRP m; struct ip_mreqn m;
/* And this one sets interface for _receiving_ multicasts from */ /* And this one sets interface for _receiving_ multicasts from */
fill_mreq_grp(&m, s->iface, s->saddr, maddr); fill_mreqn(&m, s->iface, s->saddr, maddr);
if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &m, sizeof(m)) < 0) if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &m, sizeof(m)) < 0)
return "IP_DROP_MEMBERSHIP"; return "IP_DROP_MEMBERSHIP";

View File

@ -10,13 +10,3 @@ random.c
krt.c krt.c
krt.h krt.h
krt.Y krt.Y
#ifdef CONFIG_UNIX_IFACE
krt-iface.c
krt-iface.h
#endif
#ifdef CONFIG_UNIX_SET
krt-set.c
krt-set.h
#endif

View File

@ -1,228 +0,0 @@
/*
* BIRD -- Unix Interface Scanning and Syncing
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
* (c) 2004 Ondrej Filip <feela@network.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <errno.h>
#undef LOCAL_DEBUG
#include "nest/bird.h"
#include "nest/iface.h"
#include "nest/route.h"
#include "nest/protocol.h"
#include "lib/timer.h"
#include "lib/krt.h"
#include "lib/string.h"
#include "unix.h"
int if_scan_sock = -1;
static void
scan_ifs(struct ifreq *r, int cnt)
{
struct iface i, *pi;
struct ifa a;
char *err, *colon;
unsigned fl;
ip_addr netmask;
int l, scope;
sockaddr *sa;
if_start_update();
for (cnt /= sizeof(struct ifreq); cnt; cnt--, r++)
{
int sec = 0;
bzero(&i, sizeof(i));
bzero(&a, sizeof(a));
if (colon = strchr(r->ifr_name, ':'))
{
/* It's an alias -- let's interpret it as a secondary interface address */
sec = 1;
*colon = 0;
}
strncpy(i.name, r->ifr_name, sizeof(i.name) - 1);
if(ioctl(if_scan_sock, SIOCGIFADDR,r)<0) continue;
get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &a.ip, NULL, 1);
if (ipa_nonzero(a.ip))
{
l = ipa_classify(a.ip);
if (l < 0 || !(l & IADDR_HOST))
{
log(L_ERR "%s: Invalid interface address", i.name);
a.ip = IPA_NONE;
}
else
{
a.scope = l & IADDR_SCOPE_MASK;
if (a.scope == SCOPE_HOST)
i.flags |= IF_LOOPBACK | IF_IGNORE;
}
}
if (ioctl(if_scan_sock, SIOCGIFFLAGS, r) < 0)
{
err = "SIOCGIFFLAGS";
faulty:
log(L_ERR "%s(%s): %m", err, i.name);
bad:
i.flags = (i.flags & ~IF_ADMIN_UP) | IF_SHUTDOWN;
continue;
}
fl = r->ifr_flags;
if (fl & IFF_UP)
i.flags |= IF_ADMIN_UP;
if (ioctl(if_scan_sock, SIOCGIFNETMASK, r) < 0)
{ err = "SIOCGIFNETMASK"; goto faulty; }
get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &netmask, NULL, 0);
l = ipa_mklen(netmask);
if (l < 0)
{
log(L_ERR "%s: Invalid netmask (%x)", i.name, netmask);
goto bad;
}
a.pxlen = l;
if (fl & IFF_POINTOPOINT)
{
a.flags |= IA_PEER;
if (ioctl(if_scan_sock, SIOCGIFDSTADDR, r) < 0)
{ err = "SIOCGIFDSTADDR"; goto faulty; }
get_sockaddr((struct sockaddr_in *) &r->ifr_addr, &a.opposite, NULL, 1);
a.prefix = a.opposite;
a.pxlen = BITS_PER_IP_ADDRESS;
}
else
a.prefix = ipa_and(a.ip, ipa_mkmask(a.pxlen));
if (fl & IFF_LOOPBACK)
i.flags |= IF_LOOPBACK | IF_IGNORE;
if (1
#ifndef CONFIG_ALL_MULTICAST
&& (fl & IFF_MULTICAST)
#endif
#ifndef CONFIG_UNNUM_MULTICAST
&& !(a.flags & IA_PEER)
#endif
)
i.flags |= IF_MULTICAST;
scope = ipa_classify(a.ip);
if (scope < 0)
{
log(L_ERR "%s: Invalid address", i.name);
goto bad;
}
a.scope = scope & IADDR_SCOPE_MASK;
if (a.pxlen < 32)
{
a.brd = ipa_or(a.prefix, ipa_not(ipa_mkmask(a.pxlen)));
if (ipa_equal(a.ip, a.prefix) || ipa_equal(a.ip, a.brd))
{
log(L_ERR "%s: Using network or broadcast address for interface", i.name);
goto bad;
}
if (fl & IFF_BROADCAST)
i.flags |= IF_BROADCAST;
if (a.pxlen < 30)
i.flags |= IF_MULTIACCESS;
if (a.pxlen == 30)
ifa.opposite = ipa_opposite_m2(ifa.ip);
if (a.pxlen == 31)
ifa.opposite = ipa_opposite_m1(ifa.ip);
}
else
a.brd = a.opposite;
a.scope = SCOPE_UNIVERSE;
if (ioctl(if_scan_sock, SIOCGIFMTU, r) < 0)
{ err = "SIOCGIFMTU"; goto faulty; }
i.mtu = r->ifr_mtu;
#ifdef SIOCGIFINDEX
if (ioctl(if_scan_sock, SIOCGIFINDEX, r) >= 0)
i.index = r->ifr_ifindex;
else if (errno != EINVAL)
DBG("SIOCGIFINDEX failed: %m\n");
else /* defined, but not supported by the kernel */
#endif
/*
* The kernel doesn't give us real ifindices, but we still need them
* at least for OSPF unnumbered links. So let's make them up ourselves.
*/
if (pi = if_find_by_name(i.name))
i.index = pi->index;
else
{
static int if_index_counter = 1;
i.index = if_index_counter++;
}
pi = NULL;
if (sec)
{
a.flags |= IA_SECONDARY;
pi = if_find_by_index(i.index);
}
if (!pi)
pi = if_update(&i);
a.iface = pi;
ifa_update(&a);
}
if_end_update();
}
void
kif_do_scan(struct kif_proto *p)
{
struct ifconf ic;
static int last_ifbuf_size = 4*sizeof(struct ifreq);
int res;
for(;;)
{
ic.ifc_buf = alloca(last_ifbuf_size);
ic.ifc_len = last_ifbuf_size;
res = ioctl(if_scan_sock, SIOCGIFCONF, &ic);
if (res < 0 && errno != EFAULT)
die("SIOCCGIFCONF: %m");
if (res >= 0 && ic.ifc_len <= last_ifbuf_size)
break;
last_ifbuf_size *= 2;
DBG("Increased ifconf buffer size to %d\n", last_ifbuf_size);
}
scan_ifs(ic.ifc_req, ic.ifc_len);
}
void
kif_start(struct kif_proto *p)
{
}
void
kif_shutdown(struct kif_proto *p)
{
}
void
kif_io_init(void)
{
if_scan_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
DBG("Using socket %d for interface and route scanning\n", if_scan_sock);
if (if_scan_sock < 0)
die("Cannot create scanning socket: %m");
}

View File

@ -1,29 +0,0 @@
/*
* BIRD -- Unix Kernel Interface Syncer
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_IFACE_H_
#define _BIRD_KRT_IFACE_H_
struct kif_params {
};
struct kif_status {
};
extern int if_scan_sock;
static inline void kif_sys_init(struct kif_proto *p UNUSED) { }
static inline int kif_sys_reconfigure(struct kif_proto *p UNUSED, struct kif_config *n UNUSED, struct kif_config *o UNUSED) { return 1; }
static inline void kif_sys_preconfig(struct config *c UNUSED) { }
static inline void kif_sys_postconfig(struct kif_config *c UNUSED) { }
static inline void kif_sys_init_config(struct kif_config *c UNUSED) { }
static inline void kif_sys_copy_config(struct kif_config *d UNUSED, struct kif_config *s UNUSED) { }
#endif

View File

@ -1,112 +0,0 @@
/*
* BIRD -- Unix Routing Table Syncing
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <net/route.h>
#undef LOCAL_DEBUG
#include "nest/bird.h"
#include "nest/iface.h"
#include "nest/route.h"
#include "nest/protocol.h"
#include "lib/unix.h"
#include "lib/krt.h"
#include "lib/string.h"
int
krt_capable(rte *e)
{
rta *a = e->attrs;
#ifdef CONFIG_AUTO_ROUTES
if (a->source == RTS_DEVICE)
return 0;
#endif
return
a->cast == RTC_UNICAST &&
(a->dest == RTD_ROUTER
|| a->dest == RTD_DEVICE
#ifdef RTF_REJECT
|| a->dest == RTD_UNREACHABLE
#endif
);
}
static void
krt_ioctl(int ioc, rte *e, char *name)
{
net *net = e->net;
struct rtentry re;
rta *a = e->attrs;
bzero(&re, sizeof(re));
fill_in_sockaddr((struct sockaddr_in *) &re.rt_dst, net->n.prefix, 0);
fill_in_sockaddr((struct sockaddr_in *) &re.rt_genmask, ipa_mkmask(net->n.pxlen), 0);
re.rt_flags = RTF_UP;
if (net->n.pxlen == 32)
re.rt_flags |= RTF_HOST;
switch (a->dest)
{
case RTD_ROUTER:
fill_in_sockaddr((struct sockaddr_in *) &re.rt_gateway, a->gw, 0);
re.rt_flags |= RTF_GATEWAY;
break;
case RTD_DEVICE:
if (!a->iface)
return;
re.rt_dev = a->iface->name;
break;
#ifdef RTF_REJECT
case RTD_UNREACHABLE:
re.rt_flags |= RTF_REJECT;
break;
#endif
default:
bug("krt set: unknown flags, but not filtered");
}
if (ioctl(if_scan_sock, ioc, &re) < 0)
log(L_ERR "%s(%I/%d): %m", name, net->n.prefix, net->n.pxlen);
}
void
krt_do_notify(struct krt_proto *p, net *net, rte *new, rte *old)
{
if (old)
{
DBG("krt_remove_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
krt_ioctl(SIOCDELRT, old, "SIOCDELRT");
}
if (new)
{
DBG("krt_add_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
krt_ioctl(SIOCADDRT, new, "SIOCADDRT");
}
}
void
krt_sys_start(struct krt_proto *x, int first)
{
if (if_scan_sock < 0)
bug("krt set: missing socket");
}
void
krt_sys_shutdown(struct krt_proto *x, int last)
{
}
void
krt_sys_construct(struct krt_config *c)
{
}

View File

@ -1,27 +0,0 @@
/*
* BIRD -- Unix Kernel Route Syncer
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_KRT_SET_H_
#define _BIRD_KRT_SET_H_
struct krt_params {
};
struct krt_status {
};
static inline void krt_sys_init(struct krt_proto *p UNUSED) { }
static inline int krt_sys_reconfigure(struct krt_proto *p UNUSED, struct krt_config *n UNUSED, struct krt_config *o UNUSED) { return 1; }
static inline void krt_sys_preconfig(struct config *c UNUSED) { }
static inline void krt_sys_postconfig(struct krt_config *c UNUSED) { }
static inline void krt_sys_init_config(struct krt_config *c UNUSED) { }
static inline void krt_sys_copy_config(struct krt_config *d UNUSED, struct krt_config *s UNUSED) { }
#endif

View File

@ -23,7 +23,7 @@
* Either with a single routing table and single KRT protocol [traditional UNIX] * Either with a single routing table and single KRT protocol [traditional UNIX]
* or with many routing tables and separate KRT protocols for all of them * or with many routing tables and separate KRT protocols for all of them
* or with many routing tables, but every scan including all tables, so we start * or with many routing tables, but every scan including all tables, so we start
* separate KRT protocols which cooperate with each other [Linux 2.2]. * separate KRT protocols which cooperate with each other [Linux].
* In this case, we keep only a single scan timer. * In this case, we keep only a single scan timer.
* *
* We use FIB node flags in the routing table to keep track of route * We use FIB node flags in the routing table to keep track of route
@ -34,6 +34,15 @@
* When starting up, we cheat by looking if there is another * When starting up, we cheat by looking if there is another
* KRT instance to be initialized later and performing table scan * KRT instance to be initialized later and performing table scan
* only once for all the instances. * only once for all the instances.
*
* The code uses OS-dependent parts for kernel updates and scans. These parts are
* in more specific sysdep directories (e.g. sysdep/linux) in functions krt_sys_*
* and kif_sys_* (and some others like krt_do_notify()) and krt-sys.h header file.
* This is also used for platform specific protocol options and route attributes.
*
* There was also an old code that used traditional UNIX ioctls for these tasks.
* It was unmaintained and later removed. For reference, see sysdep/krt-* files
* in commit 396dfa9042305f62da1f56589c4b98fac57fc2f6
*/ */
/* /*
@ -66,7 +75,6 @@ krt_io_init(void)
{ {
krt_pool = rp_new(&root_pool, "Kernel Syncer"); krt_pool = rp_new(&root_pool, "Kernel Syncer");
krt_filter_lp = lp_new(krt_pool, 4080); krt_filter_lp = lp_new(krt_pool, 4080);
kif_sys_io_init();
} }
/* /*

View File

@ -15,9 +15,7 @@ struct krt_proto;
struct kif_config; struct kif_config;
struct kif_proto; struct kif_proto;
#include "lib/krt-scan.h" #include "lib/krt-sys.h"
#include "lib/krt-set.h"
#include "lib/krt-iface.h"
/* Flags stored in net->n.flags, rest are in nest/route.h */ /* Flags stored in net->n.flags, rest are in nest/route.h */
@ -113,7 +111,7 @@ struct kif_proto {
struct proto_config * krt_init_config(int class); struct proto_config * krt_init_config(int class);
/* krt-scan.c */ /* krt sysdep */
void krt_sys_init(struct krt_proto *); void krt_sys_init(struct krt_proto *);
void krt_sys_start(struct krt_proto *, int); void krt_sys_start(struct krt_proto *, int);
@ -130,7 +128,7 @@ void krt_do_scan(struct krt_proto *);
void krt_do_notify(struct krt_proto *p, net *n, rte *new, rte *old, struct ea_list *eattrs); void krt_do_notify(struct krt_proto *p, net *n, rte *new, rte *old, struct ea_list *eattrs);
/* krt-iface.c */ /* kif sysdep */
void kif_sys_init(struct kif_proto *); void kif_sys_init(struct kif_proto *);
void kif_sys_start(struct kif_proto *); void kif_sys_start(struct kif_proto *);
@ -142,6 +140,5 @@ void kif_sys_copy_config(struct kif_config *, struct kif_config *);
void kif_do_scan(struct kif_proto *); void kif_do_scan(struct kif_proto *);
// void kif_sys_io_init(void);
#endif #endif