diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-04 05:26:31 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-04 05:26:31 -0800 |
commit | 1df56b0786a392b8e84d5dc021ff69af2b2a1824 (patch) | |
tree | 592e834ac52f585b9e55bf9e70b8fd6fbdb65d12 /server/rpki.go | |
parent | 5c835fcc4fa03e74dd03bf7661b65771bf539adc (diff) |
rpki: handle withdraw
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/rpki.go')
-rw-r--r-- | server/rpki.go | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/server/rpki.go b/server/rpki.go index 57a76bc5..d4229d75 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -167,6 +167,27 @@ func (m *roaManager) handleROAEvent(ev *roaClientEvent) { } } +func deleteROA(host string, tree *radix.Tree, as uint32, prefix []byte, prefixLen, maxLen uint8) { + key := table.IpToRadixkey(prefix, prefixLen) + b, _ := tree.Get(key) + if b != nil { + bucket := b.(*roaBucket) + for _, r := range bucket.entries { + if r.MaxLen == maxLen && r.Src == host { + for idx, a := range r.AS { + if a == as { + r.AS = append(r.AS[:idx], r.AS[idx+1:]...) + return + } + } + + } + } + } + p := net.IP(prefix) + log.Info("can't withdraw a roa", p.String(), as, prefixLen, maxLen) +} + func addROA(host string, tree *radix.Tree, as uint32, prefix []byte, prefixLen, maxLen uint8) { key := table.IpToRadixkey(prefix, prefixLen) b, _ := tree.Get(key) @@ -213,9 +234,8 @@ func addROA(host string, tree *radix.Tree, as uint32, prefix []byte, prefixLen, func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerState, buf []byte) { received := &state.RpkiMessages.RpkiReceived - m, _ := bgp.ParseRTR(buf) - if m != nil { - + m, err := bgp.ParseRTR(buf) + if err == nil { switch msg := m.(type) { case *bgp.RTRSerialNotify: client.sessionID = msg.RTRCommon.SessionID @@ -234,7 +254,11 @@ func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta received.Ipv6Prefix++ tree = c.roas[bgp.RF_IPv6_UC] } - addROA(client.host, tree, msg.AS, msg.Prefix, msg.PrefixLen, msg.MaxLen) + if (msg.Flags & 1) == 1 { + addROA(client.host, tree, msg.AS, msg.Prefix, msg.PrefixLen, msg.MaxLen) + } else { + deleteROA(client.host, tree, msg.AS, msg.Prefix, msg.PrefixLen, msg.MaxLen) + } case *bgp.RTREndOfData: received.EndOfData++ client.sessionID = msg.RTRCommon.SessionID @@ -242,9 +266,10 @@ func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta case *bgp.RTRCacheReset: received.CacheReset++ case *bgp.RTRErrorReport: + received.Error++ } } else { - received.Error++ + log.Info("failed to parse a RTR message", client.host) } } |