Move expect-npc setup from weave script to Go code

This commit is contained in:
Bryan Boreham committed 2017-04-17 19:41:47 +00:00
1 parent a8eb7966b6
commit dd232775e6
3 files changed
+32 -39

No files matched your search

+28 -5
View File
@@ -173,6 +173,7 @@ type BridgeConfig struct {
DatapathName string
NoFastdp bool
NoBridgedFastdp bool
ExpectNPC bool
MTU int
Mac string
Port int
@@ -349,14 +350,36 @@ func configureIPTables(config *BridgeConfig) error {
}
}
// Work around the situation where there are no rules allowing traffic
// across our bridge. E.g. ufw
if err = ipt.AppendUnique("filter", "FORWARD", "-i", config.WeaveBridgeName, "-o", config.WeaveBridgeName, "-j", "ACCEPT"); err != nil {
return err
if config.ExpectNPC {
// Steer traffic via the NPC
ipt.NewChain("filter", "WEAVE-NPC") // ignoring errors such as 'chain already exists'
if err = ipt.AppendUnique("filter", "FORWARD", "-o", config.WeaveBridgeName, "-j", "WEAVE-NPC"); err != nil {
return err
}
if err = ipt.AppendUnique("filter", "FORWARD", "-o", config.WeaveBridgeName, "-m", "state", "--state", "NEW", "-j", "NFLOG", "--nflog-group", "86"); err != nil {
return err
}
if err = ipt.AppendUnique("filter", "FORWARD", "-o", config.WeaveBridgeName, "-j", "DROP"); err != nil {
return err
}
} else {
// Work around the situation where there are no rules allowing traffic
// across our bridge. E.g. ufw
if err = ipt.AppendUnique("filter", "FORWARD", "-i", config.WeaveBridgeName, "-o", config.WeaveBridgeName, "-j", "ACCEPT"); err != nil {
return err
}
// Forward from weave to the rest of the world
if err = ipt.AppendUnique("filter", "FORWARD", "-i", config.WeaveBridgeName, "!", "-o", config.WeaveBridgeName, "-j", "ACCEPT"); err != nil {
return err
}
// and allow replies back
if err = ipt.AppendUnique("filter", "FORWARD", "-o", config.WeaveBridgeName, "-m", "conntrack", "--ctstate", "RELATED,ESTABLISHED", "-j", "ACCEPT"); err != nil {
return err
}
}
// create a chain for masquerading
ipt.NewChain("nat", "WEAVE")
ipt.NewChain("nat", "WEAVE") // ignoring errors such as 'chain already exists'
if err = ipt.AppendUnique("nat", "POSTROUTING", "-j", "WEAVE"); err != nil {
return err
}