Compare commits

...

10 Commits

Author SHA1 Message Date
9f96827c7c Merge pull request #369 from Random-Liu/cherrypick-#366-0.7
[Backport v0.7] Fix: failed to set bridge addr: could not add IP address to \"cni0\": file exists
2019-08-13 15:00:55 +02:00
16f134bb58 Fix a race condition in the bridge plugin.
Signed-off-by: Lantao Liu <lantaol@google.com>
2019-08-12 10:17:42 -07:00
a62711a5da Merge pull request #269 from squeed/portmap-prepend
Portmap: append, rather than prepend, entry rules
2019-03-15 11:54:57 -05:00
f8fcb3525f Portmap: append, rather than prepend, entry rules
This means that portmapped connections can be more easily controlled /
firewalled.
2019-03-06 17:17:33 +01:00
9ebe139e77 Merge pull request #194 from squeed/revert-iptables
Revert "vendor: bump coreos/go-iptables"
2018-10-03 10:50:40 -05:00
68326ab5bb Merge pull request #201 from squeed/v0.7-revert
Revert "Merge pull request #180 from squeed/v0.7-bump-iptables"
2018-09-12 10:05:26 -05:00
01ff074ef3 Revert "Merge pull request #180 from squeed/v0.7-bump-iptables"
This reverts commit 19f2f28178, reversing
changes made to 72b62babee.
2018-09-10 14:04:49 +02:00
011c7652c5 Revert "vendor: bump coreos/go-iptables"
This reverts commit ffb78af3af.
2018-08-24 14:24:54 +02:00
19f2f28178 Merge pull request #180 from squeed/v0.7-bump-iptables
vendor: bump coreos/go-iptables
2018-08-03 17:31:42 +02:00
ffb78af3af vendor: bump coreos/go-iptables
Pick up iptables-nftables support.
2018-08-03 15:03:35 +02:00
6 changed files with 28 additions and 10 deletions

View File

@ -170,7 +170,7 @@ func ensureBridgeAddr(br *netlink.Bridge, family int, ipn *net.IPNet, forceAddre
}
addr := &netlink.Addr{IPNet: ipn, Label: ""}
if err := netlink.AddrAdd(br, addr); err != nil {
if err := netlink.AddrAdd(br, addr); err != nil && err != syscall.EEXIST {
return fmt.Errorf("could not add IP address to %q: %v", br.Name, err)
}

View File

@ -29,6 +29,8 @@ type chain struct {
entryRules [][]string // the rules that "point" to this chain
rules [][]string // the rules this chain contains
prependEntry bool // whether or not the entry rules should be prepended
}
// setup idempotently creates the chain. It will not error if the chain exists.
@ -45,19 +47,19 @@ func (c *chain) setup(ipt *iptables.IPTables) error {
}
// Add the rules to the chain
for i := len(c.rules) - 1; i >= 0; i-- {
if err := prependUnique(ipt, c.table, c.name, c.rules[i]); err != nil {
for _, rule := range c.rules {
if err := insertUnique(ipt, c.table, c.name, false, rule); err != nil {
return err
}
}
// Add the entry rules to the entry chains
for _, entryChain := range c.entryChains {
for i := len(c.entryRules) - 1; i >= 0; i-- {
for _, rule := range c.entryRules {
r := []string{}
r = append(r, c.entryRules[i]...)
r = append(r, rule...)
r = append(r, "-j", c.name)
if err := prependUnique(ipt, c.table, entryChain, r); err != nil {
if err := insertUnique(ipt, c.table, entryChain, c.prependEntry, r); err != nil {
return err
}
}
@ -105,8 +107,9 @@ func (c *chain) teardown(ipt *iptables.IPTables) error {
return nil
}
// prependUnique will prepend a rule to a chain, if it does not already exist
func prependUnique(ipt *iptables.IPTables, table, chain string, rule []string) error {
// insertUnique will add a rule to a chain if it does not already exist.
// By default the rule is appended, unless prepend is true.
func insertUnique(ipt *iptables.IPTables, table, chain string, prepend bool, rule []string) error {
exists, err := ipt.Exists(table, chain, rule...)
if err != nil {
return err
@ -115,7 +118,11 @@ func prependUnique(ipt *iptables.IPTables, table, chain string, rule []string) e
return nil
}
return ipt.Insert(table, chain, 1, rule...)
if prepend {
return ipt.Insert(table, chain, 1, rule...)
} else {
return ipt.Append(table, chain, rule...)
}
}
func chainExists(ipt *iptables.IPTables, tableName, chainName string) (bool, error) {

View File

@ -116,8 +116,8 @@ var _ = Describe("chain tests", func() {
Expect(err).NotTo(HaveOccurred())
Expect(haveRules).To(Equal([]string{
"-N " + tlChainName,
"-A " + tlChainName + " -d 203.0.113.1/32 -j " + testChain.name,
"-A " + tlChainName + ` -m comment --comment "canary value" -j ACCEPT`,
"-A " + tlChainName + " -d 203.0.113.1/32 -j " + testChain.name,
}))
// Check that the chain and rule was created

View File

@ -255,6 +255,10 @@ func genMarkMasqChain(markBit int) chain {
table: "nat",
name: MarkMasqChainName,
entryChains: []string{"POSTROUTING"},
// Only this entry chain needs to be prepended, because otherwise it is
// stomped on by the masquerading rules created by the CNI ptp and bridge
// plugins.
prependEntry: true,
entryRules: [][]string{{
"-m", "comment",
"--comment", "CNI portfwd requiring masquerade",

View File

@ -163,6 +163,12 @@ var _ = Describe("portmap integration tests", func() {
fmt.Fprintf(GinkgoWriter, "hostIP: %s:%d, contIP: %s:%d\n",
hostIP, hostPort, contIP, containerPort)
// dump iptables-save output for debugging
cmd = exec.Command("iptables-save")
cmd.Stderr = GinkgoWriter
cmd.Stdout = GinkgoWriter
Expect(cmd.Run()).To(Succeed())
// Sanity check: verify that the container is reachable directly
contOK := testEchoServer(contIP.String(), containerPort, "")

View File

@ -323,6 +323,7 @@ var _ = Describe("portmapping configuration", func() {
"--mark", "0x20/0x20",
"-j", "MASQUERADE",
}},
prependEntry: true,
}))
})
})