summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2015-07-16 15:31:36 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2015-07-16 15:31:36 +0000
commit3290c14efe2dd37257099840669fb064abb55551 (patch)
treeba5a3711491cbf10b279533a2cd8ef33426d9691
parente01a414823cbe4b676a262418678ea1f5aa1adc4 (diff)
Properly layer Router Solicitation code.
Tweak and ok florian@
-rw-r--r--sys/net/if.c15
-rw-r--r--sys/netinet6/in6_ifattach.c11
-rw-r--r--sys/netinet6/nd6.c42
-rw-r--r--sys/netinet6/nd6.h17
-rw-r--r--sys/netinet6/nd6_rtr.c78
5 files changed, 91 insertions, 72 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index ce5d5294282..d25a5400c40 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.349 2015/07/02 15:16:57 mpi Exp $ */
+/* $OpenBSD: if.c,v 1.350 2015/07/16 15:31:35 mpi Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1403,21 +1403,12 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
if ((ifr->ifr_flags & IFXF_AUTOCONF6) &&
!(ifp->if_xflags & IFXF_AUTOCONF6)) {
- nd6_rs_timeout_count++;
- RS_LHCOOKIE(ifp) = hook_establish(
- ifp->if_linkstatehooks, 1, nd6_rs_dev_state, ifp);
- if (!timeout_pending(&nd6_rs_output_timer))
- nd6_rs_output_set_timo(
- ND6_RS_OUTPUT_QUICK_INTERVAL);
+ nd6_rs_attach(ifp);
}
if ((ifp->if_xflags & IFXF_AUTOCONF6) &&
!(ifr->ifr_flags & IFXF_AUTOCONF6)) {
- hook_disestablish(ifp->if_linkstatehooks,
- RS_LHCOOKIE(ifp));
- nd6_rs_timeout_count--;
- if (nd6_rs_timeout_count == 0)
- timeout_del(&nd6_rs_output_timer);
+ nd6_rs_detach(ifp);
}
#endif /* INET6 */
diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c
index 3c027cbdc43..a9058f60c0d 100644
--- a/sys/netinet6/in6_ifattach.c
+++ b/sys/netinet6/in6_ifattach.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_ifattach.c,v 1.88 2015/06/08 22:19:28 krw Exp $ */
+/* $OpenBSD: in6_ifattach.c,v 1.89 2015/07/16 15:31:35 mpi Exp $ */
/* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */
/*
@@ -580,7 +580,7 @@ in6_ifattach(struct ifnet *ifp)
}
if (ifp->if_xflags & IFXF_AUTOCONF6)
- nd6_rs_output_set_timo(ND6_RS_OUTPUT_QUICK_INTERVAL);
+ nd6_rs_attach(ifp);
return (0);
}
@@ -639,12 +639,7 @@ in6_ifdetach(struct ifnet *ifp)
}
if (ifp->if_xflags & IFXF_AUTOCONF6) {
- nd6_rs_timeout_count--;
- if (nd6_rs_timeout_count == 0)
- timeout_del(&nd6_rs_output_timer);
- if (RS_LHCOOKIE(ifp) != NULL)
- hook_disestablish(ifp->if_linkstatehooks,
- RS_LHCOOKIE(ifp));
+ nd6_rs_detach(ifp);
ifp->if_xflags &= ~IFXF_AUTOCONF6;
}
}
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 8847335b8df..138909aa2f1 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.c,v 1.142 2015/07/15 22:16:42 deraadt Exp $ */
+/* $OpenBSD: nd6.c,v 1.143 2015/07/16 15:31:35 mpi Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@@ -102,11 +102,6 @@ struct timeout nd6_timer_ch;
struct task nd6_timer_task;
void nd6_timer_work(void *);
-struct timeout nd6_rs_output_timer;
-int nd6_rs_output_timeout = ND6_RS_OUTPUT_INTERVAL;
-int nd6_rs_timeout_count = 0;
-void nd6_rs_output_timo(void *);
-
int fill_drlist(void *, size_t *, size_t);
int fill_prlist(void *, size_t *, size_t);
@@ -142,7 +137,7 @@ nd6_init(void)
timeout_set(&nd6_slowtimo_ch, nd6_slowtimo, NULL);
timeout_add_sec(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL);
- timeout_set(&nd6_rs_output_timer, nd6_rs_output_timo, NULL);
+ nd6_rs_init();
}
struct nd_ifinfo *
@@ -1563,39 +1558,6 @@ nd6_slowtimo(void *ignored_arg)
splx(s);
}
-void
-nd6_rs_output_set_timo(int timeout)
-{
- nd6_rs_output_timeout = timeout;
- timeout_add_sec(&nd6_rs_output_timer, nd6_rs_output_timeout);
-}
-
-void
-nd6_rs_output_timo(void *ignored_arg)
-{
- struct ifnet *ifp;
- struct in6_ifaddr *ia6;
-
- if (nd6_rs_timeout_count == 0)
- return;
-
- if (nd6_rs_output_timeout < ND6_RS_OUTPUT_INTERVAL)
- /* exponential backoff if running quick timeouts */
- nd6_rs_output_timeout *= 2;
- if (nd6_rs_output_timeout > ND6_RS_OUTPUT_INTERVAL)
- nd6_rs_output_timeout = ND6_RS_OUTPUT_INTERVAL;
-
- TAILQ_FOREACH(ifp, &ifnet, if_list) {
- if (ISSET(ifp->if_flags, IFF_RUNNING) &&
- ISSET(ifp->if_xflags, IFXF_AUTOCONF6)) {
- ia6 = in6ifa_ifpforlinklocal(ifp, IN6_IFF_TENTATIVE);
- if (ia6 != NULL)
- nd6_rs_output(ifp, ia6);
- }
- }
- timeout_add_sec(&nd6_rs_output_timer, nd6_rs_output_timeout);
-}
-
#define senderr(e) { error = (e); goto bad;}
int
nd6_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr_in6 *dst,
diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h
index f15b18fea64..9286ae599bf 100644
--- a/sys/netinet6/nd6.h
+++ b/sys/netinet6/nd6.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.h,v 1.42 2015/07/09 05:45:25 mpi Exp $ */
+/* $OpenBSD: nd6.h,v 1.43 2015/07/16 15:31:35 mpi Exp $ */
/* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */
/*
@@ -233,12 +233,6 @@ extern int nd6_debug;
extern struct timeout nd6_timer_ch;
-#define ND6_RS_OUTPUT_INTERVAL 60
-#define ND6_RS_OUTPUT_QUICK_INTERVAL 1
-extern struct timeout nd6_rs_output_timer;
-extern int nd6_rs_output_timeout;
-extern int nd6_rs_timeout_count;
-
union nd_opts {
struct nd_opt_hdr *nd_opt_array[9];
struct {
@@ -299,12 +293,13 @@ void nd6_ns_output(struct ifnet *, struct in6_addr *,
caddr_t nd6_ifptomac(struct ifnet *);
void nd6_dad_start(struct ifaddr *, int *);
void nd6_dad_stop(struct ifaddr *);
+void nd6_ra_input(struct mbuf *, int, int);
+void nd6_rs_init(void);
+void nd6_rs_attach(struct ifnet *);
+void nd6_rs_detach(struct ifnet *);
void nd6_rs_input(struct mbuf *, int, int);
-void nd6_ra_input(struct mbuf *, int, int);
-void nd6_rs_output_set_timo(int);
-void nd6_rs_output(struct ifnet *, struct in6_ifaddr *);
-void nd6_rs_dev_state(void *);
+
void prelist_del(struct nd_prefix *);
void defrouter_addreq(struct nd_defrouter *);
void defrouter_reset(void);
diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index 6eeb29149cb..28ef3f8e674 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6_rtr.c,v 1.108 2015/07/08 07:56:51 mpi Exp $ */
+/* $OpenBSD: nd6_rtr.c,v 1.109 2015/07/16 15:31:35 mpi Exp $ */
/* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */
/*
@@ -76,8 +76,27 @@ int rt6_deleteroute(struct radix_node *, void *, u_int);
void nd6_addr_add(void *);
+void nd6_rs_output_timo(void *);
+void nd6_rs_output_set_timo(int);
+void nd6_rs_output(struct ifnet *, struct in6_ifaddr *);
+void nd6_rs_dev_state(void *);
+
extern int nd6_recalc_reachtm_interval;
+#define ND6_RS_OUTPUT_INTERVAL 60
+#define ND6_RS_OUTPUT_QUICK_INTERVAL 1
+
+struct timeout nd6_rs_output_timer;
+int nd6_rs_output_timeout = ND6_RS_OUTPUT_INTERVAL;
+int nd6_rs_timeout_count = 0;
+
+void
+nd6_rs_init(void)
+{
+ timeout_set(&nd6_rs_output_timer, nd6_rs_output_timo, NULL);
+}
+
+
/*
* Receive Router Solicitation Message - just for routers.
* Router solicitation/advertisement is mostly managed by userland program
@@ -260,6 +279,63 @@ nd6_rs_output(struct ifnet* ifp, struct in6_ifaddr *ia6)
}
void
+nd6_rs_output_set_timo(int timeout)
+{
+ nd6_rs_output_timeout = timeout;
+ timeout_add_sec(&nd6_rs_output_timer, nd6_rs_output_timeout);
+}
+
+void
+nd6_rs_output_timo(void *ignored_arg)
+{
+ struct ifnet *ifp;
+ struct in6_ifaddr *ia6;
+
+ if (nd6_rs_timeout_count == 0)
+ return;
+
+ if (nd6_rs_output_timeout < ND6_RS_OUTPUT_INTERVAL)
+ /* exponential backoff if running quick timeouts */
+ nd6_rs_output_timeout *= 2;
+ if (nd6_rs_output_timeout > ND6_RS_OUTPUT_INTERVAL)
+ nd6_rs_output_timeout = ND6_RS_OUTPUT_INTERVAL;
+
+ TAILQ_FOREACH(ifp, &ifnet, if_list) {
+ if (ISSET(ifp->if_flags, IFF_RUNNING) &&
+ ISSET(ifp->if_xflags, IFXF_AUTOCONF6)) {
+ ia6 = in6ifa_ifpforlinklocal(ifp, IN6_IFF_TENTATIVE);
+ if (ia6 != NULL)
+ nd6_rs_output(ifp, ia6);
+ }
+ }
+ timeout_add_sec(&nd6_rs_output_timer, nd6_rs_output_timeout);
+}
+
+void
+nd6_rs_attach(struct ifnet *ifp)
+{
+ if (!ISSET(ifp->if_xflags, IFXF_AUTOCONF6)) {
+ nd6_rs_timeout_count++;
+ RS_LHCOOKIE(ifp) = hook_establish(ifp->if_linkstatehooks, 1,
+ nd6_rs_dev_state, ifp);
+ }
+
+ nd6_rs_output_set_timo(ND6_RS_OUTPUT_QUICK_INTERVAL);
+}
+
+void
+nd6_rs_detach(struct ifnet *ifp)
+{
+ if (ISSET(ifp->if_xflags, IFXF_AUTOCONF6)) {
+ nd6_rs_timeout_count--;
+ hook_disestablish(ifp->if_linkstatehooks, RS_LHCOOKIE(ifp));
+ }
+
+ if (nd6_rs_timeout_count == 0)
+ timeout_del(&nd6_rs_output_timer);
+}
+
+void
nd6_rs_dev_state(void *arg)
{
struct ifnet *ifp;