diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-04 12:09:06 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-04 15:09:11 +0900 |
commit | 199d658c2f01b25d42961f6336a38529660c1b92 (patch) | |
tree | 4ac5bf364fe9432c6499c1da80141361b362c97a /packet/bgp.go | |
parent | 80bd1289acf006bb9e4bdf858f0fbe1eabd0a4c7 (diff) |
packet: fix FlowSpecComponent Len()
We don't need to serialize to get the length of FlowSpecComponent.
Also we need to fix FlowSpecComponent()'s serialize bug that it
wrongly assumes that the length can be calculated by it's value.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp.go')
-rw-r--r-- | packet/bgp.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index e136c807..1019d74c 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -2513,6 +2513,10 @@ type FlowSpecComponentItem struct { Value int `json:"value"` } +func (v *FlowSpecComponentItem) Len() int { + return 1 << ((uint32(v.Op) >> 4) & 0x3) +} + func (v *FlowSpecComponentItem) Serialize() ([]byte, error) { if v.Value < 0 { return nil, fmt.Errorf("invalid value size(too small): %d", v.Value) @@ -2605,8 +2609,11 @@ func (p *FlowSpecComponent) Serialize() ([]byte, error) { } func (p *FlowSpecComponent) Len() int { - buf, _ := p.Serialize() - return len(buf) + l := 1 + for _, item := range p.Items { + l += (item.Len() + 1) + } + return l } func (p *FlowSpecComponent) Type() BGPFlowSpecType { |