Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys - add m_add() that puts an mbuf to end of a chain
details: https://anonhg.NetBSD.org/src/rev/49741112470a
branches: trunk
changeset: 787648:49741112470a
user: christos <christos%NetBSD.org@localhost>
date: Thu Jun 27 17:47:18 2013 +0000
description:
- add m_add() that puts an mbuf to end of a chain
- m_append() and m_align() with their family
- remove parameters from prototypes
diffstat:
sys/kern/uipc_mbuf.c | 86 ++++++++++++++++++++++++++++++++++++++++-
sys/net80211/ieee80211_netbsd.c | 69 +-------------------------------
sys/net80211/ieee80211_netbsd.h | 4 +-
sys/sys/mbuf.h | 7 ++-
4 files changed, 92 insertions(+), 74 deletions(-)
diffs (238 lines):
diff -r 8aecd7dc43b7 -r 49741112470a sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Thu Jun 27 15:46:40 2013 +0000
+++ b/sys/kern/uipc_mbuf.c Thu Jun 27 17:47:18 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.149 2013/05/08 11:08:45 pooka Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.150 2013/06/27 17:47:18 christos Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.149 2013/05/08 11:08:45 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.150 2013/06/27 17:47:18 christos Exp $");
#include "opt_mbuftrace.h"
#include "opt_nmbclusters.h"
@@ -458,6 +458,88 @@
return (0);
}
+/*
+ * Add mbuf to the end of a chain
+ */
+struct mbuf *
+m_add(struct mbuf *c, struct mbuf *m) {
+ struct mbuf *n;
+
+ if (c == NULL)
+ return m;
+
+ for (n = c; n->m_next != NULL; n = n->m_next)
+ continue;
+ n->m_next = m;
+ return c;
+}
+
+/*
+ * Set the m_data pointer of a newly-allocated mbuf
+ * to place an object of the specified size at the
+ * end of the mbuf, longword aligned.
+ */
+void
+m_align(struct mbuf *m, int len)
+{
+ int adjust;
+
+ if (m->m_flags & M_EXT)
+ adjust = m->m_ext.ext_size - len;
+ else if (m->m_flags & M_PKTHDR)
+ adjust = MHLEN - len;
+ else
+ adjust = MLEN - len;
+ m->m_data += adjust &~ (sizeof(long)-1);
+}
+
+/*
+ * Append the specified data to the indicated mbuf chain,
+ * Extend the mbuf chain if the new data does not fit in
+ * existing space.
+ *
+ * Return 1 if able to complete the job; otherwise 0.
+ */
+int
+m_append(struct mbuf *m0, int len, const void *cpv)
+{
+ struct mbuf *m, *n;
+ int remainder, space;
+ const char *cp = cpv;
+
+ for (m = m0; m->m_next != NULL; m = m->m_next)
+ continue;
+ remainder = len;
+ space = M_TRAILINGSPACE(m);
+ if (space > 0) {
+ /*
+ * Copy into available space.
+ */
+ if (space > remainder)
+ space = remainder;
+ memmove(mtod(m, char *) + m->m_len, cp, space);
+ m->m_len += space;
+ cp = cp + space, remainder -= space;
+ }
+ while (remainder > 0) {
+ /*
+ * Allocate a new mbuf; could check space
+ * and allocate a cluster instead.
+ */
+ n = m_get(M_DONTWAIT, m->m_type);
+ if (n == NULL)
+ break;
+ n->m_len = min(MLEN, remainder);
+ memmove(mtod(n, void *), cp, n->m_len);
+ cp += n->m_len, remainder -= n->m_len;
+ m->m_next = n;
+ m = n;
+ }
+ if (m0->m_flags & M_PKTHDR)
+ m0->m_pkthdr.len += len - remainder;
+ return (remainder == 0);
+}
+
void
m_reclaim(void *arg, int flags)
{
diff -r 8aecd7dc43b7 -r 49741112470a sys/net80211/ieee80211_netbsd.c
--- a/sys/net80211/ieee80211_netbsd.c Thu Jun 27 15:46:40 2013 +0000
+++ b/sys/net80211/ieee80211_netbsd.c Thu Jun 27 17:47:18 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.c,v 1.23 2013/02/04 15:44:45 christos Exp $ */
+/* $NetBSD: ieee80211_netbsd.c,v 1.24 2013/06/27 17:47:18 christos Exp $ */
/*-
* Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
* All rights reserved.
@@ -30,7 +30,7 @@
#ifdef __FreeBSD__
__FBSDID("$FreeBSD: src/sys/net80211/ieee80211_freebsd.c,v 1.8 2005/08/08 18:46:35 sam Exp $");
#else
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.23 2013/02/04 15:44:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_netbsd.c,v 1.24 2013/06/27 17:47:18 christos Exp $");
#endif
/*
@@ -535,71 +535,6 @@
return;
}
-/*
- * Set the m_data pointer of a newly-allocated mbuf
- * to place an object of the specified size at the
- * end of the mbuf, longword aligned.
- */
-void
-m_align(struct mbuf *m, int len)
-{
- int adjust;
-
- if (m->m_flags & M_EXT)
- adjust = m->m_ext.ext_size - len;
- else if (m->m_flags & M_PKTHDR)
- adjust = MHLEN - len;
- else
- adjust = MLEN - len;
- m->m_data += adjust &~ (sizeof(long)-1);
-}
-
-/*
- * Append the specified data to the indicated mbuf chain,
- * Extend the mbuf chain if the new data does not fit in
- * existing space.
- *
- * Return 1 if able to complete the job; otherwise 0.
- */
-int
-m_append(struct mbuf *m0, int len, const void *cpv)
-{
- struct mbuf *m, *n;
- int remainder, space;
- const char *cp = cpv;
-
- for (m = m0; m->m_next != NULL; m = m->m_next)
- continue;
- remainder = len;
- space = M_TRAILINGSPACE(m);
- if (space > 0) {
- /*
- * Copy into available space.
- */
- if (space > remainder)
- space = remainder;
- memmove(mtod(m, char *) + m->m_len, cp, space);
- m->m_len += space;
- cp = cp + space, remainder -= space;
- }
- while (remainder > 0) {
- /*
- * Allocate a new mbuf; could check space
- * and allocate a cluster instead.
- */
- n = m_get(M_DONTWAIT, m->m_type);
- if (n == NULL)
- break;
- n->m_len = min(MLEN, remainder);
- memmove(mtod(n, void *), cp, n->m_len);
- cp += n->m_len, remainder -= n->m_len;
- m->m_next = n;
- m = n;
- }
- if (m0->m_flags & M_PKTHDR)
- m0->m_pkthdr.len += len - remainder;
- return (remainder == 0);
-}
/*
* Allocate and setup a management frame of the specified
diff -r 8aecd7dc43b7 -r 49741112470a sys/net80211/ieee80211_netbsd.h
--- a/sys/net80211/ieee80211_netbsd.h Thu Jun 27 15:46:40 2013 +0000
+++ b/sys/net80211/ieee80211_netbsd.h Thu Jun 27 17:47:18 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ieee80211_netbsd.h,v 1.17 2011/12/31 20:41:58 christos Exp $ */
+/* $NetBSD: ieee80211_netbsd.h,v 1.18 2013/06/27 17:47:18 christos Exp $ */
/*-
* Copyright (c) 2003-2005 Sam Leffler, Errno Consulting
* All rights reserved.
@@ -234,8 +234,6 @@
#define ovbcopy(__src, __dst, __n) ((void)memmove(__dst, __src, __n))
void if_printf(struct ifnet *, const char *, ...);
-void m_align(struct mbuf *, int);
-int m_append(struct mbuf *, int, const void *);
void get_random_bytes(void *, size_t);
void ieee80211_sysctl_attach(struct ieee80211com *);
diff -r 8aecd7dc43b7 -r 49741112470a sys/sys/mbuf.h
--- a/sys/sys/mbuf.h Thu Jun 27 15:46:40 2013 +0000
+++ b/sys/sys/mbuf.h Thu Jun 27 17:47:18 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.151 2013/01/19 00:51:52 rmind Exp $ */
+/* $NetBSD: mbuf.h,v 1.152 2013/06/27 17:47:18 christos Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -852,9 +852,12 @@
void mbinit(void);
void m_ext_free(struct mbuf *);
char * m_mapin(struct mbuf *);
-void m_move_pkthdr(struct mbuf *to, struct mbuf *from);
+void m_move_pkthdr(struct mbuf *, struct mbuf *);
bool m_ensure_contig(struct mbuf **, int);
+struct mbuf *m_add(struct mbuf *, struct mbuf *);
+void m_align(struct mbuf *, int);
+int m_append(struct mbuf *, int, const void *);
/* Inline routines. */
static __inline u_int m_length(const struct mbuf *) __unused;
Home |
Main Index |
Thread Index |
Old Index