This file is indexed.

/usr/include/varnish/vqueue.h is in libvarnishapi-dev 5.0.0-7+deb9u2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
/*-
 * Copyright (c) 1991, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)queue.h	8.5 (Berkeley) 8/20/94
 * $FreeBSD: head/sys/sys/queue.h 251887 2013-06-18 02:57:56Z lstewart $
 */

#ifndef VARNISH_QUEUE_H
#define	VARNISH_QUEUE_H

/*
 * This file defines four types of data structures: singly-linked lists,
 * singly-linked tail queues, lists and tail queues.
 *
 * A singly-linked list is headed by a single forward pointer. The elements
 * are singly linked for minimum space and pointer manipulation overhead at
 * the expense of O(n) removal for arbitrary elements. New elements can be
 * added to the list after an existing element or at the head of the list.
 * Elements being removed from the head of the list should use the explicit
 * macro for this purpose for optimum efficiency. A singly-linked list may
 * only be traversed in the forward direction.  Singly-linked lists are ideal
 * for applications with large datasets and few or no removals or for
 * implementing a LIFO queue.
 *
 * A singly-linked tail queue is headed by a pair of pointers, one to the
 * head of the list and the other to the tail of the list. The elements are
 * singly linked for minimum space and pointer manipulation overhead at the
 * expense of O(n) removal for arbitrary elements. New elements can be added
 * to the list after an existing element, at the head of the list, or at the
 * end of the list. Elements being removed from the head of the tail queue
 * should use the explicit macro for this purpose for optimum efficiency.
 * A singly-linked tail queue may only be traversed in the forward direction.
 * Singly-linked tail queues are ideal for applications with large datasets
 * and few or no removals or for implementing a FIFO queue.
 *
 * A list is headed by a single forward pointer (or an array of forward
 * pointers for a hash table header). The elements are doubly linked
 * so that an arbitrary element can be removed without a need to
 * traverse the list. New elements can be added to the list before
 * or after an existing element or at the head of the list. A list
 * may be traversed in either direction.
 *
 * A tail queue is headed by a pair of pointers, one to the head of the
 * list and the other to the tail of the list. The elements are doubly
 * linked so that an arbitrary element can be removed without a need to
 * traverse the list. New elements can be added to the list before or
 * after an existing element, at the head of the list, or at the end of
 * the list. A tail queue may be traversed in either direction.
 *
 * For details on the use of these macros, see the queue(3) manual page.
 *
 *
 *				VSLIST	VLIST	VSTAILQ	VTAILQ
 * _HEAD			+	+	+	+
 * _HEAD_INITIALIZER		+	+	+	+
 * _ENTRY			+	+	+	+
 * _INIT			+	+	+	+
 * _EMPTY			+	+	+	+
 * _FIRST			+	+	+	+
 * _NEXT			+	+	+	+
 * _PREV			-	+	-	+
 * _LAST			-	-	+	+
 * _FOREACH			+	+	+	+
 * _FOREACH_FROM		+	+	+	+
 * _FOREACH_SAFE		+	+	+	+
 * _FOREACH_FROM_SAFE		+	+	+	+
 * _FOREACH_REVERSE		-	-	-	+
 * _FOREACH_REVERSE_FROM	-	-	-	+
 * _FOREACH_REVERSE_SAFE	-	-	-	+
 * _FOREACH_REVERSE_FROM_SAFE	-	-	-	+
 * _INSERT_HEAD			+	+	+	+
 * _INSERT_BEFORE		-	+	-	+
 * _INSERT_AFTER		+	+	+	+
 * _INSERT_TAIL			-	-	+	+
 * _CONCAT			-	-	+	+
 * _REMOVE_AFTER		+	-	+	-
 * _REMOVE_HEAD			+	-	+	-
 * _REMOVE			+	+	+	+
 * _SWAP			+	+	+	+
 *
 */
#define	TRACEBUF
#define	TRACEBUF_INITIALIZER
#define	TRASHIT(x)

/*
 * Singly-linked List declarations.
 */
#define	VSLIST_HEAD(name, type)						\
struct name {								\
	struct type *vslh_first;	/* first element */		\
}

#define	VSLIST_HEAD_INITIALIZER(head)					\
	{ NULL }

#define	VSLIST_ENTRY(type)						\
struct {								\
	struct type *vsle_next;	/* next element */			\
}

/*
 * Singly-linked List functions.
 */
#define	VSLIST_EMPTY(head)	((head)->vslh_first == NULL)

#define	VSLIST_FIRST(head)	((head)->vslh_first)

#define	VSLIST_FOREACH(var, head, field)				\
	for ((var) = VSLIST_FIRST((head));				\
	    (var);							\
	    (var) = VSLIST_NEXT((var), field))

#define	VSLIST_FOREACH_FROM(var, head, field)				\
	for ((var) = ((var) ? (var) : VSLIST_FIRST((head)));		\
	    (var);							\
	    (var) = VSLIST_NEXT((var), field))

#define	VSLIST_FOREACH_SAFE(var, head, field, tvar)			\
	for ((var) = VSLIST_FIRST((head));				\
	    (var) && ((tvar) = VSLIST_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VSLIST_FOREACH_FROM_SAFE(var, head, field, tvar)			\
	for ((var) = ((var) ? (var) : VSLIST_FIRST((head)));		\
	    (var) && ((tvar) = VSLIST_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VSLIST_FOREACH_PREVPTR(var, varp, head, field)			\
	for ((varp) = &VSLIST_FIRST((head));				\
	    ((var) = *(varp)) != NULL;					\
	    (varp) = &VSLIST_NEXT((var), field))

#define	VSLIST_INIT(head) do {						\
	VSLIST_FIRST((head)) = NULL;					\
} while (0)

#define	VSLIST_INSERT_AFTER(slistelm, elm, field) do {			\
	VSLIST_NEXT((elm), field) = VSLIST_NEXT((slistelm), field);	\
	VSLIST_NEXT((slistelm), field) = (elm);				\
} while (0)

#define	VSLIST_INSERT_HEAD(head, elm, field) do {			\
	VSLIST_NEXT((elm), field) = VSLIST_FIRST((head));		\
	VSLIST_FIRST((head)) = (elm);					\
} while (0)

#define	VSLIST_NEXT(elm, field)	((elm)->field.vsle_next)

#define	VSLIST_REMOVE(head, elm, type, field) do {			\
	if (VSLIST_FIRST((head)) == (elm)) {				\
		VSLIST_REMOVE_HEAD((head), field);			\
	}								\
	else {								\
		struct type *curelm = VSLIST_FIRST((head));		\
		while (VSLIST_NEXT(curelm, field) != (elm))		\
			curelm = VSLIST_NEXT(curelm, field);		\
		VSLIST_REMOVE_AFTER(curelm, field);			\
	}								\
	TRASHIT(*oldnext);						\
} while (0)

#define VSLIST_REMOVE_AFTER(elm, field) do {				\
	VSLIST_NEXT(elm, field) =					\
	    VSLIST_NEXT(VSLIST_NEXT(elm, field), field);			\
} while (0)

#define	VSLIST_REMOVE_HEAD(head, field) do {				\
	VSLIST_FIRST((head)) = VSLIST_NEXT(VSLIST_FIRST((head)), field);\
} while (0)

#define VSLIST_SWAP(head1, head2, type) do {				\
	struct type *swap_first = VSLIST_FIRST(head1);			\
	VSLIST_FIRST(head1) = VSLIST_FIRST(head2);			\
	VSLIST_FIRST(head2) = swap_first;				\
} while (0)

/*
 * Singly-linked Tail queue declarations.
 */
#define	VSTAILQ_HEAD(name, type)					\
struct name {								\
	struct type *vstqh_first;/* first element */			\
	struct type **vstqh_last;/* addr of last next element */	\
}

#define	VSTAILQ_HEAD_INITIALIZER(head)					\
	{ NULL, &(head).vstqh_first }

#define	VSTAILQ_ENTRY(type)						\
struct {								\
	struct type *vstqe_next;	/* next element */		\
}

/*
 * Singly-linked Tail queue functions.
 */
#define	VSTAILQ_CONCAT(head1, head2) do {				\
	if (!VSTAILQ_EMPTY((head2))) {					\
		*(head1)->vstqh_last = (head2)->vstqh_first;		\
		(head1)->vstqh_last = (head2)->vstqh_last;		\
		VSTAILQ_INIT((head2));					\
	}								\
} while (0)

#define	VSTAILQ_EMPTY(head)	((head)->vstqh_first == NULL)

#define	VSTAILQ_FIRST(head)	((head)->vstqh_first)

#define	VSTAILQ_FOREACH(var, head, field)				\
	for((var) = VSTAILQ_FIRST((head));				\
	   (var);							\
	   (var) = VSTAILQ_NEXT((var), field))

#define	VSTAILQ_FOREACH_FROM(var, head, field)				\
	for ((var) = ((var) ? (var) : VSTAILQ_FIRST((head)));		\
	   (var);							\
	   (var) = VSTAILQ_NEXT((var), field))

#define	VSTAILQ_FOREACH_SAFE(var, head, field, tvar)			\
	for ((var) = VSTAILQ_FIRST((head));				\
	    (var) && ((tvar) = VSTAILQ_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VSTAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)		\
	for ((var) = ((var) ? (var) : VSTAILQ_FIRST((head)));		\
	    (var) && ((tvar) = VSTAILQ_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VSTAILQ_INIT(head) do {						\
	VSTAILQ_FIRST((head)) = NULL;					\
	(head)->vstqh_last = &VSTAILQ_FIRST((head));			\
} while (0)

#define	VSTAILQ_INSERT_AFTER(head, tqelm, elm, field) do {		\
	if ((VSTAILQ_NEXT((elm), field) = VSTAILQ_NEXT((tqelm), field)) == NULL)\
		(head)->vstqh_last = &VSTAILQ_NEXT((elm), field);	\
	VSTAILQ_NEXT((tqelm), field) = (elm);				\
} while (0)

#define	VSTAILQ_INSERT_HEAD(head, elm, field) do {			\
	if ((VSTAILQ_NEXT((elm), field) = VSTAILQ_FIRST((head))) == NULL)\
		(head)->vstqh_last = &VSTAILQ_NEXT((elm), field);	\
	VSTAILQ_FIRST((head)) = (elm);					\
} while (0)

#define	VSTAILQ_INSERT_TAIL(head, elm, field) do {			\
	VSTAILQ_NEXT((elm), field) = NULL;				\
	*(head)->vstqh_last = (elm);					\
	(head)->vstqh_last = &VSTAILQ_NEXT((elm), field);		\
} while (0)

#define	VSTAILQ_LAST(head, type, field)					\
	(VSTAILQ_EMPTY((head)) ? NULL :					\
	    __containerof((head)->vstqh_last, struct type, field.vstqe_next))

#define	VSTAILQ_NEXT(elm, field)	((elm)->field.vstqe_next)

#define	VSTAILQ_REMOVE(head, elm, type, field) do {			\
	if (VSTAILQ_FIRST((head)) == (elm)) {				\
		VSTAILQ_REMOVE_HEAD((head), field);			\
	}								\
	else {								\
		struct type *curelm = VSTAILQ_FIRST((head));		\
		while (VSTAILQ_NEXT(curelm, field) != (elm))		\
			curelm = VSTAILQ_NEXT(curelm, field);		\
		VSTAILQ_REMOVE_AFTER(head, curelm, field);		\
	}								\
	TRASHIT(*oldnext);						\
} while (0)

#define VSTAILQ_REMOVE_AFTER(head, elm, field) do {			\
	if ((VSTAILQ_NEXT(elm, field) =					\
	     VSTAILQ_NEXT(VSTAILQ_NEXT(elm, field), field)) == NULL)	\
		(head)->vstqh_last = &VSTAILQ_NEXT((elm), field);		\
} while (0)

#define	VSTAILQ_REMOVE_HEAD(head, field) do {				\
	if ((VSTAILQ_FIRST((head)) =					\
	     VSTAILQ_NEXT(VSTAILQ_FIRST((head)), field)) == NULL)	\
		(head)->vstqh_last = &VSTAILQ_FIRST((head));		\
} while (0)

#define VSTAILQ_SWAP(head1, head2, type) do {				\
	struct type *swap_first = VSTAILQ_FIRST(head1);			\
	struct type **swap_last = (head1)->vstqh_last;			\
	VSTAILQ_FIRST(head1) = VSTAILQ_FIRST(head2);			\
	(head1)->vstqh_last = (head2)->vstqh_last;			\
	VSTAILQ_FIRST(head2) = swap_first;				\
	(head2)->vstqh_last = swap_last;					\
	if (VSTAILQ_EMPTY(head1))					\
		(head1)->vstqh_last = &VSTAILQ_FIRST(head1);		\
	if (VSTAILQ_EMPTY(head2))					\
		(head2)->vstqh_last = &VSTAILQ_FIRST(head2);		\
} while (0)


/*
 * List declarations.
 */
#define	VLIST_HEAD(name, type)						\
struct name {								\
	struct type *vlh_first;	/* first element */			\
}

#define	VLIST_HEAD_INITIALIZER(head)					\
	{ NULL }

#define	VLIST_ENTRY(type)						\
struct {								\
	struct type *vle_next;	/* next element */			\
	struct type **vle_prev;	/* address of previous next element */	\
}

/*
 * List functions.
 */


#define	VLIST_EMPTY(head)	((head)->vlh_first == NULL)

#define	VLIST_FIRST(head)	((head)->vlh_first)

#define	VLIST_FOREACH(var, head, field)					\
	for ((var) = VLIST_FIRST((head));				\
	    (var);							\
	    (var) = VLIST_NEXT((var), field))

#define	VLIST_FOREACH_FROM(var, head, field)				\
	for ((var) = ((var) ? (var) : VLIST_FIRST((head)));		\
	    (var);							\
	    (var) = VLIST_NEXT((var), field))

#define	VLIST_FOREACH_SAFE(var, head, field, tvar)			\
	for ((var) = VLIST_FIRST((head));				\
	    (var) && ((tvar) = VLIST_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VLIST_FOREACH_FROM_SAFE(var, head, field, tvar)			\
	for ((var) = ((var) ? (var) : VLIST_FIRST((head)));		\
	    (var) && ((tvar) = VLIST_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VLIST_INIT(head) do {						\
	VLIST_FIRST((head)) = NULL;					\
} while (0)

#define	VLIST_INSERT_AFTER(listelm, elm, field) do {			\
	if ((VLIST_NEXT((elm), field) = VLIST_NEXT((listelm), field)) != NULL)\
		VLIST_NEXT((listelm), field)->field.vle_prev =		\
		    &VLIST_NEXT((elm), field);				\
	VLIST_NEXT((listelm), field) = (elm);				\
	(elm)->field.vle_prev = &VLIST_NEXT((listelm), field);		\
} while (0)

#define	VLIST_INSERT_BEFORE(listelm, elm, field) do {			\
	(elm)->field.vle_prev = (listelm)->field.vle_prev;		\
	VLIST_NEXT((elm), field) = (listelm);				\
	*(listelm)->field.vle_prev = (elm);				\
	(listelm)->field.vle_prev = &VLIST_NEXT((elm), field);		\
} while (0)

#define	VLIST_INSERT_HEAD(head, elm, field) do {			\
	if ((VLIST_NEXT((elm), field) = VLIST_FIRST((head))) != NULL)	\
		VLIST_FIRST((head))->field.vle_prev = &VLIST_NEXT((elm), field);\
	VLIST_FIRST((head)) = (elm);					\
	(elm)->field.vle_prev = &VLIST_FIRST((head));			\
} while (0)

#define	VLIST_NEXT(elm, field)	((elm)->field.vle_next)

#define	VLIST_PREV(elm, head, type, field)				\
	((elm)->field.vle_prev == &VLIST_FIRST((head)) ? NULL :		\
	    __containerof((elm)->field.vle_prev, struct type, field.vle_next))

#define	VLIST_REMOVE(elm, field) do {					\
	if (VLIST_NEXT((elm), field) != NULL)				\
		VLIST_NEXT((elm), field)->field.vle_prev =		\
		    (elm)->field.vle_prev;				\
	*(elm)->field.vle_prev = VLIST_NEXT((elm), field);		\
	TRASHIT(*oldnext);						\
	TRASHIT(*oldprev);						\
} while (0)

#define VLIST_SWAP(head1, head2, type, field) do {			\
	struct type *swap_tmp = VLIST_FIRST((head1));			\
	VLIST_FIRST((head1)) = VLIST_FIRST((head2));			\
	VLIST_FIRST((head2)) = swap_tmp;					\
	if ((swap_tmp = VLIST_FIRST((head1))) != NULL)			\
		swap_tmp->field.vle_prev = &VLIST_FIRST((head1));		\
	if ((swap_tmp = VLIST_FIRST((head2))) != NULL)			\
		swap_tmp->field.vle_prev = &VLIST_FIRST((head2));		\
} while (0)

/*
 * Tail queue declarations.
 */
#define	VTAILQ_HEAD(name, type)						\
struct name {								\
	struct type *vtqh_first;	/* first element */		\
	struct type **vtqh_last;	/* addr of last next element */	\
	TRACEBUF							\
}

#define	VTAILQ_HEAD_INITIALIZER(head)					\
	{ NULL, &(head).vtqh_first, TRACEBUF_INITIALIZER }

#define	VTAILQ_ENTRY(type)						\
struct {								\
	struct type *vtqe_next;	/* next element */			\
	struct type **vtqe_prev;	/* address of previous next element */\
	TRACEBUF							\
} /*lint -e(18) */

/*
 * Tail queue functions.
 */

#define	VTAILQ_CONCAT(head1, head2, field) do {				\
	if (!VTAILQ_EMPTY(head2)) {					\
		*(head1)->vtqh_last = (head2)->vtqh_first;		\
		(head2)->vtqh_first->field.vtqe_prev = (head1)->vtqh_last;\
		(head1)->vtqh_last = (head2)->vtqh_last;		\
		VTAILQ_INIT((head2));					\
	}								\
} while (0)

#define	VTAILQ_EMPTY(head)	((head)->vtqh_first == NULL)

#define	VTAILQ_FIRST(head)	((head)->vtqh_first)

#define	VTAILQ_FOREACH(var, head, field)				\
	for ((var) = VTAILQ_FIRST((head));				\
	    (var);							\
	    (var) = VTAILQ_NEXT((var), field))

#define	VTAILQ_FOREACH_FROM(var, head, field)				\
	for ((var) = ((var) ? (var) : VTAILQ_FIRST((head)));		\
	    (var);							\
	    (var) = VTAILQ_NEXT((var), field))

#define	VTAILQ_FOREACH_SAFE(var, head, field, tvar)			\
	for ((var) = VTAILQ_FIRST((head));				\
	    (var) && ((tvar) = VTAILQ_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VTAILQ_FOREACH_FROM_SAFE(var, head, field, tvar)			\
	for ((var) = ((var) ? (var) : VTAILQ_FIRST((head)));		\
	    (var) && ((tvar) = VTAILQ_NEXT((var), field), 1);		\
	    (var) = (tvar))

#define	VTAILQ_FOREACH_REVERSE(var, head, headname, field)		\
	for ((var) = VTAILQ_LAST((head), headname);			\
	    (var);							\
	    (var) = VTAILQ_PREV((var), headname, field))

#define	VTAILQ_FOREACH_REVERSE_FROM(var, head, headname, field)		\
	for ((var) = ((var) ? (var) : VTAILQ_LAST((head), headname));	\
	    (var);							\
	    (var) = VTAILQ_PREV((var), headname, field))

#define	VTAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar)	\
	for ((var) = VTAILQ_LAST((head), headname);			\
	    (var) && ((tvar) = VTAILQ_PREV((var), headname, field), 1);	\
	    (var) = (tvar))

#define	VTAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \
	for ((var) = ((var) ? (var) : VTAILQ_LAST((head), headname));	\
	    (var) && ((tvar) = VTAILQ_PREV((var), headname, field), 1);	\
	    (var) = (tvar))

#define	VTAILQ_INIT(head) do {						\
	VTAILQ_FIRST((head)) = NULL;					\
	(head)->vtqh_last = &VTAILQ_FIRST((head));			\
} while (0)

#define	VTAILQ_INSERT_AFTER(head, listelm, elm, field) do {		\
	if ((VTAILQ_NEXT((elm), field) = VTAILQ_NEXT((listelm), field)) != NULL)\
		VTAILQ_NEXT((elm), field)->field.vtqe_prev =		\
		    &VTAILQ_NEXT((elm), field);				\
	else {								\
		(head)->vtqh_last = &VTAILQ_NEXT((elm), field);		\
	}								\
	VTAILQ_NEXT((listelm), field) = (elm);				\
	(elm)->field.vtqe_prev = &VTAILQ_NEXT((listelm), field);	\
} while (0)

#define	VTAILQ_INSERT_BEFORE(listelm, elm, field) do {			\
	(elm)->field.vtqe_prev = (listelm)->field.vtqe_prev;		\
	VTAILQ_NEXT((elm), field) = (listelm);				\
	*(listelm)->field.vtqe_prev = (elm);				\
	(listelm)->field.vtqe_prev = &VTAILQ_NEXT((elm), field);	\
} while (0)

#define	VTAILQ_INSERT_HEAD(head, elm, field) do {			\
	if ((VTAILQ_NEXT((elm), field) = VTAILQ_FIRST((head))) != NULL)	\
		VTAILQ_FIRST((head))->field.vtqe_prev =			\
		    &VTAILQ_NEXT((elm), field);				\
	else								\
		(head)->vtqh_last = &VTAILQ_NEXT((elm), field);		\
	VTAILQ_FIRST((head)) = (elm);					\
	(elm)->field.vtqe_prev = &VTAILQ_FIRST((head));			\
} while (0)

#define	VTAILQ_INSERT_TAIL(head, elm, field) do {			\
	VTAILQ_NEXT((elm), field) = NULL;				\
	(elm)->field.vtqe_prev = (head)->vtqh_last;			\
	*(head)->vtqh_last = (elm);					\
	(head)->vtqh_last = &VTAILQ_NEXT((elm), field);			\
} while (0)

#define	VTAILQ_LAST(head, headname)					\
	(*(((struct headname *)((head)->vtqh_last))->vtqh_last))

#define	VTAILQ_NEXT(elm, field) ((elm)->field.vtqe_next)

#define	VTAILQ_PREV(elm, headname, field)				\
	(*(((struct headname *)((elm)->field.vtqe_prev))->vtqh_last))

#define	VTAILQ_REMOVE(head, elm, field) do {				\
	if ((VTAILQ_NEXT((elm), field)) != NULL)			\
		VTAILQ_NEXT((elm), field)->field.vtqe_prev =		\
		    (elm)->field.vtqe_prev;				\
	else {								\
		(head)->vtqh_last = (elm)->field.vtqe_prev;		\
	}								\
	*(elm)->field.vtqe_prev = VTAILQ_NEXT((elm), field);		\
	TRASHIT(*oldnext);						\
	TRASHIT(*oldprev);						\
} while (0)

#define VTAILQ_SWAP(head1, head2, type, field) do {			\
	struct type *swap_first = (head1)->vtqh_first;			\
	struct type **swap_last = (head1)->vtqh_last;			\
	(head1)->vtqh_first = (head2)->vtqh_first;			\
	(head1)->vtqh_last = (head2)->vtqh_last;				\
	(head2)->vtqh_first = swap_first;				\
	(head2)->vtqh_last = swap_last;					\
	if ((swap_first = (head1)->vtqh_first) != NULL)			\
		swap_first->field.vtqe_prev = &(head1)->vtqh_first;	\
	else								\
		(head1)->vtqh_last = &(head1)->vtqh_first;		\
	if ((swap_first = (head2)->vtqh_first) != NULL)			\
		swap_first->field.vtqe_prev = &(head2)->vtqh_first;	\
	else								\
		(head2)->vtqh_last = &(head2)->vtqh_first;		\
} while (0)

#endif /* !VARNISH_QUEUE_H */