Comparison

prosodyctl @ 5592:5705e21ba24b

prosodyctl: check dns: Use socket.local_addresses() if available
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 May 2013 14:56:36 +0100
parent 5591:f0bf2a1790d9
child 5610:f73d5fb4ea13
comparison
equal deleted inserted replaced
5591:f0bf2a1790d9 5592:5705e21ba24b
820 end 820 end
821 print("Done.\n"); 821 print("Done.\n");
822 end 822 end
823 if not what or what == "dns" then 823 if not what or what == "dns" then
824 local dns = require "net.dns"; 824 local dns = require "net.dns";
825 local ip = require "util.ip";
825 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222}); 826 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222});
826 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); 827 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269});
827 828
828 local c2s_srv_required, s2s_srv_required; 829 local c2s_srv_required, s2s_srv_required;
829 if not c2s_ports:contains(5222) then 830 if not c2s_ports:contains(5222) then
833 s2s_srv_required = true; 834 s2s_srv_required = true;
834 end 835 end
835 836
836 local problem_hosts = set.new(); 837 local problem_hosts = set.new();
837 838
838 local external_addresses = set.new(); 839 local external_addresses, internal_addresses = set.new(), set.new();
839 840
840 local fqdn = socket.dns.tohostname(socket.dns.gethostname()); 841 local fqdn = socket.dns.tohostname(socket.dns.gethostname());
841 if fqdn then 842 if fqdn then
842 local res = dns.lookup(fqdn, "A"); 843 local res = dns.lookup(fqdn, "A");
843 if res then 844 if res then
848 local res = dns.lookup(fqdn, "AAAA"); 849 local res = dns.lookup(fqdn, "AAAA");
849 if res then 850 if res then
850 for _, record in ipairs(res) do 851 for _, record in ipairs(res) do
851 external_addresses:add(record.aaaa); 852 external_addresses:add(record.aaaa);
852 end 853 end
854 end
855 end
856
857 local local_addresses = socket.local_addresses and socket.local_addresses() or {};
858
859 for addr in it.values(local_addresses) do
860 if not ip.new_ip(addr).private then
861 external_addresses:add(addr);
862 else
863 internal_addresses:add(addr);
853 end 864 end
854 end 865 end
855 866
856 if external_addresses:empty() then 867 if external_addresses:empty() then
857 print(""); 868 print("");
916 if res then 927 if res then
917 for _, record in ipairs(res) do 928 for _, record in ipairs(res) do
918 if external_addresses:contains(record.a) then 929 if external_addresses:contains(record.a) then
919 some_targets_ok = true; 930 some_targets_ok = true;
920 host_ok_v4 = true; 931 host_ok_v4 = true;
932 elseif internal_addresses:contains(record.a) then
933 host_ok_v4 = true;
934 some_targets_ok = true;
935 print(" "..host.." A record points to internal address, external connections might fail");
921 else 936 else
922 print(" "..host.." A record points to unknown address "..record.a); 937 print(" "..host.." A record points to unknown address "..record.a);
923 all_targets_ok = false; 938 all_targets_ok = false;
924 end 939 end
925 end 940 end
928 if res then 943 if res then
929 for _, record in ipairs(res) do 944 for _, record in ipairs(res) do
930 if external_addresses:contains(record.aaaa) then 945 if external_addresses:contains(record.aaaa) then
931 some_targets_ok = true; 946 some_targets_ok = true;
932 host_ok_v6 = true; 947 host_ok_v6 = true;
948 elseif internal_addresses:contains(record.aaaa) then
949 host_ok_v6 = true;
950 some_targets_ok = true;
951 print(" "..host.." AAAA record points to internal address, external connections might fail");
933 else 952 else
934 print(" "..host.." AAAA record points to unknown address "..record.aaaa); 953 print(" "..host.." AAAA record points to unknown address "..record.aaaa);
935 all_targets_ok = false; 954 all_targets_ok = false;
936 end 955 end
937 end 956 end