| 1 | /* |
| 2 | * This file is part of the go-nft project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | * Copyright 2021 Red Hat, Inc. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | package config_testscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ |
| 21 | |
| 22 | import ( |
| 23 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/" |
| 24 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 25 | "testingscip-go gomod github.com/golang/go/src go1.16 testing/" |
| 26 | |
| 27 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/ "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/" |
| 28 | |
| 29 | "github.com/networkplumbing/go-nft/nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/" |
| 30 | "github.com/networkplumbing/go-nft/nft/schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/" |
| 31 | ) |
| 32 | |
| 33 | type ruleActionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleAction# string |
| 34 | |
| 35 | // Rule Actions |
| 36 | const ( |
| 37 | ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD. ruleActionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleAction# = "add" |
| 38 | ruleDELETEscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleDELETE. ruleActionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleAction# = "delete" |
| 39 | ) |
| 40 | |
| 41 | func TestRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/TestRule().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 42 | testAddRuleWithMatchAndVerdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithMatchAndVerdict().(t) |
| 43 | testDeleteRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testDeleteRule().(t) |
| 44 | |
| 45 | testAddRuleWithRowExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithRowExpression().(t) |
| 46 | testAddRuleWithCounterscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithCounter().(t) |
| 47 | testAddRuleWithNATscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithNAT().(t) |
| 48 | |
| 49 | testRuleLookupscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testRuleLookup().(t) |
| 50 | |
| 51 | testReadRuleWithNumericalExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testReadRuleWithNumericalExpression().(t) |
| 52 | } |
| 53 | |
| 54 | func testAddRuleWithRowExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithRowExpression().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 55 | const comment = "mycomment" |
| 56 | |
| 57 | table := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().(tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP.) |
| 58 | chain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table, chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 59 | |
| 60 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Add rule with a row expression, check serialization", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 61 | statements, serializedStatements := matchWithRowExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/matchWithRowExpression().() |
| 62 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 63 | |
| 64 | config := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 65 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 66 | |
| 67 | serializedConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 68 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 69 | |
| 70 | expectedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 71 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, string(expectedConfig), string(serializedConfig)) |
| 72 | }) |
| 73 | |
| 74 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Add rule with a row expression, check deserialization", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 75 | statements, serializedStatements := matchWithRowExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/matchWithRowExpression().() |
| 76 | |
| 77 | serializedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 78 | |
| 79 | var deserializedConfig nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/Config# |
| 80 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(serializedConfig, &deserializedConfig)) |
| 81 | |
| 82 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 83 | expectedConfig := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 84 | expectedConfig.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 85 | |
| 86 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, expectedConfig, &deserializedConfig) |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | func testAddRuleWithMatchAndVerdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithMatchAndVerdict().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 91 | const comment = "mycomment" |
| 92 | |
| 93 | table := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().(tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP.) |
| 94 | chain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table, chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 95 | |
| 96 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Add rule with match and verdict, check serialization", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 97 | statements, serializedStatements := matchSrcIP4withReturnVerdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/matchSrcIP4withReturnVerdict().() |
| 98 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 99 | |
| 100 | config := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 101 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 102 | |
| 103 | serializedConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 104 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 105 | |
| 106 | expectedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 107 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, string(expectedConfig), string(serializedConfig)) |
| 108 | }) |
| 109 | |
| 110 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Add rule with match and verdict, check deserialization", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 111 | statements, serializedStatements := matchSrcIP4withReturnVerdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/matchSrcIP4withReturnVerdict().() |
| 112 | |
| 113 | serializedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 114 | |
| 115 | var deserializedConfig nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/Config# |
| 116 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(serializedConfig, &deserializedConfig)) |
| 117 | |
| 118 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 119 | expectedConfig := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 120 | expectedConfig.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 121 | |
| 122 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, expectedConfig, &deserializedConfig) |
| 123 | }) |
| 124 | } |
| 125 | |
| 126 | func testDeleteRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testDeleteRule().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 127 | table := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().(tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP.) |
| 128 | chain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table, chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 129 | |
| 130 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Delete rule", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 131 | handleID := 100 |
| 132 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, nil, &handleID, nil, "") |
| 133 | |
| 134 | config := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 135 | config.DeleteRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#DeleteRule().(rule) |
| 136 | |
| 137 | serializedConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 138 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 139 | |
| 140 | expectedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleDELETEscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleDELETE., "", &handleID, "") |
| 141 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, string(expectedConfig), string(serializedConfig)) |
| 142 | }) |
| 143 | } |
| 144 | |
| 145 | func buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(action ruleActionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleAction#, serializedStatements string, handle *int, comment string) []byte { |
| 146 | ruleArgs := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`"family":%q,"table":%q,"chain":%q`, nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP., tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 147 | if serializedStatements != "" { |
| 148 | ruleArgs += "," + serializedStatements |
| 149 | } |
| 150 | if handle != nil { |
| 151 | ruleArgs += fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`,"handle":%d`, *handle) |
| 152 | } |
| 153 | if comment != "" { |
| 154 | ruleArgs += fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`,"comment":%q`, comment) |
| 155 | } |
| 156 | |
| 157 | var config string |
| 158 | if action == ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD. { |
| 159 | config = fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`{"nftables":[{"rule":{%s}}]}`, ruleArgs) |
| 160 | } else { |
| 161 | config = fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`{"nftables":[{%q:{"rule":{%s}}}]}`, action, ruleArgs) |
| 162 | } |
| 163 | return []byte(config) |
| 164 | } |
| 165 | |
| 166 | func matchSrcIP4withReturnVerdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/matchSrcIP4withReturnVerdict().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 167 | ipAddress := "10.10.10.10" |
| 168 | matchSrcIP4 := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{ |
| 169 | Matchscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Match.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Matchscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#{ |
| 170 | Opscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#Op.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.OperEQscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/OperEQ., |
| 171 | Leftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#Left.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{ |
| 172 | Payloadscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#Payload.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Payloadscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Payload#{ |
| 173 | Protocolscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Payload#Protocol.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.PayloadProtocolIP4scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PayloadProtocolIP4., |
| 174 | Fieldscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Payload#Field.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.PayloadFieldIPSAddrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PayloadFieldIPSAddr., |
| 175 | }, |
| 176 | }, |
| 177 | Rightscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#Right.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Stringscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#String.: &ipAddress}, |
| 178 | }, |
| 179 | } |
| 180 | |
| 181 | verdict := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 182 | verdict.Returnscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/SimpleVerdict#Return. = true |
| 183 | |
| 184 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{matchSrcIP4, verdict} |
| 185 | |
| 186 | expectedMatch := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().( |
| 187 | `"match":{"op":"==","left":{"payload":{"protocol":"ip","field":"saddr"}},"right":%q}`, ipAddress, |
| 188 | ) |
| 189 | expectedVerdict := `"return":null` |
| 190 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`"expr":[{%s},{%s}]`, expectedMatch, expectedVerdict) |
| 191 | |
| 192 | return statements, serializedStatements |
| 193 | } |
| 194 | |
| 195 | func matchWithRowExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/matchWithRowExpression().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 196 | stringExpression := "string-expression" |
| 197 | rowExpression := `{"foo":"boo"}` |
| 198 | match := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{ |
| 199 | Matchscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Match.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Matchscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#{ |
| 200 | Opscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#Op.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.OperEQscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/OperEQ., |
| 201 | Leftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#Left.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{RowDatascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#RowData.: jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#(rowExpression)}, |
| 202 | Rightscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Match#Right.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Stringscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#String.: &stringExpression}, |
| 203 | }, |
| 204 | } |
| 205 | |
| 206 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{match} |
| 207 | |
| 208 | expectedMatch := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`"match":{"op":"==","left":%s,"right":%q}`, rowExpression, stringExpression) |
| 209 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`"expr":[{%s}]`, expectedMatch) |
| 210 | |
| 211 | return statements, serializedStatements |
| 212 | } |
| 213 | |
| 214 | func testRuleLookupscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testRuleLookup().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 215 | config := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 216 | table_br := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().("table-br", nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyBridge.) |
| 217 | config.AddTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddTable().(table_br) |
| 218 | |
| 219 | chainRegular := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table_br, "chain-regular") |
| 220 | config.AddChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddChain().(chainRegular) |
| 221 | |
| 222 | ruleSimple := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, nil, nil, nil, "comment123") |
| 223 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(ruleSimple) |
| 224 | |
| 225 | ruleWithStatement := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{{}}, nil, nil, "comment456") |
| 226 | ruleWithStatement.Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.[0].Dropscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/SimpleVerdict#Drop. = true |
| 227 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(ruleWithStatement) |
| 228 | |
| 229 | handle := 10 |
| 230 | index := 1 |
| 231 | ruleWithAllParams := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{{}, {}}, &handle, &index, "comment789") |
| 232 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(ruleWithAllParams) |
| 233 | |
| 234 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup an existing rule by table, chain and comment", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 235 | rules := config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(ruleSimple) |
| 236 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Len().(t, rules, 1) |
| 237 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, ruleSimple, rules[0]) |
| 238 | }) |
| 239 | |
| 240 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup an existing rule by table, chain, statement and comment", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 241 | rules := config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(ruleWithStatement) |
| 242 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Len().(t, rules, 1) |
| 243 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, ruleWithStatement, rules[0]) |
| 244 | }) |
| 245 | |
| 246 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup an existing rule by all (root) parameters", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 247 | rules := config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(ruleWithAllParams) |
| 248 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Lenscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Len().(t, rules, 1) |
| 249 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, ruleWithAllParams, rules[0]) |
| 250 | }) |
| 251 | |
| 252 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup a missing rule (comment not matching)", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 253 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, nil, nil, nil, "comment-missing") |
| 254 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Emptyscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Empty().(t, config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(rule)) |
| 255 | }) |
| 256 | |
| 257 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup a missing rule (statement content not matching)", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 258 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{{}}, nil, nil, "comment456") |
| 259 | rule.Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.[0].Dropscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/SimpleVerdict#Drop. = false |
| 260 | rule.Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.[0].Returnscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/SimpleVerdict#Return. = true |
| 261 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Emptyscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Empty().(t, config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(rule)) |
| 262 | }) |
| 263 | |
| 264 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup a missing rule (statements count not matching)", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 265 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{{}, {}}, nil, nil, "comment456") |
| 266 | rule.Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.[0].Dropscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/SimpleVerdict#Drop. = true |
| 267 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Emptyscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Empty().(t, config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(rule)) |
| 268 | }) |
| 269 | |
| 270 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Lookup a missing rule (handle not matching)", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 271 | changedHandle := 99 |
| 272 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table_br, chainRegular, []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{{}, {}}, &changedHandle, &index, "comment789") |
| 273 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Emptyscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Empty().(t, config.LookupRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#LookupRule().(rule)) |
| 274 | }) |
| 275 | } |
| 276 | |
| 277 | func testReadRuleWithNumericalExpressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testReadRuleWithNumericalExpression().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 278 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Read rule with numerical expression", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 279 | c := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 280 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, c.FromJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#FromJSON().([]byte(` |
| 281 | {"nftables":[{"rule":{ |
| 282 | "expr":[{"match":{"op":"==","left":"foo","right":12345}}] |
| 283 | }}]} |
| 284 | `))) |
| 285 | }) |
| 286 | } |
| 287 | |
| 288 | func testAddRuleWithCounterscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithCounter().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 289 | const comment = "mycomment" |
| 290 | |
| 291 | table := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().(tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP.) |
| 292 | chain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table, chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 293 | |
| 294 | statements, serializedStatements := counterStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/counterStatements().() |
| 295 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 296 | |
| 297 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Add rule with counter, check serialization", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 298 | config := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 299 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 300 | |
| 301 | serializedConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 302 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 303 | |
| 304 | expectedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 305 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.JSONEqscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/JSONEq().(t, string(expectedConfig), string(serializedConfig)) |
| 306 | }) |
| 307 | |
| 308 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().("Add rule with counter, check deserialization", func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 309 | serializedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 310 | |
| 311 | var deserializedConfig nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/Config# |
| 312 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(serializedConfig, &deserializedConfig)) |
| 313 | |
| 314 | expectedConfig := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 315 | expectedConfig.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 316 | |
| 317 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, expectedConfig, &deserializedConfig) |
| 318 | }) |
| 319 | } |
| 320 | |
| 321 | func counterStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/counterStatements().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 322 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{{ |
| 323 | Counterscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Counter.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Counterscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Counter#{ |
| 324 | Packetsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Counter#Packets.: 0, |
| 325 | Bytesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Counter#Bytes.: 0, |
| 326 | }, |
| 327 | }} |
| 328 | |
| 329 | expectedCounter := `"counter":{"packets":0,"bytes":0}` |
| 330 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().(`"expr":[{%s}]`, expectedCounter) |
| 331 | |
| 332 | return statements, serializedStatements |
| 333 | } |
| 334 | |
| 335 | func testAddRuleWithNATscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testAddRuleWithNAT().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 336 | tableTests := []struct { |
| 337 | typeName string |
| 338 | createStatements func() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) |
| 339 | }{ |
| 340 | {"dnat", dNATStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/dNATStatements().}, |
| 341 | {"snat", sNATStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/sNATStatements().}, |
| 342 | {"masquerade", masqueradeStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/masqueradeStatements().}, |
| 343 | {"redirect", redirectStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/redirectStatements().}, |
| 344 | } |
| 345 | for _, tt := range tableTests { |
| 346 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("Add rule with %s, check serialization", tt.typeName), func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 347 | testSerializationWithscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testSerializationWith().(t, dNATStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/dNATStatements().) |
| 348 | }) |
| 349 | t.Runscip-go gomod github.com/golang/go/src go1.16 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("Add rule with %s, check deserialization", tt.typeName), func(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 350 | testDeserializationWithscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testDeserializationWith().(t, dNATStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/dNATStatements().) |
| 351 | }) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | func testSerializationWithscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testSerializationWith().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#, createStatements func() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string)) { |
| 356 | const comment = "mycomment" |
| 357 | |
| 358 | table := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().(tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP.) |
| 359 | chain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table, chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 360 | |
| 361 | statements, serializedStatements := createStatements() |
| 362 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 363 | |
| 364 | config := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 365 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 366 | |
| 367 | serializedConfig, err := config.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 368 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 369 | |
| 370 | expectedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 371 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, string(expectedConfig), string(serializedConfig)) |
| 372 | } |
| 373 | |
| 374 | func testDeserializationWithscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/testDeserializationWith().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#, createStatements func() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string)) { |
| 375 | const comment = "mycomment" |
| 376 | |
| 377 | table := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewTable().(tableNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/tableName., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/FamilyIP.) |
| 378 | chain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRegularChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRegularChain().(table, chainNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/chainName.) |
| 379 | |
| 380 | statements, serializedStatements := createStatements() |
| 381 | |
| 382 | serializedConfig := buildSerializedConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/buildSerializedConfig().(ruleADDscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/ruleADD., serializedStatements, nil, comment) |
| 383 | |
| 384 | var deserializedConfig nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.Configscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/Config# |
| 385 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/NoError().(t, jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(serializedConfig, &deserializedConfig)) |
| 386 | |
| 387 | rule := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(table, chain, statements, nil, nil, comment) |
| 388 | expectedConfig := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewConfig().() |
| 389 | expectedConfig.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(rule) |
| 390 | |
| 391 | assertscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.7.0 `github.com/stretchr/testify/require`/Equal().(t, expectedConfig, &deserializedConfig) |
| 392 | } |
| 393 | |
| 394 | func dNATStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/dNATStatements().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 395 | address0 := "1.2.3.4" |
| 396 | addressWithFamily := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 397 | familyIP4 := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyIP. |
| 398 | addressWithFamily.Dnatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Dnat. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Dnatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#{ |
| 399 | Addrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Addr.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Stringscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#String.: &address0}, |
| 400 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Family.: &familyIP4, |
| 401 | } |
| 402 | |
| 403 | portList := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 404 | portList.Dnatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Dnat. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Dnatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#{ |
| 405 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{RowDatascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#RowData.: jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#(`[80,8080]`)}, |
| 406 | } |
| 407 | |
| 408 | var port float64 = 12345 |
| 409 | address1 := "feed::c0fe" |
| 410 | fullHouse := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 411 | familyIP6 := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyIP6scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyIP6. |
| 412 | fullHouse.Dnatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Dnat. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Dnatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#{ |
| 413 | Addrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Addr.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Stringscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#String.: &address1}, |
| 414 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Family.: &familyIP6, |
| 415 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Float64scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#Float64.: &port}, |
| 416 | Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Dnat#Flags.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#{Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#Flags.: []string{schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.NATFlagRandomscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/NATFlagRandom., schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.NATFlagPersistentscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/NATFlagPersistent.}}, |
| 417 | } |
| 418 | |
| 419 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{addressWithFamily, portList, fullHouse} |
| 420 | |
| 421 | expectedDNATIP4 := `"dnat":{"addr":"1.2.3.4","family":"ip"}` |
| 422 | expectedDNATMultiPorts := `"dnat":{"port":[80,8080]}` |
| 423 | expectedDNATIP6PortAndFlags := `"dnat":{"addr":"feed::c0fe","family":"ip6","port":12345,"flags":["random","persistent"]}` |
| 424 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().( |
| 425 | `"expr":[{%s},{%s},{%s}]`, expectedDNATIP4, expectedDNATMultiPorts, expectedDNATIP6PortAndFlags, |
| 426 | ) |
| 427 | |
| 428 | return statements, serializedStatements |
| 429 | } |
| 430 | |
| 431 | func sNATStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/sNATStatements().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 432 | address0 := "1.2.3.4" |
| 433 | addressWithFamily := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 434 | familyIP4 := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyIPscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyIP. |
| 435 | addressWithFamily.Snatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Snat. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Snatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#{ |
| 436 | Addrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Addr.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Stringscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#String.: &address0}, |
| 437 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Family.: &familyIP4, |
| 438 | } |
| 439 | |
| 440 | portList := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 441 | portList.Snatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Snat. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Snatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#{ |
| 442 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{RowDatascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#RowData.: jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#(`[80,8080]`)}, |
| 443 | } |
| 444 | |
| 445 | var port float64 = 12345 |
| 446 | address1 := "feed::c0fe" |
| 447 | fullHouse := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 448 | familyIP6 := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyIP6scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyIP6. |
| 449 | fullHouse.Snatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Snat. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Snatscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#{ |
| 450 | Addrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Addr.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Stringscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#String.: &address1}, |
| 451 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Family.: &familyIP6, |
| 452 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Float64scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#Float64.: &port}, |
| 453 | Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Snat#Flags.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#{Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#Flags.: []string{schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.NATFlagFullyRandomscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/NATFlagFullyRandom.}}, |
| 454 | } |
| 455 | |
| 456 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{addressWithFamily, portList, fullHouse} |
| 457 | |
| 458 | expectedDNATIP4 := `"snat":{"addr":"1.2.3.4","family":"ip"}` |
| 459 | expectedDNATMultiPorts := `"snat":{"port":[80,8080]}` |
| 460 | expectedDNATIP6PortAndFlag := `"snat":{"addr":"feed::c0fe","family":"ip6","port":12345,"flags":"fully-random"}` |
| 461 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().( |
| 462 | `"expr":[{%s},{%s},{%s}]`, expectedDNATIP4, expectedDNATMultiPorts, expectedDNATIP6PortAndFlag, |
| 463 | ) |
| 464 | |
| 465 | return statements, serializedStatements |
| 466 | } |
| 467 | |
| 468 | func masqueradeStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/masqueradeStatements().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 469 | basic := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 470 | basic.Masqueradescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Masquerade. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Masqueradescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#{Enabledscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#Enabled.: true} |
| 471 | |
| 472 | portList := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 473 | portList.Masqueradescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Masquerade. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Masqueradescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#{ |
| 474 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{RowDatascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#RowData.: jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#(`[80,8080]`)}, |
| 475 | } |
| 476 | |
| 477 | var port float64 = 12345 |
| 478 | portAndFlags := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 479 | portAndFlags.Masqueradescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Masquerade. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Masqueradescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#{ |
| 480 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Float64scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#Float64.: &port}, |
| 481 | Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Masquerade#Flags.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#{Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#Flags.: []string{schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.NATFlagFullyRandomscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/NATFlagFullyRandom.}}, |
| 482 | } |
| 483 | |
| 484 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{basic, portList, portAndFlags} |
| 485 | |
| 486 | expectedMasqueradeNoValues := `"masquerade":null` |
| 487 | expectedMasqueradeMultiPorts := `"masquerade":{"port":[80,8080]}` |
| 488 | expectedMasqueradePortAndFlag := `"masquerade":{"port":12345,"flags":"fully-random"}` |
| 489 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().( |
| 490 | `"expr":[{%s},{%s},{%s}]`, |
| 491 | expectedMasqueradeNoValues, expectedMasqueradeMultiPorts, expectedMasqueradePortAndFlag, |
| 492 | ) |
| 493 | |
| 494 | return statements, serializedStatements |
| 495 | } |
| 496 | |
| 497 | func redirectStatementsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config_test`/redirectStatements().() ([]schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#, string) { |
| 498 | basic := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 499 | basic.Redirectscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Redirect. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Redirectscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#{Enabledscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#Enabled.: true} |
| 500 | |
| 501 | portList := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 502 | portList.Redirectscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Redirect. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Redirectscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#{ |
| 503 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{RowDatascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#RowData.: jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage#(`[80,8080]`)}, |
| 504 | } |
| 505 | |
| 506 | var port float64 = 12345 |
| 507 | portAndFlags := schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{} |
| 508 | portAndFlags.Redirectscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nat#Redirect. = &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Redirectscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#{ |
| 509 | Portscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#Port.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Expressionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#{Float64scip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Expression#Float64.: &port}, |
| 510 | Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Redirect#Flags.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#{Flagsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Flags#Flags.: []string{schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.NATFlagFullyRandomscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/NATFlagFullyRandom.}}, |
| 511 | } |
| 512 | |
| 513 | statements := []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Statementscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#{basic, portList, portAndFlags} |
| 514 | |
| 515 | expectedRedirectNoValues := `"redirect":null` |
| 516 | expectedRedirectMultiPorts := `"redirect":{"port":[80,8080]}` |
| 517 | expectedRedirectPortAndFlag := `"redirect":{"port":12345,"flags":"fully-random"}` |
| 518 | serializedStatements := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().( |
| 519 | `"expr":[{%s},{%s},{%s}]`, |
| 520 | expectedRedirectNoValues, expectedRedirectMultiPorts, expectedRedirectPortAndFlag, |
| 521 | ) |
| 522 | |
| 523 | return statements, serializedStatements |
| 524 | } |