Move INET6 specific in6_if_{up,down}() and in6_if_link_{up,down}()

into agnostic domain functions.
This commit is contained in:
roy 2015-04-22 19:46:08 +00:00
parent 70483504a1
commit b1f5fd8a7f
5 changed files with 55 additions and 35 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.311 2015/04/21 10:39:41 pooka Exp $ */
/* $NetBSD: if.c,v 1.312 2015/04/22 19:46:08 roy Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.311 2015/04/21 10:39:41 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.312 2015/04/22 19:46:08 roy Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@ -1423,9 +1423,8 @@ void
if_link_state_change(struct ifnet *ifp, int link_state)
{
int s;
#if defined(DEBUG) || defined(INET6)
int old_link_state;
#endif
struct domain *dp;
s = splnet();
if (ifp->if_link_state == link_state) {
@ -1433,9 +1432,7 @@ if_link_state_change(struct ifnet *ifp, int link_state)
return;
}
#if defined(DEBUG) || defined(INET6)
old_link_state = ifp->if_link_state;
#endif
ifp->if_link_state = link_state;
#ifdef DEBUG
log(LOG_DEBUG, "%s: link state %s (was %s)\n", ifp->if_xname,
@ -1447,7 +1444,6 @@ if_link_state_change(struct ifnet *ifp, int link_state)
"UNKNOWN");
#endif
#ifdef INET6
/*
* When going from UNKNOWN to UP, we need to mark existing
* IPv6 addresses as tentative and restart DAD as we may have
@ -1457,10 +1453,15 @@ if_link_state_change(struct ifnet *ifp, int link_state)
* listeners would have an address and expect it to work right
* away.
*/
if (in6_present && link_state == LINK_STATE_UP &&
if (link_state == LINK_STATE_UP &&
old_link_state == LINK_STATE_UNKNOWN)
in6_if_link_down(ifp);
#endif
{
DOMAIN_FOREACH(dp) {
if (dp->dom_if_link_state_change != NULL)
dp->dom_if_link_state_change(ifp,
LINK_STATE_DOWN);
}
}
/* Notify that the link state has changed. */
rt_ifmsg(ifp);
@ -1470,14 +1471,10 @@ if_link_state_change(struct ifnet *ifp, int link_state)
carp_carpdev_state(ifp);
#endif
#ifdef INET6
if (in6_present) {
if (link_state == LINK_STATE_DOWN)
in6_if_link_down(ifp);
else if (link_state == LINK_STATE_UP)
in6_if_link_up(ifp);
DOMAIN_FOREACH(dp) {
if (dp->dom_if_link_state_change != NULL)
dp->dom_if_link_state_change(ifp, link_state);
}
#endif
splx(s);
}
@ -1543,6 +1540,7 @@ void
if_down(struct ifnet *ifp)
{
struct ifaddr *ifa;
struct domain *dp;
ifp->if_flags &= ~IFF_UP;
nanotime(&ifp->if_lastchange);
@ -1554,10 +1552,10 @@ if_down(struct ifnet *ifp)
carp_carpdev_state(ifp);
#endif
rt_ifmsg(ifp);
#ifdef INET6
if (in6_present)
in6_if_down(ifp);
#endif
DOMAIN_FOREACH(dp) {
if (dp->dom_if_down)
dp->dom_if_down(ifp);
}
}
/*
@ -1571,6 +1569,7 @@ if_up(struct ifnet *ifp)
#ifdef notyet
struct ifaddr *ifa;
#endif
struct domain *dp;
ifp->if_flags |= IFF_UP;
nanotime(&ifp->if_lastchange);
@ -1584,10 +1583,10 @@ if_up(struct ifnet *ifp)
carp_carpdev_state(ifp);
#endif
rt_ifmsg(ifp);
#ifdef INET6
if (in6_present)
in6_if_up(ifp);
#endif
DOMAIN_FOREACH(dp) {
if (dp->dom_if_down)
dp->dom_if_down(ifp);
}
}
/*
@ -2067,13 +2066,11 @@ doifioctl(struct socket *so, u_long cmd, void *data, struct lwp *l)
}
if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) {
#ifdef INET6
if (in6_present && (ifp->if_flags & IFF_UP) != 0) {
if ((ifp->if_flags & IFF_UP) != 0) {
int s = splnet();
in6_if_up(ifp);
if_up(ifp);
splx(s);
}
#endif
}
#ifdef COMPAT_OIFREQ
if (cmd != ocmd)

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6.c,v 1.187 2015/04/20 10:19:54 roy Exp $ */
/* $NetBSD: in6.c,v 1.188 2015/04/22 19:46:08 roy Exp $ */
/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.187 2015/04/20 10:19:54 roy Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.188 2015/04/22 19:46:08 roy Exp $");
#include "opt_inet.h"
#include "opt_compat_netbsd.h"
@ -2099,6 +2099,20 @@ in6_if_down(struct ifnet *ifp)
in6_if_link_down(ifp);
}
void
in6_if_link_state_change(struct ifnet *ifp, int link_state)
{
switch (link_state) {
case LINK_STATE_DOWN:
in6_if_link_down(ifp);
break;
case LINK_STATE_UP:
in6_if_link_up(ifp);
break;
}
}
/*
* Calculate max IPv6 MTU through all the interfaces and store it
* to in6_maxmtu.

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6.h,v 1.83 2015/02/20 22:13:48 rjs Exp $ */
/* $NetBSD: in6.h,v 1.84 2015/04/22 19:46:08 roy Exp $ */
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
/*
@ -705,6 +705,7 @@ int in6_addrscope(const struct in6_addr *);
struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
extern void in6_if_link_up(struct ifnet *);
extern void in6_if_link_down(struct ifnet *);
extern void in6_if_link_state_change(struct ifnet *, int);
extern void in6_if_up(struct ifnet *);
extern void in6_if_down(struct ifnet *);
#ifndef __FreeBSD__

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6_proto.c,v 1.104 2015/02/10 19:11:52 rjs Exp $ */
/* $NetBSD: in6_proto.c,v 1.105 2015/04/22 19:46:08 roy Exp $ */
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.104 2015/02/10 19:11:52 rjs Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.105 2015/04/22 19:46:08 roy Exp $");
#include "opt_gateway.h"
#include "opt_inet.h"
@ -397,7 +397,9 @@ struct domain inet6domain = {
.dom_rtattach = rt_inithead,
.dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr) << 3,
.dom_maxrtkey = sizeof(struct ip_pack6),
.dom_if_up = in6_if_up, .dom_if_down = in6_if_down,
.dom_ifattach = in6_domifattach, .dom_ifdetach = in6_domifdetach,
.dom_if_link_state_change = in6_if_link_state_change,
.dom_ifqueues = { NULL, NULL },
.dom_link = { NULL },
.dom_mowner = MOWNER_INIT("",""),

View File

@ -1,4 +1,4 @@
/* $NetBSD: domain.h,v 1.31 2011/06/26 16:43:12 christos Exp $ */
/* $NetBSD: domain.h,v 1.32 2015/04/22 19:46:08 roy Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -66,10 +66,16 @@ struct domain {
(rtbl_t **, int);
int dom_rtoffset; /* an arg to rtattach, in bits */
int dom_maxrtkey; /* for routing layer */
void (*dom_if_up) /* ifnet brought up */
(struct ifnet *);
void (*dom_if_down) /* ifnet brought down */
(struct ifnet *);
void *(*dom_ifattach) /* attach af-dependent data on ifnet */
(struct ifnet *);
void (*dom_ifdetach) /* detach af-dependent data on ifnet */
(struct ifnet *, void *);
void (*dom_if_link_state_change)
(struct ifnet *, int);
const void *(*dom_sockaddr_const_addr)(const struct sockaddr *,
socklen_t *);
void *(*dom_sockaddr_addr)(struct sockaddr *, socklen_t *);