Filename | /usr/local/lib/perl5/site_perl/Net/DNS/Update.pm |
Statements | Executed 14 statements in 1.08ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 44µs | 54µs | BEGIN@32 | Net::DNS::Update::
1 | 1 | 1 | 24µs | 61µs | BEGIN@33 | Net::DNS::Update::
1 | 1 | 1 | 22µs | 195µs | BEGIN@35 | Net::DNS::Update::
1 | 1 | 1 | 21µs | 226µs | BEGIN@37 | Net::DNS::Update::
1 | 1 | 1 | 19µs | 27µs | BEGIN@34 | Net::DNS::Update::
1 | 1 | 1 | 18µs | 18µs | BEGIN@39 | Net::DNS::Update::
0 | 0 | 0 | 0s | 0s | new | Net::DNS::Update::
0 | 0 | 0 | 0s | 0s | push | Net::DNS::Update::
0 | 0 | 0 | 0s | 0s | unique_push | Net::DNS::Update::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Net::DNS::Update; | ||||
2 | |||||
3 | # | ||||
4 | # $Id: Update.pm 1571 2017-06-03 20:14:15Z willem $ | ||||
5 | # | ||||
6 | 1 | 2µs | our $VERSION = (qw$LastChangedRevision: 1571 $)[1]; | ||
7 | |||||
8 | |||||
9 | =head1 NAME | ||||
10 | |||||
11 | Net::DNS::Update - DNS dynamic update packet | ||||
12 | |||||
13 | =head1 SYNOPSIS | ||||
14 | |||||
15 | use Net::DNS; | ||||
16 | |||||
17 | $update = new Net::DNS::Update( 'example.com', 'IN' ); | ||||
18 | |||||
19 | $update->push( prereq => nxrrset('foo.example.com. A') ); | ||||
20 | $update->push( update => rr_add('foo.example.com. 86400 A 192.168.1.2') ); | ||||
21 | |||||
22 | =head1 DESCRIPTION | ||||
23 | |||||
24 | Net::DNS::Update is a subclass of Net::DNS::Packet, to be used for | ||||
25 | making DNS dynamic updates. | ||||
26 | |||||
27 | Programmers should refer to RFC2136 for dynamic update semantics. | ||||
28 | |||||
29 | =cut | ||||
30 | |||||
31 | |||||
32 | 2 | 58µs | 2 | 64µs | # spent 54µs (44+10) within Net::DNS::Update::BEGIN@32 which was called:
# once (44µs+10µs) by Mail::SpamAssassin::PerMsgStatus::BEGIN@74 at line 32 # spent 54µs making 1 call to Net::DNS::Update::BEGIN@32
# spent 10µs making 1 call to strict::import |
33 | 2 | 56µs | 2 | 98µs | # spent 61µs (24+37) within Net::DNS::Update::BEGIN@33 which was called:
# once (24µs+37µs) by Mail::SpamAssassin::PerMsgStatus::BEGIN@74 at line 33 # spent 61µs making 1 call to Net::DNS::Update::BEGIN@33
# spent 37µs making 1 call to warnings::import |
34 | 2 | 65µs | 2 | 34µs | # spent 27µs (19+7) within Net::DNS::Update::BEGIN@34 which was called:
# once (19µs+7µs) by Mail::SpamAssassin::PerMsgStatus::BEGIN@74 at line 34 # spent 27µs making 1 call to Net::DNS::Update::BEGIN@34
# spent 8µs making 1 call to integer::import |
35 | 2 | 63µs | 2 | 367µs | # spent 195µs (22+172) within Net::DNS::Update::BEGIN@35 which was called:
# once (22µs+172µs) by Mail::SpamAssassin::PerMsgStatus::BEGIN@74 at line 35 # spent 195µs making 1 call to Net::DNS::Update::BEGIN@35
# spent 172µs making 1 call to Exporter::import |
36 | |||||
37 | 2 | 68µs | 2 | 431µs | # spent 226µs (21+205) within Net::DNS::Update::BEGIN@37 which was called:
# once (21µs+205µs) by Mail::SpamAssassin::PerMsgStatus::BEGIN@74 at line 37 # spent 226µs making 1 call to Net::DNS::Update::BEGIN@37
# spent 205µs making 1 call to base::import |
38 | |||||
39 | 2 | 756µs | 1 | 18µs | # spent 18µs within Net::DNS::Update::BEGIN@39 which was called:
# once (18µs+0s) by Mail::SpamAssassin::PerMsgStatus::BEGIN@74 at line 39 # spent 18µs making 1 call to Net::DNS::Update::BEGIN@39 |
40 | |||||
41 | |||||
42 | =head1 METHODS | ||||
43 | |||||
44 | =head2 new | ||||
45 | |||||
46 | $update = new Net::DNS::Update; | ||||
47 | $update = new Net::DNS::Update( 'example.com' ); | ||||
48 | $update = new Net::DNS::Update( 'example.com', 'HS' ); | ||||
49 | |||||
50 | Returns a Net::DNS::Update object suitable for performing a DNS | ||||
51 | dynamic update. Specifically, it creates a packet with the header | ||||
52 | opcode set to UPDATE and the zone record type to SOA (per RFC 2136, | ||||
53 | Section 2.3). | ||||
54 | |||||
55 | Programs must use the push() method to add RRs to the prerequisite, | ||||
56 | update, and additional sections before performing the update. | ||||
57 | |||||
58 | Arguments are the zone name and the class. The zone and class may | ||||
59 | be undefined or omitted and default to the default domain from the | ||||
60 | resolver configuration and IN respectively. | ||||
61 | |||||
62 | =cut | ||||
63 | |||||
64 | sub new { | ||||
65 | shift; | ||||
66 | my ( $zone, @class ) = @_; | ||||
67 | |||||
68 | my ($domain) = grep defined && length, $zone, Net::DNS::Resolver->searchlist; | ||||
69 | |||||
70 | eval { | ||||
71 | local $SIG{__DIE__}; | ||||
72 | |||||
73 | my $self = __PACKAGE__->SUPER::new( $domain, 'SOA', @class ); | ||||
74 | |||||
75 | my $header = $self->header; | ||||
76 | $header->opcode('UPDATE'); | ||||
77 | $header->qr(0); | ||||
78 | $header->rd(0); | ||||
79 | |||||
80 | return $self; | ||||
81 | } || croak $@; | ||||
82 | } | ||||
83 | |||||
84 | |||||
85 | =head2 push | ||||
86 | |||||
87 | $ancount = $update->push( prereq => $rr ); | ||||
88 | $nscount = $update->push( update => $rr ); | ||||
89 | $arcount = $update->push( additional => $rr ); | ||||
90 | |||||
91 | $nscount = $update->push( update => $rr1, $rr2, $rr3 ); | ||||
92 | $nscount = $update->push( update => @rr ); | ||||
93 | |||||
94 | Adds RRs to the specified section of the update packet. | ||||
95 | |||||
96 | Returns the number of resource records in the specified section. | ||||
97 | |||||
98 | Section names may be abbreviated to the first three characters. | ||||
99 | |||||
100 | =cut | ||||
101 | |||||
102 | sub push { | ||||
103 | my $self = shift; | ||||
104 | my $list = $self->_section(shift); | ||||
105 | my @arg = grep ref($_), @_; | ||||
106 | |||||
107 | my ($zone) = $self->zone; | ||||
108 | my $zclass = $zone->zclass; | ||||
109 | my @rr = grep $_->class( $_->class =~ /ANY|NONE/ ? () : $zclass ), @arg; | ||||
110 | |||||
111 | CORE::push( @$list, @rr ); | ||||
112 | } | ||||
113 | |||||
114 | |||||
115 | =head2 unique_push | ||||
116 | |||||
117 | $ancount = $update->unique_push( prereq => $rr ); | ||||
118 | $nscount = $update->unique_push( update => $rr ); | ||||
119 | $arcount = $update->unique_push( additional => $rr ); | ||||
120 | |||||
121 | $nscount = $update->unique_push( update => $rr1, $rr2, $rr3 ); | ||||
122 | $nscount = $update->unique_push( update => @rr ); | ||||
123 | |||||
124 | Adds RRs to the specified section of the update packet provided | ||||
125 | that the RRs are not already present in the same section. | ||||
126 | |||||
127 | Returns the number of resource records in the specified section. | ||||
128 | |||||
129 | Section names may be abbreviated to the first three characters. | ||||
130 | |||||
131 | =cut | ||||
132 | |||||
133 | sub unique_push { | ||||
134 | my $self = shift; | ||||
135 | my $list = $self->_section(shift); | ||||
136 | my @arg = grep ref($_), @_; | ||||
137 | |||||
138 | my ($zone) = $self->zone; | ||||
139 | my $zclass = $zone->zclass; | ||||
140 | my @rr = grep $_->class( $_->class =~ /ANY|NONE/ ? () : $zclass ), @arg; | ||||
141 | |||||
142 | my %unique = map { ( bless( {%$_, ttl => 0}, ref $_ )->canonical => $_ ) } @rr, @$list; | ||||
143 | |||||
144 | scalar( @$list = values %unique ); | ||||
145 | } | ||||
146 | |||||
147 | |||||
148 | 1 | 8µs | 1; | ||
149 | |||||
150 | __END__ |