Commit Graph

23 Commits

Author SHA1 Message Date
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Thomas Haller
10e05bf8ab wireguard: support configuring policy routing to avoid routing loops
For WireGuard (like for all IP-tunnels and IP-based VPNs), the IP addresses of
the peers must be reached outside the tunnel/VPN itself.

For VPN connections, NetworkManager usually adds a direct /32 route to
the external VPN gateway to the underlying device. For WireGuard that is
not done, because injecting a route to another device is ugly and error
prone. Worse: WireGuard with automatic roaming and multiple peers makes this
more complicated.

This is commonly a problem when setting the default-route via the VPN,
but there are also other subtle setups where special care must be taken
to prevent such routing loops.

WireGuard's wg-quick provides a simple, automatic solution by adding two policy
routing rules and relying on the WireGuard packets having a fwmark set (see [1]).

Let's also do that. Add new properties "wireguard.ip4-auto-default-route"
and "wireguard.ip6-auto-default-route" to enable/disable this. Note that
the default value lets NetworkManager automatically choose whether to
enable it (depending on whether there are any peers that have a default
route). This means, common scenarios should now work well without additional
configuration.

Note that this is also a change in behavior and upon package upgrade
NetworkManager may start adding policy routes (if there are peers that
have a default-route). This is a change in behavior, as the user already
clearly had this setup working and configured some working solution
already.

The new automatism picks the rule priority automatically and adds the
default-route to the routing table that has the same number as the fwmark.
If any of this is unsuitable, then the user is free to disable this
automatism. Note that since 1.18.0 NetworkManager supports policy routing (*).
That means, what this automatism does can be also achieved via explicit
configuration of the profile, which gives the user more flexibility to
adjust all parameters explicitly).

(*) but only since 1.20.0 NetworkManager supports the "suppress_prefixlength"
rule attribute, which makes it impossible to configure exactly this rule-based
solution with 1.18.0 NetworkManager.

[1] https://www.wireguard.com/netns/#improved-rule-based-routing
2019-07-29 20:45:49 +02:00
Thomas Haller
441dd1f3c8 libnm: add nm_connection_to_dbus_full() with options argument
No options are implemented yet.
2019-06-28 16:48:17 +02:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
We no longer add these. If you use Emacs, configure it yourself.

Also, due to our "smart-tab" usage the editor anyway does a subpar
job handling our tabs. However, on the upside every user can choose
whatever tab-width he/she prefers. If "smart-tabs" are used properly
(like we do), every tab-width will work.

No manual changes, just ran commands:

    F=($(git grep -l -e '-\*-'))
    sed '1 { /\/\* *-\*-  *[mM]ode.*\*\/$/d }'     -i "${F[@]}"
    sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}"

Check remaining lines with:

    git grep -e '-\*-'

The ultimate purpose of this is to cleanup our files and eventually use
SPDX license identifiers. For that, first get rid of the boilerplate lines.
2019-06-11 10:04:00 +02:00
Thomas Haller
86dc50d476 libnm: use macro and designated initializers for NMVariantAttributeSpec
I think initializing structs should (almost) be always done with designated
initializers, because otherwise it's easy to get the order wrong. The
problem is that otherwise the order of fields gets additional meaning
not only for the memory layout, but also for the code that initialize
the structs.

Add a macro NM_VARIANT_ATTRIBUTE_SPEC_DEFINE() that replaces the other
(duplicate) macros. This macro also gets it right to mark the struct as
const.
2019-05-07 20:58:17 +02:00
Thomas Haller
4e3955e6dd libnm: mark NMVariantAttributeSpec pointers as const
This actually allows the compiler/linker to mark the memory as read-only and any
modification will cause a segmentation fault.

I would also think that it allows the compiler to put the structure directly
beside the outer constant array (in which this pointer is embedded). That is good
locality-wise.
2019-05-07 20:58:17 +02:00
Thomas Haller
0d1b8ee92a libnm: unify property-to-dbus handling of NMSetting
Merge the function pointer get_func() into to_dbus_fcn().

Previously, get_func() as handled separately from to_dbus_fnc()
(formerly synth_func()). The notion was that synth-func would syntetize
properties that are D-Bus only. But that distinction does not seem
very helpful to me.

Instaed, we want to convert a property to D-Bus. Period. The
implementation should be handled uniformly. Hence, now that is
all done by property_to_dbus().

Note that property_to_dbus() is also called as default implementation
for compare-property. At least, for properties that are backed by a
GObject property.
2019-05-01 13:46:32 +02:00
Thomas Haller
b1344b6b94 libnm: pass connection to compare_property() function
We have certain artificial properties that not only depend on one
property alone or that depend on a property in another(!) setting.

For that, we have synth_func.

Other than that, synth_func and get_func are really fundamentally
similar and should be merged. That is because the distinction whether a
property value is "synthetized" or just based on a plain property is
minor. It's better to have the general concept of "convert property to
GVariant" in one form only.

Note that compare_property() is by default implemented based
on get_func. Hence, if get_func and synth_func get merged,
compare_property() will also require access to the NMConnection.

Also it makes some sense: some properties are artificial and actually
stored in "another" setting of the connection. But still, the property
descriptor for the property is in this setting. The example is the
"bond.interface-name" which only exists on D-Bus. It's stored as
"connection.interface-name".
I don't really like to say "exists on D-Bus only". It's still a valid
property, despite in NMSetting it's stored somehow differently (or not
at all). So, this is also just a regular property for which we have a
property-info vtable.
Does it make sense to compare such properties? Maybe. But the point is that
compare_property() function needs sometimes access to the entire
connection. So add the argument.
2019-05-01 13:46:32 +02:00
Beniamino Galvani
2691fd279d libnm-core: fix typos in API documentation 2019-03-26 17:18:29 +01:00
Beniamino Galvani
d9143d851d libnm-core: add missing notify in sriov setting 2019-03-26 17:18:29 +01:00
Thomas Haller
c77871e5e9 all: avoid bogus compiler warning about uninitialized variable
With LTO and optimizations, gcc issues several bogus
"maybe-uninitialized" warnings.

Work-around them by initializing the variables.
2019-02-04 10:55:25 +01:00
Thomas Haller
19141ef770 libnm-core: reorder code in settings
Order the code in our common way. No other changes.

- ensure to include the main header first (directly after
  "nm-default.h").

- reorder function definitions: get_property(), set_property(),
  *_init(), *_new(), finalize(), *_class_init().
2019-01-15 09:55:24 +01:00
Thomas Haller
a3d6976efc libnm-core: cleanup NMSetting's class initialization
Unify the coding style for class-init functions in libnm-core.

Also make use of obj_properties, NM_GOBJECT_PROPERTIES_DEFINE(), and
_notify().
2019-01-15 09:55:24 +01:00
Thomas Haller
885c872d5a libnm: rework compare_property() implementation for NMSetting
NMSetting's compare_property() has and had two callers:
nm_setting_compare() and nm_setting_diff().

compare_property() accepts a NMSettingCompareFlags argument, but
at the same time, both callers have another complex (and
inconsistent!) set of pre-checks for shortcuting the call of
compare_property(): should_compare_prop().

Merge should_compare_prop() into compare_property(). This way,
nm_setting_compare() and nm_setting_diff() has less additional
code, and are simpler to follow. Especially nm_setting_compare()
is now trivial. And nm_setting_diff() is still complicated, but
not related to the question how the property compares or whether
it should be compared at all.

If you want to know whether it should be compared, all you need to do
now is follow NMSettingClass.compare_property().

This changes function pointer NMSettingClass.compare_property(),
which is public API. However, no user can actually use this (and shall
not!), because _nm_setting_class_commit_full() etc. is private API. A
user outside of libnm-core cannot create his/her own subclasses of
NMSetting, and never could in the past. So, this API/ABI change doesn't
matter.
2019-01-11 11:48:47 +01:00
Beniamino Galvani
3de25bbc97 libnm-core: slightly improve SR-IOV documentation
Describe how to specify multiple VFs and which attributes are
supported, so that this information is available in the nm-settings
manual page.

Also, clarify that SR-IOV parameters are managed only when the setting
is present.

https://bugzilla.redhat.com/show_bug.cgi?id=1651979
2018-12-12 14:18:53 +01:00
Beniamino Galvani
27ab932a49 libnm-core: use g_variant_type_equal() to compare variant types
Even if a direct pointer comparison should be fine, use the proper
function. GVariantType documentation says:

 "Two types may not be compared by value; use g_variant_type_equal()
 or g_variant_type_is_subtype_of()."

This also fixes coverity warnings.
2018-10-06 10:03:48 +02:00
Rafael Fontenelle
34fd628990 Fix typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/21

[thaller@redhat.com: fix generated clients/common/settings-docs.h.in file
   and fix wrong change in src/systemd/src/libsystemd/sd-event/sd-event.c]
2018-09-30 21:14:55 +02:00
luz.paz
58510ed566 docs: misc. typos pt2
Remainder of typos found using `codespell -q 3 --skip="./shared,./src/systemd,*.po" -I ../NetworkManager-word-whitelist.txt` whereby whitelist consists of:
 ```
ans
busses
cace
cna
conexant
crasher
iff
liftime
creat
nd
sav
technik
uint
```

https://github.com/NetworkManager/NetworkManager/pull/205
2018-09-17 11:26:13 +02:00
Thomas Haller
3793804314 libnm: rework setting metadata for property handling
NMSetting internally already tracked a list of all proper GObject properties
and D-Bus-only properties.

Rework the tracking of the list, so that:

- instead of attaching the data to the GType of the setting via
  g_type_set_qdata(), it is tracked in a static array indexed by
  NMMetaSettingType. This allows to find the setting-data by simple
  pointer arithmetic, instead of taking a look and iterating (like
  g_type_set_qdata() does).

  Note, that this is still thread safe, because the static table entry is
  initialized in the class-init function with _nm_setting_class_commit().
  And it only accessed by following a NMSettingClass instance, thus
  the class constructor already ran (maybe not for all setting classes,
  but for the particular one that we look up).

  I think this makes initialization of the metadata simpler to
  understand.
  Previously, in a first phase each class would attach the metadata
  to the GType as setting_property_overrides_quark(). Then during
  nm_setting_class_ensure_properties() it would merge them and
  set as setting_properties_quark(). Now, during the first phase,
  we only incrementally build a properties_override GArray, which
  we finally hand over during nm_setting_class_commit().

- sort the property infos by name and do binary search.

Also expose this meta data types as internal API in nm-setting-private.h.
While not accessed yet, it can prove beneficial, to have direct (internal)
access to these structures.

Also, rename NMSettingProperty to NMSettInfoProperty to use a distinct
naming scheme. We already have 40+ subclasses of NMSetting that are called
NMSetting*. Likewise, NMMetaSetting* is heavily used already. So, choose a
new, distinct name.
2018-08-10 10:38:19 +02:00
Thomas Haller
9c47e2ce30 libnm: use NMMetaSettingInfo for tracking setting priority
Previously, each (non abstract) NMSetting class had to register
its name and priority via _nm_register_setting().

Note, that libnm-core.la already links against "nm-meta-setting.c",
which also redundantly keeps track of the settings name and gtype
as well.

Re-use NMMetaSettingInfo also in libnm-core.la, to track this meta
data.

The goal is to get rid of private data structures that track
meta data about NMSetting classes. In this case, "registered_settings"
hash. Instead, we should have one place where all this meta data
is tracked. This was, it is also accessible as internal API,
which can be useful (for keyfile).

Note that NMSettingClass has some overlap with NMMetaSettingInfo.
One difference is, that NMMetaSettingInfo is const, while NMSettingClass
is only initialized during the class_init() method. Appart from that,
it's mostly a matter of taste, whether we attach meta data to
NMSettingClass, to NMMetaSettingInfo, or to a static-array indexed
by NMMetaSettingType.

Note, that previously, _nm_register_setting() was private API. That
means, no user could subclass a functioning NMSetting instance. The same
is still true: NMMetaSettingInfo is internal API and users cannot access
it to create their own NMSetting subclasses. But that is almost desired.
libnm is not designed, to be extensible via subclassing, nor is it
clear why that would be a useful thing to do. One day, we should remove
the NMSetting and NMSettingClass definitions from public headers. Their
only use is subclassing the types, which however does not work.

While libnm-core was linking already against nm-meta-setting.c,
nm_meta_setting_infos was unreferenced. So, this change increases
the binary size of libnm and NetworkManager (1032 bytes). Note however
that roughly the same information was previously allocated at runtime.
2018-08-10 10:38:19 +02:00
Thomas Haller
23adc37377 libnm/trivial: cleanup variable names in settings' class-init functions
- Don't use @parent_class name. This local variable (and @object_class) is
  the class instance up-cast to the pointer types of the parents. The point
  here is not that it is the direct parent. The point is, that it's the
  NMSettingClass type.
  Also, it can only be used inconsistently, in face of NMSettingIP4Config,
  who's parent type is NMSettingIPConfig. Clearly, inside
  nm-setting-ip4-config.c we wouldn't want to use the "parent_class"
  name. Consistently rename @parent_class to @setting_class.

- Also rename the pointer to the own class to @klass. "setting_class" is also the
  wrong name for that, because the right name would be something like
  "setting_6lowpan_class".
  However, "klass" is preferred over the latter, because we commonly create new
  GObject implementations by copying an existing one. Generic names like "klass"
  and "self" inside a type implementation make that simpler.

- drop useless comments like

     /* virtual functions */
     /* Properties */

  It's better to logically and visually structure the code, and avoid trival
  remarks about that. They only end up being used inconsistently. If you
  even need a stronger visual separator, then an 80 char /****/ line
  should be preferred.
2018-08-10 10:38:19 +02:00
Beniamino Galvani
c02d1c488f ifcfg-rh: SR-IOV support 2018-07-11 16:16:22 +02:00
Beniamino Galvani
a9b4532fa7 libnm-core: add SR-IOV setting
Add a setting containing SR-IOV parameters.
2018-07-11 16:16:22 +02:00