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