aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/facemgr
diff options
context:
space:
mode:
Diffstat (limited to 'ctrl/facemgr')
-rw-r--r--ctrl/facemgr/includes/hicn/facemgr/facelet.h1
-rw-r--r--ctrl/facemgr/src/api.c116
-rw-r--r--ctrl/facemgr/src/facelet.c45
-rw-r--r--ctrl/facemgr/src/interfaces/android_utility/android_utility.c2
-rw-r--r--ctrl/facemgr/src/interfaces/netlink/netlink.c10
-rw-r--r--ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c4
-rw-r--r--ctrl/facemgr/src/interfaces/updown/updown.c2
7 files changed, 81 insertions, 99 deletions
diff --git a/ctrl/facemgr/includes/hicn/facemgr/facelet.h b/ctrl/facemgr/includes/hicn/facemgr/facelet.h
index 355af551d..a963c50a7 100644
--- a/ctrl/facemgr/includes/hicn/facemgr/facelet.h
+++ b/ctrl/facemgr/includes/hicn/facemgr/facelet.h
@@ -271,6 +271,7 @@ int facelet_merge(facelet_t * facelet, facelet_t * facelet_to_merge);
facelet_status_t facelet_get_status(const facelet_t * facelet);
void facelet_set_status(facelet_t * facelet, facelet_status_t status);
+void facelet_set_attr_clean(facelet_t * facelet);
void facelet_set_error(facelet_t * facelet, facelet_error_reason_t reason);
void facelet_unset_error(facelet_t * facelet);
diff --git a/ctrl/facemgr/src/api.c b/ctrl/facemgr/src/api.c
index d9bba43a9..7fbabbe72 100644
--- a/ctrl/facemgr/src/api.c
+++ b/ctrl/facemgr/src/api.c
@@ -303,7 +303,8 @@ facemgr_set_config(facemgr_t * facemgr, facemgr_cfg_t * cfg)
} else {
for (unsigned i = 0; i < n; i++) {
facelet_t * facelet = facelet_dup(facelet_array[i]);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_status(facelet, FACELET_STATUS_UNDEFINED);
+ facelet_set_attr_clean(facelet);
if (facelet_array_add(facemgr->static_facelets, facelet)) {
ERROR("[facemgr_finalize] Could not add static facelet to face manager");
}
@@ -1087,14 +1088,13 @@ facemgr_process_facelet(facemgr_t * facemgr, facelet_t * facelet)
goto ERR;
}
+#if 0
if (facelet_set_remove(facemgr->facelet_cache, facelet, NULL) < 0) {
ERROR("[facemgr_process_facelet] Could not remove deleted facelet from cache");
goto ERR;
}
facelet_free(facelet);
- goto END;
-
-#if 0
+#else
/* This works assuming the call to hicn-light is blocking */
DEBUG("[facemgr_process_facelet] Cleaning cached data");
facelet_unset_local_addr(facelet);
@@ -1126,7 +1126,6 @@ facemgr_process_facelet(facemgr_t * facemgr, facelet_t * facelet)
}
facelet_unset_error(facelet);
-END:
return 0;
ERR:
@@ -1207,11 +1206,15 @@ facemgr_start_reattempts(facemgr_t * facemgr)
int
facemgr_process_facelet_create(facemgr_t * facemgr, facelet_t * facelet)
{
+ char facelet_s[MAXSZ_FACELET];
+ facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet);
+ DEBUG("[facemgr_process_facelet_create] %s", facelet_s);
switch(facelet_get_status(facelet)) {
case FACELET_STATUS_UNCERTAIN:
case FACELET_STATUS_INCOMPLETE:
case FACELET_STATUS_CREATE:
/* No change */
+ DEBUG("[facemgr_process_facelet_create] UNCHANGED STATUS");
break;
case FACELET_STATUS_UPDATE:
case FACELET_STATUS_DELETE:
@@ -1222,6 +1225,7 @@ facemgr_process_facelet_create(facemgr_t * facemgr, facelet_t * facelet)
* correctly if the face is still present.
* TODO What if some fields have been updated ?
*/
+ DEBUG("[facemgr_process_facelet_create] SET STATUS TO CREATE");
facelet_set_status(facelet, FACELET_STATUS_CREATE);
break;
case FACELET_STATUS_CLEAN:
@@ -1230,6 +1234,7 @@ facemgr_process_facelet_create(facemgr_t * facemgr, facelet_t * facelet)
* We should have nothing to do unless some fields have
* been updated.
*/
+ DEBUG("[facemgr_process_facelet_create] NOTHING TO DO");
break;
case FACELET_STATUS_DOWN:
@@ -1239,6 +1244,7 @@ facemgr_process_facelet_create(facemgr_t * facemgr, facelet_t * facelet)
* missing information, and proceed to face creation.
* Rule changes should be handled separately.
*/
+ DEBUG("[facemgr_process_facelet_create] SET STATUS TO INCOMPLETE");
facelet_set_status(facelet, FACELET_STATUS_INCOMPLETE);
break;
case FACELET_STATUS_UNDEFINED:
@@ -1247,6 +1253,8 @@ facemgr_process_facelet_create(facemgr_t * facemgr, facelet_t * facelet)
return -1;
}
+
+ DEBUG("[facemgr_process_facelet_create] Processing facelet");
if (facemgr_process_facelet(facemgr, facelet) < 0) {
ERROR("[facemgr_process_facelet_create] Error processing facelet");
return -1;
@@ -1432,14 +1440,19 @@ facemgr_process_facelet_get(facemgr_t * facemgr, facelet_t * facelet)
int
facemgr_process_facelet_update(facemgr_t * facemgr, facelet_t * facelet)
{
+ char facelet_s[MAXSZ_FACELET];
+ facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet);
+ DEBUG("[facemgr_process_facelet_update] %s", facelet_s);
switch(facelet_get_status(facelet)) {
case FACELET_STATUS_UNCERTAIN:
case FACELET_STATUS_INCOMPLETE:
case FACELET_STATUS_CREATE:
case FACELET_STATUS_UPDATE:
/* No change */
+ DEBUG("[facemgr_process_facelet_update] UNCHANGED STATUS");
break;
case FACELET_STATUS_CLEAN:
+ DEBUG("[facemgr_process_facelet_update] SET STATUS TO UPDATE");
facelet_set_status(facelet, FACELET_STATUS_UPDATE);
break;
case FACELET_STATUS_DOWN:
@@ -1447,6 +1460,7 @@ facemgr_process_facelet_update(facemgr_t * facemgr, facelet_t * facelet)
case FACELET_STATUS_DELETED:
case FACELET_STATUS_IGNORED:
/* Reconsider face creation in light of new information */
+ DEBUG("[facemgr_process_facelet_update] SET STATUS TO UNCERTAIN");
facelet_set_status(facelet, FACELET_STATUS_UNCERTAIN);
break;
case FACELET_STATUS_UNDEFINED:
@@ -1455,6 +1469,7 @@ facemgr_process_facelet_update(facemgr_t * facemgr, facelet_t * facelet)
return -1;
}
+ DEBUG("[facemgr_process_facelet_update] Processing facelet");
if (facemgr_process_facelet(facemgr, facelet) < 0) {
ERROR("[facemgr_process_facelet_update] Error processing facelet");
return -1;
@@ -1478,77 +1493,34 @@ facemgr_process_facelet_delete(facemgr_t * facemgr, facelet_t * facelet)
case FACELET_STATUS_INCOMPLETE:
case FACELET_STATUS_IGNORED:
case FACELET_STATUS_DOWN:
- if (facelet_set_remove(facemgr->facelet_cache, facelet, NULL) < 0) {
- ERROR("[facemgr_process_facelet] Could not remove deleted facelet from cache");
- return -1;
- }
-
- facelet_free(facelet);
- return 0;
-#if 0
- facelet_unset_local_addr(facelet);
- facelet_unset_local_port(facelet);
- facelet_unset_remote_addr(facelet);
- facelet_unset_remote_port(facelet);
- facelet_unset_bj_done(facelet);
-#ifdef WITH_ANDROID_UTILITY
- facelet_unset_au_done(facelet);
-#endif /* WITH_ANDROID_UTILITY */
+ case FACELET_STATUS_CREATE:
+ /* Face has not been created */
+ facelet_unset_error(facelet);
facelet_set_status(facelet, FACELET_STATUS_DELETED);
-#endif
break;
- case FACELET_STATUS_CREATE:
+
case FACELET_STATUS_UPDATE:
case FACELET_STATUS_CLEAN:
facelet_set_status(facelet, FACELET_STATUS_DELETE);
+ if (facemgr_process_facelet(facemgr, facelet) < 0) {
+ ERROR("[facemgr_process_facelet_delete] Error processing facelet");
+ return -1;
+ }
break;
+
case FACELET_STATUS_DELETE:
case FACELET_STATUS_DELETED:
/* Nothing to do */
- DEBUG("%s\n", facelet_status_str[facelet_get_status(facelet)]);
break;
+
case FACELET_STATUS_UNDEFINED:
case FACELET_STATUS_N:
ERROR("[facemgr_process_facelet_delete] Unexpected facelet status");
return -1;
}
- if (facemgr_process_facelet(facemgr, facelet) < 0) {
- ERROR("[facemgr_process_facelet_delete] Error processing facelet");
- return -1;
- }
-
- return 0;
-}
-
-#if 0
-int facemgr_process_facelet_first_time(facemgr_t * facemgr, facelet_t * facelet)
-{
- assert(facelet);
-
- facelet_set_status(facelet, FACELET_STATUS_UNCERTAIN);
- char facelet_s[MAXSZ_FACELET];
- facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet);
- if (facelet_set_add(facemgr->facelet_cache, facelet) < 0) {
- ERROR("[facemgr_process_facelet_first_time] Error adding facelet to cache");
- goto ERR_CACHE;
- }
-
- if (facemgr_process_facelet_create(facemgr, facelet) < 0) {
- ERROR("[facemgr_process_facelet_first_time] Error processing facelet CREATE event");
- goto ERR_CREATE;
- }
-
return 0;
-
-ERR_CREATE:
- if (facelet_set_remove(facemgr->facelet_cache, facelet, NULL) < 0) {
- ERROR("[facemgr_process_facelet_first_time] Error removing failed facelet from cache");
- }
-ERR_CACHE:
- return -1;
}
-#endif
int facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet);
@@ -1563,10 +1535,10 @@ facemgr_process_facelet_create_no_family(facemgr_t * facemgr, facelet_t * facele
ERROR("[facemgr_process_facelet_create_no_family] Error allocating default IPv4 face");
} else {
facelet_set_family(facelet_v4, AF_INET);
- facelet_set_status(facelet_v4, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet_v4);
if (facemgr_on_event(facemgr, facelet_v4) < 0) {
ERROR("[facemgr_process_facelet_create_no_family] Error creating default IPv4 face");
- facelet_free(facelet_v4);
+ //facelet_free(facelet_v4);
}
}
@@ -1576,10 +1548,10 @@ facemgr_process_facelet_create_no_family(facemgr_t * facemgr, facelet_t * facele
ERROR("[facemgr_process_facelet_create_no_family] Error allocating default IPv6 face");
} else {
facelet_set_family(facelet_v6, AF_INET6);
- facelet_set_status(facelet_v6, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet_v6);
if (facemgr_on_event(facemgr, facelet_v6) < 0) {
ERROR("[facemgr_process_facelet_create_no_family] Error creating default IPv6 face");
- facelet_free(facelet_v6);
+ //facelet_free(facelet_v6);
}
}
@@ -1620,11 +1592,12 @@ facemgr_process_facelet_create_no_family(facemgr_t * facemgr, facelet_t * facele
}
/* The id must be different than 0 */
facelet_set_id(facelet_new, ++facemgr->cur_static_id);
- facelet_set_status(facelet_new, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet_new);
+ facelet_set_status(facelet, FACELET_STATUS_UNDEFINED);
if (facemgr_on_event(facemgr, facelet_new) < 0) {
ERROR("[facemgr_process_facelet_create_no_family] Error creating default IPv6 face");
- facelet_free(facelet_new);
+ //facelet_free(facelet_new);
}
}
}
@@ -1668,6 +1641,10 @@ facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet_in)
facelet_t ** cached_facelets = NULL;
assert(facelet_in);
+ if (facelet_get_status(facelet_in) == FACELET_STATUS_UNDEFINED) {
+ facelet_set_status(facelet_in, FACELET_STATUS_UNCERTAIN);
+ }
+
int n = facelet_cache_lookup(facemgr->facelet_cache, facelet_in, &cached_facelets);
if (n < 0) {
ERROR("[facemgr_on_event] Error during cache lookup");
@@ -1687,6 +1664,7 @@ facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet_in)
* assignment
*/
DEBUG("[facemgr_on_event] CREATE NEW %s", facelet_s);
+
if (!facelet_has_family(facelet_in)) {
facemgr_assign_face_type(facemgr, facelet_in);
if (facemgr_process_facelet_create_no_family(facemgr, facelet_in) < 0) {
@@ -1696,8 +1674,6 @@ facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet_in)
goto DUMP_CACHE;
}
- facelet_set_status(facelet_in, FACELET_STATUS_UNCERTAIN);
-
if (facelet_set_add(facemgr->facelet_cache, facelet_in) < 0) {
ERROR("[facemgr_on_event] Error adding facelet to cache");
goto ERR;
@@ -1715,7 +1691,7 @@ facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet_in)
case FACELET_EVENT_GET:
/* Insert new facelet in cached */
- DEBUG("[facemgr_on_event] GET NEW %s", facelet_s);
+ //DEBUG("[facemgr_on_event] GET NEW %s", facelet_s);
rc = facemgr_process_facelet_get(facemgr, facelet_in);
if (rc == 0)
remove_facelet = false;
@@ -1794,7 +1770,7 @@ facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet_in)
continue;
}
- if (facemgr_process_facelet_create(facemgr, facelet_in) < 0) {
+ if (facemgr_process_facelet_create(facemgr, facelet) < 0) {
ERROR("[facemgr_on_event] Error processing facelet CREATE event");
ret = -1;
}
@@ -1806,8 +1782,8 @@ facemgr_on_event(facemgr_t * facemgr, facelet_t * facelet_in)
* This happens due to polling of the forwarder (or when it
* restarts)
*/
- DEBUG("[facemgr_on_event] GET EXISTING %s", facelet_old_s);
- DEBUG(" WITH %s", facelet_s);
+ //DEBUG("[facemgr_on_event] GET EXISTING %s", facelet_old_s);
+ //DEBUG(" WITH %s", facelet_s);
//ERROR("[facemgr_on_event] GET event for a face that already exists...");
dump = false;
continue;
diff --git a/ctrl/facemgr/src/facelet.c b/ctrl/facemgr/src/facelet.c
index 2308f3b6d..cce7fe611 100644
--- a/ctrl/facemgr/src/facelet.c
+++ b/ctrl/facemgr/src/facelet.c
@@ -433,21 +433,8 @@ facelet_dup(const facelet_t * current_facelet)
return facelet;
ERR_ROUTE:
- {
- /* Free all routes */
- hicn_route_t ** new_route_array;
- int n = route_set_get_array(facelet->routes, &new_route_array);
- if (n < 0) {
- ERROR("[facelet_free] Error getting route set associated to facelet");
- } else {
- for (unsigned i = 0; i < n; i++) {
- hicn_route_t * new_route = new_route_array[i];
- hicn_route_free(new_route);
- }
- }
- free(route_array);
+ /* This will free all routes */
facelet_free(facelet);
- }
ERR_CREATE:
return NULL;
}
@@ -563,6 +550,14 @@ facelet_match(const facelet_t * facelet, const facelet_t * facelet_match)
#define _(TYPE, NAME) MATCH_ATTRIBUTE(TYPE, NAME);
foreach_facelet_attr
#undef _
+
+#if 0
+ char facelet_s[MAXSZ_FACELET];
+ facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet_match);
+ DEBUG("MATCHED FACELET %s", facelet_s);
+ facelet_snprintf(facelet_s, MAXSZ_FACELET, facelet);
+ DEBUG(" WITH %s", facelet_s);
+#endif
return true;
}
@@ -721,8 +716,15 @@ int facelet_merge(facelet_t * facelet, facelet_t * facelet_to_merge)
ERROR("[facelet_free] Error getting route set associated to facelet");
} else {
for (unsigned i = 0; i < n; i++) {
- hicn_route_t * route = hicn_route_dup(route_array[i]);
- route_set_add(facelet->routes, route);
+ hicn_route_t * route = route_array[i];
+ hicn_route_t * route_found = NULL;
+ if (route_set_get(facelet->routes, route, &route_found) < 0) {
+ ERROR("Error searching for route");
+ continue;
+ }
+ if (route_found)
+ continue;
+ route_set_add(facelet->routes, hicn_route_dup(route));
}
}
free(route_array);
@@ -903,6 +905,12 @@ facelet_get_status(const facelet_t * facelet)
return facelet->status;
}
+void
+facelet_set_status(facelet_t * facelet, facelet_status_t status)
+{
+ facelet->status = status;
+}
+
#define SET_ATTR_STATUS_CLEAN(TYPE, NAME) \
do { \
if (facelet->NAME ## _status == FACELET_ATTR_STATUS_DIRTY) \
@@ -910,14 +918,11 @@ do { \
} while (0)
void
-facelet_set_status(facelet_t * facelet, facelet_status_t status)
+facelet_set_attr_clean(facelet_t * facelet)
{
- if (status == FACELET_STATUS_CLEAN) {
#define _(TYPE, NAME) SET_ATTR_STATUS_CLEAN(TYPE, NAME);
foreach_facelet_attr
#undef _
- }
- facelet->status = status;
}
void
diff --git a/ctrl/facemgr/src/interfaces/android_utility/android_utility.c b/ctrl/facemgr/src/interfaces/android_utility/android_utility.c
index 47d3cd106..8eca6c2b0 100644
--- a/ctrl/facemgr/src/interfaces/android_utility/android_utility.c
+++ b/ctrl/facemgr/src/interfaces/android_utility/android_utility.c
@@ -119,7 +119,7 @@ int au_on_event(interface_t * interface, facelet_t * facelet)
facelet_t * facelet_new = facelet_create();
facelet_set_netdevice(facelet_new, netdevice);
- facelet_set_status(facelet_new, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet_new);
facelet_set_netdevice_type(facelet_new, netdevice_type);
facelet_set_event(facelet_new, FACELET_EVENT_UPDATE);
diff --git a/ctrl/facemgr/src/interfaces/netlink/netlink.c b/ctrl/facemgr/src/interfaces/netlink/netlink.c
index 4d92f2511..b57a4e480 100644
--- a/ctrl/facemgr/src/interfaces/netlink/netlink.c
+++ b/ctrl/facemgr/src/interfaces/netlink/netlink.c
@@ -428,7 +428,7 @@ int nl_callback(interface_t * interface, int fd, void * unused)
DEBUG("Interface %s: address was removed", interface_name);
if (facelet) {
facelet_set_event(facelet, FACELET_EVENT_SET_DOWN);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet);
interface_raise_event(interface, facelet);
}
break;
@@ -450,7 +450,7 @@ int nl_callback(interface_t * interface, int fd, void * unused)
if (facelet) {
facelet_set_event(facelet, FACELET_EVENT_UPDATE);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet);
interface_raise_event(interface, facelet);
}
break;
@@ -474,7 +474,7 @@ int nl_callback(interface_t * interface, int fd, void * unused)
break;
facelet_set_event(facelet, FACELET_EVENT_DELETE);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet);
interface_raise_event(interface, facelet);
break;
@@ -505,7 +505,7 @@ int nl_callback(interface_t * interface, int fd, void * unused)
if (up && running) {
facelet_set_event(facelet, FACELET_EVENT_CREATE);
//facelet_set_family(facelet, AF_INET);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet);
interface_raise_event(interface, facelet);
#if 0
@@ -520,7 +520,7 @@ int nl_callback(interface_t * interface, int fd, void * unused)
} else {
#if 1
facelet_set_event(facelet, FACELET_EVENT_SET_DOWN);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet);
interface_raise_event(interface, facelet);
#else
facelet_free(facelet);
diff --git a/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c b/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c
index 5452c0e85..76538185f 100644
--- a/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c
+++ b/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c
@@ -115,8 +115,8 @@ int priority_controller_callback(interface_t * interface, int fd, void * unused)
facelet_t * facelet_c = facelet_create();
facelet_set_netdevice_type(facelet_w, NETDEVICE_TYPE_WIFI);
facelet_set_netdevice_type(facelet_c, NETDEVICE_TYPE_CELLULAR);
- facelet_set_status(facelet_w, FACELET_STATUS_CLEAN);
- facelet_set_status(facelet_c, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet_w);
+ facelet_set_attr_clean(facelet_c);
switch(buf[0]) {
case '\0':
facelet_set_priority(facelet_w, 0);
diff --git a/ctrl/facemgr/src/interfaces/updown/updown.c b/ctrl/facemgr/src/interfaces/updown/updown.c
index b804cdac1..7d305a5cd 100644
--- a/ctrl/facemgr/src/interfaces/updown/updown.c
+++ b/ctrl/facemgr/src/interfaces/updown/updown.c
@@ -118,7 +118,7 @@ int updown_callback(interface_t * interface, int fd, void * unused)
/* Raise facelet update event */
facelet_t * facelet = facelet_create();
facelet_set_netdevice_type(facelet, NETDEVICE_TYPE_WIFI); //CELLULAR);
- facelet_set_status(facelet, FACELET_STATUS_CLEAN);
+ facelet_set_attr_clean(facelet);
switch(buf[0]) {
case '\0':
facelet_set_admin_state(facelet, FACE_STATE_DOWN);