Skip to content

Commit 2819c56

Browse files
tonusoofujita
authored andcommitted
adding support for injecting the prefixes in MRT file only from a specified AS number
1 parent 815ca4c commit 2819c56

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cmd/gobgp/common.go

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ var mrtOpts struct {
117117
SkipV4 bool `long:"no-ipv4" description:"Skip importing IPv4 routes"`
118118
SkipV6 bool `long:"no-ipv4" description:"Skip importing IPv6 routes"`
119119
NextHop net.IP `long:"nexthop" description:"Rewrite nexthop"`
120+
PeerASN uint32 `long:"peer-asn" description:"Inject prefixes only from specified AS number"`
120121
}
121122

122123
var bmpOpts struct {

cmd/gobgp/mrt.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func injectMrt() error {
5757
fmt.Println("You should probably specify either --no-ipv4 or --no-ipv6 when overwriting nexthop, unless your dump contains only one type of routes")
5858
}
5959

60+
if mrtOpts.Best && mrtOpts.PeerASN != 0 {
61+
fmt.Println("--only-best has no effect when --peer-asn is specified")
62+
}
63+
6064
var idx int64
6165
if mrtOpts.QueueSize < 1 {
6266
return fmt.Errorf("specified queue size is smaller than 1, refusing to run with unbounded memory usage")
@@ -132,6 +136,10 @@ func injectMrt() error {
132136
}
133137
//t := time.Unix(int64(e.OriginatedTime), 0)
134138

139+
if mrtOpts.PeerASN != 0 && peers[e.PeerIndex].AS != mrtOpts.PeerASN {
140+
continue
141+
}
142+
135143
var attrs []bgp.PathAttributeInterface
136144
switch subType {
137145
case mrt.RIB_IPV4_UNICAST, mrt.RIB_IPV4_UNICAST_ADDPATH:
@@ -169,7 +177,7 @@ func injectMrt() error {
169177
}
170178

171179
// TODO: calculate properly if necessary.
172-
if mrtOpts.Best {
180+
if mrtOpts.Best && len(paths) > 0 {
173181
paths = []*api.Path{paths[0]}
174182
}
175183

@@ -250,5 +258,6 @@ func newMrtCmd() *cobra.Command {
250258
mrtCmd.PersistentFlags().BoolVarP(&mrtOpts.SkipV6, "no-ipv6", "", false, "Do not import IPv6 routes")
251259
mrtCmd.PersistentFlags().IntVarP(&mrtOpts.QueueSize, "queue-size", "", 1<<10, "Maximum number of updates to keep queued")
252260
mrtCmd.PersistentFlags().IPVarP(&mrtOpts.NextHop, "nexthop", "", nil, "Overwrite nexthop")
261+
mrtCmd.PersistentFlags().Uint32VarP(&mrtOpts.PeerASN, "peer-asn", "", 0, "Inject prefixes only from specified AS number")
253262
return mrtCmd
254263
}

0 commit comments

Comments
 (0)