1 /*
2  * scamper_host
3  *
4  * $Id: scamper_host.h,v 1.7 2021/08/23 08:31:27 mjl Exp $
5  *
6  * Copyright (C) 2018-2021 Matthew Luckie
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 
23 #ifndef __SCAMPER_HOST_H
24 #define __SCAMPER_HOST_H
25 
26 #define SCAMPER_HOST_FLAG_NORECURSE 0x0001
27 
28 #define SCAMPER_HOST_CLASS_IN     1
29 
30 #define SCAMPER_HOST_TYPE_A       1
31 #define SCAMPER_HOST_TYPE_NS      2
32 #define SCAMPER_HOST_TYPE_CNAME   5
33 #define SCAMPER_HOST_TYPE_SOA     6
34 #define SCAMPER_HOST_TYPE_PTR    12
35 #define SCAMPER_HOST_TYPE_MX     15
36 #define SCAMPER_HOST_TYPE_TXT    16
37 #define SCAMPER_HOST_TYPE_AAAA   28
38 #define SCAMPER_HOST_TYPE_DS     43
39 #define SCAMPER_HOST_TYPE_SSHFP  44
40 #define SCAMPER_HOST_TYPE_RRSIG  46
41 #define SCAMPER_HOST_TYPE_NSEC   47
42 #define SCAMPER_HOST_TYPE_DNSKEY 48
43 
44 #define SCAMPER_HOST_STOP_NONE    0
45 #define SCAMPER_HOST_STOP_DONE    1
46 #define SCAMPER_HOST_STOP_TIMEOUT 2
47 #define SCAMPER_HOST_STOP_HALTED  3
48 #define SCAMPER_HOST_STOP_ERROR   4
49 
50 #define SCAMPER_HOST_RR_DATA_TYPE_ADDR 1
51 #define SCAMPER_HOST_RR_DATA_TYPE_STR  2
52 #define SCAMPER_HOST_RR_DATA_TYPE_SOA  3
53 #define SCAMPER_HOST_RR_DATA_TYPE_MX   4
54 
55 typedef struct scamper_host_rr_mx
56 {
57   uint16_t                 preference;
58   char                    *exchange;
59 } scamper_host_rr_mx_t;
60 
61 typedef struct scamper_host_rr_soa
62 {
63   char                    *mname;
64   char                    *rname;
65   uint32_t                 serial;
66   uint32_t                 refresh;
67   uint32_t                 retry;
68   uint32_t                 expire;
69   uint32_t                 minimum;
70 } scamper_host_rr_soa_t;
71 
72 typedef struct scamper_host_rr
73 {
74   uint16_t                 class;
75   uint16_t                 type;
76   char                    *name;
77   uint32_t                 ttl;
78   union
79   {
80     void                  *v;
81     scamper_addr_t        *addr;
82     char                  *str;
83     scamper_host_rr_soa_t *soa;
84     scamper_host_rr_mx_t  *mx;
85   } un;
86 } scamper_host_rr_t;
87 
88 typedef struct scamper_host_query
89 {
90   struct timeval           tx;
91   struct timeval           rx;
92   uint16_t                 id;
93   uint16_t                 ancount; /* answer count */
94   uint16_t                 nscount; /* authority count */
95   uint16_t                 arcount; /* additional count */
96   scamper_host_rr_t      **an;
97   scamper_host_rr_t      **ns;
98   scamper_host_rr_t      **ar;
99 } scamper_host_query_t;
100 
101 typedef struct scamper_host
102 {
103   scamper_list_t          *list;     /* list */
104   scamper_cycle_t         *cycle;    /* cycle */
105   scamper_addr_t          *src;      /* source IP address */
106   scamper_addr_t          *dst;      /* DNS server to query */
107   uint32_t                 userid;   /* user assigned id */
108   struct timeval           start;    /* when started */
109   uint16_t                 flags;    /* flags controlling */
110   uint16_t                 wait;     /* how long to wait, in ms */
111   uint8_t                  stop;     /* reason we stopped */
112   uint8_t                  retries;  /* how many retries to make */
113   uint16_t                 qtype;    /* query type */
114   uint16_t                 qclass;   /* query class */
115   char                    *qname;    /* query name */
116   scamper_host_query_t   **queries;  /* queries sent */
117   uint8_t                  qcount;   /* number of queries sent */
118 } scamper_host_t;
119 
120 scamper_host_rr_mx_t *scamper_host_rr_mx_alloc(uint16_t, const char *);
121 void scamper_host_rr_mx_free(scamper_host_rr_mx_t *);
122 scamper_host_rr_soa_t *scamper_host_rr_soa_alloc(const char *, const char *);
123 void scamper_host_rr_soa_free(scamper_host_rr_soa_t *);
124 
125 scamper_host_rr_t *scamper_host_rr_alloc(const char *,
126 					 uint16_t, uint16_t, uint32_t);
127 void scamper_host_rr_free(scamper_host_rr_t *);
128 
129 int scamper_host_rr_data_type(uint16_t class, uint16_t type);
130 
131 int scamper_host_queries_alloc(scamper_host_t *host, int n);
132 scamper_host_query_t *scamper_host_query_alloc(void);
133 int scamper_host_query_rr_alloc(scamper_host_query_t *query);
134 
135 scamper_host_t *scamper_host_alloc(void);
136 void scamper_host_free(scamper_host_t *);
137 
138 #endif /* __SCAMPER_HOST_H */
139