1 /* $KAME: if_altq.h,v 1.11 2003/07/10 12:07:50 kjc Exp $ */ 2 /* $DragonFly: src/sys/net/altq/if_altq.h,v 1.3 2006/05/20 02:42:09 dillon Exp $ */ 3 4 /* 5 * Copyright (C) 1997-2003 6 * Sony Computer Science Laboratories Inc. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 #ifndef _NET_ALTQ_IF_ALTQ_H_ 30 #define _NET_ALTQ_IF_ALTQ_H_ 31 32 struct altq_pktattr; 33 34 /* 35 * Structure defining a queue for a network interface. 36 */ 37 struct ifaltq { 38 /* fields compatible with struct ifqueue */ 39 struct mbuf *ifq_head; 40 struct mbuf *ifq_tail; 41 int ifq_len; 42 int ifq_maxlen; 43 int ifq_drops; 44 45 /* alternate queueing related fields */ 46 int altq_type; /* discipline type */ 47 int altq_flags; /* flags (e.g. ready, in-use) */ 48 void *altq_disc; /* for discipline-specific use */ 49 struct ifnet *altq_ifp; /* back pointer to interface */ 50 51 int (*altq_enqueue)(struct ifaltq *, struct mbuf *, 52 struct altq_pktattr *); 53 struct mbuf *(*altq_dequeue)(struct ifaltq *, struct mbuf *, int); 54 int (*altq_request)(struct ifaltq *, int, void *); 55 56 /* classifier fields */ 57 void *altq_clfier; /* classifier-specific use */ 58 void *(*altq_classify)(struct ifaltq *, struct mbuf *, 59 struct altq_pktattr *); 60 61 /* token bucket regulator */ 62 struct tb_regulator *altq_tbr; 63 }; 64 65 66 #ifdef _KERNEL 67 68 /* 69 * packet attributes used by queueing disciplines. 70 * pattr_class is a discipline-dependent scheduling class that is 71 * set by a classifier. 72 * pattr_hdr and pattr_af may be used by a discipline to access 73 * the header within a mbuf. (e.g. ECN needs to update the CE bit) 74 * note that pattr_hdr could be stale after m_pullup, though link 75 * layer output routines usually don't use m_pullup. link-level 76 * compression also invalidates these fields. thus, pattr_hdr needs 77 * to be verified when a discipline touches the header. 78 */ 79 struct altq_pktattr { 80 void *pattr_class; /* sched class set by classifier */ 81 int pattr_af; /* address family */ 82 caddr_t pattr_hdr; /* saved header position in mbuf */ 83 }; 84 85 /* 86 * a token-bucket regulator limits the rate that a network driver can 87 * dequeue packets from the output queue. 88 * modern cards are able to buffer a large amount of packets and dequeue 89 * too many packets at a time. this bursty dequeue behavior makes it 90 * impossible to schedule packets by queueing disciplines. 91 * a token-bucket is used to control the burst size in a device 92 * independent manner. 93 */ 94 struct tb_regulator { 95 int64_t tbr_rate; /* (scaled) token bucket rate */ 96 int64_t tbr_depth; /* (scaled) token bucket depth */ 97 98 int64_t tbr_token; /* (scaled) current token */ 99 int64_t tbr_filluptime; /* (scaled) time to fill up bucket */ 100 uint64_t tbr_last; /* last time token was updated */ 101 102 int tbr_lastop; /* last dequeue operation type 103 needed for poll-and-dequeue */ 104 }; 105 106 /* if_altqflags */ 107 #define ALTQF_READY 0x01 /* driver supports alternate queueing */ 108 #define ALTQF_ENABLED 0x02 /* altq is in use */ 109 #define ALTQF_CLASSIFY 0x04 /* classify packets */ 110 #define ALTQF_DRIVER1 0x40 /* driver specific */ 111 112 /* if_altqflags set internally only: */ 113 #define ALTQF_CANTCHANGE (ALTQF_READY) 114 115 /* altq_dequeue 2nd arg */ 116 #define ALTDQ_REMOVE 1 /* dequeue mbuf from the queue */ 117 #define ALTDQ_POLL 2 /* don't dequeue mbuf from the queue */ 118 119 /* altq request types (currently only purge is defined) */ 120 #define ALTRQ_PURGE 1 /* purge all packets */ 121 122 int altq_attach(struct ifaltq *, int, void *, 123 int (*)(struct ifaltq *, struct mbuf *, struct altq_pktattr *), 124 struct mbuf *(*)(struct ifaltq *, struct mbuf *, int), 125 int (*)(struct ifaltq *, int, void *), 126 void *, void *(*)(struct ifaltq *, struct mbuf *, 127 struct altq_pktattr *)); 128 int altq_detach(struct ifaltq *); 129 int altq_enable(struct ifaltq *); 130 int altq_disable(struct ifaltq *); 131 struct mbuf *tbr_dequeue(struct ifaltq *, struct mbuf *, int); 132 extern int (*altq_input)(struct mbuf *, int); 133 #endif /* _KERNEL */ 134 135 #endif /* _NET_ALTQ_IF_ALTQ_H_ */ 136