Commit graph

174 commits

Author SHA1 Message Date
Lubomir Rintel ee916a1e9e all: fix -Wcast-function-type warnings
GCC 8.0's -Wcast-function-type objects casting function pointers to ones
with incompatible prototypes. Sometimes we do that on purpose though.

Notably, the g_source_set_callback()'s func argument can point to functions
of various prototypes. Also, libnm-glib/nm-remote-connection is perhaps
just not worth reworking, that would just be a waste of time.

A cast to void(*)(void) avoids the GCC warning, let's use it.
2018-02-08 17:11:46 +01:00
Thomas Haller 28da0154fc all: drop trailing spaces 2018-02-07 13:32:04 +01:00
Thomas Haller e4839accf5 all: replace non-leading tabs with spaces
We commonly only allow tabs at the beginning of a line, not
afterwards. The reason for this style is so that the code
looks formated right with tabstop=4 and tabstop=8.
2018-02-07 13:32:04 +01:00
Lubomir Rintel 8a46b25cfa all: require glib 2.40
RHEL 7.1 and Ubuntu 14.04 LTS both have this.

https://bugzilla.gnome.org/show_bug.cgi?id=792323
2018-01-18 11:45:36 +01:00
Thomas Haller 34cb6f9877 build/meson: use variables for ldflags and linker-script 2018-01-11 12:46:01 +01:00
Thomas Haller 349861ceec build/meson: unconditionally use linker version scripts
We also unconditionally use them with autotools.
Also, the detection for have_version_script does
not seem correct to me. At least, it didn't work
with clang.
2018-01-10 12:31:44 +01:00
Iñigo Martínez 50930ed19a meson: Use string variables extensively
The strings holding the names used for libraries have also been
moved to different variables. This way they would be less error
as these variables can be reused easily and any typing error
would be quickly detected.
2018-01-10 12:22:55 +01:00
Iñigo Martínez 5e16bcf268 meson: Improve dependency system
Some targets are missing dependencies on some generated sources in
the meson port. These makes the build to fail due to missing source
files on a highly parallelized build.

These dependencies have been resolved by taking advantage of meson's
internal dependencies which can be used to pass source files,
include directories, libraries and compiler flags.

One of such internal dependencies called `core_dep` was already in
use. However, in order to avoid any confusion with another new
internal dependency called `nm_core_dep`, which is used to include
directories and source files from the `libnm-core` directory, the
`core_dep` dependency has been renamed to `nm_dep`.

These changes have allowed minimizing the build details which are
inherited by using those dependencies. The parallelized build has
also been improved.
2018-01-10 12:20:17 +01:00
Thomas Haller 52baa8c52b clients: drop redundant #include "NetworkManager.h"
This header is already included by "nm-default.h".
2018-01-08 12:38:54 +01:00
Thomas Haller 22ef6a507a build: refine the NETWORKMANAGER_COMPILATION define
Note that:

 - we compile some source files multiple times. Most notably those
   under "shared/".

 - we include a default header "shared/nm-default.h" in every source
   file. This header is supposed to setup a common environment by defining
   and including parts that are commonly used. As we always include the
   same header, the header must behave differently depending
   one whether the compilation is for libnm-core, NetworkManager or
   libnm-glib. E.g. it must include <glib/gi18n.h> or <glib/gi18n-lib.h>
   depending on whether we compile a library or an application.

For that, the source files need the NETWORKMANAGER_COMPILATION #define
to behave accordingly.

Extend the define to be composed of flags. These flags are all named
NM_NETWORKMANAGER_COMPILATION_WITH_*, they indicate which part of the
build are available. E.g. when building libnm-core.la itself, then
WITH_LIBNM_CORE, WITH_LIBNM_CORE_INTERNAL, and WITH_LIBNM_CORE_PRIVATE
are available. When building NetworkManager, WITH_LIBNM_CORE_PRIVATE
is not available but the internal parts are still accessible. When
building nmcli, only WITH_LIBNM_CORE (the public part) is available.
This granularily controls the build.
2018-01-08 12:38:53 +01:00
Iñigo Martínez 03ba0f1b3a build: Remove default install directories
The install directories of those targets that match the default
install directories have been removed because they are redundant.

This also allows a simple meson build files and it is unnecessary
to create some paths.

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00078.html
2018-01-02 10:44:05 +01:00
Lubomir Rintel 9e4de97967 libnm-core: move detection of UTF-8 capable terminals to clients/
Having it in libnm doesn't make any sense and prevents using it for more
internal functionality.

Too bad nm_utils_wifi_strength_bars() is already a public API.
No problem -- replace it with a compatible yet dumber equivalent.
2017-12-18 14:47:37 +01:00
Lubomir Rintel 6672c5e92e all: get rid of a handful of unused-but-set variables 2017-12-18 13:29:32 +01:00
Iñigo Martínez 0735b35dd0 build: use template files for enum types' sources generation
Source files for enum types are generated by passing segments of the
source code of the files to the `glib-mkenums` command.

This patch removes those parameters where source code is used from
meson build files by moving those segmeents to template files.

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00057.html
2017-12-18 11:25:06 +01:00
Iñigo Martínez 03637ad8b5 build: add initial support for meson build system
meson is a build system focused on speed an ease of use, which
helps speeding up the software development. This patch adds meson
support along autotools.

[thaller@redhat.com: rebased patch and adjusted for iwd support]

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00022.html
2017-12-13 15:48:50 +01:00
Beniamino Galvani fead82f419 tui: fix creation of open Wi-Fi connections
Commit 6a4af482f0 ("nmtui: always create ethernet settings for VLAN
and wireless security for wifi.") changed nmtui to always add the
wireless security setting to the new connection, but without
initializing it. This leads to a crash that was fixed in 40fcf67a84
("tui: fix crash creating Wi-Fi connection").

There is an additional bug: connections without authentication can't
be saved because the wireless security setting has uninitialized
fields.

To fix this, revert both patches (the first partially) because the
previous code did the right thing as it added the setting only when
needed.

Fixes: 6a4af482f0

https://bugzilla.redhat.com/show_bug.cgi?id=1518167
2017-11-30 17:22:28 +01:00
Thomas Haller 0601b5d725 clients: some cleanup of requesting VPN secrets 2017-11-23 14:44:25 +01:00
Thomas Haller 3ee8de20c4 all: include "nm-utils/nm-hash-utils.h" by default
Next we will use siphash24() instead of the glib version g_direct_hash() or
g_str_hash(). Hence, the "nm-utils/nm-hash-utils.h" header becomes very
fundamental and will be needed basically everywhere.

Instead of requiring the users to include them, let it be included via
"nm-default.h" header.
2017-11-16 11:49:51 +01:00
Thomas Haller 5b29c2e5b9 all: use nm_close() instead of close() 2017-11-14 15:10:42 +01:00
Thomas Haller 3434261811 core,clients: use our own string hashing function nm_str_hash()
Replace the usage of g_str_hash() with our own nm_str_hash().

GLib's g_str_hash() uses djb2 hashing function, just like we
do at the moment. The only difference is, that we use a diffrent
seed value.

Note, that we initialize the hash seed with random data (by calling
getrandom() or reading /dev/urandom). That is a change compared to
before.

This change of the hashing function and accessing the random pool
might be undesired for libnm/libnm-core. Hence, the change is not
done there as it possibly changes behavior for public API. Maybe
we should do that later though.

At this point, there isn't much of a change. This patch becomes
interesting, if we decide to use a different hashing algorithm.
2017-10-18 13:05:00 +02:00
Beniamino Galvani 90aa8a8b7b tui: fix memory leak 2017-10-16 17:43:37 +02:00
Beniamino Galvani c898594c71 tui: improve tracking of activation state
nmtui determines the activation result by tracking the active
connection state but that is not enough, as the active connection may
disappear or because we need to consider also the device state in some
particular cases.

Use the same logic implemented in nmcli that is now provided by the
nmc_activation_get_effective_state() helper.
2017-10-16 17:43:37 +02:00
Beniamino Galvani 802116db43 tui: add group-forward-mask property to bridge page
The validation on allowed bits is done when the user saves the
connection.

https://bugzilla.redhat.com/show_bug.cgi?id=1358615
2017-10-13 14:17:26 +02:00
Thomas Haller 40fcf67a84 tui: fix crash creating Wi-Fi connection
When adding a new Wi-Fi connection, nmtui crashes.
Usually, a verified Wi-Fi connection always has key_mgnt set.
However, the client doesn't have the luxury to assume that all
connections verify. Especially, while creating a new connection.

    #0  0x00007ffff4fe5baa in __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
    #1  0x000055555556654c in get_security_type (binding=0x5555557d1cf0) at clients/tui/nm-editor-bindings.c:591
    #2  0x000055555556593b in wireless_security_changed (object=0x0, pspec=0x0, user_data=0x5555557d1cf0) at clients/tui/nm-editor-bindings.c:628
    #3  0x000055555556536d in nm_editor_bind_wireless_security_method (connection=0x5555558028e0, s_wsec=0x555555892eb0 [NMSettingWirelessSecurity], target=0x555555935e10, target_property=0x55555559311b "active-id", flags=(G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE)) at clients/tui/nm-editor-bindings.c:796
    #4  0x000055555557a3aa in nmt_page_wifi_constructed (object=0x5555559349e0 [NmtPageWifi]) at clients/tui/nmt-page-wifi.c:338
    #5  0x00007ffff5e6b670 in g_object_new_internal (class=class@entry=0x5555557c14c0, params=params@entry=0x7fffffffc440, n_params=n_params@entry=2) at gobject.c:1823
    #6  0x00007ffff5e6d24d in g_object_new_valist (object_type=object_type@entry=93824994775616, first_property_name=first_property_name@entry=0x5555555920c6 "connection", var_args=var_args@entry=0x7fffffffc590) at gobject.c:2042
    #7  0x00007ffff5e6d691 in g_object_new (object_type=93824994775616, first_property_name=0x5555555920c6 "connection") at gobject.c:1626
    #8  0x000055555557985a in nmt_page_wifi_new (conn=0x5555558028e0, deventry=0x5555557d15e0 [NmtDeviceEntry]) at clients/tui/nmt-page-wifi.c:45
    #9  0x000055555556f7e2 in nmt_editor_constructed (object=0x555555922af0 [NmtEditor]) at clients/tui/nmt-editor.c:374
    #10 0x00007ffff5e6b670 in g_object_new_internal (class=class@entry=0x555555932750, params=params@entry=0x7fffffffcac0, n_params=n_params@entry=4) at gobject.c:1823
    #11 0x00007ffff5e6d24d in g_object_new_valist (object_type=object_type@entry=93824996288016, first_property_name=first_property_name@entry=0x5555555920c6 "connection", var_args=var_args@entry=0x7fffffffcc10) at gobject.c:2042
    #12 0x00007ffff5e6d691 in g_object_new (object_type=93824996288016, first_property_name=0x5555555920c6 "connection") at gobject.c:1626
    #13 0x000055555556f261 in nmt_editor_new (connection=0x555555802880) at clients/tui/nmt-editor.c:109
    #14 0x0000555555562b35 in nmt_edit_connection (connection=0x555555802880) at clients/tui/nmtui-edit.c:448
    #15 0x0000555555563a29 in create_connection (widget=0x55555588b150 [NmtNewtListbox], list=0x555555922a00) at clients/tui/nmtui-edit.c:185
    #16 0x0000555555563a5d in create_connection_and_quit (widget=0x55555588b150 [NmtNewtListbox], list=0x555555922a00) at clients/tui/nmtui-edit.c:192
    #20 0x00007ffff5e81b0f in <emit signal ??? on instance 0x55555588b150 [NmtNewtListbox]> (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>) at gsignal.c:3447
        #17 0x00007ffff5e6630d in g_closure_invoke (closure=0x555555929260, return_value=0x0, n_param_values=1, param_values=0x7fffffffcfe0, invocation_hint=0x7fffffffcf60) at gclosure.c:804
        #18 0x00007ffff5e7898e in signal_emit_unlocked_R (node=node@entry=0x55555582ac70, detail=detail@entry=0, instance=instance@entry=0x55555588b150, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffcfe0) at gsignal.c:3635
        #19 0x00007ffff5e811a5 in g_signal_emit_valist (instance=0x55555588b150, signal_id=<optimized out>, detail=0, var_args=var_args@entry=0x7fffffffd1b0) at gsignal.c:3391
    #21 0x000055555558e43f in nmt_newt_widget_activated (widget=0x55555588b150 [NmtNewtListbox]) at clients/tui/newt/nmt-newt-widget.c:329
    #22 0x0000555555584fc8 in nmt_newt_form_iterate (form=0x555555922a00 [NmtAddConnection]) at clients/tui/newt/nmt-newt-form.c:309
    #23 0x0000555555585d62 in nmt_newt_form_keypress_callback (fd=1435623072, condition=G_IO_IN, user_data=0x0) at clients/tui/newt/nmt-newt-form.c:335
    #24 0x00007ffff598a247 in g_main_dispatch (context=0x5555557c3af0) at gmain.c:3234
    #25 0x00007ffff598a247 in g_main_context_dispatch (context=context@entry=0x5555557c3af0) at gmain.c:3899
    #26 0x00007ffff598a5e8 in g_main_context_iterate (context=0x5555557c3af0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3972
    #27 0x00007ffff598a902 in g_main_loop_run (loop=0x55555591b190) at gmain.c:4168
    #28 0x00005555555609b5 in main (argc=1, argv=0x7fffffffd5e8) at clients/tui/nmtui.c:298

Fixes: 6a4af482f0
2017-10-11 15:48:47 +02:00
Thomas Haller a0aec7efea shared: pass addr_family as first argument to nm_utils_parse_inaddr*()
The addr_family should be the first argument. It mirrors inet_pton()
and is just nicer.

Also, rename the argument from "family" to "addr_family".
2017-10-06 11:08:39 +02:00
Thomas Haller 4a5ab5f6cb tui: extend range of route metric to full uint32
That is how kernel allows it and the rest of NetworkManager's API.
2017-09-05 19:27:19 +02:00
Thomas Haller 08a186558c tui: extend numeric range of NmtNewtEntryNumeric to gint64
It is used for example for the route's metric, which is
guint32 and may not fit into int type.
2017-09-05 19:27:19 +02:00
Thomas Haller 416a9616de tui: change default route metric of new routes to -1
-1 means "unset" to allow fallback to the per-device metric.
That shall be the preferred default.
2017-09-05 19:10:07 +02:00
Thomas Haller 506fca65b3 tui: guess the prefix length (netmask) of private IPv4 addresses and routes based on network class
For RFC1918 private IPv4addresses, guess a better prefix length for
addresses and routes.

nmtui is an interactive program. It makes sense to be a bit smarter
about what the user probably meant.

It would be nice if nmtui would update the entry field immediately when
the cursor leaves the field, to show the guessed prefix length. However,
that is not easily possible, so lets to that another time.

For IPv6 addresses, default to /64 instead of /128.

https://bugzilla.redhat.com/show_bug.cgi?id=1474295
2017-09-05 18:44:04 +02:00
Thomas Haller 69ccbb7513 tui: avoid integer overflow checking the range in NmtNewtEntryNumeric
strtoul() operates on "unsigned long" while NmtNewtEntryNumeric uses
"int".

strtoul() might indicate that the text is a valid "unsigned long",
however, then casting to "int" might lead to truncation of the number
and wrong range check.

Also, the type supposedly handles negative integers as well. Not with
strtoul().
2017-09-05 18:44:04 +02:00
Thomas Haller ccc2af0efb tui: allow empty route metric to indicate default
When entering a manual route, the metric defaults internally to "-1".
That is indicated in the TUI as empty entry. We must allow that as
valid configuration.
2017-09-05 18:44:04 +02:00
Thomas Haller 9400f0d84d tui: extend NmtNewtEntryNumeric to allow optional empty entry 2017-09-05 18:44:04 +02:00
Beniamino Galvani 7246c87f0f tui: add ignore-auto-dns property to IPv4 and IPv6 pages
https://bugzilla.redhat.com/show_bug.cgi?id=1487084
2017-09-01 17:09:57 +02:00
Thomas Haller 3443f25001 tui: use nm_streq0() in nmt_connect_connection_list_get_connection() 2017-05-30 14:33:23 +02:00
Arnaud Lefebvre 1fcbb69ae2 nmtui connect: avoid segfault when iface is not found
https://github.com/NetworkManager/NetworkManager/pull/21
2017-05-30 14:30:30 +02:00
Nikolay Martynov fd14aa033e nmtui: add support for cloned mac in bond interfaces
This is useful because bond gets its mac from first slave and order of
slave attachement is not guaranteed.
For example if we have bond with wifi and ethernet we want mac from
wifi to be use by bond interface because many wifi defices do now
allow one to send data with spoofed macs.

Signed-off-by: Nikolay Martynov <mar.kolya@gmail.com>
2017-05-28 23:22:55 +02:00
Nikolay Martynov 6a4af482f0 nmtui: always create ethernet settings for VLAN and wireless security for wifi.
Ethernet settings for VLAN are always created later in settings
normalization. We might as well always created them.

This fixes a user visible problem: currently if user specifies cloned
mac when connection is created this value doesn't get saved. User has
to go, edit saved connection to add it again.

Similar problem existed for wireless security and wifi

Signed-off-by: Nikolay Martynov <mar.kolya@gmail.com>
2017-05-28 23:22:55 +02:00
Thomas Haller 22b7282d84 all: use "unsigned" instead of "unsigned int" 2017-03-14 11:26:29 +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
Lubomir Rintel 9cc15d39eb tui: recommit bond, bridge and team slaves on master save
The ifcfg-rh plugin may want to update its MASTER= key accordingly for
better compatibility with the legacy network service.
2017-02-27 11:17:39 +01:00
Lubomir Rintel c8969dbf80 tui/editor: notify the pages after the connection is saved
This will make it possible for the pages to commit slave connections
when the master connection is saved.
2017-02-27 11:17:39 +01:00
Lubomir Rintel 8fce72360e tui/edit-connection-list: add routine to recommit connections in a list
This is useful when master connections are saved potentially influencing
how slave connections are serialized.
2017-02-27 11:16:45 +01:00
Lubomir Rintel ff46158d9e tui: generate names for bonds, teams and bridges
This makes it more likely that the user will end up with a master
connection that has connection.interface-name property. This makes it
possible for ifcfg plugin to specify the master in the for of device
name (as opposed to UUID) for compatibility with the legacy network
tooling.

This is equivalent to what nmcli does.

https://bugzilla.redhat.com/show_bug.cgi?id=1369091
2017-02-20 16:07:43 +01:00
Lubomir Rintel 260563a7d9 all: use nm_utils_is_valid_iface_name() 2017-01-06 15:11:56 +01:00
Beniamino Galvani cd73f281cc tui: add support for IP tunnel connections 2016-11-09 17:45:39 +01:00
Thomas Haller 586e830e05 build: merge "clients/tui/Makefile.am" into toplevel Makefile 2016-10-21 17:37:56 +02:00
Thomas Haller a8284c57f9 tui,cli/build: add linker version script for nmcli and nmtui 2016-10-13 21:36:06 +02:00
Beniamino Galvani b28b2ba8a9 clients: add define for NMSecretAgentSimple signal name 2016-09-14 23:32:52 +02:00
Thomas Haller 814784aa46 libnm: fix regression serializing empty "cloned-mac-address"
For "cloned-mac-address", the empty string "" is an invalid
value that is rejected by verify().

Commit 8eed671 changed how the property is serialized to D-Bus.
Before, it was serialized using _nm_utils_hwaddr_to_dbus().
For invalid or empty addresses, this would not serialize the
value on D-Bus (or before commit 76aa6f8e0, it would create
a bogus value with no array elements).

With commit 8eed671, the cloned-mac-address gets also serialized
as "assigned-mac-address" via _nm_utils_hwaddr_cloned_data_synth(),
which would pass on invalid strings that the server would then reject.

That breaks for example nmtui. Try editing a connection with
"cloned-mac-address" set to NULL. Note, as long as you don't edit
the cloned MAC address in nmtui, you can save the modification.
Once you start modifying the entry, you can no longer set an empty
MAC address as the server now receives the invalid empty string.
Thus, the "OK" button fails with
   Unable to save connection:
   802-3-ethernet.cloned-mac-address:
   is not a valid MAC address
It also means, nmtui cannot modify the "cloned-mac-address" field to
become empty.

Fix that problem at various places by coercing "" to NULL.

Fixes: 8eed67122c

https://bugzilla.redhat.com/show_bug.cgi?id=1372799
2016-09-06 16:11:23 +02:00
Thomas Haller 0bdcab100c all: cleanup includes in header files
- don't include "nm-default.h" in header files. Every source file must
  include as first header "nm-default.h", thus our headers get the
  default include already implicitly.

- we don't support compiling NetworkManager itself with a C++ compiler. Remove
  G_BEGIN_DECLS/G_END_DECLS from internal headers. We do however support
  users of libnm to use C++, thus they stay in public headers.

(cherry picked from commit f19aff8909)
2016-08-17 19:51:17 +02:00