Add missing .El to silence groff warning.
[dragonfly.git] / sys / net / ifq_var.h
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.1 2005/02/11 22:25:57 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         if (ifq_is_enabled(_ifq)) {
78                 return((*_ifq->altq_enqueue)(_ifq, _m, _pa));
79         } else {
80                 if (IF_QFULL(_ifq)) {
81                         m_freem(_m);
82                         return(ENOBUFS);
83                 } else {
84                         IF_ENQUEUE(_ifq, _m);
85                         return(0);
86                 }
87         }
88 }
89
90 static __inline struct mbuf *
91 ifq_dequeue(struct ifaltq *_ifq)
92 {
93 #ifdef ALTQ
94         if (_ifq->altq_tbr != NULL)
95                 return(tbr_dequeue(_ifq, ALTDQ_REMOVE));
96 #endif
97         if (ifq_is_enabled(_ifq)) {
98                 return((*_ifq->altq_dequeue)(_ifq, ALTDQ_REMOVE));
99         } else {
100                 struct mbuf *_m;
101
102                 IF_DEQUEUE(_ifq, _m);
103                 return(_m);
104         }
105 }
106
107 static __inline struct mbuf *
108 ifq_poll(struct ifaltq *_ifq)
109 {
110 #ifdef ALTQ
111         if (_ifq->altq_tbr != NULL)
112                 return(tbr_dequeue(_ifq, ALTDQ_POLL));
113 #endif
114         if (ifq_is_enabled(_ifq)) {
115                 return((*_ifq->altq_dequeue)(_ifq, ALTDQ_POLL));
116         } else {
117                 struct mbuf *_m;
118
119                 IF_POLL(_ifq, _m);
120                 return(_m);
121         }
122 }
123
124 static __inline void
125 ifq_purge(struct ifaltq *_ifq)
126 {
127         if (ifq_is_enabled(_ifq))
128                 (*_ifq->altq_request)(_ifq, ALTRQ_PURGE, NULL);
129         else
130                 IF_DRAIN(_ifq);
131 }
132
133 static __inline void
134 ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af,
135              struct altq_pktattr *_pa)
136 {
137         if (!ifq_is_enabled(_ifq))
138                 return;
139         _pa->pattr_af = _af;
140         _pa->pattr_hdr = mtod(_m, caddr_t);
141         if (_ifq->altq_flags & ALTQF_CLASSIFY)
142                 (*_ifq->altq_classify)(_ifq, _m, _pa);
143 }
144
145 static __inline int
146 ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa)
147 {
148         int _error, _s;
149
150         _s = splimp();
151         _error = ifq_enqueue(&_ifp->if_snd, _m, _pa);
152         if (_error == 0) {
153                 _ifp->if_obytes += _m->m_pkthdr.len;
154                 if (_m->m_flags & M_MCAST)
155                         _ifp->if_omcasts++;
156                 if ((_ifp->if_flags & IFF_OACTIVE) == 0)
157                         (*_ifp->if_start)(_ifp);
158         }
159         splx(_s);
160         return(_error);
161 }
162
163 static __inline int
164 ifq_is_empty(struct ifaltq *_ifq)
165 {
166         return(_ifq->ifq_len == 0);
167 }
168
169 static __inline void
170 ifq_set_maxlen(struct ifaltq *_ifq, int _len)
171 {
172         _ifq->ifq_maxlen = _len;
173 }
174
175 #endif