xref: /freebsd/sys/dev/tcp_log/tcp_log_dev.h (revision 4543ef516683042d46f3bd3bb8a4f3f746e00499)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2016 Netflix, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef __tcp_log_dev_h__
29 #define	__tcp_log_dev_h__
30 
31 /*
32  * This is the common header for data streamed from the log device. All
33  * blocks of data need to start with this header.
34  */
35 struct tcp_log_common_header {
36 	uint32_t	tlch_version;	/* Version is specific to type. */
37 	uint32_t	tlch_type;	/* Type of entry(ies) that follow. */
38 	uint64_t	tlch_length;	/* Total length, including header. */
39 } __packed;
40 
41 #define	TCP_LOG_DEV_TYPE_BBR	1	/* black box recorder */
42 
43 #ifdef _KERNEL
44 /*
45  * This is a queue entry. All queue entries need to start with this structure
46  * so the common code can cast them to this structure; however, other modules
47  * are free to include additional data after this structure.
48  *
49  * The elements are explained here:
50  * tldq_queue: used by the common code to maintain this entry's position in the
51  *     queue.
52  * tldq_buf: should be NULL, or a pointer to a chunk of data. The data must be
53  *     as long as the common header indicates.
54  * tldq_xform: If tldq_buf is NULL, the code will call this to create the
55  *     the tldq_buf object. The function should *not* directly modify tldq_buf,
56  *     but should return the buffer (which must meet the restrictions
57  *     indicated for tldq_buf).
58  * tldq_dtor: This function is called to free the queue entry. If tldq_buf is
59  *     not NULL, the dtor function must free that, too.
60  * tldq_refcnt: used by the common code to indicate how many readers still need
61  *     this data.
62  */
63 struct tcp_log_dev_queue {
64 	STAILQ_ENTRY(tcp_log_dev_queue) tldq_queue;
65 	struct tcp_log_common_header *tldq_buf;
66 	struct tcp_log_common_header *(*tldq_xform)(struct tcp_log_dev_queue *entry);
67 	void	(*tldq_dtor)(struct tcp_log_dev_queue *entry);
68 	volatile u_int tldq_refcnt;
69 };
70 
71 STAILQ_HEAD(log_queueh, tcp_log_dev_queue);
72 
73 struct tcp_log_dev_info {
74 	STAILQ_ENTRY(tcp_log_dev_info) tldi_list;
75 	struct tcp_log_dev_queue *tldi_head;
76 	struct tcp_log_common_header *tldi_cur;
77 	off_t			tldi_off;
78 };
79 STAILQ_HEAD(log_infoh, tcp_log_dev_info);
80 
81 #ifdef TCP_BLACKBOX
82 MALLOC_DECLARE(M_TCPLOGDEV);
83 int tcp_log_dev_add_log(struct tcp_log_dev_queue *entry);
84 #endif /* TCP_BLACKBOX */
85 #endif /* _KERNEL */
86 #endif /* !__tcp_log_dev_h__ */
87