Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-ISC-DHCPd CPAN distribution.

Report information
The Basics
Id: 71372
Status: resolved
Priority: 0/
Queue: Net-ISC-DHCPd

People
Owner: JHTHORSEN [...] cpan.org
Requestors: itsrath [...] itsm.uni-stuttgart.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.15



Subject: Groups in dhcpd.conf
Date: Fri, 30 Sep 2011 19:32:10 +0200
To: jhthorsen [...] cpan.org, bug-net-isc-dhcpd [...] rt.cpan.org
From: Michael Rath <itsrath [...] itsm.uni-stuttgart.de>
Hi Jan Henning, I am about to write a script that makes the generation of a dhcpd.conf file easier. Therefore I'd like to parse the file, add new host entries and save it back with a script. I gladly found your Perl class Net::ISC::DHCPd:Config that should help me a lot. Unfortunately I first found no way to retain host groups. There seemed to be a class for it, but it doesn't show up as a member of Config. Without nearly any knowledge of Perl ;-) I tried inserting the line Net::ISC::DHCPd::Config::Group under __PACKAGE__->create_children(qw/ in line 107 in the file "/usr/lib/perl5/site_perl/5.8.8/Net/ISC/DHCPd/Config.pm" and wow! the groups are there... So you probably should patch that?!? But there are some problems remaining: The pools are lost and so are the keys and the classes. I send you a copy of the first part of my dhcpd.conf. If you try it with ------------------------------------------------ #!/usr/bin/perl use Net::ISC::DHCPd::Config; my $config = Net::ISC::DHCPd::Config->new( file => '/etc/dhcpd3/dhcpd.conf', ); # parse the config $config->parse; # parsing includes are lazy for my $include ($config->includes) { $include->parse; } print $config->generate; ------------------------------------------------ and compare the output with the original you will see what the problems are... Regards Michael

Message body is not shown because sender requested not to inline it.

I just released 0.11 to cpan: 0.11 Mon Oct 3 21:17:46 CEST 2011 - [RT71372] Add missing ::Config::Group to children - [RT71372] Quick fix to missing blocks - [RT71372] Fix parsing of "next-server" inside subnet - [RT71372] Add parsing of key{} blocks - Add support for logging with ISC_DHCPD_TRACE=1 The "quick fix" is not bad, but it's far from perfect. The problem is that I'm not sure when I will have enough time to make a proper parser for class{}, subclass{}, and friends. Let me know if this is an issue for you.
Subject: Re: [rt.cpan.org #71372] Groups in dhcpd.conf
Date: Tue, 04 Oct 2011 12:38:34 +0200
To: bug-Net-ISC-DHCPd [...] rt.cpan.org
From: Michael Rath <itsrath [...] itsm.uni-stuttgart.de>
Hi Jan Henning, Am 03.10.2011 21:22, schrieb Jan Henning Thorsen via RT: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=71372> > > I just released 0.11 to cpan: > > 0.11 Mon Oct 3 21:17:46 CEST 2011 > - [RT71372] Add missing ::Config::Group to children > - [RT71372] Quick fix to missing blocks > - [RT71372] Fix parsing of "next-server" inside subnet > - [RT71372] Add parsing of key{} blocks > - Add support for logging with ISC_DHCPD_TRACE=1
thank you very much for this quick response. Show quoted text
> The "quick fix" is not bad, but it's far from perfect. The problem is > that I'm not sure when I will have enough time to make a proper parser > for class{}, subclass{}, and friends. > > Let me know if this is an issue for you.
not as long as it is put out by "generate" as it was in the input. The fix is nearly perfect as it now generates all the missing lines. But there are still some problems: - The main problem that keeps me from being able to use your class is: the sequence of commands is mixed up in the output of "generate". This leads to the daemon not accepting the generated dhcpd.conf file. The subnet sections with the class definitions and the option statements defining the user options have to be in front of the host and host group definitions or the deamon will produce many error messages. - You don't output a trailing ';' after the '}' of the key section. Most examples show that but it doesn't seem to be required by the daemon. But very easy to fix ;-) ... - When specifying the keyname in double quotes the name contains the last double quote leading to two double quotes at the end in the output of generate which messes up the daemons parsing. That's perhaps because the regex matching when parsing the name in your key class is not greedy. This is a very minor issue as most examples don't use double quotes around the key name. But it is accepted by the DHCP daemon. - And I personally have a very special problem: I need comments to be retained (at least the "# monitor: 3 4 Y Studenten_DHCP" comment in the pool definition). That is because of the nagios plugin dhcp-pool ( http://folk.uio.no/trondham/software/dhcpd-pool.html ) needing these comments to work correctly. That's of minor priority as I can easily write a script that inserts those after generating the dhcpd.conf. I already worked around the problem of the disappearing comments by defining the user options which now contain the comments (I hope they have no side effects as I don't fully understand the concept of user options...). But that won't work with this plugin unless I change the source code (might be easy, but a bit of a hassle in case of updates of that plugin). Regards Michael
I have pushed a new release to CPAN now. Please check it out. 0.12 Tue Oct 4 15:06:11 CEST 2011 - [RT71372] Contributor: Michael Rath - Change child nodes has the same order as input - Config::Block has _body (ArrayRef) instead of body (Str) - Config::Block body text is indented as expected - Config::Key->_build_regex handle quotes - Add trailing ";" to Config::Key block (not sure why though...) - Add support for comments before elements. Generated output will also have comments See Net::ISC::DHCPd::Config::Role/comments for new attribute containing comments. t/40-rt71372-group.t now takes your input file and checks for the same output from generate() so I think it is OK now, even though I have made some changes to the input. The changes I made is adding whitespace in front of comments and config lines.
Subject: Re: [rt.cpan.org #71372] Groups in dhcpd.conf
Date: Tue, 04 Oct 2011 19:16:09 +0200
To: bug-Net-ISC-DHCPd [...] rt.cpan.org
From: Michael Rath <itsrath [...] itsm.uni-stuttgart.de>
Hi Jan Henning, calm down - relax... I'm not used to "turn around" times of less than 3 hours for bug reports ;-) - is this standard on CPAN or do you want to break any records? Anyway - thank you very much for your fast response. I never thought it might be possible to implement all my whishes (especially the last) in such a short time. Though I could perfectly live with that version there are a few inconsistencies remaining: Am 04.10.2011 15:10, schrieb Jan Henning Thorsen via RT: Show quoted text
> - Config::Block body text is indented as expected
I have two files appended where the indentation is not as I would have expected it to be. In the output generated from dhcpd.conf there is even an error because the first host statement is ignored (whyever). I admit that it is not a beauty of a DHCP configuration file (it's a cutout from our DHCP configuration here at the institute which grew over the years without me having much knowledge about DHCP config files ;-) ). But it was recognized by the DHCP daemon as valid an worked as expected. In the other example (example1_dhcpd.conf) I would have expected an indentation of the parameters and host blocks within the group block. But that's just a cosmetic change and I don't know if it was on purpose. Show quoted text
> - Add support for comments before elements. Generated output will > also have comments > > See Net::ISC::DHCPd::Config::Role/comments for new attribute containing > comments.
OK. Comments before lines work. But comments after lines (at the end of a block) or inline (at the end of the line) don't. Again no big deal. But if you want to retain all information possibly given in a config file these cases should be covered too (you see - I#m sort of a erfectionist... ;-) ). Show quoted text
> t/40-rt71372-group.t now takes your input file and checks for the same > output from generate() so I think it is OK now, even though I have made > some changes to the input. The changes I made is adding whitespace in > front of comments and config lines.
Adding or deleting whitespace and empty lines is not bad. On the contrary: it's beautifying my mess ;-) ... Thanks again! Regards Michael

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

I had some spare time, so I thought that it was better to do it now, than later :-) My module is indeed limited, since it parses one line at a time, and the regular expressions used may be a bit too strict. That means that it may not be able to read "ugly" dhcpd.config files. Too help understand it's limits I add support for the ISC_DHCPD_TRACE environment, which will print what could NOT be parsed to STDERR. Very much like perl's warnings would do. Please set the variable to see what lines it fails on... (ISC_DHCPD_TRACE should probably be set to 1 by default?) The comment "Config::Block body text is indented as expected" is really, really bad. What I discovered is that the indentation was *better* after my latest commit, but i *knew* it was probably not perfect, since I'm removing the first four whitespaces... Patches are welcome :-) My goal was not to make really pretty config-files, but rather to be able to print something that was readable and parsable again by the module. Not sure if I will focus on this cosmetic change. Reason for that is I don't use ISC DHCPd myself, so I only fix bugs that are fatal because I feel that is the responsibility of module author... Comments at the end of block will be attached to the config line afterwards. The only comments which is not parsed, is the one at the end of file and "trailing" comments. Example: # this comment will be attached to the "host" object host foo { # this comment will be stripped away ... } # this comment will be attached to "option" object below option foo 42; # the last comment in the file will be ignored (Should probably add that to the documentation...) I do not want to retain all details. I just want to retain enough details. I think it is acceptable to require a format on the input text... So to sum up... Was there anything I needed to fix - except cosmetic bugs?
Subject: Re: [rt.cpan.org #71372] Groups in dhcpd.conf
Date: Wed, 05 Oct 2011 11:11:40 +0200
To: bug-Net-ISC-DHCPd [...] rt.cpan.org
From: Michael Rath <itsrath [...] itsm.uni-stuttgart.de>
Hi Jan Henning, Am 04.10.2011 20:04, schrieb Jan Henning Thorsen via RT: Show quoted text
> limits I add support for the ISC_DHCPD_TRACE environment, which will > print what could NOT be parsed to STDERR. Very much like perl's warnings > would do. Please set the variable to see what lines it fails on...
OK, I tried that. With my dhcpd.conf sent to you it gives 3 errors: Could not parse " host itsm-dhcptest1 {" at dhcpd.conf line 95 Could not parse "key "itsm-key" {" at dhcpd.conf line 1 Could not parse "};" at dhcpd.conf line 4 The first is the problem why it messes up the resulting config file, but I see no reason why as it is valid for the daemon in the source. The other two come from the line include "/etc/itsm.key"; I don't know either why this should be a problem as /etc/itsm.key contains only: key "itsm-key" { algorithm hmac-md5; secret "xxxxxxxxxxxxxxxxxxxxxxxxx"; }; which should be perfectly valid and is indeed parsed by your class without error if fed directly to the parser. Show quoted text
> The comment "Config::Block body text is indented as expected" is really, > really bad. What I discovered is that the indentation was *better* after > my latest commit, but i *knew* it was probably not perfect, since I'm > removing the first four whitespaces... Patches are welcome :-)
I think it should be easy: increase the indentation level with every found '{' and decrease it with every '}'. But it's not so important... Show quoted text
> Comments at the end of block will be attached to the config line > afterwards. The only comments which is not parsed, is the one at the end > of file and "trailing" comments.
No, the comments directly in front of a closing '}' are not parsed either. Example: host ITSM-RAID { hardware ethernet 00:1b:f1:20:83:c1; fixed-address 129.69.62.222; # this is a comment at the end of a block } # ITSM-EYB2 host itsm-tyb2 { hardware ethernet 4a:19:66:41:c5:4d; fixed-address itsm-tyb2.itsm.uni-stuttgart.de; # 129.69.62.132 } generates host ITSM-RAID { hardware ethernet 00:1b:f1:20:83:c1; fixed-address 129.69.62.222; } # ITSM-EYB2 host itsm-tyb2 { hardware ethernet 4a:19:66:41:c5:4d; fixed-address itsm-tyb2.itsm.uni-stuttgart.de; } with the line # this is a comment at the end of a block completely missing. If it's easy to fix that, it would be good. Otherwise put that in the docu too ;-) . Show quoted text
> So to sum up... Was there anything I needed to fix - except cosmetic > bugs?
Yes, I think the errors produced by my last sent dhcpd.conf file are somewhat troublesome. Regards Michael
The reason was that Pool and Include had missing child elements. I just added the missing elements and created a new release to CPAN. Hope I haven't forgotten about anything... If you like, you're more than welcome to look over the list of childrens in each Config:: package to see if it makes sense. Look for: __PACKAGE__->create_children(qw/ ... /); (as you probably already know). 0.13 Wed Oct 5 12:43:42 CEST 2011 - Add custom warnings group for Role->parse() warnings. This can be silenced with (no warnings 'net_isc_dhcpd_config_parse';) - Add example config parser script - Add more child nodes to Config::Include * Net::ISC::DHCPd::Config::Key * Net::ISC::DHCPd::Config::Group * Net::ISC::DHCPd::Config::Block - Add more child nodes to Config::Pool * Net::ISC::DHCPd::Config::Host
On Wed Oct 05 07:56:46 2011, JHTHORSEN wrote: Show quoted text
> The reason was that Pool and Include had missing child elements. I just > added the missing elements and created a new release to CPAN. Hope I > haven't forgotten about anything... > > If you like, you're more than welcome to look over the list of childrens > in each Config:: package to see if it makes sense. Look for: > > __PACKAGE__->create_children(qw/ ... /); > > (as you probably already know). > > > 0.13 Wed Oct 5 12:43:42 CEST 2011 > - Add custom warnings group for Role->parse() warnings. This can > be > silenced with (no warnings 'net_isc_dhcpd_config_parse';) > - Add example config parser script > - Add more child nodes to Config::Include > * Net::ISC::DHCPd::Config::Key > * Net::ISC::DHCPd::Config::Group > * Net::ISC::DHCPd::Config::Block > - Add more child nodes to Config::Pool > * Net::ISC::DHCPd::Config::Host
I think this is safe to mark as resolved.