Module Name: src Committed By: yamaguchi Date: Thu Mar 31 03:15:15 UTC 2022
Modified Files: src/sys/net/lagg: if_lagg.c if_lagg_lacp.c if_laggproto.h Log Message: Use addlog(4) for putting 2 messages to one line To generate a diff of this commit: cvs rdiff -u -r1.41 -r1.42 src/sys/net/lagg/if_lagg.c cvs rdiff -u -r1.19 -r1.20 src/sys/net/lagg/if_lagg_lacp.c cvs rdiff -u -r1.13 -r1.14 src/sys/net/lagg/if_laggproto.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/lagg/if_lagg.c diff -u src/sys/net/lagg/if_lagg.c:1.41 src/sys/net/lagg/if_lagg.c:1.42 --- src/sys/net/lagg/if_lagg.c:1.41 Thu Mar 31 03:12:31 2022 +++ src/sys/net/lagg/if_lagg.c Thu Mar 31 03:15:15 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: if_lagg.c,v 1.41 2022/03/31 03:12:31 yamaguchi Exp $ */ +/* $NetBSD: if_lagg.c,v 1.42 2022/03/31 03:15:15 yamaguchi Exp $ */ /* * Copyright (c) 2005, 2006 Reyk Floeter <r...@openbsd.org> @@ -20,7 +20,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.41 2022/03/31 03:12:31 yamaguchi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_lagg.c,v 1.42 2022/03/31 03:15:15 yamaguchi Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -244,15 +244,6 @@ lagg_sizeof_softc(enum lagg_iftypes ift) return s; } -static bool -lagg_debug_enable(struct lagg_softc *sc) -{ - if (__predict_false(ISSET(sc->sc_if.if_flags, IFF_DEBUG))) - return true; - - return false; -} - static void lagg_evcnt_attach(struct lagg_softc *sc, struct evcnt *ev, const char *name) @@ -743,7 +734,7 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd error = lagg_lp_ioctl(lp, cmd, (void *)ifr); if (error != 0) { - lagg_log(sc, LOG_ERR, + LAGG_LOG(sc, LOG_ERR, "failed to change MTU to %d on port %s, " "reverting all ports to original " "MTU(%" PRIu64 ")\n", @@ -798,65 +789,65 @@ lagg_ioctl(struct ifnet *ifp, u_long cmd static int lagg_setup_sysctls(struct lagg_softc *sc) { - struct sysctllog **log; + struct sysctllog **slog; const struct sysctlnode **rnode, *hashnode; const char *ifname; int error; - log = &sc->sc_sysctllog; + slog = &sc->sc_sysctllog; rnode = &sc->sc_sysctlnode; ifname = sc->sc_if.if_xname; - error = sysctl_createv(log, 0, NULL, rnode, + error = sysctl_createv(slog, 0, NULL, rnode, CTLFLAG_PERMANENT, CTLTYPE_NODE, ifname, SYSCTL_DESCR("lagg information and settings"), NULL, 0, NULL, 0, CTL_NET, CTL_CREATE, CTL_EOL); if (error != 0) goto done; - error = sysctl_createv(log, 0, rnode, &hashnode, + error = sysctl_createv(slog, 0, rnode, &hashnode, CTLFLAG_PERMANENT, CTLTYPE_NODE, "hash", SYSCTL_DESCR("hash calculation settings"), NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL); if (error != 0) goto done; - error = sysctl_createv(log, 0, &hashnode, NULL, + error = sysctl_createv(slog, 0, &hashnode, NULL, CTLFLAG_READWRITE, CTLTYPE_BOOL, "macaddr", SYSCTL_DESCR("use src/dst mac addresses"), NULL, 0, &sc->sc_hash_mac, 0, CTL_CREATE, CTL_EOL); if (error != 0) goto done; - error = sysctl_createv(log, 0, &hashnode, NULL, + error = sysctl_createv(slog, 0, &hashnode, NULL, CTLFLAG_READWRITE, CTLTYPE_BOOL, "ipaddr", SYSCTL_DESCR("use src/dst IPv4 addresses"), NULL, 0, &sc->sc_hash_ipaddr, 0, CTL_CREATE, CTL_EOL); if (error != 0) goto done; - error = sysctl_createv(log, 0, &hashnode, NULL, + error = sysctl_createv(slog, 0, &hashnode, NULL, CTLFLAG_READWRITE, CTLTYPE_BOOL, "ip6addr", SYSCTL_DESCR("use src/dst IPv6 addresses"), NULL, 0, &sc->sc_hash_ip6addr, 0, CTL_CREATE, CTL_EOL); if (error != 0) goto done; - error = sysctl_createv(log, 0, &hashnode, NULL, + error = sysctl_createv(slog, 0, &hashnode, NULL, CTLFLAG_READWRITE, CTLTYPE_BOOL, "tcp", SYSCTL_DESCR("use TCP src/dst port"), NULL, 0, &sc->sc_hash_tcp, 0, CTL_CREATE, CTL_EOL); if (error != 0) goto done; - error = sysctl_createv(log, 0, &hashnode, NULL, + error = sysctl_createv(slog, 0, &hashnode, NULL, CTLFLAG_READWRITE, CTLTYPE_BOOL, "udp", SYSCTL_DESCR("use UDP src/dst port"), NULL, 0, &sc->sc_hash_udp, 0, CTL_CREATE, CTL_EOL); done: if (error != 0) { - lagg_log(sc, LOG_ERR, "unable to create sysctl node\n"); - sysctl_teardown(log); + LAGG_LOG(sc, LOG_ERR, "unable to create sysctl node\n"); + sysctl_teardown(slog); } return error; @@ -1243,7 +1234,7 @@ lagg_vlan_cb(struct ethercom *ec, uint16 LAGG_PORTS_FOREACH(sc, lp) { error = lagg_port_vlan_cb(lp, lvt, set); if (error != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "%s failed to configure vlan on %d\n", lp->lp_ifp->if_xname, error); } @@ -1763,7 +1754,7 @@ lagg_port_vlan(struct lagg_softc *sc, st TAILQ_FOREACH(lvt, &sc->sc_vtags, lvt_entry) { error = lagg_port_vlan_cb(lp, lvt, set); if (error != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "%s failed to configure vlan on %d\n", lp->lp_ifp->if_xname, error); } @@ -1817,9 +1808,9 @@ lagg_sync_ifcaps(struct lagg_softc *sc) error = lagg_setifcaps(lp, ifp->if_capenable); if (error != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "failed to update capabilities " - "of %s, error=%d", + "of %s, error=%d\n", lp->lp_ifp->if_xname, error); } } @@ -1865,9 +1856,9 @@ lagg_sync_ethcaps(struct lagg_softc *sc) error = lagg_setethcaps(lp, ec->ec_capenable); if (error != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "failed to update ether " - "capabilities"" of %s, error=%d", + "capabilities"" of %s, error=%d\n", lp->lp_ifp->if_xname, error); } @@ -1914,8 +1905,8 @@ lagg_ifcap_update(struct lagg_softc *sc) } if (pena != ena) { - lagg_log(sc, LOG_DEBUG, "couldn't set " - "capabilities 0x%08"PRIx64, pena); + LAGG_LOG(sc, LOG_DEBUG, "couldn't set " + "capabilities 0x%08"PRIx64"\n", pena); } ifp = &sc->sc_if; @@ -1925,8 +1916,8 @@ lagg_ifcap_update(struct lagg_softc *sc) ifp->if_capabilities = cap; ifp->if_capenable = ena; - lagg_log(sc, LOG_DEBUG,"capabilities " - "0x%08"PRIx64" enabled 0x%08"PRIx64, + LAGG_LOG(sc, LOG_DEBUG,"capabilities " + "0x%08"PRIx64" enabled 0x%08"PRIx64"\n", cap, ena); } } @@ -1989,8 +1980,8 @@ lagg_ethercap_update(struct lagg_softc * } if (pena != ena) { - lagg_log(sc, LOG_DEBUG, "couldn't set " - "ether capabilities 0x%08x", pena); + LAGG_LOG(sc, LOG_DEBUG, "couldn't set " + "ether capabilities 0x%08x\n", pena); } ec = (struct ethercom *)&sc->sc_if; @@ -2000,9 +1991,9 @@ lagg_ethercap_update(struct lagg_softc * ec->ec_capabilities = cap; ec->ec_capenable = ena; - lagg_log(sc, LOG_DEBUG, + LAGG_LOG(sc, LOG_DEBUG, "ether capabilities 0x%08x" - " enabled 0x%08x", cap, ena); + " enabled 0x%08x\n", cap, ena); } } @@ -2077,7 +2068,7 @@ lagg_teardown_mtu(struct lagg_softc *sc, ifr.ifr_mtu = lp->lp_mtu; error = lp->lp_ioctl(ifp_port, SIOCSIFMTU, (void *)&ifr); if (error != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "failed to reset MTU %d to %s\n", ifr.ifr_mtu, ifp_port->if_xname); } @@ -2116,7 +2107,7 @@ lagg_port_setsadl(struct lagg_port *lp, error = if_init(ifp_port); if (error != 0) { - lagg_log(lp->lp_softc, LOG_WARNING, + LAGG_LOG(lp->lp_softc, LOG_WARNING, "%s failed to if_init() on %d\n", ifp_port->if_xname, error); } @@ -2158,7 +2149,7 @@ lagg_port_unsetsadl(struct lagg_port *lp error = if_init(ifp_port); if (error != 0) { - lagg_log(lp->lp_softc, LOG_WARNING, + LAGG_LOG(lp->lp_softc, LOG_WARNING, "%s failed to if_init() on %d\n", ifp_port->if_xname, error); } @@ -2409,7 +2400,7 @@ restore_ipv6lla: lagg_in6_ifdetach(ifp_port); if (stopped) { if (if_init(ifp_port) != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "couldn't re-start port %s\n", ifp_port->if_xname); } @@ -2667,7 +2658,7 @@ lagg_config_promisc(struct lagg_softc *s if (error == 0) { lp->lp_promisc = promisc; } else { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "couldn't %s promisc on %s\n", promisc ? "set" : "unset", ifp_port->if_xname); @@ -2693,7 +2684,7 @@ lagg_unconfig_promisc(struct lagg_softc } if (error != 0) { - lagg_log(sc, LOG_WARNING, + LAGG_LOG(sc, LOG_WARNING, "couldn't unset promisc on %s\n", ifp_port->if_xname); } @@ -2860,20 +2851,6 @@ lagg_port_putref(struct lagg_port *lp, s psref_release(psref, &lp->lp_psref, lagg_port_psref_class); } -void -lagg_log(struct lagg_softc *sc, int lvl, const char *fmt, ...) -{ - va_list ap; - - if (lvl == LOG_DEBUG && !lagg_debug_enable(sc)) - return; - - log(lvl, "%s: ", sc->sc_if.if_xname); - va_start(ap, fmt); - vlog(lvl, fmt, ap); - va_end(ap); -} - static void lagg_workq_work(struct work *wk, void *context) { Index: src/sys/net/lagg/if_lagg_lacp.c diff -u src/sys/net/lagg/if_lagg_lacp.c:1.19 src/sys/net/lagg/if_lagg_lacp.c:1.20 --- src/sys/net/lagg/if_lagg_lacp.c:1.19 Thu Mar 31 03:04:04 2022 +++ src/sys/net/lagg/if_lagg_lacp.c Thu Mar 31 03:15:15 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: if_lagg_lacp.c,v 1.19 2022/03/31 03:04:04 yamaguchi Exp $ */ +/* $NetBSD: if_lagg_lacp.c,v 1.20 2022/03/31 03:15:15 yamaguchi Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.19 2022/03/31 03:04:04 yamaguchi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_lagg_lacp.c,v 1.20 2022/03/31 03:15:15 yamaguchi Exp $"); #ifdef _KERNEL_OPT #include "opt_lagg.h" @@ -493,7 +493,7 @@ lacp_attach(struct lagg_softc *sc, struc lsc->lsc_workq = lagg_workq_create(xnamebuf, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE); if (lsc->lsc_workq == NULL) { - lagg_log(sc, LOG_ERR, "workqueue create failed\n"); + LAGG_LOG(sc, LOG_ERR, "workqueue create failed\n"); error = ENOMEM; goto destroy_lock; } @@ -681,7 +681,7 @@ lacp_allocport(struct lagg_proto_softc * added_multi = false; break; default: - lagg_log(sc, LOG_ERR, "SIOCADDMULTI failed on %s\n", + LAGG_LOG(sc, LOG_ERR, "SIOCADDMULTI failed on %s\n", lp->lp_ifp->if_xname); return error; } Index: src/sys/net/lagg/if_laggproto.h diff -u src/sys/net/lagg/if_laggproto.h:1.13 src/sys/net/lagg/if_laggproto.h:1.14 --- src/sys/net/lagg/if_laggproto.h:1.13 Thu Mar 31 03:12:31 2022 +++ src/sys/net/lagg/if_laggproto.h Thu Mar 31 03:15:15 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: if_laggproto.h,v 1.13 2022/03/31 03:12:31 yamaguchi Exp $ */ +/* $NetBSD: if_laggproto.h,v 1.14 2022/03/31 03:15:15 yamaguchi Exp $ */ /* * Copyright (c) 2021 Internet Initiative Japan Inc. @@ -260,8 +260,24 @@ lagg_portactive(struct lagg_port *lp) return false; } -void lagg_log(struct lagg_softc *, int, const char *, ...) - __printflike(3, 4); +static inline bool +lagg_debug_enable(struct lagg_softc *sc) +{ + if (__predict_false(ISSET(sc->sc_if.if_flags, IFF_DEBUG))) + return true; + + return false; +} + +#define LAGG_LOG(_sc, _lvl, _fmt, _arg...) do { \ + if ((_lvl) == LOG_DEBUG && \ + !lagg_debug_enable(_sc)) \ + break; \ + \ + log((_lvl), "%s: ", (_sc)->sc_if.if_xname); \ + addlog((_fmt), ##_arg); \ +} while(0) + void lagg_port_getref(struct lagg_port *, struct psref *); void lagg_port_putref(struct lagg_port *, struct psref *); void lagg_enqueue(struct lagg_softc *,