Skip to content

Commit 8a4334f

Browse files
committed
feat: add irr-accept-child-prefixes (#144)
1 parent 2e833de commit 8a4334f

File tree

2 files changed

+55
-37
lines changed

2 files changed

+55
-37
lines changed

pkg/config/config.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,42 @@ type Peer struct {
1313
Disabled *bool `yaml:"disabled" description:"Should the sessions be disabled?" default:"false"`
1414

1515
// BGP Attributes
16-
ASN *int `yaml:"asn" description:"Local ASN" validate:"required" default:"0"`
17-
NeighborIPs *[]string `yaml:"neighbors" description:"List of neighbor IPs" validate:"required,ip" default:"-"`
18-
Prepends *int `yaml:"prepends" description:"Number of times to prepend local AS on export" default:"0"`
19-
PrependPath *[]uint32 `yaml:"prepend-path" description:"List of ASNs to prepend" default:"-"`
20-
ClearPath *bool `yaml:"clear-path" description:"Remove all ASNs from path (before prepends and prepend-path)" default:"false"`
21-
LocalPref *int `yaml:"local-pref" description:"BGP local preference" default:"100"`
22-
SetLocalPref *bool `yaml:"set-local-pref" description:"Should an explicit local pref be set?" default:"true"`
23-
Multihop *bool `yaml:"multihop" description:"Should BGP multihop be enabled? (255 max hops)" default:"false"`
24-
Listen4 *string `yaml:"listen4" description:"IPv4 BGP listen address" default:"-"`
25-
Listen6 *string `yaml:"listen6" description:"IPv6 BGP listen address" default:"-"`
26-
LocalASN *int `yaml:"local-asn" description:"Local ASN as defined in the global ASN field" default:"-"`
27-
LocalPort *int `yaml:"local-port" description:"Local TCP port" default:"179"`
28-
NeighborPort *int `yaml:"neighbor-port" description:"Neighbor TCP port" default:"179"`
29-
Passive *bool `yaml:"passive" description:"Should we listen passively?" default:"false"`
30-
Direct *bool `yaml:"direct" description:"Specify that the neighbor is directly connected" default:"false"`
31-
NextHopSelf *bool `yaml:"next-hop-self" description:"Should BGP next-hop-self be enabled?" default:"false"`
32-
BFD *bool `yaml:"bfd" description:"Should BFD be enabled?" default:"false"`
33-
Password *string `yaml:"password" description:"BGP MD5 password" default:"-"`
34-
RSClient *bool `yaml:"rs-client" description:"Should this peer be a route server client?" default:"false"`
35-
RRClient *bool `yaml:"rr-client" description:"Should this peer be a route reflector client?" default:"false"`
36-
RemovePrivateASNs *bool `yaml:"remove-private-asns" description:"Should private ASNs be removed from path before exporting?" default:"true"`
37-
MPUnicast46 *bool `yaml:"mp-unicast-46" description:"Should this peer be configured with multiprotocol IPv4 and IPv6 unicast?" default:"false"`
38-
AllowLocalAS *bool `yaml:"allow-local-as" description:"Should routes originated by the local ASN be accepted?" default:"false"`
39-
AddPathTx *bool `yaml:"add-path-tx" description:"Enable BGP additional paths on export?" default:"false"`
40-
AddPathRx *bool `yaml:"add-path-rx" description:"Enable BGP additional paths on import?" default:"false"`
41-
ImportNextHop *string `yaml:"import-next-hop" description:"Rewrite the BGP next hop before importing routes learned from this peer" default:"-"`
42-
ExportNextHop *string `yaml:"export-next-hop" description:"Rewrite the BGP next hop before announcing routes to this peer" default:"-"`
43-
Confederation *int `yaml:"confederation" description:"BGP confederation (RFC 5065)" default:"-"`
44-
ConfederationMember *bool `yaml:"confederation-member" description:"Should this peer be a member of the local confederation?" default:"false"`
45-
TTLSecurity *bool `yaml:"ttl-security" description:"RFC 5082 Generalized TTL Security Mechanism" default:"false"`
46-
InterpretCommunities *bool `yaml:"interpret-communities" description:"Should well-known BGP communities be interpreted by their intended action?" default:"true"`
47-
DefaultLocalPref *int `yaml:"default-local-pref" description:"Default value for local preference" default:"-"`
48-
AdvertiseHostname *bool `yaml:"advertise-hostname" description:"Advertise hostname capability" default:"false"`
49-
DisableAfterError *bool `yaml:"disable-after-error" description:"Disable peer after error" default:"false"`
50-
PreferOlderRoutes *bool `yaml:"prefer-older-routes" description:"Prefer older routes instead of comparing router IDs (RFC 5004)" default:"false"`
16+
ASN *int `yaml:"asn" description:"Local ASN" validate:"required" default:"0"`
17+
NeighborIPs *[]string `yaml:"neighbors" description:"List of neighbor IPs" validate:"required,ip" default:"-"`
18+
Prepends *int `yaml:"prepends" description:"Number of times to prepend local AS on export" default:"0"`
19+
PrependPath *[]uint32 `yaml:"prepend-path" description:"List of ASNs to prepend" default:"-"`
20+
ClearPath *bool `yaml:"clear-path" description:"Remove all ASNs from path (before prepends and prepend-path)" default:"false"`
21+
LocalPref *int `yaml:"local-pref" description:"BGP local preference" default:"100"`
22+
SetLocalPref *bool `yaml:"set-local-pref" description:"Should an explicit local pref be set?" default:"true"`
23+
Multihop *bool `yaml:"multihop" description:"Should BGP multihop be enabled? (255 max hops)" default:"false"`
24+
Listen4 *string `yaml:"listen4" description:"IPv4 BGP listen address" default:"-"`
25+
Listen6 *string `yaml:"listen6" description:"IPv6 BGP listen address" default:"-"`
26+
LocalASN *int `yaml:"local-asn" description:"Local ASN as defined in the global ASN field" default:"-"`
27+
LocalPort *int `yaml:"local-port" description:"Local TCP port" default:"179"`
28+
NeighborPort *int `yaml:"neighbor-port" description:"Neighbor TCP port" default:"179"`
29+
Passive *bool `yaml:"passive" description:"Should we listen passively?" default:"false"`
30+
Direct *bool `yaml:"direct" description:"Specify that the neighbor is directly connected" default:"false"`
31+
NextHopSelf *bool `yaml:"next-hop-self" description:"Should BGP next-hop-self be enabled?" default:"false"`
32+
BFD *bool `yaml:"bfd" description:"Should BFD be enabled?" default:"false"`
33+
Password *string `yaml:"password" description:"BGP MD5 password" default:"-"`
34+
RSClient *bool `yaml:"rs-client" description:"Should this peer be a route server client?" default:"false"`
35+
RRClient *bool `yaml:"rr-client" description:"Should this peer be a route reflector client?" default:"false"`
36+
RemovePrivateASNs *bool `yaml:"remove-private-asns" description:"Should private ASNs be removed from path before exporting?" default:"true"`
37+
MPUnicast46 *bool `yaml:"mp-unicast-46" description:"Should this peer be configured with multiprotocol IPv4 and IPv6 unicast?" default:"false"`
38+
AllowLocalAS *bool `yaml:"allow-local-as" description:"Should routes originated by the local ASN be accepted?" default:"false"`
39+
AddPathTx *bool `yaml:"add-path-tx" description:"Enable BGP additional paths on export?" default:"false"`
40+
AddPathRx *bool `yaml:"add-path-rx" description:"Enable BGP additional paths on import?" default:"false"`
41+
ImportNextHop *string `yaml:"import-next-hop" description:"Rewrite the BGP next hop before importing routes learned from this peer" default:"-"`
42+
ExportNextHop *string `yaml:"export-next-hop" description:"Rewrite the BGP next hop before announcing routes to this peer" default:"-"`
43+
Confederation *int `yaml:"confederation" description:"BGP confederation (RFC 5065)" default:"-"`
44+
ConfederationMember *bool `yaml:"confederation-member" description:"Should this peer be a member of the local confederation?" default:"false"`
45+
TTLSecurity *bool `yaml:"ttl-security" description:"RFC 5082 Generalized TTL Security Mechanism" default:"false"`
46+
InterpretCommunities *bool `yaml:"interpret-communities" description:"Should well-known BGP communities be interpreted by their intended action?" default:"true"`
47+
DefaultLocalPref *int `yaml:"default-local-pref" description:"Default value for local preference" default:"-"`
48+
AdvertiseHostname *bool `yaml:"advertise-hostname" description:"Advertise hostname capability" default:"false"`
49+
DisableAfterError *bool `yaml:"disable-after-error" description:"Disable peer after error" default:"false"`
50+
PreferOlderRoutes *bool `yaml:"prefer-older-routes" description:"Prefer older routes instead of comparing router IDs (RFC 5004)" default:"false"`
51+
IRRAcceptChildPrefixes *bool `yaml:"irr-accept-child-prefixes" description:"Accept prefixes up to /24 and /48 from covering parent IRR objects" default:"false"`
5152

5253
ImportCommunities *[]string `yaml:"add-on-import" description:"List of communities to add to all imported routes" default:"-"`
5354
ExportCommunities *[]string `yaml:"add-on-export" description:"List of communities to add to all exported routes" default:"-"`

pkg/irr/irr.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,28 @@ func Update(peerData *config.Peer, irrServer string, queryTimeout uint, bgpqArgs
8585
hasNeighbor4 = true
8686
} else if strings.Contains(n, ":") {
8787
hasNeighbor6 = true
88+
} else {
89+
log.Fatalf("Invalid neighbor IP %s", n)
8890
}
8991
}
9092
}
9193

92-
prefixesFromIRR4, err := PrefixSet(*peerData.ASSet, 4, irrServer, queryTimeout, bgpqArgs)
94+
// Handle acceptChildPrefixes
95+
bgpqArgs4 := bgpqArgs
96+
bgpqArgs6 := bgpqArgs
97+
if peerData.IRRAcceptChildPrefixes != nil && *peerData.IRRAcceptChildPrefixes {
98+
if bgpqArgs4 != "" {
99+
bgpqArgs4 += " "
100+
}
101+
bgpqArgs4 += "-R 24"
102+
103+
if bgpqArgs6 != "" {
104+
bgpqArgs6 += " "
105+
}
106+
bgpqArgs6 += "-R 48"
107+
}
108+
109+
prefixesFromIRR4, err := PrefixSet(*peerData.ASSet, 4, irrServer, queryTimeout, bgpqArgs4)
93110
if err != nil {
94111
return fmt.Errorf("unable to get IPv4 IRR prefix list from %s: %s", *peerData.ASSet, err)
95112
}
@@ -102,7 +119,7 @@ func Update(peerData *config.Peer, irrServer string, queryTimeout uint, bgpqArgs
102119
log.Warnf("peer has IPv4 session(s) but no IPv4 prefixes")
103120
}
104121

105-
prefixesFromIRR6, err := PrefixSet(*peerData.ASSet, 6, irrServer, queryTimeout, bgpqArgs)
122+
prefixesFromIRR6, err := PrefixSet(*peerData.ASSet, 6, irrServer, queryTimeout, bgpqArgs6)
106123
if err != nil {
107124
return fmt.Errorf("unable to get IPv6 IRR prefix list from %s: %s", *peerData.ASSet, err)
108125
}

0 commit comments

Comments
 (0)