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"
44 static int on_pim_hello_send(struct thread
*t
);
45 static int pim_hello_send(struct interface
*ifp
, uint16_t holdtime
);
47 static const char *pim_pim_msgtype2str(enum pim_msg_type type
)
50 case PIM_MSG_TYPE_HELLO
:
52 case PIM_MSG_TYPE_REGISTER
:
54 case PIM_MSG_TYPE_REG_STOP
:
56 case PIM_MSG_TYPE_JOIN_PRUNE
:
58 case PIM_MSG_TYPE_BOOTSTRAP
:
60 case PIM_MSG_TYPE_ASSERT
:
62 case PIM_MSG_TYPE_GRAFT
:
64 case PIM_MSG_TYPE_GRAFT_ACK
:
66 case PIM_MSG_TYPE_CANDIDATE
:
73 static void sock_close(struct interface
*ifp
)
75 struct pim_interface
*pim_ifp
= ifp
->info
;
77 if (PIM_DEBUG_PIM_TRACE
) {
78 if (pim_ifp
->t_pim_sock_read
) {
80 "Cancelling READ event for PIM socket fd=%d on interface %s",
81 pim_ifp
->pim_sock_fd
, ifp
->name
);
84 THREAD_OFF(pim_ifp
->t_pim_sock_read
);
86 if (PIM_DEBUG_PIM_TRACE
) {
87 if (pim_ifp
->t_pim_hello_timer
) {
89 "Cancelling PIM hello timer for interface %s",
93 THREAD_OFF(pim_ifp
->t_pim_hello_timer
);
95 if (PIM_DEBUG_PIM_TRACE
) {
96 zlog_debug("Deleting PIM socket fd=%d on interface %s",
97 pim_ifp
->pim_sock_fd
, ifp
->name
);
101 * If the fd is already deleted no need to do anything here
103 if (pim_ifp
->pim_sock_fd
> 0 && close(pim_ifp
->pim_sock_fd
)) {
105 "Failure closing PIM socket fd=%d on interface %s: errno=%d: %s",
106 pim_ifp
->pim_sock_fd
, ifp
->name
, errno
,
107 safe_strerror(errno
));
110 pim_ifp
->pim_sock_fd
= -1;
111 pim_ifp
->pim_sock_creation
= 0;
114 void pim_sock_delete(struct interface
*ifp
, const char *delete_message
)
116 zlog_info("PIM INTERFACE DOWN: on interface %s: %s", ifp
->name
,
120 flog_err(EC_PIM_CONFIG
,
121 "%s: %s: but PIM not enabled on interface %s (!)",
122 __func__
, delete_message
, ifp
->name
);
127 RFC 4601: 4.3.1. Sending Hello Messages
129 Before an interface goes down or changes primary IP address, a Hello
130 message with a zero HoldTime should be sent immediately (with the
131 old IP address if the IP address changed).
133 pim_hello_send(ifp
, 0 /* zero-sec holdtime */);
135 pim_neighbor_delete_all(ifp
, delete_message
);
140 int pim_pim_packet(struct interface
*ifp
, uint8_t *buf
, size_t len
)
143 size_t ip_hlen
; /* ip header length in bytes */
144 char src_str
[INET_ADDRSTRLEN
];
145 char dst_str
[INET_ADDRSTRLEN
];
148 uint16_t pim_checksum
; /* received checksum */
149 uint16_t checksum
; /* computed checksum */
150 struct pim_neighbor
*neigh
;
151 struct pim_msg_header
*header
;
154 if (len
< sizeof(*ip_hdr
)) {
155 if (PIM_DEBUG_PIM_PACKETS
)
157 "PIM packet size=%zu shorter than minimum=%zu",
158 len
, sizeof(*ip_hdr
));
162 ip_hdr
= (struct ip
*)buf
;
163 ip_hlen
= ip_hdr
->ip_hl
<< 2; /* ip_hl gives length in 4-byte words */
165 pim_msg
= buf
+ ip_hlen
;
166 pim_msg_len
= len
- ip_hlen
;
168 header
= (struct pim_msg_header
*)pim_msg
;
169 if (pim_msg_len
< PIM_PIM_MIN_LEN
) {
170 if (PIM_DEBUG_PIM_PACKETS
)
172 "PIM message size=%d shorter than minimum=%d",
173 pim_msg_len
, PIM_PIM_MIN_LEN
);
177 if (header
->ver
!= PIM_PROTO_VERSION
) {
178 if (PIM_DEBUG_PIM_PACKETS
)
180 "Ignoring PIM pkt from %s with unsupported version: %d",
181 ifp
->name
, header
->ver
);
185 /* save received checksum */
186 pim_checksum
= header
->checksum
;
188 /* for computing checksum */
189 header
->checksum
= 0;
190 no_fwd
= header
->Nbit
;
192 if (header
->type
== PIM_MSG_TYPE_REGISTER
) {
193 if (pim_msg_len
< PIM_MSG_REGISTER_LEN
) {
194 if (PIM_DEBUG_PIM_PACKETS
)
195 zlog_debug("PIM Register Message size=%d shorther than min length %d",
196 pim_msg_len
, PIM_MSG_REGISTER_LEN
);
199 /* First 8 byte header checksum */
200 checksum
= in_cksum(pim_msg
, PIM_MSG_REGISTER_LEN
);
201 if (checksum
!= pim_checksum
) {
202 checksum
= in_cksum(pim_msg
, pim_msg_len
);
203 if (checksum
!= pim_checksum
) {
204 if (PIM_DEBUG_PIM_PACKETS
)
206 "Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x",
207 ifp
->name
, pim_checksum
,
214 checksum
= in_cksum(pim_msg
, pim_msg_len
);
215 if (checksum
!= pim_checksum
) {
216 if (PIM_DEBUG_PIM_PACKETS
)
218 "Ignoring PIM pkt from %s with invalid checksum: received=%x calculated=%x",
219 ifp
->name
, pim_checksum
, checksum
);
225 if (PIM_DEBUG_PIM_PACKETS
) {
226 pim_inet4_dump("<src?>", ip_hdr
->ip_src
, src_str
,
228 pim_inet4_dump("<dst?>", ip_hdr
->ip_dst
, dst_str
,
231 "Recv PIM %s packet from %s to %s on %s: ttl=%d pim_version=%d pim_msg_size=%d checksum=%x",
232 pim_pim_msgtype2str(header
->type
), src_str
, dst_str
,
233 ifp
->name
, ip_hdr
->ip_ttl
, header
->ver
, pim_msg_len
,
235 if (PIM_DEBUG_PIM_PACKETDUMP_RECV
) {
236 pim_pkt_dump(__func__
, pim_msg
, pim_msg_len
);
240 switch (header
->type
) {
241 case PIM_MSG_TYPE_HELLO
:
242 return pim_hello_recv(ifp
, ip_hdr
->ip_src
,
243 pim_msg
+ PIM_MSG_HEADER_LEN
,
244 pim_msg_len
- PIM_MSG_HEADER_LEN
);
246 case PIM_MSG_TYPE_REGISTER
:
247 return pim_register_recv(ifp
, ip_hdr
->ip_dst
, ip_hdr
->ip_src
,
248 pim_msg
+ PIM_MSG_HEADER_LEN
,
249 pim_msg_len
- PIM_MSG_HEADER_LEN
);
251 case PIM_MSG_TYPE_REG_STOP
:
252 return pim_register_stop_recv(ifp
, pim_msg
+ PIM_MSG_HEADER_LEN
,
253 pim_msg_len
- PIM_MSG_HEADER_LEN
);
255 case PIM_MSG_TYPE_JOIN_PRUNE
:
256 neigh
= pim_neighbor_find(ifp
, ip_hdr
->ip_src
);
258 if (PIM_DEBUG_PIM_PACKETS
)
260 "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
261 __FILE__
, __func__
, header
->type
,
265 pim_neighbor_timer_reset(neigh
, neigh
->holdtime
);
266 return pim_joinprune_recv(ifp
, neigh
, ip_hdr
->ip_src
,
267 pim_msg
+ PIM_MSG_HEADER_LEN
,
268 pim_msg_len
- PIM_MSG_HEADER_LEN
);
270 case PIM_MSG_TYPE_ASSERT
:
271 neigh
= pim_neighbor_find(ifp
, ip_hdr
->ip_src
);
273 if (PIM_DEBUG_PIM_PACKETS
)
275 "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s",
276 __FILE__
, __func__
, header
->type
,
280 pim_neighbor_timer_reset(neigh
, neigh
->holdtime
);
281 return pim_assert_recv(ifp
, neigh
, ip_hdr
->ip_src
,
282 pim_msg
+ PIM_MSG_HEADER_LEN
,
283 pim_msg_len
- PIM_MSG_HEADER_LEN
);
285 case PIM_MSG_TYPE_BOOTSTRAP
:
286 return pim_bsm_process(ifp
, ip_hdr
, pim_msg
, pim_msg_len
,
291 if (PIM_DEBUG_PIM_PACKETS
) {
293 "Recv PIM packet type %d which is not currently understood",
301 static void pim_sock_read_on(struct interface
*ifp
);
303 static int pim_sock_read(struct thread
*t
)
305 struct interface
*ifp
, *orig_ifp
;
306 struct pim_interface
*pim_ifp
;
308 struct sockaddr_in from
;
309 struct sockaddr_in to
;
310 socklen_t fromlen
= sizeof(from
);
311 socklen_t tolen
= sizeof(to
);
312 uint8_t buf
[PIM_PIM_BUFSIZE_READ
];
314 ifindex_t ifindex
= -1;
315 int result
= -1; /* defaults to bad */
316 static long long count
= 0;
319 orig_ifp
= ifp
= THREAD_ARG(t
);
325 len
= pim_socket_recvfromto(fd
, buf
, sizeof(buf
), &from
,
326 &fromlen
, &to
, &tolen
, &ifindex
);
330 if (errno
== EWOULDBLOCK
|| errno
== EAGAIN
)
333 if (PIM_DEBUG_PIM_PACKETS
)
334 zlog_debug("Received errno: %d %s", errno
,
335 safe_strerror(errno
));
340 * What? So with vrf's the incoming packet is received
341 * on the vrf interface but recvfromto above returns
342 * the right ifindex, so just use it. We know
343 * it's the right interface because we bind to it
345 ifp
= if_lookup_by_index(ifindex
, pim_ifp
->pim
->vrf_id
);
346 if (!ifp
|| !ifp
->info
) {
347 if (PIM_DEBUG_PIM_PACKETS
)
349 "%s: Received incoming pim packet on interface(%s:%d) not yet configured for pim",
350 __func__
, ifp
? ifp
->name
: "Unknown",
354 int fail
= pim_pim_packet(ifp
, buf
, len
);
356 if (PIM_DEBUG_PIM_PACKETS
)
357 zlog_debug("%s: pim_pim_packet() return=%d",
363 if (count
% router
->packet_process
== 0)
367 result
= 0; /* good */
370 pim_sock_read_on(orig_ifp
);
373 ++pim_ifp
->pim_ifstat_hello_recvfail
;
379 static void pim_sock_read_on(struct interface
*ifp
)
381 struct pim_interface
*pim_ifp
;
388 if (PIM_DEBUG_PIM_TRACE_DETAIL
) {
389 zlog_debug("Scheduling READ event on PIM socket fd=%d",
390 pim_ifp
->pim_sock_fd
);
392 pim_ifp
->t_pim_sock_read
= NULL
;
393 thread_add_read(router
->master
, pim_sock_read
, ifp
,
394 pim_ifp
->pim_sock_fd
, &pim_ifp
->t_pim_sock_read
);
397 static int pim_sock_open(struct interface
*ifp
)
400 struct pim_interface
*pim_ifp
= ifp
->info
;
402 fd
= pim_socket_mcast(IPPROTO_PIM
, pim_ifp
->primary_address
, ifp
,
407 if (pim_socket_join(fd
, qpim_all_pim_routers_addr
,
408 pim_ifp
->primary_address
, ifp
->ifindex
)) {
416 void pim_ifstat_reset(struct interface
*ifp
)
418 struct pim_interface
*pim_ifp
;
427 pim_ifp
->pim_ifstat_start
= pim_time_monotonic_sec();
428 pim_ifp
->pim_ifstat_hello_sent
= 0;
429 pim_ifp
->pim_ifstat_hello_sendfail
= 0;
430 pim_ifp
->pim_ifstat_hello_recv
= 0;
431 pim_ifp
->pim_ifstat_hello_recvfail
= 0;
434 void pim_sock_reset(struct interface
*ifp
)
436 struct pim_interface
*pim_ifp
;
443 pim_ifp
->primary_address
= pim_find_primary_addr(ifp
);
445 pim_ifp
->pim_sock_fd
= -1;
446 pim_ifp
->pim_sock_creation
= 0;
447 pim_ifp
->t_pim_sock_read
= NULL
;
449 pim_ifp
->t_pim_hello_timer
= NULL
;
450 pim_ifp
->pim_hello_period
= PIM_DEFAULT_HELLO_PERIOD
;
451 pim_ifp
->pim_default_holdtime
=
452 -1; /* unset: means 3.5 * pim_hello_period */
453 pim_ifp
->pim_triggered_hello_delay
= PIM_DEFAULT_TRIGGERED_HELLO_DELAY
;
454 pim_ifp
->pim_dr_priority
= PIM_DEFAULT_DR_PRIORITY
;
455 pim_ifp
->pim_propagation_delay_msec
=
456 PIM_DEFAULT_PROPAGATION_DELAY_MSEC
;
457 pim_ifp
->pim_override_interval_msec
=
458 PIM_DEFAULT_OVERRIDE_INTERVAL_MSEC
;
459 if (PIM_DEFAULT_CAN_DISABLE_JOIN_SUPPRESSION
) {
460 PIM_IF_DO_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp
->options
);
462 PIM_IF_DONT_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp
->options
);
465 /* neighbors without lan_delay */
466 pim_ifp
->pim_number_of_nonlandelay_neighbors
= 0;
467 pim_ifp
->pim_neighbors_highest_propagation_delay_msec
= 0;
468 pim_ifp
->pim_neighbors_highest_override_interval_msec
= 0;
471 pim_ifp
->pim_dr_election_last
= 0; /* timestamp */
472 pim_ifp
->pim_dr_election_count
= 0;
473 pim_ifp
->pim_dr_election_changes
= 0;
474 pim_ifp
->pim_dr_num_nondrpri_neighbors
=
475 0; /* neighbors without dr_pri */
476 pim_ifp
->pim_dr_addr
= pim_ifp
->primary_address
;
478 pim_ifstat_reset(ifp
);
481 static uint16_t ip_id
= 0;
484 static int pim_msg_send_frame(int fd
, char *buf
, size_t len
,
485 struct sockaddr
*dst
, size_t salen
)
487 struct ip
*ip
= (struct ip
*)buf
;
489 while (sendto(fd
, buf
, len
, MSG_DONTWAIT
, dst
, salen
) < 0) {
490 char dst_str
[INET_ADDRSTRLEN
];
494 size_t hdrsize
= sizeof(struct ip
);
495 size_t newlen1
= ((len
- hdrsize
) / 2) & 0xFFF8;
496 size_t sendlen
= newlen1
+ hdrsize
;
497 size_t offset
= ntohs(ip
->ip_off
);
499 ip
->ip_len
= htons(sendlen
);
500 ip
->ip_off
= htons(offset
| IP_MF
);
501 if (pim_msg_send_frame(fd
, buf
, sendlen
, dst
, salen
)
503 struct ip
*ip2
= (struct ip
*)(buf
+ newlen1
);
504 size_t newlen2
= len
- sendlen
;
505 sendlen
= newlen2
+ hdrsize
;
507 memcpy(ip2
, ip
, hdrsize
);
508 ip2
->ip_len
= htons(sendlen
);
509 ip2
->ip_off
= htons(offset
+ (newlen1
>> 3));
510 return pim_msg_send_frame(fd
, (char *)ip2
,
511 sendlen
, dst
, salen
);
517 if (PIM_DEBUG_PIM_PACKETS
) {
518 pim_inet4_dump("<dst?>", ip
->ip_dst
, dst_str
,
521 "%s: sendto() failure to %s: fd=%d msg_size=%zd: errno=%d: %s",
522 __func__
, dst_str
, fd
, len
, errno
,
523 safe_strerror(errno
));
532 int pim_msg_send(int fd
, struct in_addr src
, struct in_addr dst
,
533 uint8_t *pim_msg
, int pim_msg_size
, const char *ifname
)
535 struct sockaddr_in to
;
537 unsigned char buffer
[10000];
538 unsigned char *msg_start
;
540 struct pim_msg_header
*header
;
543 memset(buffer
, 0, 10000);
544 int sendlen
= sizeof(struct ip
) + pim_msg_size
;
546 msg_start
= buffer
+ sizeof(struct ip
);
547 memcpy(msg_start
, pim_msg
, pim_msg_size
);
549 header
= (struct pim_msg_header
*)pim_msg
;
551 * Omnios apparently doesn't have a #define for IP default
552 * ttl that is the same as all other platforms.
557 /* TTL for packets destine to ALL-PIM-ROUTERS is 1 */
558 switch (header
->type
) {
559 case PIM_MSG_TYPE_HELLO
:
560 case PIM_MSG_TYPE_JOIN_PRUNE
:
561 case PIM_MSG_TYPE_BOOTSTRAP
:
562 case PIM_MSG_TYPE_ASSERT
:
565 case PIM_MSG_TYPE_REGISTER
:
566 case PIM_MSG_TYPE_REG_STOP
:
567 case PIM_MSG_TYPE_GRAFT
:
568 case PIM_MSG_TYPE_GRAFT_ACK
:
569 case PIM_MSG_TYPE_CANDIDATE
:
577 ip
= (struct ip
*)buffer
;
578 ip
->ip_id
= htons(++ip_id
);
581 ip
->ip_tos
= IPTOS_PREC_INTERNETCONTROL
;
582 ip
->ip_p
= PIM_IP_PROTO_PIM
;
586 ip
->ip_len
= htons(sendlen
);
588 if (PIM_DEBUG_PIM_PACKETS
) {
589 char dst_str
[INET_ADDRSTRLEN
];
590 pim_inet4_dump("<dst?>", dst
, dst_str
, sizeof(dst_str
));
591 zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x", __func__
,
592 dst_str
, ifname
, pim_msg_size
, header
->checksum
);
595 memset(&to
, 0, sizeof(to
));
596 to
.sin_family
= AF_INET
;
600 if (PIM_DEBUG_PIM_PACKETDUMP_SEND
) {
601 pim_pkt_dump(__func__
, pim_msg
, pim_msg_size
);
604 pim_msg_send_frame(fd
, (char *)buffer
, sendlen
, (struct sockaddr
*)&to
,
609 static int hello_send(struct interface
*ifp
, uint16_t holdtime
)
611 uint8_t pim_msg
[PIM_PIM_BUFSIZE_WRITE
];
612 struct pim_interface
*pim_ifp
;
618 if (PIM_DEBUG_PIM_HELLO
) {
619 char dst_str
[INET_ADDRSTRLEN
];
620 pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr
, dst_str
,
623 "%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",
624 __func__
, dst_str
, ifp
->name
, holdtime
,
625 pim_ifp
->pim_propagation_delay_msec
,
626 pim_ifp
->pim_override_interval_msec
,
627 PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(
629 pim_ifp
->pim_dr_priority
, pim_ifp
->pim_generation_id
,
630 listcount(ifp
->connected
));
633 pim_tlv_size
= pim_hello_build_tlv(
634 ifp
, pim_msg
+ PIM_PIM_MIN_LEN
,
635 sizeof(pim_msg
) - PIM_PIM_MIN_LEN
, holdtime
,
636 pim_ifp
->pim_dr_priority
, pim_ifp
->pim_generation_id
,
637 pim_ifp
->pim_propagation_delay_msec
,
638 pim_ifp
->pim_override_interval_msec
,
639 PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPRESSION(pim_ifp
->options
));
640 if (pim_tlv_size
< 0) {
644 pim_msg_size
= pim_tlv_size
+ PIM_PIM_MIN_LEN
;
646 zassert(pim_msg_size
>= PIM_PIM_MIN_LEN
);
647 zassert(pim_msg_size
<= PIM_PIM_BUFSIZE_WRITE
);
649 pim_msg_build_header(pim_msg
, pim_msg_size
, PIM_MSG_TYPE_HELLO
, false);
651 if (pim_msg_send(pim_ifp
->pim_sock_fd
, pim_ifp
->primary_address
,
652 qpim_all_pim_routers_addr
, pim_msg
, pim_msg_size
,
654 if (PIM_DEBUG_PIM_HELLO
) {
656 "%s: could not send PIM message on interface %s",
657 __func__
, ifp
->name
);
665 static int pim_hello_send(struct interface
*ifp
, uint16_t holdtime
)
667 struct pim_interface
*pim_ifp
= ifp
->info
;
669 if (if_is_loopback_or_vrf(ifp
))
672 if (hello_send(ifp
, holdtime
)) {
673 ++pim_ifp
->pim_ifstat_hello_sendfail
;
675 if (PIM_DEBUG_PIM_HELLO
) {
676 zlog_warn("Could not send PIM hello on interface %s",
682 ++pim_ifp
->pim_ifstat_hello_sent
;
687 static void hello_resched(struct interface
*ifp
)
689 struct pim_interface
*pim_ifp
;
693 if (PIM_DEBUG_PIM_HELLO
) {
694 zlog_debug("Rescheduling %d sec hello on interface %s",
695 pim_ifp
->pim_hello_period
, ifp
->name
);
697 THREAD_OFF(pim_ifp
->t_pim_hello_timer
);
698 thread_add_timer(router
->master
, on_pim_hello_send
, ifp
,
699 pim_ifp
->pim_hello_period
,
700 &pim_ifp
->t_pim_hello_timer
);
706 static int on_pim_hello_send(struct thread
*t
)
708 struct pim_interface
*pim_ifp
;
709 struct interface
*ifp
;
715 * Schedule next hello
722 return pim_hello_send(ifp
, PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
726 RFC 4601: 4.3.1. Sending Hello Messages
728 Thus, if a router needs to send a Join/Prune or Assert message on an
729 interface on which it has not yet sent a Hello message with the
730 currently configured IP address, then it MUST immediately send the
731 relevant Hello message without waiting for the Hello Timer to
732 expire, followed by the Join/Prune or Assert message.
734 void pim_hello_restart_now(struct interface
*ifp
)
736 struct pim_interface
*pim_ifp
;
741 * Reset next hello timer
746 * Immediately send hello
748 pim_hello_send(ifp
, PIM_IF_DEFAULT_HOLDTIME(pim_ifp
));
752 RFC 4601: 4.3.1. Sending Hello Messages
754 To allow new or rebooting routers to learn of PIM neighbors quickly,
755 when a Hello message is received from a new neighbor, or a Hello
756 message with a new GenID is received from an existing neighbor, a
757 new Hello message should be sent on this interface after a
758 randomized delay between 0 and Triggered_Hello_Delay.
760 void pim_hello_restart_triggered(struct interface
*ifp
)
762 struct pim_interface
*pim_ifp
;
763 int triggered_hello_delay_msec
;
769 * No need to ever start loopback or vrf device hello's
771 if (if_is_loopback_or_vrf(ifp
))
775 * There exists situations where we have the a RPF out this
776 * interface, but we haven't formed a neighbor yet. This
777 * happens especially during interface flaps. While
778 * we would like to handle this more gracefully in other
779 * parts of the code. In order to get us up and running
780 * let's just send the hello immediate'ish
781 * This should be revisited when we get nexthop tracking
782 * in and when we have a better handle on safely
783 * handling the rpf information for upstreams that
784 * we cannot legally reach yet.
786 triggered_hello_delay_msec
= 1;
787 // triggered_hello_delay_msec = 1000 *
788 // pim_ifp->pim_triggered_hello_delay;
790 if (pim_ifp
->t_pim_hello_timer
) {
792 pim_time_timer_remain_msec(pim_ifp
->t_pim_hello_timer
);
793 if (remain_msec
<= triggered_hello_delay_msec
) {
794 /* Rescheduling hello would increase the delay, then
796 to just wait for the scheduled periodic hello. */
800 THREAD_OFF(pim_ifp
->t_pim_hello_timer
);
803 random_msec
= triggered_hello_delay_msec
;
804 // random_msec = random() % (triggered_hello_delay_msec + 1);
806 if (PIM_DEBUG_PIM_HELLO
) {
807 zlog_debug("Scheduling %d msec triggered hello on interface %s",
808 random_msec
, ifp
->name
);
811 thread_add_timer_msec(router
->master
, on_pim_hello_send
, ifp
,
812 random_msec
, &pim_ifp
->t_pim_hello_timer
);
815 int pim_sock_add(struct interface
*ifp
)
817 struct pim_interface
*pim_ifp
;
823 if (pim_ifp
->pim_sock_fd
>= 0) {
824 if (PIM_DEBUG_PIM_PACKETS
)
826 "Can't recreate existing PIM socket fd=%d for interface %s",
827 pim_ifp
->pim_sock_fd
, ifp
->name
);
831 pim_ifp
->pim_sock_fd
= pim_sock_open(ifp
);
832 if (pim_ifp
->pim_sock_fd
< 0) {
833 if (PIM_DEBUG_PIM_PACKETS
)
834 zlog_debug("Could not open PIM socket on interface %s",
839 pim_socket_ip_hdr(pim_ifp
->pim_sock_fd
);
841 pim_ifp
->t_pim_sock_read
= NULL
;
842 pim_ifp
->pim_sock_creation
= pim_time_monotonic_sec();
845 * Just ensure that the new generation id
846 * actually chooses something different.
847 * Actually ran across a case where this
848 * happened, pre-switch to random().
849 * While this is unlikely to happen now
850 * let's make sure it doesn't.
852 old_genid
= pim_ifp
->pim_generation_id
;
854 while (old_genid
== pim_ifp
->pim_generation_id
)
855 pim_ifp
->pim_generation_id
= random();
857 zlog_info("PIM INTERFACE UP: on interface %s ifindex=%d", ifp
->name
,
861 * Start receiving PIM messages
863 pim_sock_read_on(ifp
);
866 * Start sending PIM hello's
868 pim_hello_restart_triggered(ifp
);