3 * Copyright (C) 2008 Everton da Silva Marques
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include "pim_iface.h"
35 #include "pim_neighbor.h"
36 #include "pim_hello.h"
38 #include "pim_assert.h"
40 #include "pim_register.h"
41 #include "pim_errors.h"
43 static int on_pim_hello_send(struct thread
*t
);
44 static int pim_hello_send(struct interface
*ifp
, uint16_t holdtime
);
46 static const char *pim_pim_msgtype2str(enum pim_msg_type type
)
49 case PIM_MSG_TYPE_HELLO
:
51 case PIM_MSG_TYPE_REGISTER
:
53 case PIM_MSG_TYPE_REG_STOP
:
55 case PIM_MSG_TYPE_JOIN_PRUNE
:
57 case PIM_MSG_TYPE_BOOTSTRAP
:
59 case PIM_MSG_TYPE_ASSERT
:
61 case PIM_MSG_TYPE_GRAFT
:
63 case PIM_MSG_TYPE_GRAFT_ACK
:
65 case PIM_MSG_TYPE_CANDIDATE
:
72 static void sock_close(struct interface
*ifp
)
74 struct pim_interface
*pim_ifp
= ifp
->info
;
76 if (PIM_DEBUG_PIM_TRACE
) {
77 if (pim_ifp
->t_pim_sock_read
) {
79 "Cancelling READ event for PIM socket fd=%d on interface %s",
80 pim_ifp
->pim_sock_fd
, ifp
->name
);
83 THREAD_OFF(pim_ifp
->t_pim_sock_read
);
85 if (PIM_DEBUG_PIM_TRACE
) {
86 if (pim_ifp
->t_pim_hello_timer
) {
88 "Cancelling PIM hello timer for interface %s",
92 THREAD_OFF(pim_ifp
->t_pim_hello_timer
);
94 if (PIM_DEBUG_PIM_TRACE
) {
95 zlog_debug("Deleting PIM socket fd=%d on interface %s",
96 pim_ifp
->pim_sock_fd
, ifp
->name
);
100 * If the fd is already deleted no need to do anything here
102 if (pim_ifp
->pim_sock_fd
> 0 && close(pim_ifp
->pim_sock_fd
)) {
104 "Failure closing PIM socket fd=%d on interface %s: errno=%d: %s",
105 pim_ifp
->pim_sock_fd
, ifp
->name
, errno
,
106 safe_strerror(errno
));
109 pim_ifp
->pim_sock_fd
= -1;
110 pim_ifp
->pim_sock_creation
= 0;
113 void pim_sock_delete(struct interface
*ifp
, const char *delete_message
)
115 zlog_info("PIM INTERFACE DOWN: on interface %s: %s", ifp
->name
,
119 flog_err(PIM_ERR_CONFIG
,
120 "%s: %s: but PIM not enabled on interface %s (!)",
121 __PRETTY_FUNCTION__
, delete_message
, ifp
->name
);
126 RFC 4601: 4.3.1. Sending Hello Messages
128 Before an interface goes down or changes primary IP address, a Hello
129 message with a zero HoldTime should be sent immediately (with the
130 old IP address if the IP address changed).
132 pim_hello_send(ifp
, 0 /* zero-sec holdtime */);
134 pim_neighbor_delete_all(ifp
, delete_message
);
139 int pim_pim_packet(struct interface
*ifp
, uint8_t *buf
, size_t len
)
142 size_t ip_hlen
; /* ip header length in bytes */
143 char src_str
[INET_ADDRSTRLEN
];
144 char dst_str
[INET_ADDRSTRLEN
];
147 uint16_t pim_checksum
; /* received checksum */
148 uint16_t checksum
; /* computed checksum */
149 struct pim_neighbor
*neigh
;
150 struct pim_msg_header
*header
;
152 if (len
< sizeof(*ip_hdr
)) {
153 if (PIM_DEBUG_PIM_PACKETS
)
155 "PIM packet size=%zu shorter than minimum=%zu",
156 len
, sizeof(*ip_hdr
));
160 ip_hdr
= (struct ip
*)buf
;
161 ip_hlen
= ip_hdr
->ip_hl
<< 2; /* ip_hl gives length in 4-byte words */
163 pim_msg
= buf
+ ip_hlen
;
164 pim_msg_len
= len
- ip_hlen
;
166 header
= (struct pim_msg_header
*)pim_msg
;
167 if (pim_msg_len
< PIM_PIM_MIN_LEN
) {
168 if (PIM_DEBUG_PIM_PACKETS
)
170 "PIM message size=%d shorter than minimum=%d",
171 pim_msg_len
, PIM_PIM_MIN_LEN
);
175 if (header
->ver
!= PIM_PROTO_VERSION
) {
176 if (PIM_DEBUG_PIM_PACKETS
)
178 "Ignoring PIM pkt from %s with unsupported version: %d",
179 ifp
->name
, header
->ver
);
183 /* save received checksum */
184 pim_checksum
= header
->checksum
;
186 /* for computing checksum */
187 header
->checksum
= 0;
189 if (header
->type
== PIM_MSG_TYPE_REGISTER
) {
190 /* First 8 byte header checksum */
191 checksum
= in_cksum(pim_msg
, PIM_MSG_REGISTER_LEN
);
192 if (checksum
!= pim_checksum
) {
193 checksum
= in_cksum(pim_msg
, pim_msg_len
);
194 if (checksum
!= pim_checksum
) {
195 if (PIM_DEBUG_PIM_PACKETS
)
197 "Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x",
198 ifp
->name
, pim_checksum
,
205 checksum
= in_cksum(pim_msg
, pim_msg_len
);
206 if (checksum
!= pim_checksum
) {
207 if (PIM_DEBUG_PIM_PACKETS
)
209 "Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x",
210 ifp
->name
, pim_checksum
, checksum
);
216 if (PIM_DEBUG_PIM_PACKETS
) {
217 pim_inet4_dump("<src?>", ip_hdr
->ip_src
, src_str
,
219 pim_inet4_dump("<dst?>", ip_hdr
->ip_dst
, dst_str
,
222 "Recv PIM %s packet from %s to %s on %s: ttl=%d pim_version=%d pim_msg_size=%d checksum=%x",
223 pim_pim_msgtype2str(header
->type
), src_str
, dst_str
,
224 ifp
->name
, ip_hdr
->ip_ttl
, header
->ver
, pim_msg_len
,
226 if (PIM_DEBUG_PIM_PACKETDUMP_RECV
) {
227 pim_pkt_dump(__PRETTY_FUNCTION__
, pim_msg
, pim_msg_len
);
231 switch (header
->type
) {
232 case PIM_MSG_TYPE_HELLO
:
233 return pim_hello_recv(ifp
, ip_hdr
->ip_src
,
234 pim_msg
+ PIM_MSG_HEADER_LEN
,
235 pim_msg_len
- PIM_MSG_HEADER_LEN
);
237 case PIM_MSG_TYPE_REGISTER
:
238 return pim_register_recv(ifp
, ip_hdr
->ip_dst
, ip_hdr
->ip_src
,
239 pim_msg
+ PIM_MSG_HEADER_LEN
,
240 pim_msg_len
- PIM_MSG_HEADER_LEN
);
242 case PIM_MSG_TYPE_REG_STOP
:
243 return pim_register_stop_recv(ifp
, pim_msg
+ PIM_MSG_HEADER_LEN
,
244 pim_msg_len
- PIM_MSG_HEADER_LEN
);
246 case PIM_MSG_TYPE_JOIN_PRUNE
:
247 neigh
= pim_neighbor_find(ifp
, ip_hdr
->ip_src
);
249 if (PIM_DEBUG_PIM_PACKETS
)
251 "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
252 __FILE__
, __PRETTY_FUNCTION__
,
253 header
->type
, src_str
, ifp
->name
);
256 pim_neighbor_timer_reset(neigh
, neigh
->holdtime
);
257 return pim_joinprune_recv(ifp
, neigh
, ip_hdr
->ip_src
,
258 pim_msg
+ PIM_MSG_HEADER_LEN
,
259 pim_msg_len
- PIM_MSG_HEADER_LEN
);
261 case PIM_MSG_TYPE_ASSERT
:
262 neigh
= pim_neighbor_find(ifp
, ip_hdr
->ip_src
);
264 if (PIM_DEBUG_PIM_PACKETS
)
266 "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
267 __FILE__
, __PRETTY_FUNCTION__
,
268 header
->type
, src_str
, ifp
->name
);
271 pim_neighbor_timer_reset(neigh
, neigh
->holdtime
);
272 return pim_assert_recv(ifp
, neigh
, ip_hdr
->ip_src
,
273 pim_msg
+ PIM_MSG_HEADER_LEN
,
274 pim_msg_len
- PIM_MSG_HEADER_LEN
);
277 if (PIM_DEBUG_PIM_PACKETS
) {
279 "Recv PIM packet type %d which is not currently understood",
287 static void pim_sock_read_on(struct interface
*ifp
);
289 static int pim_sock_read(struct thread
*t
)
291 struct interface
*ifp
, *orig_ifp
;
292 struct pim_interface
*pim_ifp
;
294 struct sockaddr_in from
;
295 struct sockaddr_in to
;
296 socklen_t fromlen
= sizeof(from
);
297 socklen_t tolen
= sizeof(to
);
298 uint8_t buf
[PIM_PIM_BUFSIZE_READ
];
300 ifindex_t ifindex
= -1;
301 int result
= -1; /* defaults to bad */
302 static long long count
= 0;
305 orig_ifp
= ifp
= THREAD_ARG(t
);
311 len
= pim_socket_recvfromto(fd
, buf
, sizeof(buf
), &from
,
312 &fromlen
, &to
, &tolen
, &ifindex
);
316 if (errno
== EWOULDBLOCK
|| errno
== EAGAIN
)
319 if (PIM_DEBUG_PIM_PACKETS
)
320 zlog_debug("Received errno: %d %s", errno
,
321 safe_strerror(errno
));
326 * What? So with vrf's the incoming packet is received
327 * on the vrf interface but recvfromto above returns
328 * the right ifindex, so just use it. We know
329 * it's the right interface because we bind to it
331 ifp
= if_lookup_by_index(ifindex
, pim_ifp
->pim
->vrf_id
);
332 if (!ifp
|| !ifp
->info
) {
333 if (PIM_DEBUG_PIM_PACKETS
)
335 "%s: Received incoming pim packet on interface not yet configured for pim",
336 __PRETTY_FUNCTION__
);
339 int fail
= pim_pim_packet(ifp
, buf
, len
);
341 if (PIM_DEBUG_PIM_PACKETS
)
342 zlog_debug("%s: pim_pim_packet() return=%d",
343 __PRETTY_FUNCTION__
, fail
);
348 if (count
% qpim_packet_process
== 0)
352 result
= 0; /* good */
355 pim_sock_read_on(orig_ifp
);
358 ++pim_ifp
->pim_ifstat_hello_recvfail
;
364 static void pim_sock_read_on(struct interface
*ifp
)
366 struct pim_interface
*pim_ifp
;
373 if (PIM_DEBUG_PIM_TRACE_DETAIL
) {
374 zlog_debug("Scheduling READ event on PIM socket fd=%d",
375 pim_ifp
->pim_sock_fd
);
377 pim_ifp
->t_pim_sock_read
= NULL
;
378 thread_add_read(master
, pim_sock_read
, ifp
, pim_ifp
->pim_sock_fd
,
379 &pim_ifp
->t_pim_sock_read
);
382 static int pim_sock_open(struct interface
*ifp
)
385 struct pim_interface
*pim_ifp
= ifp
->info
;
387 fd
= pim_socket_mcast(IPPROTO_PIM
, pim_ifp
->primary_address
, ifp
,
392 if (pim_socket_join(fd
, qpim_all_pim_routers_addr
,
393 pim_ifp
->primary_address
, ifp
->ifindex
)) {
401 void pim_ifstat_reset(struct interface
*ifp
)
403 struct pim_interface
*pim_ifp
;
412 pim_ifp
->pim_ifstat_start
= pim_time_monotonic_sec();
413 pim_ifp
->pim_ifstat_hello_sent
= 0;
414 pim_ifp
->pim_ifstat_hello_sendfail
= 0;
415 pim_ifp
->pim_ifstat_hello_recv
= 0;
416 pim_ifp
->pim_ifstat_hello_recvfail
= 0;
419 void pim_sock_reset(struct interface
*ifp
)
421 struct pim_interface
*pim_ifp
;
428 pim_ifp
->primary_address
= pim_find_primary_addr(ifp
);
430 pim_ifp
->pim_sock_fd
= -1;
431 pim_ifp
->pim_sock_creation
= 0;
432 pim_ifp
->t_pim_sock_read
= NULL
;
434 pim_ifp
->t_pim_hello_timer
= NULL
;
435 pim_ifp
->pim_hello_period
= PIM_DEFAULT_HELLO_PERIOD
;
436 pim_ifp
->pim_default_holdtime
=
437 -1; /* unset: means 3.5 * pim_hello_period */
438 pim_ifp
->pim_triggered_hello_delay
= PIM_DEFAULT_TRIGGERED_HELLO_DELAY
;
439 pim_ifp
->pim_dr_priority
= PIM_DEFAULT_DR_PRIORITY
;
440 pim_ifp
->pim_propagation_delay_msec
=
441 PIM_DEFAULT_PROPAGATION_DELAY_MSEC
;
442 pim_ifp
->pim_override_interval_msec
=
443 PIM_DEFAULT_OVERRIDE_INTERVAL_MSEC
;
444 if (PIM_DEFAULT_CAN_DISABLE_JOIN_SUPPRESSION
) {
445 PIM_IF_DO_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp
->options
);
447 PIM_IF_DONT_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp
->options
);
450 /* neighbors without lan_delay */
451 pim_ifp
->pim_number_of_nonlandelay_neighbors
= 0;
452 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
= 0;
453 pim_ifp
->pim_neighbors_highest_override_interval_msec
= 0;
456 pim_ifp
->pim_dr_election_last
= 0; /* timestamp */
457 pim_ifp
->pim_dr_election_count
= 0;
458 pim_ifp
->pim_dr_election_changes
= 0;
459 pim_ifp
->pim_dr_num_nondrpri_neighbors
=
460 0; /* neighbors without dr_pri */
461 pim_ifp
->pim_dr_addr
= pim_ifp
->primary_address
;
463 pim_ifstat_reset(ifp
);
466 static uint16_t ip_id
= 0;
469 static int pim_msg_send_frame(int fd
, char *buf
, size_t len
,
470 struct sockaddr
*dst
, size_t salen
)
472 struct ip
*ip
= (struct ip
*)buf
;
474 while (sendto(fd
, buf
, len
, MSG_DONTWAIT
, dst
, salen
) < 0) {
475 char dst_str
[INET_ADDRSTRLEN
];
479 size_t hdrsize
= sizeof(struct ip
);
480 size_t newlen1
= ((len
- hdrsize
) / 2) & 0xFFF8;
481 size_t sendlen
= newlen1
+ hdrsize
;
482 size_t offset
= ntohs(ip
->ip_off
);
484 ip
->ip_len
= htons(sendlen
);
485 ip
->ip_off
= htons(offset
| IP_MF
);
486 if (pim_msg_send_frame(fd
, buf
, sendlen
, dst
, salen
)
488 struct ip
*ip2
= (struct ip
*)(buf
+ newlen1
);
489 size_t newlen2
= len
- sendlen
;
490 sendlen
= newlen2
+ hdrsize
;
492 memcpy(ip2
, ip
, hdrsize
);
493 ip2
->ip_len
= htons(sendlen
);
494 ip2
->ip_off
= htons(offset
+ (newlen1
>> 3));
495 return pim_msg_send_frame(fd
, (char *)ip2
,
496 sendlen
, dst
, salen
);
503 if (PIM_DEBUG_PIM_PACKETS
) {
504 pim_inet4_dump("<dst?>", ip
->ip_dst
, dst_str
,
507 "%s: sendto() failure to %s: fd=%d msg_size=%zd: errno=%d: %s",
508 __PRETTY_FUNCTION__
, dst_str
, fd
, len
,
509 errno
, safe_strerror(errno
));
519 int pim_msg_send(int fd
, struct in_addr src
, struct in_addr dst
,
520 uint8_t *pim_msg
, int pim_msg_size
, const char *ifname
)
522 struct sockaddr_in to
;
524 unsigned char buffer
[10000];
525 unsigned char *msg_start
;
527 struct pim_msg_header
*header
;
530 memset(buffer
, 0, 10000);
531 int sendlen
= sizeof(struct ip
) + pim_msg_size
;
533 msg_start
= buffer
+ sizeof(struct ip
);
534 memcpy(msg_start
, pim_msg
, pim_msg_size
);
536 header
= (struct pim_msg_header
*)pim_msg
;
538 * Omnios apparently doesn't have a #define for IP default
539 * ttl that is the same as all other platforms.
544 /* TTL for packets destine to ALL-PIM-ROUTERS is 1 */
545 switch (header
->type
) {
546 case PIM_MSG_TYPE_HELLO
:
547 case PIM_MSG_TYPE_JOIN_PRUNE
:
548 case PIM_MSG_TYPE_BOOTSTRAP
:
549 case PIM_MSG_TYPE_ASSERT
:
552 case PIM_MSG_TYPE_REGISTER
:
553 case PIM_MSG_TYPE_REG_STOP
:
554 case PIM_MSG_TYPE_GRAFT
:
555 case PIM_MSG_TYPE_GRAFT_ACK
:
556 case PIM_MSG_TYPE_CANDIDATE
:
564 ip
= (struct ip
*)buffer
;
565 ip
->ip_id
= htons(++ip_id
);
568 ip
->ip_p
= PIM_IP_PROTO_PIM
;
572 ip
->ip_len
= htons(sendlen
);
574 if (PIM_DEBUG_PIM_PACKETS
) {
575 struct pim_msg_header
*header
=
576 (struct pim_msg_header
*)pim_msg
;
577 char dst_str
[INET_ADDRSTRLEN
];
578 pim_inet4_dump("<dst?>", dst
, dst_str
, sizeof(dst_str
));
579 zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x",
580 __PRETTY_FUNCTION__
, dst_str
, ifname
, pim_msg_size
,
584 memset(&to
, 0, sizeof(to
));
585 to
.sin_family
= AF_INET
;
589 if (PIM_DEBUG_PIM_PACKETDUMP_SEND
) {
590 pim_pkt_dump(__PRETTY_FUNCTION__
, pim_msg
, pim_msg_size
);
593 pim_msg_send_frame(fd
, (char *)buffer
, sendlen
, (struct sockaddr
*)&to
,
598 static int hello_send(struct interface
*ifp
, uint16_t holdtime
)
600 uint8_t pim_msg
[PIM_PIM_BUFSIZE_WRITE
];
601 struct pim_interface
*pim_ifp
;
607 if (PIM_DEBUG_PIM_HELLO
) {
608 char dst_str
[INET_ADDRSTRLEN
];
609 pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr
, dst_str
,
612 "%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d",
613 __PRETTY_FUNCTION__
, dst_str
, ifp
->name
, holdtime
,
614 pim_ifp
->pim_propagation_delay_msec
,
615 pim_ifp
->pim_override_interval_msec
,
616 PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(
618 pim_ifp
->pim_dr_priority
, pim_ifp
->pim_generation_id
,
619 listcount(ifp
->connected
));
622 pim_tlv_size
= pim_hello_build_tlv(
623 ifp
, pim_msg
+ PIM_PIM_MIN_LEN
,
624 sizeof(pim_msg
) - PIM_PIM_MIN_LEN
, holdtime
,
625 pim_ifp
->pim_dr_priority
, pim_ifp
->pim_generation_id
,
626 pim_ifp
->pim_propagation_delay_msec
,
627 pim_ifp
->pim_override_interval_msec
,
628 PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp
->options
));
629 if (pim_tlv_size
< 0) {
633 pim_msg_size
= pim_tlv_size
+ PIM_PIM_MIN_LEN
;
635 zassert(pim_msg_size
>= PIM_PIM_MIN_LEN
);
636 zassert(pim_msg_size
<= PIM_PIM_BUFSIZE_WRITE
);
638 pim_msg_build_header(pim_msg
, pim_msg_size
, PIM_MSG_TYPE_HELLO
);
640 if (pim_msg_send(pim_ifp
->pim_sock_fd
, pim_ifp
->primary_address
,
641 qpim_all_pim_routers_addr
, pim_msg
, pim_msg_size
,
643 if (PIM_DEBUG_PIM_HELLO
) {
645 "%s: could not send PIM message on interface %s",
646 __PRETTY_FUNCTION__
, ifp
->name
);
654 static int pim_hello_send(struct interface
*ifp
, uint16_t holdtime
)
656 struct pim_interface
*pim_ifp
= ifp
->info
;
658 if (pim_if_is_loopback(ifp
))
661 if (hello_send(ifp
, holdtime
)) {
662 ++pim_ifp
->pim_ifstat_hello_sendfail
;
664 if (PIM_DEBUG_PIM_HELLO
) {
665 zlog_warn("Could not send PIM hello on interface %s",
671 ++pim_ifp
->pim_ifstat_hello_sent
;
676 static void hello_resched(struct interface
*ifp
)
678 struct pim_interface
*pim_ifp
;
682 if (PIM_DEBUG_PIM_HELLO
) {
683 zlog_debug("Rescheduling %d sec hello on interface %s",
684 pim_ifp
->pim_hello_period
, ifp
->name
);
686 THREAD_OFF(pim_ifp
->t_pim_hello_timer
);
687 thread_add_timer(master
, on_pim_hello_send
, ifp
,
688 pim_ifp
->pim_hello_period
,
689 &pim_ifp
->t_pim_hello_timer
);
695 static int on_pim_hello_send(struct thread
*t
)
697 struct pim_interface
*pim_ifp
;
698 struct interface
*ifp
;
704 * Schedule next hello
711 return pim_hello_send(ifp
, PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
715 RFC 4601: 4.3.1. Sending Hello Messages
717 Thus, if a router needs to send a Join/Prune or Assert message on an
718 interface on which it has not yet sent a Hello message with the
719 currently configured IP address, then it MUST immediately send the
720 relevant Hello message without waiting for the Hello Timer to
721 expire, followed by the Join/Prune or Assert message.
723 void pim_hello_restart_now(struct interface
*ifp
)
725 struct pim_interface
*pim_ifp
;
730 * Reset next hello timer
735 * Immediately send hello
737 pim_hello_send(ifp
, PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
741 RFC 4601: 4.3.1. Sending Hello Messages
743 To allow new or rebooting routers to learn of PIM neighbors quickly,
744 when a Hello message is received from a new neighbor, or a Hello
745 message with a new GenID is received from an existing neighbor, a
746 new Hello message should be sent on this interface after a
747 randomized delay between 0 and Triggered_Hello_Delay.
749 void pim_hello_restart_triggered(struct interface
*ifp
)
751 struct pim_interface
*pim_ifp
;
752 int triggered_hello_delay_msec
;
758 * No need to ever start loopback or vrf device hello's
760 if (pim_if_is_loopback(ifp
))
764 * There exists situations where we have the a RPF out this
765 * interface, but we haven't formed a neighbor yet. This
766 * happens especially during interface flaps. While
767 * we would like to handle this more gracefully in other
768 * parts of the code. In order to get us up and running
769 * let's just send the hello immediate'ish
770 * This should be revisited when we get nexthop tracking
771 * in and when we have a better handle on safely
772 * handling the rpf information for upstreams that
773 * we cannot legally reach yet.
775 triggered_hello_delay_msec
= 1;
776 // triggered_hello_delay_msec = 1000 *
777 // pim_ifp->pim_triggered_hello_delay;
779 if (pim_ifp
->t_pim_hello_timer
) {
781 pim_time_timer_remain_msec(pim_ifp
->t_pim_hello_timer
);
782 if (remain_msec
<= triggered_hello_delay_msec
) {
783 /* Rescheduling hello would increase the delay, then
785 to just wait for the scheduled periodic hello. */
789 THREAD_OFF(pim_ifp
->t_pim_hello_timer
);
792 random_msec
= triggered_hello_delay_msec
;
793 // random_msec = random() % (triggered_hello_delay_msec + 1);
795 if (PIM_DEBUG_PIM_HELLO
) {
796 zlog_debug("Scheduling %d msec triggered hello on interface %s",
797 random_msec
, ifp
->name
);
800 thread_add_timer_msec(master
, on_pim_hello_send
, ifp
, random_msec
,
801 &pim_ifp
->t_pim_hello_timer
);
804 int pim_sock_add(struct interface
*ifp
)
806 struct pim_interface
*pim_ifp
;
812 if (pim_ifp
->pim_sock_fd
>= 0) {
813 if (PIM_DEBUG_PIM_PACKETS
)
815 "Can't recreate existing PIM socket fd=%d for interface %s",
816 pim_ifp
->pim_sock_fd
, ifp
->name
);
820 pim_ifp
->pim_sock_fd
= pim_sock_open(ifp
);
821 if (pim_ifp
->pim_sock_fd
< 0) {
822 if (PIM_DEBUG_PIM_PACKETS
)
823 zlog_debug("Could not open PIM socket on interface %s",
828 pim_socket_ip_hdr(pim_ifp
->pim_sock_fd
);
830 pim_ifp
->t_pim_sock_read
= NULL
;
831 pim_ifp
->pim_sock_creation
= pim_time_monotonic_sec();
834 * Just ensure that the new generation id
835 * actually chooses something different.
836 * Actually ran across a case where this
837 * happened, pre-switch to random().
838 * While this is unlikely to happen now
839 * let's make sure it doesn't.
841 old_genid
= pim_ifp
->pim_generation_id
;
843 while (old_genid
== pim_ifp
->pim_generation_id
)
844 pim_ifp
->pim_generation_id
= random();
846 zlog_info("PIM INTERFACE UP: on interface %s ifindex=%d", ifp
->name
,
850 * Start receiving PIM messages
852 pim_sock_read_on(ifp
);
855 * Start sending PIM hello's
857 pim_hello_restart_triggered(ifp
);