Commit graph

18 commits

Author SHA1 Message Date
Lennart Poettering a1e58e8ee1 tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this:

        free(p);
        p = NULL;

by this:

        p = mfree(p);

Change generated using coccinelle. Semantic patch is added to the
sources.
2015-09-09 08:19:27 +02:00
Karel Zak 0610939d6b libsystemd: fix RTNL_CONTAINER_DEPTH assert
The m->n_containers is index and has to be smaller than the array
size.
2015-08-06 13:33:53 +02:00
Susant Sahani c06aead0c3 sd-netlink: introduce api for new NL type NLA_FLAG 2015-07-29 11:59:16 +05:30
Tom Gundersen 4c641e99fa sd-netlink: respect attribute type flags
Though currently unused by us, netlink attribute types support embedding flags to indicate
if the type is encoded in network byte-order and if it is a nested attribute. Read out
these flags when parsing the message.

We will now swap the byteorder in case it is non-native when reading out integers (though
this is not needed by any of the types we currently support). We do not enforce the NESTED
flag, as the kernel gets this wrong in many cases.
2015-06-30 23:14:53 +02:00
Tom Gundersen f663aeb80b netlink: rework containers
Instead of representing containers as several arrays, make a new
netlink_container struct and keep one array of these structs. We
also introduce netlink_attribute structs that in the future will
hold meta-information about each atribute.
2015-06-28 19:16:04 +02:00
Tom Gundersen 4203fc8b81 sd-netlink: make a couple of helper functions static
Also rename from rtnl_* to netlink_*.
2015-06-28 19:10:51 +02:00
Tom Gundersen da041d69d1 sd-netlink: mark union containers as nested
This was an oversight, they are no different from regular containers in this respect.
2015-06-28 19:10:51 +02:00
David Herrmann 846a6b3d89 sd-netlink: don't treat NULL as root type-system
Explicitly export the root type-system to the type-system callers. This
avoids treating NULL as root, which for one really looks backwards (NULL
is usually a leaf, not root), and secondly prevents us from properly
debugging calling into non-nested types.

Also rename the root to "type_system_root". Once we support more than
rtnl, well will have to revisit that, anyway.
2015-06-24 13:46:11 +02:00
David Herrmann 12b7dff45b sd-netlink: make sure the root-level type is nested
In sd-netlink-message, we always guarantee that the currently selected
type-system is non-NULL. Otherwise, we would be unable to parse any types
in the current container level. Hence, this assertion must be true:
    message->container_type_system[m->n_containers] != NULL

During message_new() we currently do not verify that this assertion is
true. Instead, we blindly access nl_type->type_system and use it (which
might be NULL for basic types and unions). Fix this, by explicitly
checking that the root-level type is nested.

Note that this is *not* a strict requirement of netlink, but it's a strict
requirement for all message types we currently support. Furthermore, all
the callers of message_new() already verify that only supported types are
passed, therefore, this is a pure cosmetic check. However, it might be
needed on the future, so make sure we don't trap into this once we change
the type-system.
2015-06-24 13:45:56 +02:00
David Herrmann c1df8dee28 sd-netlink: turn 'max' into 'count' to support empty type-systems
Right now we store the maximum type-ID of a type-system. This prevents us
from creating empty type-systems. Store the "count" instead, which should
be treated as max+1.

Note that type_system_union_protocol_get_type_system() currently has a
nasty hack to treat empty type-systems as invalid. This might need some
modification later on as well.
2015-06-24 13:45:47 +02:00
David Herrmann 6c14ad61db sd-netlink: avoid casting size_t into int
size_t is usually 64bit and int 32bit on a 64bit machine. This probably
does not matter for netlink message sizes, but nevertheless, avoid
hard-coding it anywhere.
2015-06-24 13:45:47 +02:00
David Herrmann 435bbb0233 sd-netlink: make NLTypeSystem internal
Same as NLType, move NLTypeSystem into netlink-types.c and hide it from
the outside. Provide an accessor function for the 'max' field that is used
to allocate suitable array sizes.

Note that this will probably be removed later on, anyway. Once we support
bigger type-systems, it just seems impractical to allocate such big arrays
for each container entry. An RBTree would probably do just fine.
2015-06-24 13:45:47 +02:00
David Herrmann 817d1cd824 sd-netlink: make NLType internal
If we extend NLType to support arrays and further extended types, we
really want to avoid hard-coding the type-layout outside of
netlink-types.c. We already avoid accessing nl_type->type_system outside
of netlink-types.c, extend this to also avoid accessing any other fields.

Provide accessor functions for nl_type->type and nl_type->size and then
move NLType away from the type-system header.

With this in place, follow-up patches can safely turn "type_system" and
"type_system_union" into a real "union { }", and then add another type for
arrays.
2015-06-24 13:45:47 +02:00
David Herrmann c658008f50 sd-netlink: don't access type->type_system[_union] directly
Make sure we never access type->type_system or type->type_system_union
directly. This is an implementation detail of the type-system and we
should always use the accessors. Right now, they only exist for 2-level
accesses (type-system to type-system). This patch introduces the 1-level
accessors (type to type-system) and makes use of it.

This patch makes sure the proper assertions are in place, so we never
accidentally access sub-type-systems for non-nested/union types.

Note that this places hard-asserts on the accessors. This should be fine,
as we expect callers to only access sub type-systems if they *know*
they're dealing with nested types.
2015-06-24 13:45:47 +02:00
David Herrmann cafbc790d1 sd-netlink: rename NLA_ to NETLINK_TYPE_
The NLA_ names are used to name real datatypes we extract out of netlink
messages. The kernel has an internal enum with the same names
(NLA_foobar), which is *NOT* binary compatible to our types. Furthermore,
we support a different set of types than the kernel (as we try to treat
some kernel peculiarities as our own types to simplify the API).

Rename NLA_ to NETLINK_TYPE_ to make clear that this is our own set of
types.
2015-06-24 13:45:47 +02:00
Tom Gundersen 89489ef7d4 sd-netlink: message - split up source file
Split netlink-socket.c and rtnl-message.c from netlink-message.c.
2015-06-13 21:11:01 +02:00
Tom Gundersen bbe181b489 sd-netlink: drop the write-queue
AF_NETLINK is not write-buffered, so this was actually never used.
2015-06-13 20:51:56 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Renamed from src/libsystemd/sd-rtnl/rtnl-message.c (Browse further)