]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
RPKI: move rtr_change_socket_state() to proto/rpki/rtr.c
authorPavel Tvrdík <pawel.tvrdik@gmail.com>
Wed, 23 Dec 2015 13:40:43 +0000 (14:40 +0100)
committerPavel Tvrdík <pawel.tvrdik@gmail.com>
Wed, 23 Dec 2015 14:09:12 +0000 (15:09 +0100)
proto/rpki/packets.c
proto/rpki/packets.h
proto/rpki/rpki.c
proto/rpki/rtr.c
proto/rpki/rtr.h

index e5bc1fc71ddcdfbb2233401642aee0c525fbd575..4b4bcd3d26a19a28a396c851ff11c5533d44e7f8 100644 (file)
@@ -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)
 {
index 4d89ed2a99cdc8e8939d6e5d6211bfd8b2d27906..0fa62cd552f9a812e7557cc743413a0fdd9aaa1e 100644 (file)
@@ -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);
index da79e3f90249f7378cbbc44c8ac0f747f607756b..4762202588afcd8bbfd3d3b04eccea7a859df614 100644 (file)
@@ -253,7 +253,6 @@ static void
 rpki_remove_cache_from_group(struct rpki_cache *cache)
 {
   rem2_node(&cache->n);
-
 }
 
 static void
index 89db0c780a31e6fde607d6b9e2c36134c66ffae6..da84a9ce3ba0f741dd83f6273cb1314e450b70e9 100644 (file)
@@ -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
  */
index 2a487909745304b0dc6bf7c5574c0ba13c3f6ea1..ab308686ebc6591fb71b7a9b2c692c2600cb5400 100644 (file)
@@ -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);