summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/rde_attr.c
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2009-03-19 06:53:00 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2009-03-19 06:53:00 +0000
commit7ce2d296a96fe58889baaa6681aa25aa393cc95d (patch)
tree56650dd95fd51937e1f978ffdd3253f46f93f701 /usr.sbin/bgpd/rde_attr.c
parent1e556e2cedf7bec67ef80f0ce0def52fc6e088e4 (diff)
Implement a attr_writebuf() function that works on a struct buf instead of
a pre allocated piece of memory. Will be used by newer mrt code. OK henning@
Diffstat (limited to 'usr.sbin/bgpd/rde_attr.c')
-rw-r--r--usr.sbin/bgpd/rde_attr.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/usr.sbin/bgpd/rde_attr.c b/usr.sbin/bgpd/rde_attr.c
index 19bbce3126f..7b4591f179f 100644
--- a/usr.sbin/bgpd/rde_attr.c
+++ b/usr.sbin/bgpd/rde_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_attr.c,v 1.78 2009/02/17 14:10:48 claudio Exp $ */
+/* $OpenBSD: rde_attr.c,v 1.79 2009/03/19 06:52:59 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
@@ -62,6 +62,31 @@ attr_write(void *p, u_int16_t p_len, u_int8_t flags, u_int8_t type,
return (tot_len);
}
+int
+attr_writebuf(struct buf *buf, u_int8_t flags, u_int8_t type, void *data,
+ u_int16_t data_len)
+{
+ u_char hdr[4];
+
+ if (data_len > 255) {
+ flags |= ATTR_EXTLEN;
+ hdr[2] = (data_len >> 8) & 0xff;
+ hdr[3] = data_len & 0xff;
+ } else {
+ flags &= ~ATTR_EXTLEN;
+ hdr[2] = data_len & 0xff;
+ }
+
+ hdr[0] = flags;
+ hdr[1] = type;
+
+ if (buf_add(buf, hdr, flags & ATTR_EXTLEN ? 4 : 3) == -1)
+ return (-1);
+ if (buf_add(buf, data, data_len) == -1)
+ return (-1);
+ return (0);
+}
+
/* optional attribute specific functions */
int attr_diff(struct attr *, struct attr *);
struct attr *attr_alloc(u_int8_t, u_int8_t, const void *, u_int16_t);