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.4 2005/06/15 19:29:30 joerg Exp $ 32 */ 33 #ifndef _NET_IFQ_VAR_H 34 #define _NET_IFQ_VAR_H 35 36 #include <sys/thread2.h> 37 38 #ifdef ALTQ 39 static __inline int 40 ifq_is_enabled(struct ifaltq *_ifq) 41 { 42 return(_ifq->altq_flags & ALTQF_ENABLED); 43 } 44 45 static __inline int 46 ifq_is_attached(struct ifaltq *_ifq) 47 { 48 return(_ifq->altq_disc != NULL); 49 } 50 #else 51 static __inline int 52 ifq_is_enabled(struct ifaltq *_ifq) 53 { 54 return(0); 55 } 56 57 static __inline int 58 ifq_is_attached(struct ifaltq *_ifq) 59 { 60 return(0); 61 } 62 #endif 63 64 static __inline int 65 ifq_is_ready(struct ifaltq *_ifq) 66 { 67 return(_ifq->altq_flags & ALTQF_READY); 68 } 69 70 static __inline void 71 ifq_set_ready(struct ifaltq *_ifq) 72 { 73 _ifq->altq_flags |= ALTQF_READY; 74 } 75 76 static __inline int 77 ifq_enqueue(struct ifaltq *_ifq, struct mbuf *_m, struct altq_pktattr *_pa) 78 { 79 return((*_ifq->altq_enqueue)(_ifq, _m, _pa)); 80 } 81 82 static __inline struct mbuf * 83 ifq_dequeue(struct ifaltq *_ifq) 84 { 85 #ifdef ALTQ 86 if (_ifq->altq_tbr != NULL) 87 return(tbr_dequeue(_ifq, ALTDQ_REMOVE)); 88 #endif 89 return((*_ifq->altq_dequeue)(_ifq, ALTDQ_REMOVE)); 90 } 91 92 static __inline struct mbuf * 93 ifq_poll(struct ifaltq *_ifq) 94 { 95 #ifdef ALTQ 96 if (_ifq->altq_tbr != NULL) 97 return(tbr_dequeue(_ifq, ALTDQ_POLL)); 98 #endif 99 return((*_ifq->altq_dequeue)(_ifq, ALTDQ_POLL)); 100 } 101 102 static __inline void 103 ifq_purge(struct ifaltq *_ifq) 104 { 105 (*_ifq->altq_request)(_ifq, ALTRQ_PURGE, NULL); 106 } 107 108 static __inline void 109 ifq_classify(struct ifaltq *_ifq, struct mbuf *_m, uint8_t _af, 110 struct altq_pktattr *_pa) 111 { 112 if (!ifq_is_enabled(_ifq)) 113 return; 114 _pa->pattr_af = _af; 115 _pa->pattr_hdr = mtod(_m, caddr_t); 116 if (_ifq->altq_flags & ALTQF_CLASSIFY) 117 (*_ifq->altq_classify)(_ifq, _m, _pa); 118 } 119 120 static __inline int 121 ifq_handoff(struct ifnet *_ifp, struct mbuf *_m, struct altq_pktattr *_pa) 122 { 123 int _error; 124 125 crit_enter(); 126 _error = ifq_enqueue(&_ifp->if_snd, _m, _pa); 127 if (_error == 0) { 128 _ifp->if_obytes += _m->m_pkthdr.len; 129 if (_m->m_flags & M_MCAST) 130 _ifp->if_omcasts++; 131 if ((_ifp->if_flags & IFF_OACTIVE) == 0) 132 (*_ifp->if_start)(_ifp); 133 } 134 crit_exit(); 135 return(_error); 136 } 137 138 static __inline int 139 ifq_is_empty(struct ifaltq *_ifq) 140 { 141 return(_ifq->ifq_len == 0); 142 } 143 144 static __inline void 145 ifq_set_maxlen(struct ifaltq *_ifq, int _len) 146 { 147 _ifq->ifq_maxlen = _len; 148 } 149 150 void ifq_set_classic(struct ifaltq *); 151 152 #endif 153