go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/dnsplugin/vppcalls/api_vppcalls.go (about) 1 // Copyright (c) 2020 Pantheon.tech 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package vppcalls 16 17 import ( 18 "net" 19 20 govppapi "go.fd.io/govpp/api" 21 "go.ligato.io/cn-infra/v2/logging" 22 23 "go.ligato.io/vpp-agent/v3/plugins/vpp" 24 ) 25 26 // DNSVppAPI is API boundary for vppcall package access, introduced to properly test code dependent on vppcalls package 27 type DNSVppAPI interface { 28 DNSVPPWrite 29 DNSVPPRead 30 } 31 32 // DNSVPPWrite provides write methods for DNS cache server functionality 33 type DNSVPPWrite interface { 34 // EnableDNS make act VPP as DNS cache server 35 EnableDNS() error 36 37 // DisableDNS disables functionality that makes VPP act as DNS cache server 38 DisableDNS() error 39 40 // AddUpstreamDNSServer adds new upstream DNS Server to the upstream DNS server list 41 AddUpstreamDNSServer(serverIPAddress net.IP) error 42 43 // DeleteUpstreamDNSServer removes upstream DNS Server from the upstream DNS server list 44 DeleteUpstreamDNSServer(serverIPAddress net.IP) error 45 } 46 47 // DNSVPPRead provides read methods for DNS cache server functionality 48 type DNSVPPRead interface { 49 // TODO check whether dump can be implemented(vppcalls + descriptor's retrieve) (currently there is 50 // no dump binapi or VPP CLI check whether the functionality is enabled - dns cache is not good indicator 51 // because it can't detect feature disabling after first enabling) 52 // DumpDNSCache retrieves DNSCache if DNS cache server functionality is enabled, otherwise it returns nil 53 // DumpDNSCache() (dnsCache *dns.DNSCache, err error) 54 } 55 56 var Handler = vpp.RegisterHandler(vpp.HandlerDesc{ 57 Name: "dns", 58 HandlerAPI: (*DNSVppAPI)(nil), 59 }) 60 61 type NewHandlerFunc func(vpp.Client, logging.Logger) DNSVppAPI 62 63 func AddHandlerVersion(version vpp.Version, msgs []govppapi.Message, h NewHandlerFunc) { 64 Handler.AddVersion(vpp.HandlerVersion{ 65 Version: version, 66 Check: func(c vpp.Client) error { 67 return c.CheckCompatiblity(msgs...) 68 }, 69 NewHandler: func(c vpp.Client, a ...interface{}) vpp.HandlerAPI { 70 return h(c, a[0].(logging.Logger)) 71 }, 72 }) 73 } 74 75 func CompatibleDNSHandler(c vpp.Client, log logging.Logger) DNSVppAPI { 76 if v := Handler.FindCompatibleVersion(c); v != nil { 77 return v.NewHandler(c, log).(DNSVppAPI) 78 } 79 return nil 80 }