summaryrefslogtreecommitdiff
path: root/pythonmod
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2020-12-08 21:23:03 +0000
committerCy Schubert <cy@FreeBSD.org>2020-12-08 21:23:03 +0000
commitc1dbcbf2d10cd99864ab0eb44358d9875ba0c0a5 (patch)
tree8cbca8d9dc814933d2bc59b6623b792b549aac6b /pythonmod
parent4cb89f2eee3bb358f0491932ab0498b5319f4229 (diff)
Notes
Diffstat (limited to 'pythonmod')
-rw-r--r--pythonmod/doc/examples/example6.rst7
-rw-r--r--pythonmod/doc/modules/functions.rst5
-rw-r--r--pythonmod/examples/inplace_callbacks.py30
-rw-r--r--pythonmod/interface.i26
4 files changed, 33 insertions, 35 deletions
diff --git a/pythonmod/doc/examples/example6.rst b/pythonmod/doc/examples/example6.rst
index d294fb8be618..fd6caf74d549 100644
--- a/pythonmod/doc/examples/example6.rst
+++ b/pythonmod/doc/examples/example6.rst
@@ -60,7 +60,6 @@ The callback function's prototype is the following:
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh states.
:return: True on success, False on failure.
@@ -105,8 +104,6 @@ The callback function's prototype is the following:
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
@@ -154,8 +151,6 @@ The callback function's prototype is the following:
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
@@ -201,8 +196,6 @@ The callback function's prototype is the following:
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
diff --git a/pythonmod/doc/modules/functions.rst b/pythonmod/doc/modules/functions.rst
index 43c66eb380dd..333f696b814f 100644
--- a/pythonmod/doc/modules/functions.rst
+++ b/pythonmod/doc/modules/functions.rst
@@ -89,7 +89,7 @@ EDNS options
Inplace callbacks
-----------------
-.. function:: inplace_cb_reply(qinfo, qstate, rep, rcode, edns, opt_list_out, region)
+.. function:: inplace_cb_reply(qinfo, qstate, rep, rcode, edns, opt_list_out, region, \*\*kwargs)
Function prototype for callback functions used in
`register_inplace_cb_reply`_, `register_inplace_cb_reply_cache`_,
@@ -102,6 +102,9 @@ Inplace callbacks
:param edns: :class:`edns_data`
:param opt_list_out: :class:`edns_option`. EDNS option list to append options to.
:param region: :class:`regional`
+ :param \*\*kwargs: Dictionary that may contain parameters added in a future
+ release. Current parameters:
+ ``repinfo``: :class:`comm_reply`. Reply information for a communication point.
.. function:: inplace_cb_query(qinfo, flags, qstate, addr, zone, region)
diff --git a/pythonmod/examples/inplace_callbacks.py b/pythonmod/examples/inplace_callbacks.py
index 768c2d0138c5..de375b4e12fc 100644
--- a/pythonmod/examples/inplace_callbacks.py
+++ b/pythonmod/examples/inplace_callbacks.py
@@ -43,7 +43,7 @@
# This query returns SERVFAIL as the txt record of bogus.nlnetlabs.nl is
# intentionally bogus. The reply will contain an empty EDNS option
# with option code 65003.
-# Unbound will also log the source address(es) of the client(s) that made
+# Unbound will also log the source address of the client that made
# the request.
# (unbound needs to be validating for this example to work)
@@ -91,8 +91,6 @@ def inplace_reply_callback(qinfo, qstate, rep, rcode, edns, opt_list_out,
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
@@ -121,8 +119,6 @@ def inplace_cache_callback(qinfo, qstate, rep, rcode, edns, opt_list_out,
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
@@ -173,8 +169,6 @@ def inplace_local_callback(qinfo, qstate, rep, rcode, edns, opt_list_out,
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
@@ -205,13 +199,11 @@ def inplace_servfail_callback(qinfo, qstate, rep, rcode, edns, opt_list_out,
:param **kwargs: Dictionary that may contain parameters added in a future
release. Current parameters:
``repinfo``: Reply information for a communication point (comm_reply).
- It is None when the callback happens in the mesh
- states(modules).
:return: True on success, False on failure.
For demonstration purposes we want to reply with an empty EDNS code '65003'
- and log the IP address(es) of the client(s).
+ and log the IP address of the client.
"""
log_info("python: called back while servfail.")
@@ -219,30 +211,14 @@ def inplace_servfail_callback(qinfo, qstate, rep, rcode, edns, opt_list_out,
b = bytearray.fromhex("")
edns_opt_list_append(opt_list_out, 65003, b, region)
- # Log the client(s) IP address(es)
+ # Log the client's IP address
comm_reply = kwargs['repinfo']
if comm_reply:
- # If it is not None this callback was called before the query reached
- # the mesh states(modules). There is only one client associated with
- # this query.
addr = comm_reply.addr
port = comm_reply.port
addr_family = comm_reply.family
log_info("python: Client IP: {}({}), port: {}"
"".format(addr, addr_family, port))
- else:
- # If it is not None this callback was called while the query is in the
- # mesh states(modules). In this case they may be multiple clients
- # waiting for this query.
- # The following code is the same as with the resip.py example.
- rl = qstate.mesh_info.reply_list
- while (rl):
- if rl.query_reply:
- q = rl.query_reply
- log_info("python: Client IP: {}({}), port: {}"
- "".format(q.addr, q.family, q.port))
- rl = rl.next
-
return True
diff --git a/pythonmod/interface.i b/pythonmod/interface.i
index 71f2bf774d0f..cbee4f714764 100644
--- a/pythonmod/interface.i
+++ b/pythonmod/interface.i
@@ -1413,6 +1413,19 @@ struct delegpt* find_delegation(struct module_qstate* qstate, char *nm, size_t n
/******************************
* Various debugging functions *
******************************/
+
+/* rename the variadic functions because python does the formatting already*/
+%rename (unbound_log_info) log_info;
+%rename (unbound_log_err) log_err;
+%rename (unbound_log_warn) log_warn;
+%rename (unbound_verbose) verbose;
+/* provide functions that take one string as argument, so python can cook
+the string */
+%rename (log_info) pymod_log_info;
+%rename (log_warn) pymod_log_warn;
+%rename (log_err) pymod_log_err;
+%rename (verbose) pymod_verbose;
+
void verbose(enum verbosity_value level, const char* format, ...);
void log_info(const char* format, ...);
void log_err(const char* format, ...);
@@ -1422,6 +1435,19 @@ void log_dns_msg(const char* str, struct query_info* qinfo, struct reply_info* r
void log_query_info(enum verbosity_value v, const char* str, struct query_info* qinf);
void regional_log_stats(struct regional *r);
+/* the one argument string log functions */
+void pymod_log_info(const char* str);
+void pymod_log_err(const char* str);
+void pymod_log_warn(const char* str);
+void pymod_verbose(enum verbosity_value level, const char* str);
+%{
+void pymod_log_info(const char* str) { log_info("%s", str); }
+void pymod_log_err(const char* str) { log_err("%s", str); }
+void pymod_log_warn(const char* str) { log_warn("%s", str); }
+void pymod_verbose(enum verbosity_value level, const char* str) {
+ verbose(level, "%s", str); }
+%}
+
/***************************************************************************
* Free allocated memory from marked sources returning corresponding types *
***************************************************************************/