Skip to content

Commit

Permalink
pimd, pim6d: Send register msg via register socket
Browse files Browse the repository at this point in the history
The problem here is when the same node is FHR as well as RP,
then the node keeps on sending the register packet.
Register-stop is not sent as well.

This problem has occurred because the RP is the same node
and there is no socket created on loopback interface, so the
packet is never send out and never received back on the same
node, so register recv could not be processed on the node and
hence no register-stop is sent.

Since register packets are unicast packets, its better to handle
the send of register packet via a separate register socket.
This fixes the problem mentioned above as well.

Fixes: #11331
Signed-off-by: Mobashshera Rasool <[email protected]>
  • Loading branch information
mobash-rasool committed Aug 4, 2022
1 parent ad9b47e commit 9461953
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pimd/pim_cmd_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,8 @@ void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty)
vty_out(vty, "Mroute socket descriptor:");

vty_out(vty, " %d(%s)\n", pim->mroute_socket, vrf->name);
vty_out(vty, "PIM Register socket descriptor:");
vty_out(vty, " %d(%s)\n", pim->reg_sock, vrf->name);

pim_time_uptime(uptime, sizeof(uptime),
now - pim->mroute_socket_creation);
Expand Down
7 changes: 7 additions & 0 deletions pimd/pim_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "pim_vty.h"
#include "pim_bsm.h"
#include "pim_mlag.h"
#include "pim_sock.h"

static void pim_instance_terminate(struct pim_instance *pim)
{
Expand Down Expand Up @@ -70,6 +71,8 @@ static void pim_instance_terminate(struct pim_instance *pim)

pim_msdp_exit(pim);

close(pim->reg_sock);

pim_mroute_socket_disable(pim);

XFREE(MTYPE_PIM_PLIST_NAME, pim->spt.plist);
Expand Down Expand Up @@ -131,6 +134,10 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf)

pim->last_route_change_time = -1;

pim->reg_sock = pim_reg_sock();
if (pim->reg_sock < 0)
assert(0);

/* MSDP global timer defaults. */
pim->msdp.hold_time = PIM_MSDP_PEER_HOLD_TIME;
pim->msdp.keep_alive = PIM_MSDP_PEER_KA_TIME;
Expand Down
1 change: 1 addition & 0 deletions pimd/pim_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct pim_instance {

struct thread *thread;
int mroute_socket;
int reg_sock; /* Socket to send register msg */
int64_t mroute_socket_creation;
int64_t mroute_add_events;
int64_t mroute_add_last;
Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src,
if (!pinfo->pim_passive_enable)
++pinfo->pim_ifstat_reg_send;

if (pim_msg_send(pinfo->pim_sock_fd, src, rpg->rpf_addr, buffer,
if (pim_msg_send(pinfo->pim->reg_sock, src, rpg->rpf_addr, buffer,
buf_size + PIM_MSG_REGISTER_LEN, ifp)) {
if (PIM_DEBUG_PIM_TRACE) {
zlog_debug(
Expand Down
40 changes: 40 additions & 0 deletions pimd/pim_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,46 @@ static inline int pim_setsockopt(int protocol, int fd, struct interface *ifp)
}
#endif

int pim_reg_sock(void)
{
int fd;
long flags;

frr_with_privs (&pimd_privs) {
fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
}

if (fd < 0) {
zlog_warn("Could not create raw socket: errno=%d: %s", errno,
safe_strerror(errno));
return PIM_SOCK_ERR_SOCKET;
}

if (sockopt_reuseaddr(fd)) {
close(fd);
return PIM_SOCK_ERR_REUSE;
}

flags = fcntl(fd, F_GETFL, 0);
if (flags < 0) {
zlog_warn(
"Could not get fcntl(F_GETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s",
fd, errno, safe_strerror(errno));
close(fd);
return PIM_SOCK_ERR_NONBLOCK_GETFL;
}

if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
zlog_warn(
"Could not set fcntl(F_SETFL,O_NONBLOCK) on socket fd=%d: errno=%d: %s",
fd, errno, safe_strerror(errno));
close(fd);
return PIM_SOCK_ERR_NONBLOCK_SETFL;
}

return fd;
}

int pim_socket_mcast(int protocol, pim_addr ifaddr, struct interface *ifp,
uint8_t loop)
{
Expand Down
2 changes: 2 additions & 0 deletions pimd/pim_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ int pim_socket_recvfromto(int fd, uint8_t *buf, size_t len,

int pim_socket_getsockname(int fd, struct sockaddr *name, socklen_t *namelen);

int pim_reg_sock(void);

#endif /* PIM_SOCK_H */

0 comments on commit 9461953

Please sign in to comment.