1. 19 Nov, 2014 2 commits
    • Lubomir Rintel's avatar
      libnm-core: Add missing type cast · c30379e0
      Lubomir Rintel authored
      Fixes testing on 32-bit arches:
      
      /core/general/test_setting_compare_timestamp:
      (./test-general:29331): GLib-GObject-WARNING **: g_object_set_valist: object class `NMSettingConnection' has no property named `$?\xff\xff\x89t$0\x89|$4\xe8\u001c\x98\xff\xff\x85\xc0tM\x83\xf8\xfft3\x8dT$(\xc7D$\u0008'
      /bin/sh: line 5: 29331 Trace/breakpoint trap   ${dir}$tst
      FAIL: test-general
      
      Fixes: 093a3c88
      c30379e0
    • Jiří Klimeš's avatar
      libnm-core: add NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP flag · 093a3c88
      Jiří Klimeš authored
      for ignoring timestamp when comparing settings or connections.
      093a3c88
  2. 15 Nov, 2014 1 commit
    • Dan Winship's avatar
      libnm-core: change how new and legacy properties are serialized · c785a7df
      Dan Winship authored
      Although libnm filters out properties received from the daemon that it
      doesn't understand, there may be other clients that do not. In
      particular, a client might call GetSettings() on a connection, update
      the ipv4.addresses property in the returned dictionary, and then pass
      the dictionary to Update(). In that case, the updated dictionary would
      contain ipv4.address-data, but it would not reflect the changes the
      client intended to make.
      
      Fix this by changing the daemon side to prefer the legacy properties
      to the new ones if both are set, and changing the client side to not
      send the legacy properties (since we don't support new clients talking
      to old servers anyway).
      c785a7df
  3. 13 Nov, 2014 1 commit
    • Dan Winship's avatar
      all: consistently include config.h · 3bfb163a
      Dan Winship authored
      config.h should be included from every .c file, and it should be
      included before any other include. Fix that.
      
      (As a side effect of how I did this, this also changes us to
      consistently use "config.h" rather than <config.h>. To the extent that
      it matters [which is not much], quotes are more correct anyway, since
      we're talking about a file in our own build tree, not a system
      include.)
      3bfb163a
  4. 07 Nov, 2014 8 commits
    • Dan Williams's avatar
      libnm,core: enhance nm_utils_hexstr2bin() · 22762324
      Dan Williams authored
      Make the type return GBytes since most in-tree users want that.
      
      Allow the function to accept many more formats as valid hex, including
      bytes delimited by ':' and a leading '0x'.
      22762324
    • Thomas Haller's avatar
    • Dan Winship's avatar
      libnm-core: don't serialize empty address-labels · ff608c24
      Dan Winship authored
      If no address in an NMSettingIP4Config has a label, then don't bother
      serializing an array of empty strings.
      ff608c24
    • Dan Winship's avatar
      libnm-core, libnm, core: add AddressData and RouteData properties · d16905df
      Dan Winship authored
      Add AddressData and RouteData properties to NMSettingIPConfig and
      NMIP[46]Config. These are like the existing "addresses" and "routes"
      properties, but using strings and containing additional attributes,
      like NMIPAddress and NMIPRoute.
      
      This only affects the D-Bus representations; there are no API changes
      to NMSettingIP{,4,6}Config or NMIP{4,6}Config as a result of this; the
      additional information is just added to the existing 'addresses' and
      'routes' properties.
      
      NMSettingIP4Config and NMSettingIP6Config now always generate both
      old-style data ('addresses', 'address-labels', 'routes') and new-style
      data ('address-data', 'gateway', 'route-data') when serializing to
      D-Bus, for backward compatibility. When deserializing, they will fill
      in the 'addresses' and 'routes' properties from the new-style data if
      it is present (ignoring the old-style data), or from the old-style
      data if the new-style isn't present.
      
      The daemon-side NMIP4Config and NMIP6Config always emit changes for
      both 'Addresses'/'Routes' and 'AddressData'/'RouteData'. The
      libnm-side classes initially listen for changes on both properties,
      but start ignoring the 'Addresses' and 'Routes' properties once they
      know the daemon is also providing 'AddressData' and 'RouteData'.
      d16905df
    • Dan Winship's avatar
      libnm-core: add NMSettingIPConfig:gateway, drop NMIPAddress:gateway · f17699f4
      Dan Winship authored
      The gateway is a global property of the IPv4/IPv6 configuration, not
      an attribute of any particular address. So represent it as such in the
      API; remove the gateway from NMIPAddress, and add it to
      NMSettingIPConfig.
      
      Behind the scenes, the gateway is still serialized along with the
      first address in NMSettingIPConfig:addresses, and is deserialized from
      that if the settings dictionary doesn't contain a 'gateway' key.
      
      Adjust nmcli's interactive mode to prompt for IP addresses and gateway
      separately. (Patch partly from Jirka Klimeš.)
      f17699f4
    • Dan Winship's avatar
      libnm-core: extract NMSettingIPConfig superclass out of IP4, IP6 classes · 3f30c6f1
      Dan Winship authored
      Split a base NMSettingIPConfig class out of NMSettingIP4Config and
      NMSettingIP6Config, and update things accordingly.
      
      Further simplifications of now-redundant IPv4-vs-IPv6 code are
      possible, and should happen in the future.
      3f30c6f1
    • Dan Winship's avatar
      libnm-core: add NMIPAddress/NMIPRoute attributes, use for labels · 39709fdc
      Dan Winship authored
      Add key-value attributes to NMIPAddress and NMIPRoute, and use them to
      store IPv4 address labels. Demote NMSettingIP4Config:address-labels to
      a D-Bus-only property, and arrange for :addresses setter to read the
      labels out of that property when creating the addresses.
      39709fdc
    • Dan Winship's avatar
      libnm-core, all: merge IPv4 and IPv6 address/route types · 21c8a6b2
      Dan Winship authored
      Merge NMIP4Address and NMIP6Address into NMIPAddress, and NMIP4Route
      and NMIP6Route into NMIPRoute. The new types represent IP addresses as
      strings, rather than in binary, and so are address-family agnostic.
      21c8a6b2
  5. 29 Oct, 2014 1 commit
  6. 28 Oct, 2014 3 commits
    • Dan Winship's avatar
      libnm-core: add nm-core-types.h, remove cross-includes · b1087908
      Dan Winship authored
      Add nm-core-types.h, typedefing all of the GObject types in
      libnm-core; this is needed so that nm-setting.h can reference
      NMConnection in addition to nm-connection.h referencing NMSetting.
      
      Removing the cross-includes from the various headers causes lots of
      fallout elsewhere. (In particular, nm-utils.h used to include
      nm-connection.h, which included every setting header, so any file that
      included nm-utils.h automatically got most of the rest of libnm-core
      without needing to pay attention to specifics.) Fix this up by
      including nm-core-internal.h from those files that are now missing
      includes.
      b1087908
    • Dan Winship's avatar
      libnm-core: canonicalize hardware addresses in settings · b084ad7f
      Dan Winship authored
      Convert hardware addresses to canonical form (uppercase, leading
      zeros, colons) when setting them on/adding them to NMSetting
      properties.
      b084ad7f
    • Dan Winship's avatar
      libnm-core: add nm_utils_hwaddr_canonical() · 61e489a7
      Dan Winship authored
      Add a helper function for converting hardware addresses to canonical
      form.
      61e489a7
  7. 22 Oct, 2014 2 commits
    • Dan Winship's avatar
      libnm-core: merge NMSetting*Error into NMConnectionError · 2d8e7bd2
      Dan Winship authored
      Each setting type was defining its own error type, but most of them
      had exactly the same three errors ("unknown", "missing property", and
      "invalid property"), and none of the other values was of much use
      programmatically anyway.
      
      So, this commit merges NMSettingError, NMSettingAdslError, etc, all
      into NMConnectionError. (The reason for merging into NMConnectionError
      rather than NMSettingError is that we also already have
      "NMSettingsError", for errors related to the settings service, so
      "NMConnectionError" is a less-confusable name for settings/connection
      errors than "NMSettingError".)
      
      Also, make sure that all of the affected error messages are localized,
      and (where appropriate) prefix them with the relevant property name.
      
      Renamed error codes:
      
      NM_SETTING_ERROR_PROPERTY_NOT_FOUND -> NM_CONNECTION_ERROR_PROPERTY_NOT_FOUND
      NM_SETTING_ERROR_PROPERTY_NOT_SECRET -> NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET
      
      Remapped error codes:
      
      NM_SETTING_*_ERROR_MISSING_PROPERTY -> NM_CONNECTION_ERROR_MISSING_PROPERTY
      NM_SETTING_*_ERROR_INVALID_PROPERTY -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_BLUETOOTH_ERROR_TYPE_SETTING_NOT_FOUND -> NM_CONNECTION_ERROR_INVALID_SETTING
      NM_SETTING_BOND_ERROR_INVALID_OPTION -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_BOND_ERROR_MISSING_OPTION -> NM_CONNECTION_ERROR_MISSING_PROPERTY
      NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND -> NM_CONNECTION_ERROR_MISSING_SETTING
      NM_SETTING_CONNECTION_ERROR_SLAVE_SETTING_NOT_FOUND -> NM_CONNECTION_ERROR_MISSING_SETTING
      NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_VLAN_ERROR_INVALID_PARENT -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_802_1X_SETTING -> NM_CONNECTION_ERROR_MISSING_SETTING
      NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_802_1X -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME -> NM_CONNECTION_ERROR_MISSING_PROPERTY
      NM_SETTING_WIRELESS_SECURITY_ERROR_SHARED_KEY_REQUIRES_WEP -> NM_CONNECTION_ERROR_INVALID_PROPERTY
      NM_SETTING_WIRELESS_ERROR_CHANNEL_REQUIRES_BAND -> NM_CONNECTION_ERROR_MISSING_PROPERTY
      
      Dropped error codes (were previously defined but unused):
      
      NM_SETTING_CDMA_ERROR_MISSING_SERIAL_SETTING
      NM_SETTING_CONNECTION_ERROR_IP_CONFIG_NOT_ALLOWED
      NM_SETTING_GSM_ERROR_MISSING_SERIAL_SETTING
      NM_SETTING_PPP_ERROR_REQUIRE_MPPE_NOT_ALLOWED
      NM_SETTING_PPPOE_ERROR_MISSING_PPP_SETTING
      NM_SETTING_SERIAL_ERROR_MISSING_PPP_SETTING
      NM_SETTING_WIRELESS_ERROR_MISSING_SECURITY_SETTING
      2d8e7bd2
    • Dan Winship's avatar
      libnm-core: clean up NMConnectionError · aeb3d093
      Dan Winship authored
      Rename NM_CONNECTION_ERROR_UNKNOWN to NM_CONNECTION_ERROR_FAILED,
      following GError best practices.
      
      Replace NM_CONNECTION_ERROR_CONNECTION_SETTING_NOT_FOUND ("no
      NMSettingConnection") with a more generic
      NM_CONNECTION_ERROR_MISSING_SETTING. Use that new code in a few places
      that had previously been using NM_CONNECTION_ERROR_SETTING_NOT_FOUND,
      which was supposed to mean "the setting that you asked about doesn't
      exist", not "the connection is invalid because it's missing a required
      setting".
      
      Clarify that NM_CONNECTION_ERROR_INVALID_SETTING can be used for any
      "invalid or inappropriate NMSetting", not just a "conflicting" one.
      (But fix a case in nm_connection_update_secrets() that was returning
      INVALID_SETTING when it should have been return-if-failing instead.)
      
      For both MISSING_SETTING and INVALID_SETTING, always prefix the error
      message with "setting-name: ", just like we do with the various
      NMSetting MISSING_PROPERTY and INVALID_PROPERTY errors. And make sure
      that the error message is marked for localization.
      
      Drop NM_CONNECTION_ERROR_CONNECTION_TYPE_INVALID, which is pretty
      pointless; it was only used in the case where connection.type was the
      name of a valid setting type that is not a base setting type. Instead,
      just return NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY for
      connection.type in this case (which is what the code already did when
      connection.type was completely unrecognized).
      aeb3d093
  8. 12 Oct, 2014 1 commit
  9. 03 Oct, 2014 2 commits
    • Dan Winship's avatar
      libnm-core: make NMSettingSerial:parity an enum · a91e6090
      Dan Winship authored
      NMSettingSerial:parity was defined as a char-typed property that could
      have the (case-sensitive!) values 'n', 'E', or 'o'. This is zany. Add
      an NMSettingSerialParity enum, and use that instead.
      a91e6090
    • Dan Winship's avatar
      libnm: make use of GParamSpecFlags and GParamSpecEnum · fcfb4b40
      Dan Winship authored
      Make enum- and flags-valued properties use GParamSpecEnum and
      GParamSpecFlags, for better introspectability/bindability.
      
      This requires no changes outside libnm-core/libnm since the expected
      data size is still the same with g_object_get()/g_object_set(), and
      GLib will internally convert between int/uint and enum/flags GValues
      when using g_object_get_property()/g_object_set_property().
      fcfb4b40
  10. 18 Sep, 2014 2 commits
    • Dan Winship's avatar
      libnm-core: update tests to be fully variant-based · 16871ebc
      Dan Winship authored
      Use nmtst_variant_editor() to rewrite the libnm-core tests to work
      entirely in connection dictionaries, not connection hash tables.
      16871ebc
    • Dan Winship's avatar
      libnm-core: change connection hash tables to variants in API · acf86f68
      Dan Winship authored
      In preparation for porting to GDBus, make nm_connection_to_dbus(),
      etc, represent connections as GVariants of type 'a{sa{sv}}' rather
      than as GHashTables-of-GHashTables-of-GValues.
      
      This means we're constantly converting back and forth internally, but
      this is just a stepping stone on the way to the full GDBus port, and
      all of that code will go away again later.
      acf86f68
  11. 17 Sep, 2014 2 commits
    • Dan Winship's avatar
      libnm-core: fix up connection deserialize/copy/replace semantics · ad8b1309
      Dan Winship authored
      libnm-util's connection deserializing/copying/replacing functions have
      odd semantics where sometimes they both modify a connection AND return
      an error. libnm-core tried to improve things by guaranteeing that the
      connection would not be modified if the new settings were invalid, but
      this ended up breaking a bunch of places that needed to be able to
      work with invalid connections. So re-fix the functions by reverting
      back to the old semantics, but having return values that clearly
      distinguish whether the connection was modified or not.
      
      For comparison:
      
        - nm_connection_new_from_hash() / nm_simple_connection_new_from_dbus():
      
            - libnm-util: returns a valid connection or NULL.
      
            - OLD libnm-core: returned a valid connection or NULL.
      
            - NEW libnm-core: returns a valid connection or NULL.
      
        - nm_connection_duplicate() / nm_simple_connection_new_clone():
      
            - libnm-util: always succeeds, whether or not the connection is
              valid.
      
            - OLD libnm-core: returned a valid connection or NULL
      
            - NEW libnm-core: always succeeds, whether or not the connection
              is valid.
      
          - nm_connection_replace_settings_from_connection():
      
            - libnm-util: always replaces the settings, but returns FALSE if
              the connection is now invalid.
      
            - OLD libnm-core: either replaced the settings and returned TRUE
              (if the settings were valid), or else left the connection
              unchanged and returned FALSE (if not).
      
            - NEW libnm-core: always replaces the settings, and has no
              return value. (The modified connection is valid if and only if
              the replaced-from connection was valid; just like with the
              libnm-util version.)
      
          - nm_connection_replace_settings():
      
            - libnm-util: returns TRUE if the new settings are valid, or
              FALSE if either (a) the new settings could not be deserialized
              and the connection is unchanged, or (b) the new settings were
              deserialized, and the connection was updated, but is now not
              valid.
      
            - OLD libnm-core: either replaced the settings and returned TRUE
              (if the settings were valid), or else left the connection
              unchanged and returned FALSE (if not).
      
            - NEW libnm-core: returns TRUE if the connection was updated
              (whether or not it is valid), or FALSE if the new settings
              could not be deserialized and the connection is unchanged.
      ad8b1309
    • Dan Winship's avatar
      libnm-core: drop the ability to verify settings from property overrides · c4716508
      Dan Winship authored
      It needs to be possible to deserialize a connection hash into an
      invalid NMConnection; in particular, AddAndActivateConnection()
      explicitly allows this.
      
      Previously, the SetFunc and NotSetFunc passed to
      _nm_setting_class_override_property() could return a verification
      error immediately, but this functionality has to go away if we're
      going to be able to deserialize invalid connections.
      
      That functionality was only used in the handling of invalid virtual
      interface names; reorganize how that code works so that
      NMSettingConnection does all of the verification itself. (The code to
      make sure that it returned the "correct" error domain in that case
      turned out to be irrelevant, since the setting error domains don't get
      serialized over D-Bus correctly anyway.)
      c4716508
  12. 04 Sep, 2014 11 commits
    • Dan Winship's avatar
      libnm-core: change DBUS_TYPE_G_UCHAR_ARRAY properties to G_TYPE_BYTES · c43f8890
      Dan Winship authored
      Change all DBUS_TYPE_G_UCHAR_ARRAY properties to G_TYPE_BYTES, and
      update corresponding APIs. Notably, this means they are now refcounted
      rather than being copied.
      
      Update the rest of NM for the changes. The daemon still converts SSIDs
      to GByteArrays internally, because changing it to use GBytes has lots
      of trickle-down effects. It can possibly be changed later.
      c43f8890
    • Dan Winship's avatar
      libnm-core: improve NMSettingIP4Config / NMSettingIP6Config property types · 98375657
      Dan Winship authored
      Make the :addresses and :routes properties be GPtrArrays of
      NMIP4Address, etc, rather than just reflecting the D-Bus data.
      
      Make the :dns properties be arrays of strings rather than arrays of
      binary IP addresses (and update the corresponding APIs as well).
      98375657
    • Dan Winship's avatar
      libnm-core: change list-of-string and array-of-string properties to G_TYPE_STRV · 6a4127cf
      Dan Winship authored
      Change all DBUS_TYPE_G_LIST_OF_STRING and DBUS_TYPE_G_ARRAY_OF_STRING
      properties to G_TYPE_STRV, and update everything accordingly.
      
      (This doesn't actually require using
      _nm_setting_class_transform_property(); dbus-glib is happy to transform
      between 'as' and G_TYPE_STRV.)
      6a4127cf
    • Dan Winship's avatar
      libnm-core: change all mac-address properties to G_TYPE_STRING · 3a54d050
      Dan Winship authored
      Make all mac-address properties (including NMSettingBluetooth:bdaddr,
      NMSettingOlpcMesh:dhcp-anycast-addr, and NMSettingWireless:bssid) be
      strings, using _nm_setting_class_transform_property() to handle
      translating to/from binary form when dealing with D-Bus.
      
      Update everything accordingly for the change, and also add a test for
      transformed setting properties to test-general.
      3a54d050
    • Dan Winship's avatar
      libnm-core: drop :interface-name properties on virtual NMSetting types · 6217c1e7
      Dan Winship authored
      Remove the virtual :interface-name properties and their getters, and
      use property overrides to do backward-compat handling when
      serializing/deserializing.
      
      Now when constructing an NMConnection from a hash, if the virtual
      property is set and the NMSettingConnection property isn't, then the
      override for NMSettingConnection:interface-name will set that property
      to the value of the virtual interface-name. And when converting an
      NMConnection to a hash, the overrides for the virtual properties will
      return the value of NMSettingConnection:interface-name.
      6217c1e7
    • Dan Winship's avatar
      all: stop using virtual interface-name properties · ab26964c
      Dan Winship authored
      The virtual :interface-name properties (eg,
      NMDeviceBond:interface-name) are deprecated in favor of
      NMSettingConnection:interface-name, and nm_connection_verify() ensures
      that their values are kept in sync. So (a) there is no need to set
      those properties when we can just set
      NMSettingConnection:interface-name instead, and (b) we can replace any
      calls to the setting-specific get_interface_name() methods with
      nm_connection_get_interface_name() or
      nm_setting_connection_get_interface_name().
      ab26964c
    • Dan Winship's avatar
      libnm-core: drop previously-deprecated NMSetting properties · a5ac95ca
      Dan Winship authored
      Drop the NMSetting properties that were marked deprecated in
      libnm-util in 0.9.10, but use nm_setting_class_add_dbus_property() to
      deal with them appropriately when serializing/deserializing.
      a5ac95ca
    • Dan Winship's avatar
      libnm-core: add dbus-only properties to NMSettingClass · 002b19f4
      Dan Winship authored
      Add _nm_setting_class_add_dbus_only_property(), for declaring
      properties that appear in the D-Bus serialization, but which don't
      correspond to GObject properties.
      
      Since some property overrides will require examining settings other
      than the setting that they are on (eg, the value of
      802-11-wireless.security depends on whether an
      NMSettingWirelessSecurity setting is present, and
      NMSettingConnection:interface-name might sometimes be set from, eg,
      bond.interface-name), we also update _nm_setting_to_dbus() to take the
      full NMConnection as an argument, and _nm_setting_new_from_dbus() to
      take the full connection hash.
      
      Additionally, with some deprecated properties, we'll want to validate
      them on construction, but we don't need to keep the value around after
      that. So allow _nm_setting_new_from_dbus() to return a verification
      error directly, so we don't need to store the value until the verify()
      call.
      002b19f4
    • Dan Winship's avatar
      libnm-core: clean up nm_connection_replace_settings()'s semantics · 504c292d
      Dan Winship authored
      On failure, nm_connection_replace_settings() would leave the
      connection in an undefined state. Fix it so that either (a) the
      settings are replaced and the resulting connection is valid and we
      return TRUE, or (b) the connection is untouched and we return FALSE
      and an error. (And add a test case for this.)
      504c292d
    • Dan Winship's avatar
      libnm-core: rename NMConnection to/from_hash methods · 773d3f0a
      Dan Winship authored
      Rename nm_connection_to_hash() to nm_connection_to_dbus(), and
      nm_connection_new_from_hash() to nm_connection_new_from_dbus(). In
      addition to clarifying that this is specifically the D-Bus
      serialization format, these names will also work better in the
      GDBus-based future where the serialization format is GVariant, not
      GHashTable.
      
      Also, move NMSettingHashFlags to nm-connection.h, and rename it
      NMConnectionSerializationFlags.
      773d3f0a
    • Dan Winship's avatar
      libnm-core: make the NMSetting hash methods private · c9653a9e
      Dan Winship authored
      Make nm_setting_to_hash() and nm_setting_new_from_hash() private, and
      remove the public nm_setting_update_secrets() wrapper around the
      existing private _nm_setting_update_secrets().
      
      These functions should really only be called from the corresponding
      NMConnection-level methods, and in particular, with certain
      compatibility properties in the future, we will need to consider the
      entire connection all at once when setting properties, so it won't
      make sense to serialize/deserialize a single setting in isolation.
      c9653a9e
  13. 22 Aug, 2014 4 commits