Skip to content

Commit

Permalink
fix: acl rule error
Browse files Browse the repository at this point in the history
1. acl rule should not be wrapped with quotation
2. remove empty allow parts
  • Loading branch information
oilbeater committed Apr 19, 2019
1 parent 0cccd53 commit cb2f50d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,20 @@ func (c Client) CleanLogicalSwitchAcl(ls string) error {
}

func (c Client) SetPrivateLogicalSwitch(ls string, allow []string) error {
allowArgs := []string{}
for _, subnet := range allow {
match := fmt.Sprintf(`"ip4.src == %s"`, strings.TrimSpace(subnet))
allowArgs = append(allowArgs, "--", "acl-add", ls, "to-lport", util.SubnetAllowPriority, match, "allow-related")
}
delArgs := []string{"acl-del", ls}
dropArgs := []string{"--", "acl-add", ls, "to-lport", util.DefaultDropPriority, fmt.Sprintf(`inport == "%s-%s"`, ls, c.ClusterRouter), "drop"}
nodeSwitchArgs := []string{"--", "acl-add", ls, "to-lport", util.NodeAllowPriority, fmt.Sprintf(`"ip4.src == %s"`, c.NodeSwitchCIDR), "allow-related"}
dropArgs := []string{"--", "acl-add", ls, "to-lport", util.DefaultDropPriority, fmt.Sprintf(`inport=="%s-%s"`, ls, c.ClusterRouter), "drop"}
nodeSwitchArgs := []string{"--", "acl-add", ls, "to-lport", util.NodeAllowPriority, fmt.Sprintf("ip4.src==%s", c.NodeSwitchCIDR), "allow-related"}

ovnArgs := append(delArgs, dropArgs...)
ovnArgs = append(ovnArgs, nodeSwitchArgs...)

allowArgs := []string{}
for _, subnet := range allow {
if strings.TrimSpace(subnet) != "" {
match := fmt.Sprintf("ip4.src==%s", strings.TrimSpace(subnet))
allowArgs = append(allowArgs, "--", "acl-add", ls, "to-lport", util.SubnetAllowPriority, match, "allow-related")
}
}
ovnArgs = append(ovnArgs, allowArgs...)

_, err := c.ovnNbCommand(ovnArgs...)
Expand Down

0 comments on commit cb2f50d

Please sign in to comment.