summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSergey Elantsev <elantsev.s@yandex.ru>2020-03-29 13:51:41 +0300
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2020-03-29 21:47:56 +0900
commit750aa23633fa9f66cfa816b64077164668203564 (patch)
treeeb0b3b26513f6fac469909ea3a627d8e842a21ea
parent80f18d5bb5438c4be2d15be4ad29d065b467b549 (diff)
fixed naming issue, removed one more error allocation
-rw-r--r--pkg/packet/mrt/mrt.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/pkg/packet/mrt/mrt.go b/pkg/packet/mrt/mrt.go
index 68be3d34..377ce8ab 100644
--- a/pkg/packet/mrt/mrt.go
+++ b/pkg/packet/mrt/mrt.go
@@ -199,10 +199,11 @@ type Peer struct {
AS uint32
}
+var errNotAllPeerBytesAbailable = errors.New("not all Peer bytes are available")
+
func (p *Peer) DecodeFromBytes(data []byte) ([]byte, error) {
- notAllBytesAvail := fmt.Errorf("not all Peer bytes are available")
if len(data) < 5 {
- return nil, notAllBytesAvail
+ return nil, errNotAllPeerBytesAbailable
}
p.Type = uint8(data[0])
p.BgpId = net.IP(data[1:5])
@@ -210,13 +211,13 @@ func (p *Peer) DecodeFromBytes(data []byte) ([]byte, error) {
if p.Type&1 > 0 {
if len(data) < 16 {
- return nil, notAllBytesAvail
+ return nil, errNotAllPeerBytesAbailable
}
p.IpAddress = net.IP(data[:16])
data = data[16:]
} else {
if len(data) < 4 {
- return nil, notAllBytesAvail
+ return nil, errNotAllPeerBytesAbailable
}
p.IpAddress = net.IP(data[:4])
data = data[4:]
@@ -224,13 +225,13 @@ func (p *Peer) DecodeFromBytes(data []byte) ([]byte, error) {
if p.Type&(1<<1) > 0 {
if len(data) < 4 {
- return nil, notAllBytesAvail
+ return nil, errNotAllPeerBytesAbailable
}
p.AS = binary.BigEndian.Uint32(data[:4])
data = data[4:]
} else {
if len(data) < 2 {
- return nil, notAllBytesAvail
+ return nil, errNotAllPeerBytesAbailable
}
p.AS = uint32(binary.BigEndian.Uint16(data[:2]))
data = data[2:]
@@ -292,23 +293,23 @@ type PeerIndexTable struct {
Peers []*Peer
}
-var notAllPeerIndexBytesAvailableErr = errors.New("not all PeerIndexTable bytes are available")
+var errNnotAllPeerIndexBytesAvailable = errors.New("not all PeerIndexTable bytes are available")
func (t *PeerIndexTable) DecodeFromBytes(data []byte) error {
if len(data) < 6 {
- return notAllPeerIndexBytesAvailableErr
+ return errNnotAllPeerIndexBytesAvailable
}
t.CollectorBgpId = net.IP(data[:4])
viewLen := binary.BigEndian.Uint16(data[4:6])
if len(data) < 6+int(viewLen) {
- return notAllPeerIndexBytesAvailableErr
+ return errNnotAllPeerIndexBytesAvailable
}
t.ViewName = string(data[6 : 6+viewLen])
data = data[6+viewLen:]
if len(data) < 2 {
- return notAllPeerIndexBytesAvailableErr
+ return errNnotAllPeerIndexBytesAvailable
}
peerNum := binary.BigEndian.Uint16(data[:2])
data = data[2:]