Completo interfaz gráfica para agregar una ruta.
parent
64ca906dd7
commit
a9afc75ba6
|
@ -57,11 +57,14 @@ struct _NIAddRouteDialogPrivate {
|
|||
|
||||
GtkListStore *tables_store;
|
||||
GtkWidget *entry_tabla;
|
||||
GtkWidget *entry_tipo;
|
||||
GtkWidget *entry_protocol;
|
||||
GtkWidget *check_prefsrc, *entry_prefsrc;
|
||||
|
||||
gboolean valid_main_ip, valid_gw;
|
||||
|
||||
gboolean valid_metric;
|
||||
gboolean valid_route_table, valid_route_type;
|
||||
gboolean valid_route_table, valid_route_protocol;
|
||||
gboolean valid_prefsrc;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -79,11 +82,11 @@ enum {
|
|||
};
|
||||
|
||||
enum {
|
||||
COL_ROUTE_TYPE_STR,
|
||||
COL_ROUTE_PROTOCOL_STR,
|
||||
|
||||
COL_ROUTE_TYPE_DESC,
|
||||
COL_ROUTE_PROTOCOL_DESC,
|
||||
|
||||
NUM_ROUTE_TYPE_COLS
|
||||
NUM_ROUTE_PROTOCOL_COLS
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (NIAddRouteDialog, ni_add_route_dialog, GTK_TYPE_DIALOG)
|
||||
|
@ -144,7 +147,7 @@ static void ni_add_route_dialog_update_response (NIAddRouteDialog *dialog) {
|
|||
}*/
|
||||
gboolean res;
|
||||
|
||||
res = dialog->priv->valid_main_ip && dialog->priv->valid_gw && dialog->priv->valid_metric && dialog->priv->valid_route_table && dialog->priv->valid_route_type;
|
||||
res = dialog->priv->valid_main_ip && dialog->priv->valid_gw && dialog->priv->valid_metric && dialog->priv->valid_route_table && dialog->priv->valid_route_protocol && dialog->priv->valid_prefsrc;
|
||||
|
||||
if (res == FALSE) {
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, FALSE);
|
||||
|
@ -240,7 +243,7 @@ static void ni_add_route_dialog_validate_route_table (GtkComboBox *combo, gpoint
|
|||
ni_add_route_dialog_update_response (dialog);
|
||||
}
|
||||
|
||||
static void ni_add_route_dialog_validate_route_type (GtkComboBox *combo, gpointer data) {
|
||||
static void ni_add_route_dialog_validate_route_protocol (GtkComboBox *combo, gpointer data) {
|
||||
NIAddRouteDialog *dialog = NI_ADD_ROUTE_DIALOG (data);
|
||||
const char *texto;
|
||||
int n, g;
|
||||
|
@ -252,16 +255,58 @@ static void ni_add_route_dialog_validate_route_type (GtkComboBox *combo, gpointe
|
|||
|
||||
n = sscanf (texto, "%i%c", &g, &endptr);
|
||||
if (n != 1 || g > 255) {
|
||||
dialog->priv->valid_route_type = FALSE;
|
||||
dialog->priv->valid_route_protocol = FALSE;
|
||||
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, "dialog-warning");
|
||||
} else {
|
||||
dialog->priv->valid_route_type = TRUE;
|
||||
dialog->priv->valid_route_protocol = TRUE;
|
||||
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, NULL);
|
||||
}
|
||||
|
||||
ni_add_route_dialog_update_response (dialog);
|
||||
}
|
||||
|
||||
static void ni_add_route_dialog_validate_prefsrc_ip (GtkEditable *editable, gpointer data) {
|
||||
NIAddRouteDialog *dialog = NI_ADD_ROUTE_DIALOG (data);
|
||||
const gchar *texto;
|
||||
int prefix;
|
||||
|
||||
texto = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry_prefsrc));
|
||||
|
||||
dialog->priv->valid_prefsrc = FALSE;
|
||||
if (dialog->priv->family == AF_INET || dialog->priv->family == AF_UNSPEC) {
|
||||
dialog->priv->valid_prefsrc = ip_valid_ipv4 (texto);
|
||||
if (dialog->priv->valid_prefsrc) {
|
||||
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (dialog->priv->entry_prefsrc), GTK_ENTRY_ICON_SECONDARY, NULL);
|
||||
ni_add_route_dialog_update_response (dialog);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog->priv->family == AF_INET6 || dialog->priv->family == AF_UNSPEC) {
|
||||
dialog->priv->valid_prefsrc = ip_valid_ipv6 (texto);
|
||||
}
|
||||
|
||||
if (dialog->priv->valid_prefsrc) {
|
||||
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (dialog->priv->entry_prefsrc), GTK_ENTRY_ICON_SECONDARY, NULL);
|
||||
} else {
|
||||
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (dialog->priv->entry_prefsrc), GTK_ENTRY_ICON_SECONDARY, "dialog-warning");
|
||||
}
|
||||
ni_add_route_dialog_update_response (dialog);
|
||||
}
|
||||
|
||||
void ni_add_route_dialog_toggle_prefsrc_cb (GtkWidget *widget, gpointer data) {
|
||||
NIAddRouteDialog *dialog = NI_ADD_ROUTE_DIALOG (data);
|
||||
|
||||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
|
||||
gtk_widget_set_sensitive (dialog->priv->entry_prefsrc, TRUE);
|
||||
ni_add_route_dialog_validate_prefsrc_ip (NULL, dialog);
|
||||
} else {
|
||||
gtk_widget_set_sensitive (dialog->priv->entry_prefsrc, FALSE);
|
||||
dialog->priv->valid_prefsrc = TRUE;
|
||||
}
|
||||
ni_add_route_dialog_update_response (dialog);
|
||||
}
|
||||
|
||||
/* Función para renderizar la tabla y el nombre con guion separado */
|
||||
void ni_add_route_dialog_cell_renderer_table_id (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) {
|
||||
const gchar *name;
|
||||
|
@ -532,30 +577,42 @@ static void ni_add_route_dialog_init (NIAddRouteDialog *dialog) {
|
|||
label = gtk_label_new ("Tipo de ruta:");
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
||||
|
||||
store = gtk_list_store_new (NUM_ROUTE_TYPE_COLS, G_TYPE_STRING, G_TYPE_STRING);
|
||||
gtk_list_store_insert_with_values (store, NULL, -1, COL_ROUTE_TYPE_STR, "2", COL_ROUTE_TYPE_DESC, "Kernel", -1);
|
||||
gtk_list_store_insert_with_values (store, NULL, -1, COL_ROUTE_TYPE_STR, "3", COL_ROUTE_TYPE_DESC, "Arranque (Boot)", -1);
|
||||
gtk_list_store_insert_with_values (store, &iter, -1, COL_ROUTE_TYPE_STR, "4", COL_ROUTE_TYPE_DESC, "Estática", -1);
|
||||
gtk_list_store_insert_with_values (store, NULL, -1, COL_ROUTE_TYPE_STR, "16", COL_ROUTE_TYPE_DESC, "Por DHCP", -1);
|
||||
store = gtk_list_store_new (NUM_ROUTE_PROTOCOL_COLS, G_TYPE_STRING, G_TYPE_STRING);
|
||||
gtk_list_store_insert_with_values (store, NULL, -1, COL_ROUTE_PROTOCOL_STR, "2", COL_ROUTE_PROTOCOL_DESC, "Kernel", -1);
|
||||
gtk_list_store_insert_with_values (store, NULL, -1, COL_ROUTE_PROTOCOL_STR, "3", COL_ROUTE_PROTOCOL_DESC, "Arranque (Boot)", -1);
|
||||
gtk_list_store_insert_with_values (store, &iter, -1, COL_ROUTE_PROTOCOL_STR, "4", COL_ROUTE_PROTOCOL_DESC, "Estática", -1);
|
||||
gtk_list_store_insert_with_values (store, NULL, -1, COL_ROUTE_PROTOCOL_STR, "16", COL_ROUTE_PROTOCOL_DESC, "Por DHCP", -1);
|
||||
|
||||
priv->entry_tipo = gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL (store));
|
||||
g_signal_connect (priv->entry_tipo, "changed", G_CALLBACK (ni_add_route_dialog_validate_route_type), dialog);
|
||||
priv->entry_protocol = gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL (store));
|
||||
g_signal_connect (priv->entry_protocol, "changed", G_CALLBACK (ni_add_route_dialog_validate_route_protocol), dialog);
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->entry_tipo), renderer, TRUE);
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->entry_tipo), renderer, "text", COL_ROUTE_TYPE_DESC);
|
||||
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->entry_tipo), COL_ROUTE_TYPE_STR);
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->entry_tipo), &iter);
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->entry_protocol), renderer, TRUE);
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->entry_protocol), renderer, "text", COL_ROUTE_PROTOCOL_DESC);
|
||||
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->entry_protocol), COL_ROUTE_PROTOCOL_STR);
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->entry_protocol), &iter);
|
||||
|
||||
g_object_unref (store);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), priv->entry_tipo, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), priv->entry_protocol, TRUE, TRUE, 0);
|
||||
|
||||
/* TODO: Agregar pref-src en las opciones avanzadas */
|
||||
/* Agregar pref-src en las opciones avanzadas */
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3);
|
||||
|
||||
priv->check_prefsrc = gtk_check_button_new_with_label ("Pref src:");
|
||||
g_signal_connect (priv->check_prefsrc, "toggled", G_CALLBACK (ni_add_route_dialog_toggle_prefsrc_cb), dialog);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), priv->check_prefsrc, FALSE, FALSE, 0);
|
||||
|
||||
priv->entry_prefsrc = gtk_entry_new ();
|
||||
g_signal_connect (priv->entry_prefsrc, "changed", G_CALLBACK (ni_add_route_dialog_validate_prefsrc_ip), dialog);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), priv->entry_prefsrc, TRUE, TRUE, 0);
|
||||
gtk_widget_set_sensitive (priv->entry_prefsrc, FALSE);
|
||||
|
||||
dialog->priv->valid_main_ip = FALSE;
|
||||
dialog->priv->valid_gw = FALSE;
|
||||
dialog->priv->valid_metric = TRUE;
|
||||
dialog->priv->valid_route_table = TRUE;
|
||||
dialog->priv->valid_route_type = TRUE;
|
||||
dialog->priv->valid_route_protocol = TRUE;
|
||||
dialog->priv->valid_prefsrc = TRUE;
|
||||
|
||||
gtk_widget_show_all (container);
|
||||
|
||||
|
@ -669,14 +726,51 @@ int ni_add_route_dialog_get_route_table (NIAddRouteDialog *dialog) {
|
|||
return g_ascii_strtoll (texto, NULL, 10);
|
||||
}
|
||||
|
||||
int ni_add_route_dialog_get_route_type (NIAddRouteDialog *dialog) {
|
||||
int ni_add_route_dialog_get_route_protocol (NIAddRouteDialog *dialog) {
|
||||
const char *texto;
|
||||
|
||||
texto = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (dialog->priv->entry_tipo))));
|
||||
texto = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (dialog->priv->entry_protocol))));
|
||||
|
||||
return g_ascii_strtoll (texto, NULL, 10);
|
||||
}
|
||||
|
||||
gboolean ni_add_route_dialog_has_prefsrc_address (NIAddRouteDialog *dialog) {
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->check_prefsrc));
|
||||
}
|
||||
|
||||
gboolean ni_add_route_dialog_get_prefsrc_address (NIAddRouteDialog *dialog, struct_addr *addr) {
|
||||
gboolean valid;
|
||||
const gchar *texto;
|
||||
|
||||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->check_prefsrc)) == FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
texto = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry_prefsrc));
|
||||
|
||||
if (dialog->priv->family == AF_INET || dialog->priv->family == AF_UNSPEC) {
|
||||
valid = ip_valid_ipv4 (texto);
|
||||
|
||||
if (valid) {
|
||||
inet_pton (AF_INET, texto, addr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog->priv->family == AF_INET6 || dialog->priv->family == AF_UNSPEC) {
|
||||
valid = ip_valid_ipv6 (texto);
|
||||
|
||||
if (valid) {
|
||||
inet_pton (AF_INET6, texto, addr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GtkWidget* ni_add_route_dialog_new (int family) {
|
||||
NIAddRouteDialog *dialog;
|
||||
|
||||
|
|
|
@ -71,7 +71,9 @@ gboolean ni_add_route_dialog_get_destination (NIAddRouteDialog *dialog, struct_a
|
|||
GList *ni_add_route_dialog_get_gateways (NIAddRouteDialog *dialog);
|
||||
int ni_add_route_dialog_get_metric (NIAddRouteDialog *dialog);
|
||||
int ni_add_route_dialog_get_route_table (NIAddRouteDialog *dialog);
|
||||
int ni_add_route_dialog_get_route_type (NIAddRouteDialog *dialog);
|
||||
int ni_add_route_dialog_get_route_protocol (NIAddRouteDialog *dialog);
|
||||
gboolean ni_add_route_dialog_has_prefsrc_address (NIAddRouteDialog *dialog);
|
||||
gboolean ni_add_route_dialog_get_prefsrc_address (NIAddRouteDialog *dialog, struct_addr *addr);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -910,6 +910,87 @@ void ni_client_ask_interface_dhcp_status (NIClient *ni_client, NIInterface *ni_i
|
|||
send (ni_client->priv->client_socket, buffer, 7, 0);
|
||||
}
|
||||
|
||||
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) {
|
||||
unsigned char buffer[80];
|
||||
int family_size;
|
||||
int pos, c;
|
||||
GList *g;
|
||||
NIRouteNH *nexthop;
|
||||
|
||||
if (ni_client->priv->client_socket < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (family == AF_INET) {
|
||||
family_size = sizeof (struct in_addr);
|
||||
} else if (family == AF_INET6) {
|
||||
family_size = sizeof (struct in6_addr);
|
||||
}
|
||||
|
||||
buffer[0] = NET_INADOR_TYPE_COMMAND;
|
||||
buffer[1] = NET_INADOR_COMMAND_ADD_ROUTE;
|
||||
buffer[2] = family;
|
||||
buffer[3] = type;
|
||||
memcpy (&buffer[4], &tabla, 4);
|
||||
|
||||
buffer[8] = prefix;
|
||||
buffer[9] = protocol;
|
||||
buffer[10] = tos;
|
||||
buffer[11] = scope;
|
||||
|
||||
buffer[12] = 0;
|
||||
|
||||
if (has_prefsrc) {
|
||||
buffer[12] |= 0x01;
|
||||
}
|
||||
|
||||
/* La cantidad de gateways que voy a enviar con esta ruta */
|
||||
g = gws;
|
||||
c = 0;
|
||||
while (g != NULL) {
|
||||
c++;
|
||||
g = g->next;
|
||||
}
|
||||
buffer[13] = c;
|
||||
|
||||
memcpy (&buffer[14], &priority, 4);
|
||||
|
||||
memcpy (&buffer[18], dest, family_size);
|
||||
|
||||
pos = 18 + family_size;
|
||||
|
||||
if (has_prefsrc) {
|
||||
memcpy (&buffer[pos], prefsrc, family_size);
|
||||
pos += family_size;
|
||||
}
|
||||
|
||||
g = gws;
|
||||
while (g != NULL) {
|
||||
nexthop = (NIRouteNH *) g->data;
|
||||
|
||||
buffer[pos] = 0;
|
||||
if (nexthop->has_gw) {
|
||||
buffer[pos] |= 0x01;
|
||||
}
|
||||
|
||||
buffer[pos + 1] = nexthop->flags;
|
||||
buffer[pos + 2] = nexthop->weight;
|
||||
buffer[pos + 3] = 0;
|
||||
memcpy (&buffer[pos + 4], &nexthop->out_index, 4);
|
||||
|
||||
if (nexthop->has_gw) {
|
||||
memcpy (&buffer[pos + 8], &nexthop->gw, family_size);
|
||||
pos += (8 + family_size);
|
||||
} else {
|
||||
pos += 8;
|
||||
}
|
||||
|
||||
g = g->next;
|
||||
}
|
||||
|
||||
send (ni_client->priv->client_socket, buffer, pos, 0);
|
||||
}
|
||||
|
||||
static void ni_client_foreach_has_table (gpointer key, gpointer value, gpointer data) {
|
||||
GList **lista = (GList **) data;
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ void ni_client_ask_ip_delete (NIClient *ni_client, NIInterface *ni_interface, NI
|
|||
void ni_client_ask_change_iface_name (NIClient *ni_client, NIInterface *ni_interface, const gchar *new_name);
|
||||
void ni_client_ask_change_iface_mtu (NIClient *ni_client, NIInterface *ni_interface, guint new_mtu);
|
||||
void ni_client_ask_up_down_interface (NIClient *ni_client, NIInterface *ni_interface, gboolean is_up);
|
||||
|
||||
void ni_client_ask_create_bridge (NIClient *ni_client, const gchar *name);
|
||||
|
||||
GList *ni_client_get_list_interfaces (NIClient *ni_client);
|
||||
|
@ -94,6 +95,8 @@ 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);
|
||||
|
||||
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_interface_clear_master (NIClient *ni_client, NIInterface *ni_interface);
|
||||
void ni_client_ask_interface_set_master (NIClient *ni_client, NIInterface *ni_interface, NIInterface *master);
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@ struct _NIInterfaceChooserDialog {
|
|||
NIInterfaceChooserDialogPrivate *priv;
|
||||
};
|
||||
|
||||
enum {
|
||||
enum NIInterfaceChooserOrder {
|
||||
NI_INTERFACE_CHOOSER_ORDER_INDEX,
|
||||
NI_INTERFACE_CHOOSER_ORDER_NAME,
|
||||
NI_INTERFACE_CHOOSER_ORDER_TYPE
|
||||
} NIInterfaceChooserOrder;
|
||||
};
|
||||
|
||||
/*
|
||||
* Method definitions.
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <linux/if_addr.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
|
||||
#include "ni-window-route.h"
|
||||
|
||||
|
@ -142,14 +143,17 @@ static void ni_window_route_updated_route_cb (NIRoute *ni_route, gpointer data)
|
|||
|
||||
static void ni_window_route_route_added_cb (NIWindowRoute *window_route, NIRoute *ni_route) {
|
||||
int family, prefix;
|
||||
char buffer_ip[256], buffer[512];
|
||||
char buffer_ip[256], buffer[512], buffer2[512];
|
||||
const struct_addr *dest;
|
||||
uint32_t table;
|
||||
guint priority;
|
||||
struct _NIWindowRouteSearchTable for_search;
|
||||
int route_type;
|
||||
char *route_type_desc;
|
||||
|
||||
family = ni_route_get_family (ni_route);
|
||||
dest = ni_route_get_dest (ni_route);
|
||||
route_type = ni_route_get_route_type (ni_route);
|
||||
prefix = ni_route_get_prefix (ni_route);
|
||||
table = ni_route_get_table (ni_route);
|
||||
priority = ni_route_get_priority (ni_route);
|
||||
|
@ -158,6 +162,28 @@ static void ni_window_route_route_added_cb (NIWindowRoute *window_route, NIRoute
|
|||
return;
|
||||
}
|
||||
|
||||
route_type_desc = NULL;
|
||||
/* Preparar el tipo de ruta */
|
||||
switch (route_type) {
|
||||
case RTN_UNICAST:
|
||||
//route_type_desc = "";
|
||||
break;
|
||||
case RTN_BROADCAST:
|
||||
route_type_desc = "[Broadcast]";
|
||||
break;
|
||||
case RTN_LOCAL:
|
||||
route_type_desc = "[Local]";
|
||||
break;
|
||||
case RTN_BLACKHOLE:
|
||||
route_type_desc = "[Blackhole]";
|
||||
break;
|
||||
case RTN_MULTICAST:
|
||||
route_type_desc = "[Multicast]";
|
||||
break;
|
||||
default:
|
||||
route_type_desc = "[Other...]";
|
||||
}
|
||||
|
||||
/* Preparar el dest-gw */
|
||||
inet_ntop (family, dest, buffer_ip, sizeof (buffer_ip));
|
||||
if (family == AF_INET && prefix == 32) {
|
||||
|
@ -167,6 +193,11 @@ static void ni_window_route_route_added_cb (NIWindowRoute *window_route, NIRoute
|
|||
} else {
|
||||
snprintf (buffer, sizeof (buffer), "%s/%i", buffer_ip, prefix);
|
||||
}
|
||||
if (route_type_desc != NULL) {
|
||||
snprintf (buffer2, sizeof (buffer2), "%s %s", buffer, route_type_desc);
|
||||
} else {
|
||||
strncpy (buffer2, buffer, sizeof (buffer2));
|
||||
}
|
||||
|
||||
/* Preparar el pref-src, si lo tiene */
|
||||
buffer_ip[0] = 0;
|
||||
|
@ -187,7 +218,7 @@ static void ni_window_route_route_added_cb (NIWindowRoute *window_route, NIRoute
|
|||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
gtk_list_store_insert_with_values (window_route->priv->routes_store, NULL, -1, ROUTE_STORE_TABLE, table, ROUTE_STORE_COL_DST_GW, buffer2, 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);
|
||||
}
|
||||
|
@ -434,9 +465,16 @@ static void ni_window_route_add_route_button_add_cb (GtkWidget *button, gpointer
|
|||
gint response;
|
||||
NIClient *ni_client;
|
||||
GList *gws;
|
||||
int metrica, tabla, tipo;
|
||||
int metrica, tabla, protocol;
|
||||
struct_addr destino;
|
||||
gboolean has_
|
||||
int prefix;
|
||||
gboolean good;
|
||||
NIRouteNH *next_hop;
|
||||
struct NIAddRouteDialogGW *next_hop_dialog;
|
||||
GList *new_list, *g;
|
||||
gboolean has_prefsrc;
|
||||
struct_addr prefsrc;
|
||||
|
||||
dialog = ni_add_route_dialog_new (window_route->priv->family);
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window_route));
|
||||
|
@ -447,35 +485,42 @@ static void ni_window_route_add_route_button_add_cb (GtkWidget *button, gpointer
|
|||
|
||||
if (response == GTK_RESPONSE_OK) {
|
||||
/* Mandar la ip al network-inador */
|
||||
ni_client = ni_interface_get_client (window_route->priv->ni_interface);
|
||||
ni_client = window_route->priv->ni_client;
|
||||
|
||||
good = ni_add_route_dialog_get_destination (NI_ADD_ROUTE_DIALOG (dialog), &destino, &prefix);
|
||||
tabla = ni_add_route_dialog_get_route_table (NI_ADD_ROUTE_DIALOG (dialog));
|
||||
metrica = ni_add_route_dialog_get_metric (NI_ADD_ROUTE_DIALOG (dialog));
|
||||
protocol = ni_add_route_dialog_get_route_protocol (NI_ADD_ROUTE_DIALOG (dialog));
|
||||
|
||||
has_prefsrc = ni_add_route_dialog_has_prefsrc_address (NI_ADD_ROUTE_DIALOG (dialog));
|
||||
if (has_prefsrc) {
|
||||
ni_add_route_dialog_get_prefsrc_address (NI_ADD_ROUTE_DIALOG (dialog), &prefsrc);
|
||||
}
|
||||
gws = ni_add_route_dialog_get_gateways (NI_ADD_ROUTE_DIALOG (dialog));
|
||||
|
||||
if (gws != NULL) {
|
||||
/* Reacomodar los next-hop del cuadro de dialogo en las otras estructuras */
|
||||
new_list = NULL;
|
||||
g = gws;
|
||||
while (g != NULL) {
|
||||
next_hop_dialog = (struct NIAddRouteDialogGW *) g->data;
|
||||
|
||||
next_hop = (NIRouteNH *) g_malloc (sizeof (NIRouteNH));
|
||||
memset (next_hop, 0, sizeof (NIRouteNH));
|
||||
|
||||
next_hop->has_gw = 1;
|
||||
memcpy (&next_hop->gw, &next_hop_dialog->addr, sizeof (next_hop->gw));
|
||||
|
||||
next_hop->weight = next_hop_dialog->metric;
|
||||
|
||||
new_list = g_list_append (new_list, next_hop);
|
||||
g = g->next;
|
||||
}
|
||||
|
||||
//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)
|
||||
ni_client_ask_route_new (ni_client, window_route->priv->family, prefix, &destino, RTN_UNICAST, tabla, protocol, 0, 0, has_prefsrc, &prefsrc, metrica, new_list);
|
||||
|
||||
g_list_free_full (gws, g_free);
|
||||
#if 0
|
||||
ni_ip_add_dialog_get_address (NI_IP_ADD_DIALOG (dialog), &addr, &prefix);
|
||||
has_p2p = ni_ip_add_dialog_has_p2p_address (NI_IP_ADD_DIALOG (dialog));
|
||||
if (has_p2p) {
|
||||
memcpy (&p2p_addr, &addr, sizeof (p2p_addr));
|
||||
ni_ip_add_dialog_get_p2p_address (NI_IP_ADD_DIALOG (dialog), &addr);
|
||||
}
|
||||
|
||||
flags |= IFA_F_PERMANENT;
|
||||
if (ni_ip_add_dialog_get_noprefix (NI_IP_ADD_DIALOG (dialog))) {
|
||||
flags |= IFA_F_NOPREFIXROUTE;
|
||||
}
|
||||
//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) {
|
||||
|
||||
/* TODO: Pedir los tiempos de validez de la interfaz */
|
||||
guint32 cacheinfo[2];
|
||||
cacheinfo[0] = 60;
|
||||
cacheinfo[1] = 60;
|
||||
ni_client_ask_ip_new (ni_client, window_iface->priv->ni_interface, family, prefix, &addr, flags, 0, has_p2p, (has_p2p ? &p2p_addr : NULL), FALSE, NULL, cacheinfo);
|
||||
#endif
|
||||
g_list_free_full (new_list, g_free);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
|
|
@ -1254,12 +1254,12 @@ void _manager_execute_add_route (ManagerClientInfo *manager_client, unsigned cha
|
|||
nh->nh_weight = buffer[pos + 2];
|
||||
memcpy (&nh->out_index, &buffer[pos + 4], 4);
|
||||
|
||||
pos += 8;
|
||||
|
||||
if (buffer[pos] & 0x01) {
|
||||
/* Tiene GW */
|
||||
memcpy (&nh->gw, &buffer[pos], family_size);
|
||||
pos += family_size;
|
||||
memcpy (&nh->gw, &buffer[pos + 8], family_size);
|
||||
pos += (8 + family_size);
|
||||
} else {
|
||||
pos += 8;
|
||||
}
|
||||
route.nexthops = g_list_append (route.nexthops, nh);
|
||||
g--;
|
||||
|
|
Loading…
Reference in New Issue