Use ether_ifattach in carp_clone_create instead of C&P code

carp_clone_destroy calls ether_ifdetach so not calling ether_ifattach is
inconsistent. If we add something pair of initialization and destruction
to ether_ifattach and ether_ifdetach (e.g., mutex_init/mutex_destroy),
ether_ifdetach of carp_clone_destroy won't work. So use ether_ifattach.

In order to do so, make ether_ifattach accept the 2nd argument (lla) as
NULL to allow carp to initialize its link level address by itself.
This commit is contained in:
ozaki-r 2016-12-28 07:26:24 +00:00
parent 7d8e034047
commit b79bd95d27
3 changed files with 21 additions and 31 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ethersubr.9,v 1.25 2013/09/17 19:58:03 wiz Exp $
.\" $NetBSD: ethersubr.9,v 1.26 2016/12/28 07:26:24 ozaki-r Exp $
.\"
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd March 3, 1997
.Dd December 28, 2016
.Dt ETHERSUBR 9
.Os
.Sh NAME
@ -94,6 +94,11 @@ address in the interface's address list and records the link level address
pointed to by
.Fa lla
there.
Drivers can initialize the link level address by themselves by calling
the function with
.Fa lla
as NULL and calling
.Fn if_set_sadl .
.Pp
This function must be called from the driver's attach function.
.It Fn fddi_ifattach "ifp" "lla"

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ethersubr.c,v 1.229 2016/10/18 07:30:30 ozaki-r Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.230 2016/12/28 07:26:24 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.229 2016/10/18 07:30:30 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.230 2016/12/28 07:26:24 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -962,7 +962,8 @@ ether_ifattach(struct ifnet *ifp, const uint8_t *lla)
if (ifp->if_baudrate == 0)
ifp->if_baudrate = IF_Mbps(10); /* just a default */
if_set_sadl(ifp, lla, ETHER_ADDR_LEN, !ETHER_IS_LOCAL(lla));
if (lla != NULL)
if_set_sadl(ifp, lla, ETHER_ADDR_LEN, !ETHER_IS_LOCAL(lla));
LIST_INIT(&ec->ec_multiaddrs);
ifp->if_broadcastaddr = etherbroadcastaddr;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_carp.c,v 1.80 2016/12/12 03:55:57 ozaki-r Exp $ */
/* $NetBSD: ip_carp.c,v 1.81 2016/12/28 07:26:25 ozaki-r Exp $ */
/* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */
/*
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.80 2016/12/12 03:55:57 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.81 2016/12/28 07:26:25 ozaki-r Exp $");
/*
* TODO:
@ -835,33 +835,17 @@ carp_clone_create(struct if_clone *ifc, int unit)
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = carp_ioctl;
ifp->if_start = carp_start;
ifp->if_output = carp_output;
ifp->if_type = IFT_CARP;
ifp->if_addrlen = ETHER_ADDR_LEN;
ifp->if_hdrlen = ETHER_HDR_LEN;
ifp->if_mtu = ETHERMTU;
IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
IFQ_SET_READY(&ifp->if_snd);
if_attach(ifp);
if_alloc_sadl(ifp);
ifp->if_broadcastaddr = etherbroadcastaddr;
if_initialize(ifp);
ether_ifattach(ifp, NULL);
carp_set_enaddr(sc);
LIST_INIT(&sc->sc_ac.ec_multiaddrs);
bpf_attach(ifp, DLT_EN10MB, ETHER_HDR_LEN);
#ifdef MBUFTRACE
strlcpy(sc->sc_ac.ec_tx_mowner.mo_name, ifp->if_xname,
sizeof(sc->sc_ac.ec_tx_mowner.mo_name));
strlcpy(sc->sc_ac.ec_tx_mowner.mo_descr, "tx",
sizeof(sc->sc_ac.ec_tx_mowner.mo_descr));
strlcpy(sc->sc_ac.ec_rx_mowner.mo_name, ifp->if_xname,
sizeof(sc->sc_ac.ec_rx_mowner.mo_name));
strlcpy(sc->sc_ac.ec_rx_mowner.mo_descr, "rx",
sizeof(sc->sc_ac.ec_rx_mowner.mo_descr));
MOWNER_ATTACH(&sc->sc_ac.ec_tx_mowner);
MOWNER_ATTACH(&sc->sc_ac.ec_rx_mowner);
ifp->if_mowner = &sc->sc_ac.ec_tx_mowner;
#endif
/* Overwrite ethernet defaults */
ifp->if_type = IFT_CARP;
ifp->if_output = carp_output;
ifp->if_extflags &= ~IFEF_OUTPUT_MPSAFE;
if_register(ifp);
return (0);
}