Skip to content

Commit 84923f5

Browse files
committed
protect: bind wildcard addrs
1 parent 8b1fd04 commit 84923f5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

intra/protect/protect.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const (
5050
// When advertised routes are actually null routed (no reply)
5151
// this timeout will help short circuit dial attempts on it.
5252
defaultConnectTimeout = 10 * time.Second
53+
54+
// if true, only protects the socket from routing loops & binds to active network.
55+
onlyProtectWildcardAddrs = false
5356
)
5457

5558
// never resolve system/default/"hostless" resolver; expected to have seeded ips
@@ -79,7 +82,7 @@ func ifbind(who string, ctl Controller) func(string, string, syscall.RawConn) er
7982
log.VV("control: netbinder: %s: %s(%s); err? %v", who, network, addr, err)
8083
return c.Control(func(fd uintptr) {
8184
sock := int(fd)
82-
if !maybeGlobalUnicast(addr, true) {
85+
if onlyProtectWildcardAddrs && !maybeGlobalUnicast(addr, true) {
8386
ctl.Protect(who, sock)
8487
return
8588
}
@@ -106,7 +109,7 @@ func ipbind(p Protector) func(string, string, syscall.RawConn) error {
106109
log.VV("control: ipbinder: %s(%s/%w), bindto(%s); err? %v",
107110
network, addr, origaddr, ipaddr, perr)
108111

109-
if !maybeGlobalUnicast(addr, true) {
112+
if onlyProtectWildcardAddrs && !maybeGlobalUnicast(addr, true) {
110113
// todo: protect fd?
111114
return nil
112115
}
@@ -181,7 +184,7 @@ func MakeNsRDial(who string, ctx context.Context, c Controller) *RDial {
181184
}
182185

183186
// Creates a RDial that can bind to any active interface, with additional control fns.
184-
func MakeNsRDialExt(who string, ctx context.Context, ctl Controller, ext []ControlFn) *RDial {
187+
func MakeNsRDialExt(who string, ctx context.Context, ctl Controller, ext ...ControlFn) *RDial {
185188
dialer := MakeNsDialer(who, ctl)
186189
dialer.Control = func(network, address string, c syscall.RawConn) error {
187190
for _, fn := range ext {

0 commit comments

Comments
 (0)