| 1 | // Copyright 2017 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package mainscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/ |
| 16 | |
| 17 | import ( |
| 18 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/" |
| 19 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 20 | "stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/" |
| 21 | |
| 22 | "github.com/coreos/go-iptables/iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/" |
| 23 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 24 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 25 | "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/" |
| 26 | |
| 27 | "github.com/containernetworking/cni/pkg/skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/" |
| 28 | "github.com/containernetworking/cni/pkg/typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/" |
| 29 | types040scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/040`/ "github.com/containernetworking/cni/pkg/types/040scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/040`/" |
| 30 | currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/ "github.com/containernetworking/cni/pkg/types/100scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/" |
| 31 | "github.com/containernetworking/cni/pkg/versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/" |
| 32 | "github.com/containernetworking/plugins/pkg/netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/" |
| 33 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 34 | "github.com/containernetworking/plugins/pkg/testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/" |
| 35 | ) |
| 36 | |
| 37 | func findChainsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findChains().(chains []string) (bool, bool) { |
| 38 | var foundAdmin, foundPriv bool |
| 39 | for _, ch := range chains { |
| 40 | switch ch { |
| 41 | case "CNI-ADMIN": |
| 42 | foundAdmin = true |
| 43 | case "CNI-FORWARD": |
| 44 | foundPriv = true |
| 45 | } |
| 46 | } |
| 47 | return foundAdmin, foundPriv |
| 48 | } |
| 49 | |
| 50 | func findForwardJumpRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardJumpRules().(rules []string) (bool, bool) { |
| 51 | var foundAdmin, foundPriv bool |
| 52 | for _, rule := range rules { |
| 53 | if stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.2 strings/Contains().(rule, "-j CNI-ADMIN") { |
| 54 | foundAdmin = true |
| 55 | } else if stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.2 strings/Contains().(rule, "-j CNI-FORWARD") { |
| 56 | foundPriv = true |
| 57 | } |
| 58 | } |
| 59 | return foundAdmin, foundPriv |
| 60 | } |
| 61 | |
| 62 | func findForwardAllowRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardAllowRules().(rules []string, ip string) (bool, bool) { |
| 63 | var foundOne, foundTwo bool |
| 64 | for _, rule := range rules { |
| 65 | if !stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.24.2 strings/HasSuffix().(rule, "-j ACCEPT") { |
| 66 | continue |
| 67 | } |
| 68 | if stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.2 strings/Contains().(rule, fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(" -s %s ", ip)) { |
| 69 | foundOne = true |
| 70 | } else if stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.2 strings/Contains().(rule, fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(" -d %s ", ip)) && stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.Containsscip-go gomod github.com/golang/go/src go1.24.2 strings/Contains().(rule, "RELATED,ESTABLISHED") { |
| 71 | foundTwo = true |
| 72 | } |
| 73 | } |
| 74 | return foundOne, foundTwo |
| 75 | } |
| 76 | |
| 77 | func getPrevResultscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/getPrevResult().(bytes []byte) *currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Resultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result# { |
| 78 | type TmpConf struct { |
| 79 | typesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/.NetConfscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/NetConf# |
| 80 | RawPrevResult map[string]interface{} `json:"prevResult,omitempty"` |
| 81 | PrevResult *currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.Resultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result# `json:"-"` |
| 82 | } |
| 83 | |
| 84 | conf := &TmpConf{} |
| 85 | err := jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/Unmarshal().(bytes, conf) |
| 86 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 87 | if conf.RawPrevResult == nil { |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | resultBytes, err := jsonscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.24.2 `encoding/json`/Marshal().(conf.RawPrevResult) |
| 92 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 93 | res, err := versionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/.NewResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/version`/NewResult().(conf.CNIVersionscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types`/PluginConf#CNIVersion., resultBytes) |
| 94 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 95 | prevResult, err := currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.NewResultFromResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/NewResultFromResult().(res) |
| 96 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 97 | |
| 98 | return prevResult |
| 99 | } |
| 100 | |
| 101 | func validateFullRulesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/validateFullRuleset().(bytes []byte) { |
| 102 | prevResult := getPrevResultscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/getPrevResult().(bytes) |
| 103 | |
| 104 | for _, ip := range prevResult.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs. { |
| 105 | ipt, err := iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.NewWithProtocolscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/NewWithProtocol().(protoForIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/protoForIP().(ip.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.)) |
| 106 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 107 | |
| 108 | // Ensure chains |
| 109 | chains, err := ipt.ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().("filter") |
| 110 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 111 | foundAdmin, foundPriv := findChainsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findChains().(chains) |
| 112 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundAdmin).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 113 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundPriv).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 114 | |
| 115 | // Look for the FORWARD chain jump rules to our custom chains |
| 116 | rules, err := ipt.Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().("filter", "FORWARD") |
| 117 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 118 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(len(rules)).Shouldscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#Should().(BeNumericallyscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeNumerically().(">", 1)) |
| 119 | _, foundPriv = findForwardJumpRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardJumpRules().(rules) |
| 120 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundPriv).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 121 | |
| 122 | // Look for the allow rules in our custom FORWARD chain |
| 123 | rules, err = ipt.Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().("filter", "CNI-FORWARD") |
| 124 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 125 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(len(rules)).Shouldscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#Should().(BeNumericallyscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeNumerically().(">", 1)) |
| 126 | foundAdmin, _ = findForwardJumpRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardJumpRules().(rules) |
| 127 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundAdmin).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 128 | |
| 129 | // Look for the IP allow rules |
| 130 | foundOne, foundTwo := findForwardAllowRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardAllowRules().(rules, ipStringscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/ipString().(ip.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.)) |
| 131 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundOne).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 132 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundTwo).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | func validateCleanedUpscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/validateCleanedUp().(bytes []byte) { |
| 137 | prevResult := getPrevResultscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/getPrevResult().(bytes) |
| 138 | |
| 139 | for _, ip := range prevResult.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs. { |
| 140 | ipt, err := iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.NewWithProtocolscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/NewWithProtocol().(protoForIPscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/protoForIP().(ip.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.)) |
| 141 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 142 | |
| 143 | // Our private and admin chains don't get cleaned up |
| 144 | chains, err := ipt.ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().("filter") |
| 145 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 146 | foundAdmin, foundPriv := findChainsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findChains().(chains) |
| 147 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundAdmin).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 148 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundPriv).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 149 | |
| 150 | // Look for the FORWARD chain jump rules to our custom chains |
| 151 | rules, err := ipt.Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().("filter", "FORWARD") |
| 152 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 153 | _, foundPriv = findForwardJumpRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardJumpRules().(rules) |
| 154 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundPriv).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 155 | |
| 156 | // Look for the allow rules in our custom FORWARD chain |
| 157 | rules, err = ipt.Listscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#List().("filter", "CNI-FORWARD") |
| 158 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 159 | foundAdmin, _ = findForwardJumpRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardJumpRules().(rules) |
| 160 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundAdmin).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 161 | |
| 162 | // Expect no IP address rules for this IP |
| 163 | foundOne, foundTwo := findForwardAllowRulesscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/findForwardAllowRules().(rules, ipStringscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/ipString().(ip.Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address.)) |
| 164 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundOne).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeFalsescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeFalse().()) |
| 165 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundTwo).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeFalsescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeFalse().()) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | func makeIptablesConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/makeIptablesConf().(ver string) []byte { |
| 170 | return []byte(fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(`{ |
| 171 | "name": "test", |
| 172 | "type": "firewall", |
| 173 | "backend": "iptables", |
| 174 | "ifName": "dummy0", |
| 175 | "cniVersion": "%s", |
| 176 | "prevResult": { |
| 177 | "cniVersion": "%s", |
| 178 | "interfaces": [ |
| 179 | {"name": "dummy0"} |
| 180 | ], |
| 181 | "ips": [ |
| 182 | { |
| 183 | "version": "4", |
| 184 | "address": "10.0.0.2/24", |
| 185 | "interface": 0 |
| 186 | }, |
| 187 | { |
| 188 | "version": "6", |
| 189 | "address": "2001:db8:1:2::1/64", |
| 190 | "interface": 0 |
| 191 | } |
| 192 | ] |
| 193 | } |
| 194 | }`, ver, ver)) |
| 195 | } |
| 196 | |
| 197 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("firewall plugin iptables backend", func() { |
| 198 | var originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS., targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS. nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS# |
| 199 | const IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME. string = "dummy0" |
| 200 | |
| 201 | BeforeEachscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/BeforeEach().(func() { |
| 202 | // Create a new NetNS so we don't modify the host |
| 203 | var errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err. error |
| 204 | originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS., errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err. = testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.NewNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/NewNS().() |
| 205 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err.).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 206 | |
| 207 | errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err. = originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS..Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 208 | defer GinkgoRecoverscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoRecover().() |
| 209 | |
| 210 | linkAttrs := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NewLinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NewLinkAttrs().() |
| 211 | linkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME. |
| 212 | errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err. = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(&netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Dummyscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Dummy#{ |
| 213 | LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Dummy#LinkAttrs.: linkAttrs, |
| 214 | }) |
| 215 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err.).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 216 | _, errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err. = netlinksafescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/.LinkByNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/netlinksafe`/LinkByName().(IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME.) |
| 217 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err.).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 218 | return nil |
| 219 | }) |
| 220 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err.).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 221 | |
| 222 | targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS., errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err. = testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.NewNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/NewNS().() |
| 223 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(errscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:err.).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 224 | }) |
| 225 | |
| 226 | AfterEachscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/AfterEach().(func() { |
| 227 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS..Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().()) |
| 228 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Closescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Close.()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Succeedscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Succeed().()) |
| 229 | }) |
| 230 | |
| 231 | // firewall plugin requires a prevResult and thus only supports 0.3.0 |
| 232 | // and later CNI versions |
| 233 | for _, ver := range []string{"0.3.0", "0.3.1", "0.4.0", "1.0.0"} { |
| 234 | // Redefine ver inside for scope so real value is picked up by each dynamically defined It() |
| 235 | // See Gingkgo's "Patterns for dynamically generating tests" documentation. |
| 236 | ver := ver |
| 237 | |
| 238 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().(fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("[%s] passes prevResult through unchanged", ver), func() { |
| 239 | fullConf := makeIptablesConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/makeIptablesConf().(ver) |
| 240 | args := &skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#{ |
| 241 | ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.: "dummy", |
| 242 | Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.: targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), |
| 243 | IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.: IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., |
| 244 | StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.: fullConf, |
| 245 | } |
| 246 | |
| 247 | err := originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS..Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 248 | defer GinkgoRecoverscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoRecover().() |
| 249 | |
| 250 | r, _, err := testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdAdd().(targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID., IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., fullConf, func() error { |
| 251 | return cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdAdd().(args) |
| 252 | }) |
| 253 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 254 | |
| 255 | result, err := currentscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/.GetResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/GetResult().(r) |
| 256 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 257 | |
| 258 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces.).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(1)) |
| 259 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(result.Interfacesscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#Interfaces.[0].Namescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Interface#Name.).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().(IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME.)) |
| 260 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(HaveLenscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveLen().(2)) |
| 261 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.[0].Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("10.0.0.2/24")) |
| 262 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(result.IPsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/Result#IPs.[1].Addressscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/100`/IPConfig#Address..Stringscip-go gomod github.com/golang/go/src go1.24.2 net/IPNet#String().()).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(Equalscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Equal().("2001:db8:1:2::1/64")) |
| 263 | return nil |
| 264 | }) |
| 265 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 266 | }) |
| 267 | |
| 268 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().(fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("[%s] installs the right iptables rules on the host", ver), func() { |
| 269 | fullConf := makeIptablesConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/makeIptablesConf().(ver) |
| 270 | args := &skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#{ |
| 271 | ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.: "dummy", |
| 272 | Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.: targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), |
| 273 | IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.: IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., |
| 274 | StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.: fullConf, |
| 275 | } |
| 276 | |
| 277 | err := originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS..Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 278 | defer GinkgoRecoverscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoRecover().() |
| 279 | |
| 280 | _, _, err := testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdAdd().(targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID., IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., fullConf, func() error { |
| 281 | return cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdAdd().(args) |
| 282 | }) |
| 283 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 284 | |
| 285 | validateFullRulesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/validateFullRuleset().(fullConf) |
| 286 | |
| 287 | // ensure creation is idempotent |
| 288 | _, _, err = testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdAdd().(targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID., IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., fullConf, func() error { |
| 289 | return cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdAdd().(args) |
| 290 | }) |
| 291 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 292 | |
| 293 | return nil |
| 294 | }) |
| 295 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 296 | }) |
| 297 | |
| 298 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().(fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("[%s] correctly handles a custom IptablesAdminChainName", ver), func() { |
| 299 | conf := []byte(fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(`{ |
| 300 | "name": "test", |
| 301 | "type": "firewall", |
| 302 | "backend": "iptables", |
| 303 | "ifName": "dummy0", |
| 304 | "cniVersion": "%s", |
| 305 | "iptablesAdminChainName": "CNI-foobar", |
| 306 | "prevResult": { |
| 307 | "cniVersion": "%s", |
| 308 | "interfaces": [ |
| 309 | {"name": "dummy0"} |
| 310 | ], |
| 311 | "ips": [ |
| 312 | { |
| 313 | "version": "4", |
| 314 | "address": "10.0.0.2/24", |
| 315 | "interface": 0 |
| 316 | }, |
| 317 | { |
| 318 | "version": "6", |
| 319 | "address": "2001:db8:1:2::1/64", |
| 320 | "interface": 0 |
| 321 | } |
| 322 | ] |
| 323 | } |
| 324 | }`, ver, ver)) |
| 325 | |
| 326 | args := &skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#{ |
| 327 | ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.: "dummy", |
| 328 | Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.: targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), |
| 329 | IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.: IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., |
| 330 | StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.: conf, |
| 331 | } |
| 332 | |
| 333 | err := originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS..Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 334 | defer GinkgoRecoverscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoRecover().() |
| 335 | |
| 336 | _, _, err := testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdAdd().(targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), args.ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID., IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., conf, func() error { |
| 337 | return cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdAdd().(args) |
| 338 | }) |
| 339 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 340 | |
| 341 | var iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:ipt. *iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.IPTablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables# |
| 342 | for _, proto := range []iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.Protocolscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/Protocol#{iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.ProtocolIPv4scip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/ProtocolIPv4., iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.ProtocolIPv6scip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/ProtocolIPv6.} { |
| 343 | iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:ipt., err = iptablesscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/.NewWithProtocolscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/NewWithProtocol().(proto) |
| 344 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 345 | |
| 346 | // Ensure custom admin chain name |
| 347 | chains, err := iptscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:ipt..ListChainsscip-go gomod github.com/coreos/go-iptables v0.8.0 `github.com/coreos/go-iptables/iptables`/IPTables#ListChains().("filter") |
| 348 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 349 | var foundAdminscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:foundAdmin. bool |
| 350 | for _, ch := range chains { |
| 351 | if ch == "CNI-foobar" { |
| 352 | foundAdminscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:foundAdmin. = true |
| 353 | } |
| 354 | } |
| 355 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(foundAdminscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:foundAdmin.).Toscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#To().(BeTruescip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/BeTrue().()) |
| 356 | } |
| 357 | |
| 358 | return nil |
| 359 | }) |
| 360 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 361 | }) |
| 362 | |
| 363 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().(fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("[%s] installs iptables rules, checks rules, then cleans up on delete", ver), func() { |
| 364 | fullConf := makeIptablesConfscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/makeIptablesConf().(ver) |
| 365 | args := &skelscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/.CmdArgsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#{ |
| 366 | ContainerIDscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#ContainerID.: "dummy", |
| 367 | Netnsscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#Netns.: targetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:targetNS..Pathscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Path.(), |
| 368 | IfNamescip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#IfName.: IFNAMEscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:IFNAME., |
| 369 | StdinDatascip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/skel`/CmdArgs#StdinData.: fullConf, |
| 370 | } |
| 371 | |
| 372 | err := originalNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/_:originalNS..Doscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Do.(func(nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.NetNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#) error { |
| 373 | defer GinkgoRecoverscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/GinkgoRecover().() |
| 374 | |
| 375 | r, _, err := testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdAddWithArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdAddWithArgs().(args, func() error { |
| 376 | return cmdAddscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdAdd().(args) |
| 377 | }) |
| 378 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 379 | |
| 380 | _, err = types040scip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/040`/.GetResultscip-go gomod github.com/containernetworking/cni v1.3.0 `github.com/containernetworking/cni/pkg/types/040`/GetResult().(r) |
| 381 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 382 | |
| 383 | if testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.SpecVersionHasCHECKscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/SpecVersionHasCHECK().(ver) { |
| 384 | err = testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdCheckWithArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdCheckWithArgs().(args, func() error { |
| 385 | return cmdCheckscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdCheck().(args) |
| 386 | }) |
| 387 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 388 | validateFullRulesetscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/validateFullRuleset().(fullConf) |
| 389 | } |
| 390 | |
| 391 | err = testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.CmdDelWithArgsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/CmdDelWithArgs().(args, func() error { |
| 392 | return cmdDelscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/cmdDel().(args) |
| 393 | }) |
| 394 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 395 | validateCleanedUpscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/plugins/meta/firewall`/validateCleanedUp().(fullConf) |
| 396 | return nil |
| 397 | }) |
| 398 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 399 | }) |
| 400 | } |
| 401 | }) |