1313#include "network.h"
1414
1515#include "pimd.h"
16- #include "pim_instance.h"
1716#include "pim_pim.h"
1817#include "pim_time.h"
1918#include "pim_iface.h"
@@ -355,30 +354,19 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len,
355354 }
356355}
357356
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 )
361358{
362- struct interface * ifp , * orig_ifp ;
363- struct pim_interface * pim_ifp ;
364- int fd ;
359+ struct interface * ifp = NULL ;
365360 struct sockaddr_storage from ;
366361 struct sockaddr_storage to ;
367362 socklen_t fromlen = sizeof (from );
368363 socklen_t tolen = sizeof (to );
369364 uint8_t buf [PIM_PIM_BUFSIZE_READ ];
370365 int len ;
371366 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 ;
380368
381- while ( cont ) {
369+ for ( i = 0 ; i < router -> packet_process ; i ++ ) {
382370 pim_sgaddr sg ;
383371
384372 len = pim_socket_recvfromto (fd , buf , sizeof (buf ), & from ,
@@ -392,7 +380,7 @@ static void pim_sock_read(struct event *t)
392380 if (PIM_DEBUG_PIM_PACKETS )
393381 zlog_debug ("Received errno: %d %s" , errno ,
394382 safe_strerror (errno ));
395- goto done ;
383+ return -1 ;
396384 }
397385
398386 /*
@@ -401,14 +389,21 @@ static void pim_sock_read(struct event *t)
401389 * the right ifindex, so just use it. We know
402390 * it's the right interface because we bind to it
403391 */
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 )) {
406400 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 ;
412407 }
413408#if PIM_IPV == 4
414409 sg .src = ((struct sockaddr_in * )& from )-> sin_addr ;
@@ -418,27 +413,34 @@ static void pim_sock_read(struct event *t)
418413 sg .grp = ((struct sockaddr_in6 * )& to )-> sin6_addr ;
419414#endif
420415
421- int fail = pim_pim_packet (ifp , buf , len , sg , true );
416+ int fail = pim_pim_packet (ifp , buf , len , sg , is_mcast );
422417 if (fail ) {
423418 if (PIM_DEBUG_PIM_PACKETS )
424419 zlog_debug ("%s: pim_pim_packet() return=%d" ,
425420 __func__ , fail );
426- goto done ;
421+ return -1 ;
427422 }
428-
429- count ++ ;
430- if (count % router -> packet_process == 0 )
431- cont = 0 ;
432423 }
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 ;
433434
434- result = 0 ; /* good */
435+ ifp = EVENT_ARG (t );
436+ fd = EVENT_FD (t );
435437
436- done :
437- pim_sock_read_on (orig_ifp );
438+ pim_ifp = ifp -> info ;
438439
439- if (result ) {
440+ if (pim_sock_read_helper ( fd , pim_ifp -> pim , true) == 0 )
440441 ++ pim_ifp -> pim_ifstat_hello_recvfail ;
441- }
442+
443+ pim_sock_read_on (ifp );
442444}
443445
444446static void pim_sock_read_on (struct interface * ifp )
0 commit comments