Skip to content

Commit

Permalink
intra/tunnel: m comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Sep 2, 2023
1 parent 3235af2 commit 2e38ed7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions intra/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ type Tunnel interface {
SetTunMode(dnsmode, blockmode, ptmode int)
// Get proxies.
GetProxies() ipn.Proxies
// Reset the tunnel with new tundevice, mtu, engine, pcap file.
// Reset(fd, mtu, engine int, pcap string) error
// Creates a new link for fd and mtu.
SetLink(fd, mtu int, pcap string) error
// Sets new default routes for the given engine.
SetRoute(engine int) error
// Reset the tunnel with new tundevice, mtu, engine, pcap file.
// Reset(fd, mtu, engine int, pcap string) error
}

type intratunnel struct {
Expand Down
19 changes: 10 additions & 9 deletions tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ const invalidfd = -1
var errStackMissing = errors.New("tun: netstack not initialized")

type gtunnel struct {
endpoint stack.LinkEndpoint
stack *stack.Stack
l3 string
hdl netstack.GConnHandler
fdref int
pcapio io.Closer
mtu int
endpoint stack.LinkEndpoint // wires up tun fd to netstack
stack *stack.Stack // a tcpip stack
hdl netstack.GConnHandler // tcp, udp, and icmp handlers
mtu int // mtu of the tun device
fdref int // the tun device
pcapio io.Closer // closes pcap output, if any
}

func (t *gtunnel) Mtu() int {
Expand Down Expand Up @@ -123,7 +122,9 @@ func (t *gtunnel) Write([]byte) (int, error) {

func NewGTunnel(fd, mtu int, fpcap, l3 string, tcph netstack.GTCPConnHandler, udph netstack.GUDPConnHandler, icmph netstack.GICMPHandler) (t Tunnel, err error) {
var endpoint stack.LinkEndpoint

hdl := netstack.NewGConnHandler(tcph, udph, icmph)

stack := netstack.NewNetstack(settings.IP46) // force dual stack
netstack.Route(stack, l3)

Expand All @@ -146,7 +147,7 @@ func NewGTunnel(fd, mtu int, fpcap, l3 string, tcph netstack.GTCPConnHandler, ud
}

log.I("tun: new netstack up; fd(%d), pcap(%t), l3(%v), mtu(%d)", fd, len(fpcap) > 0, l3, mtu)
return &gtunnel{endpoint, stack, l3, hdl, fd, pcapio, mtu}, nil
return &gtunnel{endpoint, stack, hdl, mtu, fd, pcapio}, nil
}

func (t *gtunnel) SetLink(fd, mtu int, fpcap string) error {
Expand Down Expand Up @@ -174,7 +175,7 @@ func (t *gtunnel) SetLink(fd, mtu int, fpcap string) error {
return err
}

log.I("tun: new link; fd(%d), pcap(%t), l3(%v), mtu(%d)", fd, len(fpcap) > 0, t.l3, mtu)
log.I("tun: new link; fd(%d), pcap(%t), mtu(%d)", fd, len(fpcap) > 0, mtu)
t.endpoint = ep
t.mtu = mtu
t.pcapio = pcapio
Expand Down

0 comments on commit 2e38ed7

Please sign in to comment.