From 261816b0d4f3d4549a4402b95541b82fc7f10a4b Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 15 Nov 2016 16:24:39 +0100 Subject: [PATCH 1/8] BGP: Cluster list item should be prepended Commit 3c09af41... changed behavior of int_set_add() from prepend to append, which makes more sense for community list, but prepend must be used for cluster list. Add int_set_prepend() and use it in cluster list handling code. --- nest/a-set.c | 23 +++++++++++++++++++++-- nest/attrs.h | 1 + proto/bgp/attrs.c | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/nest/a-set.c b/nest/a-set.c index bd244e2e..a6c07f45 100644 --- a/nest/a-set.c +++ b/nest/a-set.c @@ -231,6 +231,26 @@ lc_set_contains(struct adata *list, lcomm val) return 0; } +struct adata * +int_set_prepend(struct linpool *pool, struct adata *list, u32 val) +{ + struct adata *res; + int len; + + if (int_set_contains(list, val)) + return list; + + len = list ? list->length : 0; + res = lp_alloc(pool, sizeof(struct adata) + len + 4); + res->length = len + 4; + + if (list) + memcpy(res->data + 4, list->data, list->length); + + * (u32 *) res->data = val; + + return res; +} struct adata * int_set_add(struct linpool *pool, struct adata *list, u32 val) @@ -248,8 +268,7 @@ int_set_add(struct linpool *pool, struct adata *list, u32 val) if (list) memcpy(res->data, list->data, list->length); - u32 *c = (u32 *) (res->data + len); - *c = val; + * (u32 *) (res->data + len) = val; return res; } diff --git a/nest/attrs.h b/nest/attrs.h index 548d71a9..a34e64d3 100644 --- a/nest/attrs.h +++ b/nest/attrs.h @@ -132,6 +132,7 @@ int lc_set_format(struct adata *set, int from, byte *buf, uint size); int int_set_contains(struct adata *list, u32 val); int ec_set_contains(struct adata *list, u64 val); int lc_set_contains(struct adata *list, lcomm val); +struct adata *int_set_prepend(struct linpool *pool, struct adata *list, u32 val); struct adata *int_set_add(struct linpool *pool, struct adata *list, u32 val); struct adata *ec_set_add(struct linpool *pool, struct adata *list, u64 val); struct adata *lc_set_add(struct linpool *pool, struct adata *list, lcomm val); diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 0309c1f7..aa2a3b46 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -1077,7 +1077,7 @@ static inline void bgp_cluster_list_prepend(rte *e, ea_list **attrs, struct linpool *pool, u32 cid) { eattr *a = ea_find(e->attrs->eattrs, EA_CODE(EAP_BGP, BA_CLUSTER_LIST)); - bgp_attach_attr(attrs, pool, BA_CLUSTER_LIST, (uintptr_t) int_set_add(pool, a ? a->u.ptr : NULL, cid)); + bgp_attach_attr(attrs, pool, BA_CLUSTER_LIST, (uintptr_t) int_set_prepend(pool, a ? a->u.ptr : NULL, cid)); } static int From ed1a908e535e4333b358d83b472453a2ad6d3f51 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Fri, 25 Nov 2016 11:51:38 +0100 Subject: [PATCH 2/8] BGP: Fix memory leak in graceful restart code Prefix and bucket tables are initialized when entering established state but not explicitly freed when leaving it (that is handled by protocol restart). With graceful restart, BGP may enter and leave established state multiple times without hard protocol restart causing memory leak. --- lib/hash.h | 6 ++++++ proto/bgp/attrs.c | 26 ++++++++++++++++++++++++++ proto/bgp/bgp.c | 3 +++ proto/bgp/bgp.h | 2 ++ 4 files changed, 37 insertions(+) diff --git a/lib/hash.h b/lib/hash.h index 4239b1d8..6995bbc8 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -25,6 +25,12 @@ (v).data = mb_allocz(pool, HASH_SIZE(v) * sizeof(* (v).data)); \ }) +#define HASH_FREE(v) \ + ({ \ + mb_free((v).data); \ + (v) = (typeof(v)){ }; \ + }) + #define HASH_FIND(v,id,key...) \ ({ \ u32 _h = HASH_FN(v, id, key); \ diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index aa2a3b46..9d23374a 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -934,6 +934,15 @@ bgp_init_prefix_table(struct bgp_proto *p, u32 order) p->prefix_slab = sl_new(p->p.pool, sizeof(struct bgp_prefix)); } +void +bgp_free_prefix_table(struct bgp_proto *p) +{ + HASH_FREE(p->prefix_hash); + + rfree(p->prefix_slab); + p->prefix_slab = NULL; +} + static struct bgp_prefix * bgp_get_prefix(struct bgp_proto *p, ip_addr prefix, int pxlen, u32 path_id) { @@ -1940,6 +1949,23 @@ bgp_init_bucket_table(struct bgp_proto *p) // fib_init(&p->prefix_fib, p->p.pool, sizeof(struct bgp_prefix), 0, bgp_init_prefix); } +void +bgp_free_bucket_table(struct bgp_proto *p) +{ + mb_free(p->bucket_hash); + p->bucket_hash = NULL; + + struct bgp_bucket *b; + WALK_LIST_FIRST(b, p->bucket_queue) + { + rem_node(&b->send_node); + mb_free(b); + } + + mb_free(p->withdraw_bucket); + p->withdraw_bucket = NULL; +} + void bgp_get_route_info(rte *e, byte *buf, ea_list *attrs) { diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 8ef4b990..0f1c9446 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -416,6 +416,9 @@ bgp_conn_leave_established_state(struct bgp_proto *p) BGP_TRACE(D_EVENTS, "BGP session closed"); p->conn = NULL; + bgp_free_prefix_table(p); + bgp_free_bucket_table(p); + if (p->p.proto_state == PS_UP) bgp_stop(p, 0); } diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index b4067f3a..d028bef4 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -253,8 +253,10 @@ int bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_be void bgp_rt_notify(struct proto *P, rtable *tbl UNUSED, net *n, rte *new, rte *old UNUSED, ea_list *attrs); int bgp_import_control(struct proto *, struct rte **, struct ea_list **, struct linpool *); void bgp_init_bucket_table(struct bgp_proto *); +void bgp_free_bucket_table(struct bgp_proto *p); void bgp_free_bucket(struct bgp_proto *p, struct bgp_bucket *buck); void bgp_init_prefix_table(struct bgp_proto *p, u32 order); +void bgp_free_prefix_table(struct bgp_proto *p); void bgp_free_prefix(struct bgp_proto *p, struct bgp_prefix *bp); uint bgp_encode_attrs(struct bgp_proto *p, byte *w, ea_list *attrs, int remains); void bgp_get_route_info(struct rte *, byte *buf, struct ea_list *attrs); From 9e7d3a781075b39a7e0f97e63b6f313955daa661 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 13 Dec 2016 17:34:42 +0100 Subject: [PATCH 3/8] OSPF: Fix net-summary origination combined with stubnet option Stubnet nodes in OSPF FIB were removed during rt_sync(), but the pointer remained in top_hash_entry.nf, so net-summary LSA origination was confused, reported 'LSA ID collision' and net-summary LSAs were not originated properly. Thanks to Naveen Chowdary Yerramneni for bugreport and analysis. --- proto/ospf/rt.c | 17 ++++++++++------- proto/ospf/rt.h | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index 19f2d074..21aaf144 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -429,10 +429,9 @@ add_network(struct ospf_area *oa, ip_addr px, int pxlen, int metric, struct top_ if (en == oa->rt) { /* - * Local stub networks does not have proper iface in en->nhi - * (because they all have common top_hash_entry en). - * We have to find iface responsible for that stub network. - * Configured stubnets does not have any iface. They will + * Local stub networks do not have proper iface in en->nhi (because they all + * have common top_hash_entry en). We have to find iface responsible for + * that stub network. Configured stubnets do not have any iface. They will * be removed in rt_sync(). */ @@ -1560,6 +1559,7 @@ ospf_rt_reset(struct ospf_proto *p) { ri = (ort *) nftmp; ri->area_net = 0; + ri->keep = 0; reset_ri(ri); } FIB_WALK_END; @@ -1929,9 +1929,12 @@ again1: } } - /* Remove configured stubnets */ - if (!nf->n.nhs) + /* Remove configured stubnets but keep the entries */ + if (nf->n.type && !nf->n.nhs) + { reset_ri(nf); + nf->keep = 1; + } if (nf->n.type) /* Add the route */ { @@ -1991,7 +1994,7 @@ again1: } /* Remove unused rt entry, some special entries are persistent */ - if (!nf->n.type && !nf->external_rte && !nf->area_net) + if (!nf->n.type && !nf->external_rte && !nf->area_net && !nf->keep) { FIB_ITERATE_PUT(&fit, nftmp); fib_delete(fib, nftmp); diff --git a/proto/ospf/rt.h b/proto/ospf/rt.h index 30332f3b..73b28375 100644 --- a/proto/ospf/rt.h +++ b/proto/ospf/rt.h @@ -84,6 +84,7 @@ typedef struct ort rta *old_rta; u8 external_rte; u8 area_net; + u8 keep; } ort; From 7d95c44572d79ef15ec8b0220950b4e4374c6bc6 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Thu, 15 Dec 2016 15:31:25 +0100 Subject: [PATCH 4/8] OSPF: Fix ECMP external merging The variable nfa is not cleaned before each loop iteration and can have a wrong value of nfa.nhs_reuse from the previous step. Thanks to Bernardo Figueiredo for the bugreport and analysis. --- proto/ospf/rt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index 21aaf144..368e3d05 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -1405,7 +1405,6 @@ ospf_ext_spf(struct ospf_proto *p) struct top_hash_entry *en; struct ospf_lsa_ext_local rt; ort *nf1, *nf2; - orta nfa = {}; ip_addr rtid; u32 br_metric; struct ospf_area *atmp; @@ -1414,6 +1413,8 @@ ospf_ext_spf(struct ospf_proto *p) WALK_SLIST(en, p->lsal) { + orta nfa = {}; + /* 16.4. (1) */ if ((en->lsa_type != LSA_T_EXT) && (en->lsa_type != LSA_T_NSSA)) continue; From 2c33da507046c25d87741fe0ce7947985c8c7a10 Mon Sep 17 00:00:00 2001 From: Jan Moskyto Matejka Date: Tue, 20 Dec 2016 20:13:08 +0100 Subject: [PATCH 5/8] Netlink: fix occasional netlink hangs on busy machines --- sysdep/linux/netlink.c | 1 + sysdep/unix/io.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index 368e0ef9..22313f43 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -1497,6 +1497,7 @@ nl_async_hook(sock *sk, uint size UNUSED) * One day we might react to it by asking for route table * scan in near future. */ + log(L_WARN "Kernel dropped some netlink messages, will resync on next scan."); return 1; /* More data are likely to be ready */ } else if (errno != EWOULDBLOCK) diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 644a4fcd..8773f4c4 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -2238,7 +2238,8 @@ io_loop(void) if (pfd[s->index].revents & (POLLHUP | POLLERR)) { sk_err(s, pfd[s->index].revents); - goto next2; + if (s != current_sock) + goto next2; } current_sock = sk_next(s); From 017da76b729cc36c4a3416995b06386235660f42 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Wed, 21 Dec 2016 16:46:47 +0100 Subject: [PATCH 6/8] NEWS and version update --- NEWS | 7 +++++++ misc/bird.spec | 2 +- sysdep/config.h | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 26314d82..a9bd6a72 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +Version 1.6.3 (2016-12-21) + o Large BGP communities + o BFD authentication (MD5, SHA1) + o SHA1 and SHA2 authentication for RIP and OSPF + o Improved documentation + o Several bug fixes + Version 1.6.2 (2016-09-29) o Fixes serious bug introduced in the previous version diff --git a/misc/bird.spec b/misc/bird.spec index ebc0c942..bfbfc484 100644 --- a/misc/bird.spec +++ b/misc/bird.spec @@ -1,6 +1,6 @@ Summary: BIRD Internet Routing Daemon Name: bird -Version: 1.6.2 +Version: 1.6.3 Release: 1 Copyright: GPL Group: Networking/Daemons diff --git a/sysdep/config.h b/sysdep/config.h index c7f63e69..84085f9c 100644 --- a/sysdep/config.h +++ b/sysdep/config.h @@ -7,7 +7,7 @@ #define _BIRD_CONFIG_H_ /* BIRD version */ -#define BIRD_VERSION "1.6.2" +#define BIRD_VERSION "1.6.3" /* Include parameters determined by configure script */ #include "sysdep/autoconf.h" From f6e6c3b5a5997ffc67d96785bbde76bcec072890 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 17 Jan 2017 13:21:25 +0100 Subject: [PATCH 7/8] Fix IP_HDRINCL usage on FreeBSD 11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FreeBSD 11 changed endianity of ip_len field from host order to network order. Also DragonFly BSD allegedly expects network order here. Thanks to Olivier Cochard-Labbé for the patch. --- sysdep/bsd/sysio.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sysdep/bsd/sysio.h b/sysdep/bsd/sysio.h index 2610a47b..9b10e6e8 100644 --- a/sysdep/bsd/sysio.h +++ b/sysdep/bsd/sysio.h @@ -9,6 +9,7 @@ #include #include // Workaround for some BSDs #include +#include #ifdef __NetBSD__ @@ -179,8 +180,8 @@ sk_prepare_ip_header(sock *s, void *hdr, int dlen) ip->ip_src = ipa_to_in4(s->saddr); ip->ip_dst = ipa_to_in4(s->daddr); -#ifdef __OpenBSD__ - /* OpenBSD expects ip_len in network order, other BSDs expect host order */ +#if (defined __OpenBSD__) || (defined __DragonFly__) || (defined __FreeBSD__ && (__FreeBSD_version >= 1100030)) + /* Different BSDs have different expectations of ip_len endianity */ ip->ip_len = htons(ip->ip_len); #endif } From da65a3d898fde0ce567782d86919a66e29916ed7 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 24 Jan 2017 15:35:38 +0100 Subject: [PATCH 8/8] Filter: Fix missing case for !~ operator Thanks to Vincent Bernat for the patch. --- filter/filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/filter/filter.c b/filter/filter.c index 85a06258..f18970e0 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -1559,6 +1559,7 @@ i_same(struct f_inst *f1, struct f_inst *f2) case P('<','='): TWOARGS; break; case '!': ONEARG; break; + case P('!', '~'): case '~': TWOARGS; break; case P('d','e'): ONEARG; break;