Skip to content

Commit

Permalink
l2: exclude common virtual interfaces for announce services
Browse files Browse the repository at this point in the history
In arp mode, Some common virtual interfaces should not be used to announce services, such as kube-ipvs0, docker0, etc. This PR will dispatch these common virtual interfaces.

Signed-off-by: cyclinder <qifeng.guo@daocloud.io>
  • Loading branch information
cyclinder committed Jan 28, 2023
1 parent f56103a commit d9440a9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/layer2/announcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package layer2
import (
"net"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"

Expand All @@ -26,7 +28,8 @@ type Announce struct {

// This channel can block - do not write to it while holding the mutex
// to avoid deadlocking.
spamCh chan IPAdvertisement
spamCh chan IPAdvertisement
excludeRegexp *regexp.Regexp
}

// New returns an initialized Announce.
Expand All @@ -40,6 +43,13 @@ func New(l log.Logger) (*Announce, error) {
ipRefcnt: map[string]int{},
spamCh: make(chan IPAdvertisement, 1024),
}
excludeRegexp, err := regexp.Compile("(" + strings.Join(DefaultInterfacesToExclude, ")|(") + ")")
if err != nil {
level.Error(l).Log("error", err, "msg", "couldn't get excludeRegexp")
return nil, err
}
ret.excludeRegexp = excludeRegexp

go ret.interfaceScan()
go ret.spamLoop()

Expand Down Expand Up @@ -67,6 +77,12 @@ func (a *Announce) updateInterfaces() {
curIfs := make([]string, 0, len(ifs))
for _, intf := range ifs {
ifi := intf

if (a.excludeRegexp != nil) && a.excludeRegexp.MatchString(ifi.Name) {
level.Info(a.logger).Log("event", "exclude interface", ifi.Name)
continue
}

curIfs = append(curIfs, ifi.Name)
l := log.With(a.logger, "interface", ifi.Name)
addrs, err := ifi.Addrs()
Expand Down Expand Up @@ -337,3 +353,10 @@ const (
dropReasonAnnounceIP
dropReasonNotMatchInterface
)

// DefaultInterfacesToExclude the interfaces in the list not be used to service announce.
var DefaultInterfacesToExclude = []string{
"docker.*", "cbr.*", "dummy.*",
"virbr.*", "lxcbr.*", "veth.*", "lo",
"^cali.*", "^tunl.*", "flannel.*", "kube-ipvs.*", "cni.*", "^nodelocaldns.*",
}

0 comments on commit d9440a9

Please sign in to comment.