@@ -217,7 +217,7 @@ type ProxyProvider interface {
217217 // ProxyFor returns a transport from this multi-transport.
218218 ProxyFor (id string ) (Proxy , error )
219219 // ProxyTo returns the proxy to use for ipp from given pids.
220- ProxyTo (ipp netip.AddrPort , proto , uid string , pids []string ) (Proxy , error )
220+ ProxyTo (who string , ipp netip.AddrPort , proto , uid string , pids []string ) (Proxy , error )
221221 // ProxyRef returns currently reachable reference to Proxy, if any.
222222 ProxyRef (who , id string ) (* core.WeakRef [Proxy ], error )
223223}
@@ -488,7 +488,7 @@ func (px *proxifier) ProxyRef(who, id string) (*core.WeakRef[Proxy], error) {
488488// ProxyTo implements Proxies.
489489// May return both a Proxy and an error, in which case, the error
490490// denotes that while the Proxy is not healthy, it is still registered.
491- func (px * proxifier ) ProxyTo (ipp netip.AddrPort , proto , uid string , pids []string ) (theone Proxy , err error ) {
491+ func (px * proxifier ) ProxyTo (who string , ipp netip.AddrPort , proto , uid string , pids []string ) (theone Proxy , err error ) {
492492 waitedForMissingProxy := false
493493
494494 ippstr := ipp .String ()
@@ -520,26 +520,37 @@ func (px *proxifier) ProxyTo(ipp netip.AddrPort, proto, uid string, pids []strin
520520 goto retryPin
521521 }
522522 }
523- logev (err )("proxy: pin: %s: %s+%s; pin pid0: %s (stalled? %ds / waited? %t); err? %v" ,
524- proto , uid , ippstr , pids [0 ], stalledSec , waitedForMissingProxy , err )
523+ logev (err )("proxy: pin: single: 1 %s: %s: %s+%s; pin pid0: %s (stalled? %ds / waited? %t); err? %v" ,
524+ who , proto , uid , ippstr , pids [0 ], stalledSec , waitedForMissingProxy , err )
525525 if p != nil {
526- if iscircular (p , ippstr ) {
527- circular = append (circular , pids [0 ])
526+ pid0 := p .ID ()
527+ iscircle := iscircular (p , ippstr )
528+ noroute := ! hasroute (p , ippstr )
529+ canth3 := uid != protect .MyUid && maybeH3 (proto , ipp ) && cantProxyH3 (p .ID ())
530+ notok := p .Status () == TNT
531+
532+ if log .Verbose {
533+ log .V ("proxy: pin: single: 2 %s: %s: %s+%s; pin pid0: (%s <> %s) (stalled? %ds / waited? %t); err? %v; circular? %t; noroute? %t; canth3? %t; notok? %t" ,
534+ who , proto , uid , ippstr , pid0 , pids [0 ], stalledSec , waitedForMissingProxy , err , iscircle , noroute , canth3 , notok )
535+ }
536+
537+ if iscircle {
538+ circular = append (circular , pid0 )
528539 px .delpin (uid , ipp )
529540 // circular route must be returned as-is (clients may check for equality)
530541 return nil , ErrCircularRoute
531542 }
532- if ! hasroute ( p , ippstr ) {
543+ if noroute {
533544 px .delpin (uid , ipp )
534545 return nil , e (core .JoinErr (err , errProxyRoute ))
535546 } // there is only one pid to route to
536- if uid != protect . MyUid && maybeH3 ( proto , ipp ) && cantProxyH3 ( p . ID ()) {
547+ if canth3 {
537548 // allow h3 like traffic from myuid, which could actually be rpn/wg on 443
538549 err = errProxyProtoH3
539550 px .delpin (uid , ipp )
540551 return nil , e (core .JoinErr (err , errProxyProtoH3 ))
541552 }
542- if p . Status () == TNT { // proxy not ok
553+ if notok { // proxy not ok
543554 stalledSec = px .stall (uid + ippstr )
544555 }
545556 // wipe out err; return p, even if err is not nil
@@ -555,9 +566,10 @@ func (px *proxifier) ProxyTo(ipp netip.AddrPort, proto, uid string, pids []strin
555566 chosen := has (pids , pinnedpid )
556567 lo := local (pinnedpid )
557568
558- log .VV ("proxy: pin: %s: %s+%s; pinned: %s (ok? %t); chosen? %t / local? %t; from pids: %v" ,
559- proto , uid , ippstr , pinnedpid , pinok , chosen , lo , pids )
560-
569+ if log .Verbose {
570+ log .VV ("proxy: pin: %s: %s: %s+%s; pinned: %s (ok? %t); chosen? %t / local? %t; from pids: %v" ,
571+ who , proto , uid , ippstr , pinnedpid , pinok , chosen , lo , pids )
572+ }
561573 if ! pinok { // discard pinnedpid if pin has expired
562574 pinnedpid = ""
563575 }
@@ -567,24 +579,33 @@ func (px *proxifier) ProxyTo(ipp netip.AddrPort, proto, uid string, pids []strin
567579 lopinned = pinnedpid
568580 } else if pinok && chosen {
569581 p , err := px .pinID (uid , ipp , pinnedpid ) // repin & health check
570-
582+ pidc := idstr ( p )
571583 hasp := core .IsNotNil (p )
584+
572585 if hasp && p != nil && err != nil {
586+ iscircle := iscircular (p , ippstr )
587+ noroute := ! hasroute (p , ippstr )
588+ canth3 := uid != protect .MyUid && maybeH3 (proto , ipp ) && cantProxyH3 (pidc )
589+
590+ if log .Verbose {
591+ log .V ("proxy: pin: %s: %s: %s+%s; chosen and pinned: 1 (%s <> %s) (stalled? %ds); err? %v; circular? %t; noroute? %t; canth3? %t" ,
592+ who , proto , uid , ippstr , pinnedpid , pidc , stalledSec , err , iscircle , noroute , canth3 )
593+ }
573594 // check for circular route before other checks
574- if iscircular ( p , ippstr ) {
595+ if iscircle {
575596 circular = append (circular , pinnedpid )
576597 px .delpin (uid , ipp )
577- } else if uid != protect . MyUid && maybeH3 ( proto , ipp ) && cantProxyH3 ( p . ID ()) {
598+ } else if canth3 {
578599 // allow h3 like egress from myuid, which could actually be rpn/wg on 443
579600 err = core .JoinErr (err , errProxyProtoH3 )
580- } else if hasroute ( p , ippstr ) {
601+ } else if ! noroute { // hasroute
581602 return p , nil
582603 } else {
583604 px .delpin (uid , ipp ) // del pin if no route
584605 }
585606 } // else: pinnedpid not ok (ex: END/TPU/TNT) or no route
586- logev (err )("proxy: pin: %s: %s+%s; chosen and pinned: %s (but err? %v); hasproxy? %t (or no route)" ,
587- proto , uid , ippstr , pinnedpid , err , hasp )
607+ logev (err )("proxy: pin: %s: %s: %s +%s; chosen and pinned: 2 %s <> %s (but err? %v); hasproxy? %t (or no route)" ,
608+ who , proto , uid , ippstr , pinnedpid , pidc , err , hasp )
588609 } else if pinok && ! chosen {
589610 px .delpin (uid , ipp )
590611 }
@@ -602,8 +623,8 @@ func (px *proxifier) ProxyTo(ipp netip.AddrPort, proto, uid string, pids []strin
602623 }
603624
604625 defer func () {
605- logev (err )("proxy: pin: %s: %s+%s; chosen? %s; stalled? %ds; local: %v; miss: %v; notok: %v; noroute: %v; paused %v; ended %v; noh3: %v; circular: %v" ,
606- proto , uid , ipp , idstr (theone ), stalledSec , loproxies , missproxies , notokproxies , norouteproxies , pausedproxies , endproxies , noh3proxies , circular )
626+ logev (err )("proxy: pin: %s: %s: %s +%s; chosen? %s; stalled? %ds; local: %v; miss: %v; notok: %v; noroute: %v; paused %v; ended %v; noh3: %v; circular: %v" ,
627+ who , proto , uid , ippstr , idstr (theone ), stalledSec , loproxies , missproxies , notokproxies , norouteproxies , pausedproxies , endproxies , noh3proxies , circular )
607628 }()
608629
609630retrySearch:
@@ -652,8 +673,7 @@ retrySearch:
652673
653674 err := px .pin (uid , ipp , p ) // repin & ping if needed
654675 if err == nil {
655- log .VV ("proxy: pin: %s: %s+%s; pinned: %s; from pids: %v" ,
656- proto , uid , ippstr , pid , pids )
676+ log .VV ("proxy: pin: %s: %s: %s+%s; pinned: %s; from pids: %v" , who , proto , uid , ippstr , pid , pids )
657677 return p , nil
658678 } // else: proxy not ok
659679 notokproxies = append (notokproxies , pid )
@@ -669,16 +689,16 @@ retrySearch:
669689 stalledSec = px .stall (uid + ippstr )
670690 if one := core .ChooseOne (notok ); one != nil {
671691 if log .Verbose {
672- log .V ("proxy: pin: %s: %s+%s; pinned: %s; from notok: %v" ,
673- proto , uid , ippstr , idstr (one ), notokproxies )
692+ log .V ("proxy: pin: %s: %s: %s +%s; pinned: %s; from notok: %v" ,
693+ who , proto , uid , ippstr , idstr (one ), notokproxies )
674694 }
675695 return one , nil
676696 }
677697 for i , one := range noh3 {
678698 err := px .pin (uid , ipp , one ) // repin & ping if needed
679699 if err != nil || log .Verbose {
680- logev (err )("proxy: pin: %s: %s+%s; pinned: %s #%d; from noh3: %v; err? %v" ,
681- proto , uid , ippstr , idstr (one ), i , noh3proxies , err )
700+ logev (err )("proxy: pin: %s: %s: %s +%s; pinned: %s #%d; from noh3: %v; err? %v" ,
701+ who , proto , uid , ippstr , idstr (one ), i , noh3proxies , err )
682702 }
683703 if err == nil {
684704 return one , nil
@@ -705,8 +725,8 @@ retrySearch:
705725 time .Sleep (time .Duration (minWaitPeriodSec - stalledSec ) * time .Second )
706726 stalledSec = minWaitPeriodSec
707727 }
708- log .W ("proxy: pin: %s: %s+%s; missing: %v; notok: %v; noroute: %v; paused: %v; ended: %v; waited: %ds" ,
709- proto , uid , ippstr , missproxies , notokproxies , norouteproxies , pausedproxies , endproxies , stalledSec )
728+ log .W ("proxy: pin: %s: %s: %s +%s; missing: %v; notok: %v; noroute: %v; paused: %v; ended: %v; waited: %ds" ,
729+ who , proto , uid , ippstr , missproxies , notokproxies , norouteproxies , pausedproxies , endproxies , stalledSec )
710730 pids = missproxies
711731 missproxies = make ([]string , 0 )
712732 goto retrySearch
0 commit comments