Skip to content

Commit

Permalink
udpmux: announce on any addr not src
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Aug 23, 2024
1 parent 27914db commit 1efa7b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
17 changes: 11 additions & 6 deletions intra/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,7 @@ func (h *icmpHandler) Ping(source, target netip.AddrPort, msg []byte) (echoed bo
}

dst := oneRealIp(realips, target)
anyaddr := "0.0.0.0:0"
proto := "udp4"
if target.Addr().Is6() {
proto = "udp6"
anyaddr = "[::]:0"
}
proto, anyaddr := anyaddrFor(dst)
// todo: use dialers.ListenICMP?
uc, err := px.Dialer().Probe(proto, anyaddr)
ucnil := uc == nil || core.IsNil(uc)
Expand Down Expand Up @@ -221,6 +216,16 @@ func extend(c core.MinConn, t time.Duration) {
}
}

func anyaddrFor(ipp netip.AddrPort) (proto, anyaddr string) {
anyaddr = "0.0.0.0:0"
proto = "udp4"
if ipp.Addr().Is6() {
proto = "udp6"
anyaddr = "[::]:0"
}
return
}

func logei(err error, msg string, args ...any) {
f := log.E
if err == nil {
Expand Down
7 changes: 4 additions & 3 deletions intra/udpmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,16 @@ func newMuxTable() *muxTable {
return &muxTable{t: make(map[netip.AddrPort]*muxer)}
}

func (e *muxTable) associate(id string, src netip.AddrPort, mk assocFn, vendor netstack.DemuxerFn) (*muxer, error) {
func (e *muxTable) associate(id string, src netip.AddrPort, mk assocFn, v netstack.DemuxerFn) (*muxer, error) {
e.Lock()
defer e.Unlock()

proto, anyaddr := anyaddrFor(src)
if mxr, ok := e.t[src]; ok {
return mxr, nil
} else if pc, err := mk("udp", src.String()); err == nil {
} else if pc, err := mk(proto, anyaddr); err == nil {
log.I("udp: mux: %s new assoc for %s", id, src)
mxr = newMuxerLocked(id, pc, vendor, func() {
mxr = newMuxerLocked(id, pc, v, func() {
e.dissociate(id, src)
})
e.t[src] = mxr
Expand Down

1 comment on commit 1efa7b1

@ignoramous
Copy link
Contributor Author

@ignoramous ignoramous commented on 1efa7b1 Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#77

Please sign in to comment.