git: dc9029d863dc - main - if_vtnet: Move ioctl handlers into separate functions
Bryan Venteicher
bryanv at FreeBSD.org
Tue Jan 19 05:08:27 UTC 2021
The branch main has been updated by bryanv:
URL: https://cgit.FreeBSD.org/src/commit/?id=dc9029d863dcc48efebb6a31a25553a7459132aa
commit dc9029d863dcc48efebb6a31a25553a7459132aa
Author: Bryan Venteicher <bryanv at FreeBSD.org>
AuthorDate: 2021-01-19 04:55:25 +0000
Commit: Bryan Venteicher <bryanv at FreeBSD.org>
CommitDate: 2021-01-19 04:55:25 +0000
if_vtnet: Move ioctl handlers into separate functions
Reviewed by: grehan (mentor)
Differential Revision: https://reviews.freebsd.org/D27914 https://reviews.freebsd.org/D27915
---
sys/dev/virtio/network/if_vtnet.c | 168 ++++++++++++++++++++++++--------------
1 file changed, 106 insertions(+), 62 deletions(-)
diff --git a/sys/dev/virtio/network/if_vtnet.c b/sys/dev/virtio/network/if_vtnet.c
index d0c98afe5b20..876dc1e152c4 100644
--- a/sys/dev/virtio/network/if_vtnet.c
+++ b/sys/dev/virtio/network/if_vtnet.c
@@ -112,6 +112,9 @@ static void vtnet_free_rx_filters(struct vtnet_softc *);
static int vtnet_alloc_virtqueues(struct vtnet_softc *);
static int vtnet_setup_interface(struct vtnet_softc *);
static int vtnet_ioctl_mtu(struct vtnet_softc *, int);
+static int vtnet_ioctl_ifflags(struct vtnet_softc *);
+static int vtnet_ioctl_multi(struct vtnet_softc *);
+static int vtnet_ioctl_ifcap(struct vtnet_softc *, struct ifreq *);
static int vtnet_ioctl(struct ifnet *, u_long, caddr_t);
static uint64_t vtnet_get_counter(struct ifnet *, ift_counter);
@@ -1158,12 +1161,111 @@ vtnet_ioctl_mtu(struct vtnet_softc *sc, int mtu)
return (0);
}
+static int
+vtnet_ioctl_ifflags(struct vtnet_softc *sc)
+{
+ struct ifnet *ifp;
+ int drv_running;
+
+ ifp = sc->vtnet_ifp;
+ drv_running = (ifp->if_drv_flags & IFF_DRV_RUNNING) != 0;
+
+ VTNET_CORE_LOCK_ASSERT(sc);
+
+ if ((ifp->if_flags & IFF_UP) == 0) {
+ if (drv_running)
+ vtnet_stop(sc);
+ goto out;
+ }
+
+ if (!drv_running) {
+ vtnet_init_locked(sc, 0);
+ goto out;
+ }
+
+ if ((ifp->if_flags ^ sc->vtnet_if_flags) &
+ (IFF_PROMISC | IFF_ALLMULTI)) {
+ if ((sc->vtnet_flags & VTNET_FLAG_CTRL_RX) == 0)
+ return (ENOTSUP);
+ vtnet_rx_filter(sc);
+ }
+
+out:
+ sc->vtnet_if_flags = ifp->if_flags;
+ return (0);
+}
+
+static int
+vtnet_ioctl_multi(struct vtnet_softc *sc)
+{
+ struct ifnet *ifp;
+
+ ifp = sc->vtnet_ifp;
+
+ VTNET_CORE_LOCK_ASSERT(sc);
+
+ if (sc->vtnet_flags & VTNET_FLAG_CTRL_RX &&
+ ifp->if_drv_flags & IFF_DRV_RUNNING)
+ vtnet_rx_filter_mac(sc);
+
+ return (0);
+}
+
+static int
+vtnet_ioctl_ifcap(struct vtnet_softc *sc, struct ifreq *ifr)
+{
+ struct ifnet *ifp;
+ int mask, reinit;
+
+ ifp = sc->vtnet_ifp;
+ mask = (ifr->ifr_reqcap & ifp->if_capabilities) ^ ifp->if_capenable;
+
+ VTNET_CORE_LOCK_ASSERT(sc);
+
+ if (mask & IFCAP_TXCSUM)
+ ifp->if_capenable ^= IFCAP_TXCSUM;
+ if (mask & IFCAP_TXCSUM_IPV6)
+ ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
+ if (mask & IFCAP_TSO4)
+ ifp->if_capenable ^= IFCAP_TSO4;
+ if (mask & IFCAP_TSO6)
+ ifp->if_capenable ^= IFCAP_TSO6;
+
+ if (mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_LRO |
+ IFCAP_VLAN_HWFILTER)) {
+ /* These Rx features require us to renegotiate. */
+ reinit = 1;
+
+ if (mask & IFCAP_RXCSUM)
+ ifp->if_capenable ^= IFCAP_RXCSUM;
+ if (mask & IFCAP_RXCSUM_IPV6)
+ ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
+ if (mask & IFCAP_LRO)
+ ifp->if_capenable ^= IFCAP_LRO;
+ if (mask & IFCAP_VLAN_HWFILTER)
+ ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
+ } else
+ reinit = 0;
+
+ if (mask & IFCAP_VLAN_HWTSO)
+ ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
+ if (mask & IFCAP_VLAN_HWTAGGING)
+ ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
+
+ if (reinit && (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
+ ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ vtnet_init_locked(sc, 0);
+ }
+
+ return (0);
+}
+
static int
vtnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct vtnet_softc *sc;
struct ifreq *ifr;
- int reinit, mask, error;
+ int error;
sc = ifp->if_softc;
ifr = (struct ifreq *) data;
@@ -1178,35 +1280,14 @@ vtnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
case SIOCSIFFLAGS:
VTNET_CORE_LOCK(sc);
- if ((ifp->if_flags & IFF_UP) == 0) {
- if (ifp->if_drv_flags & IFF_DRV_RUNNING)
- vtnet_stop(sc);
- } else if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
- if ((ifp->if_flags ^ sc->vtnet_if_flags) &
- (IFF_PROMISC | IFF_ALLMULTI)) {
- if (sc->vtnet_flags & VTNET_FLAG_CTRL_RX)
- vtnet_rx_filter(sc);
- else {
- ifp->if_flags |= IFF_PROMISC;
- if ((ifp->if_flags ^ sc->vtnet_if_flags)
- & IFF_ALLMULTI)
- error = ENOTSUP;
- }
- }
- } else
- vtnet_init_locked(sc, 0);
-
- if (error == 0)
- sc->vtnet_if_flags = ifp->if_flags;
+ error = vtnet_ioctl_ifflags(sc);
VTNET_CORE_UNLOCK(sc);
break;
case SIOCADDMULTI:
case SIOCDELMULTI:
VTNET_CORE_LOCK(sc);
- if (sc->vtnet_flags & VTNET_FLAG_CTRL_RX &&
- ifp->if_drv_flags & IFF_DRV_RUNNING)
- vtnet_rx_filter_mac(sc);
+ error = vtnet_ioctl_multi(sc);
VTNET_CORE_UNLOCK(sc);
break;
@@ -1217,46 +1298,9 @@ vtnet_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
case SIOCSIFCAP:
VTNET_CORE_LOCK(sc);
- mask = ifr->ifr_reqcap ^ ifp->if_capenable;
-
- if (mask & IFCAP_TXCSUM)
- ifp->if_capenable ^= IFCAP_TXCSUM;
- if (mask & IFCAP_TXCSUM_IPV6)
- ifp->if_capenable ^= IFCAP_TXCSUM_IPV6;
- if (mask & IFCAP_TSO4)
- ifp->if_capenable ^= IFCAP_TSO4;
- if (mask & IFCAP_TSO6)
- ifp->if_capenable ^= IFCAP_TSO6;
-
- if (mask & (IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | IFCAP_LRO |
- IFCAP_VLAN_HWFILTER)) {
- /* These Rx features require us to renegotiate. */
- reinit = 1;
-
- if (mask & IFCAP_RXCSUM)
- ifp->if_capenable ^= IFCAP_RXCSUM;
- if (mask & IFCAP_RXCSUM_IPV6)
- ifp->if_capenable ^= IFCAP_RXCSUM_IPV6;
- if (mask & IFCAP_LRO)
- ifp->if_capenable ^= IFCAP_LRO;
- if (mask & IFCAP_VLAN_HWFILTER)
- ifp->if_capenable ^= IFCAP_VLAN_HWFILTER;
- } else
- reinit = 0;
-
- if (mask & IFCAP_VLAN_HWTSO)
- ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
- if (mask & IFCAP_VLAN_HWTAGGING)
- ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
-
- if (reinit && (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
- ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
- vtnet_init_locked(sc, 0);
- }
-
+ error = vtnet_ioctl_ifcap(sc, ifr);
VTNET_CORE_UNLOCK(sc);
VLAN_CAPABILITIES(ifp);
-
break;
default:
More information about the dev-commits-src-main
mailing list