paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
paul | 02ff83c | 2004-06-11 11:27:03 +0000 | [diff] [blame] | 26 | #include "prefix.h" |
| 27 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 28 | /* Stream buffer. */ |
| 29 | struct stream |
| 30 | { |
| 31 | struct stream *next; |
| 32 | |
| 33 | unsigned char *data; |
| 34 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 35 | /* Get pointer. */ |
| 36 | unsigned long getp; |
| 37 | |
| 38 | /* End of pointer. */ |
| 39 | unsigned long endp; |
| 40 | |
| 41 | /* Data size. */ |
| 42 | unsigned long size; |
| 43 | }; |
| 44 | |
| 45 | /* First in first out queue structure. */ |
| 46 | struct stream_fifo |
| 47 | { |
| 48 | unsigned long count; |
| 49 | |
| 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) |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 57 | #define STREAM_REMAIN(S) ((S)->size - (S)->endp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 58 | #define STREAM_DATA(S) ((S)->data) |
| 59 | |
| 60 | /* Stream prototypes. */ |
| 61 | struct stream *stream_new (size_t); |
| 62 | void stream_free (struct stream *); |
| 63 | |
| 64 | unsigned long stream_get_getp (struct stream *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | unsigned long stream_get_endp (struct stream *); |
| 66 | unsigned long stream_get_size (struct stream *); |
| 67 | u_char *stream_get_data (struct stream *); |
| 68 | |
| 69 | void stream_set_getp (struct stream *, unsigned long); |
paul | 9985f83 | 2005-02-09 15:51:56 +0000 | [diff] [blame] | 70 | void stream_forward_getp (struct stream *, int); |
| 71 | void stream_forward_endp (struct stream *, int); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | |
| 73 | void stream_put (struct stream *, void *, size_t); |
| 74 | int stream_putc (struct stream *, u_char); |
| 75 | int stream_putc_at (struct stream *, unsigned long, u_char); |
| 76 | int stream_putw (struct stream *, u_int16_t); |
| 77 | int stream_putw_at (struct stream *, unsigned long, u_int16_t); |
| 78 | int stream_putl (struct stream *, u_int32_t); |
| 79 | int stream_putl_at (struct stream *, unsigned long, u_int32_t); |
| 80 | int stream_put_ipv4 (struct stream *, u_int32_t); |
| 81 | int stream_put_in_addr (struct stream *, struct in_addr *); |
paul | 02ff83c | 2004-06-11 11:27:03 +0000 | [diff] [blame] | 82 | int stream_put_prefix (struct stream *, struct prefix *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 83 | |
| 84 | void stream_get (void *, struct stream *, size_t); |
| 85 | u_char stream_getc (struct stream *); |
| 86 | u_char stream_getc_from (struct stream *, unsigned long); |
| 87 | u_int16_t stream_getw (struct stream *); |
| 88 | u_int16_t stream_getw_from (struct stream *, unsigned long); |
| 89 | u_int32_t stream_getl (struct stream *); |
| 90 | u_int32_t stream_get_ipv4 (struct stream *); |
| 91 | |
| 92 | #undef stream_read |
| 93 | #undef stream_write |
| 94 | int stream_read (struct stream *, int, size_t); |
| 95 | int stream_read_unblock (struct stream *, int, size_t); |
| 96 | int stream_write (struct stream *, u_char *, size_t); |
| 97 | |
| 98 | u_char *stream_pnt (struct stream *); |
| 99 | void stream_reset (struct stream *); |
| 100 | int stream_flush (struct stream *, int); |
| 101 | int stream_empty (struct stream *); |
| 102 | |
| 103 | /* Stream fifo. */ |
| 104 | struct stream_fifo *stream_fifo_new (); |
| 105 | void stream_fifo_push (struct stream_fifo *fifo, struct stream *s); |
| 106 | struct stream *stream_fifo_pop (struct stream_fifo *fifo); |
| 107 | struct stream *stream_fifo_head (struct stream_fifo *fifo); |
| 108 | void stream_fifo_clean (struct stream_fifo *fifo); |
| 109 | void stream_fifo_free (struct stream_fifo *fifo); |
| 110 | |
| 111 | #endif /* _ZEBRA_STREAM_H */ |