libnm: add libnm/libnm-core (part 1)

This commit begins creating the new "libnm", which will replace
libnm-util and libnm-glib.

The main reason for the libnm-util/libnm-glib split is that the daemon
needs to link to libnm-util (to get NMSettings, NMConnection, etc),
but can't link to libnm-glib (because it uses many of the same type
names as the NetworkManager daemon. eg, NMDevice). So the daemon links
to only libnm-util, but basically all clients link to both.

With libnm, there will be only a single client-visible library, and
NetworkManager will internally link against a private "libnm-core"
containing the parts that used to be in libnm-util.

(The "libnm-core" parts still need to be in their own directory so
that the daemon can see those header files without also seeing the
ones in libnm/ that conflict with its own headers.)

[This commit just copies the source code from libnm-util/ to
libnm-core/, and libnm-glib/ to libnm/:

  mkdir -p libnm-core/tests/
  mkdir -p libnm/tests/
  cp libnm-util/*.[ch] libnm-util/nm-version.h.in libnm-core/
  rm -f libnm-core/nm-version.h libnm-core/nm-setting-template.[ch] libnm-core/nm-utils-enum-types.[ch]
  cp libnm-util/tests/*.[ch] libnm-core/tests/
  cp libnm-glib/*.[ch] libnm/
  rm -f libnm/libnm_glib.[ch] libnm/libnm-glib-test.c libnm/nm-glib-enum-types.[ch]
  cp libnm-glib/tests/*.[ch] libnm/tests/

]
This commit is contained in:
Dan Winship
2014-07-24 08:53:33 -04:00
parent c123a24dc4
commit d595f7843e
150 changed files with 67616 additions and 0 deletions

563
libnm-core/NetworkManager.h Normal file
View File

@@ -0,0 +1,563 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2004 - 2014 Red Hat, Inc.
*/
/* Definitions related to NetworkManager's D-Bus interfaces.
*
* Note that although this header is installed as part of libnm-util, it is also
* used by some external code that does not link to libnm-util.
*/
#ifndef NETWORK_MANAGER_H
#define NETWORK_MANAGER_H
#include "nm-version.h"
/*
* dbus services details
*/
#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager"
#define NM_DBUS_PATH "/org/freedesktop/NetworkManager"
#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
#define NM_DBUS_INTERFACE_DEVICE NM_DBUS_INTERFACE ".Device"
#define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired"
#define NM_DBUS_INTERFACE_DEVICE_ADSL NM_DBUS_INTERFACE_DEVICE ".Adsl"
#define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless"
#define NM_DBUS_INTERFACE_DEVICE_BLUETOOTH NM_DBUS_INTERFACE_DEVICE ".Bluetooth"
#define NM_DBUS_INTERFACE_DEVICE_OLPC_MESH NM_DBUS_INTERFACE_DEVICE ".OlpcMesh"
#define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint"
#define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint"
#define NM_DBUS_INTERFACE_DEVICE_MODEM NM_DBUS_INTERFACE_DEVICE ".Modem"
#define NM_DBUS_INTERFACE_DEVICE_WIMAX NM_DBUS_INTERFACE_DEVICE ".WiMax"
#define NM_DBUS_INTERFACE_WIMAX_NSP NM_DBUS_INTERFACE ".WiMax.Nsp"
#define NM_DBUS_PATH_WIMAX_NSP NM_DBUS_PATH "/Nsp"
#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"
#define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config"
#define NM_DBUS_INTERFACE_DHCP4_CONFIG NM_DBUS_INTERFACE ".DHCP4Config"
#define NM_DBUS_INTERFACE_IP6_CONFIG NM_DBUS_INTERFACE ".IP6Config"
#define NM_DBUS_INTERFACE_DHCP6_CONFIG NM_DBUS_INTERFACE ".DHCP6Config"
#define NM_DBUS_INTERFACE_DEVICE_INFINIBAND NM_DBUS_INTERFACE_DEVICE ".Infiniband"
#define NM_DBUS_INTERFACE_DEVICE_BOND NM_DBUS_INTERFACE_DEVICE ".Bond"
#define NM_DBUS_INTERFACE_DEVICE_TEAM NM_DBUS_INTERFACE_DEVICE ".Team"
#define NM_DBUS_INTERFACE_DEVICE_VLAN NM_DBUS_INTERFACE_DEVICE ".Vlan"
#define NM_DBUS_INTERFACE_DEVICE_BRIDGE NM_DBUS_INTERFACE_DEVICE ".Bridge"
#define NM_DBUS_INTERFACE_DEVICE_GENERIC NM_DBUS_INTERFACE_DEVICE ".Generic"
#define NM_DBUS_INTERFACE_DEVICE_VETH NM_DBUS_INTERFACE_DEVICE ".Veth"
#define NM_DBUS_INTERFACE_DEVICE_TUN NM_DBUS_INTERFACE_DEVICE ".Tun"
#define NM_DBUS_INTERFACE_DEVICE_MACVLAN NM_DBUS_INTERFACE_DEVICE ".Macvlan"
#define NM_DBUS_INTERFACE_DEVICE_VXLAN NM_DBUS_INTERFACE_DEVICE ".Vxlan"
#define NM_DBUS_INTERFACE_DEVICE_GRE NM_DBUS_INTERFACE_DEVICE ".Gre"
#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager.Settings"
#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManager/Settings"
#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManager.Settings.Connection"
#define NM_DBUS_PATH_SETTINGS_CONNECTION "/org/freedesktop/NetworkManager/Settings/Connection"
#define NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS "org.freedesktop.NetworkManager.Settings.Connection.Secrets"
#define NM_DBUS_INTERFACE_AGENT_MANAGER NM_DBUS_INTERFACE ".AgentManager"
#define NM_DBUS_PATH_AGENT_MANAGER "/org/freedesktop/NetworkManager/AgentManager"
#define NM_DBUS_INTERFACE_SECRET_AGENT NM_DBUS_INTERFACE ".SecretAgent"
#define NM_DBUS_PATH_SECRET_AGENT "/org/freedesktop/NetworkManager/SecretAgent"
/**
* NMState:
* @NM_STATE_UNKNOWN: networking state is unknown
* @NM_STATE_ASLEEP: networking is not enabled
* @NM_STATE_DISCONNECTED: there is no active network connection
* @NM_STATE_DISCONNECTING: network connections are being cleaned up
* @NM_STATE_CONNECTING: a network connection is being started
* @NM_STATE_CONNECTED_LOCAL: there is only local IPv4 and/or IPv6 connectivity
* @NM_STATE_CONNECTED_SITE: there is only site-wide IPv4 and/or IPv6 connectivity
* @NM_STATE_CONNECTED_GLOBAL: there is global IPv4 and/or IPv6 Internet connectivity
*
* #NMState values indicate the current overall networking state.
*
* (Corresponds to the NM_STATE type in nm-manager.xml.)
**/
typedef enum {
NM_STATE_UNKNOWN = 0,
NM_STATE_ASLEEP = 10,
NM_STATE_DISCONNECTED = 20,
NM_STATE_DISCONNECTING = 30,
NM_STATE_CONNECTING = 40,
NM_STATE_CONNECTED_LOCAL = 50,
NM_STATE_CONNECTED_SITE = 60,
NM_STATE_CONNECTED_GLOBAL = 70
} NMState;
/* For backwards compat */
#define NM_STATE_CONNECTED NM_STATE_CONNECTED_GLOBAL
/**
* NMConnectivityState:
* @NM_CONNECTIVITY_UNKNOWN: Network connectivity is unknown.
* @NM_CONNECTIVITY_NONE: The host is not connected to any network.
* @NM_CONNECTIVITY_PORTAL: The host is behind a captive portal and
* cannot reach the full Internet.
* @NM_CONNECTIVITY_LIMITED: The host is connected to a network, but
* does not appear to be able to reach the full Internet.
* @NM_CONNECTIVITY_FULL: The host is connected to a network, and
* appears to be able to reach the full Internet.
*
* (Corresponds to the NM_CONNECTIVITY type in nm-manager.xml.)
*
* Since: 0.9.8.6
*/
typedef enum {
NM_CONNECTIVITY_UNKNOWN,
NM_CONNECTIVITY_NONE,
NM_CONNECTIVITY_PORTAL,
NM_CONNECTIVITY_LIMITED,
NM_CONNECTIVITY_FULL
} NMConnectivityState;
/**
* NMDeviceType:
* @NM_DEVICE_TYPE_UNKNOWN: unknown device
* @NM_DEVICE_TYPE_GENERIC: generic support for unrecognized device types
* @NM_DEVICE_TYPE_ETHERNET: a wired ethernet device
* @NM_DEVICE_TYPE_WIFI: an 802.11 WiFi device
* @NM_DEVICE_TYPE_UNUSED1: not used
* @NM_DEVICE_TYPE_UNUSED2: not used
* @NM_DEVICE_TYPE_BT: a Bluetooth device supporting PAN or DUN access protocols
* @NM_DEVICE_TYPE_OLPC_MESH: an OLPC XO mesh networking device
* @NM_DEVICE_TYPE_WIMAX: an 802.16e Mobile WiMAX broadband device
* @NM_DEVICE_TYPE_MODEM: a modem supporting analog telephone, CDMA/EVDO,
* GSM/UMTS, or LTE network access protocols
* @NM_DEVICE_TYPE_INFINIBAND: an IP-over-InfiniBand device
* @NM_DEVICE_TYPE_BOND: a bond master interface
* @NM_DEVICE_TYPE_VLAN: an 802.1Q VLAN interface
* @NM_DEVICE_TYPE_ADSL: ADSL modem
* @NM_DEVICE_TYPE_BRIDGE: a bridge master interface
* @NM_DEVICE_TYPE_TEAM: a team master interface
*
* #NMDeviceType values indicate the type of hardware represented by
* an #NMDevice.
*
* (Corresponds to the NM_DEVICE_TYPE type in nm-device.xml.)
**/
typedef enum {
NM_DEVICE_TYPE_UNKNOWN = 0,
NM_DEVICE_TYPE_ETHERNET = 1,
NM_DEVICE_TYPE_WIFI = 2,
NM_DEVICE_TYPE_UNUSED1 = 3,
NM_DEVICE_TYPE_UNUSED2 = 4,
NM_DEVICE_TYPE_BT = 5, /* Bluetooth */
NM_DEVICE_TYPE_OLPC_MESH = 6,
NM_DEVICE_TYPE_WIMAX = 7,
NM_DEVICE_TYPE_MODEM = 8,
NM_DEVICE_TYPE_INFINIBAND = 9,
NM_DEVICE_TYPE_BOND = 10,
NM_DEVICE_TYPE_VLAN = 11,
NM_DEVICE_TYPE_ADSL = 12,
NM_DEVICE_TYPE_BRIDGE = 13,
NM_DEVICE_TYPE_GENERIC = 14,
NM_DEVICE_TYPE_TEAM = 15,
} NMDeviceType;
/**
* NMDeviceCapabilities:
* @NM_DEVICE_CAP_NONE: device has no special capabilities
* @NM_DEVICE_CAP_NM_SUPPORTED: NetworkManager supports this device
* @NM_DEVICE_CAP_CARRIER_DETECT: this device can indicate carrier status
* @NM_DEVICE_CAP_IS_SOFTWARE: this device is a software device
*
* General device capability flags.
*
* (Corresponds to the NM_DEVICE_CAP type in nm-device-wifi.xml.)
**/
typedef enum {
NM_DEVICE_CAP_NONE = 0x00000000,
NM_DEVICE_CAP_NM_SUPPORTED = 0x00000001,
NM_DEVICE_CAP_CARRIER_DETECT = 0x00000002,
NM_DEVICE_CAP_IS_SOFTWARE = 0x00000004,
} NMDeviceCapabilities;
/**
* NMDeviceWifiCapabilities:
* @NM_WIFI_DEVICE_CAP_NONE: device has no encryption/authentication capabilities
* @NM_WIFI_DEVICE_CAP_CIPHER_WEP40: device supports 40/64-bit WEP encryption
* @NM_WIFI_DEVICE_CAP_CIPHER_WEP104: device supports 104/128-bit WEP encryption
* @NM_WIFI_DEVICE_CAP_CIPHER_TKIP: device supports TKIP encryption
* @NM_WIFI_DEVICE_CAP_CIPHER_CCMP: device supports AES/CCMP encryption
* @NM_WIFI_DEVICE_CAP_WPA: device supports WPA1 authentication
* @NM_WIFI_DEVICE_CAP_RSN: device supports WPA2/RSN authentication
* @NM_WIFI_DEVICE_CAP_AP: device supports Access Point mode
* @NM_WIFI_DEVICE_CAP_ADHOC: device supports Ad-Hoc mode
*
* 802.11 specific device encryption and authentication capabilities.
*
* (Corresponds to the NM_802_11_DEVICE_CAP type in nm-device-wifi.xml.)
**/
typedef enum {
NM_WIFI_DEVICE_CAP_NONE = 0x00000000,
NM_WIFI_DEVICE_CAP_CIPHER_WEP40 = 0x00000001,
NM_WIFI_DEVICE_CAP_CIPHER_WEP104 = 0x00000002,
NM_WIFI_DEVICE_CAP_CIPHER_TKIP = 0x00000004,
NM_WIFI_DEVICE_CAP_CIPHER_CCMP = 0x00000008,
NM_WIFI_DEVICE_CAP_WPA = 0x00000010,
NM_WIFI_DEVICE_CAP_RSN = 0x00000020,
NM_WIFI_DEVICE_CAP_AP = 0x00000040,
NM_WIFI_DEVICE_CAP_ADHOC = 0x00000080
} NMDeviceWifiCapabilities;
/**
* NM80211ApFlags:
* @NM_802_11_AP_FLAGS_NONE: access point has no special capabilities
* @NM_802_11_AP_FLAGS_PRIVACY: access point requires authentication and
* encryption (usually means WEP)
*
* 802.11 access point flags.
*
* (Corresponds to the NM_802_11_AP_FLAGS type in nm-access-point.xml.)
**/
typedef enum {
NM_802_11_AP_FLAGS_NONE = 0x00000000,
NM_802_11_AP_FLAGS_PRIVACY = 0x00000001
} NM80211ApFlags;
/**
* NM80211ApSecurityFlags:
* @NM_802_11_AP_SEC_NONE: the access point has no special security requirements
* @NM_802_11_AP_SEC_PAIR_WEP40: 40/64-bit WEP is supported for
* pairwise/unicast encryption
* @NM_802_11_AP_SEC_PAIR_WEP104: 104/128-bit WEP is supported for
* pairwise/unicast encryption
* @NM_802_11_AP_SEC_PAIR_TKIP: TKIP is supported for pairwise/unicast encryption
* @NM_802_11_AP_SEC_PAIR_CCMP: AES/CCMP is supported for pairwise/unicast encryption
* @NM_802_11_AP_SEC_GROUP_WEP40: 40/64-bit WEP is supported for group/broadcast
* encryption
* @NM_802_11_AP_SEC_GROUP_WEP104: 104/128-bit WEP is supported for
* group/broadcast encryption
* @NM_802_11_AP_SEC_GROUP_TKIP: TKIP is supported for group/broadcast encryption
* @NM_802_11_AP_SEC_GROUP_CCMP: AES/CCMP is supported for group/broadcast
* encryption
* @NM_802_11_AP_SEC_KEY_MGMT_PSK: WPA/RSN Pre-Shared Key encryption is
* supported
* @NM_802_11_AP_SEC_KEY_MGMT_802_1X: 802.1x authentication and key management
* is supported
*
* 802.11 access point security and authentication flags. These flags describe
* the current security requirements of an access point as determined from the
* access point's beacon.
*
* (Corresponds to the NM_802_11_AP_SEC type in nm-access-point.xml.)
**/
typedef enum {
NM_802_11_AP_SEC_NONE = 0x00000000,
NM_802_11_AP_SEC_PAIR_WEP40 = 0x00000001,
NM_802_11_AP_SEC_PAIR_WEP104 = 0x00000002,
NM_802_11_AP_SEC_PAIR_TKIP = 0x00000004,
NM_802_11_AP_SEC_PAIR_CCMP = 0x00000008,
NM_802_11_AP_SEC_GROUP_WEP40 = 0x00000010,
NM_802_11_AP_SEC_GROUP_WEP104 = 0x00000020,
NM_802_11_AP_SEC_GROUP_TKIP = 0x00000040,
NM_802_11_AP_SEC_GROUP_CCMP = 0x00000080,
NM_802_11_AP_SEC_KEY_MGMT_PSK = 0x00000100,
NM_802_11_AP_SEC_KEY_MGMT_802_1X = 0x00000200
} NM80211ApSecurityFlags;
/**
* NM80211Mode:
* @NM_802_11_MODE_UNKNOWN: the device or access point mode is unknown
* @NM_802_11_MODE_ADHOC: for both devices and access point objects, indicates
* the object is part of an Ad-Hoc 802.11 network without a central
* coordinating access point.
* @NM_802_11_MODE_INFRA: the device or access point is in infrastructure mode.
* For devices, this indicates the device is an 802.11 client/station. For
* access point objects, this indicates the object is an access point that
* provides connectivity to clients.
* @NM_802_11_MODE_AP: the device is an access point/hotspot. Not valid for
* access point objects; used only for hotspot mode on the local machine.
*
* Indicates the 802.11 mode an access point or device is currently in.
*
* (Corresponds to the NM_802_11_MODE type in generic-types.xml.)
**/
typedef enum {
NM_802_11_MODE_UNKNOWN = 0,
NM_802_11_MODE_ADHOC,
NM_802_11_MODE_INFRA,
NM_802_11_MODE_AP
} NM80211Mode;
/**
* NMBluetoothCapabilities:
* @NM_BT_CAPABILITY_NONE: device has no usable capabilities
* @NM_BT_CAPABILITY_DUN: device provides Dial-Up Networking capability
* @NM_BT_CAPABILITY_NAP: device provides Network Access Point capability
*
* #NMBluetoothCapabilities values indicate the usable capabilities of a
* Bluetooth device.
*
* (Corresponds to the NM_BT_CAPABILITY type in nm-device-bt.xml.)
**/
typedef enum {
NM_BT_CAPABILITY_NONE = 0x00000000,
NM_BT_CAPABILITY_DUN = 0x00000001,
NM_BT_CAPABILITY_NAP = 0x00000002,
} NMBluetoothCapabilities;
/**
* NMDeviceModemCapabilities:
* @NM_DEVICE_MODEM_CAPABILITY_NONE: modem has no usable capabilities
* @NM_DEVICE_MODEM_CAPABILITY_POTS: modem uses the analog wired telephone
* network and is not a wireless/cellular device
* @NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO: modem supports at least one of CDMA
* 1xRTT, EVDO revision 0, EVDO revision A, or EVDO revision B
* @NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS: modem supports at least one of GSM,
* GPRS, EDGE, UMTS, HSDPA, HSUPA, or HSPA+ packet switched data capability
* @NM_DEVICE_MODEM_CAPABILITY_LTE: modem has LTE data capability
*
* #NMDeviceModemCapabilities values indicate the generic radio access
* technology families a modem device supports. For more information on the
* specific access technologies the device supports use the ModemManager D-Bus
* API.
*
* (Corresponds to the NM_DEVICE_MODEM_CAPABILITY type in nm-device-modem.xml.)
**/
typedef enum {
NM_DEVICE_MODEM_CAPABILITY_NONE = 0x00000000,
NM_DEVICE_MODEM_CAPABILITY_POTS = 0x00000001,
NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO = 0x00000002,
NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS = 0x00000004,
NM_DEVICE_MODEM_CAPABILITY_LTE = 0x00000008,
} NMDeviceModemCapabilities;
/**
* NMDeviceState:
* @NM_DEVICE_STATE_UNKNOWN: the device's state is unknown
* @NM_DEVICE_STATE_UNMANAGED: the device is recognized, but not managed by
* NetworkManager
* @NM_DEVICE_STATE_UNAVAILABLE: the device is managed by NetworkManager, but
* is not available for use. Reasons may include the wireless switched off,
* missing firmware, no ethernet carrier, missing supplicant or modem manager,
* etc.
* @NM_DEVICE_STATE_DISCONNECTED: the device can be activated, but is currently
* idle and not connected to a network.
* @NM_DEVICE_STATE_PREPARE: the device is preparing the connection to the
* network. This may include operations like changing the MAC address,
* setting physical link properties, and anything else required to connect
* to the requested network.
* @NM_DEVICE_STATE_CONFIG: the device is connecting to the requested network.
* This may include operations like associating with the WiFi AP, dialing
* the modem, connecting to the remote Bluetooth device, etc.
* @NM_DEVICE_STATE_NEED_AUTH: the device requires more information to continue
* connecting to the requested network. This includes secrets like WiFi
* passphrases, login passwords, PIN codes, etc.
* @NM_DEVICE_STATE_IP_CONFIG: the device is requesting IPv4 and/or IPv6
* addresses and routing information from the network.
* @NM_DEVICE_STATE_IP_CHECK: the device is checking whether further action is
* required for the requested network connection. This may include checking
* whether only local network access is available, whether a captive portal
* is blocking access to the Internet, etc.
* @NM_DEVICE_STATE_SECONDARIES: the device is waiting for a secondary
* connection (like a VPN) which must activated before the device can be
* activated
* @NM_DEVICE_STATE_ACTIVATED: the device has a network connection, either local
* or global.
* @NM_DEVICE_STATE_DEACTIVATING: a disconnection from the current network
* connection was requested, and the device is cleaning up resources used for
* that connection. The network connection may still be valid.
* @NM_DEVICE_STATE_FAILED: the device failed to connect to the requested
* network and is cleaning up the connection request
*
* (Corresponds to the NM_DEVICE_STATE type in nm-device.xml.)
**/
typedef enum {
NM_DEVICE_STATE_UNKNOWN = 0,
NM_DEVICE_STATE_UNMANAGED = 10,
NM_DEVICE_STATE_UNAVAILABLE = 20,
NM_DEVICE_STATE_DISCONNECTED = 30,
NM_DEVICE_STATE_PREPARE = 40,
NM_DEVICE_STATE_CONFIG = 50,
NM_DEVICE_STATE_NEED_AUTH = 60,
NM_DEVICE_STATE_IP_CONFIG = 70,
NM_DEVICE_STATE_IP_CHECK = 80,
NM_DEVICE_STATE_SECONDARIES = 90,
NM_DEVICE_STATE_ACTIVATED = 100,
NM_DEVICE_STATE_DEACTIVATING = 110,
NM_DEVICE_STATE_FAILED = 120
} NMDeviceState;
/**
* NMDeviceStateReason:
* @NM_DEVICE_STATE_REASON_NONE: No reason given
* @NM_DEVICE_STATE_REASON_UNKNOWN: Unknown error
* @NM_DEVICE_STATE_REASON_NOW_MANAGED: Device is now managed
* @NM_DEVICE_STATE_REASON_NOW_UNMANAGED: Device is now unmanaged
* @NM_DEVICE_STATE_REASON_CONFIG_FAILED: The device could not be readied for configuration
* @NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE: IP configuration could not be reserved (no available address, timeout, etc)
* @NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED: The IP config is no longer valid
* @NM_DEVICE_STATE_REASON_NO_SECRETS: Secrets were required, but not provided
* @NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT: 802.1x supplicant disconnected
* @NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED: 802.1x supplicant configuration failed
* @NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED: 802.1x supplicant failed
* @NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT: 802.1x supplicant took too long to authenticate
* @NM_DEVICE_STATE_REASON_PPP_START_FAILED: PPP service failed to start
* @NM_DEVICE_STATE_REASON_PPP_DISCONNECT: PPP service disconnected
* @NM_DEVICE_STATE_REASON_PPP_FAILED: PPP failed
* @NM_DEVICE_STATE_REASON_DHCP_START_FAILED: DHCP client failed to start
* @NM_DEVICE_STATE_REASON_DHCP_ERROR: DHCP client error
* @NM_DEVICE_STATE_REASON_DHCP_FAILED: DHCP client failed
* @NM_DEVICE_STATE_REASON_SHARED_START_FAILED: Shared connection service failed to start
* @NM_DEVICE_STATE_REASON_SHARED_FAILED: Shared connection service failed
* @NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED: AutoIP service failed to start
* @NM_DEVICE_STATE_REASON_AUTOIP_ERROR: AutoIP service error
* @NM_DEVICE_STATE_REASON_AUTOIP_FAILED: AutoIP service failed
* @NM_DEVICE_STATE_REASON_MODEM_BUSY: The line is busy
* @NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE: No dial tone
* @NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER: No carrier could be established
* @NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT: The dialing request timed out
* @NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED: The dialing attempt failed
* @NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED: Modem initialization failed
* @NM_DEVICE_STATE_REASON_GSM_APN_FAILED: Failed to select the specified APN
* @NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING: Not searching for networks
* @NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED: Network registration denied
* @NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT: Network registration timed out
* @NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED: Failed to register with the requested network
* @NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED: PIN check failed
* @NM_DEVICE_STATE_REASON_FIRMWARE_MISSING: Necessary firmware for the device may be missing
* @NM_DEVICE_STATE_REASON_REMOVED: The device was removed
* @NM_DEVICE_STATE_REASON_SLEEPING: NetworkManager went to sleep
* @NM_DEVICE_STATE_REASON_CONNECTION_REMOVED: The device's active connection disappeared
* @NM_DEVICE_STATE_REASON_USER_REQUESTED: Device disconnected by user or client
* @NM_DEVICE_STATE_REASON_CARRIER: Carrier/link changed
* @NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED: The device's existing connection was assumed
* @NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE: The supplicant is now available
* @NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND: The modem could not be found
* @NM_DEVICE_STATE_REASON_BT_FAILED: The Bluetooth connection failed or timed out
* @NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED: GSM Modem's SIM Card not inserted
* @NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED: GSM Modem's SIM Pin required
* @NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED: GSM Modem's SIM Puk required
* @NM_DEVICE_STATE_REASON_GSM_SIM_WRONG: GSM Modem's SIM wrong
* @NM_DEVICE_STATE_REASON_INFINIBAND_MODE: InfiniBand device does not support connected mode
* @NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED: A dependency of the connection failed
* @NM_DEVICE_STATE_REASON_BR2684_FAILED: Problem with the RFC 2684 Ethernet over ADSL bridge
* @NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE: ModemManager not running
* @NM_DEVICE_STATE_REASON_SSID_NOT_FOUND: The WiFi network could not be found
* @NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED: A secondary connection of the base connection failed
* @NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED: DCB or FCoE setup failed
* @NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED: teamd control failed
* @NM_DEVICE_STATE_REASON_MODEM_FAILED: Modem failed or no longer available
* @NM_DEVICE_STATE_REASON_MODEM_AVAILABLE: Modem now ready and available
* @NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT: SIM PIN was incorrect
*
* Device state change reason codes
*
* (Corresponds to the NM_DEVICE_STATE_REASON type in nm-device.xml.)
*/
typedef enum {
NM_DEVICE_STATE_REASON_NONE = 0,
NM_DEVICE_STATE_REASON_UNKNOWN = 1,
NM_DEVICE_STATE_REASON_NOW_MANAGED = 2,
NM_DEVICE_STATE_REASON_NOW_UNMANAGED = 3,
NM_DEVICE_STATE_REASON_CONFIG_FAILED = 4,
NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE = 5,
NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED = 6,
NM_DEVICE_STATE_REASON_NO_SECRETS = 7,
NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT = 8,
NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED = 9,
NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED = 10,
NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT = 11,
NM_DEVICE_STATE_REASON_PPP_START_FAILED = 12,
NM_DEVICE_STATE_REASON_PPP_DISCONNECT = 13,
NM_DEVICE_STATE_REASON_PPP_FAILED = 14,
NM_DEVICE_STATE_REASON_DHCP_START_FAILED = 15,
NM_DEVICE_STATE_REASON_DHCP_ERROR = 16,
NM_DEVICE_STATE_REASON_DHCP_FAILED = 17,
NM_DEVICE_STATE_REASON_SHARED_START_FAILED = 18,
NM_DEVICE_STATE_REASON_SHARED_FAILED = 19,
NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED = 20,
NM_DEVICE_STATE_REASON_AUTOIP_ERROR = 21,
NM_DEVICE_STATE_REASON_AUTOIP_FAILED = 22,
NM_DEVICE_STATE_REASON_MODEM_BUSY = 23,
NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE = 24,
NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER = 25,
NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT = 26,
NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED = 27,
NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED = 28,
NM_DEVICE_STATE_REASON_GSM_APN_FAILED = 29,
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING = 30,
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED = 31,
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT = 32,
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED = 33,
NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED = 34,
NM_DEVICE_STATE_REASON_FIRMWARE_MISSING = 35,
NM_DEVICE_STATE_REASON_REMOVED = 36,
NM_DEVICE_STATE_REASON_SLEEPING = 37,
NM_DEVICE_STATE_REASON_CONNECTION_REMOVED = 38,
NM_DEVICE_STATE_REASON_USER_REQUESTED = 39,
NM_DEVICE_STATE_REASON_CARRIER = 40,
NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED = 41,
NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE = 42,
NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND = 43,
NM_DEVICE_STATE_REASON_BT_FAILED = 44,
NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED = 45,
NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED = 46,
NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED = 47,
NM_DEVICE_STATE_REASON_GSM_SIM_WRONG = 48,
NM_DEVICE_STATE_REASON_INFINIBAND_MODE = 49,
NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED = 50,
NM_DEVICE_STATE_REASON_BR2684_FAILED = 51,
NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE = 52,
NM_DEVICE_STATE_REASON_SSID_NOT_FOUND = 53,
NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED = 54,
NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED = 55,
NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED = 56,
NM_DEVICE_STATE_REASON_MODEM_FAILED = 57,
NM_DEVICE_STATE_REASON_MODEM_AVAILABLE = 58,
NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT = 59,
NM_DEVICE_STATE_REASON_LAST = 0xFFFF
} NMDeviceStateReason;
/**
* NMActiveConnectionState:
* @NM_ACTIVE_CONNECTION_STATE_UNKNOWN: the state of the connection is unknown
* @NM_ACTIVE_CONNECTION_STATE_ACTIVATING: a network connection is being prepared
* @NM_ACTIVE_CONNECTION_STATE_ACTIVATED: there is a connection to the network
* @NM_ACTIVE_CONNECTION_STATE_DEACTIVATING: the network connection is being
* torn down and cleaned up
* @NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: the network connection is disconnected
* and will be removed
*
* #NMActiveConnectionState values indicate the state of a connection to a
* specific network while it is starting, connected, or disconnecting from that
* network.
*
* (Corresponds to the NM_ACTIVE_CONNECTION_STATE type in nm-active-connection.xml.)
**/
typedef enum {
NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0,
NM_ACTIVE_CONNECTION_STATE_ACTIVATING,
NM_ACTIVE_CONNECTION_STATE_ACTIVATED,
NM_ACTIVE_CONNECTION_STATE_DEACTIVATING,
NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
} NMActiveConnectionState;
#endif /* NETWORK_MANAGER_H */

View File

@@ -0,0 +1,302 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2004 Red Hat, Inc.
*/
/* D-Bus-related definitions for NetworkManager VPN plugins.
*
* Note that although this header is installed as part of libnm-util, it is also
* used by some external code that does not link to libnm-util.
*/
#ifndef NETWORK_MANAGER_VPN_H
#define NETWORK_MANAGER_VPN_H
/*
* dbus services details
*/
#define NM_DBUS_PATH_VPN "/org/freedesktop/NetworkManager/VPN/Manager"
#define NM_DBUS_INTERFACE_VPN "org.freedesktop.NetworkManager.VPN.Manager"
#define NM_DBUS_PATH_VPN_CONNECTION "/org/freedesktop/NetworkManager/VPN/Connection"
#define NM_DBUS_INTERFACE_VPN_CONNECTION "org.freedesktop.NetworkManager.VPN.Connection"
#define NM_VPN_DBUS_PLUGIN_PATH "/org/freedesktop/NetworkManager/VPN/Plugin"
#define NM_VPN_DBUS_PLUGIN_INTERFACE "org.freedesktop.NetworkManager.VPN.Plugin"
/*
* VPN Errors
*/
#define NM_DBUS_NO_ACTIVE_VPN_CONNECTION "org.freedesktop.NetworkManager.VPNConnections.NoActiveVPNConnection"
#define NM_DBUS_NO_VPN_CONNECTIONS "org.freedesktop.NetworkManager.VPNConnections.NoVPNConnections"
#define NM_DBUS_INVALID_VPN_CONNECTION "org.freedesktop.NetworkManager.VPNConnections.InvalidVPNConnection"
#define NM_DBUS_VPN_ERROR_PREFIX "org.freedesktop.NetworkManager.VPN.Error"
#define NM_DBUS_VPN_STARTING_IN_PROGRESS "StartingInProgress"
#define NM_DBUS_VPN_ALREADY_STARTED "AlreadyStarted"
#define NM_DBUS_VPN_STOPPING_IN_PROGRESS "StoppingInProgress"
#define NM_DBUS_VPN_ALREADY_STOPPED "AlreadyStopped"
#define NM_DBUS_VPN_WRONG_STATE "WrongState"
#define NM_DBUS_VPN_BAD_ARGUMENTS "BadArguments"
#define NM_DBUS_VPN_INTERACTIVE_NOT_SUPPORTED "InteractiveNotSupported"
/*
* VPN daemon signals
*/
#define NM_DBUS_VPN_SIGNAL_LOGIN_BANNER "LoginBanner"
#define NM_DBUS_VPN_SIGNAL_LOGIN_FAILED "LoginFailed"
#define NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED "LaunchFailed"
#define NM_DBUS_VPN_SIGNAL_CONNECT_FAILED "ConnectFailed"
#define NM_DBUS_VPN_SIGNAL_VPN_CONFIG_BAD "VPNConfigBad"
#define NM_DBUS_VPN_SIGNAL_IP_CONFIG_BAD "IPConfigBad"
#define NM_DBUS_VPN_SIGNAL_STATE_CHANGE "StateChange"
#define NM_DBUS_VPN_SIGNAL_IP4_CONFIG "IP4Config"
/**
* NMVPNServiceState:
* @NM_VPN_SERVICE_STATE_UNKNOWN: The state of the VPN plugin is unknown.
* @NM_VPN_SERVICE_STATE_INIT: The VPN plugin is initialized.
* @NM_VPN_SERVICE_STATE_SHUTDOWN: Not used.
* @NM_VPN_SERVICE_STATE_STARTING: The plugin is attempting to connect to a VPN server.
* @NM_VPN_SERVICE_STATE_STARTED: The plugin has connected to a VPN server.
* @NM_VPN_SERVICE_STATE_STOPPING: The plugin is disconnecting from the VPN server.
* @NM_VPN_SERVICE_STATE_STOPPED: The plugin has disconnected from the VPN server.
*
* VPN daemon states
*
* (Corresponds to the NM_VPN_SERVICE_STATE type in nm-vpn-connection.xml.)
*/
typedef enum NMVPNServiceState {
NM_VPN_SERVICE_STATE_UNKNOWN = 0,
NM_VPN_SERVICE_STATE_INIT,
NM_VPN_SERVICE_STATE_SHUTDOWN,
NM_VPN_SERVICE_STATE_STARTING,
NM_VPN_SERVICE_STATE_STARTED,
NM_VPN_SERVICE_STATE_STOPPING,
NM_VPN_SERVICE_STATE_STOPPED
} NMVPNServiceState;
/**
* NMVPNConnectionState:
* @NM_VPN_CONNECTION_STATE_UNKNOWN: The state of the VPN connection is
* unknown.
* @NM_VPN_CONNECTION_STATE_PREPARE: The VPN connection is preparing to
* connect.
* @NM_VPN_CONNECTION_STATE_NEED_AUTH: The VPN connection needs authorization
* credentials.
* @NM_VPN_CONNECTION_STATE_CONNECT: The VPN connection is being established.
* @NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: The VPN connection is getting an IP
* address.
* @NM_VPN_CONNECTION_STATE_ACTIVATED: The VPN connection is active.
* @NM_VPN_CONNECTION_STATE_FAILED: The VPN connection failed.
* @NM_VPN_CONNECTION_STATE_DISCONNECTED: The VPN connection is disconnected.
*
* VPN connection states
*
* (Corresponds to the NM_VPN_CONNECTION_STATE type in nm-vpn-connection.xml.)
*/
typedef enum NMVPNConnectionState {
NM_VPN_CONNECTION_STATE_UNKNOWN = 0,
NM_VPN_CONNECTION_STATE_PREPARE,
NM_VPN_CONNECTION_STATE_NEED_AUTH,
NM_VPN_CONNECTION_STATE_CONNECT,
NM_VPN_CONNECTION_STATE_IP_CONFIG_GET,
NM_VPN_CONNECTION_STATE_ACTIVATED,
NM_VPN_CONNECTION_STATE_FAILED,
NM_VPN_CONNECTION_STATE_DISCONNECTED
} NMVPNConnectionState;
/**
* NMVPNConnectionStateReason:
* @NM_VPN_CONNECTION_STATE_REASON_UNKNOWN: The reason for the VPN connection
* state change is unknown.
* @NM_VPN_CONNECTION_STATE_REASON_NONE: No reason was given for the VPN
* connection state change.
* @NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED: The VPN connection changed
* state because the user disconnected it.
* @NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED: The VPN connection
* changed state because the device it was using was disconnected.
* @NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED: The service providing the
* VPN connection was stopped.
* @NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID: The IP config of the VPN
* connection was invalid.
* @NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT: The connection attempt to
* the VPN service timed out.
* @NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT: A timeout occurred
* while starting the service providing the VPN connection.
* @NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED: Starting the service
* starting the service providing the VPN connection failed.
* @NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS: Necessary secrets for the VPN
* connection were not provided.
* @NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED: Authentication to the VPN
* server failed.
* @NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED: The connection was
* deleted from settings.
*
* VPN connection state reasons
*
* (Corresponds to the NM_VPN_CONNECTION_STATE_REASON type in nm-vpn-connection.xml.)
*/
typedef enum NMVPNConnectionStateReason {
NM_VPN_CONNECTION_STATE_REASON_UNKNOWN = 0,
NM_VPN_CONNECTION_STATE_REASON_NONE,
NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED,
NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED,
NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED,
NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID,
NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT,
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT,
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED,
NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS,
NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED,
NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED
} NMVPNConnectionStateReason;
/**
* NMVPNPluginFailure:
* @NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED: Login failed.
* @NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED: Connect failed.
* @NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG: Invalid IP configuration returned from
* the VPN plugin.
*
* VPN plugin failure reasons
*
* (Corresponds to the NM_VPN_PLUGIN_FAILURE type in nm-vpn-plugin.xml.)
*/
typedef enum {
NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED,
NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED,
NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG
} NMVPNPluginFailure;
/*** Generic config ***/
/* string: VPN interface name (tun0, tap0, etc) */
#define NM_VPN_PLUGIN_CONFIG_TUNDEV "tundev"
/* string: Login message */
#define NM_VPN_PLUGIN_CONFIG_BANNER "banner"
/* uint32 / array of uint8: IP address of the public external VPN gateway (network byte order) */
#define NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY "gateway"
/* uint32: Maximum Transfer Unit that the VPN interface should use */
#define NM_VPN_PLUGIN_CONFIG_MTU "mtu"
/* boolean: Has IP4 configuration? */
#define NM_VPN_PLUGIN_CONFIG_HAS_IP4 "has-ip4"
/* boolean: Has IP6 configuration? */
#define NM_VPN_PLUGIN_CONFIG_HAS_IP6 "has-ip6"
/*** Ip4Config ***/
/* uint32: IP address of the internal gateway of the subnet the VPN interface is
* on, if the VPN uses subnet configuration (network byte order)
*/
#define NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY "internal-gateway"
/* uint32: internal IP address of the local VPN interface (network byte order) */
#define NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS "address"
/* uint32: IP address of the other side of Point-to-Point connection if the VPN
* uses Point-to-Point configuration. (network byte order)
*/
#define NM_VPN_PLUGIN_IP4_CONFIG_PTP "ptp"
/* uint32: IP prefix of the VPN interface; 1 - 32 inclusive */
#define NM_VPN_PLUGIN_IP4_CONFIG_PREFIX "prefix"
/* array of uint32: IP addresses of DNS servers for the VPN (network byte order) */
#define NM_VPN_PLUGIN_IP4_CONFIG_DNS "dns"
/* array of uint32: IP addresses of NBNS/WINS servers for the VPN (network byte order) */
#define NM_VPN_PLUGIN_IP4_CONFIG_NBNS "nbns"
/* uint32: Message Segment Size that the VPN interface should use */
#define NM_VPN_PLUGIN_IP4_CONFIG_MSS "mss"
/* string: DNS domain name */
#define NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN "domain"
/* array of strings: DNS domain names */
#define NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS "domains"
/* [ip4 routes]: custom routes the client should apply, in the format used
* by nm_utils_ip4_routes_to/from_gvalue
*/
#define NM_VPN_PLUGIN_IP4_CONFIG_ROUTES "routes"
/* boolean: prevent this VPN connection from ever getting the default route */
#define NM_VPN_PLUGIN_IP4_CONFIG_NEVER_DEFAULT "never-default"
/* Deprecated */
#define NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY
/* Legacy IP4 items; these are included in the IP4 config by older plugins,
* but in the generic config by newer plugins.
*/
#define NM_VPN_PLUGIN_IP4_CONFIG_BANNER NM_VPN_PLUGIN_CONFIG_BANNER
#define NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY
#define NM_VPN_PLUGIN_IP4_CONFIG_MTU NM_VPN_PLUGIN_CONFIG_MTU
#define NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV NM_VPN_PLUGIN_CONFIG_TUNDEV
/*** Ip6Config ***/
/* array of uint8: IP address of the internal gateway of the subnet the VPN interface is
* on, if the VPN uses subnet configuration (network byte order)
*/
#define NM_VPN_PLUGIN_IP6_CONFIG_INT_GATEWAY "internal-gateway"
/* array of uint8: internal IP address of the local VPN interface (network byte order) */
#define NM_VPN_PLUGIN_IP6_CONFIG_ADDRESS "address"
/* array of uint8: IP address of the other side of Point-to-Point connection if the VPN
* uses Point-to-Point configuration. (network byte order)
*/
#define NM_VPN_PLUGIN_IP6_CONFIG_PTP "ptp"
/* uint32: prefix length of the VPN interface; 1 - 128 inclusive */
#define NM_VPN_PLUGIN_IP6_CONFIG_PREFIX "prefix"
/* array of array of uint8: IP addresses of DNS servers for the VPN (network byte order) */
#define NM_VPN_PLUGIN_IP6_CONFIG_DNS "dns"
/* uint32: Message Segment Size that the VPN interface should use */
#define NM_VPN_PLUGIN_IP6_CONFIG_MSS "mss"
/* string: DNS domain name */
#define NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN "domain"
/* array of strings: DNS domain names */
#define NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS "domains"
/* [ip6 routes]: custom routes the client should apply, in the format used
* by nm_utils_ip6_routes_to/from_gvalue
*/
#define NM_VPN_PLUGIN_IP6_CONFIG_ROUTES "routes"
/* boolean: prevent this VPN connection from ever getting the default route */
#define NM_VPN_PLUGIN_IP6_CONFIG_NEVER_DEFAULT "never-default"
#endif /* NETWORK_MANAGER_VPN_H */

749
libnm-core/crypto.c Normal file
View File

@@ -0,0 +1,749 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Dan Williams <dcbw@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
*/
#include "config.h"
#include <glib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include <glib/gi18n.h>
#include "crypto.h"
GQuark
_nm_crypto_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-crypto-error-quark");
return quark;
}
#define PEM_RSA_KEY_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
#define PEM_RSA_KEY_END "-----END RSA PRIVATE KEY-----"
#define PEM_DSA_KEY_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
#define PEM_DSA_KEY_END "-----END DSA PRIVATE KEY-----"
#define PEM_CERT_BEGIN "-----BEGIN CERTIFICATE-----"
#define PEM_CERT_END "-----END CERTIFICATE-----"
#define PEM_PKCS8_ENC_KEY_BEGIN "-----BEGIN ENCRYPTED PRIVATE KEY-----"
#define PEM_PKCS8_ENC_KEY_END "-----END ENCRYPTED PRIVATE KEY-----"
#define PEM_PKCS8_DEC_KEY_BEGIN "-----BEGIN PRIVATE KEY-----"
#define PEM_PKCS8_DEC_KEY_END "-----END PRIVATE KEY-----"
static gboolean
find_tag (const char *tag,
const GByteArray *array,
gsize start_at,
gsize *out_pos)
{
gsize i, taglen;
gsize len = array->len - start_at;
g_return_val_if_fail (out_pos != NULL, FALSE);
taglen = strlen (tag);
if (len >= taglen) {
for (i = 0; i < len - taglen + 1; i++) {
if (memcmp (array->data + start_at + i, tag, taglen) == 0) {
*out_pos = start_at + i;
return TRUE;
}
}
}
return FALSE;
}
#define DEK_INFO_TAG "DEK-Info: "
#define PROC_TYPE_TAG "Proc-Type: "
static GByteArray *
parse_old_openssl_key_file (const GByteArray *contents,
int key_type,
char **out_cipher,
char **out_iv,
GError **error)
{
GByteArray *bindata = NULL;
char **lines = NULL;
char **ln = NULL;
gsize start = 0, end = 0;
GString *str = NULL;
int enc_tags = 0;
char *iv = NULL;
char *cipher = NULL;
unsigned char *tmp = NULL;
gsize tmp_len = 0;
const char *start_tag;
const char *end_tag;
guint8 save_end = 0;
switch (key_type) {
case NM_CRYPTO_KEY_TYPE_RSA:
start_tag = PEM_RSA_KEY_BEGIN;
end_tag = PEM_RSA_KEY_END;
break;
case NM_CRYPTO_KEY_TYPE_DSA:
start_tag = PEM_DSA_KEY_BEGIN;
end_tag = PEM_DSA_KEY_END;
break;
default:
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_KEY_TYPE,
"Unknown key type %d",
key_type);
g_assert_not_reached ();
return NULL;
}
if (!find_tag (start_tag, contents, 0, &start))
goto parse_error;
start += strlen (start_tag);
if (!find_tag (end_tag, contents, start, &end)) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("PEM key file had no end tag '%s'."),
end_tag);
goto parse_error;
}
save_end = contents->data[end];
contents->data[end] = '\0';
lines = g_strsplit ((const char *) (contents->data + start), "\n", 0);
contents->data[end] = save_end;
if (!lines || g_strv_length (lines) <= 1) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Doesn't look like a PEM private key file."));
goto parse_error;
}
str = g_string_new_len (NULL, end - start);
for (ln = lines; *ln; ln++) {
char *p = *ln;
/* Chug leading spaces */
p = g_strstrip (p);
if (!*p)
continue;
if (!strncmp (p, PROC_TYPE_TAG, strlen (PROC_TYPE_TAG))) {
if (enc_tags++ != 0) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Malformed PEM file: Proc-Type was not first tag."));
goto parse_error;
}
p += strlen (PROC_TYPE_TAG);
if (strcmp (p, "4,ENCRYPTED")) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Malformed PEM file: unknown Proc-Type tag '%s'."),
p);
goto parse_error;
}
} else if (!strncmp (p, DEK_INFO_TAG, strlen (DEK_INFO_TAG))) {
char *comma;
if (enc_tags++ != 1) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Malformed PEM file: DEK-Info was not the second tag."));
goto parse_error;
}
p += strlen (DEK_INFO_TAG);
/* Grab the IV first */
comma = strchr (p, ',');
if (!comma || (*(comma + 1) == '\0')) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Malformed PEM file: no IV found in DEK-Info tag."));
goto parse_error;
}
*comma++ = '\0';
if (!g_ascii_isxdigit (*comma)) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Malformed PEM file: invalid format of IV in DEK-Info tag."));
goto parse_error;
}
iv = g_strdup (comma);
/* Get the private key cipher */
if (!strcasecmp (p, "DES-EDE3-CBC")) {
cipher = g_strdup (p);
} else if (!strcasecmp (p, "DES-CBC")) {
cipher = g_strdup (p);
} else if (!strcasecmp (p, "AES-128-CBC")) {
cipher = g_strdup (p);
} else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_KEY_TYPE,
_("Malformed PEM file: unknown private key cipher '%s'."),
p);
goto parse_error;
}
} else {
if ((enc_tags != 0) && (enc_tags != 2)) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
"Malformed PEM file: both Proc-Type and DEK-Info tags are required.");
goto parse_error;
}
g_string_append (str, p);
}
}
tmp = g_base64_decode (str->str, &tmp_len);
if (tmp == NULL || !tmp_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_DECODE_FAILED,
_("Could not decode private key."));
goto parse_error;
}
g_string_free (str, TRUE);
if (lines)
g_strfreev (lines);
bindata = g_byte_array_sized_new (tmp_len);
g_byte_array_append (bindata, tmp, tmp_len);
g_free (tmp);
*out_iv = iv;
*out_cipher = cipher;
return bindata;
parse_error:
g_free (tmp);
g_free (cipher);
g_free (iv);
if (str)
g_string_free (str, TRUE);
if (lines)
g_strfreev (lines);
return NULL;
}
static GByteArray *
parse_pkcs8_key_file (const GByteArray *contents,
gboolean *out_encrypted,
GError **error)
{
GByteArray *key = NULL;
gsize start = 0, end = 0;
unsigned char *der = NULL;
guint8 save_end;
gsize length = 0;
const char *start_tag = NULL, *end_tag = NULL;
gboolean encrypted = FALSE;
/* Try encrypted first, decrypted next */
if (find_tag (PEM_PKCS8_ENC_KEY_BEGIN, contents, 0, &start)) {
start_tag = PEM_PKCS8_ENC_KEY_BEGIN;
end_tag = PEM_PKCS8_ENC_KEY_END;
encrypted = TRUE;
} else if (find_tag (PEM_PKCS8_DEC_KEY_BEGIN, contents, 0, &start)) {
start_tag = PEM_PKCS8_DEC_KEY_BEGIN;
end_tag = PEM_PKCS8_DEC_KEY_END;
encrypted = FALSE;
} else {
g_set_error_literal (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Failed to find expected PKCS#8 start tag."));
return NULL;
}
start += strlen (start_tag);
if (!find_tag (end_tag, contents, start, &end)) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Failed to find expected PKCS#8 end tag '%s'."),
end_tag);
return NULL;
}
/* g_base64_decode() wants a NULL-terminated string */
save_end = contents->data[end];
contents->data[end] = '\0';
der = g_base64_decode ((const char *) (contents->data + start), &length);
contents->data[end] = save_end;
if (der && length) {
key = g_byte_array_sized_new (length);
g_byte_array_append (key, der, length);
g_assert (key->len == length);
*out_encrypted = encrypted;
} else {
g_set_error_literal (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_DECODE_FAILED,
_("Failed to decode PKCS#8 private key."));
}
g_free (der);
return key;
}
static GByteArray *
file_to_g_byte_array (const char *filename, GError **error)
{
char *contents;
GByteArray *array = NULL;
gsize length = 0;
if (g_file_get_contents (filename, &contents, &length, error)) {
array = g_byte_array_sized_new (length);
g_byte_array_append (array, (guint8 *) contents, length);
g_assert (array->len == length);
g_free (contents);
}
return array;
}
/*
* Convert a hex string into bytes.
*/
static char *
convert_iv (const char *src,
gsize *out_len,
GError **error)
{
int num;
int i;
char conv[3];
char *c;
g_return_val_if_fail (src != NULL, NULL);
num = strlen (src);
if (num % 2) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_RAW_IV_INVALID,
_("IV must be an even number of bytes in length."));
return NULL;
}
num /= 2;
c = g_malloc0 (num + 1);
conv[2] = '\0';
for (i = 0; i < num; i++) {
conv[0] = src[(i * 2)];
conv[1] = src[(i * 2) + 1];
if (!g_ascii_isxdigit (conv[0]) || !g_ascii_isxdigit (conv[1])) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_RAW_IV_INVALID,
_("IV contains non-hexadecimal digits."));
goto error;
}
c[i] = strtol(conv, NULL, 16);
}
*out_len = num;
return c;
error:
g_free (c);
return NULL;
}
static char *
make_des_aes_key (const char *cipher,
const char *salt,
const gsize salt_len,
const char *password,
gsize *out_len,
GError **error)
{
char *key;
guint32 digest_len;
g_return_val_if_fail (cipher != NULL, NULL);
g_return_val_if_fail (salt != NULL, NULL);
g_return_val_if_fail (salt_len >= 8, NULL);
g_return_val_if_fail (password != NULL, NULL);
g_return_val_if_fail (out_len != NULL, NULL);
if (!strcmp (cipher, "DES-EDE3-CBC"))
digest_len = 24;
else if (!strcmp (cipher, "DES-CBC"))
digest_len = 8;
else if (!strcmp (cipher, "AES-128-CBC"))
digest_len = 16;
else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_CIPHER,
_("Private key cipher '%s' was unknown."),
cipher);
return NULL;
}
if (password[0] == '\0')
return NULL;
key = g_malloc0 (digest_len + 1);
if (!crypto_md5_hash (salt,
salt_len,
password,
strlen (password),
key,
digest_len,
error))
goto error;
*out_len = digest_len;
return key;
error:
if (key) {
/* Don't leak stale key material */
memset (key, 0, digest_len);
g_free (key);
}
return NULL;
}
static GByteArray *
decrypt_key (const char *cipher,
int key_type,
GByteArray *data,
const char *iv,
const char *password,
GError **error)
{
char *bin_iv = NULL;
gsize bin_iv_len = 0;
char *key = NULL;
gsize key_len = 0;
char *output = NULL;
gsize decrypted_len = 0;
GByteArray *decrypted = NULL;
g_return_val_if_fail (password != NULL, NULL);
bin_iv = convert_iv (iv, &bin_iv_len, error);
if (!bin_iv)
return NULL;
/* Convert the password and IV into a DES or AES key */
key = make_des_aes_key (cipher, bin_iv, bin_iv_len, password, &key_len, error);
if (!key || !key_len)
goto out;
output = crypto_decrypt (cipher, key_type,
data,
bin_iv, bin_iv_len,
key, key_len,
&decrypted_len,
error);
if (output && decrypted_len) {
decrypted = g_byte_array_sized_new (decrypted_len);
g_byte_array_append (decrypted, (guint8 *) output, decrypted_len);
}
out:
/* Don't leak stale key material */
if (key)
memset (key, 0, key_len);
g_free (output);
g_free (key);
g_free (bin_iv);
return decrypted;
}
GByteArray *
crypto_decrypt_private_key_data (const GByteArray *contents,
const char *password,
NMCryptoKeyType *out_key_type,
GError **error)
{
GByteArray *decrypted = NULL;
NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_RSA;
GByteArray *data;
char *iv = NULL;
char *cipher = NULL;
g_return_val_if_fail (contents != NULL, NULL);
if (out_key_type)
g_return_val_if_fail (*out_key_type == NM_CRYPTO_KEY_TYPE_UNKNOWN, NULL);
/* OpenSSL non-standard legacy PEM files */
/* Try RSA keys first */
data = parse_old_openssl_key_file (contents, key_type, &cipher, &iv, error);
if (!data) {
g_clear_error (error);
/* DSA next */
key_type = NM_CRYPTO_KEY_TYPE_DSA;
data = parse_old_openssl_key_file (contents, key_type, &cipher, &iv, error);
if (!data) {
g_clear_error (error);
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Unable to determine private key type."));
}
}
if (data) {
/* return the key type even if decryption failed */
if (out_key_type)
*out_key_type = key_type;
if (password) {
decrypted = decrypt_key (cipher,
key_type,
data,
iv,
password,
error);
}
g_byte_array_free (data, TRUE);
}
g_free (cipher);
g_free (iv);
return decrypted;
}
GByteArray *
crypto_decrypt_private_key (const char *file,
const char *password,
NMCryptoKeyType *out_key_type,
GError **error)
{
GByteArray *contents;
GByteArray *key = NULL;
contents = file_to_g_byte_array (file, error);
if (contents) {
key = crypto_decrypt_private_key_data (contents, password, out_key_type, error);
g_byte_array_free (contents, TRUE);
}
return key;
}
static GByteArray *
extract_pem_cert_data (GByteArray *contents, GError **error)
{
GByteArray *cert = NULL;
gsize start = 0, end = 0;
unsigned char *der = NULL;
guint8 save_end;
gsize length = 0;
if (!find_tag (PEM_CERT_BEGIN, contents, 0, &start)) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("PEM certificate had no start tag '%s'."),
PEM_CERT_BEGIN);
goto done;
}
start += strlen (PEM_CERT_BEGIN);
if (!find_tag (PEM_CERT_END, contents, start, &end)) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("PEM certificate had no end tag '%s'."),
PEM_CERT_END);
goto done;
}
/* g_base64_decode() wants a NULL-terminated string */
save_end = contents->data[end];
contents->data[end] = '\0';
der = g_base64_decode ((const char *) (contents->data + start), &length);
contents->data[end] = save_end;
if (der && length) {
cert = g_byte_array_sized_new (length);
g_byte_array_append (cert, der, length);
g_assert (cert->len == length);
} else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_DECODE_FAILED,
_("Failed to decode certificate."));
}
done:
g_free (der);
return cert;
}
GByteArray *
crypto_load_and_verify_certificate (const char *file,
NMCryptoFileFormat *out_file_format,
GError **error)
{
GByteArray *array, *contents;
g_return_val_if_fail (file != NULL, NULL);
g_return_val_if_fail (out_file_format != NULL, NULL);
g_return_val_if_fail (*out_file_format == NM_CRYPTO_FILE_FORMAT_UNKNOWN, NULL);
contents = file_to_g_byte_array (file, error);
if (!contents)
return NULL;
/* Check for PKCS#12 */
if (crypto_is_pkcs12_data (contents)) {
*out_file_format = NM_CRYPTO_FILE_FORMAT_PKCS12;
return contents;
}
/* Check for plain DER format */
if (contents->len > 2 && contents->data[0] == 0x30 && contents->data[1] == 0x82) {
*out_file_format = crypto_verify_cert (contents->data, contents->len, error);
} else {
array = extract_pem_cert_data (contents, error);
if (!array) {
g_byte_array_free (contents, TRUE);
return NULL;
}
*out_file_format = crypto_verify_cert (array->data, array->len, error);
g_byte_array_free (array, TRUE);
}
if (*out_file_format != NM_CRYPTO_FILE_FORMAT_X509) {
g_byte_array_free (contents, TRUE);
contents = NULL;
}
return contents;
}
gboolean
crypto_is_pkcs12_data (const GByteArray *data)
{
GError *error = NULL;
gboolean success;
g_return_val_if_fail (data != NULL, FALSE);
success = crypto_verify_pkcs12 (data, NULL, &error);
if (success == FALSE) {
/* If the error was just a decryption error, then it's pkcs#12 */
if (error) {
if (g_error_matches (error, NM_CRYPTO_ERROR, NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED))
success = TRUE;
g_error_free (error);
}
}
return success;
}
gboolean
crypto_is_pkcs12_file (const char *file, GError **error)
{
GByteArray *contents;
gboolean success = FALSE;
g_return_val_if_fail (file != NULL, FALSE);
contents = file_to_g_byte_array (file, error);
if (contents) {
success = crypto_is_pkcs12_data (contents);
g_byte_array_free (contents, TRUE);
}
return success;
}
/* Verifies that a private key can be read, and if a password is given, that
* the private key can be decrypted with that password.
*/
NMCryptoFileFormat
crypto_verify_private_key_data (const GByteArray *contents,
const char *password,
GError **error)
{
GByteArray *tmp;
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
NMCryptoKeyType ktype = NM_CRYPTO_KEY_TYPE_UNKNOWN;
gboolean is_encrypted = FALSE;
g_return_val_if_fail (contents != NULL, FALSE);
/* Check for PKCS#12 first */
if (crypto_is_pkcs12_data (contents)) {
if (!password || crypto_verify_pkcs12 (contents, password, error))
format = NM_CRYPTO_FILE_FORMAT_PKCS12;
} else {
/* Maybe it's PKCS#8 */
tmp = parse_pkcs8_key_file (contents, &is_encrypted, error);
if (tmp) {
if (crypto_verify_pkcs8 (tmp, is_encrypted, password, error))
format = NM_CRYPTO_FILE_FORMAT_RAW_KEY;
} else {
g_clear_error (error);
/* Or it's old-style OpenSSL */
tmp = crypto_decrypt_private_key_data (contents, password, &ktype, error);
if (tmp)
format = NM_CRYPTO_FILE_FORMAT_RAW_KEY;
else if (!password && (ktype != NM_CRYPTO_KEY_TYPE_UNKNOWN))
format = NM_CRYPTO_FILE_FORMAT_RAW_KEY;
}
if (tmp) {
/* Don't leave decrypted key data around */
memset (tmp->data, 0, tmp->len);
g_byte_array_free (tmp, TRUE);
}
}
return format;
}
NMCryptoFileFormat
crypto_verify_private_key (const char *filename,
const char *password,
GError **error)
{
GByteArray *contents;
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
g_return_val_if_fail (filename != NULL, FALSE);
contents = file_to_g_byte_array (filename, error);
if (contents) {
format = crypto_verify_private_key_data (contents, password, error);
g_byte_array_free (contents, TRUE);
}
return format;
}

145
libnm-core/crypto.h Normal file
View File

@@ -0,0 +1,145 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Dan Williams <dcbw@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
*/
#ifndef __CRYPTO_H__
#define __CRYPTO_H__
#include <glib.h>
#define MD5_HASH_LEN 20
#define CIPHER_DES_EDE3_CBC "DES-EDE3-CBC"
#define CIPHER_DES_CBC "DES-CBC"
#define CIPHER_AES_CBC "AES-128-CBC"
enum {
NM_CRYPTO_ERR_NONE = 0,
NM_CRYPTO_ERR_INIT_FAILED,
NM_CRYPTO_ERR_CANT_READ_FILE,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
NM_CRYPTO_ERR_CERT_FORMAT_INVALID,
NM_CRYPTO_ERR_DECODE_FAILED,
NM_CRYPTO_ERR_OUT_OF_MEMORY,
NM_CRYPTO_ERR_UNKNOWN_KEY_TYPE,
NM_CRYPTO_ERR_UNKNOWN_CIPHER,
NM_CRYPTO_ERR_RAW_IV_INVALID,
NM_CRYPTO_ERR_MD5_INIT_FAILED,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
NM_CRYPTO_ERR_CIPHER_SET_KEY_FAILED,
NM_CRYPTO_ERR_CIPHER_SET_IV_FAILED,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
NM_CRYPTO_ERR_INVALID_PASSWORD,
NM_CRYPTO_ERR_CIPHER_ENCRYPT_FAILED,
NM_CRYPTO_ERR_RANDOMIZE_FAILED
};
typedef enum {
NM_CRYPTO_KEY_TYPE_UNKNOWN = 0,
NM_CRYPTO_KEY_TYPE_RSA,
NM_CRYPTO_KEY_TYPE_DSA
} NMCryptoKeyType;
typedef enum {
NM_CRYPTO_FILE_FORMAT_UNKNOWN = 0,
NM_CRYPTO_FILE_FORMAT_X509,
NM_CRYPTO_FILE_FORMAT_RAW_KEY,
NM_CRYPTO_FILE_FORMAT_PKCS12
} NMCryptoFileFormat;
#define NM_CRYPTO_ERROR _nm_crypto_error_quark ()
GQuark _nm_crypto_error_quark (void);
gboolean crypto_init (GError **error);
void crypto_deinit (void);
GByteArray *crypto_decrypt_private_key_data (const GByteArray *contents,
const char *password,
NMCryptoKeyType *out_key_type,
GError **error);
GByteArray *crypto_decrypt_private_key (const char *file,
const char *password,
NMCryptoKeyType *out_key_type,
GError **error);
GByteArray *crypto_load_and_verify_certificate (const char *file,
NMCryptoFileFormat *out_file_format,
GError **error);
gboolean crypto_is_pkcs12_file (const char *file, GError **error);
gboolean crypto_is_pkcs12_data (const GByteArray *data);
NMCryptoFileFormat crypto_verify_private_key_data (const GByteArray *contents,
const char *password,
GError **error);
NMCryptoFileFormat crypto_verify_private_key (const char *file,
const char *password,
GError **error);
/* Internal utils API bits for crypto providers */
gboolean crypto_md5_hash (const char *salt,
const gsize salt_len,
const char *password,
gsize password_len,
char *buffer,
gsize buflen,
GError **error);
char * crypto_decrypt (const char *cipher,
int key_type,
GByteArray *data,
const char *iv,
const gsize iv_len,
const char *key,
const gsize key_len,
gsize *out_len,
GError **error);
char * crypto_encrypt (const char *cipher,
const GByteArray *data,
const char *iv,
gsize iv_len,
const char *key,
gsize key_len,
gsize *out_len,
GError **error);
gboolean crypto_randomize (void *buffer, gsize buffer_len, GError **error);
NMCryptoFileFormat crypto_verify_cert (const unsigned char *data,
gsize len,
GError **error);
gboolean crypto_verify_pkcs12 (const GByteArray *data,
const char *password,
GError **error);
gboolean crypto_verify_pkcs8 (const GByteArray *data,
gboolean is_encrypted,
const char *password,
GError **error);
#endif /* __CRYPTO_H__ */

493
libnm-core/crypto_gnutls.c Normal file
View File

@@ -0,0 +1,493 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
*
* Dan Williams <dcbw@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2009 Red Hat, Inc.
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <gcrypt.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <gnutls/pkcs12.h>
#include "crypto.h"
#define SALT_LEN 8
static gboolean initialized = FALSE;
gboolean
crypto_init (GError **error)
{
if (initialized)
return TRUE;
if (gnutls_global_init() != 0) {
gnutls_global_deinit();
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_INIT_FAILED,
"%s",
_("Failed to initialize the crypto engine."));
return FALSE;
}
initialized = TRUE;
return TRUE;
}
void
crypto_deinit (void)
{
}
gboolean
crypto_md5_hash (const char *salt,
const gsize salt_len,
const char *password,
gsize password_len,
char *buffer,
gsize buflen,
GError **error)
{
gcry_md_hd_t ctx;
gcry_error_t err;
int nkey = buflen;
const gsize digest_len = 16;
int count = 0;
char digest[MD5_HASH_LEN];
char *p = buffer;
if (salt)
g_return_val_if_fail (salt_len >= SALT_LEN, FALSE);
g_return_val_if_fail (password != NULL, FALSE);
g_return_val_if_fail (password_len > 0, FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (buflen > 0, FALSE);
err = gcry_md_open (&ctx, GCRY_MD_MD5, 0);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_MD5_INIT_FAILED,
_("Failed to initialize the MD5 engine: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
return FALSE;
}
while (nkey > 0) {
int i = 0;
if (count++)
gcry_md_write (ctx, digest, digest_len);
gcry_md_write (ctx, password, password_len);
if (salt)
gcry_md_write (ctx, salt, SALT_LEN); /* Only use 8 bytes of salt */
gcry_md_final (ctx);
memcpy (digest, gcry_md_read (ctx, 0), digest_len);
gcry_md_reset (ctx);
while (nkey && (i < digest_len)) {
*(p++) = digest[i++];
nkey--;
}
}
memset (digest, 0, sizeof (digest));
gcry_md_close (ctx);
return TRUE;
}
char *
crypto_decrypt (const char *cipher,
int key_type,
GByteArray *data,
const char *iv,
const gsize iv_len,
const char *key,
const gsize key_len,
gsize *out_len,
GError **error)
{
gcry_cipher_hd_t ctx;
gcry_error_t err;
int cipher_mech, i;
char *output = NULL;
gboolean success = FALSE;
gsize pad_len, real_iv_len;
if (!strcmp (cipher, CIPHER_DES_EDE3_CBC)) {
cipher_mech = GCRY_CIPHER_3DES;
real_iv_len = SALT_LEN;
} else if (!strcmp (cipher, CIPHER_DES_CBC)) {
cipher_mech = GCRY_CIPHER_DES;
real_iv_len = SALT_LEN;
} else if (!strcmp (cipher, CIPHER_AES_CBC)) {
cipher_mech = GCRY_CIPHER_AES;
real_iv_len = 16;
} else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_CIPHER,
_("Private key cipher '%s' was unknown."),
cipher);
return NULL;
}
if (iv_len < real_iv_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_RAW_IV_INVALID,
_("Invalid IV length (must be at least %zd)."),
real_iv_len);
return NULL;
}
output = g_malloc0 (data->len);
err = gcry_cipher_open (&ctx, cipher_mech, GCRY_CIPHER_MODE_CBC, 0);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
_("Failed to initialize the decryption cipher context: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
err = gcry_cipher_setkey (ctx, key, key_len);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_KEY_FAILED,
_("Failed to set symmetric key for decryption: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
err = gcry_cipher_setiv (ctx, iv, iv_len);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_IV_FAILED,
_("Failed to set IV for decryption: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
err = gcry_cipher_decrypt (ctx, output, data->len, data->data, data->len);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
pad_len = output[data->len - 1];
/* Check if the padding at the end of the decrypted data is valid */
if (pad_len == 0 || pad_len > real_iv_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key: unexpected padding length."));
goto out;
}
/* Validate tail padding; last byte is the padding size, and all pad bytes
* should contain the padding size.
*/
for (i = 1; i <= pad_len; ++i) {
if (output[data->len - i] != pad_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key."));
goto out;
}
}
*out_len = data->len - pad_len;
success = TRUE;
out:
if (!success) {
if (output) {
/* Don't expose key material */
memset (output, 0, data->len);
g_free (output);
output = NULL;
}
}
gcry_cipher_close (ctx);
return output;
}
char *
crypto_encrypt (const char *cipher,
const GByteArray *data,
const char *iv,
const gsize iv_len,
const char *key,
gsize key_len,
gsize *out_len,
GError **error)
{
gcry_cipher_hd_t ctx;
gcry_error_t err;
int cipher_mech;
char *output = NULL;
gboolean success = FALSE;
gsize padded_buf_len, pad_len, output_len;
char *padded_buf = NULL;
guint32 i;
gsize salt_len;
if (!strcmp (cipher, CIPHER_DES_EDE3_CBC)) {
cipher_mech = GCRY_CIPHER_3DES;
salt_len = SALT_LEN;
} else if (!strcmp (cipher, CIPHER_AES_CBC)) {
cipher_mech = GCRY_CIPHER_AES;
salt_len = iv_len;
} else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_CIPHER,
_("Private key cipher '%s' was unknown."),
cipher);
return NULL;
}
/* If data->len % ivlen == 0, then we add another complete block
* onto the end so that the decrypter knows there's padding.
*/
pad_len = iv_len - (data->len % iv_len);
output_len = padded_buf_len = data->len + pad_len;
padded_buf = g_malloc0 (padded_buf_len);
memcpy (padded_buf, data->data, data->len);
for (i = 0; i < pad_len; i++)
padded_buf[data->len + i] = (guint8) (pad_len & 0xFF);
output = g_malloc0 (output_len);
err = gcry_cipher_open (&ctx, cipher_mech, GCRY_CIPHER_MODE_CBC, 0);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
_("Failed to initialize the encryption cipher context: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
err = gcry_cipher_setkey (ctx, key, key_len);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_KEY_FAILED,
_("Failed to set symmetric key for encryption: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
/* gcrypt only wants 8 bytes of the IV (same as the DES block length) */
err = gcry_cipher_setiv (ctx, iv, salt_len);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_IV_FAILED,
_("Failed to set IV for encryption: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
err = gcry_cipher_encrypt (ctx, output, output_len, padded_buf, padded_buf_len);
if (err) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to encrypt the data: %s / %s."),
gcry_strsource (err), gcry_strerror (err));
goto out;
}
*out_len = output_len;
success = TRUE;
out:
if (padded_buf) {
memset (padded_buf, 0, padded_buf_len);
g_free (padded_buf);
padded_buf = NULL;
}
if (!success) {
if (output) {
/* Don't expose key material */
memset (output, 0, output_len);
g_free (output);
output = NULL;
}
}
gcry_cipher_close (ctx);
return output;
}
NMCryptoFileFormat
crypto_verify_cert (const unsigned char *data,
gsize len,
GError **error)
{
gnutls_x509_crt_t der;
gnutls_datum_t dt;
int err;
err = gnutls_x509_crt_init (&der);
if (err < 0) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CERT_FORMAT_INVALID,
_("Error initializing certificate data: %s"),
gnutls_strerror (err));
return NM_CRYPTO_FILE_FORMAT_UNKNOWN;
}
/* Try DER first */
dt.data = (unsigned char *) data;
dt.size = len;
err = gnutls_x509_crt_import (der, &dt, GNUTLS_X509_FMT_DER);
if (err == GNUTLS_E_SUCCESS) {
gnutls_x509_crt_deinit (der);
return NM_CRYPTO_FILE_FORMAT_X509;
}
/* And PEM next */
err = gnutls_x509_crt_import (der, &dt, GNUTLS_X509_FMT_PEM);
gnutls_x509_crt_deinit (der);
if (err == GNUTLS_E_SUCCESS)
return NM_CRYPTO_FILE_FORMAT_X509;
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CERT_FORMAT_INVALID,
_("Couldn't decode certificate: %s"),
gnutls_strerror (err));
return NM_CRYPTO_FILE_FORMAT_UNKNOWN;
}
gboolean
crypto_verify_pkcs12 (const GByteArray *data,
const char *password,
GError **error)
{
gnutls_pkcs12_t p12;
gnutls_datum_t dt;
gboolean success = FALSE;
int err;
g_return_val_if_fail (data != NULL, FALSE);
dt.data = (unsigned char *) data->data;
dt.size = data->len;
err = gnutls_pkcs12_init (&p12);
if (err < 0) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_DECODE_FAILED,
_("Couldn't initialize PKCS#12 decoder: %s"),
gnutls_strerror (err));
return FALSE;
}
/* DER first */
err = gnutls_pkcs12_import (p12, &dt, GNUTLS_X509_FMT_DER, 0);
if (err < 0) {
/* PEM next */
err = gnutls_pkcs12_import (p12, &dt, GNUTLS_X509_FMT_PEM, 0);
if (err < 0) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Couldn't decode PKCS#12 file: %s"),
gnutls_strerror (err));
goto out;
}
}
err = gnutls_pkcs12_verify_mac (p12, password);
if (err == GNUTLS_E_SUCCESS)
success = TRUE;
else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Couldn't verify PKCS#12 file: %s"),
gnutls_strerror (err));
}
out:
gnutls_pkcs12_deinit (p12);
return success;
}
gboolean
crypto_verify_pkcs8 (const GByteArray *data,
gboolean is_encrypted,
const char *password,
GError **error)
{
gnutls_x509_privkey_t p8;
gnutls_datum_t dt;
int err;
g_return_val_if_fail (data != NULL, FALSE);
dt.data = (unsigned char *) data->data;
dt.size = data->len;
err = gnutls_x509_privkey_init (&p8);
if (err < 0) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_DECODE_FAILED,
_("Couldn't initialize PKCS#8 decoder: %s"),
gnutls_strerror (err));
return FALSE;
}
err = gnutls_x509_privkey_import_pkcs8 (p8,
&dt,
GNUTLS_X509_FMT_DER,
is_encrypted ? password : NULL,
is_encrypted ? 0 : GNUTLS_PKCS_PLAIN);
gnutls_x509_privkey_deinit (p8);
if (err < 0) {
if (err == GNUTLS_E_UNKNOWN_CIPHER_TYPE) {
/* HACK: gnutls doesn't support all the cipher types that openssl
* can use with PKCS#8, so if we encounter one, we have to assume
* the given password works. gnutls needs to unsuckify, apparently.
* Specifically, by default openssl uses pbeWithMD5AndDES-CBC
* which gnutls does not support.
*/
} else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Couldn't decode PKCS#8 file: %s"),
gnutls_strerror (err));
return FALSE;
}
}
return TRUE;
}
gboolean
crypto_randomize (void *buffer, gsize buffer_len, GError **error)
{
gcry_randomize (buffer, buffer_len, GCRY_STRONG_RANDOM);
return TRUE;
}

562
libnm-core/crypto_nss.c Normal file
View File

@@ -0,0 +1,562 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Dan Williams <dcbw@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2009 Red Hat, Inc.
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <prinit.h>
#include <nss.h>
#include <pk11pub.h>
#include <pkcs11t.h>
#include <cert.h>
#include <prerror.h>
#include <p12.h>
#include <ciferfam.h>
#include <p12plcy.h>
#include "crypto.h"
static gboolean initialized = FALSE;
gboolean
crypto_init (GError **error)
{
SECStatus ret;
if (initialized)
return TRUE;
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 1);
ret = NSS_NoDB_Init (NULL);
if (ret != SECSuccess) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_INIT_FAILED,
_("Failed to initialize the crypto engine: %d."),
PR_GetError ());
PR_Cleanup ();
return FALSE;
}
SEC_PKCS12EnableCipher(PKCS12_RC4_40, 1);
SEC_PKCS12EnableCipher(PKCS12_RC4_128, 1);
SEC_PKCS12EnableCipher(PKCS12_RC2_CBC_40, 1);
SEC_PKCS12EnableCipher(PKCS12_RC2_CBC_128, 1);
SEC_PKCS12EnableCipher(PKCS12_DES_56, 1);
SEC_PKCS12EnableCipher(PKCS12_DES_EDE3_168, 1);
SEC_PKCS12SetPreferredCipher(PKCS12_DES_EDE3_168, 1);
initialized = TRUE;
return TRUE;
}
void
crypto_deinit (void)
{
}
gboolean
crypto_md5_hash (const char *salt,
const gsize salt_len,
const char *password,
gsize password_len,
char *buffer,
gsize buflen,
GError **error)
{
PK11Context *ctx;
int nkey = buflen;
unsigned int digest_len;
int count = 0;
char digest[MD5_HASH_LEN];
char *p = buffer;
if (salt)
g_return_val_if_fail (salt_len >= 8, FALSE);
g_return_val_if_fail (password != NULL, FALSE);
g_return_val_if_fail (password_len > 0, FALSE);
g_return_val_if_fail (buffer != NULL, FALSE);
g_return_val_if_fail (buflen > 0, FALSE);
ctx = PK11_CreateDigestContext (SEC_OID_MD5);
if (!ctx) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_MD5_INIT_FAILED,
_("Failed to initialize the MD5 context: %d."),
PORT_GetError ());
return FALSE;
}
while (nkey > 0) {
int i = 0;
PK11_DigestBegin (ctx);
if (count++)
PK11_DigestOp (ctx, (const unsigned char *) digest, digest_len);
PK11_DigestOp (ctx, (const unsigned char *) password, password_len);
if (salt)
PK11_DigestOp (ctx, (const unsigned char *) salt, 8); /* Only use 8 bytes of salt */
PK11_DigestFinal (ctx, (unsigned char *) digest, &digest_len, sizeof (digest));
while (nkey && (i < digest_len)) {
*(p++) = digest[i++];
nkey--;
}
}
memset (digest, 0, sizeof (digest));
PK11_DestroyContext (ctx, PR_TRUE);
return TRUE;
}
char *
crypto_decrypt (const char *cipher,
int key_type,
GByteArray *data,
const char *iv,
const gsize iv_len,
const char *key,
const gsize key_len,
gsize *out_len,
GError **error)
{
char *output = NULL;
int decrypted_len = 0;
CK_MECHANISM_TYPE cipher_mech;
PK11SlotInfo *slot = NULL;
SECItem key_item;
PK11SymKey *sym_key = NULL;
SECItem *sec_param = NULL;
PK11Context *ctx = NULL;
SECStatus s;
gboolean success = FALSE;
unsigned int pad_len = 0, extra = 0;
guint32 i, real_iv_len = 0;
if (!strcmp (cipher, CIPHER_DES_EDE3_CBC)) {
cipher_mech = CKM_DES3_CBC_PAD;
real_iv_len = 8;
} else if (!strcmp (cipher, CIPHER_DES_CBC)) {
cipher_mech = CKM_DES_CBC_PAD;
real_iv_len = 8;
} else if (!strcmp (cipher, CIPHER_AES_CBC)) {
cipher_mech = CKM_AES_CBC_PAD;
real_iv_len = 16;
} else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_CIPHER,
_("Private key cipher '%s' was unknown."),
cipher);
return NULL;
}
if (iv_len < real_iv_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_RAW_IV_INVALID,
_("Invalid IV length (must be at least %d)."),
real_iv_len);
return NULL;
}
output = g_malloc0 (data->len);
slot = PK11_GetBestSlot (cipher_mech, NULL);
if (!slot) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
_("Failed to initialize the decryption cipher slot."));
goto out;
}
key_item.data = (unsigned char *) key;
key_item.len = key_len;
sym_key = PK11_ImportSymKey (slot, cipher_mech, PK11_OriginUnwrap, CKA_DECRYPT, &key_item, NULL);
if (!sym_key) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_KEY_FAILED,
_("Failed to set symmetric key for decryption."));
goto out;
}
key_item.data = (unsigned char *) iv;
key_item.len = real_iv_len;
sec_param = PK11_ParamFromIV (cipher_mech, &key_item);
if (!sec_param) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_IV_FAILED,
_("Failed to set IV for decryption."));
goto out;
}
ctx = PK11_CreateContextBySymKey (cipher_mech, CKA_DECRYPT, sym_key, sec_param);
if (!ctx) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
_("Failed to initialize the decryption context."));
goto out;
}
s = PK11_CipherOp (ctx,
(unsigned char *) output,
&decrypted_len,
data->len,
data->data,
data->len);
if (s != SECSuccess) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key: %d."),
PORT_GetError ());
goto out;
}
if (decrypted_len > data->len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key: decrypted data too large."));
goto out;
}
s = PK11_DigestFinal (ctx,
(unsigned char *) (output + decrypted_len),
&extra,
data->len - decrypted_len);
if (s != SECSuccess) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to finalize decryption of the private key: %d."),
PORT_GetError ());
goto out;
}
decrypted_len += extra;
pad_len = data->len - decrypted_len;
/* Check if the padding at the end of the decrypted data is valid */
if (pad_len == 0 || pad_len > real_iv_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key: unexpected padding length."));
goto out;
}
/* Validate tail padding; last byte is the padding size, and all pad bytes
* should contain the padding size.
*/
for (i = pad_len; i > 0; i--) {
if (output[data->len - i] != pad_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Failed to decrypt the private key."));
goto out;
}
}
*out_len = decrypted_len;
success = TRUE;
out:
if (ctx)
PK11_DestroyContext (ctx, PR_TRUE);
if (sym_key)
PK11_FreeSymKey (sym_key);
if (sec_param)
SECITEM_FreeItem (sec_param, PR_TRUE);
if (slot)
PK11_FreeSlot (slot);
if (!success) {
if (output) {
/* Don't expose key material */
memset (output, 0, data->len);
g_free (output);
output = NULL;
}
}
return output;
}
char *
crypto_encrypt (const char *cipher,
const GByteArray *data,
const char *iv,
gsize iv_len,
const char *key,
gsize key_len,
gsize *out_len,
GError **error)
{
SECStatus ret;
CK_MECHANISM_TYPE cipher_mech = CKM_DES3_CBC_PAD;
PK11SlotInfo *slot = NULL;
SECItem key_item = { .data = (unsigned char *) key, .len = key_len };
SECItem iv_item = { .data = (unsigned char *) iv, .len = iv_len };
PK11SymKey *sym_key = NULL;
SECItem *sec_param = NULL;
PK11Context *ctx = NULL;
unsigned char *output, *padded_buf;
gsize output_len;
int encrypted_len = 0, i;
gboolean success = FALSE;
gsize padded_buf_len, pad_len;
if (!strcmp (cipher, CIPHER_DES_EDE3_CBC))
cipher_mech = CKM_DES3_CBC_PAD;
else if (!strcmp (cipher, CIPHER_AES_CBC))
cipher_mech = CKM_AES_CBC_PAD;
else {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_UNKNOWN_CIPHER,
_("Private key cipher '%s' was unknown."),
cipher);
return NULL;
}
/* If data->len % ivlen == 0, then we add another complete block
* onto the end so that the decrypter knows there's padding.
*/
pad_len = iv_len - (data->len % iv_len);
output_len = padded_buf_len = data->len + pad_len;
padded_buf = g_malloc0 (padded_buf_len);
memcpy (padded_buf, data->data, data->len);
for (i = 0; i < pad_len; i++)
padded_buf[data->len + i] = (guint8) (pad_len & 0xFF);
output = g_malloc0 (output_len);
slot = PK11_GetBestSlot (cipher_mech, NULL);
if (!slot) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
_("Failed to initialize the encryption cipher slot."));
goto out;
}
sym_key = PK11_ImportSymKey (slot, cipher_mech, PK11_OriginUnwrap, CKA_ENCRYPT, &key_item, NULL);
if (!sym_key) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_KEY_FAILED,
_("Failed to set symmetric key for encryption."));
goto out;
}
sec_param = PK11_ParamFromIV (cipher_mech, &iv_item);
if (!sec_param) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_SET_IV_FAILED,
_("Failed to set IV for encryption."));
goto out;
}
ctx = PK11_CreateContextBySymKey (cipher_mech, CKA_ENCRYPT, sym_key, sec_param);
if (!ctx) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_INIT_FAILED,
_("Failed to initialize the encryption context."));
goto out;
}
ret = PK11_CipherOp (ctx, output, &encrypted_len, output_len, padded_buf, padded_buf_len);
if (ret != SECSuccess) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_ENCRYPT_FAILED,
_("Failed to encrypt: %d."),
PORT_GetError ());
goto out;
}
if (encrypted_len != output_len) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_ENCRYPT_FAILED,
_("Unexpected amount of data after encrypting."));
goto out;
}
*out_len = encrypted_len;
success = TRUE;
out:
if (ctx)
PK11_DestroyContext (ctx, PR_TRUE);
if (sym_key)
PK11_FreeSymKey (sym_key);
if (sec_param)
SECITEM_FreeItem (sec_param, PR_TRUE);
if (slot)
PK11_FreeSlot (slot);
memset (padded_buf, 0, padded_buf_len);
g_free (padded_buf);
if (!success) {
memset (output, 0, output_len);
g_free (output);
output = NULL;
}
return (char *) output;
}
NMCryptoFileFormat
crypto_verify_cert (const unsigned char *data,
gsize len,
GError **error)
{
CERTCertificate *cert;
/* Try DER/PEM first */
cert = CERT_DecodeCertFromPackage ((char *) data, len);
if (!cert) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CERT_FORMAT_INVALID,
_("Couldn't decode certificate: %d"),
PORT_GetError());
return NM_CRYPTO_FILE_FORMAT_UNKNOWN;
}
CERT_DestroyCertificate (cert);
return NM_CRYPTO_FILE_FORMAT_X509;
}
gboolean
crypto_verify_pkcs12 (const GByteArray *data,
const char *password,
GError **error)
{
SEC_PKCS12DecoderContext *p12ctx = NULL;
SECItem pw = { 0 };
PK11SlotInfo *slot = NULL;
SECStatus s;
char *ucs2_password;
glong ucs2_chars = 0;
#ifndef WORDS_BIGENDIAN
guint16 *p;
#endif /* WORDS_BIGENDIAN */
if (error)
g_return_val_if_fail (*error == NULL, FALSE);
/* PKCS#12 passwords are apparently UCS2 BIG ENDIAN, and NSS doesn't do
* any conversions for us.
*/
if (password && strlen (password)) {
ucs2_password = (char *) g_utf8_to_utf16 (password, strlen (password), NULL, &ucs2_chars, NULL);
if (!ucs2_password || !ucs2_chars) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_INVALID_PASSWORD,
_("Couldn't convert password to UCS2: %d"),
PORT_GetError());
return FALSE;
}
ucs2_chars *= 2; /* convert # UCS2 characters -> bytes */
pw.data = PORT_ZAlloc(ucs2_chars + 2);
memcpy (pw.data, ucs2_password, ucs2_chars);
pw.len = ucs2_chars + 2; /* include terminating NULL */
memset (ucs2_password, 0, ucs2_chars);
g_free (ucs2_password);
#ifndef WORDS_BIGENDIAN
for (p = (guint16 *) pw.data; p < (guint16 *) (pw.data + pw.len); p++)
*p = GUINT16_SWAP_LE_BE (*p);
#endif /* WORDS_BIGENDIAN */
} else {
/* NULL password */
pw.data = NULL;
pw.len = 0;
}
slot = PK11_GetInternalKeySlot();
p12ctx = SEC_PKCS12DecoderStart (&pw, slot, NULL, NULL, NULL, NULL, NULL, NULL);
if (!p12ctx) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_DECODE_FAILED,
_("Couldn't initialize PKCS#12 decoder: %d"),
PORT_GetError());
goto error;
}
s = SEC_PKCS12DecoderUpdate (p12ctx, data->data, data->len);
if (s != SECSuccess) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_FILE_FORMAT_INVALID,
_("Couldn't decode PKCS#12 file: %d"),
PORT_GetError());
goto error;
}
s = SEC_PKCS12DecoderVerify (p12ctx);
if (s != SECSuccess) {
g_set_error (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_CIPHER_DECRYPT_FAILED,
_("Couldn't verify PKCS#12 file: %d"),
PORT_GetError());
goto error;
}
SEC_PKCS12DecoderFinish (p12ctx);
SECITEM_ZfreeItem (&pw, PR_FALSE);
return TRUE;
error:
if (p12ctx)
SEC_PKCS12DecoderFinish (p12ctx);
if (slot)
PK11_FreeSlot(slot);
SECITEM_ZfreeItem (&pw, PR_FALSE);
return FALSE;
}
gboolean
crypto_verify_pkcs8 (const GByteArray *data,
gboolean is_encrypted,
const char *password,
GError **error)
{
g_return_val_if_fail (data != NULL, FALSE);
/* NSS apparently doesn't do PKCS#8 natively, but you have to put the
* PKCS#8 key into a PKCS#12 file and import that?? So until we figure
* all that out, we can only assume the password is valid.
*/
return TRUE;
}
gboolean
crypto_randomize (void *buffer, gsize buffer_len, GError **error)
{
SECStatus s;
s = PK11_GenerateRandom (buffer, buffer_len);
if (s != SECSuccess) {
g_set_error_literal (error, NM_CRYPTO_ERROR,
NM_CRYPTO_ERR_RANDOMIZE_FAILED,
_("Could not generate random data."));
return FALSE;
}
return TRUE;
}

2189
libnm-core/nm-connection.c Normal file

File diff suppressed because it is too large Load Diff

256
libnm-core/nm-connection.h Normal file
View File

@@ -0,0 +1,256 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_CONNECTION_H
#define NM_CONNECTION_H
#include <glib.h>
#include <glib-object.h>
#include <nm-setting.h>
#include <nm-setting-8021x.h>
#include <nm-setting-bluetooth.h>
#include <nm-setting-bond.h>
#include <nm-setting-team.h>
#include <nm-setting-team-port.h>
#include <nm-setting-bridge.h>
#include <nm-setting-bridge-port.h>
#include <nm-setting-cdma.h>
#include <nm-setting-connection.h>
#include <nm-setting-dcb.h>
#include <nm-setting-generic.h>
#include <nm-setting-gsm.h>
#include <nm-setting-infiniband.h>
#include <nm-setting-ip4-config.h>
#include <nm-setting-ip6-config.h>
#include <nm-setting-olpc-mesh.h>
#include <nm-setting-ppp.h>
#include <nm-setting-pppoe.h>
#include <nm-setting-serial.h>
#include <nm-setting-vpn.h>
#include <nm-setting-wimax.h>
#include <nm-setting-wired.h>
#include <nm-setting-adsl.h>
#include <nm-setting-wireless.h>
#include <nm-setting-wireless-security.h>
#include <nm-setting-vlan.h>
G_BEGIN_DECLS
#define NM_TYPE_CONNECTION (nm_connection_get_type ())
#define NM_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION, NMConnection))
#define NM_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CONNECTION, NMConnectionClass))
#define NM_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION))
#define NM_IS_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CONNECTION))
#define NM_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CONNECTION, NMConnectionClass))
/* Signals */
#define NM_CONNECTION_SECRETS_UPDATED "secrets-updated"
#define NM_CONNECTION_SECRETS_CLEARED "secrets-cleared"
#define NM_CONNECTION_CHANGED "changed"
/* Properties */
#define NM_CONNECTION_PATH "path"
/**
* NMConnectionError:
* @NM_CONNECTION_ERROR_UNKNOWN: unknown or unclassified error
* @NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND: the #NMConnection object
* did not contain the required #NMSettingConnection object, which must be
* present for all connections
* @NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID: the 'type' property of the
* 'connection' setting did not point to a valid connection base type; ie
* it was not a hardware-related setting like #NMSettingWired or
* #NMSettingWireless.
* @NM_CONNECTION_ERROR_SETTING_NOT_FOUND: the #NMConnection object
* did not contain the specified #NMSetting object
*@NM_CONNECTION_ERROR_INVALID_SETTING: the #NMConnection object contains
* a conflicting setting object
*
* Describes errors that may result from operations involving a #NMConnection.
*
**/
typedef enum
{
NM_CONNECTION_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND, /*< nick=ConnectionSettingNotFound >*/
NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID, /*< nick=ConnectionTypeInvalid >*/
NM_CONNECTION_ERROR_SETTING_NOT_FOUND, /*< nick=SettingNotFound >*/
NM_CONNECTION_ERROR_INVALID_SETTING, /*< nick=InvalidSetting >*/
} NMConnectionError;
/*
* NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD: overwrite the ip6 method
* when normalizing ip6 configuration. If omited, this defaults to
* @NM_SETTING_IP6_CONFIG_METHOD_AUTO.
*/
#define NM_CONNECTION_NORMALIZE_PARAM_IP6_CONFIG_METHOD "ip6-config-method"
#define NM_CONNECTION_ERROR nm_connection_error_quark ()
GQuark nm_connection_error_quark (void);
/**
* NMConnection:
*
* The NMConnection struct contains only private data.
* It should only be accessed through the functions described below.
*/
typedef struct {
GObject parent;
} NMConnection;
typedef struct {
GObjectClass parent;
/* Signals */
void (*secrets_updated) (NMConnection *connection, const char * setting);
} NMConnectionClass;
GType nm_connection_get_type (void);
NMConnection *nm_connection_new (void);
NMConnection *nm_connection_new_from_hash (GHashTable *hash, GError **error);
NMConnection *nm_connection_duplicate (NMConnection *connection);
NMSetting *nm_connection_create_setting (const char *name);
void nm_connection_add_setting (NMConnection *connection,
NMSetting *setting);
void nm_connection_remove_setting (NMConnection *connection,
GType setting_type);
NMSetting *nm_connection_get_setting (NMConnection *connection,
GType setting_type);
NMSetting *nm_connection_get_setting_by_name (NMConnection *connection,
const char *name);
gboolean nm_connection_replace_settings (NMConnection *connection,
GHashTable *new_settings,
GError **error);
NM_AVAILABLE_IN_0_9_10
gboolean nm_connection_replace_settings_from_connection (NMConnection *connection,
NMConnection *new_connection,
GError **error);
gboolean nm_connection_compare (NMConnection *a,
NMConnection *b,
NMSettingCompareFlags flags);
gboolean nm_connection_diff (NMConnection *a,
NMConnection *b,
NMSettingCompareFlags flags,
GHashTable **out_settings);
gboolean nm_connection_verify (NMConnection *connection, GError **error);
NM_AVAILABLE_IN_1_0
gboolean nm_connection_normalize (NMConnection *connection,
GHashTable *parameters,
gboolean *modified,
GError **error);
const char * nm_connection_need_secrets (NMConnection *connection,
GPtrArray **hints);
void nm_connection_clear_secrets (NMConnection *connection);
void nm_connection_clear_secrets_with_flags (NMConnection *connection,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data);
gboolean nm_connection_update_secrets (NMConnection *connection,
const char *setting_name,
GHashTable *secrets,
GError **error);
void nm_connection_set_path (NMConnection *connection,
const char *path);
const char * nm_connection_get_path (NMConnection *connection);
const char * nm_connection_get_virtual_iface_name (NMConnection *connection);
NM_AVAILABLE_IN_1_0
const char * nm_connection_get_interface_name (NMConnection *connection);
gboolean nm_connection_is_type (NMConnection *connection, const char *type);
void nm_connection_for_each_setting_value (NMConnection *connection,
NMSettingValueIterFn func,
gpointer user_data);
GHashTable *nm_connection_to_hash (NMConnection *connection,
NMSettingHashFlags flags);
void nm_connection_dump (NMConnection *connection);
GType nm_connection_lookup_setting_type (const char *name);
GType nm_connection_lookup_setting_type_by_quark (GQuark error_quark);
/* Helpers */
const char * nm_connection_get_uuid (NMConnection *connection);
const char * nm_connection_get_id (NMConnection *connection);
NM_AVAILABLE_IN_0_9_10
const char * nm_connection_get_connection_type (NMConnection *connection);
NM_AVAILABLE_IN_0_9_10
char * nm_connection_get_virtual_device_description (NMConnection *connection);
NMSetting8021x * nm_connection_get_setting_802_1x (NMConnection *connection);
NMSettingBluetooth * nm_connection_get_setting_bluetooth (NMConnection *connection);
NMSettingBond * nm_connection_get_setting_bond (NMConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMSettingTeam * nm_connection_get_setting_team (NMConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMSettingTeamPort * nm_connection_get_setting_team_port (NMConnection *connection);
NMSettingBridge * nm_connection_get_setting_bridge (NMConnection *connection);
NMSettingBridgePort * nm_connection_get_setting_bridge_port (NMConnection *connection);
NMSettingCdma * nm_connection_get_setting_cdma (NMConnection *connection);
NMSettingConnection * nm_connection_get_setting_connection (NMConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMSettingDcb * nm_connection_get_setting_dcb (NMConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMSettingGeneric * nm_connection_get_setting_generic (NMConnection *connection);
NMSettingGsm * nm_connection_get_setting_gsm (NMConnection *connection);
NMSettingInfiniband * nm_connection_get_setting_infiniband (NMConnection *connection);
NMSettingIP4Config * nm_connection_get_setting_ip4_config (NMConnection *connection);
NMSettingIP6Config * nm_connection_get_setting_ip6_config (NMConnection *connection);
NMSettingOlpcMesh * nm_connection_get_setting_olpc_mesh (NMConnection *connection);
NMSettingPPP * nm_connection_get_setting_ppp (NMConnection *connection);
NMSettingPPPOE * nm_connection_get_setting_pppoe (NMConnection *connection);
NMSettingSerial * nm_connection_get_setting_serial (NMConnection *connection);
NMSettingVPN * nm_connection_get_setting_vpn (NMConnection *connection);
NMSettingWimax * nm_connection_get_setting_wimax (NMConnection *connection);
NMSettingAdsl * nm_connection_get_setting_adsl (NMConnection *connection);
NMSettingWired * nm_connection_get_setting_wired (NMConnection *connection);
NMSettingWireless * nm_connection_get_setting_wireless (NMConnection *connection);
NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security (NMConnection *connection);
NMSettingVlan * nm_connection_get_setting_vlan (NMConnection *connection);
G_END_DECLS
#endif /* NM_CONNECTION_H */

View File

@@ -0,0 +1,972 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include "nm-param-spec-specialized.h"
#include "nm-glib-compat.h"
struct _NMParamSpecSpecialized {
GParamSpec parent;
};
#include <string.h>
#include <math.h>
#include <netinet/in.h>
#include <dbus/dbus-glib.h>
#include "nm-dbus-glib-types.h"
/***********************************************************/
/* _gvalues_compare */
static gint _gvalues_compare (const GValue *value1, const GValue *value2);
static gboolean
type_is_fixed_size (GType type, gsize *tsize)
{
switch (type) {
case G_TYPE_CHAR:
if (tsize) *tsize = sizeof (char);
return TRUE;
case G_TYPE_UCHAR:
if (tsize) *tsize = sizeof (guchar);
return TRUE;
case G_TYPE_BOOLEAN:
if (tsize) *tsize = sizeof (gboolean);
return TRUE;
case G_TYPE_LONG:
if (tsize) *tsize = sizeof (glong);
return TRUE;
case G_TYPE_ULONG:
if (tsize) *tsize = sizeof (gulong);
return TRUE;
case G_TYPE_INT:
if (tsize) *tsize = sizeof (gint);
return TRUE;
case G_TYPE_UINT:
if (tsize) *tsize = sizeof (guint);
return TRUE;
case G_TYPE_INT64:
if (tsize) *tsize = sizeof (gint64);
return TRUE;
case G_TYPE_UINT64:
if (tsize) *tsize = sizeof (guint64);
return TRUE;
case G_TYPE_FLOAT:
if (tsize) *tsize = sizeof (gfloat);
return TRUE;
case G_TYPE_DOUBLE:
if (tsize) *tsize = sizeof (gdouble);
return TRUE;
default:
return FALSE;
}
}
#define FLOAT_FACTOR 0.00000001
static gint
_gvalues_compare_fixed (const GValue *value1, const GValue *value2)
{
int ret = 0;
switch (G_VALUE_TYPE (value1)) {
case G_TYPE_CHAR: {
gchar val1 = g_value_get_schar (value1);
gchar val2 = g_value_get_schar (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_UCHAR: {
guchar val1 = g_value_get_uchar (value1);
guchar val2 = g_value_get_uchar (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_BOOLEAN: {
gboolean val1 = g_value_get_boolean (value1);
gboolean val2 = g_value_get_boolean (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_LONG: {
glong val1 = g_value_get_long (value1);
glong val2 = g_value_get_long (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_ULONG: {
gulong val1 = g_value_get_ulong (value1);
gulong val2 = g_value_get_ulong (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_INT: {
gint val1 = g_value_get_int (value1);
gint val2 = g_value_get_int (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_UINT: {
guint val1 = g_value_get_uint (value1);
guint val2 = g_value_get_uint (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_INT64: {
gint64 val1 = g_value_get_int64 (value1);
gint64 val2 = g_value_get_int64 (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_UINT64: {
guint64 val1 = g_value_get_uint64 (value1);
guint64 val2 = g_value_get_uint64 (value2);
if (val1 != val2)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_FLOAT: {
gfloat val1 = g_value_get_float (value1);
gfloat val2 = g_value_get_float (value2);
/* Can't use == or != here due to inexactness of FP */
if (fabsf (val1 - val2) > FLOAT_FACTOR)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
case G_TYPE_DOUBLE: {
gdouble val1 = g_value_get_double (value1);
gdouble val2 = g_value_get_double (value2);
if (fabs (val1 - val2) > FLOAT_FACTOR)
ret = val1 < val2 ? -1 : val1 > val2;
break;
}
default:
g_warning ("Unhandled fixed size type '%s'", G_VALUE_TYPE_NAME (value1));
}
return ret;
}
static gint
_gvalues_compare_string (const GValue *value1, const GValue *value2)
{
const char *str1 = g_value_get_string (value1);
const char *str2 = g_value_get_string (value2);
if (str1 == str2)
return 0;
if (!str1)
return 1;
if (!str2)
return -1;
return strcmp (str1, str2);
}
static gint
_gvalues_compare_strv (const GValue *value1, const GValue *value2)
{
char **strv1;
char **strv2;
gint ret;
guint i = 0;
strv1 = (char **) g_value_get_boxed (value1);
strv2 = (char **) g_value_get_boxed (value2);
while (strv1[i] && strv2[i]) {
ret = strcmp (strv1[i], strv2[i]);
if (ret)
return ret;
i++;
}
if (strv1[i] == NULL && strv2[i] == NULL)
return 0;
if (strv1[i])
return 1;
return -1;
}
static void
_gvalue_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static GValue *
_gvalue_dup (const GValue *value)
{
GValue *dup;
dup = g_slice_new0 (GValue);
g_value_init (dup, G_VALUE_TYPE (value));
g_value_copy (value, dup);
return dup;
}
static void
iterate_collection (const GValue *value, gpointer user_data)
{
GSList **list = (GSList **) user_data;
*list = g_slist_prepend (*list, _gvalue_dup (value));
}
static gint
_gvalues_compare_collection (const GValue *value1, const GValue *value2)
{
gint ret;
guint len1;
guint len2;
GType value_type = dbus_g_type_get_collection_specialization (G_VALUE_TYPE (value1));
gsize element_size = 0;
if (type_is_fixed_size (value_type, &element_size)) {
gpointer data1 = NULL;
gpointer data2 = NULL;
dbus_g_type_collection_get_fixed ((GValue *) value1, &data1, &len1);
dbus_g_type_collection_get_fixed ((GValue *) value2, &data2, &len2);
if (len1 != len2)
ret = len1 < len2 ? -1 : len1 > len2;
else
ret = memcmp (data1, data2, len1 * element_size);
} else {
GSList *list1 = NULL;
GSList *list2 = NULL;
dbus_g_type_collection_value_iterate (value1, iterate_collection, &list1);
len1 = g_slist_length (list1);
dbus_g_type_collection_value_iterate (value2, iterate_collection, &list2);
len2 = g_slist_length (list2);
if (len1 != len2)
ret = len1 < len2 ? -1 : len1 > len2;
else {
GSList *iter1;
GSList *iter2;
for (iter1 = list1, iter2 = list2, ret = 0;
ret == 0 && iter1 && iter2;
iter1 = iter1->next, iter2 = iter2->next)
ret = _gvalues_compare ((GValue *) iter1->data, (GValue *) iter2->data);
}
g_slist_free_full (list1, _gvalue_destroy);
g_slist_free_full (list2, _gvalue_destroy);
}
return ret;
}
static void
iterate_map (const GValue *key_val,
const GValue *value_val,
gpointer user_data)
{
GHashTable **hash = (GHashTable **) user_data;
g_hash_table_insert (*hash, g_value_dup_string (key_val), _gvalue_dup (value_val));
}
typedef struct {
GHashTable *hash2;
gint ret;
} CompareMapInfo;
static void
compare_one_map_item (gpointer key, gpointer val, gpointer user_data)
{
CompareMapInfo *info = (CompareMapInfo *) user_data;
GValue *value2;
if (info->ret)
return;
value2 = (GValue *) g_hash_table_lookup (info->hash2, key);
if (value2)
info->ret = _gvalues_compare ((GValue *) val, value2);
else
info->ret = 1;
}
static gint
_gvalues_compare_map (const GValue *value1, const GValue *value2)
{
GHashTable *hash1 = NULL;
GHashTable *hash2 = NULL;
guint len1;
guint len2;
gint ret = 0;
if (dbus_g_type_get_map_key_specialization (G_VALUE_TYPE (value1)) != G_TYPE_STRING) {
g_warning ("Can not compare maps with '%s' for keys",
g_type_name (dbus_g_type_get_map_key_specialization (G_VALUE_TYPE (value1))));
return 0;
}
hash1 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _gvalue_destroy);
dbus_g_type_map_value_iterate (value1, iterate_map, &hash1);
len1 = g_hash_table_size (hash1);
hash2 = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, _gvalue_destroy);
dbus_g_type_map_value_iterate (value2, iterate_map, &hash2);
len2 = g_hash_table_size (hash2);
if (len1 != len2)
ret = len1 < len2 ? -1 : len1 > len2;
else {
CompareMapInfo info;
info.ret = 0;
info.hash2 = hash2;
g_hash_table_foreach (hash1, compare_one_map_item, &info);
ret = info.ret;
}
g_hash_table_destroy (hash1);
g_hash_table_destroy (hash2);
return ret;
}
static gint
_gvalue_ip6_address_compare (const GValue *value1, const GValue *value2)
{
GValueArray *values1, *values2;
GValue *tmp_val;
GByteArray *addr1, *addr2;
guint32 prefix1, prefix2;
GByteArray *gw1, *gw2;
gint ret = 0;
int i;
/* IP6 addresses are GValueArrays (see nm-dbus-glib-types.h) */
values1 = g_value_get_boxed (value1);
values2 = g_value_get_boxed (value2);
/* Since they are NM IPv6 address structures, we expect both
* to contain two elements as specified in nm-dbus-glib-types.h.
*/
g_return_val_if_fail (values1->n_values == 3, 0);
g_return_val_if_fail (values2->n_values == 3, 0);
/* First struct IPv6 address */
tmp_val = g_value_array_get_nth (values1, 0);
addr1 = g_value_get_boxed (tmp_val);
/* First struct IPv6 prefix */
tmp_val = g_value_array_get_nth (values1, 1);
prefix1 = g_value_get_uint (tmp_val);
/* First struct IPv6 gateway */
tmp_val = g_value_array_get_nth (values1, 2);
gw1 = g_value_get_boxed (tmp_val);
/* Second struct IPv6 address */
tmp_val = g_value_array_get_nth (values2, 0);
addr2 = g_value_get_boxed (tmp_val);
/* Second struct IPv6 prefix */
tmp_val = g_value_array_get_nth (values2, 1);
prefix2 = g_value_get_uint (tmp_val);
/* Second struct IPv6 gateway */
tmp_val = g_value_array_get_nth (values2, 2);
gw2 = g_value_get_boxed (tmp_val);
/* Compare IPv6 addresses */
if (prefix1 != prefix2)
return prefix1 < prefix2 ? -1 : prefix1 > prefix2;
if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *)addr1->data, (struct in6_addr *)addr2->data)) {
for (i = 0; ret == 0 && i < addr1->len; i++)
ret = addr1->data[i] < addr2->data[i] ? -1 : addr1->data[i] > addr2->data[i];
}
if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *) gw1->data, (struct in6_addr *) gw2->data)) {
for (i = 0; ret == 0 && i < gw1->len; i++)
ret = gw1->data[i] < gw2->data[i] ? -1 : gw1->data[i] > gw2->data[i];
}
return ret;
}
static gint
_gvalue_ip6_route_compare (const GValue *value1, const GValue *value2)
{
GValueArray *values1, *values2;
GValue *tmp_val;
GByteArray *dest1, *dest2;
GByteArray *next_hop1, *next_hop2;
guint32 prefix1, prefix2;
guint32 metric1, metric2;
gint ret = 0;
int i;
/* IP6 routes are GValueArrays (see nm-dbus-glib-types.h) */
values1 = g_value_get_boxed (value1);
values2 = g_value_get_boxed (value2);
/* Since they are NM IPv6 route structures, we expect both
* to contain 4 elements as specified in nm-dbus-glib-types.h.
*/
g_return_val_if_fail (values1->n_values == 4, 0);
g_return_val_if_fail (values2->n_values == 4, 0);
/* First struct IPv6 route */
tmp_val = g_value_array_get_nth (values1, 0);
dest1 = g_value_get_boxed (tmp_val);
tmp_val = g_value_array_get_nth (values1, 1);
prefix1 = g_value_get_uint (tmp_val);
tmp_val = g_value_array_get_nth (values1, 2);
next_hop1 = g_value_get_boxed (tmp_val);
tmp_val = g_value_array_get_nth (values1, 3);
metric1 = g_value_get_uint (tmp_val);
/* Second struct IPv6 route */
tmp_val = g_value_array_get_nth (values2, 0);
dest2 = g_value_get_boxed (tmp_val);
tmp_val = g_value_array_get_nth (values2, 1);
prefix2 = g_value_get_uint (tmp_val);
tmp_val = g_value_array_get_nth (values2, 2);
next_hop2 = g_value_get_boxed (tmp_val);
tmp_val = g_value_array_get_nth (values2, 3);
metric2 = g_value_get_uint (tmp_val);
/* Compare the routes */
if (prefix1 != prefix2)
return prefix1 < prefix2 ? -1 : prefix1 > prefix2;
if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *)dest1->data, (struct in6_addr *)dest2->data)) {
for (i = 0; ret == 0 && i < dest1->len; i++)
ret = dest1->data[i] < dest2->data[i] ? -1 : dest1->data[i] > dest2->data[i];
}
if (!IN6_ARE_ADDR_EQUAL ((struct in6_addr *)next_hop1->data, (struct in6_addr *)next_hop2->data)) {
for (i = 0; ret == 0 && i < next_hop1->len; i++)
ret = next_hop1->data[i] < next_hop2->data[i] ? -1 : next_hop1->data[i] > next_hop2->data[i];
}
if (metric1 != metric2)
ret = metric1 < metric2 ? -1 : metric1 > metric2;
return ret;
}
static gint
_gvalues_compare_struct (const GValue *value1, const GValue *value2)
{
/* value1 and value2 must contain the same type since
* _gvalues_compare() enforced that already.
*/
if (G_VALUE_HOLDS (value1, DBUS_TYPE_G_IP6_ADDRESS)) {
return _gvalue_ip6_address_compare (value1, value2);
} else if (G_VALUE_HOLDS (value1, DBUS_TYPE_G_IP6_ROUTE)) {
return _gvalue_ip6_route_compare (value1, value2);
} else {
g_warning ("Don't know how to compare structures");
return (value1 == value2);
}
}
gint
_gvalues_compare (const GValue *value1, const GValue *value2)
{
GType type1;
GType type2;
gint ret;
if (value1 == value2)
return 0;
if (!value1)
return 1;
if (!value2)
return -1;
type1 = G_VALUE_TYPE (value1);
type2 = G_VALUE_TYPE (value2);
if (type1 != type2)
return type1 < type2 ? -1 : type1 > type2;
if (type_is_fixed_size (type1, NULL))
ret = _gvalues_compare_fixed (value1, value2);
else if (type1 == G_TYPE_STRING)
ret = _gvalues_compare_string (value1, value2);
else if (G_VALUE_HOLDS_BOXED (value1)) {
gpointer p1 = g_value_get_boxed (value1);
gpointer p2 = g_value_get_boxed (value2);
if (p1 == p2)
ret = 0; /* Exactly the same values */
else if (!p1)
ret = 1; /* The comparision functions below don't handle NULLs */
else if (!p2)
ret = -1; /* The comparision functions below don't handle NULLs */
else if (type1 == G_TYPE_STRV)
ret = _gvalues_compare_strv (value1, value2);
else if (dbus_g_type_is_collection (type1))
ret = _gvalues_compare_collection (value1, value2);
else if (dbus_g_type_is_map (type1))
ret = _gvalues_compare_map (value1, value2);
else if (dbus_g_type_is_struct (type1))
ret = _gvalues_compare_struct (value1, value2);
else if (type1 == G_TYPE_VALUE)
ret = _gvalues_compare ((GValue *) g_value_get_boxed (value1), (GValue *) g_value_get_boxed (value2));
else {
g_warning ("Don't know how to compare boxed types '%s'", g_type_name (type1));
ret = value1 == value2;
}
} else {
g_warning ("Don't know how to compare types '%s'", g_type_name (type1));
ret = value1 == value2;
}
return ret;
}
/***********************************************************/
static void
param_specialized_init (GParamSpec *pspec)
{
}
static void
param_specialized_set_default (GParamSpec *pspec, GValue *value)
{
value->data[0].v_pointer = NULL;
}
static gboolean
param_specialized_validate (GParamSpec *pspec, GValue *value)
{
NMParamSpecSpecialized *sspec = NM_PARAM_SPEC_SPECIALIZED (pspec);
GType value_type = G_VALUE_TYPE (value);
gboolean changed = FALSE;
if (!g_value_type_compatible (value_type, G_PARAM_SPEC_VALUE_TYPE (sspec))) {
g_value_reset (value);
changed = TRUE;
}
return changed;
}
static gint
param_specialized_values_cmp (GParamSpec *pspec,
const GValue *value1,
const GValue *value2)
{
return _gvalues_compare (value1, value2);
}
GType
_nm_param_spec_specialized_get_type (void)
{
static GType type;
if (G_UNLIKELY (type) == 0) {
static const GParamSpecTypeInfo pspec_info = {
sizeof (NMParamSpecSpecialized),
0,
param_specialized_init,
G_TYPE_OBJECT, /* value_type */
NULL, /* finalize */
param_specialized_set_default,
param_specialized_validate,
param_specialized_values_cmp,
};
type = g_param_type_register_static ("NMParamSpecSpecialized", &pspec_info);
}
return type;
}
GParamSpec *
_nm_param_spec_specialized (const char *name,
const char *nick,
const char *blurb,
GType specialized_type,
GParamFlags flags)
{
NMParamSpecSpecialized *pspec;
g_return_val_if_fail (g_type_is_a (specialized_type, G_TYPE_BOXED), NULL);
pspec = g_param_spec_internal (NM_TYPE_PARAM_SPEC_SPECIALIZED,
name, nick, blurb, flags);
G_PARAM_SPEC (pspec)->value_type = specialized_type;
return G_PARAM_SPEC (pspec);
}
/***********************************************************/
/* Tests */
#if 0
static void
compare_ints (void)
{
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
g_value_init (&value1, G_TYPE_INT);
g_value_init (&value2, G_TYPE_INT);
g_value_set_int (&value1, 5);
g_value_set_int (&value2, 5);
g_print ("Comparing ints 5 and 5: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_int (&value2, 10);
g_print ("Comparing ints 5 and 10: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_int (&value2, 1);
g_print ("Comparing ints 5 and 1: %d\n", _gvalues_compare (&value1, &value2));
}
static void
compare_strings (void)
{
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
const char *str1 = "hello";
const char *str2 = "world";
g_value_init (&value1, G_TYPE_STRING);
g_value_init (&value2, G_TYPE_STRING);
g_value_set_string (&value1, str1);
g_value_set_string (&value2, str1);
g_print ("Comparing identical strings: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_string (&value2, str2);
g_print ("Comparing different strings: %d\n", _gvalues_compare (&value1, &value2));
}
static void
compare_strv (void)
{
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
char *strv1[] = { "foo", "bar", "baz", NULL };
char *strv2[] = { "foo", "bar", "bar", NULL };
char *strv3[] = { "foo", "bar", NULL };
char *strv4[] = { "foo", "bar", "baz", "bam", NULL };
g_value_init (&value1, G_TYPE_STRV);
g_value_init (&value2, G_TYPE_STRV);
g_value_set_boxed (&value1, strv1);
g_value_set_boxed (&value2, strv1);
g_print ("Comparing identical strv's: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_boxed (&value2, strv2);
g_print ("Comparing different strv's: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_boxed (&value2, strv3);
g_print ("Comparing different len (smaller) strv's: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_boxed (&value2, strv4);
g_print ("Comparing different len (longer) strv's: %d\n", _gvalues_compare (&value1, &value2));
}
static void
compare_garrays (void)
{
GArray *array1;
GArray *array2;
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
int i;
g_value_init (&value1, DBUS_TYPE_G_UINT_ARRAY);
array1 = g_array_new (FALSE, FALSE, sizeof (guint32));
g_value_init (&value2, DBUS_TYPE_G_UINT_ARRAY);
array2 = g_array_new (FALSE, FALSE, sizeof (guint32));
for (i = 0; i < 5; i++) {
g_array_append_val (array1, i);
g_array_append_val (array2, i);
}
g_value_set_boxed (&value1, array1);
g_value_set_boxed (&value2, array2);
g_print ("Comparing identical arrays's: %d\n", _gvalues_compare (&value1, &value2));
g_array_remove_index (array2, 0);
g_value_set_boxed (&value2, array2);
g_print ("Comparing different length arrays's: %d\n", _gvalues_compare (&value1, &value2));
i = 7;
g_array_prepend_val (array2, i);
g_value_set_boxed (&value2, array2);
g_print ("Comparing different arrays's: %d\n", _gvalues_compare (&value1, &value2));
}
static void
compare_ptrarrays (void)
{
GPtrArray *array1;
GPtrArray *array2;
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
g_value_init (&value1, dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING));
array1 = g_ptr_array_new ();
g_value_init (&value2, dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING));
array2 = g_ptr_array_new ();
g_ptr_array_add (array1, "hello");
g_ptr_array_add (array1, "world");
g_value_set_boxed (&value1, array1);
g_ptr_array_add (array2, "hello");
g_ptr_array_add (array2, "world");
g_value_set_boxed (&value2, array2);
g_print ("Comparing identical ptr arrays's: %d\n", _gvalues_compare (&value1, &value2));
g_ptr_array_add (array2, "boo");
g_value_set_boxed (&value2, array2);
g_print ("Comparing different len ptr arrays's: %d\n", _gvalues_compare (&value1, &value2));
g_ptr_array_add (array1, "booz");
g_value_set_boxed (&value1, array1);
g_print ("Comparing different ptr arrays's: %d\n", _gvalues_compare (&value1, &value2));
}
static void
compare_str_hash (void)
{
GHashTable *hash1;
GHashTable *hash2;
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
g_value_init (&value1, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING));
g_value_init (&value2, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING));
hash1 = g_hash_table_new (g_str_hash, g_str_equal);
hash2 = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (hash1, "key1", "hello");
g_hash_table_insert (hash1, "key2", "world");
g_hash_table_insert (hash2, "key1", "hello");
g_hash_table_insert (hash2, "key2", "world");
g_value_set_boxed (&value1, hash1);
g_value_set_boxed (&value2, hash2);
g_print ("Comparing identical str hashes: %d\n", _gvalues_compare (&value1, &value2));
g_hash_table_remove (hash2, "key2");
g_value_set_boxed (&value2, hash2);
g_print ("Comparing different length str hashes: %d\n", _gvalues_compare (&value1, &value2));
g_hash_table_insert (hash2, "key2", "moon");
g_value_set_boxed (&value2, hash2);
g_print ("Comparing different str hashes: %d\n", _gvalues_compare (&value1, &value2));
}
static GValue *
str_to_gvalue (const char *str)
{
GValue *value;
value = g_slice_new0 (GValue);
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, str);
return value;
}
static GValue *
int_to_gvalue (int i)
{
GValue *value;
value = g_slice_new0 (GValue);
g_value_init (value, G_TYPE_INT);
g_value_set_int (value, i);
return value;
}
static void
compare_gvalue_hash (void)
{
GHashTable *hash1;
GHashTable *hash2;
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
g_value_init (&value1, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE));
g_value_init (&value2, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE));
hash1 = g_hash_table_new (g_str_hash, g_str_equal);
hash2 = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (hash1, "key1", str_to_gvalue ("hello"));
g_hash_table_insert (hash1, "key2", int_to_gvalue (5));
g_hash_table_insert (hash2, "key1", str_to_gvalue ("hello"));
g_hash_table_insert (hash2, "key2", int_to_gvalue (5));
g_value_set_boxed (&value1, hash1);
g_value_set_boxed (&value2, hash2);
g_print ("Comparing identical gvalue hashes: %d\n", _gvalues_compare (&value1, &value2));
g_hash_table_remove (hash2, "key2");
g_value_set_boxed (&value2, hash2);
g_print ("Comparing different length str hashes: %d\n", _gvalues_compare (&value1, &value2));
g_hash_table_insert (hash2, "key2", str_to_gvalue ("moon"));
g_value_set_boxed (&value2, hash2);
g_print ("Comparing different str hashes: %d\n", _gvalues_compare (&value1, &value2));
}
static void
compare_ip6_addresses (void)
{
GValueArray *array1;
GValueArray *array2;
GValueArray *array3;
GByteArray *ba1;
GByteArray *ba2;
GByteArray *ba3;
GValue element = G_VALUE_INIT;
GValue value1 = G_VALUE_INIT;
GValue value2 = G_VALUE_INIT;
struct in6_addr addr1;
struct in6_addr addr2;
struct in6_addr addr3;
guint32 prefix1 = 64;
guint32 prefix2 = 64;
guint32 prefix3 = 0;
inet_pton (AF_INET6, "1:2:3:4:5:6:7:8", &addr1, sizeof (struct in6_addr));
inet_pton (AF_INET6, "ffff:2:3:4:5:6:7:8", &addr2, sizeof (struct in6_addr));
inet_pton (AF_INET6, "::", &addr3, sizeof (struct in6_addr));
/* address 1 */
ba1 = g_byte_array_new ();
array1 = g_value_array_new (2);
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
g_byte_array_append (ba1, (guint8 *) addr1.s6_addr, 16);
g_value_take_boxed (&element, ba1);
g_value_array_append (array1, &element);
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, prefix1);
g_value_array_append (array1, &element);
g_value_unset (&element);
/* address 2 */
ba2 = g_byte_array_new ();
array2 = g_value_array_new (2);
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
g_byte_array_append (ba2, (guint8 *) addr2.s6_addr, 16);
g_value_take_boxed (&element, ba2);
g_value_array_append (array2, &element);
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, prefix2);
g_value_array_append (array2, &element);
g_value_unset (&element);
/* address 3 */
ba3 = g_byte_array_new ();
array3 = g_value_array_new (2);
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
g_byte_array_append (ba3, (guint8 *) addr3.s6_addr, 16);
g_value_take_boxed (&element, ba3);
g_value_array_append (array3, &element);
g_value_unset (&element);
g_value_init (&element, G_TYPE_UINT);
g_value_set_uint (&element, prefix3);
g_value_array_append (array3, &element);
g_value_unset (&element);
g_value_init (&value1, DBUS_TYPE_G_IP6_ADDRESS);
g_value_init (&value2, DBUS_TYPE_G_IP6_ADDRESS);
g_value_set_boxed (&value1, array1);
g_value_set_boxed (&value2, array1);
g_print ("Comparing identical IPv6 address structures: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_boxed (&value1, array1);
g_value_set_boxed (&value2, array2);
g_print ("Comparing different IPv6 address structures: %d\n", _gvalues_compare (&value1, &value2));
g_value_set_boxed (&value1, array1);
g_value_set_boxed (&value2, array3);
g_print ("Comparing different IPv6 address structures: %d\n", _gvalues_compare (&value1, &value2));
}
int
main (int argc, char *argv[])
{
DBusGConnection *bus;
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
compare_ints ();
compare_strings ();
compare_strv ();
compare_garrays ();
compare_ptrarrays ();
compare_str_hash ();
compare_gvalue_hash ();
compare_ip6_addresses ();
return 0;
}
#endif

View File

@@ -0,0 +1,43 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_PARAM_SPEC_SPECIALIZED_H
#define NM_PARAM_SPEC_SPECIALIZED_H
#include <glib-object.h>
typedef struct _NMParamSpecSpecialized NMParamSpecSpecialized;
#define NM_TYPE_PARAM_SPEC_SPECIALIZED (_nm_param_spec_specialized_get_type ())
#define NM_IS_PARAM_SPEC_SPECIALIZED(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), NM_TYPE_PARAM_SPEC_SPECIALIZED))
#define NM_PARAM_SPEC_SPECIALIZED(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), NM_TYPE_PARAM_SPEC_SPECIALIZED, NMParamSpecSpecialized))
GType _nm_param_spec_specialized_get_type (void);
GParamSpec *_nm_param_spec_specialized (const char *name,
const char *nick,
const char *blurb,
GType specialized_type,
GParamFlags flags);
#endif /* NM_PARAM_SPEC_SPECIALIZED_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,297 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_8021X_H
#define NM_SETTING_8021X_H
#include <nm-setting.h>
G_BEGIN_DECLS
/**
* NMSetting8021xCKFormat:
* @NM_SETTING_802_1X_CK_FORMAT_UNKNOWN: unknown file format
* @NM_SETTING_802_1X_CK_FORMAT_X509: file contains an X.509 format certificate
* @NM_SETTING_802_1X_CK_FORMAT_RAW_KEY: file contains an old-style OpenSSL PEM
* or DER private key
* @NM_SETTING_802_1X_CK_FORMAT_PKCS12: file contains a PKCS#12 certificate
* and private key
*
* #NMSetting8021xCKFormat values indicate the general type of a certificate
* or private key
*/
typedef enum { /*< underscore_name=nm_setting_802_1x_ck_format >*/
NM_SETTING_802_1X_CK_FORMAT_UNKNOWN = 0,
NM_SETTING_802_1X_CK_FORMAT_X509,
NM_SETTING_802_1X_CK_FORMAT_RAW_KEY,
NM_SETTING_802_1X_CK_FORMAT_PKCS12
} NMSetting8021xCKFormat;
/**
* NMSetting8021xCKScheme:
* @NM_SETTING_802_1X_CK_SCHEME_UNKNOWN: unknown certificate or private key
* scheme
* @NM_SETTING_802_1X_CK_SCHEME_BLOB: certificate or key is stored as the raw
* item data
* @NM_SETTING_802_1X_CK_SCHEME_PATH: certificate or key is stored as a path
* to a file containing the certificate or key data
*
* #NMSetting8021xCKScheme values indicate how a certificate or private key is
* stored in the setting properties, either as a blob of the item's data, or as
* a path to a certificate or private key file on the filesystem
*/
typedef enum { /*< underscore_name=nm_setting_802_1x_ck_scheme >*/
NM_SETTING_802_1X_CK_SCHEME_UNKNOWN = 0,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
NM_SETTING_802_1X_CK_SCHEME_PATH
} NMSetting8021xCKScheme;
#define NM_TYPE_SETTING_802_1X (nm_setting_802_1x_get_type ())
#define NM_SETTING_802_1X(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_802_1X, NMSetting8021x))
#define NM_SETTING_802_1X_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_802_1X, NMSetting8021xClass))
#define NM_IS_SETTING_802_1X(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_802_1X))
#define NM_IS_SETTING_802_1X_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_802_1X))
#define NM_SETTING_802_1X_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_802_1X, NMSetting8021xClass))
#define NM_SETTING_802_1X_SETTING_NAME "802-1x"
/**
* NMSetting8021xError:
* @NM_SETTING_802_1X_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_802_1X_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_802_1X_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum { /*< underscore_name=nm_setting_802_1x_error >*/
NM_SETTING_802_1X_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_802_1X_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_802_1X_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSetting8021xError;
#define NM_SETTING_802_1X_ERROR nm_setting_802_1x_error_quark ()
GQuark nm_setting_802_1x_error_quark (void);
#define NM_SETTING_802_1X_EAP "eap"
#define NM_SETTING_802_1X_IDENTITY "identity"
#define NM_SETTING_802_1X_ANONYMOUS_IDENTITY "anonymous-identity"
#define NM_SETTING_802_1X_PAC_FILE "pac-file"
#define NM_SETTING_802_1X_CA_CERT "ca-cert"
#define NM_SETTING_802_1X_CA_PATH "ca-path"
#define NM_SETTING_802_1X_SUBJECT_MATCH "subject-match"
#define NM_SETTING_802_1X_ALTSUBJECT_MATCHES "altsubject-matches"
#define NM_SETTING_802_1X_CLIENT_CERT "client-cert"
#define NM_SETTING_802_1X_PHASE1_PEAPVER "phase1-peapver"
#define NM_SETTING_802_1X_PHASE1_PEAPLABEL "phase1-peaplabel"
#define NM_SETTING_802_1X_PHASE1_FAST_PROVISIONING "phase1-fast-provisioning"
#define NM_SETTING_802_1X_PHASE2_AUTH "phase2-auth"
#define NM_SETTING_802_1X_PHASE2_AUTHEAP "phase2-autheap"
#define NM_SETTING_802_1X_PHASE2_CA_CERT "phase2-ca-cert"
#define NM_SETTING_802_1X_PHASE2_CA_PATH "phase2-ca-path"
#define NM_SETTING_802_1X_PHASE2_SUBJECT_MATCH "phase2-subject-match"
#define NM_SETTING_802_1X_PHASE2_ALTSUBJECT_MATCHES "phase2-altsubject-matches"
#define NM_SETTING_802_1X_PHASE2_CLIENT_CERT "phase2-client-cert"
#define NM_SETTING_802_1X_PASSWORD "password"
#define NM_SETTING_802_1X_PASSWORD_FLAGS "password-flags"
#define NM_SETTING_802_1X_PASSWORD_RAW "password-raw"
#define NM_SETTING_802_1X_PASSWORD_RAW_FLAGS "password-raw-flags"
#define NM_SETTING_802_1X_PRIVATE_KEY "private-key"
#define NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD "private-key-password"
#define NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS "private-key-password-flags"
#define NM_SETTING_802_1X_PHASE2_PRIVATE_KEY "phase2-private-key"
#define NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD "phase2-private-key-password"
#define NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD_FLAGS "phase2-private-key-password-flags"
#define NM_SETTING_802_1X_PIN "pin"
#define NM_SETTING_802_1X_PIN_FLAGS "pin-flags"
#define NM_SETTING_802_1X_SYSTEM_CA_CERTS "system-ca-certs"
/* PRIVATE KEY NOTE: when setting PKCS#12 private keys directly via properties
* using the "blob" scheme, the data must be passed in PKCS#12 binary format.
* In this case, the appropriate "client-cert" (or "phase2-client-cert")
* property of the NMSetting8021x object must also contain the exact same
* PKCS#12 binary data that the private key does. This is because the
* PKCS#12 file contains both the private key and client certificate, so both
* properties need to be set to the same thing. When using the "path" scheme,
* just set both the private-key and client-cert properties to the same path.
*
* When setting OpenSSL-derived "traditional" format (ie S/MIME style, not
* PKCS#8) RSA and DSA keys directly via properties with the "blob" scheme, they
* should be passed to NetworkManager in PEM format with the "DEK-Info" and
* "Proc-Type" tags intact. Decrypted private keys should not be used as this
* is insecure and could allow unprivileged users to access the decrypted
* private key data.
*
* When using the "path" scheme, just set the private-key and client-cert
* properties to the paths to their respective objects.
*/
typedef struct {
NMSetting parent;
} NMSetting8021x;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSetting8021xClass;
GType nm_setting_802_1x_get_type (void);
NMSetting *nm_setting_802_1x_new (void);
guint32 nm_setting_802_1x_get_num_eap_methods (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_eap_method (NMSetting8021x *setting, guint32 i);
gboolean nm_setting_802_1x_add_eap_method (NMSetting8021x *setting, const char *eap);
void nm_setting_802_1x_remove_eap_method (NMSetting8021x *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_802_1x_remove_eap_method_by_value (NMSetting8021x *setting, const char *eap);
void nm_setting_802_1x_clear_eap_methods (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_identity (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_anonymous_identity (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_pac_file (NMSetting8021x *setting);
gboolean nm_setting_802_1x_get_system_ca_certs (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_ca_path (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_ca_path (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_ca_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_ca_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_ca_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_ca_cert (NMSetting8021x *setting,
const char *cert_path,
NMSetting8021xCKScheme scheme,
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_subject_match (NMSetting8021x *setting);
guint32 nm_setting_802_1x_get_num_altsubject_matches (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_altsubject_match (NMSetting8021x *setting,
guint32 i);
gboolean nm_setting_802_1x_add_altsubject_match (NMSetting8021x *setting,
const char *altsubject_match);
void nm_setting_802_1x_remove_altsubject_match (NMSetting8021x *setting,
guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_802_1x_remove_altsubject_match_by_value (NMSetting8021x *setting,
const char *altsubject_match);
void nm_setting_802_1x_clear_altsubject_matches (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_client_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_client_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_client_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_client_cert (NMSetting8021x *setting,
const char *cert_path,
NMSetting8021xCKScheme scheme,
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_phase1_peapver (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase1_peaplabel (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase1_fast_provisioning (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_auth (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_autheap (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_ca_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_phase2_ca_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_ca_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_ca_cert (NMSetting8021x *setting,
const char *cert_path,
NMSetting8021xCKScheme scheme,
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_phase2_subject_match (NMSetting8021x *setting);
guint32 nm_setting_802_1x_get_num_phase2_altsubject_matches (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_altsubject_match (NMSetting8021x *setting,
guint32 i);
gboolean nm_setting_802_1x_add_phase2_altsubject_match (NMSetting8021x *setting,
const char *phase2_altsubject_match);
void nm_setting_802_1x_remove_phase2_altsubject_match (NMSetting8021x *setting,
guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_802_1x_remove_phase2_altsubject_match_by_value (NMSetting8021x *setting,
const char *phase2_altsubject_match);
void nm_setting_802_1x_clear_phase2_altsubject_matches (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_client_cert_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_phase2_client_cert_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_client_cert_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_client_cert (NMSetting8021x *setting,
const char *cert_path,
NMSetting8021xCKScheme scheme,
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_password_flags (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_password_raw (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_password_raw_flags (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_pin (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_pin_flags (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_private_key_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_private_key_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_private_key_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_private_key (NMSetting8021x *setting,
const char *key_path,
const char *password,
NMSetting8021xCKScheme scheme,
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_private_key_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_private_key_password_flags (NMSetting8021x *setting);
NMSetting8021xCKFormat nm_setting_802_1x_get_private_key_format (NMSetting8021x *setting);
NMSetting8021xCKScheme nm_setting_802_1x_get_phase2_private_key_scheme (NMSetting8021x *setting);
const GByteArray * nm_setting_802_1x_get_phase2_private_key_blob (NMSetting8021x *setting);
const char * nm_setting_802_1x_get_phase2_private_key_path (NMSetting8021x *setting);
gboolean nm_setting_802_1x_set_phase2_private_key (NMSetting8021x *setting,
const char *key_path,
const char *password,
NMSetting8021xCKScheme scheme,
NMSetting8021xCKFormat *out_format,
GError **error);
const char * nm_setting_802_1x_get_phase2_private_key_password (NMSetting8021x *setting);
NMSettingSecretFlags nm_setting_802_1x_get_phase2_private_key_password_flags (NMSetting8021x *setting);
NMSetting8021xCKFormat nm_setting_802_1x_get_phase2_private_key_format (NMSetting8021x *setting);
G_END_DECLS
#endif /* NM_SETTING_8021X_H */

View File

@@ -0,0 +1,465 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2013 Red Hat, Inc.
*/
#include <string.h>
#include <glib/gi18n.h>
#include "nm-setting-adsl.h"
#include "nm-setting-ppp.h"
#include "nm-setting-private.h"
#include "nm-utils.h"
/**
* SECTION:nm-setting-adsl
* @short_description: Describes ADSL-based properties
* @include: nm-setting-adsl.h
*
* The #NMSettingAdsl object is a #NMSetting subclass that describes
* properties of ADSL connections.
*/
/**
* nm_setting_adsl_error_quark:
*
* Registers an error quark for #NMSettingAdsl if necessary.
*
* Returns: the error quark used for #NMSettingAdsl errors.
**/
GQuark
nm_setting_adsl_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-adsl-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingAdsl, nm_setting_adsl, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_ADSL_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_ADSL_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_ADSL)
#define NM_SETTING_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_ADSL, NMSettingAdslPrivate))
typedef struct {
char * username;
char * password;
NMSettingSecretFlags password_flags;
char * protocol;
char * encapsulation;
guint32 vpi;
guint32 vci;
} NMSettingAdslPrivate;
enum {
PROP_0,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
PROP_PROTOCOL,
PROP_ENCAPSULATION,
PROP_VPI,
PROP_VCI,
LAST_PROP
};
/**
* nm_setting_adsl_new:
*
* Creates a new #NMSettingAdsl object with default values.
*
* Returns: the new empty #NMSettingAdsl object
**/
NMSetting *
nm_setting_adsl_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_ADSL, NULL);
}
/**
* nm_setting_adsl_get_username:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingAdsl:username property of the setting
**/
const char *
nm_setting_adsl_get_username (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->username;
}
/**
* nm_setting_adsl_get_password:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingAdsl:password property of the setting
**/
const char *
nm_setting_adsl_get_password (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_adsl_get_password_flags:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingAdsl:password
**/
NMSettingSecretFlags
nm_setting_adsl_get_password_flags (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->password_flags;
}
/**
* nm_setting_adsl_get_protocol:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingAdsl:protocol property of the setting
**/
const char *
nm_setting_adsl_get_protocol (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->protocol;
}
/**
* nm_setting_adsl_get_encapsulation:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingAdsl:encapsulation property of the setting
**/
const char *
nm_setting_adsl_get_encapsulation (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), NULL);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->encapsulation;
}
/**
* nm_setting_adsl_get_vpi:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingAdsl:vpi property of the setting
**/
guint32
nm_setting_adsl_get_vpi (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), 0);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->vpi;
}
/**
* nm_setting_adsl_get_vci:
* @setting: the #NMSettingAdsl
*
* Returns: the #NMSettingAdsl:vci property of the setting
**/
guint32
nm_setting_adsl_get_vci (NMSettingAdsl *setting)
{
g_return_val_if_fail (NM_IS_SETTING_ADSL (setting), 0);
return NM_SETTING_ADSL_GET_PRIVATE (setting)->vci;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);
if (!priv->username) {
g_set_error_literal (error,
NM_SETTING_ADSL_ERROR,
NM_SETTING_ADSL_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_USERNAME);
return FALSE;
} else if (!strlen (priv->username)) {
g_set_error_literal (error,
NM_SETTING_ADSL_ERROR,
NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_USERNAME);
return FALSE;
}
if (priv->password && !strlen (priv->password)) {
g_set_error_literal (error,
NM_SETTING_ADSL_ERROR,
NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_PASSWORD);
return FALSE;
}
if (strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_PPPOA) &&
strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE) &&
strcmp (priv->protocol, NM_SETTING_ADSL_PROTOCOL_IPOATM)) {
g_set_error (error,
NM_SETTING_ADSL_ERROR,
NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid value for the property"),
priv->protocol);
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_PROTOCOL);
return FALSE;
}
if (strcmp (priv->encapsulation, NM_SETTING_ADSL_ENCAPSULATION_VCMUX) &&
strcmp (priv->encapsulation, NM_SETTING_ADSL_ENCAPSULATION_LLC) ) {
g_set_error (error,
NM_SETTING_ADSL_ERROR,
NM_SETTING_ADSL_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid value for the property"),
priv->encapsulation);
g_prefix_error (error, "%s.%s: ", NM_SETTING_ADSL_SETTING_NAME, NM_SETTING_ADSL_ENCAPSULATION);
return FALSE;
}
return TRUE;
}
static GPtrArray *
need_secrets (NMSetting *setting)
{
NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (setting);
GPtrArray *secrets = NULL;
if (priv->password)
return NULL;
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_ADSL_PASSWORD);
}
return secrets;
}
static void
nm_setting_adsl_init (NMSettingAdsl *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (object);
g_free (priv->username);
g_free (priv->password);
g_free (priv->protocol);
g_free (priv->encapsulation);
G_OBJECT_CLASS (nm_setting_adsl_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingAdslPrivate *priv = NM_SETTING_ADSL_GET_PRIVATE (object);
switch (prop_id) {
case PROP_USERNAME:
g_free (priv->username);
priv->username = g_value_dup_string (value);
break;
case PROP_PASSWORD:
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
case PROP_PROTOCOL:
g_free (priv->protocol);
priv->protocol = g_ascii_strdown (g_value_get_string (value), -1);
break;
case PROP_ENCAPSULATION:
g_free (priv->encapsulation);
priv->encapsulation = g_ascii_strdown (g_value_get_string (value), -1);
break;
case PROP_VPI:
priv->vpi = g_value_get_uint (value);
break;
case PROP_VCI:
priv->vci = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingAdsl *setting = NM_SETTING_ADSL (object);
switch (prop_id) {
case PROP_USERNAME:
g_value_set_string (value, nm_setting_adsl_get_username (setting));
break;
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_adsl_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_adsl_get_password_flags (setting));
break;
case PROP_PROTOCOL:
g_value_set_string (value, nm_setting_adsl_get_protocol (setting));
break;
case PROP_ENCAPSULATION:
g_value_set_string (value, nm_setting_adsl_get_encapsulation (setting));
break;
case PROP_VPI:
g_value_set_uint (value, nm_setting_adsl_get_vpi (setting));
break;
case PROP_VCI:
g_value_set_uint (value, nm_setting_adsl_get_vci (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_adsl_class_init (NMSettingAdslClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingAdslPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->need_secrets = need_secrets;
/* Properties */
/**
* NMSettingAdsl:username:
*
* Username used to authenticate with the ADSL service.
**/
g_object_class_install_property
(object_class, PROP_USERNAME,
g_param_spec_string (NM_SETTING_ADSL_USERNAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingAdsl:password:
*
* Password used to authenticate with the ADSL service.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD,
g_param_spec_string (NM_SETTING_ADSL_PASSWORD, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_SECRET |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingAdsl:password-flags:
*
* Flags indicating how to handle the #NMSettingAdsl:password property.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_ADSL_PASSWORD_FLAGS, "", "",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingAdsl:protocol:
*
* ADSL connection protocol. Can be "pppoa", "pppoe" or "ipoatm".
**/
g_object_class_install_property
(object_class, PROP_PROTOCOL,
g_param_spec_string (NM_SETTING_ADSL_PROTOCOL, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingAdsl:encapsulation:
*
* Encapsulation of ADSL connection. Can be "vcmux" or "llc".
**/
g_object_class_install_property
(object_class, PROP_ENCAPSULATION,
g_param_spec_string (NM_SETTING_ADSL_ENCAPSULATION, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingAdsl:vpi:
*
* VPI of ADSL connection
**/
g_object_class_install_property
(object_class, PROP_VPI,
g_param_spec_uint (NM_SETTING_ADSL_VPI, "", "",
0, 65536, 0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingAdsl:vci:
*
* VCI of ADSL connection
**/
g_object_class_install_property
(object_class, PROP_VCI,
g_param_spec_uint (NM_SETTING_ADSL_VCI, "", "",
0, 65536, 0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,96 @@
/* -*- mode: c; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Red Hat, Inc.
*/
#ifndef NM_SETTING_ADSL_H
#define NM_SETTING_ADSL_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_ADSL (nm_setting_adsl_get_type ())
#define NM_SETTING_ADSL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_ADSL, NMSettingAdsl))
#define NM_SETTING_ADSL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_ADSL, NMSettingAdslClass))
#define NM_IS_SETTING_ADSL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_ADSL))
#define NM_IS_SETTING_ADSL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_ADSL))
#define NM_SETTING_ADSL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_ADSL, NMSettingAdslClass))
#define NM_SETTING_ADSL_SETTING_NAME "adsl"
/**
* NMSettingAdslError:
* @NM_SETTING_ADSL_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_ADSL_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_ADSL_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_ADSL_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_ADSL_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_ADSL_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingAdslError;
#define NM_SETTING_ADSL_ERROR nm_setting_adsl_error_quark ()
GQuark nm_setting_adsl_error_quark (void);
#define NM_SETTING_ADSL_USERNAME "username"
#define NM_SETTING_ADSL_PASSWORD "password"
#define NM_SETTING_ADSL_PASSWORD_FLAGS "password-flags"
#define NM_SETTING_ADSL_PROTOCOL "protocol"
#define NM_SETTING_ADSL_ENCAPSULATION "encapsulation"
#define NM_SETTING_ADSL_VPI "vpi"
#define NM_SETTING_ADSL_VCI "vci"
#define NM_SETTING_ADSL_PROTOCOL_PPPOA "pppoa"
#define NM_SETTING_ADSL_PROTOCOL_PPPOE "pppoe"
#define NM_SETTING_ADSL_PROTOCOL_IPOATM "ipoatm"
#define NM_SETTING_ADSL_ENCAPSULATION_VCMUX "vcmux"
#define NM_SETTING_ADSL_ENCAPSULATION_LLC "llc"
typedef struct {
NMSetting parent;
} NMSettingAdsl;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingAdslClass;
GType nm_setting_adsl_get_type (void);
NMSetting *nm_setting_adsl_new (void);
const char *nm_setting_adsl_get_username (NMSettingAdsl *setting);
const char *nm_setting_adsl_get_password (NMSettingAdsl *setting);
const char *nm_setting_adsl_get_protocol (NMSettingAdsl *setting);
const char *nm_setting_adsl_get_encapsulation (NMSettingAdsl *setting);
guint32 nm_setting_adsl_get_vpi (NMSettingAdsl *setting);
guint32 nm_setting_adsl_get_vci (NMSettingAdsl *setting);
NMSettingSecretFlags nm_setting_adsl_get_password_flags (NMSettingAdsl *setting);
G_END_DECLS
#endif /* NM_SETTING_ADSL_H */

View File

@@ -0,0 +1,297 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include <net/ethernet.h>
#include <glib/gi18n.h>
#include "nm-param-spec-specialized.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-bluetooth.h"
#include "nm-setting-cdma.h"
#include "nm-setting-gsm.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-bluetooth
* @short_description: Describes Bluetooth connection properties
* @include: nm-setting-bluetooth.h
*
* The #NMSettingBluetooth object is a #NMSetting subclass that describes
* properties necessary for connection to devices that provide network
* connections via the Bluetooth Dial-Up Networking (DUN) and Network Access
* Point (NAP) profiles.
**/
/**
* nm_setting_bluetooth_error_quark:
*
* Registers an error quark for #NMSettingBluetooth if necessary.
*
* Returns: the error quark used for #NMSettingBluetooth errors.
**/
GQuark
nm_setting_bluetooth_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-bluetooth-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingBluetooth, nm_setting_bluetooth, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_BLUETOOTH_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_BLUETOOTH_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BLUETOOTH)
#define NM_SETTING_BLUETOOTH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothPrivate))
typedef struct {
GByteArray *bdaddr;
char *type;
} NMSettingBluetoothPrivate;
enum {
PROP_0,
PROP_BDADDR,
PROP_TYPE,
LAST_PROP
};
/**
* nm_setting_bluetooth_new:
*
* Creates a new #NMSettingBluetooth object with default values.
*
* Returns: (transfer full): the new empty #NMSettingBluetooth object
**/
NMSetting *nm_setting_bluetooth_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BLUETOOTH, NULL);
}
/**
* nm_setting_bluetooth_get_connection_type:
* @setting: the #NMSettingBluetooth
*
* Returns the connection method for communicating with the remote device (i.e.
* either DUN to a DUN-capable device or PANU to a NAP-capable device).
*
* Returns: the type, either %NM_SETTING_BLUETOOTH_PANU or %NM_SETTING_BLUETOOTH_DUN
**/
const char *
nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->type;
}
/**
* nm_setting_bluetooth_get_bdaddr:
* @setting: the #NMSettingBluetooth
*
* Gets the Bluetooth address of the remote device which this setting
* describes a connection to.
*
* Returns: the Bluetooth address
**/
const GByteArray *
nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BLUETOOTH (setting), NULL);
return NM_SETTING_BLUETOOTH_GET_PRIVATE (setting)->bdaddr;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (setting);
if (!priv->bdaddr) {
g_set_error_literal (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR);
return FALSE;
}
if (priv->bdaddr && priv->bdaddr->len != ETH_ALEN) {
g_set_error_literal (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR);
return FALSE;
}
if (!priv->type) {
g_set_error_literal (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
return FALSE;
} else if (!g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN) &&
!g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_PANU)) {
g_set_error (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid value for the property"),
priv->type);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
return FALSE;
}
/* Make sure the corresponding 'type' setting is present */
if ( all_settings
&& !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) {
gboolean gsm = FALSE, cdma = FALSE;
gsm = !!nm_setting_find_in_list (all_settings, NM_SETTING_GSM_SETTING_NAME);
cdma = !!nm_setting_find_in_list (all_settings, NM_SETTING_CDMA_SETTING_NAME);
if (!gsm && !cdma) {
g_set_error (error,
NM_SETTING_BLUETOOTH_ERROR,
NM_SETTING_BLUETOOTH_ERROR_TYPE_SETTING_NOT_FOUND,
_("requires '%s' or '%s' setting"),
NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE);
return FALSE;
}
}
/* PANU doesn't need a 'type' setting since no further configuration
* is required at the interface level.
*/
return TRUE;
}
static void
nm_setting_bluetooth_init (NMSettingBluetooth *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
if (priv->bdaddr)
g_byte_array_free (priv->bdaddr, TRUE);
g_free (priv->type);
G_OBJECT_CLASS (nm_setting_bluetooth_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (object);
switch (prop_id) {
case PROP_BDADDR:
if (priv->bdaddr)
g_byte_array_free (priv->bdaddr, TRUE);
priv->bdaddr = g_value_dup_boxed (value);
break;
case PROP_TYPE:
g_free (priv->type);
priv->type = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingBluetooth *setting = NM_SETTING_BLUETOOTH (object);
switch (prop_id) {
case PROP_BDADDR:
g_value_set_boxed (value, nm_setting_bluetooth_get_bdaddr (setting));
break;
case PROP_TYPE:
g_value_set_string (value, nm_setting_bluetooth_get_connection_type (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_bluetooth_class_init (NMSettingBluetoothClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingBluetoothPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingBluetooth:bdaddr:
*
* The Bluetooth address of the device.
**/
g_object_class_install_property
(object_class, PROP_BDADDR,
_nm_param_spec_specialized (NM_SETTING_BLUETOOTH_BDADDR, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBluetooth:type:
*
* Either "dun" for Dial-Up Networking connections or "panu" for Personal
* Area Networking connections to devices supporting the NAP profile.
**/
g_object_class_install_property
(object_class, PROP_TYPE,
g_param_spec_string (NM_SETTING_BLUETOOTH_TYPE, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,100 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2009 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_BLUETOOTH_H
#define NM_SETTING_BLUETOOTH_H
#include "nm-setting.h"
G_BEGIN_DECLS
#define NM_TYPE_SETTING_BLUETOOTH (nm_setting_bluetooth_get_type ())
#define NM_SETTING_BLUETOOTH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetooth))
#define NM_SETTING_BLUETOOTH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothClass))
#define NM_IS_SETTING_BLUETOOTH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BLUETOOTH))
#define NM_IS_SETTING_BLUETOOTH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_BLUETOOTH))
#define NM_SETTING_BLUETOOTH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BLUETOOTH, NMSettingBluetoothClass))
#define NM_SETTING_BLUETOOTH_SETTING_NAME "bluetooth"
/**
* NMSettingBluetoothError:
* @NM_SETTING_BLUETOOTH_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_BLUETOOTH_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_BLUETOOTH_ERROR_TYPE_SETTING_NOT_FOUND: the connection
* did not contain a required type setting, ie for DUN connections the connection
* must also contain an #NMSettingGsm or #NMSettingCdma as appropriate
*/
typedef enum {
NM_SETTING_BLUETOOTH_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_BLUETOOTH_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_BLUETOOTH_ERROR_TYPE_SETTING_NOT_FOUND, /*< nick=TypeSettingNotFound >*/
} NMSettingBluetoothError;
#define NM_SETTING_BLUETOOTH_ERROR nm_setting_bluetooth_error_quark ()
GQuark nm_setting_bluetooth_error_quark (void);
#define NM_SETTING_BLUETOOTH_BDADDR "bdaddr"
#define NM_SETTING_BLUETOOTH_TYPE "type"
/**
* NM_SETTING_BLUETOOTH_TYPE_DUN:
*
* Connection type describing a connection to devices that support the Bluetooth
* DUN profile.
*/
#define NM_SETTING_BLUETOOTH_TYPE_DUN "dun"
/**
* NM_SETTING_BLUETOOTH_TYPE_PANU:
*
* Connection type describing a connection to devices that support the Bluetooth
* NAP (Network Access Point) protocol, which accepts connections via PANU.
*/
#define NM_SETTING_BLUETOOTH_TYPE_PANU "panu"
typedef struct {
NMSetting parent;
} NMSettingBluetooth;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingBluetoothClass;
GType nm_setting_bluetooth_get_type (void);
NMSetting * nm_setting_bluetooth_new (void);
const GByteArray *nm_setting_bluetooth_get_bdaddr (NMSettingBluetooth *setting);
const char * nm_setting_bluetooth_get_connection_type (NMSettingBluetooth *setting);
G_END_DECLS
#endif /* NM_SETTING_BLUETOOTH_H */

View File

@@ -0,0 +1,804 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2013 Red Hat, Inc.
*/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-bond.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-bond
* @short_description: Describes connection properties for bonds
* @include: nm-setting-bond.h
*
* The #NMSettingBond object is a #NMSetting subclass that describes properties
* necessary for bond connections.
**/
/**
* nm_setting_bond_error_quark:
*
* Registers an error quark for #NMSettingBond if necessary.
*
* Returns: the error quark used for #NMSettingBond errors.
**/
GQuark
nm_setting_bond_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-bond-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingBond, nm_setting_bond, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_BOND_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_BOND_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND)
#define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
typedef struct {
char *interface_name;
GHashTable *options;
} NMSettingBondPrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_OPTIONS,
LAST_PROP
};
enum {
TYPE_INT,
TYPE_STR,
TYPE_BOTH,
TYPE_IP,
TYPE_IFNAME,
};
typedef struct {
const char *opt;
const char *val;
guint opt_type;
guint min;
guint max;
char *list[10];
} BondDefault;
static const BondDefault defaults[] = {
{ NM_SETTING_BOND_OPTION_MODE, "balance-rr", TYPE_BOTH, 0, 6,
{ "balance-rr", "active-backup", "balance-xor", "broadcast", "802.3ad", "balance-tlb", "balance-alb", NULL } },
{ NM_SETTING_BOND_OPTION_MIIMON, "100", TYPE_INT, 0, G_MAXINT },
{ NM_SETTING_BOND_OPTION_DOWNDELAY, "0", TYPE_INT, 0, G_MAXINT },
{ NM_SETTING_BOND_OPTION_UPDELAY, "0", TYPE_INT, 0, G_MAXINT },
{ NM_SETTING_BOND_OPTION_ARP_INTERVAL, "0", TYPE_INT, 0, G_MAXINT },
{ NM_SETTING_BOND_OPTION_ARP_IP_TARGET, "", TYPE_IP },
{ NM_SETTING_BOND_OPTION_ARP_VALIDATE, "0", TYPE_BOTH, 0, 3,
{ "none", "active", "backup", "all", NULL } },
{ NM_SETTING_BOND_OPTION_PRIMARY, "", TYPE_IFNAME },
{ NM_SETTING_BOND_OPTION_PRIMARY_RESELECT, "0", TYPE_BOTH, 0, 2,
{ "always", "better", "failure", NULL } },
{ NM_SETTING_BOND_OPTION_FAIL_OVER_MAC, "0", TYPE_BOTH, 0, 2,
{ "none", "active", "follow", NULL } },
{ NM_SETTING_BOND_OPTION_USE_CARRIER, "1", TYPE_INT, 0, 1 },
{ NM_SETTING_BOND_OPTION_AD_SELECT, "0", TYPE_BOTH, 0, 2,
{ "stable", "bandwidth", "count", NULL } },
{ NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY, "0", TYPE_BOTH, 0, 2,
{ "layer2", "layer3+4", "layer2+3", NULL } },
{ NM_SETTING_BOND_OPTION_RESEND_IGMP, "1", TYPE_INT, 0, 255 },
};
/**
* nm_setting_bond_new:
*
* Creates a new #NMSettingBond object with default values.
*
* Returns: (transfer full): the new empty #NMSettingBond object
**/
NMSetting *
nm_setting_bond_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BOND, NULL);
}
/**
* nm_setting_bond_get_interface_name:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:interface-name property of the setting
**/
const char *
nm_setting_bond_get_interface_name (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
return NM_SETTING_BOND_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_bond_get_num_options:
* @setting: the #NMSettingBond
*
* Returns the number of options that should be set for this bond when it
* is activated. This can be used to retrieve each option individually
* using nm_setting_bond_get_option().
*
* Returns: the number of bonding options
**/
guint32
nm_setting_bond_get_num_options (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), 0);
return g_hash_table_size (NM_SETTING_BOND_GET_PRIVATE (setting)->options);
}
/**
* nm_setting_bond_get_option:
* @setting: the #NMSettingBond
* @idx: index of the desired option, from 0 to
* nm_setting_bond_get_num_options() - 1
* @out_name: (out): on return, the name of the bonding option; this
* value is owned by the setting and should not be modified
* @out_value: (out): on return, the value of the name of the bonding
* option; this value is owned by the setting and should not be modified
*
* Given an index, return the value of the bonding option at that index. Indexes
* are *not* guaranteed to be static across modifications to options done by
* nm_setting_bond_add_option() and nm_setting_bond_remove_option(),
* and should not be used to refer to options except for short periods of time
* such as during option iteration.
*
* Returns: %TRUE on success if the index was valid and an option was found,
* %FALSE if the index was invalid (ie, greater than the number of options
* currently held by the setting)
**/
gboolean
nm_setting_bond_get_option (NMSettingBond *setting,
guint32 idx,
const char **out_name,
const char **out_value)
{
NMSettingBondPrivate *priv;
GList *keys;
const char *_key = NULL, *_value = NULL;
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
priv = NM_SETTING_BOND_GET_PRIVATE (setting);
if (idx >= nm_setting_bond_get_num_options (setting))
return FALSE;
keys = g_hash_table_get_keys (priv->options);
_key = g_list_nth_data (keys, idx);
_value = g_hash_table_lookup (priv->options, _key);
if (out_name)
*out_name = _key;
if (out_value)
*out_value = _value;
g_list_free (keys);
return TRUE;
}
static gboolean
validate_int (const char *name, const char *value, const BondDefault *def)
{
glong num;
guint i;
for (i = 0; i < strlen (value); i++) {
if (!g_ascii_isdigit (value[i]) && value[i] != '-')
return FALSE;
}
errno = 0;
num = strtol (value, NULL, 10);
if (errno)
return FALSE;
if (num < def->min || num > def->max)
return FALSE;
return TRUE;
}
static gboolean
validate_list (const char *name, const char *value, const BondDefault *def)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (def->list) && def->list[i]; i++) {
if (g_strcmp0 (def->list[i], value) == 0)
return TRUE;
}
/* empty validation list means all values pass */
return def->list[0] == NULL ? TRUE : FALSE;
}
static gboolean
validate_ip (const char *name, const char *value)
{
char **ips, **iter;
gboolean success = TRUE;
struct in_addr addr;
if (!value || !value[0])
return FALSE;
ips = g_strsplit_set (value, ",", 0);
for (iter = ips; iter && *iter && success; iter++)
success = !!inet_aton (*iter, &addr);
g_strfreev (ips);
return success;
}
static gboolean
validate_ifname (const char *name, const char *value)
{
if (!value || !value[0])
return FALSE;
return nm_utils_iface_valid_name (value);
}
/**
* nm_setting_bond_validate_option:
* @name: the name of the option to validate
* @value: the value of the option to validate
*
* Checks whether @name is a valid bond option and @value is a valid value for
* the @name. If @value is %NULL, the function only validates the option name.
*
* Returns: %TRUE, if the @value is valid for the given name.
* If the @name is not a valid option, %FALSE will be returned.
*
* Since: 0.9.10
**/
gboolean
nm_setting_bond_validate_option (const char *name,
const char *value)
{
guint i;
if (!name || !name[0])
return FALSE;
for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
if (g_strcmp0 (defaults[i].opt, name) == 0) {
if (value == NULL)
return TRUE;
switch (defaults[i].opt_type) {
case TYPE_INT:
return validate_int (name, value, &defaults[i]);
case TYPE_STR:
return validate_list (name, value, &defaults[i]);
case TYPE_BOTH:
return ( validate_int (name, value, &defaults[i])
|| validate_list (name, value, &defaults[i]));
case TYPE_IP:
return validate_ip (name, value);
case TYPE_IFNAME:
return validate_ifname (name, value);
}
return FALSE;
}
}
return FALSE;
}
/**
* nm_setting_bond_get_option_by_name:
* @setting: the #NMSettingBond
* @name: the option name for which to retrieve the value
*
* Returns the value associated with the bonding option specified by
* @name, if it exists.
*
* Returns: the value, or %NULL if the key/value pair was never added to the
* setting; the value is owned by the setting and must not be modified
**/
const char *
nm_setting_bond_get_option_by_name (NMSettingBond *setting,
const char *name)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
if (!nm_setting_bond_validate_option (name, NULL))
return NULL;
return g_hash_table_lookup (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
}
/**
* nm_setting_bond_add_option:
* @setting: the #NMSettingBond
* @name: name for the option
* @value: value for the option
*
* Add an option to the table. The option is compared to an internal list
* of allowed options. Option names may contain only alphanumeric characters
* (ie [a-zA-Z0-9]). Adding a new name replaces any existing name/value pair
* that may already exist.
*
* The order of how to set several options is relevant because there are options
* that conflict with each other.
*
* Returns: %TRUE if the option was valid and was added to the internal option
* list, %FALSE if it was not.
**/
gboolean
nm_setting_bond_add_option (NMSettingBond *setting,
const char *name,
const char *value)
{
NMSettingBondPrivate *priv;
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
if (!value || !nm_setting_bond_validate_option (name, value))
return FALSE;
priv = NM_SETTING_BOND_GET_PRIVATE (setting);
g_hash_table_insert (priv->options, g_strdup (name), g_strdup (value));
if ( !strcmp (name, NM_SETTING_BOND_OPTION_MIIMON)
&& strcmp (value, "0") != 0) {
g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
} else if ( !strcmp (name, NM_SETTING_BOND_OPTION_ARP_INTERVAL)
&& strcmp (value, "0") != 0) {
g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY);
g_hash_table_remove (priv->options, NM_SETTING_BOND_OPTION_UPDELAY);
}
g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS);
return TRUE;
}
/**
* nm_setting_bond_remove_option:
* @setting: the #NMSettingBond
* @name: name of the option to remove
*
* Remove the bonding option referenced by @name from the internal option
* list.
*
* Returns: %TRUE if the option was found and removed from the internal option
* list, %FALSE if it was not.
**/
gboolean
nm_setting_bond_remove_option (NMSettingBond *setting,
const char *name)
{
gboolean found;
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), FALSE);
if (!nm_setting_bond_validate_option (name, NULL))
return FALSE;
found = g_hash_table_remove (NM_SETTING_BOND_GET_PRIVATE (setting)->options, name);
if (found)
g_object_notify (G_OBJECT (setting), NM_SETTING_BOND_OPTIONS);
return found;
}
/**
* nm_setting_bond_get_valid_options:
* @setting: the #NMSettingBond
*
* Returns a list of valid bond options.
*
* Returns: (transfer none): a %NULL-terminated array of strings of valid bond options.
**/
const char **
nm_setting_bond_get_valid_options (NMSettingBond *setting)
{
static const char *array[G_N_ELEMENTS (defaults) + 1] = { NULL };
int i;
/* initialize the array once */
if (G_UNLIKELY (array[0] == NULL)) {
for (i = 0; i < G_N_ELEMENTS (defaults); i++)
array[i] = defaults[i].opt;
array[i] = NULL;
}
return array;
}
/**
* nm_setting_bond_get_option_default:
* @setting: the #NMSettingBond
* @name: the name of the option
*
* Returns: the value of the bond option if not overridden by an entry in
* the #NMSettingBond:options property.
**/
const char *
nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
{
guint i;
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
g_return_val_if_fail (nm_setting_bond_validate_option (name, NULL), NULL);
for (i = 0; i < G_N_ELEMENTS (defaults); i++) {
if (g_strcmp0 (defaults[i].opt, name) == 0)
return defaults[i].val;
}
/* Any option that passes nm_setting_bond_validate_option() should also be found in defaults */
g_assert_not_reached ();
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
GHashTableIter iter;
const char *key, *value;
const char *valid_modes[] = { "balance-rr",
"active-backup",
"balance-xor",
"broadcast",
"802.3ad",
"balance-tlb",
"balance-alb",
NULL };
int miimon = 0, arp_interval = 0;
const char *arp_ip_target = NULL;
const char *primary;
g_hash_table_iter_init (&iter, priv->options);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value)) {
if (!value[0] || !nm_setting_bond_validate_option (key, value)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("invalid option '%s' or its value '%s'"),
key, value);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
}
value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MIIMON);
if (value)
miimon = atoi (value);
value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
if (value)
arp_interval = atoi (value);
/* Can only set one of miimon and arp_interval */
if (miimon > 0 && arp_interval > 0) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("only one of '%s' and '%s' can be set"),
NM_SETTING_BOND_OPTION_MIIMON,
NM_SETTING_BOND_OPTION_ARP_INTERVAL);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
}
value = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_MODE);
if (!value) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_MISSING_OPTION,
_("mandatory option '%s' is missing"),
NM_SETTING_BOND_OPTION_MODE);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
if (!_nm_utils_string_in_list (value, valid_modes)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' is not a valid value for '%s'"),
value, NM_SETTING_BOND_OPTION_MODE);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
/* Make sure mode is compatible with other settings */
if ( strcmp (value, "balance-alb") == 0
|| strcmp (value, "balance-tlb") == 0) {
if (arp_interval > 0) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s=%s' is incompatible with '%s > 0'"),
NM_SETTING_BOND_OPTION_MODE, value, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
}
primary = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_PRIMARY);
if (strcmp (value, "active-backup") == 0) {
if (primary && !nm_utils_iface_valid_name (primary)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' is not a valid interface name for '%s' option"),
primary, NM_SETTING_BOND_OPTION_PRIMARY);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
} else {
if (primary) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' option is only valid for '%s=%s'"),
NM_SETTING_BOND_OPTION_PRIMARY,
NM_SETTING_BOND_OPTION_MODE, "active-backup");
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
}
if (nm_setting_find_in_list (all_settings, NM_SETTING_INFINIBAND_SETTING_NAME)) {
if (strcmp (value, "active-backup") != 0) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s=%s' is not a valid configuration for '%s'"),
NM_SETTING_BOND_OPTION_MODE, value, NM_SETTING_INFINIBAND_SETTING_NAME);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
}
if (miimon == 0) {
/* updelay and downdelay can only be used with miimon */
if (g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_UPDELAY)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' option requires '%s' option to be set"),
NM_SETTING_BOND_OPTION_UPDELAY, NM_SETTING_BOND_OPTION_MIIMON);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
if (g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_DOWNDELAY)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' option requires '%s' option to be set"),
NM_SETTING_BOND_OPTION_DOWNDELAY, NM_SETTING_BOND_OPTION_MIIMON);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
}
/* arp_ip_target can only be used with arp_interval, and must
* contain a comma-separated list of IPv4 addresses.
*/
arp_ip_target = g_hash_table_lookup (priv->options, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
if (arp_interval > 0) {
char **addrs;
guint32 addr;
int i;
if (!arp_ip_target) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_MISSING_OPTION,
_("'%s' option requires '%s' option to be set"),
NM_SETTING_BOND_OPTION_ARP_INTERVAL, NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
addrs = g_strsplit (arp_ip_target, ",", -1);
if (!addrs[0]) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' option is empty"),
NM_SETTING_BOND_OPTION_ARP_IP_TARGET);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
g_strfreev (addrs);
return FALSE;
}
for (i = 0; addrs[i]; i++) {
if (!inet_pton (AF_INET, addrs[i], &addr)) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' is not a valid IPv4 address for '%s' option"),
NM_SETTING_BOND_OPTION_ARP_IP_TARGET, addrs[i]);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
g_strfreev (addrs);
return FALSE;
}
}
g_strfreev (addrs);
} else {
if (arp_ip_target) {
g_set_error (error,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_OPTION,
_("'%s' option requires '%s' option to be set"),
NM_SETTING_BOND_OPTION_ARP_IP_TARGET, NM_SETTING_BOND_OPTION_ARP_INTERVAL);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_OPTIONS);
return FALSE;
}
}
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingBond *self = NM_SETTING_BOND (setting);
return nm_setting_bond_get_interface_name (self);
}
static void
nm_setting_bond_init (NMSettingBond *setting)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (setting);
priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
/* Default values: */
nm_setting_bond_add_option (setting, NM_SETTING_BOND_OPTION_MODE, "balance-rr");
}
static void
finalize (GObject *object)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
g_free (priv->interface_name);
g_hash_table_destroy (priv->options);
G_OBJECT_CLASS (nm_setting_bond_parent_class)->finalize (object);
}
static void
copy_hash (gpointer key, gpointer value, gpointer user_data)
{
g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
GHashTable *new_hash;
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_OPTIONS:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (priv->options);
new_hash = g_value_get_boxed (value);
if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, priv->options);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
NMSettingBond *setting = NM_SETTING_BOND (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_bond_get_interface_name (setting));
break;
case PROP_OPTIONS:
g_value_set_boxed (value, priv->options);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_bond_class_init (NMSettingBondClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingBondPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
* NMSettingBond:interface-name:
*
* The name of the virtual in-kernel bonding network interface
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_BOND_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBond:options:
*
* Dictionary of key/value pairs of bonding options. Both keys and values
* must be strings. Option names must contain only alphanumeric characters
* (ie, [a-zA-Z0-9]).
**/
g_object_class_install_property
(object_class, PROP_OPTIONS,
_nm_param_spec_specialized (NM_SETTING_BOND_OPTIONS, "", "",
DBUS_TYPE_G_MAP_OF_STRING,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,117 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2013 Red Hat, Inc.
*/
#ifndef NM_SETTING_BOND_H
#define NM_SETTING_BOND_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_BOND (nm_setting_bond_get_type ())
#define NM_SETTING_BOND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BOND, NMSettingBond))
#define NM_SETTING_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BOND, NMSettingBondClass))
#define NM_IS_SETTING_BOND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BOND))
#define NM_IS_SETTING_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_BOND))
#define NM_SETTING_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BOND, NMSettingBondClass))
#define NM_SETTING_BOND_SETTING_NAME "bond"
/**
* NMSettingBondError:
* @NM_SETTING_BOND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_BOND_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_BOND_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_BOND_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_BOND_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_BOND_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_BOND_ERROR_INVALID_OPTION, /*< nick=InvalidOption >*/
NM_SETTING_BOND_ERROR_MISSING_OPTION, /*< nick=MissingOption >*/
} NMSettingBondError;
#define NM_SETTING_BOND_ERROR nm_setting_bond_error_quark ()
GQuark nm_setting_bond_error_quark (void);
#define NM_SETTING_BOND_INTERFACE_NAME "interface-name"
#define NM_SETTING_BOND_OPTIONS "options"
/* Valid options for the 'options' property */
#define NM_SETTING_BOND_OPTION_MODE "mode"
#define NM_SETTING_BOND_OPTION_MIIMON "miimon"
#define NM_SETTING_BOND_OPTION_DOWNDELAY "downdelay"
#define NM_SETTING_BOND_OPTION_UPDELAY "updelay"
#define NM_SETTING_BOND_OPTION_ARP_INTERVAL "arp_interval"
#define NM_SETTING_BOND_OPTION_ARP_IP_TARGET "arp_ip_target"
#define NM_SETTING_BOND_OPTION_ARP_VALIDATE "arp_validate"
#define NM_SETTING_BOND_OPTION_PRIMARY "primary"
#define NM_SETTING_BOND_OPTION_PRIMARY_RESELECT "primary_reselect"
#define NM_SETTING_BOND_OPTION_FAIL_OVER_MAC "fail_over_mac"
#define NM_SETTING_BOND_OPTION_USE_CARRIER "use_carrier"
#define NM_SETTING_BOND_OPTION_AD_SELECT "ad_select"
#define NM_SETTING_BOND_OPTION_XMIT_HASH_POLICY "xmit_hash_policy"
#define NM_SETTING_BOND_OPTION_RESEND_IGMP "resend_igmp"
typedef struct {
NMSetting parent;
} NMSettingBond;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingBondClass;
GType nm_setting_bond_get_type (void);
NMSetting * nm_setting_bond_new (void);
const char * nm_setting_bond_get_interface_name (NMSettingBond *setting);
guint32 nm_setting_bond_get_num_options (NMSettingBond *setting);
gboolean nm_setting_bond_get_option (NMSettingBond *setting,
guint32 idx,
const char **out_name,
const char **out_value);
const char * nm_setting_bond_get_option_by_name (NMSettingBond *setting,
const char *name);
gboolean nm_setting_bond_add_option (NMSettingBond *setting,
const char *name,
const char *value);
gboolean nm_setting_bond_remove_option (NMSettingBond *setting,
const char *name);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_bond_validate_option (const char *name,
const char *value);
const char **nm_setting_bond_get_valid_options (NMSettingBond *setting);
const char * nm_setting_bond_get_option_default (NMSettingBond *setting,
const char *name);
G_END_DECLS
#endif /* NM_SETTING_BOND_H */

View File

@@ -0,0 +1,304 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2012 - 2013 Red Hat, Inc.
*/
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-bridge-port.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-bridge-port
* @short_description: Describes connection properties for bridge ports
* @include: nm-setting-bridge-port.h
*
* The #NMSettingBridgePort object is a #NMSetting subclass that describes
* optional properties that apply to bridge ports.
*
* Since: 0.9.8
**/
/**
* nm_setting_bridge_port_error_quark:
*
* Registers an error quark for #NMSettingBridgePort if necessary.
*
* Returns: the error quark used for #NMSettingBridgePort errors.
*
* Since: 0.9.8
**/
GQuark
nm_setting_bridge_port_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-bridge-port-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingBridgePort, nm_setting_bridge_port, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_BRIDGE_PORT_SETTING_NAME,
g_define_type_id,
3,
NM_SETTING_BRIDGE_PORT_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE_PORT)
#define NM_SETTING_BRIDGE_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortPrivate))
typedef struct {
guint16 priority;
guint16 path_cost;
gboolean hairpin_mode;
} NMSettingBridgePortPrivate;
enum {
PROP_0,
PROP_PRIORITY,
PROP_PATH_COST,
PROP_HAIRPIN_MODE,
LAST_PROP
};
/**************************************************************************/
/**
* nm_setting_bridge_port_get_priority:
* @setting: the #NMSettingBridgePort
*
* Returns: the #NMSettingBridgePort:priority property of the setting
*
* Since: 0.9.8
**/
guint16
nm_setting_bridge_port_get_priority (NMSettingBridgePort *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), 0);
return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->priority;
}
/**
* nm_setting_bridge_port_get_path_cost:
* @setting: the #NMSettingBridgePort
*
* Returns: the #NMSettingBridgePort:path-cost property of the setting
*
* Since: 0.9.8
**/
guint16
nm_setting_bridge_port_get_path_cost (NMSettingBridgePort *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), 0);
return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->path_cost;
}
/**
* nm_setting_bridge_port_get_hairpin_mode:
* @setting: the #NMSettingBridgePort
*
* Returns: the #NMSettingBridgePort:hairpin-mode property of the setting
*
* Since: 0.9.8
**/
gboolean
nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), FALSE);
return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->hairpin_mode;
}
/**************************************************************************/
#define BR_MAX_PORT_PRIORITY 63
#define BR_DEF_PRIORITY 32
#define BR_MIN_PATH_COST 1
#define BR_MAX_PATH_COST 65535
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting);
if (priv->priority > BR_MAX_PORT_PRIORITY) {
g_set_error (error,
NM_SETTING_BRIDGE_PORT_ERROR,
NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY,
_("'%d' is not a valid value for the property (should be <= %d)"),
priv->priority, BR_MAX_PORT_PRIORITY);
g_prefix_error (error, "%s.%s: ",
NM_SETTING_BRIDGE_PORT_SETTING_NAME,
NM_SETTING_BRIDGE_PORT_PRIORITY);
return FALSE;
}
if (priv->path_cost > BR_MAX_PATH_COST) {
g_set_error (error,
NM_SETTING_BRIDGE_PORT_ERROR,
NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY,
_("'%d' is not a valid value for the property (should be <= %d)"),
priv->path_cost, BR_MAX_PATH_COST);
g_prefix_error (error, "%s.%s: ",
NM_SETTING_BRIDGE_PORT_SETTING_NAME,
NM_SETTING_BRIDGE_PORT_PATH_COST);
return FALSE;
}
return TRUE;
}
/**************************************************************************/
/**
* nm_setting_bridge_port_new:
*
* Creates a new #NMSettingBridgePort object with default values.
*
* Returns: (transfer full): the new empty #NMSettingBridgePort object
*
* Since: 0.9.8
**/
NMSetting *
nm_setting_bridge_port_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE_PORT, NULL);
}
static void
nm_setting_bridge_port_init (NMSettingBridgePort *setting)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (object);
switch (prop_id) {
case PROP_PRIORITY:
priv->priority = (guint16) (g_value_get_uint (value) & 0xFFFF);
break;
case PROP_PATH_COST:
priv->path_cost = (guint16) (g_value_get_uint (value) & 0xFFFF);
break;
case PROP_HAIRPIN_MODE:
priv->hairpin_mode = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (object);
switch (prop_id) {
case PROP_PRIORITY:
g_value_set_uint (value, priv->priority);
break;
case PROP_PATH_COST:
g_value_set_uint (value, priv->path_cost);
break;
case PROP_HAIRPIN_MODE:
g_value_set_boolean (value, priv->hairpin_mode);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_bridge_port_class_init (NMSettingBridgePortClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingBridgePortPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingBridgePort:priority:
*
* The Spanning Tree Protocol (STP) priority of this bridge port.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_PRIORITY,
g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PRIORITY, "", "",
0, BR_MAX_PORT_PRIORITY, BR_DEF_PRIORITY,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridgePort:path-cost:
*
* The Spanning Tree Protocol (STP) port cost for destinations via this
* port.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_PATH_COST,
g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PATH_COST, "", "",
0, BR_MAX_PATH_COST, 100,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridgePort:hairpin-mode:
*
* Enables or disabled "hairpin mode" for the port, which allows frames to
* be sent back out through the port the frame was received on.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_HAIRPIN_MODE,
g_param_spec_boolean (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, "", "",
FALSE,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,86 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2012 Red Hat, Inc.
*/
#ifndef NM_SETTING_BRIDGE_PORT_H
#define NM_SETTING_BRIDGE_PORT_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_BRIDGE_PORT (nm_setting_bridge_port_get_type ())
#define NM_SETTING_BRIDGE_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePort))
#define NM_SETTING_BRIDGE_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortClass))
#define NM_IS_SETTING_BRIDGE_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BRIDGE_PORT))
#define NM_IS_SETTING_BRIDGE_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_BRIDGE_PORT))
#define NM_SETTING_BRIDGE_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortClass))
#define NM_SETTING_BRIDGE_PORT_SETTING_NAME "bridge-port"
/**
* NMSettingBridgePortError:
* @NM_SETTING_BRIDGE_PORT_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_BRIDGE_PORT_ERROR_MISSING_PROPERTY: the property was missing and
* is required
*
* Since: 0.9.8
*/
typedef enum {
NM_SETTING_BRIDGE_PORT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_BRIDGE_PORT_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
} NMSettingBridgePortError;
#define NM_SETTING_BRIDGE_PORT_ERROR nm_setting_bridge_port_error_quark ()
GQuark nm_setting_bridge_port_error_quark (void);
#define NM_SETTING_BRIDGE_PORT_PRIORITY "priority"
#define NM_SETTING_BRIDGE_PORT_PATH_COST "path-cost"
#define NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE "hairpin-mode"
typedef struct {
NMSetting parent;
} NMSettingBridgePort;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingBridgePortClass;
GType nm_setting_bridge_port_get_type (void);
NMSetting * nm_setting_bridge_port_new (void);
guint16 nm_setting_bridge_port_get_priority (NMSettingBridgePort *setting);
guint16 nm_setting_bridge_port_get_path_cost (NMSettingBridgePort *setting);
gboolean nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting);
G_END_DECLS
#endif /* NM_SETTING_BRIDGE_PORT_H */

View File

@@ -0,0 +1,576 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2013 Red Hat, Inc.
*/
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include <linux/if_ether.h>
#include "nm-setting-bridge.h"
#include "nm-param-spec-specialized.h"
#include "nm-setting-private.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
/**
* SECTION:nm-setting-bridge
* @short_description: Describes connection properties for bridges
* @include: nm-setting-bridge.h
*
* The #NMSettingBridge object is a #NMSetting subclass that describes properties
* necessary for bridging connections.
*
* Since: 0.9.8
**/
/**
* nm_setting_bridge_error_quark:
*
* Registers an error quark for #NMSettingBridge if necessary.
*
* Returns: the error quark used for #NMSettingBridge errors.
*
* Since: 0.9.8
**/
GQuark
nm_setting_bridge_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-bridge-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingBridge, nm_setting_bridge, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_BRIDGE_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_BRIDGE_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE)
#define NM_SETTING_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE, NMSettingBridgePrivate))
typedef struct {
char * interface_name;
GByteArray *mac_address;
gboolean stp;
guint16 priority;
guint16 forward_delay;
guint16 hello_time;
guint16 max_age;
guint32 ageing_time;
} NMSettingBridgePrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_MAC_ADDRESS,
PROP_STP,
PROP_PRIORITY,
PROP_FORWARD_DELAY,
PROP_HELLO_TIME,
PROP_MAX_AGE,
PROP_AGEING_TIME,
LAST_PROP
};
/**
* nm_setting_bridge_new:
*
* Creates a new #NMSettingBridge object with default values.
*
* Returns: (transfer full): the new empty #NMSettingBridge object
*
* Since: 0.9.8
**/
NMSetting *
nm_setting_bridge_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE, NULL);
}
/**
* nm_setting_bridge_get_interface_name:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:interface-name property of the setting
*
* Since: 0.9.8
**/
const char *
nm_setting_bridge_get_interface_name (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_bridge_get_mac_address:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:mac-address property of the setting
*
* Since: 0.9.10
**/
const GByteArray *
nm_setting_bridge_get_mac_address (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), NULL);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->mac_address;
}
/**
* nm_setting_bridge_get_stp:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:stp property of the setting
*
* Since: 0.9.8
**/
gboolean
nm_setting_bridge_get_stp (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), FALSE);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->stp;
}
/**
* nm_setting_bridge_get_priority:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:priority property of the setting
*
* Since: 0.9.8
**/
guint16
nm_setting_bridge_get_priority (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->priority;
}
/**
* nm_setting_bridge_get_forward_delay:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:forward-delay property of the setting
*
* Since: 0.9.8
**/
guint16
nm_setting_bridge_get_forward_delay (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->forward_delay;
}
/**
* nm_setting_bridge_get_hello_time:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:hello-time property of the setting
*
* Since: 0.9.8
**/
guint16
nm_setting_bridge_get_hello_time (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->hello_time;
}
/**
* nm_setting_bridge_get_max_age:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:max-age property of the setting
*
* Since: 0.9.8
**/
guint16
nm_setting_bridge_get_max_age (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->max_age;
}
/**
* nm_setting_bridge_get_ageing_time:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:ageing-time property of the setting
*
* Since: 0.9.8
**/
guint
nm_setting_bridge_get_ageing_time (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->ageing_time;
}
/* IEEE 802.1D-1998 timer values */
#define BR_MIN_HELLO_TIME 1
#define BR_MAX_HELLO_TIME 10
#define BR_MIN_FORWARD_DELAY 2
#define BR_MAX_FORWARD_DELAY 30
#define BR_MIN_MAX_AGE 6
#define BR_MAX_MAX_AGE 40
/* IEEE 802.1D-1998 Table 7.4 */
#define BR_MIN_AGEING_TIME 0
#define BR_MAX_AGEING_TIME 1000000
static inline gboolean
check_range (guint32 val,
guint32 min,
guint32 max,
const char *prop,
GError **error)
{
if ((val != 0) && (val < min || val > max)) {
g_set_error (error,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
_("value '%d' is out of range <%d-%d>"),
val, min, max);
g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, prop);
return FALSE;
}
return TRUE;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
if (priv->mac_address && priv->mac_address->len != ETH_ALEN) {
g_set_error_literal (error,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
_("is not a valid MAC address"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_MAC_ADDRESS);
return FALSE;
}
if (!check_range (priv->forward_delay,
BR_MIN_FORWARD_DELAY,
BR_MAX_FORWARD_DELAY,
NM_SETTING_BRIDGE_FORWARD_DELAY,
error))
return FALSE;
if (!check_range (priv->hello_time,
BR_MIN_HELLO_TIME,
BR_MAX_HELLO_TIME,
NM_SETTING_BRIDGE_HELLO_TIME,
error))
return FALSE;
if (!check_range (priv->max_age,
BR_MIN_MAX_AGE,
BR_MAX_MAX_AGE,
NM_SETTING_BRIDGE_MAX_AGE,
error))
return FALSE;
if (!check_range (priv->ageing_time,
BR_MIN_AGEING_TIME,
BR_MAX_AGEING_TIME,
NM_SETTING_BRIDGE_AGEING_TIME,
error))
return FALSE;
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_INTERFACE_NAME,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingBridge *self = NM_SETTING_BRIDGE (setting);
return nm_setting_bridge_get_interface_name (self);
}
static void
nm_setting_bridge_init (NMSettingBridge *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
g_free (priv->interface_name);
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
G_OBJECT_CLASS (nm_setting_bridge_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_MAC_ADDRESS:
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
priv->mac_address = g_value_dup_boxed (value);
break;
case PROP_STP:
priv->stp = g_value_get_boolean (value);
break;
case PROP_PRIORITY:
priv->priority = (guint16) g_value_get_uint (value);
break;
case PROP_FORWARD_DELAY:
priv->forward_delay = (guint16) g_value_get_uint (value);
break;
case PROP_HELLO_TIME:
priv->hello_time = (guint16) g_value_get_uint (value);
break;
case PROP_MAX_AGE:
priv->max_age = (guint16) g_value_get_uint (value);
break;
case PROP_AGEING_TIME:
priv->ageing_time = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
NMSettingBridge *setting = NM_SETTING_BRIDGE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_bridge_get_interface_name (setting));
break;
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, nm_setting_bridge_get_mac_address (setting));
break;
case PROP_STP:
g_value_set_boolean (value, priv->stp);
break;
case PROP_PRIORITY:
g_value_set_uint (value, priv->priority);
break;
case PROP_FORWARD_DELAY:
g_value_set_uint (value, priv->forward_delay);
break;
case PROP_HELLO_TIME:
g_value_set_uint (value, priv->hello_time);
break;
case PROP_MAX_AGE:
g_value_set_uint (value, priv->max_age);
break;
case PROP_AGEING_TIME:
g_value_set_uint (value, priv->ageing_time);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingBridgePrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
* NMSettingBridge:interface-name:
*
* The name of the virtual in-kernel bridging network interface
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_BRIDGE_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:mac-address:
*
* If specified, the MAC address of bridge. When creating a new bridge, this
* MAC address will be set. When matching an existing (outside
* NetworkManager created) bridge, this MAC address must match.
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
_nm_param_spec_specialized (NM_SETTING_BRIDGE_MAC_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:stp:
*
* Controls whether Spanning Tree Protocol (STP) is enabled for this bridge.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_STP,
g_param_spec_boolean (NM_SETTING_BRIDGE_STP, "", "",
TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:priority:
*
* Sets the Spanning Tree Protocol (STP) priority for this bridge. Lower
* values are "better"; the lowest priority bridge will be elected the root
* bridge.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_PRIORITY,
g_param_spec_uint (NM_SETTING_BRIDGE_PRIORITY, "", "",
0, G_MAXUINT16, 0x8000,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:forward-delay:
*
* The Spanning Tree Protocol (STP) forwarding delay, in seconds.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_FORWARD_DELAY,
g_param_spec_uint (NM_SETTING_BRIDGE_FORWARD_DELAY, "", "",
0, BR_MAX_FORWARD_DELAY, 15,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:hello-time:
*
* The Spanning Tree Protocol (STP) hello time, in seconds.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_HELLO_TIME,
g_param_spec_uint (NM_SETTING_BRIDGE_HELLO_TIME, "", "",
0, BR_MAX_HELLO_TIME, 2,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:max-age:
*
* The Spanning Tree Protocol (STP) maximum message age, in seconds.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_MAX_AGE,
g_param_spec_uint (NM_SETTING_BRIDGE_MAX_AGE, "", "",
0, BR_MAX_MAX_AGE, 20,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:ageing-time:
*
* The Ethernet MAC address aging time, in seconds.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_AGEING_TIME,
g_param_spec_uint (NM_SETTING_BRIDGE_AGEING_TIME, "", "",
0, BR_MAX_AGEING_TIME, 300,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,102 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2012 Red Hat, Inc.
*/
#ifndef NM_SETTING_BRIDGE_H
#define NM_SETTING_BRIDGE_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_BRIDGE (nm_setting_bridge_get_type ())
#define NM_SETTING_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BRIDGE, NMSettingBridge))
#define NM_SETTING_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BRIDGE, NMSettingBridgeClass))
#define NM_IS_SETTING_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BRIDGE))
#define NM_IS_SETTING_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_BRIDGE))
#define NM_SETTING_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BRIDGE, NMSettingBridgeClass))
#define NM_SETTING_BRIDGE_SETTING_NAME "bridge"
/**
* NMSettingBridgeError:
* @NM_SETTING_BRIDGE_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*
* Since: 0.9.8
*/
typedef enum {
NM_SETTING_BRIDGE_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
} NMSettingBridgeError;
#define NM_SETTING_BRIDGE_ERROR nm_setting_bridge_error_quark ()
GQuark nm_setting_bridge_error_quark (void);
#define NM_SETTING_BRIDGE_INTERFACE_NAME "interface-name"
#define NM_SETTING_BRIDGE_MAC_ADDRESS "mac-address"
#define NM_SETTING_BRIDGE_STP "stp"
#define NM_SETTING_BRIDGE_PRIORITY "priority"
#define NM_SETTING_BRIDGE_FORWARD_DELAY "forward-delay"
#define NM_SETTING_BRIDGE_HELLO_TIME "hello-time"
#define NM_SETTING_BRIDGE_MAX_AGE "max-age"
#define NM_SETTING_BRIDGE_AGEING_TIME "ageing-time"
typedef struct {
NMSetting parent;
} NMSettingBridge;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingBridgeClass;
GType nm_setting_bridge_get_type (void);
NMSetting * nm_setting_bridge_new (void);
const char * nm_setting_bridge_get_interface_name (NMSettingBridge *setting);
NM_AVAILABLE_IN_0_9_10
const GByteArray *nm_setting_bridge_get_mac_address (NMSettingBridge *setting);
gboolean nm_setting_bridge_get_stp (NMSettingBridge *setting);
guint16 nm_setting_bridge_get_priority (NMSettingBridge *setting);
guint16 nm_setting_bridge_get_forward_delay (NMSettingBridge *setting);
guint16 nm_setting_bridge_get_hello_time (NMSettingBridge *setting);
guint16 nm_setting_bridge_get_max_age (NMSettingBridge *setting);
guint32 nm_setting_bridge_get_ageing_time (NMSettingBridge *setting);
G_END_DECLS
#endif /* NM_SETTING_BRIDGE_H */

View File

@@ -0,0 +1,356 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
*/
#include <string.h>
#include <glib/gi18n.h>
#include "nm-setting-cdma.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-cdma
* @short_description: Describes CDMA-based mobile broadband properties
* @include: nm-setting-cdma.h
*
* The #NMSettingCdma object is a #NMSetting subclass that describes
* properties that allow connections to IS-95-based mobile broadband
* networks, including those using CDMA2000/EVDO technology.
*/
/**
* nm_setting_cdma_error_quark:
*
* Registers an error quark for #NMSettingCdma if necessary.
*
* Returns: the error quark used for #NMSettingCdma errors.
**/
GQuark
nm_setting_cdma_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-cdma-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingCdma, nm_setting_cdma, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_CDMA_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_CDMA_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_CDMA)
#define NM_SETTING_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_CDMA, NMSettingCdmaPrivate))
typedef struct {
char *number; /* For dialing, duh */
char *username;
char *password;
NMSettingSecretFlags password_flags;
} NMSettingCdmaPrivate;
enum {
PROP_0,
PROP_NUMBER,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
LAST_PROP
};
/**
* nm_setting_cdma_new:
*
* Creates a new #NMSettingCdma object with default values.
*
* Returns: the new empty #NMSettingCdma object
**/
NMSetting *
nm_setting_cdma_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_CDMA, NULL);
}
/**
* nm_setting_cdma_get_number:
* @setting: the #NMSettingCdma
*
* Returns: the #NMSettingCdma:number property of the setting
**/
const char *
nm_setting_cdma_get_number (NMSettingCdma *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
return NM_SETTING_CDMA_GET_PRIVATE (setting)->number;
}
/**
* nm_setting_cdma_get_username:
* @setting: the #NMSettingCdma
*
* Returns: the #NMSettingCdma:username property of the setting
**/
const char *
nm_setting_cdma_get_username (NMSettingCdma *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
return NM_SETTING_CDMA_GET_PRIVATE (setting)->username;
}
/**
* nm_setting_cdma_get_password:
* @setting: the #NMSettingCdma
*
* Returns: the #NMSettingCdma:password property of the setting
**/
const char *
nm_setting_cdma_get_password (NMSettingCdma *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NULL);
return NM_SETTING_CDMA_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_cdma_get_password_flags:
* @setting: the #NMSettingCdma
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingCdma:password
**/
NMSettingSecretFlags
nm_setting_cdma_get_password_flags (NMSettingCdma *setting)
{
g_return_val_if_fail (NM_IS_SETTING_CDMA (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_CDMA_GET_PRIVATE (setting)->password_flags;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);
if (!priv->number) {
g_set_error_literal (error,
NM_SETTING_CDMA_ERROR,
NM_SETTING_CDMA_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_NUMBER);
return FALSE;
} else if (!strlen (priv->number)) {
g_set_error_literal (error,
NM_SETTING_CDMA_ERROR,
NM_SETTING_CDMA_ERROR_INVALID_PROPERTY,
_("property is empty'"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_NUMBER);
return FALSE;
}
if (priv->username && !strlen (priv->username)) {
g_set_error_literal (error,
NM_SETTING_CDMA_ERROR,
NM_SETTING_CDMA_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_USERNAME);
return FALSE;
}
if (priv->password && !strlen (priv->password)) {
g_set_error_literal (error,
NM_SETTING_CDMA_ERROR,
NM_SETTING_CDMA_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CDMA_SETTING_NAME, NM_SETTING_CDMA_PASSWORD);
return FALSE;
}
return TRUE;
}
static GPtrArray *
need_secrets (NMSetting *setting)
{
NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (setting);
GPtrArray *secrets = NULL;
if (priv->password)
return NULL;
if (priv->username) {
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_CDMA_PASSWORD);
}
}
return secrets;
}
static void
nm_setting_cdma_init (NMSettingCdma *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (object);
g_free (priv->number);
g_free (priv->username);
g_free (priv->password);
G_OBJECT_CLASS (nm_setting_cdma_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingCdmaPrivate *priv = NM_SETTING_CDMA_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NUMBER:
g_free (priv->number);
priv->number = g_value_dup_string (value);
break;
case PROP_USERNAME:
g_free (priv->username);
priv->username = g_value_dup_string (value);
break;
case PROP_PASSWORD:
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingCdma *setting = NM_SETTING_CDMA (object);
switch (prop_id) {
case PROP_NUMBER:
g_value_set_string (value, nm_setting_cdma_get_number (setting));
break;
case PROP_USERNAME:
g_value_set_string (value, nm_setting_cdma_get_username (setting));
break;
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_cdma_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_cdma_get_password_flags (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_cdma_class_init (NMSettingCdmaClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingCdmaPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->need_secrets = need_secrets;
/* Properties */
/**
* NMSettingCdma:number:
*
* The number to dial to establish the connection to the CDMA-based mobile
* broadband network, if any. If not specified, the default number (#777)
* is used when required.
**/
g_object_class_install_property
(object_class, PROP_NUMBER,
g_param_spec_string (NM_SETTING_CDMA_NUMBER, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingCdma:username:
*
* The username used to authenticate with the network, if required. Many
* providers do not require a username, or accept any username. But if a
* username is required, it is specified here.
**/
g_object_class_install_property
(object_class, PROP_USERNAME,
g_param_spec_string (NM_SETTING_CDMA_USERNAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingCdma:password:
*
* The password used to authenticate with the network, if required. Many
* providers do not require a password, or accept any password. But if a
* password is required, it is specified here.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD,
g_param_spec_string (NM_SETTING_CDMA_PASSWORD, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_SECRET |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingCdma:password-flags:
*
* Flags indicating how to handle the #NMSettingCdma:password property.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_CDMA_PASSWORD_FLAGS, "", "",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,87 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_CDMA_H
#define NM_SETTING_CDMA_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_CDMA (nm_setting_cdma_get_type ())
#define NM_SETTING_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_CDMA, NMSettingCdma))
#define NM_SETTING_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_CDMA, NMSettingCdmaClass))
#define NM_IS_SETTING_CDMA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_CDMA))
#define NM_IS_SETTING_CDMA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_CDMA))
#define NM_SETTING_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_CDMA, NMSettingCdmaClass))
#define NM_SETTING_CDMA_SETTING_NAME "cdma"
/**
* NMSettingCdmaError:
* @NM_SETTING_CDMA_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_CDMA_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_CDMA_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_CDMA_ERROR_MISSING_SERIAL_SETTING: the required #NMSettingSerial
* is missing in the connection
*/
typedef enum {
NM_SETTING_CDMA_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_CDMA_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_CDMA_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_CDMA_ERROR_MISSING_SERIAL_SETTING /*< nick=MissingSerialSetting >*/
} NMSettingCdmaError;
#define NM_SETTING_CDMA_ERROR nm_setting_cdma_error_quark ()
GQuark nm_setting_cdma_error_quark (void);
#define NM_SETTING_CDMA_NUMBER "number"
#define NM_SETTING_CDMA_USERNAME "username"
#define NM_SETTING_CDMA_PASSWORD "password"
#define NM_SETTING_CDMA_PASSWORD_FLAGS "password-flags"
typedef struct {
NMSetting parent;
} NMSettingCdma;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingCdmaClass;
GType nm_setting_cdma_get_type (void);
NMSetting *nm_setting_cdma_new (void);
const char *nm_setting_cdma_get_number (NMSettingCdma *setting);
const char *nm_setting_cdma_get_username (NMSettingCdma *setting);
const char *nm_setting_cdma_get_password (NMSettingCdma *setting);
NMSettingSecretFlags nm_setting_cdma_get_password_flags (NMSettingCdma *setting);
G_END_DECLS
#endif /* NM_SETTING_CDMA_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,151 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_CONNECTION_H
#define NM_SETTING_CONNECTION_H
#include "nm-setting.h"
G_BEGIN_DECLS
#define NM_TYPE_SETTING_CONNECTION (nm_setting_connection_get_type ())
#define NM_SETTING_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_CONNECTION, NMSettingConnection))
#define NM_SETTING_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionClass))
#define NM_IS_SETTING_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_CONNECTION))
#define NM_IS_SETTING_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_CONNECTION))
#define NM_SETTING_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_CONNECTION, NMSettingConnectionClass))
#define NM_SETTING_CONNECTION_SETTING_NAME "connection"
/**
* NMSettingConnectionError:
* @NM_SETTING_CONNECTION_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY: the property's value is
* invalid
* @NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY: a required property is not
* present
* @NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND: the #NMSetting object
* referenced by the setting name contained in the
* #NMSettingConnection:type property was not present in the #NMConnection
* @NM_SETTING_CONNECTION_ERROR_IP_CONFIG_NOT_ALLOWED: ip configuration is not
* allowed to be present.
*
* Describes errors that may result from operations involving a
* #NMSettingConnection.
*
**/
typedef enum
{
NM_SETTING_CONNECTION_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND, /*< nick=TypeSettingNotFound >*/
NM_SETTING_CONNECTION_ERROR_IP_CONFIG_NOT_ALLOWED, /*< nick=IpConfigNotAllowed >*/
} NMSettingConnectionError;
#define NM_SETTING_CONNECTION_ERROR nm_setting_connection_error_quark ()
GQuark nm_setting_connection_error_quark (void);
#define NM_SETTING_CONNECTION_ID "id"
#define NM_SETTING_CONNECTION_UUID "uuid"
#define NM_SETTING_CONNECTION_INTERFACE_NAME "interface-name"
#define NM_SETTING_CONNECTION_TYPE "type"
#define NM_SETTING_CONNECTION_AUTOCONNECT "autoconnect"
#define NM_SETTING_CONNECTION_TIMESTAMP "timestamp"
#define NM_SETTING_CONNECTION_READ_ONLY "read-only"
#define NM_SETTING_CONNECTION_PERMISSIONS "permissions"
#define NM_SETTING_CONNECTION_ZONE "zone"
#define NM_SETTING_CONNECTION_MASTER "master"
#define NM_SETTING_CONNECTION_SLAVE_TYPE "slave-type"
#define NM_SETTING_CONNECTION_SECONDARIES "secondaries"
#define NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT "gateway-ping-timeout"
/**
* NMSettingConnection:
*
* The NMSettingConnection struct contains only private data.
* It should only be accessed through the functions described below.
*/
typedef struct {
NMSetting parent;
} NMSettingConnection;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingConnectionClass;
GType nm_setting_connection_get_type (void);
NMSetting * nm_setting_connection_new (void);
const char *nm_setting_connection_get_id (NMSettingConnection *setting);
const char *nm_setting_connection_get_uuid (NMSettingConnection *setting);
NM_AVAILABLE_IN_0_9_10
const char *nm_setting_connection_get_interface_name (NMSettingConnection *setting);
const char *nm_setting_connection_get_connection_type (NMSettingConnection *setting);
gboolean nm_setting_connection_get_autoconnect (NMSettingConnection *setting);
guint64 nm_setting_connection_get_timestamp (NMSettingConnection *setting);
gboolean nm_setting_connection_get_read_only (NMSettingConnection *setting);
guint32 nm_setting_connection_get_num_permissions (NMSettingConnection *setting);
gboolean nm_setting_connection_get_permission (NMSettingConnection *setting,
guint32 idx,
const char **out_ptype,
const char **out_pitem,
const char **out_detail);
const char *nm_setting_connection_get_zone (NMSettingConnection *setting);
gboolean nm_setting_connection_permissions_user_allowed (NMSettingConnection *setting, const char *uname);
gboolean nm_setting_connection_add_permission (NMSettingConnection *setting,
const char *ptype,
const char *pitem,
const char *detail);
void nm_setting_connection_remove_permission (NMSettingConnection *setting,
guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_connection_remove_permission_by_value (NMSettingConnection *setting,
const char *ptype,
const char *pitem,
const char *detail);
const char *nm_setting_connection_get_master (NMSettingConnection *setting);
gboolean nm_setting_connection_is_slave_type (NMSettingConnection *setting,
const char *type);
const char *nm_setting_connection_get_slave_type (NMSettingConnection *setting);
guint32 nm_setting_connection_get_num_secondaries (NMSettingConnection *setting);
const char *nm_setting_connection_get_secondary (NMSettingConnection *setting, guint32 idx);
gboolean nm_setting_connection_add_secondary (NMSettingConnection *setting, const char *sec_uuid);
void nm_setting_connection_remove_secondary (NMSettingConnection *setting, guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_connection_remove_secondary_by_value (NMSettingConnection *setting, const char *sec_uuid);
NM_AVAILABLE_IN_0_9_10
guint32 nm_setting_connection_get_gateway_ping_timeout (NMSettingConnection *setting);
G_END_DECLS
#endif /* NM_SETTING_CONNECTION_H */

1207
libnm-core/nm-setting-dcb.c Normal file

File diff suppressed because it is too large Load Diff

187
libnm-core/nm-setting-dcb.h Normal file
View File

@@ -0,0 +1,187 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NM_SETTING_DCB_H
#define NM_SETTING_DCB_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_DCB (nm_setting_dcb_get_type ())
#define NM_SETTING_DCB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_DCB, NMSettingDcb))
#define NM_SETTING_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_DCB, NMSettingDcbClass))
#define NM_IS_SETTING_DCB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_DCB))
#define NM_IS_SETTING_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_DCB))
#define NM_SETTING_DCB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_DCB, NMSettingDcbClass))
#define NM_SETTING_DCB_SETTING_NAME "dcb"
/**
* NMSettingDcbError:
* @NM_SETTING_DCB_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_DCB_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_DCB_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_DCB_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_DCB_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_DCB_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingDcbError;
#define NM_SETTING_DCB_ERROR nm_setting_dcb_error_quark ()
GQuark nm_setting_dcb_error_quark (void);
/**
* NMSettingDcbFlags:
* @NM_SETTING_DCB_FLAG_NONE: no flag
* @NM_SETTING_DCB_FLAG_ENABLE: the feature is enabled
* @NM_SETTING_DCB_FLAG_ADVERTISE: the feature is advertised
* @NM_SETTING_DCB_FLAG_WILLING: the feature is willing to change based on
* peer configuration advertisements
*
* DCB feature flags.
*
* Since: 0.9.10
**/
typedef enum {
NM_SETTING_DCB_FLAG_NONE = 0x00000000,
NM_SETTING_DCB_FLAG_ENABLE = 0x00000001,
NM_SETTING_DCB_FLAG_ADVERTISE = 0x00000002,
NM_SETTING_DCB_FLAG_WILLING = 0x00000004
} NMSettingDcbFlags;
/**
* NM_SETTING_DCB_FCOE_MODE_FABRIC:
*
* Indicates that the FCoE controller should use "fabric" mode (default)
*
* Since: 0.9.10
*/
#define NM_SETTING_DCB_FCOE_MODE_FABRIC "fabric"
/**
* NM_SETTING_DCB_FCOE_MODE_VN2VN:
*
* Indicates that the FCoE controller should use "VN2VN" mode.
*
* Since: 0.9.10
*/
#define NM_SETTING_DCB_FCOE_MODE_VN2VN "vn2vn"
/* Properties */
#define NM_SETTING_DCB_APP_FCOE_FLAGS "app-fcoe-flags"
#define NM_SETTING_DCB_APP_FCOE_PRIORITY "app-fcoe-priority"
#define NM_SETTING_DCB_APP_FCOE_MODE "app-fcoe-mode"
#define NM_SETTING_DCB_APP_ISCSI_FLAGS "app-iscsi-flags"
#define NM_SETTING_DCB_APP_ISCSI_PRIORITY "app-iscsi-priority"
#define NM_SETTING_DCB_APP_FIP_FLAGS "app-fip-flags"
#define NM_SETTING_DCB_APP_FIP_PRIORITY "app-fip-priority"
#define NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS "priority-flow-control-flags"
#define NM_SETTING_DCB_PRIORITY_FLOW_CONTROL "priority-flow-control"
#define NM_SETTING_DCB_PRIORITY_GROUP_FLAGS "priority-group-flags"
#define NM_SETTING_DCB_PRIORITY_GROUP_ID "priority-group-id"
#define NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH "priority-group-bandwidth"
#define NM_SETTING_DCB_PRIORITY_BANDWIDTH "priority-bandwidth"
#define NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH "priority-strict-bandwidth"
#define NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS "priority-traffic-class"
typedef struct {
NMSetting parent;
} NMSettingDcb;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingDcbClass;
NM_AVAILABLE_IN_0_9_10
GType nm_setting_dcb_get_type (void);
NM_AVAILABLE_IN_0_9_10
NMSetting * nm_setting_dcb_new (void);
NMSettingDcbFlags nm_setting_dcb_get_app_fcoe_flags (NMSettingDcb *setting);
gint nm_setting_dcb_get_app_fcoe_priority (NMSettingDcb *setting);
const char * nm_setting_dcb_get_app_fcoe_mode (NMSettingDcb *setting);
NMSettingDcbFlags nm_setting_dcb_get_app_iscsi_flags (NMSettingDcb *setting);
gint nm_setting_dcb_get_app_iscsi_priority (NMSettingDcb *setting);
NMSettingDcbFlags nm_setting_dcb_get_app_fip_flags (NMSettingDcb *setting);
gint nm_setting_dcb_get_app_fip_priority (NMSettingDcb *setting);
/* Priority Flow Control */
NMSettingDcbFlags nm_setting_dcb_get_priority_flow_control_flags (NMSettingDcb *setting);
gboolean nm_setting_dcb_get_priority_flow_control (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_flow_control (NMSettingDcb *setting,
guint user_priority,
gboolean enabled);
/* Priority Groups */
NMSettingDcbFlags nm_setting_dcb_get_priority_group_flags (NMSettingDcb *setting);
guint nm_setting_dcb_get_priority_group_id (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_group_id (NMSettingDcb *setting,
guint user_priority,
guint group_id);
guint nm_setting_dcb_get_priority_group_bandwidth (NMSettingDcb *setting,
guint group_id);
void nm_setting_dcb_set_priority_group_bandwidth (NMSettingDcb *setting,
guint group_id,
guint bandwidth_percent);
guint nm_setting_dcb_get_priority_bandwidth (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_bandwidth (NMSettingDcb *setting,
guint user_priority,
guint bandwidth_percent);
gboolean nm_setting_dcb_get_priority_strict_bandwidth (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_strict_bandwidth (NMSettingDcb *setting,
guint user_priority,
gboolean strict);
guint nm_setting_dcb_get_priority_traffic_class (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_traffic_class (NMSettingDcb *setting,
guint user_priority,
guint traffic_class);
G_END_DECLS
#endif /* NM_SETTING_DCB_H */

View File

@@ -0,0 +1,100 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#include "config.h"
#include "nm-setting-generic.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-generic
* @short_description: Describes connection properties for generic devices
* @include: nm-setting-generic.h
*
* The #NMSettingGeneric object is a #NMSetting subclass that describes
* optional properties that apply to "generic" devices (ie, devices that
* NetworkManager does not specifically recognize).
*
* There are currently no properties on this object; it exists only to be
* the "connection type" setting on #NMConnections for generic devices.
*
* Since: 0.9.10
**/
/**
* nm_setting_generic_error_quark:
*
* Registers an error quark for #NMSettingGeneric if necessary.
*
* Returns: the error quark used for #NMSettingGeneric errors.
*
* Since: 0.9.10
**/
GQuark
nm_setting_generic_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-generic-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingGeneric, nm_setting_generic, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_GENERIC_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_GENERIC_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_GENERIC)
#define NM_SETTING_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_GENERIC, NMSettingGenericPrivate))
typedef struct {
int dummy;
} NMSettingGenericPrivate;
/**************************************************************************/
/**
* nm_setting_generic_new:
*
* Creates a new #NMSettingGeneric object with default values.
*
* Returns: (transfer full): the new empty #NMSettingGeneric object
*
* Since: 0.9.10
**/
NMSetting *
nm_setting_generic_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_GENERIC, NULL);
}
static void
nm_setting_generic_init (NMSettingGeneric *setting)
{
}
static void
nm_setting_generic_class_init (NMSettingGenericClass *setting_class)
{
g_type_class_add_private (setting_class, sizeof (NMSettingGenericPrivate));
}

View File

@@ -0,0 +1,78 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NM_SETTING_GENERIC_H
#define NM_SETTING_GENERIC_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_GENERIC (nm_setting_generic_get_type ())
#define NM_SETTING_GENERIC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_GENERIC, NMSettingGeneric))
#define NM_SETTING_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_GENERIC, NMSettingGenericClass))
#define NM_IS_SETTING_GENERIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_GENERIC))
#define NM_IS_SETTING_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_GENERIC))
#define NM_SETTING_GENERIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_GENERIC, NMSettingGenericClass))
#define NM_SETTING_GENERIC_SETTING_NAME "generic"
/**
* NMSettingGenericError:
* @NM_SETTING_GENERIC_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_GENERIC_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_GENERIC_ERROR_MISSING_PROPERTY: the property was missing and
* is required
*
* Since: 0.9.10
*/
typedef enum {
NM_SETTING_GENERIC_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_GENERIC_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_GENERIC_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
} NMSettingGenericError;
#define NM_SETTING_GENERIC_ERROR nm_setting_generic_error_quark ()
GQuark nm_setting_generic_error_quark (void);
typedef struct {
NMSetting parent;
} NMSettingGeneric;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingGenericClass;
NM_AVAILABLE_IN_0_9_10
GType nm_setting_generic_get_type (void);
NM_AVAILABLE_IN_0_9_10
NMSetting * nm_setting_generic_new (void);
G_END_DECLS
#endif /* NM_SETTING_GENERIC_H */

723
libnm-core/nm-setting-gsm.c Normal file
View File

@@ -0,0 +1,723 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include <glib/gi18n.h>
#include "nm-setting-gsm.h"
#include "nm-utils.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-gsm
* @short_description: Describes GSM/3GPP-based mobile broadband properties
* @include: nm-setting-gsm.h
*
* The #NMSettingGsm object is a #NMSetting subclass that describes
* properties that allow connections to 3GPP-based mobile broadband
* networks, including those using GPRS/EDGE and UMTS/HSPA technology.
*/
/**
* nm_setting_gsm_error_quark:
*
* Registers an error quark for #NMSettingGsm if necessary.
*
* Returns: the error quark used for #NMSettingGsm errors.
**/
GQuark
nm_setting_gsm_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-gsm-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingGsm, nm_setting_gsm, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_GSM_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_GSM_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_GSM)
#define NM_SETTING_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_GSM, NMSettingGsmPrivate))
typedef struct {
char *number; /* For dialing, duh */
char *username;
char *password;
NMSettingSecretFlags password_flags;
char *apn; /* NULL for dynamic */
char *network_id; /* for manual registration or NULL for automatic */
int network_type; /* One of the NM_SETTING_GSM_NETWORK_TYPE_* */
guint32 allowed_bands; /* A bitfield of NM_SETTING_GSM_BAND_* */
char *pin;
NMSettingSecretFlags pin_flags;
gboolean home_only;
} NMSettingGsmPrivate;
enum {
PROP_0,
PROP_NUMBER,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
PROP_APN,
PROP_NETWORK_ID,
PROP_NETWORK_TYPE,
PROP_PIN,
PROP_PIN_FLAGS,
PROP_ALLOWED_BANDS,
PROP_HOME_ONLY,
LAST_PROP
};
/**
* nm_setting_gsm_new:
*
* Creates a new #NMSettingGsm object with default values.
*
* Returns: the new empty #NMSettingGsm object
**/
NMSetting *
nm_setting_gsm_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_GSM, NULL);
}
/**
* nm_setting_gsm_get_number:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:number property of the setting
**/
const char *
nm_setting_gsm_get_number (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
return NM_SETTING_GSM_GET_PRIVATE (setting)->number;
}
/**
* nm_setting_gsm_get_username:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:username property of the setting
**/
const char *
nm_setting_gsm_get_username (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
return NM_SETTING_GSM_GET_PRIVATE (setting)->username;
}
/**
* nm_setting_gsm_get_password:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:password property of the setting
**/
const char *
nm_setting_gsm_get_password (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
return NM_SETTING_GSM_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_gsm_get_password_flags:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingGsm:password
**/
NMSettingSecretFlags
nm_setting_gsm_get_password_flags (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_GSM_GET_PRIVATE (setting)->password_flags;
}
/**
* nm_setting_gsm_get_apn:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:apn property of the setting
**/
const char *
nm_setting_gsm_get_apn (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
return NM_SETTING_GSM_GET_PRIVATE (setting)->apn;
}
/**
* nm_setting_gsm_get_network_id:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:network-id property of the setting
**/
const char *
nm_setting_gsm_get_network_id (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
return NM_SETTING_GSM_GET_PRIVATE (setting)->network_id;
}
/**
* nm_setting_gsm_get_network_type:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:network-type property of the setting
*
* Deprecated: 0.9.10: No longer used. Network type setting should be done talking to ModemManager directly.
**/
int
nm_setting_gsm_get_network_type (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), -1);
return NM_SETTING_GSM_GET_PRIVATE (setting)->network_type;
}
/**
* nm_setting_gsm_get_allowed_bands:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:allowed-bands property of the setting
*
* Deprecated: 0.9.10: No longer used. Bands setting should be done talking to ModemManager directly.
**/
guint32
nm_setting_gsm_get_allowed_bands (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_GSM_BAND_UNKNOWN);
return NM_SETTING_GSM_GET_PRIVATE (setting)->allowed_bands;
}
/**
* nm_setting_gsm_get_pin:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:pin property of the setting
**/
const char *
nm_setting_gsm_get_pin (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
return NM_SETTING_GSM_GET_PRIVATE (setting)->pin;
}
/**
* nm_setting_gsm_get_pin_flags:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingGsm:pin
**/
NMSettingSecretFlags
nm_setting_gsm_get_pin_flags (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_GSM_GET_PRIVATE (setting)->pin_flags;
}
/**
* nm_setting_gsm_get_home_only:
* @setting: the #NMSettingGsm
*
* Returns: the #NMSettingGsm:home-only property of the setting
**/
gboolean
nm_setting_gsm_get_home_only (NMSettingGsm *setting)
{
g_return_val_if_fail (NM_IS_SETTING_GSM (setting), FALSE);
return NM_SETTING_GSM_GET_PRIVATE (setting)->home_only;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (setting);
if (priv->number && !priv->number[0]) {
g_set_error_literal (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_NUMBER);
return FALSE;
}
if (priv->apn) {
guint32 apn_len = strlen (priv->apn);
guint32 i;
if (apn_len < 1 || apn_len > 64) {
g_set_error (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("property value '%s' is empty or too long (>64)"),
priv->apn);
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_APN);
return FALSE;
}
/* APNs roughly follow the same rules as DNS domain names. Allowed
* characters are a-z, 0-9, . and -. GSM 03.03 Section 9.1 states:
*
* The syntax of the APN shall follow the Name Syntax defined in
* RFC 2181 [14] and RFC 1035 [15]. The APN consists of one or
* more labels. Each label is coded as one octet length field
* followed by that number of octets coded as 8 bit ASCII characters.
* Following RFC 1035 [15] the labels should consist only of the
* alphabetic characters (A-Z and a-z), digits (0-9) and the
* dash (-). The case of alphabetic characters is not significant.
*
* A dot (.) is commonly used to separate parts of the APN, and
* apparently the underscore (_) is used as well. RFC 2181 indicates
* that no restrictions of any kind are placed on DNS labels, and thus
* it would appear that none are placed on APNs either, but many modems
* and networks will fail to accept APNs that include odd characters
* like space ( ) and such.
*/
for (i = 0; i < apn_len; i++) {
if ( !g_ascii_isalnum (priv->apn[i])
&& (priv->apn[i] != '.')
&& (priv->apn[i] != '_')
&& (priv->apn[i] != '-')) {
g_set_error (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("'%s' contains invalid char(s) (use [A-Za-z._-])"),
priv->apn);
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_APN);
return FALSE;
}
}
}
if (priv->username && !strlen (priv->username)) {
g_set_error_literal (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_USERNAME);
return FALSE;
}
if (priv->password && !strlen (priv->password)) {
g_set_error_literal (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_USERNAME);
return FALSE;
}
if (priv->network_id) {
guint32 nid_len = strlen (priv->network_id);
guint32 i;
/* Accept both 5 and 6 digit MCC/MNC codes */
if ((nid_len < 5) || (nid_len > 6)) {
g_set_error (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("'%s' length is invalid (should be 5 or 6 digits)"),
priv->network_id);
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_NETWORK_ID);
return FALSE;
}
for (i = 0; i < nid_len; i++) {
if (!g_ascii_isdigit (priv->network_id[i])) {
g_set_error (error,
NM_SETTING_GSM_ERROR,
NM_SETTING_GSM_ERROR_INVALID_PROPERTY,
_("'%s' is not a number"),
priv->network_id);
g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_NETWORK_ID);
return FALSE;
}
}
}
return TRUE;
}
static GPtrArray *
need_secrets (NMSetting *setting)
{
NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (setting);
GPtrArray *secrets = NULL;
if (priv->password)
return NULL;
if (priv->username) {
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_GSM_PASSWORD);
}
}
return secrets;
}
static void
nm_setting_gsm_init (NMSettingGsm *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (object);
g_free (priv->number);
g_free (priv->username);
g_free (priv->password);
g_free (priv->apn);
g_free (priv->network_id);
g_free (priv->pin);
G_OBJECT_CLASS (nm_setting_gsm_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (object);
char *tmp;
switch (prop_id) {
case PROP_NUMBER:
g_free (priv->number);
priv->number = g_value_dup_string (value);
break;
case PROP_USERNAME:
g_free (priv->username);
priv->username = g_value_dup_string (value);
break;
case PROP_PASSWORD:
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
case PROP_APN:
g_free (priv->apn);
priv->apn = NULL;
tmp = g_value_dup_string (value);
if (tmp)
priv->apn = g_strstrip (tmp);
break;
case PROP_NETWORK_ID:
g_free (priv->network_id);
priv->network_id = NULL;
tmp = g_value_dup_string (value);
if (tmp)
priv->network_id = g_strstrip (tmp);
break;
case PROP_NETWORK_TYPE:
priv->network_type = g_value_get_int (value);
break;
case PROP_ALLOWED_BANDS:
priv->allowed_bands = g_value_get_uint (value);
break;
case PROP_PIN:
g_free (priv->pin);
priv->pin = g_value_dup_string (value);
break;
case PROP_PIN_FLAGS:
priv->pin_flags = g_value_get_uint (value);
break;
case PROP_HOME_ONLY:
priv->home_only = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingGsm *setting = NM_SETTING_GSM (object);
switch (prop_id) {
case PROP_NUMBER:
g_value_set_string (value, nm_setting_gsm_get_number (setting));
break;
case PROP_USERNAME:
g_value_set_string (value, nm_setting_gsm_get_username (setting));
break;
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_gsm_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_gsm_get_password_flags (setting));
break;
case PROP_APN:
g_value_set_string (value, nm_setting_gsm_get_apn (setting));
break;
case PROP_NETWORK_ID:
g_value_set_string (value, nm_setting_gsm_get_network_id (setting));
break;
case PROP_NETWORK_TYPE:
g_value_set_int (value, NM_SETTING_GSM_GET_PRIVATE (setting)->network_type);
break;
case PROP_ALLOWED_BANDS:
g_value_set_uint (value, NM_SETTING_GSM_GET_PRIVATE (setting)->allowed_bands);
break;
case PROP_PIN:
g_value_set_string (value, nm_setting_gsm_get_pin (setting));
break;
case PROP_PIN_FLAGS:
g_value_set_uint (value, nm_setting_gsm_get_pin_flags (setting));
break;
case PROP_HOME_ONLY:
g_value_set_boolean (value, nm_setting_gsm_get_home_only (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_gsm_class_init (NMSettingGsmClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingGsmPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->need_secrets = need_secrets;
/* Properties */
/**
* NMSettingGsm:number:
*
* Number to dial when establishing a PPP data session with the GSM-based
* mobile broadband network. Many modems do not require PPP for connections
* to the mobile network and thus this property should be left blank, which
* allows NetworkManager to select the appropriate settings automatically.
**/
g_object_class_install_property
(object_class, PROP_NUMBER,
g_param_spec_string (NM_SETTING_GSM_NUMBER, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:username:
*
* The username used to authenticate with the network, if required. Many
* providers do not require a username, or accept any username. But if a
* username is required, it is specified here.
**/
g_object_class_install_property
(object_class, PROP_USERNAME,
g_param_spec_string (NM_SETTING_GSM_USERNAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:password:
*
* The password used to authenticate with the network, if required. Many
* providers do not require a password, or accept any password. But if a
* password is required, it is specified here.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD,
g_param_spec_string (NM_SETTING_GSM_PASSWORD, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_SECRET |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:password-flags:
*
* Flags indicating how to handle the #NMSettingGsm:password property.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_GSM_PASSWORD_FLAGS, "", "",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:apn:
*
* The GPRS Access Point Name specifying the APN used when establishing a
* data session with the GSM-based network. The APN often determines how
* the user will be billed for their network usage and whether the user has
* access to the Internet or just a provider-specific walled-garden, so it
* is important to use the correct APN for the user's mobile broadband plan.
* The APN may only be composed of the characters a-z, 0-9, ., and - per GSM
* 03.60 Section 14.9.
**/
g_object_class_install_property
(object_class, PROP_APN,
g_param_spec_string (NM_SETTING_GSM_APN, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:network-id:
*
* The Network ID (GSM LAI format, ie MCC-MNC) to force specific network
* registration. If the Network ID is specified, NetworkManager will
* attempt to force the device to register only on the specified network.
* This can be used to ensure that the device does not roam when direct
* roaming control of the device is not otherwise possible.
**/
g_object_class_install_property
(object_class, PROP_NETWORK_ID,
g_param_spec_string (NM_SETTING_GSM_NETWORK_ID, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:network-type:
*
* Network preference to force the device to only use specific network
* technologies. The permitted values are %NM_SETTING_GSM_NETWORK_TYPE_ANY,
* %NM_SETTING_GSM_NETWORK_TYPE_UMTS_HSPA,
* %NM_SETTING_GSM_NETWORK_TYPE_GPRS_EDGE,
* %NM_SETTING_GSM_NETWORK_TYPE_PREFER_UMTS_HSPA,
* %NM_SETTING_GSM_NETWORK_TYPE_PREFER_GPRS_EDGE,
* %NM_SETTING_GSM_NETWORK_TYPE_PREFER_4G, and
* %NM_SETTING_GSM_NETWORK_TYPE_4G. Note that not all devices allow network
* preference control.
*
* Deprecated: 0.9.10: No longer used. Network type setting should be done
* by talking to ModemManager directly.
**/
g_object_class_install_property
(object_class, PROP_NETWORK_TYPE,
g_param_spec_int (NM_SETTING_GSM_NETWORK_TYPE, "", "",
NM_SETTING_GSM_NETWORK_TYPE_ANY,
NM_SETTING_GSM_NETWORK_TYPE_4G,
NM_SETTING_GSM_NETWORK_TYPE_ANY,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:allowed-bands:
*
* Bitfield of allowed frequency bands. Note that not all devices allow
* frequency band control. Permitted values are those specified by
* #NMSettingGsmNetworkBand.
*
* Deprecated: 0.9.10: No longer used. Band setting should be done by
* talking to ModemManager directly.
**/
g_object_class_install_property
(object_class, PROP_ALLOWED_BANDS,
g_param_spec_uint (NM_SETTING_GSM_ALLOWED_BANDS, "", "",
NM_SETTING_GSM_BAND_UNKNOWN,
NM_SETTING_GSM_BANDS_MAX,
NM_SETTING_GSM_BAND_ANY,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:pin:
*
* If the SIM is locked with a PIN it must be unlocked before any other
* operations are requested. Specify the PIN here to allow operation of the
* device.
**/
g_object_class_install_property
(object_class, PROP_PIN,
g_param_spec_string (NM_SETTING_GSM_PIN, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_SECRET |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:pin-flags:
*
* Flags indicating how to handle the #NMSettingGsm:pin property.
**/
g_object_class_install_property
(object_class, PROP_PIN_FLAGS,
g_param_spec_uint (NM_SETTING_GSM_PIN_FLAGS, "", "",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingGsm:home-only:
*
* When %TRUE, only connections to the home network will be allowed.
* Connections to roaming networks will not be made.
**/
g_object_class_install_property
(object_class, PROP_HOME_ONLY,
g_param_spec_boolean (NM_SETTING_GSM_HOME_ONLY, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

204
libnm-core/nm-setting-gsm.h Normal file
View File

@@ -0,0 +1,204 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_GSM_H
#define NM_SETTING_GSM_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_GSM (nm_setting_gsm_get_type ())
#define NM_SETTING_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_GSM, NMSettingGsm))
#define NM_SETTING_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_GSM, NMSettingGsmClass))
#define NM_IS_SETTING_GSM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_GSM))
#define NM_IS_SETTING_GSM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_GSM))
#define NM_SETTING_GSM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_GSM, NMSettingGsmClass))
#define NM_SETTING_GSM_SETTING_NAME "gsm"
/**
* NMSettingGsmError:
* @NM_SETTING_GSM_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_GSM_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_GSM_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_GSM_ERROR_MISSING_SERIAL_SETTING: the required #NMSettingSerial
* is missing in the connection
*/
typedef enum {
NM_SETTING_GSM_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_GSM_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_GSM_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_GSM_ERROR_MISSING_SERIAL_SETTING /*< nick=MissingSerialSetting >*/
} NMSettingGsmError;
#define NM_SETTING_GSM_ERROR nm_setting_gsm_error_quark ()
GQuark nm_setting_gsm_error_quark (void);
#define NM_SETTING_GSM_NUMBER "number"
#define NM_SETTING_GSM_USERNAME "username"
#define NM_SETTING_GSM_PASSWORD "password"
#define NM_SETTING_GSM_PASSWORD_FLAGS "password-flags"
#define NM_SETTING_GSM_APN "apn"
#define NM_SETTING_GSM_NETWORK_ID "network-id"
#define NM_SETTING_GSM_PIN "pin"
#define NM_SETTING_GSM_PIN_FLAGS "pin-flags"
#define NM_SETTING_GSM_HOME_ONLY "home-only"
/* Deprecated */
#define NM_SETTING_GSM_ALLOWED_BANDS "allowed-bands"
#define NM_SETTING_GSM_NETWORK_TYPE "network-type"
/**
* NMSettingGsmNetworkType:
* @NM_SETTING_GSM_NETWORK_TYPE_ANY: any access technology may be used
* @NM_SETTING_GSM_NETWORK_TYPE_UMTS_HSPA: only 3G-type (UMTS and HSPA)
* technologies may be used
* @NM_SETTING_GSM_NETWORK_TYPE_GPRS_EDGE: only 2G-type (GPRS and EDGE)
* technologies may be used
* @NM_SETTING_GSM_NETWORK_TYPE_PREFER_UMTS_HSPA: 3G-type technologies are
* preferred but 2G-type technologies may be used as a fallback
* @NM_SETTING_GSM_NETWORK_TYPE_PREFER_GPRS_EDGE: 2G-type technologies are
* preferred but 3G-type technologies may be used as a fallback
* @NM_SETTING_GSM_NETWORK_TYPE_PREFER_4G: 4G/LTE-type technologies are
* preferred but 3G/2/-type technologies may be used as a fallback
* @NM_SETTING_GSM_NETWORK_TYPE_4G: only 4G/LTE type
* technologies may be used
*
* #NMSettingGsmNetworkType values indicate the allowed access technologies
* the device may use when connecting to this network.
*
* Deprecated: 0.9.10: No longer used.
*/
typedef enum {
NM_SETTING_GSM_NETWORK_TYPE_ANY = -1,
NM_SETTING_GSM_NETWORK_TYPE_UMTS_HSPA = 0,
NM_SETTING_GSM_NETWORK_TYPE_GPRS_EDGE = 1,
NM_SETTING_GSM_NETWORK_TYPE_PREFER_UMTS_HSPA = 2,
NM_SETTING_GSM_NETWORK_TYPE_PREFER_GPRS_EDGE = 3,
NM_SETTING_GSM_NETWORK_TYPE_PREFER_4G = 4,
NM_SETTING_GSM_NETWORK_TYPE_4G = 5
} NMSettingGsmNetworkType;
/**
* NMSettingGsmNetworkBand:
* @NM_SETTING_GSM_BAND_UNKNOWN: unknown or no band specified
* @NM_SETTING_GSM_BAND_ANY: any band is allowed
* @NM_SETTING_GSM_BAND_EGSM: 900 MHz original GSM band
* @NM_SETTING_GSM_BAND_DCS: 1800 MHz DCS band
* @NM_SETTING_GSM_BAND_PCS: US 1900 MHz PCS band
* @NM_SETTING_GSM_BAND_G850: US 850 MHz Cellular band
* @NM_SETTING_GSM_BAND_U2100: WCDMA 3GPP UMTS 2100 MHz (Class I)
* @NM_SETTING_GSM_BAND_U1800: WCDMA 3GPP UMTS 1800 MHz (Class III)
* @NM_SETTING_GSM_BAND_U17IV: WCDMA 3GPP AWS 1700/2100 MHz (Class IV)
* @NM_SETTING_GSM_BAND_U800: WCDMA 3GPP UMTS 800 MHz (Class VI)
* @NM_SETTING_GSM_BAND_U850: WCDMA 3GPP UMTS 850 MHz (Class V)
* @NM_SETTING_GSM_BAND_U900: WCDMA 3GPP UMTS 900 MHz (Class VIII)
* @NM_SETTING_GSM_BAND_U17IX: WCDMA 3GPP UMTS 1700 MHz (Class IX)
* @NM_SETTING_GSM_BAND_U1900: WCDMA 3GPP UMTS 1900 MHz (Class II)
* @NM_SETTING_GSM_BAND_U2600: WCDMA 3GPP UMTS 2600 MHz (Class VII, internal)
*
* #NMSettingGsmNetworkBand values indicate the allowed frequency bands
* the device may use when connecting to this network.
*
* Deprecated: 0.9.10: No longer used.
*/
typedef enum {
NM_SETTING_GSM_BAND_UNKNOWN = 0x00000000,
NM_SETTING_GSM_BAND_ANY = 0x00000001,
NM_SETTING_GSM_BAND_EGSM = 0x00000002, /* 900 MHz */
NM_SETTING_GSM_BAND_DCS = 0x00000004, /* 1800 MHz */
NM_SETTING_GSM_BAND_PCS = 0x00000008, /* 1900 MHz */
NM_SETTING_GSM_BAND_G850 = 0x00000010, /* 850 MHz */
NM_SETTING_GSM_BAND_U2100 = 0x00000020, /* WCDMA 3GPP UMTS 2100 MHz (Class I) */
NM_SETTING_GSM_BAND_U1800 = 0x00000040, /* WCDMA 3GPP UMTS 1800 MHz (Class III) */
NM_SETTING_GSM_BAND_U17IV = 0x00000080, /* WCDMA 3GPP AWS 1700/2100 MHz (Class IV) */
NM_SETTING_GSM_BAND_U800 = 0x00000100, /* WCDMA 3GPP UMTS 800 MHz (Class VI) */
NM_SETTING_GSM_BAND_U850 = 0x00000200, /* WCDMA 3GPP UMTS 850 MHz (Class V) */
NM_SETTING_GSM_BAND_U900 = 0x00000400, /* WCDMA 3GPP UMTS 900 MHz (Class VIII) */
NM_SETTING_GSM_BAND_U17IX = 0x00000800, /* WCDMA 3GPP UMTS 1700 MHz (Class IX) */
NM_SETTING_GSM_BAND_U1900 = 0x00001000, /* WCDMA 3GPP UMTS 1900 MHz (Class II) */
NM_SETTING_GSM_BAND_U2600 = 0x00002000, /* WCDMA 3GPP UMTS 2600 MHz (Class VII, internal) */
} NMSettingGsmNetworkBand;
/**
* NM_SETTING_GSM_BANDS_MAX:
*
* #NM_SETTING_GSM_BANDS_MAX macro indicate the maximal value that can be used
* as the allowed frequency bands (#NMSettingGsm:allowed-bands property).
*
* Deprecated: 0.9.10: No longer used.
*/
#define NM_SETTING_GSM_BANDS_MAX ( NM_SETTING_GSM_BAND_UNKNOWN \
| NM_SETTING_GSM_BAND_ANY \
| NM_SETTING_GSM_BAND_EGSM \
| NM_SETTING_GSM_BAND_DCS \
| NM_SETTING_GSM_BAND_PCS \
| NM_SETTING_GSM_BAND_G850 \
| NM_SETTING_GSM_BAND_U2100 \
| NM_SETTING_GSM_BAND_U1800 \
| NM_SETTING_GSM_BAND_U17IV \
| NM_SETTING_GSM_BAND_U800 \
| NM_SETTING_GSM_BAND_U850 \
| NM_SETTING_GSM_BAND_U900 \
| NM_SETTING_GSM_BAND_U17IX \
| NM_SETTING_GSM_BAND_U1900 \
| NM_SETTING_GSM_BAND_U2600)
typedef struct {
NMSetting parent;
} NMSettingGsm;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingGsmClass;
GType nm_setting_gsm_get_type (void);
NMSetting *nm_setting_gsm_new (void);
const char *nm_setting_gsm_get_number (NMSettingGsm *setting);
const char *nm_setting_gsm_get_username (NMSettingGsm *setting);
const char *nm_setting_gsm_get_password (NMSettingGsm *setting);
const char *nm_setting_gsm_get_apn (NMSettingGsm *setting);
const char *nm_setting_gsm_get_network_id (NMSettingGsm *setting);
const char *nm_setting_gsm_get_pin (NMSettingGsm *setting);
gboolean nm_setting_gsm_get_home_only (NMSettingGsm *setting);
NMSettingSecretFlags nm_setting_gsm_get_pin_flags (NMSettingGsm *setting);
NMSettingSecretFlags nm_setting_gsm_get_password_flags (NMSettingGsm *setting);
/* Deprecated */
NM_DEPRECATED_IN_0_9_10
int nm_setting_gsm_get_network_type (NMSettingGsm *setting);
NM_DEPRECATED_IN_0_9_10
guint32 nm_setting_gsm_get_allowed_bands (NMSettingGsm *setting);
G_END_DECLS
#endif /* NM_SETTING_GSM_H */

View File

@@ -0,0 +1,472 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2013 Red Hat, Inc.
*/
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include <linux/if_infiniband.h>
#include <glib/gi18n.h>
#include "nm-setting-infiniband.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-setting-connection.h"
/**
* SECTION:nm-setting-infiniband
* @short_description: Describes connection properties for IP-over-InfiniBand networks
* @include: nm-setting-infiniband.h
*
* The #NMSettingInfiniband object is a #NMSetting subclass that describes properties
* necessary for connection to IP-over-InfiniBand networks.
**/
/**
* nm_setting_infiniband_error_quark:
*
* Registers an error quark for #NMSettingInfiniband if necessary.
*
* Returns: the error quark used for #NMSettingInfiniband errors.
**/
GQuark
nm_setting_infiniband_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-infiniband-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingInfiniband, nm_setting_infiniband, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_INFINIBAND_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_INFINIBAND_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_INFINIBAND)
#define NM_SETTING_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_INFINIBAND, NMSettingInfinibandPrivate))
typedef struct {
GByteArray *mac_address;
char *transport_mode;
guint32 mtu;
int p_key;
char *parent, *virtual_iface_name;
} NMSettingInfinibandPrivate;
enum {
PROP_0,
PROP_MAC_ADDRESS,
PROP_MTU,
PROP_TRANSPORT_MODE,
PROP_P_KEY,
PROP_PARENT,
LAST_PROP
};
/**
* nm_setting_infiniband_new:
*
* Creates a new #NMSettingInfiniband object with default values.
*
* Returns: (transfer full): the new empty #NMSettingInfiniband object
**/
NMSetting *
nm_setting_infiniband_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_INFINIBAND, NULL);
}
/**
* nm_setting_infiniband_get_mac_address:
* @setting: the #NMSettingInfiniband
*
* Returns: the #NMSettingInfiniband:mac-address property of the setting
**/
const GByteArray *
nm_setting_infiniband_get_mac_address (NMSettingInfiniband *setting)
{
g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), NULL);
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->mac_address;
}
/**
* nm_setting_infiniband_get_mtu:
* @setting: the #NMSettingInfiniband
*
* Returns: the #NMSettingInfiniband:mtu property of the setting
**/
guint32
nm_setting_infiniband_get_mtu (NMSettingInfiniband *setting)
{
g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), 0);
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->mtu;
}
/**
* nm_setting_infiniband_get_transport_mode:
* @setting: the #NMSettingInfiniband
*
* Returns the transport mode for this device. Either 'datagram' or
* 'connected'.
*
* Returns: the IPoIB transport mode
**/
const char *
nm_setting_infiniband_get_transport_mode (NMSettingInfiniband *setting)
{
g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), NULL);
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->transport_mode;
}
/**
* nm_setting_infiniband_get_p_key:
* @setting: the #NMSettingInfiniband
*
* Returns the P_Key to use for this device. A value of -1 means to
* use the default P_Key (aka "the P_Key at index 0"). Otherwise it is
* a 16-bit unsigned integer.
*
* Returns: the IPoIB P_Key
**/
int
nm_setting_infiniband_get_p_key (NMSettingInfiniband *setting)
{
g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), -1);
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->p_key;
}
/**
* nm_setting_infiniband_get_parent:
* @setting: the #NMSettingInfiniband
*
* Returns the parent interface name for this device, if set.
*
* Returns: the parent interface name
**/
const char *
nm_setting_infiniband_get_parent (NMSettingInfiniband *setting)
{
g_return_val_if_fail (NM_IS_SETTING_INFINIBAND (setting), NULL);
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->parent;
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting);
if (priv->p_key == -1 || !priv->parent)
return NULL;
if (!priv->virtual_iface_name)
priv->virtual_iface_name = g_strdup_printf ("%s.%04x", priv->parent, priv->p_key);
return NM_SETTING_INFINIBAND_GET_PRIVATE (setting)->virtual_iface_name;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingConnection *s_con;
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (setting);
if (priv->mac_address && priv->mac_address->len != INFINIBAND_ALEN) {
g_set_error_literal (error,
NM_SETTING_INFINIBAND_ERROR,
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_MAC_ADDRESS);
return FALSE;
}
if (!g_strcmp0 (priv->transport_mode, "datagram")) {
if (priv->mtu > 2044)
priv->mtu = 2044;
} else if (!g_strcmp0 (priv->transport_mode, "connected")) {
if (priv->mtu > 65520)
priv->mtu = 65520;
} else {
g_set_error_literal (error,
NM_SETTING_INFINIBAND_ERROR,
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_TRANSPORT_MODE);
return FALSE;
}
if (priv->parent) {
if (!nm_utils_iface_valid_name (priv->parent)) {
g_set_error_literal (error,
NM_SETTING_INFINIBAND_ERROR,
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
_("not a valid interface name"));
g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT);
return FALSE;
}
if (priv->p_key == -1) {
g_set_error_literal (error,
NM_SETTING_INFINIBAND_ERROR,
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
_("Must specify a P_Key if specifying parent"));
g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT);
}
}
if (priv->p_key != -1) {
if (!priv->mac_address && !priv->parent) {
g_set_error_literal (error,
NM_SETTING_INFINIBAND_ERROR,
NM_SETTING_INFINIBAND_ERROR_MISSING_PROPERTY,
_("InfiniBand P_Key connection did not specify parent interface name"));
g_prefix_error (error, "%s: ", NM_SETTING_INFINIBAND_PARENT);
return FALSE;
}
}
s_con = NM_SETTING_CONNECTION (nm_setting_find_in_list (all_settings, NM_SETTING_CONNECTION_SETTING_NAME));
if (s_con) {
const char *interface_name = nm_setting_connection_get_interface_name (s_con);
if (!interface_name)
;
else if (!nm_utils_iface_valid_name (interface_name)) {
/* report the error for NMSettingConnection:interface-name, because
* it's that property that is invalid -- although we currently verify()
* NMSettingInfiniband.
**/
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("'%s' is not a valid interface name"),
interface_name);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
} else {
if (priv->p_key != -1) {
if (!priv->virtual_iface_name)
priv->virtual_iface_name = g_strdup_printf ("%s.%04x", priv->parent, priv->p_key);
if (strcmp (interface_name, priv->virtual_iface_name) != 0) {
/* We don't support renaming software infiniband devices. Later we might, but
* for now just reject such connections.
**/
g_set_error (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("interface name of software infiniband device must be '%s' or unset (instead it is '%s')"),
priv->virtual_iface_name, interface_name);
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
}
}
}
}
return TRUE;
}
static void
nm_setting_infiniband_init (NMSettingInfiniband *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (object);
g_free (priv->transport_mode);
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
g_free (priv->parent);
g_free (priv->virtual_iface_name);
G_OBJECT_CLASS (nm_setting_infiniband_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingInfinibandPrivate *priv = NM_SETTING_INFINIBAND_GET_PRIVATE (object);
switch (prop_id) {
case PROP_MAC_ADDRESS:
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
priv->mac_address = g_value_dup_boxed (value);
break;
case PROP_MTU:
priv->mtu = g_value_get_uint (value);
break;
case PROP_TRANSPORT_MODE:
g_free (priv->transport_mode);
priv->transport_mode = g_value_dup_string (value);
break;
case PROP_P_KEY:
priv->p_key = g_value_get_int (value);
g_clear_pointer (&priv->virtual_iface_name, g_free);
break;
case PROP_PARENT:
g_free (priv->parent);
priv->parent = g_value_dup_string (value);
g_clear_pointer (&priv->virtual_iface_name, g_free);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingInfiniband *setting = NM_SETTING_INFINIBAND (object);
switch (prop_id) {
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, nm_setting_infiniband_get_mac_address (setting));
break;
case PROP_MTU:
g_value_set_uint (value, nm_setting_infiniband_get_mtu (setting));
break;
case PROP_TRANSPORT_MODE:
g_value_set_string (value, nm_setting_infiniband_get_transport_mode (setting));
break;
case PROP_P_KEY:
g_value_set_int (value, nm_setting_infiniband_get_p_key (setting));
break;
case PROP_PARENT:
g_value_set_string (value, nm_setting_infiniband_get_parent (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_infiniband_class_init (NMSettingInfinibandClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingInfinibandPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
* NMSettingInfiniband:mac-address:
*
* If specified, this connection will only apply to the IPoIB device whose
* permanent MAC address matches. This property does not change the MAC
* address of the device (i.e. MAC spoofing).
**/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
_nm_param_spec_specialized (NM_SETTING_INFINIBAND_MAC_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingInfiniband:mtu:
*
* If non-zero, only transmit packets of the specified size or smaller,
* breaking larger packets up into multiple frames.
**/
g_object_class_install_property
(object_class, PROP_MTU,
g_param_spec_uint (NM_SETTING_INFINIBAND_MTU, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingInfiniband:transport-mode:
*
* The IP-over-InfiniBand transport mode. Either "datagram" or
* "connected".
**/
g_object_class_install_property
(object_class, PROP_TRANSPORT_MODE,
g_param_spec_string (NM_SETTING_INFINIBAND_TRANSPORT_MODE, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingInfiniband:p-key:
*
* The InfiniBand P_Key to use for this device. A value of -1 means to use
* the default P_Key (aka "the P_Key at index 0"). Otherwise it is a 16-bit
* unsigned integer, whose high bit is set if it is a "full membership"
* P_Key.
**/
g_object_class_install_property
(object_class, PROP_P_KEY,
g_param_spec_int (NM_SETTING_INFINIBAND_P_KEY, "", "",
-1, 0xFFFF, -1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingInfiniband:parent:
*
* The interface name of the parent device of this device. Normally %NULL,
* but if the #NMSettingInfiniband:p_key property is set, then you must
* specify the base device by setting either this property or
* #NMSettingInfiniband:mac-address.
**/
g_object_class_install_property
(object_class, PROP_PARENT,
g_param_spec_string (NM_SETTING_INFINIBAND_PARENT, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,85 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 Red Hat, Inc.
*/
#ifndef NM_SETTING_INFINIBAND_H
#define NM_SETTING_INFINIBAND_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_INFINIBAND (nm_setting_infiniband_get_type ())
#define NM_SETTING_INFINIBAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_INFINIBAND, NMSettingInfiniband))
#define NM_SETTING_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_INFINIBAND, NMSettingInfinibandClass))
#define NM_IS_SETTING_INFINIBAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_INFINIBAND))
#define NM_IS_SETTING_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_INFINIBAND))
#define NM_SETTING_INFINIBAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_INFINIBAND, NMSettingInfinibandClass))
#define NM_SETTING_INFINIBAND_SETTING_NAME "infiniband"
/**
* NMSettingInfinibandError:
* @NM_SETTING_INFINIBAND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_INFINIBAND_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_INFINIBAND_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_INFINIBAND_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingInfinibandError;
#define NM_SETTING_INFINIBAND_ERROR nm_setting_infiniband_error_quark ()
GQuark nm_setting_infiniband_error_quark (void);
#define NM_SETTING_INFINIBAND_MAC_ADDRESS "mac-address"
#define NM_SETTING_INFINIBAND_MTU "mtu"
#define NM_SETTING_INFINIBAND_TRANSPORT_MODE "transport-mode"
#define NM_SETTING_INFINIBAND_P_KEY "p-key"
#define NM_SETTING_INFINIBAND_PARENT "parent"
typedef struct {
NMSetting parent;
} NMSettingInfiniband;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingInfinibandClass;
GType nm_setting_infiniband_get_type (void);
NMSetting * nm_setting_infiniband_new (void);
const GByteArray *nm_setting_infiniband_get_mac_address (NMSettingInfiniband *setting);
guint32 nm_setting_infiniband_get_mtu (NMSettingInfiniband *setting);
const char * nm_setting_infiniband_get_transport_mode (NMSettingInfiniband *setting);
int nm_setting_infiniband_get_p_key (NMSettingInfiniband *setting);
const char * nm_setting_infiniband_get_parent (NMSettingInfiniband *setting);
G_END_DECLS
#endif /* NM_SETTING_INFINIBAND_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,229 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_IP4_CONFIG_H
#define NM_SETTING_IP4_CONFIG_H
#include "nm-setting.h"
G_BEGIN_DECLS
#define NM_TYPE_SETTING_IP4_CONFIG (nm_setting_ip4_config_get_type ())
#define NM_SETTING_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4Config))
#define NM_SETTING_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_IP4CONFIG, NMSettingIP4ConfigClass))
#define NM_IS_SETTING_IP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_IP4_CONFIG))
#define NM_IS_SETTING_IP4_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_IP4_CONFIG))
#define NM_SETTING_IP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_IP4_CONFIG, NMSettingIP4ConfigClass))
#define NM_SETTING_IP4_CONFIG_SETTING_NAME "ipv4"
/**
* NMSettingIP4ConfigError:
* @NM_SETTING_IP4_CONFIG_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD: the property's value is
* not valid with the given IP4 method
*/
typedef enum {
NM_SETTING_IP4_CONFIG_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_IP4_CONFIG_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD /*< nick=NotAllowedForMethod >*/
} NMSettingIP4ConfigError;
#define NM_SETTING_IP4_CONFIG_ERROR nm_setting_ip4_config_error_quark ()
GQuark nm_setting_ip4_config_error_quark (void);
#define NM_SETTING_IP4_CONFIG_METHOD "method"
#define NM_SETTING_IP4_CONFIG_DNS "dns"
#define NM_SETTING_IP4_CONFIG_DNS_SEARCH "dns-search"
#define NM_SETTING_IP4_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP4_CONFIG_ROUTES "routes"
#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
#define NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID "dhcp-client-id"
#define NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME "dhcp-send-hostname"
#define NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME "dhcp-hostname"
#define NM_SETTING_IP4_CONFIG_NEVER_DEFAULT "never-default"
#define NM_SETTING_IP4_CONFIG_MAY_FAIL "may-fail"
/**
* NM_SETTING_IP4_CONFIG_METHOD_AUTO:
*
* IPv4 configuration should be automatically determined via a method appropriate
* for the hardware interface, ie DHCP or PPP or some other device-specific
* manner.
*/
#define NM_SETTING_IP4_CONFIG_METHOD_AUTO "auto"
/**
* NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL:
*
* IPv4 configuration should be automatically configured for link-local-only
* operation.
*/
#define NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL "link-local"
/**
* NM_SETTING_IP4_CONFIG_METHOD_MANUAL:
*
* All necessary IPv4 configuration (addresses, prefix, DNS, etc) is specified
* in the setting's properties.
*/
#define NM_SETTING_IP4_CONFIG_METHOD_MANUAL "manual"
/**
* NM_SETTING_IP4_CONFIG_METHOD_SHARED:
*
* This connection specifies configuration that allows other computers to
* connect through it to the default network (usually the Internet). The
* connection's interface will be assigned a private address, and a DHCP server,
* caching DNS server, and Network Address Translation (NAT) functionality will
* be started on this connection's interface to allow other devices to connect
* through that interface to the default network.
*/
#define NM_SETTING_IP4_CONFIG_METHOD_SHARED "shared"
/**
* NM_SETTING_IP4_CONFIG_METHOD_DISABLED:
*
* This connection does not use or require IPv4 address and it should be disabled.
*/
#define NM_SETTING_IP4_CONFIG_METHOD_DISABLED "disabled"
typedef struct NMIP4Address NMIP4Address;
GType nm_ip4_address_get_type (void);
NMIP4Address * nm_ip4_address_new (void);
NMIP4Address * nm_ip4_address_dup (NMIP4Address *source);
void nm_ip4_address_ref (NMIP4Address *address);
void nm_ip4_address_unref (NMIP4Address *address);
/* Return TRUE if addresses are identical */
gboolean nm_ip4_address_compare (NMIP4Address *address, NMIP4Address *other);
guint32 nm_ip4_address_get_address (NMIP4Address *address);
void nm_ip4_address_set_address (NMIP4Address *address,
guint32 addr); /* network byte order */
guint32 nm_ip4_address_get_prefix (NMIP4Address *address);
void nm_ip4_address_set_prefix (NMIP4Address *address,
guint32 prefix);
guint32 nm_ip4_address_get_gateway (NMIP4Address *address);
void nm_ip4_address_set_gateway (NMIP4Address *address,
guint32 gateway); /* network byte order */
typedef struct NMIP4Route NMIP4Route;
GType nm_ip4_route_get_type (void);
NMIP4Route * nm_ip4_route_new (void);
NMIP4Route * nm_ip4_route_dup (NMIP4Route *source);
void nm_ip4_route_ref (NMIP4Route *route);
void nm_ip4_route_unref (NMIP4Route *route);
/* Return TRUE if routes are identical */
gboolean nm_ip4_route_compare (NMIP4Route *route, NMIP4Route *other);
guint32 nm_ip4_route_get_dest (NMIP4Route *route);
void nm_ip4_route_set_dest (NMIP4Route *route,
guint32 dest); /* network byte order */
guint32 nm_ip4_route_get_prefix (NMIP4Route *route);
void nm_ip4_route_set_prefix (NMIP4Route *route,
guint32 prefix);
guint32 nm_ip4_route_get_next_hop (NMIP4Route *route);
void nm_ip4_route_set_next_hop (NMIP4Route *route,
guint32 next_hop); /* network byte order */
guint32 nm_ip4_route_get_metric (NMIP4Route *route);
void nm_ip4_route_set_metric (NMIP4Route *route,
guint32 metric);
typedef struct {
NMSetting parent;
} NMSettingIP4Config;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingIP4ConfigClass;
GType nm_setting_ip4_config_get_type (void);
NMSetting * nm_setting_ip4_config_new (void);
const char * nm_setting_ip4_config_get_method (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_num_dns (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_dns (NMSettingIP4Config *setting, guint32 i);
gboolean nm_setting_ip4_config_add_dns (NMSettingIP4Config *setting, guint32 dns);
void nm_setting_ip4_config_remove_dns (NMSettingIP4Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip4_config_remove_dns_by_value (NMSettingIP4Config *setting, guint32 dns);
void nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_num_dns_searches (NMSettingIP4Config *setting);
const char * nm_setting_ip4_config_get_dns_search (NMSettingIP4Config *setting, guint32 i);
gboolean nm_setting_ip4_config_add_dns_search (NMSettingIP4Config *setting, const char *dns_search);
void nm_setting_ip4_config_remove_dns_search (NMSettingIP4Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip4_config_remove_dns_search_by_value (NMSettingIP4Config *setting, const char *dns_search);
void nm_setting_ip4_config_clear_dns_searches (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_num_addresses (NMSettingIP4Config *setting);
NMIP4Address *nm_setting_ip4_config_get_address (NMSettingIP4Config *setting, guint32 i);
gboolean nm_setting_ip4_config_add_address (NMSettingIP4Config *setting, NMIP4Address *address);
void nm_setting_ip4_config_remove_address (NMSettingIP4Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip4_config_remove_address_by_value (NMSettingIP4Config *setting, NMIP4Address *address);
void nm_setting_ip4_config_clear_addresses (NMSettingIP4Config *setting);
guint32 nm_setting_ip4_config_get_num_routes (NMSettingIP4Config *setting);
NMIP4Route * nm_setting_ip4_config_get_route (NMSettingIP4Config *setting, guint32 i);
gboolean nm_setting_ip4_config_add_route (NMSettingIP4Config *setting, NMIP4Route *route);
void nm_setting_ip4_config_remove_route (NMSettingIP4Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip4_config_remove_route_by_value (NMSettingIP4Config *setting, NMIP4Route *route);
void nm_setting_ip4_config_clear_routes (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_ignore_auto_routes (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_ignore_auto_dns (NMSettingIP4Config *setting);
const char * nm_setting_ip4_config_get_dhcp_client_id (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_dhcp_send_hostname (NMSettingIP4Config *setting);
const char * nm_setting_ip4_config_get_dhcp_hostname (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_never_default (NMSettingIP4Config *setting);
gboolean nm_setting_ip4_config_get_may_fail (NMSettingIP4Config *setting);
G_END_DECLS
#endif /* NM_SETTING_IP4_CONFIG_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,256 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
*/
#ifndef NM_SETTING_IP6_CONFIG_H
#define NM_SETTING_IP6_CONFIG_H
#include <arpa/inet.h>
#include "nm-setting.h"
G_BEGIN_DECLS
#define NM_TYPE_SETTING_IP6_CONFIG (nm_setting_ip6_config_get_type ())
#define NM_SETTING_IP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_IP6_CONFIG, NMSettingIP6Config))
#define NM_SETTING_IP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_IP6CONFIG, NMSettingIP6ConfigClass))
#define NM_IS_SETTING_IP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_IP6_CONFIG))
#define NM_IS_SETTING_IP6_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_IP6_CONFIG))
#define NM_SETTING_IP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_IP6_CONFIG, NMSettingIP6ConfigClass))
#define NM_SETTING_IP6_CONFIG_SETTING_NAME "ipv6"
/**
* NMSettingIP6ConfigError:
* @NM_SETTING_IP6_CONFIG_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_IP6_CONFIG_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD: the property's value is
* not valid with the given IPv6 method
*/
typedef enum {
NM_SETTING_IP6_CONFIG_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_IP6_CONFIG_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_IP6_CONFIG_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD /*< nick=NotAllowedForMethod >*/
} NMSettingIP6ConfigError;
#define NM_SETTING_IP6_CONFIG_ERROR nm_setting_ip6_config_error_quark ()
GQuark nm_setting_ip6_config_error_quark (void);
#define NM_SETTING_IP6_CONFIG_METHOD "method"
#define NM_SETTING_IP6_CONFIG_DNS "dns"
#define NM_SETTING_IP6_CONFIG_DNS_SEARCH "dns-search"
#define NM_SETTING_IP6_CONFIG_ADDRESSES "addresses"
#define NM_SETTING_IP6_CONFIG_ROUTES "routes"
#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_ROUTES "ignore-auto-routes"
#define NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS "ignore-auto-dns"
#define NM_SETTING_IP6_CONFIG_NEVER_DEFAULT "never-default"
#define NM_SETTING_IP6_CONFIG_MAY_FAIL "may-fail"
#define NM_SETTING_IP6_CONFIG_IP6_PRIVACY "ip6-privacy"
#define NM_SETTING_IP6_CONFIG_DHCP_HOSTNAME "dhcp-hostname"
/**
* NM_SETTING_IP6_CONFIG_METHOD_IGNORE:
*
* IPv6 is not required or is handled by some other mechanism, and NetworkManager
* should not configure IPv6 for this connection.
*/
#define NM_SETTING_IP6_CONFIG_METHOD_IGNORE "ignore"
/**
* NM_SETTING_IP6_CONFIG_METHOD_AUTO:
*
* IPv6 configuration should be automatically determined via a method appropriate
* for the hardware interface, ie router advertisements, DHCP, or PPP or some
* other device-specific manner.
*/
#define NM_SETTING_IP6_CONFIG_METHOD_AUTO "auto"
/**
* NM_SETTING_IP6_CONFIG_METHOD_DHCP:
*
* IPv6 configuration should be automatically determined via DHCPv6 only and
* router advertisements should be ignored.
*/
#define NM_SETTING_IP6_CONFIG_METHOD_DHCP "dhcp"
/**
* NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL:
*
* IPv6 configuration should be automatically configured for link-local-only
* operation.
*/
#define NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL "link-local"
/**
* NM_SETTING_IP6_CONFIG_METHOD_MANUAL:
*
* All necessary IPv6 configuration (addresses, prefix, DNS, etc) is specified
* in the setting's properties.
*/
#define NM_SETTING_IP6_CONFIG_METHOD_MANUAL "manual"
/**
* NM_SETTING_IP6_CONFIG_METHOD_SHARED:
*
* This connection specifies configuration that allows other computers to
* connect through it to the default network (usually the Internet). The
* connection's interface will be assigned a private address, and router
* advertisements, a caching DNS server, and Network Address Translation (NAT)
* functionality will be started on this connection's interface to allow other
* devices to connect through that interface to the default network. (not yet
* supported for IPv6)
*/
#define NM_SETTING_IP6_CONFIG_METHOD_SHARED "shared"
/**
* NMSettingIP6ConfigPrivacy:
* @NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN: unknown or no value specified
* @NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED: IPv6 Privacy Extensions are disabled
* @NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR: IPv6 Privacy Extensions
* are enabled, but public addresses are preferred over temporary addresses
* @NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR: IPv6 Privacy Extensions
* are enabled and temporary addresses are preferred over public addresses
*
* #NMSettingIP6ConfigPrivacy values indicate if and how IPv6 Privacy
* Extensions are used (RFC4941).
*/
typedef enum {
NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN = -1,
NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED = 0,
NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR = 1,
NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR = 2
} NMSettingIP6ConfigPrivacy;
typedef struct NMIP6Address NMIP6Address;
GType nm_ip6_address_get_type (void);
NMIP6Address * nm_ip6_address_new (void);
NMIP6Address * nm_ip6_address_dup (NMIP6Address *source);
void nm_ip6_address_ref (NMIP6Address *address);
void nm_ip6_address_unref (NMIP6Address *address);
/* Return TRUE if addresses are identical */
gboolean nm_ip6_address_compare (NMIP6Address *address, NMIP6Address *other);
const struct in6_addr *nm_ip6_address_get_address (NMIP6Address *address);
void nm_ip6_address_set_address (NMIP6Address *address,
const struct in6_addr *addr);
guint32 nm_ip6_address_get_prefix (NMIP6Address *address);
void nm_ip6_address_set_prefix (NMIP6Address *address,
guint32 prefix);
const struct in6_addr *nm_ip6_address_get_gateway (NMIP6Address *address);
void nm_ip6_address_set_gateway (NMIP6Address *address,
const struct in6_addr *gateway);
typedef struct NMIP6Route NMIP6Route;
GType nm_ip6_route_get_type (void);
NMIP6Route * nm_ip6_route_new (void);
NMIP6Route * nm_ip6_route_dup (NMIP6Route *source);
void nm_ip6_route_ref (NMIP6Route *route);
void nm_ip6_route_unref (NMIP6Route *route);
/* Return TRUE if routes are identical */
gboolean nm_ip6_route_compare (NMIP6Route *route, NMIP6Route *other);
const struct in6_addr *nm_ip6_route_get_dest (NMIP6Route *route);
void nm_ip6_route_set_dest (NMIP6Route *route,
const struct in6_addr *dest);
guint32 nm_ip6_route_get_prefix (NMIP6Route *route);
void nm_ip6_route_set_prefix (NMIP6Route *route,
guint32 prefix);
const struct in6_addr *nm_ip6_route_get_next_hop (NMIP6Route *route);
void nm_ip6_route_set_next_hop (NMIP6Route *route,
const struct in6_addr *next_hop);
guint32 nm_ip6_route_get_metric (NMIP6Route *route);
void nm_ip6_route_set_metric (NMIP6Route *route,
guint32 metric);
typedef struct {
NMSetting parent;
} NMSettingIP6Config;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingIP6ConfigClass;
GType nm_setting_ip6_config_get_type (void);
NMSetting * nm_setting_ip6_config_new (void);
const char * nm_setting_ip6_config_get_method (NMSettingIP6Config *setting);
guint32 nm_setting_ip6_config_get_num_dns (NMSettingIP6Config *setting);
const struct in6_addr *nm_setting_ip6_config_get_dns (NMSettingIP6Config *setting, guint32 i);
gboolean nm_setting_ip6_config_add_dns (NMSettingIP6Config *setting, const struct in6_addr *dns);
void nm_setting_ip6_config_remove_dns (NMSettingIP6Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip6_config_remove_dns_by_value (NMSettingIP6Config *setting, const struct in6_addr *dns);
void nm_setting_ip6_config_clear_dns (NMSettingIP6Config *setting);
guint32 nm_setting_ip6_config_get_num_dns_searches (NMSettingIP6Config *setting);
const char * nm_setting_ip6_config_get_dns_search (NMSettingIP6Config *setting, guint32 i);
gboolean nm_setting_ip6_config_add_dns_search (NMSettingIP6Config *setting, const char *dns_search);
void nm_setting_ip6_config_remove_dns_search (NMSettingIP6Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip6_config_remove_dns_search_by_value (NMSettingIP6Config *setting, const char *dns_search);
void nm_setting_ip6_config_clear_dns_searches (NMSettingIP6Config *setting);
guint32 nm_setting_ip6_config_get_num_addresses (NMSettingIP6Config *setting);
NMIP6Address * nm_setting_ip6_config_get_address (NMSettingIP6Config *setting, guint32 i);
gboolean nm_setting_ip6_config_add_address (NMSettingIP6Config *setting, NMIP6Address *address);
void nm_setting_ip6_config_remove_address (NMSettingIP6Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip6_config_remove_address_by_value (NMSettingIP6Config *setting, NMIP6Address *address);
void nm_setting_ip6_config_clear_addresses (NMSettingIP6Config *setting);
guint32 nm_setting_ip6_config_get_num_routes (NMSettingIP6Config *setting);
NMIP6Route * nm_setting_ip6_config_get_route (NMSettingIP6Config *setting, guint32 i);
gboolean nm_setting_ip6_config_add_route (NMSettingIP6Config *setting, NMIP6Route *route);
void nm_setting_ip6_config_remove_route (NMSettingIP6Config *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_ip6_config_remove_route_by_value (NMSettingIP6Config *setting, NMIP6Route *route);
void nm_setting_ip6_config_clear_routes (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_ignore_auto_routes (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_ignore_auto_dns (NMSettingIP6Config *setting);
const char * nm_setting_ip6_config_get_dhcp_hostname (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_never_default (NMSettingIP6Config *setting);
gboolean nm_setting_ip6_config_get_may_fail (NMSettingIP6Config *setting);
NMSettingIP6ConfigPrivacy nm_setting_ip6_config_get_ip6_privacy (NMSettingIP6Config *setting);
G_END_DECLS
#endif /* NM_SETTING_IP6_CONFIG_H */

View File

@@ -0,0 +1,274 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2009 One Laptop per Child
*/
#include <string.h>
#include <netinet/ether.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "NetworkManager.h"
#include "nm-setting-olpc-mesh.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
GQuark
nm_setting_olpc_mesh_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-olpc-mesh-error-quark");
return quark;
}
static void nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting);
G_DEFINE_TYPE_WITH_CODE (NMSettingOlpcMesh, nm_setting_olpc_mesh, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_OLPC_MESH_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_OLPC_MESH_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_OLPC_MESH)
#define NM_SETTING_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshPrivate))
typedef struct {
GByteArray *ssid;
guint32 channel;
GByteArray *dhcp_anycast_addr;
} NMSettingOlpcMeshPrivate;
enum {
PROP_0,
PROP_SSID,
PROP_CHANNEL,
PROP_DHCP_ANYCAST_ADDRESS,
LAST_PROP
};
/**
* nm_setting_olpc_mesh_new:
*
* Creates a new #NMSettingOlpcMesh object with default values.
*
* Returns: the new empty #NMSettingOlpcMesh object
**/
NMSetting *nm_setting_olpc_mesh_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_OLPC_MESH, NULL);
}
static void
nm_setting_olpc_mesh_init (NMSettingOlpcMesh *setting)
{
}
const GByteArray *
nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting)
{
g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), NULL);
return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->ssid;
}
guint32
nm_setting_olpc_mesh_get_channel (NMSettingOlpcMesh *setting)
{
g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), 0);
return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->channel;
}
const GByteArray *
nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting)
{
g_return_val_if_fail (NM_IS_SETTING_OLPC_MESH (setting), NULL);
return NM_SETTING_OLPC_MESH_GET_PRIVATE (setting)->dhcp_anycast_addr;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (setting);
if (!priv->ssid) {
g_set_error_literal (error,
NM_SETTING_OLPC_MESH_ERROR,
NM_SETTING_OLPC_MESH_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_SSID);
return FALSE;
}
if (!priv->ssid->len || priv->ssid->len > 32) {
g_set_error_literal (error,
NM_SETTING_OLPC_MESH_ERROR,
NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
_("SSID length is out of range <1-32> bytes"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_SSID);
return FALSE;
}
if (priv->channel == 0 || priv->channel > 13) {
g_set_error (error,
NM_SETTING_OLPC_MESH_ERROR,
NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
_("'%d' is not a valid channel"),
priv->channel);
g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_CHANNEL);
return FALSE;
}
if (priv->dhcp_anycast_addr && priv->dhcp_anycast_addr->len != ETH_ALEN) {
g_set_error_literal (error,
NM_SETTING_OLPC_MESH_ERROR,
NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_OLPC_MESH_SETTING_NAME, NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS);
return FALSE;
}
return TRUE;
}
static void
finalize (GObject *object)
{
NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (object);
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
if (priv->dhcp_anycast_addr)
g_byte_array_free (priv->dhcp_anycast_addr, TRUE);
G_OBJECT_CLASS (nm_setting_olpc_mesh_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingOlpcMeshPrivate *priv = NM_SETTING_OLPC_MESH_GET_PRIVATE (object);
switch (prop_id) {
case PROP_SSID:
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
priv->ssid = g_value_dup_boxed (value);
break;
case PROP_CHANNEL:
priv->channel = g_value_get_uint (value);
break;
case PROP_DHCP_ANYCAST_ADDRESS:
if (priv->dhcp_anycast_addr)
g_byte_array_free (priv->dhcp_anycast_addr, TRUE);
priv->dhcp_anycast_addr = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingOlpcMesh *setting = NM_SETTING_OLPC_MESH (object);
switch (prop_id) {
case PROP_SSID:
g_value_set_boxed (value, nm_setting_olpc_mesh_get_ssid (setting));
break;
case PROP_CHANNEL:
g_value_set_uint (value, nm_setting_olpc_mesh_get_channel (setting));
break;
case PROP_DHCP_ANYCAST_ADDRESS:
g_value_set_boxed (value, nm_setting_olpc_mesh_get_dhcp_anycast_address (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_olpc_mesh_class_init (NMSettingOlpcMeshClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingOlpcMeshPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingOlpcMesh:ssid:
*
* SSID of the mesh network to join.
**/
g_object_class_install_property
(object_class, PROP_SSID,
_nm_param_spec_specialized (NM_SETTING_OLPC_MESH_SSID, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingOlpcMesh:channel:
*
* Channel on which the mesh network to join is located.
**/
g_object_class_install_property
(object_class, PROP_CHANNEL,
g_param_spec_uint (NM_SETTING_OLPC_MESH_CHANNEL, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingOlpcMesh:dhcp-anycast-address:
*
* Anycast DHCP MAC address used when requesting an IP address via DHCP.
* The specific anycast address used determines which DHCP server class
* answers the request.
**/
g_object_class_install_property
(object_class, PROP_DHCP_ANYCAST_ADDRESS,
_nm_param_spec_specialized (NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2009 One Laptop per Child
*/
#ifndef NM_SETTING_OLPC_MESH_H
#define NM_SETTING_OLPC_MESH_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_OLPC_MESH (nm_setting_olpc_mesh_get_type ())
#define NM_SETTING_OLPC_MESH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMesh))
#define NM_SETTING_OLPC_MESH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshClass))
#define NM_IS_SETTING_OLPC_MESH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_OLPC_MESH))
#define NM_IS_SETTING_OLPC_MESH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_OLPC_MESH))
#define NM_SETTING_OLPC_MESH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_OLPC_MESH, NMSettingOlpcMeshClass))
#define NM_SETTING_OLPC_MESH_SETTING_NAME "802-11-olpc-mesh"
/**
* NMSettingOlpcMeshError:
* @NM_SETTING_OLPC_MESH_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_OLPC_MESH_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_OLPC_MESH_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_OLPC_MESH_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_OLPC_MESH_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingOlpcMeshError;
#define NM_SETTING_OLPC_MESH_ERROR nm_setting_olpc_mesh_error_quark ()
GQuark nm_setting_olpc_mesh_error_quark (void);
#define NM_SETTING_OLPC_MESH_SSID "ssid"
#define NM_SETTING_OLPC_MESH_CHANNEL "channel"
#define NM_SETTING_OLPC_MESH_DHCP_ANYCAST_ADDRESS "dhcp-anycast-address"
typedef struct {
NMSetting parent;
} NMSettingOlpcMesh;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingOlpcMeshClass;
GType nm_setting_olpc_mesh_get_type (void);
NMSetting * nm_setting_olpc_mesh_new (void);
const GByteArray *nm_setting_olpc_mesh_get_ssid (NMSettingOlpcMesh *setting);
guint32 nm_setting_olpc_mesh_get_channel (NMSettingOlpcMesh *setting);
const GByteArray *nm_setting_olpc_mesh_get_dhcp_anycast_address (NMSettingOlpcMesh *setting);
G_END_DECLS
#endif /* NM_SETTING_OLPC_MESH_H */

823
libnm-core/nm-setting-ppp.c Normal file
View File

@@ -0,0 +1,823 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include <glib/gi18n.h>
#include "nm-setting-ppp.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-ppp
* @short_description: Describes connection properties for devices/networks
* that require PPP to deliver IP capability
* @include: nm-setting-ppp.h
*
* The #NMSettingPPP object is a #NMSetting subclass that describes properties
* necessary for connection to networks that require PPP transport, like PPPoE
* cable and DSL modems and some mobile broadband devices.
**/
/**
* nm_setting_ppp_error_quark:
*
* Registers an error quark for #NMSettingPPP if necessary.
*
* Returns: the error quark used for #NMSettingPPP errors.
**/
GQuark
nm_setting_ppp_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-ppp-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingPPP, nm_setting_ppp, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_PPP_SETTING_NAME,
g_define_type_id,
3,
NM_SETTING_PPP_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPP)
#define NM_SETTING_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPP, NMSettingPPPPrivate))
typedef struct {
gboolean noauth;
gboolean refuse_eap;
gboolean refuse_pap;
gboolean refuse_chap;
gboolean refuse_mschap;
gboolean refuse_mschapv2;
gboolean nobsdcomp;
gboolean nodeflate;
gboolean no_vj_comp;
gboolean require_mppe;
gboolean require_mppe_128;
gboolean mppe_stateful;
gboolean crtscts;
guint32 baud;
guint32 mru;
guint32 mtu;
guint32 lcp_echo_failure;
guint32 lcp_echo_interval;
} NMSettingPPPPrivate;
enum {
PROP_0,
PROP_NOAUTH,
PROP_REFUSE_EAP,
PROP_REFUSE_PAP,
PROP_REFUSE_CHAP,
PROP_REFUSE_MSCHAP,
PROP_REFUSE_MSCHAPV2,
PROP_NOBSDCOMP,
PROP_NODEFLATE,
PROP_NO_VJ_COMP,
PROP_REQUIRE_MPPE,
PROP_REQUIRE_MPPE_128,
PROP_MPPE_STATEFUL,
PROP_CRTSCTS,
PROP_BAUD,
PROP_MRU,
PROP_MTU,
PROP_LCP_ECHO_FAILURE,
PROP_LCP_ECHO_INTERVAL,
LAST_PROP
};
/**
* nm_setting_ppp_new:
*
* Creates a new #NMSettingPPP object with default values.
*
* Returns: (transfer full): the new empty #NMSettingPPP object
**/
NMSetting *
nm_setting_ppp_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_PPP, NULL);
}
/**
* nm_setting_ppp_get_noauth:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:noauth property of the setting
**/
gboolean
nm_setting_ppp_get_noauth (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->noauth;
}
/**
* nm_setting_ppp_get_refuse_eap:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:refuse-eap property of the setting
**/
gboolean
nm_setting_ppp_get_refuse_eap (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->refuse_eap;
}
/**
* nm_setting_ppp_get_refuse_pap:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:refuse-pap property of the setting
**/
gboolean
nm_setting_ppp_get_refuse_pap (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->refuse_pap;
}
/**
* nm_setting_ppp_get_refuse_chap:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:refuse-chap property of the setting
**/
gboolean
nm_setting_ppp_get_refuse_chap (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->refuse_chap;
}
/**
* nm_setting_ppp_get_refuse_mschap:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:refuse-mschap property of the setting
**/
gboolean
nm_setting_ppp_get_refuse_mschap (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->refuse_mschap;
}
/**
* nm_setting_ppp_get_refuse_mschapv2:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:refuse-mschapv2 property of the setting
**/
gboolean
nm_setting_ppp_get_refuse_mschapv2 (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->refuse_mschapv2;
}
/**
* nm_setting_ppp_get_nobsdcomp:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:nobsdcomp property of the setting
**/
gboolean
nm_setting_ppp_get_nobsdcomp (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->nobsdcomp;
}
/**
* nm_setting_ppp_get_nodeflate:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:nodeflate property of the setting
**/
gboolean
nm_setting_ppp_get_nodeflate (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->nodeflate;
}
/**
* nm_setting_ppp_get_no_vj_comp:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:no-vj-comp property of the setting
**/
gboolean
nm_setting_ppp_get_no_vj_comp (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->no_vj_comp;
}
/**
* nm_setting_ppp_get_require_mppe:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:require-mppe property of the setting
**/
gboolean
nm_setting_ppp_get_require_mppe (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->require_mppe;
}
/**
* nm_setting_ppp_get_require_mppe_128:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:require-mppe-128 property of the setting
**/
gboolean
nm_setting_ppp_get_require_mppe_128 (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->require_mppe_128;
}
/**
* nm_setting_ppp_get_mppe_stateful:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:mppe-stateful property of the setting
**/
gboolean
nm_setting_ppp_get_mppe_stateful (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->mppe_stateful;
}
/**
* nm_setting_ppp_get_crtscts:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:crtscts property of the setting
**/
gboolean
nm_setting_ppp_get_crtscts (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), FALSE);
return NM_SETTING_PPP_GET_PRIVATE (setting)->crtscts;
}
/**
* nm_setting_ppp_get_baud:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:baud property of the setting
**/
guint32
nm_setting_ppp_get_baud (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), 0);
return NM_SETTING_PPP_GET_PRIVATE (setting)->baud;
}
/**
* nm_setting_ppp_get_mru:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:mru property of the setting
**/
guint32
nm_setting_ppp_get_mru (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), 0);
return NM_SETTING_PPP_GET_PRIVATE (setting)->mru;
}
/**
* nm_setting_ppp_get_mtu:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:mtu property of the setting
**/
guint32
nm_setting_ppp_get_mtu (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), 0);
return NM_SETTING_PPP_GET_PRIVATE (setting)->mtu;
}
/**
* nm_setting_ppp_get_lcp_echo_failure:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:lcp-echo-failure property of the setting
**/
guint32
nm_setting_ppp_get_lcp_echo_failure (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), 0);
return NM_SETTING_PPP_GET_PRIVATE (setting)->lcp_echo_failure;
}
/**
* nm_setting_ppp_get_lcp_echo_interval:
* @setting: the #NMSettingPPP
*
* Returns: the #NMSettingPPP:lcp-echo-interval property of the setting
**/
guint32
nm_setting_ppp_get_lcp_echo_interval (NMSettingPPP *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPP (setting), 0);
return NM_SETTING_PPP_GET_PRIVATE (setting)->lcp_echo_interval;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingPPPPrivate *priv = NM_SETTING_PPP_GET_PRIVATE (setting);
/* FIXME: Do we even want this or can we just let pppd evaluate the options? */
if (priv->mru > 0) {
if (priv->mru < 128 || priv->mru > 16384) {
g_set_error (error,
NM_SETTING_PPP_ERROR,
NM_SETTING_PPP_ERROR_INVALID_PROPERTY,
_("'%d' is out of valid range <128-16384>"),
priv->mru);
g_prefix_error (error, "%s.%s: ", NM_SETTING_PPP_SETTING_NAME, NM_SETTING_PPP_MRU);
return FALSE;
}
}
if (priv->lcp_echo_failure > 0) {
/* lcp_echo_interval must also be non-zero */
if (priv->lcp_echo_interval == 0) {
g_set_error (error,
NM_SETTING_PPP_ERROR,
NM_SETTING_PPP_ERROR_INVALID_PROPERTY,
_("setting this property requires non-zero '%s' property"),
NM_SETTING_PPP_LCP_ECHO_INTERVAL);
g_prefix_error (error, "%s.%s: ", NM_SETTING_PPP_SETTING_NAME, NM_SETTING_PPP_LCP_ECHO_FAILURE);
return FALSE;
}
}
return TRUE;
}
static void
nm_setting_ppp_init (NMSettingPPP *setting)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingPPPPrivate *priv = NM_SETTING_PPP_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NOAUTH:
priv->noauth = g_value_get_boolean (value);
break;
case PROP_REFUSE_EAP:
priv->refuse_eap = g_value_get_boolean (value);
break;
case PROP_REFUSE_PAP:
priv->refuse_pap = g_value_get_boolean (value);
break;
case PROP_REFUSE_CHAP:
priv->refuse_chap = g_value_get_boolean (value);
break;
case PROP_REFUSE_MSCHAP:
priv->refuse_mschap = g_value_get_boolean (value);
break;
case PROP_REFUSE_MSCHAPV2:
priv->refuse_mschapv2 = g_value_get_boolean (value);
break;
case PROP_NOBSDCOMP:
priv->nobsdcomp = g_value_get_boolean (value);
break;
case PROP_NODEFLATE:
priv->nodeflate = g_value_get_boolean (value);
break;
case PROP_NO_VJ_COMP:
priv->no_vj_comp = g_value_get_boolean (value);
break;
case PROP_REQUIRE_MPPE:
priv->require_mppe = g_value_get_boolean (value);
break;
case PROP_REQUIRE_MPPE_128:
priv->require_mppe_128 = g_value_get_boolean (value);
break;
case PROP_MPPE_STATEFUL:
priv->mppe_stateful = g_value_get_boolean (value);
break;
case PROP_CRTSCTS:
priv->crtscts = g_value_get_boolean (value);
break;
case PROP_BAUD:
priv->baud = g_value_get_uint (value);
break;
case PROP_MRU:
priv->mru = g_value_get_uint (value);
break;
case PROP_MTU:
priv->mtu = g_value_get_uint (value);
break;
case PROP_LCP_ECHO_FAILURE:
priv->lcp_echo_failure = g_value_get_uint (value);
break;
case PROP_LCP_ECHO_INTERVAL:
priv->lcp_echo_interval = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingPPP *setting = NM_SETTING_PPP (object);
switch (prop_id) {
case PROP_NOAUTH:
g_value_set_boolean (value, nm_setting_ppp_get_noauth (setting));
break;
case PROP_REFUSE_EAP:
g_value_set_boolean (value, nm_setting_ppp_get_refuse_eap (setting));
break;
case PROP_REFUSE_PAP:
g_value_set_boolean (value, nm_setting_ppp_get_refuse_pap (setting));
break;
case PROP_REFUSE_CHAP:
g_value_set_boolean (value, nm_setting_ppp_get_refuse_chap (setting));
break;
case PROP_REFUSE_MSCHAP:
g_value_set_boolean (value, nm_setting_ppp_get_refuse_mschap (setting));
break;
case PROP_REFUSE_MSCHAPV2:
g_value_set_boolean (value, nm_setting_ppp_get_refuse_mschapv2 (setting));
break;
case PROP_NOBSDCOMP:
g_value_set_boolean (value, nm_setting_ppp_get_nobsdcomp (setting));
break;
case PROP_NODEFLATE:
g_value_set_boolean (value, nm_setting_ppp_get_nodeflate (setting));
break;
case PROP_NO_VJ_COMP:
g_value_set_boolean (value, nm_setting_ppp_get_no_vj_comp (setting));
break;
case PROP_REQUIRE_MPPE:
g_value_set_boolean (value, nm_setting_ppp_get_require_mppe (setting));
break;
case PROP_REQUIRE_MPPE_128:
g_value_set_boolean (value, nm_setting_ppp_get_require_mppe_128 (setting));
break;
case PROP_MPPE_STATEFUL:
g_value_set_boolean (value, nm_setting_ppp_get_mppe_stateful (setting));
break;
case PROP_CRTSCTS:
g_value_set_boolean (value, nm_setting_ppp_get_crtscts (setting));
break;
case PROP_BAUD:
g_value_set_uint (value, nm_setting_ppp_get_baud (setting));
break;
case PROP_MRU:
g_value_set_uint (value, nm_setting_ppp_get_mru (setting));
break;
case PROP_MTU:
g_value_set_uint (value, nm_setting_ppp_get_mtu (setting));
break;
case PROP_LCP_ECHO_FAILURE:
g_value_set_uint (value, nm_setting_ppp_get_lcp_echo_failure (setting));
break;
case PROP_LCP_ECHO_INTERVAL:
g_value_set_uint (value, nm_setting_ppp_get_lcp_echo_interval (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_ppp_class_init (NMSettingPPPClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingPPPPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingPPP:noauth:
*
* If %TRUE, do not require the other side (usually the PPP server) to
* authenticate itself to the client. If %FALSE, require authentication
* from the remote side. In almost all cases, this should be %TRUE.
**/
g_object_class_install_property
(object_class, PROP_NOAUTH,
g_param_spec_boolean (NM_SETTING_PPP_NOAUTH, "", "",
TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:refuse-eap:
*
* If %TRUE, the EAP authentication method will not be used.
**/
g_object_class_install_property
(object_class, PROP_REFUSE_EAP,
g_param_spec_boolean (NM_SETTING_PPP_REFUSE_EAP, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:refuse-pap:
*
* If %TRUE, the PAP authentication method will not be used.
**/
g_object_class_install_property
(object_class, PROP_REFUSE_PAP,
g_param_spec_boolean (NM_SETTING_PPP_REFUSE_PAP, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:refuse-chap:
*
* If %TRUE, the CHAP authentication method will not be used.
**/
g_object_class_install_property
(object_class, PROP_REFUSE_CHAP,
g_param_spec_boolean (NM_SETTING_PPP_REFUSE_CHAP, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:refuse-mschap:
*
* If %TRUE, the MSCHAP authentication method will not be used.
**/
g_object_class_install_property
(object_class, PROP_REFUSE_MSCHAP,
g_param_spec_boolean (NM_SETTING_PPP_REFUSE_MSCHAP, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:refuse-mschapv2:
*
* If %TRUE, the MSCHAPv2 authentication method will not be used.
**/
g_object_class_install_property
(object_class, PROP_REFUSE_MSCHAPV2,
g_param_spec_boolean (NM_SETTING_PPP_REFUSE_MSCHAPV2, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:nobsdcomp:
*
* If %TRUE, BSD compression will not be requested.
**/
g_object_class_install_property
(object_class, PROP_NOBSDCOMP,
g_param_spec_boolean (NM_SETTING_PPP_NOBSDCOMP, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:nodeflate:
*
* If %TRUE, "deflate" compression will not be requested.
**/
g_object_class_install_property
(object_class, PROP_NODEFLATE,
g_param_spec_boolean (NM_SETTING_PPP_NODEFLATE, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:no-vj-comp:
*
* If %TRUE, Van Jacobsen TCP header compression will not be requested.
**/
g_object_class_install_property
(object_class, PROP_NO_VJ_COMP,
g_param_spec_boolean (NM_SETTING_PPP_NO_VJ_COMP, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:require-mppe:
*
* If %TRUE, MPPE (Microsoft Point-to-Point Encrpytion) will be required for
* the PPP session. If either 64-bit or 128-bit MPPE is not available the
* session will fail. Note that MPPE is not used on mobile broadband
* connections.
**/
g_object_class_install_property
(object_class, PROP_REQUIRE_MPPE,
g_param_spec_boolean (NM_SETTING_PPP_REQUIRE_MPPE, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:require-mppe-128:
*
* If %TRUE, 128-bit MPPE (Microsoft Point-to-Point Encrpytion) will be
* required for the PPP session, and the "require-mppe" property must also
* be set to %TRUE. If 128-bit MPPE is not available the session will fail.
**/
g_object_class_install_property
(object_class, PROP_REQUIRE_MPPE_128,
g_param_spec_boolean (NM_SETTING_PPP_REQUIRE_MPPE_128, "", "",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:mppe-stateful:
*
* If %TRUE, stateful MPPE is used. See pppd documentation for more
* information on stateful MPPE.
**/
g_object_class_install_property
(object_class, PROP_MPPE_STATEFUL,
g_param_spec_boolean (NM_SETTING_PPP_MPPE_STATEFUL, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:crtscts:
*
* If %TRUE, specify that pppd should set the serial port to use hardware
* flow control with RTS and CTS signals. This value should normally be set
* to %FALSE.
**/
g_object_class_install_property
(object_class, PROP_CRTSCTS,
g_param_spec_boolean (NM_SETTING_PPP_CRTSCTS, "", "",
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:baud:
*
* If non-zero, instruct pppd to set the serial port to the specified
* baudrate. This value should normally be left as 0 to automatically
* choose the speed.
**/
g_object_class_install_property
(object_class, PROP_BAUD,
g_param_spec_uint (NM_SETTING_PPP_BAUD, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:mru:
*
* If non-zero, instruct pppd to request that the peer send packets no
* larger than the specified size. If non-zero, the MRU should be between
* 128 and 16384.
*/
g_object_class_install_property
(object_class, PROP_MRU,
g_param_spec_uint (NM_SETTING_PPP_MRU, "", "",
0, 16384, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:mtu:
*
* If non-zero, instruct pppd to send packets no larger than the specified
* size.
**/
g_object_class_install_property
(object_class, PROP_MTU,
g_param_spec_uint (NM_SETTING_PPP_MTU, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:lcp-echo-failure:
*
* If non-zero, instruct pppd to presume the connection to the peer has
* failed if the specified number of LCP echo-requests go unanswered by the
* peer. The "lcp-echo-interval" property must also be set to a non-zero
* value if this property is used.
**/
g_object_class_install_property
(object_class, PROP_LCP_ECHO_FAILURE,
g_param_spec_uint (NM_SETTING_PPP_LCP_ECHO_FAILURE, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPP:lcp-echo-interval:
*
* If non-zero, instruct pppd to send an LCP echo-request frame to the peer
* every n seconds (where n is the specified value). Note that some PPP
* peers will respond to echo requests and some will not, and it is not
* possible to autodetect this.
**/
g_object_class_install_property
(object_class, PROP_LCP_ECHO_INTERVAL,
g_param_spec_uint (NM_SETTING_PPP_LCP_ECHO_INTERVAL, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_FUZZY_IGNORE |
G_PARAM_STATIC_STRINGS));
}

115
libnm-core/nm-setting-ppp.h Normal file
View File

@@ -0,0 +1,115 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_PPP_H
#define NM_SETTING_PPP_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_PPP (nm_setting_ppp_get_type ())
#define NM_SETTING_PPP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_PPP, NMSettingPPP))
#define NM_SETTING_PPP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_PPP, NMSettingPPPClass))
#define NM_IS_SETTING_PPP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_PPP))
#define NM_IS_SETTING_PPP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_PPP))
#define NM_SETTING_PPP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_PPP, NMSettingPPPClass))
#define NM_SETTING_PPP_SETTING_NAME "ppp"
/**
* NMSettingPPPError:
* @NM_SETTING_PPP_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_PPP_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_PPP_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_PPP_ERROR_REQUIRE_MPPE_NOT_ALLOWED: requiring MPPE is not compatible
* with other setting configuration parameters
*/
typedef enum {
NM_SETTING_PPP_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_PPP_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_PPP_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_PPP_ERROR_REQUIRE_MPPE_NOT_ALLOWED /*< nick=RequireMPPENotAllowed >*/
} NMSettingPPPError;
#define NM_SETTING_PPP_ERROR nm_setting_ppp_error_quark ()
GQuark nm_setting_ppp_error_quark (void);
#define NM_SETTING_PPP_NOAUTH "noauth"
#define NM_SETTING_PPP_REFUSE_EAP "refuse-eap"
#define NM_SETTING_PPP_REFUSE_PAP "refuse-pap"
#define NM_SETTING_PPP_REFUSE_CHAP "refuse-chap"
#define NM_SETTING_PPP_REFUSE_MSCHAP "refuse-mschap"
#define NM_SETTING_PPP_REFUSE_MSCHAPV2 "refuse-mschapv2"
#define NM_SETTING_PPP_NOBSDCOMP "nobsdcomp"
#define NM_SETTING_PPP_NODEFLATE "nodeflate"
#define NM_SETTING_PPP_NO_VJ_COMP "no-vj-comp"
#define NM_SETTING_PPP_REQUIRE_MPPE "require-mppe"
#define NM_SETTING_PPP_REQUIRE_MPPE_128 "require-mppe-128"
#define NM_SETTING_PPP_MPPE_STATEFUL "mppe-stateful"
#define NM_SETTING_PPP_CRTSCTS "crtscts"
#define NM_SETTING_PPP_BAUD "baud"
#define NM_SETTING_PPP_MRU "mru"
#define NM_SETTING_PPP_MTU "mtu"
#define NM_SETTING_PPP_LCP_ECHO_FAILURE "lcp-echo-failure"
#define NM_SETTING_PPP_LCP_ECHO_INTERVAL "lcp-echo-interval"
typedef struct {
NMSetting parent;
} NMSettingPPP;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingPPPClass;
GType nm_setting_ppp_get_type (void);
NMSetting *nm_setting_ppp_new (void);
gboolean nm_setting_ppp_get_noauth (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_refuse_eap (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_refuse_pap (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_refuse_chap (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_refuse_mschap (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_refuse_mschapv2 (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_nobsdcomp (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_nodeflate (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_no_vj_comp (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_require_mppe (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_require_mppe_128 (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_mppe_stateful (NMSettingPPP *setting);
gboolean nm_setting_ppp_get_crtscts (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_baud (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_mru (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_mtu (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_lcp_echo_failure (NMSettingPPP *setting);
guint32 nm_setting_ppp_get_lcp_echo_interval (NMSettingPPP *setting);
G_END_DECLS
#endif /* NM_SETTING_PPP_H */

View File

@@ -0,0 +1,342 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include <glib/gi18n.h>
#include "nm-setting-pppoe.h"
#include "nm-setting-ppp.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-pppoe
* @short_description: Describes PPPoE connection properties
* @include: nm-setting-pppoe.h
*
* The #NMSettingPPPOE object is a #NMSetting subclass that describes
* properties necessary for connection to networks that require PPPoE connections
* to provide IP transport, for example cable or DSL modems.
**/
/**
* nm_setting_pppoe_error_quark:
*
* Registers an error quark for #NMSettingPPPOE if necessary.
*
* Returns: the error quark used for #NMSettingPPPOE errors.
**/
GQuark
nm_setting_pppoe_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-pppoe-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingPPPOE, nm_setting_pppoe, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_PPPOE_SETTING_NAME,
g_define_type_id,
3,
NM_SETTING_PPPOE_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_PPPOE)
#define NM_SETTING_PPPOE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_PPPOE, NMSettingPPPOEPrivate))
typedef struct {
char *service;
char *username;
char *password;
NMSettingSecretFlags password_flags;
} NMSettingPPPOEPrivate;
enum {
PROP_0,
PROP_SERVICE,
PROP_USERNAME,
PROP_PASSWORD,
PROP_PASSWORD_FLAGS,
LAST_PROP
};
/**
* nm_setting_pppoe_new:
*
* Creates a new #NMSettingPPPOE object with default values.
*
* Returns: (transfer full): the new empty #NMSettingPPPOE object
**/
NMSetting *
nm_setting_pppoe_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_PPPOE, NULL);
}
/**
* nm_setting_pppoe_get_service:
* @setting: the #NMSettingPPPOE
*
* Returns: the #NMSettingPPPOE:service property of the setting
**/
const char *
nm_setting_pppoe_get_service (NMSettingPPPOE *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
return NM_SETTING_PPPOE_GET_PRIVATE (setting)->service;
}
/**
* nm_setting_pppoe_get_username:
* @setting: the #NMSettingPPPOE
*
* Returns: the #NMSettingPPPOE:username property of the setting
**/
const char *
nm_setting_pppoe_get_username (NMSettingPPPOE *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
return NM_SETTING_PPPOE_GET_PRIVATE (setting)->username;
}
/**
* nm_setting_pppoe_get_password:
* @setting: the #NMSettingPPPOE
*
* Returns: the #NMSettingPPPOE:password property of the setting
**/
const char *
nm_setting_pppoe_get_password (NMSettingPPPOE *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NULL);
return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password;
}
/**
* nm_setting_pppoe_get_password_flags:
* @setting: the #NMSettingPPPOE
*
* Returns: the #NMSettingSecretFlags pertaining to the #NMSettingPPPOE:password
**/
NMSettingSecretFlags
nm_setting_pppoe_get_password_flags (NMSettingPPPOE *setting)
{
g_return_val_if_fail (NM_IS_SETTING_PPPOE (setting), NM_SETTING_SECRET_FLAG_NONE);
return NM_SETTING_PPPOE_GET_PRIVATE (setting)->password_flags;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
if (!priv->username) {
g_set_error_literal (error,
NM_SETTING_PPPOE_ERROR,
NM_SETTING_PPPOE_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_USERNAME);
return FALSE;
} else if (!strlen (priv->username)) {
g_set_error_literal (error,
NM_SETTING_PPPOE_ERROR,
NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_USERNAME);
return FALSE;
}
if (priv->service && !strlen (priv->service)) {
g_set_error_literal (error,
NM_SETTING_PPPOE_ERROR,
NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_PPPOE_SETTING_NAME, NM_SETTING_PPPOE_SERVICE);
return FALSE;
}
return TRUE;
}
static GPtrArray *
need_secrets (NMSetting *setting)
{
NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (setting);
GPtrArray *secrets = NULL;
if (priv->password)
return NULL;
if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
secrets = g_ptr_array_sized_new (1);
g_ptr_array_add (secrets, NM_SETTING_PPPOE_PASSWORD);
}
return secrets;
}
static void
nm_setting_pppoe_init (NMSettingPPPOE *setting)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_SERVICE:
g_free (priv->service);
priv->service = g_value_dup_string (value);
break;
case PROP_USERNAME:
g_free (priv->username);
priv->username = g_value_dup_string (value);
break;
case PROP_PASSWORD:
g_free (priv->password);
priv->password = g_value_dup_string (value);
break;
case PROP_PASSWORD_FLAGS:
priv->password_flags = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingPPPOE *setting = NM_SETTING_PPPOE (object);
switch (prop_id) {
case PROP_SERVICE:
g_value_set_string (value, nm_setting_pppoe_get_service (setting));
break;
case PROP_USERNAME:
g_value_set_string (value, nm_setting_pppoe_get_username (setting));
break;
case PROP_PASSWORD:
g_value_set_string (value, nm_setting_pppoe_get_password (setting));
break;
case PROP_PASSWORD_FLAGS:
g_value_set_uint (value, nm_setting_pppoe_get_password_flags (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
finalize (GObject *object)
{
NMSettingPPPOEPrivate *priv = NM_SETTING_PPPOE_GET_PRIVATE (object);
g_free (priv->username);
g_free (priv->password);
g_free (priv->service);
G_OBJECT_CLASS (nm_setting_pppoe_parent_class)->finalize (object);
}
static void
nm_setting_pppoe_class_init (NMSettingPPPOEClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingPPPOEPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->need_secrets = need_secrets;
/* Properties */
/**
* NMSettingPPPOE:service:
*
* If specified, instruct PPPoE to only initiate sessions with access
* concentrators that provide the specified service. For most providers,
* this should be left blank. It is only required if there are multiple
* access concentrators or a specific service is known to be required.
**/
g_object_class_install_property
(object_class, PROP_SERVICE,
g_param_spec_string (NM_SETTING_PPPOE_SERVICE, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPPOE:username:
*
* Username used to authenticate with the PPPoE service.
**/
g_object_class_install_property
(object_class, PROP_USERNAME,
g_param_spec_string (NM_SETTING_PPPOE_USERNAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPPOE:password:
*
* Password used to authenticate with the PPPoE service.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD,
g_param_spec_string (NM_SETTING_PPPOE_PASSWORD, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_SECRET |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingPPPOE:password-flags:
*
* Flags indicating how to handle the #NMSettingPPPOE:password property.
**/
g_object_class_install_property
(object_class, PROP_PASSWORD_FLAGS,
g_param_spec_uint (NM_SETTING_PPPOE_PASSWORD_FLAGS, "", "",
NM_SETTING_SECRET_FLAG_NONE,
NM_SETTING_SECRET_FLAGS_ALL,
NM_SETTING_SECRET_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,87 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_PPPOE_H
#define NM_SETTING_PPPOE_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_PPPOE (nm_setting_pppoe_get_type ())
#define NM_SETTING_PPPOE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_PPPOE, NMSettingPPPOE))
#define NM_SETTING_PPPOE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_PPPOE, NMSettingPPPOEClass))
#define NM_IS_SETTING_PPPOE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_PPPOE))
#define NM_IS_SETTING_PPPOE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_PPPOE))
#define NM_SETTING_PPPOE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_PPPOE, NMSettingPPPOEClass))
#define NM_SETTING_PPPOE_SETTING_NAME "pppoe"
/**
* NMSettingPPPOEError:
* @NM_SETTING_PPPOE_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_PPPOE_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_PPPOE_ERROR_MISSING_PPP_SETTING: the connection
* did not contain a required PPP setting for PPP related options
*/
typedef enum {
NM_SETTING_PPPOE_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_PPPOE_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_PPPOE_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_PPPOE_ERROR_MISSING_PPP_SETTING /*< nick=MissingPPPSetting >*/
} NMSettingPPPOEError;
#define NM_SETTING_PPPOE_ERROR nm_setting_pppoe_error_quark ()
GQuark nm_setting_pppoe_error_quark (void);
#define NM_SETTING_PPPOE_SERVICE "service"
#define NM_SETTING_PPPOE_USERNAME "username"
#define NM_SETTING_PPPOE_PASSWORD "password"
#define NM_SETTING_PPPOE_PASSWORD_FLAGS "password-flags"
typedef struct {
NMSetting parent;
} NMSettingPPPOE;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingPPPOEClass;
GType nm_setting_pppoe_get_type (void);
NMSetting *nm_setting_pppoe_new (void);
const char *nm_setting_pppoe_get_service (NMSettingPPPOE *setting);
const char *nm_setting_pppoe_get_username (NMSettingPPPOE *setting);
const char *nm_setting_pppoe_get_password (NMSettingPPPOE *setting);
NMSettingSecretFlags nm_setting_pppoe_get_password_flags (NMSettingPPPOE *setting);
G_END_DECLS
#endif /* NM_SETTING_PPPOE_H */

View File

@@ -0,0 +1,125 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 Red Hat, Inc.
*/
#ifndef NM_SETTING_PRIVATE_H
#define NM_SETTING_PRIVATE_H
#include "nm-setting.h"
#include "nm-glib-compat.h"
#define NM_SETTING_SECRET_FLAGS_ALL \
(NM_SETTING_SECRET_FLAG_NONE | \
NM_SETTING_SECRET_FLAG_AGENT_OWNED | \
NM_SETTING_SECRET_FLAG_NOT_SAVED | \
NM_SETTING_SECRET_FLAG_NOT_REQUIRED)
/**
* NMSettingVerifyResult:
* @NM_SETTING_VERIFY_SUCCESS: the setting verifies successfully
* @NM_SETTING_VERIFY_ERROR: the setting has a serious misconfiguration
* @NM_SETTING_VERIFY_NORMALIZABLE: the setting is valid but has properties
* that should be normalized
* @NM_SETTING_VERIFY_NORMALIZABLE_ERROR: the setting is invalid but the
* errors can be fixed by nm_connection_normalize().
*/
typedef enum {
NM_SETTING_VERIFY_SUCCESS = TRUE,
NM_SETTING_VERIFY_ERROR = FALSE,
NM_SETTING_VERIFY_NORMALIZABLE = 2,
NM_SETTING_VERIFY_NORMALIZABLE_ERROR = 3,
} NMSettingVerifyResult;
void _nm_register_setting (const char *name,
const GType type,
const guint32 priority,
const GQuark error_quark);
/* Ensure, that name is a compile time constant string. Put the function name in parenthesis to suppress expansion. */
#define _nm_register_setting(name, type, priority, error_quark) _nm_register_setting ((name ""), type, priority, error_quark)
gboolean _nm_setting_is_base_type (NMSetting *setting);
gboolean _nm_setting_type_is_base_type (GType type);
GType _nm_setting_lookup_setting_type (const char *name);
GType _nm_setting_lookup_setting_type_by_quark (GQuark error_quark);
gint _nm_setting_compare_priority (gconstpointer a, gconstpointer b);
typedef enum NMSettingUpdateSecretResult {
NM_SETTING_UPDATE_SECRET_ERROR = FALSE,
NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED = TRUE,
NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED = 2,
} NMSettingUpdateSecretResult;
NMSettingUpdateSecretResult _nm_setting_update_secrets (NMSetting *setting,
GHashTable *secrets,
GError **error);
gboolean _nm_setting_clear_secrets (NMSetting *setting);
gboolean _nm_setting_clear_secrets_with_flags (NMSetting *setting,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data);
/* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated
* connection can be replaced by a already-defined connection. This flag only
* takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE
* flag.
*/
#define NM_SETTING_COMPARE_FLAG_INFERRABLE 0x80000000
/* The property of the #NMSetting should be considered during comparisons that
* use the %NM_SETTING_COMPARE_FLAG_INFERRABLE flag. Properties that don't have
* this flag, are ignored when doing an infrerrable comparison. This flag should
* be set on all properties that are read from the kernel or the system when a
* connection is generated. eg, IP addresses/routes can be read from the
* kernel, but the 'autoconnect' property cannot, so
* %NM_SETTING_IP4_CONFIG_ADDRESSES gets the INFERRABLE flag, but
* %NM_SETTING_CONNECTION_AUTOCONNECT would not.
*
* This flag should not be used with properties where the default cannot be
* read separately from the current value, like MTU or wired duplex mode.
*/
#define NM_SETTING_PARAM_INFERRABLE (1 << (4 + G_PARAM_USER_SHIFT))
/* Ensure the setting's GType is registered at library load time */
#define NM_SETTING_REGISTER_TYPE(x) \
static void __attribute__((constructor)) register_setting (void) \
{ g_type_init (); g_type_ensure (x); }
NMSetting *nm_setting_find_in_list (GSList *settings_list, const char *setting_name);
/* Private NMSettingIP4Config methods */
#include "nm-setting-ip4-config.h"
const char *nm_setting_ip4_config_get_address_label (NMSettingIP4Config *setting, guint32 i);
gboolean nm_setting_ip4_config_add_address_with_label (NMSettingIP4Config *setting, NMIP4Address *address, const char *label);
NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
gboolean allow_missing,
const char *setting_name,
const char *setting_property,
GQuark error_quark,
gint e_invalid_property,
gint e_missing_property,
GSList *all_settings,
GError **error);
NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
GSList *all_settings,
GError **error);
#endif /* NM_SETTING_PRIVATE_H */

View File

@@ -0,0 +1,320 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include "nm-setting-serial.h"
#include "nm-glib-compat.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-serial
* @short_description: Describes connection properties for devices that use
* serial communications
* @include: nm-setting-serial.h
*
* The #NMSettingSerial object is a #NMSetting subclass that describes
* properties necessary for connections that may use serial communications,
* such as mobile broadband or analog telephone connections.
**/
/**
* nm_setting_serial_error_quark:
*
* Registers an error quark for #NMSettingSerial if necessary.
*
* Returns: the error quark used for #NMSettingSerial errors.
**/
GQuark
nm_setting_serial_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-serial-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingSerial, nm_setting_serial, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_SERIAL_SETTING_NAME,
g_define_type_id,
2,
NM_SETTING_SERIAL_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_SERIAL)
#define NM_SETTING_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_SERIAL, NMSettingSerialPrivate))
typedef struct {
guint baud;
guint bits;
char parity;
guint stopbits;
guint64 send_delay;
} NMSettingSerialPrivate;
enum {
PROP_0,
PROP_BAUD,
PROP_BITS,
PROP_PARITY,
PROP_STOPBITS,
PROP_SEND_DELAY,
LAST_PROP
};
/**
* nm_setting_serial_new:
*
* Creates a new #NMSettingSerial object with default values.
*
* Returns: (transfer full): the new empty #NMSettingSerial object
**/
NMSetting *
nm_setting_serial_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_SERIAL, NULL);
}
/**
* nm_setting_serial_get_baud:
* @setting: the #NMSettingSerial
*
* Returns: the #NMSettingSerial:baud property of the setting
**/
guint
nm_setting_serial_get_baud (NMSettingSerial *setting)
{
g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
return NM_SETTING_SERIAL_GET_PRIVATE (setting)->baud;
}
/**
* nm_setting_serial_get_bits:
* @setting: the #NMSettingSerial
*
* Returns: the #NMSettingSerial:bits property of the setting
**/
guint
nm_setting_serial_get_bits (NMSettingSerial *setting)
{
g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
return NM_SETTING_SERIAL_GET_PRIVATE (setting)->bits;
}
/**
* nm_setting_serial_get_parity:
* @setting: the #NMSettingSerial
*
* Returns: the #NMSettingSerial:parity property of the setting
**/
char
nm_setting_serial_get_parity (NMSettingSerial *setting)
{
g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
return NM_SETTING_SERIAL_GET_PRIVATE (setting)->parity;
}
/**
* nm_setting_serial_get_stopbits:
* @setting: the #NMSettingSerial
*
* Returns: the #NMSettingSerial:stopbits property of the setting
**/
guint
nm_setting_serial_get_stopbits (NMSettingSerial *setting)
{
g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
return NM_SETTING_SERIAL_GET_PRIVATE (setting)->stopbits;
}
/**
* nm_setting_serial_get_send_delay:
* @setting: the #NMSettingSerial
*
* Returns: the #NMSettingSerial:send-delay property of the setting
**/
guint64
nm_setting_serial_get_send_delay (NMSettingSerial *setting)
{
g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), 0);
return NM_SETTING_SERIAL_GET_PRIVATE (setting)->send_delay;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
return TRUE;
}
static void
nm_setting_serial_init (NMSettingSerial *setting)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingSerialPrivate *priv = NM_SETTING_SERIAL_GET_PRIVATE (object);
switch (prop_id) {
case PROP_BAUD:
priv->baud = g_value_get_uint (value);
break;
case PROP_BITS:
priv->bits = g_value_get_uint (value);
break;
case PROP_PARITY:
priv->parity = g_value_get_schar (value);
break;
case PROP_STOPBITS:
priv->stopbits = g_value_get_uint (value);
break;
case PROP_SEND_DELAY:
priv->send_delay = g_value_get_uint64 (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingSerial *setting = NM_SETTING_SERIAL (object);
switch (prop_id) {
case PROP_BAUD:
g_value_set_uint (value, nm_setting_serial_get_baud (setting));
break;
case PROP_BITS:
g_value_set_uint (value, nm_setting_serial_get_bits (setting));
break;
case PROP_PARITY:
g_value_set_schar (value, nm_setting_serial_get_parity (setting));
break;
case PROP_STOPBITS:
g_value_set_uint (value, nm_setting_serial_get_stopbits (setting));
break;
case PROP_SEND_DELAY:
g_value_set_uint64 (value, nm_setting_serial_get_send_delay (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_serial_class_init (NMSettingSerialClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingSerialPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingSerial:baud:
*
* Speed to use for communication over the serial port. Note that this
* value usually has no effect for mobile broadband modems as they generally
* ignore speed settings and use the highest available speed.
**/
g_object_class_install_property
(object_class, PROP_BAUD,
g_param_spec_uint (NM_SETTING_SERIAL_BAUD, "", "",
0, G_MAXUINT, 57600,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingSerial:bits:
*
* Byte-width of the serial communication. The 8 in "8n1" for example.
**/
g_object_class_install_property
(object_class, PROP_BITS,
g_param_spec_uint (NM_SETTING_SERIAL_BITS, "", "",
5, 8, 8,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingSerial:parity:
*
* Parity setting of the serial port. Either 'E' for even parity, 'o' for
* odd parity, or 'n' for no parity.
**/
g_object_class_install_property
(object_class, PROP_PARITY,
g_param_spec_char (NM_SETTING_SERIAL_PARITY, "", "",
'E', 'o', 'n',
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingSerial:stopbits:
*
* Number of stop bits for communication on the serial port. Either 1 or 2.
* The 1 in "8n1" for example.
**/
g_object_class_install_property
(object_class, PROP_STOPBITS,
g_param_spec_uint (NM_SETTING_SERIAL_STOPBITS, "", "",
1, 2, 1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingSerial:send-delay:
*
* Time to delay between each byte sent to the modem, in microseconds.
**/
g_object_class_install_property
(object_class, PROP_SEND_DELAY,
g_param_spec_uint64 (NM_SETTING_SERIAL_SEND_DELAY, "", "",
0, G_MAXUINT64, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,89 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_SERIAL_H
#define NM_SETTING_SERIAL_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_SERIAL (nm_setting_serial_get_type ())
#define NM_SETTING_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_SERIAL, NMSettingSerial))
#define NM_SETTING_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_SERIAL, NMSettingSerialClass))
#define NM_IS_SETTING_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_SERIAL))
#define NM_IS_SETTING_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_SERIAL))
#define NM_SETTING_SERIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_SERIAL, NMSettingSerialClass))
#define NM_SETTING_SERIAL_SETTING_NAME "serial"
/**
* NMSettingSerialError:
* @NM_SETTING_SERIAL_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_SERIAL_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_SERIAL_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_SERIAL_ERROR_MISSING_PPP_SETTING: one of the properties of the
* setting requires the connection to contain an #NMSettingPPP setting
*/
typedef enum {
NM_SETTING_SERIAL_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_SERIAL_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_SERIAL_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_SERIAL_ERROR_MISSING_PPP_SETTING /*< nick=MissingPPPSetting >*/
} NMSettingSerialError;
#define NM_SETTING_SERIAL_ERROR nm_setting_serial_error_quark ()
GQuark nm_setting_serial_error_quark (void);
#define NM_SETTING_SERIAL_BAUD "baud"
#define NM_SETTING_SERIAL_BITS "bits"
#define NM_SETTING_SERIAL_PARITY "parity"
#define NM_SETTING_SERIAL_STOPBITS "stopbits"
#define NM_SETTING_SERIAL_SEND_DELAY "send-delay"
typedef struct {
NMSetting parent;
} NMSettingSerial;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingSerialClass;
GType nm_setting_serial_get_type (void);
NMSetting *nm_setting_serial_new (void);
guint nm_setting_serial_get_baud (NMSettingSerial *setting);
guint nm_setting_serial_get_bits (NMSettingSerial *setting);
char nm_setting_serial_get_parity (NMSettingSerial *setting);
guint nm_setting_serial_get_stopbits (NMSettingSerial *setting);
guint64 nm_setting_serial_get_send_delay (NMSettingSerial *setting);
G_END_DECLS
#endif /* NM_SETTING_SERIAL_H */

View File

@@ -0,0 +1,184 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Jiri Pirko <jiri@resnulli.us>
*/
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-team-port.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-team-port
* @short_description: Describes connection properties for team ports
* @include: nm-setting-team-port.h
*
* The #NMSettingTeamPort object is a #NMSetting subclass that describes
* optional properties that apply to team ports.
*
* Since: 0.9.10
**/
/**
* nm_setting_team_port_error_quark:
*
* Registers an error quark for #NMSettingTeamPort if necessary.
*
* Returns: the error quark used for #NMSettingTeamPort errors.
*
* Since: 0.9.10
**/
GQuark
nm_setting_team_port_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-team-port-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingTeamPort, nm_setting_team_port, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_TEAM_PORT_SETTING_NAME,
g_define_type_id,
3,
NM_SETTING_TEAM_PORT_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM_PORT)
#define NM_SETTING_TEAM_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortPrivate))
typedef struct {
char *config;
} NMSettingTeamPortPrivate;
enum {
PROP_0,
PROP_CONFIG,
LAST_PROP
};
/**
* nm_setting_team_port_new:
*
* Creates a new #NMSettingTeamPort object with default values.
*
* Returns: (transfer full): the new empty #NMSettingTeamPort object
*
* Since: 0.9.10
**/
NMSetting *
nm_setting_team_port_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM_PORT, NULL);
}
/**
* nm_setting_team_port_get_config:
* @setting: the #NMSettingTeamPort
*
* Returns: the #NMSettingTeamPort:config property of the setting
*
* Since: 0.9.10
**/
const char *
nm_setting_team_port_get_config (NMSettingTeamPort *setting)
{
g_return_val_if_fail (NM_IS_SETTING_TEAM_PORT (setting), NULL);
return NM_SETTING_TEAM_PORT_GET_PRIVATE (setting)->config;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
return TRUE;
}
static void
nm_setting_team_port_init (NMSettingTeamPort *setting)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
switch (prop_id) {
case PROP_CONFIG:
priv->config = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingTeamPort *setting = NM_SETTING_TEAM_PORT (object);
switch (prop_id) {
case PROP_CONFIG:
g_value_set_string (value, nm_setting_team_port_get_config (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingTeamPortPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingTeamPort:config:
*
* The JSON configuration for the team port. The property should contain raw
* JSON configuration data suitable for teamd, because the value is passed
* directly to teamd. If not specified, the default configuration is
* used. See man teamd.conf for the format details.
**/
g_object_class_install_property
(object_class, PROP_CONFIG,
g_param_spec_string (NM_SETTING_TEAM_PORT_CONFIG, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Jiri Pirko <jiri@resnulli.us>
*/
#ifndef NM_SETTING_TEAM_PORT_H
#define NM_SETTING_TEAM_PORT_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_TEAM_PORT (nm_setting_team_port_get_type ())
#define NM_SETTING_TEAM_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPort))
#define NM_SETTING_TEAM_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortClass))
#define NM_IS_SETTING_TEAM_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_TEAM_PORT))
#define NM_IS_SETTING_TEAM_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_TEAM_PORT))
#define NM_SETTING_TEAM_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_TEAM_PORT, NMSettingTeamPortClass))
#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port"
/**
* NMSettingTeamPortError:
* @NM_SETTING_TEAM_PORT_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_TEAM_PORT_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_TEAM_PORT_ERROR_MISSING_PROPERTY: the property was missing and
* is required
*/
typedef enum {
NM_SETTING_TEAM_PORT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_TEAM_PORT_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_TEAM_PORT_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
} NMSettingTeamPortError;
#define NM_SETTING_TEAM_PORT_ERROR nm_setting_team_port_error_quark ()
GQuark nm_setting_team_port_error_quark (void);
#define NM_SETTING_TEAM_PORT_CONFIG "config"
typedef struct {
NMSetting parent;
} NMSettingTeamPort;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingTeamPortClass;
NM_AVAILABLE_IN_0_9_10
GType nm_setting_team_port_get_type (void);
NM_AVAILABLE_IN_0_9_10
NMSetting * nm_setting_team_port_new (void);
const char * nm_setting_team_port_get_config (NMSettingTeamPort *setting);
G_END_DECLS
#endif /* NM_SETTING_TEAM_PORT_H */

View File

@@ -0,0 +1,254 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Jiri Pirko <jiri@resnulli.us>
*/
#include <string.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-team.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-team
* @short_description: Describes connection properties for teams
* @include: nm-setting-team.h
*
* The #NMSettingTeam object is a #NMSetting subclass that describes properties
* necessary for team connections.
*
* Since: 0.9.10
**/
/**
* nm_setting_team_error_quark:
*
* Registers an error quark for #NMSettingTeam if necessary.
*
* Returns: the error quark used for #NMSettingTeam errors.
*
* Since: 0.9.10
**/
GQuark
nm_setting_team_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-team-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingTeam, nm_setting_team, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_TEAM_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_TEAM_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM)
#define NM_SETTING_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM, NMSettingTeamPrivate))
typedef struct {
char *interface_name;
char *config;
} NMSettingTeamPrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_CONFIG,
LAST_PROP
};
/**
* nm_setting_team_new:
*
* Creates a new #NMSettingTeam object with default values.
*
* Returns: (transfer full): the new empty #NMSettingTeam object
*
* Since: 0.9.10
**/
NMSetting *
nm_setting_team_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM, NULL);
}
/**
* nm_setting_team_get_interface_name:
* @setting: the #NMSettingTeam
*
* Returns: the #NMSettingTeam:interface-name property of the setting
*
* Since: 0.9.10
**/
const char *
nm_setting_team_get_interface_name (NMSettingTeam *setting)
{
g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
return NM_SETTING_TEAM_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_team_get_config:
* @setting: the #NMSettingTeam
*
* Returns: the #NMSettingTeam:config property of the setting
*
* Since: 0.9.10
**/
const char *
nm_setting_team_get_config (NMSettingTeam *setting)
{
g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
return NM_SETTING_TEAM_GET_PRIVATE (setting)->config;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_INTERFACE_NAME,
NM_SETTING_TEAM_ERROR,
NM_SETTING_TEAM_ERROR_INVALID_PROPERTY,
NM_SETTING_TEAM_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
NMSettingTeam *self = NM_SETTING_TEAM (setting);
return nm_setting_team_get_interface_name (self);
}
static void
nm_setting_team_init (NMSettingTeam *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
g_free (priv->interface_name);
g_free (priv->config);
G_OBJECT_CLASS (nm_setting_team_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_CONFIG:
g_free (priv->config);
priv->config = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingTeam *setting = NM_SETTING_TEAM (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_team_get_interface_name (setting));
break;
case PROP_CONFIG:
g_value_set_string (value, nm_setting_team_get_config (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_team_class_init (NMSettingTeamClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingTeamPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
* NMSettingTeam:interface-name:
*
* The name of the virtual in-kernel team network interface
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_TEAM_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingTeam:config:
*
* The JSON configuration for the team network interface. The property
* should contain raw JSON configuration data suitable for teamd, because
* the value is passed directly to teamd. If not specified, the default
* configuration is used. See man teamd.conf for the format details.
**/
g_object_class_install_property
(object_class, PROP_CONFIG,
g_param_spec_string (NM_SETTING_TEAM_CONFIG, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,81 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Jiri Pirko <jiri@resnulli.us>
*/
#ifndef NM_SETTING_TEAM_H
#define NM_SETTING_TEAM_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_TEAM (nm_setting_team_get_type ())
#define NM_SETTING_TEAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_TEAM, NMSettingTeam))
#define NM_SETTING_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_TEAM, NMSettingTeamClass))
#define NM_IS_SETTING_TEAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_TEAM))
#define NM_IS_SETTING_TEAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_TEAM))
#define NM_SETTING_TEAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_TEAM, NMSettingTeamClass))
#define NM_SETTING_TEAM_SETTING_NAME "team"
/**
* NMSettingTeamError:
* @NM_SETTING_TEAM_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_TEAM_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_TEAM_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_TEAM_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_TEAM_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_TEAM_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
} NMSettingTeamError;
#define NM_SETTING_TEAM_ERROR nm_setting_team_error_quark ()
GQuark nm_setting_team_error_quark (void);
#define NM_SETTING_TEAM_INTERFACE_NAME "interface-name"
#define NM_SETTING_TEAM_CONFIG "config"
typedef struct {
NMSetting parent;
} NMSettingTeam;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingTeamClass;
NM_AVAILABLE_IN_0_9_10
GType nm_setting_team_get_type (void);
NM_AVAILABLE_IN_0_9_10
NMSetting * nm_setting_team_new (void);
const char * nm_setting_team_get_interface_name (NMSettingTeam *setting);
const char * nm_setting_team_get_config (NMSettingTeam *setting);
G_END_DECLS
#endif /* NM_SETTING_TEAM_H */

View File

@@ -0,0 +1,841 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2014 Red Hat, Inc.
*/
#include <stdlib.h>
#include <string.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-vlan.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-connection.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-vlan
* @short_description: Describes connection properties for VLAN interfaces
* @include: nm-setting-vlan.h
*
* The #NMSettingVlan object is a #NMSetting subclass that describes properties
* necessary for connection to VLAN interfaces.
**/
/**
* nm_setting_vlan_error_quark:
*
* Registers an error quark for #NMSettingVlan if necessary.
*
* Returns: the error quark used for #NMSettingVlan errors.
**/
GQuark
nm_setting_vlan_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-vlan-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingVlan, nm_setting_vlan, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_VLAN_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_VLAN_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VLAN)
#define NM_SETTING_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VLAN, NMSettingVlanPrivate))
typedef struct {
char *interface_name;
char *parent;
guint32 id;
guint32 flags;
GSList *ingress_priority_map;
GSList *egress_priority_map;
} NMSettingVlanPrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_PARENT,
PROP_ID,
PROP_FLAGS,
PROP_INGRESS_PRIORITY_MAP,
PROP_EGRESS_PRIORITY_MAP,
LAST_PROP
};
#define MAX_SKB_PRIO G_MAXUINT32
#define MAX_8021P_PRIO 7 /* Max 802.1p priority */
typedef struct {
guint32 from;
guint32 to;
} PriorityMap;
/**
* nm_setting_vlan_new:
*
* Creates a new #NMSettingVlan object with default values.
*
* Returns: (transfer full): the new empty #NMSettingVlan object
**/
NMSetting *
nm_setting_vlan_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_VLAN, NULL);
}
/**
* nm_setting_vlan_get_interface_name:
* @setting: the #NMSettingVlan
*
* Returns: the #NMSettingVlan:interface_name property of the setting
**/
const char *
nm_setting_vlan_get_interface_name (NMSettingVlan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), NULL);
return NM_SETTING_VLAN_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_vlan_get_parent:
* @setting: the #NMSettingVlan
*
* Returns: the #NMSettingVlan:parent property of the setting
**/
const char *
nm_setting_vlan_get_parent (NMSettingVlan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), NULL);
return NM_SETTING_VLAN_GET_PRIVATE (setting)->parent;
}
/**
* nm_setting_vlan_get_id:
* @setting: the #NMSettingVlan
*
* Returns: the #NMSettingVlan:id property of the setting
**/
guint32
nm_setting_vlan_get_id (NMSettingVlan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), 0);
return NM_SETTING_VLAN_GET_PRIVATE (setting)->id;
}
/**
* nm_setting_vlan_get_flags:
* @setting: the #NMSettingVlan
*
* Returns: the #NMSettingVlan:flags property of the setting
**/
guint32
nm_setting_vlan_get_flags (NMSettingVlan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), 0);
return NM_SETTING_VLAN_GET_PRIVATE (setting)->flags;
}
static guint32
get_max_prio (NMVlanPriorityMap map, gboolean from)
{
if (map == NM_VLAN_INGRESS_MAP)
return from ? MAX_8021P_PRIO : MAX_SKB_PRIO;
else if (map == NM_VLAN_EGRESS_MAP)
return from ? MAX_SKB_PRIO : MAX_8021P_PRIO;
g_assert_not_reached ();
}
static PriorityMap *
priority_map_new_from_str (NMVlanPriorityMap map, const char *str)
{
PriorityMap *p = NULL;
gchar **t = NULL;
guint32 len;
guint64 from, to;
g_return_val_if_fail (str && str[0], NULL);
t = g_strsplit (str, ":", 0);
len = g_strv_length (t);
if (len == 2) {
from = g_ascii_strtoull (t[0], NULL, 10);
to = g_ascii_strtoull (t[1], NULL, 10);
if ((from <= get_max_prio (map, TRUE)) && (to <= get_max_prio (map, FALSE))) {
p = g_malloc0 (sizeof (PriorityMap));
p->from = from;
p->to = to;
}
} else {
/* Warn */
g_warn_if_fail (len == 2);
}
g_strfreev (t);
return p;
}
static void
priority_map_free (PriorityMap *map)
{
g_return_if_fail (map != NULL);
g_free (map);
}
static GSList *
get_map (NMSettingVlan *self, NMVlanPriorityMap map)
{
if (map == NM_VLAN_INGRESS_MAP)
return NM_SETTING_VLAN_GET_PRIVATE (self)->ingress_priority_map;
else if (map == NM_VLAN_EGRESS_MAP)
return NM_SETTING_VLAN_GET_PRIVATE (self)->egress_priority_map;
g_assert_not_reached ();
return NULL;
}
static void
set_map (NMSettingVlan *self, NMVlanPriorityMap map, GSList *list)
{
if (map == NM_VLAN_INGRESS_MAP) {
NM_SETTING_VLAN_GET_PRIVATE (self)->ingress_priority_map = list;
g_object_notify (G_OBJECT (self), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP);
} else if (map == NM_VLAN_EGRESS_MAP) {
NM_SETTING_VLAN_GET_PRIVATE (self)->egress_priority_map = list;
g_object_notify (G_OBJECT (self), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP);
} else
g_assert_not_reached ();
}
/**
* nm_setting_vlan_add_priority_str:
* @setting: the #NMSettingVlan
* @map: the type of priority map
* @str: the string which contains a priority map, like "3:7"
*
* Adds a priority map entry into either the #NMSettingVlan:ingress_priority_map
* or the #NMSettingVlan:egress_priority_map properties. The priority map maps
* the Linux SKB priorities to 802.1p priorities.
*
* Returns: %TRUE if the entry was successfully added to the list, or it
* overwrote the old value, %FALSE if error
*/
gboolean
nm_setting_vlan_add_priority_str (NMSettingVlan *setting,
NMVlanPriorityMap map,
const char *str)
{
GSList *list = NULL, *iter = NULL;
PriorityMap *item = NULL;
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE);
g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE);
g_return_val_if_fail (str && str[0], FALSE);
list = get_map (setting, map);
item = priority_map_new_from_str (map, str);
g_return_val_if_fail (item != NULL, FALSE);
/* Duplicates get replaced */
for (iter = list; iter; iter = g_slist_next (iter)) {
PriorityMap *p = iter->data;
if (p->from == item->from) {
p->to = item->to;
g_free (item);
if (map == NM_VLAN_INGRESS_MAP)
g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP);
else
g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP);
return TRUE;
}
}
set_map (setting, map, g_slist_append (list, item));
return TRUE;
}
/**
* nm_setting_vlan_get_num_priorities:
* @setting: the #NMSettingVlan
* @map: the type of priority map
*
* Returns the number of entires in the
* #NMSettingVlan:ingress_priority_map or #NMSettingVlan:egress_priority_map
* properties of this setting.
*
* Returns: return the number of ingress/egress priority entries, -1 if error
**/
gint32
nm_setting_vlan_get_num_priorities (NMSettingVlan *setting, NMVlanPriorityMap map)
{
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), -1);
g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, -1);
return g_slist_length (get_map (setting, map));
}
/**
* nm_setting_vlan_get_priority:
* @setting: the #NMSettingVlan
* @map: the type of priority map
* @idx: the zero-based index of the ingress/egress priority map entry
* @out_from: (out): on return the value of the priority map's 'from' item
* @out_to: (out): on return the value of priority map's 'to' item
*
* Retrieve one of the entries of the #NMSettingVlan:ingress_priority_map
* or #NMSettingVlan:egress_priority_map properties of this setting.
*
* Returns: %TRUE if a priority map was returned, %FALSE if error
**/
gboolean
nm_setting_vlan_get_priority (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 idx,
guint32 *out_from,
guint32 *out_to)
{
GSList *list = NULL;
PriorityMap *item = NULL;
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE);
g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE);
g_return_val_if_fail (out_from != NULL, FALSE);
g_return_val_if_fail (out_to != NULL, FALSE);
list = get_map (setting, map);
g_return_val_if_fail (idx < g_slist_length (list), FALSE);
item = g_slist_nth_data (list, idx);
g_assert (item);
*out_from = item->from;
*out_to = item->to;
return TRUE;
}
/**
* nm_setting_vlan_add_priority:
* @setting: the #NMSettingVlan
* @map: the type of priority map
* @from: the priority to map to @to
* @to: the priority to map @from to
*
* Adds a priority mapping to the #NMSettingVlan:ingress_priority_map or
* #NMSettingVlan:egress_priority_map properties of the setting. If @from is
* already in the given priority map, this function will overwrite the
* existing entry with the new @to.
*
* If @map is #NM_VLAN_INGRESS_MAP then @from is the incoming 802.1q VLAN
* Priority Code Point (PCP) value, and @to is the Linux SKB priority value.
*
* If @map is #NM_VLAN_EGRESS_MAP then @from is the Linux SKB priority value and
* @to is the outgoing 802.1q VLAN Priority Code Point (PCP) value.
*
* Returns: %TRUE if the new priority mapping was successfully added to the
* list, %FALSE if error
*/
gboolean
nm_setting_vlan_add_priority (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 from,
guint32 to)
{
GSList *list = NULL, *iter = NULL;
PriorityMap *item;
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE);
g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE);
list = get_map (setting, map);
for (iter = list; iter; iter = g_slist_next (iter)) {
item = iter->data;
if (item->from == from) {
item->to = to;
if (map == NM_VLAN_INGRESS_MAP)
g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_INGRESS_PRIORITY_MAP);
else
g_object_notify (G_OBJECT (setting), NM_SETTING_VLAN_EGRESS_PRIORITY_MAP);
return TRUE;
}
}
item = g_malloc0 (sizeof (PriorityMap));
item->from = from;
item->to = to;
set_map (setting, map, g_slist_append (list, item));
return TRUE;
}
/**
* nm_setting_vlan_remove_priority:
* @setting: the #NMSettingVlan
* @map: the type of priority map
* @idx: the zero-based index of the priority map to remove
*
* Removes the priority map at index @idx from the
* #NMSettingVlan:ingress_priority_map or #NMSettingVlan:egress_priority_map
* properties.
*/
void
nm_setting_vlan_remove_priority (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 idx)
{
GSList *list = NULL, *item = NULL;
g_return_if_fail (NM_IS_SETTING_VLAN (setting));
g_return_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP);
list = get_map (setting, map);
g_return_if_fail (idx < g_slist_length (list));
item = g_slist_nth (list, idx);
priority_map_free ((PriorityMap *) (item->data));
set_map (setting, map, g_slist_delete_link (list, item));
}
/**
* nm_setting_vlan_remove_priority_by_value:
* @setting: the #NMSettingVlan
* @map: the type of priority map
* @from: the priority to map to @to
* @to: the priority to map @from to
*
* Removes the priority map @form:@to from the #NMSettingVlan:ingress_priority_map
* or #NMSettingVlan:egress_priority_map (according to @map argument)
* properties.
*
* Returns: %TRUE if the priority mapping was found and removed; %FALSE if it was not.
*
* Since: 0.9.10
*/
gboolean
nm_setting_vlan_remove_priority_by_value (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 from,
guint32 to)
{
GSList *list = NULL, *iter = NULL;
PriorityMap *item;
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE);
g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE);
list = get_map (setting, map);
for (iter = list; iter; iter = g_slist_next (iter)) {
item = iter->data;
if (item->from == from && item->to == to) {
priority_map_free ((PriorityMap *) (iter->data));
set_map (setting, map, g_slist_delete_link (list, iter));
return TRUE;
}
}
return FALSE;
}
/**
* nm_setting_vlan_remove_priority_str_by_value:
* @setting: the #NMSettingVlan
* @map: the type of priority map
* @str: the string which contains a priority map, like "3:7"
*
* Removes the priority map @str from the #NMSettingVlan:ingress_priority_map
* or #NMSettingVlan:egress_priority_map (according to @map argument)
* properties.
*
* Returns: %TRUE if the priority mapping was found and removed; %FALSE if it was not.
*
* Since: 0.9.10
*/
gboolean
nm_setting_vlan_remove_priority_str_by_value (NMSettingVlan *setting,
NMVlanPriorityMap map,
const char *str)
{
PriorityMap *item;
gboolean found;
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), FALSE);
g_return_val_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP, FALSE);
item = priority_map_new_from_str (map, str);
if (!item)
return FALSE;
found = nm_setting_vlan_remove_priority_by_value (setting, map, item->from, item->to);
g_free (item);
return found;
}
/**
* nm_setting_vlan_clear_priorities:
* @setting: the #NMSettingVlan
* @map: the type of priority map
*
* Clear all the entires from #NMSettingVlan:ingress_priority_map or
* #NMSettingVlan:egress_priority_map properties.
*/
void
nm_setting_vlan_clear_priorities (NMSettingVlan *setting, NMVlanPriorityMap map)
{
GSList *list = NULL;
g_return_if_fail (NM_IS_SETTING_VLAN (setting));
g_return_if_fail (map == NM_VLAN_INGRESS_MAP || map == NM_VLAN_EGRESS_MAP);
list = get_map (setting, map);
g_slist_free_full (list, g_free);
set_map (setting, map, NULL);
}
/*********************************************************************/
static void
nm_setting_vlan_init (NMSettingVlan *setting)
{
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
NMSettingConnection *s_con = NULL;
NMSettingWired *s_wired = NULL;
GSList *iter;
for (iter = all_settings; iter; iter = iter->next) {
if (NM_IS_SETTING_CONNECTION (iter->data))
s_con = iter->data;
else if (NM_IS_SETTING_WIRED (iter->data))
s_wired = iter->data;
}
if (priv->parent) {
if (nm_utils_is_uuid (priv->parent)) {
/* If we have an NMSettingConnection:master with slave-type="vlan",
* then it must be the same UUID.
*/
if (s_con) {
const char *master = NULL, *slave_type = NULL;
slave_type = nm_setting_connection_get_slave_type (s_con);
if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME))
master = nm_setting_connection_get_master (s_con);
if (master && g_strcmp0 (priv->parent, master) != 0) {
g_set_error (error,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PARENT,
_("'%s' value doesn't match '%s=%s'"),
priv->parent, NM_SETTING_CONNECTION_MASTER, master);
g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
return FALSE;
}
}
} else if (!nm_utils_iface_valid_name (priv->parent)) {
/* parent must be either a UUID or an interface name */
g_set_error (error,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
_("'%s' is neither an UUID nor an interface name"),
priv->parent);
g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
return FALSE;
}
} else {
/* If parent is NULL, the parent must be specified via
* NMSettingWired:mac-address.
*/
if (!s_wired || !nm_setting_wired_get_mac_address (s_wired)) {
g_set_error (error,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_MISSING_PROPERTY,
_("property is not specified and neither is '%s:%s'"),
NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_MAC_ADDRESS);
g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_PARENT);
return FALSE;
}
}
if (priv->flags & ~(NM_VLAN_FLAG_REORDER_HEADERS |
NM_VLAN_FLAG_GVRP |
NM_VLAN_FLAG_LOOSE_BINDING)) {
g_set_error_literal (error,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
_("flags are invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_FLAGS);
return FALSE;
}
/* If interface_name is specified, it must be a valid interface name. We
* don't check that it matches parent and/or id, because we allow
* renaming vlans to arbitrary names.
*/
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, TRUE,
NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_INTERFACE_NAME,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
NM_SETTING_VLAN_ERROR_MISSING_PROPERTY,
all_settings, error);
}
static const char *
get_virtual_iface_name (NMSetting *setting)
{
return nm_setting_vlan_get_interface_name (NM_SETTING_VLAN (setting));
}
static GSList *
priority_stringlist_to_maplist (NMVlanPriorityMap map, GSList *strlist)
{
GSList *list = NULL, *iter;
for (iter = strlist; iter; iter = g_slist_next (iter)) {
PriorityMap *item;
item = priority_map_new_from_str (map, (const char *) iter->data);
if (item)
list = g_slist_prepend (list, item);
}
return g_slist_reverse (list);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingVlan *setting = NM_SETTING_VLAN (object);
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_PARENT:
g_free (priv->parent);
priv->parent = g_value_dup_string (value);
break;
case PROP_ID:
priv->id = g_value_get_uint (value);
break;
case PROP_FLAGS:
priv->flags = g_value_get_uint (value);
break;
case PROP_INGRESS_PRIORITY_MAP:
g_slist_free_full (priv->ingress_priority_map, g_free);
priv->ingress_priority_map =
priority_stringlist_to_maplist (NM_VLAN_INGRESS_MAP, g_value_get_boxed (value));
break;
case PROP_EGRESS_PRIORITY_MAP:
g_slist_free_full (priv->egress_priority_map, g_free);
priv->egress_priority_map =
priority_stringlist_to_maplist (NM_VLAN_EGRESS_MAP, g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GSList *
priority_maplist_to_stringlist (GSList *list)
{
GSList *strlist = NULL, *iter;
for (iter = list; iter; iter = g_slist_next (iter)) {
PriorityMap *item = iter->data;
strlist = g_slist_prepend (strlist, g_strdup_printf ("%d:%d", item->from, item->to));
}
return g_slist_reverse (strlist);
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingVlan *setting = NM_SETTING_VLAN (object);
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, priv->interface_name);
break;
case PROP_PARENT:
g_value_set_string (value, priv->parent);
break;
case PROP_ID:
g_value_set_uint (value, priv->id);
break;
case PROP_FLAGS:
g_value_set_uint (value, priv->flags);
break;
case PROP_INGRESS_PRIORITY_MAP:
g_value_take_boxed (value, priority_maplist_to_stringlist (priv->ingress_priority_map));
break;
case PROP_EGRESS_PRIORITY_MAP:
g_value_take_boxed (value, priority_maplist_to_stringlist (priv->egress_priority_map));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
finalize (GObject *object)
{
NMSettingVlan *setting = NM_SETTING_VLAN (object);
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
g_free (priv->interface_name);
g_free (priv->parent);
g_slist_free_full (priv->ingress_priority_map, g_free);
g_slist_free_full (priv->egress_priority_map, g_free);
G_OBJECT_CLASS (nm_setting_vlan_parent_class)->finalize (object);
}
static void
nm_setting_vlan_class_init (NMSettingVlanClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingVlanPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->get_virtual_iface_name = get_virtual_iface_name;
/* Properties */
/**
* NMSettingVlan:interface-name:
*
* If given, specifies the kernel name of the VLAN interface. If not given,
* a default name will be constructed from the interface described by the
* parent interface and the #NMSettingVlan:id property, eg "eth2.1". The
* parent interface may be given by the #NMSettingVlan:parent property or by
* the #NMSettingWired:mac-address property of an #NMSettingWired setting.
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_VLAN_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVlan:parent:
*
* If given, specifies the parent interface name or parent connection UUID
* from which this VLAN interface should be created. If this property is
* not specified, the connection must contain an #NMSettingWired setting
* with a #NMSettingWired:mac-address property.
**/
g_object_class_install_property
(object_class, PROP_PARENT,
g_param_spec_string (NM_SETTING_VLAN_PARENT, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVlan:id:
*
* The VLAN identifier that the interface created by this connection should
* be assigned.
**/
g_object_class_install_property
(object_class, PROP_ID,
g_param_spec_uint (NM_SETTING_VLAN_ID, "", "",
0, 4095, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVlan:flags:
*
* One or more flags which control the behavior and features of the VLAN
* interface. Flags include %NM_VLAN_FLAG_REORDER_HEADERS (reordering of
* output packet headers), %NM_VLAN_FLAG_GVRP (use of the GVRP protocol),
* and %NM_VLAN_FLAG_LOOSE_BINDING (loose binding of the interface to its
* master device's operating state).
**/
g_object_class_install_property
(object_class, PROP_FLAGS,
g_param_spec_uint (NM_SETTING_VLAN_FLAGS, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVlan:ingress-priority-map:
*
* For incoming packets, a list of mappings from 802.1p priorities to Linux
* SKB priorities. The mapping is given in the format "from:to" where both
* "from" and "to" are unsigned integers, ie "7:3".
**/
g_object_class_install_property
(object_class, PROP_INGRESS_PRIORITY_MAP,
_nm_param_spec_specialized (NM_SETTING_VLAN_INGRESS_PRIORITY_MAP, "", "",
DBUS_TYPE_G_LIST_OF_STRING,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVlan:egress-priority-map:
*
* For outgoing packets, a list of mappings from Linux SKB priorities to
* 802.1p priorities. The mapping is given in the format "from:to" where
* both "from" and "to" are unsigned integers, ie "7:3".
**/
g_object_class_install_property
(object_class, PROP_EGRESS_PRIORITY_MAP,
_nm_param_spec_specialized (NM_SETTING_VLAN_EGRESS_PRIORITY_MAP, "", "",
DBUS_TYPE_G_LIST_OF_STRING,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,156 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2014 Red Hat, Inc.
*/
#ifndef NM_SETTING_VLAN_H
#define NM_SETTING_VLAN_H
#include "nm-setting.h"
#include <linux/if_vlan.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_VLAN (nm_setting_vlan_get_type ())
#define NM_SETTING_VLAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_VLAN, NMSettingVlan))
#define NM_SETTING_VLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_VLANCONFIG, NMSettingVlanClass))
#define NM_IS_SETTING_VLAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_VLAN))
#define NM_IS_SETTING_VLAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_VLAN))
#define NM_SETTING_VLAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_VLAN, NMSettingVlanClass))
#define NM_SETTING_VLAN_SETTING_NAME "vlan"
/**
* NMSettingVlanError:
* @NM_SETTING_VLAN_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_VLAN_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_VLAN_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_VLAN_ERROR_INVALID_PARENT: the VLAN parent was specified
* inconsistently
*/
typedef enum {
NM_SETTING_VLAN_ERROR_UNKNOWN = 0, /*< nick=Unknown >*/
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_VLAN_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_VLAN_ERROR_INVALID_PARENT /*< nick=InvalidParent >*/
} NMSettingVlanError;
#define NM_SETTING_VLAN_ERROR nm_setting_vlan_error_quark ()
GQuark nm_setting_vlan_error_quark (void);
#define NM_SETTING_VLAN_INTERFACE_NAME "interface-name"
#define NM_SETTING_VLAN_PARENT "parent"
#define NM_SETTING_VLAN_ID "id"
#define NM_SETTING_VLAN_FLAGS "flags"
#define NM_SETTING_VLAN_INGRESS_PRIORITY_MAP "ingress-priority-map"
#define NM_SETTING_VLAN_EGRESS_PRIORITY_MAP "egress-priority-map"
typedef struct {
NMSetting parent;
} NMSettingVlan;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingVlanClass;
/**
* NMVlanPriorityMap:
* @NM_VLAN_INGRESS_MAP: map for incoming data
* @NM_VLAN_EGRESS_MAP: map for outgoing data
*
* A selector for traffic priority maps; these map Linux SKB priorities
* to 802.1p priorities used in VLANs.
**/
typedef enum {
NM_VLAN_INGRESS_MAP,
NM_VLAN_EGRESS_MAP
} NMVlanPriorityMap;
/**
* NMVlanFlags:
* @NM_VLAN_FLAG_REORDER_HEADERS: indicates that this interface should reorder
* outgoing packet headers to look more like a non-VLAN Ethernet interface
* @NM_VLAN_FLAG_GVRP: indicates that this interface should use GVRP to register
* itself with it's switch
* @NM_VLAN_FLAG_LOOSE_BINDING: indicates that this interface's operating
* state is tied to the underlying network interface but other details
* (like routing) are not.
*
* #NMVlanFlags values control the behavior of the VLAN interface.
**/
typedef enum {
NM_VLAN_FLAG_REORDER_HEADERS = 0x1,
NM_VLAN_FLAG_GVRP = 0x2,
NM_VLAN_FLAG_LOOSE_BINDING = 0x4,
/* NOTE: if adding flags update nm-setting-vlan.c::verify() */
} NMVlanFlags;
GType nm_setting_vlan_get_type (void);
NMSetting *nm_setting_vlan_new (void);
const char *nm_setting_vlan_get_interface_name (NMSettingVlan *setting);
const char *nm_setting_vlan_get_parent (NMSettingVlan *setting);
guint32 nm_setting_vlan_get_id (NMSettingVlan *setting);
guint32 nm_setting_vlan_get_flags (NMSettingVlan *setting);
gint32 nm_setting_vlan_get_num_priorities (NMSettingVlan *setting, NMVlanPriorityMap map);
gboolean nm_setting_vlan_get_priority (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 idx,
guint32 *out_from,
guint32 *out_to);
gboolean nm_setting_vlan_add_priority (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 from,
guint32 to);
void nm_setting_vlan_remove_priority (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_vlan_remove_priority_by_value (NMSettingVlan *setting,
NMVlanPriorityMap map,
guint32 from,
guint32 to);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_vlan_remove_priority_str_by_value (NMSettingVlan *setting,
NMVlanPriorityMap map,
const char *str);
void nm_setting_vlan_clear_priorities (NMSettingVlan *setting, NMVlanPriorityMap map);
gboolean nm_setting_vlan_add_priority_str (NMSettingVlan *setting,
NMVlanPriorityMap map,
const char *str);
G_END_DECLS
#endif /* NM_SETTING_VLAN_H */

870
libnm-core/nm-setting-vpn.c Normal file
View File

@@ -0,0 +1,870 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-vpn.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
#include "nm-dbus-glib-types.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-vpn
* @short_description: Describes connection properties for Virtual Private Networks
* @include: nm-setting-vpn.h
*
* The #NMSettingVPN object is a #NMSetting subclass that describes properties
* necessary for connection to Virtual Private Networks. NetworkManager uses
* a plugin architecture to allow easier use of new VPN types, and this
* setting abstracts the configuration for those plugins. Since the configuration
* options are only known to the VPN plugins themselves, the VPN configuration
* options are stored as key/value pairs of strings rather than GObject
* properties.
**/
/**
* nm_setting_vpn_error_quark:
*
* Registers an error quark for #NMSettingVPN if necessary.
*
* Returns: the error quark used for #NMSettingVPN errors.
**/
GQuark
nm_setting_vpn_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-vpn-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingVPN, nm_setting_vpn, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_VPN_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_VPN_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VPN)
#define NM_SETTING_VPN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VPN, NMSettingVPNPrivate))
typedef struct {
char *service_type;
/* username of the user requesting this connection, thus
* it's really only valid for user connections, and it also
* should never be saved out to persistent config.
*/
char *user_name;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should not contain secrets.
*/
GHashTable *data;
/* The hash table is created at setting object
* init time and should not be replaced. It is
* a char * -> char * mapping, and both the key
* and value are owned by the hash table, and should
* be allocated with functions whose value can be
* freed with g_free(). Should contain secrets only.
*/
GHashTable *secrets;
} NMSettingVPNPrivate;
enum {
PROP_0,
PROP_SERVICE_TYPE,
PROP_USER_NAME,
PROP_DATA,
PROP_SECRETS,
LAST_PROP
};
/**
* nm_setting_vpn_new:
*
* Creates a new #NMSettingVPN object with default values.
*
* Returns: (transfer full): the new empty #NMSettingVPN object
**/
NMSetting *
nm_setting_vpn_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_VPN, NULL);
}
/**
* nm_setting_vpn_get_service_type:
* @setting: the #NMSettingVPN
*
* Returns the service name of the VPN, which identifies the specific VPN
* plugin that should be used to connect to this VPN.
*
* Returns: the VPN plugin's service name
**/
const char *
nm_setting_vpn_get_service_type (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return NM_SETTING_VPN_GET_PRIVATE (setting)->service_type;
}
/**
* nm_setting_vpn_get_user_name:
* @setting: the #NMSettingVPN
*
* Returns: the #NMSettingVPN:user-name property of the setting
**/
const char *
nm_setting_vpn_get_user_name (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return NM_SETTING_VPN_GET_PRIVATE (setting)->user_name;
}
/**
* nm_setting_vpn_get_num_data_items:
* @setting: the #NMSettingVPN
*
* Gets number of key/value pairs of VPN configuration data.
*
* Returns: the number of VPN plugin specific configuration data items
**/
guint32
nm_setting_vpn_get_num_data_items (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), 0);
return g_hash_table_size (NM_SETTING_VPN_GET_PRIVATE (setting)->data);
}
/**
* nm_setting_vpn_add_data_item:
* @setting: the #NMSettingVPN
* @key: a name that uniquely identifies the given value @item
* @item: the value to be referenced by @key
*
* Establishes a relationship between @key and @item internally in the
* setting which may be retrieved later. Should not be used to store passwords
* or other secrets, which is what nm_setting_vpn_add_secret() is for.
**/
void
nm_setting_vpn_add_data_item (NMSettingVPN *setting,
const char *key,
const char *item)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_return_if_fail (key != NULL);
g_return_if_fail (strlen (key) > 0);
g_return_if_fail (item != NULL);
g_return_if_fail (strlen (item) > 0);
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
g_strdup (key), g_strdup (item));
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_DATA);
}
/**
* nm_setting_vpn_get_data_item:
* @setting: the #NMSettingVPN
* @key: the name of the data item to retrieve
*
* Retrieves the data item of a key/value relationship previously established
* by nm_setting_vpn_add_data_item().
*
* Returns: the data item, if any
**/
const char *
nm_setting_vpn_get_data_item (NMSettingVPN *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
}
/**
* nm_setting_vpn_remove_data_item:
* @setting: the #NMSettingVPN
* @key: the name of the data item to remove
*
* Deletes a key/value relationship previously established by
* nm_setting_vpn_add_data_item().
*
* Returns: %TRUE if the data item was found and removed from the internal list,
* %FALSE if it was not.
**/
gboolean
nm_setting_vpn_remove_data_item (NMSettingVPN *setting, const char *key)
{
gboolean found;
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
found = g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->data, key);
if (found)
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_DATA);
return found;
}
static void
foreach_item_helper (GHashTable *hash,
NMVPNIterFunc func,
gpointer user_data)
{
GList *keys, *liter;
GSList *copied = NULL, *siter;
g_return_if_fail (hash != NULL);
/* Grab keys and copy them so that the callback func can modify
* the hash table items if it wants to.
*/
keys = g_hash_table_get_keys (hash);
for (liter = keys; liter; liter = g_list_next (liter))
copied = g_slist_prepend (copied, g_strdup (liter->data));
copied = g_slist_reverse (copied);
g_list_free (keys);
for (siter = copied; siter; siter = g_slist_next (siter)) {
gpointer value;
value = g_hash_table_lookup (hash, siter->data);
func (siter->data, value, user_data);
}
g_slist_free_full (copied, g_free);
}
/**
* nm_setting_vpn_foreach_data_item:
* @setting: a #NMSettingVPN
* @func: (scope call): an user provided function
* @user_data: data to be passed to @func
*
* Iterates all data items stored in this setting. It is safe to add, remove,
* and modify data items inside @func, though any additions or removals made
* during iteration will not be part of the iteration.
*/
void
nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
NMVPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->data, func, user_data);
}
/**
* nm_setting_vpn_get_num_secrets:
* @setting: the #NMSettingVPN
*
* Gets number of VPN plugin specific secrets in the setting.
*
* Returns: the number of VPN plugin specific secrets
**/
guint32
nm_setting_vpn_get_num_secrets (NMSettingVPN *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), 0);
return g_hash_table_size (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets);
}
/**
* nm_setting_vpn_add_secret:
* @setting: the #NMSettingVPN
* @key: a name that uniquely identifies the given secret @secret
* @secret: the secret to be referenced by @key
*
* Establishes a relationship between @key and @secret internally in the
* setting which may be retrieved later.
**/
void
nm_setting_vpn_add_secret (NMSettingVPN *setting,
const char *key,
const char *secret)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
g_return_if_fail (key != NULL);
g_return_if_fail (strlen (key) > 0);
g_return_if_fail (secret != NULL);
g_return_if_fail (strlen (secret) > 0);
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets,
g_strdup (key), g_strdup (secret));
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
}
/**
* nm_setting_vpn_get_secret:
* @setting: the #NMSettingVPN
* @key: the name of the secret to retrieve
*
* Retrieves the secret of a key/value relationship previously established
* by nm_setting_vpn_add_secret().
*
* Returns: the secret, if any
**/
const char *
nm_setting_vpn_get_secret (NMSettingVPN *setting, const char *key)
{
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), NULL);
return (const char *) g_hash_table_lookup (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
}
/**
* nm_setting_vpn_remove_secret:
* @setting: the #NMSettingVPN
* @key: the name of the secret to remove
*
* Deletes a key/value relationship previously established by
* nm_setting_vpn_add_secret().
*
* Returns: %TRUE if the secret was found and removed from the internal list,
* %FALSE if it was not.
**/
gboolean
nm_setting_vpn_remove_secret (NMSettingVPN *setting, const char *key)
{
gboolean found;
g_return_val_if_fail (NM_IS_SETTING_VPN (setting), FALSE);
found = g_hash_table_remove (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, key);
if (found)
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
return found;
}
/**
* nm_setting_vpn_foreach_secret:
* @setting: a #NMSettingVPN
* @func: (scope call): an user provided function
* @user_data: data to be passed to @func
*
* Iterates all secrets stored in this setting. It is safe to add, remove,
* and modify secrets inside @func, though any additions or removals made during
* iteration will not be part of the iteration.
*/
void
nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
NMVPNIterFunc func,
gpointer user_data)
{
g_return_if_fail (NM_IS_SETTING_VPN (setting));
foreach_item_helper (NM_SETTING_VPN_GET_PRIVATE (setting)->secrets, func, user_data);
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
if (!priv->service_type) {
g_set_error_literal (error,
NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_SERVICE_TYPE);
return FALSE;
}
if (!strlen (priv->service_type)) {
g_set_error_literal (error,
NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_SERVICE_TYPE);
return FALSE;
}
/* default username can be NULL, but can't be zero-length */
if (priv->user_name && !strlen (priv->user_name)) {
g_set_error_literal (error,
NM_SETTING_VPN_ERROR,
NM_SETTING_VPN_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_VPN_SETTING_NAME, NM_SETTING_VPN_USER_NAME);
return FALSE;
}
return TRUE;
}
static NMSettingUpdateSecretResult
update_secret_string (NMSetting *setting,
const char *key,
const char *value,
GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
g_return_val_if_fail (key != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
g_return_val_if_fail (value != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Secret %s was empty", key);
return NM_SETTING_UPDATE_SECRET_ERROR;
}
if (g_strcmp0 (g_hash_table_lookup (priv->secrets, key), value) == 0)
return NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED;
g_hash_table_insert (priv->secrets, g_strdup (key), g_strdup (value));
return NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED;
}
static NMSettingUpdateSecretResult
update_secret_hash (NMSetting *setting,
GHashTable *secrets,
GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
GHashTableIter iter;
const char *name, *value;
NMSettingUpdateSecretResult result = NM_SETTING_UPDATE_SECRET_SUCCESS_UNCHANGED;
g_return_val_if_fail (secrets != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
/* Make sure the items are valid */
g_hash_table_iter_init (&iter, secrets);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) {
if (!name || !strlen (name)) {
g_set_error_literal (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Secret name was empty");
return NM_SETTING_UPDATE_SECRET_ERROR;
}
if (!value || !strlen (value)) {
g_set_error (error, NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Secret %s value was empty", name);
return NM_SETTING_UPDATE_SECRET_ERROR;
}
}
/* Now add the items to the settings' secrets list */
g_hash_table_iter_init (&iter, secrets);
while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &value)) {
if (value == NULL) {
g_warn_if_fail (value != NULL);
continue;
}
if (strlen (value) == 0) {
g_warn_if_fail (strlen (value) > 0);
continue;
}
if (g_strcmp0 (g_hash_table_lookup (priv->secrets, name), value) == 0)
continue;
g_hash_table_insert (priv->secrets, g_strdup (name), g_strdup (value));
result = NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED;
}
return result;
}
static int
update_one_secret (NMSetting *setting, const char *key, GValue *value, GError **error)
{
NMSettingUpdateSecretResult success = NM_SETTING_UPDATE_SECRET_ERROR;
g_return_val_if_fail (key != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
g_return_val_if_fail (value != NULL, NM_SETTING_UPDATE_SECRET_ERROR);
if (G_VALUE_HOLDS_STRING (value)) {
/* Passing the string properties individually isn't correct, and won't
* produce the correct result, but for some reason that's how it used
* to be done. So even though it's not correct, keep the code around
* for compatibility's sake.
*/
success = update_secret_string (setting, key, g_value_get_string (value), error);
} else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_STRING)) {
if (strcmp (key, NM_SETTING_VPN_SECRETS) != 0) {
g_set_error (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_NOT_SECRET,
"Property %s not a secret property", key);
} else
success = update_secret_hash (setting, g_value_get_boxed (value), error);
} else
g_set_error_literal (error, NM_SETTING_ERROR, NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH, key);
if (success == NM_SETTING_UPDATE_SECRET_SUCCESS_MODIFIED)
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
return success;
}
static gboolean
get_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags *out_flags,
GError **error)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
gboolean success = FALSE;
char *flags_key;
gpointer val;
unsigned long tmp;
flags_key = g_strdup_printf ("%s-flags", secret_name);
if (g_hash_table_lookup_extended (priv->data, flags_key, NULL, &val)) {
errno = 0;
tmp = strtoul ((const char *) val, NULL, 10);
if ((errno == 0) && (tmp <= NM_SETTING_SECRET_FLAGS_ALL)) {
if (out_flags)
*out_flags = (guint32) tmp;
success = TRUE;
} else {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH,
"Failed to convert '%s' value '%s' to uint",
flags_key, (const char *) val);
}
} else {
g_set_error (error,
NM_SETTING_ERROR,
NM_SETTING_ERROR_PROPERTY_NOT_FOUND,
"Secret flags property '%s' not found", flags_key);
}
g_free (flags_key);
return success;
}
static gboolean
set_secret_flags (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags flags,
GError **error)
{
g_hash_table_insert (NM_SETTING_VPN_GET_PRIVATE (setting)->data,
g_strdup_printf ("%s-flags", secret_name),
g_strdup_printf ("%u", flags));
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
return TRUE;
}
static GPtrArray *
need_secrets (NMSetting *setting)
{
/* Assume that VPN connections need secrets since they almost always will */
return g_ptr_array_sized_new (1);
}
static gboolean
compare_one_secret (NMSettingVPN *a,
NMSettingVPN *b,
NMSettingCompareFlags flags)
{
GHashTable *a_secrets, *b_secrets;
GHashTableIter iter;
const char *key, *val;
a_secrets = NM_SETTING_VPN_GET_PRIVATE (a)->secrets;
b_secrets = NM_SETTING_VPN_GET_PRIVATE (b)->secrets;
g_hash_table_iter_init (&iter, a_secrets);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &val)) {
NMSettingSecretFlags a_secret_flags = NM_SETTING_SECRET_FLAG_NONE;
NMSettingSecretFlags b_secret_flags = NM_SETTING_SECRET_FLAG_NONE;
nm_setting_get_secret_flags (NM_SETTING (a), key, &a_secret_flags, NULL);
nm_setting_get_secret_flags (NM_SETTING (b), key, &b_secret_flags, NULL);
/* If the secret flags aren't the same, the settings aren't the same */
if (a_secret_flags != b_secret_flags)
return FALSE;
if ( (flags & NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS)
&& (a_secret_flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED))
continue;
if ( (flags & NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)
&& (a_secret_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED))
continue;
/* Now compare the values themselves */
if (g_strcmp0 (val, nm_setting_vpn_get_secret (b, key)) != 0)
return FALSE;
}
return TRUE;
}
static gboolean
compare_property (NMSetting *setting,
NMSetting *other,
const GParamSpec *prop_spec,
NMSettingCompareFlags flags)
{
gboolean same;
/* We only need to treat the 'secrets' property specially */
if (g_strcmp0 (prop_spec->name, NM_SETTING_VPN_SECRETS) != 0)
return NM_SETTING_CLASS (nm_setting_vpn_parent_class)->compare_property (setting, other, prop_spec, flags);
/* Compare A to B to ensure everything in A is found in B */
same = compare_one_secret (NM_SETTING_VPN (setting), NM_SETTING_VPN (other), flags);
if (same) {
/* And then B to A to ensure everything in B is also found in A */
same = compare_one_secret (NM_SETTING_VPN (other), NM_SETTING_VPN (setting), flags);
}
return same;
}
static gboolean
clear_secrets_with_flags (NMSetting *setting,
GParamSpec *pspec,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
GHashTableIter iter;
const char *secret;
gboolean changed = TRUE;
if (priv->secrets == NULL)
return FALSE;
/* Iterate through secrets hash and check each entry */
g_hash_table_iter_init (&iter, priv->secrets);
while (g_hash_table_iter_next (&iter, (gpointer) &secret, NULL)) {
NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
nm_setting_get_secret_flags (setting, secret, &flags, NULL);
if (func (setting, pspec->name, flags, user_data) == TRUE) {
g_hash_table_iter_remove (&iter);
changed = TRUE;
}
}
if (changed)
g_object_notify (G_OBJECT (setting), NM_SETTING_VPN_SECRETS);
return changed;
}
static void
destroy_one_secret (gpointer data)
{
char *secret = (char *) data;
/* Don't leave the secret lying around in memory */
memset (secret, 0, strlen (secret));
g_free (secret);
}
static void
nm_setting_vpn_init (NMSettingVPN *setting)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
priv->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_one_secret);
}
static void
finalize (GObject *object)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
g_free (priv->service_type);
g_free (priv->user_name);
g_hash_table_destroy (priv->data);
g_hash_table_destroy (priv->secrets);
G_OBJECT_CLASS (nm_setting_vpn_parent_class)->finalize (object);
}
static void
copy_hash (gpointer key, gpointer value, gpointer user_data)
{
g_return_if_fail (value != NULL);
g_return_if_fail (strlen (value));
g_hash_table_insert ((GHashTable *) user_data, g_strdup (key), g_strdup (value));
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (object);
GHashTable *new_hash;
switch (prop_id) {
case PROP_SERVICE_TYPE:
g_free (priv->service_type);
priv->service_type = g_value_dup_string (value);
break;
case PROP_USER_NAME:
g_free (priv->user_name);
priv->user_name = g_value_dup_string (value);
break;
case PROP_DATA:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (priv->data);
new_hash = g_value_get_boxed (value);
if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, priv->data);
break;
case PROP_SECRETS:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (priv->secrets);
new_hash = g_value_get_boxed (value);
if (new_hash)
g_hash_table_foreach (new_hash, copy_hash, priv->secrets);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingVPN *setting = NM_SETTING_VPN (object);
NMSettingVPNPrivate *priv = NM_SETTING_VPN_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_SERVICE_TYPE:
g_value_set_string (value, nm_setting_vpn_get_service_type (setting));
break;
case PROP_USER_NAME:
g_value_set_string (value, nm_setting_vpn_get_user_name (setting));
break;
case PROP_DATA:
g_value_set_boxed (value, priv->data);
break;
case PROP_SECRETS:
g_value_set_boxed (value, priv->secrets);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_vpn_class_init (NMSettingVPNClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingVPNPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
parent_class->update_one_secret = update_one_secret;
parent_class->get_secret_flags = get_secret_flags;
parent_class->set_secret_flags = set_secret_flags;
parent_class->need_secrets = need_secrets;
parent_class->compare_property = compare_property;
parent_class->clear_secrets_with_flags = clear_secrets_with_flags;
/* Properties */
/**
* NMSettingVPN:service-type:
*
* D-Bus service name of the VPN plugin that this setting uses to connect to
* its network. i.e. org.freedesktop.NetworkManager.vpnc for the vpnc
* plugin.
**/
g_object_class_install_property
(object_class, PROP_SERVICE_TYPE,
g_param_spec_string (NM_SETTING_VPN_SERVICE_TYPE, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVPN:user-name:
*
* If the VPN connection requires a user name for authentication, that name
* should be provided here. If the connection is available to more than one
* user, and the VPN requires each user to supply a different name, then
* leave this property empty. If this property is empty, NetworkManager
* will automatically supply the username of the user which requested the
* VPN connection.
**/
g_object_class_install_property
(object_class, PROP_USER_NAME,
g_param_spec_string (NM_SETTING_VPN_USER_NAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVPN:data:
*
* Dictionary of key/value pairs of VPN plugin specific data. Both keys and
* values must be strings.
**/
g_object_class_install_property
(object_class, PROP_DATA,
_nm_param_spec_specialized (NM_SETTING_VPN_DATA, "", "",
DBUS_TYPE_G_MAP_OF_STRING,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVPN:secrets:
*
* Dictionary of key/value pairs of VPN plugin specific secrets like
* passwords or private keys. Both keys and values must be strings.
**/
g_object_class_install_property
(object_class, PROP_SECRETS,
_nm_param_spec_specialized (NM_SETTING_VPN_SECRETS, "", "",
DBUS_TYPE_G_MAP_OF_STRING,
G_PARAM_READWRITE |
NM_SETTING_PARAM_SECRET |
G_PARAM_STATIC_STRINGS));
}

115
libnm-core/nm-setting-vpn.h Normal file
View File

@@ -0,0 +1,115 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2013 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_VPN_H
#define NM_SETTING_VPN_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_VPN (nm_setting_vpn_get_type ())
#define NM_SETTING_VPN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_VPN, NMSettingVPN))
#define NM_SETTING_VPN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_VPN, NMSettingVPNClass))
#define NM_IS_SETTING_VPN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_VPN))
#define NM_IS_SETTING_VPN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_VPN))
#define NM_SETTING_VPN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_VPN, NMSettingVPNClass))
#define NM_SETTING_VPN_SETTING_NAME "vpn"
/**
* NMSettingVpnError:
* @NM_SETTING_VPN_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_VPN_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_VPN_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_VPN_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_VPN_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_VPN_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
} NMSettingVpnError;
#define NM_SETTING_VPN_ERROR nm_setting_vpn_error_quark ()
GQuark nm_setting_vpn_error_quark (void);
#define NM_SETTING_VPN_SERVICE_TYPE "service-type"
#define NM_SETTING_VPN_USER_NAME "user-name"
#define NM_SETTING_VPN_DATA "data"
#define NM_SETTING_VPN_SECRETS "secrets"
typedef struct {
NMSetting parent;
} NMSettingVPN;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingVPNClass;
/**
* NMVPNIterFunc:
* @key: the name of the data or secret item
* @value: the value of the data or secret item
* @user_data: User data passed to nm_setting_vpn_foreach_data_item() or
* nm_setting_vpn_foreach_secret()
**/
typedef void (*NMVPNIterFunc) (const char *key, const char *value, gpointer user_data);
GType nm_setting_vpn_get_type (void);
NMSetting *nm_setting_vpn_new (void);
const char *nm_setting_vpn_get_service_type (NMSettingVPN *setting);
const char *nm_setting_vpn_get_user_name (NMSettingVPN *setting);
guint32 nm_setting_vpn_get_num_data_items (NMSettingVPN *setting);
void nm_setting_vpn_add_data_item (NMSettingVPN *setting,
const char *key,
const char *item);
const char * nm_setting_vpn_get_data_item (NMSettingVPN *setting,
const char *key);
gboolean nm_setting_vpn_remove_data_item (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_data_item (NMSettingVPN *setting,
NMVPNIterFunc func,
gpointer user_data);
guint32 nm_setting_vpn_get_num_secrets (NMSettingVPN *setting);
void nm_setting_vpn_add_secret (NMSettingVPN *setting,
const char *key,
const char *secret);
const char * nm_setting_vpn_get_secret (NMSettingVPN *setting,
const char *key);
gboolean nm_setting_vpn_remove_secret (NMSettingVPN *setting,
const char *key);
void nm_setting_vpn_foreach_secret (NMSettingVPN *setting,
NMVPNIterFunc func,
gpointer user_data);
G_END_DECLS
#endif /* NM_SETTING_VPN_H */

View File

@@ -0,0 +1,262 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2013 Red Hat, Inc.
* Copyright 2009 Novell, Inc.
*/
#include <string.h>
#include <net/ethernet.h>
#include <dbus/dbus-glib.h>
#include <glib/gi18n.h>
#include "nm-setting-wimax.h"
#include "nm-param-spec-specialized.h"
#include "nm-setting-private.h"
/**
* SECTION:nm-setting-wimax
* @short_description: Describes 802.16e Mobile WiMAX connection properties
* @include: nm-setting-wimax.h
*
* The #NMSettingWimax object is a #NMSetting subclass that describes properties
* necessary for connection to 802.16e Mobile WiMAX networks.
**/
/**
* nm_setting_wimax_error_quark:
*
* Registers an error quark for #NMSettingWimax if necessary.
*
* Returns: the error quark used for #NMSettingWimax errors.
**/
GQuark
nm_setting_wimax_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-setting-wimax-error-quark");
return quark;
}
G_DEFINE_TYPE_WITH_CODE (NMSettingWimax, nm_setting_wimax, NM_TYPE_SETTING,
_nm_register_setting (NM_SETTING_WIMAX_SETTING_NAME,
g_define_type_id,
1,
NM_SETTING_WIMAX_ERROR))
NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_WIMAX)
#define NM_SETTING_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIMAX, NMSettingWimaxPrivate))
typedef struct {
char *network_name;
GByteArray *mac_address;
} NMSettingWimaxPrivate;
enum {
PROP_0,
PROP_NETWORK_NAME,
PROP_MAC_ADDRESS,
LAST_PROP
};
/**
* nm_setting_wimax_new:
*
* Creates a new #NMSettingWimax object with default values.
*
* Returns: the new empty #NMSettingWimax object
**/
NMSetting *
nm_setting_wimax_new (void)
{
return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIMAX, NULL);
}
/**
* nm_setting_wimax_get_network_name:
* @setting: the #NMSettingWimax
*
* Returns the WiMAX NSP name (ex "Sprint" or "CLEAR") which identifies the
* specific WiMAX network this setting describes a connection to.
*
* Returns: the WiMAX NSP name
**/
const char *
nm_setting_wimax_get_network_name (NMSettingWimax *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIMAX (setting), NULL);
return NM_SETTING_WIMAX_GET_PRIVATE (setting)->network_name;
}
/**
* nm_setting_wimax_get_mac_address:
* @setting: the #NMSettingWimax
*
* Returns the MAC address of a WiMAX device which this connection is locked
* to.
*
* Returns: the MAC address
**/
const GByteArray *
nm_setting_wimax_get_mac_address (NMSettingWimax *setting)
{
g_return_val_if_fail (NM_IS_SETTING_WIMAX (setting), NULL);
return NM_SETTING_WIMAX_GET_PRIVATE (setting)->mac_address;
}
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (setting);
if (!priv->network_name) {
g_set_error_literal (error,
NM_SETTING_WIMAX_ERROR,
NM_SETTING_WIMAX_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_NETWORK_NAME);
return FALSE;
}
if (!strlen (priv->network_name)) {
g_set_error_literal (error,
NM_SETTING_WIMAX_ERROR,
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY,
_("property is empty"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_NETWORK_NAME);
return FALSE;
}
if (priv->mac_address && priv->mac_address->len != ETH_ALEN) {
g_set_error_literal (error,
NM_SETTING_WIMAX_ERROR,
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_MAC_ADDRESS);
return FALSE;
}
return TRUE;
}
static void
nm_setting_wimax_init (NMSettingWimax *setting)
{
}
static void
finalize (GObject *object)
{
NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (object);
g_free (priv->network_name);
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
G_OBJECT_CLASS (nm_setting_wimax_parent_class)->finalize (object);
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMSettingWimaxPrivate *priv = NM_SETTING_WIMAX_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NETWORK_NAME:
g_free (priv->network_name);
priv->network_name = g_value_dup_string (value);
break;
case PROP_MAC_ADDRESS:
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
priv->mac_address = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingWimax *setting = NM_SETTING_WIMAX (object);
switch (prop_id) {
case PROP_NETWORK_NAME:
g_value_set_string (value, nm_setting_wimax_get_network_name (setting));
break;
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, nm_setting_wimax_get_mac_address (setting));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_setting_wimax_class_init (NMSettingWimaxClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
g_type_class_add_private (setting_class, sizeof (NMSettingWimaxPrivate));
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */
/**
* NMSettingWimax:network-name:
*
* Network Service Provider (NSP) name of the WiMAX network this connection
* should use.
**/
g_object_class_install_property
(object_class, PROP_NETWORK_NAME,
g_param_spec_string (NM_SETTING_WIMAX_NETWORK_NAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingWimax:mac-address:
*
* If specified, this connection will only apply to the WiMAX device whose
* MAC address matches. This property does not change the MAC address of the
* device (known as MAC spoofing).
**/
g_object_class_install_property
(object_class, PROP_MAC_ADDRESS,
_nm_param_spec_specialized (NM_SETTING_WIMAX_MAC_ADDRESS, "", "",
DBUS_TYPE_G_UCHAR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,73 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2009 Novell, Inc.
*/
#ifndef NM_SETTING_WIMAX_H
#define NM_SETTING_WIMAX_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_WIMAX (nm_setting_wimax_get_type ())
#define NM_SETTING_WIMAX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_WIMAX, NMSettingWimax))
#define NM_SETTING_WIMAX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_WIMAX, NMSettingWimaxClass))
#define NM_IS_SETTING_WIMAX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_WIMAX))
#define NM_IS_SETTING_WIMAX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_WIMAX))
#define NM_SETTING_WIMAX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_WIMAX, NMSettingWimaxClass))
#define NM_SETTING_WIMAX_SETTING_NAME "wimax"
/**
* NMSettingWimaxError:
* @NM_SETTING_WIMAX_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_WIMAX_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_WIMAX_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_WIMAX_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingWimaxError;
#define NM_SETTING_WIMAX_ERROR nm_setting_wimax_error_quark ()
GQuark nm_setting_wimax_error_quark (void);
#define NM_SETTING_WIMAX_NETWORK_NAME "network-name"
#define NM_SETTING_WIMAX_MAC_ADDRESS "mac-address"
typedef struct {
NMSetting parent;
} NMSettingWimax;
typedef struct {
NMSettingClass parent;
} NMSettingWimaxClass;
GType nm_setting_wimax_get_type (void);
NMSetting *nm_setting_wimax_new (void);
const char *nm_setting_wimax_get_network_name (NMSettingWimax *setting);
const GByteArray *nm_setting_wimax_get_mac_address (NMSettingWimax *setting);
G_END_DECLS
#endif /* NM_SETTING_WIMAX_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_WIRED_H
#define NM_SETTING_WIRED_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_WIRED (nm_setting_wired_get_type ())
#define NM_SETTING_WIRED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_WIRED, NMSettingWired))
#define NM_SETTING_WIRED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_WIRED, NMSettingWiredClass))
#define NM_IS_SETTING_WIRED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_WIRED))
#define NM_IS_SETTING_WIRED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_WIRED))
#define NM_SETTING_WIRED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_WIRED, NMSettingWiredClass))
#define NM_SETTING_WIRED_SETTING_NAME "802-3-ethernet"
/**
* NMSettingWiredError:
* @NM_SETTING_WIRED_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_WIRED_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_WIRED_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_WIRED_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_WIRED_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_WIRED_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingWiredError;
#define NM_SETTING_WIRED_ERROR nm_setting_wired_error_quark ()
GQuark nm_setting_wired_error_quark (void);
#define NM_SETTING_WIRED_PORT "port"
#define NM_SETTING_WIRED_SPEED "speed"
#define NM_SETTING_WIRED_DUPLEX "duplex"
#define NM_SETTING_WIRED_AUTO_NEGOTIATE "auto-negotiate"
#define NM_SETTING_WIRED_MAC_ADDRESS "mac-address"
#define NM_SETTING_WIRED_CLONED_MAC_ADDRESS "cloned-mac-address"
#define NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST "mac-address-blacklist"
#define NM_SETTING_WIRED_MTU "mtu"
#define NM_SETTING_WIRED_S390_SUBCHANNELS "s390-subchannels"
#define NM_SETTING_WIRED_S390_NETTYPE "s390-nettype"
#define NM_SETTING_WIRED_S390_OPTIONS "s390-options"
typedef struct {
NMSetting parent;
} NMSettingWired;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingWiredClass;
GType nm_setting_wired_get_type (void);
NMSetting * nm_setting_wired_new (void);
const char * nm_setting_wired_get_port (NMSettingWired *setting);
guint32 nm_setting_wired_get_speed (NMSettingWired *setting);
const char * nm_setting_wired_get_duplex (NMSettingWired *setting);
gboolean nm_setting_wired_get_auto_negotiate (NMSettingWired *setting);
const GByteArray *nm_setting_wired_get_mac_address (NMSettingWired *setting);
const GByteArray *nm_setting_wired_get_cloned_mac_address (NMSettingWired *setting);
const GSList *nm_setting_wired_get_mac_address_blacklist (NMSettingWired *setting);
NM_AVAILABLE_IN_0_9_10
guint32 nm_setting_wired_get_num_mac_blacklist_items (NMSettingWired *setting);
NM_AVAILABLE_IN_0_9_10
const char * nm_setting_wired_get_mac_blacklist_item (NMSettingWired *setting,
guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wired_add_mac_blacklist_item (NMSettingWired *setting,
const char *mac);
NM_AVAILABLE_IN_0_9_10
void nm_setting_wired_remove_mac_blacklist_item (NMSettingWired *setting,
guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wired_remove_mac_blacklist_item_by_value (NMSettingWired *setting,
const char *mac);
NM_AVAILABLE_IN_0_9_10
void nm_setting_wired_clear_mac_blacklist_items (NMSettingWired *setting);
guint32 nm_setting_wired_get_mtu (NMSettingWired *setting);
const GPtrArray * nm_setting_wired_get_s390_subchannels (NMSettingWired *setting);
const char * nm_setting_wired_get_s390_nettype (NMSettingWired *setting);
guint32 nm_setting_wired_get_num_s390_options (NMSettingWired *setting);
gboolean nm_setting_wired_get_s390_option (NMSettingWired *setting,
guint32 idx,
const char **out_key,
const char **out_value);
const char * nm_setting_wired_get_s390_option_by_key (NMSettingWired *setting,
const char *key);
gboolean nm_setting_wired_add_s390_option (NMSettingWired *setting,
const char *key,
const char *value);
gboolean nm_setting_wired_remove_s390_option (NMSettingWired *setting,
const char *key);
NM_AVAILABLE_IN_0_9_10
const char ** nm_setting_wired_get_valid_s390_options (NMSettingWired *setting);
G_END_DECLS
#endif /* NM_SETTING_WIRED_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,178 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_WIRELESS_SECURITY_H
#define NM_SETTING_WIRELESS_SECURITY_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_get_type ())
#define NM_SETTING_WIRELESS_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurity))
#define NM_SETTING_WIRELESS_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurityClass))
#define NM_IS_SETTING_WIRELESS_SECURITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_WIRELESS_SECURITY))
#define NM_IS_SETTING_WIRELESS_SECURITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_WIRELESS_SECURITY))
#define NM_SETTING_WIRELESS_SECURITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_WIRELESS_SECURITY, NMSettingWirelessSecurityClass))
#define NM_SETTING_WIRELESS_SECURITY_SETTING_NAME "802-11-wireless-security"
/**
* NMSettingWirelessSecurityError:
* @NM_SETTING_WIRELESS_SECURITY_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_PROPERTY: the property was
* missing and is required
* @NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_802_1X_SETTING: a property contained
* a value that requires the connection to contain a #NMSetting8021x setting
* @NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_802_1X: LEAP authentication
* was specified but key management was not set to "8021x"
* @NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME: LEAP authentication
* was specified but no LEAP username was given
* @NM_SETTING_WIRELESS_SECURITY_ERROR_SHARED_KEY_REQUIRES_WEP: Shared Key
* authentication was specified but the setting did not specify WEP as the
* encryption protocol
*/
typedef enum {
NM_SETTING_WIRELESS_SECURITY_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_802_1X_SETTING, /*< nick=Missing8021xSetting >*/
NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_802_1X, /*< nick=LEAPRequires8021x >*/
NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME, /*< nick=LEAPRequiresUsername >*/
NM_SETTING_WIRELESS_SECURITY_ERROR_SHARED_KEY_REQUIRES_WEP /*< nick=SharedKeyRequiresWEP >*/
} NMSettingWirelessSecurityError;
#define NM_SETTING_WIRELESS_SECURITY_ERROR nm_setting_wireless_security_error_quark ()
GQuark nm_setting_wireless_security_error_quark (void);
/**
* NMWepKeyType:
* @NM_WEP_KEY_TYPE_UNKNOWN: unknown WEP key type
* @NM_WEP_KEY_TYPE_KEY: indicates a hexadecimal or ASCII formatted WEP key.
* Hex keys are either 10 or 26 hexadecimal characters (ie "5f782f2f5f" or
* "732f2d712e4a394a375d366931"), while ASCII keys are either 5 or 13 ASCII
* characters (ie "abcde" or "blahblah99$*1").
* @NM_WEP_KEY_TYPE_PASSPHRASE: indicates a WEP passphrase (ex "I bought a duck
* on my way back from the market 235Q&^%^*%") instead of a hexadecimal or ASCII
* key. Passphrases are between 8 and 64 characters inclusive and are hashed
* the actual WEP key using the MD5 hash algorithm.
* @NM_WEP_KEY_TYPE_LAST: placeholder value for bounds-checking
*
* The #NMWepKeyType values specify how any WEP keys present in the setting
* are intepreted. There are no standards governing how to hash the various WEP
* key/passphrase formats into the actual WEP key. Unfortunately some WEP keys
* can be interpreted in multiple ways, requring the setting to specify how to
* interpret the any WEP keys. For example, the key "732f2d712e4a394a375d366931"
* is both a valid Hexadecimal WEP key and a WEP passphrase. Further, many
* ASCII keys are also valid WEP passphrases, but since passphrases and ASCII
* keys are hashed differently to determine the actual WEP key the type must be
* specified.
*/
typedef enum {
NM_WEP_KEY_TYPE_UNKNOWN = 0,
NM_WEP_KEY_TYPE_KEY = 1, /* Hex or ASCII */
NM_WEP_KEY_TYPE_PASSPHRASE = 2, /* 104/128-bit Passphrase */
NM_WEP_KEY_TYPE_LAST = NM_WEP_KEY_TYPE_PASSPHRASE
} NMWepKeyType;
#define NM_SETTING_WIRELESS_SECURITY_KEY_MGMT "key-mgmt"
#define NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX "wep-tx-keyidx"
#define NM_SETTING_WIRELESS_SECURITY_AUTH_ALG "auth-alg"
#define NM_SETTING_WIRELESS_SECURITY_PROTO "proto"
#define NM_SETTING_WIRELESS_SECURITY_PAIRWISE "pairwise"
#define NM_SETTING_WIRELESS_SECURITY_GROUP "group"
#define NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME "leap-username"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY0 "wep-key0"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 "wep-key1"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 "wep-key2"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 "wep-key3"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS "wep-key-flags"
#define NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE "wep-key-type"
#define NM_SETTING_WIRELESS_SECURITY_PSK "psk"
#define NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS "psk-flags"
#define NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD "leap-password"
#define NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS "leap-password-flags"
typedef struct {
NMSetting parent;
} NMSettingWirelessSecurity;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingWirelessSecurityClass;
GType nm_setting_wireless_security_get_type (void);
NMSetting * nm_setting_wireless_security_new (void);
const char *nm_setting_wireless_security_get_key_mgmt (NMSettingWirelessSecurity *setting);
guint32 nm_setting_wireless_security_get_num_protos (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_proto (NMSettingWirelessSecurity *setting, guint32 i);
gboolean nm_setting_wireless_security_add_proto (NMSettingWirelessSecurity *setting, const char *proto);
void nm_setting_wireless_security_remove_proto (NMSettingWirelessSecurity *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wireless_security_remove_proto_by_value (NMSettingWirelessSecurity *setting, const char *proto);
void nm_setting_wireless_security_clear_protos (NMSettingWirelessSecurity *setting);
guint32 nm_setting_wireless_security_get_num_pairwise (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_pairwise (NMSettingWirelessSecurity *setting, guint32 i);
gboolean nm_setting_wireless_security_add_pairwise (NMSettingWirelessSecurity *setting, const char *pairwise);
void nm_setting_wireless_security_remove_pairwise (NMSettingWirelessSecurity *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wireless_security_remove_pairwise_by_value (NMSettingWirelessSecurity *setting, const char *pairwise);
void nm_setting_wireless_security_clear_pairwise (NMSettingWirelessSecurity *setting);
guint32 nm_setting_wireless_security_get_num_groups (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_group (NMSettingWirelessSecurity *setting, guint32 i);
gboolean nm_setting_wireless_security_add_group (NMSettingWirelessSecurity *setting, const char *group);
void nm_setting_wireless_security_remove_group (NMSettingWirelessSecurity *setting, guint32 i);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wireless_security_remove_group_by_value (NMSettingWirelessSecurity *setting, const char *group);
void nm_setting_wireless_security_clear_groups (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_psk (NMSettingWirelessSecurity *setting);
NMSettingSecretFlags nm_setting_wireless_security_get_psk_flags (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_leap_username (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_leap_password (NMSettingWirelessSecurity *setting);
NMSettingSecretFlags nm_setting_wireless_security_get_leap_password_flags (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_wep_key (NMSettingWirelessSecurity *setting, guint32 idx);
void nm_setting_wireless_security_set_wep_key (NMSettingWirelessSecurity *setting, guint32 idx, const char *key);
guint32 nm_setting_wireless_security_get_wep_tx_keyidx (NMSettingWirelessSecurity *setting);
const char *nm_setting_wireless_security_get_auth_alg (NMSettingWirelessSecurity *setting);
NMSettingSecretFlags nm_setting_wireless_security_get_wep_key_flags (NMSettingWirelessSecurity *setting);
NMWepKeyType nm_setting_wireless_security_get_wep_key_type (NMSettingWirelessSecurity *setting);
G_END_DECLS
#endif /* NM_SETTING_WIRELESS_SECURITY_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,174 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_WIRELESS_H
#define NM_SETTING_WIRELESS_H
#include <NetworkManager.h>
#include <nm-setting.h>
#include <nm-setting-wireless-security.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_WIRELESS (nm_setting_wireless_get_type ())
#define NM_SETTING_WIRELESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_WIRELESS, NMSettingWireless))
#define NM_SETTING_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessClass))
#define NM_IS_SETTING_WIRELESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_WIRELESS))
#define NM_IS_SETTING_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_WIRELESS))
#define NM_SETTING_WIRELESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessClass))
#define NM_SETTING_WIRELESS_SETTING_NAME "802-11-wireless"
/**
* NMSettingWirelessError:
* @NM_SETTING_WIRELESS_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_WIRELESS_ERROR_MISSING_PROPERTY: the property was missing and is
* required
* @NM_SETTING_WIRELESS_ERROR_MISSING_SECURITY_SETTING: property values require
* the presence of an #NMSettingWirelessSecurity object in the connection
* @NM_SETTING_WIRELESS_ERROR_CHANNEL_REQUIRES_BAND: the property channel was
* set to a value that requires the #NMSettingWireless:band property to be set
*/
typedef enum {
NM_SETTING_WIRELESS_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_WIRELESS_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
NM_SETTING_WIRELESS_ERROR_MISSING_SECURITY_SETTING, /*< nick=MissingSecuritySetting >*/
NM_SETTING_WIRELESS_ERROR_CHANNEL_REQUIRES_BAND /*< nick=ChannelRequiresBand >*/
} NMSettingWirelessError;
#define NM_SETTING_WIRELESS_ERROR nm_setting_wireless_error_quark ()
GQuark nm_setting_wireless_error_quark (void);
#define NM_SETTING_WIRELESS_SSID "ssid"
#define NM_SETTING_WIRELESS_MODE "mode"
#define NM_SETTING_WIRELESS_BAND "band"
#define NM_SETTING_WIRELESS_CHANNEL "channel"
#define NM_SETTING_WIRELESS_BSSID "bssid"
#define NM_SETTING_WIRELESS_RATE "rate"
#define NM_SETTING_WIRELESS_TX_POWER "tx-power"
#define NM_SETTING_WIRELESS_MAC_ADDRESS "mac-address"
#define NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS "cloned-mac-address"
#define NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST "mac-address-blacklist"
#define NM_SETTING_WIRELESS_MTU "mtu"
#define NM_SETTING_WIRELESS_SEEN_BSSIDS "seen-bssids"
#define NM_SETTING_WIRELESS_HIDDEN "hidden"
/* Deprecated */
#define NM_SETTING_WIRELESS_SEC "security"
/**
* NM_SETTING_WIRELESS_MODE_ADHOC:
*
* Indicates Ad-Hoc mode where no access point is expected to be present.
*/
#define NM_SETTING_WIRELESS_MODE_ADHOC "adhoc"
/**
* NM_SETTING_WIRELESS_MODE_AP:
*
* Indicates AP/master mode where the wireless device is started as an access
* point/hotspot.
*
* Since: 0.9.8
*/
#define NM_SETTING_WIRELESS_MODE_AP "ap"
/**
* NM_SETTING_WIRELESS_MODE_INFRA:
*
* Indicates infrastructure mode where an access point is expected to be present
* for this connection.
*/
#define NM_SETTING_WIRELESS_MODE_INFRA "infrastructure"
typedef struct {
NMSetting parent;
} NMSettingWireless;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingWirelessClass;
GType nm_setting_wireless_get_type (void);
NMSetting *nm_setting_wireless_new (void);
const GByteArray *nm_setting_wireless_get_ssid (NMSettingWireless *setting);
const char *nm_setting_wireless_get_mode (NMSettingWireless *setting);
const char *nm_setting_wireless_get_band (NMSettingWireless *setting);
guint32 nm_setting_wireless_get_channel (NMSettingWireless *setting);
const GByteArray *nm_setting_wireless_get_bssid (NMSettingWireless *setting);
guint32 nm_setting_wireless_get_rate (NMSettingWireless *setting);
guint32 nm_setting_wireless_get_tx_power (NMSettingWireless *setting);
const GByteArray *nm_setting_wireless_get_mac_address (NMSettingWireless *setting);
const GByteArray *nm_setting_wireless_get_cloned_mac_address (NMSettingWireless *setting);
const GSList *nm_setting_wireless_get_mac_address_blacklist (NMSettingWireless *setting);
NM_AVAILABLE_IN_0_9_10
guint32 nm_setting_wireless_get_num_mac_blacklist_items (NMSettingWireless *setting);
NM_AVAILABLE_IN_0_9_10
const char * nm_setting_wireless_get_mac_blacklist_item (NMSettingWireless *setting,
guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting,
const char *mac);
NM_AVAILABLE_IN_0_9_10
void nm_setting_wireless_remove_mac_blacklist_item (NMSettingWireless *setting,
guint32 idx);
NM_AVAILABLE_IN_0_9_10
gboolean nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setting,
const char *mac);
NM_AVAILABLE_IN_0_9_10
void nm_setting_wireless_clear_mac_blacklist_items (NMSettingWireless *setting);
guint32 nm_setting_wireless_get_mtu (NMSettingWireless *setting);
gboolean nm_setting_wireless_get_hidden (NMSettingWireless *setting);
gboolean nm_setting_wireless_add_seen_bssid (NMSettingWireless *setting,
const char *bssid);
guint32 nm_setting_wireless_get_num_seen_bssids (NMSettingWireless *setting);
const char *nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
guint32 i);
gboolean nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
NMSettingWirelessSecurity *s_wireless_sec,
NM80211ApFlags ap_flags,
NM80211ApSecurityFlags ap_wpa,
NM80211ApSecurityFlags ap_rsn,
NM80211Mode ap_mode);
/* Deprecated */
NM_DEPRECATED_IN_0_9_10
const char *nm_setting_wireless_get_security (NMSettingWireless *setting);
G_END_DECLS
#endif /* NM_SETTING_WIRELESS_H */

1445
libnm-core/nm-setting.c Normal file

File diff suppressed because it is too large Load Diff

317
libnm-core/nm-setting.h Normal file
View File

@@ -0,0 +1,317 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
* Copyright 2007 - 2008 Novell, Inc.
*/
#ifndef NM_SETTING_H
#define NM_SETTING_H
#include <glib.h>
#include <glib-object.h>
#include <nm-version.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING (nm_setting_get_type ())
#define NM_SETTING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING, NMSetting))
#define NM_SETTING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING, NMSettingClass))
#define NM_IS_SETTING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING))
#define NM_IS_SETTING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING))
#define NM_SETTING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING, NMSettingClass))
/**
* NMSettingError:
* @NM_SETTING_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_ERROR_PROPERTY_NOT_FOUND: a property required by the operation
* was not found; for example, an attempt to update an invalid secret
* @NM_SETTING_ERROR_PROPERTY_NOT_SECRET: an operation which requires a secret
* was attempted on a non-secret property
* @NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH: the operation requires a property
* of a specific type, or the value couldn't be transformed to the same type
* as the property being acted upon
*
* Describes errors that may result from operations involving a #NMSetting.
*
**/
typedef enum
{
NM_SETTING_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_ERROR_PROPERTY_NOT_FOUND, /*< nick=PropertyNotFound >*/
NM_SETTING_ERROR_PROPERTY_NOT_SECRET, /*< nick=PropertyNotSecret >*/
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH /*< nick=PropertyTypeMismatch >*/
} NMSettingError;
#define NM_SETTING_ERROR nm_setting_error_quark ()
GQuark nm_setting_error_quark (void);
/* DEPRECATED AND UNUSED */
#define NM_SETTING_PARAM_SERIALIZE (1 << (0 + G_PARAM_USER_SHIFT))
/* The property of the #NMSetting is required for the setting to be valid */
#define NM_SETTING_PARAM_REQUIRED (1 << (1 + G_PARAM_USER_SHIFT))
/* The property of the #NMSetting is a secret */
#define NM_SETTING_PARAM_SECRET (1 << (2 + G_PARAM_USER_SHIFT))
/* The property of the #NMSetting should be ignored during comparisons that
* use the %NM_SETTING_COMPARE_FLAG_FUZZY flag.
*/
#define NM_SETTING_PARAM_FUZZY_IGNORE (1 << (3 + G_PARAM_USER_SHIFT))
/* Note: all non-glib GParamFlags bits are reserved by NetworkManager */
#define NM_SETTING_NAME "name"
/**
* NMSettingSecretFlags:
* @NM_SETTING_SECRET_FLAG_NONE: the system is responsible for providing and
* storing this secret (default)
* @NM_SETTING_SECRET_FLAG_AGENT_OWNED: a user secret agent is responsible
* for providing and storing this secret; when it is required agents will be
* asked to retrieve it
* @NM_SETTING_SECRET_FLAG_NOT_SAVED: this secret should not be saved, but
* should be requested from the user each time it is needed
* @NM_SETTING_SECRET_FLAG_NOT_REQUIRED: in situations where it cannot be
* automatically determined that the secret is required (some VPNs and PPP
* providers dont require all secrets) this flag indicates that the specific
* secret is not required
*
* These flags indicate specific behavior related to handling of a secret. Each
* secret has a corresponding set of these flags which indicate how the secret
* is to be stored and/or requested when it is needed.
*
**/
typedef enum {
NM_SETTING_SECRET_FLAG_NONE = 0x00000000,
NM_SETTING_SECRET_FLAG_AGENT_OWNED = 0x00000001,
NM_SETTING_SECRET_FLAG_NOT_SAVED = 0x00000002,
NM_SETTING_SECRET_FLAG_NOT_REQUIRED = 0x00000004
/* NOTE: if adding flags, update nm-setting-private.h as well */
} NMSettingSecretFlags;
/**
* NMSettingCompareFlags:
* @NM_SETTING_COMPARE_FLAG_EXACT: match all properties exactly
* @NM_SETTING_COMPARE_FLAG_FUZZY: match only important attributes, like SSID,
* type, security settings, etc. Does not match, for example, connection ID
* or UUID.
* @NM_SETTING_COMPARE_FLAG_IGNORE_ID: ignore the connection's ID
* @NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS: ignore all secrets
* @NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS: ignore secrets for which
* the secret's flags indicate the secret is owned by a user secret agent
* (ie, the secret's flag includes @NM_SETTING_SECRET_FLAG_AGENT_OWNED)
* @NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS: ignore secrets for which
* the secret's flags indicate the secret should not be saved to persistent
* storage (ie, the secret's flag includes @NM_SETTING_SECRET_FLAG_NOT_SAVED)
*
* These flags modify the comparison behavior when comparing two settings or
* two connections.
*
**/
typedef enum {
NM_SETTING_COMPARE_FLAG_EXACT = 0x00000000,
NM_SETTING_COMPARE_FLAG_FUZZY = 0x00000001,
NM_SETTING_COMPARE_FLAG_IGNORE_ID = 0x00000002,
NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS = 0x00000004,
NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS = 0x00000008,
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS = 0x00000010
/* 0x80000000 is used for a private flag */
} NMSettingCompareFlags;
/**
* NMSetting:
*
* The NMSetting struct contains only private data.
* It should only be accessed through the functions described below.
*/
typedef struct {
GObject parent;
} NMSetting;
/**
* NMSettingClearSecretsWithFlagsFn:
* @setting: The setting for which secrets are being iterated
* @secret: The secret's name
* @flags: The secret's flags, eg %NM_SETTING_SECRET_FLAG_AGENT_OWNED
* @user_data: User data passed to nm_connection_clear_secrets_with_flags()
*
* Returns: %TRUE to clear the secret, %FALSE to not clear the secret
*/
typedef gboolean (*NMSettingClearSecretsWithFlagsFn) (NMSetting *setting,
const char *secret,
NMSettingSecretFlags flags,
gpointer user_data);
typedef struct {
GObjectClass parent;
/* Virtual functions */
gint (*verify) (NMSetting *setting,
GSList *all_settings,
GError **error);
GPtrArray *(*need_secrets) (NMSetting *setting);
int (*update_one_secret) (NMSetting *setting,
const char *key,
GValue *value,
GError **error);
gboolean (*get_secret_flags) (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags *out_flags,
GError **error);
gboolean (*set_secret_flags) (NMSetting *setting,
const char *secret_name,
gboolean verify_secret,
NMSettingSecretFlags flags,
GError **error);
/* Returns TRUE if the given property contains the same value in both settings */
gboolean (*compare_property) (NMSetting *setting,
NMSetting *other,
const GParamSpec *prop_spec,
NMSettingCompareFlags flags);
gboolean (*clear_secrets_with_flags) (NMSetting *setting,
GParamSpec *pspec,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data);
const char *(*get_virtual_iface_name) (NMSetting *setting);
/* Padding for future expansion */
void (*_reserved1) (void);
} NMSettingClass;
/**
* NMSettingValueIterFn:
* @setting: The setting for which properties are being iterated, given to
* nm_setting_enumerate_values()
* @key: The value/property name
* @value: The property's value
* @flags: The property's flags, like %NM_SETTING_PARAM_SECRET
* @user_data: User data passed to nm_setting_enumerate_values()
*/
typedef void (*NMSettingValueIterFn) (NMSetting *setting,
const char *key,
const GValue *value,
GParamFlags flags,
gpointer user_data);
GType nm_setting_get_type (void);
/**
* NMSettingHashFlags:
* @NM_SETTING_HASH_FLAG_ALL: hash all properties (including secrets)
* @NM_SETTING_HASH_FLAG_NO_SECRETS: do not include secrets
* @NM_SETTING_HASH_FLAG_ONLY_SECRETS: only hash secrets
*
* These flags determine which properties are added to the resulting hash
* when calling nm_setting_to_hash().
*
**/
typedef enum {
NM_SETTING_HASH_FLAG_ALL = 0x00000000,
NM_SETTING_HASH_FLAG_NO_SECRETS = 0x00000001,
NM_SETTING_HASH_FLAG_ONLY_SECRETS = 0x00000002,
} NMSettingHashFlags;
GHashTable *nm_setting_to_hash (NMSetting *setting,
NMSettingHashFlags flags);
NMSetting *nm_setting_new_from_hash (GType setting_type,
GHashTable *hash);
NMSetting *nm_setting_duplicate (NMSetting *setting);
const char *nm_setting_get_name (NMSetting *setting);
gboolean nm_setting_verify (NMSetting *setting,
GSList *all_settings,
GError **error);
gboolean nm_setting_compare (NMSetting *a,
NMSetting *b,
NMSettingCompareFlags flags);
/**
* NMSettingDiffResult:
* @NM_SETTING_DIFF_RESULT_UNKNOWN: unknown result
* @NM_SETTING_DIFF_RESULT_IN_A: the property is present in setting A
* @NM_SETTING_DIFF_RESULT_IN_B: the property is present in setting B
*
* These values indicate the result of a setting difference operation.
**/
typedef enum {
NM_SETTING_DIFF_RESULT_UNKNOWN = 0x00000000,
NM_SETTING_DIFF_RESULT_IN_A = 0x00000001,
NM_SETTING_DIFF_RESULT_IN_B = 0x00000002,
} NMSettingDiffResult;
gboolean nm_setting_diff (NMSetting *a,
NMSetting *b,
NMSettingCompareFlags flags,
gboolean invert_results,
GHashTable **results);
void nm_setting_enumerate_values (NMSetting *setting,
NMSettingValueIterFn func,
gpointer user_data);
char *nm_setting_to_string (NMSetting *setting);
/* Secrets */
void nm_setting_clear_secrets (NMSetting *setting);
void nm_setting_clear_secrets_with_flags (NMSetting *setting,
NMSettingClearSecretsWithFlagsFn func,
gpointer user_data);
GPtrArray *nm_setting_need_secrets (NMSetting *setting);
gboolean nm_setting_update_secrets (NMSetting *setting,
GHashTable *secrets,
GError **error);
gboolean nm_setting_get_secret_flags (NMSetting *setting,
const char *secret_name,
NMSettingSecretFlags *out_flags,
GError **error);
gboolean nm_setting_set_secret_flags (NMSetting *setting,
const char *secret_name,
NMSettingSecretFlags flags,
GError **error);
const char *nm_setting_get_virtual_iface_name (NMSetting *setting);
G_END_DECLS
#endif /* NM_SETTING_H */

View File

@@ -0,0 +1,65 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2005 - 2008 Red Hat, Inc.
*/
#ifndef __NM_UTILS_PRIVATE_H__
#define __NM_UTILS_PRIVATE_H__
#include "nm-setting-private.h"
gboolean _nm_utils_string_in_list (const char *str,
const char **valid_strings);
gboolean _nm_utils_string_slist_validate (GSList *list,
const char **valid_values);
gboolean _nm_utils_gvalue_array_validate (GValueArray *elements,
guint n_expected, ...);
void _nm_value_transforms_register (void);
/***********************************************************/
typedef struct NMUtilsPrivateData {
const char * (*nm_setting_ip4_config_get_address_label) (NMSettingIP4Config *setting,
guint32 i);
gboolean (*nm_setting_ip4_config_add_address_with_label) (NMSettingIP4Config *setting,
NMIP4Address *address,
const char *label);
} NMUtilsPrivateData;
const NMUtilsPrivateData *nm_utils_get_private (void);
/**
* NM_UTILS_PRIVATE_CALL:
* @call: a call to a private libnm-util function
*
* Used to call private libnm-util functions. Eg, if there was a
* private function called nm_foo_get_bar(), you could call it like:
*
* bar = NM_UTILS_PRIVATE_CALL (nm_foo_get_bar (foo, x, y, z));
*
* This macro only exists inside the NetworkManager source tree and
* is not part of the public API.
*
* Since: 0.9.10
*/
#define NM_UTILS_PRIVATE_CALL(call) (nm_utils_get_private ()->call)
#endif

2531
libnm-core/nm-utils.c Normal file

File diff suppressed because it is too large Load Diff

180
libnm-core/nm-utils.h Normal file
View File

@@ -0,0 +1,180 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2005 - 2013 Red Hat, Inc.
*/
#ifndef NM_UTILS_H
#define NM_UTILS_H
#include <glib.h>
#include "nm-connection.h"
#include "nm-utils-enum-types.h"
G_BEGIN_DECLS
/* init, deinit nm_utils */
gboolean nm_utils_init (GError **error);
void nm_utils_deinit (void);
/* SSID helpers */
gboolean nm_utils_is_empty_ssid (const guint8 *ssid, int len);
const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len);
gboolean nm_utils_same_ssid (const GByteArray *ssid1,
const GByteArray *ssid2,
gboolean ignore_trailing_null);
char * nm_utils_ssid_to_utf8 (const GByteArray *ssid);
GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash);
NM_DEPRECATED_IN_0_9_10
void nm_utils_slist_free (GSList *list, GDestroyNotify elem_destroy_fn);
/**
* NMUtilsSecurityType:
* @NMU_SEC_INVALID: unknown or invalid security, placeholder and not used
* @NMU_SEC_NONE: unencrypted and open
* @NMU_SEC_STATIC_WEP: static WEP keys are used for encryption
* @NMU_SEC_LEAP: Cisco LEAP is used for authentication and for generating the
* dynamic WEP keys automatically
* @NMU_SEC_DYNAMIC_WEP: standard 802.1x is used for authentication and
* generating the dynamic WEP keys automatically
* @NMU_SEC_WPA_PSK: WPA1 is used with Pre-Shared Keys (PSK)
* @NMU_SEC_WPA_ENTERPRISE: WPA1 is used with 802.1x authentication
* @NMU_SEC_WPA2_PSK: WPA2/RSN is used with Pre-Shared Keys (PSK)
* @NMU_SEC_WPA2_ENTERPRISE: WPA2 is used with 802.1x authentication
*
* Describes generic security mechanisms that 802.11 access points may offer.
* Used with nm_utils_security_valid() for checking whether a given access
* point is compatible with a network device.
**/
typedef enum {
NMU_SEC_INVALID = 0,
NMU_SEC_NONE,
NMU_SEC_STATIC_WEP,
NMU_SEC_LEAP,
NMU_SEC_DYNAMIC_WEP,
NMU_SEC_WPA_PSK,
NMU_SEC_WPA_ENTERPRISE,
NMU_SEC_WPA2_PSK,
NMU_SEC_WPA2_ENTERPRISE
} NMUtilsSecurityType;
gboolean nm_utils_security_valid (NMUtilsSecurityType type,
NMDeviceWifiCapabilities wifi_caps,
gboolean have_ap,
gboolean adhoc,
NM80211ApFlags ap_flags,
NM80211ApSecurityFlags ap_wpa,
NM80211ApSecurityFlags ap_rsn);
gboolean nm_utils_ap_mode_security_valid (NMUtilsSecurityType type,
NMDeviceWifiCapabilities wifi_caps);
gboolean nm_utils_wep_key_valid (const char *key, NMWepKeyType wep_type);
gboolean nm_utils_wpa_psk_valid (const char *psk);
GSList *nm_utils_ip4_addresses_from_gvalue (const GValue *value);
void nm_utils_ip4_addresses_to_gvalue (GSList *list, GValue *value);
GSList *nm_utils_ip4_routes_from_gvalue (const GValue *value);
void nm_utils_ip4_routes_to_gvalue (GSList *list, GValue *value);
guint32 nm_utils_ip4_netmask_to_prefix (guint32 netmask);
guint32 nm_utils_ip4_prefix_to_netmask (guint32 prefix);
guint32 nm_utils_ip4_get_default_prefix (guint32 ip);
GSList *nm_utils_ip6_addresses_from_gvalue (const GValue *value);
void nm_utils_ip6_addresses_to_gvalue (GSList *list, GValue *value);
GSList *nm_utils_ip6_routes_from_gvalue (const GValue *value);
void nm_utils_ip6_routes_to_gvalue (GSList *list, GValue *value);
GSList *nm_utils_ip6_dns_from_gvalue (const GValue *value);
void nm_utils_ip6_dns_to_gvalue (GSList *list, GValue *value);
char *nm_utils_uuid_generate (void);
char *nm_utils_uuid_generate_from_string (const char *s);
GByteArray *nm_utils_rsa_key_encrypt (const GByteArray *data,
const char *in_password,
char **out_password,
GError **error);
GByteArray *nm_utils_rsa_key_encrypt_aes (const GByteArray *data,
const char *in_password,
char **out_password,
GError **error);
gboolean nm_utils_file_is_pkcs12 (const char *filename);
guint32 nm_utils_wifi_freq_to_channel (guint32 freq);
guint32 nm_utils_wifi_channel_to_freq (guint32 channel, const char *band);
guint32 nm_utils_wifi_find_next_channel (guint32 channel, int direction, char *band);
gboolean nm_utils_wifi_is_channel_valid (guint32 channel, const char *band);
/**
* NM_UTILS_HWADDR_LEN_MAX:
*
* The maximum length of hardware addresses handled by NetworkManager itself,
* nm_utils_hwaddr_len(), and nm_utils_hwaddr_aton().
*/
#define NM_UTILS_HWADDR_LEN_MAX 20 /* INFINIBAND_ALEN */
int nm_utils_hwaddr_len (int type) G_GNUC_PURE;
NM_DEPRECATED_IN_0_9_10
int nm_utils_hwaddr_type (int len) G_GNUC_PURE;
char *nm_utils_hwaddr_ntoa (gconstpointer addr, int type);
GByteArray *nm_utils_hwaddr_atoba (const char *asc, int type);
guint8 *nm_utils_hwaddr_aton (const char *asc, int type, gpointer buffer);
NM_AVAILABLE_IN_0_9_10
char *nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length);
NM_AVAILABLE_IN_0_9_10
guint8 *nm_utils_hwaddr_aton_len (const char *asc, gpointer buffer, gsize length);
NM_AVAILABLE_IN_0_9_10
gboolean nm_utils_hwaddr_valid (const char *asc);
NM_AVAILABLE_IN_0_9_10
char *nm_utils_bin2hexstr (const char *bytes, int len, int final_len);
NM_AVAILABLE_IN_0_9_10
int nm_utils_hex2byte (const char *hex);
NM_AVAILABLE_IN_0_9_10
char *nm_utils_hexstr2bin (const char *hex, size_t len);
gboolean nm_utils_iface_valid_name(const char *name);
gboolean nm_utils_is_uuid (const char *str);
/**
* NM_UTILS_INET_ADDRSTRLEN:
*
* Defines the minimal length for a char buffer that is suitable as @dst argument
* for both nm_utils_inet4_ntop() and nm_utils_inet6_ntop().
**/
#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN
NM_AVAILABLE_IN_0_9_10
const char *nm_utils_inet4_ntop (in_addr_t inaddr, char *dst);
NM_AVAILABLE_IN_0_9_10
const char *nm_utils_inet6_ntop (const struct in6_addr *in6addr, char *dst);
NM_AVAILABLE_IN_0_9_10
gboolean nm_utils_check_virtual_device_compatibility (GType virtual_type, GType other_type);
G_END_DECLS
#endif /* NM_UTILS_H */

View File

@@ -0,0 +1,593 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2005 - 2014 Red Hat, Inc.
*/
#include "config.h"
#include <string.h>
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
static void
_nm_utils_convert_op_to_string (const GValue *src_value, GValue *dest_value)
{
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_OBJECT_PATH));
g_value_set_string (dest_value, (const char *) g_value_get_boxed (src_value));
}
static void
_nm_utils_convert_strv_to_slist (const GValue *src_value, GValue *dest_value)
{
char **str;
GSList *list = NULL;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), G_TYPE_STRV));
str = (char **) g_value_get_boxed (src_value);
while (str && str[i])
list = g_slist_prepend (list, g_strdup (str[i++]));
g_value_take_boxed (dest_value, g_slist_reverse (list));
}
static void
_nm_utils_convert_slist_to_strv (const GValue *src_value, GValue *dest_value)
{
GSList *slist;
char **strv;
int len, i = 0;
slist = g_value_get_boxed (src_value);
len = g_slist_length (slist);
strv = g_new (char *, len + 1);
for (i = 0; slist; slist = slist->next, i++)
strv[i] = g_strdup (slist->data);
strv[i] = NULL;
g_value_take_boxed (dest_value, strv);
}
static void
_nm_utils_convert_strv_to_ptrarray (const GValue *src_value, GValue *dest_value)
{
char **str;
GPtrArray *array = NULL;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), G_TYPE_STRV));
str = (char **) g_value_get_boxed (src_value);
array = g_ptr_array_sized_new (3);
while (str && str[i])
g_ptr_array_add (array, g_strdup (str[i++]));
g_value_take_boxed (dest_value, array);
}
static void
_nm_utils_convert_string_list_to_string (const GValue *src_value, GValue *dest_value)
{
GSList *strings;
GString *printable;
GSList *iter;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_LIST_OF_STRING));
strings = (GSList *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
for (iter = strings; iter; iter = iter->next) {
if (iter != strings)
g_string_append_c (printable, ',');
g_string_append (printable, iter->data ? iter->data : "(null)");
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_string_array_to_string (const GPtrArray *strings, GValue *dest_value)
{
GString *printable;
guint i;
printable = g_string_new (NULL);
for (i = 0; strings && i < strings->len; i++) {
if (i > 0)
g_string_append_c (printable, ',');
g_string_append (printable, strings->pdata[i]);
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_nm_utils_convert_string_array_to_string (const GValue *src_value, GValue *dest_value)
{
const GPtrArray *strings;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_STRING));
strings = (const GPtrArray *) g_value_get_boxed (src_value);
_string_array_to_string (strings, dest_value);
}
static void
_nm_utils_convert_op_array_to_string (const GValue *src_value, GValue *dest_value)
{
const GPtrArray *strings;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH));
strings = (const GPtrArray *) g_value_get_boxed (src_value);
_string_array_to_string (strings, dest_value);
}
static void
_nm_utils_convert_uint_array_to_string (const GValue *src_value, GValue *dest_value)
{
GArray *array;
GString *printable;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_UINT_ARRAY));
array = (GArray *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
while (array && (i < array->len)) {
guint32 addr;
if (i > 0)
g_string_append (printable, ", ");
addr = g_array_index (array, guint32, i++);
g_string_append (printable, nm_utils_inet4_ntop (addr, NULL));
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_nm_utils_convert_ip4_addr_route_struct_array_to_string (const GValue *src_value, GValue *dest_value)
{
GPtrArray *ptr_array;
GString *printable;
guint i = 0;
char buf[INET_ADDRSTRLEN];
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT));
ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
while (ptr_array && (i < ptr_array->len)) {
GArray *array;
gboolean is_addr; /* array contains address x route */
if (i > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
array = (GArray *) g_ptr_array_index (ptr_array, i++);
if (array->len < 2) {
g_string_append (printable, "invalid");
continue;
}
is_addr = (array->len < 4);
nm_utils_inet4_ntop (g_array_index (array, guint32, 0), buf);
if (is_addr)
g_string_append_printf (printable, "ip = %s", buf);
else
g_string_append_printf (printable, "dst = %s", buf);
g_string_append_printf (printable, "/%u",
g_array_index (array, guint32, 1));
if (array->len > 2) {
nm_utils_inet4_ntop (g_array_index (array, guint32, 2), buf);
if (is_addr)
g_string_append_printf (printable, ", gw = %s", buf);
else
g_string_append_printf (printable, ", nh = %s", buf);
}
if (array->len > 3) {
g_string_append_printf (printable, ", mt = %u",
g_array_index (array, guint32, 3));
}
g_string_append (printable, " }");
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
convert_one_gvalue_hash_entry (gpointer key, gpointer value, gpointer user_data)
{
GString *printable = (GString *) user_data;
char *value_as_string;
value_as_string = g_strdup_value_contents ((GValue *) value);
g_string_append_printf (printable, " { '%s': %s },", (const char *) key, value_as_string);
g_free (value_as_string);
}
static void
_nm_utils_convert_gvalue_hash_to_string (const GValue *src_value, GValue *dest_value)
{
GHashTable *hash;
GString *printable;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_MAP_OF_VARIANT));
hash = (GHashTable *) g_value_get_boxed (src_value);
printable = g_string_new ("[");
g_hash_table_foreach (hash, convert_one_gvalue_hash_entry, printable);
g_string_append (printable, " ]");
g_value_take_string (dest_value, printable->str);
g_string_free (printable, FALSE);
}
static void
convert_one_string_hash_entry (gpointer key, gpointer value, gpointer user_data)
{
GString *printable = (GString *) user_data;
if (printable->len)
g_string_append_c (printable, ',');
g_string_append_printf (printable, "%s=%s", (const char *) key, (const char *) value);
}
static void
_nm_utils_convert_string_hash_to_string (const GValue *src_value, GValue *dest_value)
{
GHashTable *hash;
GString *printable;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_MAP_OF_STRING));
hash = (GHashTable *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
if (hash)
g_hash_table_foreach (hash, convert_one_string_hash_entry, printable);
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_nm_utils_convert_byte_array_to_string (const GValue *src_value, GValue *dest_value)
{
GArray *array;
GString *printable;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_UCHAR_ARRAY));
array = (GArray *) g_value_get_boxed (src_value);
printable = g_string_new ("[");
if (array) {
while (i < MIN (array->len, 35)) {
if (i > 0)
g_string_append_c (printable, ' ');
g_string_append_printf (printable, "0x%02X",
g_array_index (array, unsigned char, i++));
}
if (i < array->len)
g_string_append (printable, " ... ");
}
g_string_append_c (printable, ']');
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_nm_utils_convert_ip6_dns_array_to_string (const GValue *src_value, GValue *dest_value)
{
GPtrArray *ptr_array;
GString *printable;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR));
ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
while (ptr_array && (i < ptr_array->len)) {
GByteArray *bytearray;
struct in6_addr *addr;
if (i > 0)
g_string_append (printable, ", ");
bytearray = (GByteArray *) g_ptr_array_index (ptr_array, i++);
if (bytearray->len != 16) {
g_string_append (printable, "invalid");
continue;
}
addr = (struct in6_addr *) bytearray->data;
g_string_append (printable, nm_utils_inet6_ntop (addr, NULL));
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_nm_utils_convert_ip6_addr_struct_array_to_string (const GValue *src_value, GValue *dest_value)
{
GPtrArray *ptr_array;
GString *printable;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS));
ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
while (ptr_array && (i < ptr_array->len)) {
GValueArray *elements;
GValue *tmp;
GByteArray *ba_addr;
struct in6_addr *addr;
guint32 prefix;
if (i > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
elements = (GValueArray *) g_ptr_array_index (ptr_array, i++);
if (!_nm_utils_gvalue_array_validate (elements, 3,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT,
DBUS_TYPE_G_UCHAR_ARRAY)) {
g_string_append (printable, "invalid }");
continue;
}
/* IPv6 address */
tmp = g_value_array_get_nth (elements, 0);
ba_addr = g_value_get_boxed (tmp);
if (ba_addr->len != 16) {
g_string_append (printable, "invalid }");
continue;
}
addr = (struct in6_addr *) ba_addr->data;
g_string_append_printf (printable, "ip = %s", nm_utils_inet6_ntop (addr, NULL));
/* Prefix */
tmp = g_value_array_get_nth (elements, 1);
prefix = g_value_get_uint (tmp);
if (prefix > 128) {
g_string_append (printable, "/invalid }");
continue;
}
g_string_append_printf (printable, "/%u", prefix);
g_string_append (printable, ", ");
/* IPv6 Gateway */
tmp = g_value_array_get_nth (elements, 2);
ba_addr = g_value_get_boxed (tmp);
if (ba_addr->len != 16) {
g_string_append (printable, "invalid }");
continue;
}
addr = (struct in6_addr *) ba_addr->data;
g_string_append_printf (printable, "gw = %s", nm_utils_inet6_ntop (addr, NULL));
g_string_append (printable, " }");
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
static void
_nm_utils_convert_ip6_route_struct_array_to_string (const GValue *src_value, GValue *dest_value)
{
GPtrArray *ptr_array;
GString *printable;
guint i = 0;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE));
ptr_array = (GPtrArray *) g_value_get_boxed (src_value);
printable = g_string_new (NULL);
while (ptr_array && (i < ptr_array->len)) {
GValueArray *elements;
GValue *tmp;
GByteArray *ba_addr;
struct in6_addr *addr;
guint32 prefix, metric;
if (i > 0)
g_string_append (printable, "; ");
g_string_append (printable, "{ ");
elements = (GValueArray *) g_ptr_array_index (ptr_array, i++);
if (!_nm_utils_gvalue_array_validate (elements, 4,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT,
DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_UINT)) {
g_string_append (printable, "invalid");
continue;
}
/* Destination address */
tmp = g_value_array_get_nth (elements, 0);
ba_addr = g_value_get_boxed (tmp);
if (ba_addr->len != 16) {
g_string_append (printable, "invalid");
continue;
}
addr = (struct in6_addr *) ba_addr->data;
g_string_append_printf (printable, "dst = %s", nm_utils_inet6_ntop (addr, NULL));
/* Prefix */
tmp = g_value_array_get_nth (elements, 1);
prefix = g_value_get_uint (tmp);
if (prefix > 128) {
g_string_append (printable, "/invalid");
continue;
}
g_string_append_printf (printable, "/%u", prefix);
g_string_append (printable, ", ");
/* Next hop addresses */
tmp = g_value_array_get_nth (elements, 2);
ba_addr = g_value_get_boxed (tmp);
if (ba_addr->len != 16) {
g_string_append (printable, "invalid");
continue;
}
addr = (struct in6_addr *) ba_addr->data;
g_string_append_printf (printable, "nh = %s", nm_utils_inet6_ntop (addr, NULL));
g_string_append (printable, ", ");
/* Metric */
tmp = g_value_array_get_nth (elements, 3);
metric = g_value_get_uint (tmp);
g_string_append_printf (printable, "mt = %u", metric);
g_string_append (printable, " }");
}
g_value_take_string (dest_value, g_string_free (printable, FALSE));
}
#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS))
static void
_nm_utils_convert_old_ip6_addr_array (const GValue *src_value, GValue *dst_value)
{
GPtrArray *src_outer_array;
GPtrArray *dst_outer_array;
guint i;
g_return_if_fail (g_type_is_a (G_VALUE_TYPE (src_value), OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS));
src_outer_array = (GPtrArray *) g_value_get_boxed (src_value);
dst_outer_array = g_ptr_array_new ();
for (i = 0; src_outer_array && (i < src_outer_array->len); i++) {
GValueArray *src_addr_array;
GValueArray *dst_addr_array;
GValue element = G_VALUE_INIT;
GValue *src_addr, *src_prefix;
GByteArray *ba;
src_addr_array = (GValueArray *) g_ptr_array_index (src_outer_array, i);
if (!_nm_utils_gvalue_array_validate (src_addr_array, 2, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT)) {
g_warning ("%s: invalid old IPv6 address type", __func__);
return;
}
dst_addr_array = g_value_array_new (3);
src_addr = g_value_array_get_nth (src_addr_array, 0);
g_value_array_append (dst_addr_array, src_addr);
src_prefix = g_value_array_get_nth (src_addr_array, 1);
g_value_array_append (dst_addr_array, src_prefix);
/* Blank Gateway */
g_value_init (&element, DBUS_TYPE_G_UCHAR_ARRAY);
ba = g_byte_array_new ();
g_byte_array_append (ba, (guint8 *) "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16);
g_value_take_boxed (&element, ba);
g_value_array_append (dst_addr_array, &element);
g_value_unset (&element);
g_ptr_array_add (dst_outer_array, dst_addr_array);
}
g_value_take_boxed (dst_value, dst_outer_array);
}
void
_nm_value_transforms_register (void)
{
static gboolean registered = FALSE;
if (G_UNLIKELY (!registered)) {
g_value_register_transform_func (DBUS_TYPE_G_OBJECT_PATH,
G_TYPE_STRING,
_nm_utils_convert_op_to_string);
g_value_register_transform_func (G_TYPE_STRV,
DBUS_TYPE_G_LIST_OF_STRING,
_nm_utils_convert_strv_to_slist);
g_value_register_transform_func (DBUS_TYPE_G_LIST_OF_STRING,
G_TYPE_STRV,
_nm_utils_convert_slist_to_strv);
g_value_register_transform_func (G_TYPE_STRV,
DBUS_TYPE_G_ARRAY_OF_STRING,
_nm_utils_convert_strv_to_ptrarray);
g_value_register_transform_func (DBUS_TYPE_G_LIST_OF_STRING,
G_TYPE_STRING,
_nm_utils_convert_string_list_to_string);
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_STRING,
G_TYPE_STRING,
_nm_utils_convert_string_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
G_TYPE_STRING,
_nm_utils_convert_op_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_UINT_ARRAY,
G_TYPE_STRING,
_nm_utils_convert_uint_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
G_TYPE_STRING,
_nm_utils_convert_ip4_addr_route_struct_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_VARIANT,
G_TYPE_STRING,
_nm_utils_convert_gvalue_hash_to_string);
g_value_register_transform_func (DBUS_TYPE_G_MAP_OF_STRING,
G_TYPE_STRING,
_nm_utils_convert_string_hash_to_string);
g_value_register_transform_func (DBUS_TYPE_G_UCHAR_ARRAY,
G_TYPE_STRING,
_nm_utils_convert_byte_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR,
G_TYPE_STRING,
_nm_utils_convert_ip6_dns_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
G_TYPE_STRING,
_nm_utils_convert_ip6_addr_struct_array_to_string);
g_value_register_transform_func (DBUS_TYPE_G_ARRAY_OF_IP6_ROUTE,
G_TYPE_STRING,
_nm_utils_convert_ip6_route_struct_array_to_string);
g_value_register_transform_func (OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS,
_nm_utils_convert_old_ip6_addr_array);
registered = TRUE;
}
}

123
libnm-core/nm-version.h.in Normal file
View File

@@ -0,0 +1,123 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 Red Hat, Inc.
*/
#ifndef NM_VERSION_H
#define NM_VERSION_H
/**
* NM_MAJOR_VERSION:
*
* Evaluates to the major version number of NetworkManager which this source
* is compiled against.
*/
#define NM_MAJOR_VERSION (@NM_MAJOR_VERSION@)
/**
* NM_MINOR_VERSION:
*
* Evaluates to the minor version number of NetworkManager which this source
* is compiled against.
*/
#define NM_MINOR_VERSION (@NM_MINOR_VERSION@)
/**
* NM_MICRO_VERSION:
*
* Evaluates to the micro version number of NetworkManager which this source
* compiled against.
*/
#define NM_MICRO_VERSION (@NM_MICRO_VERSION@)
/**
* NM_CHECK_VERSION:
* @major: major version (e.g. 1 for version 1.2.5)
* @minor: minor version (e.g. 2 for version 1.2.5)
* @micro: micro version (e.g. 5 for version 1.2.5)
*
* Returns: %TRUE if the version of the NetworkManager header files
* is the same as or newer than the passed-in version.
*/
#define NM_CHECK_VERSION(major,minor,micro) \
(NM_MAJOR_VERSION > (major) || \
(NM_MAJOR_VERSION == (major) && NM_MINOR_VERSION > (minor)) || \
(NM_MAJOR_VERSION == (major) && NM_MINOR_VERSION == (minor) && NM_MICRO_VERSION >= (micro)))
/* Deprecation / Availability macros */
#define NM_ENCODE_VERSION(major,minor,micro) ((major) << 16 | (minor) << 8 | (micro))
#define NM_VERSION_0_9_8 (NM_ENCODE_VERSION (0, 9, 8))
#define NM_VERSION_0_9_10 (NM_ENCODE_VERSION (0, 9, 10))
#define NM_VERSION_1_0 (NM_ENCODE_VERSION (1, 0, 0))
#define NM_VERSION_CUR_STABLE NM_VERSION_0_9_10
#define NM_VERSION_NEXT_STABLE NM_VERSION_1_0
#if !defined (NM_VERSION_MIN_REQUIRED) || (NM_VERSION_MIN_REQUIRED == 0)
# undef NM_VERSION_MIN_REQUIRED
# define NM_VERSION_MIN_REQUIRED (NM_VERSION_CUR_STABLE)
#endif
#if !defined (NM_VERSION_MAX_ALLOWED) || (NM_VERSION_MAX_ALLOWED == 0)
# undef NM_VERSION_MAX_ALLOWED
# define NM_VERSION_MAX_ALLOWED (NM_VERSION_CUR_STABLE)
#endif
/* sanity checks */
#if NM_VERSION_MIN_REQUIRED > NM_VERSION_NEXT_STABLE
#error "NM_VERSION_MIN_REQUIRED must be <= NM_VERSION_NEXT_STABLE"
#endif
#if NM_VERSION_MAX_ALLOWED < NM_VERSION_MIN_REQUIRED
#error "NM_VERSION_MAX_ALLOWED must be >= NM_VERSION_MIN_REQUIRED"
#endif
#if NM_VERSION_MIN_REQUIRED < NM_VERSION_0_9_8
#error "NM_VERSION_MIN_REQUIRED must be >= NM_VERSION_0_9_8"
#endif
#if NM_VERSION_MIN_REQUIRED >= NM_VERSION_0_9_10
# define NM_DEPRECATED_IN_0_9_10 G_DEPRECATED
# define NM_DEPRECATED_IN_0_9_10_FOR(f) G_DEPRECATED_FOR(f)
#else
# define NM_DEPRECATED_IN_0_9_10
# define NM_DEPRECATED_IN_0_9_10_FOR(f)
#endif
#if NM_VERSION_MIN_REQUIRED >= NM_VERSION_1_0
# define NM_DEPRECATED_IN_1_0 G_DEPRECATED
# define NM_DEPRECATED_IN_1_0_FOR(f) G_DEPRECATED_FOR(f)
#else
# define NM_DEPRECATED_IN_1_0
# define NM_DEPRECATED_IN_1_0_FOR(f)
#endif
#if NM_VERSION_MAX_ALLOWED < NM_VERSION_0_9_10
# define NM_AVAILABLE_IN_0_9_10 G_UNAVAILABLE(0.9,10)
#else
# define NM_AVAILABLE_IN_0_9_10
#endif
#if NM_VERSION_MAX_ALLOWED < NM_VERSION_1_0
# define NM_AVAILABLE_IN_1_0 G_UNAVAILABLE(1,0)
#else
# define NM_AVAILABLE_IN_1_0
#endif
#endif /* NM_VERSION_H */

View File

@@ -0,0 +1,384 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Dan Williams <dcbw@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2011 Red Hat, Inc.
*/
#include <glib.h>
#include <unistd.h>
#include <stdlib.h>
#include <glib/gi18n.h>
#include <stdio.h>
#include <string.h>
#include "crypto.h"
#include "nm-utils.h"
#include "nm-test-utils.h"
#if 0
static const char *pem_rsa_key_begin = "-----BEGIN RSA PRIVATE KEY-----";
static const char *pem_rsa_key_end = "-----END RSA PRIVATE KEY-----";
static const char *pem_dsa_key_begin = "-----BEGIN DSA PRIVATE KEY-----";
static const char *pem_dsa_key_end = "-----END DSA PRIVATE KEY-----";
static void
dump_key_to_pem (const char *key, gsize key_len, int key_type)
{
char *b64 = NULL;
GString *str = NULL;
const char *start_tag;
const char *end_tag;
char *p;
switch (key_type) {
case NM_CRYPTO_KEY_TYPE_RSA:
start_tag = pem_rsa_key_begin;
end_tag = pem_rsa_key_end;
break;
case NM_CRYPTO_KEY_TYPE_DSA:
start_tag = pem_dsa_key_begin;
end_tag = pem_dsa_key_end;
break;
default:
g_warning ("Unknown key type %d", key_type);
return;
}
b64 = g_base64_encode ((const unsigned char *) key, key_len);
if (!b64) {
g_warning ("Couldn't base64 encode the key.");
goto out;
}
str = g_string_new (NULL);
g_string_append (str, start_tag);
g_string_append_c (str, '\n');
for (p = b64; p < (b64 + strlen (b64)); p += 64) {
g_string_append_len (str, p, strnlen (p, 64));
g_string_append_c (str, '\n');
}
g_string_append (str, end_tag);
g_string_append_c (str, '\n');
g_message ("Decrypted private key:\n\n%s", str->str);
out:
g_free (b64);
if (str)
g_string_free (str, TRUE);
}
#endif
static void
test_load_cert (const char *path, const char *desc)
{
GByteArray *array;
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
GError *error = NULL;
array = crypto_load_and_verify_certificate (path, &format, &error);
ASSERT (array != NULL, desc,
"couldn't read certificate file '%s': %d %s",
path, error->code, error->message);
ASSERT (format == NM_CRYPTO_FILE_FORMAT_X509, desc,
"%s: unexpected certificate format (expected %d, got %d)",
path, NM_CRYPTO_FILE_FORMAT_X509, format);
g_byte_array_free (array, TRUE);
}
static GByteArray *
file_to_byte_array (const char *filename)
{
char *contents;
GByteArray *array = NULL;
gsize length = 0;
if (g_file_get_contents (filename, &contents, &length, NULL)) {
array = g_byte_array_sized_new (length);
g_byte_array_append (array, (guint8 *) contents, length);
g_assert (array->len == length);
g_free (contents);
}
return array;
}
static void
test_load_private_key (const char *path,
const char *password,
const char *decrypted_path,
gboolean expect_fail,
const char *desc)
{
NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN;
GByteArray *array, *decrypted;
GError *error = NULL;
array = crypto_decrypt_private_key (path, password, &key_type, &error);
if (expect_fail) {
ASSERT (array == NULL, desc,
"unexpected success reading private key file '%s' with "
"invalid password",
path);
ASSERT (key_type != NM_CRYPTO_KEY_TYPE_UNKNOWN, desc,
"unexpected failure determining private key file '%s' "
"type with invalid password (expected %d, got %d)",
path, NM_CRYPTO_KEY_TYPE_UNKNOWN, key_type);
return;
}
ASSERT (array != NULL, desc,
"couldn't read private key file '%s': %d %s",
path, error->code, error->message);
ASSERT (key_type == NM_CRYPTO_KEY_TYPE_RSA, desc,
"%s: unexpected private key type (expected %d, got %d)",
path, NM_CRYPTO_KEY_TYPE_RSA, key_type);
if (decrypted_path) {
/* Compare the crypto decrypted key against a known-good decryption */
decrypted = file_to_byte_array (decrypted_path);
ASSERT (decrypted != NULL, desc,
"couldn't read decrypted private key file '%s': %d %s",
decrypted_path, error->code, error->message);
ASSERT (decrypted->len > 0, desc, "decrypted key file invalid (size 0)");
ASSERT (decrypted->len == array->len,
desc, "decrypted key file (%d) and decrypted key data (%d) lengths don't match",
decrypted->len, array->len);
ASSERT (memcmp (decrypted->data, array->data, array->len) == 0,
desc, "decrypted key file and decrypted key data don't match");
g_byte_array_free (decrypted, TRUE);
}
g_byte_array_free (array, TRUE);
}
static void
test_load_pkcs12 (const char *path,
const char *password,
gboolean expect_fail,
const char *desc)
{
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
GError *error = NULL;
format = crypto_verify_private_key (path, password, &error);
if (expect_fail) {
ASSERT (format == NM_CRYPTO_FILE_FORMAT_UNKNOWN, desc,
"unexpected success reading PKCS#12 private key file "
"'%s' with invalid password",
path);
} else {
ASSERT (format == NM_CRYPTO_FILE_FORMAT_PKCS12, desc,
"%s: unexpected PKCS#12 private key file format (expected %d, got "
"%d): %d %s",
path, NM_CRYPTO_FILE_FORMAT_PKCS12, format, error->code, error->message);
}
}
static void
test_load_pkcs12_no_password (const char *path, const char *desc)
{
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
GError *error = NULL;
/* We should still get a valid returned crypto file format */
format = crypto_verify_private_key (path, NULL, &error);
ASSERT (format == NM_CRYPTO_FILE_FORMAT_PKCS12, desc,
"%s: unexpected PKCS#12 private key file format (expected %d, got "
"%d): %d %s",
path, NM_CRYPTO_FILE_FORMAT_PKCS12, format, error->code, error->message);
}
static void
test_is_pkcs12 (const char *path, gboolean expect_fail, const char *desc)
{
gboolean is_pkcs12;
is_pkcs12 = crypto_is_pkcs12_file (path, NULL);
if (expect_fail) {
ASSERT (is_pkcs12 == FALSE, desc,
"unexpected success reading non-PKCS#12 file '%s'",
path);
} else {
ASSERT (is_pkcs12 == TRUE, desc, "couldn't read PKCS#12 file '%s'", path);
}
}
static void
test_load_pkcs8 (const char *path,
const char *password,
gboolean expect_fail,
const char *desc)
{
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
GError *error = NULL;
format = crypto_verify_private_key (path, password, &error);
if (expect_fail) {
ASSERT (format == NM_CRYPTO_FILE_FORMAT_UNKNOWN, desc,
"unexpected success reading PKCS#8 private key file "
"'%s' with invalid password",
path);
} else {
ASSERT (format == NM_CRYPTO_FILE_FORMAT_RAW_KEY, desc,
"%s: unexpected PKCS#8 private key file format (expected %d, got "
"%d): %d %s",
path, NM_CRYPTO_FILE_FORMAT_RAW_KEY, format, error->code, error->message);
}
}
static gboolean
is_cipher_aes (const char *path)
{
char *contents;
gsize length = 0;
const char *cipher;
gboolean is_aes = FALSE;
if (!g_file_get_contents (path, &contents, &length, NULL))
return FALSE;
cipher = strstr (contents, "DEK-Info: ");
if (cipher) {
cipher += strlen ("DEK-Info: ");
if (g_str_has_prefix (cipher, "AES-128-CBC"))
is_aes = TRUE;
}
g_free (contents);
return is_aes;
}
static void
test_encrypt_private_key (const char *path,
const char *password,
const char *desc)
{
NMCryptoKeyType key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN;
GByteArray *array, *encrypted, *re_decrypted;
GError *error = NULL;
array = crypto_decrypt_private_key (path, password, &key_type, &error);
ASSERT (array != NULL, desc,
"couldn't read private key file '%s': %d %s",
path, error->code, error->message);
ASSERT (key_type == NM_CRYPTO_KEY_TYPE_RSA, desc,
"%s: unexpected private key type (expected %d, got %d)",
path, NM_CRYPTO_KEY_TYPE_RSA, key_type);
/* Now re-encrypt the private key */
if (is_cipher_aes (path))
encrypted = nm_utils_rsa_key_encrypt_aes (array, password, NULL, &error);
else
encrypted = nm_utils_rsa_key_encrypt (array, password, NULL, &error);
ASSERT (encrypted != NULL, desc,
"couldn't re-encrypt private key file '%s': %d %s",
path, error->code, error->message);
/* Then re-decrypt the private key */
key_type = NM_CRYPTO_KEY_TYPE_UNKNOWN;
re_decrypted = crypto_decrypt_private_key_data (encrypted, password, &key_type, &error);
ASSERT (re_decrypted != NULL, desc,
"couldn't read private key file '%s': %d %s",
path, error->code, error->message);
ASSERT (key_type == NM_CRYPTO_KEY_TYPE_RSA, desc,
"%s: unexpected private key type (expected %d, got %d)",
path, NM_CRYPTO_KEY_TYPE_RSA, key_type);
/* Compare the original decrypted key with the re-decrypted key */
ASSERT (array->len == re_decrypted->len, desc,
"%s: unexpected re-decrypted private key length (expected %d, got %d)",
path, array->len, re_decrypted->len);
ASSERT (!memcmp (array->data, re_decrypted->data, array->len), desc,
"%s: unexpected private key data",
path);
g_byte_array_free (re_decrypted, TRUE);
g_byte_array_free (encrypted, TRUE);
g_byte_array_free (array, TRUE);
}
int main (int argc, char **argv)
{
GError *error = NULL;
char *progname;
ASSERT (argc > 2, "test-crypto",
"wrong number of arguments (expected at least an operation and an object)");
if (!crypto_init (&error))
FAIL ("crypto-init", "failed to initialize crypto: %s", error->message);
if (!strcmp (argv[1], "--cert"))
test_load_cert (argv[2], "cert");
else if (!strcmp (argv[1], "--key")) {
const char *decrypted_path = (argc == 5) ? argv[4] : NULL;
ASSERT (argc == 4 || argc == 5, "test-crypto",
"wrong number of arguments (--key <key file> <password> [<decrypted key file>])");
test_is_pkcs12 (argv[2], TRUE, "not-pkcs12");
test_load_private_key (argv[2], argv[3], decrypted_path, FALSE, "private-key");
test_load_private_key (argv[2], "blahblahblah", NULL, TRUE, "private-key-bad-password");
test_load_private_key (argv[2], NULL, NULL, TRUE, "private-key-no-password");
test_encrypt_private_key (argv[2], argv[3], "private-key-rencrypt");
} else if (!strcmp (argv[1], "--p12")) {
test_is_pkcs12 (argv[2], FALSE, "is-pkcs12");
test_load_pkcs12 (argv[2], argv[3], FALSE, "pkcs12-private-key");
test_load_pkcs12 (argv[2], "blahblahblah", TRUE, "pkcs12-private-key-bad-password");
test_load_pkcs12_no_password (argv[2], "pkcs12-private-key-no-password");
} else if (!strcmp (argv[1], "--pkcs8")) {
ASSERT (argc == 4, "test-crypto",
"wrong number of arguments (--pkcs8 <key file> <password>)");
test_is_pkcs12 (argv[2], TRUE, "not-pkcs12");
test_load_pkcs8 (argv[2], argv[3], FALSE, "pkcs8-private-key");
/* Until gnutls and NSS grow support for all the ciphers that openssl
* can use with PKCS#8, we can't actually verify the password. So we
* expect a bad password to work for the time being.
*/
test_load_pkcs8 (argv[2], "blahblahblah", FALSE, "pkcs8-private-key-bad-password");
} else {
ASSERT (argc > 2, "test-crypto", "unknown test type (not --cert, --key, or --p12)");
}
crypto_deinit ();
progname = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", progname);
g_free (progname);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,754 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2008 - 2011 Red Hat, Inc.
*
*/
#include <glib.h>
#include <string.h>
#include <nm-utils.h>
#include "nm-setting-connection.h"
#include "nm-setting-wired.h"
#include "nm-setting-8021x.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
#include "nm-setting-cdma.h"
#include "nm-setting-gsm.h"
#include "nm-setting-ppp.h"
#include "nm-setting-pppoe.h"
#include "nm-setting-vpn.h"
#include "nm-test-utils.h"
#define TEST_NEED_SECRETS_EAP_TLS_CA_CERT TEST_CERT_DIR "/test_ca_cert.pem"
#define TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT TEST_CERT_DIR "/test_key_and_cert.pem"
#define TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY TEST_CERT_DIR "/test_key_and_cert.pem"
static gboolean
find_hints_item (GPtrArray *hints, const char *item)
{
int i;
for (i = 0; i < hints->len; i++) {
if (!strcmp (item, (const char *) g_ptr_array_index (hints, i)))
return TRUE;
}
return FALSE;
}
static NMConnection *
make_tls_connection (const char *detail, NMSetting8021xCKScheme scheme)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSetting8021x *s_8021x;
NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4;
char *uuid;
gboolean success;
GError *error = NULL;
connection = nm_connection_new ();
/* Connection setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
g_object_set (s_con,
NM_SETTING_CONNECTION_ID, "Test Need TLS Secrets",
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
NULL);
g_free (uuid);
/* Wired setting */
s_wired = (NMSettingWired *) nm_setting_wired_new ();
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* Wireless security setting */
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL);
nm_setting_802_1x_add_eap_method (s_8021x, "tls");
success = nm_setting_802_1x_set_ca_cert (s_8021x,
TEST_NEED_SECRETS_EAP_TLS_CA_CERT,
scheme,
NULL,
&error);
ASSERT (success == TRUE,
detail, "failed to set CA certificate '%s': %s",
TEST_NEED_SECRETS_EAP_TLS_CA_CERT, error->message);
success = nm_setting_802_1x_set_client_cert (s_8021x,
TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT,
scheme,
NULL,
&error);
ASSERT (success == TRUE,
detail, "failed to set client certificate '%s': %s",
TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT, error->message);
success = nm_setting_802_1x_set_private_key (s_8021x,
TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY,
"test",
scheme,
NULL,
&error);
ASSERT (success == TRUE,
detail, "failed to set private key '%s': %s",
TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY, error->message);
/* IP4 setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
detail, "failed to verify connection: %s",
(error && error->message) ? error->message : "(unknown)");
return connection;
}
static void
test_need_tls_secrets_path (void)
{
NMConnection *connection;
const char *setting_name;
GPtrArray *hints = NULL;
connection = make_tls_connection ("need-tls-secrets-path-key", NM_SETTING_802_1X_CK_SCHEME_PATH);
ASSERT (connection != NULL,
"need-tls-secrets-path-key",
"error creating test connection");
/* Ensure we don't need any secrets since we just set up the connection */
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name == NULL,
"need-tls-secrets-path-key",
"secrets are unexpectedly required");
ASSERT (hints == NULL,
"need-tls-secrets-path-key",
"hints should be NULL since no secrets were required");
/* Connection is good; clear secrets and ensure private key password is then required */
nm_connection_clear_secrets (connection);
hints = NULL;
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name != NULL,
"need-tls-secrets-path-key-password",
"unexpected secrets success");
ASSERT (strcmp (setting_name, NM_SETTING_802_1X_SETTING_NAME) == 0,
"need-tls-secrets-path-key-password",
"unexpected setting secrets required");
ASSERT (hints != NULL,
"need-tls-secrets-path-key-password",
"expected returned secrets hints");
ASSERT (find_hints_item (hints, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD),
"need-tls-secrets-path-key-password",
"expected to require private key password, but it wasn't");
g_object_unref (connection);
}
static void
test_need_tls_secrets_blob (void)
{
NMConnection *connection;
const char *setting_name;
GPtrArray *hints = NULL;
connection = make_tls_connection ("need-tls-secrets-blob-key", NM_SETTING_802_1X_CK_SCHEME_BLOB);
ASSERT (connection != NULL,
"need-tls-secrets-blob-key",
"error creating test connection");
/* Ensure we don't need any secrets since we just set up the connection */
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name == NULL,
"need-tls-secrets-blob-key",
"secrets are unexpectedly required");
ASSERT (hints == NULL,
"need-tls-secrets-blob-key",
"hints should be NULL since no secrets were required");
/* Clear secrets and ensure password is again required */
nm_connection_clear_secrets (connection);
hints = NULL;
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name != NULL,
"need-tls-secrets-blob-key-password",
"unexpected secrets success");
ASSERT (strcmp (setting_name, NM_SETTING_802_1X_SETTING_NAME) == 0,
"need-tls-secrets-blob-key-password",
"unexpected setting secrets required");
ASSERT (hints != NULL,
"need-tls-secrets-blob-key-password",
"expected returned secrets hints");
ASSERT (find_hints_item (hints, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD),
"need-tls-secrets-blob-key-password",
"expected to require private key password, but it wasn't");
g_object_unref (connection);
}
static NMConnection *
make_tls_phase2_connection (const char *detail, NMSetting8021xCKScheme scheme)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSetting8021x *s_8021x;
NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4;
char *uuid;
gboolean success;
GError *error = NULL;
connection = nm_connection_new ();
/* Connection setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
g_object_set (s_con,
NM_SETTING_CONNECTION_ID, "Test Need TLS Secrets",
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
NULL);
g_free (uuid);
/* Wired setting */
s_wired = (NMSettingWired *) nm_setting_wired_new ();
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* Wireless security setting */
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, "blahblah", NULL);
g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL);
nm_setting_802_1x_add_eap_method (s_8021x, "ttls");
g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "tls", NULL);
success = nm_setting_802_1x_set_phase2_ca_cert (s_8021x,
TEST_NEED_SECRETS_EAP_TLS_CA_CERT,
scheme,
NULL,
&error);
ASSERT (success == TRUE,
detail, "failed to set phase2 CA certificate '%s': %s",
TEST_NEED_SECRETS_EAP_TLS_CA_CERT, error->message);
success = nm_setting_802_1x_set_phase2_client_cert (s_8021x,
TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT,
scheme,
NULL,
&error);
ASSERT (success == TRUE,
detail, "failed to set phase2 client certificate '%s': %s",
TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT, error->message);
success = nm_setting_802_1x_set_phase2_private_key (s_8021x,
TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY,
"test",
scheme,
NULL,
&error);
ASSERT (success == TRUE,
detail, "failed to set phase2 private key '%s': %s",
TEST_NEED_SECRETS_EAP_TLS_PRIVATE_KEY, error->message);
/* IP4 setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
ASSERT (nm_connection_verify (connection, &error) == TRUE,
detail, "failed to verify connection: %s",
(error && error->message) ? error->message : "(unknown)");
return connection;
}
static void
test_need_tls_phase2_secrets_path (void)
{
NMConnection *connection;
const char *setting_name;
GPtrArray *hints = NULL;
connection = make_tls_phase2_connection ("need-tls-phase2-secrets-path-key",
NM_SETTING_802_1X_CK_SCHEME_PATH);
ASSERT (connection != NULL,
"need-tls-phase2-secrets-path-key",
"error creating test connection");
/* Ensure we don't need any secrets since we just set up the connection */
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name == NULL,
"need-tls-phase2-secrets-path-key",
"secrets are unexpectedly required");
ASSERT (hints == NULL,
"need-tls-phase2-secrets-path-key",
"hints should be NULL since no secrets were required");
/* Connection is good; clear secrets and ensure private key password is then required */
nm_connection_clear_secrets (connection);
hints = NULL;
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name != NULL,
"need-tls-phase2-secrets-path-key-password",
"unexpected secrets success");
ASSERT (strcmp (setting_name, NM_SETTING_802_1X_SETTING_NAME) == 0,
"need-tls-phase2-secrets-path-key-password",
"unexpected setting secrets required");
ASSERT (hints != NULL,
"need-tls-phase2-secrets-path-key-password",
"expected returned secrets hints");
ASSERT (find_hints_item (hints, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD),
"need-tls-phase2-secrets-path-key-password",
"expected to require private key password, but it wasn't");
g_object_unref (connection);
}
static void
test_need_tls_phase2_secrets_blob (void)
{
NMConnection *connection;
const char *setting_name;
GPtrArray *hints = NULL;
connection = make_tls_phase2_connection ("need-tls-phase2-secrets-blob-key",
NM_SETTING_802_1X_CK_SCHEME_BLOB);
ASSERT (connection != NULL,
"need-tls-phase2-secrets-blob-key",
"error creating test connection");
/* Ensure we don't need any secrets since we just set up the connection */
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name == NULL,
"need-tls-phase2-secrets-blob-key",
"secrets are unexpectedly required");
ASSERT (hints == NULL,
"need-tls-phase2-secrets-blob-key",
"hints should be NULL since no secrets were required");
/* Connection is good; clear secrets and ensure private key password is then required */
nm_connection_clear_secrets (connection);
hints = NULL;
setting_name = nm_connection_need_secrets (connection, &hints);
ASSERT (setting_name != NULL,
"need-tls-phase2-secrets-blob-key-password",
"unexpected secrets success");
ASSERT (strcmp (setting_name, NM_SETTING_802_1X_SETTING_NAME) == 0,
"need-tls-phase2-secrets-blob-key-password",
"unexpected setting secrets required");
ASSERT (hints != NULL,
"need-tls-phase2-secrets-blob-key-password",
"expected returned secrets hints");
ASSERT (find_hints_item (hints, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD),
"need-tls-phase2-secrets-blob-key-password",
"expected to require private key password, but it wasn't");
g_object_unref (connection);
}
static NMConnection *
wifi_connection_new (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
unsigned char tmpssid[] = { 0x31, 0x33, 0x33, 0x37 };
char *uuid;
GByteArray *ssid;
connection = nm_connection_new ();
g_assert (connection);
/* Connection setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
g_assert (s_con);
uuid = nm_utils_uuid_generate ();
g_object_set (s_con,
NM_SETTING_CONNECTION_ID, "Test Wireless",
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
NULL);
g_free (uuid);
nm_connection_add_setting (connection, NM_SETTING (s_con));
/* Wireless setting */
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
g_assert (s_wifi);
ssid = g_byte_array_sized_new (sizeof (tmpssid));
g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid));
g_object_set (s_wifi,
NM_SETTING_WIRELESS_SSID, ssid,
NULL);
g_byte_array_free (ssid, TRUE);
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
/* Wifi security */
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
g_assert (s_wsec);
g_object_set (G_OBJECT (s_wsec),
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
NULL);
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
return connection;
}
static void
value_destroy (gpointer data)
{
GValue *value = (GValue *) data;
g_value_unset (value);
g_slice_free (GValue, value);
}
static GValue *
string_to_gvalue (const char *str)
{
GValue *val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_STRING);
g_value_set_string (val, str);
return val;
}
static GValue *
uint_to_gvalue (guint32 i)
{
GValue *val;
val = g_slice_new0 (GValue);
g_value_init (val, G_TYPE_UINT);
g_value_set_uint (val, i);
return val;
}
static void
test_update_secrets_wifi_single_setting (void)
{
NMConnection *connection;
NMSettingWirelessSecurity *s_wsec;
GHashTable *secrets;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
const char *tmp;
/* Test update with a hashed setting of 802-11-wireless secrets */
connection = wifi_connection_new ();
/* Build up the secrets hash */
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY));
success = nm_connection_update_secrets (connection,
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
secrets,
&error);
g_assert_no_error (error);
g_assert (success);
/* Make sure the secret is now in the connection */
s_wsec = nm_connection_get_setting_wireless_security (connection);
g_assert (s_wsec);
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 0);
g_assert_cmpstr (tmp, ==, wepkey);
g_object_unref (connection);
}
static void
test_update_secrets_wifi_full_hash (void)
{
NMConnection *connection;
NMSettingWirelessSecurity *s_wsec;
GHashTable *secrets, *all;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
const char *tmp;
/* Test update with a hashed connection containing only 802-11-wireless
* setting and secrets.
*/
connection = wifi_connection_new ();
/* Build up the secrets hash */
all = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) g_hash_table_destroy);
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY));
g_hash_table_insert (all, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, secrets);
success = nm_connection_update_secrets (connection,
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
all,
&error);
g_assert_no_error (error);
g_assert (success);
/* Make sure the secret is now in the connection */
s_wsec = nm_connection_get_setting_wireless_security (connection);
g_assert (s_wsec);
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 0);
g_assert_cmpstr (tmp, ==, wepkey);
g_object_unref (connection);
}
static void
test_update_secrets_wifi_bad_setting_name (void)
{
NMConnection *connection;
GHashTable *secrets;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
/* Test that passing an invalid setting name to
* nm_connection_update_secrets() fails with the correct error.
*/
connection = wifi_connection_new ();
/* Build up the secrets hash */
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY));
success = nm_connection_update_secrets (connection,
"asdfasdfasdfasf",
secrets,
&error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (success == FALSE);
g_object_unref (connection);
}
static void
test_update_secrets_whole_connection (void)
{
NMConnection *connection;
NMSettingWirelessSecurity *s_wsec;
GHashTable *secrets, *wsec_hash;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
/* Test calling nm_connection_update_secrets() with an entire hashed
* connection including non-secrets.
*/
connection = wifi_connection_new ();
/* Build up the secrets hash */
secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_assert (wsec_hash);
g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_no_error (error);
g_assert (success == TRUE);
s_wsec = nm_connection_get_setting_wireless_security (connection);
g_assert (s_wsec);
g_assert_cmpstr (nm_setting_wireless_security_get_wep_key (s_wsec, 0), ==, wepkey);
g_object_unref (connection);
}
static void
test_update_secrets_whole_connection_empty_hash (void)
{
NMConnection *connection;
GHashTable *secrets;
GError *error = NULL;
gboolean success;
/* Test that updating secrets with an empty hash returns success */
connection = wifi_connection_new ();
secrets = g_hash_table_new (g_str_hash, g_str_equal);
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_no_error (error);
g_assert (success == TRUE);
g_object_unref (connection);
}
static void
test_update_secrets_whole_connection_bad_setting (void)
{
NMConnection *connection;
GHashTable *secrets, *wsec_hash;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
/* Test that sending a hashed connection containing an invalid setting
* name fails with the right error.
*/
connection = wifi_connection_new ();
/* Build up the secrets hash */
secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_assert (wsec_hash);
g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
/* Steal the wsec setting hash so it's not deallocated, and stuff it back
* in with a different name so we ensure libnm-util is returning the right
* error when it finds an entry in the connection hash that doesn't match
* any setting in the connection.
*/
g_hash_table_steal (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_hash_table_insert (secrets, "asdfasdfasdfasdf", wsec_hash);
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (success == FALSE);
g_object_unref (connection);
}
static void
test_update_secrets_whole_connection_empty_base_setting (void)
{
NMConnection *connection;
GHashTable *secrets;
GError *error = NULL;
gboolean success;
/* Test that a hashed connection which does not have any hashed secrets
* for the requested setting returns success.
*/
connection = wifi_connection_new ();
secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ONLY_SECRETS);
g_assert_cmpint (g_hash_table_size (secrets), ==, 1);
g_assert (g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SETTING_NAME));
success = nm_connection_update_secrets (connection,
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
secrets,
&error);
g_assert_no_error (error);
g_assert (success);
g_hash_table_destroy (secrets);
g_object_unref (connection);
}
static void
test_update_secrets_null_setting_name_with_setting_hash (void)
{
NMConnection *connection;
GHashTable *secrets;
GError *error = NULL;
gboolean success;
const char *wepkey = "11111111111111111111111111";
/* Ensure that a NULL setting name and only a hashed setting fails */
connection = wifi_connection_new ();
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY));
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (!success);
g_hash_table_destroy (secrets);
g_object_unref (connection);
}
int main (int argc, char **argv)
{
GError *error = NULL;
char *base;
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
/* The tests */
test_need_tls_secrets_path ();
test_need_tls_secrets_blob ();
test_need_tls_phase2_secrets_path ();
test_need_tls_phase2_secrets_blob ();
test_update_secrets_wifi_single_setting ();
test_update_secrets_wifi_full_hash ();
test_update_secrets_wifi_bad_setting_name ();
test_update_secrets_whole_connection ();
test_update_secrets_whole_connection_empty_hash ();
test_update_secrets_whole_connection_bad_setting ();
test_update_secrets_whole_connection_empty_base_setting ();
test_update_secrets_null_setting_name_with_setting_hash ();
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
g_free (base);
return 0;
}

View File

@@ -0,0 +1,443 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2008 - 2011 Red Hat, Inc.
*
*/
#include <glib.h>
#include <string.h>
#include <nm-utils.h>
#include "nm-setting-connection.h"
#include "nm-setting-8021x.h"
#include "nm-test-utils.h"
static void
compare_blob_data (const char *test,
const char *key_path,
const GByteArray *key)
{
char *contents = NULL;
gsize len = 0;
GError *error = NULL;
gboolean success;
success = g_file_get_contents (key_path, &contents, &len, &error);
ASSERT (success == TRUE,
test, "failed to read blob key file: %s", error->message);
ASSERT (len > 0, test, "blob key file invalid (size 0)");
ASSERT (len == key->len,
test, "blob key file (%d) and setting key data (%d) lengths don't match",
len, key->len);
ASSERT (memcmp (contents, key->data, len) == 0,
test, "blob key file and blob key data don't match");
g_free (contents);
}
#define SCHEME_PATH "file://"
static void
check_scheme_path (GByteArray *value, const char *path)
{
guint8 *p = value->data;
g_assert (memcmp (p, SCHEME_PATH, strlen (SCHEME_PATH)) == 0);
p += strlen (SCHEME_PATH);
g_assert (memcmp (p, path, strlen (path)) == 0);
p += strlen (path);
g_assert (*p == '\0');
}
static void
test_private_key_import (const char *path,
const char *password,
NMSetting8021xCKScheme scheme)
{
NMSetting8021x *s_8021x;
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
NMSetting8021xCKFormat tmp_fmt;
GError *error = NULL;
GByteArray *tmp_key = NULL, *client_cert = NULL;
const char *pw;
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
ASSERT (s_8021x != NULL, "private-key-import", "setting was NULL");
success = nm_setting_802_1x_set_private_key (s_8021x,
path,
password,
scheme,
&format,
&error);
ASSERT (success == TRUE,
"private-key-import", "error reading private key: %s", error->message);
ASSERT (format != NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"private-key-import", "unexpected private key format (got %d)", format);
tmp_fmt = nm_setting_802_1x_get_private_key_format (s_8021x);
ASSERT (tmp_fmt == format,
"private-key-import", "unexpected re-read private key format (expected %d, got %d)",
format, tmp_fmt);
/* Make sure the password is what we expect */
pw = nm_setting_802_1x_get_private_key_password (s_8021x);
ASSERT (pw != NULL,
"private-key-import", "failed to get previous private key password");
ASSERT (strcmp (pw, password) == 0,
"private-key-import", "failed to compare private key password");
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) {
tmp_key = (GByteArray *) nm_setting_802_1x_get_private_key_blob (s_8021x);
ASSERT (tmp_key != NULL, "private-key-import", "missing private key blob");
compare_blob_data ("private-key-import", path, tmp_key);
} else if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) {
g_object_get (s_8021x, NM_SETTING_802_1X_PRIVATE_KEY, &tmp_key, NULL);
ASSERT (tmp_key != NULL, "private-key-import", "missing private key value");
check_scheme_path (tmp_key, path);
g_byte_array_free (tmp_key, TRUE);
} else
g_assert_not_reached ();
/* If it's PKCS#12 ensure the client cert is the same value */
if (format == NM_SETTING_802_1X_CK_FORMAT_PKCS12) {
g_object_get (s_8021x, NM_SETTING_802_1X_PRIVATE_KEY, &tmp_key, NULL);
ASSERT (tmp_key != NULL, "private-key-import", "missing private key value");
g_object_get (s_8021x, NM_SETTING_802_1X_CLIENT_CERT, &client_cert, NULL);
ASSERT (client_cert != NULL, "private-key-import", "missing client certificate value");
/* make sure they are the same */
ASSERT (tmp_key->len == client_cert->len,
"private-key-import", "unexpected different private key and client cert lengths");
ASSERT (memcmp (tmp_key->data, client_cert->data, tmp_key->len) == 0,
"private-key-import", "unexpected different private key and client cert data");
g_byte_array_free (tmp_key, TRUE);
g_byte_array_free (client_cert, TRUE);
}
g_object_unref (s_8021x);
}
static void
test_phase2_private_key_import (const char *path,
const char *password,
NMSetting8021xCKScheme scheme)
{
NMSetting8021x *s_8021x;
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
NMSetting8021xCKFormat tmp_fmt;
GError *error = NULL;
GByteArray *tmp_key = NULL, *client_cert = NULL;
const char *pw;
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
ASSERT (s_8021x != NULL, "phase2-private-key-import", "setting was NULL");
success = nm_setting_802_1x_set_phase2_private_key (s_8021x,
path,
password,
scheme,
&format,
&error);
ASSERT (success == TRUE,
"phase2-private-key-import", "error reading private key: %s", error->message);
ASSERT (format != NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"phase2-private-key-import", "unexpected private key format");
tmp_fmt = nm_setting_802_1x_get_phase2_private_key_format (s_8021x);
ASSERT (tmp_fmt == format,
"phase2-private-key-import", "unexpected re-read private key format (expected %d, got %d)",
format, tmp_fmt);
/* Make sure the password is what we expect */
pw = nm_setting_802_1x_get_phase2_private_key_password (s_8021x);
ASSERT (pw != NULL,
"phase2-private-key-import", "failed to get previous private key password");
ASSERT (strcmp (pw, password) == 0,
"phase2-private-key-import", "failed to compare private key password");
if (scheme == NM_SETTING_802_1X_CK_SCHEME_BLOB) {
tmp_key = (GByteArray *) nm_setting_802_1x_get_phase2_private_key_blob (s_8021x);
ASSERT (tmp_key != NULL, "phase2-private-key-import", "missing private key blob");
compare_blob_data ("phase2-private-key-import", path, tmp_key);
} else if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) {
g_object_get (s_8021x, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, &tmp_key, NULL);
ASSERT (tmp_key != NULL, "phase2-private-key-import", "missing private key value");
check_scheme_path (tmp_key, path);
} else
g_assert_not_reached ();
/* If it's PKCS#12 ensure the client cert is the same value */
if (format == NM_SETTING_802_1X_CK_FORMAT_PKCS12) {
g_object_get (s_8021x, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, &tmp_key, NULL);
ASSERT (tmp_key != NULL, "private-key-import", "missing private key value");
g_object_get (s_8021x, NM_SETTING_802_1X_PHASE2_CLIENT_CERT, &client_cert, NULL);
ASSERT (client_cert != NULL, "private-key-import", "missing client certificate value");
/* make sure they are the same */
ASSERT (tmp_key->len == client_cert->len,
"private-key-import", "unexpected different private key and client cert lengths");
ASSERT (memcmp (tmp_key->data, client_cert->data, tmp_key->len) == 0,
"private-key-import", "unexpected different private key and client cert data");
g_byte_array_free (tmp_key, TRUE);
g_byte_array_free (client_cert, TRUE);
}
g_object_unref (s_8021x);
}
static void
test_wrong_password_keeps_data (const char *path, const char *password)
{
NMSetting8021x *s_8021x;
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
GError *error = NULL;
const char *pw;
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
ASSERT (s_8021x != NULL, "wrong-password-keeps-data", "setting was NULL");
success = nm_setting_802_1x_set_private_key (s_8021x,
path,
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
&error);
ASSERT (success == TRUE,
"wrong-password-keeps-data", "error reading private key: %s", error->message);
ASSERT (format != NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-password-keeps-data", "unexpected private key format (got %d)", format);
/* Now try to set it to something that's not a certificate */
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_private_key (s_8021x,
"Makefile.am",
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
&error);
ASSERT (success == FALSE,
"wrong-password-keeps-data", "unexpected success reading private key");
ASSERT (error != NULL,
"wrong-password-keeps-data", "unexpected missing error");
ASSERT (format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-password-keeps-data", "unexpected success reading private key format");
/* Make sure the password hasn't changed */
pw = nm_setting_802_1x_get_private_key_password (s_8021x);
ASSERT (pw != NULL,
"wrong-password-keeps-data", "failed to get previous private key password");
ASSERT (strcmp (pw, password) == 0,
"wrong-password-keeps-data", "failed to compare private key password");
g_object_unref (s_8021x);
}
static void
test_clear_private_key (const char *path, const char *password)
{
NMSetting8021x *s_8021x;
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
GError *error = NULL;
const char *pw;
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
ASSERT (s_8021x != NULL, "clear-private-key", "setting was NULL");
success = nm_setting_802_1x_set_private_key (s_8021x,
path,
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
&error);
ASSERT (success == TRUE,
"clear-private-key", "error reading private key: %s", error->message);
ASSERT (format != NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"clear-private-key", "unexpected private key format (got %d)", format);
/* Make sure the password is what we expect */
pw = nm_setting_802_1x_get_private_key_password (s_8021x);
ASSERT (pw != NULL,
"clear-private-key", "failed to get previous private key password");
ASSERT (strcmp (pw, password) == 0,
"clear-private-key", "failed to compare private key password");
/* Now clear it */
success = nm_setting_802_1x_set_private_key (s_8021x,
NULL,
NULL,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
NULL,
&error);
ASSERT (success == TRUE,
"clear-private-key", "unexpected failure clearing private key");
ASSERT (error == NULL,
"clear-private-key", "unexpected error clearing private key");
/* Ensure the password is also now clear */
ASSERT (nm_setting_802_1x_get_private_key_password (s_8021x) == NULL,
"clear-private-key", "unexpected private key password");
g_object_unref (s_8021x);
}
static void
test_wrong_phase2_password_keeps_data (const char *path, const char *password)
{
NMSetting8021x *s_8021x;
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
GError *error = NULL;
const char *pw;
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
ASSERT (s_8021x != NULL, "wrong-phase2-password-keeps-data", "setting was NULL");
success = nm_setting_802_1x_set_phase2_private_key (s_8021x,
path,
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
&error);
ASSERT (success == TRUE,
"wrong-phase2-password-keeps-data", "error reading private key: %s", error->message);
ASSERT (format != NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-phase2-password-keeps-data", "unexpected private key format (got %d)", format);
/* Now try to set it to something that's not a certificate */
format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
success = nm_setting_802_1x_set_phase2_private_key (s_8021x,
"Makefile.am",
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
&error);
ASSERT (success == FALSE,
"wrong-phase2-password-keeps-data", "unexpected success reading private key");
ASSERT (error != NULL,
"wrong-phase2-password-keeps-data", "unexpected missing error");
ASSERT (format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-phase2-password-keeps-data", "unexpected success reading private key format");
/* Make sure the password hasn't changed */
pw = nm_setting_802_1x_get_phase2_private_key_password (s_8021x);
ASSERT (pw != NULL,
"wrong-phase2-password-keeps-data", "failed to get previous private key password");
ASSERT (strcmp (pw, password) == 0,
"wrong-phase2-password-keeps-data", "failed to compare private key password");
g_object_unref (s_8021x);
}
static void
test_clear_phase2_private_key (const char *path, const char *password)
{
NMSetting8021x *s_8021x;
gboolean success;
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
GError *error = NULL;
const char *pw;
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
ASSERT (s_8021x != NULL, "clear-phase2-private-key", "setting was NULL");
success = nm_setting_802_1x_set_phase2_private_key (s_8021x,
path,
password,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
&format,
&error);
ASSERT (success == TRUE,
"clear-phase2-private-key", "error reading private key: %s", error->message);
ASSERT (format != NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"clear-phase2-private-key", "unexpected private key format (got %d)", format);
/* Make sure the password is what we expect */
pw = nm_setting_802_1x_get_phase2_private_key_password (s_8021x);
ASSERT (pw != NULL,
"clear-phase2-private-key", "failed to get previous private key password");
ASSERT (strcmp (pw, password) == 0,
"clear-phase2-private-key", "failed to compare private key password");
/* Now clear it */
success = nm_setting_802_1x_set_phase2_private_key (s_8021x,
NULL,
NULL,
NM_SETTING_802_1X_CK_SCHEME_BLOB,
NULL,
&error);
ASSERT (success == TRUE,
"clear-phase2-private-key", "unexpected failure clearing private key");
ASSERT (error == NULL,
"clear-phase2-private-key", "unexpected error clearing private key");
/* Ensure the password is also now clear */
ASSERT (nm_setting_802_1x_get_phase2_private_key_password (s_8021x) == NULL,
"clear-phase2-private-key", "unexpected private key password");
g_object_unref (s_8021x);
}
int main (int argc, char **argv)
{
GError *error = NULL;
char *base;
if (argc < 3)
FAIL ("init", "need at least two arguments: <path> <password>");
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
/* Test phase1 and phase2 path scheme */
test_private_key_import (argv[1], argv[2], NM_SETTING_802_1X_CK_SCHEME_PATH);
test_phase2_private_key_import (argv[1], argv[2], NM_SETTING_802_1X_CK_SCHEME_PATH);
/* Test phase1 and phase2 blob scheme */
test_private_key_import (argv[1], argv[2], NM_SETTING_802_1X_CK_SCHEME_BLOB);
test_phase2_private_key_import (argv[1], argv[2], NM_SETTING_802_1X_CK_SCHEME_BLOB);
/* Test that using a wrong password does not change existing data */
test_wrong_password_keeps_data (argv[1], argv[2]);
test_wrong_phase2_password_keeps_data (argv[1], argv[2]);
/* Test clearing the private key */
test_clear_private_key (argv[1], argv[2]);
test_clear_phase2_private_key (argv[1], argv[2]);
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
g_free (base);
return 0;
}

View File

@@ -0,0 +1,328 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*
*/
#include <glib.h>
#include <string.h>
#include <nm-utils.h>
#include <nm-glib-compat.h>
#include "nm-setting-dcb.h"
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
NM_SETTING_DCB_FLAG_ADVERTISE | \
NM_SETTING_DCB_FLAG_WILLING)
static void
test_dcb_flags_valid (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
guint i;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_app_iscsi_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_priority_flow_control_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_priority_group_flags (s_dcb), ==, 0);
g_object_set (G_OBJECT (s_dcb),
NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_APP_ISCSI_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_APP_FIP_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, DCB_FLAGS_ALL,
NULL);
/* Priority Group Bandwidth must total 100% */
for (i = 0; i < 7; i++)
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, 12);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16);
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
g_assert_no_error (error);
g_assert (success);
g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_app_iscsi_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_priority_flow_control_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_priority_group_flags (s_dcb), ==, DCB_FLAGS_ALL);
}
#define TEST_FLAG(p, f, v) \
{ \
/* GObject property min/max should ensure the property does not get set to \
* the invalid value, so we ensure the value we just tried to set is 0 and \
* that verify is successful since the property never got set. \
*/ \
g_object_set (G_OBJECT (s_dcb), p, v, NULL); \
g_assert_cmpint (f (s_dcb), ==, 0); \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_no_error (error); \
g_assert (success); \
}
static void
test_dcb_flags_invalid (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
TEST_FLAG (NM_SETTING_DCB_APP_FCOE_FLAGS, nm_setting_dcb_get_app_fcoe_flags, 0x332523);
g_test_assert_expected_messages ();
g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
TEST_FLAG (NM_SETTING_DCB_APP_ISCSI_FLAGS, nm_setting_dcb_get_app_iscsi_flags, 0xFF);
g_test_assert_expected_messages ();
g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
TEST_FLAG (NM_SETTING_DCB_APP_FIP_FLAGS, nm_setting_dcb_get_app_fip_flags, 0x1111);
g_test_assert_expected_messages ();
g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
TEST_FLAG (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, nm_setting_dcb_get_priority_flow_control_flags, G_MAXUINT32);
g_test_assert_expected_messages ();
g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
TEST_FLAG (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, nm_setting_dcb_get_priority_group_flags,
(NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) + 1);
g_test_assert_expected_messages ();
}
#define TEST_APP_PRIORITY(lcprop, ucprop, v) \
{ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_FLAGS, NM_SETTING_DCB_FLAG_NONE, NULL); \
\
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_PRIORITY, v, NULL); \
g_assert_cmpint (nm_setting_dcb_get_app_##lcprop##_priority (s_dcb), ==, v); \
\
/* Assert that the setting is invalid while the app is disabled unless v is default */ \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
if (v >= 0) { \
g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY); \
g_assert (success == FALSE); \
} else { \
g_assert_no_error (error); \
g_assert (success); \
} \
g_clear_error (&error); \
\
/* Set the enable flag and re-verify, this time it should be valid */ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL); \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_no_error (error); \
g_assert (success); \
\
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_PRIORITY, 0, NULL); \
}
static void
test_dcb_app_priorities (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
/* Defaults */
g_assert_cmpint (nm_setting_dcb_get_app_fcoe_priority (s_dcb), ==, -1);
g_assert_cmpint (nm_setting_dcb_get_app_iscsi_priority (s_dcb), ==, -1);
g_assert_cmpint (nm_setting_dcb_get_app_fip_priority (s_dcb), ==, -1);
TEST_APP_PRIORITY (fcoe, FCOE, 6);
TEST_APP_PRIORITY (iscsi, ISCSI, 5);
TEST_APP_PRIORITY (fip, FIP, 4);
TEST_APP_PRIORITY (fcoe, FCOE, -1);
TEST_APP_PRIORITY (iscsi, ISCSI, -1);
TEST_APP_PRIORITY (fip, FIP, -1);
}
#define TEST_PRIORITY_VALID(fn, id, val, flagsprop, verify) \
{ \
/* Assert that setting the value gets the same value back out */ \
nm_setting_dcb_set_priority_##fn (s_dcb, id, val); \
g_assert_cmpint (nm_setting_dcb_get_priority_##fn (s_dcb, id), ==, val); \
\
if (verify) { \
if (val != 0) { \
/* Assert that verify fails because the flags do not include 'enabled' \
* and a value has been set. \
*/ \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY); \
g_assert (success == FALSE); \
g_clear_error (&error); \
} \
\
/* Assert that adding the 'enabled' flag verifies the setting */ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_##flagsprop##_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL); \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_no_error (error); \
g_assert (success); \
} \
\
/* Reset everything */ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_##flagsprop##_FLAGS, NM_SETTING_DCB_FLAG_NONE, NULL); \
nm_setting_dcb_set_priority_##fn (s_dcb, id, 0); \
}
/* If Priority Groups are enabled, PG bandwidth must equal 100% */
#define SET_VALID_PRIORITY_GROUP_BANDWIDTH \
{ \
guint x; \
for (x = 0; x < 7; x++) \
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, x, 12); \
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16); \
}
static void
test_dcb_priorities_valid (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
guint i;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
for (i = 0; i < 8; i++)
TEST_PRIORITY_VALID (flow_control, i, TRUE, FLOW_CONTROL, TRUE);
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++) {
TEST_PRIORITY_VALID (group_id, i, i, GROUP, TRUE);
TEST_PRIORITY_VALID (group_id, i, 7 - i, GROUP, TRUE);
}
/* Clear PG bandwidth from earlier tests */
for (i = 0; i < 8; i++)
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, 0);
/* Priority Group Bandwidth must add up to 100% if enabled, which requires
* some dancing for verifying individual values here.
*/
for (i = 0; i < 8; i++) {
guint other = 7 - (i % 8);
/* Set another priority group to the remaining bandwidth */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 100 - i);
TEST_PRIORITY_VALID (group_bandwidth, i, i, GROUP, TRUE);
/* Set another priority group to the remaining bandwidth */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 100 - (7 - i));
TEST_PRIORITY_VALID (group_bandwidth, i, 7 - i, GROUP, TRUE);
/* Clear remaining bandwidth */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 0);
}
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++) {
TEST_PRIORITY_VALID (bandwidth, i, i, GROUP, TRUE);
TEST_PRIORITY_VALID (bandwidth, i, 7 - i, GROUP, TRUE);
}
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++)
TEST_PRIORITY_VALID (strict_bandwidth, i, TRUE, GROUP, TRUE);
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++) {
TEST_PRIORITY_VALID (traffic_class, i, i, GROUP, TRUE);
TEST_PRIORITY_VALID (traffic_class, i, 7 - i, GROUP, TRUE);
}
}
static void
test_dcb_bandwidth_sums (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
/* Assert that setting the value gets the same value back out */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 0, 9);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 1, 10);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 2, 11);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 3, 12);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 13);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 5, 14);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 6, 15);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16);
/* Assert verify success when sums total 100% */
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL);
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
g_assert_no_error (error);
g_assert (success);
/* Assert verify fails when sums do not total 100% */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 20);
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY);
g_assert (success == FALSE);
g_clear_error (&error);
}
#define TPATH "/libnm-util/settings/dcb/"
int main (int argc, char **argv)
{
GError *error = NULL;
gboolean success;
g_test_init (&argc, &argv, NULL);
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
success = nm_utils_init (&error);
g_assert_no_error (error);
g_assert (success);
#if !GLIB_CHECK_VERSION(2,34,0)
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
#endif
g_test_add_func (TPATH "flags-valid", test_dcb_flags_valid);
g_test_add_func (TPATH "flags-invalid", test_dcb_flags_invalid);
g_test_add_func (TPATH "app-priorities", test_dcb_app_priorities);
g_test_add_func (TPATH "priorities", test_dcb_priorities_valid);
g_test_add_func (TPATH "bandwidth-sums", test_dcb_bandwidth_sums);
return g_test_run ();
}

View File

@@ -0,0 +1,134 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2008 - 2011 Red Hat, Inc.
*
*/
#include <glib.h>
#include <string.h>
#include <nm-utils.h>
#include "nm-setting-8021x.h"
#include "nm-setting-cdma.h"
#include "nm-setting-connection.h"
#include "nm-setting-gsm.h"
#include "nm-setting-ip4-config.h"
#include "nm-setting-ip6-config.h"
#include "nm-setting-ppp.h"
#include "nm-setting-pppoe.h"
#include "nm-setting-serial.h"
#include "nm-setting-vpn.h"
#include "nm-setting-wired.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
#include "nm-test-utils.h"
static void
test_defaults (GType type, const char *name)
{
GParamSpec **property_specs;
guint n_property_specs;
GObject *setting;
int i;
setting = g_object_new (type, NULL);
property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting), &n_property_specs);
ASSERT (property_specs != NULL,
name, "couldn't find property specs for object of type '%s'",
g_type_name (G_OBJECT_TYPE (setting)));
for (i = 0; i < n_property_specs; i++) {
GParamSpec *prop_spec = property_specs[i];
GValue value = G_VALUE_INIT;
GValue defvalue = G_VALUE_INIT;
char *actual, *expected;
gboolean ok = FALSE;
/* Ignore non-fundamental types since they won't really have
* defaults.
*/
if (!G_TYPE_IS_FUNDAMENTAL (prop_spec->value_type))
continue;
g_value_init (&value, prop_spec->value_type);
g_object_get_property (G_OBJECT (setting), prop_spec->name, &value);
g_value_init (&defvalue, prop_spec->value_type);
g_param_value_set_default (prop_spec, &defvalue);
actual = g_strdup_value_contents (&value);
expected = g_strdup_value_contents (&defvalue);
if (!strcmp (prop_spec->name, NM_SETTING_NAME)) {
/* 'name' is always the setting name, not the default value */
ok = !strcmp (nm_setting_get_name (NM_SETTING (setting)), name);
g_free (expected);
expected = g_strdup (name);
} else
ok = g_param_value_defaults (prop_spec, &value);
ASSERT (ok,
name, "property '%s' value '%s' not the expected default value '%s'",
prop_spec->name, actual, expected);
g_free (actual);
g_free (expected);
g_value_unset (&value);
g_value_unset (&defvalue);
}
g_free (property_specs);
g_object_unref (setting);
}
int main (int argc, char **argv)
{
GError *error = NULL;
char *base;
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
/* The tests */
test_defaults (NM_TYPE_SETTING_CONNECTION, NM_SETTING_CONNECTION_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_802_1X, NM_SETTING_802_1X_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_CDMA, NM_SETTING_CDMA_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_GSM, NM_SETTING_GSM_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_IP4_CONFIG, NM_SETTING_IP4_CONFIG_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_IP6_CONFIG, NM_SETTING_IP6_CONFIG_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_PPP, NM_SETTING_PPP_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_PPPOE, NM_SETTING_PPPOE_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_SERIAL, NM_SETTING_SERIAL_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_VPN, NM_SETTING_VPN_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_WIRED, NM_SETTING_WIRED_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_WIRELESS, NM_SETTING_WIRELESS_SETTING_NAME);
test_defaults (NM_TYPE_SETTING_WIRELESS_SECURITY, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
g_free (base);
return 0;
}

673
libnm/nm-access-point.c Normal file
View File

@@ -0,0 +1,673 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2007 - 2011 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include <netinet/ether.h>
#include "nm-glib-compat.h"
#include <nm-connection.h>
#include <nm-setting-connection.h>
#include <nm-setting-wireless.h>
#include <nm-setting-wireless-security.h>
#include <nm-utils.h>
#include "nm-access-point.h"
#include "NetworkManager.h"
#include "nm-types-private.h"
#include "nm-object-private.h"
G_DEFINE_TYPE (NMAccessPoint, nm_access_point, NM_TYPE_OBJECT)
#define NM_ACCESS_POINT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACCESS_POINT, NMAccessPointPrivate))
typedef struct {
DBusGProxy *proxy;
NM80211ApFlags flags;
NM80211ApSecurityFlags wpa_flags;
NM80211ApSecurityFlags rsn_flags;
GByteArray *ssid;
guint32 frequency;
char *bssid;
NM80211Mode mode;
guint32 max_bitrate;
guint8 strength;
} NMAccessPointPrivate;
enum {
PROP_0,
PROP_FLAGS,
PROP_WPA_FLAGS,
PROP_RSN_FLAGS,
PROP_SSID,
PROP_FREQUENCY,
PROP_HW_ADDRESS,
PROP_MODE,
PROP_MAX_BITRATE,
PROP_STRENGTH,
PROP_BSSID,
LAST_PROP
};
/**
* nm_access_point_new:
* @connection: the #DBusGConnection
* @path: the DBusobject path of the access point
*
* Creates a new #NMAccessPoint.
*
* Returns: (transfer full): a new access point
**/
GObject *
nm_access_point_new (DBusGConnection *connection, const char *path)
{
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
return (GObject *) g_object_new (NM_TYPE_ACCESS_POINT,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
}
/**
* nm_access_point_get_flags:
* @ap: a #NMAccessPoint
*
* Gets the flags of the access point.
*
* Returns: the flags
**/
NM80211ApFlags
nm_access_point_get_flags (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_FLAGS_NONE);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->flags;
}
/**
* nm_access_point_get_wpa_flags:
* @ap: a #NMAccessPoint
*
* Gets the WPA (version 1) flags of the access point.
*
* Returns: the WPA flags
**/
NM80211ApSecurityFlags
nm_access_point_get_wpa_flags (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->wpa_flags;
}
/**
* nm_access_point_get_rsn_flags:
* @ap: a #NMAccessPoint
*
* Gets the RSN (Robust Secure Network, ie WPA version 2) flags of the access
* point.
*
* Returns: the RSN flags
**/
NM80211ApSecurityFlags
nm_access_point_get_rsn_flags (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->rsn_flags;
}
/**
* nm_access_point_get_ssid:
* @ap: a #NMAccessPoint
*
* Gets the SSID of the access point.
*
* Returns: the #GByteArray containing the SSID. This is the internal copy used by the
* access point, and must not be modified.
**/
const GByteArray *
nm_access_point_get_ssid (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->ssid;
}
/**
* nm_access_point_get_frequency:
* @ap: a #NMAccessPoint
*
* Gets the frequency of the access point.
*
* Returns: the frequency
**/
guint32
nm_access_point_get_frequency (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->frequency;
}
/**
* nm_access_point_get_bssid:
* @ap: a #NMAccessPoint
*
* Gets the Basic Service Set ID (BSSID) of the Wi-Fi access point.
*
* Returns: the BSSID of the access point. This is an internal string and must
* not be modified or freed.
**/
const char *
nm_access_point_get_bssid (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid;
}
/**
* nm_access_point_get_hw_address:
* @ap: a #NMAccessPoint
*
* Gets the hardware (MAC) address of the access point.
*
* Returns: the hardware address of the access point. This is the internal string used by the
* access point and must not be modified.
*
* Deprecated: 0.9: Use nm_access_point_get_bssid() instead.
**/
const char *
nm_access_point_get_hw_address (NMAccessPoint *ap)
{
return nm_access_point_get_bssid (ap);
}
/**
* nm_access_point_get_mode:
* @ap: a #NMAccessPoint
*
* Gets the mode of the access point.
*
* Returns: the mode
**/
NM80211Mode
nm_access_point_get_mode (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->mode;
}
/**
* nm_access_point_get_max_bitrate:
* @ap: a #NMAccessPoint
*
* Gets the maximum bit rate of the access point in kbit/s.
*
* Returns: the maximum bit rate (kbit/s)
**/
guint32
nm_access_point_get_max_bitrate (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->max_bitrate;
}
/**
* nm_access_point_get_strength:
* @ap: a #NMAccessPoint
*
* Gets the current signal strength of the access point.
*
* Returns: the signal strength
**/
guint8
nm_access_point_get_strength (NMAccessPoint *ap)
{
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->strength;
}
/**
* nm_access_point_connection_valid:
* @ap: an #NMAccessPoint to validate @connection against
* @connection: an #NMConnection to validate against @ap
*
* Validates a given connection against a given Wi-Fi access point to ensure that
* the connection may be activated with that AP. The connection must match the
* @ap's SSID, (if given) BSSID, and other attributes like security settings,
* channel, band, etc.
*
* Returns: %TRUE if the connection may be activated with this Wi-Fi AP,
* %FALSE if it cannot be.
**/
gboolean
nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
{
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
const char *ctype, *ap_bssid_str;
const GByteArray *setting_ssid;
const GByteArray *ap_ssid;
const GByteArray *setting_bssid;
struct ether_addr *ap_bssid;
const char *setting_mode;
NM80211Mode ap_mode;
const char *setting_band;
guint32 ap_freq, setting_chan, ap_chan;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_WIRELESS_SETTING_NAME) != 0)
return FALSE;
s_wifi = nm_connection_get_setting_wireless (connection);
if (!s_wifi)
return FALSE;
/* SSID checks */
ap_ssid = nm_access_point_get_ssid (ap);
g_warn_if_fail (ap_ssid != NULL);
setting_ssid = nm_setting_wireless_get_ssid (s_wifi);
if (!setting_ssid || !ap_ssid || (setting_ssid->len != ap_ssid->len))
return FALSE;
if (memcmp (setting_ssid->data, ap_ssid->data, ap_ssid->len) != 0)
return FALSE;
/* BSSID checks */
ap_bssid_str = nm_access_point_get_bssid (ap);
g_warn_if_fail (ap_bssid_str);
setting_bssid = nm_setting_wireless_get_bssid (s_wifi);
if (setting_bssid && ap_bssid_str) {
g_assert (setting_bssid->len == ETH_ALEN);
ap_bssid = ether_aton (ap_bssid_str);
g_warn_if_fail (ap_bssid);
if (ap_bssid) {
if (memcmp (ap_bssid->ether_addr_octet, setting_bssid->data, ETH_ALEN) != 0)
return FALSE;
}
}
/* Mode */
ap_mode = nm_access_point_get_mode (ap);
g_warn_if_fail (ap_mode != NM_802_11_MODE_UNKNOWN);
setting_mode = nm_setting_wireless_get_mode (s_wifi);
if (setting_mode && ap_mode) {
if (!strcmp (setting_mode, "infrastructure") && (ap_mode != NM_802_11_MODE_INFRA))
return FALSE;
if (!strcmp (setting_mode, "adhoc") && (ap_mode != NM_802_11_MODE_ADHOC))
return FALSE;
/* Hotspot never matches against APs as it's a device-specific mode. */
if (!strcmp (setting_mode, "ap"))
return FALSE;
}
/* Band and Channel/Frequency */
ap_freq = nm_access_point_get_frequency (ap);
if (ap_freq) {
setting_band = nm_setting_wireless_get_band (s_wifi);
if (g_strcmp0 (setting_band, "a") == 0) {
if (ap_freq < 4915 || ap_freq > 5825)
return FALSE;
} else if (g_strcmp0 (setting_band, "bg") == 0) {
if (ap_freq < 2412 || ap_freq > 2484)
return FALSE;
}
setting_chan = nm_setting_wireless_get_channel (s_wifi);
if (setting_chan) {
ap_chan = nm_utils_wifi_freq_to_channel (ap_freq);
if (setting_chan != ap_chan)
return FALSE;
}
}
s_wsec = nm_connection_get_setting_wireless_security (connection);
if (!nm_setting_wireless_ap_security_compatible (s_wifi,
s_wsec,
nm_access_point_get_flags (ap),
nm_access_point_get_wpa_flags (ap),
nm_access_point_get_rsn_flags (ap),
ap_mode))
return FALSE;
return TRUE;
}
/**
* nm_access_point_filter_connections:
* @ap: an #NMAccessPoint to filter connections for
* @connections: (element-type NMConnection): a list of
* #NMConnection objects to filter
*
* Filters a given list of connections for a given #NMAccessPoint object and
* return connections which may be activated with the access point. Any
* returned connections will match the @ap's SSID and (if given) BSSID and
* other attributes like security settings, channel, etc.
*
* To obtain the list of connections that are compatible with this access point,
* use nm_remote_settings_list_connections() and then filter the returned list
* for a given #NMDevice using nm_device_filter_connections() and finally
* filter that list with this function.
*
* Returns: (transfer container) (element-type NMConnection): a
* list of #NMConnection objects that could be activated with the given @ap.
* The elements of the list are owned by their creator and should not be freed
* by the caller, but the returned list itself is owned by the caller and should
* be freed with g_slist_free() when it is no longer required.
**/
GSList *
nm_access_point_filter_connections (NMAccessPoint *ap, const GSList *connections)
{
GSList *filtered = NULL;
const GSList *iter;
for (iter = connections; iter; iter = g_slist_next (iter)) {
NMConnection *candidate = NM_CONNECTION (iter->data);
if (nm_access_point_connection_valid (ap, candidate))
filtered = g_slist_prepend (filtered, candidate);
}
return g_slist_reverse (filtered);
}
/************************************************************/
static void
nm_access_point_init (NMAccessPoint *ap)
{
}
static void
dispose (GObject *object)
{
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_access_point_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (object);
if (priv->ssid)
g_byte_array_free (priv->ssid, TRUE);
g_free (priv->bssid);
G_OBJECT_CLASS (nm_access_point_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMAccessPoint *ap = NM_ACCESS_POINT (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_FLAGS:
g_value_set_uint (value, nm_access_point_get_flags (ap));
break;
case PROP_WPA_FLAGS:
g_value_set_uint (value, nm_access_point_get_wpa_flags (ap));
break;
case PROP_RSN_FLAGS:
g_value_set_uint (value, nm_access_point_get_rsn_flags (ap));
break;
case PROP_SSID:
g_value_set_boxed (value, nm_access_point_get_ssid (ap));
break;
case PROP_FREQUENCY:
g_value_set_uint (value, nm_access_point_get_frequency (ap));
break;
case PROP_HW_ADDRESS:
g_value_set_string (value, nm_access_point_get_bssid (ap));
break;
case PROP_BSSID:
g_value_set_string (value, nm_access_point_get_bssid (ap));
break;
case PROP_MODE:
g_value_set_uint (value, nm_access_point_get_mode (ap));
break;
case PROP_MAX_BITRATE:
g_value_set_uint (value, nm_access_point_get_max_bitrate (ap));
break;
case PROP_STRENGTH:
g_value_set_uchar (value, nm_access_point_get_strength (ap));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
demarshal_ssid (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
{
if (!_nm_ssid_demarshal (value, (GByteArray **) field))
return FALSE;
_nm_object_queue_notify (object, NM_ACCESS_POINT_SSID);
return TRUE;
}
static void
register_properties (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
const NMPropertiesInfo property_info[] = {
{ NM_ACCESS_POINT_FLAGS, &priv->flags },
{ NM_ACCESS_POINT_WPA_FLAGS, &priv->wpa_flags },
{ NM_ACCESS_POINT_RSN_FLAGS, &priv->rsn_flags },
{ NM_ACCESS_POINT_SSID, &priv->ssid, demarshal_ssid },
{ NM_ACCESS_POINT_FREQUENCY, &priv->frequency },
{ NM_ACCESS_POINT_HW_ADDRESS, &priv->bssid },
{ NM_ACCESS_POINT_MODE, &priv->mode },
{ NM_ACCESS_POINT_MAX_BITRATE, &priv->max_bitrate },
{ NM_ACCESS_POINT_STRENGTH, &priv->strength },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (ap),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMAccessPointPrivate *priv;
G_OBJECT_CLASS (nm_access_point_parent_class)->constructed (object);
priv = NM_ACCESS_POINT_GET_PRIVATE (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_ACCESS_POINT);
register_properties (NM_ACCESS_POINT (object));
}
static void
nm_access_point_class_init (NMAccessPointClass *ap_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
g_type_class_add_private (ap_class, sizeof (NMAccessPointPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
/* properties */
/**
* NMAccessPoint:flags:
*
* The flags of the access point.
**/
g_object_class_install_property
(object_class, PROP_FLAGS,
g_param_spec_uint (NM_ACCESS_POINT_FLAGS, "", "",
NM_802_11_AP_FLAGS_NONE,
NM_802_11_AP_FLAGS_PRIVACY,
NM_802_11_AP_FLAGS_NONE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:wpa-flags:
*
* The WPA flags of the access point.
**/
g_object_class_install_property
(object_class, PROP_WPA_FLAGS,
g_param_spec_uint (NM_ACCESS_POINT_WPA_FLAGS, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:rsn-flags:
*
* The RSN flags of the access point.
**/
g_object_class_install_property
(object_class, PROP_RSN_FLAGS,
g_param_spec_uint (NM_ACCESS_POINT_RSN_FLAGS, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:ssid:
*
* The SSID of the access point.
**/
g_object_class_install_property
(object_class, PROP_SSID,
g_param_spec_boxed (NM_ACCESS_POINT_SSID, "", "",
NM_TYPE_SSID,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:frequency:
*
* The frequency of the access point.
**/
g_object_class_install_property
(object_class, PROP_FREQUENCY,
g_param_spec_uint (NM_ACCESS_POINT_FREQUENCY, "", "",
0, 10000, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:bssid:
*
* The BSSID of the access point.
**/
g_object_class_install_property
(object_class, PROP_BSSID,
g_param_spec_string (NM_ACCESS_POINT_BSSID, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:hw-address:
*
* The hardware address of the access point.
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_ACCESS_POINT_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:mode:
*
* The mode of the access point; either "infrastructure" (a central
* coordinator of the wireless network allowing clients to connect) or
* "ad-hoc" (a network with no central controller).
**/
g_object_class_install_property
(object_class, PROP_MODE,
g_param_spec_uint (NM_ACCESS_POINT_MODE, "", "",
NM_802_11_MODE_ADHOC, NM_802_11_MODE_INFRA, NM_802_11_MODE_INFRA,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:max-bitrate:
*
* The maximum bit rate of the access point in kbit/s.
**/
g_object_class_install_property
(object_class, PROP_MAX_BITRATE,
g_param_spec_uint (NM_ACCESS_POINT_MAX_BITRATE, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMAccessPoint:strength:
*
* The current signal strength of the access point.
**/
g_object_class_install_property
(object_class, PROP_STRENGTH,
g_param_spec_uchar (NM_ACCESS_POINT_STRENGTH, "", "",
0, G_MAXUINT8, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

96
libnm/nm-access-point.h Normal file
View File

@@ -0,0 +1,96 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2007 - 2011 Red Hat, Inc.
*/
#ifndef NM_ACCESS_POINT_H
#define NM_ACCESS_POINT_H
#include <glib.h>
#include <glib-object.h>
#include <NetworkManager.h>
#include <nm-connection.h>
#include "nm-object.h"
G_BEGIN_DECLS
#define NM_TYPE_ACCESS_POINT (nm_access_point_get_type ())
#define NM_ACCESS_POINT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACCESS_POINT, NMAccessPoint))
#define NM_ACCESS_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_ACCESS_POINT, NMAccessPointClass))
#define NM_IS_ACCESS_POINT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_ACCESS_POINT))
#define NM_IS_ACCESS_POINT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ACCESS_POINT))
#define NM_ACCESS_POINT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACCESS_POINT, NMAccessPointClass))
#define NM_ACCESS_POINT_FLAGS "flags"
#define NM_ACCESS_POINT_WPA_FLAGS "wpa-flags"
#define NM_ACCESS_POINT_RSN_FLAGS "rsn-flags"
#define NM_ACCESS_POINT_SSID "ssid"
#define NM_ACCESS_POINT_BSSID "bssid"
#define NM_ACCESS_POINT_FREQUENCY "frequency"
#define NM_ACCESS_POINT_MODE "mode"
#define NM_ACCESS_POINT_MAX_BITRATE "max-bitrate"
#define NM_ACCESS_POINT_STRENGTH "strength"
/* DEPRECATED */
#define NM_ACCESS_POINT_HW_ADDRESS "hw-address"
typedef struct {
NMObject parent;
} NMAccessPoint;
typedef struct {
NMObjectClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMAccessPointClass;
GType nm_access_point_get_type (void);
GObject *nm_access_point_new (DBusGConnection *connection, const char *path);
NM80211ApFlags nm_access_point_get_flags (NMAccessPoint *ap);
NM80211ApSecurityFlags nm_access_point_get_wpa_flags (NMAccessPoint *ap);
NM80211ApSecurityFlags nm_access_point_get_rsn_flags (NMAccessPoint *ap);
const GByteArray * nm_access_point_get_ssid (NMAccessPoint *ap);
const char * nm_access_point_get_bssid (NMAccessPoint *ap);
guint32 nm_access_point_get_frequency (NMAccessPoint *ap);
NM80211Mode nm_access_point_get_mode (NMAccessPoint *ap);
guint32 nm_access_point_get_max_bitrate (NMAccessPoint *ap);
guint8 nm_access_point_get_strength (NMAccessPoint *ap);
GSList * nm_access_point_filter_connections (NMAccessPoint *ap,
const GSList *connections);
gboolean nm_access_point_connection_valid (NMAccessPoint *ap,
NMConnection *connection);
/* DEPRECATED */
NM_DEPRECATED_IN_0_9_10
const char * nm_access_point_get_hw_address (NMAccessPoint *ap);
G_END_DECLS
#endif /* NM_ACCESS_POINT_H */

View File

@@ -0,0 +1,851 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2008 Novell, Inc.
*/
#include <string.h>
#include "NetworkManager.h"
#include "nm-active-connection.h"
#include "nm-object-private.h"
#include "nm-types-private.h"
#include "nm-device.h"
#include "nm-device-private.h"
#include "nm-connection.h"
#include "nm-vpn-connection.h"
#include "nm-glib-compat.h"
#include "nm-dbus-helpers-private.h"
static GType _nm_active_connection_type_for_path (DBusGConnection *connection,
const char *path);
static void _nm_active_connection_type_for_path_async (DBusGConnection *connection,
const char *path,
NMObjectTypeCallbackFunc callback,
gpointer user_data);
G_DEFINE_TYPE_WITH_CODE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT,
_nm_object_register_type_func (g_define_type_id,
_nm_active_connection_type_for_path,
_nm_active_connection_type_for_path_async);
)
#define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate))
typedef struct {
DBusGProxy *proxy;
char *connection;
char *id;
char *uuid;
char *type;
char *specific_object;
GPtrArray *devices;
NMActiveConnectionState state;
gboolean is_default;
NMIP4Config *ip4_config;
NMDHCP4Config *dhcp4_config;
gboolean is_default6;
NMIP6Config *ip6_config;
NMDHCP6Config *dhcp6_config;
gboolean is_vpn;
char *master;
} NMActiveConnectionPrivate;
enum {
PROP_0,
PROP_CONNECTION,
PROP_ID,
PROP_UUID,
PROP_TYPE,
PROP_SPECIFIC_OBJECT,
PROP_DEVICES,
PROP_STATE,
PROP_DEFAULT,
PROP_IP4_CONFIG,
PROP_DHCP4_CONFIG,
PROP_DEFAULT6,
PROP_IP6_CONFIG,
PROP_DHCP6_CONFIG,
PROP_VPN,
PROP_MASTER,
LAST_PROP
};
/**
* nm_active_connection_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMActiveConnection.
*
* Returns: (transfer full): a new active connection
**/
GObject *
nm_active_connection_new (DBusGConnection *connection, const char *path)
{
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
return g_object_new (NM_TYPE_ACTIVE_CONNECTION,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
}
static GType
_nm_active_connection_type_for_path (DBusGConnection *connection,
const char *path)
{
DBusGProxy *proxy;
GError *error = NULL;
GValue value = G_VALUE_INIT;
GType type;
proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties");
if (!proxy) {
g_warning ("%s: couldn't create D-Bus object proxy.", __func__);
return G_TYPE_INVALID;
}
/* Have to create an NMVPNConnection if it's a VPN connection, otherwise
* a plain NMActiveConnection.
*/
if (dbus_g_proxy_call (proxy,
"Get", &error,
G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
G_TYPE_STRING, "Vpn",
G_TYPE_INVALID,
G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
if (g_value_get_boolean (&value))
type = NM_TYPE_VPN_CONNECTION;
else
type = NM_TYPE_ACTIVE_CONNECTION;
} else {
g_warning ("Error in getting active connection 'Vpn' property: (%d) %s",
error->code, error->message);
g_error_free (error);
type = G_TYPE_INVALID;
}
g_object_unref (proxy);
return type;
}
typedef struct {
DBusGConnection *connection;
NMObjectTypeCallbackFunc callback;
gpointer user_data;
} NMActiveConnectionAsyncData;
static void
async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
{
NMActiveConnectionAsyncData *async_data = user_data;
GValue value = G_VALUE_INIT;
const char *path = dbus_g_proxy_get_path (proxy);
GError *error = NULL;
GType type;
if (dbus_g_proxy_end_call (proxy, call, &error,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
if (g_value_get_boolean (&value))
type = NM_TYPE_VPN_CONNECTION;
else
type = NM_TYPE_ACTIVE_CONNECTION;
} else {
g_warning ("%s: could not read properties for %s: %s", __func__, path, error->message);
type = G_TYPE_INVALID;
}
async_data->callback (type, async_data->user_data);
g_object_unref (proxy);
g_slice_free (NMActiveConnectionAsyncData, async_data);
}
static void
_nm_active_connection_type_for_path_async (DBusGConnection *connection,
const char *path,
NMObjectTypeCallbackFunc callback,
gpointer user_data)
{
NMActiveConnectionAsyncData *async_data;
DBusGProxy *proxy;
async_data = g_slice_new (NMActiveConnectionAsyncData);
async_data->connection = connection;
async_data->callback = callback;
async_data->user_data = user_data;
proxy = _nm_dbus_new_proxy_for_connection (connection, path, "org.freedesktop.DBus.Properties");
dbus_g_proxy_begin_call (proxy, "Get",
async_got_type, async_data, NULL,
G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
G_TYPE_STRING, "Vpn",
G_TYPE_INVALID);
}
/**
* nm_active_connection_get_connection:
* @connection: a #NMActiveConnection
*
* Gets the #NMConnection's DBus object path. This is often used with
* nm_remote_settings_get_connection_by_path() to retrieve the
* #NMRemoteConnection object that describes the connection.
*
* Returns: the object path of the #NMConnection which this #NMActiveConnection
* is an active instance of. This is the internal string used by the
* connection, and must not be modified.
**/
const char *
nm_active_connection_get_connection (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->connection;
}
/**
* nm_active_connection_get_id:
* @connection: a #NMActiveConnection
*
* Gets the #NMConnection's ID.
*
* Returns: the ID of the #NMConnection that backs the #NMActiveConnection.
* This is the internal string used by the connection, and must not be modified.
*
* Since: 0.9.10
**/
const char *
nm_active_connection_get_id (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id;
}
/**
* nm_active_connection_get_uuid:
* @connection: a #NMActiveConnection
*
* Gets the #NMConnection's UUID.
*
* Returns: the UUID of the #NMConnection that backs the #NMActiveConnection.
* This is the internal string used by the connection, and must not be modified.
**/
const char *
nm_active_connection_get_uuid (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid;
}
/**
* nm_active_connection_get_connection_type:
* @connection: a #NMActiveConnection
*
* Gets the #NMConnection's type.
*
* Returns: the type of the #NMConnection that backs the #NMActiveConnection.
* This is the internal string used by the connection, and must not be modified.
*
* Since: 0.9.10
**/
const char *
nm_active_connection_get_connection_type (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type;
}
/**
* nm_active_connection_get_specific_object:
* @connection: a #NMActiveConnection
*
* Gets the "specific object" used at the activation.
*
* Returns: the specific object's DBus path. This is the internal string used by the
* connection, and must not be modified.
**/
const char *
nm_active_connection_get_specific_object (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object;
}
/**
* nm_active_connection_get_devices:
* @connection: a #NMActiveConnection
*
* Gets the #NMDevices used for the active connections.
*
* Returns: (element-type NMDevice): the #GPtrArray containing #NMDevices.
* This is the internal copy used by the connection, and must not be modified.
**/
const GPtrArray *
nm_active_connection_get_devices (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return handle_ptr_array_return (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices);
}
/**
* nm_active_connection_get_state:
* @connection: a #NMActiveConnection
*
* Gets the active connection's state.
*
* Returns: the state
**/
NMActiveConnectionState
nm_active_connection_get_state (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_UNKNOWN);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->state;
}
/**
* nm_active_connection_get_default:
* @connection: a #NMActiveConnection
*
* Whether the active connection is the default IPv4 one (that is, is used for
* the default IPv4 route and DNS information).
*
* Returns: %TRUE if the active connection is the default IPv4 connection
**/
gboolean
nm_active_connection_get_default (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default;
}
/**
* nm_active_connection_get_ip4_config:
* @connection: an #NMActiveConnection
*
* Gets the current #NMIP4Config associated with the #NMActiveConnection.
*
* Returns: (transfer none): the #NMIP4Config, or %NULL if the
* connection is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
* state.
*
* Since: 0.9.10
**/
NMIP4Config *
nm_active_connection_get_ip4_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip4_config;
}
/**
* nm_active_connection_get_dhcp4_config:
* @connection: an #NMActiveConnection
*
* Gets the current #NMDHCP4Config (if any) associated with the
* #NMActiveConnection.
*
* Returns: (transfer none): the #NMDHCP4Config, or %NULL if the
* connection does not use DHCP, or is not in the
* %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
*
* Since: 0.9.10
**/
NMDHCP4Config *
nm_active_connection_get_dhcp4_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp4_config;
}
/**
* nm_active_connection_get_default6:
* @connection: a #NMActiveConnection
*
* Whether the active connection is the default IPv6 one (that is, is used for
* the default IPv6 route and DNS information).
*
* Returns: %TRUE if the active connection is the default IPv6 connection
**/
gboolean
nm_active_connection_get_default6 (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default6;
}
/**
* nm_active_connection_get_ip6_config:
* @connection: an #NMActiveConnection
*
* Gets the current #NMIP6Config associated with the #NMActiveConnection.
*
* Returns: (transfer none): the #NMIP6Config, or %NULL if the
* connection is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
* state.
*
* Since: 0.9.10
**/
NMIP6Config *
nm_active_connection_get_ip6_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip6_config;
}
/**
* nm_active_connection_get_dhcp6_config:
* @connection: an #NMActiveConnection
*
* Gets the current #NMDHCP6Config (if any) associated with the
* #NMActiveConnection.
*
* Returns: (transfer none): the #NMDHCP6Config, or %NULL if the
* connection does not use DHCPv6, or is not in the
* %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
*
* Since: 0.9.10
**/
NMDHCP6Config *
nm_active_connection_get_dhcp6_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp6_config;
}
/**
* nm_active_connection_get_vpn:
* @connection: a #NMActiveConnection
*
* Whether the active connection is a VPN connection.
*
* Returns: %TRUE if the active connection is a VPN connection
*
* Since: 0.9.10
**/
gboolean
nm_active_connection_get_vpn (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_vpn;
}
/**
* nm_active_connection_get_master:
* @connection: a #NMActiveConnection
*
* Gets the path to the master #NMDevice of the connection.
*
* Returns: the path of the master #NMDevice of the #NMActiveConnection.
* This is the internal string used by the connection, and must not be modified.
**/
const char *
nm_active_connection_get_master (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->master;
}
static void
nm_active_connection_init (NMActiveConnection *ap)
{
}
static void
dispose (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
if (priv->devices) {
g_ptr_array_set_free_func (priv->devices, g_object_unref);
g_ptr_array_free (priv->devices, TRUE);
priv->devices = NULL;
}
g_clear_object (&priv->ip4_config);
g_clear_object (&priv->dhcp4_config);
g_clear_object (&priv->ip6_config);
g_clear_object (&priv->dhcp6_config);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
g_free (priv->connection);
g_free (priv->id);
g_free (priv->uuid);
g_free (priv->type);
g_free (priv->specific_object);
g_free (priv->master);
G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMActiveConnection *self = NM_ACTIVE_CONNECTION (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_CONNECTION:
g_value_set_string (value, nm_active_connection_get_connection (self));
break;
case PROP_ID:
g_value_set_string (value, nm_active_connection_get_id (self));
break;
case PROP_UUID:
g_value_set_string (value, nm_active_connection_get_uuid (self));
break;
case PROP_TYPE:
g_value_set_string (value, nm_active_connection_get_connection_type (self));
break;
case PROP_SPECIFIC_OBJECT:
g_value_set_boxed (value, nm_active_connection_get_specific_object (self));
break;
case PROP_DEVICES:
g_value_set_boxed (value, nm_active_connection_get_devices (self));
break;
case PROP_STATE:
g_value_set_uint (value, nm_active_connection_get_state (self));
break;
case PROP_DEFAULT:
g_value_set_boolean (value, nm_active_connection_get_default (self));
break;
case PROP_IP4_CONFIG:
g_value_set_object (value, nm_active_connection_get_ip4_config (self));
break;
case PROP_DHCP4_CONFIG:
g_value_set_object (value, nm_active_connection_get_dhcp4_config (self));
break;
case PROP_DEFAULT6:
g_value_set_boolean (value, nm_active_connection_get_default6 (self));
break;
case PROP_IP6_CONFIG:
g_value_set_object (value, nm_active_connection_get_ip6_config (self));
break;
case PROP_DHCP6_CONFIG:
g_value_set_object (value, nm_active_connection_get_dhcp6_config (self));
break;
case PROP_VPN:
g_value_set_boolean (value, nm_active_connection_get_vpn (self));
break;
case PROP_MASTER:
g_value_set_string (value, nm_active_connection_get_master (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
register_properties (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
const NMPropertiesInfo property_info[] = {
{ NM_ACTIVE_CONNECTION_CONNECTION, &priv->connection },
{ NM_ACTIVE_CONNECTION_ID, &priv->id },
{ NM_ACTIVE_CONNECTION_UUID, &priv->uuid },
{ NM_ACTIVE_CONNECTION_TYPE, &priv->type },
{ NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, &priv->specific_object },
{ NM_ACTIVE_CONNECTION_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE },
{ NM_ACTIVE_CONNECTION_STATE, &priv->state },
{ NM_ACTIVE_CONNECTION_DEFAULT, &priv->is_default },
{ NM_ACTIVE_CONNECTION_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
{ NM_ACTIVE_CONNECTION_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
{ NM_ACTIVE_CONNECTION_DEFAULT6, &priv->is_default6 },
{ NM_ACTIVE_CONNECTION_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
{ NM_ACTIVE_CONNECTION_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
{ NM_ACTIVE_CONNECTION_VPN, &priv->is_vpn },
{ NM_ACTIVE_CONNECTION_MASTER, &priv->master },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (connection),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_active_connection_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
register_properties (NM_ACTIVE_CONNECTION (object));
}
static void
nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
g_type_class_add_private (ap_class, sizeof (NMActiveConnectionPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
/* properties */
/**
* NMActiveConnection:connection:
*
* The connection's path of the active connection.
**/
g_object_class_install_property
(object_class, PROP_CONNECTION,
g_param_spec_string (NM_ACTIVE_CONNECTION_CONNECTION, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:id:
*
* The active connection's ID
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_ID,
g_param_spec_string (NM_ACTIVE_CONNECTION_ID, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:uuid:
*
* The active connection's UUID
**/
g_object_class_install_property
(object_class, PROP_UUID,
g_param_spec_string (NM_ACTIVE_CONNECTION_UUID, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:type:
*
* The active connection's type
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_TYPE,
g_param_spec_string (NM_ACTIVE_CONNECTION_TYPE, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:specific-object:
*
* The specific object's path of the active connection.
**/
g_object_class_install_property
(object_class, PROP_SPECIFIC_OBJECT,
g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:device:
*
* The devices (#NMDevice) of the active connection.
**/
g_object_class_install_property
(object_class, PROP_DEVICES,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:state:
*
* The state of the active connection.
**/
g_object_class_install_property
(object_class, PROP_STATE,
g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE, "", "",
NM_ACTIVE_CONNECTION_STATE_UNKNOWN,
NM_ACTIVE_CONNECTION_STATE_DEACTIVATING,
NM_ACTIVE_CONNECTION_STATE_UNKNOWN,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:default:
*
* Whether the active connection is the default IPv4 one.
**/
g_object_class_install_property
(object_class, PROP_DEFAULT,
g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:ip4-config:
*
* The #NMIP4Config of the connection.
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_IP4_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "",
NM_TYPE_IP4_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:dhcp4-config:
*
* The #NMDHCP4Config of the connection.
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_DHCP4_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "",
NM_TYPE_DHCP4_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:default6:
*
* Whether the active connection is the default IPv6 one.
**/
g_object_class_install_property
(object_class, PROP_DEFAULT6,
g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT6, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:ip6-config:
*
* The #NMIP6Config of the connection.
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_IP6_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "",
NM_TYPE_IP6_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:dhcp6-config:
*
* The #NMDHCP6Config of the connection.
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_DHCP6_CONFIG,
g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "",
NM_TYPE_DHCP6_CONFIG,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:vpn:
*
* Whether the active connection is a VPN connection.
*
* Since: 0.9.10
**/
g_object_class_install_property
(object_class, PROP_VPN,
g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:master:
*
* The path of the master device if one exists.
**/
g_object_class_install_property
(object_class, PROP_MASTER,
g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,105 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2014 Red Hat, Inc.
* Copyright 2008 Novell, Inc.
*/
#ifndef NM_ACTIVE_CONNECTION_H
#define NM_ACTIVE_CONNECTION_H
#include <glib.h>
#include <glib-object.h>
#include "nm-object.h"
#include <nm-connection.h>
#include <NetworkManager.h>
#include "nm-ip4-config.h"
#include "nm-dhcp4-config.h"
#include "nm-ip6-config.h"
#include "nm-dhcp6-config.h"
G_BEGIN_DECLS
#define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ())
#define NM_ACTIVE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnection))
#define NM_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass))
#define NM_IS_ACTIVE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_ACTIVE_CONNECTION))
#define NM_IS_ACTIVE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_ACTIVE_CONNECTION))
#define NM_ACTIVE_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionClass))
#define NM_ACTIVE_CONNECTION_CONNECTION "connection"
#define NM_ACTIVE_CONNECTION_ID "id"
#define NM_ACTIVE_CONNECTION_UUID "uuid"
#define NM_ACTIVE_CONNECTION_TYPE "type"
#define NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT "specific-object"
#define NM_ACTIVE_CONNECTION_DEVICES "devices"
#define NM_ACTIVE_CONNECTION_STATE "state"
#define NM_ACTIVE_CONNECTION_DEFAULT "default"
#define NM_ACTIVE_CONNECTION_IP4_CONFIG "ip4-config"
#define NM_ACTIVE_CONNECTION_DHCP4_CONFIG "dhcp4-config"
#define NM_ACTIVE_CONNECTION_DEFAULT6 "default6"
#define NM_ACTIVE_CONNECTION_IP6_CONFIG "ip6-config"
#define NM_ACTIVE_CONNECTION_DHCP6_CONFIG "dhcp6-config"
#define NM_ACTIVE_CONNECTION_VPN "vpn"
#define NM_ACTIVE_CONNECTION_MASTER "master"
typedef struct {
NMObject parent;
} NMActiveConnection;
typedef struct {
NMObjectClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMActiveConnectionClass;
GType nm_active_connection_get_type (void);
GObject *nm_active_connection_new (DBusGConnection *connection, const char *path);
const char * nm_active_connection_get_connection (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
const char * nm_active_connection_get_id (NMActiveConnection *connection);
const char * nm_active_connection_get_uuid (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
const char * nm_active_connection_get_connection_type (NMActiveConnection *connection);
const char * nm_active_connection_get_specific_object (NMActiveConnection *connection);
const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection);
NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection);
const char * nm_active_connection_get_master (NMActiveConnection *connection);
gboolean nm_active_connection_get_default (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMIP4Config * nm_active_connection_get_ip4_config (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMDHCP4Config *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection);
gboolean nm_active_connection_get_default6 (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMIP6Config * nm_active_connection_get_ip6_config (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
NMDHCP6Config *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection);
NM_AVAILABLE_IN_0_9_10
gboolean nm_active_connection_get_vpn (NMActiveConnection *connection);
G_END_DECLS
#endif /* NM_ACTIVE_CONNECTION_H */

2442
libnm/nm-client.c Normal file

File diff suppressed because it is too large Load Diff

255
libnm/nm-client.h Normal file
View File

@@ -0,0 +1,255 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2007 - 2012 Red Hat, Inc.
*/
#ifndef NM_CLIENT_H
#define NM_CLIENT_H
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <dbus/dbus-glib.h>
#include <NetworkManager.h>
#include "nm-object.h"
#include "nm-device.h"
#include "nm-active-connection.h"
#include "nm-vpn-connection.h"
G_BEGIN_DECLS
#define NM_TYPE_CLIENT (nm_client_get_type ())
#define NM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CLIENT, NMClient))
#define NM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CLIENT, NMClientClass))
#define NM_IS_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CLIENT))
#define NM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CLIENT))
#define NM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CLIENT, NMClientClass))
#define NM_CLIENT_VERSION "version"
#define NM_CLIENT_STATE "state"
#define NM_CLIENT_STARTUP "startup"
#define NM_CLIENT_MANAGER_RUNNING "manager-running"
#define NM_CLIENT_NETWORKING_ENABLED "networking-enabled"
#define NM_CLIENT_WIRELESS_ENABLED "wireless-enabled"
#define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
#define NM_CLIENT_WWAN_ENABLED "wwan-enabled"
#define NM_CLIENT_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
#define NM_CLIENT_WIMAX_ENABLED "wimax-enabled"
#define NM_CLIENT_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled"
#define NM_CLIENT_ACTIVE_CONNECTIONS "active-connections"
#define NM_CLIENT_CONNECTIVITY "connectivity"
#define NM_CLIENT_PRIMARY_CONNECTION "primary-connection"
#define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection"
#define NM_CLIENT_DEVICES "devices"
/**
* NMClientPermission:
* @NM_CLIENT_PERMISSION_NONE: unknown or no permission
* @NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK: controls whether networking
* can be globally enabled or disabled
* @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI: controls whether Wi-Fi can be
* globally enabled or disabled
* @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN: controls whether WWAN (3G) can be
* globally enabled or disabled
* @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX: controls whether WiMAX can be
* globally enabled or disabled
* @NM_CLIENT_PERMISSION_SLEEP_WAKE: controls whether the client can ask
* NetworkManager to sleep and wake
* @NM_CLIENT_PERMISSION_NETWORK_CONTROL: controls whether networking connections
* can be started, stopped, and changed
* @NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED: controls whether a password
* protected Wi-Fi hotspot can be created
* @NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN: controls whether an open Wi-Fi hotspot
* can be created
* @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM: controls whether connections
* that are available to all users can be modified
* @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN: controls whether connections
* owned by the current user can be modified
* @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME: controls whether the
* persistent hostname can be changed
* @NM_CLIENT_PERMISSION_LAST: a reserved boundary value
*
* #NMClientPermission values indicate various permissions that NetworkManager
* clients can obtain to perform certain tasks on behalf of the current user.
**/
typedef enum {
NM_CLIENT_PERMISSION_NONE = 0,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK = 1,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI = 2,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN = 3,
NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX = 4,
NM_CLIENT_PERMISSION_SLEEP_WAKE = 5,
NM_CLIENT_PERMISSION_NETWORK_CONTROL = 6,
NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED = 7,
NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN = 8,
NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM = 9,
NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN = 10,
NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME = 11,
NM_CLIENT_PERMISSION_LAST = NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME
} NMClientPermission;
/**
* NMClientPermissionResult:
* @NM_CLIENT_PERMISSION_RESULT_UNKNOWN: unknown or no authorization
* @NM_CLIENT_PERMISSION_RESULT_YES: the permission is available
* @NM_CLIENT_PERMISSION_RESULT_AUTH: authorization is necessary before the
* permission is available
* @NM_CLIENT_PERMISSION_RESULT_NO: permission to perform the operation is
* denied by system policy
*
* #NMClientPermissionResult values indicate what authorizations and permissions
* the user requires to obtain a given #NMClientPermission
**/
typedef enum {
NM_CLIENT_PERMISSION_RESULT_UNKNOWN = 0,
NM_CLIENT_PERMISSION_RESULT_YES,
NM_CLIENT_PERMISSION_RESULT_AUTH,
NM_CLIENT_PERMISSION_RESULT_NO
} NMClientPermissionResult;
/**
* NMClientError:
* @NM_CLIENT_ERROR_UNKNOWN: unknown or unclassified error
* @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager
* failed because NetworkManager is not running
*
* Describes errors that may result from operations involving a #NMClient.
**/
typedef enum {
NM_CLIENT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING, /*< nick=ManagerNotRunning >*/
} NMClientError;
#define NM_CLIENT_ERROR nm_client_error_quark ()
NM_AVAILABLE_IN_0_9_10
GQuark nm_client_error_quark (void);
typedef struct {
NMObject parent;
} NMClient;
typedef struct {
NMObjectClass parent;
/* Signals */
void (*device_added) (NMClient *client, NMDevice *device);
void (*device_removed) (NMClient *client, NMDevice *device);
void (*permission_changed) (NMClient *client,
NMClientPermission permission,
NMClientPermissionResult result);
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMClientClass;
GType nm_client_get_type (void);
NMClient *nm_client_new (void);
void nm_client_new_async (GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMClient *nm_client_new_finish (GAsyncResult *result,
GError **error);
const GPtrArray *nm_client_get_devices (NMClient *client);
NMDevice *nm_client_get_device_by_path (NMClient *client, const char *object_path);
NMDevice *nm_client_get_device_by_iface (NMClient *client, const char *iface);
typedef void (*NMClientActivateFn) (NMClient *client,
NMActiveConnection *active_connection,
GError *error,
gpointer user_data);
void nm_client_activate_connection (NMClient *client,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
NMClientActivateFn callback,
gpointer user_data);
typedef void (*NMClientAddActivateFn) (NMClient *client,
NMActiveConnection *connection,
const char *new_connection_path,
GError *error,
gpointer user_data);
void nm_client_add_and_activate_connection (NMClient *client,
NMConnection *partial,
NMDevice *device,
const char *specific_object,
NMClientAddActivateFn callback,
gpointer user_data);
void nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active);
gboolean nm_client_networking_get_enabled (NMClient *client);
void nm_client_networking_set_enabled (NMClient *client, gboolean enabled);
gboolean nm_client_wireless_get_enabled (NMClient *client);
void nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
gboolean nm_client_wireless_hardware_get_enabled (NMClient *client);
gboolean nm_client_wwan_get_enabled (NMClient *client);
void nm_client_wwan_set_enabled (NMClient *client, gboolean enabled);
gboolean nm_client_wwan_hardware_get_enabled (NMClient *client);
gboolean nm_client_wimax_get_enabled (NMClient *client);
void nm_client_wimax_set_enabled (NMClient *client, gboolean enabled);
gboolean nm_client_wimax_hardware_get_enabled (NMClient *client);
const char *nm_client_get_version (NMClient *client);
NMState nm_client_get_state (NMClient *client);
NM_AVAILABLE_IN_0_9_10
gboolean nm_client_get_startup (NMClient *client);
gboolean nm_client_get_manager_running (NMClient *client);
const GPtrArray *nm_client_get_active_connections (NMClient *client);
void nm_client_sleep (NMClient *client, gboolean sleep_);
NMClientPermissionResult nm_client_get_permission_result (NMClient *client,
NMClientPermission permission);
gboolean nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error);
gboolean nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error);
NMConnectivityState nm_client_get_connectivity (NMClient *client);
NMConnectivityState nm_client_check_connectivity (NMClient *client,
GCancellable *cancellable,
GError **error);
void nm_client_check_connectivity_async (NMClient *client,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMConnectivityState nm_client_check_connectivity_finish (NMClient *client,
GAsyncResult *result,
GError **error);
NMActiveConnection *nm_client_get_primary_connection (NMClient *client);
NMActiveConnection *nm_client_get_activating_connection (NMClient *client);
G_END_DECLS
#endif /* NM_CLIENT_H */

View File

@@ -0,0 +1,36 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NM_DBUS_HELPERS_PRIVATE_H
#define NM_DBUS_HELPERS_PRIVATE_H
#include <gio/gio.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
DBusGConnection *_nm_dbus_new_connection (GError **error);
gboolean _nm_dbus_is_connection_private (DBusGConnection *connection);
DBusGProxy * _nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
const char *path,
const char *interface);
#endif /* NM_DBUS_HELPERS_PRIVATE_H */

99
libnm/nm-dbus-helpers.c Normal file
View File

@@ -0,0 +1,99 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#include <string.h>
#include <config.h>
#include <gio/gio.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "nm-dbus-helpers-private.h"
#include "NetworkManager.h"
static dbus_int32_t priv_slot = -1;
static gboolean
_ensure_dbus_data_slot (void)
{
static gsize init_value = 0;
gboolean success = TRUE;
if (g_once_init_enter (&init_value)) {
success = dbus_connection_allocate_data_slot (&priv_slot);
g_once_init_leave (&init_value, 1);
}
return success;
}
DBusGConnection *
_nm_dbus_new_connection (GError **error)
{
DBusGConnection *connection = NULL;
if (!_ensure_dbus_data_slot ()) {
g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED, "failed to allocated data slot");
return NULL;
}
#if HAVE_DBUS_GLIB_100
/* If running as root try the private bus first */
if (0 == geteuid ()) {
connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error);
if (connection) {
DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection);
/* Mark this connection as private */
dbus_connection_set_data (dbus_connection, priv_slot, GUINT_TO_POINTER (TRUE), NULL);
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
return connection;
}
/* Fall back to a bus if for some reason private socket isn't available */
g_clear_error (error);
}
#endif
if (connection == NULL)
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
return connection;
}
gboolean
_nm_dbus_is_connection_private (DBusGConnection *connection)
{
if (!_ensure_dbus_data_slot ())
return FALSE;
return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot);
}
DBusGProxy *
_nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
const char *path,
const char *interface)
{
/* Private connections can't use dbus_g_proxy_new_for_name() or
* dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't
* have either a bus daemon or name owners, both of which those functions
* require.
*/
if (_nm_dbus_is_connection_private (connection))
return dbus_g_proxy_new_for_peer (connection, path, interface);
return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface);
}

242
libnm/nm-device-adsl.c Normal file
View File

@@ -0,0 +1,242 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* author: Pantelis Koukousoulas <pktoss@gmail.com>
* Copyright 2009 - 2011 Red Hat, Inc.
*/
#include "nm-device-adsl.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-setting-adsl.h"
#include <string.h>
G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE)
#define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate))
typedef struct {
DBusGProxy *proxy;
gboolean carrier;
gboolean disposed;
} NMDeviceAdslPrivate;
enum {
PROP_0,
PROP_CARRIER,
LAST_PROP
};
/**
* nm_device_adsl_error_quark:
*
* Registers an error quark for #NMDeviceAdsl if necessary.
*
* Returns: the error quark used for #NMDeviceAdsl errors.
**/
GQuark
nm_device_adsl_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-adsl-error-quark");
return quark;
}
/**
* nm_device_adsl_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceAdsl.
*
* Returns: (transfer full): a new device
**/
GObject *
nm_device_adsl_new (DBusGConnection *connection, const char *path)
{
GObject *device;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
device = g_object_new (NM_TYPE_DEVICE_ADSL,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return device;
}
/**
* nm_device_adsl_get_carrier:
* @device: a #NMDeviceAdsl
*
* Whether the device has carrier.
*
* Returns: %TRUE if the device has carrier
**/
gboolean
nm_device_adsl_get_carrier (NMDeviceAdsl *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ADSL (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_ADSL_GET_PRIVATE (device)->carrier;
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingAdsl *s_adsl;
const char *ctype;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_ADSL_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_NOT_ADSL_CONNECTION,
"The connection was not an ADSL connection.");
return FALSE;
}
s_adsl = nm_connection_get_setting_adsl (connection);
if (!s_adsl) {
g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_INVALID_ADSL_CONNECTION,
"The connection was not a valid ADSL connection.");
return FALSE;
}
return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_ADSL;
}
/******************************************************************/
static void
nm_device_adsl_init (NMDeviceAdsl *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ADSL);
}
static void
register_properties (NMDeviceAdsl *device)
{
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_ADSL_CARRIER, &priv->carrier },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_ADSL);
register_properties (NM_DEVICE_ADSL (object));
}
static void
dispose (GObject *object)
{
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
if (priv->disposed) {
G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
return;
}
priv->disposed = TRUE;
g_object_unref (priv->proxy);
G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
G_OBJECT_CLASS (nm_device_adsl_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceAdsl *device = NM_DEVICE_ADSL (object);
switch (prop_id) {
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_adsl_get_carrier (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (adsl_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class);
g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
/* properties */
/**
* NMDeviceAdsl:carrier:
*
* Whether the device has carrier.
**/
g_object_class_install_property
(object_class, PROP_CARRIER,
g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

75
libnm/nm-device-adsl.h Normal file
View File

@@ -0,0 +1,75 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 Pantelis Koukousoulas <pktoss@gmail.com>
*/
#ifndef NM_DEVICE_ADSL_H
#define NM_DEVICE_ADSL_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_ADSL (nm_device_adsl_get_type ())
#define NM_DEVICE_ADSL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_ADSL, NMDeviceAdsl))
#define NM_DEVICE_ADSL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_ADSL, NMDeviceAdslClass))
#define NM_IS_DEVICE_ADSL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_ADSL))
#define NM_IS_DEVICE_ADSL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_ADSL))
#define NM_DEVICE_ADSL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_ADSL, NMDeviceAdslClass))
/**
* NMDeviceAdslError:
* @NM_DEVICE_ADSL_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_ADSL_ERROR_NOT_ADSL_CONNECTION: the connection was not of ADSL type
* @NM_DEVICE_ADSL_ERROR_INVALID_ADSL_CONNECTION: the ADSL connection was invalid
*/
typedef enum {
NM_DEVICE_ADSL_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_ADSL_ERROR_NOT_ADSL_CONNECTION, /*< nick=NotAdslConnection >*/
NM_DEVICE_ADSL_ERROR_INVALID_ADSL_CONNECTION, /*< nick=InvalidAdslConnection >*/
} NMDeviceAdslError;
#define NM_DEVICE_ADSL_ERROR nm_device_adsl_error_quark ()
GQuark nm_device_adsl_error_quark (void);
#define NM_DEVICE_ADSL_CARRIER "carrier"
typedef struct {
NMDevice parent;
} NMDeviceAdsl;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceAdslClass;
GType nm_device_adsl_get_type (void);
GObject *nm_device_adsl_new (DBusGConnection *connection, const char *path);
gboolean nm_device_adsl_get_carrier (NMDeviceAdsl *device);
G_END_DECLS
#endif /* NM_DEVICE_ADSL_H */

347
libnm/nm-device-bond.c Normal file
View File

@@ -0,0 +1,347 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2012 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include <netinet/ether.h>
#include "nm-glib-compat.h"
#include <nm-setting-connection.h>
#include <nm-setting-bond.h>
#include <nm-utils.h>
#include "nm-device-bond.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-types.h"
G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE)
#define NM_DEVICE_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BOND, NMDeviceBondPrivate))
typedef struct {
DBusGProxy *proxy;
char *hw_address;
gboolean carrier;
GPtrArray *slaves;
} NMDeviceBondPrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_CARRIER,
PROP_SLAVES,
LAST_PROP
};
/**
* nm_device_bond_error_quark:
*
* Registers an error quark for #NMDeviceBond if necessary.
*
* Returns: the error quark used for #NMDeviceBond errors.
**/
GQuark
nm_device_bond_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-bond-error-quark");
return quark;
}
/**
* nm_device_bond_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceBond.
*
* Returns: (transfer full): a new device
**/
GObject *
nm_device_bond_new (DBusGConnection *connection, const char *path)
{
GObject *device;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
device = g_object_new (NM_TYPE_DEVICE_BOND,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return device;
}
/**
* nm_device_bond_get_hw_address:
* @device: a #NMDeviceBond
*
* Gets the hardware (MAC) address of the #NMDeviceBond
*
* Returns: the hardware address. This is the internal string used by the
* device, and must not be modified.
**/
const char *
nm_device_bond_get_hw_address (NMDeviceBond *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BOND_GET_PRIVATE (device)->hw_address;
}
/**
* nm_device_bond_get_carrier:
* @device: a #NMDeviceBond
*
* Whether the device has carrier.
*
* Returns: %TRUE if the device has carrier
**/
gboolean
nm_device_bond_get_carrier (NMDeviceBond *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BOND_GET_PRIVATE (device)->carrier;
}
/**
* nm_device_bond_get_slaves:
* @device: a #NMDeviceBond
*
* Gets the devices currently slaved to @device.
*
* Returns: (element-type NMDevice): the #GPtrArray containing
* #NMDevices that are slaves of @device. This is the internal
* copy used by the device, and must not be modified.
*
* Since: 0.9.6.4
**/
const GPtrArray *
nm_device_bond_get_slaves (NMDeviceBond *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return handle_ptr_array_return (NM_DEVICE_BOND_GET_PRIVATE (device)->slaves);
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingBond *s_bond;
const char *ctype, *dev_iface_name, *bond_iface_name;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_BOND_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_BOND_ERROR, NM_DEVICE_BOND_ERROR_NOT_BOND_CONNECTION,
"The connection was not a bond connection.");
return FALSE;
}
s_bond = nm_connection_get_setting_bond (connection);
if (!s_bond) {
g_set_error (error, NM_DEVICE_BOND_ERROR, NM_DEVICE_BOND_ERROR_INVALID_BOND_CONNECTION,
"The connection was not a valid bond connection.");
return FALSE;
}
dev_iface_name = nm_device_get_iface (device);
bond_iface_name = nm_setting_bond_get_interface_name (s_bond);
if (g_strcmp0 (dev_iface_name, bond_iface_name) != 0) {
g_set_error (error, NM_DEVICE_BOND_ERROR, NM_DEVICE_BOND_ERROR_INTERFACE_MISMATCH,
"The interfaces of the device and the connection didn't match.");
return FALSE;
}
/* FIXME: check slaves? */
return NM_DEVICE_CLASS (nm_device_bond_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_BOND;
}
static const char *
get_hw_address (NMDevice *device)
{
return nm_device_bond_get_hw_address (NM_DEVICE_BOND (device));
}
/***********************************************************/
static void
nm_device_bond_init (NMDeviceBond *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BOND);
}
static void
register_properties (NMDeviceBond *device)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BOND_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BOND_CARRIER, &priv->carrier },
{ NM_DEVICE_BOND_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_bond_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_BOND);
register_properties (NM_DEVICE_BOND (object));
}
static void
dispose (GObject *object)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
if (priv->slaves) {
g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
G_OBJECT_CLASS (nm_device_bond_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object);
g_free (priv->hw_address);
G_OBJECT_CLASS (nm_device_bond_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceBond *device = NM_DEVICE_BOND (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, nm_device_bond_get_hw_address (device));
break;
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_bond_get_carrier (device));
break;
case PROP_SLAVES:
g_value_set_boxed (value, nm_device_bond_get_slaves (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_bond_class_init (NMDeviceBondClass *eth_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (eth_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class);
g_type_class_add_private (eth_class, sizeof (NMDeviceBondPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
/* properties */
/**
* NMDeviceBond:hw-address:
*
* The hardware (MAC) address of the device.
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_BOND_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceBond:carrier:
*
* Whether the device has carrier.
**/
g_object_class_install_property
(object_class, PROP_CARRIER,
g_param_spec_boolean (NM_DEVICE_BOND_CARRIER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceBond:slaves:
*
* The devices (#NMDevice) slaved to the bond device.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

82
libnm/nm-device-bond.h Normal file
View File

@@ -0,0 +1,82 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_BOND_H
#define NM_DEVICE_BOND_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_BOND (nm_device_bond_get_type ())
#define NM_DEVICE_BOND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_BOND, NMDeviceBond))
#define NM_DEVICE_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_BOND, NMDeviceBondClass))
#define NM_IS_DEVICE_BOND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_BOND))
#define NM_IS_DEVICE_BOND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BOND))
#define NM_DEVICE_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BOND, NMDeviceBondClass))
/**
* NMDeviceBondError:
* @NM_DEVICE_BOND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_BOND_ERROR_NOT_BOND_CONNECTION: the connection was not of bond type
* @NM_DEVICE_BOND_ERROR_INVALID_BOND_CONNECTION: the bond connection was invalid
* @NM_DEVICE_BOND_ERROR_INTERFACE_MISMATCH: the interfaces of the connection and the device mismatched
*/
typedef enum {
NM_DEVICE_BOND_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_BOND_ERROR_NOT_BOND_CONNECTION, /*< nick=NotBondConnection >*/
NM_DEVICE_BOND_ERROR_INVALID_BOND_CONNECTION, /*< nick=InvalidBondConnection >*/
NM_DEVICE_BOND_ERROR_INTERFACE_MISMATCH, /*< nick=InterfaceMismatch >*/
} NMDeviceBondError;
#define NM_DEVICE_BOND_ERROR nm_device_bond_error_quark ()
GQuark nm_device_bond_error_quark (void);
#define NM_DEVICE_BOND_HW_ADDRESS "hw-address"
#define NM_DEVICE_BOND_CARRIER "carrier"
#define NM_DEVICE_BOND_SLAVES "slaves"
typedef struct {
NMDevice parent;
} NMDeviceBond;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceBondClass;
GType nm_device_bond_get_type (void);
GObject *nm_device_bond_new (DBusGConnection *connection, const char *path);
const char *nm_device_bond_get_hw_address (NMDeviceBond *device);
gboolean nm_device_bond_get_carrier (NMDeviceBond *device);
const GPtrArray *nm_device_bond_get_slaves (NMDeviceBond *device);
G_END_DECLS
#endif /* NM_DEVICE_BOND_H */

359
libnm/nm-device-bridge.c Normal file
View File

@@ -0,0 +1,359 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2012 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include <netinet/ether.h>
#include "nm-glib-compat.h"
#include <nm-setting-connection.h>
#include <nm-setting-bridge.h>
#include <nm-utils.h>
#include "nm-device-bridge.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-types.h"
G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
#define NM_DEVICE_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgePrivate))
typedef struct {
DBusGProxy *proxy;
char *hw_address;
gboolean carrier;
GPtrArray *slaves;
} NMDeviceBridgePrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_CARRIER,
PROP_SLAVES,
LAST_PROP
};
/**
* nm_device_bridge_error_quark:
*
* Registers an error quark for #NMDeviceBridge if necessary.
*
* Returns: the error quark used for #NMDeviceBridge errors.
*
* Since: 0.9.8
**/
GQuark
nm_device_bridge_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-bridge-error-quark");
return quark;
}
/**
* nm_device_bridge_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceBridge.
*
* Returns: (transfer full): a new device
*
* Since: 0.9.8
**/
GObject *
nm_device_bridge_new (DBusGConnection *connection, const char *path)
{
GObject *device;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
device = g_object_new (NM_TYPE_DEVICE_BRIDGE,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return device;
}
/**
* nm_device_bridge_get_hw_address:
* @device: a #NMDeviceBridge
*
* Gets the hardware (MAC) address of the #NMDeviceBridge
*
* Returns: the hardware address. This is the internal string used by the
* device, and must not be modified.
*
* Since: 0.9.8
**/
const char *
nm_device_bridge_get_hw_address (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->hw_address;
}
/**
* nm_device_bridge_get_carrier:
* @device: a #NMDeviceBridge
*
* Whether the device has carrier.
*
* Returns: %TRUE if the device has carrier
*
* Since: 0.9.8
**/
gboolean
nm_device_bridge_get_carrier (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->carrier;
}
/**
* nm_device_bridge_get_slaves:
* @device: a #NMDeviceBridge
*
* Gets the devices currently slaved to @device.
*
* Returns: (element-type NMDevice): the #GPtrArray containing
* #NMDevices that are slaves of @device. This is the internal
* copy used by the device, and must not be modified.
*
* Since: 0.9.8
**/
const GPtrArray *
nm_device_bridge_get_slaves (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return handle_ptr_array_return (NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves);
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingBridge *s_bridge;
const char *ctype, *dev_iface_name, *bridge_iface_name;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_BRIDGE_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_BRIDGE_ERROR, NM_DEVICE_BRIDGE_ERROR_NOT_BRIDGE_CONNECTION,
"The connection was not a bridge connection.");
return FALSE;
}
s_bridge = nm_connection_get_setting_bridge (connection);
if (!s_bridge) {
g_set_error (error, NM_DEVICE_BRIDGE_ERROR, NM_DEVICE_BRIDGE_ERROR_INVALID_BRIDGE_CONNECTION,
"The connection was not a valid bridge connection.");
return FALSE;
}
dev_iface_name = nm_device_get_iface (device);
bridge_iface_name = nm_setting_bridge_get_interface_name (s_bridge);
if (g_strcmp0 (dev_iface_name, bridge_iface_name) != 0) {
g_set_error (error, NM_DEVICE_BRIDGE_ERROR, NM_DEVICE_BRIDGE_ERROR_INTERFACE_MISMATCH,
"The interfaces of the device and the connection didn't match.");
return FALSE;
}
/* FIXME: check ports? */
return NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_BRIDGE;
}
static const char *
get_hw_address (NMDevice *device)
{
return nm_device_bridge_get_hw_address (NM_DEVICE_BRIDGE (device));
}
/***********************************************************/
static void
nm_device_bridge_init (NMDeviceBridge *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BRIDGE);
}
static void
register_properties (NMDeviceBridge *device)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BRIDGE_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BRIDGE_CARRIER, &priv->carrier },
{ NM_DEVICE_BRIDGE_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_bridge_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_BRIDGE);
register_properties (NM_DEVICE_BRIDGE (object));
}
static void
dispose (GObject *object)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
if (priv->slaves) {
g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
g_free (priv->hw_address);
G_OBJECT_CLASS (nm_device_bridge_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceBridge *device = NM_DEVICE_BRIDGE (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, nm_device_bridge_get_hw_address (device));
break;
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_bridge_get_carrier (device));
break;
case PROP_SLAVES:
g_value_set_boxed (value, nm_device_bridge_get_slaves (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (bridge_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (bridge_class);
g_type_class_add_private (bridge_class, sizeof (NMDeviceBridgePrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
/* properties */
/**
* NMDeviceBridge:hw-address:
*
* The hardware (MAC) address of the device.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_BRIDGE_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceBridge:carrier:
*
* Whether the device has carrier.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_CARRIER,
g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceBridge:slaves:
*
* The devices (#NMDevice) slaved to the bridge device.
*
* Since: 0.9.8
**/
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

84
libnm/nm-device-bridge.h Normal file
View File

@@ -0,0 +1,84 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_BRIDGE_H
#define NM_DEVICE_BRIDGE_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_BRIDGE (nm_device_bridge_get_type ())
#define NM_DEVICE_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridge))
#define NM_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
#define NM_IS_DEVICE_BRIDGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_BRIDGE))
#define NM_IS_DEVICE_BRIDGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BRIDGE))
#define NM_DEVICE_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BRIDGE, NMDeviceBridgeClass))
/**
* NMDeviceBridgeError:
* @NM_DEVICE_BRIDGE_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_BRIDGE_ERROR_NOT_BRIDGE_CONNECTION: the connection was not of bridge type
* @NM_DEVICE_BRIDGE_ERROR_INVALID_BRIDGE_CONNECTION: the bridge connection was invalid
* @NM_DEVICE_BRIDGE_ERROR_INTERFACE_MISMATCH: the interfaces of the connection and the device mismatched
*
* Since: 0.9.8
*/
typedef enum {
NM_DEVICE_BRIDGE_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_BRIDGE_ERROR_NOT_BRIDGE_CONNECTION, /*< nick=NotBridgeConnection >*/
NM_DEVICE_BRIDGE_ERROR_INVALID_BRIDGE_CONNECTION, /*< nick=InvalidBridgeConnection >*/
NM_DEVICE_BRIDGE_ERROR_INTERFACE_MISMATCH, /*< nick=InterfaceMismatch >*/
} NMDeviceBridgeError;
#define NM_DEVICE_BRIDGE_ERROR nm_device_bridge_error_quark ()
GQuark nm_device_bridge_error_quark (void);
#define NM_DEVICE_BRIDGE_HW_ADDRESS "hw-address"
#define NM_DEVICE_BRIDGE_CARRIER "carrier"
#define NM_DEVICE_BRIDGE_SLAVES "slaves"
typedef struct {
NMDevice parent;
} NMDeviceBridge;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceBridgeClass;
GType nm_device_bridge_get_type (void);
GObject * nm_device_bridge_new (DBusGConnection *connection, const char *path);
const char *nm_device_bridge_get_hw_address (NMDeviceBridge *device);
gboolean nm_device_bridge_get_carrier (NMDeviceBridge *device);
const GPtrArray *nm_device_bridge_get_slaves (NMDeviceBridge *device);
G_END_DECLS
#endif /* NM_DEVICE_BRIDGE_H */

373
libnm/nm-device-bt.c Normal file
View File

@@ -0,0 +1,373 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2007 - 2012 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include <netinet/ether.h>
#include "nm-glib-compat.h"
#include <nm-setting-connection.h>
#include <nm-setting-bluetooth.h>
#include "nm-device-bt.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
G_DEFINE_TYPE (NMDeviceBt, nm_device_bt, NM_TYPE_DEVICE)
#define NM_DEVICE_BT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_BT, NMDeviceBtPrivate))
typedef struct {
DBusGProxy *proxy;
char *hw_address;
char *name;
guint32 bt_capabilities;
} NMDeviceBtPrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_NAME,
PROP_BT_CAPABILITIES,
LAST_PROP
};
/**
* nm_device_bt_error_quark:
*
* Registers an error quark for #NMDeviceBt if necessary.
*
* Returns: the error quark used for #NMDeviceBt errors.
**/
GQuark
nm_device_bt_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-bt-error-quark");
return quark;
}
/**
* nm_device_bt_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceBt.
*
* Returns: (transfer full): a new device
**/
GObject *
nm_device_bt_new (DBusGConnection *connection, const char *path)
{
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
return g_object_new (NM_TYPE_DEVICE_BT,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
}
/**
* nm_device_bt_get_hw_address:
* @device: a #NMDeviceBt
*
* Gets the hardware (MAC) address of the #NMDeviceBt
*
* Returns: the hardware address. This is the internal string used by the
* device, and must not be modified.
**/
const char *
nm_device_bt_get_hw_address (NMDeviceBt *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BT (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BT_GET_PRIVATE (device)->hw_address;
}
/**
* nm_device_bt_get_name:
* @device: a #NMDeviceBt
*
* Gets the name of the #NMDeviceBt.
*
* Returns: the name of the device
**/
const char *
nm_device_bt_get_name (NMDeviceBt *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BT (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BT_GET_PRIVATE (device)->name;
}
/**
* nm_device_bt_get_capabilities:
* @device: a #NMDeviceBt
*
* Returns the Bluetooth device's usable capabilities.
*
* Returns: a combination of #NMBluetoothCapabilities
**/
NMBluetoothCapabilities
nm_device_bt_get_capabilities (NMDeviceBt *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BT (device), NM_BT_CAPABILITY_NONE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_BT_GET_PRIVATE (device)->bt_capabilities;
}
static NMBluetoothCapabilities
get_connection_bt_type (NMConnection *connection)
{
NMSettingBluetooth *s_bt;
const char *bt_type;
s_bt = nm_connection_get_setting_bluetooth (connection);
if (!s_bt)
return NM_BT_CAPABILITY_NONE;
bt_type = nm_setting_bluetooth_get_connection_type (s_bt);
g_assert (bt_type);
if (!strcmp (bt_type, NM_SETTING_BLUETOOTH_TYPE_DUN))
return NM_BT_CAPABILITY_DUN;
else if (!strcmp (bt_type, NM_SETTING_BLUETOOTH_TYPE_PANU))
return NM_BT_CAPABILITY_NAP;
return NM_BT_CAPABILITY_NONE;
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingBluetooth *s_bt;
const char *ctype;
const GByteArray *mac;
const char *hw_str;
struct ether_addr *hw_mac;
NMBluetoothCapabilities dev_caps;
NMBluetoothCapabilities bt_type;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_BLUETOOTH_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION,
"The connection was not a Bluetooth connection.");
return FALSE;
}
s_bt = nm_connection_get_setting_bluetooth (connection);
if (!s_bt) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION,
"The connection was not a valid Bluetooth connection.");
return FALSE;
}
/* Check BT address */
hw_str = nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
if (hw_str) {
hw_mac = ether_aton (hw_str);
if (!hw_mac) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_bluetooth_get_bdaddr (s_bt);
if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match.");
return FALSE;
}
}
dev_caps = nm_device_bt_get_capabilities (NM_DEVICE_BT (device));
bt_type = get_connection_bt_type (connection);
if (!(bt_type & dev_caps)) {
g_set_error (error, NM_DEVICE_BT_ERROR, NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS,
"The device missed BT capabilities required by the connection.");
return FALSE;
}
return NM_DEVICE_CLASS (nm_device_bt_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_BLUETOOTH;
}
static const char *
get_hw_address (NMDevice *device)
{
return nm_device_bt_get_hw_address (NM_DEVICE_BT (device));
}
/************************************************************/
static void
nm_device_bt_init (NMDeviceBt *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BT);
}
static void
register_properties (NMDeviceBt *device)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BT_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BT_NAME, &priv->name },
{ NM_DEVICE_BT_CAPABILITIES, &priv->bt_capabilities },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_bt_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_BLUETOOTH);
register_properties (NM_DEVICE_BT (object));
}
static void
dispose (GObject *object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_bt_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
g_free (priv->hw_address);
g_free (priv->name);
G_OBJECT_CLASS (nm_device_bt_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceBt *device = NM_DEVICE_BT (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, nm_device_bt_get_hw_address (device));
break;
case PROP_NAME:
g_value_set_string (value, nm_device_bt_get_name (device));
break;
case PROP_BT_CAPABILITIES:
g_value_set_uint (value, nm_device_bt_get_capabilities (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_bt_class_init (NMDeviceBtClass *bt_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (bt_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (bt_class);
g_type_class_add_private (bt_class, sizeof (NMDeviceBtPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
/* properties */
/**
* NMDeviceBt:hw-address:
*
* The hardware (MAC) address of the device.
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_BT_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceBt:name:
*
* The name of the bluetooth device.
**/
g_object_class_install_property
(object_class, PROP_NAME,
g_param_spec_string (NM_DEVICE_BT_NAME, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceBt:bt-capabilities:
*
* The device's bluetooth capabilities, a combination of #NMBluetoothCapabilities.
**/
g_object_class_install_property
(object_class, PROP_BT_CAPABILITIES,
g_param_spec_uint (NM_DEVICE_BT_CAPABILITIES, "", "",
NM_BT_CAPABILITY_NONE, G_MAXUINT32, NM_BT_CAPABILITY_NONE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

90
libnm/nm-device-bt.h Normal file
View File

@@ -0,0 +1,90 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2008 - 2012 Red Hat, Inc.
* Copyright 2008 Novell, Inc.
*/
#ifndef NM_DEVICE_BT_H
#define NM_DEVICE_BT_H
#include "NetworkManager.h"
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_BT (nm_device_bt_get_type ())
#define NM_DEVICE_BT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_BT, NMDeviceBt))
#define NM_DEVICE_BT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_BT, NMDeviceBtClass))
#define NM_IS_DEVICE_BT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_BT))
#define NM_IS_DEVICE_BT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_BT))
#define NM_DEVICE_BT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_BT, NMDeviceBtClass))
/**
* NMDeviceBtError:
* @NM_DEVICE_BT_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION: the connection was not of bluetooth type
* @NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION: the bluetooth connection was invalid
* @NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC: the device's MAC was invalid
* @NM_DEVICE_BT_ERROR_MAC_MISMATCH: the MACs of the connection and the device mismatched
* @NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS: the device missed required capabilities
*/
typedef enum {
NM_DEVICE_BT_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_BT_ERROR_NOT_BT_CONNECTION, /*< nick=NotBtConnection >*/
NM_DEVICE_BT_ERROR_INVALID_BT_CONNECTION, /*< nick=InvalidBtConnection >*/
NM_DEVICE_BT_ERROR_INVALID_DEVICE_MAC, /*< nick=InvalidDeviceMac >*/
NM_DEVICE_BT_ERROR_MAC_MISMATCH, /*< nick=MacMismatch >*/
NM_DEVICE_BT_ERROR_MISSING_DEVICE_CAPS, /*< nick=MissingDeviceCaps >*/
} NMDeviceBtError;
#define NM_DEVICE_BT_ERROR nm_device_bt_error_quark ()
GQuark nm_device_bt_error_quark (void);
#define NM_DEVICE_BT_HW_ADDRESS "hw-address"
#define NM_DEVICE_BT_NAME "name"
#define NM_DEVICE_BT_CAPABILITIES "bt-capabilities"
typedef struct {
NMDevice parent;
} NMDeviceBt;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceBtClass;
GType nm_device_bt_get_type (void);
GObject *nm_device_bt_new (DBusGConnection *connection, const char *path);
const char *nm_device_bt_get_hw_address (NMDeviceBt *device);
const char *nm_device_bt_get_name (NMDeviceBt *device);
NMBluetoothCapabilities nm_device_bt_get_capabilities (NMDeviceBt *device);
G_END_DECLS
#endif /* NM_DEVICE_BT_H */

392
libnm/nm-device-ethernet.c Normal file
View File

@@ -0,0 +1,392 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2007 - 2012 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include <netinet/ether.h>
#include "nm-glib-compat.h"
#include <nm-setting-connection.h>
#include <nm-setting-wired.h>
#include <nm-setting-pppoe.h>
#include "nm-device-ethernet.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
G_DEFINE_TYPE (NMDeviceEthernet, nm_device_ethernet, NM_TYPE_DEVICE)
#define NM_DEVICE_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetPrivate))
typedef struct {
DBusGProxy *proxy;
char *hw_address;
char *perm_hw_address;
guint32 speed;
gboolean carrier;
} NMDeviceEthernetPrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_PERM_HW_ADDRESS,
PROP_SPEED,
PROP_CARRIER,
LAST_PROP
};
/**
* nm_device_ethernet_error_quark:
*
* Registers an error quark for #NMDeviceEthernet if necessary.
*
* Returns: the error quark used for #NMDeviceEthernet errors.
**/
GQuark
nm_device_ethernet_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-ethernet-error-quark");
return quark;
}
/**
* nm_device_ethernet_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceEthernet.
*
* Returns: (transfer full): a new device
**/
GObject *
nm_device_ethernet_new (DBusGConnection *connection, const char *path)
{
GObject *device;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
device = g_object_new (NM_TYPE_DEVICE_ETHERNET,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return device;
}
/**
* nm_device_ethernet_get_hw_address:
* @device: a #NMDeviceEthernet
*
* Gets the active hardware (MAC) address of the #NMDeviceEthernet
*
* Returns: the active hardware address. This is the internal string used by the
* device, and must not be modified.
**/
const char *
nm_device_ethernet_get_hw_address (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->hw_address;
}
/**
* nm_device_ethernet_get_permanent_hw_address:
* @device: a #NMDeviceEthernet
*
* Gets the permanent hardware (MAC) address of the #NMDeviceEthernet
*
* Returns: the permanent hardware address. This is the internal string used by the
* device, and must not be modified.
**/
const char *
nm_device_ethernet_get_permanent_hw_address (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->perm_hw_address;
}
/**
* nm_device_ethernet_get_speed:
* @device: a #NMDeviceEthernet
*
* Gets the speed of the #NMDeviceEthernet.
*
* Returns: the speed of the device
**/
guint32
nm_device_ethernet_get_speed (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), 0);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->speed;
}
/**
* nm_device_ethernet_get_carrier:
* @device: a #NMDeviceEthernet
*
* Whether the device has carrier.
*
* Returns: %TRUE if the device has carrier
**/
gboolean
nm_device_ethernet_get_carrier (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_ETHERNET_GET_PRIVATE (device)->carrier;
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingWired *s_wired;
const char *ctype;
gboolean is_pppoe = FALSE;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (!strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME))
is_pppoe = TRUE;
else if (strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION,
"The connection was not a wired or PPPoE connection.");
return FALSE;
}
s_wired = nm_connection_get_setting_wired (connection);
/* Wired setting optional for PPPoE */
if (!is_pppoe && !s_wired) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION,
"The connection was not a valid Ethernet connection.");
return FALSE;
}
if (s_wired) {
const GByteArray *mac;
const char *perm_str;
struct ether_addr *perm_mac;
/* FIXME: filter using s390 subchannels when they are exported over the bus */
/* Check MAC address */
perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device));
if (perm_str) {
perm_mac = ether_aton (perm_str);
if (!perm_mac) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_wired_get_mac_address (s_wired);
if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN)) {
g_set_error (error, NM_DEVICE_ETHERNET_ERROR, NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match.");
return FALSE;
}
}
}
return NM_DEVICE_CLASS (nm_device_ethernet_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_WIRED;
}
static const char *
get_hw_address (NMDevice *device)
{
return nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (device));
}
/***********************************************************/
static void
nm_device_ethernet_init (NMDeviceEthernet *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ETHERNET);
}
static void
register_properties (NMDeviceEthernet *device)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_ETHERNET_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, &priv->perm_hw_address },
{ NM_DEVICE_ETHERNET_SPEED, &priv->speed },
{ NM_DEVICE_ETHERNET_CARRIER, &priv->carrier },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_ethernet_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_WIRED);
register_properties (NM_DEVICE_ETHERNET (object));
}
static void
dispose (GObject *object)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_ethernet_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object);
g_free (priv->hw_address);
g_free (priv->perm_hw_address);
G_OBJECT_CLASS (nm_device_ethernet_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceEthernet *device = NM_DEVICE_ETHERNET (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, nm_device_ethernet_get_hw_address (device));
break;
case PROP_PERM_HW_ADDRESS:
g_value_set_string (value, nm_device_ethernet_get_permanent_hw_address (device));
break;
case PROP_SPEED:
g_value_set_uint (value, nm_device_ethernet_get_speed (device));
break;
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_ethernet_get_carrier (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (eth_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class);
g_type_class_add_private (eth_class, sizeof (NMDeviceEthernetPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
/* properties */
/**
* NMDeviceEthernet:hw-address:
*
* The active hardware (MAC) address of the device.
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_ETHERNET_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceEthernet:perm-hw-address:
*
* The permanent hardware (MAC) address of the device.
**/
g_object_class_install_property
(object_class, PROP_PERM_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceEthernet:speed:
*
* The speed of the device.
**/
g_object_class_install_property
(object_class, PROP_SPEED,
g_param_spec_uint (NM_DEVICE_ETHERNET_SPEED, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceEthernet:carrier:
*
* Whether the device has carrier.
**/
g_object_class_install_property
(object_class, PROP_CARRIER,
g_param_spec_boolean (NM_DEVICE_ETHERNET_CARRIER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,87 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2007 - 2008 Novell, Inc.
* Copyright 2007 - 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_ETHERNET_H
#define NM_DEVICE_ETHERNET_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_ETHERNET (nm_device_ethernet_get_type ())
#define NM_DEVICE_ETHERNET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernet))
#define NM_DEVICE_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetClass))
#define NM_IS_DEVICE_ETHERNET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_ETHERNET))
#define NM_IS_DEVICE_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_ETHERNET))
#define NM_DEVICE_ETHERNET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetClass))
/**
* NMDeviceEthernetError:
* @NM_DEVICE_ETHERNET_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION: the connection was not of Ethernet or PPPoE type
* @NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION: the Ethernet connection was invalid
* @NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC: the device's MAC was invalid
* @NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH: the MACs of the connection and the device mismatched
*/
typedef enum {
NM_DEVICE_ETHERNET_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_ETHERNET_ERROR_NOT_ETHERNET_CONNECTION, /*< nick=NotEthernetConnection >*/
NM_DEVICE_ETHERNET_ERROR_INVALID_ETHERNET_CONNECTION, /*< nick=InvalidEthernetConnection >*/
NM_DEVICE_ETHERNET_ERROR_INVALID_DEVICE_MAC, /*< nick=InvalidDeviceMac >*/
NM_DEVICE_ETHERNET_ERROR_MAC_MISMATCH, /*< nick=MacMismatch >*/
} NMDeviceEthernetError;
#define NM_DEVICE_ETHERNET_ERROR nm_device_ethernet_error_quark ()
GQuark nm_device_ethernet_error_quark (void);
#define NM_DEVICE_ETHERNET_HW_ADDRESS "hw-address"
#define NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS "perm-hw-address"
#define NM_DEVICE_ETHERNET_SPEED "speed"
#define NM_DEVICE_ETHERNET_CARRIER "carrier"
typedef struct {
NMDevice parent;
} NMDeviceEthernet;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceEthernetClass;
GType nm_device_ethernet_get_type (void);
GObject *nm_device_ethernet_new (DBusGConnection *connection, const char *path);
const char * nm_device_ethernet_get_hw_address (NMDeviceEthernet *device);
const char * nm_device_ethernet_get_permanent_hw_address (NMDeviceEthernet *device);
guint32 nm_device_ethernet_get_speed (NMDeviceEthernet *device);
gboolean nm_device_ethernet_get_carrier (NMDeviceEthernet *device);
G_END_DECLS
#endif /* NM_DEVICE_ETHERNET_H */

284
libnm/nm-device-generic.c Normal file
View File

@@ -0,0 +1,284 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include "nm-device-generic.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-setting-generic.h"
G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
#define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate))
typedef struct {
DBusGProxy *proxy;
char *hw_address;
char *type_description;
} NMDeviceGenericPrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_TYPE_DESCRIPTION,
LAST_PROP
};
/**
* nm_device_generic_error_quark:
*
* Registers an error quark for #NMDeviceGeneric if necessary.
*
* Returns: the error quark used for #NMDeviceGeneric errors.
*
* Since: 0.9.10
**/
GQuark
nm_device_generic_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-generic-error-quark");
return quark;
}
/**
* nm_device_generic_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceGeneric.
*
* Returns: (transfer full): a new device
*
* Since: 0.9.10
**/
GObject *
nm_device_generic_new (DBusGConnection *connection, const char *path)
{
GObject *device;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
device = g_object_new (NM_TYPE_DEVICE_GENERIC,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return device;
}
/**
* nm_device_generic_get_hw_address:
* @device: a #NMDeviceGeneric
*
* Gets the hardware address of the #NMDeviceGeneric
*
* Returns: the hardware address. This is the internal string used by the
* device, and must not be modified.
*
* Since: 0.9.10
**/
const char *
nm_device_generic_get_hw_address (NMDeviceGeneric *device)
{
g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address;
}
/***********************************************************/
static const char *
get_type_description (NMDevice *device)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
_nm_object_ensure_inited (NM_OBJECT (device));
return priv->type_description;
}
static const char *
get_hw_address (NMDevice *device)
{
return nm_device_generic_get_hw_address (NM_DEVICE_GENERIC (device));
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
const char *ctype, *iface_name;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_GENERIC_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_GENERIC_ERROR, NM_DEVICE_GENERIC_ERROR_NOT_GENERIC_CONNECTION,
"The connection was not a generic connection.");
return FALSE;
}
iface_name = nm_setting_connection_get_interface_name (s_con);
if (!iface_name) {
g_set_error (error, NM_DEVICE_GENERIC_ERROR, NM_DEVICE_GENERIC_ERROR_MISSING_INTERFACE_NAME,
"The connection did not specify an interface name.");
return FALSE;
}
return NM_DEVICE_CLASS (nm_device_generic_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_GENERIC;
}
/***********************************************************/
static void
nm_device_generic_init (NMDeviceGeneric *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_GENERIC);
}
static void
register_properties (NMDeviceGeneric *device)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_GENERIC);
register_properties (NM_DEVICE_GENERIC (object));
}
static void
dispose (GObject *object)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_generic_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
g_free (priv->hw_address);
g_free (priv->type_description);
G_OBJECT_CLASS (nm_device_generic_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, priv->hw_address);
break;
case PROP_TYPE_DESCRIPTION:
g_value_set_string (value, priv->type_description);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_generic_class_init (NMDeviceGenericClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate));
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->get_type_description = get_type_description;
device_class->get_hw_address = get_hw_address;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
/**
* NMDeviceGeneric:hw-address:
*
* The hardware address of the device.
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceGeneric:type-description:
*
* A description of the specific type of device this is, or %NULL
* if not known.
**/
g_object_class_install_property
(object_class, PROP_TYPE_DESCRIPTION,
g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

79
libnm/nm-device-generic.h Normal file
View File

@@ -0,0 +1,79 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NM_DEVICE_GENERIC_H
#define NM_DEVICE_GENERIC_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_GENERIC (nm_device_generic_get_type ())
#define NM_DEVICE_GENERIC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_GENERIC, NMDeviceGeneric))
#define NM_DEVICE_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericClass))
#define NM_IS_DEVICE_GENERIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_GENERIC))
#define NM_IS_DEVICE_GENERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_GENERIC))
#define NM_DEVICE_GENERIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericClass))
/**
* NMDeviceGenericError:
* @NM_DEVICE_GENERIC_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_GENERIC_ERROR_NOT_GENERIC_CONNECTION: the connection was not of generic type
* @NM_DEVICE_GENERIC_ERROR_MISSING_INTERFACE_NAME: the connection did not specify the interface name
*/
typedef enum {
NM_DEVICE_GENERIC_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_GENERIC_ERROR_NOT_GENERIC_CONNECTION, /*< nick=NotGenericConnection >*/
NM_DEVICE_GENERIC_ERROR_MISSING_INTERFACE_NAME, /*< nick=MissingInterfaceName >*/
} NMDeviceGenericError;
#define NM_DEVICE_GENERIC_ERROR nm_device_generic_error_quark ()
GQuark nm_device_generic_error_quark (void);
#define NM_DEVICE_GENERIC_HW_ADDRESS "hw-address"
#define NM_DEVICE_GENERIC_TYPE_DESCRIPTION "type-description"
typedef struct {
NMDevice parent;
} NMDeviceGeneric;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceGenericClass;
NM_AVAILABLE_IN_0_9_10
GType nm_device_generic_get_type (void);
NM_AVAILABLE_IN_0_9_10
GObject *nm_device_generic_new (DBusGConnection *connection, const char *path);
const char *nm_device_generic_get_hw_address (NMDeviceGeneric *device);
G_END_DECLS
#endif /* NM_DEVICE_GENERIC_H */

View File

@@ -0,0 +1,311 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2012 Red Hat, Inc.
*/
#include <config.h>
#include <string.h>
#include <linux/if_infiniband.h>
#include <netinet/ether.h>
#include "nm-glib-compat.h"
#include <nm-setting-connection.h>
#include <nm-setting-infiniband.h>
#include <nm-utils.h>
#include "nm-device-infiniband.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE)
#define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate))
typedef struct {
DBusGProxy *proxy;
char *hw_address;
gboolean carrier;
} NMDeviceInfinibandPrivate;
enum {
PROP_0,
PROP_HW_ADDRESS,
PROP_CARRIER,
LAST_PROP
};
/**
* nm_device_infiniband_error_quark:
*
* Registers an error quark for #NMDeviceInfiniband if necessary.
*
* Returns: the error quark used for #NMDeviceInfiniband errors.
**/
GQuark
nm_device_infiniband_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-infiniband-error-quark");
return quark;
}
/**
* nm_device_infiniband_new:
* @connection: the #DBusGConnection
* @path: the DBus object path of the device
*
* Creates a new #NMDeviceInfiniband.
*
* Returns: (transfer full): a new device
**/
GObject *
nm_device_infiniband_new (DBusGConnection *connection, const char *path)
{
GObject *device;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
device = g_object_new (NM_TYPE_DEVICE_INFINIBAND,
NM_OBJECT_DBUS_CONNECTION, connection,
NM_OBJECT_DBUS_PATH, path,
NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return device;
}
/**
* nm_device_infiniband_get_hw_address:
* @device: a #NMDeviceInfiniband
*
* Gets the hardware (MAC) address of the #NMDeviceInfiniband
*
* Returns: the hardware address. This is the internal string used by the
* device, and must not be modified.
**/
const char *
nm_device_infiniband_get_hw_address (NMDeviceInfiniband *device)
{
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), NULL);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->hw_address;
}
/**
* nm_device_infiniband_get_carrier:
* @device: a #NMDeviceInfiniband
*
* Whether the device has carrier.
*
* Returns: %TRUE if the device has carrier
**/
gboolean
nm_device_infiniband_get_carrier (NMDeviceInfiniband *device)
{
g_return_val_if_fail (NM_IS_DEVICE_INFINIBAND (device), FALSE);
_nm_object_ensure_inited (NM_OBJECT (device));
return NM_DEVICE_INFINIBAND_GET_PRIVATE (device)->carrier;
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingInfiniband *s_infiniband;
const char *ctype, *hwaddr_str;
const GByteArray *mac;
guint8 *hwaddr, hwaddr_buf[INFINIBAND_ALEN];
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if (strcmp (ctype, NM_SETTING_INFINIBAND_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION,
"The connection was not a InfiniBand connection.");
return FALSE;
}
s_infiniband = nm_connection_get_setting_infiniband (connection);
if (!s_infiniband) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION,
"The connection was not a valid InfiniBand connection.");
return FALSE;
}
hwaddr_str = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
if (hwaddr_str) {
hwaddr = nm_utils_hwaddr_aton (hwaddr_str, ARPHRD_INFINIBAND, hwaddr_buf);
if (!hwaddr) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC,
"Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
/* We only match against the last 8 bytes */
if (mac && hwaddr && memcmp (mac->data + INFINIBAND_ALEN - 8, hwaddr + INFINIBAND_ALEN - 8, 8)) {
g_set_error (error, NM_DEVICE_INFINIBAND_ERROR, NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH,
"The MACs of the device and the connection didn't match.");
return FALSE;
}
}
return NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
return NM_TYPE_SETTING_INFINIBAND;
}
static const char *
get_hw_address (NMDevice *device)
{
return nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
}
/***********************************************************/
static void
nm_device_infiniband_init (NMDeviceInfiniband *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_INFINIBAND);
}
static void
register_properties (NMDeviceInfiniband *device)
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_INFINIBAND_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_INFINIBAND_CARRIER, &priv->carrier },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_infiniband_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_INFINIBAND);
register_properties (NM_DEVICE_INFINIBAND (object));
}
static void
dispose (GObject *object)
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_infiniband_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object);
g_free (priv->hw_address);
G_OBJECT_CLASS (nm_device_infiniband_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceInfiniband *device = NM_DEVICE_INFINIBAND (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_HW_ADDRESS:
g_value_set_string (value, nm_device_infiniband_get_hw_address (device));
break;
case PROP_CARRIER:
g_value_set_boolean (value, nm_device_infiniband_get_carrier (device));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_device_infiniband_class_init (NMDeviceInfinibandClass *eth_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (eth_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class);
g_type_class_add_private (eth_class, sizeof (NMDeviceInfinibandPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
/* properties */
/**
* NMDeviceInfiniband:hw-address:
*
* The hardware (MAC) address of the device.
**/
g_object_class_install_property
(object_class, PROP_HW_ADDRESS,
g_param_spec_string (NM_DEVICE_INFINIBAND_HW_ADDRESS, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceInfiniband:carrier:
*
* Whether the device has carrier.
**/
g_object_class_install_property
(object_class, PROP_CARRIER,
g_param_spec_boolean (NM_DEVICE_INFINIBAND_CARRIER, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -0,0 +1,82 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2012 Red Hat, Inc.
*/
#ifndef NM_DEVICE_INFINIBAND_H
#define NM_DEVICE_INFINIBAND_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_INFINIBAND (nm_device_infiniband_get_type ())
#define NM_DEVICE_INFINIBAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfiniband))
#define NM_DEVICE_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandClass))
#define NM_IS_DEVICE_INFINIBAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_INFINIBAND))
#define NM_IS_DEVICE_INFINIBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_INFINIBAND))
#define NM_DEVICE_INFINIBAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandClass))
/**
* NMDeviceInfinibandError:
* @NM_DEVICE_INFINIBAND_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION: the connection was not of InfiniBand type
* @NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION: the InfiniBand connection was invalid
* @NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC: the device's MAC was invalid
* @NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH: the MACs of the connection and the device mismatched
*/
typedef enum {
NM_DEVICE_INFINIBAND_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_INFINIBAND_ERROR_NOT_INFINIBAND_CONNECTION, /*< nick=NotInfinibandConnection >*/
NM_DEVICE_INFINIBAND_ERROR_INVALID_INFINIBAND_CONNECTION, /*< nick=InvalidInfinibandConnection >*/
NM_DEVICE_INFINIBAND_ERROR_INVALID_DEVICE_MAC, /*< nick=InvalidDeviceMac >*/
NM_DEVICE_INFINIBAND_ERROR_MAC_MISMATCH, /*< nick=MacMismatch >*/
} NMDeviceInfinibandError;
#define NM_DEVICE_INFINIBAND_ERROR nm_device_infiniband_error_quark ()
GQuark nm_device_infiniband_error_quark (void);
#define NM_DEVICE_INFINIBAND_HW_ADDRESS "hw-address"
#define NM_DEVICE_INFINIBAND_CARRIER "carrier"
typedef struct {
NMDevice parent;
} NMDeviceInfiniband;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceInfinibandClass;
GType nm_device_infiniband_get_type (void);
GObject *nm_device_infiniband_new (DBusGConnection *connection, const char *path);
const char * nm_device_infiniband_get_hw_address (NMDeviceInfiniband *device);
gboolean nm_device_infiniband_get_carrier (NMDeviceInfiniband *device);
G_END_DECLS
#endif /* NM_DEVICE_INFINIBAND_H */

291
libnm/nm-device-modem.c Normal file
View File

@@ -0,0 +1,291 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2012 Red Hat, Inc.
* Copyright 2008 Novell, Inc.
*/
#include <config.h>
#include <string.h>
#include "nm-glib-compat.h"
#include <nm-setting-connection.h>
#include <nm-setting-gsm.h>
#include <nm-setting-cdma.h>
#include "nm-device-modem.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
#define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate))
typedef struct {
DBusGProxy *proxy;
NMDeviceModemCapabilities caps;
NMDeviceModemCapabilities current_caps;
} NMDeviceModemPrivate;
enum {
PROP_0,
PROP_MODEM_CAPS,
PROP_CURRENT_CAPS,
LAST_PROP
};
/**
* nm_device_modem_error_quark:
*
* Registers an error quark for #NMDeviceModem if necessary.
*
* Returns: the error quark used for #NMDeviceModem errors.
**/
GQuark
nm_device_modem_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0))
quark = g_quark_from_static_string ("nm-device-modem-error-quark");
return quark;
}
/**
* nm_device_modem_get_modem_capabilities:
* @self: a #NMDeviceModem
*
* Returns a bitfield of the generic access technology families the modem
* supports. Not all capabilities are available concurrently however; some
* may require a firmware reload or reinitialization.
*
* Returns: the generic access technology families the modem supports
**/
NMDeviceModemCapabilities
nm_device_modem_get_modem_capabilities (NMDeviceModem *self)
{
g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
_nm_object_ensure_inited (NM_OBJECT (self));
return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps;
}
/**
* nm_device_modem_get_current_capabilities:
* @self: a #NMDeviceModem
*
* Returns a bitfield of the generic access technology families the modem
* supports without a firmware reload or reinitialization. This value
* represents the network types the modem can immediately connect to.
*
* Returns: the generic access technology families the modem supports without
* a firmware reload or other reinitialization
**/
NMDeviceModemCapabilities
nm_device_modem_get_current_capabilities (NMDeviceModem *self)
{
g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
_nm_object_ensure_inited (NM_OBJECT (self));
return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps;
}
static const char *
get_type_description (NMDevice *device)
{
NMDeviceModemCapabilities caps;
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
return "gsm";
else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
return "cdma";
else
return NULL;
}
#define MODEM_CAPS_3GPP(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | \
NM_DEVICE_MODEM_CAPABILITY_LTE))
#define MODEM_CAPS_3GPP2(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO))
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingGsm *s_gsm;
NMSettingCdma *s_cdma;
const char *ctype;
NMDeviceModemCapabilities current_caps;
s_con = nm_connection_get_setting_connection (connection);
g_assert (s_con);
ctype = nm_setting_connection_get_connection_type (s_con);
if ( strcmp (ctype, NM_SETTING_GSM_SETTING_NAME) != 0
&& strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME) != 0) {
g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_NOT_MODEM_CONNECTION,
"The connection was not a modem connection.");
return FALSE;
}
s_gsm = nm_connection_get_setting_gsm (connection);
s_cdma = nm_connection_get_setting_cdma (connection);
if (!s_cdma && !s_gsm) {
g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_INVALID_MODEM_CONNECTION,
"The connection was not a valid modem connection.");
return FALSE;
}
current_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
if (!(s_gsm && MODEM_CAPS_3GPP (current_caps)) && !(s_cdma && MODEM_CAPS_3GPP2 (current_caps))) {
g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_MISSING_DEVICE_CAPS,
"The device missed capabilities required by the GSM/CDMA connection.");
return FALSE;
}
return NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error);
}
static GType
get_setting_type (NMDevice *device)
{
NMDeviceModemCapabilities caps;
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
if (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE))
return NM_TYPE_SETTING_GSM;
else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
return NM_TYPE_SETTING_CDMA;
else
return G_TYPE_INVALID;
}
/*******************************************************************/
static void
nm_device_modem_init (NMDeviceModem *device)
{
_nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MODEM);
}
static void
register_properties (NMDeviceModem *device)
{
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_MODEM_MODEM_CAPABILITIES, &priv->caps },
{ NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps },
{ NULL },
};
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
constructed (GObject *object)
{
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
G_OBJECT_CLASS (nm_device_modem_parent_class)->constructed (object);
priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_MODEM);
register_properties (NM_DEVICE_MODEM (object));
}
static void
get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NMDeviceModem *self = NM_DEVICE_MODEM (object);
_nm_object_ensure_inited (NM_OBJECT (object));
switch (prop_id) {
case PROP_MODEM_CAPS:
g_value_set_uint (value, nm_device_modem_get_modem_capabilities (self));
break;
case PROP_CURRENT_CAPS:
g_value_set_uint (value, nm_device_modem_get_current_capabilities (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dispose (GObject *object)
{
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_modem_parent_class)->dispose (object);
}
static void
nm_device_modem_class_init (NMDeviceModemClass *modem_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (modem_class);
g_type_class_add_private (modem_class, sizeof (NMDeviceModemPrivate));
/* virtual methods */
object_class->constructed = constructed;
object_class->get_property = get_property;
object_class->dispose = dispose;
device_class->get_type_description = get_type_description;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
/**
* NMDeviceModem:modem-capabilities:
*
* The generic family of access technologies the modem supports. Not all
* capabilities are available at the same time however; some modems require
* a firmware reload or other reinitialization to switch between eg
* CDMA/EVDO and GSM/UMTS.
**/
g_object_class_install_property
(object_class, PROP_MODEM_CAPS,
g_param_spec_uint (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMDeviceModem:current-capabilities:
*
* The generic family of access technologies the modem currently supports
* without a firmware reload or reinitialization.
**/
g_object_class_install_property
(object_class, PROP_CURRENT_CAPS,
g_param_spec_uint (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "",
0, G_MAXUINT32, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

79
libnm/nm-device-modem.h Normal file
View File

@@ -0,0 +1,79 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* Copyright 2011 - 2012 Red Hat, Inc.
* Copyright 2008 Novell, Inc.
*/
#ifndef NM_DEVICE_MODEM_H
#define NM_DEVICE_MODEM_H
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_MODEM (nm_device_modem_get_type ())
#define NM_DEVICE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_MODEM, NMDeviceModem))
#define NM_DEVICE_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_MODEM, NMDeviceModemClass))
#define NM_IS_DEVICE_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_MODEM))
#define NM_IS_DEVICE_MODEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_MODEM))
#define NM_DEVICE_MODEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_MODEM, NMDeviceModemClass))
/**
* NMDeviceModemError:
* @NM_DEVICE_MODEM_ERROR_UNKNOWN: unknown or unclassified error
* @NM_DEVICE_MODEM_ERROR_NOT_MODEM_CONNECTION: the connection was not of modem type
* @NM_DEVICE_MODEM_ERROR_INVALID_MODEM_CONNECTION: the modem connection was invalid
* @NM_DEVICE_MODEM_ERROR_MISSING_DEVICE_CAPS: the device missed required capabilities
*/
typedef enum {
NM_DEVICE_MODEM_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_DEVICE_MODEM_ERROR_NOT_MODEM_CONNECTION, /*< nick=NotModemConnection >*/
NM_DEVICE_MODEM_ERROR_INVALID_MODEM_CONNECTION, /*< nick=InvalidModemConnection >*/
NM_DEVICE_MODEM_ERROR_MISSING_DEVICE_CAPS, /*< nick=MissingDeviceCaps >*/
} NMDeviceModemError;
#define NM_DEVICE_MODEM_ERROR nm_device_modem_error_quark ()
GQuark nm_device_modem_error_quark (void);
#define NM_DEVICE_MODEM_MODEM_CAPABILITIES "modem-capabilities"
#define NM_DEVICE_MODEM_CURRENT_CAPABILITIES "current-capabilities"
typedef struct {
NMDevice parent;
} NMDeviceModem;
typedef struct {
NMDeviceClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
void (*_reserved5) (void);
void (*_reserved6) (void);
} NMDeviceModemClass;
GType nm_device_modem_get_type (void);
NMDeviceModemCapabilities nm_device_modem_get_modem_capabilities (NMDeviceModem *self);
NMDeviceModemCapabilities nm_device_modem_get_current_capabilities (NMDeviceModem *self);
G_END_DECLS
#endif /* NM_DEVICE_MODEM_H */

Some files were not shown because too many files have changed in this diff Show More