diff --git a/client-gtk/ni-add-route-dialog.c b/client-gtk/ni-add-route-dialog.c index 144203c..8e546fa 100644 --- a/client-gtk/ni-add-route-dialog.c +++ b/client-gtk/ni-add-route-dialog.c @@ -45,6 +45,7 @@ struct _NIAddRouteGW { struct _NIAddRouteDialogPrivate { int family; + NIClient *ni_client; GtkWidget *destination; GtkWidget *button_add; @@ -70,6 +71,8 @@ struct _NIAddRouteDialogPrivate { enum { PROP_ROUTE_FAMILY = 1, + PROP_NI_CLIENT, + N_PROPERTIES }; @@ -320,6 +323,44 @@ void ni_add_route_dialog_cell_renderer_table_id (GtkCellLayout *cell_layout, Gtk } } +static void ni_add_route_dialog_constructed (GObject *obj) { + GObjectClass *parent_class = G_OBJECT_CLASS (g_type_class_peek (GTK_TYPE_DIALOG)); + NIAddRouteDialog *dialog = NI_ADD_ROUTE_DIALOG (obj); + GList *g, *route_table_names; + struct _NIClientRouteTable *rtable; + char buffer[256]; + + parent_class->constructed (obj); + + if (dialog->priv->ni_client == NULL) return; + + /* Conectar la señal de tabla de ruteo agregada */ + //g_signal_connect (window_route->priv->ni_client, "new-route", G_CALLBACK (ni_window_interface_new_route_cb), window_route); + + route_table_names = ni_client_get_route_tables_names (dialog->priv->ni_client); + for (g = route_table_names; g != NULL; g = g->next) { + rtable = (struct _NIClientRouteTable *) g->data; + + if (rtable->table == 0) continue; + snprintf (buffer, sizeof (buffer), "%i", rtable->table); + gtk_list_store_insert_with_values (dialog->priv->tables_store, NULL, -1, COL_TABLE_ID, rtable->table, COL_TABLE_ID_STR, buffer, COL_TABLE_NAME, rtable->name, -1); + } +} + +static void ni_add_route_dialog_dispose (GObject *obj) { + NIAddRouteDialog *dialog; + GObjectClass *parent_class = G_OBJECT_CLASS (g_type_class_peek (GTK_TYPE_DIALOG)); + + dialog = NI_ADD_ROUTE_DIALOG (obj); + + if (dialog->priv->ni_client != NULL) { + g_object_unref (dialog->priv->ni_client); + dialog->priv->ni_client = NULL; + } + + parent_class->dispose (obj); +} + static void ni_add_route_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NIAddRouteDialog *dialog = NI_ADD_ROUTE_DIALOG (object); g_return_if_fail (NI_IS_ADD_ROUTE_DIALOG (object)); @@ -335,6 +376,10 @@ static void ni_add_route_dialog_set_property (GObject *object, guint prop_id, co gtk_entry_set_placeholder_text (GTK_ENTRY (dialog->priv->destination), "2001:db8::1/64"); } break; + case PROP_NI_CLIENT: + dialog->priv->ni_client = NI_CLIENT (g_value_get_object (value)); + g_object_ref (dialog->priv->ni_client); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -348,6 +393,9 @@ static void ni_add_route_dialog_get_property (GObject *object, guint prop_id, GV case PROP_ROUTE_FAMILY: g_value_set_uint (value, dialog->priv->family); break; + case PROP_NI_CLIENT: + g_value_set_object (value, dialog->priv->ni_client); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -361,6 +409,8 @@ static void ni_add_route_dialog_class_init (NIAddRouteDialogClass *klass) { object_class->set_property = ni_add_route_dialog_set_property; object_class->get_property = ni_add_route_dialog_get_property; + object_class->constructed = ni_add_route_dialog_constructed; + object_class->dispose = ni_add_route_dialog_dispose; obj_properties[PROP_ROUTE_FAMILY] = g_param_spec_uint ( "family", @@ -369,6 +419,13 @@ static void ni_add_route_dialog_class_init (NIAddRouteDialogClass *klass) { 0, 10, AF_UNSPEC, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + obj_properties[PROP_NI_CLIENT] = g_param_spec_object ( + "ni-client", + "Network Inador Client", + "The client object", + NI_TYPE_CLIENT, + G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); + g_object_class_install_properties (object_class, N_PROPERTIES, obj_properties); } @@ -554,10 +611,10 @@ static void ni_add_route_dialog_init (NIAddRouteDialog *dialog) { gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); priv->tables_store = gtk_list_store_new (NUM_TABLE_STORE_COLS, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING); - /* TODO: Conseguir esta información desde el NetworkInador */ + gtk_list_store_insert_with_values (priv->tables_store, &iter, -1, COL_TABLE_ID, 0, COL_TABLE_ID_STR, "0", COL_TABLE_NAME, "Por defecto", -1); - gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, COL_TABLE_ID, 254, COL_TABLE_ID_STR, "254", COL_TABLE_NAME, "Main", -1); - gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, COL_TABLE_ID, 255, COL_TABLE_ID_STR, "255", COL_TABLE_NAME, "Local", -1); + + priv->entry_tabla = gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL (priv->tables_store)); g_signal_connect (priv->entry_tabla, "changed", G_CALLBACK (ni_add_route_dialog_validate_route_table), dialog); @@ -771,10 +828,10 @@ gboolean ni_add_route_dialog_get_prefsrc_address (NIAddRouteDialog *dialog, stru return FALSE; } -GtkWidget* ni_add_route_dialog_new (int family) { +GtkWidget* ni_add_route_dialog_new (int family, NIClient *ni_client) { NIAddRouteDialog *dialog; - dialog = g_object_new (NI_TYPE_ADD_ROUTE_DIALOG, "family", family, NULL); + dialog = g_object_new (NI_TYPE_ADD_ROUTE_DIALOG, "family", family, "ni-client", ni_client, NULL); return GTK_WIDGET (dialog); } diff --git a/client-gtk/ni-add-route-dialog.h b/client-gtk/ni-add-route-dialog.h index 403e53f..7d15749 100644 --- a/client-gtk/ni-add-route-dialog.h +++ b/client-gtk/ni-add-route-dialog.h @@ -65,7 +65,7 @@ struct NIAddRouteDialogGW { /* * Method definitions. */ -GtkWidget* ni_add_route_dialog_new (int family); +GtkWidget* ni_add_route_dialog_new (int family, NIClient *ni_client); gboolean ni_add_route_dialog_get_destination (NIAddRouteDialog *dialog, struct_addr *addr, int *prefix); GList *ni_add_route_dialog_get_gateways (NIAddRouteDialog *dialog); diff --git a/client-gtk/ni-client.c b/client-gtk/ni-client.c index f5e8efd..6629636 100644 --- a/client-gtk/ni-client.c +++ b/client-gtk/ni-client.c @@ -54,6 +54,7 @@ struct _NIClientPrivate { GHashTable *interfaces; GList *routes_v4, *routes_v6; + GList *route_tables_names; guint source; guint events; }; @@ -75,6 +76,9 @@ enum { NEW_ROUTE, DELETE_ROUTE, + NEW_ROUTE_TABLE, + DELETE_ROUTE_TABLE, + LAST_SIGNAL }; @@ -186,11 +190,36 @@ static void ni_client_class_init (NIClientClass *klass) { 1, NI_TYPE_ROUTE); + signals[NEW_ROUTE_TABLE] = g_signal_new ("new-route-table", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (NIClientClass, new_route_table), + NULL, + NULL, + _ni_marshal_VOID__UINT_STRING, + G_TYPE_NONE, + 2, + G_TYPE_UINT, + G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); + + signals[NEW_ROUTE_TABLE] = g_signal_new ("delete-route-table", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (NIClientClass, delete_route_table), + NULL, + NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, + 1, + G_TYPE_UINT); + klass->data_response = ni_client_data_read; klass->new_interface = NULL; klass->delete_interface = NULL; klass->new_route = NULL; klass->delete_route = NULL; + klass->new_route_table = NULL; + klass->delete_route_table = NULL; } static void ni_client_process_interface_response (NIClient *ni_client, gpointer data, guint size) { @@ -379,6 +408,27 @@ static void ni_client_process_route_del_response (NIClient *ni_client, gpointer g_object_unref (ni_route); } +static void ni_client_process_route_table_name_response (NIClient *ni_client, gpointer data, guint size) { + unsigned char *buffer = (unsigned char *) data; + uint8_t name_len; + uint32_t tabla; + struct _NIClientRouteTable *rtable; + + name_len = buffer[6]; + + memcpy (&tabla, &buffer[2], 4); + + rtable = g_malloc (sizeof (struct _NIClientRouteTable)); + + rtable->table = tabla; + memcpy (rtable->name, &buffer[7], name_len); + rtable->name[name_len] = 0; + + ni_client->priv->route_tables_names = g_list_append (ni_client->priv->route_tables_names, rtable); + + g_signal_emit (ni_client, signals[NEW_ROUTE_TABLE], 0, rtable->table, rtable->name); +} + static gboolean ni_client_data_read (NIClient *ni_client, gpointer data, guint size) { unsigned char *buffer = (unsigned char *) data; uint32_t index; @@ -437,6 +487,14 @@ static gboolean ni_client_data_read (NIClient *ni_client, gpointer data, guint s case NET_INADOR_EVENT_ROUTE_ADDED: /* TODO: Revisar si la ruta existe, entonces, en teoría, es una actualización */ ni_client_process_route_response (ni_client, data, size); + return FALSE; + break; + case NET_INADOR_EVENT_ROUTE_TABLE_ADDED: + + return FALSE; + break; + case NET_INADOR_EVENT_ROUTE_TABLE_REMOVED: + return FALSE; break; } @@ -472,6 +530,10 @@ static gboolean ni_client_data_read (NIClient *ni_client, gpointer data, guint s ni_client_process_route_response (ni_client, data, size); return FALSE; break; + case NET_INADOR_RESPONSE_ROUTE_TABLE: + ni_client_process_route_table_name_response (ni_client, data, size); + return FALSE; + break; } } @@ -576,6 +638,7 @@ static void ni_client_init (NIClient *ni_client) { priv->socket_path = NULL; priv->routes_v4 = NULL; priv->routes_v6 = NULL; + priv->route_tables_names = NULL; priv->source = 0; priv->events = NET_INADOR_EVENT_MASK_INTERFACES | NET_INADOR_EVENT_MASK_IP | NET_INADOR_EVENT_MASK_DHCP_STATUS | NET_INADOR_EVENT_MASK_ROUTES; @@ -624,6 +687,20 @@ void ni_client_ask_routes (NIClient *ni_client) { send (ni_client->priv->client_socket, buffer, 7, 0); } +void ni_client_ask_route_tables_names (NIClient *ni_client) { + unsigned char buffer[8]; + + if (ni_client->priv->client_socket < 0) { + return; + } + + buffer[0] = NET_INADOR_TYPE_COMMAND; + buffer[1] = NET_INADOR_COMMAND_LIST_ROUTE_TABLES; + memset (&buffer[2], 0, 4); + + send (ni_client->priv->client_socket, buffer, 6, 0); +} + void ni_client_ask_ip_new (NIClient *ni_client, NIInterface *ni_interface, int family, int prefix, struct_addr *addr, uint32_t flags, unsigned char scope, int has_local, struct_addr *local_addr, int has_brd, struct_addr *brd_addr, uint32_t *cacheinfo) { unsigned char buffer[80]; uint32_t index; @@ -1062,6 +1139,12 @@ GList *ni_client_get_routes_v6 (NIClient *ni_client) { return ni_client->priv->routes_v6; } +GList *ni_client_get_route_tables_names (NIClient *ni_client) { + g_return_val_if_fail (NI_IS_CLIENT (ni_client), NULL); + + return ni_client->priv->route_tables_names; +} + gboolean ni_client_connect (NIClient *ni_client) { int s, ret; struct sockaddr_un path_dest; @@ -1101,6 +1184,9 @@ gboolean ni_client_connect (NIClient *ni_client) { /* Pedir un listado de rutas */ ni_client_ask_routes (ni_client); + + /* Pedir un listado de los nombres de las tablas */ + ni_client_ask_route_tables_names (ni_client); } void ni_client_disconnect (NIClient *ni_client) { diff --git a/client-gtk/ni-client.h b/client-gtk/ni-client.h index cee121e..4c3fc3d 100644 --- a/client-gtk/ni-client.h +++ b/client-gtk/ni-client.h @@ -62,6 +62,8 @@ struct _NIClientClass { void (*delete_interface) (NIClient *ni_client, gpointer ni_interface); void (*new_route) (NIClient *ni_client, gpointer ni_route); void (*delete_route) (NIClient *ni_client, gpointer ni_route); + void (*new_route_table) (NIClient *ni_client, guint table_id, const gchar *table_name); + void (*delete_route_table) (NIClient *ni_client, guint table_id); }; struct _NIClient { @@ -73,6 +75,11 @@ struct _NIClient { typedef struct _NIInterface NIInterface; typedef struct _NIRoute NIRoute; +struct _NIClientRouteTable { + guint table; + char name[256]; +}; + /* * Method definitions. */ @@ -95,10 +102,13 @@ NIInterface *ni_client_get_interface_by_index (NIClient *ni_client, guint index) GList *ni_client_get_routes_v4 (NIClient *ni_client); GList *ni_client_get_routes_v6 (NIClient *ni_client); +GList *ni_client_get_route_tables_names (NIClient *ni_client); void ni_client_ask_route_new (NIClient *ni_client, int family, int prefix, struct_addr *dest, int type, uint32_t tabla, int protocol, int tos, int scope, int has_prefsrc, struct_addr *prefsrc, uint32_t priority, GList *gws); void ni_client_ask_route_del (NIClient *ni_client, NIRoute *route); +void ni_client_ask_route_tables_names (NIClient *ni_client); + void ni_client_ask_interface_clear_master (NIClient *ni_client, NIInterface *ni_interface); void ni_client_ask_interface_set_master (NIClient *ni_client, NIInterface *ni_interface, NIInterface *master); diff --git a/client-gtk/ni-marshal.list b/client-gtk/ni-marshal.list index 9432be0..9a6a30c 100644 --- a/client-gtk/ni-marshal.list +++ b/client-gtk/ni-marshal.list @@ -1,2 +1,3 @@ BOOLEAN:POINTER,UINT VOID:UINT,UINT +VOID:UINT,STRING diff --git a/client-gtk/ni-window-route.c b/client-gtk/ni-window-route.c index 3aa258f..0726097 100644 --- a/client-gtk/ni-window-route.c +++ b/client-gtk/ni-window-route.c @@ -84,8 +84,6 @@ enum { TABLE_STORE_TABLE, TABLE_STORE_NAME, - TABLE_STORE_IS_NEW, - NUM_TABLE_STORE_COLS }; @@ -109,6 +107,7 @@ static gboolean ni_window_route_foreach_tables_search_id (GtkTreeModel *tree_mod static gboolean ni_window_route_foreach_routes_search_route (GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *iter, gpointer data); static void ni_window_interface_new_route_cb (NIClient *ni_client, NIRoute *ni_route, gpointer data); static void ni_window_interface_delete_route_cb (NIClient *ni_client, NIRoute *ni_route, gpointer data); +static void ni_window_route_table_name_added_cb (NIClient *ni_client, guint table_id, const gchar *table_name, gpointer data); static void ni_window_route_updated_route_cb (NIRoute *ni_route, gpointer data) { NIWindowRoute *window_route = NI_WINDOW_ROUTE (data); @@ -219,40 +218,47 @@ static void ni_window_route_route_added_cb (NIWindowRoute *window_route, NIRoute } /* Revisar que la tabla exista, si la tabla no existe, la creamos en el menú de la lista de tablas */ - for_search.found = FALSE; - for_search.tabla = table; - - gtk_tree_model_foreach (GTK_TREE_MODEL (window_route->priv->tables_store), ni_window_route_foreach_tables_search_id, &for_search); - - if (for_search.found == FALSE) { - /* Insertar el valor en el list store de las tablas */ - gtk_list_store_insert_with_values (window_route->priv->tables_store, NULL, -1, TABLE_STORE_TABLE, table, TABLE_STORE_NAME, NULL, TABLE_STORE_IS_NEW, FALSE, -1); - } + ni_window_route_table_name_added_cb (window_route->priv->ni_client, table, NULL, window_route); gtk_list_store_insert_with_values (window_route->priv->routes_store, NULL, -1, ROUTE_STORE_TABLE, table, ROUTE_STORE_COL_DST_GW, buffer, ROUTE_STORE_COL_METRIC, priority, ROUTE_STORE_COL_PREFSRC, buffer_ip, ROUTE_STORE_COL_OBJECT, ni_route, -1); g_signal_connect (ni_route, "updated", G_CALLBACK (ni_window_route_updated_route_cb), window_route); } +static void ni_window_route_table_name_added_cb (NIClient *ni_client, guint table_id, const gchar *table_name, gpointer data) { + NIWindowRoute *window_route = NI_WINDOW_ROUTE (data); + struct _NIWindowRouteSearchTable for_search; + GtkTreeIter iter; + + /* Localizar el valor previo de la tabla, para regresar el combo */ + for_search.found = FALSE; + for_search.tabla = table_id; + + gtk_tree_model_foreach (GTK_TREE_MODEL (window_route->priv->tables_store), ni_window_route_foreach_tables_search_id, &for_search); + if (for_search.found) { + + if (table_name != NULL) { + gtk_list_store_set (window_route->priv->tables_store, &for_search.iter, TABLE_STORE_NAME, table_name, -1); + } + } else { + gtk_list_store_insert_with_values (window_route->priv->tables_store, &iter, -1, TABLE_STORE_TABLE, table_id, TABLE_STORE_NAME, table_name, -1); + } +} + /* Función para renderizar la tabla y el nombre con guion separado */ void ni_window_route_cell_renderer_table_id (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { uint32_t tabla; const gchar *name; - gboolean new; char buffer[1024]; - gtk_tree_model_get (tree_model, iter, TABLE_STORE_TABLE, &tabla, TABLE_STORE_NAME, &name, TABLE_STORE_IS_NEW, &new, -1); + gtk_tree_model_get (tree_model, iter, TABLE_STORE_TABLE, &tabla, TABLE_STORE_NAME, &name, -1); - if (new == FALSE) { - if (name == NULL) { - g_snprintf (buffer, sizeof (buffer), "%i - (Sin nombre)", tabla); - } else { - g_snprintf (buffer, sizeof (buffer), "%i - %s", tabla, name); - } - g_object_set (cell, "text", buffer, NULL); + if (name == NULL) { + g_snprintf (buffer, sizeof (buffer), "%i - (Sin nombre)", tabla); } else { - g_object_set (cell, "text", "Nueva tabla...", NULL); + g_snprintf (buffer, sizeof (buffer), "%i - %s", tabla, name); } + g_object_set (cell, "text", buffer, NULL); } /* Función para renderizar la gateway */ @@ -304,8 +310,10 @@ static gboolean ni_window_route_delete_event (GtkWidget *widget, GdkEventAny *ev static void ni_window_route_constructed (GObject *obj) { GObjectClass *parent_class = G_OBJECT_CLASS (g_type_class_peek (GTK_TYPE_WINDOW)); NIWindowRoute *window_route = NI_WINDOW_ROUTE (obj); - const GList *route_list = NULL, *g; + const GList *route_list = NULL, *g, *route_table_names; NIRoute *ni_route; + GtkTreeIter iter; + struct _NIClientRouteTable *rtable; parent_class->constructed (obj); @@ -332,6 +340,14 @@ static void ni_window_route_constructed (GObject *obj) { ni_window_route_route_added_cb (window_route, ni_route); } + + route_table_names = ni_client_get_route_tables_names (window_route->priv->ni_client); + for (g = route_table_names; g != NULL; g = g->next) { + rtable = (struct _NIClientRouteTable *) g->data; + + if (rtable->table == 0) continue; + ni_window_route_table_name_added_cb (window_route->priv->ni_client, rtable->table, rtable->name, window_route); + } } static void ni_window_route_dispose (GObject *obj) { @@ -340,8 +356,10 @@ static void ni_window_route_dispose (GObject *obj) { window_route = NI_WINDOW_ROUTE (obj); - g_object_unref (window_route->priv->ni_client); - window_route->priv->ni_client = NULL; + if (window_route->priv->ni_client != NULL) { + g_object_unref (window_route->priv->ni_client); + window_route->priv->ni_client = NULL; + } parent_class->dispose (obj); } @@ -359,10 +377,8 @@ static void ni_window_route_change_filter_table_id (NIWindowRoute *window_route, static gboolean ni_window_route_foreach_tables_search_id (GtkTreeModel *tree_model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { struct _NIWindowRouteSearchTable *for_search = (struct _NIWindowRouteSearchTable *) data; uint32_t tabla; - gboolean is_new; - gtk_tree_model_get (tree_model, iter, TABLE_STORE_TABLE, &tabla, TABLE_STORE_IS_NEW, &is_new, -1); - if (is_new) return FALSE; + gtk_tree_model_get (tree_model, iter, TABLE_STORE_TABLE, &tabla, -1); if (tabla == for_search->tabla) { for_search->found = TRUE; @@ -392,16 +408,8 @@ static gint ni_window_route_sort_tables_func (GtkTreeModel *tree_model, GtkTreeI uint32_t tabla_a, tabla_b; gboolean is_new_a, is_new_b; - gtk_tree_model_get (tree_model, a, TABLE_STORE_TABLE, &tabla_a, TABLE_STORE_IS_NEW, &is_new_a, -1); - gtk_tree_model_get (tree_model, b, TABLE_STORE_TABLE, &tabla_b, TABLE_STORE_IS_NEW, &is_new_b, -1); - - if (is_new_a) { - return 1; - } - - if (is_new_b) { - return -1; - } + gtk_tree_model_get (tree_model, a, TABLE_STORE_TABLE, &tabla_a, -1); + gtk_tree_model_get (tree_model, b, TABLE_STORE_TABLE, &tabla_b, -1); return tabla_a - tabla_b; } @@ -414,8 +422,9 @@ static void ni_window_route_changed_combo_table_cb (GtkWidget *combo, gpointer d struct _NIWindowRouteSearchTable for_search; gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter); - gtk_tree_model_get (GTK_TREE_MODEL (window_route->priv->tables_store), &iter, TABLE_STORE_TABLE, &tabla, TABLE_STORE_IS_NEW, &is_new, -1); + gtk_tree_model_get (GTK_TREE_MODEL (window_route->priv->tables_store), &iter, TABLE_STORE_TABLE, &tabla, -1); + #if 0 if (is_new) { /* TODO: Presentar el cuadro de dialogo de creación de nueva tabla */ @@ -430,9 +439,10 @@ static void ni_window_route_changed_combo_table_cb (GtkWidget *combo, gpointer d gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), NULL); } } else { + #endif /* Aplicar el nuevo filtro */ ni_window_route_change_filter_table_id (window_route, tabla); - } + //} } gboolean ni_window_route_tree_filter_routes_func (GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { @@ -512,7 +522,7 @@ static void ni_window_route_add_route_button_add_cb (GtkWidget *button, gpointer gboolean has_prefsrc; struct_addr prefsrc; - dialog = ni_add_route_dialog_new (window_route->priv->family); + dialog = ni_add_route_dialog_new (window_route->priv->family, window_route->priv->ni_client); gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window_route)); @@ -713,12 +723,12 @@ static void ni_window_route_init (NIWindowRoute *window_route) { gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, FALSE, 0); - priv->tables_store = gtk_list_store_new (NUM_TABLE_STORE_COLS, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_BOOLEAN); + priv->tables_store = gtk_list_store_new (NUM_TABLE_STORE_COLS, G_TYPE_UINT, G_TYPE_STRING); /* TODO: Recuperar esta informacion de las tablas de ruteo desde el NetworkInador */ - gtk_list_store_insert_with_values (priv->tables_store, &iter, -1, TABLE_STORE_TABLE, 0, TABLE_STORE_NAME, "Todas", TABLE_STORE_IS_NEW, FALSE, -1); - gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, TABLE_STORE_TABLE, 254, TABLE_STORE_NAME, "Main", TABLE_STORE_IS_NEW, FALSE, -1); + gtk_list_store_insert_with_values (priv->tables_store, &iter, -1, TABLE_STORE_TABLE, 0, TABLE_STORE_NAME, "Todas", -1); + /*gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, TABLE_STORE_TABLE, 254, TABLE_STORE_NAME, "Main", TABLE_STORE_IS_NEW, FALSE, -1); gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, TABLE_STORE_TABLE, 255, TABLE_STORE_NAME, "Local", TABLE_STORE_IS_NEW, FALSE, -1); - gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, TABLE_STORE_TABLE, 0, TABLE_STORE_NAME, NULL, TABLE_STORE_IS_NEW, TRUE, -1); + gtk_list_store_insert_with_values (priv->tables_store, NULL, -1, TABLE_STORE_TABLE, 0, TABLE_STORE_NAME, NULL, TABLE_STORE_IS_NEW, TRUE, -1);*/ /* Mantener ordenadas las tablas */ gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (priv->tables_store), ni_window_route_sort_tables_func, NULL, NULL); diff --git a/src/manager.c b/src/manager.c index ec91887..af33c4c 100644 --- a/src/manager.c +++ b/src/manager.c @@ -1348,6 +1348,18 @@ void _manager_send_route_table (ManagerClientInfo *manager_client, RouteTable *r send (manager_client->fd, buffer, 7 + name_len, 0); } +void _manager_send_route_table_del (ManagerClientInfo *manager_client, RouteTable *rtable) { + unsigned char buffer[80]; + int name_len; + + buffer[0] = NET_INADOR_TYPE_EVENT; + buffer[1] = NET_INADOR_EVENT_ROUTE_TABLE_REMOVED; + + memcpy (&buffer[2], &rtable->table, 4); + + send (manager_client->fd, buffer, 6, 0); +} + void _manager_send_list_route_tables (ManagerClientInfo *manager_client, unsigned char *buffer, int buffer_len) { GList *g; RouteTable *rtable; @@ -1360,7 +1372,7 @@ void _manager_send_list_route_tables (ManagerClientInfo *manager_client, unsigne memcpy (&table, &buffer[2], 4); - for (g = manager_client->manager->handle->route_v4_tables; g != NULL; g = g->next) { + for (g = manager_client->manager->handle->route_tables_names; g != NULL; g = g->next) { rtable = (RouteTable *) g->data; if (table != 0 && rtable->table != table) continue; @@ -1667,6 +1679,42 @@ void manager_send_event_route_update (NetworkInadorHandle *handle, Route *route) manager_send_event_route_add (handle, route); } +void manager_send_event_route_table_del (NetworkInadorHandle *handle, RouteTable *rtable) { + char buffer_ip[1024]; + printf ("___ MANAGER ___ Informando tabla de ruteo eliminada: %s %i\n", rtable->name, rtable->table); + GList *g; + ManagerClientInfo *manager_client; + + if (handle->manager == NULL) return; + + for (g = handle->manager->connected_client_list; g != NULL; g = g->next) { + manager_client = (ManagerClientInfo *) g->data; + + if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_ROUTE_TABLES) { + printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd); + _manager_send_route_table_del (manager_client, rtable); + } + } +} + +void manager_send_event_route_table_add (NetworkInadorHandle *handle, RouteTable *rtable) { + char buffer_ip[1024]; + printf ("___ MANAGER ___ Informando tabla de ruteo agregada: %s %i\n", rtable->name, rtable->table); + GList *g; + ManagerClientInfo *manager_client; + + if (handle->manager == NULL) return; + + for (g = handle->manager->connected_client_list; g != NULL; g = g->next) { + manager_client = (ManagerClientInfo *) g->data; + + if (manager_client->wanted_events & NET_INADOR_EVENT_MASK_ROUTE_TABLES) { + printf ("___ MANAGER ___ Informando a la conexión (%i)\n", manager_client->fd); + _manager_send_route_table (manager_client, rtable, TRUE); + } + } +} + int manager_init (NetworkInadorHandle *handle) { NetworkInadorManager *manager; struct sockaddr_un socket_name; diff --git a/src/manager.h b/src/manager.h index 1759da7..291b5e7 100644 --- a/src/manager.h +++ b/src/manager.h @@ -37,6 +37,8 @@ void manager_send_event_dhcp_change (NetworkInadorHandle *handle, InterfaceDHCPC void manager_send_event_route_add (NetworkInadorHandle *handle, Route *route); void manager_send_event_route_del (NetworkInadorHandle *handle, Route *route); void manager_send_event_route_update (NetworkInadorHandle *handle, Route *route); +void manager_send_event_route_table_del (NetworkInadorHandle *handle, RouteTable *rtable); +void manager_send_event_route_table_add (NetworkInadorHandle *handle, RouteTable *rtable); #endif /* __MANAGER_H__ */ diff --git a/src/network-inador-manager.h b/src/network-inador-manager.h index d59ce0b..d57da0a 100644 --- a/src/network-inador-manager.h +++ b/src/network-inador-manager.h @@ -14,6 +14,7 @@ enum { #define NET_INADOR_EVENT_MASK_IP 0x02 #define NET_INADOR_EVENT_MASK_DHCP_STATUS 0x04 #define NET_INADOR_EVENT_MASK_ROUTES 0x08 +#define NET_INADOR_EVENT_MASK_ROUTE_TABLES 0x10 enum { NET_INADOR_COMMAND_LIST_IFACES = 1, diff --git a/src/routes.c b/src/routes.c index 67068d3..ae5c904 100644 --- a/src/routes.c +++ b/src/routes.c @@ -742,11 +742,18 @@ gint _routes_table_find_by_number (gconstpointer left, gconstpointer right) { void _routes_table_parse_file (NetworkInadorHandle *handle, FILE *fd) { GList *g; + int ret; RouteTable *rtable, temp_table; char buffer[2048]; - while (fgets (buffer, sizeof (buffer), fd), feof (fd) != 0) { - sscanf (buffer, "%d %s", &(temp_table.table), temp_table.name); + while (fgets (buffer, sizeof (buffer), fd), feof (fd) == 0) { + if (buffer[0] == '#') continue; /* Ignorar las lineas con comentarios */ + + ret = sscanf (buffer, "%d %s", &(temp_table.table), temp_table.name); + + if (ret < 2) { + continue; + } g = g_list_find_custom (handle->route_tables_names, &temp_table, _routes_table_find_by_number); @@ -765,6 +772,8 @@ void _routes_table_parse_file (NetworkInadorHandle *handle, FILE *fd) { } /* En cualquier caso actualizar el nombre */ strncpy (rtable->name, temp_table.name, sizeof (rtable->name)); + + handle->route_tables_names = g_list_append (handle->route_tables_names, rtable); } } @@ -833,7 +842,7 @@ void routes_tables_read (NetworkInadorHandle *handle, int do_notify) { handle->route_tables_names = g_list_delete_link (handle->route_tables_names, g); if (do_notify) { - /* TODO: Notificar al manager que esta tabla fué eliminada */ + manager_send_event_route_table_del (handle, rtable); } g_free (rtable); @@ -848,7 +857,7 @@ void routes_tables_read (NetworkInadorHandle *handle, int do_notify) { if (rtable->was_new) { if (do_notify) { - /* TODO: Notificar al manager que esta tabla fué agregada */ + manager_send_event_route_table_add (handle, rtable); } rtable->was_new = 0; }