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) \
71
+ if_printf(sc->sc_ifp, ##__VA_ARGS__)
69
72
70
73
/* First byte indicating packet type on the wire */
71
74
#define WG_PKT_INITIATION htole32(1)
@@ -216,7 +219,7 @@ struct wg_socket {
216
219
217
220
struct wg_softc {
218
221
LIST_ENTRY (wg_softc ) sc_entry ;
219
- if_t sc_ifp ;
222
+ struct ifnet * sc_ifp ;
220
223
int sc_flags ;
221
224
222
225
struct ucred * sc_ucred ;
@@ -363,19 +366,17 @@ static struct wg_packet *wg_queue_dequeue_serial(struct wg_queue *);
363
366
static struct wg_packet * wg_queue_dequeue_parallel (struct wg_queue * );
364
367
static bool wg_input (struct mbuf * , int , struct inpcb * , const struct sockaddr * , void * );
365
368
static void wg_peer_send_staged (struct wg_peer * );
366
- static void wg_qflush (if_t );
367
369
static inline int determine_af_and_pullup (struct mbuf * * m , sa_family_t * af );
368
- static int wg_xmit (if_t , struct mbuf * , sa_family_t , uint32_t );
369
- static int wg_transmit (if_t , struct mbuf * );
370
- static int wg_output (if_t , struct mbuf * , const struct sockaddr * , struct route * );
370
+ static int wg_xmit (struct ifnet * , struct mbuf * , sa_family_t , uint32_t );
371
+ static int wg_transmit (struct ifnet * , struct mbuf * );
372
+ static int wg_output (struct ifnet * , struct mbuf * , const struct sockaddr * , struct rtentry * );
371
373
static bool wgc_privileged (struct wg_softc * );
372
374
static int wgc_get (struct wg_softc * , struct wg_data_io * );
373
375
static int wgc_set (struct wg_softc * , struct wg_data_io * );
374
376
static int wg_up (struct wg_softc * );
375
377
static void wg_down (struct wg_softc * );
376
- static void wg_reassign (if_t , struct vnet * , char * unused );
377
378
static void wg_init (void * );
378
- static int wg_ioctl (if_t , u_long , caddr_t );
379
+ static int wg_ioctl (struct ifnet * , u_long , caddr_t );
379
380
static int wg_module_init (void );
380
381
static int wg_module_deinit (void );
381
382
@@ -1660,7 +1661,7 @@ static void
1660
1661
wg_deliver_in (struct wg_peer * peer )
1661
1662
{
1662
1663
struct wg_softc * sc = peer -> p_sc ;
1663
- if_t ifp = sc -> sc_ifp ;
1664
+ struct ifnet * ifp = sc -> sc_ifp ;
1664
1665
struct wg_packet * pkt ;
1665
1666
struct mbuf * m ;
1666
1667
struct epoch_tracker et ;
@@ -2031,7 +2032,7 @@ wg_peer_send_staged(struct wg_peer *peer)
2031
2032
}
2032
2033
2033
2034
static inline void
2034
- xmit_err (if_t ifp , struct mbuf * m , struct wg_packet * pkt , sa_family_t af )
2035
+ xmit_err (struct ifnet * ifp , struct mbuf * m , struct wg_packet * pkt , sa_family_t af )
2035
2036
{
2036
2037
IFNET_STAT_INC (ifp , oerrors , 1 );
2037
2038
switch (af ) {
@@ -2059,20 +2060,14 @@ xmit_err(if_t ifp, struct mbuf *m, struct wg_packet *pkt, sa_family_t af)
2059
2060
}
2060
2061
2061
2062
static int
2062
- wg_xmit (if_t ifp , struct mbuf * m , sa_family_t af , uint32_t mtu )
2063
+ wg_xmit (struct ifnet * ifp , struct mbuf * m , sa_family_t af , uint32_t mtu )
2063
2064
{
2064
2065
struct wg_packet * pkt = NULL ;
2065
- struct wg_softc * sc = if_getsoftc ( ifp ) ;
2066
+ struct wg_softc * sc = ifp -> if_softc ;
2066
2067
struct wg_peer * peer ;
2067
2068
int rc = 0 ;
2068
2069
sa_family_t peer_af ;
2069
2070
2070
- /* Work around lifetime issue in the ipv6 mld code. */
2071
- if (__predict_false ((if_getflags (ifp ) & IFF_DYING ) || !sc )) {
2072
- rc = ENXIO ;
2073
- goto err_xmit ;
2074
- }
2075
-
2076
2071
if ((pkt = wg_packet_alloc (m )) == NULL ) {
2077
2072
rc = ENOBUFS ;
2078
2073
goto err_xmit ;
@@ -2145,7 +2140,7 @@ determine_af_and_pullup(struct mbuf **m, sa_family_t *af)
2145
2140
}
2146
2141
2147
2142
static int
2148
- wg_transmit (if_t ifp , struct mbuf * m )
2143
+ wg_transmit (struct ifnet * ifp , struct mbuf * m )
2149
2144
{
2150
2145
sa_family_t af ;
2151
2146
int ret ;
@@ -2165,11 +2160,11 @@ wg_transmit(if_t ifp, struct mbuf *m)
2165
2160
xmit_err (ifp , m , NULL , AF_UNSPEC );
2166
2161
return (ret );
2167
2162
}
2168
- return (wg_xmit (ifp , m , af , if_getmtu ( ifp ) ));
2163
+ return (wg_xmit (ifp , m , af , ifp -> if_mtu ));
2169
2164
}
2170
2165
2171
2166
static int
2172
- wg_output (if_t ifp , struct mbuf * m , const struct sockaddr * dst , struct route * ro )
2167
+ wg_output (struct ifnet * ifp , struct mbuf * m , const struct sockaddr * dst , struct rtentry * rt )
2173
2168
{
2174
2169
sa_family_t parsed_af ;
2175
2170
uint32_t af , mtu ;
@@ -2203,7 +2198,7 @@ wg_output(if_t ifp, struct mbuf *m, const struct sockaddr *dst, struct route *ro
2203
2198
xmit_err (ifp , m , NULL , AF_UNSPEC );
2204
2199
return (EAFNOSUPPORT );
2205
2200
}
2206
- mtu = (ro != NULL && ro -> ro_mtu > 0 ) ? ro -> ro_mtu : if_getmtu ( ifp ) ;
2201
+ mtu = (ro != NULL && ro -> ro_mtu > 0 ) ? ro -> ro_mtu : ifp -> if_mtu ;
2207
2202
return (wg_xmit (ifp , m , parsed_af , mtu ));
2208
2203
}
2209
2204
@@ -2313,7 +2308,7 @@ wg_peer_add(struct wg_softc *sc, const nvlist_t *nvl)
2313
2308
goto out ;
2314
2309
TAILQ_INSERT_TAIL (& sc -> sc_peers , peer , p_entry );
2315
2310
sc -> sc_peers_num ++ ;
2316
- if (if_getlinkstate ( sc -> sc_ifp ) == LINK_STATE_UP )
2311
+ if (sc -> sc_ifp -> if_link_state == LINK_STATE_UP )
2317
2312
wg_timers_enable (peer );
2318
2313
}
2319
2314
if (remote != NULL )
@@ -2331,7 +2326,7 @@ static int
2331
2326
wgc_set (struct wg_softc * sc , struct wg_data_io * wgd )
2332
2327
{
2333
2328
uint8_t public [WG_KEY_SIZE ], private [WG_KEY_SIZE ];
2334
- if_t ifp ;
2329
+ struct ifnet * ifp ;
2335
2330
void * nvlpacked ;
2336
2331
nvlist_t * nvl ;
2337
2332
ssize_t size ;
@@ -2367,7 +2362,7 @@ wgc_set(struct wg_softc *sc, struct wg_data_io *wgd)
2367
2362
goto out_locked ;
2368
2363
}
2369
2364
if (new_port != sc -> sc_socket .so_port ) {
2370
- if ((if_getdrvflags ( ifp ) & IFF_DRV_RUNNING ) != 0 ) {
2365
+ if ((ifp -> if_flags & IFF_RUNNING ) != 0 ) {
2371
2366
if ((err = wg_socket_init (sc , new_port )) != 0 )
2372
2367
goto out_locked ;
2373
2368
} else
@@ -2575,15 +2570,15 @@ wgc_get(struct wg_softc *sc, struct wg_data_io *wgd)
2575
2570
}
2576
2571
2577
2572
static int
2578
- wg_ioctl (if_t ifp , u_long cmd , caddr_t data )
2573
+ wg_ioctl (struct ifnet * ifp , u_long cmd , caddr_t data )
2579
2574
{
2580
2575
struct wg_data_io * wgd = (struct wg_data_io * )data ;
2581
2576
struct ifreq * ifr = (struct ifreq * )data ;
2582
2577
struct wg_softc * sc ;
2583
2578
int ret = 0 ;
2584
2579
2585
2580
lockmgr (& wg_lock , LK_SHARED );
2586
- sc = if_getsoftc ( ifp ) ;
2581
+ sc = ifp -> if_softc ;
2587
2582
if (!sc ) {
2588
2583
ret = ENXIO ;
2589
2584
goto out ;
@@ -2606,7 +2601,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2606
2601
*/
2607
2602
break ;
2608
2603
case SIOCSIFFLAGS :
2609
- if (if_getflags ( ifp ) & IFF_UP )
2604
+ if (ifp -> if_flags & IFF_UP )
2610
2605
ret = wg_up (sc );
2611
2606
else
2612
2607
wg_down (sc );
@@ -2615,7 +2610,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2615
2610
if (ifr -> ifr_mtu <= 0 || ifr -> ifr_mtu > MAX_MTU )
2616
2611
ret = EINVAL ;
2617
2612
else
2618
- if_setmtu ( ifp , ifr -> ifr_mtu ) ;
2613
+ ifp -> if_mtu = ifr -> ifr_mtu ;
2619
2614
break ;
2620
2615
case SIOCADDMULTI :
2621
2616
case SIOCDELMULTI :
@@ -2632,7 +2627,7 @@ wg_ioctl(if_t ifp, u_long cmd, caddr_t data)
2632
2627
static int
2633
2628
wg_up (struct wg_softc * sc )
2634
2629
{
2635
- if_t ifp = sc -> sc_ifp ;
2630
+ struct ifnet * ifp = sc -> sc_ifp ;
2636
2631
struct wg_peer * peer ;
2637
2632
int rc = EBUSY ;
2638
2633
@@ -2644,17 +2639,18 @@ wg_up(struct wg_softc *sc)
2644
2639
2645
2640
/* Silent success if we're already running. */
2646
2641
rc = 0 ;
2647
- if (if_getdrvflags ( ifp ) & IFF_DRV_RUNNING )
2642
+ if (ifp -> if_flags & IFF_RUNNING )
2648
2643
goto out ;
2649
- if_setdrvflagbits ( ifp , IFF_DRV_RUNNING , 0 ) ;
2644
+ ifp -> if_flags |= IFF_RUNNING ;
2650
2645
2651
2646
rc = wg_socket_init (sc , sc -> sc_socket .so_port );
2652
2647
if (rc == 0 ) {
2653
2648
TAILQ_FOREACH (peer , & sc -> sc_peers , p_entry )
2654
2649
wg_timers_enable (peer );
2655
- if_link_state_change (sc -> sc_ifp , LINK_STATE_UP );
2650
+ ifp -> if_link_state = LINK_STATE_UP ;
2651
+ if_link_state_change (ifp );
2656
2652
} else {
2657
- if_setdrvflagbits ( ifp , 0 , IFF_DRV_RUNNING ) ;
2653
+ ifp -> if_flags &= ~ IFF_RUNNING ;
2658
2654
DPRINTF (sc , "Unable to initialize sockets: %d\n" , rc );
2659
2655
}
2660
2656
out :
@@ -2665,15 +2661,15 @@ wg_up(struct wg_softc *sc)
2665
2661
static void
2666
2662
wg_down (struct wg_softc * sc )
2667
2663
{
2668
- if_t ifp = sc -> sc_ifp ;
2664
+ struct ifnet * ifp = sc -> sc_ifp ;
2669
2665
struct wg_peer * peer ;
2670
2666
2671
2667
lockmgr (& sc -> sc_lock , LK_EXCLUSIVE );
2672
- if (!( if_getdrvflags ( ifp ) & IFF_DRV_RUNNING ) ) {
2668
+ if (( ifp -> if_flags & IFF_RUNNING ) == 0 ) {
2673
2669
lockmgr (& sc -> sc_lock , LK_RELEASE );
2674
2670
return ;
2675
2671
}
2676
- if_setdrvflagbits ( ifp , 0 , IFF_DRV_RUNNING ) ;
2672
+ ifp -> if_flags &= ~ IFF_RUNNING ;
2677
2673
2678
2674
TAILQ_FOREACH (peer , & sc -> sc_peers , p_entry ) {
2679
2675
wg_queue_purge (& peer -> p_stage_queue );
@@ -2687,7 +2683,8 @@ wg_down(struct wg_softc *sc)
2687
2683
noise_remote_keypairs_clear (peer -> p_remote );
2688
2684
}
2689
2685
2690
- if_link_state_change (sc -> sc_ifp , LINK_STATE_DOWN );
2686
+ ifp -> if_link_state = LINK_STATE_DOWN ;
2687
+ if_link_state_change (ifp );
2691
2688
wg_socket_uninit (sc );
2692
2689
2693
2690
lockmgr (& sc -> sc_lock , LK_RELEASE );
@@ -2746,25 +2743,22 @@ wg_clone_create(struct if_clone *ifc __unused, int unit,
2746
2743
2747
2744
lockinit (& sc -> sc_lock , "wg softc lock" , 0 , 0 );
2748
2745
2749
- if_setsoftc (ifp , sc );
2750
- if_setcapabilities (ifp , WG_CAPS );
2751
- if_setcapenable (ifp , WG_CAPS );
2752
2746
if_initname (ifp , wgname , unit );
2753
-
2754
- if_setmtu (ifp , DEFAULT_MTU );
2755
- if_setflags (ifp , IFF_NOARP | IFF_MULTICAST );
2756
- if_setinitfn (ifp , wg_init );
2757
- if_setreassignfn (ifp , wg_reassign );
2758
- if_setqflushfn (ifp , wg_qflush );
2759
- if_settransmitfn (ifp , wg_transmit );
2760
- if_setoutputfn (ifp , wg_output );
2761
- if_setioctlfn (ifp , wg_ioctl );
2762
- if_attach (ifp );
2747
+ ifp -> if_softc = sc ;
2748
+ ifp -> if_capabilities = WG_CAPS ;
2749
+ ifp -> if_capenable = WG_CAPS ;
2750
+ ifp -> if_mtu = DEFAULT_MTU ;
2751
+ ifp -> if_flags = IFF_NOARP | IFF_MULTICAST ;
2752
+ ifp -> if_init = wg_init ;
2753
+ ifp -> if_output = wg_output ;
2754
+ ifp -> if_start = wg_start ; /* TODO(ALY) */
2755
+ ifp -> if_ioctl = wg_ioctl ;
2756
+ ifq_set_maxlen (& ifp -> if_snd , ifqmaxlen );
2757
+ ifq_set_ready (& ifp -> if_snd );
2758
+
2759
+ if_attach (ifp , NULL );
2763
2760
bpfattach (ifp , DLT_NULL , sizeof (uint32_t ));
2764
- #ifdef INET6
2765
- ND_IFINFO (ifp )-> flags &= ~ND6_IFF_AUTO_LINKLOCAL ;
2766
- ND_IFINFO (ifp )-> flags |= ND6_IFF_NO_DAD ;
2767
- #endif
2761
+
2768
2762
lockmgr (& wg_lock , LK_EXCLUSIVE );
2769
2763
LIST_INSERT_HEAD (& wg_list , sc , sc_entry );
2770
2764
lockmgr (& wg_lock , LK_RELEASE );
@@ -2792,11 +2786,11 @@ wg_clone_deferred_free(struct noise_local *l)
2792
2786
static int
2793
2787
wg_clone_destroy (struct ifnet * ifp )
2794
2788
{
2795
- struct wg_softc * sc = if_getsoftc ( ifp ) ;
2789
+ struct wg_softc * sc = ifp -> if_softc ;
2796
2790
struct ucred * cred ;
2797
2791
2798
2792
lockmgr (& wg_lock , LK_EXCLUSIVE );
2799
- if_setsoftc ( ifp , NULL ) ;
2793
+ ifp -> if_softc = NULL ;
2800
2794
lockmgr (& sc -> sc_lock , LK_EXCLUSIVE );
2801
2795
sc -> sc_flags |= WGF_DYING ;
2802
2796
cred = sc -> sc_ucred ;
@@ -2805,8 +2799,9 @@ wg_clone_destroy(struct ifnet *ifp)
2805
2799
LIST_REMOVE (sc , sc_entry );
2806
2800
lockmgr (& wg_lock , LK_RELEASE );
2807
2801
2808
- if_link_state_change (sc -> sc_ifp , LINK_STATE_DOWN );
2809
- if_purgeaddrs (sc -> sc_ifp );
2802
+ ifp -> if_link_state = LINK_STATE_DOWN ;
2803
+ if_link_state_change (ifp );
2804
+ if_purgeaddrs_nolink (ifp );
2810
2805
2811
2806
lockmgr (& sc -> sc_lock , LK_EXCLUSIVE );
2812
2807
wg_socket_uninit (sc );
@@ -2854,11 +2849,6 @@ wg_clone_destroy(struct ifnet *ifp)
2854
2849
return (0 );
2855
2850
}
2856
2851
2857
- static void
2858
- wg_qflush (if_t ifp __unused )
2859
- {
2860
- }
2861
-
2862
2852
/*
2863
2853
* Privileged information (private-key, preshared-key) are only exported for
2864
2854
* root by default.
@@ -2872,16 +2862,6 @@ wgc_privileged(struct wg_softc *sc)
2872
2862
return (priv_check (td , PRIV_NET_WG ) == 0 );
2873
2863
}
2874
2864
2875
- static void
2876
- wg_reassign (if_t ifp , struct vnet * new_vnet __unused ,
2877
- char * unused __unused )
2878
- {
2879
- struct wg_softc * sc ;
2880
-
2881
- sc = if_getsoftc (ifp );
2882
- wg_down (sc );
2883
- }
2884
-
2885
2865
static void
2886
2866
wg_init (void * xsc )
2887
2867
{
0 commit comments