summaryrefslogtreecommitdiff
path: root/sysdep/linux/netlink
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep/linux/netlink')
-rw-r--r--sysdep/linux/netlink/Modules8
-rw-r--r--sysdep/linux/netlink/krt-iface.h26
-rw-r--r--sysdep/linux/netlink/krt-scan.h26
-rw-r--r--sysdep/linux/netlink/krt-set.h26
-rw-r--r--sysdep/linux/netlink/krt.Y46
-rw-r--r--sysdep/linux/netlink/krt.h30
-rw-r--r--sysdep/linux/netlink/netlink.Y25
-rw-r--r--sysdep/linux/netlink/netlink.c (renamed from sysdep/linux/netlink/krt.c)113
8 files changed, 161 insertions, 139 deletions
diff --git a/sysdep/linux/netlink/Modules b/sysdep/linux/netlink/Modules
index 80338101..c26f7f72 100644
--- a/sysdep/linux/netlink/Modules
+++ b/sysdep/linux/netlink/Modules
@@ -1,3 +1,5 @@
-krt.c
-krt.h
-krt.Y
+krt-iface.h
+krt-set.h
+krt-scan.h
+netlink.c
+netlink.Y
diff --git a/sysdep/linux/netlink/krt-iface.h b/sysdep/linux/netlink/krt-iface.h
new file mode 100644
index 00000000..5dfb934f
--- /dev/null
+++ b/sysdep/linux/netlink/krt-iface.h
@@ -0,0 +1,26 @@
+/*
+ * 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 krt_if_params {
+};
+
+struct krt_if_status {
+};
+
+static inline void krt_if_preconfig(struct krt_config *c) { };
+static inline void krt_if_start(struct krt_proto *p) { };
+static inline void krt_if_shutdown(struct krt_proto *p) { };
+
+#endif
diff --git a/sysdep/linux/netlink/krt-scan.h b/sysdep/linux/netlink/krt-scan.h
new file mode 100644
index 00000000..cd118de4
--- /dev/null
+++ b/sysdep/linux/netlink/krt-scan.h
@@ -0,0 +1,26 @@
+/*
+ * BIRD -- Linux Kernel Netlink Route Syncer -- Scanning
+ *
+ * (c) 1998--1999 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.
+ */
+
+struct krt_scan_params {
+ int async; /* Allow asynchronous events */
+};
+
+struct krt_scan_status {
+ list temp_ifs; /* Temporary interfaces */
+};
+
+#endif
diff --git a/sysdep/linux/netlink/krt-set.h b/sysdep/linux/netlink/krt-set.h
new file mode 100644
index 00000000..32fdad0a
--- /dev/null
+++ b/sysdep/linux/netlink/krt-set.h
@@ -0,0 +1,26 @@
+/*
+ * BIRD -- Unix Kernel Netlink Route 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_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_preconfig(struct krt_config *c) { };
+static inline void krt_set_start(struct krt_proto *p) { };
+static inline void krt_set_shutdown(struct krt_proto *p) { };
+
+#endif
diff --git a/sysdep/linux/netlink/krt.Y b/sysdep/linux/netlink/krt.Y
deleted file mode 100644
index c5726408..00000000
--- a/sysdep/linux/netlink/krt.Y
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * BIRD -- Netlink Interface Configuration
- *
- * (c) 1999 Martin Mares <mj@ucw.cz>
- *
- * Can be freely distributed and used under the terms of the GNU GPL.
- */
-
-CF_HDR
-
-#include "lib/krt.h"
-
-#define KRT_PROTO ((struct krt_config *) this_proto)
-
-CF_DECLS
-
-CF_KEYWORDS(KERNEL, PERSIST, ROUTE, SCAN, TIME, LEARN)
-
-CF_GRAMMAR
-
-/* Kernel protocol */
-
-CF_ADDTO(proto, kern_proto '}')
-
-kern_proto_start: proto_start KERNEL {
- if (!(this_proto = cf_krt)) cf_error("Kernel protocol already defined");
- cf_krt = NULL;
- }
- ;
-
-kern_proto:
- kern_proto_start '{'
- | kern_proto proto_item ';'
- | kern_proto kern_item ';'
- ;
-
-kern_item:
- PERSIST bool { KRT_PROTO->persist = $2; }
- | SCAN TIME expr { KRT_PROTO->scan_time = $3; }
- | LEARN bool { KRT_PROTO->learn = $2; }
- | ROUTE SCAN TIME expr { KRT_PROTO->route_scan_time = $4; }
- ;
-
-CF_CODE
-
-CF_END
diff --git a/sysdep/linux/netlink/krt.h b/sysdep/linux/netlink/krt.h
deleted file mode 100644
index 8dd55cc5..00000000
--- a/sysdep/linux/netlink/krt.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * BIRD -- Linux Netlink Interface
- *
- * (c) 1999 Martin Mares <mj@ucw.cz>
- *
- * Can be freely distributed and used under the terms of the GNU GPL.
- */
-
-#ifndef _BIRD_NETLINK_KRT_H_
-#define _BIRD_NETLINK_KRT_H_
-
-extern struct protocol proto_unix_kernel;
-
-struct krt_config {
- struct proto_config c;
- int persist; /* Keep routes when we exit */
- int scan_time; /* How often we re-scan interfaces */
- int route_scan_time; /* How often we re-scan routes */
- int learn; /* Learn routes from other sources */
-};
-
-extern struct proto_config *cf_krt;
-
-struct krt_proto {
- struct proto p;
-};
-
-void scan_if_init(void);
-
-#endif
diff --git a/sysdep/linux/netlink/netlink.Y b/sysdep/linux/netlink/netlink.Y
new file mode 100644
index 00000000..b5c45f29
--- /dev/null
+++ b/sysdep/linux/netlink/netlink.Y
@@ -0,0 +1,25 @@
+/*
+ * BIRD -- Linux Netlink Configuration
+ *
+ * (c) 1999 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)
+
+CF_GRAMMAR
+
+CF_ADDTO(kern_proto, kern_proto nl_item ';')
+
+nl_item:
+ ASYNC bool { THIS_KRT->scan.async = $2; }
+ ;
+
+CF_CODE
+
+CF_END
diff --git a/sysdep/linux/netlink/krt.c b/sysdep/linux/netlink/netlink.c
index c399e201..6e6fafd3 100644
--- a/sysdep/linux/netlink/krt.c
+++ b/sysdep/linux/netlink/netlink.c
@@ -15,8 +15,6 @@
#define LOCAL_DEBUG
-#undef ASYNC_NETLINK /* Define if async notifications should be used (debug) */
-
#include "nest/bird.h"
#include "nest/route.h"
#include "nest/protocol.h"
@@ -46,13 +44,11 @@
#define MSG_TRUNC 0x20
#endif
-struct proto_config *cf_krt;
-
/*
* Synchronous Netlink interface
*/
-static int nl_sync_fd; /* Unix socket for synchronous netlink actions */
+static int nl_sync_fd = -1; /* Unix socket for synchronous netlink actions */
static u32 nl_sync_seq; /* Sequence number of last request sent */
static byte *nl_rx_buffer; /* Receive buffer */
@@ -62,6 +58,19 @@ static struct nlmsghdr *nl_last_hdr; /* Recently received packet */
static unsigned int nl_last_size;
static void
+nl_open(void)
+{
+ if (nl_sync_fd < 0)
+ {
+ nl_sync_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (nl_sync_fd < 0)
+ die("Unable to open rtnetlink socket: %m");
+ nl_sync_seq = now;
+ nl_rx_buffer = xmalloc(nl_rx_size);
+ }
+}
+
+static void
nl_send(void *rq, int size)
{
struct nlmsghdr *nh = rq;
@@ -327,8 +336,8 @@ nl_parse_addr(struct nlmsghdr *h)
if_update(&f);
}
-static void
-nl_scan_ifaces(void)
+void
+krt_if_scan(struct krt_proto *p)
{
struct nlmsghdr *h;
@@ -352,46 +361,48 @@ nl_scan_ifaces(void)
}
/*
- * Asynchronous Netlink interface
+ * Routes
*/
-static sock *nl_async_sk; /* BIRD socket for asynchronous notifications */
+int
+krt_capable(rte *e)
+{
+ return 1; /* FIXME */
+}
-static int
-nl_async_hook(sock *sk, int size)
+void
+krt_set_notify(struct proto *p, net *n, rte *new, rte *old)
+{
+ /* FIXME */
+}
+
+void
+krt_scan_fire(struct krt_proto *p)
{
- DBG("nl_async_hook\n");
- return 0;
}
/*
- * Protocol core
+ * Asynchronous Netlink interface
*/
-static void
-krt_preconfig(struct protocol *x, struct config *c)
-{
- struct krt_config *z = proto_config_new(&proto_unix_kernel, sizeof(struct krt_config));
-
- cf_krt = &z->c;
- z->c.preference = DEF_PREF_UKR;
-}
+static sock *nl_async_sk; /* BIRD socket for asynchronous notifications */
-static struct proto *
-krt_init(struct proto_config *c)
+static int
+nl_async_hook(sock *sk, int size)
{
- struct krt_proto *p = proto_new(c, sizeof(struct krt_proto));
-
- return &p->p;
+ DBG("nl_async_hook\n");
+ return 0;
}
static void
-nl_open_async(struct proto *p)
+nl_open_async(struct krt_proto *p)
{
sock *sk;
struct sockaddr_nl sa;
- sk = nl_async_sk = sk_new(p->pool);
+ DBG("KRT: Opening async netlink socket\n");
+
+ sk = nl_async_sk = sk_new(p->p.pool);
sk->type = SK_MAGIC;
sk->rx_hook = nl_async_hook;
sk->fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
@@ -405,43 +416,25 @@ nl_open_async(struct proto *p)
die("Unable to bind secondary rtnetlink socket: %m");
}
-static int
-krt_start(struct proto *p)
-{
-#ifdef ASYNC_NETLINK
- nl_open_async(p);
-#endif
-
- /* FIXME: Filter kernel routing table etc. */
+/*
+ * Interface to the UNIX krt module
+ */
- return PS_UP;
+void
+krt_scan_preconfig(struct krt_config *x)
+{
+ x->scan.async = 1;
}
-static int
-krt_shutdown(struct proto *p)
+void
+krt_scan_start(struct krt_proto *p)
{
- /* FIXME: Remove all our routes from the kernel */
-
- return PS_DOWN;
+ nl_open();
+ if (KRT_CF->scan.async)
+ nl_open_async(p);
}
void
-scan_if_init(void)
+krt_scan_shutdown(struct krt_proto *p)
{
- nl_sync_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
- if (nl_sync_fd < 0)
- die("Unable to open rtnetlink socket: %m");
- nl_sync_seq = now;
- nl_rx_buffer = xmalloc(nl_rx_size);
- /* FIXME: Should we fetch our local address and compare it with addresses of all incoming messages? */
-
- nl_scan_ifaces();
}
-
-struct protocol proto_unix_kernel = {
- name: "Kernel",
- preconfig: krt_preconfig,
- init: krt_init,
- start: krt_start,
- shutdown: krt_shutdown
-};