Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Use ether_ifattach in carp_clone_create instead of C&P code



details:   https://anonhg.NetBSD.org/src/rev/eed46a442b56
branches:  trunk
changeset: 820066:eed46a442b56
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Dec 28 07:26:24 2016 +0000

description:
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.

diffstat:

 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(-)

diffs (118 lines):

diff -r 57f0077a99e2 -r eed46a442b56 share/man/man9/ethersubr.9
--- a/share/man/man9/ethersubr.9        Wed Dec 28 07:05:11 2016 +0000
+++ b/share/man/man9/ethersubr.9        Wed Dec 28 07:26:24 2016 +0000
@@ -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 @@
 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 -r 57f0077a99e2 -r eed46a442b56 sys/net/if_ethersubr.c
--- a/sys/net/if_ethersubr.c    Wed Dec 28 07:05:11 2016 +0000
+++ b/sys/net/if_ethersubr.c    Wed Dec 28 07:26:24 2016 +0000
@@ -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 @@
        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 -r 57f0077a99e2 -r eed46a442b56 sys/netinet/ip_carp.c
--- a/sys/netinet/ip_carp.c     Wed Dec 28 07:05:11 2016 +0000
+++ b/sys/netinet/ip_carp.c     Wed Dec 28 07:26:24 2016 +0000
@@ -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 @@
        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);
 }
 



Home | Main Index | Thread Index | Old Index