blob: 2936f46b0156951a4699f5fc5f5a226258b1d057 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * Packet interface
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_STREAM_H
24#define _ZEBRA_STREAM_H
25
paul02ff83c2004-06-11 11:27:03 +000026#include "prefix.h"
27
paul718e3742002-12-13 20:15:29 +000028/* Stream buffer. */
29struct stream
30{
31 struct stream *next;
32
33 unsigned char *data;
34
paul718e3742002-12-13 20:15:29 +000035 /* Get pointer. */
paulf2e6c422005-02-12 14:35:49 +000036 size_t getp;
paul718e3742002-12-13 20:15:29 +000037
38 /* End of pointer. */
paulf2e6c422005-02-12 14:35:49 +000039 size_t endp;
paul718e3742002-12-13 20:15:29 +000040
41 /* Data size. */
paulf2e6c422005-02-12 14:35:49 +000042 size_t size;
paul718e3742002-12-13 20:15:29 +000043};
44
45/* First in first out queue structure. */
46struct stream_fifo
47{
paulf2e6c422005-02-12 14:35:49 +000048 size_t count;
paul718e3742002-12-13 20:15:29 +000049
50 struct stream *head;
51 struct stream *tail;
52};
53
54/* Utility macros. */
55#define STREAM_PNT(S) ((S)->data + (S)->getp)
56#define STREAM_SIZE(S) ((S)->size)
paul9985f832005-02-09 15:51:56 +000057#define STREAM_REMAIN(S) ((S)->size - (S)->endp)
paul718e3742002-12-13 20:15:29 +000058#define STREAM_DATA(S) ((S)->data)
59
60/* Stream prototypes. */
61struct stream *stream_new (size_t);
62void stream_free (struct stream *);
63
paulf2e6c422005-02-12 14:35:49 +000064size_t stream_get_getp (struct stream *);
65size_t stream_get_endp (struct stream *);
66size_t stream_get_size (struct stream *);
paul718e3742002-12-13 20:15:29 +000067u_char *stream_get_data (struct stream *);
68
paulf2e6c422005-02-12 14:35:49 +000069void stream_set_getp (struct stream *, size_t);
paul9985f832005-02-09 15:51:56 +000070void stream_forward_getp (struct stream *, int);
71void stream_forward_endp (struct stream *, int);
paul718e3742002-12-13 20:15:29 +000072
73void stream_put (struct stream *, void *, size_t);
74int stream_putc (struct stream *, u_char);
paulf2e6c422005-02-12 14:35:49 +000075int stream_putc_at (struct stream *, size_t, u_char);
paul718e3742002-12-13 20:15:29 +000076int stream_putw (struct stream *, u_int16_t);
paulf2e6c422005-02-12 14:35:49 +000077int stream_putw_at (struct stream *, size_t, u_int16_t);
paul718e3742002-12-13 20:15:29 +000078int stream_putl (struct stream *, u_int32_t);
paulf2e6c422005-02-12 14:35:49 +000079int stream_putl_at (struct stream *, size_t, u_int32_t);
paul718e3742002-12-13 20:15:29 +000080int stream_put_ipv4 (struct stream *, u_int32_t);
81int stream_put_in_addr (struct stream *, struct in_addr *);
paul02ff83c2004-06-11 11:27:03 +000082int stream_put_prefix (struct stream *, struct prefix *);
paul718e3742002-12-13 20:15:29 +000083
84void stream_get (void *, struct stream *, size_t);
85u_char stream_getc (struct stream *);
paulf2e6c422005-02-12 14:35:49 +000086u_char stream_getc_from (struct stream *, size_t);
paul718e3742002-12-13 20:15:29 +000087u_int16_t stream_getw (struct stream *);
paulf2e6c422005-02-12 14:35:49 +000088u_int16_t stream_getw_from (struct stream *, size_t);
paul718e3742002-12-13 20:15:29 +000089u_int32_t stream_getl (struct stream *);
90u_int32_t stream_get_ipv4 (struct stream *);
91
92#undef stream_read
93#undef stream_write
94int stream_read (struct stream *, int, size_t);
95int stream_read_unblock (struct stream *, int, size_t);
96int stream_write (struct stream *, u_char *, size_t);
97
98u_char *stream_pnt (struct stream *);
99void stream_reset (struct stream *);
100int stream_flush (struct stream *, int);
101int stream_empty (struct stream *);
102
103/* Stream fifo. */
104struct stream_fifo *stream_fifo_new ();
105void stream_fifo_push (struct stream_fifo *fifo, struct stream *s);
106struct stream *stream_fifo_pop (struct stream_fifo *fifo);
107struct stream *stream_fifo_head (struct stream_fifo *fifo);
108void stream_fifo_clean (struct stream_fifo *fifo);
109void stream_fifo_free (struct stream_fifo *fifo);
110
111#endif /* _ZEBRA_STREAM_H */