summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-05-20 08:31:48 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-05-20 08:31:48 +0000
commit70509555ff349187383b7eeb94da9ea4964063a0 (patch)
tree5c772d1b39e13972fcce2627db614540a425bc34
parent7fb605ac553c4526ae018da13c290b9864c5eadb (diff)
m_tag_* routines, plus minor changes (convert from tdbi to tags)
-rw-r--r--sys/kern/uipc_mbuf.c8
-rw-r--r--sys/kern/uipc_mbuf2.c160
2 files changed, 154 insertions, 14 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index c7d6cc12329..253234d30d9 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.30 2001/05/18 23:29:33 millert Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.31 2001/05/20 08:31:46 angelos Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -292,7 +292,7 @@ m_prepend(m, len, how)
if (m->m_flags & M_PKTHDR) {
M_COPY_PKTHDR(mn, m);
m->m_flags &= ~M_PKTHDR;
- m->m_pkthdr.tdbi = NULL;
+ TAILQ_INIT(&m->m_pkthdr.tags);
}
mn->m_next = m;
m = mn;
@@ -597,7 +597,7 @@ m_pullup(n, len)
if (n->m_flags & M_PKTHDR) {
M_COPY_PKTHDR(m, n);
n->m_flags &= ~M_PKTHDR;
- n->m_pkthdr.tdbi = NULL;
+ TAILQ_INIT(&n->m_pkthdr.tags);
}
}
space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
@@ -668,7 +668,7 @@ m_pullup2(n, len)
m->m_pkthdr = n->m_pkthdr;
m->m_flags = (n->m_flags & M_COPYFLAGS) | M_EXT;
n->m_flags &= ~M_PKTHDR;
- n->m_pkthdr.tdbi = NULL;
+ TAILQ_INIT(&n->m_pkthdr.tags);
/* n->m_data is cool. */
}
}
diff --git a/sys/kern/uipc_mbuf2.c b/sys/kern/uipc_mbuf2.c
index 3b335c320ef..5e2df6d9713 100644
--- a/sys/kern/uipc_mbuf2.c
+++ b/sys/kern/uipc_mbuf2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf2.c,v 1.7 2001/05/17 18:41:45 provos Exp $ */
+/* $OpenBSD: uipc_mbuf2.c,v 1.8 2001/05/20 08:31:47 angelos Exp $ */
/* $KAME: uipc_mbuf2.c,v 1.29 2001/02/14 13:42:10 itojun Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.40 1999/04/01 00:23:25 thorpej Exp $ */
@@ -104,7 +104,7 @@ m_pulldown(m, off, len, offp)
panic("m == NULL in m_pulldown()");
if (len > MCLBYTES) {
m_freem(m);
- return NULL; /* impossible */
+ return (NULL); /* impossible */
}
n = m;
@@ -119,7 +119,7 @@ m_pulldown(m, off, len, offp)
n = n->m_next;
if (!n) {
m_freem(m);
- return NULL; /* mbuf chain too short */
+ return (NULL); /* mbuf chain too short */
}
sharedcluster = M_SHAREDCLUSTER(n);
@@ -141,7 +141,7 @@ m_pulldown(m, off, len, offp)
o = m_dup1(n, off, n->m_len - off, M_DONTWAIT);
if (o == NULL) {
m_freem(m);
- return NULL; /* ENOBUFS */
+ return (NULL); /* ENOBUFS */
}
n->m_len = off;
o->m_next = n->m_next;
@@ -168,7 +168,7 @@ m_pulldown(m, off, len, offp)
olen += o->m_len;
if (hlen + olen < len) {
m_freem(m);
- return NULL; /* mbuf chain too short */
+ return (NULL); /* mbuf chain too short */
}
/*
@@ -207,7 +207,7 @@ m_pulldown(m, off, len, offp)
}
if (!o) {
m_freem(m);
- return NULL; /* ENOBUFS */
+ return (NULL); /* ENOBUFS */
}
/* get hlen from <n, off> into <o, 0> */
o->m_len = hlen;
@@ -225,7 +225,7 @@ m_pulldown(m, off, len, offp)
ok:
if (offp)
*offp = off;
- return n;
+ return (n);
}
static struct mbuf *
@@ -240,7 +240,7 @@ m_dup1(m, off, len, wait)
int copyhdr;
if (len > MCLBYTES)
- return NULL;
+ return (NULL);
if (off == 0 && (m->m_flags & M_PKTHDR) != 0) {
copyhdr = 1;
MGETHDR(n, wait, m->m_type);
@@ -258,10 +258,150 @@ m_dup1(m, off, len, wait)
}
}
if (!n)
- return NULL;
+ return (NULL);
if (copyhdr)
M_DUP_PKTHDR(n, m);
m_copydata(m, off, len, mtod(n, caddr_t));
- return n;
+ return (n);
+}
+
+/* Get a packet tag structure along with specified data following. */
+struct m_tag *
+m_tag_get(type, len, wait)
+ int type;
+ int len;
+ int wait;
+{
+ struct m_tag *t;
+
+ if (len < 0)
+ return (NULL);
+ MALLOC(t, struct m_tag *, len + sizeof(struct m_tag), M_PACKET_TAGS,
+ wait);
+ if (t == NULL)
+ return (NULL);
+ t->m_tag_id = type;
+ t->m_tag_len = len;
+ return (t);
+}
+
+/* Free a packet tag. */
+void
+m_tag_free(t)
+ struct m_tag *t;
+{
+ FREE(t, M_PACKET_TAGS);
+}
+
+/* Prepend a packet tag. */
+void
+m_tag_prepend(m, t)
+ struct mbuf *m;
+ struct m_tag *t;
+{
+ TAILQ_INSERT_HEAD(&m->m_pkthdr.tags, t, m_tag_link);
+}
+
+/* Append a packet tag. */
+void
+m_tag_append(m, t)
+ struct mbuf *m;
+ struct m_tag *t;
+{
+ TAILQ_INSERT_TAIL(&m->m_pkthdr.tags, t, m_tag_link);
+}
+
+/* Unlink a packet tag. */
+void
+m_tag_unlink(m, t)
+ struct mbuf *m;
+ struct m_tag *t;
+{
+ TAILQ_REMOVE(&m->m_pkthdr.tags, t, m_tag_link);
+}
+
+/* Unlink and free a packet tag. */
+void
+m_tag_delete(m, t)
+ struct mbuf *m;
+ struct m_tag *t;
+{
+ m_tag_unlink(m, t);
+ m_tag_free(t);
+}
+
+/* Unlink and free a packet tag chain, starting from given tag. */
+void
+m_tag_delete_chain(m, t)
+ struct mbuf *m;
+ struct m_tag *t;
+{
+ struct m_tag *p;
+
+ while ((p = TAILQ_LAST(&m->m_pkthdr.tags, packet_tags)) != NULL) {
+ m_tag_delete(m, p);
+ if (t != NULL && p == t)
+ return;
+ }
+}
+
+/* Find a tag, starting from a given position. */
+struct m_tag *
+m_tag_find(m, type, t)
+ struct mbuf *m;
+ int type;
+ struct m_tag *t;
+{
+ struct m_tag *p;
+
+ if (t == NULL)
+ p = TAILQ_FIRST(&m->m_pkthdr.tags);
+ else
+ p = TAILQ_NEXT(t, m_tag_link);
+ while (p != NULL) {
+ if (p->m_tag_id == type)
+ return (p);
+ p = TAILQ_NEXT(p, m_tag_link);
+ }
+ return (NULL);
+}
+
+/* Copy a single tag. */
+struct m_tag *
+m_tag_copy(t)
+ struct m_tag *t;
+{
+ struct m_tag *p;
+
+ p = m_tag_get(t->m_tag_id, t->m_tag_len, M_NOWAIT);
+ if (p == NULL)
+ return (NULL);
+ bcopy(t + 1, p + 1, t->m_tag_len); /* Copy the data */
+ return (p);
+}
+
+/*
+ * Copy two tag chains. The destination mbuf (to) loses any attached
+ * tags even if the operation fails. This should not be a problem, as
+ * m_tag_copy_chain() is typically called with a newly-allocated
+ * destination mbuf.
+ */
+int
+m_tag_copy_chain(to, from)
+ struct mbuf *to;
+ struct mbuf *from;
+{
+ struct m_tag *p, *t;
+
+ m_tag_delete_chain(to, NULL);
+ TAILQ_FOREACH(p, &from->m_pkthdr.tags, m_tag_link) {
+ t = m_tag_copy(p);
+ if (t == NULL) {
+ m_tag_delete_chain(to, NULL);
+ return (0);
+ }
+ m_tag_append(to, t);
+ }
+ return (1);
}