The branch stable/13 has been updated by asomers:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=8b7b81fd64ec054e6cbe0f1a817bad44aa355669

commit 8b7b81fd64ec054e6cbe0f1a817bad44aa355669
Author:     Alan Somers <[email protected]>
AuthorDate: 2022-12-18 20:12:02 +0000
Commit:     Alan Somers <[email protected]>
CommitDate: 2023-01-27 19:27:47 +0000

    Switch wg(4) to the new if_clone KPI
    
    Reviewed by:    jhb
    Differential Revision: https://reviews.freebsd.org/D37740
    
    (cherry picked from commit eb3f9a7aece9473d678adddcf6aefe6c1eec0ac4)
---
 sys/dev/wg/if_wg.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c
index 94395c86f370..9c4ebe5dd393 100644
--- a/sys/dev/wg/if_wg.c
+++ b/sys/dev/wg/if_wg.c
@@ -361,13 +361,15 @@ static struct wg_packet *wg_queue_dequeue_serial(struct 
wg_queue *);
 static struct wg_packet *wg_queue_dequeue_parallel(struct wg_queue *);
 static void wg_input(struct mbuf *, int, struct inpcb *, const struct sockaddr 
*, void *);
 static void wg_peer_send_staged(struct wg_peer *);
-static int wg_clone_create(struct if_clone *, int, caddr_t);
+static int wg_clone_create(struct if_clone *ifc, char *name, size_t len,
+       struct ifc_data *ifd, struct ifnet **ifpp);
 static void wg_qflush(struct ifnet *);
 static inline int determine_af_and_pullup(struct mbuf **m, sa_family_t *af);
 static int wg_xmit(struct ifnet *, struct mbuf *, sa_family_t, uint32_t);
 static int wg_transmit(struct ifnet *, struct mbuf *);
 static int wg_output(struct ifnet *, struct mbuf *, const struct sockaddr *, 
struct route *);
-static void wg_clone_destroy(struct ifnet *);
+static int wg_clone_destroy(struct if_clone *ifc, struct ifnet *ifp,
+       uint32_t flags);
 static bool wgc_privileged(struct wg_softc *);
 static int wgc_get(struct wg_softc *, struct wg_data_io *);
 static int wgc_set(struct wg_softc *, struct wg_data_io *);
@@ -2717,7 +2719,8 @@ wg_down(struct wg_softc *sc)
 }
 
 static int
-wg_clone_create(struct if_clone *ifc, int unit, caddr_t params)
+wg_clone_create(struct if_clone *ifc, char *name, size_t len,
+    struct ifc_data *ifd, struct ifnet **ifpp)
 {
        struct wg_softc *sc;
        struct ifnet *ifp;
@@ -2771,7 +2774,7 @@ wg_clone_create(struct if_clone *ifc, int unit, caddr_t 
params)
 
        ifp->if_softc = sc;
        ifp->if_capabilities = ifp->if_capenable = WG_CAPS;
-       if_initname(ifp, wgname, unit);
+       if_initname(ifp, wgname, ifd->unit);
 
        if_setmtu(ifp, DEFAULT_MTU);
        ifp->if_flags = IFF_NOARP | IFF_MULTICAST;
@@ -2790,6 +2793,7 @@ wg_clone_create(struct if_clone *ifc, int unit, caddr_t 
params)
        sx_xlock(&wg_sx);
        LIST_INSERT_HEAD(&wg_list, sc, sc_entry);
        sx_xunlock(&wg_sx);
+       *ifpp = ifp;
        return (0);
 free_aip4:
        RADIX_NODE_HEAD_DESTROY(sc->sc_aip4);
@@ -2811,8 +2815,8 @@ wg_clone_deferred_free(struct noise_local *l)
        atomic_add_int(&clone_count, -1);
 }
 
-static void
-wg_clone_destroy(struct ifnet *ifp)
+static int
+wg_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags)
 {
        struct wg_softc *sc = ifp->if_softc;
        struct ucred *cred;
@@ -2872,6 +2876,8 @@ wg_clone_destroy(struct ifnet *ifp)
        if_free(sc->sc_ifp);
 
        noise_local_free(sc->sc_local, wg_clone_deferred_free);
+
+       return (0);
 }
 
 static void
@@ -2914,8 +2920,12 @@ wg_init(void *xsc)
 static void
 vnet_wg_init(const void *unused __unused)
 {
-       V_wg_cloner = if_clone_simple(wgname, wg_clone_create, wg_clone_destroy,
-                                     0);
+       struct if_clone_addreq req = {
+               .create_f = wg_clone_create,
+               .destroy_f = wg_clone_destroy,
+               .flags = IFC_F_AUTOUNIT,
+       };
+       V_wg_cloner = ifc_attach_cloner(wgname, &req);
 }
 VNET_SYSINIT(vnet_wg_init, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
             vnet_wg_init, NULL);
@@ -2924,7 +2934,7 @@ static void
 vnet_wg_uninit(const void *unused __unused)
 {
        if (V_wg_cloner)
-               if_clone_detach(V_wg_cloner);
+               ifc_detach_cloner(V_wg_cloner);
 }
 VNET_SYSUNINIT(vnet_wg_uninit, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY,
               vnet_wg_uninit, NULL);
@@ -3018,7 +3028,7 @@ wg_module_deinit(void)
        VNET_FOREACH(vnet_iter) {
                struct if_clone *clone = VNET_VNET(vnet_iter, wg_cloner);
                if (clone) {
-                       if_clone_detach(clone);
+                       ifc_detach_cloner(clone);
                        VNET_VNET(vnet_iter, wg_cloner) = NULL;
                }
        }

Reply via email to