• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

恥ずかしい勘違いから生まれた、DHCP6の不要かつ部分的な実装


コミットメタ情報

リビジョン88d6ccca92ba93399efae9d65e5f631af818a92a (tree)
日時2021-08-12 19:43:39
作者dyknon <dyknon@user...>
コミッターdyknon

ログメッセージ

Rename + changes on InfoReq

MessageExchange -> Exchange
Stateless -> Exchange::InfoReq

変更サマリ

差分

--- a/Net/DHCP6/AbstractOption/DUID.pm
+++ b/Net/DHCP6/AbstractOption/DUID.pm
@@ -20,9 +20,16 @@ sub new {
2020 die "invalid data length"
2121 unless(length $opts{data} >= 1+2 && length $opts{data} <= 128+2);
2222 $self = \$opts{data};
23+ }elsif(@_ == 1 && ref $_[0] eq "ARRAY" && !eval{$_[0]->isa("ARRAY")}){
24+ my $self2 = shift;
25+ return $class->new(@$self2);
2326 }elsif(@_ == 1){
24- $self = shift;
25- $self = \$self if(!length ref $self);
27+ my $self2 = shift;
28+ if(ref $self2 == ""){
29+ $self = \$self2;
30+ }else{
31+ $self = $self2;
32+ }
2633 }elsif(lc($_[0]) eq "llt" && @_ == 4){
2734 shift; #llt
2835 $self = \(pack("S>S>L>", 1, shift, shift) . shift);
--- a/Net/DHCP6/MessageExchange.pm
+++ b/Net/DHCP6/Exchange.pm
@@ -1,4 +1,4 @@
1-package Net::DHCP6::MessageExchange;
1+package Net::DHCP6::Exchange;
22 # RFC8415 15.
33
44 use strict;
--- a/Net/DHCP6/Stateless.pm
+++ b/Net/DHCP6/Exchange/InfoReq.pm
@@ -1,23 +1,25 @@
1-package Net::DHCP6::Stateless;
1+package Net::DHCP6::Exchange::InfoReq;
22 # RFC8415 6.1.
33 # RFC8415 18.2.6.
44
55 use strict;
66 use warnings;
77
8-use Net::DHCP6::MessageExchange qw/NEXT LAST/;
8+use Net::DHCP6::Exchange qw/NEXT LAST/;
99
1010 use Net::DHCP6::Parameters qw(
1111 DHCP6_MT_REPLY
1212 DHCP6_MT_INFORMATION_REQUEST
13+ DHCP6_OPT_CLIENTID
14+ DHCP6_OPT_ORO
1315 DHCP6_OPT_INF_MAX_RT
1416 DHCP6_OPT_INFORMATION_REFRESH_TIME
1517 );
1618 use Net::DHCP6::Message;
17-use Net::DHCP6::Option qw/ElapsedTime OptionRequest/;
19+use Net::DHCP6::Option qw/ElapsedTime OptionRequest ClientId/;
1820
1921 our $VERSION = "0.0.1";
20-our @ISA = qw/Net::DHCP6::MessageExchange/;
22+our @ISA = qw/Net::DHCP6::Exchange/;
2123
2224 use constant irt => 1;
2325 use constant mrc => 0;
@@ -35,8 +37,9 @@ sub add_elements_if_not_exists {
3537 sub new {
3638 my $class = shift;
3739 my %opts = @_;
38- die "requesting options are not given" if(ref $opts{request} ne "ARRAY");
3940
41+ $opts{request} //= [];
42+ $opts{options} //= [];
4043 $opts{mrt} //= 3600;
4144 if($opts{auto_request} // 1){
4245 add_elements_if_not_exists($opts{request},
@@ -45,10 +48,28 @@ sub new {
4548 );
4649 }
4750 delete $opts{auto_request};
51+
52+ my @ooro = grep{$_->code == DHCP6_OPT_ORO}@{$opts{options}};
53+ die "there are multiple option request options" if(@ooro >= 2);
54+ @{$opts{options}} = grep{$_->code != DHCP6_OPT_ORO}@{$opts{options}};
55+ push @{$opts{request}}, $ooro[0]->all_elems if(@ooro);
56+ push @{$opts{options}}, d6opt_new_option_request(list => @{$opts{request}});
57+ delete $opts{request};
58+
59+ my $ocid = grep{$_->code == DHCP6_OPT_CLIENTID}@{$opts{options}};
60+ die "2 client ids given" if($ocid && defined $opts{client_id});
61+ if(!$ocid && !exists $opts{client_id}){
62+ die "no client id given (To send no client ids, specify undef)"
63+ }
64+ if(defined $opts{client_id}){
65+ push @{$opts{options}}, d6opt_new_client_id($opts{client_id});
66+ }
67+ delete $opts{client_id};
68+
4869 $opts{failed} //= sub{};
4970 $opts{recved} //= sub{ 1; };
5071
51- Net::DHCP6::MessageExchange::new($class, %opts);
72+ Net::DHCP6::Exchange::new($class, %opts);
5273 }
5374
5475 sub mrt {
@@ -70,12 +91,7 @@ sub recved {
7091
7192 sub options {
7293 my $self = shift;
73- $self->{options} ? @{$self->{options}} : ();
74-}
75-
76-sub requests {
77- my $self = shift;
78- @{$self->{request}}
94+ @{$self->{options}};
7995 }
8096
8197 sub message {
@@ -83,7 +99,6 @@ sub message {
8399 Net::DHCP6::Message->new(DHCP6_MT_INFORMATION_REQUEST,
84100 $self->xid,
85101 $self->options,
86- d6opt_new_option_request($self->requests),
87102 d6opt_new_elapsed_time($self->elapsed // 0),
88103 );
89104 }
--- a/query_dns_servers.pl
+++ b/query_dns_servers.pl
@@ -11,7 +11,7 @@ use Net::DHCP6::Parameters qw(
1111 DHCP6_OPT_DNS_SERVERS
1212 );
1313 use Net::DHCP6::Option qw/:all/;
14-use Net::DHCP6::Stateless;
14+use Net::DHCP6::Exchange::InfoReq;
1515 use Socket qw/getaddrinfo AF_INET6 SOCK_DGRAM AI_PASSIVE/;
1616
1717 use constant IF => "eth1";
@@ -43,11 +43,9 @@ my $bind_address_packed = $gai[1]->{addr};
4343
4444 my $ll_packed = pack "C*", map{hex $_}split(/[:.-]/, $ll_str);
4545
46-my $client = Net::DHCP6::Stateless->new(
46+my $client = Net::DHCP6::Exchange::InfoReq->new(
4747 local => $bind_address_packed,
48- options => [
49- d6opt_new_client_id(LL => 1, $ll_packed)
50- ],
48+ client_id => [ LL => 1, $ll_packed ],
5149 request => [
5250 DHCP6_OPT_DNS_SERVERS,
5351 ],