summaryrefslogtreecommitdiff
path: root/usr.sbin/dvmrpd
diff options
context:
space:
mode:
authorMichele Marchetto <michele@cvs.openbsd.org>2006-12-03 20:14:38 +0000
committerMichele Marchetto <michele@cvs.openbsd.org>2006-12-03 20:14:38 +0000
commit203a010fa05f5d3d23b26d1223c532e480a3646d (patch)
tree72f2e6289f3d3b7e0e8f47862ffad7d6a6261044 /usr.sbin/dvmrpd
parent41305b9b281484e92a86490007074dedb744834d (diff)
introduce rde_check_route that selects which routes must be accepted and which discarded.
Still not complete, just a step forward. ok norby@ henning@
Diffstat (limited to 'usr.sbin/dvmrpd')
-rw-r--r--usr.sbin/dvmrpd/dvmrpd.h7
-rw-r--r--usr.sbin/dvmrpd/interface.c17
-rw-r--r--usr.sbin/dvmrpd/rde.c15
-rw-r--r--usr.sbin/dvmrpd/rde.h7
-rw-r--r--usr.sbin/dvmrpd/rde_mfc.c4
-rw-r--r--usr.sbin/dvmrpd/rde_srt.c86
-rw-r--r--usr.sbin/dvmrpd/report.c9
7 files changed, 90 insertions, 55 deletions
diff --git a/usr.sbin/dvmrpd/dvmrpd.h b/usr.sbin/dvmrpd/dvmrpd.h
index 8e6ef2b89e6..c34a3e5c045 100644
--- a/usr.sbin/dvmrpd/dvmrpd.h
+++ b/usr.sbin/dvmrpd/dvmrpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dvmrpd.h,v 1.4 2006/06/02 15:43:16 norby Exp $ */
+/* $OpenBSD: dvmrpd.h,v 1.5 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -445,7 +445,10 @@ const char *if_type_name(enum iface_type);
const char *group_state_name(int);
/* printconf.c */
-void print_config(struct dvmrpd_conf *);
+void print_config(struct dvmrpd_conf *);
+
+/* interface.c */
+struct iface *if_find_index(u_short);
#define PREFIX_SIZE(x) (((x) + 7) / 8)
diff --git a/usr.sbin/dvmrpd/interface.c b/usr.sbin/dvmrpd/interface.c
index 453e7683d21..1ee259d535e 100644
--- a/usr.sbin/dvmrpd/interface.c
+++ b/usr.sbin/dvmrpd/interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interface.c,v 1.3 2006/06/02 17:06:50 norby Exp $ */
+/* $OpenBSD: interface.c,v 1.4 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -41,6 +41,8 @@
#include "log.h"
#include "dvmrpe.h"
+extern struct dvmrpd_conf *conf;
+
void if_probe_timer(int, short, void *);
int if_start_probe_timer(struct iface *);
int if_stop_probe_timer(struct iface *);
@@ -143,6 +145,19 @@ if_fsm(struct iface *iface, enum iface_event event)
}
struct iface *
+if_find_index(u_short ifindex)
+{
+ struct iface *iface;
+
+ LIST_FOREACH(iface, &conf->iface_list, entry) {
+ if (iface->ifindex == ifindex)
+ return (iface);
+ }
+
+ return (NULL);
+}
+
+struct iface *
if_new(struct kif *kif)
{
struct sockaddr_in *sain;
diff --git a/usr.sbin/dvmrpd/rde.c b/usr.sbin/dvmrpd/rde.c
index f4377705d5c..587f994cb68 100644
--- a/usr.sbin/dvmrpd/rde.c
+++ b/usr.sbin/dvmrpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.2 2006/06/01 21:47:27 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.3 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -188,8 +188,7 @@ rde_dispatch_imsg(int fd, short event, void *bula)
struct imsgbuf *ibuf = bula;
struct imsg imsg;
struct route_report rr;
- int n, connected = 0;
- int i;
+ int i, n, connected = 0;
struct iface *iface;
switch (event) {
@@ -231,12 +230,12 @@ rde_dispatch_imsg(int fd, short event, void *bula)
memcpy(&rr, imsg.data, sizeof(rr));
/* directly connected networks from parent */
- if (imsg.hdr.peerid == 0) {
+ if (imsg.hdr.peerid == 0)
connected = 1;
- }
- rt_update(rr.net, mask2prefixlen(rr.mask.s_addr),
- rr.nexthop, rr.metric, rr.adv_rtr, rr.ifindex, 0,
- connected);
+
+ if (rde_check_route(&rr, connected) == -1)
+ log_debug("rde_dispatch_imsg: "
+ "packet malformed");
break;
case IMSG_FULL_ROUTE_REPORT:
rt_snap(imsg.hdr.peerid);
diff --git a/usr.sbin/dvmrpd/rde.h b/usr.sbin/dvmrpd/rde.h
index 8483a05d0cd..ce8a01249ff 100644
--- a/usr.sbin/dvmrpd/rde.h
+++ b/usr.sbin/dvmrpd/rde.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.h,v 1.1 2006/06/01 14:12:20 norby Exp $ */
+/* $OpenBSD: rde.h,v 1.2 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -71,12 +71,13 @@ void mfc_delete(struct mfc *);
void rt_init(void);
int rt_compare(struct rt_node *, struct rt_node *);
struct rt_node *rt_find(in_addr_t, u_int8_t);
+struct rt_node *rr_new_rt(struct route_report *, int, int);
int rt_insert(struct rt_node *);
+void rt_update(struct rt_node *);
int rt_remove(struct rt_node *);
void rt_clear(void);
void rt_snap(u_int32_t);
void rt_dump(pid_t);
-void rt_update(struct in_addr, u_int8_t, struct in_addr,
- u_int32_t, struct in_addr, u_short, u_int8_t, u_int8_t);
+int rde_check_route(struct route_report *, int);
#endif /* _RDE_H_ */
diff --git a/usr.sbin/dvmrpd/rde_mfc.c b/usr.sbin/dvmrpd/rde_mfc.c
index b985360fa56..3ca5ff6fb43 100644
--- a/usr.sbin/dvmrpd/rde_mfc.c
+++ b/usr.sbin/dvmrpd/rde_mfc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_mfc.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */
+/* $OpenBSD: rde_mfc.c,v 1.2 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2006 Esben Norby <norby@openbsd.org>
@@ -27,9 +27,9 @@
#include "igmp.h"
#include "dvmrp.h"
#include "dvmrpd.h"
-#include "rde.h"
#include "log.h"
#include "dvmrpe.h"
+#include "rde.h"
/* multicast forwarding cache */
diff --git a/usr.sbin/dvmrpd/rde_srt.c b/usr.sbin/dvmrpd/rde_srt.c
index bc288db30b5..ddca8a45399 100644
--- a/usr.sbin/dvmrpd/rde_srt.c
+++ b/usr.sbin/dvmrpd/rde_srt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_srt.c,v 1.1 2006/06/01 14:12:20 norby Exp $ */
+/* $OpenBSD: rde_srt.c,v 1.2 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -27,9 +27,9 @@
#include "igmp.h"
#include "dvmrp.h"
#include "dvmrpd.h"
-#include "rde.h"
#include "log.h"
#include "dvmrpe.h"
+#include "rde.h"
/* source route tree */
@@ -106,6 +106,31 @@ rt_find(in_addr_t prefix, u_int8_t prefixlen)
return (RB_FIND(rt_tree, &rt, &s));
}
+struct rt_node *
+rr_new_rt(struct route_report *rr, int adj_metric, int connected)
+{
+ struct timespec now;
+ struct rt_node *rn;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+
+ if ((rn = calloc(1, sizeof(*rn))) == NULL)
+ fatal("rr_new_rt");
+
+ rn->prefix.s_addr = rr->net.s_addr;
+ rn->prefixlen = mask2prefixlen(rr->mask.s_addr);
+ rn->nexthop.s_addr = rr->nexthop.s_addr;
+ rn->cost = adj_metric;
+ rn->ifindex = rr->ifindex;
+ rn->flags = F_DVMRPD_INSERTED;
+ rn->connected = connected;
+ rn->uptime = now.tv_sec;
+
+ evtimer_set(&rn->expiration_timer, rt_expire_timer, rn);
+
+ return (rn);
+}
+
int
rt_insert(struct rt_node *r)
{
@@ -209,38 +234,35 @@ rt_dump(pid_t pid)
}
void
-rt_update(struct in_addr prefix, u_int8_t prefixlen, struct in_addr nexthop,
- u_int32_t cost, struct in_addr adv_rtr, u_short ifindex, u_int8_t flags,
- u_int8_t connected)
+rt_update(struct rt_node *rn)
{
- struct timespec now;
- struct rt_node *rte;
+ if (!rn->connected)
+ rt_start_expire_timer(rn);
+}
- clock_gettime(CLOCK_MONOTONIC, &now);
+int
+rde_check_route(struct route_report *rr, int connected)
+{
+ struct rt_node *rn;
+ struct iface *iface;
+ u_int32_t adj_metric;
+
+ if ((iface = if_find_index(rr->ifindex)) == NULL)
+ return (-1);
+
+ /* Interpret special case 0.0.0.0/8 as 0.0.0.0/0 */
+ if (rr->net.s_addr == 0)
+ rr->mask.s_addr = 0;
+
+ adj_metric = rr->metric + iface->metric;
- if ((rte = rt_find(prefix.s_addr, prefixlen)) == NULL) {
- if ((rte = calloc(1, sizeof(struct rt_node))) == NULL)
- fatalx("rt_update");
- rte->prefix.s_addr = prefix.s_addr;
- rte->prefixlen = prefixlen;
- rte->nexthop.s_addr = nexthop.s_addr;
- rte->adv_rtr.s_addr = adv_rtr.s_addr;
- rte->cost = cost;
- rte->ifindex = ifindex;
- rte->flags = flags;
- rte->invalid = 0;
- rte->connected = connected;
- rte->uptime = now.tv_sec;
-
- rt_insert(rte);
-
- evtimer_set(&rte->expiration_timer, rt_expire_timer, rte);
-
- if (!rte->connected)
- rt_start_expire_timer(rte);
-
- } else {
- if (!rte->connected)
- rt_start_expire_timer(rte);
+ if ((rn = rt_find(rr->net.s_addr, mask2prefixlen(rr->mask.s_addr)))
+ == NULL) {
+ rn = rr_new_rt(rr, adj_metric, connected);
+ rt_insert(rn);
}
+
+ rt_update(rn);
+
+ return (0);
}
diff --git a/usr.sbin/dvmrpd/report.c b/usr.sbin/dvmrpd/report.c
index f643f05f641..addef80ae76 100644
--- a/usr.sbin/dvmrpd/report.c
+++ b/usr.sbin/dvmrpd/report.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: report.c,v 1.5 2006/11/10 11:15:32 michele Exp $ */
+/* $OpenBSD: report.c,v 1.6 2006/12/03 20:14:37 michele Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -128,10 +128,6 @@ recv_report(struct nbr *nbr, char *buf, u_int16_t len)
memcpy(&netid, buf, sizeof(netid));
netid &= netmask;
- /* Interpret special case 0.0.0.0/8 as 0.0.0.0/0 */
- if (netid == 0)
- netmask = 0;
-
buf += netid_len;
len -= netid_len;
@@ -143,8 +139,7 @@ recv_report(struct nbr *nbr, char *buf, u_int16_t len)
rr.net.s_addr = netid;
rr.mask.s_addr = netmask;
rr.nexthop = nbr->id;
- /* adjusted metric */
- rr.metric = (metric & METRIC_MASK) + nbr->iface->metric;
+ rr.metric = (metric & METRIC_MASK);
/* ifindex */
rr.ifindex = nbr->iface->ifindex;