core: move NMDevice private functions to nm-device-private.h

Move stuff that's not "public" API of NMDevice to the private
header that's only used by subclasses.
This commit is contained in:
Dan Williams 2011-11-17 22:39:34 -06:00
parent 396ae5940a
commit e5c1a0ed13
4 changed files with 71 additions and 85 deletions

View file

@ -24,26 +24,45 @@
#include "nm-device.h"
/* This file should only be used by subclasses of NMDevice */
enum NMActStageReturn {
NM_ACT_STAGE_RETURN_FAILURE = 0,
NM_ACT_STAGE_RETURN_SUCCESS,
NM_ACT_STAGE_RETURN_POSTPONE,
NM_ACT_STAGE_RETURN_STOP /* This activation chain is done */
};
void nm_device_set_ip_iface (NMDevice *self, const char *iface);
void nm_device_activate_schedule_stage3_ip_config_start (NMDevice *device);
void nm_device_state_changed (NMDevice *device,
NMDeviceState state,
NMDeviceStateReason reason);
gboolean nm_device_hw_bring_up (NMDevice *self, gboolean wait, gboolean *no_firmware);
void nm_device_hw_take_down (NMDevice *self, gboolean block);
void nm_device_handle_autoip4_event (NMDevice *self,
const char *event,
const char *address);
gboolean nm_device_ip_config_should_fail (NMDevice *self, gboolean ip6);
gboolean nm_device_get_firmware_missing (NMDevice *self);
void nm_device_set_firmware_missing (NMDevice *self, gboolean missing);
guint32 nm_device_get_capabilities (NMDevice *dev);
guint32 nm_device_get_type_capabilities (NMDevice *dev);
void nm_device_activate_schedule_stage1_device_prepare (NMDevice *device);
void nm_device_activate_schedule_stage2_device_config (NMDevice *device);
void nm_device_activate_schedule_ip4_config_result(NMDevice *device, NMIP4Config *config);
void nm_device_activate_schedule_ip4_config_timeout (NMDevice *device);
void nm_device_activate_schedule_ip6_config_result (NMDevice *device, NMIP6Config *config);
void nm_device_activate_schedule_ip6_config_timeout (NMDevice *device);
gboolean nm_device_activate_ip4_state_in_conf (NMDevice *device);
gboolean nm_device_activate_ip6_state_in_conf (NMDevice *device);
void nm_device_set_dhcp_timeout (NMDevice *device, guint32 timeout);
void nm_device_set_dhcp_anycast_address (NMDevice *device, guint8 *addr);
gboolean nm_device_dhcp4_renew (NMDevice *device, gboolean release);
#endif /* NM_DEVICE_PRIVATE_H */

View file

@ -2845,6 +2845,32 @@ dnsmasq_cleanup (NMDevice *self)
priv->dnsmasq_manager = NULL;
}
static void
_update_ip4_address (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
struct ifreq req;
guint32 new_address;
int fd;
g_return_if_fail (self != NULL);
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
nm_log_err (LOGD_IP4, "couldn't open control socket.");
return;
}
memset (&req, 0, sizeof (struct ifreq));
strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
if (ioctl (fd, SIOCGIFADDR, &req) == 0) {
new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
if (new_address != priv->ip4_address)
priv->ip4_address = new_address;
}
close (fd);
}
/*
* nm_device_deactivate
*
@ -2912,7 +2938,7 @@ nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason)
family = tried_ipv6 ? AF_UNSPEC : AF_INET;
nm_system_iface_flush_routes (ifindex, family);
nm_system_iface_flush_addresses (ifindex, family);
nm_device_update_ip4_address (self);
_update_ip4_address (self);
/* Clean up nameservers and addresses */
nm_device_set_ip4_config (self, NULL, FALSE, &ignored);
@ -3106,7 +3132,7 @@ nm_device_set_ip4_config (NMDevice *self,
/* Add the DNS information to the DNS manager */
nm_dns_manager_add_ip4_config (dns_mgr, ip_iface, new_config, NM_DNS_IP_CONFIG_TYPE_DEFAULT);
nm_device_update_ip4_address (self);
_update_ip4_address (self);
}
}
g_object_unref (dns_mgr);
@ -3116,46 +3142,6 @@ nm_device_set_ip4_config (NMDevice *self,
return success;
}
/*
* nm_device_get_ip4_address
*
* Get a device's IPv4 address
*
*/
guint32
nm_device_get_ip4_address (NMDevice *self)
{
g_return_val_if_fail (self != NULL, 0);
return NM_DEVICE_GET_PRIVATE (self)->ip4_address;
}
void
nm_device_update_ip4_address (NMDevice *self)
{
struct ifreq req;
guint32 new_address;
int fd;
g_return_if_fail (self != NULL);
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
nm_log_err (LOGD_IP4, "couldn't open control socket.");
return;
}
memset (&req, 0, sizeof (struct ifreq));
strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
if (ioctl (fd, SIOCGIFADDR, &req) == 0) {
new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
if (new_address != nm_device_get_ip4_address (self))
NM_DEVICE_GET_PRIVATE (self)->ip4_address = new_address;
}
close (fd);
}
static gboolean
nm_device_set_ip6_config (NMDevice *self,
NMIP6Config *new_config,
@ -3281,7 +3267,7 @@ out:
if (NM_DEVICE_GET_CLASS (self)->update_hw_address)
NM_DEVICE_GET_CLASS (self)->update_hw_address (self);
nm_device_update_ip4_address (self);
_update_ip4_address (self);
return TRUE;
}

View file

@ -34,15 +34,6 @@
#include "nm-dhcp6-config.h"
#include "nm-connection.h"
typedef enum NMActStageReturn
{
NM_ACT_STAGE_RETURN_FAILURE = 0,
NM_ACT_STAGE_RETURN_SUCCESS,
NM_ACT_STAGE_RETURN_POSTPONE,
NM_ACT_STAGE_RETURN_STOP /* This activation chain is done */
} NMActStageReturn;
G_BEGIN_DECLS
#define NM_TYPE_DEVICE (nm_device_get_type ())
@ -52,6 +43,8 @@ G_BEGIN_DECLS
#define NM_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE))
#define NM_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE, NMDeviceClass))
typedef enum NMActStageReturn NMActStageReturn;
typedef struct {
GObject parent;
} NMDevice;
@ -135,16 +128,10 @@ const char * nm_device_get_ip_iface (NMDevice *dev);
int nm_device_get_ip_ifindex(NMDevice *dev);
const char * nm_device_get_driver (NMDevice *dev);
const char * nm_device_get_type_desc (NMDevice *dev);
NMDeviceType nm_device_get_device_type (NMDevice *dev);
guint32 nm_device_get_capabilities (NMDevice *dev);
guint32 nm_device_get_type_capabilities (NMDevice *dev);
int nm_device_get_priority (NMDevice *dev);
guint32 nm_device_get_ip4_address (NMDevice *dev);
void nm_device_update_ip4_address (NMDevice *dev);
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *dev);
NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *dev);
@ -169,18 +156,6 @@ gboolean nm_device_complete_connection (NMDevice *device,
const GSList *existing_connection,
GError **error);
void nm_device_activate_schedule_stage1_device_prepare (NMDevice *device);
void nm_device_activate_schedule_stage2_device_config (NMDevice *device);
void nm_device_activate_schedule_ip4_config_result (NMDevice *device, NMIP4Config *config);
void nm_device_activate_schedule_ip4_config_timeout (NMDevice *device);
void nm_device_activate_schedule_ip6_config_result (NMDevice *device, NMIP6Config *config);
void nm_device_activate_schedule_ip6_config_timeout (NMDevice *device);
gboolean nm_device_activate_ip4_state_in_conf (NMDevice *device);
gboolean nm_device_activate_ip6_state_in_conf (NMDevice *device);
gboolean nm_device_is_activating (NMDevice *dev);
gboolean nm_device_can_interrupt_activation (NMDevice *self);
gboolean nm_device_autoconnect_allowed (NMDevice *self);
@ -192,12 +167,18 @@ void nm_device_set_managed (NMDevice *device,
gboolean managed,
NMDeviceStateReason reason);
void nm_device_set_dhcp_timeout (NMDevice *device, guint32 timeout);
void nm_device_set_dhcp_anycast_address (NMDevice *device, guint8 *addr);
void nm_device_clear_autoconnect_inhibit (NMDevice *device);
gboolean nm_device_dhcp4_renew (NMDevice *device, gboolean release);
void nm_device_handle_autoip4_event (NMDevice *self,
const char *event,
const char *address);
void nm_device_state_changed (NMDevice *device,
NMDeviceState state,
NMDeviceStateReason reason);
gboolean nm_device_get_firmware_missing (NMDevice *self);
G_END_DECLS

View file

@ -39,7 +39,7 @@
#include "nm-modem-manager.h"
#include "nm-device-bt.h"
#include "nm-device-interface.h"
#include "nm-device-private.h"
#include "nm-device.h"
#include "nm-device-ethernet.h"
#include "nm-device-wifi.h"
#include "nm-device-olpc-mesh.h"