Module rspamd_resolver

This module allows to resolve DNS names from LUA code. All resolving is executed asynchronously. Here is an example of name resolution:

Example:

local function symbol_callback(task)
	local host = 'example.com'

	local function dns_cb(resolver, to_resolve, results, err, _, authenticated)
		if not results then
			rspamd_logger.infox('DNS resolving of %1 failed: %2', host, err)
			return
		end
		for _,r in ipairs(results) do
			-- r is of type rspamd{ip} here, but it can be converted to string
			rspamd_logger.infox('Resolved %1 to %2', host, tostring(r))
		end
	end

	task:get_resolver():resolve_a({task = task, name = host, callback = dns_cb})
end

Brief content:

Functions:

Function Description
rspamd_resolver.init(ev_base, config) No description

Methods:

Method Description
resolver:resolve_a(table) Resolve A record for a specified host.
resolver:resolve_ptr(table) Resolve PTR record for a specified host.
resolver:resolve_txt(table) Resolve TXT record for a specified host.
resolver:resolve_mx(table) Resolve MX record for a specified host.
resolver:resolve_ns(table) Resolve NS records for a specified host.
resolver:idna_convert_utf8(hostname[, pool]) Converts domain name from IDN (in utf8 format) to punycode.

Functions

The module rspamd_resolver defines the following functions.

Function rspamd_resolver.init(ev_base, config)

Parameters:

  • ev_base {event_base}: event base used for asynchronous events
  • config {rspamd_config}: rspamd configuration parameters

Returns:

  • {rspamd_resolver}: new resolver object associated with the specified base

Back to module description.

Methods

The module rspamd_resolver defines the following methods.

Method resolver:resolve_a(table)

Resolve A record for a specified host. Table elements:

  • task - task element (preferred, required to track dependencies) -or-
  • session - asynchronous session normally associated with rspamd task (task:get_session())
  • mempool - pool memory pool for storing intermediate data
  • name - host name to resolve
  • callback - callback callback function to be called upon name resolution is finished; must be of type function (resolver, to_resolve, results, err)
  • forced - true if needed to override normal limit for DNS requests

Parameters:

No parameters

Returns:

  • {boolean}: true if DNS request has been scheduled

Back to module description.

Method resolver:resolve_ptr(table)

Resolve PTR record for a specified host. Table elements:

  • task - task element (preferred, required to track dependencies) -or-
  • session - asynchronous session normally associated with rspamd task (task:get_session())
  • mempool - pool memory pool for storing intermediate data
  • name - host name to resolve
  • callback - callback callback function to be called upon name resolution is finished; must be of type function (resolver, to_resolve, results, err)
  • forced - true if needed to override normal limit for DNS requests

Parameters:

No parameters

Returns:

  • {boolean}: true if DNS request has been scheduled

Back to module description.

Method resolver:resolve_txt(table)

Resolve TXT record for a specified host. Table elements:

  • task - task element (preferred, required to track dependencies) -or-
  • session - asynchronous session normally associated with rspamd task (task:get_session())
  • mempool - pool memory pool for storing intermediate data
  • name - host name to resolve
  • callback - callback callback function to be called upon name resolution is finished; must be of type function (resolver, to_resolve, results, err)
  • forced - true if needed to override normal limit for DNS requests

Parameters:

No parameters

Returns:

  • {boolean}: true if DNS request has been scheduled

Back to module description.

Method resolver:resolve_mx(table)

Resolve MX record for a specified host. Table elements:

  • task - task element (preferred, required to track dependencies) -or-
  • session - asynchronous session normally associated with rspamd task (task:get_session())
  • mempool - pool memory pool for storing intermediate data
  • name - host name to resolve
  • callback - callback callback function to be called upon name resolution is finished; must be of type function (resolver, to_resolve, results, err)
  • forced - true if needed to override normal limit for DNS requests

Parameters:

No parameters

Returns:

  • {boolean}: true if DNS request has been scheduled

Back to module description.

Method resolver:resolve_ns(table)

Resolve NS records for a specified host. Table elements:

  • task - task element (preferred, required to track dependencies) -or-
  • session - asynchronous session normally associated with rspamd task (task:get_session())
  • mempool - pool memory pool for storing intermediate data
  • name - host name to resolve
  • callback - callback callback function to be called upon name resolution is finished; must be of type function (resolver, to_resolve, results, err)
  • forced - true if needed to override normal limit for DNS requests

Parameters:

No parameters

Returns:

  • {boolean}: true if DNS request has been scheduled

Back to module description.

Method resolver:idna_convert_utf8(hostname[, pool])

Converts domain name from IDN (in utf8 format) to punycode

Parameters:

No parameters

Returns:

  • {string}: new name converted

Back to module description.

Back to top.