|
@@ -5,7 +5,6 @@ import (
|
|
|
"encoding/json"
|
|
|
"net"
|
|
|
"os"
|
|
|
- "strings"
|
|
|
"sync"
|
|
|
"syscall"
|
|
|
|
|
@@ -49,7 +48,7 @@ func New(sm *subnet.SubnetManager, config json.RawMessage) backend.Backend {
|
|
|
return &be
|
|
|
}
|
|
|
|
|
|
-func (m *UdpBackend) Init(extIface *net.Interface, extIP net.IP, ipMasq bool) (*backend.SubnetDef, error) {
|
|
|
+func (m *UdpBackend) Init(extIface *net.Interface, extIP net.IP) (*backend.SubnetDef, error) {
|
|
|
// Parse our configuration
|
|
|
if len(m.rawCfg) > 0 {
|
|
|
if err := json.Unmarshal(m.rawCfg, &m.cfg); err != nil {
|
|
@@ -81,7 +80,7 @@ func (m *UdpBackend) Init(extIface *net.Interface, extIP net.IP, ipMasq bool) (*
|
|
|
// TUN MTU will be smaller b/c of encap (IP+UDP hdrs)
|
|
|
m.mtu = extIface.MTU - encapOverhead
|
|
|
|
|
|
- if err = m.initTun(ipMasq); err != nil {
|
|
|
+ if err = m.initTun(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
@@ -143,7 +142,7 @@ func newCtlSockets() (*os.File, *os.File, error) {
|
|
|
return f1, f2, nil
|
|
|
}
|
|
|
|
|
|
-func (m *UdpBackend) initTun(ipMasq bool) error {
|
|
|
+func (m *UdpBackend) initTun() error {
|
|
|
var tunName string
|
|
|
var err error
|
|
|
|
|
@@ -157,13 +156,6 @@ func (m *UdpBackend) initTun(ipMasq bool) error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- if ipMasq {
|
|
|
- err = setupIpMasq(m.tunNet.Network(), tunName)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -202,39 +194,6 @@ func configureIface(ifname string, ipn ip.IP4Net, mtu int) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func setupIpMasq(ipn ip.IP4Net, iface string) error {
|
|
|
- ipt, err := ip.NewIPTables()
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("failed to setup IP Masquerade. iptables was not found")
|
|
|
- }
|
|
|
-
|
|
|
- err = ipt.ClearChain("nat", "FLANNEL")
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("Failed to create/clear FLANNEL chain in NAT table: %v", err)
|
|
|
- }
|
|
|
-
|
|
|
- rules := [][]string{
|
|
|
- // This rule makes sure we don't NAT traffic within overlay network (e.g. coming out of docker0)
|
|
|
- []string{"FLANNEL", "-d", ipn.String(), "-j", "ACCEPT"},
|
|
|
- // This rule makes sure we don't NAT multicast traffic within overlay network
|
|
|
- []string{"FLANNEL", "-d", "224.0.0.0/4", "-j", "ACCEPT"}, // This rule will NAT everything originating from our overlay network and
|
|
|
- []string{"FLANNEL", "!", "-o", iface, "-j", "MASQUERADE"},
|
|
|
- // This rule will take everything coming from overlay and sent it to FLANNEL chain
|
|
|
- []string{"POSTROUTING", "-s", ipn.String(), "-j", "FLANNEL"},
|
|
|
- }
|
|
|
-
|
|
|
- for _, args := range rules {
|
|
|
- log.Info("Adding iptables rule: ", strings.Join(args, " "))
|
|
|
-
|
|
|
- err = ipt.AppendUnique("nat", args...)
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("Failed to insert IP masquerade rule: %v", err)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
func (m *UdpBackend) monitorEvents() {
|
|
|
log.Info("Watching for new subnet leases")
|
|
|
|