aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/libhicnctrl/src/modules
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2022-09-20 13:27:12 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2022-09-22 12:20:58 +0200
commitbd26d18978861b24c5707dbaa24dac76133425e2 (patch)
tree7ff84df44d440254b48f800c368005eb27d4680d /ctrl/libhicnctrl/src/modules
parent45da502db58f712b78e59c214f05c44aa01ea8d0 (diff)
fix(libhicnctrl): fix new listener validation during face or connection creation
Change-Id: I5f532320fcb3fc01cd3a027af7ea5fc6425e4097 Ref: HICN-790 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'ctrl/libhicnctrl/src/modules')
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light.c11
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/face.c307
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light/stats.h26
3 files changed, 34 insertions, 310 deletions
diff --git a/ctrl/libhicnctrl/src/modules/hicn_light.c b/ctrl/libhicnctrl/src/modules/hicn_light.c
index 658043b7f..8c2009d91 100644
--- a/ctrl/libhicnctrl/src/modules/hicn_light.c
+++ b/ctrl/libhicnctrl/src/modules/hicn_light.c
@@ -897,7 +897,7 @@ NEXT:
/* Check whether listener creation succeeded */
case REQUEST_STATE_CONNECTION_CREATE_LISTENER_CHECK:
- if (!data || hc_data_get_result(data)) return -1;
+ if (!data || !hc_data_get_result(data)) return -1;
hc_request_set_state(current_request, REQUEST_STATE_CONNECTION_CREATE);
goto NEXT;
@@ -1068,8 +1068,13 @@ static ssize_t hicnlight_prepare(hc_sock_t *sock, hc_request_t *request,
static hc_object_t object_subscribe;
- DEBUG("[hicnlight_prepare] %s %s", action_str(action),
- object_type_str(object_type));
+ WITH_DEBUG({
+ char buf[MAXSZ_HC_OBJECT];
+ hc_request_state_t state = hc_request_get_state(current_request);
+ hc_object_snprintf(buf, sizeof(buf), object_type, object);
+ DEBUG("[hicnlight_prepare] %s %s [%s] %s", action_str(action),
+ object_type_str(object_type), hc_request_state_str(state), buf);
+ });
/*
* Here the request is in progress and we just need to iterate through the
diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/face.c b/ctrl/libhicnctrl/src/modules/hicn_light/face.c
index 0d9475420..46adf633d 100644
--- a/ctrl/libhicnctrl/src/modules/hicn_light/face.c
+++ b/ctrl/libhicnctrl/src/modules/hicn_light/face.c
@@ -173,310 +173,3 @@ int hc_face_to_listener(const hc_face_t *face, hc_listener_t *listener) {
}
return -1; /* XXX Not implemented */
}
-
-#if 0
-/*----------------------------------------------------------------------------*
- * Face
- *
- * Face support is not directly available in hicn-light, but we can offer such
- * an interface through a combination of listeners and connections. The code
- * starts with some conversion functions between faces/listeners/connections.
- *
- * We also need to make sure that there always exist a (single) listener when
- *a connection is created, and in the hICN face case, that there is a single
- * connection attached to this listener.
- *
- *----------------------------------------------------------------------------*/
-
-/* FACE CREATE */
-
-static int _hcng_face_create(hc_sock_t *socket, hc_face_t *face) {
-#if 0
- hc_listener_t listener;
- hc_listener_t *listener_found;
-
- hc_connection_t connection;
- hc_connection_t *connection_found;
-
- char face_s[MAXSZ_HC_FACE];
- int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face);
- if (rc >= MAXSZ_HC_FACE)
- WARN("[hc_face_create] Unexpected truncation of face string");
- DEBUG("[hc_face_create] face=%s", face_s);
-
- switch (face->face.type) {
- case FACE_TYPE_HICN:
- case FACE_TYPE_TCP:
- case FACE_TYPE_UDP:
- if (hc_face_to_connection(face, &connection, true) < 0) {
- ERROR("[hc_face_create] Could not convert face to connection.");
- return -1;
- }
-
- /* Ensure we have a corresponding local listener */
- if (hc_connection_to_local_listener(&connection, &listener) < 0) {
- ERROR("[hc_face_create] Could not convert face to local listener.");
- return -1;
- }
-
- if (_hcng_listener_get(socket, &listener, &listener_found) < 0) {
- ERROR("[hc_face_create] Could not retrieve listener");
- return -1;
- }
-
- if (!listener_found) {
- /* We need to create the listener if it does not exist */
- if (hc_listener_create(socket, &listener) < 0) {
- ERROR("[hc_face_create] Could not create listener.");
- free(listener_found);
- return -1;
- }
- } else {
- free(listener_found);
- }
-
- /* Create corresponding connection */
- if (_hcng_connection_create(socket, &connection) < 0) {
- ERROR("[hc_face_create] Could not create connection.");
- return -1;
- }
-
- /*
- * Once the connection is created, we need to list all connections
- * and compare with the current one to find the created face ID.
- */
- if (_hcng_connection_get(socket, &connection, &connection_found) < 0) {
- ERROR("[hc_face_create] Could not retrieve connection");
- return -1;
- }
-
- if (!connection_found) {
- ERROR("[hc_face_create] Could not find newly created connection.");
- return -1;
- }
-
- face->id = connection_found->id;
- free(connection_found);
-
- break;
-
- case FACE_TYPE_HICN_LISTENER:
- case FACE_TYPE_TCP_LISTENER:
- case FACE_TYPE_UDP_LISTENER:
- if (hc_face_to_listener(face, &listener) < 0) {
- ERROR("Could not convert face to listener.");
- return -1;
- }
- if (hc_listener_create(socket, &listener) < 0) {
- ERROR("[hc_face_create] Could not create listener.");
- return -1;
- }
- break;
- default:
- ERROR("[hc_face_create] Unknwon face type.");
-
- return -1;
- };
-
-#endif
- return 0;
-}
-
-static int _hcng_face_get(hc_sock_t *socket, hc_face_t *face,
- hc_face_t **face_found) {
-#if 0
- hc_listener_t listener;
- hc_listener_t *listener_found;
-
- hc_connection_t connection;
- hc_connection_t *connection_found;
-
- char face_s[MAXSZ_HC_FACE];
- int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face);
- if (rc >= MAXSZ_HC_FACE)
- WARN("[hc_face_get] Unexpected truncation of face string");
- DEBUG("[hc_face_get] face=%s", face_s);
-
- switch (face->face.type) {
- case FACE_TYPE_HICN:
- case FACE_TYPE_TCP:
- case FACE_TYPE_UDP:
- if (hc_face_to_connection(face, &connection, false) < 0) return -1;
- if (_hcng_connection_get(socket, &connection, &connection_found) < 0)
- return -1;
- if (!connection_found) {
- *face_found = NULL;
- return 0;
- }
- *face_found = malloc(sizeof(hc_face_t));
- hc_connection_to_face(connection_found, *face_found);
- free(connection_found);
- break;
-
- case FACE_TYPE_HICN_LISTENER:
- case FACE_TYPE_TCP_LISTENER:
- case FACE_TYPE_UDP_LISTENER:
- if (hc_face_to_listener(face, &listener) < 0) return -1;
- if (_hcng_listener_get(socket, &listener, &listener_found) < 0) return -1;
- if (!listener_found) {
- *face_found = NULL;
- return 0;
- }
- *face_found = malloc(sizeof(hc_face_t));
- hc_listener_to_face(listener_found, *face_found);
- free(listener_found);
- break;
-
- default:
- return -1;
- }
-
-#endif
- return 0;
-}
-
-/* FACE DELETE */
-
-static int _hcng_face_delete(hc_sock_t *socket, hc_face_t *face,
- uint8_t delete_listener) {
-#if 0
- char face_s[MAXSZ_HC_FACE];
- int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face);
- if (rc >= MAXSZ_HC_FACE)
- WARN("[hc_face_delete] Unexpected truncation of face string");
- DEBUG("[hc_face_delete] face=%s", face_s);
-
- hc_connection_t connection;
- if (hc_face_to_connection(face, &connection, false) < 0) {
- ERROR("[hc_face_delete] Could not convert face to connection.");
- return -1;
- }
-
- if (_hcng_connection_delete(socket, &connection) < 0) {
- ERROR("[hc_face_delete] Error removing connection");
- return -1;
- }
-
- if (!delete_listener) {
- return 0;
- }
-
- /* If this is the last connection attached to the listener, remove it */
-
- hc_data_t *connections;
- hc_listener_t listener = {{0}};
-
- /*
- * Ensure we have a corresponding local listener
- * NOTE: hc_face_to_listener is not appropriate
- */
- if (hc_connection_to_local_listener(&connection, &listener) < 0) {
- ERROR("[hc_face_create] Could not convert face to local listener.");
- return -1;
- }
-#if 1
- /*
- * The name is generated to prepare listener creation, we need it to be
- * empty for deletion. The id should not need to be reset though.
- */
- listener.id = 0;
- memset(listener.name, 0, sizeof(listener.name));
-#endif
- if (_hcng_connection_list(socket, &connections) < 0) {
- ERROR("[hc_face_delete] Error getting the list of listeners");
- return -1;
- }
-
- bool delete = true;
- foreach_connection(c, connections) {
- if ((ip_address_cmp(&c->local_addr, &listener.local_addr, c->family) ==
- 0) &&
- (c->local_port == listener.local_port) &&
- (strcmp(c->interface_name, listener.interface_name) == 0)) {
- delete = false;
- }
- }
-
- if (delete) {
- if (_hcng_listener_delete(socket, &listener) < 0) {
- ERROR("[hc_face_delete] Error removing listener");
- return -1;
- }
- }
-
- hc_data_free(connections);
-
-#endif
- return 0;
-}
-
-/* FACE LIST */
-
-static int _hcng_face_list(hc_sock_t *socket, hc_data_t **pdata) {
-#if 0
- hc_data_t *connection_data;
- hc_face_t face;
-
- DEBUG("[hc_face_list]");
-
- if (_hcng_connection_list(socket, &connection_data) < 0) {
- ERROR("[hc_face_list] Could not list connections.");
- return -1;
- }
-
- hc_data_t *face_data =
- hc_data_create(sizeof(hc_connection_t), sizeof(hc_face_t), NULL);
- foreach_connection(c, connection_data) {
- if (hc_connection_to_face(c, &face) < 0) {
- ERROR("[hc_face_list] Could not convert connection to face.");
- goto ERR;
- }
- hc_data_push(face_data, &face);
- }
-
- *pdata = face_data;
- hc_data_free(connection_data);
- DEBUG("[hc_face_list] done");
- return 0;
-
-ERR:
- hc_data_free(connection_data);
- DEBUG("[hc_face_list] error");
-#endif
- return -1;
-}
-
-static int hc_connection_parse_to_face(void *in, hc_face_t *face) {
- hc_connection_t connection;
-
- if (hcng_connection_parse(in, &connection) < 0) {
- ERROR("[hc_connection_parse_to_face] Could not parse connection");
- return -1;
- }
-
- if (hc_connection_to_face(&connection, face) < 0) {
- ERROR(
- "[hc_connection_parse_to_face] Could not convert connection to "
- "face.");
- return -1;
- }
-
- return 0;
-}
-
-static int _hcng_face_set_admin_state(hc_sock_t *s, const char *conn_id_or_name,
- face_state_t admin_state) {
- return hc_connection_set_admin_state(s, conn_id_or_name, admin_state);
-}
-
-static int _hcng_face_set_priority(hc_sock_t *s, const char *conn_id_or_name,
- uint32_t priority) {
- return hc_connection_set_priority(s, conn_id_or_name, priority);
-}
-
-static int _hcng_face_set_tags(hc_sock_t *s, const char *conn_id_or_name,
- policy_tags_t tags) {
- return hc_connection_set_tags(s, conn_id_or_name, tags);
-}
-
-#endif
diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/stats.h b/ctrl/libhicnctrl/src/modules/hicn_light/stats.h
index e69de29bb..34594bb72 100644
--- a/ctrl/libhicnctrl/src/modules/hicn_light/stats.h
+++ b/ctrl/libhicnctrl/src/modules/hicn_light/stats.h
@@ -0,0 +1,26 @@
+
+#if 0
+
+int hc_stats_snprintf(char *s, size_t size, const hicn_light_stats_t *stats) {
+ return snprintf(
+ s, size,
+ "pkts processed: %u\n\tinterests: %u\n\t"
+ "data: %u\npkts from cache count: %u\npkts no pit count: "
+ "%u\nexpired:\n\t interests: "
+ "%u\n\t data: %u\ninterests aggregated: "
+ "%u\nlru evictions: "
+ "%u\ndropped: "
+ "%u\ninterests retx: "
+ "%u\npit entries: %u\ncs entries: %u",
+ stats->forwarder.countReceived, stats->forwarder.countInterestsReceived,
+ stats->forwarder.countObjectsReceived,
+ stats->forwarder.countInterestsSatisfiedFromStore,
+ stats->forwarder.countDroppedNoReversePath,
+ stats->forwarder.countInterestsExpired, stats->forwarder.countDataExpired,
+ stats->pkt_cache.n_lru_evictions, stats->forwarder.countDropped,
+ stats->forwarder.countInterestsAggregated,
+ stats->forwarder.countInterestsRetransmitted,
+ stats->pkt_cache.n_pit_entries, stats->pkt_cache.n_cs_entries);
+}
+
+#endif