From eb80a29bcd66efc836e51ac37e5e19360d4ad077 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Fri, 4 Mar 2016 16:39:15 +0900 Subject: packet: fix FlowSpecComponentItem Len() If FlowSpecComponentItem object is created by API (e.g. CLI), the length info in its Op isn't initialized. So its Len() returns a bogus value. This patch initializes the length info when creating the object instead of its Serialize(). https://github.com/osrg/gobgp/issues/753 Signed-off-by: FUJITA Tomonori --- packet/bgp.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'packet/bgp.go') diff --git a/packet/bgp.go b/packet/bgp.go index 56cbfcd2..32ef2d32 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -2527,20 +2527,6 @@ func (v *FlowSpecComponentItem) Serialize() ([]byte, error) { } order := uint32(math.Log2(float64(v.Len()))) - // we don't know if not initialized properly or initialized to - // zero... - if order == 0 { - order = func() uint32 { - for i := 0; i < 3; i++ { - if v.Value < (1 << ((1 << uint(i)) * 8)) { - return uint32(i) - } - } - // return invalid order - return 4 - }() - } - buf := make([]byte, 1+(1< 3 { + return nil + } + v.Op = int(uint32(v.Op) | order<<4) + return v } type FlowSpecComponent struct { -- cgit v1.2.3