]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
RPKI: refactore transports
authorPavel Tvrdík <pawel.tvrdik@gmail.com>
Mon, 18 Jan 2016 07:16:55 +0000 (08:16 +0100)
committerPavel Tvrdík <pawel.tvrdik@gmail.com>
Mon, 25 Jan 2016 14:39:38 +0000 (15:39 +0100)
proto/rpki/ssh_transport.c
proto/rpki/tcp_transport.c
proto/rpki/tcp_transport.h

index ec7d7421c7f2d184158bd427b154f9ae3f801420..e8e30362da6ee9b18576cf1acd09d7852850126c 100644 (file)
@@ -23,7 +23,7 @@
 static int tr_ssh_open(void *tr_ssh_sock);
 static void tr_ssh_close(void *tr_ssh_sock);
 static void tr_ssh_free(struct tr_socket *tr_sock);
-static const char *tr_ssh_ident(void *tr_ssh_sock);
+static const char *tr_ssh_ident(void *socket);
 
 int tr_ssh_open(void *socket)
 {
@@ -74,6 +74,8 @@ void tr_ssh_close(void *tr_ssh_sock)
       ssh_free(sk->ssh->session);
       sk->ssh->session = NULL;
     }
+    mb_free(sk->ssh);
+    sk->ssh = NULL;
   }
 }
 
@@ -90,26 +92,25 @@ void tr_ssh_free(struct tr_socket *tr_sock)
   }
 }
 
-const char *tr_ssh_ident(void *tr_ssh_sock)
+const char *tr_ssh_ident(void *socket)
 {
-  size_t len;
-  struct tr_ssh_socket *ssh_sock = tr_ssh_sock;
-  struct rpki_cache *cache = ssh_sock->cache;
+  ASSERT(socket != NULL);
 
-  assert(ssh_sock != NULL);
+  struct tr_ssh_socket *ssh = socket;
+  struct rpki_cache *cache = ssh->cache;
 
-  if (ssh_sock->ident != NULL)
-    return ssh_sock->ident;
+  if (ssh->ident != NULL)
+    return ssh->ident;
 
   const char *username = cache->cfg->ssh->username;
   const char *host = cache->cfg->hostname;
 
-  len = strlen(username) + 1 + strlen(host) + 1 + 5 + 1; /* <user> + '@' + <host> + ':' + <port> + '\0' */
-  ssh_sock->ident = mb_alloc(cache->p->p.pool, len);
-  if (ssh_sock->ident == NULL)
+  size_t len = strlen(username) + 1 + strlen(host) + 1 + 5 + 1; /* <user> + '@' + <host> + ':' + <port> + '\0' */
+  ssh->ident = mb_alloc(cache->p->p.pool, len);
+  if (ssh->ident == NULL)
     return NULL;
-  snprintf(ssh_sock->ident, len, "%s@%s:%u", username, host, cache->cfg->port);
-  return ssh_sock->ident;
+  snprintf(ssh->ident, len, "%s@%s:%u", username, host, cache->cfg->port);
+  return ssh->ident;
 }
 
 int tr_ssh_init(struct rpki_cache *cache)
@@ -124,7 +125,6 @@ int tr_ssh_init(struct rpki_cache *cache)
 
   tr_socket->socket = mb_allocz(p->p.pool, sizeof(struct tr_ssh_socket));
   struct tr_ssh_socket *ssh = tr_socket->socket;
-
   ssh->cache = cache;
 
   return TR_SUCCESS;
index 7c81b53706ca55c45fc238c747a3ccec006edc5a..71b9154c162665e1a8a3342ceb288800689ed25b 100644 (file)
@@ -36,7 +36,6 @@ int tr_tcp_open(void *tr_tcp_sock)
 
   sock *sk = cache->sk;
   sk->type = SK_TCP_ACTIVE;
-  sk->daddr = tcp_socket->config.ip;
 
   if (sk_open(sk) != 0)
     return TR_ERROR;
@@ -71,31 +70,33 @@ void tr_tcp_free(struct tr_socket *tr_sock)
 
 const char *tr_tcp_ident(void *socket)
 {
-  assert(socket != NULL);
+  ASSERT(socket != NULL);
 
-  struct tr_tcp_socket *sock = socket;
-  struct rpki_proto *p = sock->cache->p;
+  struct tr_tcp_socket *tcp = socket;
+  struct rpki_cache *cache = tcp->cache;
 
-  if (sock->ident != NULL)
-    return sock->ident;
+  if (tcp->ident != NULL)
+    return tcp->ident;
+
+  const char *host = cache->cfg->hostname;
 
   size_t colon_and_port_len = 6; /* max ":65535" */
   size_t ident_len;
-  if (sock->config.host)
-    ident_len = strlen(sock->config.host) + colon_and_port_len + 1;
+  if (host)
+    ident_len = strlen(host) + colon_and_port_len + 1;
   else
     ident_len = IPA_MAX_TEXT_LENGTH + colon_and_port_len + 1;
 
-  sock->ident = mb_allocz(p->p.pool, ident_len);
-  if (sock->ident == NULL)
+  tcp->ident = mb_allocz(cache->p->p.pool, ident_len);
+  if (tcp->ident == NULL)
     return NULL;
 
-  if (sock->config.host)
-    bsnprintf(sock->ident, ident_len, "%s:%u", sock->config.host, sock->config.port);
+  if (host)
+    bsnprintf(tcp->ident, ident_len, "%s:%u", host, cache->cfg->port);
   else
-    bsnprintf(sock->ident, ident_len, "%I:%u", sock->config.ip, sock->config.port);
+    bsnprintf(tcp->ident, ident_len, "%I:%u", cache->cfg->ip, cache->cfg->port);
 
-  return sock->ident;
+  return tcp->ident;
 }
 
 int tr_tcp_init(struct rpki_cache *cache)
@@ -111,11 +112,7 @@ int tr_tcp_init(struct rpki_cache *cache)
 
   tr_socket->socket = mb_allocz(p->p.pool, sizeof(struct tr_tcp_socket));
   struct tr_tcp_socket *tcp = tr_socket->socket;
-
   tcp->cache = cache;
-  tcp->config.host = cache_cfg->hostname;
-  tcp->config.ip = cache_cfg->ip;
-  tcp->config.port = cache_cfg->port;
 
   return TR_SUCCESS;
 }
index 07e8acdb85b7693ade387173cea26fe3ba905329..99661df3d8470e13e6a81ece590a6e060ce8ef2d 100644 (file)
 #include "nest/bird.h"
 #include "lib/ip.h"
 
-/**
- * @brief  A tr_tcp_config struct holds configuration for a TCP connection.
- * @param host Hostname or IP address to connect to.
- * @param port Port to connect to.
- * @param bindaddr Hostname or IP address to connect from. NULL for
- *                determination by OS.
- * to use the source address of the system's default route to the server
- */
-struct tr_tcp_config {
-  ip_addr ip;  char *host;     /* at least one of @ip or @host must be defined */
-  uint port;
-  char *bindaddr;              /* TODO: NEED THIS? */
-};
-
 struct tr_tcp_socket {
   struct rpki_cache *cache;
-  struct tr_tcp_config config;
   char *ident;
 };