Skip to content

Commit

Permalink
Merge pull request #4 from spidernet-io/multu_nic
Browse files Browse the repository at this point in the history
fix missing routes in multi-nic mode
  • Loading branch information
cyclinder authored Mar 9, 2023
2 parents d5dcb6f + 16777fc commit e14c55d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
10 changes: 5 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package config
import (
"encoding/json"
"fmt"
"net"
"regexp"
"strings"

"github.com/containernetworking/cni/pkg/version"
"github.com/spidernet-io/cni-plugins/pkg/constant"
"github.com/spidernet-io/plugins/pkg/logging"
"github.com/spidernet-io/plugins/pkg/types"
"k8s.io/utils/pointer"
"net"
"regexp"
"strings"
)

// ParseVethConfig parses the supplied configuration (and prevResult) from stdin.
Expand All @@ -36,7 +36,7 @@ func ParseVethConfig(stdin []byte) (*types.Veth, error) {

conf.LogOptions = logging.InitLogOptions(conf.LogOptions)
if conf.LogOptions.LogFilePath == "" {
conf.LogOptions.LogFilePath = constant.VethLogDefaultFilePath
conf.LogOptions.LogFilePath = types.VethLogDefaultFilePath
}

if conf.OnlyHardware {
Expand Down
28 changes: 15 additions & 13 deletions pkg/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package networking

import (
"fmt"
"net"
"os"
"regexp"
"strings"

cnitypes "github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/plugins/pkg/ns"
Expand All @@ -10,10 +15,6 @@ import (
"github.com/vishvananda/netlink"
"go.uber.org/zap"
"golang.org/x/sys/unix"
"net"
"os"
"regexp"
"strings"
)

var DefaultInterfacesToExclude = []string{
Expand Down Expand Up @@ -86,21 +87,22 @@ func IPAddressOnNode(logger *zap.Logger, ipFamily int) ([]netlink.Addr, error) {
return nil, err
}

var ipAddress []netlink.Addr
for _, link := range links {
exclude := (excludeRegexp != nil) && excludeRegexp.MatchString(link.Attrs().Name)
if exclude {
var allIPAddress []netlink.Addr
for idx, _ := range links {
iLink := links[idx]
if excludeRegexp.MatchString(iLink.Attrs().Name) {
continue
}

ipAddress, err = getAddrs(link, ipFamily)
ipAddress, err := getAddrs(iLink, ipFamily)
if err != nil {
logger.Error(err.Error())
return nil, err
}
allIPAddress = append(allIPAddress, ipAddress...)
}
logger.Debug("Get IPAddressOnNode", zap.Any("IPAddress", ipAddress))
return ipAddress, nil
logger.Debug("Get IPAddressOnNode", zap.Any("allIPAddress", allIPAddress))
return allIPAddress, nil
}

func getAddrs(link netlink.Link, ipfamily int) ([]netlink.Addr, error) {
Expand All @@ -114,10 +116,10 @@ func getAddrs(link netlink.Link, ipfamily int) ([]netlink.Addr, error) {
if addr.IP.IsMulticast() || addr.IP.IsLinkLocalUnicast() {
continue
}
if addr.IP.To4() != nil && (ipfamily == netlink.FAMILY_V4 || ipfamily == netlink.FAMILY_ALL) {
if addr.IP.To4() != nil && ipfamily != netlink.FAMILY_V6 {
ipAddress = append(ipAddress, addr)
}
if addr.IP.To4() == nil && (ipfamily == netlink.FAMILY_V6 || ipfamily == netlink.FAMILY_ALL) {
if addr.IP.To4() == nil && ipfamily != netlink.FAMILY_V4 {
ipAddress = append(ipAddress, addr)
}
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package types

import (
"github.com/containernetworking/cni/pkg/types"
"net"

"github.com/containernetworking/cni/pkg/types"
)

type MoveRouteValue int32
Expand Down Expand Up @@ -50,3 +51,11 @@ type K8sArgs struct {
K8S_POD_INFRA_CONTAINER_ID types.UnmarshallableString //revive:disable-line
K8S_POD_UID types.UnmarshallableString //revive:disable-line
}

const (
VethLogDefaultFilePath = "/var/log/spider-io/veth.log"
RouterLogDefaultFilePath = "/var/log/spider-io/router.log"
LogDefaultMaxSize = 100 // megabytes
LogDefaultMaxAge = 5 // days
LogDefaultMaxBackups = 5
)
1 change: 1 addition & 0 deletions plugins/veth/veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func setupNeighborhood(logger *zap.Logger, netns ns.NetNS, hostVethPairName stri
}

if !isfirstInterface {
// In the pod, we have already add neighbor table, so exit...
return nil
}

Expand Down

0 comments on commit e14c55d

Please sign in to comment.