diff options
| author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2024-12-12 22:44:29 -0300 |
|---|---|---|
| committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2024-12-13 08:28:42 -0300 |
| commit | a507ca11633672fb9ab0b5bac8116a130494b6af (patch) | |
| tree | 1e46165be7401e3dd023c860c5b9bd35f5b3d6f1 /pimd/pim_util.c | |
| parent | f7720ab68fcfb24e7fa51f682d248086c45ef85a (diff) | |
pimd,pim6d: optimize multicast prefix generation
Fix Coverity Scan CID 1602463: make it impossible for the function to fail.
Hardcode the multicast prefix generation instead of calling `str2prefix()`
which caused unnecessary memory allocations and returned error values.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'pimd/pim_util.c')
| -rw-r--r-- | pimd/pim_util.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/pimd/pim_util.c b/pimd/pim_util.c index 40404714e7..0aea240587 100644 --- a/pimd/pim_util.c +++ b/pimd/pim_util.c @@ -213,16 +213,21 @@ bool pim_is_group_filtered(struct pim_interface *pim_ifp, pim_addr *grp, pim_add /* This function returns all multicast group */ -int pim_get_all_mcast_group(struct prefix *prefix) +void pim_get_all_mcast_group(struct prefix *prefix) { + memset(prefix, 0, sizeof(*prefix)); + #if PIM_IPV == 4 - if (!str2prefix("224.0.0.0/4", prefix)) - return 0; + /* Precomputed version of: `str2prefix("224.0.0.0/4", prefix);` */ + prefix->family = AF_INET; + prefix->prefixlen = 4; + prefix->u.prefix4.s_addr = htonl(0xe0000000); #else - if (!str2prefix("FF00::0/8", prefix)) - return 0; + /* Precomputed version of: `str2prefix("FF00::0/8", prefix)` */ + prefix->family = AF_INET6; + prefix->prefixlen = 8; + prefix->u.prefix6.s6_addr[0] = 0xff; #endif - return 1; } bool pim_addr_is_multicast(pim_addr addr) |
