summaryrefslogtreecommitdiffstats
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* meta: Add support for input and output bridge interface nameTomasz Bursztyka2014-04-241-1/+3
| | | | | | | | | Add support for dedicated bridge meta key, related to device names: - NFT_META_BRI_IIFNAME - NFT_META_BRI_OIFNAME Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* lookup: Fix an invalid readAna Rey2014-04-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Valgrind reports the following invalid read: $ sudo valgrind ./nft-parsing-test -f ../jsonfiles/30-rule-lookup.json ==26664== Memcheck, a memory error detector ==26664== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==26664== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==26664== Command: ./nft-parsing-test -f ../jsonfiles/30-rule-lookup.json ==26664== ==26664== Invalid read of size 8 ==26664== at 0x4E45490: nft_rule_expr_lookup_set (lookup.c:50) ==26664== by 0x4E40B04: nft_rule_expr_set (expr.c:73) ==26664== by 0x4E44FFF: nft_rule_expr_lookup_json_parse (lookup.c:157) ==26664== by 0x4E408CD: nft_jansson_expr_parse (jansson.c:206) ==26664== by 0x4E3B719: nft_jansson_parse_rule (rule.c:606) ==26664== by 0x4E3F005: nft_ruleset_do_parse (ruleset.c:312) ==26664== by 0x401479: test_json (nft-parsing-test.c:129) ==26664== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==26664== by 0x400EBB: main (nft-parsing-test.c:332) ==26664== Address 0x5c34d40 is 0 bytes inside a block of size 5 alloc'd ==26664== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==26664== by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== ==26664== Invalid read of size 8 ==26664== at 0x4E45497: nft_rule_expr_lookup_set (lookup.c:50) ==26664== by 0x4E40B04: nft_rule_expr_set (expr.c:73) ==26664== by 0x4E44FFF: nft_rule_expr_lookup_json_parse (lookup.c:157) ==26664== by 0x4E408CD: nft_jansson_expr_parse (jansson.c:206) ==26664== by 0x4E3B719: nft_jansson_parse_rule (rule.c:606) ==26664== by 0x4E3F005: nft_ruleset_do_parse (ruleset.c:312) ==26664== by 0x401479: test_json (nft-parsing-test.c:129) ==26664== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==26664== by 0x400EBB: main (nft-parsing-test.c:332) ==26664== Address 0x5c34d48 is 3 bytes after a block of size 5 alloc'd ==26664== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==26664== by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26664== by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) Signed-off-by: Ana Rey <anarey@gmail.com>
* set-elem: fix a memory leakAna Rey2014-04-161-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | Valgrind reports the following memory leak: valgrind --leak-check=full ./nft-parsing-test -f jsonfiles/63-set.json ==7131== HEAP SUMMARY: ==7131== in use at exit: 2 bytes in 1 blocks ==7131== total heap usage: 155 allocs, 154 frees, 6,497 bytes allocated ==7131== ==7131== 2 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==7131== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==7131== by 0x590B829: strdup (strdup.c:42) ==7131== by 0x4E4341A: nft_data_reg_json_parse (data_reg.c:55) ==7131== by 0x4E4093A: nft_jansson_data_reg_parse (jansson.c:231) ==7131== by 0x4E40A1B: nft_jansson_et_elem_parse (jansson.c:257) ==7131== by 0x4E3CECA: nft_jansson_parse_set (set.c:398) ==7131== by 0x4E3EC65: nft_ruleset_do_parse (ruleset.c:263) ==7131== by 0x401479: test_json (nft-parsing-test.c:129) ==7131== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==7131== by 0x400EBB: main (nft-parsing-test.c:332) Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* target, match: Fix an invalid readAna Rey2014-04-142-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Valgrind reports the following invalid read: $ sudo valgrind --leak-check=full ./nft-parsing-test -f ../jsonfiles/35-rule-target.json ( and similar result with jsonfiles/29-rule-match.json file) ==26018== Invalid read of size 8 ==26018== at 0x4E484E3: nft_rule_expr_target_set (target.c:46) ==26018== by 0x4E40B54: nft_rule_expr_set (expr.c:73) ==26018== by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185) ==26018== by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206) ==26018== by 0x4E3B769: nft_jansson_parse_rule (rule.c:606) ==26018== by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312) ==26018== by 0x401479: test_json (nft-parsing-test.c:129) ==26018== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==26018== by 0x400EBB: main (nft-parsing-test.c:332) ==26018== Address 0x5c34a60 is 0 bytes inside a block of size 4 alloc'd ==26018== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==26018== by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== ==26018== Invalid read of size 8 ==26018== at 0x4E484ED: nft_rule_expr_target_set (target.c:46) ==26018== by 0x4E40B54: nft_rule_expr_set (expr.c:73) ==26018== by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185) ==26018== by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206) ==26018== by 0x4E3B769: nft_jansson_parse_rule (rule.c:606) ==26018== by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312) ==26018== by 0x401479: test_json (nft-parsing-test.c:129) ==26018== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==26018== by 0x400EBB: main (nft-parsing-test.c:332) ==26018== Address 0x5c34a68 is 4 bytes after a block of size 4 alloc'd ==26018== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==26018== by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== ==26018== Invalid read of size 8 ==26018== at 0x4E484F5: nft_rule_expr_target_set (target.c:46) ==26018== by 0x4E40B54: nft_rule_expr_set (expr.c:73) ==26018== by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185) ==26018== by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206) ==26018== by 0x4E3B769: nft_jansson_parse_rule (rule.c:606) ==26018== by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312) ==26018== by 0x401479: test_json (nft-parsing-test.c:129) ==26018== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==26018== by 0x400EBB: main (nft-parsing-test.c:332) ==26018== Address 0x5c34a70 is 12 bytes after a block of size 4 alloc'd ==26018== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==26018== by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== ==26018== Invalid read of size 4 ==26018== at 0x4E484FD: nft_rule_expr_target_set (target.c:46) ==26018== by 0x4E40B54: nft_rule_expr_set (expr.c:73) ==26018== by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185) ==26018== by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206) ==26018== by 0x4E3B769: nft_jansson_parse_rule (rule.c:606) ==26018== by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312) ==26018== by 0x401479: test_json (nft-parsing-test.c:129) ==26018== by 0x4017C2: execute_test_file (nft-parsing-test.c:270) ==26018== by 0x400EBB: main (nft-parsing-test.c:332) ==26018== Address 0x5c34a78 is 20 bytes after a block of size 4 alloc'd ==26018== at 0x4C274A0: malloc (vg_replace_malloc.c:291) ==26018== by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) ==26018== by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0) Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* xml, json: Delete an immediatedate label in xml and json fileAna Rey2014-04-141-10/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It deletes the immediatedata label in the structure of json and xml file. Example of the old structure of xmlfile: <nftables> <rule> <family>ip</family> <table>filter</table> <chain>input</chain> <handle>32</handle> <expr type="immediate"> <dreg>0</dreg> <immediatedata> <data_reg type="verdict"> <verdict>accept</verdict> </data_reg> </immediatedata> </expr> </rule> </nftables> Example of the new structure of xmlfile: <nftables> <rule> <family>ip</family> <table>filter</table> <chain>input</chain> <handle>32</handle> <expr type="immediate"> <dreg>0</dreg> <data_reg type="verdict"> <verdict>accept</verdict> </data_reg> </expr> </rule> </nftables> To generate the new testfiles, It use the option -u of nft-parsing-test script. Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* xml, json: Delete a cmpdata label in xml and json fileAna Rey2014-04-143-22/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It delete the cmpdata label in the structure of json and xml file. Example of xmlfile: The old structure of xml file: [...] <expr type="cmp"> <sreg>1</sreg> <op>eq</op> <cmpdata> <data_reg type="value"> <len>4</len> <data0>0x0100a8c0</data0> </data_reg> </cmpdata> </expr> The new structure of json file: [...] <expr type="cmp"> <sreg>1</sreg> <op>eq</op> <data_reg type="value"> <len>4</len> <data0>0x0100a8c0</data0> </data_reg> </expr> [...] To generate the new testfiles, It use the option -u of nft-parsing-test script. Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: fix bogus assertion for unset attributesPablo Neira Ayuso2014-04-075-18/+20
| | | | | | | | | | | | If you try to obtain an unset attribute, you hit an assertion error that should not happen. Fix this by checking if the attribute is unset, otherwise skip the assertion checking. Now that we have that nft_assert takes the data parameter, we can also validate if someone is using the setter passing NULL, which is illegal. So let's add an assertion for that as well. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* set_elem: parse family from Netlink messageArturo Borrero2014-04-071-0/+3
| | | | | | | Lets obtain the family from the Netlink message. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* set_elems: delete unexisting exported symbolArturo Borrero2014-03-262-2/+0
| | | | | | | There is no function called 'nft_set_elem_nlmsg_parse()' Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* rule: don't enforce attributes when parsingÁlvaro Neira Ayuso2014-03-171-41/+31
| | | | | | | | This change allow us to parser the rule and the kernel bail out if the rule is well-formed. Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* rule: don't print unset attributesÁlvaro Neira Ayuso2014-03-171-13/+79
| | | | | | | | | | | | | | | | | | | | We print some attribute that maybe the user hasn't defined for printing. We can't assume that the user want to print some attribute that we have put mandatory in the rules. Example: If we have defined family, the output is like that: {"rule":{"family":"ip","handle":4... <rule><family>ip</family><handle>4</handle>... And this if we unset the family. {"rule":{"handle":4... <rule><handle>4</handle>... Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* rule: add NFT_RULE_ATTR_USERDATA supportPablo Neira Ayuso2014-02-271-1/+57
| | | | | | This allows us to manipulate the user data area of the rule. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: check if netlink parsing failsArturo Borrero2014-02-275-10/+30
| | | | | | | | We have to check if mnl_attr_parse() returns an error, which means that it failed to validate and retrieve the attributes. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: fix wrong type in NFT_ATTR_*_FAMILYPablo Neira Ayuso2014-02-273-12/+12
| | | | | | This fixes assertions in the test files. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: add nft_*_attr_{set|get}_data interfacePablo Neira Ayuso2014-02-275-27/+193
| | | | | | | | | | | | This patch adds two functions that allows you to validate the size of the attribute. This new functions provide a replacement for nft_rule_attr_set and nft_rule_attr_get. The data_len parameter was already passed to the {_set|_get} funcion in expressions. For consistency, add nft_rule_expr_{set|get}_data alias. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: add assertion infrastructure to validate attribute typesPablo Neira Ayuso2014-02-272-0/+20
| | | | | | | This will be used to validate that the size is correct according to the expected attribute size. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: early attribute type validation in nft_*_attr_setPablo Neira Ayuso2014-02-274-11/+15
| | | | | | | | This allows us to remove the default case in the switch, which show help to spot missing attribute support since gcc will spot a compilation warning. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* expr: add conntrack label match supportFlorian Westphal2014-02-181-2/+3
| | | | Signed-off-by: Florian Westphal <fw@strlen.de>
* src: compile queue expression supportPablo Neira Ayuso2014-02-172-8/+14
| | | | | | | This got lost in 29fd6a1df9 when merging major changes in master to next-3.14. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* chain: print usage counter for base chain via default output as wellPablo Neira Ayuso2014-02-111-4/+4
| | | | | | | For some reason this was only printed in custom chains. Print it for any chain, this is useful for debugging purposes. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* Merge branch 'master' into next-3.14Pablo Neira Ayuso2014-02-0334-746/+1275
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch includes changes to adapt this branch to the library rename that happened in the master branch. Conflicts: src/Makefile.am src/expr/cmp.c src/expr/ct.c src/expr/data_reg.c src/expr/meta.c tests/jsonfiles/01-table.json tests/jsonfiles/02-table.json tests/jsonfiles/64-ruleset.json tests/xmlfiles/01-table.xml tests/xmlfiles/02-table.xml
| * build: resolve build failure involving linux/netlink.hJan Engelhardt2014-01-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This was seen with a sufficiently-old /usr/include/linux (from Linux 2.6.32). In file included from common.c:10: /usr/include/linux/netlink.h:34: error: expected specifier-qualifier-list before 'sa_family_t' The solution is to include <linux/*> last of all system headers. Signed-off-by: Jan Engelhardt <jengelh@inai.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * rename library to libnftnllibnftnl-1.0.0Pablo Neira Ayuso2014-01-2030-94/+94
| | | | | | | | | | | | We plan to use this library name for the higher layer library. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * expr: ct: fix compilation warning when json/xml support is missingPablo Neira Ayuso2014-01-201-1/+1
| | | | | | | | | | | | | | CC expr/ct.lo expr/ct.c:194:12: warning: 'str2ctdir' defined but not used [-Wunused-function] Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * ct: use a string with 'dir' attributeArturo Borrero2014-01-181-11/+48
| | | | | | | | | | | | | | | | | | This patch implements a string to represent directions in the CT expression: * original (0) * reply (1) Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * data_reg: fix verdict format approachArturo Borrero2014-01-183-96/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patrick reports that the XML/JSON formats of the data_reg object are not accuarate. This patch updates these formats, so they are now as follow: * <data_reg type=value> with raw data (this doesn't change). * <data_reg type=verdict> with a concrete verdict (eg drop accept) and an optional <chain>, with destination. In XML: <data_reg type="verdict"> <verdict>goto</verdict> <chain>output</chain> </data_reg> In JSON: "data_reg" : { "type" : "verdict", "verdict" : "goto" "chain" : "output", } The default output format is updated to reflect these changes (minor collateral thing). When parsing set_elems, to know if we need to add the NFT_SET_ELEM_ATTR_CHAIN flag, a basic check for the chain not being NULL is done, instead of evaluating if the result of the parsing was DATA_CHAIN. The DATA_CHAIN symbol is no longer used in the data_reg XML/JSON parsing zone. While at it, I updated the error reporting stuff regarding data_reg/verdict, in order to leave a consistent state in the library. A JSON testfile is updated as well. Reported-by: Patrick McHardy <kaber@trash.net> Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * utils: fix nft_str2verdict return valueArturo Borrero2014-01-184-21/+39
| | | | | | | | | | | | | | | | | | | | | | | | Some verdicts have a negative value. The caller of nft_str2verdict() checking if return was < 0 clash with enum nft_verdict. While at it, add error reporting of invalid verdicts. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * expr: meta: statify meta_key2str_arrayPablo Neira Ayuso2014-01-171-1/+1
| | | | | | | | | | | | It's not used out of the scope of expr/meta.c Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * expr: ct: direction is optionalArturo Borrero2014-01-171-16/+46
| | | | | | | | | | | | | | | | | | | | | | | | The 'dir' attribute is optional as stated in the kernel sources. Previous to this patch, using XML/JSON to manage this expr produces some undefined and erroneous behaviours. While at it, fix also the default output format. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * expr: ct: fix missing NFT_CT_L3PROTOCOL in ctkey2str_arrayArturo Borrero2014-01-161-0/+1
| | | | | | | | | | | | | | | | | | Due to missing NFT_CT_L3PROTOCOL key in ctkey2str_array, a segfault is produced when the str2ctkey() loop reaches that position, since strcmp() will try to compare a NULL value. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * lookup: xml: conditional output of dregArturo Borrero2014-01-151-13/+30
| | | | | | | | | | | | | | | | The dreg attribute is optional as stated at: linux/net/netfilter/nft_lookup.c Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * mxml: add optional/mandatory flag to nft_mxml_reg_parseArturo Borrero2014-01-1512-57/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are some cases where a reg is not mandatory, for example: * dreg in lookup * dreg/sreg in meta (last version) So, lets change the function nft_mxml_reg_parse() to add an optional/mandatory flag. dreg in lookup is optional as stated at: net/netfilter/nft_lookup.c:nft_lookup_init() Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * set: xml: data_type/data_len are optionalArturo Borrero2014-01-151-13/+20
| | | | | | | | | | | | | | | | | | | | Don't print data_type and data_len if they aren't set. Also, they are optional when parsing. Printing and parsing unconditionally leads to false values and other errors. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * expr: fix incorrect data type for several expression object fieldsPablo Neira Ayuso2014-01-105-11/+11
| | | | | | | | | | | | | | | | | | This patch fixes the incorrect data type (from uint8_t to uint32_t) in several private data area of the expressions. It also cleans up this by translating several unsigned int to uint32_t. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * src: add interface to parse from fileArturo Borrero2014-01-0910-2/+59
| | | | | | | | | | | | | | | | This patch adds a new API to parse rule-set expressed in XML/JSON from a file. A new enum nft_parse_input type is added for this purpose. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * src: rework and generalize the build/parse systemArturo Borrero2014-01-099-72/+141
| | | | | | | | | | | | | | | | | | | | | | The intention behind this patch is to prepare the introduction of the new API that will allow us to parse files that contain the rule-sets expressed in XML/JSON format. This adds the NFT_PARSE_BUFFER that indicates that the input is provided in a buffer, which is what we currently support. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * set_elem: add json parsing to APIArturo Borrero2014-01-084-5/+27
| | | | | | | | | | | | | | | | | | Add missing support in the API function to parse a JSON set_elem. I've renamed the main JSON parsing function to prevent clashing. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * mxml: add error reference of the top nodeArturo Borrero2014-01-081-2/+5
| | | | | | | | | | | | | | We know the top node we are building. Let the user also know it. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * src: new error reporting approach for XML/JSON parsersÁlvaro Neira Ayuso2014-01-0631-380/+640
| | | | | | | | | | | | | | | | | | | | | | | | | | | | I have added a new structure for reporting some errors in parser that we can't cover with errno. In this patch, we have three errors that we can't cover with errno: NFT_PARSE_EBADINPUT : Bad XML/JSON format in the input NFT_PARSE_EMISSINGNODE : Missing node in our input NFT_PARSE_EBADTYPE : Wrong type value in a node Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
| * src: rename the parameter tag to node_name in jansson functionÁlvaro Neira Ayuso2014-01-032-24/+28
| | | | | | | | | | | | | | | | I have changed this parameter for having consistence with the xml helper function. This patch is a cleanup. Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* | expr: ct: Add support for setting the markKristian Evensen2014-01-151-26/+101
| | | | | | | | | | | | | | | | | | This patch adds userspace support for setting properties of tracked connections. Currently, the connection mark is supported. This can be used to implemented the same functionality as iptables -j CONNMARK --save-mark. Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* | meta: Let user specify any combination of sreg/dregKristian Evensen2014-01-151-32/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | libnftables should not mask kernel errors. Let user specify any combination of parameters and leave the error-checking to the kernel. The kernel will return -EINVAL and users will know that they have to fix their code. This patch also a removes a redundant variable that was passed to the snprintf-functions (flag). A second iteration might be needed. I was not sure how to deal with snprintf_default in the case of both sreg and dreg. Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* | expr/cmp: fix type sizePatrick McHardy2014-01-152-5/+5
| | | | | | | | | | | | | | | | | | Since nftables now uses nft_rule_expr_get_u32(), the internal size must also be a uint32_t. Fixes complete breakage of any cmp or meta expression. Signed-off-by: Patrick McHardy <kaber@trash.net>
* | src: fix compilation due to missing NFPROTO_INET definitionPablo Neira Ayuso2014-01-101-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a copy of the include/linux/netfilter.h kernel header that defines NFPROTO_INET, so libnftables compiles with relatively old kernel headers in the system. chain.c: In function 'nft_hooknum2str': chain.c:53:7: error: 'NFPROTO_INET' undeclared (first use in this function) This required to reorder and remove unneeded headers in src/expr/data_reg.c to avoid a compilation warning due to redefinition of __visible. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* | libnftables: add support for inet family and mete nfproto/l4proto expressionsPatrick McHardy2014-01-083-1/+8
| | | | | | | | Signed-off-by: Patrick McHardy <kaber@trash.net>
* | src: update meta exprArturo Borrero2013-12-261-24/+92
| | | | | | | | | | | | | | | | | | | | This patch adds userspace support for the meta expression in the set flavour. This expression indicates that the packet has to be set with a property, currently one of mark, priority or nftrace. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* | table: Add support for NFTA_TABLE_USE attributeTomasz Bursztyka2013-12-171-6/+29
| | | | | | | | | | | | | | | | This adds support for table's attribute "use" which let us know about how many chains are in the table, if any. Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* | expr: add support for nfnetlink queueEric Leblond2013-12-042-0/+255
|/ | | | | | | This patch adds a support of the queue target. Signed-off-by: Eric Leblond <eric@regit.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* src: consolidate netlink build header functionPablo Neira Ayuso2013-11-248-110/+39
| | | | | | | | | Add new function nft_nlmsg_build_hdr which consolidates all existing functions to build headers per object. They basically look the same. This patch still provides aliases for consistency in the naming approach. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
* table/chain: add u8 setter and getter for family valuesAna Rey2013-11-203-0/+30
| | | | | | | These are needed to set the family value for chain and table. Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>