Move default interface things from nd6_rtr.c to nd6.c

This commit is contained in:
ozaki-r 2016-12-11 07:37:53 +00:00
parent 100c447a96
commit 091c448c26
3 changed files with 39 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nd6.c,v 1.211 2016/11/14 02:34:19 ozaki-r Exp $ */
/* $NetBSD: nd6.c,v 1.212 2016/12/11 07:37:53 ozaki-r Exp $ */
/* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.211 2016/11/14 02:34:19 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.212 2016/12/11 07:37:53 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@ -125,6 +125,11 @@ static struct work nd6_timer_wk;
static int fill_drlist(void *, size_t *, size_t);
static int fill_prlist(void *, size_t *, size_t);
static struct ifnet *nd6_defifp;
static int nd6_defifindex;
static int nd6_setdefaultiface(int);
MALLOC_DEFINE(M_IP6NDP, "NDP", "IPv6 Neighbour Discovery");
void
@ -2780,3 +2785,32 @@ fill_prlist(void *oldp, size_t *oldlenp, size_t ol)
return error;
}
static int
nd6_setdefaultiface(int ifindex)
{
ifnet_t *ifp;
int error = 0;
int s;
s = pserialize_read_enter();
ifp = if_byindex(ifindex);
if (ifp == NULL) {
pserialize_read_exit(s);
return EINVAL;
}
if (nd6_defifindex != ifindex) {
nd6_defifindex = ifindex;
nd6_defifp = nd6_defifindex > 0 ? ifp : NULL;
/*
* Our current implementation assumes one-to-one maping between
* interfaces and links, so it would be natural to use the
* default interface as the default link.
*/
scope6_setdefault(nd6_defifp);
}
pserialize_read_exit(s);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: nd6.h,v 1.74 2016/12/11 07:36:55 ozaki-r Exp $ */
/* $NetBSD: nd6.h,v 1.75 2016/12/11 07:37:53 ozaki-r Exp $ */
/* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */
/*
@ -354,7 +354,6 @@ extern int nd6_debug;
do { if (nd6_debug) log(level, "%s: " fmt, __func__, ##args);} while (0)
/* nd6_rtr.c */
extern int nd6_defifindex;
extern int ip6_desync_factor; /* seconds */
extern u_int32_t ip6_temp_preferred_lifetime; /* seconds */
extern u_int32_t ip6_temp_valid_lifetime; /* seconds */
@ -441,7 +440,6 @@ void prelist_remove(struct nd_prefix *);
void pfxlist_onlink_check(void);
struct nd_defrouter *defrouter_lookup(const struct in6_addr *, struct ifnet *);
void rt6_flush(struct in6_addr *, struct ifnet *);
int nd6_setdefaultiface(int);
int in6_tmpifadd(const struct in6_ifaddr *, int, int);
bool nd6_accepts_rtadv(const struct nd_ifinfo *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nd6_rtr.c,v 1.121 2016/12/11 07:36:55 ozaki-r Exp $ */
/* $NetBSD: nd6_rtr.c,v 1.122 2016/12/11 07:37:53 ozaki-r Exp $ */
/* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.121 2016/12/11 07:36:55 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.122 2016/12/11 07:37:53 ozaki-r Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -92,9 +92,6 @@ static struct nd_prefix *nd6_prefix_lookup(struct nd_prefixctl *);
extern int nd6_recalc_reachtm_interval;
static struct ifnet *nd6_defifp;
int nd6_defifindex;
int ip6_use_tempaddr = 0;
int ip6_desync_factor;
@ -2203,32 +2200,3 @@ rt6_deleteroute_matcher(struct rtentry *rt, void *arg)
return 1;
}
int
nd6_setdefaultiface(int ifindex)
{
ifnet_t *ifp;
int error = 0;
int s;
s = pserialize_read_enter();
ifp = if_byindex(ifindex);
if (ifp == NULL) {
pserialize_read_exit(s);
return EINVAL;
}
if (nd6_defifindex != ifindex) {
nd6_defifindex = ifindex;
nd6_defifp = nd6_defifindex > 0 ? ifp : NULL;
/*
* Our current implementation assumes one-to-one maping between
* interfaces and links, so it would be natural to use the
* default interface as the default link.
*/
scope6_setdefault(nd6_defifp);
}
pserialize_read_exit(s);
return (error);
}