Commit Graph

761 Commits

Author SHA1 Message Date
Thomas Haller
f00c472ee8 platform: increase netlink socket receive buffer size
When the receive buffer is too small, we easily can hit ENOBUFS during recvmsg()
and need to resync the platform cache. But even worse, we possibly also loose
ACKs for pending netlink requests so that requests seem to fail (although they
might have succeeded).

Avoid that harder by increasing the buffer size to 8MB. This is also
done by networkd:

  be660c371b
2016-01-25 15:48:09 +01:00
Thomas Haller
45df49ebdd platform: improve detecting ENOBUFS for recvmsg() on netlink socket
libnl3 maps different error codes to NLE_NOMEM. Only resync platform cache
when we really experienced a ENOBUFS from recvmsg().
2016-01-25 15:08:32 +01:00
Thomas Haller
4ba999e41e platform: refactor check for error in event_handler_recvmsgs() to switch statement 2016-01-25 15:07:10 +01:00
Thomas Haller
8ab968d4ef platform: fix draining netlink socket on cache resync
Fixes: 809c547b6c
2016-01-25 14:38:35 +01:00
Thomas Haller
809c547b6c platform: handle netlink ACKs in event_handler_recvmsgs() during cache-resync
When reading from netlink-socket fails with NLE_NOMEM, messages were
lost. In this case the cache must be resynced and all pending messages
from the socket are rejected via "event_handler_recvmsgs (platform, FALSE)".

In this case, we don't want to handle the received messages as the
cache anyway needs to resync. However, we are still interested in
all queued ACKs that are there.

We are also interested in RTM_NEWADDR messages which we use to detect
kernel support via _support_kernel_extended_ifa_flags_detect().
2016-01-25 13:33:10 +01:00
Thomas Haller
ba187e054d core: refactor functions to use NM_UTILS_LOOKUP*()
Also use NM_UTILS_LOOKUP_STR() macro, which can transform
unknown values to their numerical representation using
alloca().
2016-01-24 15:04:36 +01:00
Dan Williams
356b4ce29c platform: fix leak when netlink dump is too large 2016-01-21 12:28:13 -06:00
Lubomir Rintel
88da21caa1 linux-platform: fix accidental Python
Coverity: CID 59378 (#1 of 1): Nesting level does not match indentation
(NESTING_INDENT_MISMATCH) This statement is indented to column 41, as if
it were nested within the preceding parent statement, but it is not.
2016-01-21 16:53:56 +01:00
Lubomir Rintel
d03322b2a5 linux-platform: fix a file descriptor leak
Coverity: CID 59384 (#3-1 of 3): Resource leak (RESOURCE_LEAK)26.
leaked_handle: Handle variable fd going out of scope leaks the handle
2016-01-21 16:32:23 +01:00
Lubomir Rintel
c1cf3c25c8 linux-platform: treat gadget devices as ethernet devices
Also, don't manage them by default. Whatver created it should take care of
management.
2016-01-21 11:33:59 +01:00
Thomas Haller
4b917123ef platform: use NM_UTILS_ENUM2STR_DEFINE() to implement to-string functions 2016-01-18 13:10:18 +01:00
Thomas Haller
94fabafc1a platform: use RT_SCOPE_* names in nm_platform_route_scope2str() 2016-01-18 13:10:18 +01:00
Thomas Haller
262ba62708 core/trivial: add code comment explaining route-handling and gateway 2016-01-18 13:10:18 +01:00
Thomas Haller
7a2a96f8ef platform/tests: add test for handling IPv4 zero gateways
Adding a route via iproute2 with explicit gateway 0.0.0.0
sets the route scope to GLOBAL, contrary to a on-link device-route
which has scope LINK.

Add a test adding two such routes.
2016-01-16 21:27:12 +01:00
Thomas Haller
4c79b605bc platform: implement nmp_object_is_visible() based on nmp_object_is_alive()
An object should only be visible if it is also alive.
Hence, refactor nmp_object_is_visible() to be reject
object that fail nmp_object_is_alive().
2016-01-16 13:43:23 +01:00
Thomas Haller
3294e06c28 platform: add "link" scope to nm_platform_route_scope2str() 2016-01-16 13:43:23 +01:00
Lubomir Rintel
a6c8a45463 platform: fix a typo when comparing the peer addresses 2016-01-12 17:59:23 +01:00
Beniamino Galvani
24d8604637 core: use NM_PLATFORM_GET instead of nm_platform_get() in function calls
Replacement was done with command:

spatch --sp-file nm_platform_get.cocci --in-place --smpl-spacing --dir src

where nm_platform_get.cocci contains:

@@
identifier func;
expression list args;
@@
- func (nm_platform_get())
+ func (NM_PLATFORM_GET)

@@
identifier func;
expression list args;
@@
- func (nm_platform_get(), args)
+ func (NM_PLATFORM_GET, args)
2016-01-06 21:25:56 +01:00
Beniamino Galvani
f96abc8be5 core: always use gulong to store signal handler ids
We inconsistently use gulong,guint,int types to store signal handler
id, but the type returned by g_signal_connect() is a gulong.

This has no practical consequences because a int/guint is enough to
store the value, however it is better to use a consistent type, also
because nm_clear_g_signal_handler() accepts a pointer to the signal id
and thus it must be always called with the same pointer type.
2016-01-06 21:25:55 +01:00
Thomas Haller
0e164ac607 platform: ensure _nl_send_auto_with_seq() returns 0 on success
Just for consistency reason.
2016-01-04 18:15:17 +01:00
Thomas Haller
7102cde1ff platform/trivial: remove extra indention in constructed() 2016-01-04 18:08:04 +01:00
Thomas Haller
ac7a6d0206 systemd: merge branch 'systemd' into master 2016-01-04 17:03:11 +01:00
Thomas Haller
4b5352057a platform/tests: avoid test failure in test_ip6_address_general()
# Start of ipv6 tests
  # NetworkManager-FATAL-ERROR: NMPlatformSignalAssert: ../../../../../src/platform/tests/test-address.c:154, test_ip6_address_general(): failure to free non-accepted signal: ip6-address-changed-changed ifindex 11 (1 times received)
2016-01-04 17:01:18 +01:00
Thomas Haller
db80ec05ab build: rename directory "include" to "shared"
Up to now, the "include" directory contained (only) header files that were
used project-wide by libs, core, clients, et al.

Since the directory now also contains a non-header file, the "include"
name is misleading. Instead of adding yet another directory that is
project-wide, with non-header-only content, rename the "include"
directory to "shared".
2015-12-24 11:42:37 +01:00
Lubomir Rintel
93f1a1d461 platform: fix 32-bit build
Fixes: 6d67e6e9c4
2015-12-23 12:35:15 +01:00
Thomas Haller
ad1d74d142 platform: add index for links by ifname
Downsides:

  - Add some additional overhead to manage the index

  - The NMPCacheId struct grows to 16 bytes, affecting
    hashing performance for all object types.

Still do it, based on the assumption that it doesn't matter
for a low number of interfaces. But the O(1) access time matters
when having lots of interfaces.
2015-12-17 18:42:53 +01:00
Thomas Haller
88213b2e6a platform: tighten return value from do_add_addrroute()
Only return TRUE, if the netlink request was responded with success and
the object exists after adding.
2015-12-17 18:42:53 +01:00
Thomas Haller
1a501c6456 platform: check for existing link in do_add_link_with_lookup()
When adding a link, that can only make sense if no such link
exists yet. Check for that condition first, to properly return
an error.
2015-12-17 18:42:53 +01:00
Thomas Haller
cea8f1a0f0 platform: change meaning of return value for delete-function
When deleting an object, we allow failure to delete a non-existing object.
Thus, the only thing we care about is whether the object is no longer
present after deletion. Adjust the return values to reflect that.
2015-12-17 18:42:53 +01:00
Thomas Haller
690732cfed platform: drop delayed_action idle handler
The idea was allowing pending delayed-actions and process them in an
idle handler. We dont want to do that, because whenever platform code
returns, we want to have no pending actions -- because otherwise the
platform cache might be in an inconsistent state.

Just drop it.
2015-12-17 18:42:51 +01:00
Thomas Haller
a29f438294 platform/trivial: rename internal field with netlink socket 2015-12-17 18:42:01 +01:00
Thomas Haller
412a50bd30 platform: inline event_handler_read_netlink() 2015-12-17 18:42:01 +01:00
Thomas Haller
d7782b9769 platform: drop synchronous netlink socket 2015-12-17 18:42:01 +01:00
Thomas Haller
c73b9f6529 platform: change links via event netlink socket 2015-12-17 18:42:01 +01:00
Thomas Haller
1097967077 platform: delete objects via event netlink socket 2015-12-17 18:42:01 +01:00
Thomas Haller
be28608a8f platform: add addresses and routes via event netlink socket 2015-12-17 18:42:01 +01:00
Thomas Haller
f8378800bb platform: add links via event netlink socket 2015-12-17 18:42:01 +01:00
Thomas Haller
dce5e6d815 platform: assert that delayed_action_handle_all() is not called recursively
We would not expect that delayed_action_handle_all() is called recursively.
Assert against that. If we ever happen to call it recursively, we would
need to take care of properly avoiding infinite loops or deep call
stacks.
2015-12-17 18:41:59 +01:00
Thomas Haller
6d67e6e9c4 platform: rework waiting for netlink response
Track pending netlink requests and properly report the resulting errno
back.

Currently we send only requests in do_request_link() and do_request_all().
These callers don't actually care about the result, all they care that the
request is answered before returning back from platform code to the caller.
Thus, up to now the tracking of the sequence number was pretty simple.

Later we also want to get the errno from a request, thus rework sending
requests to also remember about outstanding sequence numbers and
properly track muliple parallel requests.

Later the synchronous actions (e.g. add-link) will also be handled
via the asynchronous socket.
2015-12-17 18:32:15 +01:00
Thomas Haller
eb182c2e1c platform: minor refactoring in delayed_action_schedule() 2015-12-17 18:32:09 +01:00
Thomas Haller
c9e04c963e platform: implement our own sequence counter
Instead of using the one from libnl's socket.
2015-12-17 18:32:06 +01:00
Thomas Haller
4ea711e03e platform/trivial: remove obsolete code comment 2015-12-17 18:08:36 +01:00
Thomas Haller
ecdcfda0dd platform: cleanup event_handler_recvmsg() (rename event_valid_msg()) 2015-12-17 18:08:36 +01:00
Thomas Haller
6ee868678b platform: cleanup event_handler_recvmsg() (drop _nl_sock_flush_data())
Also avoids/fixes a bug in _nl_sock_flush_data() where we would loop
endlessly, if nl_recvmsgs() fails for reasons other then EAGAIN.
2015-12-17 18:08:36 +01:00
Thomas Haller
385e68327f platform: cleanup event_handler_recvmsg() (adjust log messages) 2015-12-17 18:08:36 +01:00
Thomas Haller
47773c80ac platform: cleanup event_handler_recvmsg() (inline event_err()) 2015-12-17 18:08:36 +01:00
Thomas Haller
c13163cd55 platform: cleanup event_handler_recvmsg() (move EAGAIN workaround) 2015-12-17 18:08:36 +01:00
Thomas Haller
bdd2c31d39 platform: cleanup event_handler_recvmsg() (inline verify_source()) 2015-12-17 18:08:36 +01:00
Thomas Haller
3e2d0d6968 platform: cleanup event_handler_recvmsg() (code-style) 2015-12-17 18:08:36 +01:00
Thomas Haller
2f6b5d4125 platform: reimplement nl_recvmsg() in platform
Calling nl_recvmsgs_default() leads dirctly to recvmsgs() from
"nl.c". This functions reads messages (recvmsg) in a loop and
invokes the callbacks.

Later we want to merge nlh and nlh_event, meaning that we must
anticipate parsing unrelated messages while waiting for an ACK.
While that would be possible by registering different callbacks
and letting them interact, it is actually more complicated. Just
assume full control over the message parsing.

Basically, copy recvmsgs() to event_handler_recvmsg(). For now just
copy the function and do little adjustment (to show the similarity
to the original). Cleanup follows.
2015-12-17 18:08:36 +01:00