- prev = NULL;
- n = m->m_pkthdr.aux;
- while (n) {
- t = (struct mauxtag *)n->m_dat;
- next = n->m_next;
- if (n == victim) {
- if (prev)
- prev->m_next = n->m_next;
- else
- m->m_pkthdr.aux = n->m_next;
- n->m_next = NULL;
- m_free(n);
- } else
- prev = n;
- n = next;
+/*
+ * 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(struct mbuf *to, struct mbuf *from, int how)
+{
+ struct m_tag *p, *t, *tprev = NULL;
+
+ KASSERT(to && from,
+ ("m_tag_copy: null argument, to %p from %p", to, from));
+ m_tag_delete_chain(to, NULL);
+ SLIST_FOREACH(p, &from->m_pkthdr.tags, m_tag_link) {
+ t = m_tag_copy(p, how);
+ if (t == NULL) {
+ m_tag_delete_chain(to, NULL);
+ return 0;
+ }
+ if (tprev == NULL)
+ SLIST_INSERT_HEAD(&to->m_pkthdr.tags, t, m_tag_link);
+ else {
+ SLIST_INSERT_AFTER(tprev, t, m_tag_link);
+ tprev = t;
+ }