2 ===================================================================
3 RCS file: /sources/qemu/qemu/vl.c,v
4 retrieving revision 1.157
5 diff -u -p -r1.157 vl.c
6 --- vl.c 18 Dec 2005 20:34:32 -0000 1.157
7 +++ vl.c 20 Dec 2005 21:11:37 -0000
8 @@ -1768,13 +1768,16 @@ VLANState *qemu_find_vlan(int id)
11 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
12 - IOReadHandler *fd_read, void *opaque)
13 + IOReadHandler *fd_read,
14 + IOCanRWHandler *fd_can_read,
17 VLANClientState *vc, **pvc;
18 vc = qemu_mallocz(sizeof(VLANClientState));
21 vc->fd_read = fd_read;
22 + vc->fd_can_read = fd_can_read;
26 @@ -1786,6 +1789,20 @@ VLANClientState *qemu_new_vlan_client(VL
30 +int qemu_can_send_packet(VLANClientState *vc1)
32 + VLANState *vlan = vc1->vlan;
33 + VLANClientState *vc;
35 + for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
37 + if (vc->fd_can_read && !vc->fd_can_read(vc->opaque))
44 void qemu_send_packet(VLANClientState *vc1, const uint8_t *buf, int size)
46 VLANState *vlan = vc1->vlan;
47 @@ -1811,7 +1828,7 @@ static VLANClientState *slirp_vc;
49 int slirp_can_output(void)
52 + return qemu_can_send_packet(slirp_vc);
55 void slirp_output(const uint8_t *pkt, int pkt_len)
56 @@ -1839,7 +1856,7 @@ static int net_slirp_init(VLANState *vla
59 slirp_vc = qemu_new_vlan_client(vlan,
60 - slirp_receive, NULL);
61 + slirp_receive, NULL, NULL);
62 snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
65 @@ -2024,7 +2041,7 @@ static TAPState *net_tap_fd_init(VLANSta
69 - s->vc = qemu_new_vlan_client(vlan, tap_receive, s);
70 + s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
71 qemu_set_fd_handler(s->fd, tap_send, NULL, s);
72 snprintf(s->vc->info_str, sizeof(s->vc->info_str), "tap: fd=%d", fd);
74 @@ -2327,7 +2344,7 @@ static NetSocketState *net_socket_fd_ini
78 - s->vc = qemu_new_vlan_client(vlan, net_socket_receive_dgram, s);
79 + s->vc = qemu_new_vlan_client(vlan, net_socket_receive_dgram, NULL, s);
80 qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
82 /* mcast: save bound address as dst */
83 @@ -2355,7 +2372,7 @@ static NetSocketState *net_socket_fd_ini
86 s->vc = qemu_new_vlan_client(vlan,
87 - net_socket_receive, s);
88 + net_socket_receive, NULL, s);
89 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
93 ===================================================================
94 RCS file: /sources/qemu/qemu/vl.h,v
95 retrieving revision 1.99
96 diff -u -p -r1.99 vl.h
97 --- vl.h 18 Dec 2005 20:34:32 -0000 1.99
98 +++ vl.h 20 Dec 2005 21:11:38 -0000
99 @@ -279,6 +279,9 @@ typedef struct VLANClientState VLANClien
101 struct VLANClientState {
102 IOReadHandler *fd_read;
103 + /* Packets may still be sent if this returns zero. It's used to
104 + rate-limit the slirp code. */
105 + IOCanRWHandler *fd_can_read;
107 struct VLANClientState *next;
108 struct VLANState *vlan;
109 @@ -293,8 +296,12 @@ typedef struct VLANState {
111 VLANState *qemu_find_vlan(int id);
112 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
113 - IOReadHandler *fd_read, void *opaque);
114 + IOReadHandler *fd_read,
115 + IOCanRWHandler *fd_can_read,
117 +int qemu_can_send_packet(VLANClientState *vc);
118 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
119 +void qemu_handler_true(void *opaque);
121 void do_info_network(void);
124 ===================================================================
125 RCS file: /sources/qemu/qemu/hw/lance.c,v
126 retrieving revision 1.5
127 diff -u -p -r1.5 lance.c
128 --- hw/lance.c 15 Nov 2005 22:16:05 -0000 1.5
129 +++ hw/lance.c 20 Dec 2005 21:11:38 -0000
130 @@ -283,6 +283,11 @@ static CPUWriteMemoryFunc *lance_mem_wri
132 #define MIN_BUF_SIZE 60
134 +static void lance_can_receive(void *opaque)
139 static void lance_receive(void *opaque, const uint8_t *buf, int size)
141 LANCEState *s = opaque;
142 @@ -440,7 +445,7 @@ void lance_init(NICInfo *nd, int irq, ui
146 - s->vc = qemu_new_vlan_client(nd->vlan, lance_receive, s);
147 + s->vc = qemu_new_vlan_client(nd->vlan, lance_receive, lance_can_receive, s);
149 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
150 "lance macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
152 ===================================================================
153 RCS file: /sources/qemu/qemu/hw/ne2000.c,v
154 retrieving revision 1.17
155 diff -u -p -r1.17 ne2000.c
156 --- hw/ne2000.c 22 Nov 2005 20:16:13 -0000 1.17
157 +++ hw/ne2000.c 20 Dec 2005 21:11:38 -0000
158 @@ -200,14 +200,10 @@ static int compute_mcast_idx(const uint8
162 -/* return the max buffer size if the NE2000 can receive more data */
163 -static int ne2000_can_receive(void *opaque)
164 +static int ne2000_buffer_full(NE2000State *s)
166 - NE2000State *s = opaque;
167 int avail, index, boundary;
169 - if (s->cmd & E8390_STOP)
172 index = s->curpag << 8;
173 boundary = s->boundary << 8;
174 if (index < boundary)
175 @@ -215,8 +211,17 @@ static int ne2000_can_receive(void *opaq
177 avail = (s->stop - s->start) - (index - boundary);
178 if (avail < (MAX_ETH_FRAME_SIZE + 4))
180 - return MAX_ETH_FRAME_SIZE;
185 +static int ne2000_can_receive(void *opaque)
187 + NE2000State *s = opaque;
189 + if (s->cmd & E8390_STOP)
191 + return !ne2000_buffer_full(s);
194 #define MIN_BUF_SIZE 60
195 @@ -234,7 +239,7 @@ static void ne2000_receive(void *opaque,
196 printf("NE2000: received len=%d\n", size);
199 - if (!ne2000_can_receive(s))
200 + if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
203 /* XXX: check this */
204 @@ -715,7 +720,8 @@ void isa_ne2000_init(int base, int irq,
208 - s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive, s);
209 + s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive,
210 + ne2000_can_receive, s);
212 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
213 "ne2000 macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
214 @@ -784,7 +790,8 @@ void pci_ne2000_init(PCIBus *bus, NICInf
215 s->pci_dev = (PCIDevice *)d;
216 memcpy(s->macaddr, nd->macaddr, 6);
218 - s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive, s);
219 + s->vc = qemu_new_vlan_client(nd->vlan, ne2000_receive,
220 + ne2000_can_receive, s);
222 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
223 "ne2000 pci macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
224 Index: hw/smc91c111.c
225 ===================================================================
226 RCS file: /sources/qemu/qemu/hw/smc91c111.c,v
227 retrieving revision 1.2
228 diff -u -p -r1.2 smc91c111.c
229 --- hw/smc91c111.c 18 Dec 2005 17:39:52 -0000 1.2
230 +++ hw/smc91c111.c 20 Dec 2005 21:11:38 -0000
231 @@ -593,6 +593,17 @@ static uint32_t smc91c111_readl(void *op
235 +static int smc91c111_can_receive(void *opaque)
237 + smc91c111_state *s = (smc91c111_state *)opaque;
239 + if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST))
241 + if (s->allocated == (1 << NUM_PACKETS) - 1)
246 static void smc91c111_receive(void *opaque, const uint8_t *buf, int size)
248 smc91c111_state *s = (smc91c111_state *)opaque;
249 @@ -697,6 +708,7 @@ void smc91c111_init(NICInfo *nd, uint32_
253 - s->vc = qemu_new_vlan_client(nd->vlan, smc91c111_receive, s);
254 + s->vc = qemu_new_vlan_client(nd->vlan, smc91c111_receive,
255 + smc91c111_can_receive, s);
256 /* ??? Save/restore. */