xref: /freebsd/contrib/unbound/services/mesh.h (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
1 /*
2  * services/mesh.h - deal with mesh of query states and handle events for that.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /**
37  * \file
38  *
39  * This file contains functions to assist in dealing with a mesh of
40  * query states. This mesh is supposed to be thread-specific.
41  * It consists of query states (per qname, qtype, qclass) and connections
42  * between query states and the super and subquery states, and replies to
43  * send back to clients.
44  */
45 
46 #ifndef SERVICES_MESH_H
47 #define SERVICES_MESH_H
48 
49 #include "util/rbtree.h"
50 #include "util/netevent.h"
51 #include "util/data/msgparse.h"
52 #include "util/module.h"
53 #include "services/modstack.h"
54 struct sldns_buffer;
55 struct mesh_state;
56 struct mesh_reply;
57 struct mesh_cb;
58 struct query_info;
59 struct reply_info;
60 struct outbound_entry;
61 struct timehist;
62 struct respip_client_info;
63 
64 /**
65  * Maximum number of mesh state activations. Any more is likely an
66  * infinite loop in the module. It is then terminated.
67  */
68 #define MESH_MAX_ACTIVATION 3000
69 
70 /**
71  * Max number of references-to-references-to-references.. search size.
72  * Any more is treated like 'too large', and the creation of a new
73  * dependency is failed (so that no loops can be created).
74  */
75 #define MESH_MAX_SUBSUB 1024
76 
77 /**
78  * Mesh of query states
79  */
80 struct mesh_area {
81 	/** active module stack */
82 	struct module_stack mods;
83 	/** environment for new states */
84 	struct module_env* env;
85 
86 	/** set of runnable queries (mesh_state.run_node) */
87 	rbtree_type run;
88 	/** rbtree of all current queries (mesh_state.node)*/
89 	rbtree_type all;
90 
91 	/** count of the total number of mesh_reply entries */
92 	size_t num_reply_addrs;
93 	/** count of the number of mesh_states that have mesh_replies
94 	 * Because a state can send results to multiple reply addresses,
95 	 * this number must be equal or lower than num_reply_addrs. */
96 	size_t num_reply_states;
97 	/** number of mesh_states that have no mesh_replies, and also
98 	 * an empty set of super-states, thus are 'toplevel' or detached
99 	 * internal opportunistic queries */
100 	size_t num_detached_states;
101 	/** number of reply states in the forever list */
102 	size_t num_forever_states;
103 
104 	/** max total number of reply states to have */
105 	size_t max_reply_states;
106 	/** max forever number of reply states to have */
107 	size_t max_forever_states;
108 
109 	/** stats, cumulative number of reply states jostled out */
110 	size_t stats_jostled;
111 	/** stats, cumulative number of incoming client msgs dropped */
112 	size_t stats_dropped;
113 	/** number of replies sent */
114 	size_t replies_sent;
115 	/** sum of waiting times for the replies */
116 	struct timeval replies_sum_wait;
117 	/** histogram of time values */
118 	struct timehist* histogram;
119 	/** (extended stats) secure replies */
120 	size_t ans_secure;
121 	/** (extended stats) bogus replies */
122 	size_t ans_bogus;
123 	/** (extended stats) rcodes in replies */
124 	size_t ans_rcode[16];
125 	/** (extended stats) rcode nodata in replies */
126 	size_t ans_nodata;
127 
128 	/** backup of query if other operations recurse and need the
129 	 * network buffers */
130 	struct sldns_buffer* qbuf_bak;
131 
132 	/** double linked list of the run-to-completion query states.
133 	 * These are query states with a reply */
134 	struct mesh_state* forever_first;
135 	/** last entry in run forever list */
136 	struct mesh_state* forever_last;
137 
138 	/** double linked list of the query states that can be jostled out
139 	 * by new queries if too old.  These are query states with a reply */
140 	struct mesh_state* jostle_first;
141 	/** last entry in jostle list - this is the entry that is newest */
142 	struct mesh_state* jostle_last;
143 	/** timeout for jostling. if age is lower, it does not get jostled. */
144 	struct timeval jostle_max;
145 };
146 
147 /**
148  * A mesh query state
149  * Unique per qname, qtype, qclass (from the qstate).
150  * And RD / CD flag; in case a client turns it off.
151  * And priming queries are different from ordinary queries (because of hints).
152  *
153  * The entire structure is allocated in a region, this region is the qstate
154  * region. All parts (rbtree nodes etc) are also allocated in the region.
155  */
156 struct mesh_state {
157 	/** node in mesh_area all tree, key is this struct. Must be first. */
158 	rbnode_type node;
159 	/** node in mesh_area runnable tree, key is this struct */
160 	rbnode_type run_node;
161 	/** the query state. Note that the qinfo and query_flags
162 	 * may not change. */
163 	struct module_qstate s;
164 	/** the list of replies to clients for the results */
165 	struct mesh_reply* reply_list;
166 	/** the list of callbacks for the results */
167 	struct mesh_cb* cb_list;
168 	/** set of superstates (that want this state's result)
169 	 * contains struct mesh_state_ref* */
170 	rbtree_type super_set;
171 	/** set of substates (that this state needs to continue)
172 	 * contains struct mesh_state_ref* */
173 	rbtree_type sub_set;
174 	/** number of activations for the mesh state */
175 	size_t num_activated;
176 
177 	/** previous in linked list for reply states */
178 	struct mesh_state* prev;
179 	/** next in linked list for reply states */
180 	struct mesh_state* next;
181 	/** if this state is in the forever list, jostle list, or neither */
182 	enum mesh_list_select { mesh_no_list, mesh_forever_list,
183 		mesh_jostle_list } list_select;
184 	/** pointer to this state for uniqueness or NULL */
185 	struct mesh_state* unique;
186 
187 	/** true if replies have been sent out (at end for alignment) */
188 	uint8_t replies_sent;
189 };
190 
191 /**
192  * Rbtree reference to a mesh_state.
193  * Used in super_set and sub_set.
194  */
195 struct mesh_state_ref {
196 	/** node in rbtree for set, key is this structure */
197 	rbnode_type node;
198 	/** the mesh state */
199 	struct mesh_state* s;
200 };
201 
202 /**
203  * Reply to a client
204  */
205 struct mesh_reply {
206 	/** next in reply list */
207 	struct mesh_reply* next;
208 	/** the query reply destination, packet buffer and where to send. */
209 	struct comm_reply query_reply;
210 	/** edns data from query */
211 	struct edns_data edns;
212 	/** the time when request was entered */
213 	struct timeval start_time;
214 	/** id of query, in network byteorder. */
215 	uint16_t qid;
216 	/** flags of query, for reply flags */
217 	uint16_t qflags;
218 	/** qname from this query. len same as mesh qinfo. */
219 	uint8_t* qname;
220 	/** same as that in query_info. */
221 	struct local_rrset* local_alias;
222 };
223 
224 /**
225  * Mesh result callback func.
226  * called as func(cb_arg, rcode, buffer_with_reply, security, why_bogus,
227  *		was_ratelimited);
228  */
229 typedef void (*mesh_cb_func_type)(void* cb_arg, int rcode, struct sldns_buffer*,
230 	enum sec_status, char* why_bogus, int was_ratelimited);
231 
232 /**
233  * Callback to result routine
234  */
235 struct mesh_cb {
236 	/** next in list */
237 	struct mesh_cb* next;
238 	/** edns data from query */
239 	struct edns_data edns;
240 	/** id of query, in network byteorder. */
241 	uint16_t qid;
242 	/** flags of query, for reply flags */
243 	uint16_t qflags;
244 	/** buffer for reply */
245 	struct sldns_buffer* buf;
246 	/** callback routine for results. if rcode != 0 buf has message.
247 	 * called as cb(cb_arg, rcode, buf, sec_state, why_bogus, was_ratelimited);
248 	 */
249 	mesh_cb_func_type cb;
250 	/** user arg for callback */
251 	void* cb_arg;
252 };
253 
254 /* ------------------- Functions for worker -------------------- */
255 
256 /**
257  * Allocate mesh, to empty.
258  * @param stack: module stack to activate, copied (as readonly reference).
259  * @param env: environment for new queries.
260  * @return mesh: the new mesh or NULL on error.
261  */
262 struct mesh_area* mesh_create(struct module_stack* stack,
263 	struct module_env* env);
264 
265 /**
266  * Delete mesh, and all query states and replies in it.
267  * @param mesh: the mesh to delete.
268  */
269 void mesh_delete(struct mesh_area* mesh);
270 
271 /**
272  * New query incoming from clients. Create new query state if needed, and
273  * add mesh_reply to it. Returns error to client on malloc failures.
274  * Will run the mesh area queries to process if a new query state is created.
275  *
276  * @param mesh: the mesh.
277  * @param qinfo: query from client.
278  * @param cinfo: additional information associated with the query client.
279  * 	'cinfo' itself is ephemeral but data pointed to by its members
280  *      can be assumed to be valid and unchanged until the query processing is
281  *      completed.
282  * @param qflags: flags from client query.
283  * @param edns: edns data from client query.
284  * @param rep: where to reply to.
285  * @param qid: query id to reply with.
286  */
287 void mesh_new_client(struct mesh_area* mesh, struct query_info* qinfo,
288 	struct respip_client_info* cinfo, uint16_t qflags,
289 	struct edns_data* edns, struct comm_reply* rep, uint16_t qid);
290 
291 /**
292  * New query with callback. Create new query state if needed, and
293  * add mesh_cb to it.
294  * Will run the mesh area queries to process if a new query state is created.
295  *
296  * @param mesh: the mesh.
297  * @param qinfo: query from client.
298  * @param qflags: flags from client query.
299  * @param edns: edns data from client query.
300  * @param buf: buffer for reply contents.
301  * @param qid: query id to reply with.
302  * @param cb: callback function.
303  * @param cb_arg: callback user arg.
304  * @return 0 on error.
305  */
306 int mesh_new_callback(struct mesh_area* mesh, struct query_info* qinfo,
307 	uint16_t qflags, struct edns_data* edns, struct sldns_buffer* buf,
308 	uint16_t qid, mesh_cb_func_type cb, void* cb_arg);
309 
310 /**
311  * New prefetch message. Create new query state if needed.
312  * Will run the mesh area queries to process if a new query state is created.
313  *
314  * @param mesh: the mesh.
315  * @param qinfo: query from client.
316  * @param qflags: flags from client query.
317  * @param leeway: TTL leeway what to expire earlier for this update.
318  */
319 void mesh_new_prefetch(struct mesh_area* mesh, struct query_info* qinfo,
320 	uint16_t qflags, time_t leeway);
321 
322 /**
323  * Handle new event from the wire. A serviced query has returned.
324  * The query state will be made runnable, and the mesh_area will process
325  * query states until processing is complete.
326  *
327  * @param mesh: the query mesh.
328  * @param e: outbound entry, with query state to run and reply pointer.
329  * @param reply: the comm point reply info.
330  * @param what: NETEVENT_* error code (if not 0, what is wrong, TIMEOUT).
331  */
332 void mesh_report_reply(struct mesh_area* mesh, struct outbound_entry* e,
333 	struct comm_reply* reply, int what);
334 
335 /* ------------------- Functions for module environment --------------- */
336 
337 /**
338  * Detach-subqueries.
339  * Remove all sub-query references from this query state.
340  * Keeps super-references of those sub-queries correct.
341  * Updates stat items in mesh_area structure.
342  * @param qstate: used to find mesh state.
343  */
344 void mesh_detach_subs(struct module_qstate* qstate);
345 
346 /**
347  * Attach subquery.
348  * Creates it if it does not exist already.
349  * Keeps sub and super references correct.
350  * Performs a cycle detection - for double check - and fails if there is one.
351  * Also fails if the sub-sub-references become too large.
352  * Updates stat items in mesh_area structure.
353  * Pass if it is priming query or not.
354  * return:
355  * 	o if error (malloc) happened.
356  * 	o need to initialise the new state (module init; it is a new state).
357  * 	  so that the next run of the query with this module is successful.
358  * 	o no init needed, attachment successful.
359  *
360  * @param qstate: the state to find mesh state, and that wants to receive
361  * 	the results from the new subquery.
362  * @param qinfo: what to query for (copied).
363  * @param qflags: what flags to use (RD / CD flag or not).
364  * @param prime: if it is a (stub) priming query.
365  * @param valrec: if it is a validation recursion query (lookup of key, DS).
366  * @param newq: If the new subquery needs initialisation, it is returned,
367  * 	otherwise NULL is returned.
368  * @return: false on error, true if success (and init may be needed).
369  */
370 int mesh_attach_sub(struct module_qstate* qstate, struct query_info* qinfo,
371 	uint16_t qflags, int prime, int valrec, struct module_qstate** newq);
372 
373 /**
374  * Add detached query.
375  * Creates it if it does not exist already.
376  * Does not make super/sub references.
377  * Performs a cycle detection - for double check - and fails if there is one.
378  * Updates stat items in mesh_area structure.
379  * Pass if it is priming query or not.
380  * return:
381  * 	o if error (malloc) happened.
382  * 	o need to initialise the new state (module init; it is a new state).
383  * 	  so that the next run of the query with this module is successful.
384  * 	o no init needed, attachment successful.
385  * 	o added subquery, created if it did not exist already.
386  *
387  * @param qstate: the state to find mesh state, and that wants to receive
388  * 	the results from the new subquery.
389  * @param qinfo: what to query for (copied).
390  * @param qflags: what flags to use (RD / CD flag or not).
391  * @param prime: if it is a (stub) priming query.
392  * @param valrec: if it is a validation recursion query (lookup of key, DS).
393  * @param newq: If the new subquery needs initialisation, it is returned,
394  * 	otherwise NULL is returned.
395  * @param sub: The added mesh state, created if it did not exist already.
396  * @return: false on error, true if success (and init may be needed).
397  */
398 int mesh_add_sub(struct module_qstate* qstate, struct query_info* qinfo,
399         uint16_t qflags, int prime, int valrec, struct module_qstate** newq,
400 	struct mesh_state** sub);
401 
402 /**
403  * Query state is done, send messages to reply entries.
404  * Encode messages using reply entry values and the querystate (with original
405  * qinfo), using given reply_info.
406  * Pass errcode != 0 if an error reply is needed.
407  * If no reply entries, nothing is done.
408  * Must be called before a module can module_finished or return module_error.
409  * The module must handle the super query states itself as well.
410  *
411  * @param mstate: mesh state that is done. return_rcode and return_msg
412  * 	are used for replies.
413  * 	return_rcode: if not 0 (NOERROR) an error is sent back (and
414  * 		return_msg is ignored).
415  * 	return_msg: reply to encode and send back to clients.
416  */
417 void mesh_query_done(struct mesh_state* mstate);
418 
419 /**
420  * Call inform_super for the super query states that are interested in the
421  * results from this query state. These can then be changed for error
422  * or results.
423  * Called when a module is module_finished or returns module_error.
424  * The super query states become runnable with event module_event_pass,
425  * it calls the current module for the super with the inform_super event.
426  *
427  * @param mesh: mesh area to add newly runnable modules to.
428  * @param mstate: the state that has results, used to find mesh state.
429  */
430 void mesh_walk_supers(struct mesh_area* mesh, struct mesh_state* mstate);
431 
432 /**
433  * Delete mesh state, cleanup and also rbtrees and so on.
434  * Will detach from all super/subnodes.
435  * @param qstate: to remove.
436  */
437 void mesh_state_delete(struct module_qstate* qstate);
438 
439 /* ------------------- Functions for mesh -------------------- */
440 
441 /**
442  * Create and initialize a new mesh state and its query state
443  * Does not put the mesh state into rbtrees and so on.
444  * @param env: module environment to set.
445  * @param qinfo: query info that the mesh is for.
446  * @param cinfo: control info for the query client (can be NULL).
447  * @param qflags: flags for query (RD / CD flag).
448  * @param prime: if true, it is a priming query, set is_priming on mesh state.
449  * @param valrec: if true, it is a validation recursion query, and sets
450  * 	is_valrec on the mesh state.
451  * @return: new mesh state or NULL on allocation error.
452  */
453 struct mesh_state* mesh_state_create(struct module_env* env,
454 	struct query_info* qinfo, struct respip_client_info* cinfo,
455 	uint16_t qflags, int prime, int valrec);
456 
457 /**
458  * Check if the mesh state is unique.
459  * A unique mesh state uses it's unique member to point to itself, else NULL.
460  * @param mstate: mesh state to check.
461  * @return true if the mesh state is unique, false otherwise.
462  */
463 int mesh_state_is_unique(struct mesh_state* mstate);
464 
465 /**
466  * Make a mesh state unique.
467  * A unique mesh state uses it's unique member to point to itself.
468  * @param mstate: mesh state to check.
469  */
470 void mesh_state_make_unique(struct mesh_state* mstate);
471 
472 /**
473  * Cleanup a mesh state and its query state. Does not do rbtree or
474  * reference cleanup.
475  * @param mstate: mesh state to cleanup. Its pointer may no longer be used
476  * 	afterwards. Cleanup rbtrees before calling this function.
477  */
478 void mesh_state_cleanup(struct mesh_state* mstate);
479 
480 /**
481  * Delete all mesh states from the mesh.
482  * @param mesh: the mesh area to clear
483  */
484 void mesh_delete_all(struct mesh_area* mesh);
485 
486 /**
487  * Find a mesh state in the mesh area. Pass relevant flags.
488  *
489  * @param mesh: the mesh area to look in.
490  * @param cinfo: if non-NULL client specific info that may affect IP-based
491  * 	actions that apply to the query result.
492  * @param qinfo: what query
493  * @param qflags: if RD / CD bit is set or not.
494  * @param prime: if it is a priming query.
495  * @param valrec: if it is a validation-recursion query.
496  * @return: mesh state or NULL if not found.
497  */
498 struct mesh_state* mesh_area_find(struct mesh_area* mesh,
499 	struct respip_client_info* cinfo, struct query_info* qinfo,
500 	uint16_t qflags, int prime, int valrec);
501 
502 /**
503  * Setup attachment super/sub relation between super and sub mesh state.
504  * The relation must not be present when calling the function.
505  * Does not update stat items in mesh_area.
506  * @param super: super state.
507  * @param sub: sub state.
508  * @return: 0 on alloc error.
509  */
510 int mesh_state_attachment(struct mesh_state* super, struct mesh_state* sub);
511 
512 /**
513  * Create new reply structure and attach it to a mesh state.
514  * Does not update stat items in mesh area.
515  * @param s: the mesh state.
516  * @param edns: edns data for reply (bufsize).
517  * @param rep: comm point reply info.
518  * @param qid: ID of reply.
519  * @param qflags: original query flags.
520  * @param qinfo: original query info.
521  * @return: 0 on alloc error.
522  */
523 int mesh_state_add_reply(struct mesh_state* s, struct edns_data* edns,
524 	struct comm_reply* rep, uint16_t qid, uint16_t qflags,
525 	const struct query_info* qinfo);
526 
527 /**
528  * Create new callback structure and attach it to a mesh state.
529  * Does not update stat items in mesh area.
530  * @param s: the mesh state.
531  * @param edns: edns data for reply (bufsize).
532  * @param buf: buffer for reply
533  * @param cb: callback to call with results.
534  * @param cb_arg: callback user arg.
535  * @param qid: ID of reply.
536  * @param qflags: original query flags.
537  * @return: 0 on alloc error.
538  */
539 int mesh_state_add_cb(struct mesh_state* s, struct edns_data* edns,
540         struct sldns_buffer* buf, mesh_cb_func_type cb, void* cb_arg,
541 	uint16_t qid, uint16_t qflags);
542 
543 /**
544  * Run the mesh. Run all runnable mesh states. Which can create new
545  * runnable mesh states. Until completion. Automatically called by
546  * mesh_report_reply and mesh_new_client as needed.
547  * @param mesh: mesh area.
548  * @param mstate: first mesh state to run.
549  * @param ev: event the mstate. Others get event_pass.
550  * @param e: if a reply, its outbound entry.
551  */
552 void mesh_run(struct mesh_area* mesh, struct mesh_state* mstate,
553 	enum module_ev ev, struct outbound_entry* e);
554 
555 /**
556  * Print some stats about the mesh to the log.
557  * @param mesh: the mesh to print it for.
558  * @param str: descriptive string to go with it.
559  */
560 void mesh_stats(struct mesh_area* mesh, const char* str);
561 
562 /**
563  * Clear the stats that the mesh keeps (number of queries serviced)
564  * @param mesh: the mesh
565  */
566 void mesh_stats_clear(struct mesh_area* mesh);
567 
568 /**
569  * Print all the states in the mesh to the log.
570  * @param mesh: the mesh to print all states of.
571  */
572 void mesh_log_list(struct mesh_area* mesh);
573 
574 /**
575  * Calculate memory size in use by mesh and all queries inside it.
576  * @param mesh: the mesh to examine.
577  * @return size in bytes.
578  */
579 size_t mesh_get_mem(struct mesh_area* mesh);
580 
581 /**
582  * Find cycle; see if the given mesh is in the targets sub, or sub-sub, ...
583  * trees.
584  * If the sub-sub structure is too large, it returns 'a cycle'=2.
585  * @param qstate: given mesh querystate.
586  * @param qinfo: query info for dependency.
587  * @param flags: query flags of dependency.
588  * @param prime: if dependency is a priming query or not.
589  * @param valrec: if it is a validation recursion query (lookup of key, DS).
590  * @return true if the name,type,class exists and the given qstate mesh exists
591  * 	as a dependency of that name. Thus if qstate becomes dependent on
592  * 	name,type,class then a cycle is created, this is return value 1.
593  * 	Too large to search is value 2 (also true).
594  */
595 int mesh_detect_cycle(struct module_qstate* qstate, struct query_info* qinfo,
596 	uint16_t flags, int prime, int valrec);
597 
598 /** compare two mesh_states */
599 int mesh_state_compare(const void* ap, const void* bp);
600 
601 /** compare two mesh references */
602 int mesh_state_ref_compare(const void* ap, const void* bp);
603 
604 /**
605  * Make space for another recursion state for a reply in the mesh
606  * @param mesh: mesh area
607  * @param qbuf: query buffer to save if recursion is invoked to make space.
608  *    This buffer is necessary, because the following sequence in calls
609  *    can result in an overwrite of the incoming query:
610  *    delete_other_mesh_query - iter_clean - serviced_delete - waiting
611  *    udp query is sent - on error callback - callback sends SERVFAIL reply
612  *    over the same network channel, and shared UDP buffer is overwritten.
613  *    You can pass NULL if there is no buffer that must be backed up.
614  * @return false if no space is available.
615  */
616 int mesh_make_new_space(struct mesh_area* mesh, struct sldns_buffer* qbuf);
617 
618 /**
619  * Insert mesh state into a double linked list.  Inserted at end.
620  * @param m: mesh state.
621  * @param fp: pointer to the first-elem-pointer of the list.
622  * @param lp: pointer to the last-elem-pointer of the list.
623  */
624 void mesh_list_insert(struct mesh_state* m, struct mesh_state** fp,
625 	struct mesh_state** lp);
626 
627 /**
628  * Remove mesh state from a double linked list.  Remove from any position.
629  * @param m: mesh state.
630  * @param fp: pointer to the first-elem-pointer of the list.
631  * @param lp: pointer to the last-elem-pointer of the list.
632  */
633 void mesh_list_remove(struct mesh_state* m, struct mesh_state** fp,
634 	struct mesh_state** lp);
635 
636 #endif /* SERVICES_MESH_H */
637