diff options
author | Marcel Röthke <marcel.roethke@haw-hamburg.de> | 2018-07-01 22:54:51 +0200 |
---|---|---|
committer | Marcel Röthke <marcel.roethke@haw-hamburg.de> | 2018-07-01 22:57:36 +0200 |
commit | 92110aabe4ecf39cbdb572b81b78be895e262d51 (patch) | |
tree | 9b222eec2f2b7a352c6703295ac0096a9ffbc7e2 /bgpd/bgp_rpki.c | |
parent | Merge pull request #2592 from tigranmartirosyan/master (diff) | |
download | frr-92110aabe4ecf39cbdb572b81b78be895e262d51.tar.xz frr-92110aabe4ecf39cbdb572b81b78be895e262d51.zip |
bgpd: fix rpki segfault
If a cache server was added after rpki was started it's tr_socket would
not be initialized. This would lead to a segfault if the rtr manager
ever decides to switch to that socket or if rpki support is stopped.
Signed-off-by: Marcel Röthke <marcel.roethke@haw-hamburg.de>
Diffstat (limited to '')
-rw-r--r-- | bgpd/bgp_rpki.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index ac4dabc16..82e857dbf 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -158,6 +158,30 @@ static void free_wrapper(void *ptr) XFREE(MTYPE_BGP_RPKI_CACHE, ptr); } +static void init_tr_socket(struct cache *cache) +{ + if (cache->type == TCP) + tr_tcp_init(cache->tr_config.tcp_config, + cache->tr_socket); +#if defined(FOUND_SSH) + else + tr_ssh_init(cache->tr_config.ssh_config, + cache->tr_socket); +#endif +} + +static void free_tr_socket(struct cache *cache) +{ + if (cache->type == TCP) + tr_tcp_init(cache->tr_config.tcp_config, + cache->tr_socket); +#if defined(FOUND_SSH) + else + tr_ssh_init(cache->tr_config.ssh_config, + cache->tr_socket); +#endif +} + static int rpki_validate_prefix(struct peer *peer, struct attr *attr, struct prefix *prefix); @@ -253,14 +277,7 @@ static struct rtr_mgr_group *get_groups(void) rtr_mgr_groups[i].sockets_len = 1; rtr_mgr_groups[i].preference = cache->preference; - if (cache->type == TCP) - tr_tcp_init(cache->tr_config.tcp_config, - cache->tr_socket); -#if defined(FOUND_SSH) - else - tr_ssh_init(cache->tr_config.ssh_config, - cache->tr_socket); -#endif + init_tr_socket(cache); i++; } @@ -517,9 +534,13 @@ static int add_cache(struct cache *cache) listnode_add(cache_list, cache); - if (rtr_is_running - && rtr_mgr_add_group(rtr_config, &group) != RTR_SUCCESS) { - return ERROR; + if (rtr_is_running) { + init_tr_socket(cache); + + if (rtr_mgr_add_group(rtr_config, &group) != RTR_SUCCESS) { + free_tr_socket(cache); + return ERROR; + } } return SUCCESS; |