Skip to content

Commit 0950a36

Browse files
authored
Merge pull request #279 from mars1024/bugfix/ipmasq_source
change source of ipmasq rule from ipn to ip
2 parents a6a8a81 + 12b426a commit 0950a36

File tree

4 files changed

+134
-44
lines changed

4 files changed

+134
-44
lines changed

Godeps/Godeps.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ip/ipmasq_linux.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
// SetupIPMasq installs iptables rules to masquerade traffic
25-
// coming from ipn and going outside of it
25+
// coming from ip of ipn and going outside of ipn
2626
func SetupIPMasq(ipn *net.IPNet, chain string, comment string) error {
2727
isV6 := ipn.IP.To4() == nil
2828

@@ -70,7 +70,8 @@ func SetupIPMasq(ipn *net.IPNet, chain string, comment string) error {
7070
return err
7171
}
7272

73-
return ipt.AppendUnique("nat", "POSTROUTING", "-s", ipn.String(), "-j", chain, "-m", "comment", "--comment", comment)
73+
// Packets from the specific IP of this network will hit the chain
74+
return ipt.AppendUnique("nat", "POSTROUTING", "-s", ipn.IP.String(), "-j", chain, "-m", "comment", "--comment", comment)
7475
}
7576

7677
// TeardownIPMasq undoes the effects of SetupIPMasq
@@ -89,6 +90,12 @@ func TeardownIPMasq(ipn *net.IPNet, chain string, comment string) error {
8990
return fmt.Errorf("failed to locate iptables: %v", err)
9091
}
9192

93+
err = ipt.Delete("nat", "POSTROUTING", "-s", ipn.IP.String(), "-j", chain, "-m", "comment", "--comment", comment)
94+
if err != nil && !isNotExist(err) {
95+
return err
96+
}
97+
98+
// for downward compatibility
9299
err = ipt.Delete("nat", "POSTROUTING", "-s", ipn.String(), "-j", chain, "-m", "comment", "--comment", comment)
93100
if err != nil && !isNotExist(err) {
94101
return err

plugins/main/ptp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The traffic of the container interface will be routed through the interface of t
2626

2727
* `name` (string, required): the name of the network
2828
* `type` (string, required): "ptp"
29-
* `ipMasq` (boolean, optional): set up IP Masquerade on the host for traffic originating from this network and destined outside of it. Defaults to false.
29+
* `ipMasq` (boolean, optional): set up IP Masquerade on the host for traffic originating from ip of this network and destined outside of this network. Defaults to false.
3030
* `mtu` (integer, optional): explicitly set MTU to the specified value. Defaults to value chosen by the kernel.
3131
* `ipam` (dictionary, required): IPAM configuration to be used for this network.
3232
* `dns` (dictionary, optional): DNS information to return as described in the [Result](https://github.com/containernetworking/cni/blob/master/SPEC.md#result).

vendor/github.com/coreos/go-iptables/iptables/iptables.go

Lines changed: 122 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)