summaryrefslogtreecommitdiff
path: root/pythonmod/interface.i
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2023-09-18 19:59:52 +0000
committerCy Schubert <cy@FreeBSD.org>2023-09-18 19:59:52 +0000
commit401770e05c71ecb5ae61a59d316069b4b78bf622 (patch)
treea66e3d57ff5dde81aaa0fdc4c2d86c8b7a525ae0 /pythonmod/interface.i
parent7699e1386a16236002b26107ffd2dcbde375e197 (diff)
Diffstat (limited to 'pythonmod/interface.i')
-rw-r--r--pythonmod/interface.i190
1 files changed, 151 insertions, 39 deletions
diff --git a/pythonmod/interface.i b/pythonmod/interface.i
index df8514b4793b..a436389e1184 100644
--- a/pythonmod/interface.i
+++ b/pythonmod/interface.i
@@ -1378,7 +1378,7 @@ struct delegpt* dns_cache_find_delegation(struct module_env* env,
struct regional* region, struct dns_msg** msg, uint32_t timenow,
int noexpiredabove, uint8_t* expiretop, size_t expiretoplen);
int iter_dp_is_useless(struct query_info* qinfo, uint16_t qflags,
- struct delegpt* dp, int supports_ipv4, int supports_ipv6);
+ struct delegpt* dp, int supports_ipv4, int supports_ipv6, int use_nat64);
struct iter_hints_stub* hints_lookup_stub(struct iter_hints* hints,
uint8_t* qname, uint16_t qclass, struct delegpt* dp);
@@ -1409,7 +1409,8 @@ struct delegpt* find_delegation(struct module_qstate* qstate, char *nm, size_t n
if(!dp)
return NULL;
if(iter_dp_is_useless(&qinfo, BIT_RD, dp,
- qstate->env->cfg->do_ip4, qstate->env->cfg->do_ip6)) {
+ qstate->env->cfg->do_ip4, qstate->env->cfg->do_ip6,
+ qstate->env->cfg->do_nat64)) {
if (dname_is_root((uint8_t*)nm))
return NULL;
nm = (char*)dp->name;
@@ -1550,13 +1551,15 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
struct comm_reply* repinfo, struct regional* region,
struct timeval* start_time, int id, void* python_callback)
{
- PyObject *func, *py_edns, *py_qstate, *py_opt_list_out, *py_qinfo;
- PyObject *py_rep, *py_repinfo, *py_region;
+ PyObject *func = NULL, *py_edns = NULL, *py_qstate = NULL;
+ PyObject *py_opt_list_out = NULL, *py_qinfo = NULL;
+ PyObject *py_rep = NULL, *py_repinfo = NULL, *py_region = NULL;
PyObject *py_args = NULL, *py_kwargs = NULL, *result = NULL;
int res = 0;
double py_start_time = ((double)start_time->tv_sec) + ((double)start_time->tv_usec) / 1.0e6;
PyGILState_STATE gstate = PyGILState_Ensure();
+
func = (PyObject *) python_callback;
py_edns = SWIG_NewPointerObj((void*) edns, SWIGTYPE_p_edns_data, 0);
py_qstate = SWIG_NewPointerObj((void*) qstate,
@@ -1567,20 +1570,24 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
py_rep = SWIG_NewPointerObj((void*) rep, SWIGTYPE_p_reply_info, 0);
py_repinfo = SWIG_NewPointerObj((void*) repinfo, SWIGTYPE_p_comm_reply, 0);
py_region = SWIG_NewPointerObj((void*) region, SWIGTYPE_p_regional, 0);
- if(py_qinfo && py_qstate && py_rep && py_edns && py_opt_list_out
- && py_region && py_repinfo) {
- py_args = Py_BuildValue("(OOOiOOO)", py_qinfo, py_qstate, py_rep,
- rcode, py_edns, py_opt_list_out, py_region);
- py_kwargs = Py_BuildValue("{s:O,s:d}", "repinfo", py_repinfo, "start_time",
- py_start_time);
- if(py_args && py_kwargs) {
- result = PyObject_Call(func, py_args, py_kwargs);
- } else {
- log_err("pythonmod: malloc failure in python_inplace_cb_reply_generic");
- }
- } else {
- log_err("pythonmod: malloc failure in python_inplace_cb_reply_generic");
+ if(!(py_qinfo && py_qstate && py_rep && py_edns && py_opt_list_out
+ && py_region && py_repinfo)) {
+ log_err("pythonmod: swig pointer failure in python_inplace_cb_reply_generic");
+ goto out;
+ }
+ py_args = Py_BuildValue("(OOOiOOO)", py_qinfo, py_qstate, py_rep,
+ rcode, py_edns, py_opt_list_out, py_region);
+ py_kwargs = Py_BuildValue("{s:O,s:d}", "repinfo", py_repinfo, "start_time",
+ py_start_time);
+ if(!(py_args && py_kwargs)) {
+ log_err("pythonmod: BuildValue failure in python_inplace_cb_reply_generic");
+ goto out;
+ }
+ result = PyObject_Call(func, py_args, py_kwargs);
+ if (result) {
+ res = PyInt_AsLong(result);
}
+out:
Py_XDECREF(py_edns);
Py_XDECREF(py_qstate);
Py_XDECREF(py_opt_list_out);
@@ -1590,9 +1597,6 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
Py_XDECREF(py_region);
Py_XDECREF(py_args);
Py_XDECREF(py_kwargs);
- if (result) {
- res = PyInt_AsLong(result);
- }
Py_XDECREF(result);
PyGILState_Release(gstate);
return res;
@@ -1640,29 +1644,34 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
int res = 0;
PyObject *func = python_callback;
PyObject *py_args = NULL, *py_kwargs = NULL, *result = NULL;
+ PyObject *py_qinfo = NULL;
+ PyObject *py_qstate = NULL;
+ PyObject *py_addr = NULL;
+ PyObject *py_zone = NULL;
+ PyObject *py_region = NULL;
PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject *py_qinfo = SWIG_NewPointerObj((void*) qinfo, SWIGTYPE_p_query_info, 0);
- PyObject *py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
- PyObject *py_addr = SWIG_NewPointerObj((void *) addr, SWIGTYPE_p_sockaddr_storage, 0);
- PyObject *py_zone = PyBytes_FromStringAndSize((const char *)zone, zonelen);
- PyObject *py_region = SWIG_NewPointerObj((void*) region, SWIGTYPE_p_regional, 0);
- if(py_qinfo && py_qstate && py_addr && py_zone && py_region) {
- py_args = Py_BuildValue("(OiOOOO)", py_qinfo, flags, py_qstate, py_addr, py_zone, py_region);
- py_kwargs = Py_BuildValue("{}");
- if(py_args && py_kwargs) {
- result = PyObject_Call(func, py_args, py_kwargs);
- if (result) {
- res = PyInt_AsLong(result);
- }
- } else {
- log_err("pythonmod: malloc failure in python_inplace_cb_query_generic");
- }
- } else {
- log_err("pythonmod: malloc failure in python_inplace_cb_query_generic");
+ py_qinfo = SWIG_NewPointerObj((void*) qinfo, SWIGTYPE_p_query_info, 0);
+ py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
+ py_addr = SWIG_NewPointerObj((void *) addr, SWIGTYPE_p_sockaddr_storage, 0);
+ py_zone = PyBytes_FromStringAndSize((const char *)zone, zonelen);
+ py_region = SWIG_NewPointerObj((void*) region, SWIGTYPE_p_regional, 0);
+ if(!(py_qinfo && py_qstate && py_addr && py_zone && py_region)) {
+ log_err("pythonmod: swig pointer failure in python_inplace_cb_query_generic");
+ goto out;
}
-
+ py_args = Py_BuildValue("(OiOOOO)", py_qinfo, flags, py_qstate, py_addr, py_zone, py_region);
+ py_kwargs = Py_BuildValue("{}");
+ if(!(py_args && py_kwargs)) {
+ log_err("pythonmod: BuildValue failure in python_inplace_cb_query_generic");
+ goto out;
+ }
+ result = PyObject_Call(func, py_args, py_kwargs);
+ if (result) {
+ res = PyInt_AsLong(result);
+ }
+out:
Py_XDECREF(py_qinfo);
Py_XDECREF(py_qstate);
Py_XDECREF(py_addr);
@@ -1686,6 +1695,105 @@ int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len,
if (ret) Py_INCREF(py_cb);
return ret;
}
+
+ int python_inplace_cb_query_response(struct module_qstate* qstate,
+ struct dns_msg* response, int id, void* python_callback)
+ {
+ int res = 0;
+ PyObject *func = python_callback;
+ PyObject *py_qstate = NULL;
+ PyObject *py_response = NULL;
+ PyObject *py_args = NULL;
+ PyObject *py_kwargs = NULL;
+ PyObject *result = NULL;
+
+ PyGILState_STATE gstate = PyGILState_Ensure();
+
+ py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
+ py_response = SWIG_NewPointerObj((void*) response, SWIGTYPE_p_dns_msg, 0);
+ if(!(py_qstate && py_response)) {
+ log_err("pythonmod: swig pointer failure in python_inplace_cb_query_response");
+ goto out;
+ }
+ py_args = Py_BuildValue("(OO)", py_qstate, py_response);
+ py_kwargs = Py_BuildValue("{}");
+ if(!(py_args && py_kwargs)) {
+ log_err("pythonmod: BuildValue failure in python_inplace_cb_query_response");
+ goto out;
+ }
+ result = PyObject_Call(func, py_args, py_kwargs);
+ if (result) {
+ res = PyInt_AsLong(result);
+ }
+out:
+ Py_XDECREF(py_qstate);
+ Py_XDECREF(py_response);
+
+ Py_XDECREF(py_args);
+ Py_XDECREF(py_kwargs);
+ Py_XDECREF(result);
+
+ PyGILState_Release(gstate);
+
+ return res;
+ }
+
+ static int register_inplace_cb_query_response(PyObject* py_cb,
+ struct module_env* env, int id)
+ {
+ int ret = inplace_cb_register(python_inplace_cb_query_response,
+ inplace_cb_query_response, (void*) py_cb, env, id);
+ if (ret) Py_INCREF(py_cb);
+ return ret;
+ }
+
+ int python_inplace_cb_edns_back_parsed_call(struct module_qstate* qstate,
+ int id, void* python_callback)
+ {
+ int res = 0;
+ PyObject *func = python_callback;
+ PyObject *py_qstate = NULL;
+ PyObject *py_args = NULL;
+ PyObject *py_kwargs = NULL;
+ PyObject *result = NULL;
+
+ PyGILState_STATE gstate = PyGILState_Ensure();
+
+ py_qstate = SWIG_NewPointerObj((void*) qstate, SWIGTYPE_p_module_qstate, 0);
+ if(!py_qstate) {
+ log_err("pythonmod: swig pointer failure in python_inplace_cb_edns_back_parsed_call");
+ goto out;
+ }
+ py_args = Py_BuildValue("(O)", py_qstate);
+ py_kwargs = Py_BuildValue("{}");
+ if(!(py_args && py_kwargs)) {
+ log_err("pythonmod: BuildValue failure in python_inplace_cb_edns_back_parsed_call");
+ goto out;
+ }
+ result = PyObject_Call(func, py_args, py_kwargs);
+ if (result) {
+ res = PyInt_AsLong(result);
+ }
+out:
+ Py_XDECREF(py_qstate);
+
+ Py_XDECREF(py_args);
+ Py_XDECREF(py_kwargs);
+ Py_XDECREF(result);
+
+ PyGILState_Release(gstate);
+
+ return res;
+ }
+
+ static int register_inplace_cb_edns_back_parsed_call(PyObject* py_cb,
+ struct module_env* env, int id)
+ {
+ int ret = inplace_cb_register(python_inplace_cb_edns_back_parsed_call,
+ inplace_cb_edns_back_parsed, (void*) py_cb, env, id);
+ if (ret) Py_INCREF(py_cb);
+ return ret;
+ }
%}
/* C declarations */
int inplace_cb_register(void* cb, enum inplace_cb_list_type type, void* cbarg,
@@ -1702,3 +1810,7 @@ static int register_inplace_cb_reply_servfail(PyObject* py_cb,
struct module_env* env, int id);
static int register_inplace_cb_query(PyObject *py_cb,
struct module_env* env, int id);
+static int register_inplace_cb_query_response(PyObject *py_cb,
+ struct module_env* env, int id);
+static int register_inplace_cb_edns_back_parsed_call(PyObject *py_cb,
+ struct module_env* env, int id);