13
13
#include "network.h"
14
14
15
15
#include "pimd.h"
16
- #include "pim_instance.h"
17
16
#include "pim_pim.h"
18
17
#include "pim_time.h"
19
18
#include "pim_iface.h"
@@ -355,30 +354,19 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len,
355
354
}
356
355
}
357
356
358
- static void pim_sock_read_on (struct interface * ifp );
359
-
360
- static void pim_sock_read (struct event * t )
357
+ int pim_sock_read_helper (int fd , struct pim_instance * pim , bool is_mcast )
361
358
{
362
- struct interface * ifp , * orig_ifp ;
363
- struct pim_interface * pim_ifp ;
364
- int fd ;
359
+ struct interface * ifp = NULL ;
365
360
struct sockaddr_storage from ;
366
361
struct sockaddr_storage to ;
367
362
socklen_t fromlen = sizeof (from );
368
363
socklen_t tolen = sizeof (to );
369
364
uint8_t buf [PIM_PIM_BUFSIZE_READ ];
370
365
int len ;
371
366
ifindex_t ifindex = -1 ;
372
- int result = -1 ; /* defaults to bad */
373
- static long long count = 0 ;
374
- int cont = 1 ;
375
-
376
- orig_ifp = ifp = EVENT_ARG (t );
377
- fd = EVENT_FD (t );
378
-
379
- pim_ifp = ifp -> info ;
367
+ int i ;
380
368
381
- while ( cont ) {
369
+ for ( i = 0 ; i < router -> packet_process ; i ++ ) {
382
370
pim_sgaddr sg ;
383
371
384
372
len = pim_socket_recvfromto (fd , buf , sizeof (buf ), & from ,
@@ -392,7 +380,7 @@ static void pim_sock_read(struct event *t)
392
380
if (PIM_DEBUG_PIM_PACKETS )
393
381
zlog_debug ("Received errno: %d %s" , errno ,
394
382
safe_strerror (errno ));
395
- goto done ;
383
+ return -1 ;
396
384
}
397
385
398
386
/*
@@ -401,14 +389,21 @@ static void pim_sock_read(struct event *t)
401
389
* the right ifindex, so just use it. We know
402
390
* it's the right interface because we bind to it
403
391
*/
404
- ifp = if_lookup_by_index (ifindex , pim_ifp -> pim -> vrf -> vrf_id );
405
- if (!ifp || !ifp -> info ) {
392
+ if (pim != NULL )
393
+ ifp = if_lookup_by_index (ifindex , pim -> vrf -> vrf_id );
394
+
395
+ /*
396
+ * unicast BSM pkts (C-RP) may arrive on non pim interfaces
397
+ * mcast pkts are only expected in pim interfaces
398
+ */
399
+ if (!ifp || (is_mcast && !ifp -> info )) {
406
400
if (PIM_DEBUG_PIM_PACKETS )
407
- zlog_debug (
408
- "%s: Received incoming pim packet on interface(%s:%d) not yet configured for pim" ,
409
- __func__ , ifp ? ifp -> name : "Unknown" ,
410
- ifindex );
411
- goto done ;
401
+ zlog_debug ("%s: Received incoming pim packet on interface(%s:%d)%s" ,
402
+ __func__ ,
403
+ ifp ? ifp -> name : "Unknown" , ifindex ,
404
+ is_mcast ? " not yet configured for pim"
405
+ : "" );
406
+ return -1 ;
412
407
}
413
408
#if PIM_IPV == 4
414
409
sg .src = ((struct sockaddr_in * )& from )-> sin_addr ;
@@ -418,27 +413,34 @@ static void pim_sock_read(struct event *t)
418
413
sg .grp = ((struct sockaddr_in6 * )& to )-> sin6_addr ;
419
414
#endif
420
415
421
- int fail = pim_pim_packet (ifp , buf , len , sg , true );
416
+ int fail = pim_pim_packet (ifp , buf , len , sg , is_mcast );
422
417
if (fail ) {
423
418
if (PIM_DEBUG_PIM_PACKETS )
424
419
zlog_debug ("%s: pim_pim_packet() return=%d" ,
425
420
__func__ , fail );
426
- goto done ;
421
+ return -1 ;
427
422
}
428
-
429
- count ++ ;
430
- if (count % router -> packet_process == 0 )
431
- cont = 0 ;
432
423
}
424
+ return 0 ;
425
+ }
426
+
427
+ static void pim_sock_read_on (struct interface * ifp );
428
+
429
+ static void pim_sock_read (struct event * t )
430
+ {
431
+ struct interface * ifp ;
432
+ struct pim_interface * pim_ifp ;
433
+ int fd ;
433
434
434
- result = 0 ; /* good */
435
+ ifp = EVENT_ARG (t );
436
+ fd = EVENT_FD (t );
435
437
436
- done :
437
- pim_sock_read_on (orig_ifp );
438
+ pim_ifp = ifp -> info ;
438
439
439
- if (result ) {
440
+ if (pim_sock_read_helper ( fd , pim_ifp -> pim , true) == 0 )
440
441
++ pim_ifp -> pim_ifstat_hello_recvfail ;
441
- }
442
+
443
+ pim_sock_read_on (ifp );
442
444
}
443
445
444
446
static void pim_sock_read_on (struct interface * ifp )
0 commit comments