Skip to content

Commit

Permalink
Merge pull request #1466 from luthermonson/fix-regex
Browse files Browse the repository at this point in the history
fixing regex logic to get things compiling again, added windows funcs for ipv6 so it compiles
  • Loading branch information
luthermonson committed Aug 5, 2021
2 parents 0083735 + 65edc01 commit b75dc70
Show file tree
Hide file tree
Showing 28 changed files with 43 additions and 142 deletions.
2 changes: 1 addition & 1 deletion backend/alivpc/alivpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package alivpc
import (
"encoding/json"
"fmt"
"golang.org/x/net/context"
"os"
"sync"

Expand All @@ -28,6 +27,7 @@ import (
"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
8 changes: 0 additions & 8 deletions backend/alivpc/alivpc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@
// limitations under the License.

package alivpc

import (
log "k8s.io/klog"
)

func init() {
log.Infof("AliVpc is not supported on this platform")
}
3 changes: 1 addition & 2 deletions backend/awsvpc/awsvpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ import (
"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"golang.org/x/net/context"

"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
8 changes: 0 additions & 8 deletions backend/awsvpc/awsvpc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@
// limitations under the License.

package awsvpc

import (
log "k8s.io/klog"
)

func init() {
log.Infof("AWS VPC is not supported on this platform")
}
3 changes: 1 addition & 2 deletions backend/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import (
"net"
"sync"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
)

type ExternalInterface struct {
Expand Down
8 changes: 0 additions & 8 deletions backend/gce/gce_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,3 @@
// SOFTWARE.

package gce

import (
log "k8s.io/klog"
)

func init() {
log.Infof("GCE is not supported on this platform")
}
1 change: 0 additions & 1 deletion backend/hostgw/hostgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package hostgw

import (
"fmt"

"sync"

"github.com/flannel-io/flannel/backend"
Expand Down
8 changes: 0 additions & 8 deletions backend/ipip/ipip_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,3 @@
// +build windows

package ipip

import (
log "k8s.io/klog"
)

func init() {
log.Infof("ipip is not supported on this platform")
}
6 changes: 0 additions & 6 deletions backend/ipsec/ipsec_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@
// limitations under the License.

package ipsec

import log "k8s.io/klog"

func init() {
log.Infof("ipsec is not supported on this platform")
}
3 changes: 1 addition & 2 deletions backend/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"strings"
"sync"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
)

var constructors = make(map[string]BackendCtor)
Expand Down
3 changes: 1 addition & 2 deletions backend/route_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import (
"sync"
"time"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/subnet"
"github.com/vishvananda/netlink"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
3 changes: 1 addition & 2 deletions backend/route_network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
"sync"
"time"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/pkg/routing"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
3 changes: 1 addition & 2 deletions backend/simple_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package backend

import (
"golang.org/x/net/context"

"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
)

type SimpleNetwork struct {
Expand Down
8 changes: 0 additions & 8 deletions backend/tencentvpc/tencentvpc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@
// limitations under the License.

package tencentvpc

import (
log "k8s.io/klog"
)

func init() {
log.Infof("TencentVpc is not supported on this platform")
}
3 changes: 1 addition & 2 deletions backend/udp/udp_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import (
"fmt"
"sync"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions backend/udp/udp_network_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (
"sync"
"syscall"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"github.com/vishvananda/netlink"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
8 changes: 0 additions & 8 deletions backend/udp/udp_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@
// limitations under the License.

package udp

import (
log "k8s.io/klog"
)

func init() {
log.Infof("udp is not supported on this platform")
}
3 changes: 1 addition & 2 deletions backend/vxlan/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ import (
"net"
"sync"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
3 changes: 1 addition & 2 deletions backend/vxlan/vxlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import (
"sync"
"syscall"

"golang.org/x/net/context"

"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"github.com/vishvananda/netlink"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
3 changes: 1 addition & 2 deletions backend/vxlan/vxlan_network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import (
"strings"
"sync"

"golang.org/x/net/context"

"github.com/Microsoft/hcsshim/hcn"
"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
3 changes: 1 addition & 2 deletions backend/vxlan/vxlan_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ import (
"net"
"sync"

"golang.org/x/net/context"

"github.com/Microsoft/hcsshim/hcn"
"github.com/flannel-io/flannel/backend"
"github.com/flannel-io/flannel/pkg/ip"
"github.com/flannel-io/flannel/subnet"
"golang.org/x/net/context"
log "k8s.io/klog"
)

Expand Down
46 changes: 11 additions & 35 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ func main() {
}
}



// Create a backend manager then use it to create the backend and register the network with it.
bm := backend.NewManager(ctx, sm, extIface)
be, err := bm.GetBackend(config.BackendType)
Expand Down Expand Up @@ -521,10 +519,13 @@ func LookupExtIface(ifname string, ifregexS string, ipStack int) (*backend.Exter
var ifaceAddr net.IP
var ifaceV6Addr net.IP
var err error
var ifregex *regexp.Regexp

ifregex, err := regexp.Compile(ifregexS)
if err != nil {
return nil, fmt.Errorf("could not compile the IP address regex '%s': %w", ifregexS, err)
if ifregexS != "" {
ifregex, err = regexp.Compile(ifregexS)
if err != nil {
return nil, fmt.Errorf("could not compile the IP address regex '%s': %w", ifregexS, err)
}
}

// Check ip family stack
Expand Down Expand Up @@ -565,7 +566,7 @@ func LookupExtIface(ifname string, ifregexS string, ipStack int) (*backend.Exter
return nil, fmt.Errorf("error looking up interface %s: %s", ifname, err)
}
}
} else if len(ifregex) > 0 {
} else if ifregex != nil {
// Use the regex if specified and the iface option for matching a specific ip or name is not used
ifaces, err := net.Interfaces()
if err != nil {
Expand All @@ -582,12 +583,7 @@ func LookupExtIface(ifname string, ifregexS string, ipStack int) (*backend.Exter
continue
}

matched, err := ifregex.MatchString(ifaceIP.String())
if err != nil {
return nil, fmt.Errorf("regex error matching pattern %s to %s", ifregexS, ifaceIP.String())
}

if matched {
if ifregex.MatchString(ifaceIP.String()) {
ifaceAddr = ifaceIP
iface = &ifaceToMatch
break
Expand All @@ -599,12 +595,7 @@ func LookupExtIface(ifname string, ifregexS string, ipStack int) (*backend.Exter
continue
}

matched, err := ifregex.MatchString(ifaceIP.String())
if err != nil {
return nil, fmt.Errorf("regex error matching pattern %s to %s", ifregexS, ifaceIP.String())
}

if matched {
if ifregex.MatchString(ifaceIP.String()) {
ifaceV6Addr = ifaceIP
iface = &ifaceToMatch
break
Expand All @@ -616,23 +607,13 @@ func LookupExtIface(ifname string, ifregexS string, ipStack int) (*backend.Exter
continue
}

matched, err := ifregex.MatchString(ifaceIP.String())
if err != nil {
return nil, fmt.Errorf("regex error matching pattern %s to %s", ifregexS, ifaceIP.String())
}

ifaceV6IP, err := ip.GetInterfaceIP6Addr(&ifaceToMatch)
if err != nil {
// Skip if there is no IPv6 address
continue
}

v6Matched, err := ifregex.MatchString(ifaceV6IP.String())
if err != nil {
return nil, fmt.Errorf("regex error matching pattern %s to %s", ifregexS, ifaceIP.String())
}

if matched && v6Matched {
if ifregex.MatchString(ifaceIP.String()) && ifregex.MatchString(ifaceV6IP.String()) {
ifaceAddr = ifaceIP
ifaceV6Addr = ifaceV6IP
iface = &ifaceToMatch
Expand All @@ -644,12 +625,7 @@ func LookupExtIface(ifname string, ifregexS string, ipStack int) (*backend.Exter
// Check Name
if iface == nil && (ifaceAddr == nil || ifaceV6Addr == nil) {
for _, ifaceToMatch := range ifaces {
matched, err := ifregex.MatchString(ifaceToMatch.Name)
if err != nil {
return nil, fmt.Errorf("regex error matching pattern %s to %s", ifregexS, ifaceToMatch.Name)
}

if matched {
if ifregex.MatchString(ifaceToMatch.Name) {
iface = &ifaceToMatch
break
}
Expand Down
26 changes: 8 additions & 18 deletions network/iptables_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,11 @@ type IPTablesRule struct {
rulespec []string
}

func MasqRules(ipn ip.IP4Net, lease *subnet.Lease) []IPTablesRule {
return nil
}

func ForwardRules(flannelNetwork string) []IPTablesRule {
return nil
}

func SetupAndEnsureIPTables(rules []IPTablesRule, resyncPeriod int) {

}

func DeleteIPTables(rules []IPTablesRule) error {
return nil
}

func teardownIPTables(ipt IPTables, rules []IPTablesRule) {
}
func MasqRules(ipn ip.IP4Net, lease *subnet.Lease) []IPTablesRule { return nil }
func ForwardRules(flannelNetwork string) []IPTablesRule { return nil }
func SetupAndEnsureIPTables(rules []IPTablesRule, resyncPeriod int) {}
func DeleteIPTables(rules []IPTablesRule) error { return nil }
func teardownIPTables(ipt IPTables, rules []IPTablesRule) {}
func SetupAndEnsureIP6Tables(rules []IPTablesRule, resyncPeriod int) {}
func MasqIP6Rules(ipn ip.IP6Net, lease *subnet.Lease) []IPTablesRule { return nil }
func DeleteIP6Tables(rules []IPTablesRule) error { return nil }
Loading

0 comments on commit b75dc70

Please sign in to comment.