1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package network
- import (
- "fmt"
- "strings"
- log "github.com/coreos/flannel/Godeps/_workspace/src/github.com/golang/glog"
- "github.com/coreos/flannel/pkg/ip"
- )
- func setupIPMasq(ipn ip.IP4Net) 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{
-
- {"FLANNEL", "-d", ipn.String(), "-j", "ACCEPT"},
-
- {"FLANNEL", "!", "-d", "224.0.0.0/4", "-j", "MASQUERADE"},
-
- {"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
- }
|