From 883052c6f9211eadc1cc4f6ffef8413cce56f3d7 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 13 Jan 2022 14:29:09 +0100 Subject: [PATCH 01/14] pim6d: convert address comparison in I_am_DR macro Signed-off-by: David Lamparter --- pimd/pim_iface.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 1ddf743619..f5f58a4bde 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -59,7 +59,8 @@ #define PIM_IF_DONT_PIM_CAN_DISABLE_JOIN_SUPPRESSION(options) \ ((options) &= ~PIM_IF_MASK_PIM_CAN_DISABLE_JOIN_SUPPRESSION) -#define PIM_I_am_DR(pim_ifp) (pim_ifp)->pim_dr_addr.s_addr == (pim_ifp)->primary_address.s_addr +#define PIM_I_am_DR(pim_ifp) \ + !pim_addr_cmp((pim_ifp)->pim_dr_addr, (pim_ifp)->primary_address) #define PIM_I_am_DualActive(pim_ifp) (pim_ifp)->activeactive == true /* Macros for interface flags */ From 16763d77a39ae0cd84e6fcf4b3f6a05f10d94c38 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 14:57:21 +0100 Subject: [PATCH 02/14] pim6d: prepare IPv6 address encoding functions Signed-off-by: David Lamparter --- pimd/pim_join.c | 4 +-- pimd/pim_msg.c | 88 +++++++++++++++++++++++++++++++++++++++++-------- pimd/pim_msg.h | 57 ++++++++++++++++++++++++++++++-- 3 files changed, 130 insertions(+), 19 deletions(-) diff --git a/pimd/pim_join.c b/pimd/pim_join.c index fa2d8d462b..22890dc372 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -516,7 +516,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) grp = &msg->groups[0]; curr_ptr = (uint8_t *)grp; packet_size = sizeof(struct pim_msg_header); - packet_size += sizeof(struct pim_encoded_ipv4_unicast); + packet_size += sizeof(pim_encoded_unicast); packet_size += 4; // reserved (1) + groups (1) + holdtime (2) @@ -564,7 +564,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) grp = &msg->groups[0]; curr_ptr = (uint8_t *)grp; packet_size = sizeof(struct pim_msg_header); - packet_size += sizeof(struct pim_encoded_ipv4_unicast); + packet_size += sizeof(pim_encoded_unicast); packet_size += 4; // reserved (1) + groups (1) + holdtime (2) diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index c493ded0c6..e25cf11549 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -97,6 +97,68 @@ uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf, struct in_addr addr, return buf + PIM_ENCODED_IPV4_SOURCE_SIZE; } +uint8_t *pim_msg_addr_encode_ipv6_source(uint8_t *buf, struct in6_addr addr, + uint8_t bits) +{ + buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV6; /* addr family */ + buf[1] = '\0'; /* native encoding */ + buf[2] = bits; + buf[3] = 128; /* mask len */ + buf += 4; + + memcpy(buf, &addr, sizeof(addr)); + buf += sizeof(addr); + + return buf; +} + +uint8_t *pim_msg_addr_encode_ipv6_ucast(uint8_t *buf, struct in6_addr addr) +{ + buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV6; /* addr family */ + buf[1] = '\0'; /* native encoding */ + buf += 2; + + memcpy(buf, &addr, sizeof(addr)); + buf += sizeof(addr); + + return buf; +} + +uint8_t *pim_msg_addr_encode_ipv6_group(uint8_t *buf, struct in6_addr addr) +{ + buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV6; /* addr family */ + buf[1] = '\0'; /* native encoding */ + buf[2] = '\0'; /* reserved */ + buf[3] = 128; /* mask len */ + buf += 4; + + memcpy(buf, &addr, sizeof(addr)); + buf += sizeof(addr); + + return buf; +} + +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#define pim_msg_addr_encode(what) pim_msg_addr_encode_ipv4_##what +#else +#define pim_msg_addr_encode(what) pim_msg_addr_encode_ipv6_##what +#endif + +uint8_t *pim_msg_addr_encode_ucast(uint8_t *buf, pim_addr addr) +{ + return pim_msg_addr_encode(ucast)(buf, addr); +} + +uint8_t *pim_msg_addr_encode_group(uint8_t *buf, pim_addr addr) +{ + return pim_msg_addr_encode(group)(buf, addr); +} + +uint8_t *pim_msg_addr_encode_source(uint8_t *buf, pim_addr addr, uint8_t bits) +{ + return pim_msg_addr_encode(source)(buf, addr, bits); +} + /* * For the given 'struct pim_jp_sources' list * determine the size_t it would take up. @@ -109,10 +171,10 @@ size_t pim_msg_get_jp_group_size(struct list *sources) if (!sources) return 0; - size += sizeof(struct pim_encoded_group_ipv4); + size += sizeof(pim_encoded_group); size += 4; // Joined sources (2) + Pruned Sources (2) - size += sizeof(struct pim_encoded_source_ipv4) * sources->count; + size += sizeof(pim_encoded_source) * sources->count; js = listgetdata(listhead(sources)); if (js && pim_addr_is_any(js->up->sg.src) && js->is_join) { @@ -137,8 +199,7 @@ size_t pim_msg_get_jp_group_size(struct list *sources) if (child->rpf.source_nexthop.interface && !pim_rpf_is_same(&up->rpf, &child->rpf)) { - size += sizeof( - struct pim_encoded_source_ipv4); + size += sizeof(pim_encoded_source); PIM_UPSTREAM_FLAG_SET_SEND_SG_RPT_PRUNE( child->flags); if (PIM_DEBUG_PIM_PACKETS) @@ -156,8 +217,7 @@ size_t pim_msg_get_jp_group_size(struct list *sources) * but it's inherited OIL is empty. So just * prune it off. */ - size += sizeof( - struct pim_encoded_source_ipv4); + size += sizeof(pim_encoded_source); PIM_UPSTREAM_FLAG_SET_SEND_SG_RPT_PRUNE( child->flags); if (PIM_DEBUG_PIM_PACKETS) @@ -179,12 +239,12 @@ size_t pim_msg_build_jp_groups(struct pim_jp_groups *grp, struct listnode *node, *nnode; struct pim_jp_sources *source; struct pim_upstream *up = NULL; - struct in_addr stosend; + pim_addr stosend; uint8_t bits; uint8_t tgroups = 0; memset(grp, 0, size); - pim_msg_addr_encode_ipv4_group((uint8_t *)&grp->g, sgs->group); + pim_msg_addr_encode_group((uint8_t *)&grp->g, sgs->group); for (ALL_LIST_ELEMENTS(sgs->sources, node, nnode, source)) { /* number of joined/pruned sources */ @@ -198,7 +258,7 @@ size_t pim_msg_build_jp_groups(struct pim_jp_groups *grp, struct pim_rpf *rpf = pim_rp_g(pim, source->up->sg.grp); bits = PIM_ENCODE_SPARSE_BIT | PIM_ENCODE_WC_BIT | PIM_ENCODE_RPT_BIT; - stosend = rpf->rpf_addr.u.prefix4; + stosend = pim_addr_from_prefix(&rpf->rpf_addr); /* Only Send SGRpt in case of *,G Join */ if (source->is_join) up = source->up; @@ -207,8 +267,8 @@ size_t pim_msg_build_jp_groups(struct pim_jp_groups *grp, stosend = source->up->sg.src; } - pim_msg_addr_encode_ipv4_source((uint8_t *)&grp->s[tgroups], - stosend, bits); + pim_msg_addr_encode_source((uint8_t *)&grp->s[tgroups], stosend, + bits); tgroups++; } @@ -218,11 +278,11 @@ size_t pim_msg_build_jp_groups(struct pim_jp_groups *grp, for (ALL_LIST_ELEMENTS(up->sources, node, nnode, child)) { if (PIM_UPSTREAM_FLAG_TEST_SEND_SG_RPT_PRUNE( child->flags)) { - pim_msg_addr_encode_ipv4_source( + pim_msg_addr_encode_source( (uint8_t *)&grp->s[tgroups], child->sg.src, - PIM_ENCODE_SPARSE_BIT - | PIM_ENCODE_RPT_BIT); + PIM_ENCODE_SPARSE_BIT | + PIM_ENCODE_RPT_BIT); tgroups++; PIM_UPSTREAM_FLAG_UNSET_SEND_SG_RPT_PRUNE( child->flags); diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h index 2d69a4b03a..522e94504a 100644 --- a/pimd/pim_msg.h +++ b/pimd/pim_msg.h @@ -75,6 +75,12 @@ struct pim_encoded_ipv4_unicast { struct in_addr addr; } __attribute__((packed)); +struct pim_encoded_ipv6_unicast { + uint8_t family; + uint8_t reserved; + struct in6_addr addr; +} __attribute__((packed)); + /* * Encoded Group format. RFC 4601 Sec 4.9.1 * 0 1 2 3 @@ -103,6 +109,23 @@ struct pim_encoded_group_ipv4 { struct in_addr addr; } __attribute__((packed)); +struct pim_encoded_group_ipv6 { + uint8_t family; + uint8_t ne; +#if (BYTE_ORDER == LITTLE_ENDIAN) + uint8_t sz : 1; /* scope zone bit */ + uint8_t reserved : 6; /* Reserved */ + uint8_t bidir : 1; /* Bidir bit */ +#elif (BYTE_ORDER == BIG_ENDIAN) + uint8_t bidir : 1; /* Bidir bit */ + uint8_t reserved : 6; /* Reserved */ + uint8_t sz : 1; /* scope zone bit */ +#else +#error "Please set byte order" +#endif + uint8_t mask; + struct in6_addr addr; +} __attribute__((packed)); /* * Encoded Source format. RFC 4601 Sec 4.9.1 @@ -122,16 +145,36 @@ struct pim_encoded_source_ipv4 { struct in_addr addr; } __attribute__((packed)); +struct pim_encoded_source_ipv6 { + uint8_t family; + uint8_t ne; + uint8_t bits; + uint8_t mask; + struct in6_addr addr; +} __attribute__((packed)); + +/* clang-format off */ +#if PIM_IPV == 4 +typedef struct pim_encoded_ipv4_unicast pim_encoded_unicast; +typedef struct pim_encoded_group_ipv4 pim_encoded_group; +typedef struct pim_encoded_source_ipv4 pim_encoded_source; +#else +typedef struct pim_encoded_ipv6_unicast pim_encoded_unicast; +typedef struct pim_encoded_group_ipv6 pim_encoded_group; +typedef struct pim_encoded_source_ipv6 pim_encoded_source; +#endif +/* clang-format on */ + struct pim_jp_groups { - struct pim_encoded_group_ipv4 g; + pim_encoded_group g; uint16_t joins; uint16_t prunes; - struct pim_encoded_source_ipv4 s[1]; + pim_encoded_source s[1]; } __attribute__((packed)); struct pim_jp { struct pim_msg_header header; - struct pim_encoded_ipv4_unicast addr; + pim_encoded_unicast addr; uint8_t reserved; uint8_t num_groups; uint16_t holdtime; @@ -149,6 +192,14 @@ uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, struct in_addr addr); uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf, struct in_addr addr, uint8_t bits); +uint8_t *pim_msg_addr_encode_ipv6_ucast(uint8_t *buf, struct in6_addr addr); +uint8_t *pim_msg_addr_encode_ipv6_group(uint8_t *buf, struct in6_addr addr); +uint8_t *pim_msg_addr_encode_ipv6_source(uint8_t *buf, struct in6_addr addr, + uint8_t bits); + +uint8_t *pim_msg_addr_encode_ucast(uint8_t *buf, pim_addr addr); +uint8_t *pim_msg_addr_encode_group(uint8_t *buf, pim_addr addr); +uint8_t *pim_msg_addr_encode_source(uint8_t *buf, pim_addr addr, uint8_t bits); size_t pim_msg_get_jp_group_size(struct list *sources); size_t pim_msg_build_jp_groups(struct pim_jp_groups *grp, From 0d360092045fdfca1a363bbc522deafbb79255e8 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 16:38:41 +0100 Subject: [PATCH 03/14] pim6d: more TLV parse/encode IPv6 preparation More proliferation of pim_addr to work towards IPV6. Signed-off-by: David Lamparter --- pimd/pim_assert.c | 21 ++++---- pimd/pim_join.c | 39 ++++++--------- pimd/pim_register.c | 16 +++--- pimd/pim_tlv.c | 115 +++++++++++++++++++++++++++----------------- pimd/pim_tlv.h | 10 ++-- 5 files changed, 113 insertions(+), 88 deletions(-) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 3c38ebd76b..f4b6e81bd6 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -216,7 +216,8 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, struct in_addr src_addr, uint8_t *buf, int buf_size) { pim_sgaddr sg; - struct prefix msg_source_addr; + pim_addr msg_source_addr; + bool wrong_af = false; struct pim_assert_metric msg_metric; int offset; uint8_t *curr; @@ -246,8 +247,9 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, /* Parse assert source addr */ - offset = pim_parse_addr_ucast(&msg_source_addr, curr, curr_size); - if (offset < 1) { + offset = pim_parse_addr_ucast(&msg_source_addr, curr, curr_size, + &wrong_af); + if (offset < 1 || wrong_af) { char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s", @@ -286,15 +288,13 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_TRACE) { char neigh_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, neigh_str, sizeof(neigh_str)); - pim_inet4_dump("", msg_source_addr.u.prefix4, source_str, - sizeof(source_str)); zlog_debug( - "%s: from %s on %s: (S,G)=(%s,%pPAs) pref=%u metric=%u rpt_bit=%u", - __func__, neigh_str, ifp->name, source_str, &sg.grp, - msg_metric.metric_preference, msg_metric.route_metric, + "%s: from %s on %s: (S,G)=(%pPAs,%pPAs) pref=%u metric=%u rpt_bit=%u", + __func__, neigh_str, ifp->name, &msg_source_addr, + &sg.grp, msg_metric.metric_preference, + msg_metric.route_metric, PIM_FORCE_BOOLEAN(msg_metric.rpt_bit_flag)); } @@ -304,8 +304,7 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, assert(pim_ifp); ++pim_ifp->pim_ifstat_assert_recv; - return dispatch_assert(ifp, msg_source_addr.u.prefix4, sg.grp, - msg_metric); + return dispatch_assert(ifp, msg_source_addr, sg.grp, msg_metric); } /* diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 22890dc372..a3a97f20e5 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -165,7 +165,8 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, struct in_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size) { - struct prefix msg_upstream_addr; + pim_addr msg_upstream_addr; + bool wrong_af = false; struct pim_interface *pim_ifp; uint8_t msg_num_groups; uint16_t msg_holdtime; @@ -184,8 +185,8 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, /* Parse ucast addr */ - addr_offset = - pim_parse_addr_ucast(&msg_upstream_addr, buf, pastend - buf); + addr_offset = pim_parse_addr_ucast(&msg_upstream_addr, buf, + pastend - buf, &wrong_af); if (addr_offset < 1) { char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); @@ -198,12 +199,12 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, /* Check upstream address family */ - if (msg_upstream_addr.family != AF_INET) { + if (wrong_af) { char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); zlog_warn( - "%s: ignoring join/prune directed to unexpected addr family=%d from %s on %s", - __func__, msg_upstream_addr.family, src_str, ifp->name); + "%s: ignoring join/prune directed to unexpected addr family from %s on %s", + __func__, src_str, ifp->name); return -2; } @@ -226,14 +227,11 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_J_P) { char src_str[INET_ADDRSTRLEN]; - char upstream_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); - pim_inet4_dump("", msg_upstream_addr.u.prefix4, - upstream_str, sizeof(upstream_str)); zlog_debug( - "%s: join/prune upstream=%s groups=%d holdtime=%d from %s on %s", - __func__, upstream_str, msg_num_groups, msg_holdtime, - src_str, ifp->name); + "%s: join/prune upstream=%pPAs groups=%d holdtime=%d from %s on %s", + __func__, &msg_upstream_addr, msg_num_groups, + msg_holdtime, src_str, ifp->name); } /* Scan groups */ @@ -271,14 +269,11 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_J_P) { char src_str[INET_ADDRSTRLEN]; - char upstream_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); - pim_inet4_dump("", msg_upstream_addr.u.prefix4, - upstream_str, sizeof(upstream_str)); zlog_debug( - "%s: join/prune upstream=%s group=%pPA/32 join_src=%d prune_src=%d from %s on %s", - __func__, upstream_str, &sg.grp, + "%s: join/prune upstream=%pPAs group=%pPA/32 join_src=%d prune_src=%d from %s on %s", + __func__, &msg_upstream_addr, &sg.grp, msg_num_joined_sources, msg_num_pruned_sources, src_str, ifp->name); } @@ -300,9 +295,8 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, if (filtered) continue; - recv_join(ifp, neigh, msg_holdtime, - msg_upstream_addr.u.prefix4, &sg, - msg_source_flags); + recv_join(ifp, neigh, msg_holdtime, msg_upstream_addr, + &sg, msg_source_flags); if (pim_addr_is_any(sg.src)) { starg_ch = pim_ifchannel_find(ifp, &sg); @@ -326,9 +320,8 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, if (filtered) continue; - recv_prune(ifp, neigh, msg_holdtime, - msg_upstream_addr.u.prefix4, &sg, - msg_source_flags); + recv_prune(ifp, neigh, msg_holdtime, msg_upstream_addr, + &sg, msg_source_flags); /* * So if we are receiving a S,G,RPT prune * before we have any data for that S,G diff --git a/pimd/pim_register.c b/pimd/pim_register.c index 855d912566..a0def299fa 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -72,7 +72,6 @@ void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, unsigned int b1length = 0; unsigned int length; uint8_t *b1; - struct prefix p; if (PIM_DEBUG_PIM_REG) { zlog_debug("Sending Register stop for %pSG to %pI4 on %s", sg, @@ -86,10 +85,7 @@ void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, b1length += length; b1 += length; - p.family = AF_INET; - p.u.prefix4 = sg->src; - p.prefixlen = IPV4_MAX_BITLEN; - length = pim_encode_addr_ucast(b1, &p); + length = pim_encode_addr_ucast(b1, sg->src); b1length += length; pim_msg_build_header(buffer, b1length + PIM_MSG_REGISTER_STOP_LEN, @@ -117,8 +113,8 @@ int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size) struct pim_interface *pim_ifp = ifp->info; struct pim_instance *pim = pim_ifp->pim; struct pim_upstream *upstream = NULL; - struct prefix source; pim_sgaddr sg; + bool wrong_af = false; int l; ++pim_ifp->pim_ifstat_reg_stop_recv; @@ -127,8 +123,12 @@ int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size) l = pim_parse_addr_group(&sg, buf, buf_size); buf += l; buf_size -= l; - pim_parse_addr_ucast(&source, buf, buf_size); - sg.src = source.u.prefix4; + pim_parse_addr_ucast(&sg.src, buf, buf_size, &wrong_af); + + if (wrong_af) { + zlog_err("invalid AF in Register-Stop on %s", ifp->name); + return 0; + } upstream = pim_upstream_find(pim, &sg); if (!upstream) { diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index a4f60e5198..f38eed8cb1 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -29,6 +29,12 @@ #include "pim_str.h" #include "pim_msg.h" +#if PIM_IPV == 4 +#define PIM_MSG_ADDRESS_FAMILY PIM_MSG_ADDRESS_FAMILY_IPV4 +#else +#define PIM_MSG_ADDRESS_FAMILY PIM_MSG_ADDRESS_FAMILY_IPV6 +#endif + uint8_t *pim_tlv_append_uint16(uint8_t *buf, const uint8_t *buf_pastend, uint16_t option_type, uint16_t option_value) { @@ -117,7 +123,23 @@ uint8_t *pim_tlv_append_uint32(uint8_t *buf, const uint8_t *buf_pastend, * The unicast address as represented by the given Address Family * and Encoding Type. */ -int pim_encode_addr_ucast(uint8_t *buf, struct prefix *p) +int pim_encode_addr_ucast(uint8_t *buf, pim_addr addr) +{ + uint8_t *start = buf; + +#if PIM_IPV == 4 + *buf++ = PIM_MSG_ADDRESS_FAMILY_IPV4; +#else + *buf++ = PIM_MSG_ADDRESS_FAMILY_IPV6; +#endif + *buf++ = 0; + memcpy(buf, &addr, sizeof(addr)); + buf += sizeof(addr); + + return buf - start; +} + +int pim_encode_addr_ucast_prefix(uint8_t *buf, struct prefix *p) { switch (p->family) { case AF_INET: @@ -188,28 +210,22 @@ int pim_encode_addr_ucast(uint8_t *buf, struct prefix *p) * Contains the group address. */ int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope, - struct in_addr group) + pim_addr group) { + uint8_t *start = buf; uint8_t flags = 0; flags |= bidir << 8; flags |= scope; - switch (afi) { - case AFI_IP: - *buf = PIM_MSG_ADDRESS_FAMILY_IPV4; - ++buf; - *buf = 0; - ++buf; - *buf = flags; - ++buf; - *buf = 32; - ++buf; - memcpy(buf, &group, sizeof(struct in_addr)); - return group_ipv4_encoding_len; - default: - return 0; - } + *buf++ = PIM_MSG_ADDRESS_FAMILY; + *buf++ = 0; + *buf++ = flags; + *buf++ = sizeof(group) / 8; + memcpy(buf, &group, sizeof(group)); + buf += sizeof(group); + + return buf - start; } uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, @@ -248,7 +264,7 @@ uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, if (p->family != family) continue; - l_encode = pim_encode_addr_ucast(curr, p); + l_encode = pim_encode_addr_ucast_prefix(curr, p); curr += l_encode; option_len += l_encode; } @@ -441,7 +457,8 @@ int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr, return 0; } -int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) +int pim_parse_addr_ucast_prefix(struct prefix *p, const uint8_t *buf, + int buf_size) { const int ucast_encoding_min_len = 3; /* 1 family + 1 type + 1 addr */ const uint8_t *addr; @@ -510,6 +527,25 @@ int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size) return addr - buf; } +int pim_parse_addr_ucast(pim_addr *out, const uint8_t *buf, int buf_size, + bool *wrong_af) +{ + struct prefix p; + int ret; + + ret = pim_parse_addr_ucast_prefix(&p, buf, buf_size); + if (ret < 0) + return ret; + + if (p.family != PIM_AF) { + *wrong_af = true; + return -5; + } + + memcpy(out, &p.u.val, sizeof(*out)); + return ret; +} + int pim_parse_addr_group(pim_sgaddr *sg, const uint8_t *buf, int buf_size) { const int grp_encoding_min_len = @@ -532,40 +568,32 @@ int pim_parse_addr_group(pim_sgaddr *sg, const uint8_t *buf, int buf_size) family = *addr++; type = *addr++; - //++addr; ++addr; /* skip b_reserved_z fields */ mask_len = *addr++; - switch (family) { - case PIM_MSG_ADDRESS_FAMILY_IPV4: - if (type) { - zlog_warn( - "%s: unknown group address encoding type=%d from", - __func__, type); - return -2; - } + if (type) { + zlog_warn("%s: unknown group address encoding type=%d from", + __func__, type); + return -2; + } - if ((addr + sizeof(struct in_addr)) > pastend) { - zlog_warn( - "%s: IPv4 group address overflow: left=%td needed=%zu from", - __func__, pastend - addr, - sizeof(struct in_addr)); - return -3; - } - - memcpy(&sg->grp.s_addr, addr, sizeof(struct in_addr)); - - addr += sizeof(struct in_addr); - - break; - default: { + if (family != PIM_MSG_ADDRESS_FAMILY) { zlog_warn( "%s: unknown group address encoding family=%d mask_len=%d from", __func__, family, mask_len); return -4; } + + if ((addr + sizeof(sg->grp)) > pastend) { + zlog_warn( + "%s: group address overflow: left=%td needed=%zu from", + __func__, pastend - addr, sizeof(sg->grp)); + return -3; } + memcpy(&sg->grp, addr, sizeof(sg->grp)); + addr += sizeof(sg->grp); + return addr - buf; } @@ -676,7 +704,8 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, /* Parse ucast addr */ - addr_offset = pim_parse_addr_ucast(&tmp, addr, pastend - addr); + addr_offset = + pim_parse_addr_ucast_prefix(&tmp, addr, pastend - addr); if (addr_offset < 1) { char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("", src_addr, src_str, diff --git a/pimd/pim_tlv.h b/pimd/pim_tlv.h index 1aa60d5dbb..614c30a488 100644 --- a/pimd/pim_tlv.h +++ b/pimd/pim_tlv.h @@ -106,11 +106,15 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, struct list **hello_option_addr_list, uint16_t option_len, const uint8_t *tlv_curr); -int pim_encode_addr_ucast(uint8_t *buf, struct prefix *p); +int pim_encode_addr_ucast(uint8_t *buf, pim_addr addr); +int pim_encode_addr_ucast_prefix(uint8_t *buf, struct prefix *p); int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope, - struct in_addr group); + pim_addr group); -int pim_parse_addr_ucast(struct prefix *p, const uint8_t *buf, int buf_size); +int pim_parse_addr_ucast(pim_addr *out, const uint8_t *buf, int buf_size, + bool *wrong_af); +int pim_parse_addr_ucast_prefix(struct prefix *out, const uint8_t *buf, + int buf_size); int pim_parse_addr_group(pim_sgaddr *sg, const uint8_t *buf, int buf_size); int pim_parse_addr_source(pim_sgaddr *sg, uint8_t *flags, const uint8_t *buf, int buf_size); From 5d99ebea32756883267fbce7ea8103236449d97c Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 5 Jan 2022 19:38:17 +0100 Subject: [PATCH 04/14] pim6d: prepare/stub pim_rp_* functions for IPv6 These are sprinkled relatively widely through the PIM codebase, so for the time being reduce the "compiler warning surface" by moving them forward to proper types without actual implementations. Signed-off-by: David Lamparter --- pimd/pim_rp.c | 63 ++++++++++++++++++++++++++++----------------------- pimd/pim_rp.h | 8 +++---- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index f35adb0cea..702eace3c0 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -362,8 +362,8 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) { struct pim_rpf old_rpf; enum pim_rpf_result rpf_result; - struct in_addr old_upstream_addr; - struct in_addr new_upstream_addr; + pim_addr old_upstream_addr; + pim_addr new_upstream_addr; struct prefix nht_p; old_upstream_addr = up->upstream_addr; @@ -374,7 +374,7 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) zlog_debug("%s: pim upstream update for old upstream %pI4", __func__, &old_upstream_addr); - if (old_upstream_addr.s_addr == new_upstream_addr.s_addr) + if (!pim_addr_cmp(old_upstream_addr, new_upstream_addr)) return; /* Lets consider a case, where a PIM upstream has a better RP as a @@ -382,11 +382,9 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) * This upstream has to be added to the upstream hash of new RP's * NHT(pnc) and has to be removed from old RP's NHT upstream hash */ - if (old_upstream_addr.s_addr != INADDR_ANY) { + if (!pim_addr_is_any(old_upstream_addr)) { /* Deregister addr with Zebra NHT */ - nht_p.family = AF_INET; - nht_p.prefixlen = IPV4_MAX_BITLEN; - nht_p.u.prefix4 = old_upstream_addr; + pim_addr_to_prefix(&nht_p, old_upstream_addr); if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Deregister upstream %s addr %pFX with Zebra NHT", @@ -541,9 +539,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, struct prefix grp; struct rp_info *trp_info; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; + pim_addr_to_prefix(&grp, up->sg.grp); trp_info = pim_rp_find_match_group( pim, &grp); if (trp_info == rp_all) { @@ -632,9 +628,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, struct prefix grp; struct rp_info *trp_info; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; + pim_addr_to_prefix(&grp, up->sg.grp); trp_info = pim_rp_find_match_group(pim, &grp); if (trp_info == rp_info) { @@ -782,9 +776,8 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, rp_info->rp.rpf_addr.u.prefix4.s_addr) && pim_addr_is_any(up->sg.src)) { struct prefix grp; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; + + pim_addr_to_prefix(&grp, up->sg.grp); trp_info = pim_rp_find_match_group(pim, &grp); if (trp_info == rp_all) { pim_upstream_rpf_clear(pim, up); @@ -831,10 +824,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, pim_addr_is_any(up->sg.src)) { struct prefix grp; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; - + pim_addr_to_prefix(&grp, up->sg.grp); trp_info = pim_rp_find_match_group(pim, &grp); /* RP not found for the group grp */ @@ -918,9 +908,7 @@ int pim_rp_change(struct pim_instance *pim, struct in_addr new_rp_addr, struct prefix grp; struct rp_info *trp_info; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; + pim_addr_to_prefix(&grp, up->sg.grp); trp_info = pim_rp_find_match_group(pim, &grp); if (trp_info == rp_info) { @@ -1064,13 +1052,14 @@ void pim_i_am_rp_re_evaluate(struct pim_instance *pim) } } +#if PIM_IPV == 4 /* * I_am_RP(G) is true if the group-to-RP mapping indicates that * this router is the RP for the group. * * Since we only have static RP, all groups are part of this RP */ -int pim_rp_i_am_rp(struct pim_instance *pim, struct in_addr group) +int pim_rp_i_am_rp(struct pim_instance *pim, pim_addr group) { struct prefix g; struct rp_info *rp_info; @@ -1084,7 +1073,6 @@ int pim_rp_i_am_rp(struct pim_instance *pim, struct in_addr group) if (rp_info) return rp_info->i_am_rp; - return 0; } @@ -1093,7 +1081,7 @@ int pim_rp_i_am_rp(struct pim_instance *pim, struct in_addr group) * * Return the RP that the Group belongs too. */ -struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group) +struct pim_rpf *pim_rp_g(struct pim_instance *pim, pim_addr group) { struct prefix g; struct rp_info *rp_info; @@ -1135,8 +1123,8 @@ struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group) * then set the upstream addr as INADDR_ANY and return failure. * */ -int pim_rp_set_upstream_addr(struct pim_instance *pim, struct in_addr *up, - struct in_addr source, struct in_addr group) +int pim_rp_set_upstream_addr(struct pim_instance *pim, pim_addr *up, + pim_addr source, pim_addr group) { struct rp_info *rp_info; struct prefix g; @@ -1162,6 +1150,25 @@ int pim_rp_set_upstream_addr(struct pim_instance *pim, struct in_addr *up, return 1; } +#else +CPP_NOTICE("functions stubbed out for IPv6"); + +int pim_rp_i_am_rp(struct pim_instance *pim, pim_addr group) +{ + return 0; +} + +struct pim_rpf *pim_rp_g(struct pim_instance *pim, pim_addr group) +{ + return NULL; +} + +int pim_rp_set_upstream_addr(struct pim_instance *pim, pim_addr *up, + pim_addr source, pim_addr group) +{ + return 0; +} +#endif int pim_rp_config_write(struct pim_instance *pim, struct vty *vty, const char *spaces) diff --git a/pimd/pim_rp.h b/pimd/pim_rp.h index 595025e5c9..c223402ddd 100644 --- a/pimd/pim_rp.h +++ b/pimd/pim_rp.h @@ -65,17 +65,17 @@ int pim_rp_config_write(struct pim_instance *pim, struct vty *vty, void pim_rp_setup(struct pim_instance *pim); -int pim_rp_i_am_rp(struct pim_instance *pim, struct in_addr group); +int pim_rp_i_am_rp(struct pim_instance *pim, pim_addr group); void pim_rp_check_on_if_add(struct pim_interface *pim_ifp); void pim_i_am_rp_re_evaluate(struct pim_instance *pim); bool pim_rp_check_is_my_ip_address(struct pim_instance *pim, struct in_addr dest_addr); -int pim_rp_set_upstream_addr(struct pim_instance *pim, struct in_addr *up, - struct in_addr source, struct in_addr group); +int pim_rp_set_upstream_addr(struct pim_instance *pim, pim_addr *up, + pim_addr source, pim_addr group); -struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group); +struct pim_rpf *pim_rp_g(struct pim_instance *pim, pim_addr group); #define I_am_RP(P, G) pim_rp_i_am_rp ((P), (G)) #define RP(P, G) pim_rp_g ((P), (G)) From 80d9fa1e68a48786c8208dea3ef1171a7d3ccc38 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 17:23:51 +0100 Subject: [PATCH 05/14] pim6d: prepare SSM/filter functions Signed-off-by: David Lamparter --- pimd/pim_ssm.c | 9 +++------ pimd/pim_ssm.h | 2 +- pimd/pim_util.c | 8 +++----- pimd/pim_util.h | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pimd/pim_ssm.c b/pimd/pim_ssm.c index 6c5883aebf..45aac7756a 100644 --- a/pimd/pim_ssm.c +++ b/pimd/pim_ssm.c @@ -83,23 +83,20 @@ static int pim_is_grp_standard_ssm(struct prefix *group) return prefix_match(&group_ssm, group); } -int pim_is_grp_ssm(struct pim_instance *pim, struct in_addr group_addr) +int pim_is_grp_ssm(struct pim_instance *pim, pim_addr group_addr) { struct pim_ssm *ssm; struct prefix group; struct prefix_list *plist; - memset(&group, 0, sizeof(group)); - group.family = AF_INET; - group.u.prefix4 = group_addr; - group.prefixlen = 32; + pim_addr_to_prefix(&group, group_addr); ssm = pim->ssm_info; if (!ssm->plist_name) { return pim_is_grp_standard_ssm(&group); } - plist = prefix_list_lookup(AFI_IP, ssm->plist_name); + plist = prefix_list_lookup(PIM_AFI, ssm->plist_name); if (!plist) return 0; diff --git a/pimd/pim_ssm.h b/pimd/pim_ssm.h index 7235ade8dc..117713b866 100644 --- a/pimd/pim_ssm.h +++ b/pimd/pim_ssm.h @@ -34,7 +34,7 @@ struct pim_ssm { void pim_ssm_prefix_list_update(struct pim_instance *pim, struct prefix_list *plist); -int pim_is_grp_ssm(struct pim_instance *pim, struct in_addr group_addr); +int pim_is_grp_ssm(struct pim_instance *pim, pim_addr group_addr); int pim_ssm_range_set(struct pim_instance *pim, vrf_id_t vrf_id, const char *plist_name); void *pim_ssm_init(void); diff --git a/pimd/pim_util.c b/pimd/pim_util.c index decc491ede..8232d7205b 100644 --- a/pimd/pim_util.c +++ b/pimd/pim_util.c @@ -139,7 +139,7 @@ int pim_is_group_224_4(struct in_addr group_addr) return prefix_match(&group_all, &group); } -bool pim_is_group_filtered(struct pim_interface *pim_ifp, struct in_addr *grp) +bool pim_is_group_filtered(struct pim_interface *pim_ifp, pim_addr *grp) { struct prefix grp_pfx; struct prefix_list *pl; @@ -147,10 +147,8 @@ bool pim_is_group_filtered(struct pim_interface *pim_ifp, struct in_addr *grp) if (!pim_ifp->boundary_oil_plist) return false; - grp_pfx.family = AF_INET; - grp_pfx.prefixlen = IPV4_MAX_BITLEN; - grp_pfx.u.prefix4 = *grp; + pim_addr_to_prefix(&grp_pfx, *grp); - pl = prefix_list_lookup(AFI_IP, pim_ifp->boundary_oil_plist); + pl = prefix_list_lookup(PIM_AFI, pim_ifp->boundary_oil_plist); return pl ? prefix_list_apply(pl, &grp_pfx) == PREFIX_DENY : false; } diff --git a/pimd/pim_util.h b/pimd/pim_util.h index c66dd7b660..b9c227996e 100644 --- a/pimd/pim_util.h +++ b/pimd/pim_util.h @@ -35,5 +35,5 @@ void pim_pkt_dump(const char *label, const uint8_t *buf, int size); int pim_is_group_224_0_0_0_24(struct in_addr group_addr); int pim_is_group_224_4(struct in_addr group_addr); -bool pim_is_group_filtered(struct pim_interface *pim_ifp, struct in_addr *grp); +bool pim_is_group_filtered(struct pim_interface *pim_ifp, pim_addr *grp); #endif /* PIM_UTIL_H */ From c631920c151f0130986cb9051daa710bb0eb261b Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 16:55:12 +0100 Subject: [PATCH 06/14] pim6d: IPv6-adjust various pim_sgaddr uses Since `pim_sgaddr` is `pim_addr` now, that causes a whole lot of fallout anywhere S,G pairs are handled. Signed-off-by: David Lamparter --- pimd/pim_assert.c | 25 +++++++++---------------- pimd/pim_assert.h | 2 +- pimd/pim_bsm.c | 5 +---- pimd/pim_ifchannel.c | 4 +--- pimd/pim_join.c | 11 +++++------ pimd/pim_nht.c | 5 +---- pimd/pim_register.c | 7 +++---- pimd/pim_rpf.c | 4 +--- pimd/pim_upstream.c | 7 ++----- pimd/pim_zebra.c | 28 ++++++++++------------------ 10 files changed, 34 insertions(+), 64 deletions(-) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index f4b6e81bd6..7d2ebffab1 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -136,8 +136,8 @@ static void if_could_assert_do_a1(const char *caller, struct pim_ifchannel *ch) } } -static int dispatch_assert(struct interface *ifp, struct in_addr source_addr, - struct in_addr group_addr, +static int dispatch_assert(struct interface *ifp, pim_addr source_addr, + pim_addr group_addr, struct pim_assert_metric recv_metric) { struct pim_ifchannel *ch; @@ -353,7 +353,7 @@ int pim_assert_metric_match(const struct pim_assert_metric *m1, } int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, - struct in_addr group_addr, struct in_addr source_addr, + pim_addr group_addr, pim_addr source_addr, uint32_t metric_preference, uint32_t route_metric, uint32_t rpt_bit_flag) { @@ -367,28 +367,21 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, /* Encode group */ remain = buf_pastend - pim_msg_curr; - pim_msg_curr = pim_msg_addr_encode_ipv4_group(pim_msg_curr, group_addr); + pim_msg_curr = pim_msg_addr_encode_group(pim_msg_curr, group_addr); if (!pim_msg_curr) { - char group_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", group_addr, group_str, - sizeof(group_str)); zlog_warn( - "%s: failure encoding group address %s: space left=%d", - __func__, group_str, remain); + "%s: failure encoding group address %pPA: space left=%d", + __func__, &group_addr, remain); return -1; } /* Encode source */ remain = buf_pastend - pim_msg_curr; - pim_msg_curr = - pim_msg_addr_encode_ipv4_ucast(pim_msg_curr, source_addr); + pim_msg_curr = pim_msg_addr_encode_ucast(pim_msg_curr, source_addr); if (!pim_msg_curr) { - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", source_addr, source_str, - sizeof(source_str)); zlog_warn( - "%s: failure encoding source address %s: space left=%d", - __func__, source_str, remain); + "%s: failure encoding source address %pPA: space left=%d", + __func__, &source_addr, remain); return -2; } diff --git a/pimd/pim_assert.h b/pimd/pim_assert.h index a149fb176e..c7c11039af 100644 --- a/pimd/pim_assert.h +++ b/pimd/pim_assert.h @@ -67,7 +67,7 @@ int pim_assert_metric_match(const struct pim_assert_metric *m1, const struct pim_assert_metric *m2); int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, - struct in_addr group_addr, struct in_addr source_addr, + pim_addr group_addr, pim_addr source_addr, uint32_t metric_preference, uint32_t route_metric, uint32_t rpt_bit_flag); diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index 4214790476..afb4a60572 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -667,10 +667,7 @@ void pim_bsm_clear(struct pim_instance *pim) struct prefix grp; struct rp_info *trp_info; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; - + pim_addr_to_prefix(&grp, up->sg.grp); trp_info = pim_rp_find_match_group(pim, &grp); /* RP not found for the group grp */ diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 9248177724..343817544e 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -1235,10 +1235,8 @@ int pim_ifchannel_local_membership_add(struct interface *ifp, pim_sgaddr *sg, struct prefix_list *plist = prefix_list_lookup( AFI_IP, pim->spt.plist); struct prefix g; - g.family = AF_INET; - g.prefixlen = IPV4_MAX_BITLEN; - g.u.prefix4 = up->sg.grp; + pim_addr_to_prefix(&g, up->sg.grp); if (prefix_list_apply(plist, &g) == PREFIX_DENY) { pim_channel_add_oif( diff --git a/pimd/pim_join.c b/pimd/pim_join.c index a3a97f20e5..7aea411606 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -84,6 +84,7 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, if ((source_flags & PIM_RPT_BIT_MASK) && (source_flags & PIM_WILDCARD_BIT_MASK)) { struct pim_rpf *rp = RP(pim_ifp->pim, sg->grp); + pim_addr rpf_addr; if (!rp) { zlog_warn("%s: Lookup of RP failed for %pSG", __func__, @@ -94,13 +95,11 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, * If the RP sent in the message is not * our RP for the group, drop the message */ - if (sg->src.s_addr != rp->rpf_addr.u.prefix4.s_addr) { - char local_rp[INET_ADDRSTRLEN]; - pim_inet4_dump("", rp->rpf_addr.u.prefix4, - local_rp, sizeof(local_rp)); + rpf_addr = pim_addr_from_prefix(&rp->rpf_addr); + if (pim_addr_cmp(sg->src, rpf_addr)) { zlog_warn( - "%s: Specified RP(%pPAs) in join is different than our configured RP(%s)", - __func__, &sg->src, local_rp); + "%s: Specified RP(%pPAs) in join is different than our configured RP(%pPAs)", + __func__, &sg->src, &rpf_addr); return; } diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 26ca48543f..419e76c33f 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -237,10 +237,7 @@ void pim_delete_tracked_nexthop(struct pim_instance *pim, struct prefix *addr, if (!pim_addr_is_any(upstream->sg.src)) continue; - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = upstream->sg.grp; - + pim_addr_to_prefix(&grp, upstream->sg.grp); trp_info = pim_rp_find_match_group(pim, &grp); if (trp_info == rp) hash_release(pnc->upstream_hash, upstream); diff --git a/pimd/pim_register.c b/pimd/pim_register.c index a0def299fa..2cc80f957c 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -399,11 +399,10 @@ int pim_register_recv(struct interface *ifp, struct in_addr dest_addr, struct prefix_list *plist; struct prefix src; - plist = prefix_list_lookup(AFI_IP, pim->register_plist); + plist = prefix_list_lookup(PIM_AFI, + pim->register_plist); - src.family = AF_INET; - src.prefixlen = IPV4_MAX_BITLEN; - src.u.prefix4 = sg.src; + pim_addr_to_prefix(&src, sg.src); if (prefix_list_apply(plist, &src) == PREFIX_DENY) { pim_register_stop_send(ifp, &sg, dest_addr, diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index 1e865a3956..14e6e0dc98 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -255,9 +255,7 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, src.family = AF_INET; src.prefixlen = IPV4_MAX_BITLEN; src.u.prefix4 = up->upstream_addr; // RP or Src address - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = up->sg.grp; + pim_addr_to_prefix(&grp, up->sg.grp); if ((pim_addr_is_any(up->sg.src) && I_am_RP(pim, up->sg.grp)) || PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)) diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 800ec9c45c..68fb5ba382 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -2153,10 +2153,7 @@ void pim_upstream_remove_lhr_star_pimreg(struct pim_instance *pim, struct prefix g; enum prefix_list_type apply_new; - np = prefix_list_lookup(AFI_IP, nlist); - - g.family = AF_INET; - g.prefixlen = IPV4_MAX_BITLEN; + np = prefix_list_lookup(PIM_AFI, nlist); frr_each (rb_pim_upstream, &pim->upstream_head, up) { if (!pim_addr_is_any(up->sg.src)) @@ -2170,7 +2167,7 @@ void pim_upstream_remove_lhr_star_pimreg(struct pim_instance *pim, PIM_OIF_FLAG_PROTO_IGMP, __func__); continue; } - g.u.prefix4 = up->sg.grp; + pim_addr_to_prefix(&g, up->sg.grp); apply_new = prefix_list_apply(np, &g); if (apply_new == PREFIX_DENY) pim_channel_add_oif(up->channel_oil, pim->regiface, diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 2efafd4b9b..5f9273eb45 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -337,8 +337,8 @@ static int pim_zebra_vxlan_sg_proc(ZAPI_CALLBACK_ARGS) s = zclient->ibuf; prefixlen = stream_getl(s); - stream_get(&sg.src.s_addr, s, prefixlen); - stream_get(&sg.grp.s_addr, s, prefixlen); + stream_get(&sg.src, s, prefixlen); + stream_get(&sg.grp, s, prefixlen); if (PIM_DEBUG_ZEBRA) zlog_debug("%u:recv SG %s %pSG", vrf_id, @@ -606,7 +606,7 @@ void igmp_source_forward_start(struct pim_instance *pim, } if (!source->source_channel_oil) { - struct in_addr vif_source; + pim_addr vif_source; struct prefix src, grp; struct pim_nexthop nexthop; struct pim_upstream *up = NULL; @@ -619,12 +619,8 @@ void igmp_source_forward_start(struct pim_instance *pim, } else { - src.family = AF_INET; - src.prefixlen = IPV4_MAX_BITLEN; - src.u.prefix4 = vif_source; // RP or Src address - grp.family = AF_INET; - grp.prefixlen = IPV4_MAX_BITLEN; - grp.u.prefix4 = sg.grp; + pim_addr_to_prefix(&src, vif_source); // RP or Src addr + pim_addr_to_prefix(&grp, sg.grp); up = pim_upstream_find(pim, &sg); if (up) { @@ -642,15 +638,11 @@ void igmp_source_forward_start(struct pim_instance *pim, pim_ecmp_fib_lookup_if_vif_index( pim, &src, &grp); - if (PIM_DEBUG_ZEBRA) { - char buf2[INET_ADDRSTRLEN]; - - pim_inet4_dump("", vif_source, buf2, - sizeof(buf2)); - zlog_debug("%s: NHT %pSG vif_source %s vif_index:%d ", - __func__, &sg, buf2, - input_iface_vif_index); - } + if (PIM_DEBUG_ZEBRA) + zlog_debug( + "%s: NHT %pSG vif_source %pPAs vif_index:%d ", + __func__, &sg, &vif_source, + input_iface_vif_index); if (input_iface_vif_index < 1) { if (PIM_DEBUG_IGMP_TRACE) { From 9bb93fa04e58742f4afb97697381af69cddcabd4 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 17:47:14 +0100 Subject: [PATCH 07/14] pim6d: IPv6-adjust neigh->source_addr Signed-off-by: David Lamparter --- pimd/pim_bfd.c | 4 ++ pimd/pim_bsm.c | 9 ++-- pimd/pim_cmd.c | 4 +- pimd/pim_iface.c | 23 +++------ pimd/pim_iface.h | 6 +-- pimd/pim_ifchannel.c | 7 +-- pimd/pim_join.c | 27 ++++------ pimd/pim_jp_agg.c | 31 ++++-------- pimd/pim_neighbor.c | 116 +++++++++++++++++-------------------------- pimd/pim_neighbor.h | 6 ++- pimd/pim_nht.c | 35 +++++++++---- pimd/pim_rp.c | 12 +++-- pimd/pim_rpf.c | 12 +++-- pimd/pim_upstream.c | 24 ++++----- pimd/pim_zebra.c | 4 +- pimd/pim_zlookup.c | 6 +-- 16 files changed, 146 insertions(+), 180 deletions(-) diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 31f672bb80..3e3021dc4d 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -94,7 +94,11 @@ void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp, bfd_sess_set_timers( neigh->bfd_session, pim_ifp->bfd_config.detection_multiplier, pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx); +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) bfd_sess_set_ipv4_addrs(neigh->bfd_session, NULL, &neigh->source_addr); +#else + bfd_sess_set_ipv6_addrs(neigh->bfd_session, NULL, &neigh->source_addr); +#endif bfd_sess_set_interface(neigh->bfd_session, neigh->interface->name); bfd_sess_set_vrf(neigh->bfd_session, neigh->interface->vrf->vrf_id); bfd_sess_set_profile(neigh->bfd_session, pim_ifp->bfd_config.profile); diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index afb4a60572..6702feb657 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -948,12 +948,9 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) bool no_fwd = true; bool ret = false; - if (PIM_DEBUG_BSM) { - pim_inet4_dump("", neigh->source_addr, neigh_src_str, - sizeof(neigh_src_str)); - zlog_debug("%s: New neighbor %s seen on %s", __func__, - neigh_src_str, ifp->name); - } + if (PIM_DEBUG_BSM) + zlog_debug("%s: New neighbor %pPA seen on %s", __func__, + &neigh->source_addr, ifp->name); pim_ifp = ifp->info; diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 61d4f22e9f..da5fdfa51e 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2427,9 +2427,9 @@ static void pim_show_upstream(struct pim_instance *pim, struct vty *vty, if (!up->t_join_timer && up->rpf.source_nexthop.interface) { struct pim_neighbor *nbr; - nbr = pim_neighbor_find( + nbr = pim_neighbor_find_prefix( up->rpf.source_nexthop.interface, - up->rpf.rpf_addr.u.prefix4); + &up->rpf.rpf_addr); if (nbr) pim_time_timer_to_hhmmss(join_timer, sizeof(join_timer), diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 3f138e22e5..bd458b479a 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1094,8 +1094,7 @@ uint16_t pim_if_jp_override_interval_msec(struct interface *ifp) router (Section 4.3.4). The primary IP address of a neighbor is the address that it uses as the source of its PIM Hello messages. */ -struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, - struct in_addr addr) +struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, pim_addr addr) { struct listnode *neighnode; struct pim_neighbor *neigh; @@ -1111,15 +1110,13 @@ struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, return 0; } - p.family = AF_INET; - p.u.prefix4 = addr; - p.prefixlen = IPV4_MAX_BITLEN; + pim_addr_to_prefix(&p, addr); for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode, neigh)) { /* primary address ? */ - if (neigh->source_addr.s_addr == addr.s_addr) + if (!pim_addr_cmp(neigh->source_addr, addr)) return neigh; /* secondary address ? */ @@ -1127,13 +1124,10 @@ struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, return neigh; } - if (PIM_DEBUG_PIM_TRACE) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", addr, addr_str, sizeof(addr_str)); + if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: neighbor not found for address %s on interface %s", - __func__, addr_str, ifp->name); - } + "%s: neighbor not found for address %pPA on interface %s", + __func__, &addr, ifp->name); return NULL; } @@ -1383,8 +1377,7 @@ static void pim_if_igmp_join_del_all(struct interface *ifp) gone down (and may have come back up), and so we must assume it no longer knows it was the winner. */ -void pim_if_assert_on_neighbor_down(struct interface *ifp, - struct in_addr neigh_addr) +void pim_if_assert_on_neighbor_down(struct interface *ifp, pim_addr neigh_addr) { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; @@ -1397,7 +1390,7 @@ void pim_if_assert_on_neighbor_down(struct interface *ifp, if (ch->ifassert_state != PIM_IFASSERT_I_AM_LOSER) continue; /* Dead neighbor was winner ? */ - if (ch->ifassert_winner.s_addr != neigh_addr.s_addr) + if (pim_addr_cmp(ch->ifassert_winner, neigh_addr)) continue; assert_action_a5(ch); diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index f5f58a4bde..6278cb6722 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -226,8 +226,7 @@ int pim_if_lan_delay_enabled(struct interface *ifp); uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp); uint16_t pim_if_effective_override_interval_msec(struct interface *ifp); uint16_t pim_if_jp_override_interval_msec(struct interface *ifp); -struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, - struct in_addr addr); +struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, pim_addr addr); long pim_if_t_suppressed_msec(struct interface *ifp); int pim_if_t_override_msec(struct interface *ifp); @@ -241,8 +240,7 @@ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, void pim_if_update_could_assert(struct interface *ifp); -void pim_if_assert_on_neighbor_down(struct interface *ifp, - struct in_addr neigh_addr); +void pim_if_assert_on_neighbor_down(struct interface *ifp, pim_addr neigh_addr); void pim_if_rpf_interface_changed(struct interface *old_rpf_ifp, struct pim_upstream *up); diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 343817544e..a21277cde3 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -883,11 +883,8 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, address of the join message is our primary address. */ if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) { - char neigh_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", neigh_addr, neigh_str, - sizeof(neigh_str)); - zlog_warn("%s: Assert Loser recv Join%s from %s on %s", - __func__, ch->sg_str, neigh_str, ifp->name); + zlog_warn("%s: Assert Loser recv Join%s from %pI4 on %s", + __func__, ch->sg_str, &neigh_addr, ifp->name); assert_action_a5(ch); } diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 7aea411606..bb097dfe2e 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -61,15 +61,12 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_TRACE) { char up_str[INET_ADDRSTRLEN]; - char neigh_str[INET_ADDRSTRLEN]; pim_inet4_dump("", upstream, up_str, sizeof(up_str)); - pim_inet4_dump("", neigh->source_addr, neigh_str, - sizeof(neigh_str)); - zlog_debug("%s: join (S,G)=%pSG rpt=%d wc=%d upstream=%s holdtime=%d from %s on %s", - __func__, sg, - !!(source_flags & PIM_RPT_BIT_MASK), - !!(source_flags & PIM_WILDCARD_BIT_MASK), up_str, - holdtime, neigh_str, ifp->name); + zlog_debug( + "%s: join (S,G)=%pSG rpt=%d wc=%d upstream=%s holdtime=%d from %pPA on %s", + __func__, sg, !!(source_flags & PIM_RPT_BIT_MASK), + !!(source_flags & PIM_WILDCARD_BIT_MASK), up_str, + holdtime, &neigh->source_addr, ifp->name); } pim_ifp = ifp->info; @@ -126,16 +123,12 @@ static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh, if (PIM_DEBUG_PIM_TRACE) { char up_str[INET_ADDRSTRLEN]; - char neigh_str[INET_ADDRSTRLEN]; pim_inet4_dump("", upstream, up_str, sizeof(up_str)); - pim_inet4_dump("", neigh->source_addr, neigh_str, - sizeof(neigh_str)); - zlog_debug("%s: prune (S,G)=%pSG rpt=%d wc=%d upstream=%s holdtime=%d from %s on %s", - __func__, sg, - source_flags & PIM_RPT_BIT_MASK, - source_flags & PIM_WILDCARD_BIT_MASK, up_str, - holdtime, - neigh_str, ifp->name); + zlog_debug( + "%s: prune (S,G)=%pSG rpt=%d wc=%d upstream=%s holdtime=%d from %pPA on %s", + __func__, sg, source_flags & PIM_RPT_BIT_MASK, + source_flags & PIM_WILDCARD_BIT_MASK, up_str, holdtime, + &neigh->source_addr, ifp->name); } pim_ifp = ifp->info; diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index feeef15f81..f5836a1a87 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -163,17 +163,10 @@ void pim_jp_agg_remove_group(struct list *group, struct pim_upstream *up, } if (nbr) { - if (PIM_DEBUG_TRACE) { - char src_str[INET_ADDRSTRLEN]; - - pim_inet4_dump("", nbr->source_addr, src_str, - sizeof(src_str)); - zlog_debug( - "up %s remove from nbr %s/%s jp-agg-list", - up->sg_str, - nbr->interface->name, - src_str); - } + if (PIM_DEBUG_TRACE) + zlog_debug("up %s remove from nbr %s/%pPAs jp-agg-list", + up->sg_str, nbr->interface->name, + &nbr->source_addr); } if (js) { @@ -290,17 +283,11 @@ void pim_jp_agg_add_group(struct list *group, struct pim_upstream *up, } if (nbr) { - if (PIM_DEBUG_TRACE) { - char src_str[INET_ADDRSTRLEN]; - - pim_inet4_dump("", nbr->source_addr, src_str, - sizeof(src_str)); - zlog_debug( - "up %s add to nbr %s/%s jp-agg-list", - up->sg_str, - up->rpf.source_nexthop.interface->name, - src_str); - } + if (PIM_DEBUG_TRACE) + zlog_debug("up %s add to nbr %s/%pPAs jp-agg-list", + up->sg_str, + up->rpf.source_nexthop.interface->name, + &nbr->source_addr); } if (!js) { diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 530c2e429b..546c210af1 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -58,10 +58,8 @@ static void dr_election_by_addr(struct interface *ifp) } for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { - if (ntohl(neigh->source_addr.s_addr) - > ntohl(pim_ifp->pim_dr_addr.s_addr)) { + if (pim_addr_cmp(neigh->source_addr, pim_ifp->pim_dr_addr) > 0) pim_ifp->pim_dr_addr = neigh->source_addr; - } } } @@ -85,15 +83,14 @@ static void dr_election_by_pri(struct interface *ifp) for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { if (PIM_DEBUG_PIM_TRACE) { - zlog_info("%s: neigh pri %u addr %x if dr addr %x", + zlog_info("%s: neigh pri %u addr %pPA if dr addr %pPA", __func__, neigh->dr_priority, - ntohl(neigh->source_addr.s_addr), - ntohl(pim_ifp->pim_dr_addr.s_addr)); + &neigh->source_addr, &pim_ifp->pim_dr_addr); } - if ((neigh->dr_priority > dr_pri) - || ((neigh->dr_priority == dr_pri) - && (ntohl(neigh->source_addr.s_addr) - > ntohl(pim_ifp->pim_dr_addr.s_addr)))) { + if ((neigh->dr_priority > dr_pri) || + ((neigh->dr_priority == dr_pri) && + (pim_addr_cmp(neigh->source_addr, pim_ifp->pim_dr_addr) > + 0))) { pim_ifp->pim_dr_addr = neigh->source_addr; dr_pri = neigh->dr_priority; } @@ -218,14 +215,10 @@ static int on_neighbor_timer(struct thread *t) ifp = neigh->interface; - if (PIM_DEBUG_PIM_TRACE) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", neigh->source_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "Expired %d sec holdtime for neighbor %s on interface %s", - neigh->holdtime, src_str, ifp->name); - } + "Expired %d sec holdtime for neighbor %pPA on interface %s", + neigh->holdtime, &neigh->source_addr, ifp->name); snprintf(msg, sizeof(msg), "%d-sec holdtime expired", neigh->holdtime); pim_neighbor_delete(ifp, neigh, msg); @@ -255,14 +248,10 @@ void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime) return; } - if (PIM_DEBUG_PIM_TRACE_DETAIL) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", neigh->source_addr, src_str, - sizeof(src_str)); - zlog_debug("%s: starting %u sec timer for neighbor %s on %s", - __func__, neigh->holdtime, src_str, + if (PIM_DEBUG_PIM_TRACE_DETAIL) + zlog_debug("%s: starting %u sec timer for neighbor %pPA on %s", + __func__, neigh->holdtime, &neigh->source_addr, neigh->interface->name); - } thread_add_timer(router->master, on_neighbor_timer, neigh, neigh->holdtime, &neigh->t_expire_timer); @@ -273,17 +262,14 @@ static int on_neighbor_jp_timer(struct thread *t) struct pim_neighbor *neigh = THREAD_ARG(t); struct pim_rpf rpf; - if (PIM_DEBUG_PIM_TRACE) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", neigh->source_addr, src_str, - sizeof(src_str)); - zlog_debug("%s:Sending JP Agg to %s on %s with %d groups", - __func__, src_str, neigh->interface->name, + if (PIM_DEBUG_PIM_TRACE) + zlog_debug("%s:Sending JP Agg to %pPA on %s with %d groups", + __func__, &neigh->source_addr, + neigh->interface->name, neigh->upstream_jp_agg->count); - } rpf.source_nexthop.interface = neigh->interface; - rpf.rpf_addr.u.prefix4 = neigh->source_addr; + pim_addr_to_prefix(&rpf.rpf_addr, neigh->source_addr); pim_joinprune_send(&rpf, neigh->upstream_jp_agg); thread_add_timer(router->master, on_neighbor_jp_timer, neigh, @@ -300,7 +286,7 @@ static void pim_neighbor_start_jp_timer(struct pim_neighbor *neigh) } static struct pim_neighbor * -pim_neighbor_new(struct interface *ifp, struct in_addr source_addr, +pim_neighbor_new(struct interface *ifp, pim_addr source_addr, pim_hello_options hello_options, uint16_t holdtime, uint16_t propagation_delay, uint16_t override_interval, uint32_t dr_priority, uint32_t generation_id, @@ -308,7 +294,6 @@ pim_neighbor_new(struct interface *ifp, struct in_addr source_addr, { struct pim_interface *pim_ifp; struct pim_neighbor *neigh; - char src_str[INET_ADDRSTRLEN]; assert(ifp); pim_ifp = ifp->info; @@ -343,15 +328,12 @@ pim_neighbor_new(struct interface *ifp, struct in_addr source_addr, */ PIM_IF_FLAG_UNSET_HELLO_SENT(pim_ifp->flags); - pim_inet4_dump("", source_addr, src_str, sizeof(src_str)); + if (PIM_DEBUG_PIM_EVENTS) + zlog_debug("%s: creating PIM neighbor %pPA on interface %s", + __func__, &source_addr, ifp->name); - if (PIM_DEBUG_PIM_EVENTS) { - zlog_debug("%s: creating PIM neighbor %s on interface %s", - __func__, src_str, ifp->name); - } - - zlog_notice("PIM NEIGHBOR UP: neighbor %s on interface %s", src_str, - ifp->name); + zlog_notice("PIM NEIGHBOR UP: neighbor %pPA on interface %s", + &source_addr, ifp->name); if (neigh->propagation_delay_msec > pim_ifp->pim_neighbors_highest_propagation_delay_msec) { @@ -448,7 +430,7 @@ struct pim_neighbor *pim_neighbor_find_by_secondary(struct interface *ifp, } struct pim_neighbor *pim_neighbor_find(struct interface *ifp, - struct in_addr source_addr) + pim_addr source_addr) { struct pim_interface *pim_ifp; struct listnode *node; @@ -462,7 +444,7 @@ struct pim_neighbor *pim_neighbor_find(struct interface *ifp, return NULL; for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, node, neigh)) { - if (source_addr.s_addr == neigh->source_addr.s_addr) { + if (!pim_addr_cmp(source_addr, neigh->source_addr)) { return neigh; } } @@ -470,6 +452,15 @@ struct pim_neighbor *pim_neighbor_find(struct interface *ifp, return NULL; } +struct pim_neighbor *pim_neighbor_find_prefix(struct interface *ifp, + const struct prefix *src_prefix) +{ + pim_addr addr; + + addr = pim_addr_from_prefix(src_prefix); + return pim_neighbor_find(ifp, addr); +} + /* * Find the *one* interface out * this interface. If more than @@ -486,7 +477,7 @@ struct pim_neighbor *pim_neighbor_find_if(struct interface *ifp) } struct pim_neighbor * -pim_neighbor_add(struct interface *ifp, struct in_addr source_addr, +pim_neighbor_add(struct interface *ifp, pim_addr source_addr, pim_hello_options hello_options, uint16_t holdtime, uint16_t propagation_delay, uint16_t override_interval, uint32_t dr_priority, uint32_t generation_id, @@ -507,11 +498,8 @@ pim_neighbor_add(struct interface *ifp, struct in_addr source_addr, listnode_add(pim_ifp->pim_neighbor_list, neigh); - if (PIM_DEBUG_PIM_TRACE_DETAIL) { - char str[INET_ADDRSTRLEN]; - pim_inet4_dump("", source_addr, str, sizeof(str)); - zlog_debug("%s: neighbor %s added ", __func__, str); - } + if (PIM_DEBUG_PIM_TRACE_DETAIL) + zlog_debug("%s: neighbor %pPA added ", __func__, &source_addr); /* RFC 4601: 4.3.2. DR Election @@ -610,14 +598,12 @@ void pim_neighbor_delete(struct interface *ifp, struct pim_neighbor *neigh, const char *delete_message) { struct pim_interface *pim_ifp; - char src_str[INET_ADDRSTRLEN]; pim_ifp = ifp->info; assert(pim_ifp); - pim_inet4_dump("", neigh->source_addr, src_str, sizeof(src_str)); - zlog_notice("PIM NEIGHBOR DOWN: neighbor %s on interface %s: %s", - src_str, ifp->name, delete_message); + zlog_notice("PIM NEIGHBOR DOWN: neighbor %pPA on interface %s: %s", + &neigh->source_addr, ifp->name, delete_message); THREAD_OFF(neigh->t_expire_timer); @@ -664,8 +650,8 @@ void pim_neighbor_delete(struct interface *ifp, struct pim_neighbor *neigh, } if (PIM_DEBUG_PIM_TRACE) { - zlog_debug("%s: deleting PIM neighbor %s on interface %s", - __func__, src_str, ifp->name); + zlog_debug("%s: deleting PIM neighbor %pPA on interface %s", + __func__, &neigh->source_addr, ifp->name); } listnode_delete(pim_ifp->pim_neighbor_list, neigh); @@ -720,8 +706,7 @@ struct prefix *pim_neighbor_find_secondary(struct pim_neighbor *neigh, administrator in a rate-limited manner. */ static void delete_from_neigh_addr(struct interface *ifp, - struct list *addr_list, - struct in_addr neigh_addr) + struct list *addr_list, pim_addr neigh_addr) { struct listnode *addr_node; struct prefix *addr; @@ -752,24 +737,15 @@ static void delete_from_neigh_addr(struct interface *ifp, neigh, addr); if (p) { char addr_str[INET_ADDRSTRLEN]; - char this_neigh_str[INET_ADDRSTRLEN]; - char other_neigh_str[INET_ADDRSTRLEN]; pim_inet4_dump( "", addr->u.prefix4, addr_str, sizeof(addr_str)); - pim_inet4_dump("", neigh_addr, - this_neigh_str, - sizeof(this_neigh_str)); - pim_inet4_dump("", - neigh->source_addr, - other_neigh_str, - sizeof(other_neigh_str)); zlog_info( - "secondary addr %s recvd from neigh %s deleted from neigh %s on %s", - addr_str, this_neigh_str, - other_neigh_str, ifp->name); + "secondary addr %s recvd from neigh %pPA deleted from neigh %pPA on %s", + addr_str, &neigh_addr, + &neigh->source_addr, ifp->name); listnode_delete(neigh->prefix_list, p); prefix_free(&p); diff --git a/pimd/pim_neighbor.h b/pimd/pim_neighbor.h index 12c469ae2a..2673d22480 100644 --- a/pimd/pim_neighbor.h +++ b/pimd/pim_neighbor.h @@ -51,7 +51,9 @@ struct pim_neighbor { void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime); void pim_neighbor_free(struct pim_neighbor *neigh); struct pim_neighbor *pim_neighbor_find(struct interface *ifp, - struct in_addr source_addr); + pim_addr source_addr); +struct pim_neighbor *pim_neighbor_find_prefix(struct interface *ifp, + const struct prefix *src_prefix); struct pim_neighbor *pim_neighbor_find_by_secondary(struct interface *ifp, struct prefix *src); struct pim_neighbor *pim_neighbor_find_if(struct interface *ifp); @@ -60,7 +62,7 @@ struct pim_neighbor *pim_neighbor_find_if(struct interface *ifp); #define PIM_NEIGHBOR_SEND_DELAY 0 #define PIM_NEIGHBOR_SEND_NOW 1 struct pim_neighbor * -pim_neighbor_add(struct interface *ifp, struct in_addr source_addr, +pim_neighbor_add(struct interface *ifp, pim_addr source_addr, pim_hello_options hello_options, uint16_t holdtime, uint16_t propagation_delay, uint16_t override_interval, uint32_t dr_priority, uint32_t generation_id, diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 419e76c33f..beaa5c802b 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -335,8 +335,7 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, if (if_is_loopback(ifp) && if_is_loopback(src_ifp)) return true; - nbr = pim_neighbor_find(ifp, - znh->nexthop_addr.u.prefix4); + nbr = pim_neighbor_find_prefix(ifp, &znh->nexthop_addr); if (!nbr) continue; @@ -359,9 +358,10 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, */ for (nh = pnc->nexthop; nh; nh = nh->next) { - struct in_addr nhaddr; + pim_addr nhaddr; switch (nh->type) { +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) case NEXTHOP_TYPE_IPV4: if (nh->ifindex == IFINDEX_INTERNAL) continue; @@ -370,7 +370,16 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, case NEXTHOP_TYPE_IPV4_IFINDEX: nhaddr = nh->gate.ipv4; break; +#else + case NEXTHOP_TYPE_IPV6: + if (nh->ifindex == IFINDEX_INTERNAL) + continue; + /* fallthru */ + case NEXTHOP_TYPE_IPV6_IFINDEX: + nhaddr = nh->gate.ipv6; + break; +#endif case NEXTHOP_TYPE_IFINDEX: nhaddr = bsr_addr; break; @@ -547,9 +556,9 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, if (curr_route_valid && !pim_if_connected_to_source(nexthop->interface, src->u.prefix4)) { - nbr = pim_neighbor_find( + nbr = pim_neighbor_find_prefix( nexthop->interface, - nexthop->mrib_nexthop_addr.u.prefix4); + &nexthop->mrib_nexthop_addr); if (!nbr && !if_is_loopback(nexthop->interface)) { if (PIM_DEBUG_PIM_NHT) @@ -596,8 +605,12 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, ifps[i] = if_lookup_by_index(nh_node->ifindex, pim->vrf->vrf_id); if (ifps[i]) { - nbrs[i] = pim_neighbor_find(ifps[i], - nh_node->gate.ipv4); +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) + pim_addr nhaddr = nh_node->gate.ipv4; +#else + pim_addr nhaddr = nh_node->gate.ipv6; +#endif + nbrs[i] = pim_neighbor_find(ifps[i], nhaddr); if (nbrs[i] || pim_if_connected_to_source(ifps[i], src->u.prefix4)) @@ -786,7 +799,11 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) nbr = pim_neighbor_find_if(ifp1); /* Overwrite with Nbr address as NH addr */ if (nbr) +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) nexthop->gate.ipv4 = nbr->source_addr; +#else + nexthop->gate.ipv6 = nbr->source_addr; +#endif else { // Mark nexthop address to 0 until PIM // Nbr is resolved. @@ -947,8 +964,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, ifps[i] = if_lookup_by_index(nexthop_tab[i].ifindex, pim->vrf->vrf_id); if (ifps[i]) { - nbrs[i] = pim_neighbor_find( - ifps[i], nexthop_tab[i].nexthop_addr.u.prefix4); + nbrs[i] = pim_neighbor_find_prefix( + ifps[i], &nexthop_tab[i].nexthop_addr); if (nbrs[i] || pim_if_connected_to_source(ifps[i], src->u.prefix4)) diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 702eace3c0..0a52092b1e 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -1360,17 +1360,19 @@ void pim_resolve_rp_nh(struct pim_instance *pim, struct pim_neighbor *nbr) if (nbr->interface != ifp1) continue; +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) nh_node->gate.ipv4 = nbr->source_addr; +#else + nh_node->gate.ipv6 = nbr->source_addr; +#endif if (PIM_DEBUG_PIM_NHT_RP) { char str[PREFIX_STRLEN]; - char str1[INET_ADDRSTRLEN]; - pim_inet4_dump("", nbr->source_addr, - str1, sizeof(str1)); pim_addr_dump("", &nht_p, str, sizeof(str)); zlog_debug( - "%s: addr %s new nexthop addr %s interface %s", - __func__, str, str1, ifp1->name); + "%s: addr %s new nexthop addr %pPAs interface %s", + __func__, str, &nbr->source_addr, + ifp1->name); } } } diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index 14e6e0dc98..de56048632 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -141,8 +141,8 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, i++; } else if (neighbor_needed && !pim_if_connected_to_source(ifp, addr)) { - nbr = pim_neighbor_find( - ifp, nexthop_tab[i].nexthop_addr.u.prefix4); + nbr = pim_neighbor_find_prefix( + ifp, &nexthop_tab[i].nexthop_addr); if (PIM_DEBUG_PIM_TRACE_DETAIL) zlog_debug("ifp name: %s, pim nbr: %p", ifp->name, nbr); @@ -396,9 +396,11 @@ static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up) /* return NBR( RPF_interface(S), MRIB.next_hop( S ) ) */ - neigh = pim_if_find_neighbor( - up->rpf.source_nexthop.interface, - up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4); + pim_addr nhaddr; + + nhaddr = + pim_addr_from_prefix(&up->rpf.source_nexthop.mrib_nexthop_addr); + neigh = pim_if_find_neighbor(up->rpf.source_nexthop.interface, nhaddr); if (neigh) rpf_addr = neigh->source_addr; else diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 68fb5ba382..a3d46ba3d7 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -343,8 +343,8 @@ static void join_timer_stop(struct pim_upstream *up) THREAD_OFF(up->t_join_timer); if (up->rpf.source_nexthop.interface) - nbr = pim_neighbor_find(up->rpf.source_nexthop.interface, - up->rpf.rpf_addr.u.prefix4); + nbr = pim_neighbor_find_prefix(up->rpf.source_nexthop.interface, + &up->rpf.rpf_addr); if (nbr) pim_jp_agg_remove_group(nbr->upstream_jp_agg, up, nbr); @@ -357,8 +357,8 @@ void join_timer_start(struct pim_upstream *up) struct pim_neighbor *nbr = NULL; if (up->rpf.source_nexthop.interface) { - nbr = pim_neighbor_find(up->rpf.source_nexthop.interface, - up->rpf.rpf_addr.u.prefix4); + nbr = pim_neighbor_find_prefix(up->rpf.source_nexthop.interface, + &up->rpf.rpf_addr); if (PIM_DEBUG_PIM_EVENTS) { zlog_debug( @@ -449,8 +449,8 @@ void pim_upstream_join_suppress(struct pim_upstream *up, pim_time_timer_remain_msec(up->t_join_timer); else { /* Remove it from jp agg from the nbr for suppression */ - nbr = pim_neighbor_find(up->rpf.source_nexthop.interface, - up->rpf.rpf_addr.u.prefix4); + nbr = pim_neighbor_find_prefix(up->rpf.source_nexthop.interface, + &up->rpf.rpf_addr); if (nbr) { join_timer_remain_msec = pim_time_timer_remain_msec(nbr->jp_timer); @@ -504,8 +504,8 @@ void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label, /* upstream join tracked with neighbor jp timer */ struct pim_neighbor *nbr; - nbr = pim_neighbor_find(up->rpf.source_nexthop.interface, - up->rpf.rpf_addr.u.prefix4); + nbr = pim_neighbor_find_prefix(up->rpf.source_nexthop.interface, + &up->rpf.rpf_addr); if (nbr) join_timer_remain_msec = pim_time_timer_remain_msec(nbr->jp_timer); @@ -1274,15 +1274,13 @@ void pim_upstream_rpf_genid_changed(struct pim_instance *pim, */ frr_each (rb_pim_upstream, &pim->upstream_head, up) { if (PIM_DEBUG_PIM_TRACE) { - char neigh_str[INET_ADDRSTRLEN]; char rpf_addr_str[PREFIX_STRLEN]; - pim_inet4_dump("", neigh_addr, neigh_str, - sizeof(neigh_str)); pim_addr_dump("", &up->rpf.rpf_addr, rpf_addr_str, sizeof(rpf_addr_str)); zlog_debug( - "%s: matching neigh=%s against upstream (S,G)=%s[%s] joined=%d rpf_addr=%s", - __func__, neigh_str, up->sg_str, pim->vrf->name, + "%s: matching neigh=%pI4 against upstream (S,G)=%s[%s] joined=%d rpf_addr=%s", + __func__, &neigh_addr, up->sg_str, + pim->vrf->name, up->join_state == PIM_UPSTREAM_JOINED, rpf_addr_str); } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 5f9273eb45..adb1ebed93 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -254,8 +254,8 @@ void pim_zebra_upstream_rpf_changed(struct pim_instance *pim, if (old->source_nexthop.interface) { struct pim_neighbor *nbr; - nbr = pim_neighbor_find(old->source_nexthop.interface, - old->rpf_addr.u.prefix4); + nbr = pim_neighbor_find_prefix(old->source_nexthop.interface, + &old->rpf_addr); if (nbr) pim_jp_agg_remove_group(nbr->upstream_jp_agg, up, nbr); diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index 5997cc25a4..b169335a3a 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -300,9 +300,9 @@ static int zclient_read_nexthop(struct pim_instance *pim, if (nbr) { nexthop_tab[num_ifindex].nexthop_addr.family = AF_INET; - nexthop_tab[num_ifindex] - .nexthop_addr.u.prefix4 = - nbr->source_addr; + pim_addr_to_prefix( + &nexthop_tab[num_ifindex].nexthop_addr, + nbr->source_addr); } ++num_ifindex; break; From 11928ecf19e8b750b731b526863668197f38f9d6 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 18:03:21 +0100 Subject: [PATCH 08/14] pim6d: IPv6-adjust Hello/TLV processing Signed-off-by: David Lamparter --- pimd/pim_hello.c | 168 ++++++++++++++++------------------------------- pimd/pim_hello.h | 4 +- pimd/pim_tlv.c | 113 +++++++++++++------------------ pimd/pim_tlv.h | 10 +-- 4 files changed, 109 insertions(+), 186 deletions(-) diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c index 45ea6a9562..fe4f10aa6a 100644 --- a/pimd/pim_hello.c +++ b/pimd/pim_hello.c @@ -33,81 +33,62 @@ #include "pim_upstream.h" #include "pim_bsm.h" -static void on_trace(const char *label, struct interface *ifp, - struct in_addr src) +static void on_trace(const char *label, struct interface *ifp, pim_addr src) { - if (PIM_DEBUG_PIM_TRACE) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src, src_str, sizeof(src_str)); - zlog_debug("%s: from %s on %s", label, src_str, ifp->name); - } + if (PIM_DEBUG_PIM_TRACE) + zlog_debug("%s: from %pPAs on %s", label, &src, ifp->name); } static void tlv_trace_bool(const char *label, const char *tlv_name, - const char *ifname, struct in_addr src_addr, - int isset, int value) + const char *ifname, pim_addr src_addr, int isset, + int value) { - if (isset) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (isset) zlog_debug( - "%s: PIM hello option from %s on interface %s: %s=%d", - label, src_str, ifname, tlv_name, value); - } + "%s: PIM hello option from %pPAs on interface %s: %s=%d", + label, &src_addr, ifname, tlv_name, value); } static void tlv_trace_uint16(const char *label, const char *tlv_name, - const char *ifname, struct in_addr src_addr, - int isset, uint16_t value) + const char *ifname, pim_addr src_addr, int isset, + uint16_t value) { - if (isset) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (isset) zlog_debug( - "%s: PIM hello option from %s on interface %s: %s=%u", - label, src_str, ifname, tlv_name, value); - } + "%s: PIM hello option from %pPAs on interface %s: %s=%u", + label, &src_addr, ifname, tlv_name, value); } static void tlv_trace_uint32(const char *label, const char *tlv_name, - const char *ifname, struct in_addr src_addr, - int isset, uint32_t value) + const char *ifname, pim_addr src_addr, int isset, + uint32_t value) { - if (isset) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (isset) zlog_debug( - "%s: PIM hello option from %s on interface %s: %s=%u", - label, src_str, ifname, tlv_name, value); - } + "%s: PIM hello option from %pPAs on interface %s: %s=%u", + label, &src_addr, ifname, tlv_name, value); } static void tlv_trace_uint32_hex(const char *label, const char *tlv_name, - const char *ifname, struct in_addr src_addr, + const char *ifname, pim_addr src_addr, int isset, uint32_t value) { - if (isset) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (isset) zlog_debug( - "%s: PIM hello option from %s on interface %s: %s=%08x", - label, src_str, ifname, tlv_name, value); - } + "%s: PIM hello option from %pPAs on interface %s: %s=%08x", + label, &src_addr, ifname, tlv_name, value); } static void tlv_trace_list(const char *label, const char *tlv_name, - const char *ifname, struct in_addr src_addr, - int isset, struct list *addr_list) + const char *ifname, pim_addr src_addr, int isset, + struct list *addr_list) { - if (isset) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (isset) zlog_debug( - "%s: PIM hello option from %s on interface %s: %s size=%d list=%p", - label, src_str, ifname, tlv_name, + "%s: PIM hello option from %pPAs on interface %s: %s size=%d list=%p", + label, &src_addr, ifname, tlv_name, addr_list ? ((int)listcount(addr_list)) : -1, (void *)addr_list); - } } #define FREE_ADDR_LIST \ @@ -121,8 +102,8 @@ static void tlv_trace_list(const char *label, const char *tlv_name, return (code); \ } -int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, - uint8_t *tlv_buf, int tlv_buf_size) +int pim_hello_recv(struct interface *ifp, pim_addr src_addr, uint8_t *tlv_buf, + int tlv_buf_size) { struct pim_interface *pim_ifp; struct pim_neighbor *neigh; @@ -158,15 +139,11 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, int remain = tlv_pastend - tlv_curr; if (remain < PIM_TLV_MIN_SIZE) { - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: short PIM hello TLV size=%d < min=%d from %s on interface %s", + "%s: short PIM hello TLV size=%d < min=%d from %pPAs on interface %s", __func__, remain, PIM_TLV_MIN_SIZE, - src_str, ifp->name); - } + &src_addr, ifp->name); FREE_ADDR_LIST_THEN_RETURN(-1); } @@ -176,28 +153,20 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, tlv_curr += PIM_TLV_LENGTH_SIZE; if ((tlv_curr + option_len) > tlv_pastend) { - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: long PIM hello TLV type=%d length=%d > left=%td from %s on interface %s", + "%s: long PIM hello TLV type=%d length=%d > left=%td from %pPAs on interface %s", __func__, option_type, option_len, - tlv_pastend - tlv_curr, src_str, + tlv_pastend - tlv_curr, &src_addr, ifp->name); - } FREE_ADDR_LIST_THEN_RETURN(-2); } - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: parse left_size=%d: PIM hello TLV type=%d length=%d from %s on %s", + "%s: parse left_size=%d: PIM hello TLV type=%d length=%d from %pPAs on %s", __func__, remain, option_type, option_len, - src_str, ifp->name); - } + &src_addr, ifp->name); switch (option_type) { case PIM_MSG_OPTION_TYPE_HOLDTIME: @@ -242,26 +211,18 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, } break; case PIM_MSG_OPTION_TYPE_DM_STATE_REFRESH: - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: ignoring PIM hello dense-mode state refresh TLV option type=%d length=%d from %s on interface %s", + "%s: ignoring PIM hello dense-mode state refresh TLV option type=%d length=%d from %pPAs on interface %s", __func__, option_type, option_len, - src_str, ifp->name); - } + &src_addr, ifp->name); break; default: - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: ignoring unknown PIM hello TLV type=%d length=%d from %s on interface %s", + "%s: ignoring unknown PIM hello TLV type=%d length=%d from %pPAs on interface %s", __func__, option_type, option_len, - src_str, ifp->name); - } + &src_addr, ifp->name); } tlv_curr += option_len; @@ -310,14 +271,10 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, } if (!PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME)) { - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: PIM hello missing holdtime from %s on interface %s", - __func__, src_str, ifp->name); - } + "%s: PIM hello missing holdtime from %pPAs on interface %s", + __func__, &src_addr, ifp->name); } /* @@ -335,14 +292,10 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, hello_option_dr_priority, hello_option_generation_id, hello_option_addr_list, PIM_NEIGHBOR_SEND_DELAY); if (!neigh) { - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_warn( - "%s: failure creating PIM neighbor %s on interface %s", - __func__, src_str, ifp->name); - } + "%s: failure creating PIM neighbor %pPAs on interface %s", + __func__, &src_addr, ifp->name); FREE_ADDR_LIST_THEN_RETURN(-8); } /* Forward BSM if required */ @@ -368,16 +321,12 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, || (hello_option_generation_id != neigh->generation_id)) { /* GenID mismatch, then replace neighbor */ - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: GenId mismatch new=%08x old=%08x: replacing neighbor %s on %s", + "%s: GenId mismatch new=%08x old=%08x: replacing neighbor %pPAs on %s", __func__, hello_option_generation_id, - neigh->generation_id, src_str, + neigh->generation_id, &src_addr, ifp->name); - } pim_upstream_rpf_genid_changed(pim_ifp->pim, neigh->source_addr); @@ -392,15 +341,10 @@ int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, hello_option_addr_list, PIM_NEIGHBOR_SEND_NOW); if (!neigh) { - if (PIM_DEBUG_PIM_HELLO) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, - src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: failure re-creating PIM neighbor %s on interface %s", - __func__, src_str, ifp->name); - } + "%s: failure re-creating PIM neighbor %pPAs on interface %s", + __func__, &src_addr, ifp->name); FREE_ADDR_LIST_THEN_RETURN(-9); } /* Forward BSM if required */ diff --git a/pimd/pim_hello.h b/pimd/pim_hello.h index df41f97d9e..56084e06d2 100644 --- a/pimd/pim_hello.h +++ b/pimd/pim_hello.h @@ -24,8 +24,8 @@ #include "if.h" -int pim_hello_recv(struct interface *ifp, struct in_addr src_addr, - uint8_t *tlv_buf, int tlv_buf_size); +int pim_hello_recv(struct interface *ifp, pim_addr src_addr, uint8_t *tlv_buf, + int tlv_buf_size); int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf, int tlv_buf_size, uint16_t holdtime, diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index f38eed8cb1..86403dd54a 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -290,15 +290,13 @@ uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, } static int check_tlv_length(const char *label, const char *tlv_name, - const char *ifname, struct in_addr src_addr, + const char *ifname, pim_addr src_addr, int correct_len, int option_len) { if (option_len != correct_len) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); zlog_warn( - "%s: PIM hello %s TLV with incorrect value size=%d correct=%d from %s on interface %s", - label, tlv_name, option_len, correct_len, src_str, + "%s: PIM hello %s TLV with incorrect value size=%d correct=%d from %pPAs on interface %s", + label, tlv_name, option_len, correct_len, &src_addr, ifname); return -1; } @@ -306,49 +304,44 @@ static int check_tlv_length(const char *label, const char *tlv_name, return 0; } -static void check_tlv_redefinition_uint16( - const char *label, const char *tlv_name, const char *ifname, - struct in_addr src_addr, pim_hello_options options, - pim_hello_options opt_mask, uint16_t new, uint16_t old) +static void check_tlv_redefinition_uint16(const char *label, + const char *tlv_name, + const char *ifname, pim_addr src_addr, + pim_hello_options options, + pim_hello_options opt_mask, + uint16_t new, uint16_t old) { - if (PIM_OPTION_IS_SET(options, opt_mask)) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (PIM_OPTION_IS_SET(options, opt_mask)) zlog_warn( - "%s: PIM hello TLV redefined %s=%u old=%u from %s on interface %s", - label, tlv_name, new, old, src_str, ifname); - } + "%s: PIM hello TLV redefined %s=%u old=%u from %pPAs on interface %s", + label, tlv_name, new, old, &src_addr, ifname); } -static void check_tlv_redefinition_uint32( - const char *label, const char *tlv_name, const char *ifname, - struct in_addr src_addr, pim_hello_options options, - pim_hello_options opt_mask, uint32_t new, uint32_t old) +static void check_tlv_redefinition_uint32(const char *label, + const char *tlv_name, + const char *ifname, pim_addr src_addr, + pim_hello_options options, + pim_hello_options opt_mask, + uint32_t new, uint32_t old) { - if (PIM_OPTION_IS_SET(options, opt_mask)) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (PIM_OPTION_IS_SET(options, opt_mask)) zlog_warn( - "%s: PIM hello TLV redefined %s=%u old=%u from %s on interface %s", - label, tlv_name, new, old, src_str, ifname); - } + "%s: PIM hello TLV redefined %s=%u old=%u from %pPAs on interface %s", + label, tlv_name, new, old, &src_addr, ifname); } static void check_tlv_redefinition_uint32_hex( const char *label, const char *tlv_name, const char *ifname, - struct in_addr src_addr, pim_hello_options options, + pim_addr src_addr, pim_hello_options options, pim_hello_options opt_mask, uint32_t new, uint32_t old) { - if (PIM_OPTION_IS_SET(options, opt_mask)) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); + if (PIM_OPTION_IS_SET(options, opt_mask)) zlog_warn( - "%s: PIM hello TLV redefined %s=%08x old=%08x from %s on interface %s", - label, tlv_name, new, old, src_str, ifname); - } + "%s: PIM hello TLV redefined %s=%08x old=%08x from %pPAs on interface %s", + label, tlv_name, new, old, &src_addr, ifname); } -int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_holdtime(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint16_t *hello_option_holdtime, uint16_t option_len, const uint8_t *tlv_curr) @@ -372,7 +365,7 @@ int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr, return 0; } -int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_lan_prune_delay(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint16_t *hello_option_propagation_delay, uint16_t *hello_option_override_interval, @@ -408,7 +401,7 @@ int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr, return 0; } -int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_dr_priority(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint32_t *hello_option_dr_priority, uint16_t option_len, const uint8_t *tlv_curr) @@ -432,7 +425,7 @@ int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr, return 0; } -int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_generation_id(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint32_t *hello_option_generation_id, uint16_t option_len, const uint8_t *tlv_curr) @@ -682,7 +675,7 @@ int pim_parse_addr_source(pim_sgaddr *sg, uint8_t *flags, const uint8_t *buf, } \ } -int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_addr_list(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, struct list **hello_option_addr_list, uint16_t option_len, const uint8_t *tlv_curr) @@ -698,7 +691,7 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, addr = tlv_curr; pastend = tlv_curr + option_len; while (addr < pastend) { - struct prefix tmp; + struct prefix tmp, src_pfx; int addr_offset; /* @@ -707,12 +700,9 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, addr_offset = pim_parse_addr_ucast_prefix(&tmp, addr, pastend - addr); if (addr_offset < 1) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); zlog_warn( - "%s: pim_parse_addr_ucast() failure: from %s on %s", - __func__, src_str, ifname); + "%s: pim_parse_addr_ucast() failure: from %pPAs on %s", + __func__, &src_addr, ifname); FREE_ADDR_LIST(*hello_option_addr_list); return -1; } @@ -725,35 +715,28 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, switch (tmp.family) { case AF_INET: { char addr_str[INET_ADDRSTRLEN]; - char src_str[INET_ADDRSTRLEN]; pim_inet4_dump("", tmp.u.prefix4, addr_str, sizeof(addr_str)); - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); zlog_debug( - "%s: PIM hello TLV option: list_old_size=%d IPv4 address %s from %s on %s", + "%s: PIM hello TLV option: list_old_size=%d IPv4 address %s from %pPAs on %s", __func__, *hello_option_addr_list ? ((int)listcount( - *hello_option_addr_list)) + *hello_option_addr_list)) : -1, - addr_str, src_str, ifname); + addr_str, &src_addr, ifname); } break; case AF_INET6: break; - default: { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); + default: zlog_debug( - "%s: PIM hello TLV option: list_old_size=%d UNKNOWN address family from %s on %s", + "%s: PIM hello TLV option: list_old_size=%d UNKNOWN address family from %pPAs on %s", __func__, *hello_option_addr_list ? ((int)listcount( - *hello_option_addr_list)) + *hello_option_addr_list)) : -1, - src_str, ifname); - } + &src_addr, ifname); } } @@ -761,16 +744,12 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, Exclude neighbor's primary address if incorrectly included in the secondary address list */ - if (tmp.family == AF_INET) { - if (tmp.u.prefix4.s_addr == src_addr.s_addr) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, - sizeof(src_str)); - zlog_warn( - "%s: ignoring primary address in secondary list from %s on %s", - __func__, src_str, ifname); - continue; - } + pim_addr_to_prefix(&src_pfx, src_addr); + if (!prefix_cmp(&tmp, &src_pfx)) { + zlog_warn( + "%s: ignoring primary address in secondary list from %pPAs on %s", + __func__, &src_addr, ifname); + continue; } /* diff --git a/pimd/pim_tlv.h b/pimd/pim_tlv.h index 614c30a488..64b3a0b6ba 100644 --- a/pimd/pim_tlv.h +++ b/pimd/pim_tlv.h @@ -84,24 +84,24 @@ uint8_t *pim_tlv_append_uint32(uint8_t *buf, const uint8_t *buf_pastend, uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend, struct list *ifconnected, int family); -int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_holdtime(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint16_t *hello_option_holdtime, uint16_t option_len, const uint8_t *tlv_curr); -int pim_tlv_parse_lan_prune_delay(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_lan_prune_delay(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint16_t *hello_option_propagation_delay, uint16_t *hello_option_override_interval, uint16_t option_len, const uint8_t *tlv_curr); -int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_dr_priority(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint32_t *hello_option_dr_priority, uint16_t option_len, const uint8_t *tlv_curr); -int pim_tlv_parse_generation_id(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_generation_id(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, uint32_t *hello_option_generation_id, uint16_t option_len, const uint8_t *tlv_curr); -int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, +int pim_tlv_parse_addr_list(const char *ifname, pim_addr src_addr, pim_hello_options *hello_options, struct list **hello_option_addr_list, uint16_t option_len, const uint8_t *tlv_curr); From 01adb431d38c4481795cae0e36b59014f389e0e3 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 19:12:32 +0100 Subject: [PATCH 09/14] pim6d: IPv6-adjust pim_upstream addr Signed-off-by: David Lamparter --- pimd/pim_join.c | 28 +++++++++++----------------- pimd/pim_rp.c | 16 ++++++++++------ pimd/pim_rpf.c | 10 +++------- pimd/pim_upstream.c | 12 +++++------- pimd/pim_vxlan.c | 4 +--- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/pimd/pim_join.c b/pimd/pim_join.c index bb097dfe2e..1a3adc305c 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -54,20 +54,17 @@ static void on_trace(const char *label, struct interface *ifp, } static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, - uint16_t holdtime, struct in_addr upstream, - pim_sgaddr *sg, uint8_t source_flags) + uint16_t holdtime, pim_addr upstream, pim_sgaddr *sg, + uint8_t source_flags) { struct pim_interface *pim_ifp = NULL; - if (PIM_DEBUG_PIM_TRACE) { - char up_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", upstream, up_str, sizeof(up_str)); + if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: join (S,G)=%pSG rpt=%d wc=%d upstream=%s holdtime=%d from %pPA on %s", + "%s: join (S,G)=%pSG rpt=%d wc=%d upstream=%pPAs holdtime=%d from %pPA on %s", __func__, sg, !!(source_flags & PIM_RPT_BIT_MASK), - !!(source_flags & PIM_WILDCARD_BIT_MASK), up_str, + !!(source_flags & PIM_WILDCARD_BIT_MASK), &upstream, holdtime, &neigh->source_addr, ifp->name); - } pim_ifp = ifp->info; assert(pim_ifp); @@ -116,20 +113,17 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh, } static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh, - uint16_t holdtime, struct in_addr upstream, - pim_sgaddr *sg, uint8_t source_flags) + uint16_t holdtime, pim_addr upstream, pim_sgaddr *sg, + uint8_t source_flags) { struct pim_interface *pim_ifp = NULL; - if (PIM_DEBUG_PIM_TRACE) { - char up_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", upstream, up_str, sizeof(up_str)); + if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: prune (S,G)=%pSG rpt=%d wc=%d upstream=%s holdtime=%d from %pPA on %s", + "%s: prune (S,G)=%pSG rpt=%d wc=%d upstream=%pPAs holdtime=%d from %pPA on %s", __func__, sg, source_flags & PIM_RPT_BIT_MASK, - source_flags & PIM_WILDCARD_BIT_MASK, up_str, holdtime, - &neigh->source_addr, ifp->name); - } + source_flags & PIM_WILDCARD_BIT_MASK, &upstream, + holdtime, &neigh->source_addr, ifp->name); pim_ifp = ifp->info; assert(pim_ifp); diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 0a52092b1e..fb448632db 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -534,7 +534,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, /* Find (*, G) upstream whose RP is not * configured yet */ - if ((up->upstream_addr.s_addr == INADDR_ANY) && + if (pim_addr_is_any(up->upstream_addr) && pim_addr_is_any(up->sg.src)) { struct prefix grp; struct rp_info *trp_info; @@ -772,8 +772,10 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, /* Find the upstream (*, G) whose upstream address is * same as the deleted RP */ - if ((up->upstream_addr.s_addr == - rp_info->rp.rpf_addr.u.prefix4.s_addr) && + pim_addr rpf_addr; + + rpf_addr = pim_addr_from_prefix(&rp_info->rp.rpf_addr); + if (!pim_addr_cmp(up->upstream_addr, rpf_addr) && pim_addr_is_any(up->sg.src)) { struct prefix grp; @@ -781,7 +783,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, trp_info = pim_rp_find_match_group(pim, &grp); if (trp_info == rp_all) { pim_upstream_rpf_clear(pim, up); - up->upstream_addr.s_addr = INADDR_ANY; + up->upstream_addr = PIMADDR_ANY; } } } @@ -819,8 +821,10 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, /* Find the upstream (*, G) whose upstream address is same as * the deleted RP */ - if ((up->upstream_addr.s_addr == - rp_info->rp.rpf_addr.u.prefix4.s_addr) && + pim_addr rpf_addr; + + rpf_addr = pim_addr_from_prefix(&rp_info->rp.rpf_addr); + if (!pim_addr_cmp(up->upstream_addr, rpf_addr) && pim_addr_is_any(up->sg.src)) { struct prefix grp; diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index de56048632..2e8fc8e661 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -234,7 +234,7 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, if (PIM_UPSTREAM_FLAG_TEST_STATIC_IIF(up->flags)) return PIM_RPF_OK; - if (up->upstream_addr.s_addr == INADDR_ANY) { + if (pim_addr_is_any(up->upstream_addr)) { zlog_debug("%s(%s): RP is not configured yet for %s", __func__, caller, up->sg_str); return PIM_RPF_OK; @@ -248,13 +248,9 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, old->rpf_addr = saved.rpf_addr; } - nht_p.family = AF_INET; - nht_p.prefixlen = IPV4_MAX_BITLEN; - nht_p.u.prefix4.s_addr = up->upstream_addr.s_addr; + pim_addr_to_prefix(&nht_p, up->upstream_addr); - src.family = AF_INET; - src.prefixlen = IPV4_MAX_BITLEN; - src.u.prefix4 = up->upstream_addr; // RP or Src address + pim_addr_to_prefix(&src, up->upstream_addr); // RP or Src address pim_addr_to_prefix(&grp, up->sg.grp); if ((pim_addr_is_any(up->sg.src) && I_am_RP(pim, up->sg.grp)) || diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index a3d46ba3d7..a410a1c2ce 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -259,11 +259,9 @@ struct pim_upstream *pim_upstream_del(struct pim_instance *pim, * to INADDR_ANY. This is done in order to avoid de-registering for * 255.255.255.255 which is maintained for some reason.. */ - if (up->upstream_addr.s_addr != INADDR_ANY) { + if (!pim_addr_is_any(up->upstream_addr)) { /* Deregister addr with Zebra NHT */ - nht_p.family = AF_INET; - nht_p.prefixlen = IPV4_MAX_BITLEN; - nht_p.u.prefix4 = up->upstream_addr; + pim_addr_to_prefix(&nht_p, up->upstream_addr); if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: Deregister upstream %s addr %pFX with Zebra NHT", @@ -713,7 +711,7 @@ void pim_upstream_switch(struct pim_instance *pim, struct pim_upstream *up, { enum pim_upstream_state old_state = up->join_state; - if (up->upstream_addr.s_addr == INADDR_ANY) { + if (pim_addr_is_any(up->upstream_addr)) { if (PIM_DEBUG_PIM_EVENTS) zlog_debug("%s: RPF not configured for %s", __func__, up->sg_str); @@ -937,7 +935,7 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, if (PIM_UPSTREAM_FLAG_TEST_SRC_NOCACHE(up->flags)) pim_upstream_keep_alive_timer_start( up, pim->keep_alive_time); - } else if (up->upstream_addr.s_addr != INADDR_ANY) { + } else if (!pim_addr_is_any(up->upstream_addr)) { pim_upstream_update_use_rpt(up, false /*update_mroute*/); rpf_result = pim_rpf_update(pim, up, NULL, __func__); @@ -1912,7 +1910,7 @@ void pim_upstream_find_new_rpf(struct pim_instance *pim) * Scan all (S,G) upstreams searching for RPF'(S,G)=neigh_addr */ frr_each (rb_pim_upstream, &pim->upstream_head, up) { - if (up->upstream_addr.s_addr == INADDR_ANY) { + if (pim_addr_is_any(up->upstream_addr)) { if (PIM_DEBUG_PIM_TRACE) zlog_debug( "%s: RP not configured for Upstream %s", diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c index c1e7be5870..39a1a32a5b 100644 --- a/pimd/pim_vxlan.c +++ b/pimd/pim_vxlan.c @@ -354,9 +354,7 @@ static void pim_vxlan_orig_mr_up_add(struct pim_vxlan_sg *vxlan_sg) * iif */ if (!PIM_UPSTREAM_FLAG_TEST_STATIC_IIF(up->flags)) { - nht_p.family = AF_INET; - nht_p.prefixlen = IPV4_MAX_BITLEN; - nht_p.u.prefix4 = up->upstream_addr; + pim_addr_to_prefix(&nht_p, up->upstream_addr); pim_delete_tracked_nexthop(vxlan_sg->pim, &nht_p, up, NULL); } From 034db86b72933be426d220c8ff1c6d31810fb860 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 17:52:36 +0100 Subject: [PATCH 10/14] pim6d: IPv6-adjust iface primary/DR addrs Signed-off-by: David Lamparter --- pimd/pim_bsm.c | 2 +- pimd/pim_iface.c | 82 +++++++++++++++++++++------------------------ pimd/pim_iface.h | 6 ++-- pimd/pim_neighbor.c | 19 ++++------- pimd/pim_rp.c | 6 ++-- pimd/pim_vty.c | 10 ++---- pimd/pim_zebra.c | 12 ++++--- 7 files changed, 63 insertions(+), 74 deletions(-) diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index 6702feb657..add9b7fe69 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -955,7 +955,7 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) pim_ifp = ifp->info; /* DR only forwards BSM packet */ - if (pim_ifp->pim_dr_addr.s_addr == pim_ifp->primary_address.s_addr) { + if (!pim_addr_cmp(pim_ifp->pim_dr_addr, pim_ifp->primary_address)) { if (PIM_DEBUG_BSM) zlog_debug( "%s: It is not DR, so don't forward BSM packet", diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index bd458b479a..1cdc46df6a 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -299,27 +299,20 @@ static int detect_primary_address_change(struct interface *ifp, const char *caller) { struct pim_interface *pim_ifp = ifp->info; - struct in_addr new_prim_addr; + pim_addr new_prim_addr; int changed; if (force_prim_as_any) - new_prim_addr.s_addr = INADDR_ANY; + new_prim_addr = PIMADDR_ANY; else new_prim_addr = pim_find_primary_addr(ifp); - changed = new_prim_addr.s_addr != pim_ifp->primary_address.s_addr; + changed = pim_addr_cmp(new_prim_addr, pim_ifp->primary_address); - if (PIM_DEBUG_ZEBRA) { - char new_prim_str[INET_ADDRSTRLEN]; - char old_prim_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", new_prim_addr, new_prim_str, - sizeof(new_prim_str)); - pim_inet4_dump("", pim_ifp->primary_address, old_prim_str, - sizeof(old_prim_str)); - zlog_debug("%s: old=%s new=%s on interface %s: %s", __func__, - old_prim_str, new_prim_str, ifp->name, - changed ? "changed" : "unchanged"); - } + if (PIM_DEBUG_ZEBRA) + zlog_debug("%s: old=%pPA new=%pPA on interface %s: %s", + __func__, &pim_ifp->primary_address, &new_prim_addr, + ifp->name, changed ? "changed" : "unchanged"); if (changed) { /* Before updating pim_ifp send Hello time with 0 hold time */ @@ -401,19 +394,18 @@ static int pim_sec_addr_update(struct interface *ifp) } for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { - struct prefix *p = ifc->address; + pim_addr addr = pim_addr_from_prefix(ifc->address); - if (p->u.prefix4.s_addr == INADDR_ANY) { + if (pim_addr_is_any(addr)) continue; - } - if (pim_ifp->primary_address.s_addr == p->u.prefix4.s_addr) { + if (!pim_addr_cmp(addr, pim_ifp->primary_address)) { /* don't add the primary address into the secondary * address list */ continue; } - if (pim_sec_addr_add(pim_ifp, p)) { + if (pim_sec_addr_add(pim_ifp, ifc->address)) { changed = 1; } } @@ -480,7 +472,7 @@ static void detect_address_change(struct interface *ifp, int force_prim_as_any, * address change on all of them when the lo address changes */ } -int pim_update_source_set(struct interface *ifp, struct in_addr source) +int pim_update_source_set(struct interface *ifp, pim_addr source) { struct pim_interface *pim_ifp = ifp->info; @@ -488,7 +480,7 @@ int pim_update_source_set(struct interface *ifp, struct in_addr source) return PIM_IFACE_NOT_FOUND; } - if (pim_ifp->update_source.s_addr == source.s_addr) { + if (!pim_addr_cmp(pim_ifp->update_source, source)) { return PIM_UPDATE_SOURCE_DUP; } @@ -827,11 +819,10 @@ void pim_if_addr_del_all_igmp(struct interface *ifp) } } -struct in_addr pim_find_primary_addr(struct interface *ifp) +pim_addr pim_find_primary_addr(struct interface *ifp) { struct connected *ifc; struct listnode *node; - struct in_addr addr = {0}; int v4_addrs = 0; int v6_addrs = 0; struct pim_interface *pim_ifp = ifp->info; @@ -841,28 +832,35 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) } for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { - struct prefix *p = ifc->address; + pim_addr addr; - if (p->family != AF_INET) { + switch (ifc->address->family) { + case AF_INET: + v4_addrs++; + break; + case AF_INET6: v6_addrs++; + break; + default: continue; } - if (p->u.prefix4.s_addr == INADDR_ANY) { - zlog_warn( - "%s: null IPv4 address connected to interface %s", - __func__, ifp->name); - continue; - } - - v4_addrs++; - if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) continue; - return p->u.prefix4; + if (ifc->address->family != PIM_AF) + continue; + + addr = pim_addr_from_prefix(ifc->address); + +#if PIM_IPV == 6 + if (!IN6_IS_ADDR_LINKLOCAL(&addr)) + continue; +#endif + return addr; } +#if PIM_IPV == 4 /* * If we have no v4_addrs and v6 is configured * We probably are using unnumbered @@ -882,10 +880,8 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) if (lo_ifp && (lo_ifp != ifp)) return pim_find_primary_addr(lo_ifp); } - - addr.s_addr = PIM_NET_INADDR_ANY; - - return addr; +#endif + return PIMADDR_ANY; } static int pim_iface_next_vif_index(struct interface *ifp) @@ -1466,7 +1462,7 @@ void pim_if_create_pimreg(struct pim_instance *pim) } } -struct prefix *pim_if_connected_to_source(struct interface *ifp, struct in_addr src) +struct prefix *pim_if_connected_to_source(struct interface *ifp, pim_addr src) { struct listnode *cnode; struct connected *c; @@ -1475,12 +1471,10 @@ struct prefix *pim_if_connected_to_source(struct interface *ifp, struct in_addr if (!ifp) return NULL; - p.family = AF_INET; - p.u.prefix4 = src; - p.prefixlen = IPV4_MAX_BITLEN; + pim_addr_to_prefix(&p, src); for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { - if (c->address->family != AF_INET) + if (c->address->family != PIM_AF) continue; if (prefix_match(c->address, &p)) return c->address; diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 6278cb6722..00ec8e7427 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -231,7 +231,7 @@ struct pim_neighbor *pim_if_find_neighbor(struct interface *ifp, pim_addr addr); long pim_if_t_suppressed_msec(struct interface *ifp); int pim_if_t_override_msec(struct interface *ifp); -struct in_addr pim_find_primary_addr(struct interface *ifp); +pim_addr pim_find_primary_addr(struct interface *ifp); ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr); @@ -251,8 +251,8 @@ void pim_if_update_assert_tracking_desired(struct interface *ifp); void pim_if_create_pimreg(struct pim_instance *pim); -struct prefix *pim_if_connected_to_source(struct interface *ifp, struct in_addr src); -int pim_update_source_set(struct interface *ifp, struct in_addr source); +struct prefix *pim_if_connected_to_source(struct interface *ifp, pim_addr src); +int pim_update_source_set(struct interface *ifp, pim_addr source); bool pim_if_is_vrf_device(struct interface *ifp); diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 546c210af1..6e3d2739e7 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -107,7 +107,7 @@ static void dr_election_by_pri(struct interface *ifp) int pim_if_dr_election(struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; - struct in_addr old_dr_addr; + pim_addr old_dr_addr; ++pim_ifp->pim_dr_election_count; @@ -120,18 +120,13 @@ int pim_if_dr_election(struct interface *ifp) } /* DR changed ? */ - if (old_dr_addr.s_addr != pim_ifp->pim_dr_addr.s_addr) { + if (pim_addr_cmp(old_dr_addr, pim_ifp->pim_dr_addr)) { - if (PIM_DEBUG_PIM_EVENTS) { - char dr_old_str[INET_ADDRSTRLEN]; - char dr_new_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", old_dr_addr, dr_old_str, - sizeof(dr_old_str)); - pim_inet4_dump("", pim_ifp->pim_dr_addr, - dr_new_str, sizeof(dr_new_str)); - zlog_debug("%s: DR was %s now is %s on interface %s", - __func__, dr_old_str, dr_new_str, ifp->name); - } + if (PIM_DEBUG_PIM_EVENTS) + zlog_debug( + "%s: DR was %pPA now is %pPA on interface %s", + __func__, &old_dr_addr, &pim_ifp->pim_dr_addr, + ifp->name); pim_ifp->pim_dr_election_last = pim_time_monotonic_sec(); /* timestamp */ diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index fb448632db..a5183c9e9b 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -322,9 +322,11 @@ static int pim_rp_check_interface_addrs(struct rp_info *rp_info, { struct listnode *node; struct pim_secondary_addr *sec_addr; + pim_addr rpf_addr; - if (pim_ifp->primary_address.s_addr - == rp_info->rp.rpf_addr.u.prefix4.s_addr) + rpf_addr = pim_addr_from_prefix(&rp_info->rp.rpf_addr); + + if (!pim_addr_cmp(pim_ifp->primary_address, rpf_addr)) return 1; if (!pim_ifp->sec_addr_list) { diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index c543c63eeb..8130aac872 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -341,13 +341,9 @@ int pim_interface_config_write(struct vty *vty) /* update source */ if (!pim_addr_is_any(pim_ifp->update_source)) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", - pim_ifp->update_source, - src_str, - sizeof(src_str)); - vty_out(vty, " ip pim use-source %s\n", - src_str); + vty_out(vty, + " ip pim use-source %pPA\n", + &pim_ifp->update_source); ++writes; } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index adb1ebed93..11b13db318 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -141,12 +141,14 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) #endif } - if (!CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY)) { - /* trying to add primary address */ + if (p->family != PIM_AF) + SET_FLAG(c->flags, ZEBRA_IFA_SECONDARY); + else if (!CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY)) { + /* trying to add primary address? */ + pim_addr primary_addr = pim_find_primary_addr(c->ifp); + pim_addr addr = pim_addr_from_prefix(p); - struct in_addr primary_addr = pim_find_primary_addr(c->ifp); - if (p->family != AF_INET - || primary_addr.s_addr != p->u.prefix4.s_addr) { + if (pim_addr_cmp(primary_addr, addr)) { if (PIM_DEBUG_ZEBRA) zlog_warn( "%s: %s : forcing secondary flag on %pFX", From da6bed2bbe2e0cd556320b6a4d3ef573dde79b6d Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 19:43:37 +0100 Subject: [PATCH 11/14] pim6d: IPv6-adjust jp_agg->group Signed-off-by: David Lamparter --- pimd/pim_join.c | 7 ++----- pimd/pim_jp_agg.c | 8 +------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 1a3adc305c..51a3ceee15 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -504,14 +504,11 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) } if (PIM_DEBUG_PIM_J_P) { char dst_str[INET_ADDRSTRLEN]; - char grp_str[INET_ADDRSTRLEN]; pim_inet4_dump("", rpf->rpf_addr.u.prefix4, dst_str, sizeof(dst_str)); - pim_inet4_dump("", group->group, grp_str, - sizeof(grp_str)); zlog_debug( - "%s: sending (G)=%s to upstream=%s on interface %s", - __func__, grp_str, dst_str, + "%s: sending (G)=%pPAs to upstream=%s on interface %s", + __func__, &group->group, dst_str, rpf->source_nexthop.interface->name); } diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index f5836a1a87..42ad5dcd1e 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -60,13 +60,7 @@ int pim_jp_agg_group_list_cmp(void *arg1, void *arg2) const struct pim_jp_agg_group *jag2 = (const struct pim_jp_agg_group *)arg2; - if (jag1->group.s_addr < jag2->group.s_addr) - return -1; - - if (jag1->group.s_addr > jag2->group.s_addr) - return 1; - - return 0; + return pim_addr_cmp(jag1->group, jag2->group); } static int pim_jp_agg_src_cmp(void *arg1, void *arg2) From efd66f7bad62cbeb7c5987bf834099920a27813a Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 19:53:55 +0100 Subject: [PATCH 12/14] pim6d: IPv6-adjust assert-related addrs Signed-off-by: David Lamparter --- pimd/pim_assert.c | 42 +++++++++++++++--------------------------- pimd/pim_assert.h | 2 +- pimd/pim_ifchannel.c | 16 +++++----------- pimd/pimd.c | 2 +- 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 7d2ebffab1..56d3a79b71 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -87,14 +87,10 @@ void pim_ifassert_winner_set(struct pim_ifchannel *ch, } } -static void on_trace(const char *label, struct interface *ifp, - struct in_addr src) +static void on_trace(const char *label, struct interface *ifp, pim_addr src) { - if (PIM_DEBUG_PIM_TRACE) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src, src_str, sizeof(src_str)); - zlog_debug("%s: from %s on %s", label, src_str, ifp->name); - } + if (PIM_DEBUG_PIM_TRACE) + zlog_debug("%s: from %pPAs on %s", label, &src, ifp->name); } static int preferred_assert(const struct pim_ifchannel *ch, @@ -213,7 +209,7 @@ static int dispatch_assert(struct interface *ifp, pim_addr source_addr, } int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, - struct in_addr src_addr, uint8_t *buf, int buf_size) + pim_addr src_addr, uint8_t *buf, int buf_size) { pim_sgaddr sg; pim_addr msg_source_addr; @@ -235,10 +231,9 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, memset(&sg, 0, sizeof(sg)); offset = pim_parse_addr_group(&sg, curr, curr_size); if (offset < 1) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); - zlog_warn("%s: pim_parse_addr_group() failure: from %s on %s", - __func__, src_str, ifp->name); + zlog_warn( + "%s: pim_parse_addr_group() failure: from %pPAs on %s", + __func__, &src_addr, ifp->name); return -1; } curr += offset; @@ -250,21 +245,18 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, offset = pim_parse_addr_ucast(&msg_source_addr, curr, curr_size, &wrong_af); if (offset < 1 || wrong_af) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); - zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s", - __func__, src_str, ifp->name); + zlog_warn( + "%s: pim_parse_addr_ucast() failure: from %pPAs on %s", + __func__, &src_addr, ifp->name); return -2; } curr += offset; curr_size -= offset; if (curr_size < 8) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, src_str, sizeof(src_str)); zlog_warn( - "%s: preference/metric size is less than 8 bytes: size=%d from %s on interface %s", - __func__, curr_size, src_str, ifp->name); + "%s: preference/metric size is less than 8 bytes: size=%d from %pPAs on interface %s", + __func__, curr_size, &src_addr, ifp->name); return -3; } @@ -286,17 +278,13 @@ int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, msg_metric.route_metric = pim_read_uint32_host(curr); - if (PIM_DEBUG_PIM_TRACE) { - char neigh_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", src_addr, neigh_str, - sizeof(neigh_str)); + if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: from %s on %s: (S,G)=(%pPAs,%pPAs) pref=%u metric=%u rpt_bit=%u", - __func__, neigh_str, ifp->name, &msg_source_addr, + "%s: from %pPAs on %s: (S,G)=(%pPAs,%pPAs) pref=%u metric=%u rpt_bit=%u", + __func__, &src_addr, ifp->name, &msg_source_addr, &sg.grp, msg_metric.metric_preference, msg_metric.route_metric, PIM_FORCE_BOOLEAN(msg_metric.rpt_bit_flag)); - } msg_metric.ip_address = src_addr; diff --git a/pimd/pim_assert.h b/pimd/pim_assert.h index c7c11039af..22bab67c59 100644 --- a/pimd/pim_assert.h +++ b/pimd/pim_assert.h @@ -59,7 +59,7 @@ void pim_ifassert_winner_set(struct pim_ifchannel *ch, struct pim_assert_metric winner_metric); int pim_assert_recv(struct interface *ifp, struct pim_neighbor *neigh, - struct in_addr src_addr, uint8_t *buf, int buf_size); + pim_addr src_addr, uint8_t *buf, int buf_size); int pim_assert_metric_better(const struct pim_assert_metric *m1, const struct pim_assert_metric *m2); diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index a21277cde3..b26bbcd6d7 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -1363,23 +1363,17 @@ void pim_ifchannel_update_my_assert_metric(struct pim_ifchannel *ch) if (pim_assert_metric_match(&my_metric_new, &ch->ifassert_my_metric)) return; - if (PIM_DEBUG_PIM_EVENTS) { - char old_addr_str[INET_ADDRSTRLEN]; - char new_addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", ch->ifassert_my_metric.ip_address, - old_addr_str, sizeof(old_addr_str)); - pim_inet4_dump("", my_metric_new.ip_address, - new_addr_str, sizeof(new_addr_str)); + if (PIM_DEBUG_PIM_EVENTS) zlog_debug( - "%s: my_assert_metric(%pPAs,%pPAs,%s) changed from %u,%u,%u,%s to %u,%u,%u,%s", + "%s: my_assert_metric(%pPAs,%pPAs,%s) changed from %u,%u,%u,%pPAs to %u,%u,%u,%pPAs", __func__, &ch->sg.src, &ch->sg.grp, ch->interface->name, ch->ifassert_my_metric.rpt_bit_flag, ch->ifassert_my_metric.metric_preference, - ch->ifassert_my_metric.route_metric, old_addr_str, + ch->ifassert_my_metric.route_metric, + &ch->ifassert_my_metric.ip_address, my_metric_new.rpt_bit_flag, my_metric_new.metric_preference, - my_metric_new.route_metric, new_addr_str); - } + my_metric_new.route_metric, &my_metric_new.ip_address); ch->ifassert_my_metric = my_metric_new; diff --git a/pimd/pimd.c b/pimd/pimd.c index 992bb931bd..16a0c7251c 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -103,7 +103,7 @@ void pim_router_init(void) PIM_ASSERT_METRIC_PREFERENCE_MAX; router->infinite_assert_metric.route_metric = PIM_ASSERT_ROUTE_METRIC_MAX; - router->infinite_assert_metric.ip_address.s_addr = INADDR_ANY; + router->infinite_assert_metric.ip_address = PIMADDR_ANY; router->rpf_cache_refresh_delay_msec = 50; router->register_suppress_time = PIM_REGISTER_SUPPRESSION_TIME_DEFAULT; router->packet_process = PIM_DEFAULT_PACKET_PROCESS; From 2b844385dc5fcd26dd5dd816d25bb1090435fe3e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 20:02:36 +0100 Subject: [PATCH 13/14] pim6d: IPv6-adjust pim_ifchannel_* Signed-off-by: David Lamparter --- pimd/pim_assert.c | 15 ++++---------- pimd/pim_ifchannel.c | 48 +++++++++++++++++++------------------------- pimd/pim_ifchannel.h | 6 +++--- pimd/pim_macro.c | 8 ++++---- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 56d3a79b71..7d05403c36 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -61,18 +61,11 @@ void pim_ifassert_winner_set(struct pim_ifchannel *ch, ch->interface->name); } - if (winner_changed) { - char was_str[INET_ADDRSTRLEN]; - char winner_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", ch->ifassert_winner, was_str, - sizeof(was_str)); - pim_inet4_dump("", winner, winner_str, - sizeof(winner_str)); + if (winner_changed) zlog_debug( - "%s: (S,G)=%s assert winner changed from %s to %s on interface %s", - __func__, ch->sg_str, was_str, winner_str, - ch->interface->name); - } + "%s: (S,G)=%s assert winner changed from %pPAs to %pPAs on interface %s", + __func__, ch->sg_str, &ch->ifassert_winner, + &winner, ch->interface->name); } /* PIM_DEBUG_PIM_EVENTS */ ch->ifassert_state = new_state; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index b26bbcd6d7..a613c89b7e 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -423,11 +423,9 @@ const char *pim_ifchannel_ifassert_name(enum pim_ifassert_state ifassert_state) */ void reset_ifassert_state(struct pim_ifchannel *ch) { - struct in_addr any = {.s_addr = INADDR_ANY}; - THREAD_OFF(ch->t_ifassert_timer); - pim_ifassert_winner_set(ch, PIM_IFASSERT_NOINFO, any, + pim_ifassert_winner_set(ch, PIM_IFASSERT_NOINFO, PIMADDR_ANY, router->infinite_assert_metric); } @@ -587,7 +585,7 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, pim_sgaddr *sg, ch->ifassert_my_metric = pim_macro_ch_my_assert_metric_eval(ch); ch->ifassert_winner_metric = pim_macro_ch_my_assert_metric_eval(ch); - ch->ifassert_winner.s_addr = INADDR_ANY; + ch->ifassert_winner = PIMADDR_ANY; /* Assert state */ ch->t_ifassert_timer = NULL; @@ -688,8 +686,8 @@ static int on_ifjoin_prune_pending_timer(struct thread *t) struct pim_rpf rpf; rpf.source_nexthop.interface = ifp; - rpf.rpf_addr.u.prefix4 = - pim_ifp->primary_address; + pim_addr_to_prefix(&rpf.rpf_addr, + pim_ifp->primary_address); pim_jp_agg_single_upstream_send( &rpf, ch->upstream, 0); } @@ -733,11 +731,12 @@ static int on_ifjoin_prune_pending_timer(struct thread *t) } static void check_recv_upstream(int is_join, struct interface *recv_ifp, - struct in_addr upstream, pim_sgaddr *sg, + pim_addr upstream, pim_sgaddr *sg, uint8_t source_flags, int holdtime) { struct pim_upstream *up; struct pim_interface *pim_ifp = recv_ifp->info; + pim_addr rpf_addr; /* Upstream (S,G) in Joined state ? */ up = pim_upstream_find(pim_ifp->pim, sg); @@ -755,16 +754,13 @@ static void check_recv_upstream(int is_join, struct interface *recv_ifp, return; } + rpf_addr = pim_addr_from_prefix(&up->rpf.rpf_addr); + /* upstream directed to RPF'(S,G) ? */ - if (upstream.s_addr != up->rpf.rpf_addr.u.prefix4.s_addr) { - char up_str[INET_ADDRSTRLEN]; - char rpf_str[PREFIX_STRLEN]; - pim_inet4_dump("", upstream, up_str, sizeof(up_str)); - pim_addr_dump("", &up->rpf.rpf_addr, rpf_str, - sizeof(rpf_str)); + if (pim_addr_cmp(upstream, rpf_addr)) { zlog_warn( - "%s %s: (S,G)=%s upstream=%s not directed to RPF'(S,G)=%s on interface %s", - __FILE__, __func__, up->sg_str, up_str, rpf_str, + "%s %s: (S,G)=%s upstream=%pPAs not directed to RPF'(S,G)=%pPAs on interface %s", + __FILE__, __func__, up->sg_str, &upstream, &rpf_addr, recv_ifp->name); return; } @@ -798,7 +794,7 @@ static void check_recv_upstream(int is_join, struct interface *recv_ifp, } static int nonlocal_upstream(int is_join, struct interface *recv_ifp, - struct in_addr upstream, pim_sgaddr *sg, + pim_addr upstream, pim_sgaddr *sg, uint8_t source_flags, uint16_t holdtime) { struct pim_interface *recv_pim_ifp; @@ -807,18 +803,16 @@ static int nonlocal_upstream(int is_join, struct interface *recv_ifp, recv_pim_ifp = recv_ifp->info; assert(recv_pim_ifp); - is_local = (upstream.s_addr == recv_pim_ifp->primary_address.s_addr); + is_local = !pim_addr_cmp(upstream, recv_pim_ifp->primary_address); if (is_local) return 0; - if (PIM_DEBUG_PIM_TRACE_DETAIL) { - char up_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", upstream, up_str, sizeof(up_str)); - zlog_warn("%s: recv %s (S,G)=%pSG to non-local upstream=%s on %s", - __func__, is_join ? "join" : "prune", - sg, up_str, recv_ifp->name); - } + if (PIM_DEBUG_PIM_TRACE_DETAIL) + zlog_warn( + "%s: recv %s (S,G)=%pSG to non-local upstream=%pPAs on %s", + __func__, is_join ? "join" : "prune", sg, &upstream, + recv_ifp->name); /* * Since recv upstream addr was not directed to our primary @@ -851,8 +845,8 @@ static void pim_ifchannel_ifjoin_handler(struct pim_ifchannel *ch, } -void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, - struct in_addr upstream, pim_sgaddr *sg, +void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr, + pim_addr upstream, pim_sgaddr *sg, uint8_t source_flags, uint16_t holdtime) { struct pim_interface *pim_ifp; @@ -1013,7 +1007,7 @@ void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, } } -void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, +void pim_ifchannel_prune(struct interface *ifp, pim_addr upstream, pim_sgaddr *sg, uint8_t source_flags, uint16_t holdtime) { diff --git a/pimd/pim_ifchannel.h b/pimd/pim_ifchannel.h index ab405202e3..0c5b6780d1 100644 --- a/pimd/pim_ifchannel.h +++ b/pimd/pim_ifchannel.h @@ -126,10 +126,10 @@ void pim_ifchannel_delete_on_noinfo(struct interface *ifp); struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp, pim_sgaddr *sg); struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, pim_sgaddr *sg, uint8_t ch_flags, int up_flags); -void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, - struct in_addr upstream, pim_sgaddr *sg, +void pim_ifchannel_join_add(struct interface *ifp, pim_addr neigh_addr, + pim_addr upstream, pim_sgaddr *sg, uint8_t source_flags, uint16_t holdtime); -void pim_ifchannel_prune(struct interface *ifp, struct in_addr upstream, +void pim_ifchannel_prune(struct interface *ifp, pim_addr upstream, pim_sgaddr *sg, uint8_t source_flags, uint16_t holdtime); int pim_ifchannel_local_membership_add(struct interface *ifp, pim_sgaddr *sg, diff --git a/pimd/pim_macro.c b/pimd/pim_macro.c index aa41033cea..0896c52a75 100644 --- a/pimd/pim_macro.c +++ b/pimd/pim_macro.c @@ -132,7 +132,7 @@ int pim_macro_ch_lost_assert(const struct pim_ifchannel *ch) return 0; /* false */ /* AssertWinner(S,G,I) == me ? */ - if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr) + if (!pim_addr_cmp(ch->ifassert_winner, pim_ifp->primary_address)) return 0; /* false */ spt_assert_metric = pim_macro_spt_assert_metric( @@ -170,7 +170,7 @@ int pim_macro_chisin_pim_include(const struct pim_ifchannel *ch) return 0; /* false */ /* OR AssertWinner(S,G,I) == me ? */ - if (ch->ifassert_winner.s_addr == pim_ifp->primary_address.s_addr) + if (!pim_addr_cmp(ch->ifassert_winner, pim_ifp->primary_address)) return 1; /* true */ /* @@ -412,8 +412,8 @@ int pim_macro_assert_tracking_desired_eval(const struct pim_ifchannel *ch) return 1; /* true */ /* AssertWinner(S,G,I) == me ? */ - if (ch->ifassert_winner.s_addr - == pim_ifp->primary_address.s_addr) + if (!pim_addr_cmp(ch->ifassert_winner, + pim_ifp->primary_address)) return 1; /* true */ } From 29fd9fca45394602f0ff4358d1fa05c8f1867412 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 14 Jan 2022 20:17:46 +0100 Subject: [PATCH 14/14] pim6d: IPv6-adjust pim_msg_send() and related Signed-off-by: David Lamparter --- pimd/pim_bsm.c | 9 ++++----- pimd/pim_pim.c | 2 +- pimd/pim_pim.h | 4 ++-- pimd/pimd.c | 12 ++++++++++-- pimd/pimd.h | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index add9b7fe69..0b993ec05e 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -687,7 +687,7 @@ void pim_bsm_clear(struct pim_instance *pim) } static bool pim_bsm_send_intf(uint8_t *buf, int len, struct interface *ifp, - struct in_addr dst_addr) + pim_addr dst_addr) { struct pim_interface *pim_ifp; @@ -720,8 +720,7 @@ static bool pim_bsm_send_intf(uint8_t *buf, int len, struct interface *ifp, } static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, - uint32_t pim_mtu, struct in_addr dst_addr, - bool no_fwd) + uint32_t pim_mtu, pim_addr dst_addr, bool no_fwd) { struct bsmmsg_grpinfo *grpinfo, *curgrp; uint8_t *firstgrp_ptr; @@ -892,7 +891,7 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, { struct interface *ifp; struct pim_interface *pim_ifp; - struct in_addr dst_addr; + pim_addr dst_addr; uint32_t pim_mtu; bool no_fwd = false; bool ret = false; @@ -939,7 +938,7 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) { - struct in_addr dst_addr; + pim_addr dst_addr; struct pim_interface *pim_ifp; struct bsm_scope *scope; struct bsm_frag *bsfrag; diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 2142d9010b..93ccfd78df 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -570,7 +570,7 @@ static int pim_msg_send_frame(int fd, char *buf, size_t len, return 0; } -int pim_msg_send(int fd, pim_addr src, struct in_addr dst, uint8_t *pim_msg, +int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, int pim_msg_size, const char *ifname) { struct sockaddr_in to; diff --git a/pimd/pim_pim.h b/pimd/pim_pim.h index b9fdb14dc0..1931e8cee8 100644 --- a/pimd/pim_pim.h +++ b/pimd/pim_pim.h @@ -56,8 +56,8 @@ void pim_hello_restart_triggered(struct interface *ifp); int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len); -int pim_msg_send(int fd, struct in_addr src, struct in_addr dst, - uint8_t *pim_msg, int pim_msg_size, const char *ifname); +int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, + int pim_msg_size, const char *ifname); int pim_hello_send(struct interface *ifp, uint16_t holdtime); #endif /* PIM_PIM_H */ diff --git a/pimd/pimd.c b/pimd/pimd.c index 16a0c7251c..9621f9794d 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -49,15 +49,22 @@ CPP_NOTICE("Work needs to be done to make this work properly via the pim mroute socket\n"); #endif /* MAXVIFS > 256 */ +#if PIM_IPV == 4 const char *const PIM_ALL_SYSTEMS = MCAST_ALL_SYSTEMS; const char *const PIM_ALL_ROUTERS = MCAST_ALL_ROUTERS; const char *const PIM_ALL_PIM_ROUTERS = MCAST_ALL_PIM_ROUTERS; const char *const PIM_ALL_IGMP_ROUTERS = MCAST_ALL_IGMP_ROUTERS; +#else +const char *const PIM_ALL_SYSTEMS = "ff02::1"; +const char *const PIM_ALL_ROUTERS = "ff02::2"; +const char *const PIM_ALL_PIM_ROUTERS = "ff02::d"; +const char *const PIM_ALL_IGMP_ROUTERS = "ff02::16"; +#endif DEFINE_MTYPE_STATIC(PIMD, ROUTER, "PIM Router information"); struct pim_router *router = NULL; -struct in_addr qpim_all_pim_routers_addr; +pim_addr qpim_all_pim_routers_addr; void pim_prefix_list_update(struct prefix_list *plist) { @@ -120,7 +127,8 @@ void pim_router_terminate(void) void pim_init(void) { - if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) { + if (!inet_pton(PIM_AF, PIM_ALL_PIM_ROUTERS, + &qpim_all_pim_routers_addr)) { flog_err( EC_LIB_SOCKET, "%s %s: could not solve %s to group address: errno=%d: %s", diff --git a/pimd/pimd.h b/pimd/pimd.h index 7732dc5b74..d4eac58a29 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -134,7 +134,7 @@ extern const char *const PIM_ALL_PIM_ROUTERS; extern const char *const PIM_ALL_IGMP_ROUTERS; extern struct zebra_privs_t pimd_privs; -extern struct in_addr qpim_all_pim_routers_addr; +extern pim_addr qpim_all_pim_routers_addr; extern uint8_t qpim_ecmp_enable; extern uint8_t qpim_ecmp_rebalance_enable;