@@ -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