forked from dmachard/dnsdist-config-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouting_decode_ecs.yml
More file actions
102 lines (88 loc) · 2.45 KB
/
routing_decode_ecs.yml
File metadata and controls
102 lines (88 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# route traffic according to the provided list of ECS
# and test with dig @192.168.1.16 -p 5753 www.google.com +subnet=10.0.0.1/24
acl:
- 0.0.0.0/0
binds:
- listen_address: "0.0.0.0:53"
reuseport: true
protocol: Do53
threads: 2
pools:
- name: default
- name: quaddns
backends:
- address: "1.1.1.1:53"
protocol: Do53
pools:
- default
- address: "9.9.9.9:53"
protocol: Do53
pools:
- quaddns
query_rules:
- name: "ecs rule"
selector:
type: Lua
function_name: ECSOptionRule
function_code: |
listNmg = newNMG()
listNmg:addMask("10.0.0.0/8")
function ECSOptionRule(dq)
local options = dq:getEDNSOptions()
if options[EDNSOptionCode.ECS] == nil then
return false
end
if options[EDNSOptionCode.ECS]:count() ~= 1 then
return false
end
local ecs = DecodeECS(options[EDNSOptionCode.ECS]:getValues()[1])
if ecs == nil then
return false
end
return listNmg:match(ecs)
end
function DecodeECS(ecs_data)
local ip = string.byte(ecs_data:sub(2, 3))
local netmask = string.byte(ecs_data:sub(3, 4))
local cs_data = ecs_data:sub(5)
local cs_table = {}
-- decode ipv4
if ip == 1 then
-- padding to a size of 4
while #cs_data < 4 do
cs_data = cs_data .. "\0"
end
-- read each byte
for i = 1, #cs_data, 1 do
table.insert(cs_table, string.byte(cs_data:sub(i, i)) )
end
ca = newCA(table.concat(cs_table, "."))
ca:truncate(netmask)
return ca
end
-- decode ipv6
if ip == 2 then
-- padding to a size of 4
while #cs_data < 16 do
cs_data = cs_data .. "\0"
end
-- read each 2 bytes
for i = 1, #cs_data, 2 do
table.insert(cs_table, string.format("%02X%02X", cs_data:byte(i), cs_data:byte(i+1)) )
end
ca = newCA(table.concat(cs_table, ":"))
ca:truncate(netmask)
return ca
end
-- error, this should not happen
return
end
action:
type: Pool
pool_name: quaddns
- name: "default rule"
selector:
type: All
action:
type: Pool
pool_name: default