zones: fix up formatting and simplify some functions

This commit is contained in:
Dan Williams
2011-11-02 21:34:49 -05:00
parent 62cd6ece48
commit 04ecdb8187
3 changed files with 48 additions and 69 deletions

View File

@@ -25,8 +25,7 @@
#include "nm-firewall-manager.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
#include "nm-dbus-glib-types.h"
#define NM_FIREWALL_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_FIREWALL_MANAGER, \
@@ -62,7 +61,7 @@ nm_firewall_manager_add_to_zone (NMFirewallManager *self,
DBusGProxyCall * call = NULL;
if (nm_firewall_manager_available (self)) {
nm_log_dbg (LOGD_DEVICE, "telling firewall to add ip_iface: %s to zone: %s", ip_iface, zone );
nm_log_dbg (LOGD_DEVICE, "(%s) adding to firewall zone: %s", ip_iface, zone );
call = dbus_g_proxy_begin_call_with_timeout (priv->proxy,
"AddInterface",
callback,
@@ -70,12 +69,11 @@ nm_firewall_manager_add_to_zone (NMFirewallManager *self,
NULL, /* destroy callback_data */
10000, /* timeout */
G_TYPE_STRING, ip_iface,
G_TYPE_STRING, zone,
DBUS_TYPE_G_STRING_VALUE_HASHTABLE, NULL, /* a{sv}:options */
G_TYPE_STRING, zone ? zone : "",
DBUS_TYPE_G_MAP_OF_VARIANT, NULL, /* a{sv}:options */
G_TYPE_INVALID);
}
else {
nm_log_dbg (LOGD_DEVICE, "firewall isn't running.");
} else {
nm_log_dbg (LOGD_DEVICE, "Firewall zone add skipped because firewall isn't running");
callback (NULL, NULL, callback_data);
}
@@ -125,10 +123,10 @@ name_owner_changed (NMDBusManager *dbus_mgr,
return;
if (!old_owner_good && new_owner_good) {
nm_log_info (LOGD_DEVICE, "firewall started");
nm_log_dbg (LOGD_DEVICE, "firewall started");
set_running (self, TRUE);
} else if (old_owner_good && !new_owner_good) {
nm_log_info (LOGD_DEVICE, "firewall stopped");
nm_log_dbg (LOGD_DEVICE, "firewall stopped");
set_running (self, FALSE);
}
}

View File

@@ -2443,14 +2443,8 @@ ip4_add_to_zone_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_da
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);
/*
* TODO: do we need to do anything else here ?
*/
} else {
/* ip_iface was correctly added to zone by firewall */
/* FIXME: fail the device activation? */
}
} else {
/* firewall isn't running or we couldn't determine zone */
}
activation_source_schedule (self, nm_device_activate_ip4_config_commit, AF_INET);
@@ -2464,8 +2458,8 @@ void
nm_device_activate_schedule_ip4_config_result (NMDevice *self, NMIP4Config *config)
{
NMDevicePrivate *priv;
NMConnection *connection;
NMSettingConnection *s_con;
NMConnection *connection = NULL;
NMSettingConnection *s_con = NULL;
g_return_if_fail (NM_IS_DEVICE (self));
@@ -2583,19 +2577,13 @@ ip6_add_to_zone_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_da
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);
/*
* TODO: do we need to do anything else here ?
*/
} else {
/* ip_iface was correctly added to zone by firewall */
/* FIXME: fail the device activation? */
}
} else {
/* firewall isn't running or we couldn't determine zone */
}
activation_source_schedule (self, nm_device_activate_ip6_config_commit, AF_INET6);
nm_log_info (LOGD_DEVICE | LOGD_IP4,
nm_log_info (LOGD_DEVICE | LOGD_IP6,
"Activation (%s) Stage 5 of 5 (IPv6 Commit) scheduled...",
nm_device_get_iface (self));
}
@@ -2604,8 +2592,8 @@ void
nm_device_activate_schedule_ip6_config_result (NMDevice *self, NMIP6Config *config)
{
NMDevicePrivate *priv;
NMConnection *connection;
NMSettingConnection *s_con;
NMConnection *connection = NULL;
NMSettingConnection *s_con = NULL;
g_return_if_fail (NM_IS_DEVICE (self));

View File

@@ -971,13 +971,10 @@ reset_connections_retries (gpointer user_data)
static NMConnection *
get_device_connection (NMDevice *device)
{
NMActRequest *req;
NMActRequest *req = NULL;
req = nm_device_get_act_request (device);
if (!req)
return NULL;
return nm_act_request_get_connection (req);
return req ? nm_act_request_get_connection (req) : NULL;
}
static void
@@ -1207,20 +1204,21 @@ add_to_zone_cb (DBusGProxy *proxy,
DBusGProxyCall *call_id,
void *user_data)
{
NMDevice *device = NM_DEVICE (user_data);
GError *error = NULL;
if (!proxy || !call_id)
return;
if (proxy && call_id) {
if (!dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) {
nm_log_warn (LOGD_DEVICE, "adding iface to zone failed: (%d) %s",
nm_log_warn (LOGD_DEVICE, "(%s) addition to firewall zone failed: (%d) %s",
nm_device_get_ip_iface (device),
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);
/* TODO: do we need to do anything else here ? */
/* FIXME: fail connection since firewall zone add failed? */
}
}
g_object_unref (device);
}
static void
@@ -1228,23 +1226,18 @@ inform_firewall_about_zone (NMPolicy * policy,
NMConnection *connection)
{
NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
const char *zone = nm_setting_connection_get_zone(s_con);
const char *uuid = nm_setting_connection_get_uuid(s_con);
GSList *iter, *devices;
if (!zone)
return;
devices = nm_manager_get_devices (policy->manager);
for (iter = devices; iter; iter = g_slist_next (iter)) {
NMDevice *dev = NM_DEVICE (iter->data);
NMConnection *dev_connection = get_device_connection (dev);
if (g_strcmp0 (uuid, nm_connection_get_uuid (dev_connection)) == 0) {
if (get_device_connection (dev) == connection) {
nm_firewall_manager_add_to_zone (policy->fw_manager,
nm_device_get_ip_iface (dev),
zone,
nm_setting_connection_get_zone (s_con),
add_to_zone_cb,
NULL);
g_object_ref (dev));
}
}
}