Commit f1aceff5 authored by Ondřej Zajíček's avatar Ondřej Zajíček

Cleanup in sysdep KRT code, part 2.

Remove support for historic Linux kernels,
merge krt-iface, krt-set and krt-scan stub headers.
parent 396dfa90
......@@ -133,23 +133,6 @@ if test "$bird_cv_struct_ip_mreqn" = yes ; then
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_CACHE_VAL(bird_cv_c_option_no_pointer_sign, [
cat >conftest.c <<EOF
......
......@@ -105,19 +105,11 @@ elif test -f sysconfig.h ; then
sysdesc=sysconfig
else
case "$ip:$host_os" in
ipv4:linux*) BIRD_CHECK_LINUX_VERSION
ipv6:linux*) sysdesc=linux-v6
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"
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
CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
......@@ -180,7 +172,7 @@ AC_MSG_RESULT(ok)
AC_SUBST(protocols)
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.])],[
#include <asm/types.h>
#include <sys/socket.h>
......
......@@ -15,7 +15,6 @@
#include "lib/string.h"
#include "filter/filter.h"
// static inline void put_as(byte *data, u32 as) { put_u32(data, as); }
// static inline u32 get_as(byte *data) { return get_u32(data); }
......
krt-scan.h
krt-iface.h
sysio.h
krt-set.h
krt-sock.c
krt-sock.h
krt-sys.h
sysio.h
/*
* 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
/*
* 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
/*
* 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
/*
* 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
......@@ -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_MULTIPLE_TABLES The kernel supports multiple routing tables
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_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_MC_PROPER_SRC Multicast packets have source address according to socket saddr field
CONFIG_SKIP_MC_BIND Don't call bind on multicast socket (def for *BSD)
CONFIG_LINUX_SCAN Use Linux /proc/net/route scanner
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_UNIX_DONTROUTE Use setsockopts DONTROUTE (undef for *BSD)
CONFIG_RESTRICTED_PRIVILEGES Implements restricted privileges using drop_uid()
......@@ -10,14 +10,8 @@
#define CONFIG_AUTO_ROUTES
#define CONFIG_SELF_CONSCIOUS
#undef CONFIG_MULTIPLE_TABLES
#undef CONFIG_UNIX_IFACE
#undef CONFIG_UNIX_SET
#define CONFIG_SKIP_MC_BIND
#define CONFIG_ALL_MULTICAST
#define CONFIG_UNNUM_MULTICAST
/*
Link: sysdep/unix
......
......@@ -8,15 +8,8 @@
#define CONFIG_AUTO_ROUTES
#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_ALL_MULTICAST
#define CONFIG_UNNUM_MULTICAST
/*
Link: sysdep/unix
......
/*
* 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
*/
/*
* 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
*/
/*
* 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
*/
/*
* Configuration for Linux 2.2 based systems running IPv6
* Configuration for Linux based systems running IPv6
*
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
*
......@@ -9,20 +9,13 @@
#define IPV6
#define CONFIG_AUTO_ROUTES
#define CONFIG_ALL_MULTICAST
#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_ALL_TABLES_AT_ONCE
#define CONFIG_RESTRICTED_PRIVILEGES
/*
Link: sysdep/linux/netlink
Link: sysdep/linux
Link: sysdep/unix
*/
#ifdef CONFIG_LINUX_SCAN
krt-scan.c
krt-scan.h
#endif
krt-sys.h
netlink.c
netlink.Y
sysio.h
syspriv.h
/*
* 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)
{
}
/*
* 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
krt-iface.h
krt-set.h
krt-scan.h
netlink.c
netlink.Y
/*
* 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
/*
* 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
/*
* 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
/*
* 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
This diff is collapsed.
......@@ -57,45 +57,6 @@ get_inaddr(ip_addr *a, struct in_addr *ia)
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 kernel