diff options
Diffstat (limited to 'pimd/pim_pim.c')
| -rw-r--r-- | pimd/pim_pim.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 8d7a921cf4..3976b262e3 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -23,6 +23,7 @@ #include "thread.h" #include "memory.h" #include "if.h" +#include "network.h" #include "pimd.h" #include "pim_pim.h" @@ -42,7 +43,6 @@ #include "pim_bsm.h" static int on_pim_hello_send(struct thread *t); -static int pim_hello_send(struct interface *ifp, uint16_t holdtime); static const char *pim_pim_msgtype2str(enum pim_msg_type type) { @@ -137,6 +137,18 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message) sock_close(ifp); } +/* For now check dst address for hello, assrt and join/prune is all pim rtr */ +static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, in_addr_t addr) +{ + if ((type == PIM_MSG_TYPE_HELLO) || (type == PIM_MSG_TYPE_ASSERT) + || (type == PIM_MSG_TYPE_JOIN_PRUNE)) { + if (addr != qpim_all_pim_routers_addr.s_addr) + return false; + } + + return true; +} + int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) { struct ip *ip_hdr; @@ -237,6 +249,21 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) } } + if (!pim_pkt_dst_addr_ok(header->type, ip_hdr->ip_dst.s_addr)) { + char dst_str[INET_ADDRSTRLEN]; + char src_str[INET_ADDRSTRLEN]; + + pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, + sizeof(dst_str)); + pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, + sizeof(src_str)); + zlog_warn( + "%s: Ignoring Pkt. Unexpected IP destination %s for %s (Expected: all_pim_routers_addr) from %s", + __func__, dst_str, pim_pim_msgtype2str(header->type), + src_str); + return -1; + } + switch (header->type) { case PIM_MSG_TYPE_HELLO: return pim_hello_recv(ifp, ip_hdr->ip_src, @@ -662,7 +689,7 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) return 0; } -static int pim_hello_send(struct interface *ifp, uint16_t holdtime) +int pim_hello_send(struct interface *ifp, uint16_t holdtime) { struct pim_interface *pim_ifp = ifp->info; @@ -852,7 +879,7 @@ int pim_sock_add(struct interface *ifp) old_genid = pim_ifp->pim_generation_id; while (old_genid == pim_ifp->pim_generation_id) - pim_ifp->pim_generation_id = random(); + pim_ifp->pim_generation_id = frr_weak_random(); zlog_info("PIM INTERFACE UP: on interface %s ifindex=%d", ifp->name, ifp->ifindex); |
