libspf2 1.2.11
Data Structures | Macros | Typedefs | Functions
spf_dns.h File Reference
#include "spf_request.h"
#include "spf_dns_rr.h"
Include dependency graph for spf_dns.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SPF_dns_server_t
 

Macros

#define ns_t_invalid   0
 
#define ns_t_a   1
 
#define ns_t_ns   2
 
#define ns_t_cname   5
 
#define ns_t_ptr   12
 
#define ns_t_mx   15
 
#define ns_t_txt   16
 
#define ns_t_aaaa   28
 
#define ns_t_any   255
 
#define ns_t_spf   99
 
#define ns_t_invalid   0
 
#define NETDB_SUCCESS   0
 
#define HOST_NOT_FOUND   1
 
#define TRY_AGAIN   2
 
#define NO_RECOVERY   3
 
#define NO_DATA   4
 

Typedefs

typedef int ns_type
 
typedef int SPF_dns_stat_t
 
typedef void(* SPF_dns_destroy_t) (SPF_dns_server_t *spf_dns_server)
 
typedef SPF_dns_rr_t *(* SPF_dns_lookup_t) (SPF_dns_server_t *spf_dns_server, const char *domain, ns_type ns_type, int should_cache)
 
typedef SPF_errcode_t(* SPF_dns_get_spf_t) (SPF_server_t *spf_server, SPF_request_t *spf_request, SPF_response_t *spf_response, SPF_record_t **spf_recordp)
 
typedef SPF_errcode_t(* SPF_dns_get_exp_t) (SPF_server_t *spf_server, const char *domain, char **buf, size_t *buf_len)
 
typedef int(* SPF_dns_add_cache_t) (SPF_server_t *spf_server, SPF_dns_rr_t spfrr)
 

Functions

void SPF_dns_free (SPF_dns_server_t *spf_dns_server)
 
SPF_dns_rr_tSPF_dns_lookup (SPF_dns_server_t *spf_dns_server, const char *domain, ns_type rr_type, int should_cache)
 
SPF_dns_rr_tSPF_dns_rlookup (SPF_dns_server_t *spf_dns_server, struct in_addr ipv4, ns_type rr_type, int should_cache)
 
SPF_dns_rr_tSPF_dns_rlookup6 (SPF_dns_server_t *spf_dns_server, struct in6_addr ipv6, ns_type rr_type, int should_cache)
 
char * SPF_dns_get_client_dom (SPF_dns_server_t *spf_dns_server, SPF_request_t *sr)
 

Detailed Description

This library has the ability to use one or more of any of a number of DNS "layers" to obtain DNS information. These layers all have compatible APIs, with only minor differences that relate to their specific functions. So, they can be mixed and matched in any order to do what you want.

When you create a new DNS layer, you can (optionally) specify the layer below it. If the current DNS layer is not able to resolve the query, it will automatically call the lower layer.

Some of the DNS layers allow for debugging information to be printed, some do caching, and, of course, some return actual DNS results either by query the network or by looking up the query in a database.

For details about each DNS layer, see the appropriate spf_dns_<layer>.h include file.

For example, there is a caching DNS layer that saves the compiled SPF records for future use. While it takes a small amount of time to compile the AOL SPF record, you will more than make up for it by not having to parse the record every time you get a message from AOL.

If you wanted to, you can even run the SPF system without using real DNS lookups at all. For testing, I used a DNS layer that contained a built-in zone file. This idea could easily be extended to being able to read the zone file from disk, or to use a database to access information.

One example of what you could do with such a zone file would be to create your own SPF records for the many free-email providers. Depending on whether you layer this local zone file before or after the real DNS lookups, you can either override published SPF records, or you can provide defaults until SPF records are published.

Definition in file spf_dns.h.

Macro Definition Documentation

◆ HOST_NOT_FOUND

#define HOST_NOT_FOUND   1

NXDOMAIN (authoritative answer)

Definition at line 103 of file spf_dns.h.

◆ NETDB_SUCCESS

#define NETDB_SUCCESS   0

Definition at line 102 of file spf_dns.h.

◆ NO_DATA

#define NO_DATA   4

host found, but no RR of req type

Definition at line 106 of file spf_dns.h.

◆ NO_RECOVERY

#define NO_RECOVERY   3

invalid/unimplmeneted query

Definition at line 105 of file spf_dns.h.

◆ ns_t_a

#define ns_t_a   1

Definition at line 75 of file spf_dns.h.

◆ ns_t_aaaa

#define ns_t_aaaa   28

Definition at line 81 of file spf_dns.h.

◆ ns_t_any

#define ns_t_any   255

Wildcard match.

Definition at line 83 of file spf_dns.h.

◆ ns_t_cname

#define ns_t_cname   5

Definition at line 77 of file spf_dns.h.

◆ ns_t_invalid [1/2]

#define ns_t_invalid   0

Definition at line 74 of file spf_dns.h.

◆ ns_t_invalid [2/2]

#define ns_t_invalid   0

Definition at line 74 of file spf_dns.h.

◆ ns_t_mx

#define ns_t_mx   15

Definition at line 79 of file spf_dns.h.

◆ ns_t_ns

#define ns_t_ns   2

Definition at line 76 of file spf_dns.h.

◆ ns_t_ptr

#define ns_t_ptr   12

Definition at line 78 of file spf_dns.h.

◆ ns_t_spf

#define ns_t_spf   99

Definition at line 89 of file spf_dns.h.

◆ ns_t_txt

#define ns_t_txt   16

Definition at line 80 of file spf_dns.h.

◆ TRY_AGAIN

#define TRY_AGAIN   2

SERVFAIL (no authoritative answer)

Definition at line 104 of file spf_dns.h.

Typedef Documentation

◆ ns_type

typedef int ns_type

Definition at line 85 of file spf_dns.h.

◆ SPF_dns_add_cache_t

typedef int(* SPF_dns_add_cache_t) (SPF_server_t *spf_server, SPF_dns_rr_t spfrr)

Definition at line 132 of file spf_dns.h.

◆ SPF_dns_destroy_t

typedef void(* SPF_dns_destroy_t) (SPF_dns_server_t *spf_dns_server)

Definition at line 119 of file spf_dns.h.

◆ SPF_dns_get_exp_t

typedef SPF_errcode_t(* SPF_dns_get_exp_t) (SPF_server_t *spf_server, const char *domain, char **buf, size_t *buf_len)

Definition at line 129 of file spf_dns.h.

◆ SPF_dns_get_spf_t

typedef SPF_errcode_t(* SPF_dns_get_spf_t) (SPF_server_t *spf_server, SPF_request_t *spf_request, SPF_response_t *spf_response, SPF_record_t **spf_recordp)

Definition at line 125 of file spf_dns.h.

◆ SPF_dns_lookup_t

typedef SPF_dns_rr_t *(* SPF_dns_lookup_t) (SPF_dns_server_t *spf_dns_server, const char *domain, ns_type ns_type, int should_cache)

Definition at line 120 of file spf_dns.h.

◆ SPF_dns_stat_t

typedef int SPF_dns_stat_t

Definition at line 108 of file spf_dns.h.

Function Documentation

◆ SPF_dns_free()

void SPF_dns_free ( SPF_dns_server_t *  spf_dns_server)

Definition at line 116 of file spf_dns.c.

References NULL, SPF_ASSERT_NOTNULL, and SPF_dns_free().

Referenced by SPF_dns_free(), and SPF_server_free().

Here is the call graph for this function:

◆ SPF_dns_get_client_dom()

char * SPF_dns_get_client_dom ( SPF_dns_server_t *  spf_dns_server,
SPF_request_t *  sr 
)

The client domain is the validated domain name of the client IP address. This is not just the domain name(s) found in the reverse DNS tree, but involves checking to make sure these name(s) use the client IP address. The complete validation procedure is described in section 5.4 of the SPF spec.

This may return NULL if the strdup() fails.

This ought to be refactored with the PTR code in the interpreter.

Definition at line 206 of file spf_dns.c.

References SPF_dns_rr_data_t::a, SPF_dns_rr_data_t::aaaa, FALSE, ns_t_a, ns_t_aaaa, ns_t_ptr, SPF_dns_rr_t::num_rr, SPF_dns_rr_data_t::ptr, SPF_dns_rr_t::rr, SPF_ASSERT_NOTNULL, SPF_dns_lookup(), SPF_dns_rlookup(), SPF_dns_rlookup6(), SPF_dns_rr_free(), and SPF_MAX_DNS_PTR.

Referenced by SPF_request_get_client_dom().

Here is the call graph for this function:

◆ SPF_dns_lookup()

SPF_dns_rr_t * SPF_dns_lookup ( SPF_dns_server_t *  spf_dns_server,
const char *  domain,
ns_type  rr_type,
int  should_cache 
)

◆ SPF_dns_rlookup()

SPF_dns_rr_t * SPF_dns_rlookup ( SPF_dns_server_t *  spf_dns_server,
struct in_addr  ipv4,
ns_type  rr_type,
int  should_cache 
)

Definition at line 150 of file spf_dns.c.

References SPF_dns_lookup().

Referenced by main(), SPF_dns_get_client_dom(), and SPF_record_interpret().

Here is the call graph for this function:

◆ SPF_dns_rlookup6()

SPF_dns_rr_t * SPF_dns_rlookup6 ( SPF_dns_server_t *  spf_dns_server,
struct in6_addr  ipv6,
ns_type  rr_type,
int  should_cache 
)

Definition at line 171 of file spf_dns.c.

References SPF_dns_lookup().

Referenced by SPF_dns_get_client_dom(), and SPF_record_interpret().

Here is the call graph for this function: