Commit b66abe8e authored by Ondřej Zajíček's avatar Ondřej Zajíček

Reimplements 'show ospf state' for OSPFv3 and fixes some bugs.

parent d82fc18d
This diff is collapsed.
......@@ -523,19 +523,57 @@ struct ospf_lsa_prefix
#define METRIC_MASK 0x00FFFFFF
#define OPTIONS_MASK 0x00FFFFFF
static inline unsigned lsa_rt_count(struct ospf_lsa_header *lsa)
static inline unsigned
lsa_rt_count(struct ospf_lsa_header *lsa)
{
return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_rt))
/ sizeof(struct ospf_lsa_rt_link);
}
static inline unsigned lsa_net_count(struct ospf_lsa_header *lsa)
static inline unsigned
lsa_net_count(struct ospf_lsa_header *lsa)
{
return (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net))
/ sizeof(u32);
}
#ifdef OSPFv3
static inline u32 *
lsa_get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
{
u8 pxl = (*buf >> 24);
*pxopts = (*buf >> 16);
*rest = *buf;
*pxlen = pxl;
buf++;
*addr = IPA_NONE;
if (pxl > 0)
_I0(*addr) = *buf++;
if (pxl > 32)
_I1(*addr) = *buf++;
if (pxl > 64)
_I2(*addr) = *buf++;
if (pxl > 96)
_I3(*addr) = *buf++;
return buf;
}
static inline u32 *
lsa_get_ipv6_addr(u32 *buf, ip_addr *addr)
{
*addr = *(ip_addr *) buf;
return buf + 4;
}
#endif
struct ospf_lsreq_header
{
u32 type;
......
......@@ -26,41 +26,6 @@ static void rt_sync(struct proto_ospf *po);
#endif
#ifdef OSPFv3
static inline u32 *
get_ipv6_prefix(u32 *buf, ip_addr *addr, int *pxlen, u8 *pxopts, u16 *rest)
{
u8 pxl = (*buf >> 24);
*pxopts = (*buf >> 16);
*rest = *buf;
*pxlen = pxl;
buf++;
*addr = IPA_NONE;
if (pxl > 0)
_I0(*addr) = *buf++;
if (pxl > 32)
_I1(*addr) = *buf++;
if (pxl > 64)
_I2(*addr) = *buf++;
if (pxl > 96)
_I3(*addr) = *buf++;
return buf;
}
static inline u32 *
get_ipv6_addr(u32 *buf, ip_addr *addr)
{
*addr = *(ip_addr *) buf;
return buf + 4;
}
#endif
static void
fill_ri(orta * orta)
{
......@@ -244,7 +209,7 @@ process_prefixes(struct ospf_area *oa)
buf = px->rest;
for (i = 0; i < px->pxcount; i++)
{
buf = get_ipv6_prefix(buf, &pxa, &pxlen, &pxopts, &metric);
buf = lsa_get_ipv6_prefix(buf, &pxa, &pxlen, &pxopts, &metric);
if (pxopts & OPT_PX_NU)
continue;
......@@ -581,7 +546,7 @@ ospf_rt_sum_tr(struct ospf_area *oa)
u8 pxopts;
u16 rest;
struct ospf_lsa_sum_net *ls = en->lsa_body;
get_ipv6_prefix(ls->prefix, &ip, &pxlen, &pxopts, &rest);
lsa_get_ipv6_prefix(ls->prefix, &ip, &pxlen, &pxopts, &rest);
if (pxopts & OPT_PX_NU)
continue;
......@@ -680,7 +645,7 @@ ospf_rt_sum(struct ospf_area *oa)
u8 pxopts;
u16 rest;
struct ospf_lsa_sum_net *ls = en->lsa_body;
get_ipv6_prefix(ls->prefix, &ip, &pxlen, &pxopts, &rest);
lsa_get_ipv6_prefix(ls->prefix, &ip, &pxlen, &pxopts, &rest);
if (pxopts & OPT_PX_NU)
continue;
......@@ -883,14 +848,14 @@ ospf_ext_spf(struct proto_ospf *po)
u8 pxopts;
u16 rest;
u32 *buf = le->rest;
buf = get_ipv6_prefix(buf, &ip, &pxlen, &pxopts, &rest);
buf = lsa_get_ipv6_prefix(buf, &ip, &pxlen, &pxopts, &rest);
if (pxopts & OPT_PX_NU)
continue;
rt_fwaddr_valid = le->metric & LSA_EXT_FBIT;
if (rt_fwaddr_valid)
buf = get_ipv6_addr(buf, &rt_fwaddr);
buf = lsa_get_ipv6_addr(buf, &rt_fwaddr);
else
rt_fwaddr = IPA_NONE;
......
......@@ -881,11 +881,11 @@ originate_ext_lsa_body(net *n, rte *e, u16 *length, struct proto_ospf *po,
ext = mb_alloc(p->pool, size);
*length = sizeof(struct ospf_lsa_header) + size;
ext->metric = (m1 != LSINFINITY) ? m1 : (m2 & LSA_EXT_EBIT);
ext->metric = (m1 != LSINFINITY) ? m1 : (m2 | LSA_EXT_EBIT);
#ifdef OSPFv2
ext->netmask = ipa_mkmask(n->n.pxlen);
ext->fwaddr = gw ? IPA_NONE : e->attrs->gw;
ext->fwaddr = gw ? e->attrs->gw : IPA_NONE;
ext->tag = tag;
#else /* OSPFv3 */
buf = ext->rest;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment