Sat Jan 22 19:35:01 2011 UTC ()
use SLIST_FOREACH_SAFE when deleting a peer in loop


(kefren)
diff -r1.3 -r1.4 src/usr.sbin/ldpd/socketops.c

cvs diff -r1.3 -r1.4 src/usr.sbin/ldpd/socketops.c (expand / switch to unified diff)

--- src/usr.sbin/ldpd/socketops.c 2010/12/30 11:29:21 1.3
+++ src/usr.sbin/ldpd/socketops.c 2011/01/22 19:35:00 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: socketops.c,v 1.3 2010/12/30 11:29:21 kefren Exp $ */ 1/* $NetBSD: socketops.c,v 1.4 2011/01/22 19:35:00 kefren Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mihai Chelaru <kefren@NetBSD.org> 8 * by Mihai Chelaru <kefren@NetBSD.org>
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -447,49 +447,48 @@ recv_pdu(int sock) @@ -447,49 +447,48 @@ recv_pdu(int sock)
447 447
448 448
449 debugp("Read %d bytes from address %s Length: %.4d Version: %d\n", 449 debugp("Read %d bytes from address %s Length: %.4d Version: %d\n",
450 c, inet_ntoa(rpdu.ldp_id), rpdu.length, rpdu.version); 450 c, inet_ntoa(rpdu.ldp_id), rpdu.length, rpdu.version);
451 451
452 /* Fill the TLV messages */ 452 /* Fill the TLV messages */
453 t = get_hello_tlv(recvspace + i, c - i); 453 t = get_hello_tlv(recvspace + i, c - i);
454 run_ldp_hello(&rpdu, t, &fromsa.sin_addr, &local_addr, sock); 454 run_ldp_hello(&rpdu, t, &fromsa.sin_addr, &local_addr, sock);
455} 455}
456 456
457void  457void
458send_hello_alarm(int unused) 458send_hello_alarm(int unused)
459{ 459{
460 struct ldp_peer *p; 460 struct ldp_peer *p, *ptmp;
461 struct hello_info *hi, *hinext; 461 struct hello_info *hi, *hinext;
462 time_t t = time(NULL); 462 time_t t = time(NULL);
463 int olderrno = errno; 463 int olderrno = errno;
464 464
465 /* Send hellos */ 465 /* Send hellos */
466 if (!(t % ldp_hello_time)) 466 if (!(t % ldp_hello_time))
467 send_hello(); 467 send_hello();
468 468
469 /* Timeout -- */ 469 /* Timeout -- */
470 SLIST_FOREACH(p, &ldp_peer_head, peers) 470 SLIST_FOREACH(p, &ldp_peer_head, peers)
471 p->timeout--; 471 p->timeout--;
472 472
473 /* Check for timeout */ 473 /* Check for timeout */
474check_peer: 474 SLIST_FOREACH_SAFE(p, &ldp_peer_head, peers, ptmp)
475 SLIST_FOREACH(p, &ldp_peer_head, peers) 
476 if (p->timeout < 1) 475 if (p->timeout < 1)
477 switch (p->state) { 476 switch (p->state) {
478 case LDP_PEER_HOLDDOWN: 477 case LDP_PEER_HOLDDOWN:
479 debugp("LDP holddown expired for peer %s\n", 478 debugp("LDP holddown expired for peer %s\n",
480 inet_ntoa(p->ldp_id)); 479 inet_ntoa(p->ldp_id));
481 ldp_peer_delete(p); 480 ldp_peer_delete(p);
482 goto check_peer; 481 break;
483 case LDP_PEER_ESTABLISHED: 482 case LDP_PEER_ESTABLISHED:
484 case LDP_PEER_CONNECTED: 483 case LDP_PEER_CONNECTED:
485 send_notification(p, 0, 484 send_notification(p, 0,
486 NOTIF_KEEP_ALIVE_TIMER_EXPIRED); 485 NOTIF_KEEP_ALIVE_TIMER_EXPIRED);
487 warnp("Keepalive expired for %s\n", 486 warnp("Keepalive expired for %s\n",
488 inet_ntoa(p->ldp_id)); 487 inet_ntoa(p->ldp_id));
489 ldp_peer_holddown(p); 488 ldp_peer_holddown(p);
490 break; 489 break;
491 } /* switch */ 490 } /* switch */
492 491
493 /* send keepalives */ 492 /* send keepalives */
494 if (!(t % ldp_keepalive_time)) { 493 if (!(t % ldp_keepalive_time)) {
495 SLIST_FOREACH(p, &ldp_peer_head, peers)  494 SLIST_FOREACH(p, &ldp_peer_head, peers)