refactor: yet more clarity on naming around pmtu

This commit is contained in:
Matthias Radestock committed 2014-08-27 17:55:43 +01:00
1 parent f5e3450f0c
commit 6cec7a036c
5 files changed
+31 -31

No files matched your search

+8 -8
View File
@@ -63,7 +63,7 @@ func NewLocalConnection(connRemote *RemoteConnection, expectedName PeerName, tcp
Router: router, Router: router,
TCPConn: tcpConn, TCPConn: tcpConn,
remoteUDPAddr: udpAddr, remoteUDPAddr: udpAddr,
clientPMTU: DefaultPMTU, effectivePMTU: DefaultPMTU,
queryChan: queryChan} queryChan: queryChan}
go connLocal.queryLoop(queryChan, expectedName) 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 // Called by forwarder processes, read in Forward (by sniffer and udp
// listener process in router). // listener process in router).
func (conn *LocalConnection) setClientPMTU(pmtu int) { func (conn *LocalConnection) setEffectivePMTU(pmtu int) {
conn.Lock() conn.Lock()
defer conn.Unlock() defer conn.Unlock()
conn.clientPMTU = pmtu conn.effectivePMTU = pmtu
conn.pmtuVerified = false conn.pmtuVerified = false
conn.log("Client PMTU set to", pmtu) conn.log("Client PMTU set to", pmtu)
} }
func (conn *LocalConnection) clientPMTUVerification(pmtu int) { func (conn *LocalConnection) effectivePMTUVerification(pmtu int) {
conn.Lock() conn.Lock()
defer conn.Unlock() defer conn.Unlock()
if pmtu == conn.clientPMTU && !conn.pmtuVerified { if pmtu == conn.effectivePMTU && !conn.pmtuVerified {
conn.log("Client PMTU verified at", pmtu) conn.log("Effecive PMTU verified at", pmtu)
conn.pmtuVerified = true conn.pmtuVerified = true
} }
} }
func (conn *LocalConnection) isClientPMTUVerfied() bool { func (conn *LocalConnection) isEffectivePMTUVerfied() bool {
conn.RLock() conn.RLock()
defer conn.RUnlock() defer conn.RUnlock()
return conn.pmtuVerified return conn.pmtuVerified
@@ -506,7 +506,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool
} }
conn.local.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate)) conn.local.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate))
} else if msg[0] == ProtocolPMTUVerified { } else if msg[0] == ProtocolPMTUVerified {
conn.clientPMTUVerification(int(binary.BigEndian.Uint16(msg[1:]))) conn.effectivePMTUVerification(int(binary.BigEndian.Uint16(msg[1:])))
} else { } else {
conn.log("received unknown msg:\n", msg) conn.log("received unknown msg:\n", msg)
} }
+2 -2
View File
@@ -21,11 +21,11 @@ func (dec *EthernetDecoder) DecodeLayers(data []byte) error {
func (dec *EthernetDecoder) CheckFrameTooBig(err error, sendFrame func([]byte) error) error { func (dec *EthernetDecoder) CheckFrameTooBig(err error, sendFrame func([]byte) error) error {
if ftbe, ok := err.(FrameTooBigError); ok { if ftbe, ok := err.(FrameTooBigError); ok {
// we know: 1. ip is valid, 2. it was ip and DF was set // 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 { if err != nil {
return err 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) return sendFrame(icmpFrame)
} else { } else {
return err return err
+18 -18
View File
@@ -44,7 +44,7 @@ func (conn *LocalConnection) ensureForwarders() error {
conn.stopForwardDF = stopForwardDF conn.stopForwardDF = stopForwardDF
conn.Unlock() conn.Unlock()
go conn.forwarderLoop(forwardChan, stopForward, encryptor, udpSender, DefaultPMTU) 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 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 // The pmtu governs the max size of msg we can pass to the
// udpSender. udpSender will add in the UDP/IP headers // udpSender. udpSender will add in the UDP/IP headers
var pmtuVerifyTick <-chan time.Time var pmtuVerifyTick <-chan time.Time
var clientPMTU int var effectivePMTU int
maxPayload := pmtu - UDPOverhead maxPayload := pmtu - UDPOverhead
calculateClientPMTU := func(mtbe MsgTooBigError) { calculateEffectivePMTU := func(mtbe MsgTooBigError) {
maxPayload = mtbe.PMTU - UDPOverhead 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; { for gotNewPMTU := true; gotNewPMTU; {
conn.setClientPMTU(clientPMTU) conn.setEffectivePMTU(effectivePMTU)
pmtuVerifyFrame := &ForwardedFrame{ pmtuVerifyFrame := &ForwardedFrame{
srcPeer: conn.local, srcPeer: conn.local,
dstPeer: conn.remote, dstPeer: conn.remote,
frame: make([]byte, clientPMTU+EthernetOverhead)} frame: make([]byte, effectivePMTU+EthernetOverhead)}
gotNewPMTU = false gotNewPMTU = false
for cnt := 0; cnt < 10; cnt += 1 { for cnt := 0; cnt < 10; cnt += 1 {
enc.AppendFrame(pmtuVerifyFrame) enc.AppendFrame(pmtuVerifyFrame)
err := udpSender.Send(enc.Bytes()) err := udpSender.Send(enc.Bytes())
if err != nil { if err != nil {
if mtbe, ok := err.(MsgTooBigError); ok { if mtbe, ok := err.(MsgTooBigError); ok {
calculateClientPMTU(mtbe) calculateEffectivePMTU(mtbe)
gotNewPMTU = true gotNewPMTU = true
break break
} }
@@ -108,8 +108,8 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto
err := udpSender.Send(enc.Bytes()) err := udpSender.Send(enc.Bytes())
if err != nil { if err != nil {
if mtbe, ok := err.(MsgTooBigError); ok { if mtbe, ok := err.(MsgTooBigError); ok {
calculateClientPMTU(mtbe) calculateEffectivePMTU(mtbe)
updateClientPMTU() updateEffectivePMTU()
} else if PosixError(err) == syscall.ENOBUFS { } else if PosixError(err) == syscall.ENOBUFS {
// TODO handle this better // TODO handle this better
} else { } else {
@@ -145,10 +145,10 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto
// all empty so that we don't risk appending verify-frames // all empty so that we don't risk appending verify-frames
// to other data. // to other data.
pmtuVerifyTick = nil pmtuVerifyTick = nil
if !conn.isClientPMTUVerfied() { if !conn.isEffectivePMTUVerfied() {
clientPMTU -= 8 effectivePMTU -= 8
maxPayload -= 8 maxPayload -= 8
updateClientPMTU() updateEffectivePMTU()
} }
case frame = <-forwardCh: case frame = <-forwardCh:
if !appendFrame(frame) { if !appendFrame(frame) {
@@ -186,7 +186,7 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern
var ( var (
forwardChan = conn.forwardChan forwardChan = conn.forwardChan
forwardChanDF = conn.forwardChanDF forwardChanDF = conn.forwardChanDF
clientPMTU = conn.clientPMTU effectivePMTU = conn.effectivePMTU
stackFrag = conn.stackFrag stackFrag = conn.stackFrag
) )
conn.RUnlock() conn.RUnlock()
@@ -196,11 +196,11 @@ func (conn *LocalConnection) Forward(df bool, frame *ForwardedFrame, dec *Ethern
return nil return nil
} }
if df { if df {
if len(frame.frame)-EthernetOverhead <= clientPMTU { if len(frame.frame)-EthernetOverhead <= effectivePMTU {
forwardChanDF <- frame forwardChanDF <- frame
return nil return nil
} else { } else {
return FrameTooBigError{PMTU: clientPMTU} return FrameTooBigError{EPMTU: effectivePMTU}
} }
} else { } else {
if stackFrag || dec == nil || len(dec.decoded) < 2 { 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 // Don't have trustworthy stack, so we're going to have to
// send it DF in any case. // send it DF in any case.
if len(frame.frame)-EthernetOverhead <= clientPMTU { if len(frame.frame)-EthernetOverhead <= effectivePMTU {
forwardChanDF <- frame forwardChanDF <- frame
return nil 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 // 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 // have a frame that's too big for the MTU, so we have to
// fragment it ourself. // 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 forwardChanDF <- segFrame
}) })
} }
+2 -2
View File
@@ -65,7 +65,7 @@ type LocalConnection struct {
remoteUDPAddr *net.UDPAddr remoteUDPAddr *net.UDPAddr
established bool established bool
stackFrag bool stackFrag bool
clientPMTU int effectivePMTU int
pmtuVerified bool pmtuVerified bool
SessionKey *[32]byte SessionKey *[32]byte
heartbeatStop chan<- interface{} heartbeatStop chan<- interface{}
@@ -103,7 +103,7 @@ type MsgTooBigError struct {
} }
type FrameTooBigError 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 { type UnknownPeersError struct {
+1 -1
View File
@@ -35,7 +35,7 @@ func (mtbe MsgTooBigError) Error() string {
} }
func (ftbe FrameTooBigError) 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 { func (upe UnknownPeersError) Error() string {