From: Pavel TvrdĂ­k Date: Wed, 23 Dec 2015 13:40:43 +0000 (+0100) Subject: RPKI: move rtr_change_socket_state() to proto/rpki/rtr.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e138152c6f25dae4b8c94250ae9c21ef403ad456;p=thirdparty%2Fbird.git RPKI: move rtr_change_socket_state() to proto/rpki/rtr.c --- diff --git a/proto/rpki/packets.c b/proto/rpki/packets.c index e5bc1fc71..4b4bcd3d2 100644 --- a/proto/rpki/packets.c +++ b/proto/rpki/packets.c @@ -211,98 +211,6 @@ pfx_table_src_remove(struct rpki_cache *cache) roa_flush(cache->p->cf->roa_table_cf->table, cache->roa_src); } -void -rtr_change_socket_state(struct rtr_socket *rtr_socket, const enum rtr_socket_state new_state) -{ - const enum rtr_socket_state old_state = rtr_socket->state; - - if (old_state == new_state) - return; - - rtr_socket->state = new_state; - - struct rpki_cache *cache = rtr_socket->cache; - CACHE_TRACE(D_EVENTS, cache, "Change state %s -> %s", rtr_state_to_str(old_state), rtr_state_to_str(new_state)); - - switch (new_state) - { - case RTR_CONNECTING: - if (cache->sk == NULL || cache->sk->fd < 0) - { - if (rpki_open_connection(cache) == TR_SUCCESS) - cache->rtr_socket->state = RTR_SYNC; /* Need call a setup the bird socket in io.c loop */ - } - else - rtr_change_socket_state(rtr_socket, RTR_SYNC); - break; - - case RTR_ESTABLISHED: - /* Connection is established, socket is waiting for a Serial Notify or expiration of the refresh_interval timer */ - break; - - case RTR_RESET: - /* Resetting RTR connection. */ - rtr_socket->request_session_id = true; - rtr_socket->serial_number = 0; - rtr_change_socket_state(rtr_socket, RTR_SYNC); - break; - - case RTR_SYNC: - /* Requesting for receive validation records from the RTR server. */ - if (rtr_socket->request_session_id) - { - //change to state RESET, if socket dont has a session_id - if (rtr_send_reset_query(cache) != RTR_SUCCESS) - rtr_change_socket_state(rtr_socket, RTR_ERROR_FATAL); - } - else - { - //if we already have a session_id, send a serial query and start to sync - if (rtr_send_serial_query(cache) != RTR_SUCCESS) - rtr_change_socket_state(rtr_socket, RTR_ERROR_FATAL); - } - break; - - case RTR_ERROR_NO_INCR_UPDATE_AVAIL: - /* Server was unable to answer the last serial or reset query. */ - rtr_purge_records_if_outdated(cache); - /* Fall through */ - - case RTR_ERROR_NO_DATA_AVAIL: - /* No validation records are available on the RTR server. */ - rtr_change_socket_state(rtr_socket, RTR_RESET); - break; - - case RTR_ERROR_FATAL: - /* Fatal protocol error occurred. */ - rtr_socket->request_session_id = true; - rtr_socket->serial_number = 0; - rtr_socket->last_update = 0; - pfx_table_src_remove(cache); - /* Fall through */ - - case RTR_ERROR_TRANSPORT: - /* Error on the transport socket occurred. */ - rpki_close_connection(cache); - rtr_schedule_next_retry(cache); - break; - - case RTR_FAST_RECONNECT: - /* Reconnect without any waiting period */ - rpki_close_connection(cache); - rtr_change_socket_state(rtr_socket, RTR_CONNECTING); - break; - - case RTR_SHUTDOWN: - /* RTR Socket is stopped. */ - rpki_close_connection(cache); - rtr_socket->request_session_id = true; - rtr_socket->serial_number = 0; - rtr_socket->last_update = 0; - pfx_table_src_remove(cache); - break; - }; -} static void rtr_pdu_to_network_byte_order(void *pdu) { diff --git a/proto/rpki/packets.h b/proto/rpki/packets.h index 4d89ed2a9..0fa62cd55 100644 --- a/proto/rpki/packets.h +++ b/proto/rpki/packets.h @@ -26,7 +26,6 @@ #define RPKI_RECV_TIMEOUT 60 #define RPKI_SEND_TIMEOUT 60 -void rtr_change_socket_state(struct rtr_socket *rtr_socket, const enum rtr_socket_state new_state); int rtr_sync(struct rpki_cache *cache); int rtr_wait_for_sync(struct rpki_cache *cache); int rtr_send_serial_query(struct rpki_cache *cache); diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c index da79e3f90..476220258 100644 --- a/proto/rpki/rpki.c +++ b/proto/rpki/rpki.c @@ -253,7 +253,6 @@ static void rpki_remove_cache_from_group(struct rpki_cache *cache) { rem2_node(&cache->n); - } static void diff --git a/proto/rpki/rtr.c b/proto/rpki/rtr.c index 89db0c780..da84a9ce3 100644 --- a/proto/rpki/rtr.c +++ b/proto/rpki/rtr.c @@ -91,6 +91,99 @@ rtr_state_to_str(enum rtr_socket_state state) return rtr_socket_str_states[state]; } +void +rtr_change_socket_state(struct rtr_socket *rtr_socket, const enum rtr_socket_state new_state) +{ + const enum rtr_socket_state old_state = rtr_socket->state; + + if (old_state == new_state) + return; + + rtr_socket->state = new_state; + + struct rpki_cache *cache = rtr_socket->cache; + CACHE_TRACE(D_EVENTS, cache, "Change state %s -> %s", rtr_state_to_str(old_state), rtr_state_to_str(new_state)); + + switch (new_state) + { + case RTR_CONNECTING: + if (cache->sk == NULL || cache->sk->fd < 0) + { + if (rpki_open_connection(cache) == TR_SUCCESS) + cache->rtr_socket->state = RTR_SYNC; /* Need call a setup the bird socket in io.c loop */ + } + else + rtr_change_socket_state(rtr_socket, RTR_SYNC); + break; + + case RTR_ESTABLISHED: + /* Connection is established, socket is waiting for a Serial Notify or expiration of the refresh_interval timer */ + break; + + case RTR_RESET: + /* Resetting RTR connection. */ + rtr_socket->request_session_id = true; + rtr_socket->serial_number = 0; + rtr_change_socket_state(rtr_socket, RTR_SYNC); + break; + + case RTR_SYNC: + /* Requesting for receive validation records from the RTR server. */ + if (rtr_socket->request_session_id) + { + //change to state RESET, if socket dont has a session_id + if (rtr_send_reset_query(cache) != RTR_SUCCESS) + rtr_change_socket_state(rtr_socket, RTR_ERROR_FATAL); + } + else + { + //if we already have a session_id, send a serial query and start to sync + if (rtr_send_serial_query(cache) != RTR_SUCCESS) + rtr_change_socket_state(rtr_socket, RTR_ERROR_FATAL); + } + break; + + case RTR_ERROR_NO_INCR_UPDATE_AVAIL: + /* Server was unable to answer the last serial or reset query. */ + rtr_purge_records_if_outdated(cache); + /* Fall through */ + + case RTR_ERROR_NO_DATA_AVAIL: + /* No validation records are available on the RTR server. */ + rtr_change_socket_state(rtr_socket, RTR_RESET); + break; + + case RTR_ERROR_FATAL: + /* Fatal protocol error occurred. */ + rtr_socket->request_session_id = true; + rtr_socket->serial_number = 0; + rtr_socket->last_update = 0; + pfx_table_src_remove(cache); + /* Fall through */ + + case RTR_ERROR_TRANSPORT: + /* Error on the transport socket occurred. */ + rpki_close_connection(cache); + rtr_schedule_next_retry(cache); + break; + + case RTR_FAST_RECONNECT: + /* Reconnect without any waiting period */ + rpki_close_connection(cache); + rtr_change_socket_state(rtr_socket, RTR_CONNECTING); + break; + + case RTR_SHUTDOWN: + /* RTR Socket is stopped. */ + rpki_close_connection(cache); + rtr_socket->request_session_id = true; + rtr_socket->serial_number = 0; + rtr_socket->last_update = 0; + pfx_table_src_remove(cache); + break; + }; +} + /* * Timers */ diff --git a/proto/rpki/rtr.h b/proto/rpki/rtr.h index 2a4879097..ab308686e 100644 --- a/proto/rpki/rtr.h +++ b/proto/rpki/rtr.h @@ -129,10 +129,12 @@ void rtr_stop(struct rtr_socket *rtr_socket); */ const char *rtr_state_to_str(enum rtr_socket_state state); +void rtr_purge_records_if_outdated(struct rpki_cache *cache); +void rtr_change_socket_state(struct rtr_socket *rtr_socket, const enum rtr_socket_state new_state); + void rpki_retry_hook(struct timer *tm); void rpki_expire_hook(struct timer *tm); void rpki_refresh_hook(struct timer *tm); -void rtr_purge_records_if_outdated(struct rpki_cache *cache); void rtr_schedule_next_refresh(struct rpki_cache *cache); void rtr_schedule_next_retry(struct rpki_cache *cache);