From 1b00ed5f6510a227e1b1da92f1802ca565823083 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 3 May 2022 15:49:26 +0200 Subject: [PATCH] pimd: pass down length for register messages The IPv6 `mrt6msg` kernel pseudo-header does not have a length field; accessing what would be the IPv6 payload length reads zeroes. Pass down the proper length and use that instead. Signed-off-by: David Lamparter --- pimd/pim6_mroute_msg.c | 8 +++++--- pimd/pim_mroute.c | 12 +++++++----- pimd/pim_mroute.h | 6 ++++-- pimd/pim_mroute_msg.c | 8 +++++--- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pimd/pim6_mroute_msg.c b/pimd/pim6_mroute_msg.c index 37d67ad048..c5547eef5d 100644 --- a/pimd/pim6_mroute_msg.c +++ b/pimd/pim6_mroute_msg.c @@ -167,10 +167,12 @@ int pim_mroute_msg(struct pim_instance *pim, const char *buf, msg); case MRT6MSG_WHOLEPKT: return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, - (const char *)msg); + (const char *)msg, + buf_size); case MRT6MSG_WRMIFWHOLE: - return pim_mroute_msg_wrvifwhole( - pim->mroute_socket, ifp, (const char *)msg); + return pim_mroute_msg_wrvifwhole(pim->mroute_socket, + ifp, (const char *)msg, + buf_size); default: break; } diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 5f951b4dfc..1978afa7c0 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -137,7 +137,8 @@ int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg) return 0; } -int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf) +int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf, + size_t len) { struct pim_interface *pim_ifp; pim_sgaddr sg; @@ -229,7 +230,7 @@ int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf) } pim_register_send((uint8_t *)buf + sizeof(ipv_hdr), - ntohs(IPV_LEN(ip_hdr)) - sizeof(ipv_hdr), + len - sizeof(ipv_hdr), pim_ifp->primary_address, rpg, 0, up); } return 0; @@ -336,7 +337,8 @@ int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, const kernmsg *msg) return 0; } -int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf) +int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf, + size_t len) { const ipv_hdr *ip_hdr = (const ipv_hdr *)buf; struct pim_interface *pim_ifp; @@ -463,7 +465,7 @@ int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf) pim_upstream_keep_alive_timer_start( up, pim_ifp->pim->keep_alive_time); pim_upstream_inherited_olist(pim_ifp->pim, up); - pim_mroute_msg_wholepkt(fd, ifp, buf); + pim_mroute_msg_wholepkt(fd, ifp, buf, len); } return 0; } @@ -490,7 +492,7 @@ int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf) pim_upstream_mroute_add(up->channel_oil, __func__); // Send the packet to the RP - pim_mroute_msg_wholepkt(fd, ifp, buf); + pim_mroute_msg_wholepkt(fd, ifp, buf, len); } else { up = pim_upstream_add(pim_ifp->pim, &sg, ifp, PIM_UPSTREAM_FLAG_MASK_SRC_NOCACHE, diff --git a/pimd/pim_mroute.h b/pimd/pim_mroute.h index 35ba60bf35..c56da7fae0 100644 --- a/pimd/pim_mroute.h +++ b/pimd/pim_mroute.h @@ -158,8 +158,10 @@ bool pim_mroute_allow_iif_in_oil(struct channel_oil *c_oil, int pim_mroute_msg(struct pim_instance *pim, const char *buf, size_t buf_size, ifindex_t ifindex); int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg); -int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf); +int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf, + size_t len); int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, const kernmsg *msg); -int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf); +int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf, + size_t len); int pim_mroute_set(struct pim_instance *pim, int enable); #endif /* PIM_MROUTE_H */ diff --git a/pimd/pim_mroute_msg.c b/pimd/pim_mroute_msg.c index 7d80488c68..ad5d46e970 100644 --- a/pimd/pim_mroute_msg.c +++ b/pimd/pim_mroute_msg.c @@ -226,10 +226,12 @@ int pim_mroute_msg(struct pim_instance *pim, const char *buf, msg); case IGMPMSG_WHOLEPKT: return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, - (const char *)msg); + (const char *)msg, + buf_size); case IGMPMSG_WRVIFWHOLE: - return pim_mroute_msg_wrvifwhole( - pim->mroute_socket, ifp, (const char *)msg); + return pim_mroute_msg_wrvifwhole(pim->mroute_socket, + ifp, (const char *)msg, + buf_size); default: break; } -- 2.39.5