summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hash.c25
-rw-r--r--lib/hash.h6
-rw-r--r--lib/memtypes.c4
-rw-r--r--lib/plist.c2
-rw-r--r--lib/sockunion.c2
-rw-r--r--lib/sockunion.h2
-rw-r--r--lib/stream.c47
-rw-r--r--lib/stream.h3
8 files changed, 88 insertions, 3 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 56e41fa826..4d3da66d79 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -225,6 +225,31 @@ hash_iterate (struct hash *hash,
}
}
+/* Iterator function for hash. */
+void
+hash_walk (struct hash *hash,
+ int (*func) (struct hash_backet *, void *), void *arg)
+{
+ unsigned int i;
+ struct hash_backet *hb;
+ struct hash_backet *hbnext;
+ int ret = HASHWALK_CONTINUE;
+
+ for (i = 0; i < hash->size; i++)
+ {
+ for (hb = hash->index[i]; hb; hb = hbnext)
+ {
+ /* get pointer to next hash backet here, in case (*func)
+ * decides to delete hb by calling hash_release
+ */
+ hbnext = hb->next;
+ ret = (*func) (hb, arg);
+ if (ret == HASHWALK_ABORT)
+ return;
+ }
+ }
+}
+
/* Clean up hash. */
void
hash_clean (struct hash *hash, void (*free_func) (void *))
diff --git a/lib/hash.h b/lib/hash.h
index 920c6685fb..9707dbd1bf 100644
--- a/lib/hash.h
+++ b/lib/hash.h
@@ -25,6 +25,9 @@ Boston, MA 02111-1307, USA. */
#define HASH_INITIAL_SIZE 256 /* initial number of backets. */
#define HASH_THRESHOLD 10 /* expand when backet. */
+#define HASHWALK_CONTINUE 0
+#define HASHWALK_ABORT -1
+
struct hash_backet
{
/* Linked list. */
@@ -71,6 +74,9 @@ extern void *hash_release (struct hash *, void *);
extern void hash_iterate (struct hash *,
void (*) (struct hash_backet *, void *), void *);
+extern void hash_walk (struct hash *,
+ int (*) (struct hash_backet *, void *), void *);
+
extern void hash_clean (struct hash *, void (*) (void *));
extern void hash_free (struct hash *);
diff --git a/lib/memtypes.c b/lib/memtypes.c
index ca3a4a4f76..c32c08817f 100644
--- a/lib/memtypes.c
+++ b/lib/memtypes.c
@@ -99,6 +99,10 @@ struct memory_list memory_list_bgp[] =
{ MTYPE_PEER_GROUP, "Peer group" },
{ MTYPE_PEER_DESC, "Peer description" },
{ MTYPE_PEER_PASSWORD, "Peer password string" },
+ { MTYPE_BGP_PEER_AF, "BGP peer af" },
+ { MTYPE_BGP_UPDGRP, "BGP update group" },
+ { MTYPE_BGP_UPD_SUBGRP, "BGP update subgroup" },
+ { MTYPE_BGP_PACKET, "BGP packet" },
{ MTYPE_ATTR, "BGP attribute" },
{ MTYPE_ATTR_EXTRA, "BGP extra attributes" },
{ MTYPE_AS_PATH, "BGP aspath" },
diff --git a/lib/plist.c b/lib/plist.c
index f5950c331f..10012f3dc4 100644
--- a/lib/plist.c
+++ b/lib/plist.c
@@ -329,7 +329,7 @@ prefix_list_delete (struct prefix_list *plist)
route_map_notify_dependencies(plist->name, RMAP_EVENT_PLIST_DELETED);
if (master->delete_hook)
- (*master->delete_hook) (NULL);
+ (*master->delete_hook) (plist);
if (plist->name)
XFREE (MTYPE_PREFIX_LIST_STR, plist->name);
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 5dcf72563a..3cbb59cc60 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -552,7 +552,7 @@ sockopt_v6only (int family, int sock)
/* If same family and same prefix return 1. */
int
-sockunion_same (union sockunion *su1, union sockunion *su2)
+sockunion_same (const union sockunion *su1, const union sockunion *su2)
{
int ret = 0;
diff --git a/lib/sockunion.h b/lib/sockunion.h
index b9f3514246..8f0a9be37c 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -86,7 +86,7 @@ enum connect_result
extern int str2sockunion (const char *, union sockunion *);
extern const char *sockunion2str (union sockunion *, char *, size_t);
extern int sockunion_cmp (union sockunion *, union sockunion *);
-extern int sockunion_same (union sockunion *, union sockunion *);
+extern int sockunion_same (const union sockunion *, const union sockunion *);
extern union sockunion *sockunion_str2su (const char *str);
extern int sockunion_accept (int sock, union sockunion *);
diff --git a/lib/stream.c b/lib/stream.c
index 0fc3c3b118..cc5898a6db 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -401,6 +401,21 @@ stream_getl_from (struct stream *s, size_t from)
return l;
}
+/* Copy from stream at specific location to destination. */
+void
+stream_get_from (void *dst, struct stream *s, size_t from, size_t size)
+{
+ STREAM_VERIFY_SANE(s);
+
+ if (!GETP_VALID (s, from + size))
+ {
+ STREAM_BOUND_WARN (s, "get from");
+ return;
+ }
+
+ memcpy (dst, s->data + from, size);
+}
+
u_int32_t
stream_getl (struct stream *s)
{
@@ -709,6 +724,38 @@ stream_put_in_addr (struct stream *s, struct in_addr *addr)
return sizeof (u_int32_t);
}
+/* Put in_addr at location in the stream. */
+int
+stream_put_in_addr_at (struct stream *s, size_t putp, struct in_addr *addr)
+{
+ STREAM_VERIFY_SANE(s);
+
+ if (!PUT_AT_VALID (s, putp + 4))
+ {
+ STREAM_BOUND_WARN (s, "put");
+ return 0;
+ }
+
+ memcpy (&s->data[putp], addr, 4);
+ return 4;
+}
+
+/* Put in6_addr at location in the stream. */
+int
+stream_put_in6_addr_at (struct stream *s, size_t putp, struct in6_addr *addr)
+{
+ STREAM_VERIFY_SANE(s);
+
+ if (!PUT_AT_VALID (s, putp + 16))
+ {
+ STREAM_BOUND_WARN (s, "put");
+ return 0;
+ }
+
+ memcpy (&s->data[putp], addr, 16);
+ return 16;
+}
+
/* Put prefix by nlri type format. */
int
stream_put_prefix (struct stream *s, struct prefix *p)
diff --git a/lib/stream.h b/lib/stream.h
index f0c742c052..3efabe358d 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -173,9 +173,12 @@ extern int stream_putq (struct stream *, uint64_t);
extern int stream_putq_at (struct stream *, size_t, uint64_t);
extern int stream_put_ipv4 (struct stream *, u_int32_t);
extern int stream_put_in_addr (struct stream *, struct in_addr *);
+extern int stream_put_in_addr_at (struct stream *, size_t, struct in_addr *);
+extern int stream_put_in6_addr_at (struct stream *, size_t, struct in6_addr *);
extern int stream_put_prefix (struct stream *, struct prefix *);
extern void stream_get (void *, struct stream *, size_t);
+extern void stream_get_from (void *, struct stream *, size_t, size_t);
extern u_char stream_getc (struct stream *);
extern u_char stream_getc_from (struct stream *, size_t);
extern u_int16_t stream_getw (struct stream *);