diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-08-29 10:33:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-02 00:14:09 +0900 |
commit | 25ea69e4d3378ee90b142c1cb528e0d3d20629ca (patch) | |
tree | c568939883d2822b286d1b6239f4d8613d717cd4 /zebra | |
parent | 615454451d59e11786fb7756c68c3c693a1fecfe (diff) |
zebra/zapi: Constants for Interface Connected Address Flags
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/zapi.go | 27 | ||||
-rw-r--r-- | zebra/zapi_test.go | 2 |
2 files changed, 26 insertions, 3 deletions
diff --git a/zebra/zapi.go b/zebra/zapi.go index 590bce4c..88c786c5 100644 --- a/zebra/zapi.go +++ b/zebra/zapi.go @@ -122,6 +122,29 @@ func (t INTERFACE_STATUS) String() string { return strings.Join(ss, "|") } +// Interface Connected Address Flags +type INTERFACE_ADDRESS_FLAG uint8 + +const ( + INTERFACE_ADDRESS_SECONDARY INTERFACE_ADDRESS_FLAG = 0x01 + INTERFACE_ADDRESS_PEER INTERFACE_ADDRESS_FLAG = 0x02 + INTERFACE_ADDRESS_UNNUMBERED INTERFACE_ADDRESS_FLAG = 0x04 +) + +func (t INTERFACE_ADDRESS_FLAG) String() string { + ss := make([]string, 0, 3) + if t&INTERFACE_ADDRESS_SECONDARY > 0 { + ss = append(ss, "SECONDARY") + } + if t&INTERFACE_ADDRESS_PEER > 0 { + ss = append(ss, "PEER") + } + if t&INTERFACE_ADDRESS_UNNUMBERED > 0 { + ss = append(ss, "UNNUMBERED") + } + return strings.Join(ss, "|") +} + // Subsequent Address Family Identifier. //go:generate stringer -type=SAFI type SAFI uint8 @@ -685,7 +708,7 @@ func (b *InterfaceUpdateBody) String() string { type InterfaceAddressUpdateBody struct { Index uint32 - Flags uint8 + Flags INTERFACE_ADDRESS_FLAG Prefix net.IP Length uint8 Destination net.IP @@ -693,7 +716,7 @@ type InterfaceAddressUpdateBody struct { func (b *InterfaceAddressUpdateBody) DecodeFromBytes(data []byte, version uint8) error { b.Index = binary.BigEndian.Uint32(data[:4]) - b.Flags = data[4] + b.Flags = INTERFACE_ADDRESS_FLAG(data[4]) family := data[5] var addrlen int8 switch family { diff --git a/zebra/zapi_test.go b/zebra/zapi_test.go index 7763043f..57924812 100644 --- a/zebra/zapi_test.go +++ b/zebra/zapi_test.go @@ -114,7 +114,7 @@ func Test_InterfaceAddressUpdateBody(t *testing.T) { b := &InterfaceAddressUpdateBody{} err := b.DecodeFromBytes(buf, 2) assert.Equal(uint32(0), b.Index) - assert.Equal(uint8(1), b.Flags) + assert.Equal(INTERFACE_ADDRESS_FLAG(1), b.Flags) assert.Equal("192.168.100.1", b.Prefix.String()) assert.Equal(uint8(24), b.Length) assert.Equal("192.168.100.255", b.Destination.String()) |