From dff1c9b16ca5b4e11f2ff768df877534654471d9 Mon Sep 17 00:00:00 2001 From: egberts <> Date: Thu, 15 Dec 2022 15:08:47 -0500 Subject: [PATCH] Fixes #47 ParseException for filter-aaaa-on-v4 --- bind9_parser/isc_options.py | 36 ++++++++++++- examples/rough-draft/namedconfglobal.py | 1 - setup.py | 2 +- tests/test_options.py | 70 ++++++++++++++++++++++++- 4 files changed, 105 insertions(+), 4 deletions(-) diff --git a/bind9_parser/isc_options.py b/bind9_parser/isc_options.py index 83954aa..e6c4eec 100755 --- a/bind9_parser/isc_options.py +++ b/bind9_parser/isc_options.py @@ -9,7 +9,7 @@ Description: Various 'options' statement that is used only by 'options' clause. """ -from pyparsing import Group, Keyword, Optional, \ +from pyparsing import Group, Keyword, Optional, Combine, \ ZeroOrMore, OneOrMore, Literal, ungroup, CaselessLiteral from pyparsing import pyparsing_common from bind9_parser.isc_utils import lbrack, rbrack, semicolon, size_spec, \ @@ -339,6 +339,37 @@ ) options_stmt_fake_iquery.setName('fake-iquery ;') +# filter-aaaa-on-v4 ( break-dnssec | ); // not configured +options_stmt_filter_aaaa_on_v4 = ( + Keyword('filter-aaaa-on-v4').suppress() + - Combine( + isc_boolean() + | Keyword('break-dnssec') + )('filter_aaaa_on_v4') + + semicolon +) +options_stmt_filter_aaaa_on_v4.setName('filter-aaaa-on-v4 { break-dnssec | );') + +# filter-aaaa-on-v6 ( break-dnssec | ); // not configured +options_stmt_filter_aaaa_on_v6 = ( + Keyword('filter-aaaa-on-v6').suppress() + - Combine( + isc_boolean() + | Keyword('break-dnssec') + )('filter_aaaa_on_v6') + + semicolon +) +options_stmt_filter_aaaa_on_v6.setName('filter-aaaa-on-v6 { break-dnssec | );') + +# filter-aaaa { ; ... }; // not configured +options_stmt_filter_aaaa = ( + Keyword('filter-aaaa').suppress() + - Group( + aml_nesting('') + )('filter_aaaa') +) +options_stmt_filter_aaaa.setName('filter-aaaa { ; .... };') + # flush-zones-on-shutdown ; [ Opt ] # v9.3+ options_stmt_flush_zones_on_shutdown = ( Keyword('flush-zones-on-shutdown').suppress() @@ -977,6 +1008,9 @@ ^ options_stmt_dscp ^ options_stmt_dump_file ^ options_stmt_fake_iquery + ^ options_stmt_filter_aaaa_on_v4 + ^ options_stmt_filter_aaaa_on_v6 + ^ options_stmt_filter_aaaa ^ options_stmt_flush_zones_on_shutdown ^ options_stmt_geoip_directory ^ options_stmt_has_old_clients diff --git a/examples/rough-draft/namedconfglobal.py b/examples/rough-draft/namedconfglobal.py index f691b45..e4463a9 100644 --- a/examples/rough-draft/namedconfglobal.py +++ b/examples/rough-draft/namedconfglobal.py @@ -2582,7 +2582,6 @@ 'topic': 'ancient, filtering', 'comment': """Specifies a list of addresses to which -filter-aaaa-on-v4 is applies. The default is any. Option 'filter-aaaa' activated at v9.12.0 diff --git a/setup.py b/setup.py index 97b3d35..34ad618 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ 'bind9_parser', ] -bind9_parser_version = '0.99.1' +bind9_parser_version = '0.99.2' setup( # Distribution meta-data name='bind9_parser', diff --git a/tests/test_options.py b/tests/test_options.py index f06dab3..9f36949 100755 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -22,7 +22,9 @@ options_stmt_dnstap_version, \ options_stmt_dscp, \ options_stmt_dump_file, \ - options_stmt_fake_iquery, options_stmt_flush_zones_on_shutdown, \ + options_stmt_fake_iquery, \ + options_stmt_filter_aaaa_on_v4, options_stmt_filter_aaaa_on_v6, options_stmt_filter_aaaa, \ + options_stmt_flush_zones_on_shutdown, \ options_stmt_geoip_directory, \ options_stmt_has_old_clients, \ options_stmt_http_listener_clients, \ @@ -83,6 +85,8 @@ def test_isc_options_all_booleans(self): ['deallocate-on-exit', options_stmt_deallocate_on_exit, ], ['fake-iquery', options_stmt_fake_iquery, ], ['flush-zones-on-shutdown', options_stmt_flush_zones_on_shutdown, ], + ['filter-aaaa-on-v4', options_stmt_flush_zones_on_shutdown, ], + ['filter-aaaa-on-v6', options_stmt_flush_zones_on_shutdown, ], ['has-old-clients', options_stmt_has_old_clients, ], ['hostname-statistics', options_stmt_hostname_statistics, ], ['hostname-statistics-max', options_stmt_hostname_statistics_max, ], @@ -325,6 +329,70 @@ def test_isc_options_stmt_dump_file_passing(self): assert_parser_result_dict_true(options_stmt_dump_file, 'dump-file "/tmp/crapola";', {'dump_file': '/tmp/crapola'}) + def test_isc_options_stmt_filter_aaaa_on_v4_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa_on_v4, + 'filter-aaaa-on-v4 yes;', + {'filter_aaaa_on_v4': 'yes'} + ) + + def test_isc_options_stmt_filter_aaaa_on_v4_2_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa_on_v4, + 'filter-aaaa-on-v4 false;', + {'filter_aaaa_on_v4': 'False'} + ) + + def test_isc_options_stmt_filter_aaaa_on_v4_3_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa_on_v4, + 'filter-aaaa-on-v4 break-dnssec;', + {'filter_aaaa_on_v4': 'break-dnssec'} + ) + + def test_isc_options_stmt_filter_aaaa_on_v6_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa_on_v6, + 'filter-aaaa-on-v6 yes;', + {'filter_aaaa_on_v6': 'yes'} + ) + + def test_isc_options_stmt_filter_aaaa_on_v6_2_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa_on_v6, + 'filter-aaaa-on-v6 false;', + {'filter_aaaa_on_v6': 'False'} + ) + + def test_isc_options_stmt_filter_aaaa_on_v6_3_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa_on_v6, + 'filter-aaaa-on-v6 break-dnssec;', + {'filter_aaaa_on_v6': 'break-dnssec'} + ) + + def test_isc_options_stmt_filter_aaaa_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa, + 'filter-aaaa { };', + {'filter_aaaa': {'aml': []}} + ) + + def test_isc_options_stmt_filter_aaaa_2_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa, + 'filter-aaaa { 1.1.1.1; };', + {'filter_aaaa': {'aml': [{'ip4_addr': '1.1.1.1'}]}} + ) + + def test_isc_options_stmt_filter_aaaa_3_passing(self): + assert_parser_result_dict_true( + options_stmt_filter_aaaa, + 'filter-aaaa { 1.2.3.4; 5.6.7.8; };', + {'filter_aaaa': {'aml': [{'ip4_addr': '1.2.3.4'}, + {'ip4_addr': '5.6.7.8'}]}} + ) + def test_isc_options_stmt_geoip_directory(self): """ Clause options; Statement geoip-directory; passing mode """ assert_parser_result_dict(