Commit Graph

26 Commits

Author SHA1 Message Date
Thomas Haller
78629830c8 all: add "libnm-core/nm-default-libnm-core.h" as replacement for "nm-default.h" 2021-02-09 12:38:18 +01:00
Thomas Haller
977ea352a0 all: update deprecated SPDX license identifiers
These SPDX license identifiers are deprecated ([1]). Update them.

[1] https://spdx.org/licenses/

  sed \
     -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \
     -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \
     -i \
     $(git grep -l SPDX-License-Identifier -- \
         ':(exclude)shared/c-*/' \
         ':(exclude)shared/n-*/' \
         ':(exclude)shared/systemd/src' \
         ':(exclude)src/systemd/src')
2021-01-05 09:46:21 +01:00
Thomas Haller
a2b5e22f82 all: drop unnecessary cast for return value of g_object_new()
C casts unconditionally force the type, and as such they don't
necessarily improve type safety, but rather overcome restrictions
from the compiler when necessary.

Casting a void pointer is unnecessary (in C), it does not make the
code more readable nor more safe. In particular for g_object_new(),
which is known to return a void pointer of the right type.

Drop such casts.

  sed 's/([A-Za-z_0-9]\+ *\* *) *g_object_new/g_object_new/g' $(git grep -l g_object_new) -i
  ./contrib/scripts/nm-code-format-container.sh
2020-11-12 16:03:09 +01:00
Thomas Haller
88071abb43 all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
740b092fda format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Beniamino Galvani
ae7d1e2b7a libnm-core: use nm_strvarray_remove_first() 2020-08-26 17:08:13 +02:00
Thomas Haller
3ced486f41 libnm/match: extend syntax for match patterns with '|', '&', '!' and '\\'
For simple matches like match.interface-name, match.driver, and
match.path, arguably what we had was fine. There each element
(like "eth*") is a wildcard for a single name (like "eth1").

However, for match.kernel-command-line, the elements match individual
command line options, so we should have more flexibility of whether
a parameter is optional or mandatory. Extend the syntax for that.

- the elements can now be prefixed by either '|' or '&'. This makes
  optional or mandatory elements, respectively. The entire match
  evaluates to true if all mandatory elements match (if any) and
  at least one of the optional elements (if any).
  As before, if neither '|' nor '&' is specified, then the element
  is optional (that means, "foo" is the same as "|foo").

- the exclamation mark is still used to invert the match. If used
  alone (like "!foo") it is a shortcut for defining a mandatory match
  ("&!foo").

- the backslash can now be used to escape the special characters
  above. Basically, the special characters ('|', '&', '!') are
  stripped from the start of the element. If what is left afterwards
  is a backslash, it also gets stripped and the remainder is the
  pattern. For example, "\\&foo" has the pattern "&foo" where
  '&' is no longer treated specially. This special handling of
  the backslash is only done at the beginning of the element (after
  the optional special characters). The remaining string is part
  of the pattern, where backslashes might have their own meaning.

This change is mostly backward compatible, except for existing matches
that started with one of the special characters '|', '&', '!', and '\\'.

(cherry picked from commit 824ad6275d)
2020-06-26 13:33:41 +02:00
Thomas Haller
6ae1f0e459 libnm: return NULL for boxed strv properties of NMSettingMatch
The API does not allow to distinguish between an unset (NULL) or empty
strv array. For example, nm_setting_match_get_paths() never returns
%NULL, but returns an empty strv array.

On the other hand, the GObject properties of type G_TYPE_STRV have a
default value of %NULL. That means, also the getter should map both
unset and empty to %NULL.

Note that this is a change in behavior w.r.t. 1.24.0 API, where
match.interface-name property would return an empty strv array.
Regrading the other API, this is no change because it is new API
and we will fix it before 1.26.0 release.

(cherry picked from commit 62263e706f)
2020-06-22 12:18:26 +02:00
Beniamino Galvani
85535ba8ae libnm-core: fix memory leak in match setting
Fixes: 808e837149 ('all: add "path" property to the match setting')
(cherry picked from commit 92208ebd1f)
2020-06-18 14:28:47 +02:00
Beniamino Galvani
808e837149 all: add "path" property to the match setting
Add a new "path" property to the match setting, which can be used to
restrict a connection to devices with a given hardware path. The new
property is a list of patterns that are matched against the ID_PATH
udev property of devices.

ID_PATH represents the topological persistent path of a device and
typically contains a subsystem string (pci, usb, platform, etc.) and a
subsystem-specific identifier. Some examples of paths are:

 pci-0000:00:02.0
 pci-0000:00:14.0-usb-0:5:1.0
 platform-1c40000.ethernet

systemd-networkd also has a "Path=" option to match a device by udev
ID_PATH.
2020-06-12 16:04:06 +02:00
Thomas Haller
4101894466 libnm: use nm_str_is_empty() in "nm-setting-match.c" 2020-05-08 11:11:43 +02:00
Thomas Haller
0ba444a084 libnm: allocate device and kernel_command_line arrays in NMSettingMatch lazy 2020-05-06 15:39:14 +02:00
Thomas Haller
7939c8e770 libnm: allocate interface_name array in NMSettingMatch lazy
Also track the interface_name in a GArray so that
nm_setting_match_get_interface_names() returns a NULL
terminated strv array.
2020-05-06 15:39:08 +02:00
Thomas Haller
ef16dcaee4 libnm: cleanup NMSettingMatch.verify() 2020-05-06 15:19:22 +02:00
Thomas Haller
eaf3862075 libnm: fix gtk-doc annotations for nm_setting_match_get_{kernel_command_lines,drivers}()
Otherwise the function is not usable via generated bindings.
2020-05-06 15:07:09 +02:00
Adrian Freihofer
214b31dcbc settings: add match for driver
Add a new "driver" match option to nm-settings. It allows to disable a
network connection configuration if a pattern is found or is not found
in the device driver name.
2020-05-06 15:05:21 +02:00
Adrian Freihofer
3a8e46f2a5 settings: add match for proc cmdline
Add a new "kernel-command-line" match option to nm-settings. It allows
to disable a network connection configuration if a pattern is found or
is not found in /proc/cmdline.
2020-05-06 15:05:20 +02:00
Adrian Freihofer
b42c3aa97a settings: add match verify function 2020-05-06 15:05:20 +02:00
Thomas Haller
180cda7632 libnm: fix gtk-doc annotations for nm_setting_match_get_interface_names()
Otherwise the function is not usable via generated bindings.

Fixes: 9b9dce9486 ('all: add 'match' setting')
2020-05-06 15:01:06 +02:00
Beniamino Galvani
78f1977ecd libnm-core: remove trailing dot from setting description
The trailing dot is already added when generating the man page.
2020-03-23 11:42:57 +01:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
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
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
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
Beniamino Galvani
9b9dce9486 all: add 'match' setting
Add a new 'match' setting containing properties to match a connection
to devices. At the moment only the interface-name property is present
and, contrary to connection.interface-name, it allows the use of
wildcards.
2018-08-11 09:41:07 +02:00