From nobody Fri Feb 03 14:45:21 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P7djs5CzCz2pCZX; Fri, 3 Feb 2023 14:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P7djs4RJcz4M3Y; Fri, 3 Feb 2023 14:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675435521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j5Cv0nchm/fSAWaE0CaMTnDaPiPU2cl5haoWTThP5ac=; b=abkWUA6gkbiTYNLIg4PjDOppH2d7gvY+s9cA4sKzh97wN56Tla0X5/xXCv9XG1MZjoIEyr O+uGA8uckA4tKfje6kCeD+LABbCddWVt9VNwKHyMdgck2auIWfGQEbQVcHyzZEHGE85LFE BiUzS6qxk646LYZkvZB6AQ8/UbjBtBTD0AKq9Je7vyy+JKCF35tN/z+F/4XUAl0+wcRyFs r7Wt5Hff69geh7s//kX7fOseI8gN4UK6Hp78gpkmDJeo10ADvCrqqv7gvj2H30GWY4m4H4 vjpUR0VhXM8b8j27zheKaN6slVKKkvUPRGFqPi/Fr24KGZpx68WEEI3YzS/PkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675435521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j5Cv0nchm/fSAWaE0CaMTnDaPiPU2cl5haoWTThP5ac=; b=xM7+jKf0modResTtppXIBrOVOi/y8Atcz29seMxkhR5xZIF4bxfmSQ43X+h0jPr8n0s5E4 brZYQSqXGiW+ZX1H7mAFoJEb4u1J4y0P1NanGPWgDQ//vwlInod/+BEYQunQJvi2HWCdX4 D3W4Gk+KoVTGBZQBSMP9ON7O3TG9GhaiBDivpyQIC/7rdxKh978qYdDKuXa4T9tEGtpZDD +SkAqamwWdjCpGgh5ZiA7OgR94AyAX6/S1A+nSHtt95b6jkwEVJY1ksrTosFZwOcGWRXT3 lcqJdeTl6xu2bRBzrgMg+W3JPG/oHDqGy9nVeExZgoDsQBvNyK+MFpJ8KwvPdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675435521; a=rsa-sha256; cv=none; b=OxTEXeTEWJpRt2Z5brxXzM+u2Go8pkIZNXfRzr52hlvzuMKJ9077viAGvopLRDhRD3mYh9 6yGEILqtPN1POnCUxCwfZtRqveJMilFC3lxniLOPVOesE7FkklUq6VAt5piGm+2WQ8pkOh zyTEWHNkcyE+r4K78VQlBhb9N08BhW0a/a7bb6HViq1tARo9vpoE4sPB1cfMS+2aWQnNJM Y5y7/LAmQAMgZX9aBw0vRNKc+HKJahKkBtfpx47jR5j/H+SnE0gb0/JkW7unIymAJYpi+a TZoxwYDtFs8D+jfHm3P1VU9d/b94efi7aq7QqfzxcAJCECEMhXaepuRJAlWSyA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P7djs3WRvzdwj; Fri, 3 Feb 2023 14:45:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 313EjLYl027926; Fri, 3 Feb 2023 14:45:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313EjLwi027925; Fri, 3 Feb 2023 14:45:21 GMT (envelope-from git) Date: Fri, 3 Feb 2023 14:45:21 GMT Message-Id: <202302031445.313EjLwi027925@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 87e728340b1d - main - Mechanically convert wg(4) to IfAPI List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 87e728340b1d57f10e4d439d168226d9ffffed40 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=87e728340b1d57f10e4d439d168226d9ffffed40 commit 87e728340b1d57f10e4d439d168226d9ffffed40 Author: Justin Hibbits AuthorDate: 2023-01-13 16:22:11 +0000 Commit: Justin Hibbits CommitDate: 2023-02-03 14:38:03 +0000 Mechanically convert wg(4) to IfAPI Reviewed By: jhb Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D38307 --- sys/dev/wg/if_wg.c | 109 +++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c index f6c8c2d52278..6a99061cac54 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -67,7 +67,7 @@ #define NEW_HANDSHAKE_TIMEOUT (REKEY_TIMEOUT + KEEPALIVE_TIMEOUT) #define UNDERLOAD_TIMEOUT 1 -#define DPRINTF(sc, ...) if (sc->sc_ifp->if_flags & IFF_DEBUG) if_printf(sc->sc_ifp, ##__VA_ARGS__) +#define DPRINTF(sc, ...) if (if_getflags(sc->sc_ifp) & IFF_DEBUG) if_printf(sc->sc_ifp, ##__VA_ARGS__) /* First byte indicating packet type on the wire */ #define WG_PKT_INITIATION htole32(1) @@ -219,7 +219,7 @@ struct wg_socket { struct wg_softc { LIST_ENTRY(wg_softc) sc_entry; - struct ifnet *sc_ifp; + if_t sc_ifp; int sc_flags; struct ucred *sc_ucred; @@ -358,22 +358,22 @@ static struct wg_packet *wg_queue_dequeue_parallel(struct wg_queue *); static bool 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 *ifc, char *name, size_t len, - struct ifc_data *ifd, struct ifnet **ifpp); -static void wg_qflush(struct ifnet *); + struct ifc_data *ifd, if_t *ifpp); +static void wg_qflush(if_t); 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 int wg_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, +static int wg_xmit(if_t, struct mbuf *, sa_family_t, uint32_t); +static int wg_transmit(if_t, struct mbuf *); +static int wg_output(if_t, struct mbuf *, const struct sockaddr *, struct route *); +static int wg_clone_destroy(struct if_clone *ifc, if_t 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 *); static int wg_up(struct wg_softc *); static void wg_down(struct wg_softc *); -static void wg_reassign(struct ifnet *, struct vnet *, char *unused); +static void wg_reassign(if_t, struct vnet *, char *unused); static void wg_init(void *); -static int wg_ioctl(struct ifnet *, u_long, caddr_t); +static int wg_ioctl(if_t, u_long, caddr_t); static void vnet_wg_init(const void *); static void vnet_wg_uninit(const void *); static int wg_module_init(void); @@ -1308,7 +1308,7 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt) res = cookie_checker_validate_macs(&sc->sc_cookie, &init->m, init, sizeof(*init) - sizeof(init->m), underload, &e->e_remote.r_sa, - sc->sc_ifp->if_vnet); + if_getvnet(sc->sc_ifp)); if (res == EINVAL) { DPRINTF(sc, "Invalid initiation MAC\n"); @@ -1342,7 +1342,7 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt) res = cookie_checker_validate_macs(&sc->sc_cookie, &resp->m, resp, sizeof(*resp) - sizeof(resp->m), underload, &e->e_remote.r_sa, - sc->sc_ifp->if_vnet); + if_getvnet(sc->sc_ifp)); if (res == EINVAL) { DPRINTF(sc, "Invalid response MAC\n"); @@ -1677,7 +1677,7 @@ static void wg_deliver_in(struct wg_peer *peer) { struct wg_softc *sc = peer->p_sc; - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct wg_packet *pkt; struct mbuf *m; struct epoch_tracker et; @@ -1714,8 +1714,8 @@ wg_deliver_in(struct wg_peer *peer) NET_EPOCH_ENTER(et); BPF_MTAP2_AF(ifp, m, pkt->p_af); - CURVNET_SET(ifp->if_vnet); - M_SETFIB(m, ifp->if_fib); + CURVNET_SET(if_getvnet(ifp)); + M_SETFIB(m, if_getfib(ifp)); if (pkt->p_af == AF_INET) netisr_dispatch(NETISR_IP, m); if (pkt->p_af == AF_INET6) @@ -2050,7 +2050,7 @@ error: } static inline void -xmit_err(struct ifnet *ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af) +xmit_err(if_t ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af) { if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); switch (af) { @@ -2078,16 +2078,16 @@ xmit_err(struct ifnet *ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t a } static int -wg_xmit(struct ifnet *ifp, struct mbuf *m, sa_family_t af, uint32_t mtu) +wg_xmit(if_t ifp, struct mbuf *m, sa_family_t af, uint32_t mtu) { struct wg_packet *pkt = NULL; - struct wg_softc *sc = ifp->if_softc; + struct wg_softc *sc = if_getsoftc(ifp); struct wg_peer *peer; int rc = 0; sa_family_t peer_af; /* Work around lifetime issue in the ipv6 mld code. */ - if (__predict_false((ifp->if_flags & IFF_DYING) || !sc)) { + if (__predict_false((if_getflags(ifp) & IFF_DYING) || !sc)) { rc = ENXIO; goto err_xmit; } @@ -2164,7 +2164,7 @@ determine_af_and_pullup(struct mbuf **m, sa_family_t *af) } static int -wg_transmit(struct ifnet *ifp, struct mbuf *m) +wg_transmit(if_t ifp, struct mbuf *m) { sa_family_t af; int ret; @@ -2184,11 +2184,11 @@ wg_transmit(struct ifnet *ifp, struct mbuf *m) xmit_err(ifp, m, NULL, AF_UNSPEC); return (ret); } - return (wg_xmit(ifp, m, af, ifp->if_mtu)); + return (wg_xmit(ifp, m, af, if_getmtu(ifp))); } static int -wg_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro) +wg_output(if_t ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro) { sa_family_t parsed_af; uint32_t af, mtu; @@ -2222,7 +2222,7 @@ wg_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct xmit_err(ifp, m, NULL, AF_UNSPEC); return (EAFNOSUPPORT); } - mtu = (ro != NULL && ro->ro_mtu > 0) ? ro->ro_mtu : ifp->if_mtu; + mtu = (ro != NULL && ro->ro_mtu > 0) ? ro->ro_mtu : if_getmtu(ifp); return (wg_xmit(ifp, m, parsed_af, mtu)); } @@ -2332,7 +2332,7 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl) goto out; TAILQ_INSERT_TAIL(&sc->sc_peers, peer, p_entry); sc->sc_peers_num++; - if (sc->sc_ifp->if_link_state == LINK_STATE_UP) + if (if_getlinkstate(sc->sc_ifp) == LINK_STATE_UP) wg_timers_enable(peer); } if (remote != NULL) @@ -2350,7 +2350,7 @@ static int wgc_set(struct wg_softc *sc, struct wg_data_io *wgd) { uint8_t public[WG_KEY_SIZE], private[WG_KEY_SIZE]; - struct ifnet *ifp; + if_t ifp; void *nvlpacked; nvlist_t *nvl; ssize_t size; @@ -2386,7 +2386,7 @@ wgc_set(struct wg_softc *sc, struct wg_data_io *wgd) goto out_locked; } if (new_port != sc->sc_socket.so_port) { - if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) { + if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0) { if ((err = wg_socket_init(sc, new_port)) != 0) goto out_locked; } else @@ -2584,7 +2584,7 @@ err: } static int -wg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) +wg_ioctl(if_t ifp, u_long cmd, caddr_t data) { struct wg_data_io *wgd = (struct wg_data_io *)data; struct ifreq *ifr = (struct ifreq *)data; @@ -2592,7 +2592,7 @@ wg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) int ret = 0; sx_slock(&wg_sx); - sc = ifp->if_softc; + sc = if_getsoftc(ifp); if (!sc) { ret = ENXIO; goto out; @@ -2615,7 +2615,7 @@ wg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) */ break; case SIOCSIFFLAGS: - if (ifp->if_flags & IFF_UP) + if (if_getflags(ifp) & IFF_UP) ret = wg_up(sc); else wg_down(sc); @@ -2624,7 +2624,7 @@ wg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) if (ifr->ifr_mtu <= 0 || ifr->ifr_mtu > MAX_MTU) ret = EINVAL; else - ifp->if_mtu = ifr->ifr_mtu; + if_setmtu(ifp, ifr->ifr_mtu); break; case SIOCADDMULTI: case SIOCDELMULTI: @@ -2655,7 +2655,7 @@ out: static int wg_up(struct wg_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct wg_peer *peer; int rc = EBUSY; @@ -2666,9 +2666,9 @@ wg_up(struct wg_softc *sc) /* Silent success if we're already running. */ rc = 0; - if (ifp->if_drv_flags & IFF_DRV_RUNNING) + if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) goto out; - ifp->if_drv_flags |= IFF_DRV_RUNNING; + if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0); rc = wg_socket_init(sc, sc->sc_socket.so_port); if (rc == 0) { @@ -2676,7 +2676,7 @@ wg_up(struct wg_softc *sc) wg_timers_enable(peer); if_link_state_change(sc->sc_ifp, LINK_STATE_UP); } else { - ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); DPRINTF(sc, "Unable to initialize sockets: %d\n", rc); } out: @@ -2687,15 +2687,15 @@ out: static void wg_down(struct wg_softc *sc) { - struct ifnet *ifp = sc->sc_ifp; + if_t ifp = sc->sc_ifp; struct wg_peer *peer; sx_xlock(&sc->sc_lock); - if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { + if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) { sx_xunlock(&sc->sc_lock); return; } - ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING); TAILQ_FOREACH(peer, &sc->sc_peers, p_entry) { wg_queue_purge(&peer->p_stage_queue); @@ -2720,7 +2720,7 @@ 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; + if_t ifp; sc = malloc(sizeof(*sc), M_WG, M_WAITOK | M_ZERO); @@ -2769,18 +2769,19 @@ wg_clone_create(struct if_clone *ifc, char *name, size_t len, sx_init(&sc->sc_lock, "wg softc lock"); - ifp->if_softc = sc; - ifp->if_capabilities = ifp->if_capenable = WG_CAPS; + if_setsoftc(ifp, sc); + if_setcapabilities(ifp, WG_CAPS); + if_setcapenable(ifp, WG_CAPS); if_initname(ifp, wgname, ifd->unit); if_setmtu(ifp, DEFAULT_MTU); - ifp->if_flags = IFF_NOARP | IFF_MULTICAST; - ifp->if_init = wg_init; - ifp->if_reassign = wg_reassign; - ifp->if_qflush = wg_qflush; - ifp->if_transmit = wg_transmit; - ifp->if_output = wg_output; - ifp->if_ioctl = wg_ioctl; + if_setflags(ifp, IFF_NOARP | IFF_MULTICAST); + if_setinitfn(ifp, wg_init); + if_setreassignfn(ifp, wg_reassign); + if_setqflushfn(ifp, wg_qflush); + if_settransmitfn(ifp, wg_transmit); + if_setoutputfn(ifp, wg_output); + if_setioctlfn(ifp, wg_ioctl); if_attach(ifp); bpfattach(ifp, DLT_NULL, sizeof(uint32_t)); #ifdef INET6 @@ -2813,13 +2814,13 @@ wg_clone_deferred_free(struct noise_local *l) } static int -wg_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags) +wg_clone_destroy(struct if_clone *ifc, if_t ifp, uint32_t flags) { - struct wg_softc *sc = ifp->if_softc; + struct wg_softc *sc = if_getsoftc(ifp); struct ucred *cred; sx_xlock(&wg_sx); - ifp->if_softc = NULL; + if_setsoftc(ifp, NULL); sx_xlock(&sc->sc_lock); sc->sc_flags |= WGF_DYING; cred = sc->sc_ucred; @@ -2829,7 +2830,7 @@ wg_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags) sx_xunlock(&wg_sx); if_link_state_change(sc->sc_ifp, LINK_STATE_DOWN); - CURVNET_SET(sc->sc_ifp->if_vnet); + CURVNET_SET(if_getvnet(sc->sc_ifp)); if_purgeaddrs(sc->sc_ifp); CURVNET_RESTORE(); @@ -2878,7 +2879,7 @@ wg_clone_destroy(struct if_clone *ifc, struct ifnet *ifp, uint32_t flags) } static void -wg_qflush(struct ifnet *ifp __unused) +wg_qflush(if_t ifp __unused) { } @@ -2896,12 +2897,12 @@ wgc_privileged(struct wg_softc *sc) } static void -wg_reassign(struct ifnet *ifp, struct vnet *new_vnet __unused, +wg_reassign(if_t ifp, struct vnet *new_vnet __unused, char *unused __unused) { struct wg_softc *sc; - sc = ifp->if_softc; + sc = if_getsoftc(ifp); wg_down(sc); }