Slight cleanup of interface event logging.

Make if_printf() use vlog() instead of vprintf().  This means it can no
longer return the number of characters printed, as it used to, but every
single call to if_printf() in the entire kernel ignores the return value
anyway; just return 0 so we don't have to change the prototype.

Consistently use if_printf() throughout sys/net/if.c, instead of a
mixture of if_printf() and log().

In ifa_maintain_loopback_route(), don't needlessly log an error if we
either failed to add a route because it already existed or failed to
remove one because it did not.  We still return an error code, though.

MFC after:	1 week
This commit is contained in:
Dag-Erling Smørgrav
2018-05-11 00:19:49 +00:00
parent 6bff85ff9a
commit 20f8d7bc7e
+13 -15
View File
@@ -1832,9 +1832,10 @@ ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa,
error = rtrequest1_fib(cmd, &info, NULL, ifp->if_fib); error = rtrequest1_fib(cmd, &info, NULL, ifp->if_fib);
if (error != 0) if (error != 0 &&
log(LOG_DEBUG, "%s: %s failed for interface %s: %u\n", !(cmd == RTM_ADD && error == EEXIST) &&
__func__, otype, if_name(ifp), error); !(cmd == RTM_DELETE && error == ENOENT))
if_printf(ifp, "%s failed: %d\n", otype, error);
return (error); return (error);
} }
@@ -2328,7 +2329,7 @@ do_link_state_change(void *arg, int pending)
if (pending > 1) if (pending > 1)
if_printf(ifp, "%d link states coalesced\n", pending); if_printf(ifp, "%d link states coalesced\n", pending);
if (log_link_state_change) if (log_link_state_change)
log(LOG_NOTICE, "%s: link state changed to %s\n", ifp->if_xname, if_printf(ifp, "link state changed to %s\n",
(link_state == LINK_STATE_UP) ? "UP" : "DOWN" ); (link_state == LINK_STATE_UP) ? "UP" : "DOWN" );
EVENTHANDLER_INVOKE(ifnet_link_event, ifp, link_state); EVENTHANDLER_INVOKE(ifnet_link_event, ifp, link_state);
CURVNET_RESTORE(); CURVNET_RESTORE();
@@ -2631,8 +2632,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td)
else if (ifp->if_pcount == 0) else if (ifp->if_pcount == 0)
ifp->if_flags &= ~IFF_PROMISC; ifp->if_flags &= ~IFF_PROMISC;
if (log_promisc_mode_change) if (log_promisc_mode_change)
log(LOG_INFO, "%s: permanently promiscuous mode %s\n", if_printf(ifp, "permanently promiscuous mode %s\n",
ifp->if_xname,
((new_flags & IFF_PPROMISC) ? ((new_flags & IFF_PPROMISC) ?
"enabled" : "disabled")); "enabled" : "disabled"));
} }
@@ -2695,8 +2695,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td)
rt_ifannouncemsg(ifp, IFAN_DEPARTURE); rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
EVENTHANDLER_INVOKE(ifnet_departure_event, ifp); EVENTHANDLER_INVOKE(ifnet_departure_event, ifp);
log(LOG_INFO, "%s: changing name to '%s'\n", if_printf(ifp, "changing name to '%s'\n", new_name);
ifp->if_xname, new_name);
IF_ADDR_WLOCK(ifp); IF_ADDR_WLOCK(ifp);
strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname)); strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname));
@@ -3199,8 +3198,7 @@ ifpromisc(struct ifnet *ifp, int pswitch)
/* If promiscuous mode status has changed, log a message */ /* If promiscuous mode status has changed, log a message */
if (error == 0 && ((ifp->if_flags ^ oldflags) & IFF_PROMISC) && if (error == 0 && ((ifp->if_flags ^ oldflags) & IFF_PROMISC) &&
log_promisc_mode_change) log_promisc_mode_change)
log(LOG_INFO, "%s: promiscuous mode %s\n", if_printf(ifp, "promiscuous mode %s\n",
ifp->if_xname,
(ifp->if_flags & IFF_PROMISC) ? "enabled" : "disabled"); (ifp->if_flags & IFF_PROMISC) ? "enabled" : "disabled");
return (error); return (error);
} }
@@ -3905,16 +3903,16 @@ if_initname(struct ifnet *ifp, const char *name, int unit)
} }
int int
if_printf(struct ifnet *ifp, const char * fmt, ...) if_printf(struct ifnet *ifp, const char *fmt, ...)
{ {
char if_fmt[256];
va_list ap; va_list ap;
int retval;
retval = printf("%s: ", ifp->if_xname); snprintf(if_fmt, sizeof(if_fmt), "%s: %s", ifp->if_xname, fmt);
va_start(ap, fmt); va_start(ap, fmt);
retval += vprintf(fmt, ap); vlog(LOG_INFO, if_fmt, ap);
va_end(ap); va_end(ap);
return (retval); return (0);
} }
void void