aboutsummaryrefslogtreecommitdiff
path: root/icmp/dstunreach.go
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2015-01-15 01:00:16 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2015-02-06 05:26:11 +0000
commit71586c3cf98f806af322c5a361660eb046e00501 (patch)
tree67f0ebbb7bc897669317e17e1dc5d071141eeed2 /icmp/dstunreach.go
parent074db39ac33144545f748023c2857998d29c613f (diff)
downloadnet-71586c3cf98f806af322c5a361660eb046e00501.tar.gz
icmp: add extensions for MPLS
This change implements ICMP multi-part message marshaler, parser and extensions for MPLS which are used for route trace applications as described in RFC 4950. API breaking changes: type MessageBody interface, Len() int type Extension interface, Len() int type Extension interface, Marshal() ([]byte, error) are replaced with type MessageBody interface, Len(int) int type Extension interface, Len(int) int type Extension interface, Marshal(int) ([]byte, error) Change-Id: Iee1f2e03916d49b8dfe3a89fe682c702d40ecc85 Reviewed-on: https://go-review.googlesource.com/2794 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'icmp/dstunreach.go')
-rw-r--r--icmp/dstunreach.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/icmp/dstunreach.go b/icmp/dstunreach.go
index d1905a9..01dc660 100644
--- a/icmp/dstunreach.go
+++ b/icmp/dstunreach.go
@@ -12,31 +12,30 @@ type DstUnreach struct {
}
// Len implements the Len method of MessageBody interface.
-func (p *DstUnreach) Len() int {
+func (p *DstUnreach) Len(proto int) int {
if p == nil {
return 0
}
- return 4 + len(p.Data)
+ l, _ := multipartMessageBodyDataLen(proto, p.Data, p.Extensions)
+ return l
}
// Marshal implements the Marshal method of MessageBody interface.
func (p *DstUnreach) Marshal(proto int) ([]byte, error) {
- b := make([]byte, 4+len(p.Data))
- copy(b[4:], p.Data)
- return b, nil
+ return marshalMultipartMessageBody(proto, p.Data, p.Extensions)
}
// parseDstUnreach parses b as an ICMP destination unreachable message
// body.
func parseDstUnreach(proto int, b []byte) (MessageBody, error) {
- bodyLen := len(b)
- if bodyLen < 4 {
+ if len(b) < 4 {
return nil, errMessageTooShort
}
p := &DstUnreach{}
- if bodyLen > 4 {
- p.Data = make([]byte, bodyLen-4)
- copy(p.Data, b[4:])
+ var err error
+ p.Data, p.Extensions, err = parseMultipartMessageBody(proto, b)
+ if err != nil {
+ return nil, err
}
return p, nil
}