Mercurial > hg > nginx-tests
annotate http_resolver_ipv4.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | c287864444f8 |
children |
rev | line source |
---|---|
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
2 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
4 # (C) Eugene Grebenschikov |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
5 # (C) Nginx, Inc. |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
6 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
7 # Tests for http resolver with ipv4/ipv6 parameters. |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
8 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
9 ############################################################################### |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
10 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
11 use warnings; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
12 use strict; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
13 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
14 use Test::More; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
15 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
17 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
20 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
21 ############################################################################### |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
22 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
25 |
1943
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http proxy/); |
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
27 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
29 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
31 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
32 daemon off; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
33 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
34 events { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
35 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
36 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
37 http { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
39 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
40 server { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
41 listen 127.0.0.1:8080; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
42 server_name localhost; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
43 |
1943
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
44 add_header X-Addr $upstream_addr always; |
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
45 proxy_next_upstream http_403; |
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
46 |
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
47 location / { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
48 proxy_pass http://$arg_h:%%PORT_8081%%/; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
49 resolver 127.0.0.1:%%PORT_8980_UDP%% ipv4=on ipv6=on; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
50 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
51 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
52 location /ipv4 { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
53 proxy_pass http://$arg_h:%%PORT_8081%%/; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
54 resolver 127.0.0.1:%%PORT_8980_UDP%% ipv4=on ipv6=off; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
55 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
56 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
57 location /ipv6 { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
58 proxy_pass http://$arg_h:%%PORT_8081%%/; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
59 resolver 127.0.0.1:%%PORT_8980_UDP%% ipv4=off ipv6=on; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
60 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
61 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
62 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
63 server { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
64 listen 127.0.0.1:8081; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
65 listen [::1]:%%PORT_8081%%; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
66 server_name localhost; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
67 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
68 location / { |
1943
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
69 # return 403; |
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
70 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
71 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
72 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
73 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
74 EOF |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
75 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
76 $t->try_run('no resolver ipv4')->plan(3); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
77 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
78 $t->run_daemon(\&dns_daemon, port(8980), $t); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
79 $t->waitforfile($t->testdir . '/' . port(8980)); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
80 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
81 ############################################################################### |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
82 |
1944
c287864444f8
Tests: fixed http_resolver_ipv4.t with parallel tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1943
diff
changeset
|
83 my $p1 = port(8081); |
c287864444f8
Tests: fixed http_resolver_ipv4.t with parallel tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1943
diff
changeset
|
84 |
c287864444f8
Tests: fixed http_resolver_ipv4.t with parallel tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1943
diff
changeset
|
85 is(get('/'), "127.0.0.1:$p1, [::1]:$p1", 'ipv4 ipv6'); |
c287864444f8
Tests: fixed http_resolver_ipv4.t with parallel tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1943
diff
changeset
|
86 is(get('/ipv4'), "127.0.0.1:$p1", 'ipv4 only'); |
c287864444f8
Tests: fixed http_resolver_ipv4.t with parallel tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1943
diff
changeset
|
87 is(get('/ipv6'), "[::1]:$p1", 'ipv6 only'); |
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
88 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
89 ############################################################################### |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
90 |
1943
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
91 sub get { |
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
92 my ($uri) = @_; |
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
93 |
1943
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
94 my $r = http_get("$uri?h=example.com"); |
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
95 my ($addr) = $r =~ /X-Addr: (.+)\x0d/m; |
1786f49cca17
Tests: fixed spurious http_resolver_ipv4.t failures.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1797
diff
changeset
|
96 return $addr; |
1797
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
97 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
98 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
99 ############################################################################### |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
100 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
101 sub reply_handler { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
102 my ($recv_data, $port) = @_; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
103 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
104 my (@name, @rdata); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
105 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
106 use constant NOERROR => 0; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
107 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
108 use constant A => 1; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
109 use constant AAAA => 28; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
110 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
111 use constant IN => 1; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
112 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
113 # default values |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
114 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
115 my ($hdr, $rcode, $ttl) = (0x8180, NOERROR, 3600); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
116 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
117 # decode name |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
118 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
119 my ($len, $offset) = (undef, 12); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
120 while (1) { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
121 $len = unpack("\@$offset C", $recv_data); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
122 last if $len == 0; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
123 $offset++; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
124 push @name, unpack("\@$offset A$len", $recv_data); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
125 $offset += $len; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
126 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
127 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
128 $offset -= 1; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
129 my ($id, $type, $class) = unpack("n x$offset n2", $recv_data); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
130 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
131 my $name = join('.', @name); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
132 if ($name eq 'example.com') { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
133 if ($type == A) { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
134 push @rdata, rd_addr($ttl, '127.0.0.1'); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
135 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
136 if ($type == AAAA) { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
137 push @rdata, rd_addr6($ttl, "::1"); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
138 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
139 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
140 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
141 $len = @name; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
142 pack("n6 (C/a*)$len x n2", $id, $hdr | $rcode, 1, scalar @rdata, |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
143 0, 0, @name, $type, $class) . join('', @rdata); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
144 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
145 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
146 sub rd_addr { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
147 my ($ttl, $addr) = @_; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
148 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
149 my $code = 'split(/\./, $addr)'; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
150 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
151 pack 'n3N nC4', 0xc00c, A, IN, $ttl, eval "scalar $code", eval($code); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
152 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
153 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
154 sub expand_ip6 { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
155 my ($addr) = @_; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
156 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
157 substr ($addr, index($addr, "::"), 2) = |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
158 join "0", map { ":" } (0 .. 8 - (split /:/, $addr) + 1); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
159 map { hex "0" x (4 - length $_) . "$_" } split /:/, $addr; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
160 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
161 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
162 sub rd_addr6 { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
163 my ($ttl, $addr) = @_; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
164 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
165 pack 'n3N nn8', 0xc00c, AAAA, IN, $ttl, 16, expand_ip6($addr); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
166 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
167 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
168 sub dns_daemon { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
169 my ($port, $t) = @_; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
170 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
171 my ($data, $recv_data); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
172 my $socket = IO::Socket::INET->new( |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
173 LocalAddr => '127.0.0.1', |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
174 LocalPort => $port, |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
175 Proto => 'udp', |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
176 ) |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
177 or die "Can't create listening socket: $!\n"; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
178 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
179 # signal we are ready |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
180 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
181 open my $fh, '>', $t->testdir() . '/' . $port; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
182 close $fh; |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
183 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
184 while (1) { |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
185 $socket->recv($recv_data, 65536); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
186 $data = reply_handler($recv_data, $port); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
187 $socket->send($data); |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
188 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
189 } |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
190 |
0b06942f0b8b
Tests: http resolver with ipv4/ipv6 parameters.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
191 ############################################################################### |