| 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 examplescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/ |
| 21 | |
| 22 | import ( |
| 23 | "testingscip-go gomod github.com/golang/go/src go1.16 testing/" |
| 24 | |
| 25 | 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`/" |
| 26 | |
| 27 | "github.com/networkplumbing/go-nft/tests/testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/" |
| 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 | func TestNoMacSpoofingExamplescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/TestNoMacSpoofingExample().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 34 | testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/.RunTestWithFlushTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/RunTestWithFlushTable().(t, testNoMacSpoofingExamplescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/testNoMacSpoofingExample().) |
| 35 | } |
| 36 | |
| 37 | func testNoMacSpoofingExamplescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/testNoMacSpoofingExample().(t *testingscip-go gomod github.com/golang/go/src go1.16 testing/.Tscip-go gomod github.com/golang/go/src go1.16 testing/T#) { |
| 38 | // The definition of no-mac-spoofing, is to prevent users from modifying an interface mac-address and keep |
| 39 | // connectivity. |
| 40 | // A simple implementation is to allow only a pre-defined number of mac-addresses on egress (filtering the source |
| 41 | // mac) and ingress (filtering the destination mac). |
| 42 | |
| 43 | // User input |
| 44 | var ( |
| 45 | ifaceName = "nic0" |
| 46 | macAddress = "00:00:00:00:00:01" |
| 47 | ) |
| 48 | |
| 49 | desiredConfig := buildNoMacSpoofingConfigImperativelyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/buildNoMacSpoofingConfigImperatively().(ifaceName, macAddress) |
| 50 | 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, desiredConfig, buildNoMacSpoofingConfigDeclerativelyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/buildNoMacSpoofingConfigDecleratively().(ifaceName, macAddress)) |
| 51 | 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, nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.ApplyConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/ApplyConfig().(desiredConfig)) |
| 52 | |
| 53 | actualConfig, err := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.ReadConfigscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/ReadConfig().() |
| 54 | 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) |
| 55 | |
| 56 | expectedNftablesEntries := len(desiredConfig.Nftablesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#Nftables.) + 1 // +1 for the metainfo entry. |
| 57 | 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, actualConfig.Nftablesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#Nftables., expectedNftablesEntries) |
| 58 | |
| 59 | desiredConfig = testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/.NormalizeConfigForComparisonscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/NormalizeConfigForComparison().(desiredConfig) |
| 60 | actualConfig = testlibscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/.NormalizeConfigForComparisonscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/testlib`/NormalizeConfigForComparison().(actualConfig) |
| 61 | |
| 62 | desiredJson, err := desiredConfig.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 63 | 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) |
| 64 | actualJson, err := actualConfig.ToJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#ToJSON().() |
| 65 | 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) |
| 66 | 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(desiredJson), string(actualJson)) |
| 67 | } |
| 68 | |
| 69 | func buildNoMacSpoofingConfigImperativelyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/buildNoMacSpoofingConfigImperatively().(ifaceName string, macAddress string) *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# { |
| 70 | // Configuration Details |
| 71 | var ( |
| 72 | baseChainName = "preroute-bridge" |
| 73 | ifaceChainName = "example-iface-" + ifaceName |
| 74 | macChainName = ifaceChainName + "-mac" |
| 75 | ) |
| 76 | 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().() |
| 77 | |
| 78 | 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().("example", 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.) |
| 79 | config.AddTablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddTable().(table) |
| 80 | |
| 81 | chainType, chainHook, chainPrio, chainPolicy := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.TypeFilterscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/TypeFilter., nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.HookPreRoutingscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/HookPreRouting., -300, nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.PolicyAcceptscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/PolicyAccept. |
| 82 | baseChain := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewChain().(table, baseChainName, &chainType, &chainHook, &chainPrio, &chainPolicy) |
| 83 | config.AddChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddChain().(baseChain) |
| 84 | |
| 85 | ifaceChain := 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, ifaceChainName) |
| 86 | config.AddChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddChain().(ifaceChain) |
| 87 | |
| 88 | macChain := 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, macChainName) |
| 89 | config.AddChainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddChain().(macChain) |
| 90 | |
| 91 | matchIfaceAndJump := []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#{ |
| 92 | {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#{ |
| 93 | 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., |
| 94 | 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.: []byte(`{"meta":{"key":"iifname"}}`)}, |
| 95 | 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.: &ifaceName}, |
| 96 | }}, |
| 97 | {Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#{Jumpscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#Jump.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.ToTargetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#{Targetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#Target.: ifaceChainName}}}, |
| 98 | } |
| 99 | matchIfaceRule := 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, baseChain, matchIfaceAndJump, nil, nil, "match input interface name") |
| 100 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(matchIfaceRule) |
| 101 | |
| 102 | jumpToMACChain := []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#{ |
| 103 | {Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#{Jumpscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#Jump.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.ToTargetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#{Targetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#Target.: macChainName}}}, |
| 104 | } |
| 105 | ifaceRule := 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, ifaceChain, jumpToMACChain, nil, nil, "redirect to mac-chain") |
| 106 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(ifaceRule) |
| 107 | |
| 108 | matchSrcMacAndReturn := []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#{ |
| 109 | {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#{ |
| 110 | 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., |
| 111 | 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#{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#{ |
| 112 | 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`/.PayloadProtocolEtherscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PayloadProtocolEther., |
| 113 | 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`/.PayloadFieldEtherSAddrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PayloadFieldEtherSAddr., |
| 114 | }}, |
| 115 | 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.: &macAddress}, |
| 116 | }}, |
| 117 | {Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Returnscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Return().()}, |
| 118 | } |
| 119 | matchSrcMacRule := 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, macChain, matchSrcMacAndReturn, nil, nil, "match source mac address") |
| 120 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(matchSrcMacRule) |
| 121 | |
| 122 | drop := []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#{{Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Dropscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Drop().()}} |
| 123 | // When multiple rules are added to a chain, index allows to define an order between them. |
| 124 | macRulesIndex := nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRuleIndex().() |
| 125 | dropRule := 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, macChain, drop, nil, macRulesIndex.Nextscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex#Next().(), "drop all the rest") |
| 126 | config.AddRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/config`/Config#AddRule().(dropRule) |
| 127 | |
| 128 | return config |
| 129 | } |
| 130 | |
| 131 | func buildNoMacSpoofingConfigDeclerativelyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/tests/example`/buildNoMacSpoofingConfigDecleratively().(ifaceName string, macAddress string) *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# { |
| 132 | // Configuration Details |
| 133 | const tableName = "example" |
| 134 | var ( |
| 135 | baseChainName = "preroute-bridge" |
| 136 | ifaceChainName = "example-iface-" + ifaceName |
| 137 | macChainName = ifaceChainName + "-mac" |
| 138 | |
| 139 | chainPriority = -300 |
| 140 | |
| 141 | macRulesIndex = nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/.NewRuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRuleIndex().() |
| 142 | ) |
| 143 | |
| 144 | return &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#{schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Rootscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#{Nftablesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#Nftables.: []schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Nftablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#{ |
| 145 | {Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Table.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table#{Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., Namescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table#Name.: tableName}}, |
| 146 | |
| 147 | {Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Chain.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#{ |
| 148 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 149 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Table.: tableName, |
| 150 | Namescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Name.: baseChainName, |
| 151 | Typescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Type.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.TypeFilterscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/TypeFilter., |
| 152 | Hookscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Hook.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.HookPreRoutingscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/HookPreRouting., |
| 153 | Prioscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Prio.: &chainPriority, |
| 154 | Policyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Policy.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.PolicyAcceptscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PolicyAccept., |
| 155 | }}, |
| 156 | {Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Chain.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#{ |
| 157 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 158 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Table.: tableName, |
| 159 | Namescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Name.: ifaceChainName, |
| 160 | }}, |
| 161 | {Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Chain.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#{ |
| 162 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 163 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Table.: tableName, |
| 164 | Namescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Name.: macChainName, |
| 165 | }}, |
| 166 | |
| 167 | {Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Rule.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#{ |
| 168 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 169 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Table.: tableName, |
| 170 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Chain.: baseChainName, |
| 171 | Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.: []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#{ |
| 172 | {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#{ |
| 173 | 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., |
| 174 | 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.: []byte(`{"meta":{"key":"iifname"}}`)}, |
| 175 | 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.: &ifaceName}, |
| 176 | }}, |
| 177 | {Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#{Jumpscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#Jump.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.ToTargetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#{Targetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#Target.: ifaceChainName}}}, |
| 178 | }, |
| 179 | Commentscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Comment.: "match input interface name", |
| 180 | }}, |
| 181 | {Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Rule.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#{ |
| 182 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 183 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Table.: tableName, |
| 184 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Chain.: ifaceChainName, |
| 185 | Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.: []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#{ |
| 186 | {Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#{Jumpscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Verdict#Jump.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.ToTargetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#{Targetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ToTarget#Target.: macChainName}}}, |
| 187 | }, |
| 188 | Commentscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Comment.: "redirect to mac-chain", |
| 189 | }}, |
| 190 | {Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Rule.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#{ |
| 191 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 192 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Table.: tableName, |
| 193 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Chain.: macChainName, |
| 194 | Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.: []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#{ |
| 195 | {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#{ |
| 196 | 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., |
| 197 | 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#{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#{ |
| 198 | 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`/.PayloadProtocolEtherscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PayloadProtocolEther., |
| 199 | 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`/.PayloadFieldEtherSAddrscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/PayloadFieldEtherSAddr., |
| 200 | }}, |
| 201 | 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.: &macAddress}, |
| 202 | }}, |
| 203 | {Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Returnscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Return().()}, |
| 204 | }, |
| 205 | Commentscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Comment.: "match source mac address", |
| 206 | }}, |
| 207 | {Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Rule.: &schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#{ |
| 208 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Family.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.FamilyBridgescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/FamilyBridge., |
| 209 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Table.: tableName, |
| 210 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Chain.: macChainName, |
| 211 | Indexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Index.: macRulesIndex.Nextscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex#Next().(), |
| 212 | Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.: []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#{{Verdictscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Statement#Verdict.: schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/.Dropscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Drop().()}}, |
| 213 | Commentscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Comment.: "drop all the rest", |
| 214 | }}, |
| 215 | }}} |
| 216 | } |