Skip to content

Commit 75f9edb

Browse files
committed
Warn on useless attribute 'has_subnets'
This closes #28
1 parent 5d4360b commit 75f9edb

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

go/pkg/pass1/find-subnets.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -495,24 +495,23 @@ func (c *spoc) findSubnetsInNatDomain0(domains []*natDomain, networks netList) {
495495
// as value of subnet_of.
496496
if natSubnet.subnetOf == bignet {
497497
subnet.subnetOfUsed = true
498-
} else if !(bignet.hasSubnets &&
498+
} else if bignet.hasSubnets &&
499499
(bignet.ipp.Bits() == 0 ||
500500
zoneEq(bignet.zone, subnet.zone) ||
501-
isLoopbackAtZoneBorder(subnet, bignet))) {
502-
503-
if printType := c.conf.CheckSubnets; printType != "" {
504-
// Prevent multiple error messages in
505-
// different NAT domains.
506-
if natSubnet.subnetOf == nil {
507-
natSubnet.subnetOf = bignet
508-
natSubnet.subnetOfUsed = true
509-
}
510-
c.warnOrErr(printType,
511-
"%s is subnet of %s\n"+
512-
" in %s.\n"+
513-
" If desired, declare attribute 'subnet_of'",
514-
natName(natSubnet), natName(natBignet), domain.name)
501+
isLoopbackAtZoneBorder(subnet, bignet)) {
502+
bignet.hasSubnetsUsed = true
503+
} else if printType := c.conf.CheckSubnets; printType != "" {
504+
// Prevent multiple error messages in
505+
// different NAT domains.
506+
if natSubnet.subnetOf == nil {
507+
natSubnet.subnetOf = bignet
508+
natSubnet.subnetOfUsed = true
515509
}
510+
c.warnOrErr(printType,
511+
"%s is subnet of %s\n"+
512+
" in %s.\n"+
513+
" If desired, declare attribute 'subnet_of'",
514+
natName(natSubnet), natName(natBignet), domain.name)
516515
}
517516
}
518517

@@ -624,10 +623,13 @@ func isLoopbackAtZoneBorder(sub, big *network) bool {
624623
return false
625624
}
626625

627-
func (c *spoc) findUselessSubnetOf() {
626+
func (c *spoc) findUselessSubnetAttr() {
628627
for _, n := range c.allNetworks {
629628
if bignet := n.subnetOf; bignet != nil && !n.subnetOfUsed {
630-
c.warn("Useless 'subnet_of = %s' at %s", bignet, n)
629+
c.warn("Useless 'subnet_of = %s' at %s", bignet, n.vxName())
630+
}
631+
if n.hasSubnets && !n.hasSubnetsUsed {
632+
c.warn("Useless 'has_subnets' at %s", n.vxName())
631633
}
632634
}
633635
}
@@ -753,5 +755,5 @@ func (c *spoc) findSubnetsInNatDomain(domains []*natDomain) {
753755
setMaxSecondaryNet(networks)
754756
}
755757
})
756-
c.findUselessSubnetOf()
758+
c.findUselessSubnetAttr()
757759
}

go/pkg/pass1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ type network struct {
151151
hasIdHosts bool
152152
hasOtherSubnet bool
153153
hasSubnets bool
154+
hasSubnetsUsed bool
154155
hidden bool
155156
hosts []*host
156157
identity bool

go/testdata/crypto.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,8 @@ crypto map crypto-outside interface outside
32663266
=SUBST=,0.0.0.0/0,1.0.0.0/8,
32673267
# Use individual routes to VPN peers, even if all have same next hop
32683268
# and even if no route to 0.0.0.0/0 is added.
3269+
=WARNING=
3270+
Warning: Useless 'has_subnets' at network:internet
32693271
=OUTPUT=
32703272
--asavpn
32713273
! [ Routing ]

go/testdata/ipv6/crypto_ipv6.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,8 @@ crypto map crypto-outside interface outside
32663266
=SUBST=,::/0,::100:0/8,
32673267
# Use individual routes to VPN peers, even if all have same next hop
32683268
# and even if no route to ::/0 is added.
3269+
=WARNING=
3270+
Warning: Useless 'has_subnets' at network:internet
32693271
=OUTPUT=
32703272
--ipv6/asavpn
32713273
! [ Routing ]

go/testdata/ipv6/loopback_ipv6.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ router:r2 = {
187187
Warning: interface:r2.lo is subnet of network:n1
188188
in nat_domain:[network:n1].
189189
If desired, declare attribute 'subnet_of'
190+
Warning: Useless 'has_subnets' at network:n1
190191
=END=
191192
192193
############################################################

go/testdata/loopback.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ router:r2 = {
187187
Warning: interface:r2.lo is subnet of network:n1
188188
in nat_domain:[network:n1].
189189
If desired, declare attribute 'subnet_of'
190+
Warning: Useless 'has_subnets' at network:n1
190191
=END=
191192
192193
############################################################

0 commit comments

Comments
 (0)