Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1599ecf0fb | ||
|
|
a57fe8cf1e |
33
mrt/mrt.go
33
mrt/mrt.go
@@ -780,32 +780,35 @@ func DecodeBGP4TD2(buf io.Reader, timestamp time.Time, subtype uint16, length ui
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type mrtBinaryHeader struct {
|
||||
Timestamp uint32
|
||||
Mrttype uint16
|
||||
Mrtsubtype uint16
|
||||
Mrtlength uint32
|
||||
}
|
||||
|
||||
func DecodeSingle(buf io.Reader) (Mrt, error) {
|
||||
var timestamp uint32
|
||||
var mrttype uint16
|
||||
var mrtsubtype uint16
|
||||
var mrtlength uint32
|
||||
hdr := mrtBinaryHeader{}
|
||||
|
||||
binary.Read(buf, binary.BigEndian, ×tamp)
|
||||
binary.Read(buf, binary.BigEndian, &mrttype)
|
||||
binary.Read(buf, binary.BigEndian, &mrtsubtype)
|
||||
binary.Read(buf, binary.BigEndian, &mrtlength)
|
||||
e := binary.Read(buf, binary.BigEndian, &hdr)
|
||||
if e != nil { return nil, e }
|
||||
|
||||
timestampP := time.Unix(int64(timestamp), 0)
|
||||
timestampP := time.Unix(int64(hdr.Timestamp), 0)
|
||||
|
||||
content := make([]byte, mrtlength)
|
||||
binary.Read(buf, binary.BigEndian, &content)
|
||||
content := make([]byte, hdr.Mrtlength)
|
||||
e = binary.Read(buf, binary.BigEndian, &content)
|
||||
if e != nil { return nil, e }
|
||||
tmpbuf := bytes.NewBuffer(content)
|
||||
|
||||
var mrt Mrt
|
||||
var err error
|
||||
switch mrttype {
|
||||
switch hdr.Mrttype {
|
||||
case TYPE_BGP4MP:
|
||||
mrt, err = DecodeBGP4MP(tmpbuf, timestampP, mrtsubtype, mrtlength)
|
||||
mrt, err = DecodeBGP4MP(tmpbuf, timestampP, hdr.Mrtsubtype, hdr.Mrtlength)
|
||||
case TYPE_TABLE_DUMPV2:
|
||||
mrt, err = DecodeBGP4TD2(tmpbuf, timestampP, mrtsubtype, mrtlength)
|
||||
mrt, err = DecodeBGP4TD2(tmpbuf, timestampP, hdr.Mrtsubtype, hdr.Mrtlength)
|
||||
default:
|
||||
err = errors.New(fmt.Sprintf("Decoding of type %v not implemented", mrttype))
|
||||
err = errors.New(fmt.Sprintf("Decoding of type %v not implemented", hdr.Mrttype))
|
||||
}
|
||||
|
||||
return mrt, err
|
||||
|
||||
@@ -197,24 +197,25 @@ func (n *Neighbor) Connect() error {
|
||||
|
||||
func (n *Neighbor) Disconnect() {
|
||||
log.Infof("%v: Disconnected", n.String())
|
||||
wasConnected := n.Connected
|
||||
n.Connected = false
|
||||
n.State.OpenReceived = false
|
||||
n.tcpconn.Close()
|
||||
n.UpdateState(STATE_IDLE)
|
||||
|
||||
if n.HandlerEvent != nil {
|
||||
if n.HandlerEvent != nil && wasConnected == true {
|
||||
n.HandlerEvent.DisconnectedNeighbor(n)
|
||||
}
|
||||
|
||||
if n.RemoveOnDisconnect && n.s != nil && n.s.Manager != nil {
|
||||
log.Infof("%v: Removing from manager", n.String())
|
||||
select {
|
||||
case n.qLife <- true:
|
||||
default:
|
||||
case n.qLife <- true:
|
||||
default:
|
||||
}
|
||||
select {
|
||||
case n.qSender <- true:
|
||||
default:
|
||||
case n.qSender <- true:
|
||||
default:
|
||||
}
|
||||
|
||||
n.s.Manager.RemoveNeighbor(n)
|
||||
|
||||
Reference in New Issue
Block a user