summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChris Stockton <chrisstocktonaz@gmail.com>2018-06-04 15:04:19 -0700
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-06-05 20:13:19 +0900
commit789e24695699d0fe8d0851b6ed005cf4912c7454 (patch)
tree068f0f1c7533d795eb7deace44d5035556dec086
parent98e7b82ffc8a9bdfaccb1de3fc4c9cf71376d567 (diff)
table: fix potential panics in tableKey
It is possible for a call from other Table methods for an interface that does not match the tables route family to reach the type assertion and panic. This change better reflects the intention of the code by checking the concrete type using a type switch instead.
-rw-r--r--table/table.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/table/table.go b/table/table.go
index b26095f8..9d8edf40 100644
--- a/table/table.go
+++ b/table/table.go
@@ -291,18 +291,16 @@ func (t *Table) setDestination(dst *Destination) {
}
func (t *Table) tableKey(nlri bgp.AddrPrefixInterface) string {
- switch t.routeFamily {
- case bgp.RF_IPv4_UC:
+ switch T := nlri.(type) {
+ case *bgp.IPAddrPrefix:
b := make([]byte, 5)
- ip := nlri.(*bgp.IPAddrPrefix)
- copy(b, ip.Prefix.To4())
- b[4] = ip.Length
+ copy(b, T.Prefix.To4())
+ b[4] = T.Length
return *(*string)(unsafe.Pointer(&b))
- case bgp.RF_IPv6_UC:
+ case *bgp.IPv6AddrPrefix:
b := make([]byte, 17)
- ip := nlri.(*bgp.IPv6AddrPrefix)
- copy(b, ip.Prefix.To16())
- b[16] = ip.Length
+ copy(b, T.Prefix.To16())
+ b[16] = T.Length
return *(*string)(unsafe.Pointer(&b))
}
return nlri.String()