Skip to content

Commit

Permalink
dhcpd (#772)
Browse files Browse the repository at this point in the history
* Add ISC dhcp config lexer

This adds a lexer to parse ISC's dhcpd.conf, https://www.isc.org/dhcp/,
this is EOL, but distributions still carry it.

It has the keywords that I could find and takes some liberty with
LiteralNumber* tokens to return IP, network and MAC addresses.

It may be possible to make this somewhat smaller, but haven't pushed for
that yet.

Signed-off-by: Miek Gieben <miek@miek.nl>

* revert some non-related changes

Signed-off-by: Miek Gieben <miek@miek.nl>

* revert

Signed-off-by: Miek Gieben <miek@miek.nl>

---------

Signed-off-by: Miek Gieben <miek@miek.nl>
  • Loading branch information
miekg committed Mar 24, 2023
1 parent 2672d3c commit 357f0cb
Show file tree
Hide file tree
Showing 3 changed files with 534 additions and 0 deletions.
112 changes: 112 additions & 0 deletions lexers/embedded/iscdhcpd.xml
@@ -0,0 +1,112 @@
<lexer>
<config>
<name>ISCdhcpd</name>
<alias>iscdhcpd</alias>
<filename>*.conf</filename>
</config>
<rules>
<state name="interpol">
<rule pattern="\$[{(]">
<token type="LiteralStringInterpol"/>
<push/>
</rule>
<rule pattern="[})]">
<token type="LiteralStringInterpol"/>
<pop depth="1"/>
</rule>
<rule pattern="[^${()}]+">
<token type="LiteralStringInterpol"/>
</rule>
</state>
<state name="arglist">
<rule pattern="\)">
<token type="Punctuation"/>
<pop depth="1"/>
</rule>
<rule pattern=",">
<token type="Punctuation"/>
</rule>
<rule pattern="[\w\-.]+">
<token type="NameVariable"/>
</rule>
<rule pattern="\s+">
<token type="Text"/>
</rule>
</state>
<state name="root">
<rule pattern="#.*?\n">
<token type="Comment"/>
</rule>
<rule pattern="(group|host|subnet|netmask|class|pool)\b">
<token type="KeywordType"/>
</rule>
<rule pattern="(authoritative|domain-name-servers|ethernet|fixed-address|hardware|option|use-host-decl-name|include)\b">
<token type="Keyword"/>
</rule>
<rule pattern="(on|off|true|false)\b">
<token type="KeywordConstant"/>
</rule>
<rule pattern="(if|elsif|else)\b">
<token type="Keyword"/>
</rule>
<rule pattern="(and|or|not)\b">
<token type="OperatorWord"/>
</rule>
<rule pattern="(==|!=|~=|~~|=)">
<token type="Operator"/>
</rule>
<rule pattern="(exists|known|static)\b">
<token type="Keyword"/>
</rule>
<rule pattern="[{},;]">
<token type="Punctuation"/>
</rule>
<rule pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}">
<token type="LiteralNumberHex"/>
</rule>
<rule pattern="(\w+)(\s+)(\()">
<bygroups>
<token type="NameFunction"/>
<token type="Text"/>
<token type="Punctuation"/>
</bygroups>
<push state="arglist"/>
</rule>
<rule pattern="[\w\-.]+">
<token type="NameVariable"/>
</rule>
<rule pattern="&#34;">
<token type="LiteralString"/>
<push state="doublequotestring"/>
</rule>
<rule pattern="\s+">
<token type="Text"/>
</rule>
</state>
<state name="doublequotestring">
<rule pattern="\$[{(]">
<token type="LiteralStringInterpol"/>
<push state="interpol"/>
</rule>
<rule pattern="\\.">
<token type="LiteralStringEscape"/>
</rule>
<rule pattern="&#34;">
<token type="LiteralString"/>
<pop depth="1"/>
</rule>
<rule pattern="\n">
<token type="LiteralString"/>
</rule>
<rule pattern=".">
<token type="LiteralString"/>
</rule>
</state>
</rules>
</lexer>
77 changes: 77 additions & 0 deletions lexers/testdata/iscdhcpd.actual
@@ -0,0 +1,77 @@
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

ddns-update-style none;

authoritative;

log-facility local7;

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
range 10.254.239.10 10.254.239.20;
option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

subnet 10.254.239.32 netmask 255.255.255.224 {
range dynamic-bootp 10.254.239.40 10.254.239.60;
option broadcast-address 10.254.239.31;
option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option subnet-mask 255.255.255.224;
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
}

host passacaglia {
hardware ethernet 0:0:c0:5d:bd:95;
filename "vmunix.passacaglia";
server-name "toccata.example.com";
}

host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address fantasia.example.com;
}

class "foo" {
match if substring (option vendor-class-identifier, 0, 4) = "S\"UNW";
}

shared-network 224-29 {
subnet 10.17.224.0 netmask 255.255.255.0 {
option routers rtr-224.example.org;
}
subnet 10.0.29.0 netmask 255.255.255.0 {
option routers rtr-29.example.org;
}
pool {
allow members of "foo";
range 10.17.224.10 10.17.224.250;
}
pool {
deny members of "foo";
range 10.0.29.10 10.0.29.230;
}
}

0 comments on commit 357f0cb

Please sign in to comment.