]>
git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_addr.h
2 * PIM address generalizations
3 * Copyright (C) 2022 David Lamparter for NetDEF, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
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
20 #ifndef _PIMD_PIM_ADDR_H
21 #define _PIMD_PIM_ADDR_H
26 /* clang-format off */
29 typedef struct in_addr pim_addr
;
31 #define PIM_ADDRSTRLEN INET_ADDRSTRLEN
32 #define PIM_AF AF_INET
33 #define PIM_AFI AFI_IP
34 #define PIM_MAX_BITLEN IPV4_MAX_BITLEN
35 #define PIM_AF_NAME "ip"
38 prefixtype(pimprefixptr
, struct prefix
, p
)
39 prefixtype(pimprefixptr
, struct prefix_ipv4
, p4
)
42 union pimprefixconstptr
{
43 prefixtype(pimprefixconstptr
, const struct prefix
, p
)
44 prefixtype(pimprefixconstptr
, const struct prefix_ipv4
, p4
)
48 typedef struct in6_addr pim_addr
;
50 #define PIM_ADDRSTRLEN INET6_ADDRSTRLEN
51 #define PIM_AF AF_INET6
52 #define PIM_AFI AFI_IP6
53 #define PIM_MAX_BITLEN IPV6_MAX_BITLEN
54 #define PIM_AF_NAME "ipv6"
57 prefixtype(pimprefixptr
, struct prefix
, p
)
58 prefixtype(pimprefixptr
, struct prefix_ipv6
, p6
)
61 union pimprefixconstptr
{
62 prefixtype(pimprefixconstptr
, const struct prefix
, p
)
63 prefixtype(pimprefixconstptr
, const struct prefix_ipv6
, p6
)
67 /* for assignment/initialization (C99 compound literal)
68 * named PIMADDR_ANY (not PIM_ADDR_ANY) to match INADDR_ANY
70 #define PIMADDR_ANY (pim_addr){ }
74 static inline bool pim_addr_is_any(pim_addr addr
)
78 return memcmp(&addr
, &zero
, sizeof(zero
)) == 0;
81 static inline int pim_addr_cmp(pim_addr a
, pim_addr b
)
83 return memcmp(&a
, &b
, sizeof(a
));
86 static inline void pim_addr_to_prefix(union pimprefixptr out
, pim_addr in
)
88 out
.p
->family
= PIM_AF
;
89 out
.p
->prefixlen
= PIM_MAX_BITLEN
;
90 memcpy(out
.p
->u
.val
, &in
, sizeof(in
));
93 static inline pim_addr
pim_addr_from_prefix(union pimprefixconstptr in
)
97 if (in
.p
->family
!= PIM_AF
)
100 memcpy(&ret
, in
.p
->u
.val
, sizeof(ret
));
104 /* don't use this struct directly, use the pim_sgaddr typedef */
110 typedef struct _pim_sgaddr pim_sgaddr
;
112 static inline int pim_sgaddr_cmp(const pim_sgaddr a
, const pim_sgaddr b
)
114 /* memcmp over the entire struct = memcmp(grp) + memcmp(src) */
115 return memcmp(&a
, &b
, sizeof(a
));
118 static inline uint32_t pim_sgaddr_hash(const pim_sgaddr a
, uint32_t initval
)
120 return jhash2((uint32_t *)&a
, sizeof(a
) / sizeof(uint32_t), initval
);
123 #ifdef _FRR_ATTRIBUTE_PRINTFRR
124 #pragma FRR printfrr_ext "%pPA" (pim_addr *)
125 #pragma FRR printfrr_ext "%pSG" (pim_sgaddr *)
129 * There is no pim_sgaddr2str(). This is intentional. Instead, use:
130 * snprintfrr(buf, sizeof(buf), "%pPA", sgaddr)
131 * (and note that snprintfrr is implicit for vty_out and zlog_*)
134 #endif /* _PIMD_PIM_ADDR_H */