1Scriptable functions 2==================== 3 4Network 5------- 6 7.. function:: ntohs(netshort) 8 9 This subroutine converts values between the host and network byte order. 10 Specifically, **ntohs()** converts 16-bit quantities from network byte order 11 to host byte order. 12 13 :param netshort: 16-bit short addr 14 :rtype: converted addr 15 16 17Cache 18----- 19 20.. function:: storeQueryInCache(qstate, qinfo, msgrep, is_referral) 21 22 Store pending query in local cache. 23 24 :param qstate: :class:`module_qstate` 25 :param qinfo: :class:`query_info` 26 :param msgrep: :class:`reply_info` 27 :param is_referral: integer 28 :rtype: boolean 29 30.. function:: invalidateQueryInCache(qstate, qinfo) 31 32 Invalidate record in local cache. 33 34 :param qstate: :class:`module_qstate` 35 :param qinfo: :class:`query_info` 36 37 38EDNS options 39------------ 40 41.. function:: register_edns_option(env, code, bypass_cache_stage=False, no_aggregation=False) 42 43 Register EDNS option code. 44 45 :param env: :class:`module_env` 46 :param code: option code(integer) 47 :param bypass_cache_stage: whether to bypass the cache response stage 48 :param no_aggregation: whether this query should be unique 49 :return: ``1`` if successful, ``0`` otherwise 50 :rtype: integer 51 52.. function:: edns_opt_list_find(list, code) 53 54 Find the EDNS option code in the EDNS option list. 55 56 :param list: linked list of :class:`edns_option` 57 :param code: option code (integer) 58 :return: the edns option if found or None 59 :rtype: :class:`edns_option` or None 60 61.. function:: edns_opt_list_remove(list, code); 62 63 Remove an ENDS option code from the list. 64 .. note:: All :class:`edns_option` with the code will be removed 65 66 :param list: linked list of :class:`edns_option` 67 :param code: option code (integer) 68 :return: ``1`` if at least one :class:`edns_option` was removed, ``0`` otherwise 69 :rtype: integer 70 71.. function:: edns_opt_list_append(list, code, data, region) 72 73 Append given EDNS option code with data to the list. 74 75 :param list: linked list of :class:`edns_option` 76 :param code: option code (integer) 77 :param data: EDNS data. **Must** be a :class:`bytearray` 78 :param region: :class:`regional` 79 80.. function:: edns_opt_list_is_empty(list) 81 82 Check if an EDNS option list is empty. 83 84 :param list: linked list of :class:`edns_option` 85 :return: ``1`` if list is empty, ``0`` otherwise 86 :rtype: integer 87 88 89Inplace callbacks 90----------------- 91 92.. function:: inplace_cb_reply(qinfo, qstate, rep, rcode, edns, opt_list_out, region) 93 94 Function prototype for callback functions used in 95 `register_inplace_cb_reply`_, `register_inplace_cb_reply_cache`_, 96 `register_inplace_cb_reply_local` and `register_inplace_cb_reply_servfail`. 97 98 :param qinfo: :class:`query_info` 99 :param qstate: :class:`module_qstate` 100 :param rep: :class:`reply_info` 101 :param rcode: return code (integer), check ``RCODE_`` constants. 102 :param edns: :class:`edns_data` 103 :param opt_list_out: :class:`edns_option`. EDNS option list to append options to. 104 :param region: :class:`regional` 105 106.. function:: inplace_cb_query(qinfo, flags, qstate, addr, zone, region) 107 108 Function prototype for callback functions used in 109 `register_inplace_cb_query`_. 110 111 :param qinfo: :class:`query_info` 112 :param flags: query flags (integer) 113 :param qstate: :class:`module_qstate` 114 :param addr: :class:`sockaddr_storage` 115 :param zone: zone name in wire format (bytes) 116 :param region: :class:`regional` 117 118.. function:: register_inplace_cb_reply(py_cb, env, id) 119 120 Register py_cb as an inplace reply callback function. 121 122 :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable. 123 :param env: :class:`module_env` 124 :param id: Module ID. 125 :return: True on success, False otherwise 126 :rtype: boolean 127 128.. function:: register_inplace_cb_reply_cache(py_cb, env, id) 129 130 Register py_cb as an inplace reply_cache callback function. 131 132 :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable. 133 :param env: :class:`module_env` 134 :param id: Module ID. 135 :return: True on success, False otherwise 136 :rtype: boolean 137 138.. function:: register_inplace_cb_reply_local(py_cb, env, id) 139 140 Register py_cb as an inplace reply_local callback function. 141 142 :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable. 143 :param env: :class:`module_env` 144 :param id: Module ID. 145 :return: True on success, False otherwise 146 :rtype: boolean 147 148.. function:: register_inplace_cb_reply_servfail(py_cb, env, id) 149 150 Register py_cb as an inplace reply_servfail callback function. 151 152 :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable. 153 :param env: :class:`module_env` 154 :param id: Module ID. 155 :return: True on success, False otherwise 156 :rtype: boolean 157 158.. function:: register_inplace_cb_query(py_cb, env, id) 159 160 Register py_cb as an inplace query callback function. 161 162 :param py_cb: Python function that follows `inplace_cb_query`_'s prototype. **Must** be callable. 163 :param env: :class:`module_env` 164 :param id: Module ID. 165 :return: True on success, False otherwise 166 :rtype: boolean 167 168Logging 169------- 170 171.. function:: verbose(level, msg) 172 173 Log a verbose message, pass the level for this message. 174 No trailing newline is needed. 175 176 :param level: verbosity level for this message, compared to global verbosity setting. 177 :param msg: string message 178 179.. function:: log_info(msg) 180 181 Log informational message. No trailing newline is needed. 182 183 :param msg: string message 184 185.. function:: log_err(msg) 186 187 Log error message. No trailing newline is needed. 188 189 :param msg: string message 190 191.. function:: log_warn(msg) 192 193 Log warning message. No trailing newline is needed. 194 195 :param msg: string message 196 197.. function:: log_hex(msg, data, length) 198 199 Log a hex-string to the log. Can be any length. 200 performs mallocs to do so, slow. But debug useful. 201 202 :param msg: string desc to accompany the hexdump. 203 :param data: data to dump in hex format. 204 :param length: length of data. 205 206.. function:: log_dns_msg(str, qinfo, reply) 207 208 Log DNS message. 209 210 :param str: string message 211 :param qinfo: :class:`query_info` 212 :param reply: :class:`reply_info` 213 214.. function:: log_query_info(verbosity_value, str, qinf) 215 216 Log query information. 217 218 :param verbosity_value: see constants 219 :param str: string message 220 :param qinf: :class:`query_info` 221 222.. function:: regional_log_stats(r) 223 224 Log regional statistics. 225 226 :param r: :class:`regional` 227 228 229Debugging 230--------- 231 232.. function:: strextstate(module_ext_state) 233 234 Debug utility, module external qstate to string. 235 236 :param module_ext_state: the state value. 237 :rtype: descriptive string. 238 239.. function:: strmodulevent(module_event) 240 241 Debug utility, module event to string. 242 243 :param module_event: the module event value. 244 :rtype: descriptive string. 245 246.. function:: ldns_rr_type2str(atype) 247 248 Convert RR type to string. 249 250.. function:: ldns_rr_class2str(aclass) 251 252 Convert RR class to string. 253