static void on_disconnect(netc_t *netc) { jlog(L_DEBUG, "disconnect"); struct session *session = NULL; struct mac_list *mac_itr = NULL; session = netc->ext_ptr; if (session == NULL) { return; } if (session->state == SESSION_STATE_NOT_AUTHED) { session_free(session); return; } /* If the context is still valid, update the node in it. */ if (session->context != NULL) { linkst_disjoin(session->context->linkst, session->id); while (session->mac_list != NULL) { mac_itr = session->mac_list; session->mac_list = mac_itr->next; ftable_erase(session->context->ftable, mac_itr->mac_addr); free(mac_itr); } ctable_erase(session->context->ctable, session->node_info->uuid); context_del_session(session->context, session); } transmit_node_connectinfo(ConnectState_disconnected, session->ip, session->cert_name); session_free(session); return; }
int del_node(json_t *jmsg) { char *network_uuid; char *uuid; json_t *node; struct session *session; struct vnetwork *vnet; if ((node = json_object_get(jmsg, "node")) == NULL) { jlog(L_ERROR, "json_object_get failed"); return -1; } if (json_unpack(node, "{s:s}", "uuid", &uuid) == -1) { jlog(L_ERROR, "json_unpack failed"); return -1; } if (json_unpack(node, "{s:s}", "networkuuid", &network_uuid) == -1) { jlog(L_ERROR, "json_unpack failed"); return -1; } if ((vnet = vnetwork_lookup(network_uuid)) == NULL) { jlog(L_ERROR, "context_lookup failed"); return -1; } /* remove the node from the access table */ ctable_erase(vnet->atable, uuid); /* if the node is connected, mark it to be purged */ if ((session = ctable_find(vnet->ctable, uuid)) != NULL) { session->state = SESSION_STATE_PURGE; } return 0; }