summaryrefslogtreecommitdiffstats
path: root/lib/addr.c
Commit message (Collapse)AuthorAgeFilesLines
* all: fix and enable "-Wsign-compare" warningThomas Haller2024-05-291-2/+2
|
* lib: remove unused assignment in nl_addr_parse()Thomas Haller2023-12-041-2/+0
| | | | | | | | | | | | Coverity warns about this. Avoid it. Error: CLANG_WARNING: [#def3] libnl-3.8.0/lib/addr.c:324:3: warning[deadcode.DeadStores]: Value stored to 'len' is never read # 322| !strcasecmp(str, "any")) { # 323| # 324|-> len = 0; # 325| # 326| switch (hint) {
* include: use <linux/$file> instead of <linux-private/linux/$file>Thomas Haller2023-08-081-1/+1
| | | | | | As we now copy all linux headers, and we have include/linux-private in our include search path, just include the linux headers as we commonly do.
* include: include private linux headers with explicit pathThomas Haller2023-08-031-1/+1
| | | | | | | We have copies of the linux headers in include/linux-private. For those files, include the copies explicitly. No practice there is no difference, since we build with :-Ilinux-private".
* include: drop "netlink-private/netlink.h" and move declarationsThomas Haller2023-08-021-2/+1
|
* all: cleanup includes and use "nm-default.h"Thomas Haller2023-08-021-2/+6
|
* include: split and drop "netlink-private/types.h"Thomas Haller2023-08-021-0/+1
| | | | | Move all the declarations from "netlink-private/types.h" to places closer to where they are used.
* include: move "include/netlink-private/route/mpls.h" to "lib/mpls.h"Thomas Haller2023-07-311-1/+2
|
* all: use _NL_{MIN,MAX}() macrosThomas Haller2023-07-281-1/+1
| | | | | | | | | | | | | | | | | | Replace the use of the previous min()/min_t()/max()/max_t(). - min_t()/max_t() required a type, and would do plain assignment, which C would not complain about. It is thus a cumbersome and not very safe pattern. Avoid it. - min()/max() did better, it used typeof() to preserve the argument types and automatically detect it. However, it also required that both arguments had the same integer type, which is unnecessarily strict. _NL_MIN()/_NL_MAX() does better. It accepts arguments of any integer types, but has a static assertions that they match in signedness. So it's more flexible to use than min()/max() and still quite safe. Prefer the new macros.
* addr: allow constructing all-zero addressesJonas Gorski2022-07-061-1/+1
| | | | | | | | Allow easy contruction of all-zero addresses by not passing a buf to copy. Since the object is allocated with calloc, the address data will default to all-zero, and only the length needs to be set. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
* addr: create an all-zero addresses when parsing "any" or "default"Jonas Gorski2022-07-061-1/+6
| | | | | | | | | | | | | When calling nl_addr_parse() is called with "any" or "default", the constructed address will have zero-length address data. This has the side effect that a comparison with e.g. an address contructed from "0.0.0.0/0" will fail, since their address has different lengths, even if they should be equal. Fix this by allocating an appropriate zeroed address for "any" and "default", but do not for "none", since "none" implies no address. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
* license: fix and add SPDX license identifiers and drop license commentsThomas Haller2020-04-161-7/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This also fixes a few wrong SPDX license identifiers, where the original license comment indicates GPL-2.0-only. This is not done manually, but by running the following script: --- #!/bin/bash # Tool to drop license comments, adding SPDX license identifiers, while preserving # copyright comments. The point is not to manually do this task, but perform some # hacked up string replacement. _cp() { /bin/cp "$@" } _cat() { /bin/cat "$@" } in_file() { local T=$(mktemp) _cp -f "$1" "$T" _cat "$T" rm -f "$T" } out_file() { local T=$(mktemp) _cat - > "$T" _cp -f "$T" "$1" rm -f "$T" } join() { _cat "$@" | awk '{ printf("%s#x#", $0)}' } unjoin() { _cat - | sed 's/#x#/\n/g' } files_all() { git ls-files | grep -v '\.png$' | grep -v '^include/linux-private/' } adjust() { NEWLINES='\(#x#\)\+' COPYRIGHTS='\(\( \* Copyright (c) 20..\(-20..\|, 20..\)\? [^#]\+#x#\)\+\( \*#x# \* \(Stolen[^#]*\|Based on [^#]*\)#x#\)\?\)' _cat - | \ sed '1s%^\(/\* SPDX-License-Identifier: LGPL-2.1-only \*/\|\)#x#/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU Lesser General Public#x# \*[ ]\+License as published by the Free Software Foundation version 2.1#x# \*[ ]\+of the License.#x# \*#x#'"$COPYRIGHTS"' \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: LGPL-2.1-only \*/#x#/*#x#\2 */#x##x#%' | \ sed '1s%^/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU Lesser General Public#x# \*[ ]\+License as published by the Free Software Foundation version 2.1#x# \*[ ]\+of the License.#x# \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: LGPL-2.1-only \*/#x##x#%' | \ sed '1s%^\(\)/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU Lesser General Public#x# \*[ ]\+License as published by the Free Software Foundation version 2.1#x# \*[ ]\+of the License.#x# \*#x#'"$COPYRIGHTS"' \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: LGPL-2.1-only \*/#x#/*#x#\2 */#x##x#%' | \ sed '1s%^\(/\* SPDX-License-Identifier: LGPL-2.1-only \*/\|\)#x#/\*#x# \* [^#]*#x# \*#x# \*[ ]\+This library is free software; you can redistribute it and/or#x# \*[ ]\+modify it under the terms of the GNU General Public License as#x# \*[ ]\+published by the Free Software Foundation version 2 of the License.#x# \*#x#'"$COPYRIGHTS"' \*/'"$NEWLINES"'%/\* SPDX-License-Identifier: GPL-2.0-only \*/#x#/*#x#\2 */#x##x#%' } FILES=( $(files_all) ) for f in "${FILES[@]}"; do echo "processing \"$f\"..." in_file "$f" | join | adjust | unjoin | out_file "$f" done
* lib: accept %NULL arguments for nl_addr_cmp()Thomas Haller2019-08-271-1/+9
| | | | | | | | | | | | | | | | Just be more forgiving. Also, this avoids a coverity warning: Error: FORWARD_NULL (CWE-476): [#def1] libnl-3.4.0/lib/route/addr.c:502: var_compare_op: Comparing "a->a_peer" to null implies that "a->a_peer" might be null. libnl-3.4.0/lib/route/addr.c:513: var_deref_model: Passing null pointer "a->a_peer" to "nl_addr_cmp", which dereferences it. libnl-3.4.0/lib/addr.c:587:8: deref_parm: Directly dereferencing parameter "a". # 585| int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b) # 586| { # 587|-> int d = a->a_family - b->a_family; # 588| # 589| if (d == 0) { https://bugzilla.redhat.com/show_bug.cgi?id=1606988
* Add SPDX identifiersYegor Yefremov2019-08-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Software Package Data Exchange identifiers help to detect source file licenses and hence simplify the FOSS compliance process. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> https://github.com/thom311/libnl/pull/219 --- FILES=( lib/addr.c lib/attr.c lib/cache.c lib/cache_mngr.c lib/cache_mngt.c lib/data.c lib/error.c lib/fib_lookup/lookup.c lib/fib_lookup/request.c lib/genl/ctrl.c lib/genl/family.c lib/genl/genl.c lib/genl/mngt.c lib/handlers.c lib/hash.c lib/hashtable.c lib/idiag/idiag.c lib/idiag/idiag_meminfo_obj.c lib/idiag/idiag_msg_obj.c lib/idiag/idiag_req_obj.c lib/idiag/idiag_vegasinfo_obj.c lib/mpls.c lib/msg.c lib/netfilter/ct.c lib/netfilter/ct_obj.c lib/netfilter/exp.c lib/netfilter/exp_obj.c lib/netfilter/log.c lib/netfilter/log_msg.c lib/netfilter/log_msg_obj.c lib/netfilter/log_obj.c lib/netfilter/netfilter.c lib/netfilter/nfnl.c lib/netfilter/queue.c lib/netfilter/queue_msg.c lib/netfilter/queue_msg_obj.c lib/netfilter/queue_obj.c lib/nl.c lib/object.c lib/route/act.c lib/route/addr.c lib/route/class.c lib/route/classid.c lib/route/cls.c lib/route/link.c lib/route/neigh.c lib/route/neightbl.c lib/route/netconf.c lib/route/nexthop.c lib/route/nexthop_encap.c lib/route/nh_encap_mpls.c lib/route/pktloc.c lib/route/qdisc.c lib/route/route.c lib/route/route_obj.c lib/route/route_utils.c lib/route/rtnl.c lib/route/rule.c lib/route/tc.c lib/socket.c lib/utils.c lib/version.c lib/xfrm/ae.c lib/xfrm/lifetime.c lib/xfrm/sa.c lib/xfrm/selector.c lib/xfrm/sp.c lib/xfrm/template.c src/genl-ctrl-list.c src/idiag-socket-details.c src/lib/addr.c src/lib/class.c src/lib/cls.c src/lib/ct.c src/lib/exp.c src/lib/link.c src/lib/neigh.c src/lib/qdisc.c src/lib/route.c src/lib/rule.c src/lib/tc.c src/lib/utils.c src/nf-ct-add.c src/nf-ct-events.c src/nf-ct-list.c src/nf-exp-add.c src/nf-exp-delete.c src/nf-exp-list.c src/nf-log.c src/nf-monitor.c src/nf-queue.c src/nl-addr-add.c src/nl-addr-delete.c src/nl-addr-list.c src/nl-class-add.c src/nl-class-delete.c src/nl-class-list.c src/nl-classid-lookup.c src/nl-cls-add.c src/nl-cls-delete.c src/nl-cls-list.c src/nl-fib-lookup.c src/nl-link-enslave.c src/nl-link-ifindex2name.c src/nl-link-list.c src/nl-link-name2ifindex.c src/nl-link-release.c src/nl-link-set.c src/nl-link-stats.c src/nl-list-caches.c src/nl-list-sockets.c src/nl-monitor.c src/nl-neigh-add.c src/nl-neigh-delete.c src/nl-neigh-list.c src/nl-neightbl-list.c src/nl-pktloc-lookup.c src/nl-qdisc-add.c src/nl-qdisc-delete.c src/nl-qdisc-list.c src/nl-route-add.c src/nl-route-delete.c src/nl-route-get.c src/nl-route-list.c src/nl-rule-list.c src/nl-tctree-list.c src/nl-util-addr.c ) sed '1s#^#/* SPDX-License-Identifier: LGPL-2.1-only */\n#' "${FILES[@]}" -i
* addr: Add support for AF_MPLSDavid Ahern2017-08-181-11/+45
| | | | | | MPLS 'addresses' are 4-byte labels with a prefix length of 20. Signed-off-by: David Ahern <dsahern@gmail.com>
* addr: add AF_VSOCK to translation tableTobias Klauser2017-05-121-0/+3
| | | | | | | | | Add AF_VSOCK to the address family translation table. https://github.com/thom311/libnl/pull/142 Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
* nl-addr: avoid read-out-of-bound in nl_addr_fill_sockaddr()Thomas Haller2016-08-141-2/+14
| | | | | | https://github.com/thom311/libnl/issues/103 Signed-off-by: Thomas Haller <thaller@redhat.com>
* lib: add const-ness to appropriate parameters in addr, attr, dataRohan Joyce2015-02-161-20/+20
| | | | | | | | | | | | | | | This patch changes the signatures of some functions to allow const pointers in places where a const qualified pointer is enough access for what the function does (e.g. nla_get_u8). It also changes some functions that take a pointer parameter and return a pointer derived from it to use the strchr idiom. This is not exhaustive in terms of places where const can be added, but it's a decent chunk that should not make the external api any more restrictive. http://lists.infradead.org/pipermail/libnl/2015-February/001826.html Signed-off-by: Rohan Joyce <rojoyce.github@gmail.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
* style: require comma after __ADD() macroThomas Haller2014-07-271-38/+38
| | | | | | | $ sed -i 's/^\([\t ]\+\<__ADD\> \?([^)]\+)\) *$/\1,/' `git grep -w -l __ADD` Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
* do not compile some address families when not availableCong Wang2013-11-091-0/+14
| | | | | | | | | | | | | | | | This fixes the following error while compiling libnl3 on CentOS5: addr.c:1027: error: 'AF_RDS' undeclared here (not in a function) addr.c:1033: error: 'AF_CAN' undeclared here (not in a function) addr.c:1034: error: 'AF_TIPC' undeclared here (not in a function) addr.c:1036: error: 'AF_IUCV' undeclared here (not in a function) addr.c:1037: error: 'AF_RXRPC' undeclared here (not in a function) addr.c:1038: error: 'AF_ISDN' undeclared here (not in a function) addr.c:1039: error: 'AF_PHONET' undeclared here (not in a function) make[2]: *** [addr.lo] Error 1 Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* addr: only translate more recent address family names and ARP types if definedThomas Graf2013-04-051-0/+8
| | | | | | Helps making libnl compilable with older kernel headers Signed-off-by: Thomas Graf <tgraf@suug.ch>
* addr: Update to latest address familiy definition for translationThomas Graf2013-03-141-2/+11
| | | | Signed-off-by: Thomas Graf <tgraf@suug.ch>
* addr: improve API reference documentation for nl_addr_*()Thomas Graf2013-03-141-40/+164
| | | | Signed-off-by: Thomas Graf <tgraf@suug.ch>
* addr: Reset unused portion of binary address in nl_addr_set_binary_addr()Thomas Graf2013-03-141-1/+4
| | | | | | | memset() the binary address before overwriting it with new data to avoid leaving around old portions of the address. Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Fix mask calculation in nl_addr_cmp_prefix()Thomas Graf2013-01-311-2/+2
| | | | | Signed-off-by: Malte Langermann <mlangermann@radiodata.biz> Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Move private header files to <netlink-private/*>Thomas Graf2013-01-241-1/+1
| | | | | | | This clarifies the seperation between public and private header files. Signed-off-by: Thomas Graf <tgraf@suug.ch>
* Address comparison bug fixedКоренберг Марк2012-08-301-1/+2
| | | | Bug introduced in 794ac78c5618ee81a45e4f58694ee27b3403ebd7
* nl_addr_parse handling of 'default', 'any', and 'all'Justin Mayfield2012-08-291-4/+3
| | | | | | | | | | | | 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.
* Fix types-related warnings based on clang diagnosticsКоренберг Марк2012-06-131-3/+3
| | | | | | | | | | | | | | | | | 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.
* doc: documentation restructuringThomas Graf2012-05-101-14/+16
| | | | | | | | | | - changes the modules hierarchy to better represent the set of libaries - list the header file that needs to be included - remove examples/doc from api ref that is included in the guide - add references to the guide - fix doxygen api linking for version 1.8.0 - readd doxygen mainpage to config file - fix a couple of doxygen doc bugs
* nl_addr_cmp(): handle prefix length during address comparisonBrett Ciphery2012-01-121-1/+4
| | | | Signed-off-by: Brett Ciphery <brett.ciphery@windriver.com>
* addr: hide nl_addr_destroy()Thomas Graf2010-11-261-25/+14
| | | | everyone should use nl_addr_put()
* constify struct trans_tblThomas Graf2010-11-171-1/+1
|
* Make nl_str2af return a negative value if parsing failsThomas Graf2010-11-111-1/+1
|
* restructure module documentation orderThomas Graf2008-12-101-1/+1
| | | | split hiearchy into one top level module per library
* Properly handle addr=NULL in nl_addr2strThomas Graf2008-06-131-2/+5
|
* Fix error code of nl_addr_resolve()Thomas Graf2008-05-221-2/+6
|
* Remove obsolete nla_get_addr() and nla_get_data()Thomas Graf2008-05-141-1/+1
| | | | | | | | Replaces obsolete calls to nla_get_addr() and nla_get_data() with nl_addr_alloc_attr() respectively nl_data_alloc_attr(). Also fixes missing error handling while parsing routing multipath configuration.
* Thread-safe error handlingThomas Graf2008-05-141-32/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order for the interface to become more thread safe, the error handling was revised to no longer depend on a static errno and error string buffer. This patch converts all error paths to return a libnl specific error code which can be translated to a error message using nl_geterror(int error). The functions nl_error() and nl_get_errno() are therefore obsolete. This change required various sets of function prototypes to be changed in order to return an error code, the most prominent are: struct nl_cache *foo_alloc_cache(...); changed to: int foo_alloc_cache(..., struct nl_cache **); struct nl_msg *foo_build_request(...); changed to: int foo_build_request(..., struct nl_msg **); struct foo *foo_parse(...); changed to: int foo_parse(..., struct foo **); This pretty much only leaves trivial allocation functions to still return a pointer object which can still return NULL to signal out of memory. This change is a serious API and ABI breaker, sorry!
* Abstract address allocation based on netlink attributeThomas Graf2008-01-301-0/+15
|
* Support link operstate and linkmodeThomas Graf2007-12-191-0/+15
|
* Initial importThomas Graf2007-09-141-0/+883