refactor: clear distinction between actual and effective pmtu

This commit is contained in:
Matthias Radestock committed 2014-08-27 17:27:14 +01:00
1 parent b350924a63
commit f5e3450f0c
3 files changed
+16 -8

No files matched your search

+7 -7
View File
@@ -70,8 +70,8 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto
var pmtuVerifyTick <-chan time.Time
var clientPMTU int
maxPayload := pmtu - UDPOverhead
calculateClientPMTU := func(ftbe FrameTooBigError) {
maxPayload = ftbe.PMTU - UDPOverhead
calculateClientPMTU := func(mtbe MsgTooBigError) {
maxPayload = mtbe.PMTU - UDPOverhead
clientPMTU = maxPayload - enc.PacketOverhead() - enc.FrameOverhead() - EthernetOverhead
}
updateClientPMTU := func() {
@@ -86,8 +86,8 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto
enc.AppendFrame(pmtuVerifyFrame)
err := udpSender.Send(enc.Bytes())
if err != nil {
if ftbe, ok := err.(FrameTooBigError); ok {
calculateClientPMTU(ftbe)
if mtbe, ok := err.(MsgTooBigError); ok {
calculateClientPMTU(mtbe)
gotNewPMTU = true
break
}
@@ -107,8 +107,8 @@ func (conn *LocalConnection) forwarderLoop(forwardCh <-chan *ForwardedFrame, sto
flush := func() {
err := udpSender.Send(enc.Bytes())
if err != nil {
if ftbe, ok := err.(FrameTooBigError); ok {
calculateClientPMTU(ftbe)
if mtbe, ok := err.(MsgTooBigError); ok {
calculateClientPMTU(mtbe)
updateClientPMTU()
} else if PosixError(err) == syscall.ENOBUFS {
// TODO handle this better
@@ -341,7 +341,7 @@ func (sender *RawUDPSender) Send(msg []byte) error {
if err != nil {
return err
}
return FrameTooBigError{PMTU: pmtu}
return MsgTooBigError{PMTU: pmtu}
}
func (sender *RawUDPSender) Shutdown() error {
+5 -1
View File
@@ -98,8 +98,12 @@ type EthernetDecoder struct {
parser *gopacket.DecodingLayerParser
}
type MsgTooBigError struct {
PMTU int // actual pmtu, i.e. what the kernel told us
}
type FrameTooBigError struct {
PMTU int
PMTU int // effective pmtu, i.e. what we tell packet senders
}
type UnknownPeersError struct {
+4
View File
@@ -30,6 +30,10 @@ func PosixError(err error) error {
return operr.Err
}
func (mtbe MsgTooBigError) Error() string {
return fmt.Sprint("Msg too big error. PMTU is ", mtbe.PMTU)
}
func (ftbe FrameTooBigError) Error() string {
return fmt.Sprint("Frame too big error. PMTU is ", ftbe.PMTU)
}