Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package server
import (
"errors"
"io"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"github.com/bio-routing/bio-rd/route"
)
// withDrawPrefixes generates a BGPUpdate message and write it to the given
// io.Writer.
func withDrawPrefixes(out io.Writer, prefixes ...net.Prefix) error {
if len(prefixes) < 1 {
return nil
}
var rootNLRI *packet.NLRI
var currentNLRI *packet.NLRI
for _, pfx := range prefixes {
if rootNLRI == nil {
rootNLRI = &packet.NLRI{
IP: pfx.Addr(),
Pfxlen: pfx.Pfxlen(),
}
currentNLRI = rootNLRI
} else {
currentNLRI.Next = &packet.NLRI{
IP: pfx.Addr(),
Pfxlen: pfx.Pfxlen(),
}
currentNLRI = currentNLRI.Next
}
}
update := &packet.BGPUpdate{
WithdrawnRoutes: rootNLRI,
}
Christoph Petrausch
committed
return serializeAndSendUpdate(out, update)
}
// withDrawPrefixesAddPath generates a BGPUpdateAddPath message and write it to the given
// io.Writer.
func withDrawPrefixesAddPath(out io.Writer, pfx net.Prefix, p *route.Path) error {
if p.Type != route.BGPPathType {
return errors.New("wrong path type, expected BGPPathType")
}
if p.BGPPath == nil {
return errors.New("got nil BGPPath")
}
update := &packet.BGPUpdateAddPath{
WithdrawnRoutes: &packet.NLRIAddPath{
PathIdentifier: p.BGPPath.PathIdentifier,
IP: pfx.Addr(),
Pfxlen: pfx.Pfxlen(),
},
}
Christoph Petrausch
committed
return serializeAndSendUpdate(out, update)