Add next_hop field to route update record, filled in locally.
authorJennifer Richards <jennifer@painless-security.com>
Thu, 30 Jun 2016 16:32:37 +0000 (12:32 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Thu, 30 Jun 2016 16:32:37 +0000 (12:32 -0400)
common/tr_msg.c
include/trp_internal.h
trp/trp_conn.c
trp/trp_upd.c
trp/trps.c

index 685ad46..6295068 100644 (file)
@@ -673,6 +673,8 @@ static TRP_INFOREC *tr_msg_decode_trp_inforec(TALLOC_CTX *mem_ctx, json_t *jreco
     goto cleanup;
   talloc_free(s); s=NULL;
 
+  trp_inforec_set_next_hop(rec, NULL); /* make sure this is null (filled in later) */
+
   rc=tr_msg_get_json_integer(jrecord, "metric", &num);
   if ((rc != TRP_SUCCESS) || (TRP_SUCCESS!=trp_inforec_set_metric(rec,num)))
     goto cleanup;
index 5e93dcb..3f7fa0e 100644 (file)
@@ -16,6 +16,7 @@ typedef struct trp_inforec_route {
   TR_NAME *comm;
   TR_NAME *realm;
   TR_NAME *trust_router;
+  TR_NAME *next_hop;
   unsigned int metric;
   unsigned int interval;
 } TRP_INFOREC_ROUTE;
@@ -56,6 +57,7 @@ struct trp_connection {
   TRP_CONNECTION *next;
   pthread_t *thread; /* thread servicing this connection */
   int fd;
+  TR_NAME *peer; /* who is this a connection to? */
   TR_NAME *gssname;
   gss_ctx_id_t *gssctx;
   TRP_CONNECTION_STATUS status;
index 1f99496..9c3d813 100644 (file)
@@ -30,6 +30,16 @@ void trp_connection_set_fd(TRP_CONNECTION *conn, int fd)
   conn->fd=fd;
 }
 
+TR_NAME *trp_connection_get_peer(TRP_CONNECTION *conn)
+{
+  return conn->peer;
+}
+
+void trp_connection_set_peer(TRP_CONNECTION *conn, TR_NAME *peer)
+{
+  conn->peer=peer;
+}
+
 TR_NAME *trp_connection_get_gssname(TRP_CONNECTION *conn)
 {
   return conn->gssname;
@@ -139,6 +149,8 @@ static int trp_connection_destructor(void *object)
   if ((trp_connection_get_status(conn)!=TRP_CONNECTION_DOWN)
      && (trp_connection_get_fd(conn)!=-1))
     close(trp_connection_get_fd(conn));
+  if (conn->peer!=NULL)
+    tr_free_name(conn->peer);
   if (conn->gssname!=NULL)
     tr_free_name(conn->gssname);
   return 0;
@@ -154,6 +166,7 @@ TRP_CONNECTION *trp_connection_new(TALLOC_CTX *mem_ctx)
   if (new_conn != NULL) {
     trp_connection_set_next(new_conn, NULL);
     trp_connection_set_fd(new_conn, -1);
+    trp_connection_set_peer(new_conn, NULL);
     trp_connection_set_gssname(new_conn, NULL);
     trp_connection_mutex_init(new_conn);
     trp_connection_set_status(new_conn, TRP_CONNECTION_DOWN);
@@ -272,6 +285,7 @@ TRP_RC trp_connection_initiate(TRP_CONNECTION *conn, const char *server, unsigne
     return TRP_ERROR;
   } else {
     trp_connection_set_fd(conn, fd);
+    trp_connection_set_peer(conn, tr_new_name(server));
     trp_connection_set_status(conn, TRP_CONNECTION_UP);
     return TRP_SUCCESS;
   }
index 248f458..d8ba9fa 100644 (file)
@@ -76,6 +76,11 @@ static int trp_inforec_route_destructor(void *object)
     body->trust_router=NULL;
     tr_debug("trp_inforec_route_destructor: freed trust_router");
   }
+  if (body->next_hop != NULL) {
+    tr_free_name(body->next_hop);
+    body->hop=NULL;
+    tr_debug("trp_inforec_route_destructor: freed next_hop");
+  }
 
   return 0;
 }
@@ -88,6 +93,7 @@ static void *trp_inforec_route_new(TALLOC_CTX *mem_ctx)
     new_rec->comm=NULL;
     new_rec->realm=NULL;
     new_rec->trust_router=NULL;
+    new_rec->next_hop=NULL;
     new_rec->metric=TRP_METRIC_INFINITY;
     new_rec->interval=0;
     talloc_set_destructor((void *)new_rec, trp_inforec_route_destructor);
@@ -207,6 +213,34 @@ TRP_RC trp_inforec_set_trust_router(TRP_INFOREC *rec, TR_NAME *trust_router)
   return TRP_ERROR;
 }
 
+TR_NAME *trp_inforec_get_next_hop(TRP_INFOREC *rec)
+{
+  switch (rec->type) {
+  case TRP_INFOREC_TYPE_ROUTE:
+    if (rec->data.route!=NULL)
+      return rec->data.route->next_hop;
+    break;
+  default:
+    break;
+  }
+  return NULL;
+}
+
+TRP_RC trp_inforec_set_next_hop(TRP_INFOREC *rec, TR_NAME *next_hop)
+{
+  switch (rec->type) {
+  case TRP_INFOREC_TYPE_ROUTE:
+    if (rec->data.route!=NULL) {
+      rec->data.route->next_hop=next_hop;
+      return TRP_SUCCESS;
+    }
+    break;
+  default:
+    break;
+  }
+  return TRP_ERROR;
+}
+
 unsigned int trp_inforec_get_metric(TRP_INFOREC *rec)
 {
   switch (rec->type) {
index f1175e6..7a27840 100644 (file)
@@ -181,8 +181,10 @@ static TRP_RC trps_read_message(TRPS_INSTANCE *trps, TRP_CONNECTION *conn, TR_MS
   free(buf);
   if (*msg==NULL)
     return TRP_NOPARSE;
-  else
-    return TRP_SUCCESS;
+
+  /* fill in the next hop as the peer who just sent this to us */
+  trp_inforec_set_next_hop(*msg, trp_connection_get_peer(conn));
+  return TRP_SUCCESS;
 }
 
 int trps_get_listener(TRPS_INSTANCE *trps,