mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Starting DNSAgent out of sample configuration
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"}
|
||||
],
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
51
data/conf/samples/dnsagent/cgrates.json
Normal file
51
data/conf/samples/dnsagent/cgrates.json
Normal 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"
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user