Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net/lagg Make a link-layer address of lagg(4) configurab...
details: https://anonhg.NetBSD.org/src/rev/5d7a63395605
branches: trunk
changeset: 1023879:5d7a63395605
user: yamaguchi <yamaguchi%NetBSD.org@localhost>
date: Thu Sep 30 04:23:30 2021 +0000
description:
Make a link-layer address of lagg(4) configurable by ifconfig(8)
lagg(4) uses a configured link-layer (MAC) address instead
of a random MAC address generated on creating.
The configured MAC address is copied to all child interface
and used for a system id of LACP.
diffstat:
sys/net/lagg/if_lagg.c | 637 +++++++++++++++++++++++++------------------
sys/net/lagg/if_lagg_lacp.c | 35 +-
sys/net/lagg/if_laggproto.h | 7 +-
3 files changed, 383 insertions(+), 296 deletions(-)
diffs (truncated from 939 to 300 lines):
diff -r fc8ceba10763 -r 5d7a63395605 sys/net/lagg/if_lagg.c
--- a/sys/net/lagg/if_lagg.c Thu Sep 30 04:20:14 2021 +0000
+++ b/sys/net/lagg/if_lagg.c Thu Sep 30 04:23:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_lagg.c,v 1.8 2021/09/30 04:20:14 yamaguchi Exp $ */
+/* $NetBSD: if_lagg.c,v 1.9 2021/09/30 04:23:30 yamaguchi Exp $ */
/*
* Copyright (c) 2005, 2006 Reyk Floeter <reyk%openbsd.org@localhost>
@@ -20,7 +20,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.8 2021/09/30 04:20:14 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.9 2021/09/30 04:23:30 yamaguchi Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -186,8 +186,13 @@
static int lagg_ether_delmulti(struct lagg_softc *, struct ifreq *);
static void lagg_port_syncmulti(struct lagg_softc *, struct lagg_port *);
static void lagg_port_purgemulti(struct lagg_softc *, struct lagg_port *);
+static int lagg_port_setup(struct lagg_softc *, struct lagg_port *,
+ struct ifnet *);
+static void lagg_port_teardown(struct lagg_softc *, struct lagg_port *,
+ bool);
static void lagg_port_syncvlan(struct lagg_softc *, struct lagg_port *);
static void lagg_port_purgevlan(struct lagg_softc *, struct lagg_port *);
+static void lagg_lladdr_update(struct lagg_softc *);
static struct if_clone lagg_cloner =
IF_CLONE_INITIALIZER("lagg", lagg_clone_create, lagg_clone_destroy);
@@ -209,7 +214,7 @@
#define LAGG_DPRINTF(_sc, _fmt, _args...) __nothing
#endif
-static inline size_t
+static size_t
lagg_sizeof_softc(enum lagg_iftypes ift)
{
struct lagg_softc *_dummy = NULL;
@@ -229,7 +234,7 @@
return s;
}
-static inline bool
+static bool
lagg_debug_enable(struct lagg_softc *sc)
{
if (__predict_false(ISSET(sc->sc_if.if_flags, IFF_DEBUG)))
@@ -238,7 +243,7 @@
return false;
}
-static inline void
+static void
lagg_evcnt_attach(struct lagg_softc *sc,
struct evcnt *ev, const char *name)
{
@@ -247,7 +252,7 @@
sc->sc_evgroup, name);
}
-static inline void
+static void
lagg_in6_ifattach(struct ifnet *ifp)
{
@@ -261,7 +266,7 @@
#endif
}
-static inline void
+static void
lagg_in6_ifdetach(struct ifnet *ifp)
{
@@ -274,7 +279,7 @@
#endif
}
-static inline int
+static int
lagg_lp_ioctl(struct lagg_port *lp, u_long cmd, void *data)
{
struct ifnet *ifp_port;
@@ -291,6 +296,23 @@
return error;
}
+static bool
+lagg_lladdr_equal(const uint8_t *a, const uint8_t *b)
+{
+
+ if (memcmp(a, b, ETHER_ADDR_LEN) == 0)
+ return true;
+
+ return false;
+}
+
+static void
+lagg_lladdr_cpy(uint8_t *dst, const uint8_t *src)
+{
+
+ memcpy(dst, src, ETHER_ADDR_LEN);
+}
+
void
laggattach(int n)
{
@@ -386,7 +408,8 @@
switch (lagg_iftype) {
case LAGG_IF_TYPE_ETHERNET:
- cprng_fast(sc->sc_lladdr, sizeof(sc->sc_lladdr));
+ cprng_fast(sc->sc_lladdr_rand, sizeof(sc->sc_lladdr_rand));
+ lagg_lladdr_cpy(sc->sc_lladdr, sc->sc_lladdr_rand);
ether_set_vlan_cb((struct ethercom *)ifp, lagg_vlan_cb);
ether_ifattach(ifp, sc->sc_lladdr);
break;
@@ -472,6 +495,8 @@
if (ISSET(ifp->if_flags, IFF_RUNNING))
lagg_stop_locked(sc);
+ lagg_lladdr_update(sc);
+
SET(ifp->if_flags, IFF_RUNNING);
rv = lagg_proto_up(sc);
@@ -1594,142 +1619,6 @@
kmem_free(var, sizeof(*var));
}
-static void
-lagg_lladdr_set(struct lagg_softc *sc, struct lagg_port *lp, u_long if_type)
-{
- struct ifnet *ifp, *ifp_port;
- const uint8_t *lladdr;
-
- KASSERT(IFNET_LOCKED(&sc->sc_if));
- KASSERT(LAGG_LOCKED(sc));
-
- ifp = &sc->sc_if;
- ifp_port = lp->lp_ifp;
-
- if (ifp->if_type != IFT_ETHER)
- return;
-
- switch (lp->lp_iftype) {
- case IFT_ETHER:
- memcpy(lp->lp_lladdr, CLLADDR(ifp_port->if_sadl),
- ETHER_ADDR_LEN);
-
- if (SIMPLEQ_EMPTY(&sc->sc_ports)) {
- if_set_sadl(ifp, CLLADDR(ifp_port->if_sadl),
- ETHER_ADDR_LEN, 0);
- LAGG_UNLOCK(sc);
- /* apply new IPv6LLA */
- lagg_in6_ifdetach(&sc->sc_if);
- lagg_in6_ifattach(&sc->sc_if);
- LAGG_LOCK(sc);
- }
-
- lladdr = CLLADDR(ifp->if_sadl);
-
- if (lp->lp_iftype != if_type ||
- memcmp(lp->lp_lladdr, lladdr, ETHER_ADDR_LEN) != 0) {
- IFNET_LOCK(ifp_port);
- if_set_sadl(ifp_port, lladdr, ETHER_ADDR_LEN, false);
- IFNET_UNLOCK(ifp_port);
- }
- break;
- }
-}
-
-static void
-lagg_lladdr_update(struct lagg_softc *sc)
-{
- struct lagg_port *lp;
- struct ifnet *ifp_port;
- const uint8_t *lladdr;
- bool stopped;
- int error;
-
- KASSERT(LAGG_LOCKED(sc));
- KASSERT(sc->sc_if.if_type == IFT_ETHER);
-
- lladdr = CLLADDR(sc->sc_if.if_sadl);
-
- LAGG_PORTS_FOREACH(sc, lp) {
- ifp_port = lp->lp_ifp;
-
- if (memcmp(lladdr, CLLADDR(ifp_port->if_sadl),
- ETHER_ADDR_LEN) == 0) {
- continue;
- }
-
- IFNET_LOCK(ifp_port);
- if (ISSET(ifp_port->if_flags, IFF_RUNNING)) {
- ifp_port->if_stop(ifp_port, 0);
- stopped = true;
- } else {
- stopped = false;
- }
-
- if_set_sadl(ifp_port, lladdr, ETHER_ADDR_LEN, false);
-
- if (stopped) {
- error = ifp_port->if_init(ifp_port);
-
- if (error != 0) {
- lagg_log(sc, LOG_WARNING,
- "%s failed to if_init() on %d\n",
- ifp_port->if_xname, error);
- }
- }
-
- IFNET_UNLOCK(ifp_port);
- }
-}
-
-static void
-lagg_lladdr_unset(struct lagg_softc *sc, struct lagg_port *lp, u_int if_type)
-{
- struct ifnet *ifp, *ifp_port;
- struct lagg_port *lp0;
-
- KASSERT(IFNET_LOCKED(&sc->sc_if));
- KASSERT(LAGG_LOCKED(sc));
-
- ifp = &sc->sc_if;
- ifp_port = lp->lp_ifp;
-
- if (ifp->if_type != IFT_ETHER)
- return;
-
- switch (lp->lp_iftype) {
- case IFT_ETHER:
- if (memcmp(lp->lp_lladdr, CLLADDR(ifp->if_sadl),
- ETHER_ADDR_LEN) == 0) {
- lp0 = SIMPLEQ_FIRST(&sc->sc_ports);
- if (lp0 == NULL) {
- if_set_sadl(ifp, sc->sc_lladdr,
- ETHER_ADDR_LEN, 0);
- } else {
- if_set_sadl(ifp, lp0->lp_lladdr,
- ETHER_ADDR_LEN, 0);
- }
-
- LAGG_UNLOCK(sc);
- lagg_in6_ifdetach(ifp);
- lagg_in6_ifattach(ifp);
- LAGG_LOCK(sc);
-
- lagg_lladdr_update(sc);
- }
-
- if (lp->lp_iftype != if_type ||
- memcmp(lp->lp_lladdr, CLLADDR(ifp_port->if_sadl),
- ETHER_ADDR_LEN) != 0) {
- IFNET_LOCK(ifp_port);
- if_set_sadl(ifp_port, lp->lp_lladdr,
- ETHER_ADDR_LEN, false);
- IFNET_UNLOCK(ifp_port);
- }
- break;
- }
-}
-
static int
lagg_ether_addmulti(struct lagg_softc *sc, struct ifreq *ifr)
{
@@ -1891,21 +1780,215 @@
}
static int
-lagg_addport_locked(struct lagg_softc *sc, struct lagg_port *lp)
+lagg_setup_mtu(struct lagg_softc *sc, struct lagg_port *lp)
+{
+ struct ifnet *ifp_port;
+ struct ifreq ifr;
+ int error;
+
+ ifp_port = lp->lp_ifp;
+ KASSERT(IFNET_LOCKED(ifp_port));
+
+ error = 0;
+ memset(&ifr, 0, sizeof(ifr));
+
+ if (SIMPLEQ_EMPTY(&sc->sc_ports)) {
+ ifr.ifr_mtu = lp->lp_mtu;
+ } else {
+ ifr.ifr_mtu = sc->sc_if.if_mtu;
+ }
+
+ if (sc->sc_if.if_mtu != (uint64_t)ifr.ifr_mtu) {
+ sc->sc_if.if_mtu = ifr.ifr_mtu;
+ }
+
+ if (lp->lp_mtu != (uint64_t)ifr.ifr_mtu) {
Home |
Main Index |
Thread Index |
Old Index