initial integration for bounded dialer in static mode

This commit is contained in:
Vladislav Yarmak 2023-06-26 22:29:58 +03:00
parent 36235d68fb
commit f1dc40b0ce
2 changed files with 26 additions and 1 deletions

11
main.go
View File

@ -72,6 +72,7 @@ type CLIArgs struct {
passwdCost int passwdCost int
positionalArgs []string positionalArgs []string
proxy []string proxy []string
sourceIPHints []net.IP
} }
func parse_args() CLIArgs { func parse_args() CLIArgs {
@ -101,6 +102,14 @@ func parse_args() CLIArgs {
args.proxy = append(args.proxy, p) args.proxy = append(args.proxy, p)
return nil return nil
}) })
flag.Func("ip-hints", "a comma-separated list of addresses to use on dial attempts. Example: \"10.0.0.1,fe80::2,0.0.0.0,::\"", func(p string) error {
list, err := parseIPList(p)
if err != nil {
return err
}
args.sourceIPHints = list
return nil
})
flag.Parse() flag.Parse()
args.positionalArgs = flag.Args() args.positionalArgs = flag.Args()
return args return args
@ -146,7 +155,7 @@ func run() int {
} }
defer auth.Stop() defer auth.Stop()
var dialer Dialer = new(net.Dialer) var dialer Dialer = NewBoundDialer(new(net.Dialer), args.sourceIPHints)
for _, proxyURL := range args.proxy { for _, proxyURL := range args.proxy {
newDialer, err := proxyDialerFromURL(proxyURL, dialer) newDialer, err := proxyDialerFromURL(proxyURL, dialer)
if err != nil { if err != nil {

View File

@ -369,3 +369,19 @@ func maybeWrapWithContextDialer(d Dialer) ContextDialer {
} }
return wrappedDialer{d} return wrappedDialer{d}
} }
func parseIPList(list string) ([]net.IP, error) {
res := make([]net.IP, 0)
for _, elem := range strings.Split(list, ",") {
elem = strings.TrimSpace(elem)
if len(elem) == 0 {
continue
}
if parsed := net.ParseIP(elem); parsed == nil {
return nil, fmt.Errorf("unable to parse IP address %q", elem)
} else {
res = append(res, parsed)
}
}
return res, nil
}