海运的博客

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

diff制作补丁及patch打补丁

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

diff -urN  dnsproxy dnsproxy-new/ -x .git > dns.patch
#-x排除目录

应用补丁:

cd dnsproxy 
patch -p1 < dns.patch 
#复制粘贴的patch文件使用 
patch --ignore-whitespace -p1 < dns.patch 

此内容被密码保护

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

请输入密码访问

此内容被密码保护

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

请输入密码访问

tmux开机启动会话窗口并执行命令

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

加入rc.local,设置home目录,不然进入tmux时进行和home相关的操作时提示$HOME未设定,同时一些和$HOME相关的调用也不正常,如vim配置文件不加载。

export HOME=/root 
tmux new -s name -d "cmd"
tmux neww -t name -d "cmd"

或先新建窗口再执行命令:

tmux new -n window1 -s sess -d
tmux send -t "sess:window1" "top" Enter
tmux neww -n window2 -t sess
tmux send -t "sess:window2" "top" Enter
分类
最新文章
最近回复
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • 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进入关机状态,我想想办...
归档