Revision e1119477
Added by Dmitri Dolguikh over 6 years ago
modules/dhcp_common/isc/configuration_parser.rb | ||
---|---|---|
EOSTMT = ';'.r 'end of statement'
|
||
COMMA = /\s*,\s*/.r 'comma'
|
||
LITERAL = /".*?"|'.*?'/.r
|
||
HEX = /([a-fA-F0-9][a-fA-F0-9]?:)+[a-fA-F0-9][a-fA-F0-9]?/.r
|
||
MAC_ADDRESS = /([a-fA-F0-9][a-fA-F0-9]?:){5}[a-fA-F0-9][a-fA-F0-9]?/.r 'mac address'
|
||
IPV4_ADDRESS = /\d+\.\d+\.\d+\.\d+/.r 'ipv4 address'
|
||
IPV4_ADDRESS_LIST = IPV4_ADDRESS.join(COMMA).even
|
||
... | ... | |
FQDN_LIST = FQDN.join(COMMA).even
|
||
LFT_BRACKET = '{'.r 'left bracket'
|
||
RGT_BRACKET = '}'.r 'right bracket'
|
||
DOUBLE_QUOTE = '"'.r 'comma'
|
||
DOUBLE_QUOTE = '"'.r 'double quote'
|
||
|
||
def ignored_declaration
|
||
seq_(SPACE.join(/[^\s{};#]+/).odd, EOSTMT | COMMENT) {|content, _| IgnoredDeclaration[content]}
|
||
... | ... | |
SPACE.join(LITERAL | anything).odd.join(COMMA).even
|
||
end
|
||
|
||
def server_duid
|
||
Rsec::Fail.reset
|
||
keyword = word('server-duid').fail 'keyword_server_duid'
|
||
anything = /[^;,{}\s]+/.r
|
||
llt = seq_(word('llt') | word('LLT'), SPACE.join(anything).odd._?)
|
||
ll = seq_(word('ll') | word('LL'), SPACE.join(anything).odd._?)
|
||
en = seq_(word('en') | word('EN'), prim(:int32), LITERAL)
|
||
seq_(keyword, LITERAL | HEX | en | llt | ll | prim(:int32), EOSTMT) {|_, duid, _| KeyValueNode[:server_duid, duid.respond_to?(:flatten) ? duid.flatten : duid]}
|
||
end
|
||
|
||
def filename
|
||
Rsec::Fail.reset
|
||
keyword = word('filename').fail 'keyword_filename'
|
||
... | ... | |
end
|
||
|
||
def conf
|
||
SPACE.join(option | host | lease | group | subnet | shared_network | include_file | COMMENT | ignored_declaration | ignored_block | EOSTMT).odd.eof
|
||
SPACE.join(option | host | lease | group | subnet | shared_network | include_file | COMMENT | server_duid | ignored_declaration | ignored_block | EOSTMT).odd.eof
|
||
end
|
||
|
||
def start_visiting_parse_tree_nodes(parse_tree)
|
test/dhcp/conf_parser_test.rb | ||
---|---|---|
]]], Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!(MULTILINE_LEASE)
|
||
end
|
||
|
||
def test_server_duid_parser
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, '"\000\001\000\001!:}\221RT\000^\244\022"']],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid "\000\001\000\001!:}\221RT\000^\244\022";')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, '00:01:00:01:1e:68:b3:db:0a:00:27:00:00:02']],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid 00:01:00:01:1e:68:b3:db:0a:00:27:00:00:02;')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, ['llt']]],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid llt;')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, ['llt', 'ethernet', '213982198', '00:16:6F:49:7D:9B']]],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid llt ethernet 213982198 00:16:6F:49:7D:9B;')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, ['ll']]],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid ll;')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, ['ll', 'fddi', '00:16:6F:49:7D:9B']]],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid ll fddi 00:16:6F:49:7D:9B;')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, ['en', 2495, '"enterprise-specific-identifier-1234"']]],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid en 2495 "enterprise-specific-identifier-1234";')
|
||
assert_equal [Proxy::DHCP::CommonISC::ConfigurationParser::KeyValueNode[:server_duid, 1234]],
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('server-duid 1234;')
|
||
end
|
||
|
||
def test_ignored_declaration_parser
|
||
Proxy::DHCP::CommonISC::ConfigurationParser.new.conf.parse!('aaa true;')
|
||
end
|
Also available in: Unified diff
Fixes #20826: added parsing of server-duids