Better handling of ioctl(SIOCSIFFLAGS) failing in ifpromisc():

- Don't print the "promiscuous mode (enabled|disabled)" on failure
- Restore the reference count on failure
This commit is contained in:
Bill Fenner 2001-04-27 22:20:22 +00:00
parent 8ed3802bb0
commit 4f3c11a654
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=76083

View File

@ -1016,8 +1016,9 @@ ifpromisc(ifp, pswitch)
{
struct ifreq ifr;
int error;
int oldflags;
int oldflags, oldpcount;
oldpcount = ifp->if_pcount;
oldflags = ifp->if_flags;
if (pswitch) {
/*
@ -1029,21 +1030,22 @@ ifpromisc(ifp, pswitch)
if (ifp->if_pcount++ != 0)
return (0);
ifp->if_flags |= IFF_PROMISC;
log(LOG_INFO, "%s%d: promiscuous mode enabled\n",
ifp->if_name, ifp->if_unit);
} else {
if (--ifp->if_pcount > 0)
return (0);
ifp->if_flags &= ~IFF_PROMISC;
log(LOG_INFO, "%s%d: promiscuous mode disabled\n",
ifp->if_name, ifp->if_unit);
}
ifr.ifr_flags = ifp->if_flags;
error = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr);
if (error == 0)
if (error == 0) {
log(LOG_INFO, "%s%d: promiscuous mode %s\n",
ifp->if_name, ifp->if_unit,
(ifp->if_flags & IFF_PROMISC) ? "enabled" : "disabled");
rt_ifmsg(ifp);
else
} else {
ifp->if_pcount = oldpcount;
ifp->if_flags = oldflags;
}
return error;
}