xref: /dflybsd-src/sys/net/ifq_var.h (revision 402e4fa9c42adb64c3df20a1dbea61ff1afd9f2c)
1 /*-
2  * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  * 3. Neither the name of The DragonFly Project nor the names of its
15  *    contributors may be used to endorse or promote products derived
16  *    from this software without specific, prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $DragonFly: src/sys/net/ifq_var.h,v 1.2 2005/03/12 02:36:04 joerg Exp $
32  */
33 #ifndef _NET_IFQ_VAR_H
34 #define _NET_IFQ_VAR_H
35 
36 #ifdef ALTQ
37 static __inline int
38 ifq_is_enabled(struct ifaltq *_ifq)
39 {
40 	return(_ifq->altq_flags & ALTQF_ENABLED);
41 }
42 
43 static __inline int
44 ifq_is_attached(struct ifaltq *_ifq)
45 {
46 	return(_ifq->altq_disc != NULL);
47 }
48 #else
49 static __inline int
50 ifq_is_enabled(struct ifaltq *_ifq)
51 {
52 	return(0);
53 }
54 
55 static __inline int
56 ifq_is_attached(struct ifaltq *_ifq)
57 {
58 	return(0);
59 }
60 #endif
61 
62 static __inline int
63 ifq_is_ready(struct ifaltq *_ifq)
64 {
65 	return(_ifq->altq_flags & ALTQF_READY);
66 }
67 
68 static __inline void
69 ifq_set_ready(struct ifaltq *_ifq)
70 {
71 	_ifq->altq_flags |= ALTQF_READY;
72 }
73 
74 static __inline int
75 ifq_enqueue(struct ifaltq *_ifq, struct mbuf *_m, struct altq_pktattr *_pa)
76 {
77 	return((*_ifq->altq_enqueue)(_ifq, _m, _pa));
78 }
79 
80 static __inline struct mbuf *
81 ifq_dequeue(struct ifaltq *_ifq)
82 {
83 #ifdef ALTQ
84 	if (_ifq->altq_tbr != NULL)
85 		return(tbr_dequeue(_ifq, ALTDQ_REMOVE));
86 #endif
87 	return((*_ifq->altq_dequeue)(_ifq, ALTDQ_REMOVE));
88 }
89 
90 static __inline struct mbuf *
91 ifq_poll(struct ifaltq *_ifq)
92 {
93 #ifdef ALTQ
94 	if (_ifq->altq_tbr != NULL)
95 		return(tbr_dequeue(_ifq, ALTDQ_POLL));
96 #endif
97 	return((*_ifq->altq_dequeue)(_ifq, ALTDQ_POLL));
98 }
99 
100 static __inline void
101 ifq_purge(struct ifaltq *_ifq)
102 {
103 	(*_ifq->altq_request)(_ifq, ALTRQ_PURGE, NULL);
104 }
105 
106 static __inline void
107 ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af,
108 	     struct altq_pktattr *_pa)
109 {
110 	if (!ifq_is_enabled(_ifq))
111 		return;
112 	_pa->pattr_af = _af;
113 	_pa->pattr_hdr = mtod(_m, caddr_t);
114 	if (_ifq->altq_flags & ALTQF_CLASSIFY)
115 		(*_ifq->altq_classify)(_ifq, _m, _pa);
116 }
117 
118 static __inline int
119 ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa)
120 {
121 	int _error, _s;
122 
123 	_s = splimp();
124 	_error = ifq_enqueue(&_ifp->if_snd, _m, _pa);
125 	if (_error == 0) {
126 		_ifp->if_obytes += _m->m_pkthdr.len;
127 		if (_m->m_flags & M_MCAST)
128 			_ifp->if_omcasts++;
129 		if ((_ifp->if_flags & IFF_OACTIVE) == 0)
130 			(*_ifp->if_start)(_ifp);
131 	}
132 	splx(_s);
133 	return(_error);
134 }
135 
136 static __inline int
137 ifq_is_empty(struct ifaltq *_ifq)
138 {
139 	return(_ifq->ifq_len == 0);
140 }
141 
142 static __inline void
143 ifq_set_maxlen(struct ifaltq *_ifq, int _len)
144 {
145 	_ifq->ifq_maxlen = _len;
146 }
147 
148 #endif
149