| 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 nftscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/ |
| 21 | |
| 22 | import ( |
| 23 | "github.com/networkplumbing/go-nft/nft/schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/" |
| 24 | ) |
| 25 | |
| 26 | // NewRule returns a new schema rule structure. |
| 27 | func NewRulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRule().(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#, 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#, 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#, handle *int, index *int, comment string) *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# { |
| 28 | c := &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#{ |
| 29 | Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Family.: table.Familyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table#Family., |
| 30 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Table.: table.Namescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table#Name., |
| 31 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Chain.: chain.Namescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain#Name., |
| 32 | Exprscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Expr.: expr, |
| 33 | Handlescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Handle.: handle, |
| 34 | Indexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Index.: index, |
| 35 | Commentscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule#Comment.: comment, |
| 36 | } |
| 37 | |
| 38 | return c |
| 39 | } |
| 40 | |
| 41 | type RuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex# int |
| 42 | |
| 43 | // NewRuleIndex returns a rule index object which acts as an iterator. |
| 44 | // When multiple rules are added to a chain, index allows to define an order between them. |
| 45 | // The first rule which is added to a chain should have no index (it is assigned index 0), |
| 46 | // following rules should have the index set, referencing after/before which rule the new one is to be added/inserted. |
| 47 | func NewRuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/NewRuleIndex().() *RuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex# { |
| 48 | var index RuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex# = -1 |
| 49 | return &index |
| 50 | } |
| 51 | |
| 52 | // Next returns the next iteration value as an integer pointer. |
| 53 | // When first time called, it returns the value 0. |
| 54 | func (i *RuleIndexscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex#) Nextscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft`/RuleIndex#Next().() *int { |
| 55 | *i++ |
| 56 | var index = int(*i) |
| 57 | return &index |
| 58 | } |