VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/if.c@ 14470

最後變更 在這個檔案從14470是 14470,由 vboxsync 提交於 16 年 前

slirp: remove tabs

  • 屬性 svn:eol-style 設為 native
檔案大小: 7.2 KB
 
1/*
2 * Copyright (c) 1995 Danny Gasparovski.
3 *
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
6 */
7
8#include <slirp.h>
9
10
11#define ifs_init(ifm) ((ifm)->ifs_next = (ifm)->ifs_prev = (ifm))
12
13static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead)
14{
15 ifm->ifs_next = ifmhead->ifs_next;
16 ifmhead->ifs_next = ifm;
17 ifm->ifs_prev = ifmhead;
18 ifm->ifs_next->ifs_prev = ifm;
19}
20
21static void ifs_remque(struct mbuf *ifm)
22{
23 ifm->ifs_prev->ifs_next = ifm->ifs_next;
24 ifm->ifs_next->ifs_prev = ifm->ifs_prev;
25}
26
27void
28if_init(PNATState pData)
29{
30#if 0
31 /*
32 * Set if_maxlinkhdr to 48 because it's 40 bytes for TCP/IP,
33 * and 8 bytes for PPP, but need to have it on an 8byte boundary
34 */
35#ifdef USE_PPP
36 if_maxlinkhdr = 48;
37#else
38 if_maxlinkhdr = 40;
39#endif
40#else
41 /* 2 for alignment, 14 for ethernet, 40 for TCP/IP */
42 if_maxlinkhdr = 2 + 14 + 40;
43#endif
44 if_queued = 0;
45 if_thresh = 10;
46 if_mtu = 1500;
47 if_mru = 1500;
48 if_comp = IF_AUTOCOMP;
49 if_fastq.ifq_next = if_fastq.ifq_prev = &if_fastq;
50 if_batchq.ifq_next = if_batchq.ifq_prev = &if_batchq;
51 /* sl_compress_init(&comp_s); */
52 next_m = &if_batchq;
53}
54
55/*
56 * if_output: Queue packet into an output queue.
57 * There are 2 output queue's, if_fastq and if_batchq.
58 * Each output queue is a doubly linked list of double linked lists
59 * of mbufs, each list belonging to one "session" (socket). This
60 * way, we can output packets fairly by sending one packet from each
61 * session, instead of all the packets from one session, then all packets
62 * from the next session, etc. Packets on the if_fastq get absolute
63 * priority, but if one session hogs the link, it gets "downgraded"
64 * to the batchq until it runs out of packets, then it'll return
65 * to the fastq (eg. if the user does an ls -alR in a telnet session,
66 * it'll temporarily get downgraded to the batchq)
67 */
68void
69if_output(PNATState pData, struct socket *so, struct mbuf *ifm)
70{
71 struct mbuf *ifq;
72 int on_fastq = 1;
73
74 DEBUG_CALL("if_output");
75 DEBUG_ARG("so = %lx", (long)so);
76 DEBUG_ARG("ifm = %lx", (long)ifm);
77
78 /*
79 * First remove the mbuf from m_usedlist,
80 * since we're gonna use m_next and m_prev ourselves
81 * XXX Shouldn't need this, gotta change dtom() etc.
82 */
83 if (ifm->m_flags & M_USEDLIST) {
84 remque(pData, ifm);
85 ifm->m_flags &= ~M_USEDLIST;
86 }
87
88 /*
89 * See if there's already a batchq list for this session.
90 * This can include an interactive session, which should go on fastq,
91 * but gets too greedy... hence it'll be downgraded from fastq to batchq.
92 * We mustn't put this packet back on the fastq (or we'll send it out of order)
93 * XXX add cache here?
94 */
95 for (ifq = if_batchq.ifq_prev; ifq != &if_batchq; ifq = ifq->ifq_prev) {
96 if (so == ifq->ifq_so) {
97 /* A match! */
98 ifm->ifq_so = so;
99 ifs_insque(ifm, ifq->ifs_prev);
100 goto diddit;
101 }
102 }
103
104 /* No match, check which queue to put it on */
105 if (so && (so->so_iptos & IPTOS_LOWDELAY)) {
106 ifq = if_fastq.ifq_prev;
107 on_fastq = 1;
108 /*
109 * Check if this packet is a part of the last
110 * packet's session
111 */
112 if (ifq->ifq_so == so) {
113 ifm->ifq_so = so;
114 ifs_insque(ifm, ifq->ifs_prev);
115 goto diddit;
116 }
117 } else
118 ifq = if_batchq.ifq_prev;
119
120 /* Create a new doubly linked list for this session */
121 ifm->ifq_so = so;
122 ifs_init(ifm);
123 insque(pData, ifm, ifq);
124
125diddit:
126 ++if_queued;
127
128 if (so) {
129 /* Update *_queued */
130 so->so_queued++;
131 so->so_nqueued++;
132 /*
133 * Check if the interactive session should be downgraded to
134 * the batchq. A session is downgraded if it has queued 6
135 * packets without pausing, and at least 3 of those packets
136 * have been sent over the link
137 * (XXX These are arbitrary numbers, probably not optimal..)
138 */
139 if (on_fastq && ((so->so_nqueued >= 6) &&
140 (so->so_nqueued - so->so_queued) >= 3)) {
141
142 /* Remove from current queue... */
143 remque(pData, ifm->ifs_next);
144
145 /* ...And insert in the new. That'll teach ya! */
146 insque(pData, ifm->ifs_next, &if_batchq);
147 }
148 }
149
150#ifndef FULL_BOLT
151 /*
152 * This prevents us from malloc()ing too many mbufs
153 */
154 if (link_up) {
155 /* if_start will check towrite */
156 if_start(pData);
157 }
158#endif
159}
160
161/*
162 * Send a packet
163 * We choose a packet based on it's position in the output queues;
164 * If there are packets on the fastq, they are sent FIFO, before
165 * everything else. Otherwise we choose the first packet from the
166 * batchq and send it. the next packet chosen will be from the session
167 * after this one, then the session after that one, and so on.. So,
168 * for example, if there are 3 ftp session's fighting for bandwidth,
169 * one packet will be sent from the first session, then one packet
170 * from the second session, then one packet from the third, then back
171 * to the first, etc. etc.
172 */
173void
174if_start(PNATState pData)
175{
176 struct mbuf *ifm, *ifqt;
177
178 DEBUG_CALL("if_start");
179
180 if (if_queued == 0)
181 return; /* Nothing to do */
182
183 again:
184 /* check if we can really output */
185 if (!slirp_can_output(pData->pvUser))
186 return;
187
188 /*
189 * See which queue to get next packet from
190 * If there's something in the fastq, select it immediately
191 */
192 if (if_fastq.ifq_next != &if_fastq) {
193 ifm = if_fastq.ifq_next;
194 } else {
195 /* Nothing on fastq, see if next_m is valid */
196 if (next_m != &if_batchq)
197 ifm = next_m;
198 else
199 ifm = if_batchq.ifq_next;
200
201 /* Set which packet to send on next iteration */
202 next_m = ifm->ifq_next;
203 }
204 /* Remove it from the queue */
205 ifqt = ifm->ifq_prev;
206 remque(pData, ifm);
207 --if_queued;
208
209 /* If there are more packets for this session, re-queue them */
210 if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) {
211 insque(pData, ifm->ifs_next, ifqt);
212 ifs_remque(ifm);
213 }
214
215 /* Update so_queued */
216 if (ifm->ifq_so) {
217 if (--ifm->ifq_so->so_queued == 0)
218 /* If there's no more queued, reset nqueued */
219 ifm->ifq_so->so_nqueued = 0;
220 }
221
222 /* Encapsulate the packet for sending */
223 if_encap(pData, (const uint8_t *)ifm->m_data, ifm->m_len);
224
225 m_free(pData, ifm);
226
227 if (if_queued)
228 goto again;
229}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette