海运的博客

dnsporxy自定义edns ip地址补丁

发布时间:December 12, 2019 // 分类: // No Comments

转发解析主函数为Resolve,调用replyFromCache进行edns处理。

diff -urN -x .git dnsproxy/main.go dnsproxy-mod/main.go
--- dnsproxy/main.go    2019-12-12 15:41:28.962196992 +0800
+++ dnsproxy-mod/main.go        2019-12-12 15:46:45.248460512 +0800
@@ -72,6 +72,8 @@
        // Use EDNS Client Subnet extension
        EnableEDNSSubnet bool `long:"edns" description:"Use EDNS Client Subnet extension" optional:"yes" optional-value:"true"`
 
+       EDNSAddr string `long:"ednsaddr" description:"Send EDNS Client Address"`
+
        // Print DNSProxy version (just for the help)
        Version bool `long:"version" description:"Prints the program version"`
 }
@@ -146,6 +148,7 @@
 // createProxyConfig creates proxy.Config from the command line arguments
 func createProxyConfig(options Options) proxy.Config {
        listenIP := net.ParseIP(options.ListenAddr)
+       ednsIP := net.ParseIP(options.EDNSAddr)
        if listenIP == nil {
                log.Fatalf("cannot parse %s", options.ListenAddr)
        }
@@ -166,6 +169,7 @@
                RefuseAny:                options.RefuseAny,
                AllServers:               options.AllServers,
                EnableEDNSClientSubnet:   options.EnableEDNSSubnet,
+               EDNSAddr:                 ednsIP,
        }
 
        if options.Fallbacks != nil {
diff -urN -x .git dnsproxy/proxy/proxy_cache.go dnsproxy-mod/proxy/proxy_cache.go
--- dnsproxy/proxy/proxy_cache.go       2019-12-12 15:41:28.970197100 +0800
+++ dnsproxy-mod/proxy/proxy_cache.go   2019-12-12 15:40:14.297190512 +0800
@@ -10,11 +10,11 @@
 // Get response from general or subnet cache
 // Return TRUE if response is found in cache
 func (p *Proxy) replyFromCache(d *DNSContext) bool {
-       if p.cache == nil {
-               return false
-       }
 
        if !p.Config.EnableEDNSClientSubnet {
+               if p.cache == nil {
+                       return false
+               }
                val, ok := p.cache.Get(d.Req)
                if ok && val != nil {
                        d.Res = val
@@ -31,11 +31,15 @@
        if mask == 0 {
                // Set EDNS Client-Subnet data
                var clientIP net.IP
-               switch addr := d.Addr.(type) {
-               case *net.UDPAddr:
-                       clientIP = addr.IP
-               case *net.TCPAddr:
-                       clientIP = addr.IP
+               if p.Config.EDNSAddr != nil {
+                       clientIP = p.Config.EDNSAddr
+               } else {
+                       switch addr := d.Addr.(type) {
+                       case *net.UDPAddr:
+                               clientIP = addr.IP
+                       case *net.TCPAddr:
+                               clientIP = addr.IP
+                       }
                }
 
                if clientIP != nil && isPublicIP(clientIP) {
diff -urN -x .git dnsproxy/proxy/proxy.go dnsproxy-mod/proxy/proxy.go
--- dnsproxy/proxy/proxy.go     2019-12-12 15:41:28.970197100 +0800
+++ dnsproxy-mod/proxy/proxy.go 2019-12-12 14:09:50.799051551 +0800
@@ -120,6 +120,7 @@
        // We store these responses in general cache (without subnet)
        //  so they will never be used for clients with public IP addresses.
        EnableEDNSClientSubnet bool
+       EDNSAddr               net.IP // ECS IP used in request
 
        CacheEnabled   bool // cache status
        CacheSizeBytes int  // Cache size (in bytes). Default: 64k

注意:未开启edns时,客户端使用edns也可以转发,但是如果同个域名有缓存带不带edns返回的结果都相同
https://github.com/AdguardTeam/dnsproxy

标签:none

评论已关闭

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...