forked from Mirror/frr
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>
This commit is contained in:
parent
8ea50a44b5
commit
b3f72964f2
|
@ -44,41 +44,20 @@ uint32_t conf_debug_ospf6_brouter_specific_area_id;
|
||||||
/* RFC2740 3.4.3.1 Router-LSA */
|
/* RFC2740 3.4.3.1 Router-LSA */
|
||||||
/******************************/
|
/******************************/
|
||||||
|
|
||||||
|
/* OSPF6_LSTYPE_ROUTER */
|
||||||
static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa *lsa, char *buf,
|
static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa *lsa, char *buf,
|
||||||
int buflen, int pos)
|
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];
|
char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
|
||||||
|
struct ospf6_router_lsdesc *lsdesc = nth_lsdesc(lsa->header, pos);
|
||||||
|
|
||||||
if (lsa) {
|
if (!lsdesc || !buf || buflen < (2 + 2 * INET_ADDRSTRLEN))
|
||||||
router_lsa = (struct ospf6_router_lsa
|
return NULL;
|
||||||
*)((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
|
inet_ntop(AF_INET, &lsdesc->neighbor_interface_id, buf1, sizeof(buf1));
|
||||||
*)(start
|
inet_ntop(AF_INET, &lsdesc->neighbor_router_id, buf2, sizeof(buf2));
|
||||||
+ pos * (sizeof(struct
|
snprintf(buf, buflen, "%s/%s", buf2, buf1);
|
||||||
ospf6_router_lsdesc)));
|
return buf;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
|
static int ospf6_router_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
|
||||||
|
|
Loading…
Reference in a new issue