From bd68a65705f17af07e4183877b797019ea3847a0 Mon Sep 17 00:00:00 2001 From: arberkatellari Date: Fri, 30 Jun 2023 11:02:24 -0400 Subject: [PATCH] Add SRV and A record implementation & tests --- agents/dnsagent_it_test.go | 939 +++++++++++++++++- agents/libdns.go | 47 +- .../samples/dnsagent_internal/attributes.json | 51 +- .../samples/dnsagent_internal/cgrates.json | 41 +- .../samples/dnsagent_internal/dryrun.json | 70 +- data/conf/samples/dnsagent_internal/opts.json | 90 +- .../samples/dnsagent_internal/suppliers.json | 104 +- .../samples/dnsagent_mongo/attributes.json | 52 +- data/conf/samples/dnsagent_mongo/dryrun.json | 43 +- data/conf/samples/dnsagent_mongo/opts.json | 91 +- .../samples/dnsagent_mongo/suppliers.json | 86 ++ .../samples/dnsagent_mysql/attributes.json | 51 +- data/conf/samples/dnsagent_mysql/dryrun.json | 40 +- data/conf/samples/dnsagent_mysql/opts.json | 88 +- .../samples/dnsagent_mysql/suppliers.json | 86 ++ data/tariffplans/dnsagent/Attributes.csv | 6 +- data/tariffplans/dnsagent/Routes.csv | 7 +- utils/consts.go | 3 + 18 files changed, 1743 insertions(+), 152 deletions(-) diff --git a/agents/dnsagent_it_test.go b/agents/dnsagent_it_test.go index 7eeaec8a4..97c985911 100644 --- a/agents/dnsagent_it_test.go +++ b/agents/dnsagent_it_test.go @@ -54,10 +54,20 @@ var ( testDNSitApierRpcConn, testDNSitTPFromFolder, testDNSitClntConn, + testDNSitClntADryRun, + testDNSitClntSRVDryRun, testDNSitClntNAPTRDryRun, + testDNSitClntAAttributes, + testDNSitClntSRVAttributes, testDNSitClntNAPTRAttributes, + testDNSitClntASuppliers, + testDNSitClntSRVSuppliers, testDNSitClntNAPTRSuppliers, + testDNSitClntAOpts, + testDNSitClntSRVOpts, testDNSitClntNAPTROpts, + testDNSitClntAOptsWithAttributes, + testDNSitClntSRVOptsWithAttributes, testDNSitClntNAPTROptsWithAttributes, testDNSitStopEngine, } @@ -157,9 +167,141 @@ func testDNSitClntConn(t *testing.T) { } } +func testDNSitClntADryRun(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("cgrates.org.", dns.TypeA) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.UDP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "51.38.77.188" { + t.Errorf("Expected :<%q> , received: <%q>", "51.38.77.188", answr0.A) + } + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "51.38.77.188" { + t.Errorf("Expected :<%q> , received: <%q>", "51.38.77.188", answr0.A) + } + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCPTLS.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "51.38.77.188" { + t.Errorf("Expected :<%q> , received: <%q>", "51.38.77.188", answr0.A) + } + } +} +func testDNSitClntSRVDryRun(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("_sip._tcp.opensips.org.", dns.TypeSRV) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.UDP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Priority) + } + if answr.Weight != uint16(50) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(50), answr.Weight) + } + if answr.Port != uint16(5060) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5060), answr.Port) + } + if answr.Target != "opensips.org." { + t.Errorf("Expected :<%q> , received: <%q>", "opensips.org.", answr.Target) + } + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Priority) + } + if answr.Weight != uint16(50) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(50), answr.Weight) + } + if answr.Port != uint16(5060) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5060), answr.Port) + } + if answr.Target != "opensips.org." { + t.Errorf("Expected :<%q> , received: <%q>", "opensips.org.", answr.Target) + } + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCPTLS.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Priority) + } + if answr.Weight != uint16(50) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(50), answr.Weight) + } + if answr.Port != uint16(5060) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5060), answr.Port) + } + if answr.Target != "opensips.org." { + t.Errorf("Expected :<%q> , received: <%q>", "opensips.org.", answr.Target) + } + } +} + func testDNSitClntNAPTRDryRun(t *testing.T) { m := new(dns.Msg) - m.SetQuestion("3.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR) + m.SetQuestion("4.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR) if err := dnsClnt.UDP.WriteMsg(m); err != nil { t.Error(err) } @@ -173,24 +315,10 @@ func testDNSitClntNAPTRDryRun(t *testing.T) { if answr.Order != 100 { t.Errorf("received: <%q>", answr.Order) } - if answr.Preference != 10 { - t.Errorf("received: <%q>", answr.Preference) - } - if answr.Flags != "U" { - t.Errorf("received: <%q>", answr.Flags) - } - if answr.Service != "E2U+SIP" { - t.Errorf("received: <%q>", answr.Service) - } - if answr.Regexp != "!^(.*)$!sip:1@172.16.1.10.!" { - t.Errorf("received: <%q>", answr.Regexp) - } - if answr.Replacement != "." { - t.Errorf("received: <%q>", answr.Replacement) + if answr.Regexp != "sip:1@172.16.1.1." { + t.Errorf("Expected :<%q> , received: <%q>", "sip:1\\@172.16.1.1.", answr.Regexp) } } - - m.SetQuestion("3.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR) if err := dnsClnt.TCP.WriteMsg(m); err != nil { t.Error(err) } @@ -204,24 +332,10 @@ func testDNSitClntNAPTRDryRun(t *testing.T) { if answr.Order != 100 { t.Errorf("received: <%q>", answr.Order) } - if answr.Preference != 10 { - t.Errorf("received: <%q>", answr.Preference) - } - if answr.Flags != "U" { - t.Errorf("received: <%q>", answr.Flags) - } - if answr.Service != "E2U+SIP" { - t.Errorf("received: <%q>", answr.Service) - } - if answr.Regexp != "!^(.*)$!sip:1@172.16.1.10.!" { - t.Errorf("received: <%q>", answr.Regexp) - } - if answr.Replacement != "." { - t.Errorf("received: <%q>", answr.Replacement) + if answr.Regexp != "sip:1@172.16.1.1." { + t.Errorf("Expected :<%q> , received: <%q>", "sip:1\\@172.16.1.1.", answr.Regexp) } } - - m.SetQuestion("3.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR) if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { t.Error(err) } @@ -235,23 +349,149 @@ func testDNSitClntNAPTRDryRun(t *testing.T) { if answr.Order != 100 { t.Errorf("received: <%q>", answr.Order) } - if answr.Preference != 10 { - t.Errorf("received: <%q>", answr.Preference) - } - if answr.Flags != "U" { - t.Errorf("received: <%q>", answr.Flags) - } - if answr.Service != "E2U+SIP" { - t.Errorf("received: <%q>", answr.Service) - } - if answr.Regexp != "!^(.*)$!sip:1@172.16.1.10.!" { - t.Errorf("received: <%q>", answr.Regexp) - } - if answr.Replacement != "." { - t.Errorf("received: <%q>", answr.Replacement) + if answr.Regexp != "sip:1@172.16.1.1." { + t.Errorf("Expected :<%q> , received: <%q>", "sip:1\\@172.16.1.1.", answr.Regexp) } } +} +func testDNSitClntAAttributes(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("dns.google.", dns.TypeA) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.UDP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "8.8.8.8" { + t.Errorf("Expected :<%q> , received: <%q>", "8.8.8.8", answr0.A) + } + answr1 := rply.Answer[1].(*dns.A) + if answr1.A.String() != "8.8.4.4" { + t.Errorf("Expected :<%q> , received: <%q>", "8.8.4.4", answr1.A) + } + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "8.8.8.8" { + t.Errorf("Expected :<%q> , received: <%q>", "8.8.8.8", answr0.A) + } + answr1 := rply.Answer[1].(*dns.A) + if answr1.A.String() != "8.8.4.4" { + t.Errorf("Expected :<%q> , received: <%q>", "8.8.4.4", answr1.A) + } + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCPTLS.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "8.8.8.8" { + t.Errorf("Expected :<%q> , received: <%q>", "8.8.8.8", answr0.A) + } + answr1 := rply.Answer[1].(*dns.A) + if answr1.A.String() != "8.8.4.4" { + t.Errorf("Expected :<%q> , received: <%q>", "8.8.4.4", answr1.A) + } + } +} + +func testDNSitClntSRVAttributes(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("_ldap._tcp.google.com.", dns.TypeSRV) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.UDP.ReadMsg(); err != nil { + t.Error(err) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(5) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5), answr.Priority) + } + if answr.Weight != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Weight) + } + if answr.Port != uint16(389) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(389), answr.Port) + } + if answr.Target != "ldap.google.com." { + t.Errorf("Expected :<%q> , received: <%q>", "ldap.google.com.", answr.Target) + } + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCP.ReadMsg(); err != nil { + t.Error(err) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(5) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5), answr.Priority) + } + if answr.Weight != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Weight) + } + if answr.Port != uint16(389) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(389), answr.Port) + } + if answr.Target != "ldap.google.com." { + t.Errorf("Expected :<%q> , received: <%q>", "ldap.google.com.", answr.Target) + } + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCPTLS.ReadMsg(); err != nil { + t.Error(err) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(5) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5), answr.Priority) + } + if answr.Weight != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Weight) + } + if answr.Port != uint16(389) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(389), answr.Port) + } + if answr.Target != "ldap.google.com." { + t.Errorf("Expected :<%q> , received: <%q>", "ldap.google.com.", answr.Target) + } + } } func testDNSitClntNAPTRAttributes(t *testing.T) { @@ -310,6 +550,195 @@ func testDNSitClntNAPTRAttributes(t *testing.T) { } } +func testDNSitClntASuppliers(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("go.dev.", dns.TypeA) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err := dnsClnt.UDP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("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) + } + + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "216.239.32.21" { + t.Errorf("Expected :<%q> , received: <%q>", "216.239.32.21", answr0.A) + } + answr1 := rply.Answer[1].(*dns.A) + if answr1.A.String() != "216.239.34.21" { + t.Errorf("Expected :<%q> , received: <%q>", "216.239.34.21", answr1.A) + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("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) + } + + answr0 = rply.Answer[0].(*dns.A) + if answr0.A.String() != "216.239.32.21" { + t.Errorf("Expected :<%q> , received: <%q>", "216.239.32.21", answr0.A) + } + answr1 = rply.Answer[1].(*dns.A) + if answr1.A.String() != "216.239.34.21" { + t.Errorf("Expected :<%q> , received: <%q>", "216.239.34.21", answr1.A) + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCPTLS.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("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) + } + + answr0 = rply.Answer[0].(*dns.A) + if answr0.A.String() != "216.239.32.21" { + t.Errorf("Expected :<%q> , received: <%q>", "216.239.32.21", answr0.A) + } + answr1 = rply.Answer[1].(*dns.A) + if answr1.A.String() != "216.239.34.21" { + t.Errorf("Expected :<%q> , received: <%q>", "216.239.34.21", answr1.A) + } + +} + +func testDNSitClntSRVSuppliers(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("_xmpp-client._tcp.xmpp.org.", dns.TypeSRV) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err := dnsClnt.UDP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("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) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr.Priority) + } + if answr.Weight != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr.Weight) + } + if answr.Port != uint16(9222) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(9222), answr.Port) + } + if answr.Target != "xmpp.xmpp.org." { + t.Errorf("Expected :<%q> , received: <%q>", "xmpp.xmpp.org.", answr.Target) + } + answr2 := rply.Answer[1].(*dns.SRV) + if answr2.Priority != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr2.Priority) + } + if answr2.Weight != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr2.Weight) + } + if answr2.Port != uint16(9222) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(9222), answr2.Port) + } + if answr2.Target != "xmpp.xmpp.com." { + t.Errorf("Expected :<%q> , received: <%q>", "xmpp.xmpp.com.", answr2.Target) + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("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) + } + answr = rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr.Priority) + } + if answr.Weight != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr.Weight) + } + if answr.Port != uint16(9222) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(9222), answr.Port) + } + if answr.Target != "xmpp.xmpp.org." { + t.Errorf("Expected :<%q> , received: <%q>", "xmpp.xmpp.org.", answr.Target) + } + answr2 = rply.Answer[1].(*dns.SRV) + if answr2.Priority != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr2.Priority) + } + if answr2.Weight != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr2.Weight) + } + if answr2.Port != uint16(9222) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(9222), answr2.Port) + } + if answr2.Target != "xmpp.xmpp.com." { + t.Errorf("Expected :<%q> , received: <%q>", "xmpp.xmpp.com.", answr2.Target) + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCPTLS.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 2 { + t.Fatalf("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) + } + answr = rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr.Priority) + } + if answr.Weight != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr.Weight) + } + if answr.Port != uint16(9222) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(9222), answr.Port) + } + if answr.Target != "xmpp.xmpp.org." { + t.Errorf("Expected :<%q> , received: <%q>", "xmpp.xmpp.org.", answr.Target) + } + answr2 = rply.Answer[1].(*dns.SRV) + if answr2.Priority != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr2.Priority) + } + if answr2.Weight != uint16(1) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(1), answr2.Weight) + } + if answr2.Port != uint16(9222) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(9222), answr2.Port) + } + if answr2.Target != "xmpp.xmpp.com." { + t.Errorf("Expected :<%q> , received: <%q>", "xmpp.xmpp.com.", answr2.Target) + } + +} + func testDNSitClntNAPTRSuppliers(t *testing.T) { m := new(dns.Msg) m.SetQuestion("5.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR) @@ -384,6 +813,225 @@ func testDNSitClntNAPTRSuppliers(t *testing.T) { } } +func testDNSitClntAOpts(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("example.com.", dns.TypeA) + m.SetEdns0(4096, false) + m.IsEdns0().Option = append(m.IsEdns0().Option, &dns.EDNS0_ESU{Uri: "sip:cgrates@cgrates.org"}) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.UDP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "93.184.216.34" { + t.Errorf("Expected :<%q> , received: <%q>", "93.184.216.34", answr0.A) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 2 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@cgrates.com"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } else if ov, can := opts.Option[1].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[1]) + } else if expected := "sip:cgrates@cgrates.net"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + } + + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "93.184.216.34" { + t.Errorf("Expected :<%q> , received: <%q>", "93.184.216.34", answr0.A) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 2 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@cgrates.com"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } else if ov, can := opts.Option[1].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[1]) + } else if expected := "sip:cgrates@cgrates.net"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCPTLS.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "93.184.216.34" { + t.Errorf("Expected :<%q> , received: <%q>", "93.184.216.34", answr0.A) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 2 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@cgrates.com"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } else if ov, can := opts.Option[1].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[1]) + } else if expected := "sip:cgrates@cgrates.net"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + } +} +func testDNSitClntSRVOpts(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("_matrix._tcp.matrix.org.", dns.TypeSRV) + m.SetEdns0(4096, false) + m.IsEdns0().Option = append(m.IsEdns0().Option, + &dns.EDNS0_ESU{Uri: "sip:cgrates@cgrates.org"}) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err := dnsClnt.UDP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("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) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(10) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(10), answr.Priority) + } + if answr.Weight != uint16(5) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5), answr.Weight) + } + if answr.Port != uint16(8443) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(8443), answr.Port) + } + if answr.Target != "matrix-federation.matrix.org.cdn.cloudflare.net." { + t.Errorf("Expected :<%q> , received: <%q>", + "matrix-federation.matrix.org.cdn.cloudflare.net.", answr.Target) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 2 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@cgrates.com"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } else if ov, can := opts.Option[1].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[1]) + } else if expected := "sip:cgrates@cgrates.net"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("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) + } + answr = rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(10) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(10), answr.Priority) + } + if answr.Weight != uint16(5) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5), answr.Weight) + } + if answr.Port != uint16(8443) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(8443), answr.Port) + } + if answr.Target != "matrix-federation.matrix.org.cdn.cloudflare.net." { + t.Errorf("Expected :<%q> , received: <%q>", + "matrix-federation.matrix.org.cdn.cloudflare.net.", answr.Target) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 2 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@cgrates.com"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } else if ov, can := opts.Option[1].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[1]) + } else if expected := "sip:cgrates@cgrates.net"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCPTLS.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("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) + } + answr = rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(10) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(10), answr.Priority) + } + if answr.Weight != uint16(5) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5), answr.Weight) + } + if answr.Port != uint16(8443) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(8443), answr.Port) + } + if answr.Target != "matrix-federation.matrix.org.cdn.cloudflare.net." { + t.Errorf("Expected :<%q> , received: <%q>", + "matrix-federation.matrix.org.cdn.cloudflare.net.", answr.Target) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 2 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@cgrates.com"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } else if ov, can := opts.Option[1].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[1]) + } else if expected := "sip:cgrates@cgrates.net"; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } +} + func testDNSitClntNAPTROpts(t *testing.T) { m := new(dns.Msg) m.SetQuestion("5.6.9.4.7.1.7.1.5.6.8.9.5.e164.arpa.", dns.TypeNAPTR) @@ -525,6 +1173,203 @@ func testDNSitClntNAPTROpts(t *testing.T) { } } +func testDNSitClntAOptsWithAttributes(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("opendns.com.", dns.TypeA) + m.SetEdns0(4096, false) + m.IsEdns0().Option = append(m.IsEdns0().Option, &dns.EDNS0_ESU{Uri: "sip:cgrates@cgrates.org"}) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.UDP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "146.112.62.105" { + t.Errorf("Expected :<%q> , received: <%q>", "146.112.62.105", answr0.A) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 1 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@opendns.com."; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + } + + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCP.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "146.112.62.105" { + t.Errorf("Expected :<%q> , received: <%q>", "146.112.62.105", answr0.A) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 1 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@opendns.com."; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.TCPTLS.ReadMsg(); err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("wrong number of records: %s", utils.ToIJSON(rply.Answer)) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr0 := rply.Answer[0].(*dns.A) + if answr0.A.String() != "146.112.62.105" { + t.Errorf("Expected :<%q> , received: <%q>", "146.112.62.105", answr0.A) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 1 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@opendns.com."; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + } +} + +func testDNSitClntSRVOptsWithAttributes(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("_sip._udp.opensips.org.", dns.TypeSRV) + m.SetEdns0(4096, false) + m.IsEdns0().Option = append(m.IsEdns0().Option, + &dns.EDNS0_ESU{Uri: "sip:cgrates@cgrates.org"}) + if err := dnsClnt.UDP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err := dnsClnt.UDP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("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) + } + answr := rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Priority) + } + if answr.Weight != uint16(50) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(50), answr.Weight) + } + if answr.Port != uint16(5060) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5060), answr.Port) + } + if answr.Target != "opensips.org." { + t.Errorf("Expected :<%q> , received: <%q>", + "opensips.org.", answr.Target) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 1 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@_sip._udp.opensips.org."; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + if err := dnsClnt.TCP.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCP.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("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) + } + answr = rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Priority) + } + if answr.Weight != uint16(50) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(50), answr.Weight) + } + if answr.Port != uint16(5060) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5060), answr.Port) + } + if answr.Target != "opensips.org." { + t.Errorf("Expected :<%q> , received: <%q>", + "opensips.org.", answr.Target) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 1 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@_sip._udp.opensips.org."; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + if err := dnsClnt.TCPTLS.WriteMsg(m); err != nil { + t.Error(err) + } + rply, err = dnsClnt.TCPTLS.ReadMsg() + if err != nil { + t.Error(err) + } else if len(rply.Answer) != 1 { + t.Fatalf("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) + } + answr = rply.Answer[0].(*dns.SRV) + if answr.Priority != uint16(0) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(0), answr.Priority) + } + if answr.Weight != uint16(50) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(50), answr.Weight) + } + if answr.Port != uint16(5060) { + t.Errorf("Expected :<%q> , received: <%q>", uint16(5060), answr.Port) + } + if answr.Target != "opensips.org." { + t.Errorf("Expected :<%q> , received: <%q>", + "opensips.org.", answr.Target) + } + if opts := rply.IsEdns0(); opts == nil { + t.Error("recieved nil options") + } else if len(opts.Option) != 1 { + t.Errorf("recieved wrong number of options: %v", len(opts.Option)) + } else if ov, can := opts.Option[0].(*dns.EDNS0_ESU); !can { + t.Errorf("recieved wrong option type: %T", opts.Option[0]) + } else if expected := "sip:cgrates@_sip._udp.opensips.org."; ov.Uri != expected { + t.Errorf("Expected :<%q> , received: <%q>", expected, ov.Uri) + } + +} + func testDNSitClntNAPTROptsWithAttributes(t *testing.T) { m := new(dns.Msg) m.SetQuestion("7.6.9.4.7.1.7.1.5.6.8.9.5.e164.arpa.", dns.TypeNAPTR) diff --git a/agents/libdns.go b/agents/libdns.go index c182793bd..8481a2bc6 100644 --- a/agents/libdns.go +++ b/agents/libdns.go @@ -595,6 +595,8 @@ func updateDnsAnswer(q []dns.RR, qType uint16, qName string, path []string, valu switch v := q[idx].(type) { case *dns.NAPTR: err = updateDnsNAPTRAnswer(v, path, value) + case *dns.SRV: + err = updateDnsSRVAnswer(v, path, value) case *dns.A: if len(path) < 1 || (path[0] != utils.DNSHdr && len(path) != 1) || @@ -606,7 +608,12 @@ func updateDnsAnswer(q []dns.RR, qType uint16, qName string, path []string, valu case utils.DNSHdr: err = updateDnsRRHeader(&v.Hdr, path[1:], value) case utils.DNSA: - v.A = net.IP(utils.IfaceAsString(value)) + v.A = net.ParseIP(utils.IfaceAsString(value)) + if v.A == nil { + err = fmt.Errorf("invalid IP address <%v>", + utils.IfaceAsString(value)) + return + } default: err = utils.ErrWrongPath } @@ -632,12 +639,50 @@ func newDNSAnswer(qType uint16, qName string) (a dns.RR, err error) { a = &dns.A{Hdr: hdr} case dns.TypeNAPTR: a = &dns.NAPTR{Hdr: hdr} + case dns.TypeSRV: + a = &dns.SRV{Hdr: hdr} default: err = fmt.Errorf("unsupported DNS type: <%v>", dns.TypeToString[qType]) } return } +func updateDnsSRVAnswer(v *dns.SRV, path []string, value any) (err error) { + if len(path) < 1 || + (path[0] != utils.DNSHdr && len(path) != 1) || + (path[0] == utils.DNSHdr && len(path) != 2) { + err = utils.ErrWrongPath + return + } + switch path[0] { + case utils.DNSHdr: + err = updateDnsRRHeader(&v.Hdr, path[1:], value) + case utils.DNSPriority: + var vItm int64 + if vItm, err = utils.IfaceAsTInt64(value); err != nil { + return + } + v.Priority = uint16(vItm) + case utils.Weight: + var vItm int64 + if vItm, err = utils.IfaceAsTInt64(value); err != nil { + return + } + v.Weight = uint16(vItm) + case utils.DNSPort: + var vItm int64 + if vItm, err = utils.IfaceAsTInt64(value); err != nil { + return + } + v.Port = uint16(vItm) + case utils.DNSTarget: + v.Target = utils.IfaceAsString(value) + default: + err = utils.ErrWrongPath + } + return +} + func updateDnsNAPTRAnswer(v *dns.NAPTR, path []string, value any) (err error) { if len(path) < 1 || (path[0] != utils.DNSHdr && len(path) != 1) || diff --git a/data/conf/samples/dnsagent_internal/attributes.json b/data/conf/samples/dnsagent_internal/attributes.json index 0eb837549..61bf715e7 100644 --- a/data/conf/samples/dnsagent_internal/attributes.json +++ b/data/conf/samples/dnsagent_internal/attributes.json @@ -21,9 +21,52 @@ {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegex", "path": "*rep.Answer.Regexp", - "type": "*variable", "value": "~*cgrep.Attributes.NAPTRAddress"}, - ], + "type": "*variable", "value": "~*cgrep.Attributes.NAPTRAddress"} + ] }, - ], -}, + { + "id": "AAttributes", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:dns.google."], + "flags": ["*authorize","*attributes","*log"], + "request_fields":[ + {"tag": "Domain", "path": "*cgreq.Domain", + "type": "*constant", "value": "dns.google."}, + {"tag": "ADomain0", "path": "*cgreq.Aip0", + "type": "*constant", "value": "*attributes"}, + {"tag": "ADomain1", "path": "*cgreq.Aip1", + "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "dns.google."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip0", "path": "*rep.Answer.A", "type": "*variable", "value": "~*cgrep.Attributes.Aip0"}, + {"tag": "Aname1", "path": "*rep.Answer[1].Hdr.Name", "type": "*constant", "value": "dns.google."}, + {"tag": "Attl1", "path": "*rep.Answer[1].Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass1", "path": "*rep.Answer[1].Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype1", "path": "*rep.Answer[1].Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip1", "path": "*rep.Answer[1].A", "type": "*variable", "value": "~*cgrep.Attributes.Aip1"} + ] + }, + { + "id": "SRVAttributes", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_ldap._tcp.google.com."], + "flags": ["*authorize", "*attributes","*log"], + "request_fields":[ + {"tag": "SRVAddress", "path": "*cgreq.SRVAddress", + "type": "*constant", "value": "_ldap._tcp.google.com."}, + {"tag": "SRVName", "path": "*cgreq.SRVName", + "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_ldap._tcp.google.com."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "5"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "0"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "389"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*variable", "value": "~*cgrep.Attributes.SRVName"} + ] + } + ] +} } \ No newline at end of file diff --git a/data/conf/samples/dnsagent_internal/cgrates.json b/data/conf/samples/dnsagent_internal/cgrates.json index 712587070..d42494b5d 100644 --- a/data/conf/samples/dnsagent_internal/cgrates.json +++ b/data/conf/samples/dnsagent_internal/cgrates.json @@ -8,22 +8,22 @@ "general": { - "log_level": 7, // control the level of messages logged (0-emerg to 7-debug) + "log_level": 7 // control the level of messages logged (0-emerg to 7-debug) }, "data_db": { - "db_type": "*internal", + "db_type": "*internal" }, "stor_db": { - "db_type": "*internal", + "db_type": "*internal" }, "schedulers": { "enabled": true, - "cdrs_conns": ["*internal"], + "cdrs_conns": ["*internal"] }, @@ -33,41 +33,41 @@ "rals_conns": ["*internal"], "cdrs_conns": ["*internal"], "chargers_conns": ["*internal"], - "routes_conns": ["*localhost"], + "routes_conns": ["*localhost"] }, "rals": { - "enabled": true, + "enabled": true }, "cdrs": { "enabled": true, - "rals_conns": ["*internal"], + "rals_conns": ["*internal"] }, "chargers": { - "enabled": true, + "enabled": true }, "attributes": { - "enabled": true, + "enabled": true }, "routes": { - "enabled": true, + "enabled": true }, "tls": { - "server_certificate" : "/usr/share/cgrates/tls/server.crt", // path to server certificate(must conatin server.crt + ca.crt) - "server_key":"/usr/share/cgrates/tls/server.key", // path to server key - "client_certificate" : "/usr/share/cgrates/tls/client.crt", // path to client certificate(must conatin client.crt + ca.crt) - "client_key":"/usr/share/cgrates/tls/client.key", // path to client key - "ca_certificate":"/usr/share/cgrates/tls/ca.crt", + "server_certificate" : "/usr/share/cgrates/tls/server.crt", + "server_key":"/usr/share/cgrates/tls/server.key", + "client_certificate" : "/usr/share/cgrates/tls/client.crt", + "client_key":"/usr/share/cgrates/tls/client.key", + "ca_certificate":"/usr/share/cgrates/tls/ca.crt" }, "dns_agent": { @@ -84,15 +84,14 @@ { "address":":2054", "network":"tcp-tls" - }, + } ], - "sessions_conns": ["*localhost"], - + "sessions_conns": ["*localhost"] }, "apiers": { "enabled": true, - "scheduler_conns": ["*internal"], -}, -} \ No newline at end of file + "scheduler_conns": ["*internal"] +} +} diff --git a/data/conf/samples/dnsagent_internal/dryrun.json b/data/conf/samples/dnsagent_internal/dryrun.json index 375ebd4d6..fd5b6561e 100644 --- a/data/conf/samples/dnsagent_internal/dryrun.json +++ b/data/conf/samples/dnsagent_internal/dryrun.json @@ -1,22 +1,52 @@ { -"dns_agent": { - "request_processors": [ - { - "id": "DryRunNAPTR", - "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:4986517174963"], - "flags": ["*dryrun","*log"], - "request_fields":[ - {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"}, - ], - "reply_fields":[ - {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, - {"tag": "NAPTRPreference", "path": "*rep.Answer.Preference", "type": "*constant", "value": "10"}, - {"tag": "NAPTRFlags", "path": "*rep.Answer.Flags", "type": "*constant", "value": "U"}, - {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, - {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, - {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, - ], - }, - ], -}, + "dns_agent": { + "request_processors": [ + { + "id": "DryRunNAPTR", + "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:4986517174963"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, + {"tag": "NAPTRPreference", "path": "*rep.Answer.Preference", "type": "*constant", "value": "10"}, + {"tag": "NAPTRFlags", "path": "*rep.Answer.Flags", "type": "*constant", "value": "U"}, + {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, + {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, + {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."} + ] + }, + { + "id": "DryRunA", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:cgrates.org."], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "cgrates.org."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "51.38.77.188"} + ] + }, + { + "id": "DryRunSRV", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_sip._tcp.opensips.org."], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_sip._tcp.opensips.org."}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "5060"}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "0"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "50"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "opensips.org."} + ] + } + ] + } } \ No newline at end of file diff --git a/data/conf/samples/dnsagent_internal/opts.json b/data/conf/samples/dnsagent_internal/opts.json index 2da9770c6..d4b5c502b 100644 --- a/data/conf/samples/dnsagent_internal/opts.json +++ b/data/conf/samples/dnsagent_internal/opts.json @@ -6,7 +6,7 @@ "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:5986517174965", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], "flags": ["*dryrun","*log"], "request_fields":[ - {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"}, + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -17,8 +17,8 @@ {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, - {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"}, - ], + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] }, { "id": "OptsWithAttributes", @@ -27,7 +27,7 @@ "request_fields":[ {"tag": "Origin", "path": "*cgreq.Origin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, {"tag": "Domanin", "path": "*cgreq.Domanin", "type": "*variable", "value": "~*vars.QueryName{*e164Domain}"}, - {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -36,10 +36,82 @@ {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, - {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true}, - ], + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] }, - ], - }, + { + "id": "OptsA", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:example.com.", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "example.com."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "93.184.216.34"}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, + {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] + }, + { + "id": "AOptsWithAttributes", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:opendns.com."], + "flags": ["*event","*attributes"], + "request_fields":[ + {"tag": "Origin", "path": "*cgreq.AOrigin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, + {"tag": "Domain", "path": "*cgreq.ASIPDomain", "type": "*variable", "value": "~*vars.QueryName"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "example.com."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "146.112.62.105"}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] + }, + { + "id": "OptsSRV", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_matrix._tcp.matrix.org.", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "10"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "5"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "8443"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "matrix-federation.matrix.org.cdn.cloudflare.net."}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, + {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] + }, + { + "id": "SRVOptsWithAttributes", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_sip._udp.opensips.org."], + "flags": ["*event","*attributes"], + "request_fields":[ + {"tag": "Origin", "path": "*cgreq.SRVOrigin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, + {"tag": "Domain", "path": "*cgreq.SRVDomain", "type": "*variable", "value": "~*vars.QueryName"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_sip._udp.opensips.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "0"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "50"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "5060"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "opensips.org."}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] + } + ] + } - } \ No newline at end of file +} \ No newline at end of file diff --git a/data/conf/samples/dnsagent_internal/suppliers.json b/data/conf/samples/dnsagent_internal/suppliers.json index 907df1b1d..152706bde 100644 --- a/data/conf/samples/dnsagent_internal/suppliers.json +++ b/data/conf/samples/dnsagent_internal/suppliers.json @@ -8,12 +8,12 @@ "*string:~*vars.QueryName{*e164}:4986517174965"], "flags": ["*message", "*routes","*continue"], "request_fields":[ - {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1001"}, // so we can match the supplier profile + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1001"} // so we can match the supplier profile ], "reply_fields":[ {"tag": "DispatchReply", "type": "*none", - "blocker": true}, // enforces continue_on_success so we can check answer with filters - ], + "blocker": true} // enforces continue_on_success so we can check answer with filters + ] }, { "id": "NAPTRSuppliersOneSupplier", @@ -34,8 +34,8 @@ {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", - "type": "*group", "value": "."}, - ], + "type": "*group", "value": "."} + ] }, { "id": "NAPTRSuppliersTwoSuppliers", @@ -56,10 +56,96 @@ {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"}, {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", - "type": "*group", "value": "."}, - ], + "type": "*group", "value": "."} + ] }, - ], -}, + { + "id": "ARoutesQuery", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev."], + "flags": ["*message", "*routes","*continue"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1002"} + ], + "reply_fields":[ + {"tag": "DispatchReply", "type": "*none", + "blocker": true} + ] + }, + { + "id": "ASuppliersOneSupplier", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*group", "value": "go.dev."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*group", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*group", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*group", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"} + ] + }, + { + "id": "ASuppliersTwoSuppliers", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer[1].Hdr.Name", "type": "*group", "value": "go.dev."}, + {"tag": "Attl", "path": "*rep.Answer[1].Hdr.Ttl", "type": "*group", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer[1].Hdr.Class", "type": "*group", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer[1].Hdr.Rrtype", "type": "*group", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer[1].A", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"} + ] + }, + { + "id": "SRVRoutesQuery", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org."], + "flags": ["*message", "*routes","*continue"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1003"} + ], + "reply_fields":[ + {"tag": "DispatchReply", "type": "*none", + "blocker": true} + ] + }, + { + "id": "SRVSuppliersOneSupplier", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*group", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*group", "value": "1"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*group", "value": "1"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*group", "value": "9222"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"} + ] + }, + { + "id": "SRVSuppliersTwoSuppliers", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer[1].Hdr.Name", "type": "*group", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer[1].Priority", "type": "*group", "value": "1"}, + {"tag": "SRVWeight", "path": "*rep.Answer[1].Weight", "type": "*group", "value": "1"}, + {"tag": "SRVPort", "path": "*rep.Answer[1].Port", "type": "*group", "value": "9222"}, + {"tag": "SRVTarget", "path": "*rep.Answer[1].Target", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"} + ] + } + ] +} } diff --git a/data/conf/samples/dnsagent_mongo/attributes.json b/data/conf/samples/dnsagent_mongo/attributes.json index e79f73516..08d3f2f84 100644 --- a/data/conf/samples/dnsagent_mongo/attributes.json +++ b/data/conf/samples/dnsagent_mongo/attributes.json @@ -22,10 +22,52 @@ {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegex", "path": "*rep.Answer.Regexp", - "type": "*variable", "value": "~*cgrep.Attributes.NAPTRAddress"}, - ], + "type": "*variable", "value": "~*cgrep.Attributes.NAPTRAddress"} + ] }, - ], -}, - + { + "id": "AAttributes", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:dns.google."], + "flags": ["*authorize","*attributes","*log"], + "request_fields":[ + {"tag": "Domain", "path": "*cgreq.Domain", + "type": "*constant", "value": "dns.google."}, + {"tag": "ADomain0", "path": "*cgreq.Aip0", + "type": "*constant", "value": "*attributes"}, + {"tag": "ADomain1", "path": "*cgreq.Aip1", + "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "dns.google."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip0", "path": "*rep.Answer.A", "type": "*variable", "value": "~*cgrep.Attributes.Aip0"}, + {"tag": "Aname1", "path": "*rep.Answer[1].Hdr.Name", "type": "*constant", "value": "dns.google."}, + {"tag": "Attl1", "path": "*rep.Answer[1].Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass1", "path": "*rep.Answer[1].Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype1", "path": "*rep.Answer[1].Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip1", "path": "*rep.Answer[1].A", "type": "*variable", "value": "~*cgrep.Attributes.Aip1"} + ] + }, + { + "id": "SRVAttributes", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_ldap._tcp.google.com."], + "flags": ["*authorize", "*attributes","*log"], + "request_fields":[ + {"tag": "SRVAddress", "path": "*cgreq.SRVAddress", + "type": "*constant", "value": "_ldap._tcp.google.com."}, + {"tag": "SRVName", "path": "*cgreq.SRVName", + "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_ldap._tcp.google.com."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "5"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "0"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "389"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*variable", "value": "~*cgrep.Attributes.SRVName"} + ] + } + ] +} } \ No newline at end of file diff --git a/data/conf/samples/dnsagent_mongo/dryrun.json b/data/conf/samples/dnsagent_mongo/dryrun.json index 26535baec..5a00b844d 100644 --- a/data/conf/samples/dnsagent_mongo/dryrun.json +++ b/data/conf/samples/dnsagent_mongo/dryrun.json @@ -7,7 +7,7 @@ "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:4986517174963"], "flags": ["*dryrun","*log"], "request_fields":[ - {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"}, + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -15,10 +15,39 @@ {"tag": "NAPTRFlags", "path": "*rep.Answer.Flags", "type": "*constant", "value": "U"}, {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, - {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, - ], + {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."} + ] }, - ], -}, - -} \ No newline at end of file + { + "id": "DryRunA", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:cgrates.org."], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "cgrates.org."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "51.38.77.188"} + ] + }, + { + "id": "DryRunSRV", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_sip._tcp.opensips.org."], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_sip._tcp.opensips.org."}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "5060"}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "0"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "50"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "opensips.org."} + ] + } + ] +} +} diff --git a/data/conf/samples/dnsagent_mongo/opts.json b/data/conf/samples/dnsagent_mongo/opts.json index 2da9770c6..89e4dd669 100644 --- a/data/conf/samples/dnsagent_mongo/opts.json +++ b/data/conf/samples/dnsagent_mongo/opts.json @@ -6,7 +6,7 @@ "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:5986517174965", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], "flags": ["*dryrun","*log"], "request_fields":[ - {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"}, + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -17,8 +17,8 @@ {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, - {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"}, - ], + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] }, { "id": "OptsWithAttributes", @@ -27,7 +27,7 @@ "request_fields":[ {"tag": "Origin", "path": "*cgreq.Origin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, {"tag": "Domanin", "path": "*cgreq.Domanin", "type": "*variable", "value": "~*vars.QueryName{*e164Domain}"}, - {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -36,10 +36,81 @@ {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, - {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true}, - ], + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] }, - ], - }, - - } \ No newline at end of file + { + "id": "OptsA", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:example.com.", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "example.com."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "93.184.216.34"}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, + {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] + }, + { + "id": "AOptsWithAttributes", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:opendns.com."], + "flags": ["*event","*attributes"], + "request_fields":[ + {"tag": "Origin", "path": "*cgreq.AOrigin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, + {"tag": "Domain", "path": "*cgreq.ASIPDomain", "type": "*variable", "value": "~*vars.QueryName"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "example.com."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "146.112.62.105"}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] + }, + { + "id": "OptsSRV", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_matrix._tcp.matrix.org.", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "10"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "5"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "8443"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "matrix-federation.matrix.org.cdn.cloudflare.net."}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, + {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] + }, + { + "id": "SRVOptsWithAttributes", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_sip._udp.opensips.org."], + "flags": ["*event","*attributes"], + "request_fields":[ + {"tag": "Origin", "path": "*cgreq.SRVOrigin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, + {"tag": "Domain", "path": "*cgreq.SRVDomain", "type": "*variable", "value": "~*vars.QueryName"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_sip._udp.opensips.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "0"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "50"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "5060"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "opensips.org."}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] + } + ] + } +} \ No newline at end of file diff --git a/data/conf/samples/dnsagent_mongo/suppliers.json b/data/conf/samples/dnsagent_mongo/suppliers.json index 3e1e52ab8..f36f1e36a 100644 --- a/data/conf/samples/dnsagent_mongo/suppliers.json +++ b/data/conf/samples/dnsagent_mongo/suppliers.json @@ -59,6 +59,92 @@ "type": "*group", "value": "."}, ], }, + { + "id": "ARoutesQuery", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev."], + "flags": ["*message", "*routes","*continue"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1002"} + ], + "reply_fields":[ + {"tag": "DispatchReply", "type": "*none", + "blocker": true} + ] + }, + { + "id": "ASuppliersOneSupplier", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*group", "value": "go.dev."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*group", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*group", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*group", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"} + ] + }, + { + "id": "ASuppliersTwoSuppliers", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer[1].Hdr.Name", "type": "*group", "value": "go.dev."}, + {"tag": "Attl", "path": "*rep.Answer[1].Hdr.Ttl", "type": "*group", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer[1].Hdr.Class", "type": "*group", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer[1].Hdr.Rrtype", "type": "*group", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer[1].A", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"} + ] + }, + { + "id": "SRVRoutesQuery", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org."], + "flags": ["*message", "*routes","*continue"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1003"} + ], + "reply_fields":[ + {"tag": "DispatchReply", "type": "*none", + "blocker": true} + ] + }, + { + "id": "SRVSuppliersOneSupplier", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*group", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*group", "value": "1"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*group", "value": "1"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*group", "value": "9222"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"} + ] + }, + { + "id": "SRVSuppliersTwoSuppliers", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer[1].Hdr.Name", "type": "*group", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer[1].Priority", "type": "*group", "value": "1"}, + {"tag": "SRVWeight", "path": "*rep.Answer[1].Weight", "type": "*group", "value": "1"}, + {"tag": "SRVPort", "path": "*rep.Answer[1].Port", "type": "*group", "value": "9222"}, + {"tag": "SRVTarget", "path": "*rep.Answer[1].Target", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"} + ] + } ], }, diff --git a/data/conf/samples/dnsagent_mysql/attributes.json b/data/conf/samples/dnsagent_mysql/attributes.json index 0eb837549..61bf715e7 100644 --- a/data/conf/samples/dnsagent_mysql/attributes.json +++ b/data/conf/samples/dnsagent_mysql/attributes.json @@ -21,9 +21,52 @@ {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegex", "path": "*rep.Answer.Regexp", - "type": "*variable", "value": "~*cgrep.Attributes.NAPTRAddress"}, - ], + "type": "*variable", "value": "~*cgrep.Attributes.NAPTRAddress"} + ] }, - ], -}, + { + "id": "AAttributes", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:dns.google."], + "flags": ["*authorize","*attributes","*log"], + "request_fields":[ + {"tag": "Domain", "path": "*cgreq.Domain", + "type": "*constant", "value": "dns.google."}, + {"tag": "ADomain0", "path": "*cgreq.Aip0", + "type": "*constant", "value": "*attributes"}, + {"tag": "ADomain1", "path": "*cgreq.Aip1", + "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "dns.google."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip0", "path": "*rep.Answer.A", "type": "*variable", "value": "~*cgrep.Attributes.Aip0"}, + {"tag": "Aname1", "path": "*rep.Answer[1].Hdr.Name", "type": "*constant", "value": "dns.google."}, + {"tag": "Attl1", "path": "*rep.Answer[1].Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass1", "path": "*rep.Answer[1].Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype1", "path": "*rep.Answer[1].Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip1", "path": "*rep.Answer[1].A", "type": "*variable", "value": "~*cgrep.Attributes.Aip1"} + ] + }, + { + "id": "SRVAttributes", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_ldap._tcp.google.com."], + "flags": ["*authorize", "*attributes","*log"], + "request_fields":[ + {"tag": "SRVAddress", "path": "*cgreq.SRVAddress", + "type": "*constant", "value": "_ldap._tcp.google.com."}, + {"tag": "SRVName", "path": "*cgreq.SRVName", + "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_ldap._tcp.google.com."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "5"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "0"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "389"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*variable", "value": "~*cgrep.Attributes.SRVName"} + ] + } + ] +} } \ No newline at end of file diff --git a/data/conf/samples/dnsagent_mysql/dryrun.json b/data/conf/samples/dnsagent_mysql/dryrun.json index 242196a3c..26d48f125 100644 --- a/data/conf/samples/dnsagent_mysql/dryrun.json +++ b/data/conf/samples/dnsagent_mysql/dryrun.json @@ -6,7 +6,7 @@ "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:4986517174963"], "flags": ["*dryrun","*log"], "request_fields":[ - {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"}, + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -14,9 +14,39 @@ {"tag": "NAPTRFlags", "path": "*rep.Answer.Flags", "type": "*constant", "value": "U"}, {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, - {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, - ], + {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."} + ] }, - ], -}, + { + "id": "DryRunA", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:cgrates.org."], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "cgrates.org."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "51.38.77.188"} + ] + }, + { + "id": "DryRunSRV", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_sip._tcp.opensips.org."], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_sip._tcp.opensips.org."}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "5060"}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "0"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "50"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "opensips.org."} + ] + } + ] +} } diff --git a/data/conf/samples/dnsagent_mysql/opts.json b/data/conf/samples/dnsagent_mysql/opts.json index 2da9770c6..94b9071be 100644 --- a/data/conf/samples/dnsagent_mysql/opts.json +++ b/data/conf/samples/dnsagent_mysql/opts.json @@ -6,7 +6,7 @@ "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.QueryName{*e164}:5986517174965", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], "flags": ["*dryrun","*log"], "request_fields":[ - {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"}, + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -17,8 +17,8 @@ {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, - {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"}, - ], + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] }, { "id": "OptsWithAttributes", @@ -27,7 +27,7 @@ "request_fields":[ {"tag": "Origin", "path": "*cgreq.Origin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, {"tag": "Domanin", "path": "*cgreq.Domanin", "type": "*variable", "value": "~*vars.QueryName{*e164Domain}"}, - {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} ], "reply_fields":[ {"tag": "NAPTROrder", "path": "*rep.Answer.Order", "type": "*constant", "value": "100"}, @@ -36,10 +36,82 @@ {"tag": "NAPTRService", "path": "*rep.Answer.Service", "type": "*constant", "value": "E2U+SIP"}, {"tag": "NAPTRRegexp", "path": "*rep.Answer.Regexp", "type": "*constant", "value": "!^(.*)$!sip:\\1@172.16.1.10.!"}, {"tag": "NAPTRReplacement", "path": "*rep.Answer.Replacement", "type": "*constant", "value": "."}, - {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true}, - ], + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] }, - ], - }, + { + "id": "OptsA", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:example.com.", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "example.com."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "93.184.216.34"}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, + {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] + }, + { + "id": "AOptsWithAttributes", + "filters": ["*string:~*vars.QueryType:A", "*string:~*vars.QueryName:opendns.com."], + "flags": ["*event","*attributes"], + "request_fields":[ + {"tag": "Origin", "path": "*cgreq.AOrigin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, + {"tag": "Domain", "path": "*cgreq.ASIPDomain", "type": "*variable", "value": "~*vars.QueryName"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "example.com."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*constant", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*constant", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*constant", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*constant", "value": "146.112.62.105"}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] + }, + { + "id": "OptsSRV", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_matrix._tcp.matrix.org.", "*string:~*req.Option[0].Uri:sip:cgrates@cgrates.org"], + "flags": ["*dryrun","*log"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.ToR", "type": "*constant", "value": "*sms"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "10"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "5"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "8443"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "matrix-federation.matrix.org.cdn.cloudflare.net."}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*constant", "value": "sip:cgrates@cgrates.co"}, + {"tag": "Opts2", "path": "*rep.Option.Uri", "type": "*group", "value": "sip:cgrates@cgrates.net", "new_branch":true}, + {"tag": "Opts3", "path": "*rep.Option[0].Uri", "type": "*constant", "value": "sip:cgrates@cgrates.com"} + ] + }, + { + "id": "SRVOptsWithAttributes", + "filters": ["*string:~*vars.QueryType:SRV", "*string:~*vars.QueryName:_sip._udp.opensips.org."], + "flags": ["*event","*attributes"], + "request_fields":[ + {"tag": "Origin", "path": "*cgreq.SRVOrigin", "type": "*variable", "value": "~*req.Option[0].Uri{*sipuri_user}"}, + {"tag": "Domain", "path": "*cgreq.SRVDomain", "type": "*variable", "value": "~*vars.QueryName"}, + {"tag": "NewSipURI", "path": "*cgreq.SipURI", "type": "*constant", "value": "*attributes"} + ], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*constant", "value": "_sip._udp.opensips.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*constant", "value": "0"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*constant", "value": "50"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*constant", "value": "5060"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*constant", "value": "opensips.org."}, + {"tag": "Opts", "path": "*rep.Option.Uri", "type": "*variable", "value": "~*cgrep.Attributes[*raw].SipURI", "mandatory": true} + ] + } + ] + } } \ No newline at end of file diff --git a/data/conf/samples/dnsagent_mysql/suppliers.json b/data/conf/samples/dnsagent_mysql/suppliers.json index 63cc738eb..53a321151 100644 --- a/data/conf/samples/dnsagent_mysql/suppliers.json +++ b/data/conf/samples/dnsagent_mysql/suppliers.json @@ -58,6 +58,92 @@ "type": "*group", "value": "."}, ], }, + { + "id": "ARoutesQuery", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev."], + "flags": ["*message", "*routes","*continue"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1002"} + ], + "reply_fields":[ + {"tag": "DispatchReply", "type": "*none", + "blocker": true} + ] + }, + { + "id": "ASuppliersOneSupplier", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer.Hdr.Name", "type": "*group", "value": "go.dev."}, + {"tag": "Attl", "path": "*rep.Answer.Hdr.Ttl", "type": "*group", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer.Hdr.Class", "type": "*group", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer.Hdr.Rrtype", "type": "*group", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer.A", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"} + ] + }, + { + "id": "ASuppliersTwoSuppliers", + "filters": ["*string:~*vars.QueryType:A", + "*string:~*vars.QueryName:go.dev.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Aname", "path": "*rep.Answer[1].Hdr.Name", "type": "*group", "value": "go.dev."}, + {"tag": "Attl", "path": "*rep.Answer[1].Hdr.Ttl", "type": "*group", "value": "300"}, + {"tag": "Aclass", "path": "*rep.Answer[1].Hdr.Class", "type": "*group", "value": "1"}, + {"tag": "Arrtype", "path": "*rep.Answer[1].Hdr.Rrtype", "type": "*group", "value": "1"}, + {"tag": "Aip", "path": "*rep.Answer[1].A", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"} + ] + }, + { + "id": "SRVRoutesQuery", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org."], + "flags": ["*message", "*routes","*continue"], + "request_fields":[ + {"tag": "ToR", "path": "*cgreq.Account", "type": "*constant", "value": "1003"} + ], + "reply_fields":[ + {"tag": "DispatchReply", "type": "*none", + "blocker": true} + ] + }, + { + "id": "SRVSuppliersOneSupplier", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:1"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer.Hdr.Name", "type": "*group", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer.Priority", "type": "*group", "value": "1"}, + {"tag": "SRVWeight", "path": "*rep.Answer.Weight", "type": "*group", "value": "1"}, + {"tag": "SRVPort", "path": "*rep.Answer.Port", "type": "*group", "value": "9222"}, + {"tag": "SRVTarget", "path": "*rep.Answer.Target", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[0].RouteParameters"} + ] + }, + { + "id": "SRVSuppliersTwoSuppliers", + "filters": ["*string:~*vars.QueryType:SRV", + "*string:~*vars.QueryName:_xmpp-client._tcp.xmpp.org.", + "*gte:~*cgrep.RouteProfiles.Length:1", + "*gte:~*cgrep.RouteProfiles[0].Routes.Length:2"], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "SRVHdr", "path": "*rep.Answer[1].Hdr.Name", "type": "*group", "value": "_xmpp-client._tcp.xmpp.org."}, + {"tag": "SRVPriority", "path": "*rep.Answer[1].Priority", "type": "*group", "value": "1"}, + {"tag": "SRVWeight", "path": "*rep.Answer[1].Weight", "type": "*group", "value": "1"}, + {"tag": "SRVPort", "path": "*rep.Answer[1].Port", "type": "*group", "value": "9222"}, + {"tag": "SRVTarget", "path": "*rep.Answer[1].Target", "type": "*group", "value": "~*cgrep.RouteProfiles[0].Routes[1].RouteParameters"} + ] + } ], }, diff --git a/data/tariffplans/dnsagent/Attributes.csv b/data/tariffplans/dnsagent/Attributes.csv index 007c8d5bc..a809eabcb 100644 --- a/data/tariffplans/dnsagent/Attributes.csv +++ b/data/tariffplans/dnsagent/Attributes.csv @@ -1,4 +1,8 @@ #Tenant,ID,Contexts,FilterIDs,ActivationInterval,AttributeFilterIDs,Path,Type,Value,Blocker,Weight cgrates.org,ATTR_NAPTR_ADDR,*any,*string:~*req.E164Address:4986517174964,,,*req.NAPTRAddress,*constant,sip:\1@172.16.1.1.,false,20 cgrates.org,ATTR_NAPTR_SIP_URI,*any,*string:~*req.Origin:cgrates,,,*req.SipURI,*variable,sip:cgrates@;~*req.Domanin,false,20 - +cgrates.org,ATTR_A_DOM,*any,*string:~*req.Domain:dns.google.,,,*req.Aip0,*constant,8.8.8.8,false,20 +cgrates.org,ATTR_A_DOM,*any,*string:~*req.Domain:dns.google.,,,*req.Aip1,*constant,8.8.4.4,false,20 +cgrates.org,ATTR_A_SIP_URI,*any,*string:~*req.AOrigin:cgrates,,,*req.SipURI,*variable,sip:cgrates@;~*req.ASIPDomain,false,20 +cgrates.org,ATTR_SRV,*any,*string:~*req.SRVAddress:_ldap._tcp.google.com.,,,*req.SRVName,*constant,ldap.google.com.,false,20 +cgrates.org,ATTR_SRV_SIP_URI,*any,*string:~*req.SRVOrigin:cgrates,,,*req.SipURI,*variable,sip:cgrates@;~*req.SRVDomain,false,20 \ No newline at end of file diff --git a/data/tariffplans/dnsagent/Routes.csv b/data/tariffplans/dnsagent/Routes.csv index e93bd5bd1..c2493ef93 100644 --- a/data/tariffplans/dnsagent/Routes.csv +++ b/data/tariffplans/dnsagent/Routes.csv @@ -2,4 +2,9 @@ cgrates.org,ROUTE_ACNT_1001,*string:~*req.Account:1001,,*weight,,,,,,,,,,,10 cgrates.org,ROUTE_ACNT_1001,,,,,route1,,,,,,10,,!^(.*)$!sip:\1@172.16.1.11!, cgrates.org,ROUTE_ACNT_1001,,,,,route2,,,,,,5,,!^(.*)$!sip:\1@172.16.1.12!, - +cgrates.org,ROUTE_ACNT_1002,*string:~*req.Account:1002,,*weight,,,,,,,,,,,10 +cgrates.org,ROUTE_ACNT_1002,,,,,aroute1,,,,,,10,,216.239.32.21, +cgrates.org,ROUTE_ACNT_1002,,,,,aroute2,,,,,,5,,216.239.34.21, +cgrates.org,ROUTE_ACNT_1003,*string:~*req.Account:1003,,*weight,,,,,,,,,,,10 +cgrates.org,ROUTE_ACNT_1003,,,,,srvroute1,,,,,,10,,xmpp.xmpp.org., +cgrates.org,ROUTE_ACNT_1003,,,,,srvroute2,,,,,,5,,xmpp.xmpp.com., \ No newline at end of file diff --git a/utils/consts.go b/utils/consts.go index 1970529e5..8604cb323 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -911,6 +911,9 @@ const ( DNSUri = "Uri" DNSHdr = "Hdr" DNSA = "A" + DNSTarget = "Target" + DNSPriority = "Priority" + DNSPort = "Port" DNSRrtype = "Rrtype" DNSClass = "Class" DNSTtl = "Ttl"