]>
git.ipfire.org Git - thirdparty/dhcp.git/blob - tests/DHCPv6/292-decline-no-address.pl
3 # Copyright (C) 2007-2022 Internet Systems Consortium, Inc. ("ISC")
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 # Internet Systems Consortium, Inc.
19 # Newmarket, NH 03857 USA
21 # https://www.isc.org/
25 use Time
::HiRes
qw( sleep );
35 # not-yet-standard options
36 my $OPT_TIME_SERVERS = 40;
37 my $OPT_TIME_OFFSET = 41;
40 my $DOCSIS_OPT_ORO = 1;
41 # 2 to 31 are reserved
42 my $DOCSIS_OPT_TFTP_SERVERS = 32;
43 my $DOCSIS_OPT_CONFIG_FILE_NAME = 33;
44 my $DOCSIS_OPT_SYSLOG_SERVERS = 34;
45 my $DOCSIS_OPT_TLV5 = 35;
46 my $DOCSIS_OPT_DEVICE_ID = 36;
47 my $DOCSIS_OPT_CCC = 37;
48 my $DOCSIS_OPT_VERS = 38;
50 # well-known addresses
51 my $All_DHCP_Relay_Agents_and_Servers = "ff02::1:2";
52 my $All_DHCP_Servers = "ff05::1:3";
55 my $client_port = 546;
56 my $server_port = 547;
58 # create a new Solicit message
59 my $msg = dhcp_client
::msg
->new($MSG_DECLINE);
61 # add the Client Identifier (required by DOCSIS and RFC 3315)
62 $msg->add_option($OPT_CLIENTID, dhcp_client
::duid
());
64 # add the Server identifier (required by RFC 3315)
65 $msg->add_option($OPT_SERVERID, "InfiniteEntropy");
67 # add Elapsed Time, set to 0 on first packet (required by RFC 3315)
68 $msg->add_option($OPT_ELAPSED_TIME, "\x00\x00");
70 # add IA_NA for each interface (required by DOCSIS and RFC 3315)
71 # XXX: should this be a single interface only?
73 foreach my $iface (dhcp_client
::iface
()) {
74 my $option_data = pack("NNN", ++$iaid, 0, 0);
75 $msg->add_option($OPT_IA_NA, $option_data);
78 # timeout parameters, from DOCSIS
79 my $IRT = $SOL_TIMEOUT;
80 my $MRT = $SOL_MAX_RT;
81 my $MRC = 4; # DOCSIS says 4, RFC 3315 says it SHOULD be 0
84 # sleep a random amount of time between 0 and 1 second, required by RFC 3315
85 # XXX: this seems pretty stupid
86 sleep(rand($SOL_MAX_DELAY));
92 $mrd_end_time = time() + $MRD;
96 # create our socket, and send our Solicit
97 socket(SOCK
, PF_INET6
, SOCK_DGRAM
, getprotobyname('udp')) || die;
98 my $addr = inet_pton
(AF_INET6
, $All_DHCP_Servers);
99 my $packet = $msg->packet();
100 my $send_ret = send(SOCK
, $packet, 0,
101 pack_sockaddr_in6
($server_port, $addr));
102 if (not defined($send_ret)) {
104 "Error \%d sending DHCPv6 Solicit message;\n\%s\n",
107 } elsif ($send_ret != length($packet)) {
108 print STDERR
"Unable to send entire DHCPv6 Solicit message.\n";
113 my $RAND = rand(0.2) - 0.1;
115 $RT = 2*$RT + $RAND*$RT;
116 if (($RT > $MRT) && ($MRT != 0)) {
117 $RT = $MRT + $RAND*$RT;
120 $RT = $IRT + $RAND*$IRT;
123 my $rt_end_time = time() + $RT;
124 if (defined($mrd_end_time) && ($mrd_end_time > $rt_end_time)) {
125 $rt_end_time = $mrd_end_time;
129 my $timeout = $rt_end_time - time();
131 # print STDERR "Timeout waiting for DHCPv6 Advertise ",
132 # "or Reply message.\n";
136 my @ready = IO
::Select
->new(\
*SOCK
)->can_read($timeout);
142 $recv_ret = recv(SOCK
, $reply, 1500, 0);
143 if (not defined $recv_ret) {
145 "Error \%d receiving DHCPv6 " .
151 $reply_msg = dhcp_client
::msg
::decode
($reply, 1);
152 if (($reply_msg->{msg_type
} == $MSG_ADVERTISE) ||
153 ($reply_msg->{msg_type
} == $MSG_REPLY)) {
159 } until ($reply_msg ||
160 (($MRC != 0) && ($count > $MRC)) ||
161 (defined($mrd_end_time) && ($mrd_end_time > time())));
163 unless ($reply_msg) {
164 if (($MRC != 0) && ($count >= $MRC)) {
166 "No reply after maximum retransmission count.\n";
169 "No reply after maximum retransmission duration.\n";
173 if ($reply_msg && ($reply_msg->{msg_type
} == $MSG_REPLY)) {
174 print "Got DHCPv6 Reply message.\n";
178 #$Data::Dumper::Useqq = 1;
179 #print Dumper($msg), "\n";
180 #print Dumper($msg->packet()), "\n";
182 #print "packet length: ", length($msg->packet()), "\n";