1 /*- 2 * Copyright (c) 2006 Verdens Gang AS 3 * Copyright (c) 2006-2015 Varnish Software AS 4 * All rights reserved. 5 * 6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk> 7 * Author: Martin Blix Grydeland <martin@varnish-software.com> 8 * 9 * SPDX-License-Identifier: BSD-2-Clause 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * Define the layout of the shared memory log segment. 33 * 34 * This file SHALL only be included from: 35 * bin/varnishd/cache/cache.h 36 * include/vsl_priv.h 37 * include/vapi/vsl.h 38 * 39 */ 40 41 #ifndef VAPI_VSL_INT_H_INCLUDED 42 #define VAPI_VSL_INT_H_INCLUDED 43 44 #define VSL_CLASS "Log" 45 #define VSL_SEGMENTS 8U 46 47 /* 48 * Shared memory log format 49 * 50 * The log member points to an array of 32bit unsigned integers containing 51 * log records. 52 * 53 * Each logrecord consist of: 54 * [n] = ((type & 0xff) << 24) | (length & 0xffff) 55 * [n + 1] = ((marker & 0x03) << 30) | (identifier & 0x3fffffff) 56 * [n + 2] ... [m] = content (NUL-terminated) 57 * 58 * Logrecords are NUL-terminated so that string functions can be run 59 * directly on the shmlog data. 60 * 61 * Notice that the constants in these macros cannot be changed without 62 * changing corresponding magic numbers in varnishd/cache/cache_shmlog.c 63 */ 64 65 #define VSL_CLIENTMARKER (1U<<30) 66 #define VSL_BACKENDMARKER (1U<<31) 67 #define VSL_IDENTMASK (~(3U<<30)) 68 69 #define VSL_LENMASK 0xffff 70 #define VSL_WORDS(len) (((len) + 3) / 4) 71 #define VSL_BYTES(words) ((words) * 4) 72 #define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) 73 #define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) 74 #define VSL_LEN(ptr) ((ptr)[0] & VSL_LENMASK) 75 #define VSL_TAG(ptr) ((enum VSL_tag_e)((ptr)[0] >> 24)) 76 #define VSL_ID(ptr) (((ptr)[1]) & VSL_IDENTMASK) 77 #define VSL_CLIENT(ptr) (((ptr)[1]) & VSL_CLIENTMARKER) 78 #define VSL_BACKEND(ptr) (((ptr)[1]) & VSL_BACKENDMARKER) 79 #define VSL_DATA(ptr) ((char*)((ptr)+2)) 80 #define VSL_CDATA(ptr) ((const char*)((ptr)+2)) 81 #define VSL_BATCHLEN(ptr) ((ptr)[1]) 82 #define VSL_BATCHID(ptr) (VSL_ID((ptr) + 2)) 83 84 #define VSL_ENDMARKER (((uint32_t)SLT__Reserved << 24) | 0x454545) /* "EEE" */ 85 #define VSL_WRAPMARKER (((uint32_t)SLT__Reserved << 24) | 0x575757) /* "WWW" */ 86 87 /* 88 * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run 89 * on this file to extract the table rather than handcode it 90 */ 91 #define SLT__MAX 256 92 enum VSL_tag_e { 93 SLT__Bogus = 0, 94 #define SLTM(foo,flags,sdesc,ldesc) SLT_##foo, 95 #include "tbl/vsl_tags.h" 96 SLT__Reserved = 254, 97 SLT__Batch = 255 98 }; 99 100 /* VSL tag flags */ 101 #define SLT_F_UNUSED (1 << 0) 102 #define SLT_F_UNSAFE (1 << 1) 103 #define SLT_F_BINARY (1 << 2) 104 105 #endif /* VAPI_VSL_INT_H_INCLUDED */ 106