Starting DNSAgent out of sample configuration

This commit is contained in:
DanB
2019-04-05 20:00:44 +02:00
parent a9eee5b6c6
commit c8271bcb9b
6 changed files with 96 additions and 6 deletions

View File

@@ -45,13 +45,15 @@ type DNSAgent struct {
// ListenAndServe will run the DNS handler doing also the connection to listen address
func (da *DNSAgent) ListenAndServe() error {
utils.Logger.Info(fmt.Sprintf("<%s> start listening on <%s:%s>",
utils.DNSAgent, da.cgrCfg.DNSAgentCfg().ListenNet, da.cgrCfg.DNSAgentCfg().Listen))
if strings.HasSuffix(da.cgrCfg.DNSAgentCfg().ListenNet, utils.TLSNoCaps) {
return dns.ListenAndServeTLS(
da.cgrCfg.DNSAgentCfg().Listen,
da.cgrCfg.TlsCfg().ServerCerificate,
da.cgrCfg.TlsCfg().ServerKey,
dns.HandlerFunc(
func(w ResponseWriter, m *Msg) {
func(w dns.ResponseWriter, m *dns.Msg) {
go da.handleMessage(w, m)
}),
)
@@ -60,7 +62,7 @@ func (da *DNSAgent) ListenAndServe() error {
da.cgrCfg.DNSAgentCfg().Listen,
da.cgrCfg.DNSAgentCfg().ListenNet,
dns.HandlerFunc(
func(w ResponseWriter, m *Msg) {
func(w dns.ResponseWriter, m *dns.Msg) {
go da.handleMessage(w, m)
}),
)
@@ -68,6 +70,6 @@ func (da *DNSAgent) ListenAndServe() error {
// handleMessage is the entry point of all DNS requests
// requests are reaching here asynchronously
func (da *DNSAgent) handleMessage(w ResponseWriter, m *dns.Msg) {
func (da *DNSAgent) handleMessage(w dns.ResponseWriter, m *dns.Msg) {
fmt.Printf("got message: %+v\n", m)
}

View File

@@ -427,6 +427,39 @@ func startRadiusAgent(internalSMGChan chan rpcclient.RpcClientConnection, exitCh
exitChan <- true
}
func startDNSAgent(internalSMGChan chan rpcclient.RpcClientConnection,
filterSChan chan *engine.FilterS, exitChan chan bool) {
filterS := <-filterSChan
filterSChan <- filterS
utils.Logger.Info(fmt.Sprintf("starting %s service", utils.DNSAgent))
var err error
var smgConn *rpcclient.RpcClientPool
if len(cfg.RadiusAgentCfg().SessionSConns) != 0 {
smgConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST,
cfg.TlsCfg().ClientKey,
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
cfg.RadiusAgentCfg().SessionSConns, internalSMGChan,
cfg.GeneralCfg().InternalTtl, false)
if err != nil {
utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to SMG: %s", utils.DNSAgent, err.Error()))
exitChan <- true
return
}
}
da, err := agents.NewDNSAgent(cfg, filterS, smgConn)
if err != nil {
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s>", utils.DNSAgent, err.Error()))
exitChan <- true
return
}
if err = da.ListenAndServe(); err != nil {
utils.Logger.Err(fmt.Sprintf("<%s> error: <%s>", utils.DNSAgent, err.Error()))
}
exitChan <- true
}
func startFsAgent(internalSMGChan chan rpcclient.RpcClientConnection, exitChan chan bool) {
var err error
var sS rpcclient.RpcClientConnection
@@ -1450,6 +1483,10 @@ func main() {
go startRadiusAgent(internalSMGChan, exitChan, filterSChan)
}
if cfg.DNSAgentCfg().Enabled {
go startDNSAgent(internalSMGChan, filterSChan, exitChan)
}
if len(cfg.HttpAgentCfg()) != 0 {
go startHTTPAgent(internalSMGChan, exitChan, server, filterSChan,
cfg.GeneralCfg().DefaultTenant)

View File

@@ -455,8 +455,8 @@ const CGRATES_CFG_JSON = `
"dns_agent": {
"enabled": false, // enables the DNS agent: <true|false>
"listen": "127.0.0.1:2053", // address where to listen for DNS requests <x.y.z.y:1234>
"listen_net": "udp", // network to listen on <udp|tcp|tcp-tls>
"listen": "127.0.0.1:53", // address where to listen for DNS requests <x.y.z.y:1234>
"sessions_conns": [ // connections to SessionS for session management and CDR posting
{"address": "*internal"}
],

View File

@@ -741,7 +741,7 @@ func TestDNSAgentJsonCfg(t *testing.T) {
eCfg := &DNSAgentJsonCfg{
Enabled: utils.BoolPointer(false),
Listen_net: utils.StringPointer("udp"),
Listen: utils.StringPointer("127.0.0.1:53"),
Listen: utils.StringPointer("127.0.0.1:2053"),
Sessions_conns: &[]*HaPoolJsonCfg{
{
Address: utils.StringPointer(utils.MetaInternal),

View File

@@ -24,8 +24,8 @@ import (
type DNSAgentCfg struct {
Enabled bool
ListenNet string // udp or tcp
Listen string
ListenNet string // udp or tcp
SessionSConns []*RemoteHost
Timezone string
RequestProcessors []*RequestProcessor

View File

@@ -0,0 +1,51 @@
{
// Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
// Copyright (C) ITsysCOM GmbH
//
// This file contains the default configuration hardcoded into CGRateS.
// This is what you get when you load CGRateS with an empty configuration file.
"stor_db": {
"db_password": "CGRateS.org",
},
"sessions": {
"enabled": true,
"attributes_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}
],
},
"rals": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"rals_conns": [
{"address": "*internal"}
],
},
"chargers": {
"enabled": true,
},
"attributes": {
"enabled": true,
},
"dns_agent": {
"enabled": true,
"listen": ":53"
},
}