]> git.proxmox.com Git - mirror_frr.git/blob - lib/imsg.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / imsg.h
1 // SPDX-License-Identifier: ISC
2 /* $OpenBSD$ */
3
4 /*
5 * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
6 * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
7 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
8 */
9
10 #ifndef _IMSG_H_
11 #define _IMSG_H_
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #define IBUF_READ_SIZE 65535
18 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
19 #define MAX_IMSGSIZE 16384
20
21 struct ibuf {
22 TAILQ_ENTRY(ibuf) entry;
23 uint8_t *buf;
24 size_t size;
25 size_t max;
26 size_t wpos;
27 size_t rpos;
28 int fd;
29 };
30
31 struct msgbuf {
32 TAILQ_HEAD(, ibuf) bufs;
33 uint32_t queued;
34 int fd;
35 };
36
37 struct ibuf_read {
38 uint8_t buf[IBUF_READ_SIZE];
39 uint8_t *rptr;
40 size_t wpos;
41 };
42
43 struct imsg_fd {
44 TAILQ_ENTRY(imsg_fd) entry;
45 int fd;
46 };
47
48 struct imsgbuf {
49 TAILQ_HEAD(, imsg_fd) fds;
50 struct ibuf_read r;
51 struct msgbuf w;
52 int fd;
53 pid_t pid;
54 };
55
56 #define IMSGF_HASFD 1
57
58 struct imsg_hdr {
59 uint32_t type;
60 uint16_t len;
61 uint16_t flags;
62 uint32_t peerid;
63 uint32_t pid;
64 };
65
66 struct imsg {
67 struct imsg_hdr hdr;
68 int fd;
69 void *data;
70 };
71
72
73 /* buffer.c */
74 struct ibuf *ibuf_open(size_t);
75 struct ibuf *ibuf_dynamic(size_t, size_t);
76 int ibuf_add(struct ibuf *, const void *, size_t);
77 void *ibuf_reserve(struct ibuf *, size_t);
78 void *ibuf_seek(struct ibuf *, size_t, size_t);
79 size_t ibuf_size(struct ibuf *);
80 size_t ibuf_left(struct ibuf *);
81 void ibuf_close(struct msgbuf *, struct ibuf *);
82 int ibuf_write(struct msgbuf *);
83 void ibuf_free(struct ibuf *);
84 void msgbuf_init(struct msgbuf *);
85 void msgbuf_clear(struct msgbuf *);
86 int msgbuf_write(struct msgbuf *);
87 void msgbuf_drain(struct msgbuf *, size_t);
88
89 /* imsg.c */
90 void imsg_init(struct imsgbuf *, int);
91 ssize_t imsg_read(struct imsgbuf *);
92 ssize_t imsg_get(struct imsgbuf *, struct imsg *);
93 int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const void *,
94 uint16_t);
95 int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
96 const struct iovec *, int);
97 struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t);
98 int imsg_add(struct ibuf *, const void *, uint16_t);
99 void imsg_close(struct imsgbuf *, struct ibuf *);
100 void imsg_free(struct imsg *);
101 int imsg_flush(struct imsgbuf *);
102 void imsg_clear(struct imsgbuf *);
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif