]> git.proxmox.com Git - mirror_frr.git/blame - lib/imsg.h
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / imsg.h
CommitLineData
8429abe0
RW
1/* $OpenBSD$ */
2
3/*
4 * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
5 * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
6 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20
21#ifndef _IMSG_H_
22#define _IMSG_H_
23
24#define IBUF_READ_SIZE 65535
25#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
26#define MAX_IMSGSIZE 16384
27
28struct ibuf {
996c9314 29 TAILQ_ENTRY(ibuf) entry;
d7c0a89a 30 uint8_t *buf;
996c9314
LB
31 size_t size;
32 size_t max;
33 size_t wpos;
34 size_t rpos;
35 int fd;
8429abe0
RW
36};
37
38struct msgbuf {
996c9314 39 TAILQ_HEAD(, ibuf) bufs;
d7c0a89a 40 uint32_t queued;
996c9314 41 int fd;
8429abe0
RW
42};
43
44struct ibuf_read {
d7c0a89a
QY
45 uint8_t buf[IBUF_READ_SIZE];
46 uint8_t *rptr;
996c9314 47 size_t wpos;
8429abe0
RW
48};
49
50struct imsg_fd {
996c9314
LB
51 TAILQ_ENTRY(imsg_fd) entry;
52 int fd;
8429abe0
RW
53};
54
55struct imsgbuf {
996c9314
LB
56 TAILQ_HEAD(, imsg_fd) fds;
57 struct ibuf_read r;
58 struct msgbuf w;
59 int fd;
60 pid_t pid;
8429abe0
RW
61};
62
63#define IMSGF_HASFD 1
64
65struct imsg_hdr {
d7c0a89a
QY
66 uint32_t type;
67 uint16_t len;
68 uint16_t flags;
69 uint32_t peerid;
70 uint32_t pid;
8429abe0
RW
71};
72
73struct imsg {
996c9314
LB
74 struct imsg_hdr hdr;
75 int fd;
76 void *data;
8429abe0
RW
77};
78
79
80/* buffer.c */
996c9314
LB
81struct ibuf *ibuf_open(size_t);
82struct ibuf *ibuf_dynamic(size_t, size_t);
83int ibuf_add(struct ibuf *, const void *, size_t);
84void *ibuf_reserve(struct ibuf *, size_t);
85void *ibuf_seek(struct ibuf *, size_t, size_t);
86size_t ibuf_size(struct ibuf *);
87size_t ibuf_left(struct ibuf *);
88void ibuf_close(struct msgbuf *, struct ibuf *);
89int ibuf_write(struct msgbuf *);
90void ibuf_free(struct ibuf *);
91void msgbuf_init(struct msgbuf *);
92void msgbuf_clear(struct msgbuf *);
93int msgbuf_write(struct msgbuf *);
94void msgbuf_drain(struct msgbuf *, size_t);
8429abe0
RW
95
96/* imsg.c */
996c9314
LB
97void imsg_init(struct imsgbuf *, int);
98ssize_t imsg_read(struct imsgbuf *);
99ssize_t imsg_get(struct imsgbuf *, struct imsg *);
d7c0a89a
QY
100int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const void *,
101 uint16_t);
102int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
996c9314 103 const struct iovec *, int);
d7c0a89a
QY
104struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t);
105int imsg_add(struct ibuf *, const void *, uint16_t);
996c9314
LB
106void imsg_close(struct imsgbuf *, struct ibuf *);
107void imsg_free(struct imsg *);
108int imsg_flush(struct imsgbuf *);
109void imsg_clear(struct imsgbuf *);
8429abe0
RW
110
111#endif