Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/reflect/reflect.go b/reflect/reflect.go
index 2baa4b3..f5ffc1e 100644
--- a/reflect/reflect.go
+++ b/reflect/reflect.go
@@ -48,10 +48,11 @@ 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")
)
const dom = "whoami.miek.nl."
@@ -138,15 +139,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())
}
@@ -173,8 +175,15 @@ func main() {
}
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
You can’t perform that action at this time.