From b79bd95d277a48b64e9bc7158f34c77802dc3585 Mon Sep 17 00:00:00 2001 From: ozaki-r Date: Wed, 28 Dec 2016 07:26:24 +0000 Subject: [PATCH] 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. --- share/man/man9/ethersubr.9 | 9 +++++++-- sys/net/if_ethersubr.c | 7 ++++--- sys/netinet/ip_carp.c | 36 ++++++++++-------------------------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/share/man/man9/ethersubr.9 b/share/man/man9/ethersubr.9 index 05b329166d6f..1f264a3adf83 100644 --- a/share/man/man9/ethersubr.9 +++ b/share/man/man9/ethersubr.9 @@ -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" diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index f1cddd8d7b94..53ac9f732381 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -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 -__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; diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index f4adfeee7b6f..f4837cd4ea72 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -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 -__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); }