From 1df56b0786a392b8e84d5dc021ff69af2b2a1824 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Mon, 4 Jan 2016 05:26:31 -0800 Subject: rpki: handle withdraw Signed-off-by: FUJITA Tomonori --- server/rpki.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'server') 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) } } -- cgit v1.2.3