From cc9aaac7d81d264698c98e7506f9f2a8490cf9a9 Mon Sep 17 00:00:00 2001 From: kn Date: Wed, 29 Jul 2020 12:13:29 +0000 Subject: Remove redundant bridge checks bridge_status() and switch_status() do the regular sanity check with SIOCGIFFLAGS, but both functions also call is_switch() and bridge_status() also calls is_bridge(). is_bridge() checks SIOCGIFFLAGS again, then both is_*() helpers finally do driver specific ioctl(2) calls to test whether the given interface is indeed a bridge(4) or a switch(4). SIOCGIFFLAGS serves no purpose here and is taken care of in ifconfig.c's getinfo(), so remove its calls from brconfig.c entirely. OK dlg --- sbin/ifconfig/brconfig.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'sbin') diff --git a/sbin/ifconfig/brconfig.c b/sbin/ifconfig/brconfig.c index e33b73ebf2c..1d11598ef5d 100644 --- a/sbin/ifconfig/brconfig.c +++ b/sbin/ifconfig/brconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: brconfig.c,v 1.25 2020/01/22 06:24:07 tedu Exp $ */ +/* $OpenBSD: brconfig.c,v 1.26 2020/07/29 12:13:28 kn Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -762,14 +762,8 @@ bridge_holdcnt(const char *value, int d) int is_bridge() { - struct ifreq ifr; struct ifbaconf ifbac; - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - - if (ioctl(sock, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) - return (0); - ifbac.ifbac_len = 0; strlcpy(ifbac.ifbac_name, ifname, sizeof(ifbac.ifbac_name)); if (ioctl(sock, SIOCBRDGRTS, (caddr_t)&ifbac) == -1) { @@ -783,16 +777,11 @@ is_bridge() void bridge_status(void) { - struct ifreq ifr; struct ifbrparam bp1, bp2; if (!is_bridge() || is_switch()) return; - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - if (ioctl(sock, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) - return; - bridge_cfg("\t"); bridge_list("\t"); @@ -1184,15 +1173,9 @@ switch_cfg(char *delim) void switch_status(void) { - struct ifreq ifr; - if (!is_switch()) return; - strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); - if (ioctl(sock, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) - return; - switch_cfg("\t"); bridge_list("\t"); -- cgit v1.2.3