@@ -14,8 +14,7 @@ import (
1414 "github.com/anywherelan/awl/config"
1515 "github.com/anywherelan/awl/entity"
1616 "github.com/anywherelan/awl/vpn"
17- "github.com/anywherelan/awl/vpn/routes"
18- "github.com/anywherelan/awl/vpn/sockmark"
17+ "github.com/anywherelan/awl/vpn/netstate"
1918)
2019
2120// DNSReconfigurer is the narrow slice of the DNS service the gateway needs to
@@ -49,7 +48,7 @@ type VPNGateway struct {
4948 tunnel * Tunnel
5049 device * vpn.Device
5150 p2p P2p
52- sockMarker sockmark .Marker
51+ sockMarker netstate .Marker
5352 dns DNSReconfigurer
5453 logger * log.ZapEventLogger
5554
@@ -63,14 +62,14 @@ type VPNGateway struct {
6362 // paths. Connectivity to the bound gateway peer is observed via p2p
6463 // events inside Tunnel — no background goroutine here.
6564 mu sync.Mutex
66- clientRouteState * routes .RouteState
67- serverNATState * routes .NATState
65+ clientRouteState * netstate .RouteState
66+ serverNATState * netstate .NATState
6867}
6968
7069// NewVPNGateway constructs a VPNGateway service. tunnel may be nil when the
7170// VPN interface is disabled; the API methods still work but only update the
7271// persisted config.
73- func NewVPNGateway (conf * config.Config , tunnel * Tunnel , device * vpn.Device , p2p P2p , sockMarker sockmark .Marker , dns DNSReconfigurer , disableOSSetup bool ) * VPNGateway {
72+ func NewVPNGateway (conf * config.Config , tunnel * Tunnel , device * vpn.Device , p2p P2p , sockMarker netstate .Marker , dns DNSReconfigurer , disableOSSetup bool ) * VPNGateway {
7473 return & VPNGateway {
7574 conf : conf ,
7675 tunnel : tunnel ,
@@ -155,7 +154,7 @@ func (g *VPNGateway) ListAvailableVPNGateways() []entity.AvailableVPNGateway {
155154// gateway, applying OS-level routes immediately. Atomic: rolls back the
156155// tunnel binding on apply failure.
157156//
158- // On android the OS-level apply (routes .SetupGatewayRoutes / sockmark) is a
157+ // On android the OS-level apply (netstate .SetupGatewayRoutes / sockmark) is a
159158// no-op — routing is owned by the host's VpnService.Builder. This call flips
160159// the in-memory tunnel binding and persists config; the host then re-establishes
161160// the VpnService with the new routes and hot-swaps the fresh tun fd into the
@@ -298,7 +297,7 @@ func (g *VPNGateway) IsServerActive() bool {
298297// ClientRouteState returns the current route state pointer (or nil). For
299298// tests that need pointer-identity comparisons (idempotent re-enable must
300299// not reinstall routes).
301- func (g * VPNGateway ) ClientRouteState () * routes .RouteState {
300+ func (g * VPNGateway ) ClientRouteState () * netstate .RouteState {
302301 g .mu .Lock ()
303302 defer g .mu .Unlock ()
304303 return g .clientRouteState
@@ -323,7 +322,7 @@ func (g *VPNGateway) applyServer() error {
323322 if g .disableOSSetup {
324323 // Keep state tracking working (so teardown is symmetric) without
325324 // touching the kernel.
326- g .serverNATState = & routes .NATState {}
325+ g .serverNATState = & netstate .NATState {}
327326 return nil
328327 }
329328
@@ -334,7 +333,7 @@ func (g *VPNGateway) applyServer() error {
334333 localIP , netMask := g .conf .VPNLocalIPMask ()
335334 awlSubnet := (& net.IPNet {IP : localIP .Mask (netMask ), Mask : netMask }).String ()
336335
337- natState , err := routes .SetupNAT (awlSubnet , tunName )
336+ natState , err := netstate .SetupNAT (awlSubnet , tunName )
338337 if err != nil {
339338 return fmt .Errorf ("setup NAT: %w" , err )
340339 }
@@ -352,7 +351,7 @@ func (g *VPNGateway) teardownServer() {
352351 return
353352 }
354353 if ! g .disableOSSetup {
355- if err := routes .TeardownNAT (g .serverNATState ); err != nil {
354+ if err := netstate .TeardownNAT (g .serverNATState ); err != nil {
356355 g .logger .Errorf ("teardown NAT: %v" , err )
357356 }
358357 }
@@ -394,7 +393,7 @@ func (g *VPNGateway) applyClient() error {
394393 // the netstate manager in the next MR and flattens there.
395394 //nolint:nestif
396395 if g .disableOSSetup {
397- g .clientRouteState = & routes .RouteState {}
396+ g .clientRouteState = & netstate .RouteState {}
398397 } else {
399398 // Markers that can be temporarily unable to guarantee loop-free
400399 // marking (Windows: no uplink detected right now) expose Ready.
@@ -412,7 +411,7 @@ func (g *VPNGateway) applyClient() error {
412411 if err != nil {
413412 return fmt .Errorf ("get TUN name for gateway routes: %w" , err )
414413 }
415- routeState , err := routes .SetupGatewayRoutes (tunName , g .sockMarker .FWMark ())
414+ routeState , err := netstate .SetupGatewayRoutes (tunName , g .sockMarker .FWMark ())
416415 if err != nil {
417416 return fmt .Errorf ("setup gateway routes: %w" , err )
418417 }
@@ -446,7 +445,7 @@ func (g *VPNGateway) teardownClient() {
446445 return
447446 }
448447 if ! g .disableOSSetup {
449- if err := routes .TeardownGatewayRoutes (g .clientRouteState ); err != nil {
448+ if err := netstate .TeardownGatewayRoutes (g .clientRouteState ); err != nil {
450449 g .logger .Errorf ("teardown gateway routes: %v" , err )
451450 }
452451 }
0 commit comments