|
|
@ -2,16 +2,24 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
"github.com/fangdingjun/gpp/util"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func initListeners(c *cfg) {
|
|
|
|
func initListeners(c *cfg) {
|
|
|
|
for _, a := range c.listen {
|
|
|
|
for _, a := range c.listen {
|
|
|
|
log.Printf("Listen on %s %s...\n", a.network, a.addr)
|
|
|
|
log.Printf("Listen on %s %s...\n", a.network, a.addr)
|
|
|
|
s := dns.Server{Addr: a.addr, Net: a.network}
|
|
|
|
s := &dns.Server{Addr: a.addr, Net: a.network}
|
|
|
|
go s.ListenAndServe()
|
|
|
|
go func(s *dns.Server) {
|
|
|
|
|
|
|
|
err := s.ListenAndServe()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Println(err)
|
|
|
|
|
|
|
|
os.Exit(-1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -30,5 +38,13 @@ func main() {
|
|
|
|
initRouters(config)
|
|
|
|
initRouters(config)
|
|
|
|
initListeners(config)
|
|
|
|
initListeners(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make a delay to make sure net bind completed before drop privilege
|
|
|
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = util.DropPrivilege(config.User, config.Group)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
select {}
|
|
|
|
select {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|