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