svn commit: r277071 - projects/ifnet/sys/sys
Gleb Smirnoff
glebius at FreeBSD.org
Mon Jan 12 13:53:41 UTC 2015
Author: glebius
Date: Mon Jan 12 13:53:40 2015
New Revision: 277071
URL: https://svnweb.freebsd.org/changeset/base/277071
Log:
Provide struct mbufq, a STAILQ of mbufs, with counter for packets
and maximum limit set. The structure is supposed to have external
locking. The aim of new structure is to substitute struct ifqueue
in several places in the kernel, where struct ifqueue is used
outside of ifnet code itself.
Modified:
projects/ifnet/sys/sys/mbuf.h
Modified: projects/ifnet/sys/sys/mbuf.h
==============================================================================
--- projects/ifnet/sys/sys/mbuf.h Mon Jan 12 13:50:34 2015 (r277070)
+++ projects/ifnet/sys/sys/mbuf.h Mon Jan 12 13:53:40 2015 (r277071)
@@ -1197,5 +1197,94 @@ rt_m_getfib(struct mbuf *m)
#define M_PROFILE(m)
#endif
+struct mbufq {
+ STAILQ_HEAD(, mbuf) mq_head;
+ int mq_len;
+ int mq_maxlen;
+};
+static inline void
+mbufq_init(struct mbufq *mq, int maxlen)
+{
+
+ STAILQ_INIT(&mq->mq_head);
+ mq->mq_maxlen = maxlen;
+ mq->mq_len = 0;
+}
+
+static inline struct mbuf *
+mbufq_flush(struct mbufq *mq)
+{
+ struct mbuf *m;
+
+ m = STAILQ_FIRST(&mq->mq_head);
+ STAILQ_INIT(&mq->mq_head);
+ mq->mq_len = 0;
+ return (m);
+}
+
+static inline void
+mbufq_drain(struct mbufq *mq)
+{
+ struct mbuf *m, *n;
+
+ n = mbufq_flush(mq);
+ while ((m = n) != NULL) {
+ n = m->m_nextpkt;
+ m_freem(m);
+ }
+}
+
+static inline struct mbuf *
+mbufq_first(struct mbufq *mq)
+{
+
+ return (STAILQ_FIRST(&mq->mq_head));
+}
+
+static inline struct mbuf *
+mbufq_last(struct mbufq *mq)
+{
+
+ return (STAILQ_LAST(&mq->mq_head, mbuf, m_stailqpkt));
+}
+
+static inline int
+mbufq_full(struct mbufq *mq)
+{
+
+ return (mq->mq_len >= mq->mq_maxlen);
+}
+
+static inline int
+mbufq_enqueue(struct mbufq *mq, struct mbuf *m)
+{
+
+ if (mbufq_full(mq))
+ return (ENOBUFS);
+ STAILQ_INSERT_TAIL(&mq->mq_head, m, m_stailqpkt);
+ mq->mq_len++;
+ return (0);
+}
+
+static inline struct mbuf *
+mbufq_dequeue(struct mbufq *mq)
+{
+ struct mbuf *m;
+
+ m = STAILQ_FIRST(&mq->mq_head);
+ if (m) {
+ STAILQ_REMOVE_HEAD(&mq->mq_head, m_stailqpkt);
+ mq->mq_len--;
+ }
+ return (m);
+}
+
+static inline void
+mbufq_prepend(struct mbufq *mq, struct mbuf *m)
+{
+
+ STAILQ_INSERT_HEAD(&mq->mq_head, m, m_stailqpkt);
+ mq->mq_len++;
+}
#endif /* !_SYS_MBUF_H_ */
More information about the svn-src-projects
mailing list