diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2018-09-11 21:10:58 +0000 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-02-27 22:41:31 +0100 |
commit | 079c415c4d25474a6a608406276ba5cbd8b244cf (patch) | |
tree | e2b75390ab62c8de86bda2305bde4442f283cc7b | |
parent | 7c36eb3e8bd7d06f65dc7319d42b6abe782c5b89 (diff) |
WIP debugold/debug
-rw-r--r-- | lib/ip.c | 2 | ||||
-rw-r--r-- | nest/neighbor.c | 29 | ||||
-rw-r--r-- | proto/bgp/bgp.c | 2 | ||||
-rw-r--r-- | proto/bgp/packets.c | 19 |
4 files changed, 38 insertions, 14 deletions
@@ -93,6 +93,8 @@ ip4_classify(ip4_addr ad) ((a & 0xffff0000) == 0xc0a80000) || ((a & 0xfff00000) == 0xac100000)) return IADDR_HOST | SCOPE_SITE; +// else if ((a & 0xffff0000) == 0xa9fe0000) +// return IADDR_HOST | SCOPE_LINK; else return IADDR_HOST | SCOPE_UNIVERSE; } diff --git a/nest/neighbor.c b/nest/neighbor.c index 87253857..78337b47 100644 --- a/nest/neighbor.c +++ b/nest/neighbor.c @@ -72,28 +72,38 @@ if_connected(ip_addr a, struct iface *i, struct ifa **ap, uint flags) struct ifa *b; /* Handle iface pseudo-neighbors */ - if (flags & NEF_IFACE) + if (flags & NEF_IFACE) { + debug("pseudo-neighbor\n"); return *ap = NULL, (i->flags & IF_UP) ? SCOPE_HOST : -1; + } /* Host addresses match even if iface is down */ WALK_LIST(b, i->addrs) - if (ipa_equal(a, b->ip)) + if (ipa_equal(a, b->ip)) { + debug("host addresses\n"); return *ap = b, SCOPE_HOST; + } /* Rest do not match if iface is down */ - if (!(i->flags & IF_UP)) + if (!(i->flags & IF_UP)) { + debug("iface not up %s\n", i->name); return *ap = NULL, -1; + } + + debug("regular neighbor %I %s\n", a, i->name); /* Regular neighbors */ WALK_LIST(b, i->addrs) { if (b->flags & IA_PEER) { + debug("Peer: %N\n", &b->prefix); if (ipa_equal(a, b->opposite)) return *ap = b, b->scope; } else { + debug("Test prefix: %N\n", &b->prefix); if (ipa_in_netX(a, &b->prefix)) { /* Do not allow IPv4 network and broadcast addresses */ @@ -101,7 +111,10 @@ if_connected(ip_addr a, struct iface *i, struct ifa **ap, uint flags) (net_pxlen(&b->prefix) < (IP4_MAX_PREFIX_LENGTH - 1)) && (ipa_equal(a, net_prefix(&b->prefix)) || /* Network address */ ipa_equal(a, b->brd))) /* Broadcast */ + { + debug("Do not allow IPv4 network and broadcast addresses\n"); return *ap = NULL, -1; + } return *ap = b, b->scope; } @@ -112,6 +125,8 @@ if_connected(ip_addr a, struct iface *i, struct ifa **ap, uint flags) if (flags & NEF_ONLINK) return *ap = NULL, ipa_classify(a) & IADDR_SCOPE_MASK; + debug("regular neighbor not found\n"); + return *ap = NULL, -1; } @@ -133,8 +148,10 @@ if_connected_any(ip_addr a, struct iface *vrf, struct iface **iface, struct ifa *iface = i; *addr = b; scope = s; + debug("iface found scope %s %x\n", i->name, scope); } + debug("found scope %x\n", scope); return scope; } @@ -175,12 +192,14 @@ neigh_find(struct proto *p, ip_addr a, struct iface *iface, uint flags) else { class = ipa_classify(a); + debug("find class 0x%x\n", class); if (class < 0) /* Invalid address */ return NULL; - if (((class & IADDR_SCOPE_MASK) == SCOPE_HOST) || +/* if (((class & IADDR_SCOPE_MASK) == SCOPE_HOST) || (((class & IADDR_SCOPE_MASK) == SCOPE_LINK) && !iface) || !(class & IADDR_HOST)) - return NULL; /* Bad scope or a somecast */ + return NULL;*/ /* Bad scope or a somecast */ + } if ((flags & NEF_ONLINK) && !iface) diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 8dedde9f..512220ae 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -1405,7 +1405,7 @@ bgp_start_locked(struct object_lock *lock) p->neigh = n; - if (n->scope <= 0) + if (n->scope < 0) BGP_TRACE(D_EVENTS, "Waiting for %I%J to become my neighbor", cf->remote_ip, cf->iface); else if (p->cf->check_link && !(n->iface->flags & IF_LINK_UP)) BGP_TRACE(D_EVENTS, "Waiting for link on %s", n->iface->name); diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 26716573..cc3ab6f7 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -775,7 +775,8 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len) ({ REPORT(msg, ## args); s->err_withdraw = 1; return; }) #define BAD_AFI "Unexpected AF <%u/%u> in UPDATE" -#define BAD_NEXT_HOP "Invalid NEXT_HOP attribute" +#define BAD_NEXT_HOP "Invalid NEXT_HOP attribute %d" +#define BAD_NEXT_HOP2 "Invalid NEXT_HOP attribute %d %I %I" #define NO_NEXT_HOP "Missing NEXT_HOP attribute" #define NO_LABEL_STACK "Missing MPLS stack" @@ -796,8 +797,10 @@ bgp_apply_next_hop(struct bgp_parse_state *s, rta *a, ip_addr gw, ip_addr ll) else if (ipa_nonzero(ll)) nbr = neigh_find(&p->p, ll, p->neigh->iface, 0); + REPORT("DIRECT: %d %d %p %d", ipa_nonzero(gw), ipa_nonzero(ll), nbr, nbr?nbr->scope == SCOPE_HOST:-1); + if (!nbr || (nbr->scope == SCOPE_HOST)) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP, 1); a->dest = RTD_UNICAST; a->nh.gw = nbr->addr; @@ -806,7 +809,7 @@ bgp_apply_next_hop(struct bgp_parse_state *s, rta *a, ip_addr gw, ip_addr ll) else /* GW_RECURSIVE */ { if (ipa_zero(gw)) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP, 2); rtable *tab = ipa_is_ip4(gw) ? c->igp_table_ip4 : c->igp_table_ip6; s->hostentry = rt_get_hostentry(tab, gw, ll, c->c.table); @@ -967,16 +970,16 @@ bgp_update_next_hop_ip(struct bgp_export_state *s, eattr *a, ea_list **to) /* Forbid zero next hop */ if (ipa_zero(nh[0]) && ((len != 32) || ipa_zero(nh[1]))) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP2, 3, nh[0], nh[1]); /* Forbid next hop equal to neighbor IP */ if (ipa_equal(peer, nh[0]) || ((len == 32) && ipa_equal(peer, nh[1]))) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP, 4); /* Forbid next hop with non-matching AF */ if ((ipa_is_ip4(nh[0]) != bgp_channel_is_ipv4(s->channel)) && !s->channel->ext_next_hop) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP, 5); /* Just check if MPLS stack */ if (s->mpls && !bgp_find_attr(*to, BA_MPLS_LABEL_STACK)) @@ -1048,7 +1051,7 @@ bgp_decode_next_hop_ip(struct bgp_parse_state *s, byte *data, uint len, rta *a) ad->length = 16; if ((bgp_channel_is_ipv4(c) != ipa_is_ip4(nh[0])) && !c->ext_next_hop) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP, 6); // XXXX validate next hop @@ -1129,7 +1132,7 @@ bgp_decode_next_hop_vpn(struct bgp_parse_state *s, byte *data, uint len, rta *a) bgp_parse_error(s, 9); if ((bgp_channel_is_ipv4(c) != ipa_is_ip4(nh[0])) && !c->ext_next_hop) - WITHDRAW(BAD_NEXT_HOP); + WITHDRAW(BAD_NEXT_HOP, 7); // XXXX validate next hop |