npc: Add getRuleSpec for ipBlockSpec
This commit is contained in:
1 parent
2e85018c26
commit
0a1ca30aae
1 file changed
+18
-16
+18
-16
@@ -1,6 +1,7 @@
|
|||||||
package npc
|
package npc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -29,22 +30,23 @@ func newIPBlockSpec(ipb *networkingv1.IPBlock) *ipBlockSpec {
|
|||||||
return spec
|
return spec
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (ipb ipBlock) GetRuleSpec() (spec *ruleSpec) {
|
func (spec *ipBlockSpec) getRuleSpec(src bool) ([]string, string) {
|
||||||
// spec = &ruleSpec{
|
dir, dirOpt := "dst", "-d"
|
||||||
// chain: IngressIPBlockChain,
|
if src {
|
||||||
// }
|
dir, dirOpt = "src", "-s"
|
||||||
//
|
}
|
||||||
// if len(ipb.spec.Except) == 0 {
|
|
||||||
// spec.args = append(spec.args, "-s", ipb.spec.CIDR)
|
if spec.key == "" {
|
||||||
// spec.comment = fmt.Sprintf("cidr: %s", ipb.spec.CIDR)
|
rule := []string{dirOpt, spec.ipBlock.CIDR}
|
||||||
// } else {
|
comment := fmt.Sprintf("cidr: %s", spec.ipBlock.CIDR)
|
||||||
// spec.args = append(spec.args, "-s", ipb.spec.CIDR, "-m", "set", "!", "--match-set",
|
return rule, comment
|
||||||
// string(ipb.ipsetName), "src")
|
}
|
||||||
// spec.comment = fmt.Sprintf("cidr: %s except [%s]", ipb.spec.CIDR,
|
|
||||||
// strings.Join(ipb.spec.Except, `,`))
|
rule := []string{dirOpt, spec.ipBlock.CIDR,
|
||||||
// }
|
"-m", "set", "!", "--match-set", string(spec.ipsetName), dir}
|
||||||
// return
|
comment := fmt.Sprintf("cidr: %s except [%s]", spec.ipBlock.CIDR, spec.key)
|
||||||
//}
|
return rule, comment
|
||||||
|
}
|
||||||
|
|
||||||
type ipBlockSet struct {
|
type ipBlockSet struct {
|
||||||
ips ipset.Interface
|
ips ipset.Interface
|
||||||
|
|||||||
Reference in new issue
Block a user