Skip to content

Commit

Permalink
fixing regex logic to get things compiling again, added windows funcs…
Browse files Browse the repository at this point in the history
… for ipv6 so it compiles
  • Loading branch information
luthermonson committed Aug 5, 2021
1 parent 0083735 commit 1378c46
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 60 deletions.
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")
}
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 }
7 changes: 6 additions & 1 deletion pkg/ip/iface_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ package ip
import (
"errors"
"fmt"
"github.com/flannel-io/flannel/pkg/powershell"
"net"

"github.com/flannel-io/flannel/pkg/powershell"
)

// GetInterfaceIP4Addr returns the IPv4 address for the given network interface
Expand Down Expand Up @@ -143,3 +144,7 @@ func IsForwardingEnabledForInterface(iface *net.Interface) (bool, error) {

return powerShellJsonData.Forwarding == 1, nil
}

func GetInterfaceByIP6(ip net.IP) (*net.Interface, error) { return nil, nil }
func GetInterfaceIP6Addr(iface *net.Interface) (net.IP, error) { return nil, nil }
func GetDefaultV6GatewayInterface() (*net.Interface, error) { return nil, nil }

0 comments on commit 1378c46

Please sign in to comment.