]> granicus.if.org Git - pdns/commitdiff
move rcodes and qtypes to their own namespace; add fallback and deprecate it
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Wed, 10 Apr 2019 20:03:15 +0000 (22:03 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Wed, 10 Apr 2019 20:03:15 +0000 (22:03 +0200)
pdns/dnsdist-lua-vars.cc

index 9cf840093155c51915a6904ab8d83c8cbd881bcf..b912cda51b4ef6028a3e3cd8cd02e479841035eb 100644 (file)
@@ -87,33 +87,54 @@ void setupLuaVars()
       {"KEYTAG",       EDNSOptionCode::KEYTAG }
     });
 
-  vector<pair<string, int> > rcodes = {{"NOERROR",  RCode::NoError  },
-                                       {"FORMERR",  RCode::FormErr  },
-                                       {"SERVFAIL", RCode::ServFail },
-                                       {"NXDOMAIN", RCode::NXDomain },
-                                       {"NOTIMP",   RCode::NotImp   },
-                                       {"REFUSED",  RCode::Refused  },
-                                       {"YXDOMAIN", RCode::YXDomain },
-                                       {"YXRRSET",  RCode::YXRRSet  },
-                                       {"NXRRSET",  RCode::NXRRSet  },
-                                       {"NOTAUTH",  RCode::NotAuth  },
-                                       {"NOTZONE",  RCode::NotZone  },
-                                       {"BADVERS",  ERCode::BADVERS },
-                                       {"BADSIG",   ERCode::BADSIG  },
-                                       {"BADKEY",   ERCode::BADKEY  },
-                                       {"BADTIME",  ERCode::BADTIME   },
-                                       {"BADMODE",  ERCode::BADMODE   },
-                                       {"BADNAME",  ERCode::BADNAME   },
-                                       {"BADALG",   ERCode::BADALG    },
-                                       {"BADTRUNC", ERCode::BADTRUNC  },
-                                       {"BADCOOKIE",ERCode::BADCOOKIE },
-  };
+  g_lua.writeVariable("DNSRCode", std::unordered_map<string, int>{
+      {"NOERROR",  RCode::NoError  },
+      {"FORMERR",  RCode::FormErr  },
+      {"SERVFAIL", RCode::ServFail },
+      {"NXDOMAIN", RCode::NXDomain },
+      {"NOTIMP",   RCode::NotImp   },
+      {"REFUSED",  RCode::Refused  },
+      {"YXDOMAIN", RCode::YXDomain },
+      {"YXRRSET",  RCode::YXRRSet  },
+      {"NXRRSET",  RCode::NXRRSet  },
+      {"NOTAUTH",  RCode::NotAuth  },
+      {"NOTZONE",  RCode::NotZone  },
+      {"BADVERS",  ERCode::BADVERS },
+      {"BADSIG",   ERCode::BADSIG  },
+      {"BADKEY",   ERCode::BADKEY  },
+      {"BADTIME",  ERCode::BADTIME   },
+      {"BADMODE",  ERCode::BADMODE   },
+      {"BADNAME",  ERCode::BADNAME   },
+      {"BADALG",   ERCode::BADALG    },
+      {"BADTRUNC", ERCode::BADTRUNC  },
+      {"BADCOOKIE",ERCode::BADCOOKIE }
+  });
+
   vector<pair<string, int> > dd;
   for(const auto& n : QType::names)
     dd.push_back({n.first, n.second});
-  for(const auto& n : rcodes)
-    dd.push_back({n.first, n.second});
-  g_lua.writeVariable("dnsdist", dd);
+  g_lua.writeVariable("DNSQType", dd);
+
+  g_lua.executeCode(R"LUA(
+    local tables = {
+      DNSQType = DNSQType,
+      DNSRCode = DNSRCode
+    }
+    local function index (table, key)
+      for tname,t in pairs(tables)
+      do
+        local val = t[key]
+        if val then
+          warnlog(string.format("access to dnsdist.%s is deprecated, please use %s.%s", key, tname, key))
+          return val
+        end
+      end
+    end
+
+    dnsdist = {}
+    setmetatable(dnsdist, { __index = index })
+    )LUA"
+  );
 
 #ifdef HAVE_DNSCRYPT
     g_lua.writeVariable("DNSCryptExchangeVersion", std::unordered_map<string,int>{