DNSAgent - create branch on next path usage in order to append to the same answer

This commit is contained in:
DanB
2019-06-23 17:42:09 +02:00
parent d8f44da254
commit 95df7618e9
6 changed files with 29 additions and 9 deletions

View File

@@ -147,6 +147,7 @@ func (ar *AgentRequest) AsNavigableMap(tplFlds []*config.FCTemplate) (
}
var valSet []*config.NMItem
fldPath := strings.Split(tplFld.FieldId, utils.NestingSep)
nMItm := &config.NMItem{Data: out, Path: fldPath, Config: tplFld}
if nMFields, err := ar.CGRAReq.FieldAsInterface(fldPath); err != nil {
if err != utils.ErrNotFound {

View File

@@ -167,7 +167,8 @@ func (da *DNSAgent) processRequest(reqProcessor *config.RequestProcessor,
break
}
}
cgrArgs := cgrEv.ConsumeArgs(reqProcessor.Flags.HasKey(utils.MetaDispatchers), reqType == utils.MetaAuth || reqType == utils.MetaEvent)
cgrArgs := cgrEv.ConsumeArgs(reqProcessor.Flags.HasKey(utils.MetaDispatchers),
reqType == utils.MetaAuth || reqType == utils.MetaEvent)
if reqProcessor.Flags.HasKey(utils.MetaLog) {
utils.Logger.Info(
fmt.Sprintf("<%s> LOG, processorID: <%s>, message: %s",

View File

@@ -179,7 +179,8 @@ func testDNSitClntNAPTRSuppliers(t *testing.T) {
}
if rply, err := dnsClnt.ReadMsg(); err != nil {
t.Error(err)
} else {
} else if len(rply.Answer) != 2 {
t.Errorf("wrong number of records: %s", utils.ToIJSON(rply.Answer))
if rply.Rcode != dns.RcodeSuccess {
t.Errorf("failed to get an valid answer\n%v", rply)
}
@@ -190,6 +191,10 @@ func testDNSitClntNAPTRSuppliers(t *testing.T) {
if answr.Regexp != "!^(.*)$!sip:1@172.16.1.11!" {
t.Errorf("received: <%q>", answr.Regexp)
}
answr2 := rply.Answer[1].(*dns.NAPTR)
if answr2.Regexp != "!^(.*)$!sip:\\1@172.16.1.12!" {
t.Errorf("received: <%q>", answr.Regexp)
}
}
}

View File

@@ -147,6 +147,7 @@ func appendDNSAnswer(msg *dns.Msg) (err error) {
// updateDNSMsgFromNM will update DNS message with values from NavigableMap
func updateDNSMsgFromNM(msg *dns.Msg, nm *config.NavigableMap) (err error) {
msgFields := make(map[string]struct{}) // work around to NMap issue
for _, valX := range nm.Values() {
nmItms, cast := valX.([]*config.NMItem)
if !cast {
@@ -155,15 +156,21 @@ func updateDNSMsgFromNM(msg *dns.Msg, nm *config.NavigableMap) (err error) {
if len(nmItms) == 0 {
continue
}
cfgItm := nmItms[0] // first item gives some config for the rest
if len(msg.Answer) == 0 || cfgItm.Config.NewBranch {
if err = appendDNSAnswer(msg); err != nil {
return
}
}
cfgItm := nmItms[0] // first item gives some config for the rest, cannot iterate through NMItems since they are multipled by order
if len(cfgItm.Path) == 0 {
return errors.New("empty path in config item")
}
apnd := len(msg.Answer) == 0
if _, has := msgFields[cfgItm.Path[0]]; has { // force append if the same path was already used
apnd = true
}
if apnd {
if err = appendDNSAnswer(msg); err != nil {
return
}
msgFields = make(map[string]struct{}) // reset the fields inside since we have a new message
}
switch cfgItm.Path[0] {
case utils.Rcode:
var itm int64
@@ -211,6 +218,8 @@ func updateDNSMsgFromNM(msg *dns.Msg, nm *config.NavigableMap) (err error) {
msg.Answer[len(msg.Answer)-1].(*dns.NAPTR).Replacement = utils.IfaceAsString(cfgItm.Data)
}
msgFields[cfgItm.Path[0]] = struct{}{} // detect new branch
}
return
}

View File

@@ -7,6 +7,10 @@
// This is what you get when you load CGRateS with an empty configuration file.
"general": {
"log_level": 7, // control the level of messages logged (0-emerg to 7-debug)
},
"stor_db": {
"db_password": "CGRateS.org",
},

View File

@@ -53,7 +53,7 @@
{"tag": "NAPTRService", "field_id": "Service",
"type": "*constant", "value": "E2U+SIP"},
{"tag": "NAPTRRegexp", "field_id": "Regexp", "type": "*variable",
"value": "~*cgrep.Suppliers.SortedSuppliers[1].SupplierParameters;!"},
"value": "~*cgrep.Suppliers.SortedSuppliers[1].SupplierParameters"},
],
},
],