From af8b0557ba6c6a50e24b7eafa7ef0826fe1b79ba Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Fri, 18 May 2012 23:53:01 +0400 Subject: [PATCH] if_lagg: allow to invoke SIOCSLAGGPORT multiple times in a row Currently, 'ifconfig laggX down' does not remove members from this lagg(4) interface. So, 'service netif stop laggX' followed by 'service netif start laggX' will choke, because "stop" will leave interfaces attached to the laggX and ifconfig from the "start" will refuse to add already-existing interfaces. The real-world case is when I am bundling together my Ethernet and WiFi interfaces and using multiple profiles for accessing network in different places: system being booted up with one profile, but later this profile being exchanged to another one, followed by 'service netif restart' will not add WiFi interface back to the lagg: the "stop" action from 'service netif restart' will shut down my main WiFi interface, so wlan0 that exists in the lagg0 will be destroyed and purged from lagg0; the "start" action will try to re-add both interfaces, but since Ethernet one is already in lagg0, ifconfig will refuse to add the wlan0 from WiFi interface. Since adding the interface to the lagg(4) when it is already here should be an idempotent action: we're really not changing anything, so this fix doesn't change the semantics of interface addition. Signed-off-by: Eygene Ryabinkin --- sbin/ifconfig/iflagg.c | 3 ++- sys/net/if_lagg.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sbin/ifconfig/iflagg.c b/sbin/ifconfig/iflagg.c index ed39868..a474729 100644 --- a/sbin/ifconfig/iflagg.c +++ b/sbin/ifconfig/iflagg.c @@ -40,7 +40,8 @@ setlaggport(const char *val, int d, int s, const struct afswtch *afp) strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname)); strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname)); - if (ioctl(s, SIOCSLAGGPORT, &rp)) + /* Don't choke if the port is already in this lagg. */ + if (ioctl(s, SIOCSLAGGPORT, &rp) && errno != EEXIST) err(1, "SIOCSLAGGPORT"); } diff --git a/sys/net/if_lagg.c b/sys/net/if_lagg.c index c8b8ecb..9041e18 100644 --- a/sys/net/if_lagg.c +++ b/sys/net/if_lagg.c @@ -516,8 +516,13 @@ lagg_port_create(struct lagg_softc *sc, struct ifnet *ifp) return (ENOSPC); /* Check if port has already been associated to a lagg */ - if (ifp->if_lagg != NULL) + if (ifp->if_lagg != NULL) { + /* Port is already in the current lagg? */ + lp = (struct lagg_port *)ifp->if_lagg; + if (lp->lp_softc == sc) + return (EEXIST); return (EBUSY); + } /* XXX Disallow non-ethernet interfaces (this should be any of 802) */ if (ifp->if_type != IFT_ETHER) -- 1.7.10.1