Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 340267 | Differences between
and this patch

Collapse All | Expand All

(-)ppp-2.4.5.org/pppd/plugins/rp-pppoe/discovery.c (-73 / +96 lines)
Lines 196-201 Link Here
196
    }
196
    }
197
}
197
}
198
198
199
200
/**********************************************************************
201
*%FUNCTION: recvPacketForMe
202
*%ARGUMENTS:
203
* packet -- output parameter
204
* len -- output parameter length
205
* conn -- connection 
206
* timeout -- don't wait more than timeout
207
*%RETURNS:
208
* -1:	error
209
*  0:	timed out
210
*  1:	packet recived
211
*%DESCRIPTION:
212
* recive and filter junk packets
213
***********************************************************************/
214
215
static int
216
recvPacketForMe(PPPoEPacket *packet, int *len, PPPoEConnection *conn, int
217
{
218
219
    fd_set readable;
220
    int r;
221
    struct timeval tv;
222
    time_t start, now;
223
    int time_remain;
224
225
    start = time(&now);
226
    do {
227
	time(&now);
228
	time_remain = timeout - (int)difftime(now, start);
229
	if (time_remain > timeout) time_remain = timeout;
230
231
	if (time_remain <= 0) /* Timed out */
232
	    return 0;
233
    
234
        if (BPF_BUFFER_IS_EMPTY) {
235
            tv.tv_sec = time_remain;
236
            tv.tv_usec = 0;
237
238
            FD_ZERO(&readable);
239
            FD_SET(conn->discoverySocket, &readable);
240
241
	    r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
242
	    if (r < 0)
243
		if (errno == EINTR)
244
		{
245
		    continue;	/* interrupted, so retry */
246
		}else     	/* select error */
247
		{
248
		    error("pppoe: recvPacketForMe: select: %m");
249
		    return -1;
250
		}
251
252
            if (r == 0) return 0;        /* Timed out */
253
        }
254
255
        /* Get the packet */
256
        receivePacket(conn->discoverySocket, packet, len);
257
258
        /* Check length */
259
        if (ntohs(packet->length) + HDR_SIZE > *len) {
260
            error("Bogus PPPoE length field (%u)",
261
                   (unsigned int) ntohs(packet->length));
262
            continue;
263
        }
264
265
#ifdef USE_BPF
266
        /* If it's not a Discovery packet, loop again */
267
        if (etherType(&packet) != Eth_PPPOE_Discovery) continue;
268
#endif
269
270
        /* If it's not for us, loop again */
271
        }while ( ! packetIsForMe(conn, packet));
272
273
        return 1;
274
}
275
276
199
/***********************************************************************
277
/***********************************************************************
200
*%FUNCTION: sendPADI
278
*%FUNCTION: sendPADI
201
*%ARGUMENTS:
279
*%ARGUMENTS:
Lines 277-287 Link Here
277
void
355
void
278
waitForPADO(PPPoEConnection *conn, int timeout)
356
waitForPADO(PPPoEConnection *conn, int timeout)
279
{
357
{
280
    fd_set readable;
281
    int r;
358
    int r;
282
    struct timeval tv;
283
    PPPoEPacket packet;
359
    PPPoEPacket packet;
284
    int len;
360
    int len;
361
    time_t start, now;
362
    int time_remain;
285
363
286
    struct PacketCriteria pc;
364
    struct PacketCriteria pc;
287
    pc.conn          = conn;
365
    pc.conn          = conn;
Lines 291-332 Link Here
291
    pc.seenServiceName = 0;
369
    pc.seenServiceName = 0;
292
    conn->error = 0;
370
    conn->error = 0;
293
371
372
    start = time(&now);
294
    do {
373
    do {
295
	if (BPF_BUFFER_IS_EMPTY) {
374
	time(&now);
296
	    tv.tv_sec = timeout;
375
	time_remain = timeout - (int)difftime(now, start);
297
	    tv.tv_usec = 0;
376
	if (time_remain > timeout) time_remain = timeout;
298
299
	    FD_ZERO(&readable);
300
	    FD_SET(conn->discoverySocket, &readable);
301
302
	    while(1) {
303
		r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
304
		if (r >= 0 || errno != EINTR) break;
305
	    }
306
	    if (r < 0) {
307
		error("select (waitForPADO): %m");
308
		return;
309
	    }
310
	    if (r == 0) return;        /* Timed out */
311
	}
312
377
313
	/* Get the packet */
378
	if (time_remain <= 0) return; /* Timed out */
314
	receivePacket(conn->discoverySocket, &packet, &len);
315
379
316
	/* Check length */
380
	r = recvPacketForMe(&packet, &len, conn, time_remain);
317
	if (ntohs(packet.length) + HDR_SIZE > len) {
381
	if (r<=0) return;  /* Timed out or error */
318
	    error("Bogus PPPoE length field (%u)",
319
		   (unsigned int) ntohs(packet.length));
320
	    continue;
321
	}
322
323
#ifdef USE_BPF
324
	/* If it's not a Discovery packet, loop again */
325
	if (etherType(&packet) != Eth_PPPOE_Discovery) continue;
326
#endif
327
328
	/* If it's not for us, loop again */
329
	if (!packetIsForMe(conn, &packet)) continue;
330
382
331
	if (packet.code == CODE_PADO) {
383
	if (packet.code == CODE_PADO) {
332
	    if (NOT_UNICAST(packet.ethHdr.h_source)) {
384
	    if (NOT_UNICAST(packet.ethHdr.h_source)) {
Lines 447-498 Link Here
447
static void
499
static void
448
waitForPADS(PPPoEConnection *conn, int timeout)
500
waitForPADS(PPPoEConnection *conn, int timeout)
449
{
501
{
450
    fd_set readable;
451
    int r;
502
    int r;
452
    struct timeval tv;
453
    PPPoEPacket packet;
503
    PPPoEPacket packet;
454
    int len;
504
    int len;
505
    time_t start, now;
506
    int time_remain;
455
507
508
    start = time(&now);
456
    conn->error = 0;
509
    conn->error = 0;
457
    do {
510
    do {
458
	if (BPF_BUFFER_IS_EMPTY) {
511
	time(&now);
459
	    tv.tv_sec = timeout;
512
	time_remain = timeout - (int)difftime(now, start);
460
	    tv.tv_usec = 0;
513
	if (time_remain > timeout) time_remain = timeout;
461
462
	    FD_ZERO(&readable);
463
	    FD_SET(conn->discoverySocket, &readable);
464
465
	    while(1) {
466
		r = select(conn->discoverySocket+1, &readable, NULL, NULL, &tv);
467
		if (r >= 0 || errno != EINTR) break;
468
	    }
469
	    if (r < 0) {
470
		error("select (waitForPADS): %m");
471
		return;
472
	    }
473
	    if (r == 0) return;
474
	}
475
476
	/* Get the packet */
477
	receivePacket(conn->discoverySocket, &packet, &len);
478
479
	/* Check length */
480
	if (ntohs(packet.length) + HDR_SIZE > len) {
481
	    error("Bogus PPPoE length field (%u)",
482
		   (unsigned int) ntohs(packet.length));
483
	    continue;
484
	}
485
486
#ifdef USE_BPF
487
	/* If it's not a Discovery packet, loop again */
488
	if (etherType(&packet) != Eth_PPPOE_Discovery) continue;
489
#endif
490
514
491
	/* If it's not from the AC, it's not for me */
515
	if (time_remain <= 0) return; /* Timed out */
492
	if (memcmp(packet.ethHdr.h_source, conn->peerEth, ETH_ALEN)) continue;
493
516
494
	/* If it's not for us, loop again */
517
	r = recvPacketForMe(&packet, &len, conn, time_remain);
495
	if (!packetIsForMe(conn, &packet)) continue;
518
	if (r<=0) return;  /* Timed out or error */
496
519
497
	/* Is it PADS?  */
520
	/* Is it PADS?  */
498
	if (packet.code == CODE_PADS) {
521
	if (packet.code == CODE_PADS) {

Return to bug 340267