summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-11-29 22:03:58 +0000
committerMartin Mares <mj@ucw.cz>1998-11-29 22:03:58 +0000
commit50d8424ad1f40f9979214c1d6cbf8e290ba9a5cb (patch)
tree59f58fdb5b3e37c00c9d4955ed671e4dcec9f814 /nest
parent66efdf962a343c7cf5aef475f35f9e3864cb4fdd (diff)
Added configuration of the device internal protocol. This is primarily
intended to serve as an example of interface pattern list use. As a side effect, you can disable generating of device routes by disabling this protocol.
Diffstat (limited to 'nest')
-rw-r--r--nest/config.Y41
-rw-r--r--nest/protocol.h7
-rw-r--r--nest/rt-dev.c17
-rw-r--r--nest/rt-dev.h17
4 files changed, 79 insertions, 3 deletions
diff --git a/nest/config.Y b/nest/config.Y
index 9efebbe6..7b82ba72 100644
--- a/nest/config.Y
+++ b/nest/config.Y
@@ -10,9 +10,14 @@ CF_HDR
static struct proto *this_proto;
+#include "nest/rt-dev.h"
+
+void rt_dev_add_iface(char *);
+
CF_DECLS
-CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF)
+CF_KEYWORDS(ROUTER, ID, PROTOCOL, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DEVICE)
+CF_KEYWORDS(INTERFACE)
%type <i> idval
@@ -64,6 +69,40 @@ proto_item:
| DEBUG OFF { this_proto->debug = 0; }
;
+/* Device protocol */
+
+CF_ADDTO(proto, dev_proto '}')
+
+dev_proto_start: proto_start DEVICE {
+ if (!(this_proto = cf_dev_proto)) cf_error("Device protocol already defined");
+ cf_dev_proto = NULL;
+ }
+ ;
+
+dev_proto:
+ dev_proto_start '{'
+ | dev_proto proto_item ';'
+ | dev_proto dev_iface_list ';'
+ ;
+
+dev_iface_list:
+ INTERFACE TEXT {
+ init_list(&((struct rt_dev_proto *) this_proto)->iface_list);
+ rt_dev_add_iface($2);
+ }
+ | dev_iface_list ',' TEXT { rt_dev_add_iface($3); }
+ ;
+
CF_CODE
+void
+rt_dev_add_iface(char *n)
+{
+ struct rt_dev_proto *p = (void *) this_proto;
+ struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt));
+
+ k->pattern = cfg_strcpy(n);
+ add_tail(&p->iface_list, &k->n);
+}
+
CF_END
diff --git a/nest/protocol.h b/nest/protocol.h
index 34624e95..59db4287 100644
--- a/nest/protocol.h
+++ b/nest/protocol.h
@@ -75,7 +75,6 @@ struct proto {
void (*rte_remove)(struct network *, struct rte *);
/* Reconfigure function? */
- /* Interface patterns */
/* Input/output filters */
/* Connection to routing tables? */
@@ -90,4 +89,10 @@ void *proto_new(struct protocol *, unsigned size);
extern list proto_list, inactive_proto_list;
+/*
+ * Known unique protocol instances as referenced by config routines
+ */
+
+extern struct proto *cf_dev_proto;
+
#endif
diff --git a/nest/rt-dev.c b/nest/rt-dev.c
index 7ef04f09..e7d43fb1 100644
--- a/nest/rt-dev.c
+++ b/nest/rt-dev.c
@@ -14,11 +14,20 @@
#include "nest/iface.h"
#include "nest/protocol.h"
#include "nest/route.h"
+#include "nest/rt-dev.h"
+#include "conf/conf.h"
#include "lib/resource.h"
+struct proto *cf_dev_proto;
+
static void
dev_if_notify(struct proto *p, unsigned c, struct iface *old, struct iface *new)
{
+ struct rt_dev_proto *P = (void *) p;
+
+ if (old && !iface_patt_match(&P->iface_list, old) ||
+ new && !iface_patt_match(&P->iface_list, new))
+ return;
if (c & IF_CHANGE_DOWN)
{
net *n;
@@ -72,11 +81,17 @@ dev_init(struct protocol *p)
static void
dev_preconfig(struct protocol *x)
{
- struct proto *p = proto_new(&proto_device, sizeof(struct proto));
+ struct rt_dev_proto *P = proto_new(&proto_device, sizeof(struct rt_dev_proto));
+ struct proto *p = &P->p;
+ struct iface_patt *k = cfg_alloc(sizeof(struct iface_patt));
+ cf_dev_proto = p;
p->preference = DEF_PREF_DIRECT;
p->start = dev_start;
p->if_notify = dev_if_notify;
+ init_list(&P->iface_list);
+ k->pattern = "*";
+ add_tail(&P->iface_list, &k->n);
}
static void
diff --git a/nest/rt-dev.h b/nest/rt-dev.h
new file mode 100644
index 00000000..05a7f4c6
--- /dev/null
+++ b/nest/rt-dev.h
@@ -0,0 +1,17 @@
+/*
+ * BIRD -- Direct Device Routes
+ *
+ * (c) 1998 Martin Mares <mj@ucw.cz>
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#ifndef _BIRD_RT_DEV_H_
+#define _BIRD_RT_DEV_H_
+
+struct rt_dev_proto {
+ struct proto p;
+ list iface_list;
+};
+
+#endif