13b6c3722SchristosScriptable functions 23b6c3722Schristos==================== 33b6c3722Schristos 43b6c3722SchristosNetwork 53b6c3722Schristos------- 63b6c3722Schristos 73b6c3722Schristos.. function:: ntohs(netshort) 83b6c3722Schristos 93b6c3722Schristos This subroutine converts values between the host and network byte order. 100cd9f4ecSchristos Specifically, **ntohs()** converts 16-bit quantities from network byte order 110cd9f4ecSchristos to host byte order. 123b6c3722Schristos 133b6c3722Schristos :param netshort: 16-bit short addr 143b6c3722Schristos :rtype: converted addr 153b6c3722Schristos 163b6c3722Schristos 173b6c3722SchristosCache 183b6c3722Schristos----- 193b6c3722Schristos 203b6c3722Schristos.. function:: storeQueryInCache(qstate, qinfo, msgrep, is_referral) 213b6c3722Schristos 223b6c3722Schristos Store pending query in local cache. 233b6c3722Schristos 243b6c3722Schristos :param qstate: :class:`module_qstate` 253b6c3722Schristos :param qinfo: :class:`query_info` 263b6c3722Schristos :param msgrep: :class:`reply_info` 270cd9f4ecSchristos :param is_referral: integer 283b6c3722Schristos :rtype: boolean 293b6c3722Schristos 303b6c3722Schristos.. function:: invalidateQueryInCache(qstate, qinfo) 313b6c3722Schristos 323b6c3722Schristos Invalidate record in local cache. 333b6c3722Schristos 343b6c3722Schristos :param qstate: :class:`module_qstate` 353b6c3722Schristos :param qinfo: :class:`query_info` 363b6c3722Schristos 373b6c3722Schristos 380cd9f4ecSchristosEDNS options 390cd9f4ecSchristos------------ 400cd9f4ecSchristos 410cd9f4ecSchristos.. function:: register_edns_option(env, code, bypass_cache_stage=False, no_aggregation=False) 420cd9f4ecSchristos 430cd9f4ecSchristos Register EDNS option code. 440cd9f4ecSchristos 450cd9f4ecSchristos :param env: :class:`module_env` 460cd9f4ecSchristos :param code: option code(integer) 470cd9f4ecSchristos :param bypass_cache_stage: whether to bypass the cache response stage 480cd9f4ecSchristos :param no_aggregation: whether this query should be unique 490cd9f4ecSchristos :return: ``1`` if successful, ``0`` otherwise 500cd9f4ecSchristos :rtype: integer 510cd9f4ecSchristos 520cd9f4ecSchristos.. function:: edns_opt_list_find(list, code) 530cd9f4ecSchristos 540cd9f4ecSchristos Find the EDNS option code in the EDNS option list. 550cd9f4ecSchristos 560cd9f4ecSchristos :param list: linked list of :class:`edns_option` 570cd9f4ecSchristos :param code: option code (integer) 580cd9f4ecSchristos :return: the edns option if found or None 590cd9f4ecSchristos :rtype: :class:`edns_option` or None 600cd9f4ecSchristos 610cd9f4ecSchristos.. function:: edns_opt_list_remove(list, code); 620cd9f4ecSchristos 63*7a540f2bSchristos Remove an EDNS option code from the list. 640cd9f4ecSchristos .. note:: All :class:`edns_option` with the code will be removed 650cd9f4ecSchristos 660cd9f4ecSchristos :param list: linked list of :class:`edns_option` 670cd9f4ecSchristos :param code: option code (integer) 680cd9f4ecSchristos :return: ``1`` if at least one :class:`edns_option` was removed, ``0`` otherwise 690cd9f4ecSchristos :rtype: integer 700cd9f4ecSchristos 710cd9f4ecSchristos.. function:: edns_opt_list_append(list, code, data, region) 720cd9f4ecSchristos 730cd9f4ecSchristos Append given EDNS option code with data to the list. 740cd9f4ecSchristos 750cd9f4ecSchristos :param list: linked list of :class:`edns_option` 760cd9f4ecSchristos :param code: option code (integer) 770cd9f4ecSchristos :param data: EDNS data. **Must** be a :class:`bytearray` 780cd9f4ecSchristos :param region: :class:`regional` 790cd9f4ecSchristos 800cd9f4ecSchristos.. function:: edns_opt_list_is_empty(list) 810cd9f4ecSchristos 820cd9f4ecSchristos Check if an EDNS option list is empty. 830cd9f4ecSchristos 840cd9f4ecSchristos :param list: linked list of :class:`edns_option` 850cd9f4ecSchristos :return: ``1`` if list is empty, ``0`` otherwise 860cd9f4ecSchristos :rtype: integer 870cd9f4ecSchristos 880cd9f4ecSchristos 890cd9f4ecSchristosInplace callbacks 900cd9f4ecSchristos----------------- 910cd9f4ecSchristos 92d0eba39bSchristos.. function:: inplace_cb_reply(qinfo, qstate, rep, rcode, edns, opt_list_out, region, \*\*kwargs) 930cd9f4ecSchristos 940cd9f4ecSchristos Function prototype for callback functions used in 95*7a540f2bSchristos `register_inplace_cb_reply`, `register_inplace_cb_reply_cache`, 960cd9f4ecSchristos `register_inplace_cb_reply_local` and `register_inplace_cb_reply_servfail`. 970cd9f4ecSchristos 980cd9f4ecSchristos :param qinfo: :class:`query_info` 990cd9f4ecSchristos :param qstate: :class:`module_qstate` 1000cd9f4ecSchristos :param rep: :class:`reply_info` 1010cd9f4ecSchristos :param rcode: return code (integer), check ``RCODE_`` constants. 1020cd9f4ecSchristos :param edns: :class:`edns_data` 1030cd9f4ecSchristos :param opt_list_out: :class:`edns_option`. EDNS option list to append options to. 1040cd9f4ecSchristos :param region: :class:`regional` 105d0eba39bSchristos :param \*\*kwargs: Dictionary that may contain parameters added in a future 106d0eba39bSchristos release. Current parameters: 107d0eba39bSchristos ``repinfo``: :class:`comm_reply`. Reply information for a communication point. 1080cd9f4ecSchristos 109f42d8de7Schristos.. function:: inplace_cb_query(qinfo, flags, qstate, addr, zone, region) 110f42d8de7Schristos 111f42d8de7Schristos Function prototype for callback functions used in 112*7a540f2bSchristos `register_inplace_cb_query`. 113f42d8de7Schristos 114f42d8de7Schristos :param qinfo: :class:`query_info` 115f42d8de7Schristos :param flags: query flags (integer) 116f42d8de7Schristos :param qstate: :class:`module_qstate` 117f42d8de7Schristos :param addr: :class:`sockaddr_storage` 118f42d8de7Schristos :param zone: zone name in wire format (bytes) 119f42d8de7Schristos :param region: :class:`regional` 120f42d8de7Schristos 121f42d8de7Schristos.. function:: register_inplace_cb_reply(py_cb, env, id) 1220cd9f4ecSchristos 1230cd9f4ecSchristos Register py_cb as an inplace reply callback function. 1240cd9f4ecSchristos 125*7a540f2bSchristos :param py_cb: Python function that follows `inplace_cb_reply`'s prototype. **Must** be callable. 1260cd9f4ecSchristos :param env: :class:`module_env` 127f42d8de7Schristos :param id: Module ID. 1280cd9f4ecSchristos :return: True on success, False otherwise 1290cd9f4ecSchristos :rtype: boolean 1300cd9f4ecSchristos 131f42d8de7Schristos.. function:: register_inplace_cb_reply_cache(py_cb, env, id) 1320cd9f4ecSchristos 1330cd9f4ecSchristos Register py_cb as an inplace reply_cache callback function. 1340cd9f4ecSchristos 135*7a540f2bSchristos :param py_cb: Python function that follows `inplace_cb_reply`'s prototype. **Must** be callable. 1360cd9f4ecSchristos :param env: :class:`module_env` 137f42d8de7Schristos :param id: Module ID. 1380cd9f4ecSchristos :return: True on success, False otherwise 1390cd9f4ecSchristos :rtype: boolean 1400cd9f4ecSchristos 141f42d8de7Schristos.. function:: register_inplace_cb_reply_local(py_cb, env, id) 1420cd9f4ecSchristos 1430cd9f4ecSchristos Register py_cb as an inplace reply_local callback function. 1440cd9f4ecSchristos 145*7a540f2bSchristos :param py_cb: Python function that follows `inplace_cb_reply`'s prototype. **Must** be callable. 1460cd9f4ecSchristos :param env: :class:`module_env` 147f42d8de7Schristos :param id: Module ID. 1480cd9f4ecSchristos :return: True on success, False otherwise 1490cd9f4ecSchristos :rtype: boolean 1500cd9f4ecSchristos 151f42d8de7Schristos.. function:: register_inplace_cb_reply_servfail(py_cb, env, id) 1520cd9f4ecSchristos 1530cd9f4ecSchristos Register py_cb as an inplace reply_servfail callback function. 1540cd9f4ecSchristos 155*7a540f2bSchristos :param py_cb: Python function that follows `inplace_cb_reply`'s prototype. **Must** be callable. 1560cd9f4ecSchristos :param env: :class:`module_env` 157f42d8de7Schristos :param id: Module ID. 1580cd9f4ecSchristos :return: True on success, False otherwise 1590cd9f4ecSchristos :rtype: boolean 1600cd9f4ecSchristos 161f42d8de7Schristos.. function:: register_inplace_cb_query(py_cb, env, id) 162f42d8de7Schristos 163f42d8de7Schristos Register py_cb as an inplace query callback function. 164f42d8de7Schristos 165*7a540f2bSchristos :param py_cb: Python function that follows `inplace_cb_query`'s prototype. **Must** be callable. 166f42d8de7Schristos :param env: :class:`module_env` 167f42d8de7Schristos :param id: Module ID. 168f42d8de7Schristos :return: True on success, False otherwise 169f42d8de7Schristos :rtype: boolean 1700cd9f4ecSchristos 1713b6c3722SchristosLogging 1723b6c3722Schristos------- 1733b6c3722Schristos 1743b6c3722Schristos.. function:: verbose(level, msg) 1753b6c3722Schristos 1763b6c3722Schristos Log a verbose message, pass the level for this message. 1773b6c3722Schristos No trailing newline is needed. 1783b6c3722Schristos 1793b6c3722Schristos :param level: verbosity level for this message, compared to global verbosity setting. 1803b6c3722Schristos :param msg: string message 1813b6c3722Schristos 1823b6c3722Schristos.. function:: log_info(msg) 1833b6c3722Schristos 1843b6c3722Schristos Log informational message. No trailing newline is needed. 1853b6c3722Schristos 1863b6c3722Schristos :param msg: string message 1873b6c3722Schristos 1883b6c3722Schristos.. function:: log_err(msg) 1893b6c3722Schristos 1903b6c3722Schristos Log error message. No trailing newline is needed. 1913b6c3722Schristos 1923b6c3722Schristos :param msg: string message 1933b6c3722Schristos 1943b6c3722Schristos.. function:: log_warn(msg) 1953b6c3722Schristos 1963b6c3722Schristos Log warning message. No trailing newline is needed. 1973b6c3722Schristos 1983b6c3722Schristos :param msg: string message 1993b6c3722Schristos 2003b6c3722Schristos.. function:: log_hex(msg, data, length) 2013b6c3722Schristos 2023b6c3722Schristos Log a hex-string to the log. Can be any length. 2033b6c3722Schristos performs mallocs to do so, slow. But debug useful. 2043b6c3722Schristos 2053b6c3722Schristos :param msg: string desc to accompany the hexdump. 2063b6c3722Schristos :param data: data to dump in hex format. 2073b6c3722Schristos :param length: length of data. 2083b6c3722Schristos 2093b6c3722Schristos.. function:: log_dns_msg(str, qinfo, reply) 2103b6c3722Schristos 2113b6c3722Schristos Log DNS message. 2123b6c3722Schristos 2133b6c3722Schristos :param str: string message 2143b6c3722Schristos :param qinfo: :class:`query_info` 2153b6c3722Schristos :param reply: :class:`reply_info` 2163b6c3722Schristos 2173b6c3722Schristos.. function:: log_query_info(verbosity_value, str, qinf) 2183b6c3722Schristos 2193b6c3722Schristos Log query information. 2203b6c3722Schristos 2213b6c3722Schristos :param verbosity_value: see constants 2223b6c3722Schristos :param str: string message 2233b6c3722Schristos :param qinf: :class:`query_info` 2243b6c3722Schristos 2253b6c3722Schristos.. function:: regional_log_stats(r) 2263b6c3722Schristos 2273b6c3722Schristos Log regional statistics. 2283b6c3722Schristos 2293b6c3722Schristos :param r: :class:`regional` 2303b6c3722Schristos 2310cd9f4ecSchristos 2323b6c3722SchristosDebugging 2333b6c3722Schristos--------- 2343b6c3722Schristos 2353b6c3722Schristos.. function:: strextstate(module_ext_state) 2363b6c3722Schristos 2373b6c3722Schristos Debug utility, module external qstate to string. 2383b6c3722Schristos 2393b6c3722Schristos :param module_ext_state: the state value. 2403b6c3722Schristos :rtype: descriptive string. 2413b6c3722Schristos 2423b6c3722Schristos.. function:: strmodulevent(module_event) 2433b6c3722Schristos 2443b6c3722Schristos Debug utility, module event to string. 2453b6c3722Schristos 2463b6c3722Schristos :param module_event: the module event value. 2473b6c3722Schristos :rtype: descriptive string. 2483b6c3722Schristos 2493b6c3722Schristos.. function:: ldns_rr_type2str(atype) 2503b6c3722Schristos 2513b6c3722Schristos Convert RR type to string. 2523b6c3722Schristos 2533b6c3722Schristos.. function:: ldns_rr_class2str(aclass) 2543b6c3722Schristos 2553b6c3722Schristos Convert RR class to string. 256