respip.h revision 1.1 1 1.1 christos /*
2 1.1 christos * respip/respip.h - IP-based response modification module
3 1.1 christos */
4 1.1 christos
5 1.1 christos /**
6 1.1 christos * \file
7 1.1 christos *
8 1.1 christos * This file contains a module that selectively modifies query responses
9 1.1 christos * based on their AAAA/A IP addresses.
10 1.1 christos */
11 1.1 christos
12 1.1 christos #ifndef RESPIP_RESPIP_H
13 1.1 christos #define RESPIP_RESPIP_H
14 1.1 christos
15 1.1 christos #include "util/module.h"
16 1.1 christos #include "services/localzone.h"
17 1.1 christos
18 1.1 christos /**
19 1.1 christos * Set of response IP addresses with associated actions and tags.
20 1.1 christos * Forward declaration only here. Actual definition is hidden within the
21 1.1 christos * module.
22 1.1 christos */
23 1.1 christos struct respip_set;
24 1.1 christos
25 1.1 christos /**
26 1.1 christos * Forward declaration for the structure that represents a node in the
27 1.1 christos * respip_set address tree
28 1.1 christos */
29 1.1 christos struct resp_addr;
30 1.1 christos
31 1.1 christos /**
32 1.1 christos * Forward declaration for the structure that represents a tree of view data.
33 1.1 christos */
34 1.1 christos struct views;
35 1.1 christos
36 1.1 christos struct respip_addr_info;
37 1.1 christos
38 1.1 christos /**
39 1.1 christos * Client-specific attributes that can affect IP-based actions.
40 1.1 christos * This is essentially a subset of acl_addr (except for respip_set) but
41 1.1 christos * defined as a separate structure to avoid dependency on the daemon-specific
42 1.1 christos * structure.
43 1.1 christos * respip_set is supposed to refer to the response-ip set for the global view.
44 1.1 christos */
45 1.1 christos struct respip_client_info {
46 1.1 christos uint8_t* taglist;
47 1.1 christos size_t taglen;
48 1.1 christos uint8_t* tag_actions;
49 1.1 christos size_t tag_actions_size;
50 1.1 christos struct config_strlist** tag_datas;
51 1.1 christos size_t tag_datas_size;
52 1.1 christos struct view* view;
53 1.1 christos struct respip_set* respip_set;
54 1.1 christos };
55 1.1 christos
56 1.1 christos /**
57 1.1 christos * Data items representing the result of response-ip processing.
58 1.1 christos * Note: this structure currently only define a few members, but exists
59 1.1 christos * as a separate struct mainly for the convenience of custom extensions.
60 1.1 christos */
61 1.1 christos struct respip_action_info {
62 1.1 christos enum respip_action action;
63 1.1 christos struct respip_addr_info* addrinfo; /* set only for inform variants */
64 1.1 christos };
65 1.1 christos
66 1.1 christos /**
67 1.1 christos * Forward declaration for the structure that represents a node in the
68 1.1 christos * respip_set address tree
69 1.1 christos */
70 1.1 christos struct resp_addr;
71 1.1 christos
72 1.1 christos /**
73 1.1 christos * Create response IP set.
74 1.1 christos * @return new struct or NULL on error.
75 1.1 christos */
76 1.1 christos struct respip_set* respip_set_create(void);
77 1.1 christos
78 1.1 christos /**
79 1.1 christos * Delete response IP set.
80 1.1 christos * @param set: to delete.
81 1.1 christos */
82 1.1 christos void respip_set_delete(struct respip_set* set);
83 1.1 christos
84 1.1 christos /**
85 1.1 christos * Apply response-ip config settings to the global (default) view.
86 1.1 christos * It assumes exclusive access to set (no internal locks).
87 1.1 christos * @param set: processed global respip config data
88 1.1 christos * @param cfg: config data.
89 1.1 christos * @return 1 on success, 0 on error.
90 1.1 christos */
91 1.1 christos int respip_global_apply_cfg(struct respip_set* set, struct config_file* cfg);
92 1.1 christos
93 1.1 christos /**
94 1.1 christos * Apply response-ip config settings in named views.
95 1.1 christos * @param vs: view structures with processed config data
96 1.1 christos * @param cfg: config data.
97 1.1 christos * @param have_view_respip_cfg: set to true if any named view has respip
98 1.1 christos * configuration; otherwise set to false
99 1.1 christos * @return 1 on success, 0 on error.
100 1.1 christos */
101 1.1 christos int respip_views_apply_cfg(struct views* vs, struct config_file* cfg,
102 1.1 christos int* have_view_respip_cfg);
103 1.1 christos
104 1.1 christos /**
105 1.1 christos * Merge two replies to build a complete CNAME chain.
106 1.1 christos * It appends the content of 'tgt_rep' to 'base_rep', assuming (but not
107 1.1 christos * checking) the former ends with a CNAME and the latter resolves its target.
108 1.1 christos * A merged new reply will be built using 'region' and *new_repp will point
109 1.1 christos * to the new one on success.
110 1.1 christos * If the target reply would also be subject to a response-ip action for
111 1.1 christos * 'cinfo', this function uses 'base_rep' as the merged reply, ignoring
112 1.1 christos * 'tgt_rep'. This is for avoiding cases like a CNAME loop or failure of
113 1.1 christos * applying an action to an address.
114 1.1 christos * RRSIGs in 'tgt_rep' will be excluded in the merged reply, as the resulting
115 1.1 christos * reply is assumed to be faked due to a response-ip action and can't be
116 1.1 christos * considered secure in terms of DNSSEC.
117 1.1 christos * The caller must ensure that neither 'base_rep' nor 'tgt_rep' can be modified
118 1.1 christos * until this function returns.
119 1.1 christos * @param base_rep: the reply info containing an incomplete CNAME.
120 1.1 christos * @param qinfo: query info corresponding to 'base_rep'.
121 1.1 christos * @param tgt_rep: the reply info that completes the CNAME chain.
122 1.1 christos * @param cinfo: client info corresponding to 'base_rep'.
123 1.1 christos * @param must_validate: whether 'tgt_rep' must be DNSSEC-validated.
124 1.1 christos * @param new_repp: pointer placeholder for the merged reply. will be intact
125 1.1 christos * on error.
126 1.1 christos * @param region: allocator to build *new_repp.
127 1.1 christos * @return 1 on success, 0 on error.
128 1.1 christos */
129 1.1 christos int respip_merge_cname(struct reply_info* base_rep,
130 1.1 christos const struct query_info* qinfo, const struct reply_info* tgt_rep,
131 1.1 christos const struct respip_client_info* cinfo, int must_validate,
132 1.1 christos struct reply_info** new_repp, struct regional* region);
133 1.1 christos
134 1.1 christos /**
135 1.1 christos * See if any IP-based action should apply to any IP address of AAAA/A answer
136 1.1 christos * record in the reply. If so, apply the action. In some cases it rewrites
137 1.1 christos * the reply rrsets, in which case *new_repp will point to the updated reply
138 1.1 christos * info. Depending on the action, some of the rrsets in 'rep' will be
139 1.1 christos * shallow-copied into '*new_repp'; the caller must ensure that the rrsets
140 1.1 christos * in 'rep' are valid throughout the lifetime of *new_repp, and it must
141 1.1 christos * provide appropriate mutex if the rrsets can be shared by multiple threads.
142 1.1 christos * @param qinfo: query info corresponding to the reply.
143 1.1 christos * @param cinfo: client-specific info to identify the best matching action.
144 1.1 christos * can be NULL.
145 1.1 christos * @param rep: original reply info. must not be NULL.
146 1.1 christos * @param new_repp: can be set to the rewritten reply info (intact on failure).
147 1.1 christos * @param actinfo: result of response-ip processing
148 1.1 christos * @param alias_rrset: must not be NULL.
149 1.1 christos * @param search_only: if true, only check if an action would apply. actionp
150 1.1 christos * will be set (or intact) accordingly but the modified reply won't be built.
151 1.1 christos * @param region: allocator to build *new_repp.
152 1.1 christos * @return 1 on success, 0 on error.
153 1.1 christos */
154 1.1 christos int respip_rewrite_reply(const struct query_info* qinfo,
155 1.1 christos const struct respip_client_info* cinfo,
156 1.1 christos const struct reply_info *rep, struct reply_info** new_repp,
157 1.1 christos struct respip_action_info* actinfo,
158 1.1 christos struct ub_packed_rrset_key** alias_rrset,
159 1.1 christos int search_only, struct regional* region);
160 1.1 christos
161 1.1 christos /**
162 1.1 christos * Get the response-ip function block.
163 1.1 christos * @return: function block with function pointers to response-ip methods.
164 1.1 christos */
165 1.1 christos struct module_func_block* respip_get_funcblock(void);
166 1.1 christos
167 1.1 christos /** response-ip init */
168 1.1 christos int respip_init(struct module_env* env, int id);
169 1.1 christos
170 1.1 christos /** response-ip deinit */
171 1.1 christos void respip_deinit(struct module_env* env, int id);
172 1.1 christos
173 1.1 christos /** response-ip operate on a query */
174 1.1 christos void respip_operate(struct module_qstate* qstate, enum module_ev event, int id,
175 1.1 christos struct outbound_entry* outbound);
176 1.1 christos
177 1.1 christos /** inform response-ip super */
178 1.1 christos void respip_inform_super(struct module_qstate* qstate, int id,
179 1.1 christos struct module_qstate* super);
180 1.1 christos
181 1.1 christos /** response-ip cleanup query state */
182 1.1 christos void respip_clear(struct module_qstate* qstate, int id);
183 1.1 christos
184 1.1 christos /**
185 1.1 christos * returns address of the IP address tree of the specified respip set;
186 1.1 christos * returns NULL for NULL input; exists for test purposes only
187 1.1 christos */
188 1.1 christos struct rbtree_type* respip_set_get_tree(struct respip_set* set);
189 1.1 christos
190 1.1 christos /**
191 1.1 christos * returns respip action for the specified node in the respip address
192 1.1 christos * returns respip_none for NULL input; exists for test purposes only
193 1.1 christos */
194 1.1 christos enum respip_action resp_addr_get_action(const struct resp_addr* addr);
195 1.1 christos
196 1.1 christos /**
197 1.1 christos * returns rrset portion of the specified node in the respip address
198 1.1 christos * tree; returns NULL for NULL input; exists for test purposes only
199 1.1 christos */
200 1.1 christos struct ub_packed_rrset_key* resp_addr_get_rrset(struct resp_addr* addr);
201 1.1 christos
202 1.1 christos /** response-ip alloc size routine */
203 1.1 christos size_t respip_get_mem(struct module_env* env, int id);
204 1.1 christos
205 1.1 christos /**
206 1.1 christos * respip set emptiness test
207 1.1 christos * @param set respip set to test
208 1.1 christos * @return 0 if the specified set exists (non-NULL) and is non-empty;
209 1.1 christos * otherwise returns 1
210 1.1 christos */
211 1.1 christos int respip_set_is_empty(const struct respip_set* set);
212 1.1 christos
213 1.1 christos /**
214 1.1 christos * print log information for a query subject to an inform or inform-deny
215 1.1 christos * response-ip action.
216 1.1 christos * @param respip_addr: response-ip information that causes the action
217 1.1 christos * @param qname: query name in the context, will be ignored if local_alias is
218 1.1 christos * non-NULL.
219 1.1 christos * @param qtype: query type, in host byte order.
220 1.1 christos * @param qclass: query class, in host byte order.
221 1.1 christos * @param local_alias: set to a local alias if the query matches an alias in
222 1.1 christos * a local zone. In this case its owner name will be considered the actual
223 1.1 christos * query name.
224 1.1 christos * @param repinfo: reply info containing the client's source address and port.
225 1.1 christos */
226 1.1 christos void respip_inform_print(struct respip_addr_info* respip_addr, uint8_t* qname,
227 1.1 christos uint16_t qtype, uint16_t qclass, struct local_rrset* local_alias,
228 1.1 christos struct comm_reply* repinfo);
229 1.1 christos
230 1.1 christos #endif /* RESPIP_RESPIP_H */
231