1/* 2 * Copyright (c) 2008-2012 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* $OpenBSD: if_altq.h,v 1.11 2007/11/18 12:51:48 mpf Exp $ */ 29/* $KAME: if_altq.h,v 1.6 2001/01/29 19:59:09 itojun Exp $ */ 30 31/* 32 * Copyright (C) 1997-2003 33 * Sony Computer Science Laboratories Inc. All rights reserved. 34 * 35 * Redistribution and use in source and binary forms, with or without 36 * modification, are permitted provided that the following conditions 37 * are met: 38 * 1. Redistributions of source code must retain the above copyright 39 * notice, this list of conditions and the following disclaimer. 40 * 2. Redistributions in binary form must reproduce the above copyright 41 * notice, this list of conditions and the following disclaimer in the 42 * documentation and/or other materials provided with the distribution. 43 * 44 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54 * SUCH DAMAGE. 55 */ 56#ifndef _NET_ALTQ_IF_ALTQ_H_ 57#define _NET_ALTQ_IF_ALTQ_H_ 58 59#ifdef BSD_KERNEL_PRIVATE 60#if PF_ALTQ 61#include <net/classq/if_classq.h> 62 63/* altq request types */ 64typedef enum altrq { 65 ALTRQ_PURGE = CLASSQRQ_PURGE, /* purge all packets */ 66 ALTRQ_PURGE_SC = CLASSQRQ_PURGE_SC, /* purge SC flow */ 67 ALTRQ_EVENT = CLASSQRQ_EVENT, /* interface events */ 68 ALTRQ_THROTTLE = CLASSQRQ_THROTTLE, /* throttle packets */ 69} altrq_t; 70 71struct ifaltq; 72enum altdq_op; 73 74typedef int (*altq_enq_func)(struct ifaltq *, struct mbuf *); 75typedef struct mbuf *(*altq_deq_func)(struct ifaltq *, enum altdq_op); 76typedef struct mbuf *(*altq_deq_sc_func)(struct ifaltq *, 77 mbuf_svc_class_t, enum altdq_op); 78typedef int (*altq_req_func)(struct ifaltq *, enum altrq, void *); 79 80/* 81 * Structure defining a queue for a network interface. 82 */ 83struct ifaltq { 84 struct ifclassq *altq_ifcq; /* back pointer to interface queue */ 85 86 /* alternate queueing related fields */ 87 u_int32_t altq_type; /* discipline type */ 88 u_int32_t altq_flags; /* flags (e.g. ready, in-use) */ 89 void *altq_disc; /* for discipline-specific use */ 90 91 altq_enq_func altq_enqueue; 92 altq_deq_func altq_dequeue; 93 altq_deq_sc_func altq_dequeue_sc; 94 altq_req_func altq_request; 95}; 96 97/* altq_flags */ 98#define ALTQF_READY 0x01 /* driver supports alternate queueing */ 99#define ALTQF_ENABLED 0x02 /* altq is in use */ 100#define ALTQF_DRIVER1 0x40 /* driver specific */ 101 102/* altq_flags set internally only: */ 103#define ALTQF_CANTCHANGE (ALTQF_READY) 104 105/* altq_dequeue op arg */ 106typedef enum altdq_op { 107 ALTDQ_REMOVE = CLASSQDQ_REMOVE, /* dequeue mbuf from the queue */ 108 ALTDQ_POLL = CLASSQDQ_POLL, /* don't dequeue mbuf from the queue */ 109} altdq_op_t; 110 111#define ALTQ_IS_READY(_altq) ((_altq)->altq_flags & ALTQF_READY) 112#define ALTQ_IS_ENABLED(_altq) ((_altq)->altq_flags & ALTQF_ENABLED) 113#define ALTQ_IS_ATTACHED(_altq) ((_altq)->altq_disc != NULL) 114 115#define ALTQ_ENQUEUE(_altq, _m, _err) do { \ 116 (_err) = (*(_altq)->altq_enqueue)(_altq, _m); \ 117} while (0) 118 119#define ALTQ_DEQUEUE(_altq, _m) do { \ 120 (_m) = (*(_altq)->altq_dequeue)(_altq, ALTDQ_REMOVE); \ 121} while (0) 122 123#define ALTQ_DEQUEUE_SC(_altq, _sc, _m) do { \ 124 (_m) = (*(_altq)->altq_dequeue_sc)(_altq, _sc, ALTDQ_REMOVE); \ 125} while (0) 126 127#define ALTQ_POLL(_altq, _m) do { \ 128 (_m) = (*(_altq)->altq_dequeue)(_altq, ALTDQ_POLL); \ 129} while (0) 130 131#define ALTQ_POLL_SC(_altq, _sc, _m) do { \ 132 (_m) = (*(_altq)->altq_dequeue_sc)(_altq, _sc, ALTDQ_POLL); \ 133} while (0) 134 135#define ALTQ_PURGE(_altq) do { \ 136 (void) (*(_altq)->altq_request)(_altq, ALTRQ_PURGE, NULL); \ 137} while (0) 138 139#define ALTQ_PURGE_SC(_altq, _sc, _flow, _packets, _bytes) do { \ 140 cqrq_purge_sc_t _req = { _sc, _flow, 0, 0 }; \ 141 (void) (*(_altq)->altq_request)(_altq, ALTRQ_PURGE_SC, &_req); \ 142 (_packets) = _req.packets; \ 143 (_bytes) = _req.bytes; \ 144} while (0) 145 146#define ALTQ_UPDATE(_altq, _ev) do { \ 147 (void) (*(_altq)->altq_request)(_altq, ALTRQ_EVENT, \ 148 (void *)(_ev)); \ 149} while (0) 150 151#define ALTQ_SET_READY(_altq) do { \ 152 IFCQ_LOCK_ASSERT_HELD((_altq)->altq_ifcq); \ 153 (_altq)->altq_flags |= ALTQF_READY; \ 154} while (0) 155 156#define ALTQ_CLEAR_READY(_altq) do { \ 157 IFCQ_LOCK_ASSERT_HELD((_altq)->altq_ifcq); \ 158 (_altq)->altq_flags &= ~ALTQF_READY; \ 159} while (0) 160 161extern int altq_attach(struct ifaltq *, u_int32_t, void *, 162 altq_enq_func, altq_deq_func, altq_deq_sc_func, altq_req_func); 163extern int altq_detach(struct ifaltq *); 164extern int altq_enable(struct ifaltq *); 165extern int altq_disable(struct ifaltq *); 166#endif /* PF_ALTQ */ 167#endif /* BSD_KERNEL_PRIVATE */ 168#endif /* _NET_ALTQ_IF_ALTQ_H_ */ 169