]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1998 Luigi Rizzo | |
24 | * | |
25 | * Redistribution and use in source forms, with and without modification, | |
26 | * are permitted provided that this entire comment appears intact. | |
27 | * | |
28 | * Redistribution in binary form may occur without any restrictions. | |
29 | * Obviously, it would be nice if you gave credit where credit is due | |
30 | * but requiring it would be too onerous. | |
31 | * | |
32 | * This software is provided ``AS IS'' without any warranties of any kind. | |
33 | * | |
34 | */ | |
35 | ||
36 | #ifndef _IP_DUMMYNET_H | |
37 | #define _IP_DUMMYNET_H | |
38 | ||
39 | /* | |
40 | * Definition of dummynet data structures. | |
41 | * Dummynet handles a list of pipes, each one identified by a unique | |
42 | * number (hopefully the list is short so we use a linked list). | |
43 | * | |
44 | * Each list contains a set of parameters identifying the pipe, and | |
45 | * a set of packets queued on the pipe itself. | |
46 | * | |
47 | * I could have used queue macros, but the management i have | |
48 | * is pretty simple and this makes the code more portable. | |
49 | */ | |
50 | ||
51 | /* | |
52 | * struct dn_pkt identifies a packet in the dummynet queue. The | |
53 | * first part is really an m_hdr for implementation purposes, and some | |
54 | * fields are saved there. When passing the packet back to the ip_input/ | |
55 | * ip_output(), the struct is prepended to the mbuf chain with type | |
56 | * MT_DUMMYNET, and contains the pointer to the matching rule. | |
57 | */ | |
58 | struct dn_pkt { | |
59 | struct m_hdr hdr ; | |
60 | #define dn_next hdr.mh_nextpkt /* next element in queue */ | |
61 | #define dn_m hdr.mh_next /* packet to be forwarded */ | |
62 | #define dn_hlen hdr.mh_len /* hlen, for ip_output */ | |
63 | #define dn_dir hdr.mh_flags /* IP_FW_F_IN or IP_FW_F_OUT */ | |
64 | int delay; /* stays queued until delay=0 */ | |
65 | struct ifnet *ifp; /* interface, for ip_output */ | |
66 | struct route ro; /* route, for ip_output. MUST COPY */ | |
67 | ||
68 | #if DUMMYNET_DEBUG | |
69 | struct timeval beg, mid; /* testing only */ | |
70 | int act_delay; /* testing only */ | |
71 | int in_delay; /* testing only */ | |
72 | #endif | |
73 | }; | |
74 | ||
75 | struct dn_queue { | |
76 | struct dn_pkt *head, *tail; | |
77 | } ; | |
78 | ||
79 | /* | |
80 | * descriptor of a pipe. The flags field will be used to speed up the | |
81 | * forwarding code paths, in case some of the parameters are not | |
82 | * used. | |
83 | */ | |
84 | struct dn_pipe { /* a pipe */ | |
85 | struct dn_pipe *next ; | |
86 | ||
87 | u_short pipe_nr ; /* number */ | |
88 | u_short flags ; /* to speed up things */ | |
89 | #define DN_HAVE_BW 1 | |
90 | #define DN_HAVE_QUEUE 2 | |
91 | #define DN_HAVE_DELAY 4 | |
92 | int bandwidth; /* really, bytes/tick. */ | |
93 | int queue_size ; | |
94 | int queue_size_bytes ; | |
95 | int delay ; /* really, ticks */ | |
96 | int plr ; /* pkt loss rate (2^31-1 means 100%) */ | |
97 | ||
98 | struct dn_queue r; | |
99 | int r_len; /* elements in r_queue */ | |
100 | int r_len_bytes; /* bytes in r_queue */ | |
101 | int r_drops; /* drops from r_queue */ | |
102 | struct dn_queue p ; | |
103 | int ticks_from_last_insert; | |
104 | long numbytes; /* which can send or receive */ | |
105 | }; | |
106 | ||
107 | /* | |
108 | * The following is used to define a new mbuf type that is | |
109 | * prepended to the packet when it comes out of a pipe. The definition | |
110 | * ought to go in /sys/sys/mbuf.h but here it is less intrusive. | |
111 | */ | |
112 | ||
113 | #define MT_DUMMYNET MT_CONTROL | |
114 | /* | |
115 | * what to do of a packet when it comes out of a pipe | |
116 | */ | |
117 | #define DN_TO_IP_OUT 1 | |
118 | #define DN_TO_IP_IN 2 | |
119 | #define DN_TO_BDG_FWD 3 | |
120 | ||
121 | #if KERNEL | |
122 | ||
123 | MALLOC_DECLARE(M_IPFW); | |
124 | ||
125 | typedef int ip_dn_ctl_t __P((struct sockopt *)) ; | |
126 | extern ip_dn_ctl_t *ip_dn_ctl_ptr; | |
127 | ||
128 | void ip_dn_init(void); /* called in ip_input.c */ | |
129 | void dn_rule_delete(void *r); /* used in ip_fw.c */ | |
130 | int dummynet_io(int pipe, int dir, | |
131 | struct mbuf *m, struct ifnet *ifp, struct route *ro, int hlen, | |
132 | struct ip_fw_chain *rule); | |
133 | #endif /* KERNEL */ | |
134 | ||
135 | #endif /* _IP_DUMMYNET_H */ |