summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-11 06:55:21 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-11 06:55:21 -0800
commitff4e5662393e6d1147eed62809e6fe9f4d34b0d8 (patch)
tree51183c4457f6ad85e694953b22f7a799842ea231
parentb850c9eeb977bd82950c6590054671e0de563bc5 (diff)
rpki: use io instead of bufio
Seems that sometimes it fails to get the proper data from a socket. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/rpki.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/server/rpki.go b/server/rpki.go
index 711a7c65..0185b3f8 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -16,8 +16,9 @@
package server
import (
- "bufio"
+ "encoding/binary"
"fmt"
+ "io"
"net"
"sort"
"strconv"
@@ -392,7 +393,7 @@ func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta
received.Error++
}
} else {
- log.Info("failed to parse a RTR message", client.host)
+ log.Info("failed to parse a RTR message ", client.host, err)
}
}
@@ -675,16 +676,29 @@ func (c *roaClient) established() error {
return nil
}
- reader := bufio.NewReader(c.conn)
- scanner := bufio.NewScanner(reader)
- scanner.Split(bgp.SplitRTR)
+ for {
+ header := make([]byte, bgp.RTR_MIN_LEN)
+ _, err := io.ReadFull(c.conn, header)
+ if err != nil {
+ break
+ }
+ totalLen := binary.BigEndian.Uint32(header[4:8])
+ if totalLen < bgp.RTR_MIN_LEN {
+ break
+ }
+
+ body := make([]byte, totalLen-bgp.RTR_MIN_LEN)
+ _, err = io.ReadFull(c.conn, body)
+ if err != nil {
+ break
+ }
- for scanner.Scan() {
c.eventCh <- &roaClientEvent{
eventType: RTR,
src: c.host,
- data: scanner.Bytes(),
+ data: append(header, body...),
}
+
}
disconnected()
return nil