Skip to content

Commit a6d4741

Browse files
committed
netstack: m Up and Rev handlers api change
1 parent 04fe473 commit a6d4741

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

intra/netstack/netstack.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"net/netip"
13+
"strconv"
1314

1415
"github.com/celzero/firestack/intra/core"
1516
"github.com/celzero/firestack/intra/log"
@@ -29,8 +30,9 @@ const nicfwd = false
2930
const mustAddIfAddrs = false
3031

3132
// ref: github.com/brewlin/net-protocol/blob/ec64e5f899/internal/endpoint/endpoint.go#L20
32-
func Up(who string, s *stack.Stack, ep stack.LinkEndpoint, h GConnHandler) (tcpip.NICID, error) {
33+
func Up(s *stack.Stack, ep SeamlessEndpoint, h GConnHandler) (tcpip.NICID, error) {
3334
nic := tcpip.NICID(settings.NICID)
35+
who := strconv.Itoa(ep.Stat().Fd)
3436

3537
// fetch existing routes before adding removing nic, which wipes out routes
3638
existingroutes := s.GetRouteTable()

intra/netstack/rev.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111
"net"
1212
"net/netip"
13+
"strconv"
1314
"sync/atomic"
1415

1516
"github.com/celzero/firestack/intra/core"
@@ -51,7 +52,8 @@ var _ GTCPConnHandler = (*revtcp)(nil)
5152
var _ GUDPConnHandler = (*revudp)(nil)
5253
var _ GICMPHandler = (*revicmp)(nil)
5354

54-
func NewReverseGConnHandler(id string, pctx context.Context, to *stack.Stack, of tcpip.NICID, ep stack.LinkEndpoint, via GConnHandler) *gconnhandler {
55+
func NewReverseGConnHandler(pctx context.Context, to *stack.Stack, of tcpip.NICID, ep SeamlessEndpoint, via GConnHandler) *gconnhandler {
56+
id := strconv.Itoa(ep.Stat().Fd)
5557
h := &gconnhandler{
5658
tcp: newReverseTCP(id, to, of, via.TCP()),
5759
udp: newReverseUDP(id, to, of, via.UDP()),

tunnel/tunnel.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"fmt"
3030
"os"
3131
"path/filepath"
32-
"strconv"
3332
"sync"
3433
"sync/atomic"
3534
"syscall"
@@ -182,21 +181,19 @@ func NewGTunnel(pctx context.Context, fd, mtu int, l3 string, hdl netstack.GConn
182181
return nil, nil, eerr
183182
}
184183

184+
var nic tcpip.NICID
185185
if l3 != settings.IP46 {
186+
l3 = settings.IP46 // always dual-stack
186187
log.W("tun: new netstack(%d) l3 is %s needed %s", fd, l3, settings.IP46)
187188
}
188189
netstack.Route(stack, l3)
189-
190-
who := strconv.Itoa(ep.Stat().Fd)
191-
192-
var nic tcpip.NICID
193190
// Enabled() may temporarily return false when Up() is in progress.
194-
if nic, err = netstack.Up(who, stack, ep, hdl); err != nil { // attach new endpoint
191+
if nic, err = netstack.Up(stack, ep, hdl); err != nil { // attach new endpoint
195192
done()
196193
return nil, nil, err
197194
}
198195

199-
rev = netstack.NewReverseGConnHandler(who, ctx, stack, nic, ep, hdl)
196+
rev = netstack.NewReverseGConnHandler(ctx, stack, nic, ep, hdl)
200197

201198
log.I("tun: new netstack(%d) up; fd(%d=>%d), mtu(%d)", nic, fd, myfd, mtu)
202199

0 commit comments

Comments
 (0)