Skip to content

Commit

Permalink
Merge pull request #40 from hhyasdf/improve/clear-stale-neigh-entries…
Browse files Browse the repository at this point in the history
…-for-overlay

improvement: clear-stale-neigh-entries-for-overlay
  • Loading branch information
mars1024 authored Aug 5, 2021
2 parents 61d7913 + 732c525 commit fc0350c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ All notable changes to this project will be documented in this file.

### Fixed Issues
- Fix error data path for overlay pod to access underlay gateway and excluded ip addresses

## v0.1.2
### Improvements
- Clear stale neigh entries for overlay network
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Rama

[![Go Report Card](https://goreportcard.com/badge/github.com/oecp/rama)](https://goreportcard.com/report/github.com/oecp/rama)
[![Github All Releases](https://img.shields.io/docker/pulls/ramanetworking/rama.svg)](https://hub.docker.com/r/ramanetworking/rama/tags)
[![codecov](https://codecov.io/gh/oecp/rama/branch/main/graphs/badge.svg)](https://codecov.io/gh/oecp/rama)

## What is Rama?

Rama is an open source container networking solution, integrated with Kubernetes and used officially by following well-known PaaS platforms,
Expand Down
21 changes: 21 additions & 0 deletions pkg/daemon/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ func (c *Controller) handleVxlanInterfaceNeighEvent() error {
return fmt.Errorf("parse vtep mac %v failed: %v",
node.Annotations[constants.AnnotationNodeVtepMac], err)
}
} else {
// if ip not exist, try to clear it's neigh entries
if err := neigh.ClearStaleNeighEntryByIP(link.Attrs().Index, ip); err != nil {
return fmt.Errorf("clear stale neigh for link %v and ip %v failed: %v",
link.Attrs().Name, ip.String(), err)
}
}
}

Expand Down Expand Up @@ -363,6 +369,21 @@ func (c *Controller) handleVxlanInterfaceNeighEvent() error {

ch := make(chan netlink.NeighUpdate)

// clear stale neigh entries for vxlan interface at the first time
linkList, err := netlink.LinkList()
if err != nil {
return fmt.Errorf("list link failed: %v", err)
}

for _, link := range linkList {
if strings.Contains(link.Attrs().Name, containernetwork.VxlanLinkInfix) {
if err := neigh.ClearStaleNeighEntries(link.Attrs().Index); err != nil {
return fmt.Errorf("clear stale neigh entries for link %v failed: %v",
link.Attrs().Name, err)
}
}
}

hostNetNs, err := netns.Get()
if err != nil {
return fmt.Errorf("get root netns failed: %v", err)
Expand Down
66 changes: 66 additions & 0 deletions pkg/daemon/neigh/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2021 The Rama Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package neigh

import (
"fmt"
"net"

"github.com/vishvananda/netlink"
)

// If neigh entry not exist, return nil
func ClearStaleNeighEntryByIP(linkIndex int, ip net.IP) error {
family := netlink.FAMILY_V4
if ip.To4() == nil {
family = netlink.FAMILY_V6
}

neighList, err := netlink.NeighList(linkIndex, family)
if err != nil {
return fmt.Errorf("list neigh for link index %v error: %v", linkIndex, err)
}

for _, neigh := range neighList {
if neigh.IP.Equal(ip) && neigh.State == netlink.NUD_STALE {
if err := netlink.NeighDel(&neigh); err != nil {
return fmt.Errorf("del neigh cache %v error: %v", neigh.String(), err)
}
}
}

return nil
}

func ClearStaleNeighEntries(linkIndex int) error {
for _, family := range []int{netlink.FAMILY_V4, netlink.FAMILY_V6} {
neighList, err := netlink.NeighList(linkIndex, family)
if err != nil {
return fmt.Errorf("list neigh for link index %v error: %v", linkIndex, err)
}

for _, neigh := range neighList {
if neigh.State == netlink.NUD_STALE {
if err := netlink.NeighDel(&neigh); err != nil {
return fmt.Errorf("del neigh cache %v error: %v", neigh.String(), err)
}
}
}
}

return nil
}

0 comments on commit fc0350c

Please sign in to comment.