nl_recv(): Memory allocation errors are handled properly now
1. all cleanup actions (like free()) now located at the end of function
2. in case of error or EOF, *buf and *creds (if given) set to NULL
This protect from invalid code at user's side, like:
char *buf;
x = nl_recv(..., &buf, ...);
if (x<=0)
goto cleanup;
cleanup:
free(buf);
3. all intermediate buffers are stored into local variables, and user's
variables only touches at the end.
genl/family flags can be damaged during the auto-indentation.
"-" was never used in the names of the flags. "_" was used in all places
of the library. So, I just changed the undescore to the minus.
Automatic indentation can insert spaces on either side of the minus,
so the library will be compiled, but will not be usable (in this part of the code),
as the parser will split words by white space, and the flag "admin - perm"
will never work.
With this change you can still set do modifications of
Links and then to change to pass the changes to the
kernel. But it additionally enables you to interact
with this part of libnl-python in a more pythonic
way. Instead of:
libnl-3.2.12 - ./configure --disable-doc: error: conditional "LINK_DOC" was never defined. \ Usually this means the macro was only invoked conditionally.
configure: error: conditional "LINK_DOC" was never defined.
Usually this means the macro was only invoked conditionally.
Attached patch provided by Martin Jansa.
See also https://bugs.gentoo.org/show_bug.cgi?id=433565
Коренберг Марк [Thu, 30 Aug 2012 16:25:21 +0000 (22:25 +0600)]
asprintf related fixed in yy parser
1. According to man asprintf:
If memory allocation wasn't possible, or some other error occurs,
these functions will return -1, and the contents of strp is undefined.
2. Sometimes, errp was not filled at all. In high-level code, free(errp)
will called, so segmantation fault may appear in case of error in parser
3. The most cases of using asprintf is to report about allocation fail.
So, probability of allocation of asprintf buffer is very high. And that
will lead to trash in errp.
4. For simple casses I decide to replace asprintf with strdup
Fix warning "not checking return value of fscanf" in lib/utils.c: get_psched_settings
Also, change internal variables type from uint32_t to unsigned int.
Correct scanf format string should contain "SCNx32" instead of just "x",
but I decide not to fix that and just changed variable type.
So, according to man 3 printf,
uint64_t should be printed as "%llu" on some architectures, and as "%lu" on another. The same for scanf.
To eliminate that challenge, there is inttypes.h, in which appropriate constants
are defined for current architecture.
32-bit types (and even 16 and 8 bit types) should be printed using such constants if
printed variable defined as uint_XXXt or intXXXt type. But in reality 32-bit and less
types does not gain run-time error (except in scanf), because they pushed to stack as
32-bit values at least. So, I decide not to fix that.
Run-time version information is available as exported four integers:
- const int nl_ver_num = LIBNL_VER_NUM;
- const int nl_ver_maj = LIBNL_VER_MAJ;
- const int nl_ver_min = LIBNL_VER_MIN;
- const int nl_ver_mic = LIBNL_VER_MIC;
The purpose of this is to get version of compiled library as run time.
Use cases:
- To know exact version of the library in Python's ctypes module,
Say, to find out if nl_cache_mngr_alloc() allow sk=NULL
- To make sure that the version of the loaded library corresponds to the
version of headers (for the paranoid). Say, to check:
Justin Mayfield [Fri, 17 Aug 2012 01:03:48 +0000 (19:03 -0600)]
single nexthop flags bug
I ran into a bug today related to how Linux handles a route's nexthop
flags when there is just one nexthop. Namely Linux expects the flags
to be OR'd into the rtm_flags field when there is only one nexthop and
so rtnl_route_build_msg needs to check the number of nexthops and
store the nexthops flags into this field prior to calling
nlmsg_append(...&rtmsg).
Conversely the rtnl_route_parse function needs to pull these lower
0xff bits when a single nexthop is detected.
Attached is my patch. I don't like the slight duplication of doing
the rtnl_route_get_nnexthops check twice but it seemed to be the least
turmoil of any solution I thought of.
Justin Mayfield [Sat, 18 Aug 2012 00:16:44 +0000 (18:16 -0600)]
nl_addr_parse handling of 'default', 'any', and 'all'
I found a small bug in the nl_addr_parse function when being passed the
strings "default", "any", or "all". Currently nl_addr_parse will create
a zeroed nl_addr with a length corresponding to the family/hint or
AF_INET if omitted. This behavior when used in conjunction with the
libnl-route library to add default routes to the system has the side
effect of creating a route to the host address 0.0.0.0/32.
Attached is a patch that matches the iproute2 behavior more closely
where we do set the family but the length of the nl_addr is set to 0.
Thomas Graf [Wed, 29 Aug 2012 10:05:51 +0000 (12:05 +0200)]
Fix build warning after const char ** convert
Commit 25d640da4a caused the following build warning:
../include/netlink/utils.h:47:15: note: expected 'const char **' but argument is of type 'char **'
route/link/inet6.c:300:11: warning: passing argument 2 of 'nl_cancel_down_bytes' from incompatible pointer type [enabled by default]
Коренберг Марк [Fri, 8 Jun 2012 14:15:06 +0000 (20:15 +0600)]
Fix types-related warnings based on clang diagnostics
1. Fix some places where unsigned value compared < 0
2. Fix obsolete %Z specifier to more portable %z
3. Some erroneous types substitution
4. nl_msec2str() - 64-bit msec is now properly used,
Only safe changes. I mean int <--> uint32_t and signed/unsigned fixes.
Some functinos require size_t argument instead of int, but changes of
signatures of that functions is terrible thing.
Also, I do not pretend for a full list of fixes.
Just to shut up clang -Wall -Wextra
One more thing. ifindex. I don't change that because changes will
be too big for simple fix.
Andrew Collins [Mon, 11 Jun 2012 16:44:42 +0000 (10:44 -0600)]
Add 'ingress' to the list of recognized TC handles.
Currently, rtnl_tc_handle2str understands the ingress handle but
rtnl_tc_str2handle does not. This change lets rtnl_tc_str2handle
recognize 'ingress' as a valid handle as well.
Flags properties description and implementation fixed
1. Address, Link and Vlan classes affected with same bug
2. Flags property are not designed as set class. Setting to property will
not replace flags, just add flags to set. So, jist document that, and
fixed obvious logick.