diff --git a/connection.go b/connection.go index f3654e4d..27f5621d 100644 --- a/connection.go +++ b/connection.go @@ -63,7 +63,7 @@ func NewLocalConnection(connRemote *RemoteConnection, expectedName PeerName, tcp Router: router, TCPConn: tcpConn, remoteUDPAddr: udpAddr, - clientPMTU: DefaultPMTU, + effectivePMTU: DefaultPMTU, queryChan: queryChan} go connLocal.queryLoop(queryChan, expectedName) } @@ -96,24 +96,24 @@ func (conn *LocalConnection) CheckFatal(err error) error { // Called by forwarder processes, read in Forward (by sniffer and udp // listener process in router). -func (conn *LocalConnection) setClientPMTU(pmtu int) { +func (conn *LocalConnection) setEffectivePMTU(pmtu int) { conn.Lock() defer conn.Unlock() - conn.clientPMTU = pmtu + conn.effectivePMTU = pmtu conn.pmtuVerified = false conn.log("Client PMTU set to", pmtu) } -func (conn *LocalConnection) clientPMTUVerification(pmtu int) { +func (conn *LocalConnection) effectivePMTUVerification(pmtu int) { conn.Lock() defer conn.Unlock() - if pmtu == conn.clientPMTU && !conn.pmtuVerified { - conn.log("Client PMTU verified at", pmtu) + if pmtu == conn.effectivePMTU && !conn.pmtuVerified { + conn.log("Effecive PMTU verified at", pmtu) conn.pmtuVerified = true } } -func (conn *LocalConnection) isClientPMTUVerfied() bool { +func (conn *LocalConnection) isEffectivePMTUVerfied() bool { conn.RLock() defer conn.RUnlock() return conn.pmtuVerified @@ -506,7 +506,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool } conn.local.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate)) } else if msg[0] == ProtocolPMTUVerified { - conn.clientPMTUVerification(int(binary.BigEndian.Uint16(msg[1:]))) + conn.effectivePMTUVerification(int(binary.BigEndian.Uint16(msg[1:]))) } else { conn.log("received unknown msg:\n", msg) } diff --git a/ethernet_decoder.go b/ethernet_decoder.go index aae4a358..92be8728 100644 --- a/ethernet_decoder.go +++ b/ethernet_decoder.go @@ -21,11 +21,11 @@ func (dec *EthernetDecoder) DecodeLayers(data []byte) error { func (dec *EthernetDecoder) CheckFrameTooBig(err error, sendFrame func([]byte) error) error { if ftbe, ok := err.(FrameTooBigError); ok { // we know: 1. ip is valid, 2. it was ip and DF was set - icmpFrame, err := dec.formICMPMTUPacket(ftbe.PMTU) + icmpFrame, err := dec.formICMPMTUPacket(ftbe.EPMTU) if err != nil { return err } - log.Printf("Sending ICMP 3,4 (%v -> %v): PMTU= %v\n", dec.ip.DstIP, dec.ip.SrcIP, ftbe.PMTU) + log.Printf("Sending ICMP 3,4 (%v -> %v): PMTU= %v\n", dec.ip.DstIP, dec.ip.SrcIP, ftbe.EPMTU) return sendFrame(icmpFrame) } else { return err diff --git a/forwarder.go b/forwarder.go index 00442dc1..73899a84 100644 --- a/forwarder.go +++ b/forwarder.go @@ -44,7 +44,7 @@ func (conn *LocalConnection) ensureForwarders() error { conn.stopForwardDF = stopForwardDF conn.Unlock() go conn.forwarderLoop(forwardChan, stopForward, encryptor, udpSender, DefaultPMTU) - go conn.forwarderLoop(forwardChanDF, stopForwardDF, encryptorDF, udpSenderDF, conn.clientPMTU) + go conn.forwarderLoop(forwardChanDF, stopForwardDF, encryptorDF, udpSenderDF, conn.effectivePMTU) return nil } @@ -68,26 +68,26 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto // The pmtu governs the max size of msg we can pass to the // udpSender. udpSender will add in the UDP/IP headers var pmtuVerifyTick <-chan time.Time - var clientPMTU int + var effectivePMTU int maxPayload := pmtu - UDPOverhead - calculateClientPMTU := func(mtbe MsgTooBigError) { + calculateEffectivePMTU := func(mtbe MsgTooBigError) { maxPayload = mtbe.PMTU - UDPOverhead - clientPMTU = maxPayload - enc.PacketOverhead() - enc.FrameOverhead() - EthernetOverhead + effectivePMTU = maxPayload - enc.PacketOverhead() - enc.FrameOverhead() - EthernetOverhead } - updateClientPMTU := func() { + updateEffectivePMTU := func() { for gotNewPMTU := true; gotNewPMTU; { - conn.setClientPMTU(clientPMTU) + conn.setEffectivePMTU(effectivePMTU) pmtuVerifyFrame := &ForwardedFrame{ srcPeer: conn.local, dstPeer: conn.remote, - frame: make([]byte, clientPMTU+EthernetOverhead)} + frame: make([]byte, effectivePMTU+EthernetOverhead)} gotNewPMTU = false for cnt := 0; cnt < 10; cnt += 1 { enc.AppendFrame(pmtuVerifyFrame) err := udpSender.Send(enc.Bytes()) if err != nil { if mtbe, ok := err.(MsgTooBigError); ok { - calculateClientPMTU(mtbe) + calculateEffectivePMTU(mtbe) gotNewPMTU = true break } @@ -108,8 +108,8 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto err := udpSender.Send(enc.Bytes()) if err != nil { if mtbe, ok := err.(MsgTooBigError); ok { - calculateClientPMTU(mtbe) - updateClientPMTU() + calculateEffectivePMTU(mtbe) + updateEffectivePMTU() } else if PosixError(err) == syscall.ENOBUFS { // TODO handle this better } else { @@ -145,10 +145,10 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto // all empty so that we don't risk appending verify-frames // to other data. pmtuVerifyTick = nil - if !conn.isClientPMTUVerfied() { - clientPMTU -= 8 + if !conn.isEffectivePMTUVerfied() { + effectivePMTU -= 8 maxPayload -= 8 - updateClientPMTU() + updateEffectivePMTU() } case frame = <-forwardCh: if !appendFrame(frame) { @@ -186,7 +186,7 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern var ( forwardChan = conn.forwardChan forwardChanDF = conn.forwardChanDF - clientPMTU = conn.clientPMTU + effectivePMTU = conn.effectivePMTU stackFrag = conn.stackFrag ) conn.RUnlock() @@ -196,11 +196,11 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern return nil } if df { - if len(frame.frame)-EthernetOverhead <= clientPMTU { + if len(frame.frame)-EthernetOverhead <= effectivePMTU { forwardChanDF <- frame return nil } else { - return FrameTooBigError{PMTU: clientPMTU} + return FrameTooBigError{EPMTU: effectivePMTU} } } else { if stackFrag || dec == nil || len(dec.decoded) < 2 { @@ -209,7 +209,7 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern } // Don't have trustworthy stack, so we're going to have to // send it DF in any case. - if len(frame.frame)-EthernetOverhead <= clientPMTU { + if len(frame.frame)-EthernetOverhead <= effectivePMTU { forwardChanDF <- frame return nil } @@ -217,7 +217,7 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern // We can't trust the stack to fragment, we have IP, and we // have a frame that's too big for the MTU, so we have to // fragment it ourself. - return fragment(dec.eth, dec.ip, clientPMTU, frame, func(segFrame *ForwardedFrame) { + return fragment(dec.eth, dec.ip, effectivePMTU, frame, func(segFrame *ForwardedFrame) { forwardChanDF <- segFrame }) } diff --git a/types.go b/types.go index a2210d39..a1247e44 100644 --- a/types.go +++ b/types.go @@ -65,7 +65,7 @@ type LocalConnection struct { remoteUDPAddr *net.UDPAddr established bool stackFrag bool - clientPMTU int + effectivePMTU int pmtuVerified bool SessionKey *[32]byte heartbeatStop chan<- interface{} @@ -103,7 +103,7 @@ type MsgTooBigError struct { } type FrameTooBigError struct { - PMTU int // effective pmtu, i.e. what we tell packet senders + EPMTU int // effective pmtu, i.e. what we tell packet senders } type UnknownPeersError struct { diff --git a/utils.go b/utils.go index 4c262d61..22d7235b 100644 --- a/utils.go +++ b/utils.go @@ -35,7 +35,7 @@ func (mtbe MsgTooBigError) Error() string { } func (ftbe FrameTooBigError) Error() string { - return fmt.Sprint("Frame too big error. PMTU is ", ftbe.PMTU) + return fmt.Sprint("Frame too big error. Effective PMTU is ", ftbe.EPMTU) } func (upe UnknownPeersError) Error() string {