Skip to content

Commit

Permalink
support masquerade all config
Browse files Browse the repository at this point in the history
Signed-off-by: bingshen.wbs <[email protected]>
  • Loading branch information
BSWANG committed Sep 16, 2022
1 parent f1f128e commit 271041e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugins/meta/portmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type PortMapConf struct {
SNAT *bool `json:"snat,omitempty"`
ConditionsV4 *[]string `json:"conditionsV4"`
ConditionsV6 *[]string `json:"conditionsV6"`
MasqAll bool `json:"masqAll,omitempty"`
MarkMasqBit *int `json:"markMasqBit"`
ExternalSetMarkChain *string `json:"externalSetMarkChain"`
RuntimeConfig struct {
Expand Down
9 changes: 7 additions & 2 deletions plugins/meta/portmap/portmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,18 @@ func fillDnatRules(c *chain, config *PortMapConf, containerNet net.IPNet) {
hpRule := make([]string, len(ruleBase), len(ruleBase)+4)
copy(hpRule, ruleBase)

masqCIDR := containerNet.String()
if config.MasqAll {
masqCIDR = "0.0.0.0/0"
}

hpRule = append(hpRule,
"-s", containerNet.String(),
"-s", masqCIDR,
"-j", setMarkChainName,
)
c.rules = append(c.rules, hpRule)

if !isV6 {
if !isV6 && !config.MasqAll {
// localhost
localRule := make([]string, len(ruleBase), len(ruleBase)+4)
copy(localRule, ruleBase)
Expand Down

0 comments on commit 271041e

Please sign in to comment.