diff options
author | Andrew Cooks <acooks.at.bda@gmail.com> | 2024-06-10 06:08:12 +0200 |
---|---|---|
committer | Andrew Cooks <acooks.at.bda@gmail.com> | 2024-09-16 10:38:16 +0200 |
commit | b3f72964f28653a683b40e7db3d5d343b9a971fc (patch) | |
tree | 47fc29ac90ace79e9e300b4e4293a947006a16ef /ospf6d | |
parent | ospf6d: use nth_lsdesc() in ospf6_network_lsa_get_ar_id() (diff) | |
download | frr-b3f72964f28653a683b40e7db3d5d343b9a971fc.tar.xz frr-b3f72964f28653a683b40e7db3d5d343b9a971fc.zip |
ospf6d: use nth_lsdesc() in ospf6_router_lsa_get_nbr_id()
Improves code readability by reducing pointer casting and arithmetic,
and intendation.
Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
Diffstat (limited to 'ospf6d')
-rw-r--r-- | ospf6d/ospf6_intra.c | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index ebecd41ad..fb3bf15dc 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -44,41 +44,20 @@ uint32_t conf_debug_ospf6_brouter_specific_area_id; /* RFC2740 3.4.3.1 Router-LSA */ /******************************/ +/* OSPF6_LSTYPE_ROUTER */ static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa *lsa, char *buf, int buflen, int pos) { - struct ospf6_router_lsa *router_lsa; - struct ospf6_router_lsdesc *lsdesc; - char *start, *end; char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN]; + struct ospf6_router_lsdesc *lsdesc = nth_lsdesc(lsa->header, pos); - if (lsa) { - router_lsa = (struct ospf6_router_lsa - *)((char *)lsa->header - + sizeof(struct ospf6_lsa_header)); - start = (char *)router_lsa + sizeof(struct ospf6_router_lsa); - end = (char *)lsa->header + ntohs(lsa->header->length); - - lsdesc = (struct ospf6_router_lsdesc - *)(start - + pos * (sizeof(struct - ospf6_router_lsdesc))); - if ((char *)lsdesc + sizeof(struct ospf6_router_lsdesc) - <= end) { - if (buf && (buflen > INET_ADDRSTRLEN * 2)) { - inet_ntop(AF_INET, - &lsdesc->neighbor_interface_id, buf1, - sizeof(buf1)); - inet_ntop(AF_INET, &lsdesc->neighbor_router_id, - buf2, sizeof(buf2)); - snprintf(buf, buflen, "%s/%s", buf2, buf1); - - return buf; - } - } - } + if (!lsdesc || !buf || buflen < (2 + 2 * INET_ADDRSTRLEN)) + return NULL; - return NULL; + inet_ntop(AF_INET, &lsdesc->neighbor_interface_id, buf1, sizeof(buf1)); + inet_ntop(AF_INET, &lsdesc->neighbor_router_id, buf2, sizeof(buf2)); + snprintf(buf, buflen, "%s/%s", buf2, buf1); + return buf; } static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, |