Commit Graph

790 Commits

Author SHA1 Message Date
Thomas Haller
e26a81cf35 libnm: handler numeric values more gracefully in nm_utils_enum_from_str()
nm_utils_enum_to_str() may also output numeric values if there is no
corresponding "nick" for the enum/flag value.

For enums the value is in decimal and for flags the value is hexadecimal
(with a "0x" prefix).

The same was already supported by nm_utils_enum_from_str() when reading
the value. However, previously, reading a flag would only support hex
numbers and reading a enum would only support decimal numbers.

Extend that, to allow passing numbers in any base. For nm_utils_enum_to_str()
also make sure to never output nicks that may be misinterpreted as
numbers.
2017-03-30 13:09:55 +02:00
Thomas Haller
112f09cf4b libnm: return zero flags value from nm_utils_enum_to_str()
It is not uncommon that a flags type has also the value 0 mapped,
for example to "unknown" or "none".

In that case, we should not return an empty string, but instead
that zero value.

Also, flags actually have an unsigned type. That isn't a real
problem to cast it to a signed int. But be more careful about
it and use unsigned while handling unsigned values and only
cast to int once.
2017-03-30 13:09:54 +02:00
Thomas Haller
255bc928d7 libnm: fix error message for invalid ipv6.addr-gen-mode 2017-03-30 10:19:13 +02:00
Lubomir Rintel
1fcb3b40c2 release: bump version to 1.9.0 (development) 2017-03-28 16:34:22 +02:00
Thomas Haller
4ec7dd987e libnm: add NMSettingUser
This only adds new API for a NMSettingUser. The setting class
is still entirely unused.

The point is getting the new API into 1.8.0 release of libnm.
It's easier to backport the use of the API to a stable branch
then backporting public API.

https://bugzilla.gnome.org/show_bug.cgi?id=776276
https://bugzilla.redhat.com/show_bug.cgi?id=1421429
2017-03-28 14:58:21 +02:00
Thomas Haller
1601d2caf6 libnm: document to allow omitting argument to get-options functions
These functions return static information, and don't require
a @setting argument. The list of options is interesting even
when having now setting instance at hand.

Document this to promise the user that passing %NULL is allowed.

It was allowed since when those functions were added.
2017-03-28 14:58:21 +02:00
Thomas Haller
163e193286 libnm: fix type annotation for nm_utils_enum_from_str() 2017-03-25 17:12:27 +01:00
Thomas Haller
0fefcbfb2d build: don't link against libm.so
There are very few places where we actually use floating point
or #include <math.h>.

Drop that library, although we very likely still get it as indirect
dependency (e.g. on my system it is still dragged in by libsystemd.so,
libudev.so and libnl-3.so).
2017-03-23 19:06:02 +01:00
Beniamino Galvani
80dfb8cdab core,libnm-core: use same route attribute names of iproute2
Users are probably more familiar with iproute2 route option names than
kernel ones.

Fixes: 54e58eb96b
2017-03-22 12:04:25 +01:00
Yuri Chornoivan
4c6edb22b7 all: fix typos in documentation and comments
https://bugzilla.gnome.org/show_bug.cgi?id=780199

[thaller@redhat.com: reworded commit message]
2017-03-17 15:11:20 +01:00
Thomas Haller
5022e3b8ee libnm: revert coercing NMVpnConnectionStateReason to NMActiveConnectionStateReason
NMVpnConnectionStateReason is no longer used and replaced by
NMActiveConnectionStateReason. However, the old enums should
stay in place as they were:

Otherwise:
  #define NMVpnConnectionStateReason NMActiveConnectionStateReason
causes compiler warnings:
  NMVpnConnectionStateReason x;
  x = NM_VPN_CONNECTION_STATE_REASON_UNKNOWN;             // -Wenum-conversion
  if (x == NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS) { } // -Wenum-compare

Similarly, a user who didn't upgrade shall continue to get the
old GType for NM_TYPE_VPN_CONNECTION_STATE_REASON.

In practice, old users will have no issues using the old enum
the places where it worked before.
The only use of the deprecated enum is in vpn_state_changed()
signal slot of NMVpnConnection. This makes the signal slot
itself deprecated. However, NMVpnConnection is an NMObject and commonly
created within libnm itself, not by the user. It is very unlikely that
a user of libnm subclassed NMVpnConnection and makes use of the
vpn_state_changed() signal slot. So, deprecate it without replacement.

Fixes: a91369f80d
2017-03-17 13:00:32 +01:00
Thomas Haller
e65aa9e6ff trivial/whitespace: remove non-leading tabs 2017-03-17 10:58:33 +01:00
Lubomir Rintel
a91369f80d libnm-core: drop NMVpnConnectionStateReason
It's now the same as NMActiveConnectionStateReason. Keep a compatibility
typedef and enum.
2017-03-17 10:21:19 +01:00
Lubomir Rintel
8b649a8c84 active-connection: emit a StateChanged signal on state changes
It includes a reason code that makes it possible for the clients to be
more reasonable about error messages.

The reason code is essentially copied from the VPN, plus three more
reasons that were useful for non-VPN connections.
2017-03-17 10:21:19 +01:00
Lubomir Rintel
67688fd2e5 libnm-core/trivial: include literals next to NMVPNStateReason values
Makes it slightly more readable, useful when we copy it to
NMActiveConnectionStateReason.
2017-03-17 10:21:19 +01:00
Lubomir Rintel
7bd69aa08d libnm-core: sensible docstrings for NMSettings* 2017-03-17 10:15:11 +01:00
Lubomir Rintel
3f6af3360b libnm-core/8021x: add a missing colon in gtk-doc
The universe is now perfect.
2017-03-17 10:15:11 +01:00
Thomas Haller
22b7282d84 all: use "unsigned" instead of "unsigned int" 2017-03-14 11:26:29 +01:00
Thomas Haller
b1eeb00937 all: use "unsigned long" instead of "long unsigned" 2017-03-14 11:23:46 +01:00
Thomas Haller
831286df30 include: use double-quotes to include our own headers
In practice, this should only matter when there are multiple
header files with the same name. That is something we try
to avoid already, by giving headers a distinct name.

When building NetworkManager itself, we clearly want to use
double-quotes for including our own headers.
But we also want to do that in our public headers. For example:

  ./a.c
    #include <stdio.h>
    #include <nm-1.h>
    void main() {
        printf ("INCLUDED %s/nm-2.h\n", SYMB);
    }

  ./1/nm-1.h
    #include <nm-2.h>

  ./1/nm-2.h
    #define SYMB "1"

  ./2/nm-2.h
    #define SYMB "2"

$ cc -I./2 -I./1 ./a.c
$ ./a.out
INCLUDED 2/nm-2.h

Exceptions to this are
  - headers in "shared/nm-utils" that include <NetworkManager.h>. These
    headers are copied into projects and hence used like headers owned by
    those projects.
  - examples/C
2017-03-09 14:12:35 +01:00
Beniamino Galvani
40e1fd9531 ifcfg-rh: support route options
For IPv4 we support both the legacy and the new route file format. In
the legacy format, option are appended to the "ip route" command
arguments:

  203.0.113.0/24 metric 3 via 198.51.100.1 dev eth2 cwnd 14 mtu lock 1500

This is backwards compatible with initscripts. In the new format, a
OPTIONSx= variable is added to represent the options in the same
format understood by iproute2:

 ADDRESS0=203.0.113.0
 NETMASK0=255.255.255.0
 GATEWAY0=198.51.100.1
 METRIC0=3
 OPTIONS0="cwnd 14 mtu lock 1500"

initscripts do not support this variable at the moment (but the
changes needed to support it are trivial).

By default the new format is used, unless the route file is already in
the legacy format.

For IPv6 only the legacy format is supported, as before.
2017-03-06 15:20:25 +01:00
Beniamino Galvani
cdfa625102 keyfile: support route options 2017-03-06 15:20:25 +01:00
Beniamino Galvani
54e58eb96b libnm-core: define known route attribute names and validation function
This adds definition of a set of known route option attributes to
libnm-core and helper functions.

nm_ip_route_attribute_validate() performs the validation of the
attribute type and, in case of a formatted string attribute, of its
content.

nm_ip_route_get_variant_attribute_spec() returns the attribute format
specifier to be passed to nm_utils_parse_variant_attributes(). Since
at the moment NMIPRoute is the only user of NMVariantAttributeSpec and
the type is opaque to users of the library, the struct is extended to
carry some other data useful for validation.
2017-03-06 15:20:25 +01:00
Beniamino Galvani
93b3a478bb libnm-core: add attribute parsing/format helpers
Various libnm objects (addresses, routes) carry an hash table of
attributes represented as GVariants indexed by name. Add common
routines to convert to and from a string representation.

To parse a string, a knowledge of the supported attributes (and their
types) is needed: we represent it as an opaque type
NMVariantAttributeSpec that callers must query to the library for the
specific object type and pass to the parse function.
2017-03-06 15:20:25 +01:00
Lubomir Rintel
c2329e0ee3 libnm-core: remove a redundant docstring
It makes gtk-doc unhappy.
2017-03-05 21:04:06 +01:00
Thomas Haller
670e088efe libnm-core: normalize invalid bridge|team slave-port settings
Having a bridge-port/team-port setting for a connection that
has a different slave-type makes no sense. Such a configuration
shall be considered invalid, and be fixed by normalization.

Note that there is already a normalization the other way around,
when you omit the "slave-type" but a "master" and one(!) port-type
setting is present, the slave-type is automatically determined
based on the port-type.

The use of this is of course to modify an existing slave connection
to make it a non-slave. Then the invalid port settings should be
automatically removed.

Previously, ifcfg-rh writer would write the "BRIDGING_OPTS" setting
without a "BRIDGE". The reader would then (correctly) ignore the
bridge-port. Avoid that altogehter, by requiring the connection to
strictly verify.
2017-03-02 12:14:29 +01:00
Thomas Haller
8b1b6f3d1a libnm-core: expose internal _nm_connection_verify() function 2017-03-02 12:14:29 +01:00
Thomas Haller
72bfe62a9a all: use stack-allocated uuid at various places
No need to create a UUID on the heap in this case.
2017-03-02 12:14:29 +01:00
Thomas Haller
cf213216fd libnm-core: add ethernet setting for vlan connection
A "vlan" setting can optionally have an ethernet setting.
However, ifcfg-rh reader always adds such a setting, because
well... Anyway, the result is that writing a VLAN setting
without ethernet section will yield a different result
on re-read.

Let's have normalization add the ethernet setting, so that
two we consistently have it present.
2017-03-02 12:14:29 +01:00
Lubomir Rintel
61722fdeb1 libnm-core/trivial: fix a typo in doc comment 2017-02-25 22:17:46 +01:00
Beniamino Galvani
fcb0fffb85 libnm-core: require interface name for dummy connections
Fixes: 1bf2d3b049
2017-02-23 10:58:32 +01:00
Beniamino Galvani
b42f780e04 core: add support for dummy devices
Add support for creating dummy devices. This commit adds a D-Bus
interface 'org.freedesktop.NetworkManager.Device.Dummy' which is used
primarily for determining the device type but does not carry any
properties.
2017-02-22 21:05:04 +01:00
Beniamino Galvani
1bf2d3b049 libnm-core: add dummy connection setting
The setting must be present in connections with type=dummy. It does
not contain any property.
2017-02-22 21:05:04 +01:00
Thomas Haller
f95b6cadd2 libnm: fix gtk-doc comment for nm_setting_802_1x_get_phase2_ca_cert_password()
Fixes: 538e510473
2017-02-22 13:57:31 +01:00
Beniamino Galvani
556a46959f ifcfg-rh: add support for 802-1x.auth-timeout property 2017-02-21 09:18:53 +01:00
Beniamino Galvani
078bd7b1a9 libnm-core: add auth-timeout property to the 802.1x setting
The property can be used to tune the authentication timeout. It's
especially useful to speed up the failure in case the port doesn't
support 802.1X and make NM try a different, non-authenticated
connection.
2017-02-21 09:18:53 +01:00
Beniamino Galvani
436eec6083 ifcfg-rh: support 802-1x.phase1-auth-alg 2017-02-20 14:06:14 +01:00
Thomas Haller
2a11c57c4e libnm/wifi: rework NMSetting8021xAuthFlags to explicitly disable TLS version
The wpa_supplicant API supports to enable/disable each TLS version
individually, or leave it at the default. Currently, the default
means to enable a TLS version, thus, the only meaningful option
for the momemnt means to explicitly disable it.

In the future, supplicant may disable options by default, and
the inverse option can become interesting to configure
"tls_disable_tlsv1_0=0". When that happens, we can solve it by
adding another flag NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_ENABLE.

Change the previous behavior of the NMSetting8021xAuthFlags.
Previously, when not specifying TLS_DISABLE_DEFAULT, all
options were unspecified. On the other hand, when specifying
a single TLS disable flag, all versions were explicitly enabled
or disabled.

Instead, change the meaning of the disable flags. When present,
it explicitly disables an option. But it does not explicitly enable
it.
2017-02-20 14:06:14 +01:00
Leorize
e3a9f1b32a libnm-core/8021x: add phase1-auth-flags configuration items 2017-02-20 13:45:32 +01:00
Thomas Haller
1525b44714 utils: support unknown numeric values in nm_utils_enum_to_str() and nm_utils_enum_from_str()
- for nm_utils_enum_to_str(), whenever encounter a numeric value
  that has no expression as enum/flag, encode the value numerically.
  For enums, encode it as decimal. For flags, encode it as hexadecimal
  (with 0x prefix).
  Also check that an existing value_nick cannot be wrongly interpreted
  as a integer, and if they would, encode them instead as integers only.

- Likewise, in nm_utils_enum_from_str() accept numerical values
  and for nm_utils_enum_get_values() return enum nicks that look
  like numeric values in their numeric form only.

- In nm_utils_enum_from_str(), don't use g_strsplit(), but clone the
  string only once and manipulate it inplace.

- Accept '\n' and '\r' as additional delimiters for flags.

- For consistency, also return an err_token for enum types. If the caller
  doesn't care about that, he should simply not pass the out-argument.
2017-02-20 13:45:32 +01:00
Beniamino Galvani
8950d18362 libnm-core: add _nm_utils_enum_to_str_full()
Unfortunately nm_utils_enum_to_str() doesn't allow to specify the
separator between enum values. Since the function is public API and
can't be modified now, add a new internal function which accepts the
separator as argument.
2017-02-20 13:45:32 +01:00
Beniamino Galvani
4d3ec516bd libnm-core: add missing transfer annotation for nm_utils_enum_to_str() 2017-02-20 13:44:08 +01:00
Beniamino Galvani
65837f5fff libnm-core: add mtu property to cdma setting 2017-02-20 09:18:16 +01:00
Beniamino Galvani
5d09183922 libnm-core: add mtu property to gsm setting 2017-02-20 09:18:16 +01:00
Thomas Haller
2c9ef8cf2e shared: move NMSetting8021xSchemeVtable to "shared/nm-setting-metadata.h" 2017-02-17 19:52:13 +01:00
Thomas Haller
324cf7ce82 ifcfg-rh: reuse file-suffix from NMSetting8021xSchemeVtable
Keyfile writer computes the file extension and only uses
the file suffix from the vtable.

Do that for ifcfg-rh too. No change in behavior.
2017-02-17 14:24:34 +01:00
Thomas Haller
7a21ae3e77 keyfile: reuse NMSetting8021xSchemeVtable in NMKeyfileWriteTypeDataCert 2017-02-17 14:24:34 +01:00
Thomas Haller
01b8520447 ifcfg-rh: merge ObjectType with NMSetting8021xSchemeVtable in ifcfg-rh writer 2017-02-17 14:24:34 +01:00
Thomas Haller
1c6b67b0cb libnm-core: add and use internal struct NMSetting8021xSchemeVtable in keyfile 2017-02-17 14:24:34 +01:00
Lubomir Rintel
57e379320e core/8021x: request secrets for keys and certificates PKCS#11 tokens
Unless the secrets are explicitely flagged as not needed we probably require
the PINs.
2017-02-17 14:24:34 +01:00