summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.c4
-rw-r--r--proto/ospf/config.Y10
-rw-r--r--proto/ospf/lsupd.c2
-rw-r--r--proto/ospf/ospf.c213
-rw-r--r--proto/ospf/topology.c42
-rw-r--r--sysdep/linux/netlink/netlink.c5
-rw-r--r--sysdep/unix/io.c4
7 files changed, 264 insertions, 16 deletions
diff --git a/client/client.c b/client/client.c
index d65ea066..e3f539e1 100644
--- a/client/client.c
+++ b/client/client.c
@@ -252,6 +252,10 @@ server_connect(void)
server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (server_fd < 0)
die("Cannot create socket: %m");
+
+ if (strlen(server_path) >= sizeof(sa.sun_path))
+ die("server_connect: path too long");
+
bzero(&sa, sizeof(sa));
sa.sun_family = AF_UNIX;
strcpy(sa.sun_path, server_path);
diff --git a/proto/ospf/config.Y b/proto/ospf/config.Y
index 0c6a4087..dfcab4e6 100644
--- a/proto/ospf/config.Y
+++ b/proto/ospf/config.Y
@@ -255,14 +255,20 @@ CF_ADDTO(dynamic_attr, OSPF_METRIC2 { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF
CF_ADDTO(dynamic_attr, OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_TAG); })
CF_CLI(SHOW OSPF, optsym, [<name>], [[Show information about OSPF protocol]])
-{ ospf_sh(proto_get_named($3, &proto_ospf)); } ;
+{ ospf_sh(proto_get_named($3, &proto_ospf)); };
CF_CLI(SHOW OSPF NEIGHBORS, optsym opttext, [<name>] [\"<interface>\"], [[Show information about OSPF neighbors]])
-{ ospf_sh_neigh(proto_get_named($4, &proto_ospf), $5); } ;
+{ ospf_sh_neigh(proto_get_named($4, &proto_ospf), $5); };
CF_CLI(SHOW OSPF INTERFACE, optsym opttext, [<name>] [\"<interface>\"], [[Show information about interface]])
{ ospf_sh_iface(proto_get_named($4, &proto_ospf), $5); };
+CF_CLI(SHOW OSPF TOPOLOGY, optsym opttext, [<name>], [[Show information about OSPF network topology]])
+{ ospf_sh_state(proto_get_named($4, &proto_ospf), 0); };
+
+CF_CLI(SHOW OSPF STATE, optsym opttext, [<name>], [[Show information about OSPF network state]])
+{ ospf_sh_state(proto_get_named($4, &proto_ospf), 1); };
+
CF_CODE
CF_END
diff --git a/proto/ospf/lsupd.c b/proto/ospf/lsupd.c
index d1881445..9f7dd638 100644
--- a/proto/ospf/lsupd.c
+++ b/proto/ospf/lsupd.c
@@ -183,7 +183,7 @@ ospf_lsupd_flood(struct ospf_neighbor *n, struct ospf_lsa_header *hn,
op->length = htons(len);
OSPF_TRACE(D_PACKETS, "LS upd flooded via %s", ifa->iface->name);
- DBG("ID=%I, AGE=%d, SEQ=%x", ntohl(lh->id), ntohs(lh->age),
+ DBG("ID=%I, AGE=%d, SEQ=%x\n", ntohl(lh->id), ntohs(lh->age),
ntohl(lh->sn));
switch (ifa->type)
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index b382df07..1fce7091 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -73,6 +73,7 @@
* and conserves memory.
*/
+#include <stdlib.h>
#include "ospf.h"
static int ospf_rte_better(struct rte *new, struct rte *old);
@@ -982,6 +983,218 @@ ospf_sh_iface(struct proto *p, char *iff)
cli_msg(0, "");
}
+/* First we want to separate network-LSAs and other LSAs (because network-LSAs
+ * will be presented as network nodes and other LSAs together as router nodes)
+ * Network-LSAs are sorted according to network prefix, other LSAs are sorted
+ * according to originating router id (to get all LSA needed to represent one
+ * router node together). Then, according to LSA type, ID and age.
+ */
+static int
+he_compare(const void *p1, const void *p2)
+{
+ struct top_hash_entry * he1 = * (struct top_hash_entry **) p1;
+ struct top_hash_entry * he2 = * (struct top_hash_entry **) p2;
+ struct ospf_lsa_header *lsa1 = &(he1->lsa);
+ struct ospf_lsa_header *lsa2 = &(he2->lsa);
+ int nt1 = (lsa1->type == LSA_T_NET);
+ int nt2 = (lsa2->type == LSA_T_NET);
+
+ if (he1->oa->areaid != he2->oa->areaid)
+ return he1->oa->areaid - he2->oa->areaid;
+
+ if (nt1 != nt2)
+ return nt1 - nt2;
+
+ if (nt1)
+ {
+ // we are cheating for now
+ if (lsa1->id != lsa2->id)
+ return lsa1->id - lsa2->id;
+
+ return lsa1->age - lsa2->age;
+ }
+ else
+ {
+ if (lsa1->rt != lsa2->rt)
+ return lsa1->rt - lsa2->rt;
+
+ if (lsa1->type != lsa2->type)
+ return lsa1->type - lsa2->type;
+
+ if (lsa1->id != lsa2->id)
+ return lsa1->id - lsa2->id;
+
+ return lsa1->age - lsa2->age;
+ }
+}
+
+static inline void
+show_lsa_router(struct top_hash_entry *he)
+{
+ struct ospf_lsa_header *lsa = &(he->lsa);
+ struct ospf_lsa_rt *rt = he->lsa_body;
+ struct ospf_lsa_rt_link *rr = (struct ospf_lsa_rt_link *) (rt + 1);
+ u32 i;
+
+ for (i = 0; i < rt->links; i++)
+ if (rr[i].type == LSART_PTP)
+ cli_msg(-1016, "\t\trouter %I metric %u ", rr[i].id, rr[i].metric);
+
+ for (i = 0; i < rt->links; i++)
+ if (rr[i].type == LSART_NET)
+ {
+ struct proto_ospf *po = he->oa->po;
+ struct top_hash_entry *net_he = ospf_hash_find(po->gr, he->oa->areaid, rr[i].id, rr[i].id, LSA_T_NET);
+ if (net_he)
+ {
+ struct ospf_lsa_header *net_lsa = &(net_he->lsa);
+ struct ospf_lsa_net *net_ln = net_he->lsa_body;
+ cli_msg(-1016, "\t\tnetwork %I/%d metric %u ", ipa_and(ipa_from_u32(net_lsa->id), net_ln->netmask), ipa_mklen(net_ln->netmask), rr[i].metric);
+ }
+ else
+ cli_msg(-1016, "\t\tnetwork ??? metric %u ", rr[i].id, ipa_mklen(rr[i].data), rr[i].metric);
+ }
+
+ for (i = 0; i < rt->links; i++)
+ if (rr[i].type == LSART_STUB)
+ cli_msg(-1016, "\t\tstubnet %I/%d metric %u ", rr[i].id, ipa_mklen(rr[i].data), rr[i].metric);
+
+ for (i = 0; i < rt->links; i++)
+ if (rr[i].type == LSART_VLNK)
+ cli_msg(-1016, "\t\tvlink %I metric %u ", rr[i].id, rr[i].metric);
+}
+
+static inline void
+show_lsa_network(struct top_hash_entry *he)
+{
+ struct ospf_lsa_header *lsa = &(he->lsa);
+ struct ospf_lsa_net *ln = he->lsa_body;
+ u32 *rts = (u32 *) (ln + 1);
+ u32 max = (lsa->length - sizeof(struct ospf_lsa_header) - sizeof(struct ospf_lsa_net)) / sizeof(u32);
+ u32 i;
+
+ cli_msg(-1016, "");
+ cli_msg(-1016, "\tnetwork %I/%d", ipa_and(ipa_from_u32(lsa->id), ln->netmask), ipa_mklen(ln->netmask));
+ cli_msg(-1016, "\t\tdr %I", lsa->rt);
+
+ for (i = 0; i < max; i++)
+ cli_msg(-1016, "\t\trouter %I", rts[i]);
+}
+
+static inline void
+show_lsa_sum_net(struct top_hash_entry *he)
+{
+ struct ospf_lsa_header *lsa = &(he->lsa);
+ struct ospf_lsa_sum *sm = he->lsa_body;
+
+ cli_msg(-1016, "\t\txnetwork %I/%d", ipa_and(ipa_from_u32(lsa->id), sm->netmask), ipa_mklen(sm->netmask));
+}
+
+static inline void
+show_lsa_sum_rt(struct top_hash_entry *he)
+{
+ cli_msg(-1016, "\t\txrouter %I", he->lsa.id);
+}
+
+
+static inline void
+show_lsa_external(struct top_hash_entry *he)
+{
+ struct ospf_lsa_header *lsa = &(he->lsa);
+ struct ospf_lsa_ext *ext = he->lsa_body;
+ struct ospf_lsa_ext_tos *et = (struct ospf_lsa_ext_tos *) (ext + 1);
+
+ char str_via[STD_ADDRESS_P_LENGTH + 8] = "";
+ char str_tag[16] = "";
+
+ if (et->fwaddr)
+ bsprintf(str_via, " via %I", et->fwaddr);
+
+ if (et->tag)
+ bsprintf(str_tag, " tag %08x", et->tag);
+
+ cli_msg(-1016, "\t\texternal %I/%d metric%s %u%s%s",
+ ipa_and(ipa_from_u32(lsa->id), ext->netmask),
+ ipa_mklen(ext->netmask), et->etm.etos.ebit ? "2" : "",
+ et->etm.metric & METRIC_MASK, str_via, str_tag);
+}
+
+
+void
+ospf_sh_state(struct proto *p, int verbose)
+{
+ struct proto_ospf *po = (struct proto_ospf *) p;
+ struct top_graph *f = po->gr;
+ unsigned int i, j;
+ u32 last_rt = 0xFFFFFFFF;
+ u32 last_area = 0xFFFFFFFF;
+
+ if (p->proto_state != PS_UP)
+ {
+ cli_msg(-1016, "%s: is not up", p->name);
+ cli_msg(0, "");
+ return;
+ }
+
+ struct top_hash_entry *hea[f->hash_entries];
+ struct top_hash_entry *he;
+
+ j = 0;
+ for (i = 0; i < f->hash_size; i++)
+ for (he = f->hash_table[i]; he != NULL; he = he->next)
+ hea[j++] = he;
+
+ if (j == f->hash_size)
+ die("Fatal mismatch");
+
+ qsort(hea, j, sizeof(struct top_hash_entry *), he_compare);
+
+ for (i = 0; i < j; i++)
+ {
+ if ((verbose == 0) && (hea[i]->lsa.type > LSA_T_NET))
+ continue;
+
+ if (last_area != hea[i]->oa->areaid)
+ {
+ cli_msg(-1016, "");
+ cli_msg(-1016, "area %I", hea[i]->oa->areaid);
+ last_area = hea[i]->oa->areaid;
+ last_rt = 0xFFFFFFFF;
+ }
+
+ if ((hea[i]->lsa.rt != last_rt) && (hea[i]->lsa.type != LSA_T_NET))
+ {
+ cli_msg(-1016, "");
+ cli_msg(-1016, (hea[i]->lsa.type != LSA_T_EXT) ? "\trouter %I" : "\txrouter %I", hea[i]->lsa.rt);
+ last_rt = hea[i]->lsa.rt;
+ }
+
+ switch (hea[i]->lsa.type)
+ {
+ case LSA_T_RT:
+ show_lsa_router(hea[i]);
+ break;
+
+ case LSA_T_NET:
+ show_lsa_network(hea[i]);
+ break;
+
+ case LSA_T_SUM_NET:
+ show_lsa_sum_net(hea[i]);
+ break;
+
+ case LSA_T_SUM_RT:
+ show_lsa_sum_rt(hea[i]);
+ break;
+ case LSA_T_EXT:
+ show_lsa_external(hea[i]);
+ break;
+ }
+ }
+
+ cli_msg(0, "");
+}
+
struct protocol proto_ospf = {
name:"OSPF",
template:"ospf%d",
diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c
index 419a3951..1d6b06ef 100644
--- a/proto/ospf/topology.c
+++ b/proto/ospf/topology.c
@@ -20,6 +20,8 @@
#define HASH_LO_STEP 2
#define HASH_LO_MIN 8
+int ptp_unnumbered_stub_lsa = 0;
+
static void *
originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
{
@@ -28,7 +30,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
int j = 0, k = 0;
u16 i = 0;
struct ospf_lsa_rt *rt;
- struct ospf_lsa_rt_link *ln;
+ struct ospf_lsa_rt_link *ln, *ln_after;
struct ospf_neighbor *neigh;
DBG("%s: Originating RT_lsa body for area \"%I\".\n", po->proto.name,
@@ -39,6 +41,9 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
if ((ifa->oa == oa) && (ifa->state != OSPF_IS_DOWN))
{
i++;
+ if ((ifa->type == OSPF_IT_PTP) && (ifa->state == OSPF_IS_PTP) &&
+ (ptp_unnumbered_stub_lsa || !(ifa->iface->addr->flags & IA_UNNUMBERED)))
+ i++;
}
}
rt = mb_allocz(po->proto.pool, sizeof(struct ospf_lsa_rt) +
@@ -48,6 +53,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
if ((po->ebit) && (!oa->stub))
rt->veb.bit.e = 1;
ln = (struct ospf_lsa_rt_link *) (rt + 1);
+ ln_after = ln + i;
WALK_LIST(ifa, po->iface_list)
{
@@ -61,6 +67,9 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
if ((ifa->oa != oa) || (ifa->state == OSPF_IS_DOWN))
continue;
+ if (ln == ln_after)
+ die("LSA space overflow");
+
if (ifa->state == OSPF_IS_LOOP)
{
ln->type = 3;
@@ -81,7 +90,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
ln->id = neigh->rid;
ln->metric = ifa->cost;
ln->notos = 0;
- if (ifa->iface->flags && IA_UNNUMBERED)
+ if (ifa->iface->addr->flags & IA_UNNUMBERED)
{
ln->data = ifa->iface->index;
}
@@ -92,19 +101,30 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 * length)
}
else
{
- if (ifa->state == OSPF_IS_PTP)
+ ln--;
+ i--; /* No link added */
+ }
+
+ if ((ifa->state == OSPF_IS_PTP) &&
+ (ptp_unnumbered_stub_lsa || !(ifa->iface->addr->flags & IA_UNNUMBERED)))
+ {
+ ln++;
+ if (ln == ln_after)
+ die("LSA space overflow");
+
+ ln->type = LSART_STUB;
+ ln->metric = ifa->cost;
+ ln->notos = 0;
+ if (ifa->iface->addr->flags & IA_UNNUMBERED)
{
- ln->type = LSART_STUB;
- ln->id = ln->id = ipa_to_u32(ifa->iface->addr->opposite);
- ln->metric = ifa->cost;
- ln->notos = 0;
+ ln->id = ipa_to_u32(ifa->iface->addr->opposite);
ln->data = 0xffffffff;
}
else
- {
- ln--;
- i--; /* No link added */
- }
+ {
+ ln->data = ipa_to_u32(ipa_mkmask(ifa->iface->addr->pxlen));
+ ln->id = ipa_to_u32(ifa->iface->addr->prefix) & ln->data;
+ }
}
break;
case OSPF_IT_BCAST:
diff --git a/sysdep/linux/netlink/netlink.c b/sysdep/linux/netlink/netlink.c
index 98c63f02..38d00afe 100644
--- a/sysdep/linux/netlink/netlink.c
+++ b/sysdep/linux/netlink/netlink.c
@@ -268,7 +268,8 @@ nl_parse_link(struct nlmsghdr *h, int scan)
if (!a[IFLA_IFNAME] || RTA_PAYLOAD(a[IFLA_IFNAME]) < 2 ||
!a[IFLA_MTU] || RTA_PAYLOAD(a[IFLA_MTU]) != 4)
{
- log(L_ERR "nl_parse_link: Malformed message received");
+ if (scan)
+ log(L_ERR "nl_parse_link: Malformed message received");
return;
}
name = RTA_DATA(a[IFLA_IFNAME]);
@@ -384,7 +385,7 @@ nl_parse_addr(struct nlmsghdr *h)
ipa_ntoh(xbrd);
if (ipa_equal(xbrd, ifa.prefix) || ipa_equal(xbrd, ifa.brd))
ifa.brd = xbrd;
- else
+ else if (ifi->flags & IF_TMP_DOWN) /* Complain only during the first scan */
log(L_ERR "KIF: Invalid broadcast address %I for %s", xbrd, ifi->name);
}
#endif
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 6faa176b..8cec2cdd 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -940,6 +940,10 @@ sk_open_unix(sock *s, char *name)
if (err = sk_setup(s))
goto bad;
unlink(name);
+
+ if (strlen(name) >= sizeof(sa.sun_path))
+ die("sk_open_unix: path too long");
+
sa.sun_family = AF_UNIX;
strcpy(sa.sun_path, name);
if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0)