File 0367-Revise-handling-of-IPv4-compatible-IPv6-address-look.patch of Package erlang (Revision 803d29f7e9aa4c09100926e3598be691)
Currently displaying revision 803d29f7e9aa4c09100926e3598be691 , Show latest
xxxxxxxxxx
1
From f52792b570a9d27f724fa0a107519b8f449c3de2 Mon Sep 17 00:00:00 2001
2
From: Raimo Niskanen <raimo@erlang.org>
3
Date: Fri, 2 Jul 2021 12:09:27 +0200
4
Subject: [PATCH 7/8] Revise handling of IPv4-compatible IPv6 address lookup
5
6
---
7
lib/kernel/src/inet_db.erl | 43 +++++++++++++++++--------------------
8
lib/kernel/src/inet_res.erl | 16 +++++++++++++-
9
2 files changed, 35 insertions(+), 24 deletions(-)
10
11
diff --git a/lib/kernel/src/inet_db.erl b/lib/kernel/src/inet_db.erl
12
index 4644bea344..f95d8c0eec 100644
13
--- a/lib/kernel/src/inet_db.erl
14
+++ b/lib/kernel/src/inet_db.erl
15
16
%% res_gethostbyaddr (newly resolved version)
17
%% match data field directly and cache RRs.
18
%%
19
-res_gethostbyaddr(Name, IP, Rec) ->
20
+res_gethostbyaddr(Domain, IP, Rec) ->
21
RRs = res_filter_rrs(?S_PTR, Rec#dns_rec.anlist),
22
?dbg("res_gethostbyaddr: ~p - ~p~n", [IP, RRs]),
23
LookupFun = res_lookup_fun(RRs),
24
- case resolve_cnames(Name, ?S_PTR, LookupFun) of
25
+ case resolve_cnames(Domain, ?S_PTR, LookupFun) of
26
{error, _} = Error ->
27
Error;
28
{_D, Domains, _Aliases} ->
29
30
end.
31
32
ent_gethostbyaddr([Domain], IP) ->
33
- {IP_1, AddrType, Length} = norm_ip(IP),
34
- H =
35
- #hostent{
36
- h_name = Domain,
37
- h_aliases = [],
38
- h_addr_list = [IP_1],
39
- h_addrtype = AddrType,
40
- h_length = Length },
41
- {ok, H};
42
+ HEnt =
43
+ if
44
+ tuple_size(IP) =:= 4 ->
45
+ #hostent{
46
+ h_name = Domain,
47
+ h_aliases = [],
48
+ h_addr_list = [IP],
49
+ h_addrtype = inet,
50
+ h_length = 4};
51
+ tuple_size(IP) =:= 8 ->
52
+ #hostent{
53
+ h_name = Domain,
54
+ h_aliases = [],
55
+ h_addr_list = [IP],
56
+ h_addrtype = inet6,
57
+ h_length = 16}
58
+ end,
59
+ {ok, HEnt};
60
ent_gethostbyaddr([_ | _] = _Domains, _IP) ->
61
?dbg("gethostbyaddr duplicate domains=~p~n", [_Domains]),
62
{error, nxdomain}.
63
64
-%% Normalize an IPv4-compatible IPv6 address
65
-%% into a plain IPv4 address
66
-%%
67
-norm_ip(IP) when tuple_size(IP) =:= 4 ->
68
- {IP, inet, 4};
69
-norm_ip({0,0,0,0,0,16#ffff,G,H}) ->
70
- A = G bsr 8, B = G band 16#ff, C = H bsr 8, D = H band 16#ff,
71
- {{A,B,C,D}, inet, 4};
72
-norm_ip(IP) when tuple_size(IP) =:= 8 ->
73
- {IP, inet6, 16}.
74
-
75
-
76
77
%%
78
%% Register socket Modules
79
diff --git a/lib/kernel/src/inet_res.erl b/lib/kernel/src/inet_res.erl
80
index f5ab7e6a23..fda656831e 100644
81
--- a/lib/kernel/src/inet_res.erl
82
+++ b/lib/kernel/src/inet_res.erl
83
84
_Error -> {error, formerr}
85
end;
86
gethostbyaddr_tm(IP, Timer) ->
87
- case dn_ip(IP) of
88
+ %% The call to norm_ip/1 here translates a lookup of
89
+ %% ::ffff:A.B.C.D (AAAA in ...ip6.arpa) into a plain
90
+ %% A.B.C.D (A in ...in-addr.arpa) lookup, and pretends
91
+ %% the result as if it was from the original IPv6 lookup
92
+ %%
93
+ case dn_ip(norm_ip(IP)) of
94
{error, _} = Error ->
95
Error;
96
Name ->
97
98
[(N - 10) + $a, $. | Tail]
99
end.
100
101
+%% Normalize an IPv4-compatible IPv6 address
102
+%% into a plain IPv4 address
103
+%%
104
+norm_ip({0,0,0,0,0,16#ffff,G,H}) ->
105
+ A = G bsr 8, B = G band 16#ff, C = H bsr 8, D = H band 16#ff,
106
+ {A,B,C,D};
107
+norm_ip(IP) ->
108
+ IP.
109
+
110
111
112
dns_msg([]) -> [];
113
--
114
2.31.1
115
116