IFQ_ENQUEUE refactor (1/3) : add altq_pktattr fields to m_pkthdr

Reviewed by joerg@n.o and tls@n.o, thanks.
This commit is contained in:
knakahara 2016-04-20 08:56:32 +00:00
parent 465626aae4
commit 6190bb13a7
3 changed files with 41 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.h,v 1.198 2016/02/19 20:05:43 roy Exp $ */
/* $NetBSD: if.h,v 1.199 2016/04/20 08:56:32 knakahara Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@ -757,12 +757,17 @@ struct if_addrprefreq {
#define ALTQ_DECL(x) x
#define ALTQ_COMMA ,
#define IFQ_ENQUEUE(ifq, m, pattr, err) \
#define IFQ_ENQUEUE(ifq, m, unused, err) \
do { \
struct altq_pktattr *_unused __unused = unused; \
IFQ_LOCK((ifq)); \
if (ALTQ_IS_ENABLED((ifq))) \
ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \
else { \
if (ALTQ_IS_ENABLED((ifq))) { \
struct altq_pktattr pattr; \
pattr.pattr_class = (m)->m_pkthdr.pattr_class; \
pattr.pattr_af = (m)->m_pkthdr.pattr_af; \
pattr.pattr_hdr = (m)->m_pkthdr.pattr_hdr; \
ALTQ_ENQUEUE((ifq), (m), &pattr, (err)); \
} else { \
if (IF_QFULL((ifq))) { \
m_freem((m)); \
(err) = ENOBUFS; \
@ -815,15 +820,16 @@ do { \
(ifq)->altq_flags |= ALTQF_READY; \
} while (/*CONSTCOND*/ 0)
#define IFQ_CLASSIFY(ifq, m, af, pattr) \
#define IFQ_CLASSIFY(ifq, m, af, unused) \
do { \
struct altq_pktattr *_unused __unused = unused; \
IFQ_LOCK((ifq)); \
if (ALTQ_IS_ENABLED((ifq))) { \
if (ALTQ_NEEDS_CLASSIFY((ifq))) \
(pattr)->pattr_class = (*(ifq)->altq_classify) \
m->m_pkthdr.pattr_class = (*(ifq)->altq_classify) \
((ifq)->altq_clfier, (m), (af)); \
(pattr)->pattr_af = (af); \
(pattr)->pattr_hdr = mtod((m), void *); \
m->m_pkthdr.pattr_af = (af); \
m->m_pkthdr.pattr_hdr = mtod((m), void *); \
} \
IFQ_UNLOCK((ifq)); \
} while (/*CONSTCOND*/ 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ethersubr.c,v 1.218 2016/04/15 01:31:29 ozaki-r Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.219 2016/04/20 08:56:32 knakahara Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.218 2016/04/15 01:31:29 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.219 2016/04/20 08:56:32 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -418,7 +418,7 @@ ether_output(struct ifnet * const ifp0, struct mbuf * const m0,
* address family/header pointer in the pktattr.
*/
if (ALTQ_IS_ENABLED(&ifp->if_snd))
altq_etherclassify(&ifp->if_snd, m, &pktattr);
altq_etherclassify(&ifp->if_snd, m, NULL);
#endif
return ifq_enqueue(ifp, m ALTQ_COMMA ALTQ_DECL(&pktattr));
@ -504,10 +504,10 @@ altq_etherclassify(struct ifaltq *ifq, struct mbuf *m,
hdr = mtod(m, void *);
if (ALTQ_NEEDS_CLASSIFY(ifq))
pktattr->pattr_class =
m->m_pkthdr.pattr_class =
(*ifq->altq_classify)(ifq->altq_clfier, m, af);
pktattr->pattr_af = af;
pktattr->pattr_hdr = hdr;
m->m_pkthdr.pattr_af = af;
m->m_pkthdr.pattr_hdr = hdr;
m->m_data -= hlen;
m->m_len += hlen;
@ -515,9 +515,9 @@ altq_etherclassify(struct ifaltq *ifq, struct mbuf *m,
return;
bad:
pktattr->pattr_class = NULL;
pktattr->pattr_hdr = NULL;
pktattr->pattr_af = AF_UNSPEC;
m->m_pkthdr.pattr_class = NULL;
m->m_pkthdr.pattr_hdr = NULL;
m->m_pkthdr.pattr_af = AF_UNSPEC;
}
#endif /* ALTQ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mbuf.h,v 1.160 2016/04/20 08:50:43 knakahara Exp $ */
/* $NetBSD: mbuf.h,v 1.161 2016/04/20 08:56:32 knakahara Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@ -75,6 +75,7 @@
#include <sys/queue.h>
#if defined(_KERNEL)
#include <sys/percpu_types.h>
#include <sys/socket.h> /* for AF_UNSPEC */
#endif /* defined(_KERNEL) */
/* For offsetof() */
@ -169,6 +170,9 @@ struct m_hdr {
* be bit-wise inverted (the final step in the calculation of an IP
* checksum) -- this is so we can accumulate the checksum for fragmented
* packets during reassembly.
*
* Size ILP32: 36
* LP64: 56
*/
struct pkthdr {
struct ifnet *rcvif; /* rcv interface */
@ -177,6 +181,14 @@ struct pkthdr {
int csum_flags; /* checksum flags */
uint32_t csum_data; /* checksum data */
u_int segsz; /* segment size */
/*
* Following three fields are open-coded struct altq_pktattr
* to rearrange struct pkthdr fields flexibly.
*/
void *pattr_class; /* ALTQ: sched class set by classifier */
void *pattr_hdr; /* ALTQ: saved header position in mbuf */
int pattr_af; /* ALTQ: address family */
};
/*
@ -964,6 +976,10 @@ m_pkthdr_init(struct mbuf *m)
m->m_pkthdr.csum_flags = 0;
m->m_pkthdr.csum_data = 0;
SLIST_INIT(&m->m_pkthdr.tags);
m->m_pkthdr.pattr_class = NULL;
m->m_pkthdr.pattr_af = AF_UNSPEC;
m->m_pkthdr.pattr_hdr = NULL;
}
void m_print(const struct mbuf *, const char *, void (*)(const char *, ...)