-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement nftables rules expressions #592
Merged
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6b933e4
nftables: Adding meta keys in NLA nft_meta
inemajo 1da292c
nftables: Adding verdict_code from verdict NLA
inemajo d0e60f9
nftables: Adding nat_flag NLA
inemajo 8810f08
nftables: fix nft_set_msg and add set_flags NLA
inemajo add929e
nftables: adding flags for nft_lookup NLA
inemajo a3e99ba
nftables: fix implementation of nft_exthdr NLA
inemajo 7ecabaf
nftables: adding dynset expression. NOTE: NFTA_DYNSET_EXPR is a rule_…
inemajo 1296883
nftables: Adding nft_match NLA
inemajo 8eaa7f9
nftables: Adding nft_target NLA
inemajo 46df388
nftables: Create a parser module.
inemajo 3e169c5
nftables: Create Rule object and parser for expressions
inemajo c2ea524
nftables: expr parser adding a class for parsing expressions
inemajo 06a3e79
nftables: adding nftreg for expr parser
inemajo 0cd161b
nftables: parser: expr: Adding the replaxce_str class
inemajo e1b2059
nftables: parser: adding meta expression
inemajo 7ebdfef
nftables: parser: expr: adding NFTVerdict and NFTData classes
inemajo 9df8203
nftables: parser: adding cmp expression
inemajo bbc1743
nftables: parser: parser: adding __repr__
inemajo c7cc031
nftables: parser/expr: Adding ExprImmediate
inemajo 4e13ddb
nftables: parser/expr: Adding ExprPayload
inemajo 773a0b4
nftables: parser/expr: Adding ExprLookup
inemajo 22571a3
nftables: parser/expr: Adding ExprNat
inemajo d66d8fa
nftables: parser/expr: Adding ExprBitwise
inemajo dcc8260
nftables: parser/expr: Adding ExprCounter
inemajo 3360d1c
nftables: parser/expr: Adding ExprMatch
inemajo 187a176
nftables: parser/expr: Adding ExprTarget
inemajo 7683d3e
nftables: parser: passing from ascci to raw
inemajo a88bee2
nftables: flake8
inemajo 41d88d4
nftables: rule: Adding nfproto family
inemajo 947a179
nftables: Adding tests
inemajo fa30212
test_nftables: Remove debug comment, raise SkipTest than Exception
inemajo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import json | ||
import errno | ||
from subprocess import check_output, CalledProcessError | ||
|
||
from pyroute2 import netns | ||
from pyroute2.nftables.main import NFTables | ||
from pyroute2.nftables.rule import NFTRule | ||
|
||
from utils import require_user | ||
|
||
#NFT_BIN_PATH = "/root/nft/nftables/src/nft" | ||
NFT_BIN_PATH = "nft" | ||
NS_NAME = 'pyroute2_test_nftable' | ||
|
||
|
||
class NFTables_test(object): | ||
|
||
def setup(self): | ||
require_user('root') | ||
try: | ||
netns.create(NS_NAME) | ||
except OSError as e: | ||
if e.errno == errno.EEXIST: | ||
netns.remove(NS_NAME) | ||
netns.create(NS_NAME) | ||
else: | ||
raise | ||
try: | ||
check_output([NFT_BIN_PATH, "-f", "nftables.ruleset"]) | ||
except OSError as e: | ||
if e.errno == errno.ENOENT: | ||
raise Exception("You must install nftables for the test") | ||
else: | ||
raise | ||
|
||
def teardown(self): | ||
netns.remove(NS_NAME) | ||
|
||
def test_export_json(self): | ||
try: | ||
nft_res = json.loads( | ||
check_output([NFT_BIN_PATH, "export", "json"])) | ||
except CalledProcessError: | ||
raise Exception( | ||
"Please install nft compiled with --with-json option") | ||
nft_res = [e['rule'] for e in nft_res['nftables'] if 'rule' in e] | ||
my_res = [] | ||
for r in NFTables(nfgen_family=0).get_rules(): | ||
my_res.append(NFTRule.from_netlink(r).to_dict()) | ||
assert my_res == nft_res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
flush ruleset | ||
|
||
table inet filter { | ||
chain coucou { | ||
accept | ||
} | ||
chain input { | ||
type filter hook input priority 0; policy accept; | ||
meta l4proto tcp tcp dport 1234 accept | ||
iifname lo0 oifname wan0 ip saddr 1.2.3.4 ip daddr 1.2.3.4 ip version 3 jump coucou | ||
iifname lo0 oifname wan0 (tcp dport | 1234) & 34 == 56 jump coucou | ||
iifname lo0 oifname wan0 ether saddr 00:11:22:33:44:55 jump coucou | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to disable this test for a while since the nft command does not support
export json
anymore, and-j list ruleset
provides a completely different output.We have to rework the test somehow.