+#subnet 192.168.9.0 netmask 255.255.255.0 {
+# range 192.168.9.2 192.168.9.100;
+# ttl 7200;
+# rttl 3600;
+# router 192.168.9.254;
+# dns-servers 192.168.2.201;
+# ntp-servers 192.168.9.254;
+# broadcast 192.168.9.255;
+# domain-name "foo.bar";
+# {
+# allow 001cc0c33317,001cc0c33318,001cc0c33319,001cc0c33320;
+# static 001cc0c33317 192.168.9.100,001cc0c33318 192.168.9.200;
+# }
+#}
+sub read_config {
+ my ($self) = @_;
+ my ($res, $key, $netmask, $config, $subopt);
+
+ $self->lock($self->{conf_file}, 1);
+ if ($self->{file_handle}) {
+ my $fh = $self->{file_handle};
+ my @lines = <$fh>;
+ $subopt = 0;
+ foreach (@lines) {
+ $self->logger("Read: $_");
+ if ($_ =~ /^\s*subnet\s+([\d\.]+)\s+netmask\s+([\d\.]+)\s+{\s*/) {
+ $self->{_config}->{$key} = $config if $config;
+ $key = $1;
+ $config = undef;
+ $config->{netmask} = $2;
+ $self->logger("Key: $key Netmask: $config->{netmask}");
+ } else {
+ next if (($_ =~ /^\s*}\s*/ && ! $subopt) || $_ =~ /^\s*$/ || $_ =~ /^\s*#.*/);
+ if (! $subopt && $_ =~ /^\s*(range|ttl|rttl|router|dns-servers|ntp-servers|broadcast|domain-name)\s+(.+)\s*;/) {
+ $config->{$1} = $2;
+ $self->logger("Key: $1 Value: $2");
+ } elsif ($subopt &&$_ =~ /^\s*}\s*/) {
+ $subopt = 0;
+ } elsif ($subopt || $_ =~ /^\s*{\s*/) {
+ if ($subopt) {
+ if ($_ =~ /^\s*(allow|static)\s+(.+)\s*;/) {
+ my (@vals, @tmp);
+ @vals = split(/\s*,\s*/, $2);
+ $config->{$1} = [@vals];
+ $self->logger("Key: $1 Value: $2");
+ } else {
+ $key = 'UNDEF' unless $key;
+ my $err = "$key: 'suboptions' Bad format";
+ $self->logger($err, ERROR);
+ $key = undef;
+ $config = undef;
+ die $err;
+ }
+ } else {
+ $subopt = 1;
+ }
+ } else {
+ $key = 'UNDEF' unless $key;
+ my $err = "$key: Bad format";
+ $self->logger($err, ERROR);
+ $key = undef;
+ $config = undef;
+ die $err;
+ }
+ }
+ }
+ if ($config) {
+ $self->{_config}->{$key} = $config;
+ }
+ $self->logger("Config data structure: \n" . Dumper($self->{_config}));
+ $self->unlock($self->{conf_file});
+ if (!$self->{_config}) {
+ die "Empty config file";
+ }
+ } else {
+ die "Could not read config file";
+ }
+}
+