Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in dispatcher #3637

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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