Created
March 21, 2018 18:35
-
-
Save chantra/abc8edf0c4cdce2e5aaf8c0d5473dd79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/reflect/reflect.go b/reflect/reflect.go | |
index 2baa4b3..5d0953e 100644 | |
--- a/reflect/reflect.go | |
+++ b/reflect/reflect.go | |
@@ -38,6 +38,7 @@ import ( | |
"net" | |
"os" | |
"os/signal" | |
+ "runtime" | |
"runtime/pprof" | |
"strconv" | |
"strings" | |
@@ -48,10 +49,12 @@ import ( | |
) | |
var ( | |
- cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") | |
- printf = flag.Bool("print", false, "print replies") | |
- compress = flag.Bool("compress", false, "compress replies") | |
- tsig = flag.String("tsig", "", "use MD5 hmac tsig: keyname:base64") | |
+ cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") | |
+ printf = flag.Bool("print", false, "print replies") | |
+ compress = flag.Bool("compress", false, "compress replies") | |
+ tsig = flag.String("tsig", "", "use MD5 hmac tsig: keyname:base64") | |
+ soreuseport = flag.Int("soreuseport", 0, "use SO_REUSE_PORT") | |
+ cpu = flag.Int("cpu", 0, "number of cpu to use") | |
) | |
const dom = "whoami.miek.nl." | |
@@ -138,15 +141,16 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) { | |
w.WriteMsg(m) | |
} | |
-func serve(net, name, secret string) { | |
+func serve(net, name, secret string, soreuseport bool) { | |
switch name { | |
case "": | |
- server := &dns.Server{Addr: ":8053", Net: net, TsigSecret: nil} | |
+ server := &dns.Server{Addr: "[::]:8053", Net: net, TsigSecret: nil, Soreuseport: soreuseport} | |
if err := server.ListenAndServe(); err != nil { | |
fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) | |
+ | |
} | |
default: | |
- server := &dns.Server{Addr: ":8053", Net: net, TsigSecret: map[string]string{name: secret}} | |
+ server := &dns.Server{Addr: ":8053", Net: net, TsigSecret: map[string]string{name: secret}, Soreuseport: soreuseport} | |
if err := server.ListenAndServe(); err != nil { | |
fmt.Printf("Failed to setup the "+net+" server: %s\n", err.Error()) | |
} | |
@@ -172,9 +176,19 @@ func main() { | |
defer pprof.StopCPUProfile() | |
} | |
+ if *cpu != 0 { | |
+ runtime.GOMAXPROCS(*cpu) | |
+ } | |
dns.HandleFunc("miek.nl.", handleReflect) | |
- go serve("tcp", name, secret) | |
- go serve("udp", name, secret) | |
+ if *soreuseport > 0 { | |
+ for i := 0; i < *soreuseport; i++ { | |
+ go serve("tcp", name, secret, true) | |
+ go serve("udp", name, secret, true) | |
+ } | |
+ } else { | |
+ go serve("tcp", name, secret, false) | |
+ go serve("udp", name, secret, false) | |
+ } | |
sig := make(chan os.Signal) | |
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) | |
s := <-sig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment