Skip to content

Commit 649b4fa

Browse files
committed
No longer extend aggregate with /0 ip to combined46
1 parent 06d4765 commit 649b4fa

File tree

4 files changed

+87
-44
lines changed

4 files changed

+87
-44
lines changed

go/pkg/pass1/set-zone.go

+24-12
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ func (c *spoc) processAggregates() {
670670
func(a, b *network) int {
671671
return strings.Compare(a.name, b.name)
672672
})
673+
var unset netip.Prefix
673674
for _, agg := range aggList {
674675
process := func(agg *network, z *zone) {
675676
// Assure that no other aggregate with same IP and mask
@@ -692,19 +693,30 @@ func (c *spoc) processAggregates() {
692693
c.linkAggregateToZone(agg, z)
693694
}
694695
z := agg.link.zone
695-
process(agg, z)
696-
// Add non matching aggregate to combined zone.
697-
if z2 := z.combined46; z2 != nil && agg.ipp.Bits() == 0 {
698-
agg2 := new(network)
699-
agg2.name = agg.name
700-
agg2.isAggregate = true
701-
agg2.ipV6 = !agg.ipV6
702-
agg2.ipp = c.getNetwork00(agg2.ipV6).ipp
703-
agg.combined46 = agg2
704-
agg2.combined46 = agg
705-
process(agg2, z2)
696+
if agg.ipp == unset {
697+
agg.ipp = c.getNetwork00(z.ipV6).ipp
698+
agg.ipV6 = z.ipV6
699+
process(agg, z)
700+
// Add non matching aggregate to combined zone.
701+
if z2 := z.combined46; z2 != nil {
702+
agg2 := new(network)
703+
agg2.name = agg.name
704+
agg2.isAggregate = true
705+
agg2.ipV6 = z2.ipV6
706+
agg2.ipp = c.getNetwork00(agg2.ipV6).ipp
707+
if !agg2.ipV6 {
708+
agg2.nat = agg.nat
709+
agg.nat = nil
710+
}
711+
agg.combined46 = agg2
712+
agg2.combined46 = agg
713+
process(agg2, z2)
714+
} else if agg.ipV6 && agg.nat != nil {
715+
c.err("NAT not supported for IPv6 %s", agg)
716+
}
717+
} else {
718+
process(agg, z)
706719
}
707-
708720
}
709721
// Add aggregate to all zones in zone cluster.
710722
for _, agg := range aggList {

go/pkg/pass1/setup-objects.go

+22-30
Original file line numberDiff line numberDiff line change
@@ -1278,39 +1278,31 @@ func (c *spoc) setupAggregate(v *ast.TopStruct) {
12781278
}
12791279
}
12801280
c.checkDuplAttr(v.Attributes, name)
1281-
if !hasLink {
1282-
c.err("Attribute 'link' must be defined for %s", name)
1283-
} else if net := ag.link; net != nil {
1284-
if !ag.ipp.IsValid() {
1285-
ag.ipp = c.getNetwork00(net.ipV6).ipp
1286-
ag.ipV6 = net.ipV6
1287-
if net6 := net.combined46; net6 != nil {
1288-
ag6 := *ag
1289-
ag6.link = net6
1290-
ag6.ipp = c.getNetwork00(true).ipp
1291-
ag6.ipV6 = true
1292-
ag6.nat = nil
1293-
ag6.combined46 = ag
1294-
ag.combined46 = &ag6
1295-
}
1296-
} else if ag.ipV6 != ag.link.ipV6 {
1281+
net := ag.link
1282+
if net == nil {
1283+
if !hasLink {
1284+
c.err("Attribute 'link' must be defined for %s", name)
1285+
}
1286+
return
1287+
}
1288+
// If no ipAttr is given, this case is handled later when
1289+
// processing zones.
1290+
if ipAttr != "" {
1291+
if ag.ipV6 != net.ipV6 {
12971292
c.err("Must not link %s address to %s network in %s",
12981293
ipvx(ag.ipV6), ipvx(ag.link.ipV6), name)
12991294
}
1300-
if ag.nat != nil && ag.link.ipV6 {
1301-
c.err("NAT not supported for IPv6 %s", ag)
1302-
}
1303-
}
1304-
if ag.ipp.Bits() != 0 {
1305-
for _, a := range v.Attributes {
1306-
switch a.Name {
1307-
case "ip", "ip6", "link", "owner",
1308-
"overlaps", "identical_body", "multi_owner", "has_unenforceable":
1309-
continue
1310-
}
1311-
if !strings.HasPrefix(a.Name, "nat:") {
1312-
c.err("Must not use attribute '%s' if IP is set for %s",
1313-
a.Name, name)
1295+
if ag.ipp.Bits() != 0 {
1296+
for _, a := range v.Attributes {
1297+
switch a.Name {
1298+
case "ip", "ip6", "link", "owner",
1299+
"overlaps", "identical_body", "multi_owner", "has_unenforceable":
1300+
continue
1301+
}
1302+
if !strings.HasPrefix(a.Name, "nat:") {
1303+
c.err("Must not use attribute '%s' if IP is set for %s",
1304+
a.Name, name)
1305+
}
13141306
}
13151307
}
13161308
}

go/testdata/ipv46-combined.t

+29
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,35 @@ Error: Duplicate any:n1-v4 and any:n1-v6 in any:[network:n1-v6]
987987
Error: Duplicate any:n1-v4 and any:n1-v6 in any:[network:n1-v4]
988988
=END=
989989

990+
############################################################
991+
=TITLE=Aggregate with NAT linked to v6 network in combined zone
992+
=INPUT=
993+
any:n1-v6 = { link = network:n1-v6; nat:n1 = { ip = 10.9.9.0/24; } }
994+
network:n1-v6 = { ip6 = 2001:db8:1:6::/64; }
995+
network:n1 = { ip = 10.1.1.0/24; ip6 = 2001:db8:1:1::/64; }
996+
network:n2-v4 = { ip = 10.1.2.0/24; }
997+
router:u = {
998+
interface:n1-v6;
999+
interface:n1 = { ip = 10.1.1.1; ip6 = 2001:db8:1:1::1; }
1000+
}
1001+
router:r1 = {
1002+
managed;
1003+
model = IOS;
1004+
interface:n1 = { ip = 10.1.1.2; ip6 = 2001:db8:1:1::2; hardware = n1; }
1005+
interface:n2-v4 = { ip = 10.1.2.1; bind_nat = n1; hardware = n2; }
1006+
}
1007+
service:s1 = {
1008+
user = network:n2-v4;
1009+
permit src = user; dst = network:n1; prt = tcp 80;
1010+
}
1011+
=OUTPUT=
1012+
--r1
1013+
ip access-list extended n2_in
1014+
deny ip any host 10.9.9.2
1015+
permit tcp 10.1.2.0 0.0.0.255 10.9.9.0 0.0.0.255 eq 80
1016+
deny ip any any
1017+
=END=
1018+
9901019
############################################################
9911020
=TITLE=Bridged network
9921021
=INPUT=

go/testdata/ipv6.t

+12-2
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ Aborted
446446
=TITLE=NAT not supported
447447
=INPUT=
448448
area:n1 = { anchor = network:n1; nat:ar = { hidden; } }
449-
any:n1 = { link = network:n1; nat:ag = { hidden; } }
450449
network:n1 = {
451450
ip6 = 2001:db8:1:1::/64; nat:n = { hidden; }
452451
host:h1 = { ip6 = 2001:db8:1:1::10; nat:h = { ip = 2001:db8:1:ffff::10; } }
@@ -458,6 +457,17 @@ router:r1 = {
458457
=ERROR=
459458
Error: NAT not supported for IPv6 host:h1
460459
Error: NAT not supported for IPv6 network:n1
461-
Error: NAT not supported for IPv6 any:n1
462460
Error: NAT not supported for IPv6 area:n1
463461
=END=
462+
463+
############################################################
464+
=TITLE=NAT not supported at aggregate
465+
=INPUT=
466+
any:n1 = { link = network:n1; nat:ag = { hidden; } }
467+
network:n1 = {
468+
ip6 = 2001:db8:1:1::/64;
469+
}
470+
=ERROR=
471+
Error: NAT not supported for IPv6 any:n1
472+
Warning: nat:ag is defined, but not bound to any interface
473+
=END=

0 commit comments

Comments
 (0)