恥ずかしい勘違いから生まれた、DHCP6の不要かつ部分的な実装
Revision | 916c9dd705307497cf53e8253123e3f6f192c3f1 (tree) |
---|---|
Time | 2021-08-14 06:12:11 |
Author | dyknon <dyknon@user...> |
Commiter | dyknon |
AbstructOption::Numeric
@@ -11,6 +11,8 @@ use Net::DHCP6::Option; | ||
11 | 11 | our $VERSION = "0.001"; |
12 | 12 | our @ISA = qw/Net::DHCP6::Option/; |
13 | 13 | |
14 | +use constant verify => 1; | |
15 | + | |
14 | 16 | sub new { |
15 | 17 | my $class = shift; |
16 | 18 | my $self; |
@@ -0,0 +1,46 @@ | ||
1 | +package Net::DHCP6::AbstractOption::Numeric; | |
2 | +# base class for option | |
3 | + | |
4 | +use strict; | |
5 | +use warnings; | |
6 | +use Net::DHCP6::AbstractOption::FixedLength; | |
7 | + | |
8 | +our $VERSION = "0.001"; | |
9 | +our @ISA = qw/Net::DHCP6::AbstractOption::FixedLength/; | |
10 | + | |
11 | +sub template { ... } | |
12 | +sub range { (undef, undef) } | |
13 | + | |
14 | +sub value { | |
15 | + my $self = shift; | |
16 | + $$self; | |
17 | +} | |
18 | + | |
19 | +sub len { | |
20 | + my $self = shift; | |
21 | + length pack($self->template, 0); | |
22 | +} | |
23 | + | |
24 | +sub verify { | |
25 | + my $self = shift; | |
26 | + my $who = shift; | |
27 | + my ($from, $to) = $self->range; | |
28 | + return 0 if(defined $from && $from > $self->value); | |
29 | + return 0 if(defined $to && $to <= $self->value); | |
30 | + 1; | |
31 | +} | |
32 | + | |
33 | +sub data { | |
34 | + my $self = shift; | |
35 | + die "out of range" unless($self->value >= 0 && $self->value < 2**16); | |
36 | + pack($self->template, $self->value); | |
37 | +} | |
38 | + | |
39 | +sub parse_data { | |
40 | + my $class = shift; | |
41 | + my $data = shift; | |
42 | + my ($value) = unpack($self->template, $data); | |
43 | + \$value; | |
44 | +} | |
45 | + | |
46 | +1; |
@@ -0,0 +1,14 @@ | ||
1 | +package Net::DHCP6::AbstractOption::U16; | |
2 | +# base class for option | |
3 | + | |
4 | +use strict; | |
5 | +use warnings; | |
6 | +use Net::DHCP6::AbstractOption::Numeric; | |
7 | + | |
8 | +our $VERSION = "0.001"; | |
9 | +our @ISA = qw/Net::DHCP6::AbstractOption::Numeric/; | |
10 | + | |
11 | +use constant template => "S>"; | |
12 | +use constant len => 2; | |
13 | + | |
14 | +1; |
@@ -0,0 +1,14 @@ | ||
1 | +package Net::DHCP6::AbstractOption::U32; | |
2 | +# base class for option | |
3 | + | |
4 | +use strict; | |
5 | +use warnings; | |
6 | +use Net::DHCP6::AbstractOption::Numeric; | |
7 | + | |
8 | +our $VERSION = "0.001"; | |
9 | +our @ISA = qw/Net::DHCP6::AbstractOption::Numeric/; | |
10 | + | |
11 | +use constant template => "L>"; | |
12 | +use constant len => 4; | |
13 | + | |
14 | +1; |
@@ -11,6 +11,7 @@ our @ISA = qw/Net::DHCP6::AbstractOption::Ipv6AddrList/; | ||
11 | 11 | |
12 | 12 | use constant code => DHCP6_OPT_DNS_SERVERS; |
13 | 13 | use constant name => "DnsServer"; |
14 | +use constant verify => 1; | |
14 | 15 | |
15 | 16 | __PACKAGE__->register_option; |
16 | 17 | 1; |
@@ -11,6 +11,7 @@ our @ISA = qw/Net::DHCP6::AbstractOption::DomainNameList/; | ||
11 | 11 | |
12 | 12 | use constant code => DHCP6_OPT_DOMAIN_LIST; |
13 | 13 | use constant name => "DomainList"; |
14 | +use constant verify => 1; | |
14 | 15 | |
15 | 16 | __PACKAGE__->register_option; |
16 | 17 | 1; |
@@ -3,15 +3,15 @@ package Net::DHCP6::Option::ElapsedTime; | ||
3 | 3 | |
4 | 4 | use strict; |
5 | 5 | use warnings; |
6 | -use Net::DHCP6::AbstractOption::FixedLength; | |
6 | +use Net::DHCP6::AbstractOption::U16; | |
7 | 7 | use Net::DHCP6::Parameters qw/DHCP6_OPT_ELAPSED_TIME/; |
8 | 8 | |
9 | 9 | our $VERSION = "0.001"; |
10 | -our @ISA = qw/Net::DHCP6::AbstractOption::FixedLength/; | |
10 | +our @ISA = qw/Net::DHCP6::AbstractOption::U16/; | |
11 | 11 | |
12 | 12 | use constant code => DHCP6_OPT_ELAPSED_TIME; |
13 | 13 | use constant name => "ElapsedTime"; |
14 | -use constant len => 2; | |
14 | +use constant verify => 1; | |
15 | 15 | |
16 | 16 | sub new_special { |
17 | 17 | my $class = shift; |
@@ -20,15 +20,9 @@ sub new_special { | ||
20 | 20 | bless $self, $class; |
21 | 21 | } |
22 | 22 | |
23 | -sub data { | |
24 | - my $self = shift; | |
25 | - die "out of range" unless($self->time >= 0 && $self->time < 2**16); | |
26 | - pack("S>", $self->time); | |
27 | -} | |
28 | - | |
29 | 23 | sub time { |
30 | 24 | my $self = shift; |
31 | - $$self; | |
25 | + $self->value; | |
32 | 26 | } |
33 | 27 | |
34 | 28 | sub sec { |
@@ -36,13 +30,6 @@ sub sec { | ||
36 | 30 | $self->time / 100; |
37 | 31 | } |
38 | 32 | |
39 | -sub parse_data { | |
40 | - my $class = shift; | |
41 | - my $data = shift; | |
42 | - my ($time) = unpack("S>", $data); | |
43 | - \$time; | |
44 | -} | |
45 | - | |
46 | 33 | sub data_str { |
47 | 34 | my $self = shift; |
48 | 35 | $self->sec . "s"; |