diff options
-rw-r--r-- | packet/mrt.go | 8 | ||||
-rw-r--r-- | server/fsm.go | 7 | ||||
-rw-r--r-- | server/server.go | 1 | ||||
-rw-r--r-- | server/watcher.go | 4 |
4 files changed, 16 insertions, 4 deletions
diff --git a/packet/mrt.go b/packet/mrt.go index 7c336684..15dbc839 100644 --- a/packet/mrt.go +++ b/packet/mrt.go @@ -641,8 +641,9 @@ func NewBGP4MPStateChange(peeras, localas uint32, intfindex uint16, peerip, loca type BGP4MPMessage struct { *BGP4MPHeader - BGPMessage *BGPMessage - isLocal bool + BGPMessage *BGPMessage + BGPMessagePayload []byte + isLocal bool } func (m *BGP4MPMessage) DecodeFromBytes(data []byte) error { @@ -668,6 +669,9 @@ func (m *BGP4MPMessage) Serialize() ([]byte, error) { if err != nil { return nil, err } + if m.BGPMessagePayload != nil { + return append(buf, m.BGPMessagePayload...), nil + } bbuf, err := m.BGPMessage.Serialize() if err != nil { return nil, err diff --git a/server/fsm.go b/server/fsm.go index 9377b5a8..15d935bb 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -43,6 +43,7 @@ type FsmMsg struct { MsgData interface{} PathList []*table.Path timestamp time.Time + payload []byte } const ( @@ -471,6 +472,7 @@ func (h *FSMHandler) recvMessageWithError() error { return err } + now := time.Now() m, err := bgp.ParseBGPBody(hd, bodyBuf) if err == nil { h.fsm.bgpMessageStateUpdate(m.Header.Type, true) @@ -482,7 +484,7 @@ func (h *FSMHandler) recvMessageWithError() error { MsgType: FSM_MSG_BGP_MESSAGE, MsgSrc: h.fsm.pConf.NeighborConfig.NeighborAddress.String(), MsgDst: h.fsm.pConf.Transport.TransportConfig.LocalAddress.String(), - timestamp: time.Now(), + timestamp: now, } if err != nil { log.WithFields(log.Fields{ @@ -514,6 +516,9 @@ func (h *FSMHandler) recvMessageWithError() error { h.fsm.peer.ApplyPolicy(table.POLICY_DIRECTION_IN, fmsg.PathList) policyMutex.RUnlock() } + fmsg.payload = make([]byte, len(headerBuf)+len(bodyBuf)) + copy(fmsg.payload, headerBuf) + copy(fmsg.payload[len(headerBuf):], bodyBuf) fallthrough case bgp.BGP_MSG_KEEPALIVE: // if the lenght of h.holdTimerResetCh diff --git a/server/server.go b/server/server.go index 52d917ac..ecdbc8c2 100644 --- a/server/server.go +++ b/server/server.go @@ -801,6 +801,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg, incoming chan * localAddress: net.ParseIP(l), fourBytesAs: y, timestamp: e.timestamp, + payload: e.payload, } for _, ch := range listener { bm := &broadcastWatcherMsg{ diff --git a/server/watcher.go b/server/watcher.go index 73c3f251..d186e9cf 100644 --- a/server/watcher.go +++ b/server/watcher.go @@ -64,6 +64,7 @@ type watcherEventUpdateMsg struct { localAddress net.IP fourBytesAs bool timestamp time.Time + payload []byte } type watcher interface { @@ -115,7 +116,8 @@ func (w *mrtWatcher) loop() error { write := func(ev watcherEvent) { m := ev.(*watcherEventUpdateMsg) subtype := bgp.MESSAGE_AS4 - mp := bgp.NewBGP4MPMessage(m.peerAS, m.localAS, 0, m.peerAddress.String(), m.localAddress.String(), m.fourBytesAs, m.message) + mp := bgp.NewBGP4MPMessage(m.peerAS, m.localAS, 0, m.peerAddress.String(), m.localAddress.String(), m.fourBytesAs, nil) + mp.BGPMessagePayload = m.payload if m.fourBytesAs == false { subtype = bgp.MESSAGE } |