Content-Length: 897472 | pFad | http://github.com/liweitianux/dragonflybsd/commit/430b012a0ccf836aed86b73e79f66c34f7d4863a

74 wg: Port #15: adapt 'struct ifnet' related code and routines · liweitianux/dragonflybsd@430b012 · GitHub
Skip to content

Commit 430b012

Browse files
committed
wg: Port DragonFlyBSD#15: adapt 'struct ifnet' related code and routines
Remove unsupported routines, like wg_qflush() and wg_reassign(). Also remove the unsupported 'IFF_DYING' workaround for IPv6. If we also have such an issue, should fix the IPv6 code. TODO: rework the if_output() and if_start() routines.
1 parent bc3a907 commit 430b012

File tree

1 file changed

+53
-74
lines changed

1 file changed

+53
-74
lines changed

sys/net/wg/if_wg.c

Lines changed: 53 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <net/if_clone.h>
3636
#include <net/if_types.h>
3737
#include <net/if_var.h>
38+
#include <net/ifq_var.h>
3839
#include <net/netisr.h>
3940
#include <net/radix.h>
4041
#include <netinet/in.h>
@@ -65,7 +66,8 @@
6566
#define NEW_HANDSHAKE_TIMEOUT (REKEY_TIMEOUT + KEEPALIVE_TIMEOUT)
6667
#define UNDERLOAD_TIMEOUT 1
6768

68-
#define DPRINTF(sc, ...) if (if_getflags(sc->sc_ifp) & IFF_DEBUG) if_printf(sc->sc_ifp, ##__VA_ARGS__)
69+
#define DPRINTF(sc, ...) \
70+
if (sc->sc_ifp->if_flags & IFF_DEBUG) if_printf(sc->sc_ifp, ##__VA_ARGS__)
6971

7072
/* First byte indicating packet type on the wire */
7173
#define WG_PKT_INITIATION htole32(1)
@@ -216,7 +218,7 @@ struct wg_socket {
216218

217219
struct wg_softc {
218220
LIST_ENTRY(wg_softc) sc_entry;
219-
if_t sc_ifp;
221+
struct ifnet *sc_ifp;
220222
int sc_flags;
221223

222224
struct ucred *sc_ucred;
@@ -361,20 +363,18 @@ static struct wg_packet *wg_queue_dequeue_parallel(struct wg_queue *);
361363
static bool wg_input(struct mbuf *, int, struct inpcb *, const struct sockaddr *, void *);
362364
static void wg_peer_send_staged(struct wg_peer *);
363365
static int wg_clone_create(struct if_clone *, int, caddr_t, caddr_t);
364-
static void wg_qflush(if_t);
365366
static inline int determine_af_and_pullup(struct mbuf **m, sa_family_t *af);
366-
static int wg_xmit(if_t, struct mbuf *, sa_family_t, uint32_t);
367-
static int wg_transmit(if_t, struct mbuf *);
368-
static int wg_output(if_t, struct mbuf *, const struct sockaddr *, struct route *);
367+
static int wg_xmit(struct ifnet *, struct mbuf *, sa_family_t, uint32_t);
368+
static int wg_transmit(struct ifnet *, struct mbuf *);
369+
static int wg_output(struct ifnet *, struct mbuf *, const struct sockaddr *, struct rtentry *);
369370
static int wg_clone_destroy(struct ifnet *ifp);
370371
static bool wgc_privileged(struct wg_softc *);
371372
static int wgc_get(struct wg_softc *, struct wg_data_io *);
372373
static int wgc_set(struct wg_softc *, struct wg_data_io *);
373374
static int wg_up(struct wg_softc *);
374375
static void wg_down(struct wg_softc *);
375-
static void wg_reassign(if_t, struct vnet *, char *unused);
376376
static void wg_init(void *);
377-
static int wg_ioctl(if_t, u_long, caddr_t);
377+
static int wg_ioctl(struct ifnet *, u_long, caddr_t);
378378
static int wg_module_init(void);
379379
static int wg_module_deinit(void);
380380

@@ -1659,7 +1659,7 @@ static void
16591659
wg_deliver_in(struct wg_peer *peer)
16601660
{
16611661
struct wg_softc *sc = peer->p_sc;
1662-
if_t ifp = sc->sc_ifp;
1662+
struct ifnet *ifp = sc->sc_ifp;
16631663
struct wg_packet *pkt;
16641664
struct mbuf *m;
16651665
struct epoch_tracker et;
@@ -2030,7 +2030,7 @@ wg_peer_send_staged(struct wg_peer *peer)
20302030
}
20312031

20322032
static inline void
2033-
xmit_err(if_t ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af)
2033+
xmit_err(struct ifnet *ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af)
20342034
{
20352035
IFNET_STAT_INC(ifp, oerrors, 1);
20362036
switch (af) {
@@ -2058,20 +2058,14 @@ xmit_err(if_t ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af)
20582058
}
20592059

20602060
static int
2061-
wg_xmit(if_t ifp, struct mbuf *m, sa_family_t af, uint32_t mtu)
2061+
wg_xmit(struct ifnet *ifp, struct mbuf *m, sa_family_t af, uint32_t mtu)
20622062
{
20632063
struct wg_packet *pkt = NULL;
2064-
struct wg_softc *sc = if_getsoftc(ifp);
2064+
struct wg_softc *sc = ifp->if_softc;
20652065
struct wg_peer *peer;
20662066
int rc = 0;
20672067
sa_family_t peer_af;
20682068

2069-
/* Work around lifetime issue in the ipv6 mld code. */
2070-
if (__predict_false((if_getflags(ifp) & IFF_DYING) || !sc)) {
2071-
rc = ENXIO;
2072-
goto err_xmit;
2073-
}
2074-
20752069
if ((pkt = wg_packet_alloc(m)) == NULL) {
20762070
rc = ENOBUFS;
20772071
goto err_xmit;
@@ -2144,7 +2138,7 @@ determine_af_and_pullup(struct mbuf **m, sa_family_t *af)
21442138
}
21452139

21462140
static int
2147-
wg_transmit(if_t ifp, struct mbuf *m)
2141+
wg_transmit(struct ifnet *ifp, struct mbuf *m)
21482142
{
21492143
sa_family_t af;
21502144
int ret;
@@ -2164,11 +2158,11 @@ wg_transmit(if_t ifp, struct mbuf *m)
21642158
xmit_err(ifp, m, NULL, AF_UNSPEC);
21652159
return (ret);
21662160
}
2167-
return (wg_xmit(ifp, m, af, if_getmtu(ifp)));
2161+
return (wg_xmit(ifp, m, af, ifp->if_mtu));
21682162
}
21692163

21702164
static int
2171-
wg_output(if_t ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro)
2165+
wg_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct rtentry *rt)
21722166
{
21732167
sa_family_t parsed_af;
21742168
uint32_t af, mtu;
@@ -2202,7 +2196,7 @@ wg_output(if_t ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro
22022196
xmit_err(ifp, m, NULL, AF_UNSPEC);
22032197
return (EAFNOSUPPORT);
22042198
}
2205-
mtu = (ro != NULL && ro->ro_mtu > 0) ? ro->ro_mtu : if_getmtu(ifp);
2199+
mtu = (ro != NULL && ro->ro_mtu > 0) ? ro->ro_mtu : ifp->if_mtu;
22062200
return (wg_xmit(ifp, m, parsed_af, mtu));
22072201
}
22082202

@@ -2312,7 +2306,7 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl)
23122306
goto out;
23132307
TAILQ_INSERT_TAIL(&sc->sc_peers, peer, p_entry);
23142308
sc->sc_peers_num++;
2315-
if (if_getlinkstate(sc->sc_ifp) == LINK_STATE_UP)
2309+
if (sc->sc_ifp->if_link_state == LINK_STATE_UP)
23162310
wg_timers_enable(peer);
23172311
}
23182312
if (remote != NULL)
@@ -2330,7 +2324,7 @@ static int
23302324
wgc_set(struct wg_softc *sc, struct wg_data_io *wgd)
23312325
{
23322326
uint8_t public[WG_KEY_SIZE], private[WG_KEY_SIZE];
2333-
if_t ifp;
2327+
struct ifnet *ifp;
23342328
void *nvlpacked;
23352329
nvlist_t *nvl;
23362330
ssize_t size;
@@ -2366,7 +2360,7 @@ wgc_set(struct wg_softc *sc, struct wg_data_io *wgd)
23662360
goto out_locked;
23672361
}
23682362
if (new_port != sc->sc_socket.so_port) {
2369-
if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0) {
2363+
if ((ifp->if_flags & IFF_RUNNING) != 0) {
23702364
if ((err = wg_socket_init(sc, new_port)) != 0)
23712365
goto out_locked;
23722366
} else
@@ -2574,15 +2568,15 @@ wgc_get(struct wg_softc *sc, struct wg_data_io *wgd)
25742568
}
25752569

25762570
static int
2577-
wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2571+
wg_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
25782572
{
25792573
struct wg_data_io *wgd = (struct wg_data_io *)data;
25802574
struct ifreq *ifr = (struct ifreq *)data;
25812575
struct wg_softc *sc;
25822576
int ret = 0;
25832577

25842578
lockmgr(&wg_lock, LK_SHARED);
2585-
sc = if_getsoftc(ifp);
2579+
sc = ifp->if_softc;
25862580
if (!sc) {
25872581
ret = ENXIO;
25882582
goto out;
@@ -2605,7 +2599,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
26052599
*/
26062600
break;
26072601
case SIOCSIFFLAGS:
2608-
if (if_getflags(ifp) & IFF_UP)
2602+
if (ifp->if_flags & IFF_UP)
26092603
ret = wg_up(sc);
26102604
else
26112605
wg_down(sc);
@@ -2614,7 +2608,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
26142608
if (ifr->ifr_mtu <= 0 || ifr->ifr_mtu > MAX_MTU)
26152609
ret = EINVAL;
26162610
else
2617-
if_setmtu(ifp, ifr->ifr_mtu);
2611+
ifp->if_mtu = ifr->ifr_mtu;
26182612
break;
26192613
case SIOCADDMULTI:
26202614
case SIOCDELMULTI:
@@ -2631,7 +2625,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
26312625
static int
26322626
wg_up(struct wg_softc *sc)
26332627
{
2634-
if_t ifp = sc->sc_ifp;
2628+
struct ifnet *ifp = sc->sc_ifp;
26352629
struct wg_peer *peer;
26362630
int rc = EBUSY;
26372631

@@ -2643,17 +2637,18 @@ wg_up(struct wg_softc *sc)
26432637

26442638
/* Silent success if we're already running. */
26452639
rc = 0;
2646-
if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
2640+
if (ifp->if_flags & IFF_RUNNING)
26472641
goto out;
2648-
if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
2642+
ifp->if_flags |= IFF_RUNNING;
26492643

26502644
rc = wg_socket_init(sc, sc->sc_socket.so_port);
26512645
if (rc == 0) {
26522646
TAILQ_FOREACH(peer, &sc->sc_peers, p_entry)
26532647
wg_timers_enable(peer);
2654-
if_link_state_change(sc->sc_ifp, LINK_STATE_UP);
2648+
ifp->if_link_state = LINK_STATE_UP;
2649+
if_link_state_change(ifp);
26552650
} else {
2656-
if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
2651+
ifp->if_flags &= ~IFF_RUNNING;
26572652
DPRINTF(sc, "Unable to initialize sockets: %d\n", rc);
26582653
}
26592654
out:
@@ -2664,15 +2659,15 @@ wg_up(struct wg_softc *sc)
26642659
static void
26652660
wg_down(struct wg_softc *sc)
26662661
{
2667-
if_t ifp = sc->sc_ifp;
2662+
struct ifnet *ifp = sc->sc_ifp;
26682663
struct wg_peer *peer;
26692664

26702665
lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
2671-
if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING)) {
2666+
if ((ifp->if_flags & IFF_RUNNING) == 0) {
26722667
lockmgr(&sc->sc_lock, LK_RELEASE);
26732668
return;
26742669
}
2675-
if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
2670+
ifp->if_flags &= ~IFF_RUNNING;
26762671

26772672
TAILQ_FOREACH(peer, &sc->sc_peers, p_entry) {
26782673
wg_queue_purge(&peer->p_stage_queue);
@@ -2686,7 +2681,8 @@ wg_down(struct wg_softc *sc)
26862681
noise_remote_keypairs_clear(peer->p_remote);
26872682
}
26882683

2689-
if_link_state_change(sc->sc_ifp, LINK_STATE_DOWN);
2684+
ifp->if_link_state = LINK_STATE_DOWN;
2685+
if_link_state_change(ifp);
26902686
wg_socket_uninit(sc);
26912687

26922688
lockmgr(&sc->sc_lock, LK_RELEASE);
@@ -2745,25 +2741,22 @@ wg_clone_create(struct if_clone *ifc __unused, int unit,
27452741

27462742
lockinit(&sc->sc_lock, "wg softc lock", 0, 0);
27472743

2748-
if_setsoftc(ifp, sc);
2749-
if_setcapabilities(ifp, WG_CAPS);
2750-
if_setcapenable(ifp, WG_CAPS);
27512744
if_initname(ifp, wgname, unit);
2752-
2753-
if_setmtu(ifp, DEFAULT_MTU);
2754-
if_setflags(ifp, IFF_NOARP | IFF_MULTICAST);
2755-
if_setinitfn(ifp, wg_init);
2756-
if_setreassignfn(ifp, wg_reassign);
2757-
if_setqflushfn(ifp, wg_qflush);
2758-
if_settransmitfn(ifp, wg_transmit);
2759-
if_setoutputfn(ifp, wg_output);
2760-
if_setioctlfn(ifp, wg_ioctl);
2761-
if_attach(ifp);
2745+
ifp->if_softc = sc;
2746+
ifp->if_capabilities = WG_CAPS;
2747+
ifp->if_capenable = WG_CAPS;
2748+
ifp->if_mtu = DEFAULT_MTU;
2749+
ifp->if_flags = IFF_NOARP | IFF_MULTICAST;
2750+
ifp->if_init = wg_init;
2751+
ifp->if_output = wg_output;
2752+
ifp->if_start = wg_start; /* TODO(ALY) */
2753+
ifp->if_ioctl = wg_ioctl;
2754+
ifq_set_maxlen(&ifp->if_snd, ifqmaxlen);
2755+
ifq_set_ready(&ifp->if_snd);
2756+
2757+
if_attach(ifp, NULL);
27622758
bpfattach(ifp, DLT_NULL, sizeof(uint32_t));
2763-
#ifdef INET6
2764-
ND_IFINFO(ifp)->flags &= ~ND6_IFF_AUTO_LINKLOCAL;
2765-
ND_IFINFO(ifp)->flags |= ND6_IFF_NO_DAD;
2766-
#endif
2759+
27672760
lockmgr(&wg_lock, LK_EXCLUSIVE);
27682761
LIST_INSERT_HEAD(&wg_list, sc, sc_entry);
27692762
lockmgr(&wg_lock, LK_RELEASE);
@@ -2791,11 +2784,11 @@ wg_clone_deferred_free(struct noise_local *l)
27912784
static int
27922785
wg_clone_destroy(struct ifnet *ifp)
27932786
{
2794-
struct wg_softc *sc = if_getsoftc(ifp);
2787+
struct wg_softc *sc = ifp->if_softc;
27952788
struct ucred *cred;
27962789

27972790
lockmgr(&wg_lock, LK_EXCLUSIVE);
2798-
if_setsoftc(ifp, NULL);
2791+
ifp->if_softc = NULL;
27992792
lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
28002793
sc->sc_flags |= WGF_DYING;
28012794
cred = sc->sc_ucred;
@@ -2804,8 +2797,9 @@ wg_clone_destroy(struct ifnet *ifp)
28042797
LIST_REMOVE(sc, sc_entry);
28052798
lockmgr(&wg_lock, LK_RELEASE);
28062799

2807-
if_link_state_change(sc->sc_ifp, LINK_STATE_DOWN);
2808-
if_purgeaddrs(sc->sc_ifp);
2800+
ifp->if_link_state = LINK_STATE_DOWN;
2801+
if_link_state_change(ifp);
2802+
if_purgeaddrs_nolink(ifp);
28092803

28102804
lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
28112805
wg_socket_uninit(sc);
@@ -2853,11 +2847,6 @@ wg_clone_destroy(struct ifnet *ifp)
28532847
return (0);
28542848
}
28552849

2856-
static void
2857-
wg_qflush(if_t ifp __unused)
2858-
{
2859-
}
2860-
28612850
/*
28622851
* Privileged information (private-key, preshared-key) are only exported for
28632852
* root by default.
@@ -2871,16 +2860,6 @@ wgc_privileged(struct wg_softc *sc)
28712860
return (priv_check(td, PRIV_NET_WG) == 0);
28722861
}
28732862

2874-
static void
2875-
wg_reassign(if_t ifp, struct vnet *new_vnet __unused,
2876-
char *unused __unused)
2877-
{
2878-
struct wg_softc *sc;
2879-
2880-
sc = if_getsoftc(ifp);
2881-
wg_down(sc);
2882-
}
2883-
28842863
static void
28852864
wg_init(void *xsc)
28862865
{

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/liweitianux/dragonflybsd/commit/430b012a0ccf836aed86b73e79f66c34f7d4863a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy