35
35
#include <net/if_clone.h>
36
36
#include <net/if_types.h>
37
37
#include <net/if_var.h>
38
+ #include <net/ifq_var.h>
38
39
#include <net/netisr.h>
39
40
#include <net/radix.h>
40
41
#include <netinet/in.h>
65
66
#define NEW_HANDSHAKE_TIMEOUT (REKEY_TIMEOUT + KEEPALIVE_TIMEOUT)
66
67
#define UNDERLOAD_TIMEOUT 1
67
68
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__)
69
71
70
72
/* First byte indicating packet type on the wire */
71
73
#define WG_PKT_INITIATION htole32(1)
@@ -216,7 +218,7 @@ struct wg_socket {
216
218
217
219
struct wg_softc {
218
220
LIST_ENTRY (wg_softc ) sc_entry ;
219
- if_t sc_ifp ;
221
+ struct ifnet * sc_ifp ;
220
222
int sc_flags ;
221
223
222
224
struct ucred * sc_ucred ;
@@ -361,20 +363,18 @@ static struct wg_packet *wg_queue_dequeue_parallel(struct wg_queue *);
361
363
static bool wg_input (struct mbuf * , int , struct inpcb * , const struct sockaddr * , void * );
362
364
static void wg_peer_send_staged (struct wg_peer * );
363
365
static int wg_clone_create (struct if_clone * , int , caddr_t , caddr_t );
364
- static void wg_qflush (if_t );
365
366
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 * );
369
370
static int wg_clone_destroy (struct ifnet * ifp );
370
371
static bool wgc_privileged (struct wg_softc * );
371
372
static int wgc_get (struct wg_softc * , struct wg_data_io * );
372
373
static int wgc_set (struct wg_softc * , struct wg_data_io * );
373
374
static int wg_up (struct wg_softc * );
374
375
static void wg_down (struct wg_softc * );
375
- static void wg_reassign (if_t , struct vnet * , char * unused );
376
376
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 );
378
378
static int wg_module_init (void );
379
379
static int wg_module_deinit (void );
380
380
@@ -1659,7 +1659,7 @@ static void
1659
1659
wg_deliver_in (struct wg_peer * peer )
1660
1660
{
1661
1661
struct wg_softc * sc = peer -> p_sc ;
1662
- if_t ifp = sc -> sc_ifp ;
1662
+ struct ifnet * ifp = sc -> sc_ifp ;
1663
1663
struct wg_packet * pkt ;
1664
1664
struct mbuf * m ;
1665
1665
struct epoch_tracker et ;
@@ -2030,7 +2030,7 @@ wg_peer_send_staged(struct wg_peer *peer)
2030
2030
}
2031
2031
2032
2032
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 )
2034
2034
{
2035
2035
IFNET_STAT_INC (ifp , oerrors , 1 );
2036
2036
switch (af ) {
@@ -2058,20 +2058,14 @@ xmit_err(if_t ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af)
2058
2058
}
2059
2059
2060
2060
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 )
2062
2062
{
2063
2063
struct wg_packet * pkt = NULL ;
2064
- struct wg_softc * sc = if_getsoftc ( ifp ) ;
2064
+ struct wg_softc * sc = ifp -> if_softc ;
2065
2065
struct wg_peer * peer ;
2066
2066
int rc = 0 ;
2067
2067
sa_family_t peer_af ;
2068
2068
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
-
2075
2069
if ((pkt = wg_packet_alloc (m )) == NULL ) {
2076
2070
rc = ENOBUFS ;
2077
2071
goto err_xmit ;
@@ -2144,7 +2138,7 @@ determine_af_and_pullup(struct mbuf **m, sa_family_t *af)
2144
2138
}
2145
2139
2146
2140
static int
2147
- wg_transmit (if_t ifp , struct mbuf * m )
2141
+ wg_transmit (struct ifnet * ifp , struct mbuf * m )
2148
2142
{
2149
2143
sa_family_t af ;
2150
2144
int ret ;
@@ -2164,11 +2158,11 @@ wg_transmit(if_t ifp, struct mbuf *m)
2164
2158
xmit_err (ifp , m , NULL , AF_UNSPEC );
2165
2159
return (ret );
2166
2160
}
2167
- return (wg_xmit (ifp , m , af , if_getmtu ( ifp ) ));
2161
+ return (wg_xmit (ifp , m , af , ifp -> if_mtu ));
2168
2162
}
2169
2163
2170
2164
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 )
2172
2166
{
2173
2167
sa_family_t parsed_af ;
2174
2168
uint32_t af , mtu ;
@@ -2202,7 +2196,7 @@ wg_output(if_t ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro
2202
2196
xmit_err (ifp , m , NULL , AF_UNSPEC );
2203
2197
return (EAFNOSUPPORT );
2204
2198
}
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 ;
2206
2200
return (wg_xmit (ifp , m , parsed_af , mtu ));
2207
2201
}
2208
2202
@@ -2312,7 +2306,7 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl)
2312
2306
goto out ;
2313
2307
TAILQ_INSERT_TAIL (& sc -> sc_peers , peer , p_entry );
2314
2308
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 )
2316
2310
wg_timers_enable (peer );
2317
2311
}
2318
2312
if (remote != NULL )
@@ -2330,7 +2324,7 @@ static int
2330
2324
wgc_set (struct wg_softc * sc , struct wg_data_io * wgd )
2331
2325
{
2332
2326
uint8_t public [WG_KEY_SIZE ], private [WG_KEY_SIZE ];
2333
- if_t ifp ;
2327
+ struct ifnet * ifp ;
2334
2328
void * nvlpacked ;
2335
2329
nvlist_t * nvl ;
2336
2330
ssize_t size ;
@@ -2366,7 +2360,7 @@ wgc_set(struct wg_softc *sc, struct wg_data_io *wgd)
2366
2360
goto out_locked ;
2367
2361
}
2368
2362
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 ) {
2370
2364
if ((err = wg_socket_init (sc , new_port )) != 0 )
2371
2365
goto out_locked ;
2372
2366
} else
@@ -2574,15 +2568,15 @@ wgc_get(struct wg_softc *sc, struct wg_data_io *wgd)
2574
2568
}
2575
2569
2576
2570
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 )
2578
2572
{
2579
2573
struct wg_data_io * wgd = (struct wg_data_io * )data ;
2580
2574
struct ifreq * ifr = (struct ifreq * )data ;
2581
2575
struct wg_softc * sc ;
2582
2576
int ret = 0 ;
2583
2577
2584
2578
lockmgr (& wg_lock , LK_SHARED );
2585
- sc = if_getsoftc ( ifp ) ;
2579
+ sc = ifp -> if_softc ;
2586
2580
if (!sc ) {
2587
2581
ret = ENXIO ;
2588
2582
goto out ;
@@ -2605,7 +2599,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2605
2599
*/
2606
2600
break ;
2607
2601
case SIOCSIFFLAGS :
2608
- if (if_getflags ( ifp ) & IFF_UP )
2602
+ if (ifp -> if_flags & IFF_UP )
2609
2603
ret = wg_up (sc );
2610
2604
else
2611
2605
wg_down (sc );
@@ -2614,7 +2608,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2614
2608
if (ifr -> ifr_mtu <= 0 || ifr -> ifr_mtu > MAX_MTU )
2615
2609
ret = EINVAL ;
2616
2610
else
2617
- if_setmtu ( ifp , ifr -> ifr_mtu ) ;
2611
+ ifp -> if_mtu = ifr -> ifr_mtu ;
2618
2612
break ;
2619
2613
case SIOCADDMULTI :
2620
2614
case SIOCDELMULTI :
@@ -2631,7 +2625,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2631
2625
static int
2632
2626
wg_up (struct wg_softc * sc )
2633
2627
{
2634
- if_t ifp = sc -> sc_ifp ;
2628
+ struct ifnet * ifp = sc -> sc_ifp ;
2635
2629
struct wg_peer * peer ;
2636
2630
int rc = EBUSY ;
2637
2631
@@ -2643,17 +2637,18 @@ wg_up(struct wg_softc *sc)
2643
2637
2644
2638
/* Silent success if we're already running. */
2645
2639
rc = 0 ;
2646
- if (if_getdrvflags ( ifp ) & IFF_DRV_RUNNING )
2640
+ if (ifp -> if_flags & IFF_RUNNING )
2647
2641
goto out ;
2648
- if_setdrvflagbits ( ifp , IFF_DRV_RUNNING , 0 ) ;
2642
+ ifp -> if_flags |= IFF_RUNNING ;
2649
2643
2650
2644
rc = wg_socket_init (sc , sc -> sc_socket .so_port );
2651
2645
if (rc == 0 ) {
2652
2646
TAILQ_FOREACH (peer , & sc -> sc_peers , p_entry )
2653
2647
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 );
2655
2650
} else {
2656
- if_setdrvflagbits ( ifp , 0 , IFF_DRV_RUNNING ) ;
2651
+ ifp -> if_flags &= ~ IFF_RUNNING ;
2657
2652
DPRINTF (sc , "Unable to initialize sockets: %d\n" , rc );
2658
2653
}
2659
2654
out :
@@ -2664,15 +2659,15 @@ wg_up(struct wg_softc *sc)
2664
2659
static void
2665
2660
wg_down (struct wg_softc * sc )
2666
2661
{
2667
- if_t ifp = sc -> sc_ifp ;
2662
+ struct ifnet * ifp = sc -> sc_ifp ;
2668
2663
struct wg_peer * peer ;
2669
2664
2670
2665
lockmgr (& sc -> sc_lock , LK_EXCLUSIVE );
2671
- if (!( if_getdrvflags ( ifp ) & IFF_DRV_RUNNING ) ) {
2666
+ if (( ifp -> if_flags & IFF_RUNNING ) == 0 ) {
2672
2667
lockmgr (& sc -> sc_lock , LK_RELEASE );
2673
2668
return ;
2674
2669
}
2675
- if_setdrvflagbits ( ifp , 0 , IFF_DRV_RUNNING ) ;
2670
+ ifp -> if_flags &= ~ IFF_RUNNING ;
2676
2671
2677
2672
TAILQ_FOREACH (peer , & sc -> sc_peers , p_entry ) {
2678
2673
wg_queue_purge (& peer -> p_stage_queue );
@@ -2686,7 +2681,8 @@ wg_down(struct wg_softc *sc)
2686
2681
noise_remote_keypairs_clear (peer -> p_remote );
2687
2682
}
2688
2683
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 );
2690
2686
wg_socket_uninit (sc );
2691
2687
2692
2688
lockmgr (& sc -> sc_lock , LK_RELEASE );
@@ -2745,25 +2741,22 @@ wg_clone_create(struct if_clone *ifc __unused, int unit,
2745
2741
2746
2742
lockinit (& sc -> sc_lock , "wg softc lock" , 0 , 0 );
2747
2743
2748
- if_setsoftc (ifp , sc );
2749
- if_setcapabilities (ifp , WG_CAPS );
2750
- if_setcapenable (ifp , WG_CAPS );
2751
2744
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 );
2762
2758
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
+
2767
2760
lockmgr (& wg_lock , LK_EXCLUSIVE );
2768
2761
LIST_INSERT_HEAD (& wg_list , sc , sc_entry );
2769
2762
lockmgr (& wg_lock , LK_RELEASE );
@@ -2791,11 +2784,11 @@ wg_clone_deferred_free(struct noise_local *l)
2791
2784
static int
2792
2785
wg_clone_destroy (struct ifnet * ifp )
2793
2786
{
2794
- struct wg_softc * sc = if_getsoftc ( ifp ) ;
2787
+ struct wg_softc * sc = ifp -> if_softc ;
2795
2788
struct ucred * cred ;
2796
2789
2797
2790
lockmgr (& wg_lock , LK_EXCLUSIVE );
2798
- if_setsoftc ( ifp , NULL ) ;
2791
+ ifp -> if_softc = NULL ;
2799
2792
lockmgr (& sc -> sc_lock , LK_EXCLUSIVE );
2800
2793
sc -> sc_flags |= WGF_DYING ;
2801
2794
cred = sc -> sc_ucred ;
@@ -2804,8 +2797,9 @@ wg_clone_destroy(struct ifnet *ifp)
2804
2797
LIST_REMOVE (sc , sc_entry );
2805
2798
lockmgr (& wg_lock , LK_RELEASE );
2806
2799
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 );
2809
2803
2810
2804
lockmgr (& sc -> sc_lock , LK_EXCLUSIVE );
2811
2805
wg_socket_uninit (sc );
@@ -2853,11 +2847,6 @@ wg_clone_destroy(struct ifnet *ifp)
2853
2847
return (0 );
2854
2848
}
2855
2849
2856
- static void
2857
- wg_qflush (if_t ifp __unused )
2858
- {
2859
- }
2860
-
2861
2850
/*
2862
2851
* Privileged information (private-key, preshared-key) are only exported for
2863
2852
* root by default.
@@ -2871,16 +2860,6 @@ wgc_privileged(struct wg_softc *sc)
2871
2860
return (priv_check (td , PRIV_NET_WG ) == 0 );
2872
2861
}
2873
2862
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
-
2884
2863
static void
2885
2864
wg_init (void * xsc )
2886
2865
{
0 commit comments