From 92a6859b91b53e103eb1297ea95b11479de2b7a2 Mon Sep 17 00:00:00 2001 From: Dexuan Cui Date: Tue, 24 Jan 2017 09:19:46 +0000 Subject: [PATCH] ifnet: introduce event handlers for ifup/ifdown events Hyper-V's NIC SR-IOV implementation needs a Hyper-V synthetic NIC and a VF NIC to work together, mainly to support seamless live migration. When the VF device becomes UP (or DOWN), the synthetic NIC driver needs to switch the data path from the synthetic NIC to the VF (or the opposite). So the synthetic NIC driver needs to know when a VF device is becoming UP or DOWN and hence the patch is made. Reviewed by: sephe Approved by: sephe (mentor) MFC after: 2 weeks Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D8963 --- sys/net/if.c | 3 +++ sys/sys/eventhandler.h | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index 58c8a062ffcd..9c1f6946def5 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -2218,6 +2219,7 @@ void if_down(struct ifnet *ifp) { + EVENTHANDLER_INVOKE(ifnet_event, ifp, IFNET_EVENT_DOWN); if_unroute(ifp, IFF_UP, AF_UNSPEC); } @@ -2230,6 +2232,7 @@ if_up(struct ifnet *ifp) { if_route(ifp, IFF_UP, AF_UNSPEC); + EVENTHANDLER_INVOKE(ifnet_event, ifp, IFNET_EVENT_UP); } /* diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h index b071c63926ee..0f0665ccb947 100644 --- a/sys/sys/eventhandler.h +++ b/sys/sys/eventhandler.h @@ -284,4 +284,11 @@ typedef void (*swapoff_fn)(void *, struct swdevt *); EVENTHANDLER_DECLARE(swapon, swapon_fn); EVENTHANDLER_DECLARE(swapoff, swapoff_fn); +/* ifup/ifdown events */ +#define IFNET_EVENT_UP 0 +#define IFNET_EVENT_DOWN 1 +struct ifnet; +typedef void (*ifnet_event_fn)(void *, struct ifnet *ifp, int event); +EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn); + #endif /* _SYS_EVENTHANDLER_H_ */