@@ -375,9 +375,39 @@ func (pol *ACLPolicy) getNetPortRangeFromDestination(
375
375
machines types.Machines ,
376
376
needsWildcard bool ,
377
377
) ([]tailcfg.NetPortRange , error ) {
378
- var tokens []string
378
+ alias , port , err := parseDestination (dest )
379
+ if err != nil {
380
+ return nil , err
381
+ }
382
+
383
+ expanded , err := pol .ExpandAlias (
384
+ machines ,
385
+ alias ,
386
+ )
387
+ if err != nil {
388
+ return nil , err
389
+ }
390
+ ports , err := expandPorts (port , needsWildcard )
391
+ if err != nil {
392
+ return nil , err
393
+ }
394
+
395
+ dests := []tailcfg.NetPortRange {}
396
+ for _ , dest := range expanded .Prefixes () {
397
+ for _ , port := range * ports {
398
+ pr := tailcfg.NetPortRange {
399
+ IP : dest .String (),
400
+ Ports : port ,
401
+ }
402
+ dests = append (dests , pr )
403
+ }
404
+ }
405
+
406
+ return dests , nil
407
+ }
379
408
380
- log .Trace ().Str ("destination" , dest ).Msg ("generating policy destination" )
409
+ func parseDestination (dest string ) (string , string , error ) {
410
+ var tokens []string
381
411
382
412
// Check if there is a IPv4/6:Port combination, IPv6 has more than
383
413
// three ":".
@@ -397,7 +427,7 @@ func (pol *ACLPolicy) getNetPortRangeFromDestination(
397
427
if maybeIPv6 , err := netip .ParseAddr (filteredMaybeIPv6Str ); err != nil && ! maybeIPv6 .Is6 () {
398
428
log .Trace ().Err (err ).Msg ("trying to parse as IPv6" )
399
429
400
- return nil , fmt .Errorf (
430
+ return "" , "" , fmt .Errorf (
401
431
"failed to parse destination, tokens %v: %w" ,
402
432
tokens ,
403
433
ErrInvalidPortFormat ,
@@ -407,8 +437,6 @@ func (pol *ACLPolicy) getNetPortRangeFromDestination(
407
437
}
408
438
}
409
439
410
- log .Trace ().Strs ("tokens" , tokens ).Msg ("generating policy destination" )
411
-
412
440
var alias string
413
441
// We can have here stuff like:
414
442
// git-server:*
@@ -424,30 +452,7 @@ func (pol *ACLPolicy) getNetPortRangeFromDestination(
424
452
alias = fmt .Sprintf ("%s:%s" , tokens [0 ], tokens [1 ])
425
453
}
426
454
427
- expanded , err := pol .ExpandAlias (
428
- machines ,
429
- alias ,
430
- )
431
- if err != nil {
432
- return nil , err
433
- }
434
- ports , err := expandPorts (tokens [len (tokens )- 1 ], needsWildcard )
435
- if err != nil {
436
- return nil , err
437
- }
438
-
439
- dests := []tailcfg.NetPortRange {}
440
- for _ , dest := range expanded .Prefixes () {
441
- for _ , port := range * ports {
442
- pr := tailcfg.NetPortRange {
443
- IP : dest .String (),
444
- Ports : port ,
445
- }
446
- dests = append (dests , pr )
447
- }
448
- }
449
-
450
- return dests , nil
455
+ return alias , tokens [len (tokens )- 1 ], nil
451
456
}
452
457
453
458
// parseProtocol reads the proto field of the ACL and generates a list of
0 commit comments