diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2015-04-04 15:15:45 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2015-04-04 15:15:45 +0000 |
commit | 199b8d04391a85ada25d77f1e65de032def39c85 (patch) | |
tree | fd4c5ff7473d5c1936c3b60e883b501c8c5acb00 | |
parent | 06d3ec3581eb4cb29ccd0923aae49c1f1268ea59 (diff) |
Show the full LIB in the "ldpctl show lib" command.
The LIB is a table where the router keeps all known MPLS labels. So,
we should loop over all the received label mappings from all neighbors
to show the full LIB.
The lde_nbr_is_nexthop() function was introduced to verify if a lib
entry is supposed to be installed in the fib (according to the fib entry's
nexthop and the addresses advertised by the lib entry's nexthop). This is
better than keeping track of lib<->fib entries with pointers and back
pointers because it keeps the lib/fib structures independent of each
other, which in turn makes the code less prone to bugs.
OK claudio@
-rw-r--r-- | usr.sbin/ldpd/lde_lib.c | 47 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldpd.h | 7 |
2 files changed, 27 insertions, 27 deletions
diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c index d8234a0e6d9..736cd12486c 100644 --- a/usr.sbin/ldpd/lde_lib.c +++ b/usr.sbin/ldpd/lde_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde_lib.c,v 1.31 2013/10/15 20:21:25 renato Exp $ */ +/* $OpenBSD: lde_lib.c,v 1.32 2015/04/04 15:15:44 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -45,6 +45,7 @@ struct rt_node *rt_add(struct in_addr, u_int8_t); struct rt_lsp *rt_lsp_find(struct rt_node *, struct in_addr, u_int8_t); struct rt_lsp *rt_lsp_add(struct rt_node *, struct in_addr, u_int8_t); void rt_lsp_del(struct rt_lsp *); +int lde_nbr_is_nexthop(struct rt_node *, struct lde_nbr *); RB_PROTOTYPE(fec_tree, fec, entry, fec_compare) RB_GENERATE(fec_tree, fec, entry, fec_compare) @@ -123,12 +124,23 @@ fec_clear(struct fec_tree *fh, void (*free_cb)(void *)) } /* routing table functions */ +int +lde_nbr_is_nexthop(struct rt_node *rn, struct lde_nbr *ln) +{ + struct rt_lsp *rl; + + LIST_FOREACH(rl, &rn->lsp, entry) + if (lde_address_find(ln, &rl->nexthop)) + return (1); + + return (0); +} + void rt_dump(pid_t pid) { struct fec *f; struct rt_node *rr; - struct rt_lsp *rl; struct lde_map *me; static struct ctl_rt rtctl; @@ -139,30 +151,21 @@ rt_dump(pid_t pid) rtctl.flags = rr->flags; rtctl.local_label = rr->local_label; - LIST_FOREACH(rl, &rr->lsp, entry) { - rtctl.nexthop = rl->nexthop; - rtctl.remote_label = rl->remote_label; - rtctl.in_use = 1; - - if (rtctl.nexthop.s_addr == htonl(INADDR_ANY)) - rtctl.connected = 1; - else - rtctl.connected = 0; + LIST_FOREACH(me, &rr->downstream, entry) { + rtctl.in_use = lde_nbr_is_nexthop(rr, me->nexthop); + rtctl.nexthop = me->nexthop->id; + rtctl.remote_label = me->label; lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB, 0, pid, &rtctl, sizeof(rtctl)); } - if (LIST_EMPTY(&rr->lsp)) { - LIST_FOREACH(me, &rr->downstream, entry) { - rtctl.in_use = 0; - rtctl.connected = 0; - /* we don't know the nexthop use id instead */ - rtctl.nexthop = me->nexthop->id; - rtctl.remote_label = me->label; - - lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB, 0, pid, - &rtctl, sizeof(rtctl)); - } + if (LIST_EMPTY(&rr->downstream)) { + rtctl.in_use = 0; + rtctl.nexthop.s_addr = INADDR_ANY; + rtctl.remote_label = NO_LABEL; + + lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB, 0, pid, + &rtctl, sizeof(rtctl)); } } } diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h index 64dd9637b2d..1988adab7b4 100644 --- a/usr.sbin/ldpd/ldpd.h +++ b/usr.sbin/ldpd/ldpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldpd.h,v 1.44 2015/03/21 18:32:01 renato Exp $ */ +/* $OpenBSD: ldpd.h,v 1.45 2015/04/04 15:15:44 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -321,14 +321,11 @@ struct ctl_nbr { struct ctl_rt { struct in_addr prefix; + u_int8_t prefixlen; struct in_addr nexthop; - struct in_addr adv_rtr; - time_t uptime; u_int32_t local_label; u_int32_t remote_label; u_int8_t flags; - u_int8_t prefixlen; - u_int8_t connected; u_int8_t in_use; }; |