-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Flannel to support Windows for host-gw and VXLAN #832
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a00bfc2
flannel: get flannel to build and run on windows
4e73b4c
backend: Support host-gw backed on Windows
rakelkar dfc4099
Merge branch 'master' into rakelkar/windows-hostgw
rakelkar 9fd313b
Support VXLAN (#5)
rakelkar 31b0b86
revert logrus addition - its not needed
rakelkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ cover.out | |
.editorconfig | ||
.idea/ | ||
|
||
default.etcd/ | ||
flannel.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build !linux | ||
|
||
// Copyright 2015 flannel 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 alivpc | ||
|
||
import ( | ||
log "github.com/golang/glog" | ||
) | ||
|
||
func init() { | ||
log.Infof("AliVpc is not supported on this platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build !linux | ||
|
||
// Copyright 2015 flannel 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 awsvpc | ||
|
||
import ( | ||
log "github.com/golang/glog" | ||
) | ||
|
||
func init() { | ||
log.Infof("AWS VPC is not supported on this platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// +build !linux | ||
|
||
// Copyright 2015 flannel 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. | ||
|
||
// This work borrows from the https://github.com/kelseyhightower/flannel-route-manager | ||
// project which has the following license agreement. | ||
|
||
// Copyright (c) 2014 Kelsey Hightower | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
// of the Software, and to permit persons to whom the Software is furnished to do | ||
// so, subject to the following conditions: | ||
|
||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package gce | ||
|
||
import ( | ||
log "github.com/golang/glog" | ||
) | ||
|
||
func init() { | ||
log.Infof("GCE is not supported on this platform") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
// +build windows | ||
|
||
// Copyright 2015 flannel 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 hostgw | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
log "github.com/golang/glog" | ||
"golang.org/x/net/context" | ||
|
||
"github.com/coreos/flannel/backend" | ||
"github.com/coreos/flannel/subnet" | ||
|
||
netroute "github.com/rakelkar/gonetsh/netroute" | ||
) | ||
|
||
type network struct { | ||
name string | ||
extIface *backend.ExternalInterface | ||
linkIndex int | ||
rl []netroute.Route | ||
lease *subnet.Lease | ||
sm subnet.Manager | ||
} | ||
|
||
func (n *network) Lease() *subnet.Lease { | ||
return n.lease | ||
} | ||
|
||
func (n *network) MTU() int { | ||
return n.extIface.Iface.MTU | ||
} | ||
|
||
func (n *network) Run(ctx context.Context) { | ||
wg := sync.WaitGroup{} | ||
|
||
log.Info("Watching for new subnet leases") | ||
evts := make(chan []subnet.Event) | ||
wg.Add(1) | ||
go func() { | ||
subnet.WatchLeases(ctx, n.sm, n.lease, evts) | ||
wg.Done() | ||
}() | ||
|
||
n.rl = make([]netroute.Route, 0, 10) | ||
wg.Add(1) | ||
go func() { | ||
n.routeCheck(ctx) | ||
wg.Done() | ||
}() | ||
|
||
defer wg.Wait() | ||
|
||
for { | ||
select { | ||
case evtBatch := <-evts: | ||
n.handleSubnetEvents(evtBatch) | ||
|
||
case <-ctx.Done(): | ||
return | ||
} | ||
} | ||
} | ||
func (n *network) handleSubnetEvents(batch []subnet.Event) { | ||
nr := netroute.New() | ||
defer nr.Exit() | ||
|
||
for _, evt := range batch { | ||
switch evt.Type { | ||
case subnet.EventAdded: | ||
log.Infof("Subnet added: %v via %v", evt.Lease.Subnet, evt.Lease.Attrs.PublicIP) | ||
|
||
if evt.Lease.Attrs.BackendType != "host-gw" { | ||
log.Warningf("Ignoring non-host-gw subnet: type=%v", evt.Lease.Attrs.BackendType) | ||
continue | ||
} | ||
|
||
route := netroute.Route{ | ||
DestinationSubnet: evt.Lease.Subnet.ToIPNet(), | ||
GatewayAddress: evt.Lease.Attrs.PublicIP.ToIP(), | ||
LinkIndex: n.linkIndex, | ||
} | ||
|
||
existingRoutes, _ := nr.GetNetRoutes(route.LinkIndex, route.DestinationSubnet) | ||
|
||
if existingRoutes != nil && len(existingRoutes) > 0 { | ||
if existingRoutes[0].Equal(route) { | ||
continue | ||
} | ||
|
||
log.Warningf("Replacing existing route to %v via %v with %v via %v.", evt.Lease.Subnet, existingRoutes[0].GatewayAddress, evt.Lease.Subnet, evt.Lease.Attrs.PublicIP) | ||
err := nr.RemoveNetRoute(route.LinkIndex, route.DestinationSubnet, existingRoutes[0].GatewayAddress) | ||
if err != nil { | ||
log.Errorf("Error removing route: %v", err) | ||
continue | ||
} | ||
} | ||
|
||
err := nr.NewNetRoute(route.LinkIndex, route.DestinationSubnet, route.GatewayAddress) | ||
if err != nil { | ||
log.Errorf("Error creating route: %v", err) | ||
} | ||
|
||
n.addToRouteList(route) | ||
|
||
case subnet.EventRemoved: | ||
log.Info("Subnet removed: ", evt.Lease.Subnet) | ||
|
||
if evt.Lease.Attrs.BackendType != "host-gw" { | ||
log.Warningf("Ignoring non-host-gw subnet: type=%v", evt.Lease.Attrs.BackendType) | ||
continue | ||
} | ||
|
||
route := netroute.Route{ | ||
DestinationSubnet: evt.Lease.Subnet.ToIPNet(), | ||
GatewayAddress: evt.Lease.Attrs.PublicIP.ToIP(), | ||
LinkIndex: n.linkIndex, | ||
} | ||
|
||
existingRoutes, _ := nr.GetNetRoutes(route.LinkIndex, route.DestinationSubnet) | ||
|
||
if existingRoutes != nil { | ||
err := nr.RemoveNetRoute(route.LinkIndex, route.DestinationSubnet, route.GatewayAddress) | ||
if err != nil { | ||
log.Errorf("Error removing route: %v", err) | ||
} | ||
} | ||
|
||
n.removeFromRouteList(route) | ||
|
||
default: | ||
log.Error("Internal error: unknown event type: ", int(evt.Type)) | ||
} | ||
} | ||
} | ||
|
||
func (n *network) addToRouteList(route netroute.Route) { | ||
for _, r := range n.rl { | ||
if r.Equal(route) { | ||
return | ||
} | ||
} | ||
n.rl = append(n.rl, route) | ||
} | ||
|
||
func (n *network) removeFromRouteList(route netroute.Route) { | ||
for index, r := range n.rl { | ||
if r.Equal(route) { | ||
n.rl = append(n.rl[:index], n.rl[index+1:]...) | ||
return | ||
} | ||
} | ||
} | ||
|
||
func (n *network) routeCheck(ctx context.Context) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-time.After(routeCheckRetries * time.Second): | ||
n.checkSubnetExistInRoutes() | ||
} | ||
} | ||
} | ||
|
||
func (n *network) checkSubnetExistInRoutes() { | ||
nr := netroute.New() | ||
defer nr.Exit() | ||
|
||
currentRoutes, err := nr.GetNetRoutesAll() | ||
if err != nil { | ||
log.Errorf("Error enumerating routes", err) | ||
return | ||
} | ||
for _, r := range n.rl { | ||
exist := false | ||
for _, currentRoute := range currentRoutes { | ||
if r.Equal(currentRoute) { | ||
exist = true | ||
break | ||
} | ||
} | ||
|
||
if !exist { | ||
err := nr.NewNetRoute(r.LinkIndex, r.DestinationSubnet, r.GatewayAddress) | ||
if err != nil { | ||
log.Errorf("Error recovering route to %v via %v on %v (%v).", r.DestinationSubnet, r.GatewayAddress, r.LinkIndex, err) | ||
continue | ||
} | ||
log.Errorf("Recovered route to %v via %v on %v.", r.DestinationSubnet, r.GatewayAddress, r.LinkIndex) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// +build !linux,!windows | ||
|
||
// Copyright 2015 flannel 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 hostgw | ||
|
||
import ( | ||
log "github.com/golang/glog" | ||
) | ||
|
||
func init() { | ||
log.Infof("hostgw is not supported on this platform") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be added to the glide.* files