Commit Graph

748 Commits

Author SHA1 Message Date
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
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
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
Lubomir Rintel
93f1a1d461 platform: fix 32-bit build
Fixes: 6d67e6e9c4
2015-12-23 12:35:15 +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
Thomas Haller
be0f8e2854 platform/trivial: move code
sysctl handling is independent from netlink-cache. Move the code.
2015-12-17 18:08:36 +01:00
Thomas Haller
600a247f57 platform: refactor handling netlink message by manually inlining cache functions
There are only one caller of the two functions. It's shorter and simpler
just to implement the short functionality right there.
2015-12-12 22:18:28 +01:00
Thomas Haller
8a38b4dd13 platform: inline setup_socket() function
Constructing the sockets is already quite simple, yet distinct.
Later this distinction will become bigger, so unwrap setup_socket().
2015-12-12 12:34:29 +01:00
Thomas Haller
461cf0c571 platform: factor out completing and sending netlink message 2015-12-12 12:34:29 +01:00
Thomas Haller
9ce3733d0c platform: add const to input arguments to link-add functions
Some line-breaks and adding "const".
2015-12-11 14:14:13 +01:00
Thomas Haller
d2fab2df54 platform: EAGAIN is equal to EWOULDBLOCK
The macro EWOULDBLOCK is another name for EAGAIN; they are always the
  same in the GNU C Library.

  https://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/Error-Codes.html

Otherwise, we would need a workaround for EWOULDBLOCK too, because
libnl maps that to NLE_FAILURE. So we would have to detect EAGAIN
as (nle == -NLE_FAILURE && errno == EWOULDBLOCK).
2015-12-10 17:53:04 +01:00
Thomas Haller
eeb7d20ee0 platform: fix memleak in _nl_sock_flush_data()
Fixes: 9a16ce0876
2015-12-10 17:13:48 +01:00
Thomas Haller
10b684b827 platform: fix event_handler_read_netlink_one() wrongly returning with nothing to read
When the errno was accidentally set to EAGAIN or EWOULDBLOCK,
we would only read one single message and return that there is
nothing to read.

This means, if there were more then one messages ready to read,
we would only read the first one and return to the main-loop
(which then again calls back to platform as more data is ready
to be read).
2015-12-10 17:13:48 +01:00
Thomas Haller
1a7b19ea6a platform: move reading sysctl-options for master/slave to NMPlatform
These functions are only helpers for accessing sysctl and independent
from NMLinuxPlatform. Move their implementation to the base class.
2015-12-10 14:33:49 +01:00
Thomas Haller
eef388990f platform/trivial: rename link related functions
Link related functions should have a "nm_platform_link" prefix. Rename.

Naming is a subjective matter and one might argue that omitting
the "link" part from the name is shorter and even preferred.

However, I think functions related to links should have a common
prefix as the underlyings are strongly related.
2015-12-10 14:33:49 +01:00
Thomas Haller
6a7730241b trival: fix whitespace 2015-12-10 14:33:49 +01:00
Thomas Haller
a4de9187ff platform: return pointer to NMPlatformLink object for add functions
Let the link-add functions return the internal pointer to the platform
link object. Similar to link-get, which doesn't copy the link either.

Also adjust the sole users of the add-functions (create-and-realize)
to take the pointer.

Eventually we still copy the returned data, because accessing platform can
invalidate the returned pointer. Thus we don't actually safe any copying
by this (at least every use of the function currently leads to the data
being copied).
Still change it, because I think the API of NMPlatform should look like that.
2015-12-10 14:33:49 +01:00
Beniamino Galvani
01e95c8c95 platform: add vxlan support
Add a new method to the platform code to create vxlan devices.
2015-12-09 16:36:46 +01:00
Beniamino Galvani
3871056019 platform: add macvtap link creation support 2015-12-09 14:30:08 +01:00
Beniamino Galvani
27c0f8def4 platform: add macvlan link creation support 2015-12-09 14:30:08 +01:00
Beniamino Galvani
c1be9856bf platform: return the macvlan mode as integer
It's easier to handle it as an integer than as a string.
2015-12-09 14:30:07 +01:00
Beniamino Galvani
32f6e1ef2e platform: add IP6TNL links support 2015-12-01 17:39:41 +01:00