summaryrefslogtreecommitdiffhomepage
path: root/packet/rtr.go
diff options
context:
space:
mode:
authorEiichiro Watanabe <a16tochjp@gmail.com>2015-12-09 11:40:24 +0900
committerEiichiro Watanabe <a16tochjp@gmail.com>2015-12-09 12:30:49 +0900
commit86c92e09677875c027cf0aba9f15052b2becdadf (patch)
treed8a49eca74e2e1cd41fd1f25c86f413929c298b0 /packet/rtr.go
parent54addf3f4c04920283ca47f48e89eb07b9acbd55 (diff)
packet: add constructor for RTRErrorReport
Diffstat (limited to 'packet/rtr.go')
-rw-r--r--packet/rtr.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/packet/rtr.go b/packet/rtr.go
index 91a57b32..34186234 100644
--- a/packet/rtr.go
+++ b/packet/rtr.go
@@ -331,6 +331,23 @@ func (m *RTRErrorReport) Serialize() ([]byte, error) {
return data, nil
}
+func NewRTRErrorReport(errCode uint16, errPDU []byte, errMsg []byte) *RTRErrorReport {
+ pdu := &RTRErrorReport{Type: RTR_ERROR_REPORT}
+ if errPDU != nil {
+ if errPDU[1] == RTR_ERROR_REPORT {
+ return nil
+ }
+ pdu.PDULen = uint32(len(errPDU))
+ pdu.PDU = errPDU
+ }
+ if errMsg != nil {
+ pdu.Text = errMsg
+ pdu.TextLen = uint32(len(errMsg))
+ }
+ pdu.Len = uint32(RTR_MIN_LEN) + uint32(RTR_ERROR_REPORT_ERR_PDU_LEN) + pdu.PDULen + uint32(RTR_ERROR_REPORT_ERR_TEXT_LEN) + pdu.TextLen
+ return pdu
+}
+
func SplitRTR(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 || len(data) < RTR_MIN_LEN {
return 0, nil, nil