diff options
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/Modules | 10 | ||||
-rw-r--r-- | sysdep/unix/io.c | 2 | ||||
-rw-r--r-- | sysdep/unix/krt-iface.c | 228 | ||||
-rw-r--r-- | sysdep/unix/krt-iface.h | 29 | ||||
-rw-r--r-- | sysdep/unix/krt-set.c | 112 | ||||
-rw-r--r-- | sysdep/unix/krt-set.h | 27 | ||||
-rw-r--r-- | sysdep/unix/krt.c | 12 | ||||
-rw-r--r-- | sysdep/unix/krt.h | 9 |
8 files changed, 14 insertions, 415 deletions
diff --git a/sysdep/unix/Modules b/sysdep/unix/Modules index 2666f9d6..2c6514df 100644 --- a/sysdep/unix/Modules +++ b/sysdep/unix/Modules @@ -10,13 +10,3 @@ random.c krt.c krt.h krt.Y - -#ifdef CONFIG_UNIX_IFACE -krt-iface.c -krt-iface.h -#endif - -#ifdef CONFIG_UNIX_SET -krt-set.c -krt-set.h -#endif diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 2dced67a..475d660c 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -950,7 +950,7 @@ int sk_join_group(sock *s, ip_addr maddr) { struct ipv6_mreq mreq; - + set_inaddr(&mreq.ipv6mr_multiaddr, maddr); #ifdef CONFIG_IPV6_GLIBC_20 diff --git a/sysdep/unix/krt-iface.c b/sysdep/unix/krt-iface.c deleted file mode 100644 index 88c17ecd..00000000 --- a/sysdep/unix/krt-iface.c +++ /dev/null @@ -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"); -} - diff --git a/sysdep/unix/krt-iface.h b/sysdep/unix/krt-iface.h deleted file mode 100644 index e9e8e507..00000000 --- a/sysdep/unix/krt-iface.h +++ /dev/null @@ -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 diff --git a/sysdep/unix/krt-set.c b/sysdep/unix/krt-set.c deleted file mode 100644 index 252c5d3e..00000000 --- a/sysdep/unix/krt-set.c +++ /dev/null @@ -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) -{ -} - diff --git a/sysdep/unix/krt-set.h b/sysdep/unix/krt-set.h deleted file mode 100644 index 8ef3170e..00000000 --- a/sysdep/unix/krt-set.h +++ /dev/null @@ -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 diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index cc03bb88..b0d22227 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -23,7 +23,7 @@ * 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, 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. * * 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 * KRT instance to be initialized later and performing table scan * 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_filter_lp = lp_new(krt_pool, 4080); - kif_sys_io_init(); } /* diff --git a/sysdep/unix/krt.h b/sysdep/unix/krt.h index a3b5658a..9d5639f2 100644 --- a/sysdep/unix/krt.h +++ b/sysdep/unix/krt.h @@ -15,9 +15,7 @@ struct krt_proto; struct kif_config; struct kif_proto; -#include "lib/krt-scan.h" -#include "lib/krt-set.h" -#include "lib/krt-iface.h" +#include "lib/krt-sys.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); -/* krt-scan.c */ +/* krt sysdep */ void krt_sys_init(struct krt_proto *); 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); -/* krt-iface.c */ +/* kif sysdep */ void kif_sys_init(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_sys_io_init(void); #endif |