Skip to content

Commit 1efa7b1

Browse files
committed
udpmux: announce on any addr not src
1 parent 27914db commit 1efa7b1

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

intra/icmp.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,7 @@ func (h *icmpHandler) Ping(source, target netip.AddrPort, msg []byte) (echoed bo
171171
}
172172

173173
dst := oneRealIp(realips, target)
174-
anyaddr := "0.0.0.0:0"
175-
proto := "udp4"
176-
if target.Addr().Is6() {
177-
proto = "udp6"
178-
anyaddr = "[::]:0"
179-
}
174+
proto, anyaddr := anyaddrFor(dst)
180175
// todo: use dialers.ListenICMP?
181176
uc, err := px.Dialer().Probe(proto, anyaddr)
182177
ucnil := uc == nil || core.IsNil(uc)
@@ -221,6 +216,16 @@ func extend(c core.MinConn, t time.Duration) {
221216
}
222217
}
223218

219+
func anyaddrFor(ipp netip.AddrPort) (proto, anyaddr string) {
220+
anyaddr = "0.0.0.0:0"
221+
proto = "udp4"
222+
if ipp.Addr().Is6() {
223+
proto = "udp6"
224+
anyaddr = "[::]:0"
225+
}
226+
return
227+
}
228+
224229
func logei(err error, msg string, args ...any) {
225230
f := log.E
226231
if err == nil {

intra/udpmux.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,16 @@ func newMuxTable() *muxTable {
473473
return &muxTable{t: make(map[netip.AddrPort]*muxer)}
474474
}
475475

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

480+
proto, anyaddr := anyaddrFor(src)
480481
if mxr, ok := e.t[src]; ok {
481482
return mxr, nil
482-
} else if pc, err := mk("udp", src.String()); err == nil {
483+
} else if pc, err := mk(proto, anyaddr); err == nil {
483484
log.I("udp: mux: %s new assoc for %s", id, src)
484-
mxr = newMuxerLocked(id, pc, vendor, func() {
485+
mxr = newMuxerLocked(id, pc, v, func() {
485486
e.dissociate(id, src)
486487
})
487488
e.t[src] = mxr

0 commit comments

Comments
 (0)