Skip to content

Commit

Permalink
Fix bug in dispatcher (#3637)
Browse files Browse the repository at this point in the history
  • Loading branch information
sustrik authored Jan 24, 2020
1 parent 0f042cb commit f0ec43e
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions go/godispatcher/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,14 @@ func (as *Server) Register(ctx context.Context, ia addr.IA, address *net.UDPAddr
if err != nil {
return nil, 0, err
}
var ovConn net.PacketConn
if address.IP.To4() == nil {
ovConn = as.ipv6Conn
} else {
ovConn = as.ipv4Conn
}
conn := &Conn{
ipv4Conn: as.ipv4Conn,
ipv6Conn: as.ipv6Conn,
conn: ovConn,
ring: tableEntry.appIngressRing,
regReference: ref,
}
Expand All @@ -107,10 +112,8 @@ func (as *Server) Close() {

// Conn represents a connection bound to a specific SCION port/SVC.
type Conn struct {
// ipv4Conn is used to send IPv4 packets.
ipv4Conn net.PacketConn
// ipv6Conn is used to send IPv6 packets.
ipv6Conn net.PacketConn
// conn is used to send packets.
conn net.PacketConn
// ring is used to retrieve incoming packets.
ring *ringbuf.Ring
// regReference is the reference to the registration in the routing table.
Expand All @@ -123,25 +126,15 @@ func (ac *Conn) WriteTo(p []byte, addr net.Addr) (int, error) {
if err := registerIfSCMPRequest(ac.regReference, &info); err != nil {
log.Warn("SCMP Request ID error, packet still sent", "err", err)
}
isIPv6 := addr.(*net.UDPAddr).IP.To4() == nil
if isIPv6 {
return ac.ipv6Conn.WriteTo(p, addr)
} else {
return ac.ipv4Conn.WriteTo(p, addr)
}
return ac.conn.WriteTo(p, addr)
}

// Write is optimized for the use by ConnHandler (avoids reparsing the packet).
func (ac *Conn) Write(pkt *respool.Packet) (int, error) {
if err := registerIfSCMPRequest(ac.regReference, &pkt.Info); err != nil {
log.Warn("SCMP Request ID error, packet still sent", "err", err)
}
isIPv6 := pkt.OverlayRemote.IP.To4() == nil
if isIPv6 {
return pkt.SendOnConn(ac.ipv6Conn, pkt.OverlayRemote)
} else {
return pkt.SendOnConn(ac.ipv4Conn, pkt.OverlayRemote)
}
return pkt.SendOnConn(ac.conn, pkt.OverlayRemote)
}

func (ac *Conn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
Expand Down

0 comments on commit f0ec43e

Please sign in to comment.