diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 219cb299834e..038f71ed0de0 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -1330,26 +1330,50 @@ static int rpki_create_socket(void *_cache) frr_with_privs (&bgpd_privs) { ret = vrf_getaddrinfo(host, port, &hints, &res, vrf->vrf_id); } - if (ret != 0) + if (ret != 0) { + if (res) + freeaddrinfo(res); return -1; + } frr_with_privs (&bgpd_privs) { socket = vrf_socket(res->ai_family, res->ai_socktype, res->ai_protocol, vrf->vrf_id, NULL); } - if (socket < 0) + if (socket < 0) { + if (res) + freeaddrinfo(res); return -1; + } pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &cancel_state); timeout.tv_sec = 30; timeout.tv_usec = 0; optlen = sizeof(prev_rcv_tmout); - getsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout, &optlen); - getsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout, &optlen); - - setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); - setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); + ret = getsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout, + &optlen); + if (ret < 0) + zlog_warn("%s: failed to getsockopt SO_RCVTIMEO for socket %d", + __func__, socket); + + ret = getsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout, + &optlen); + if (ret < 0) + zlog_warn("%s: failed to getsockopt SO_SNDTIMEO for socket %d", + __func__, socket); + + ret = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, + sizeof(timeout)); + if (ret < 0) + zlog_warn("%s: failed to setsockopt SO_RCVTIMEO for socket %d", + __func__, socket); + + ret = setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &timeout, + sizeof(timeout)); + if (ret < 0) + zlog_warn("%s: failed to setsockopt SO_SNDTIMEO for socket %d", + __func__, socket); if (connect(socket, res->ai_addr, res->ai_addrlen) == -1) { if (res) @@ -1363,10 +1387,17 @@ static int rpki_create_socket(void *_cache) freeaddrinfo(res); pthread_setcancelstate(cancel_state, NULL); - setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout, - sizeof(prev_rcv_tmout)); - setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout, - sizeof(prev_snd_tmout)); + ret = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout, + sizeof(prev_rcv_tmout)); + if (ret < 0) + zlog_warn("%s: failed to setsockopt SO_RCVTIMEO for socket %d", + __func__, socket); + + ret = setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout, + sizeof(prev_snd_tmout)); + if (ret < 0) + zlog_warn("%s: failed to setsockopt SO_SNDTIMEO for socket %d", + __func__, socket); return socket; } @@ -1627,6 +1658,9 @@ DEFUN_NOSH (rpki, else { struct vrf *vrf = VTY_GET_CONTEXT(vrf); + if (!vrf) + return CMD_WARNING_CONFIG_FAILED; + vty->node = RPKI_VRF_NODE; if (vrf->vrf_id != VRF_DEFAULT) vrfname = vrf->name; @@ -1732,6 +1766,9 @@ DEFPY (rpki_polling_period, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + rpki_vrf->polling_period = pp; return CMD_SUCCESS; } @@ -1751,6 +1788,9 @@ DEFUN (no_rpki_polling_period, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + rpki_vrf->polling_period = POLLING_PERIOD_DEFAULT; return CMD_SUCCESS; } @@ -1769,6 +1809,9 @@ DEFPY (rpki_expire_interval, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + if ((unsigned int)tmp >= rpki_vrf->polling_period) { rpki_vrf->expire_interval = tmp; return CMD_SUCCESS; @@ -1793,6 +1836,9 @@ DEFUN (no_rpki_expire_interval, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + rpki_vrf->expire_interval = rpki_vrf->polling_period * 2; return CMD_SUCCESS; } @@ -1811,6 +1857,9 @@ DEFPY (rpki_retry_interval, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + rpki_vrf->retry_interval = tmp; return CMD_SUCCESS; } @@ -1830,6 +1879,9 @@ DEFUN (no_rpki_retry_interval, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + rpki_vrf->retry_interval = RETRY_INTERVAL_DEFAULT; return CMD_SUCCESS; } @@ -1930,9 +1982,12 @@ DEFPY (no_rpki_cache, else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + if (!rpki_vrf) + return CMD_WARNING; + cache_list = rpki_vrf->cache_list; cache_p = find_cache(preference, cache_list); - if (!rpki_vrf || !cache_p) { + if (!cache_p) { vty_out(vty, "Could not find cache with preference %ld\n", preference); return CMD_WARNING; @@ -2376,7 +2431,7 @@ DEFPY(show_rpki_configuration, show_rpki_configuration_cmd, if (!rpki_vrf) { if (uj) vty_json(vty, json); - return CMD_SUCCESS; + return CMD_WARNING_CONFIG_FAILED; } if (uj) { @@ -2422,6 +2477,10 @@ static int config_on_exit(struct vty *vty) rpki_vrf = VTY_GET_CONTEXT_SUB(rpki_vrf); else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + reset(false, rpki_vrf); return 1; } @@ -2454,6 +2513,10 @@ DEFPY (rpki_reset_config_mode, rpki_vrf = VTY_GET_CONTEXT_SUB(rpki_vrf); else rpki_vrf = VTY_GET_CONTEXT(rpki_vrf); + + if (!rpki_vrf) + return CMD_WARNING_CONFIG_FAILED; + return reset(true, rpki_vrf) == SUCCESS ? CMD_SUCCESS : CMD_WARNING; }