Commit Graph

557 Commits

Author SHA1 Message Date
jiachanglin e84626de81 Description: Generate c files and header files in libnl
Feature or Bugfix: Feature
Binary Source: No

Signed-off-by: jiachanglin <jiachanglin@huawei.com>
2022-02-28 04:49:19 +00:00
Thomas Haller 7b167ef85f libnl-3.5.0 release 2019-09-01 16:19:02 +02:00
Thomas Haller 03ee05d975 route/qdisc: adjust API for 64 bit rate/ceil support for htb class
- existing API/ABI must stay unchanged. We cannot change parameter
  types. Ad most we can add new variants that support 64 bit integers.

- rtnl_tc_calc_txtime64() and rtnl_tc_calc_bufsize64() are trivial.
  We should not blow up the public API of libnl for such a thing.
  If the users needs it, they can just reimplement it.

- getters should return an error code. Especially if the return type
  does not support encoding an error there.

- don't add separate rs_rate64/rs_ceil64 field. Instead, extend the
  "rs_rate" field of "struct rtnl_ratespec" to 64 bits. It's internal
  API.
2019-09-01 15:54:33 +02:00
d0u9 4cf69a1b7b Add 64bit rate/ceil support for htb class
Htb class has already supported 64bit rate and ceil settings for times.
Now, in this patch, we grant this ability to libnl library.
2019-09-01 14:44:42 +02:00
Thomas Haller ff61de28d7 xfrmi: return error code from getters for XFRM links
Returning the value directly as uint32_t does not leave room for an error
code. E.g. we want to indicate to the caller whether the attribute is present
or not (-NLE_NOATTR). Currenlty, the code is quite unforgiving and will just
crash/assert against invalid arguments. In theory, we could also be more forgiving
and return a error code if the link argument is invalid.
2019-09-01 14:38:59 +02:00
Eyal Birger d147019c4b xfrmi: introduce XFRM interfaces support
XFRM interfaces were introduced in kernel 4.19.
This commit adds link support for these interfaces.

Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
2019-09-01 14:24:52 +02:00
Michael Forney 73c1d04796 Sync linux headers to 4.19.66
This fixes the build with musl libc.

Additionally, several changes were made to account for changes to the
headers:

- ip_mp_alg.h was removed, since it was removed in linux commit e06e7c61
  (v2.6.23), and the last use of those constants was removed in libnl
  commit 535e8316.
- Uses of TCF_META_ID_SK_ROUTE_CAPS were updated to
  __TCF_META_ID_SK_ROUTE_CAPS, since it was renamed in linux commit
  e20e6940 (v3.1).
- Uses of IF_CARRIER_DOWN and IF_CARRIER_UP were replaced with their
  values, 0 and 1, since they are not in linux/if.h (they appear to be
  libnl-specific, added in libnl commit 3540e44b).

https://github.com/thom311/libnl/pull/222
2019-08-26 15:27:32 +02:00
Michael Forney 24e5b315a5 all: Use __typeof__ instead of typeof
This allows libnl to be built with -std=c99, which prevents the compiler
from using non-reserved identifiers for extensions.
2019-08-16 07:42:03 +02:00
Michael Forney 1a88619b72 dbg: Use __func__ instead of __PRETTY_FUNCTION__
These behave the same, except when used at top-level. This can't happen
since the macro body is a statement.

__func__ is standardized since C99, while __PRETTY_FUNCTION__ is a
GNU extension.
2019-08-16 07:42:03 +02:00
Thomas Haller 6c574429d9 utils: add internal helper macros for cleanup
Yes, these use gcc-isms like typeof(), __attribute__((__unused__)),
__attribute__((__cleanup__(fcn))) and expression statements.

First of all, this is now only required when building libnl3 itself.
The public headers still should to be conservative and only use C89
features.

Also, clang supports these too, so you can at least build libnl3 with
gcc and clang. Since libnl3 uses internally linux headers, and the linux
kernel also can only be compiled with gcc (and maybe clang), it seems
clear that on the target platform a suitable compiler is available.

If there is a reasonable request of a real-world compiler that is not
able to compile this, we can revisit some choices. But not having
__attribute__((__cleanup__(fcn))) is like programming C from a decade
ago. Especially during parsing (which libnl3 does obviously a lot), this
allows to return-early while cleanup up memory. While this sounds simple
to get right manually, in practice the resulting code is either
unnecessary complex or simply buggy.

To make implementing libnl3 more convenient, these helpers are
introduced.
2019-08-09 16:48:55 +02:00
xinbao fbf831fe47 Add CTA_LABELS and CTA_LABELS_MASK to ctattr_type according to the new kernel
https://github.com/thom311/libnl/pull/218
2019-08-07 15:39:35 +02:00
Tobias Jungel c503f924a0 route/link: expose IFLA_INFO_SLAVE_KIND
add rtnl_link_{get,set}_slave_type functions to expose the
IFLA_INFO_SLAVE_KIND attribute.
2018-10-22 15:20:19 +02:00
Thomas Haller 46440e7fe7 route/act: return error code from act-vlan getters
Our API is unfortunately not consistent about this.
However, in general, getters should aim to return an
error code whether the attribute could be retrieved.
2018-10-10 11:37:41 +02:00
Thomas Haller a358cf2cd1 route/act: style fixes in "lib/route/act/vlan.c" 2018-10-10 11:30:06 +02:00
Volodymyr Bendiuga b004e40063 route:act: add vlan action
For more information please see:
http://man7.org/linux/man-pages/man8/tc-vlan.8.html

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-10-10 11:12:08 +02:00
Volodymyr Bendiuga 07fa87ba90 include: import tc_vlan.h
Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-10-10 11:12:08 +02:00
Thomas Haller a90256de2f route/tc: return error code from rtnl_tc_get_chain()
Our API is unfortunately not consistent about this.
However, in general, getters should aim to return an
error code whether the attribute could be retrieved.
2018-10-10 11:02:46 +02:00
Volodymyr Bendiuga c9b28170e7 route:tc: allow to set chain index for tc objects
This is useful when one wants to chain filters.

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-10-10 11:00:21 +02:00
Thomas Haller b7419a1bce lib/qdisc: avoid BUG() in "lib/route/qdisc/mqprio.c"
BUG() raises an assertion. It seems overly harsh.

For example, rtnl_tc_data() can fail if we fail to allocate
memory. Asserting against that, makes libnl3 not out-of-memory
safe.

Just return a regular error.
2018-10-09 15:31:39 +02:00
Thomas Haller 8a6c8e548d lib/qdisc: style fixes in "lib/route/qdisc/mqprio.c" 2018-10-09 10:57:58 +02:00
Volodymyr Bendiuga 25cf1d39ed route:qdisc: add MQPRIO Qdisc
More about Qdisc mqprio can be found at:
http://man7.org/linux/man-pages/man8/tc-mqprio.8.html

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-07-26 11:17:37 +02:00
Volodymyr Bendiuga 0fc332dc9c include: import linux header pkt_sched.h
Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-07-24 11:49:09 +02:00
Thomas Haller 2eb0eebc41 include/linux: update copy of kernel headers
Taken from upstream kernel commit 29dcea88779c856c7dc92040a0c01233263101d4
(v4.17).
2018-06-25 15:13:19 +02:00
Thomas Winter bb504393c4 if_tunnel: Update IFLA defines up to FWMARK
This is a new option that was added in Linux v4.12.

Signed-off-by: Thomas Winter <Thomas.Winter@alliedtelesis.co.nz>
2018-06-25 15:10:42 +02:00
Tobias Jungel a153517c5c neigh: update neighbour.h and add missing flags
NTF_EXT_LEARNED, NTF_OFFLOADED and NTF_MASTER are added to neigh_flags.

https://github.com/thom311/libnl/pull/186
2018-06-25 14:50:03 +02:00
d0u9 ddfc36f46e Add support for cloning cgroup filter object.
In this commit, we implement ematch_tree_clone(), which is basis of
cgroup_clone() interface. The whole ematch tree is deep-copied except
the e_ops filed.

Also, a new unit test is added for testing the interface, which named as
check-ematch-tree-clone.c located in tests directory.

https://github.com/thom311/libnl/pull/176
2018-06-25 14:39:41 +02:00
Tobias Jungel 2e87f72bf4 neigh: add get/set functions for NEIGH_ATTR_MASTER
Beeing able to set NEIGH_ATTR_MASTER hash based lookups are possible for
AF_BRIDGE neighbours.

https://github.com/thom311/libnl/pull/189
2018-06-25 14:27:50 +02:00
d0u9 17f0459c8d route/class: add new api rtnl_class_get_by_parent()
This function searches a class cache previously allocated with
rtnl_class_alloc_cache() and searches for a class matching the interface
index and parent qdisc.

https://github.com/thom311/libnl/pull/185
2018-04-11 13:05:09 +02:00
Volodymyr Bendiuga 5893c3f18e route:cls: add matchall classifier
This simple classifier allows any traffic pass through.
Useful as an example for port mirroring.

Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-04-11 12:22:16 +02:00
Volodymyr Bendiuga 50918a9a50 include: copy entire pkt_cls.h from linux
Signed-off-by: Volodymyr Bendiuga <volodymyr.bendiuga@westermo.se>
2018-04-11 12:22:16 +02:00
David Ahern 961c4f6750 rule: Add support for protocol and port ranges
Add support for recent fib rule features - specifying a protocol
that installed a rule and an IP protocol plus port range for rules.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2018-04-06 14:54:12 +02:00
David Ahern fc4880fa5b Update fib_rules.h to latest kernel
Update fib_rules.h to kernel as of bfff4862653b
("net: fib_rules: support for match on ip_proto, sport and dport")

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
2018-04-06 14:54:12 +02:00
Thomas Haller cb8e34859b lib/rtnl: rename public define RTNL_GENEVE_ID_MAX
Public defines must have a libnl3 related prefix. Rename
GENEVE_ID_MAX to RTNL_GENEVE_ID_MAX.
2018-02-12 15:23:02 +01:00
Wang Jian 6b4fc607ba link: add Geneve support.
Signed-off-by: Wang Jian <jianjian.wang1@gmail.com>
2018-02-12 14:36:15 +01:00
d0u9 5205783203 Fix for cgroup filter addition problem.
Currently, due to the incomplete netlink datagram sent by libnl, cgroup
filter addition is not fully functional. The datagram generated by `tc`
command includes an empty attribute section, which is stripped off
in the libnl counterpart.

In this commit, a new `interface nla_nest_end_keep_empty()` is added.
This function closes attribute without stripping off empty attribute.
2018-01-24 00:02:55 +08:00
Thomas Haller 7eeb29bc53 route: rename rtnl_cls_cache_set_tcm_params() and fix symbol versioning
After rethinking, "tcm_params" doesn't seem like a good name. Change it to
"tc_params".

Also, an already released section in the linker file must never be
modified. It defeats the purpose of symbol versioning. Move the symbol
to the right section.
2018-01-18 07:54:27 +01:00
d0u9 ca02edd101 Add new function for setting ifindex and parent of a classifier cache.
It is not good to give classifier cache users only one chance to
set interface index and parent handle when allocte new cache.
Sometimes we want to reuse classifier cache to reduce the overhead
of allocating new memory everytime a new cache is created.
2018-01-18 07:51:23 +01:00
Thomas Haller 11580c5564 route: mark data argument for rtnl_netem_set_delay_distribution_data() as const 2018-01-16 07:14:47 +01:00
Steffen Vogel b590366ffb route: add separate function to set netem qdisc delay distribution
A new function rtnl_netem_set_delay_distribution_data() has been added
to allow the user to pass the delay distribution directly without loading
it from a file.

In conjunction with the maketable code (see iproute2 / NISTnet) this can
be used to generate and load custom delay distributions on the fly.
2017-12-20 11:09:08 +01:00
Jef Oliver 3c427d0f4f Change rtnl_link_af_ops.ao_override_rtm behavior
rtnl_link_af_ops.ao_override_rtm allows for a link module to
override the change request type being sent to the kernel. More
specifically, the default change request type is RTM_NEWLINK.
Some link change requests require the reqeust type to be set to
RTM_SETLINK. This is the case for IFLA_PROTINFO specific
attributes for a link that is slave to a bridge.

Currently, ao_override_rtm is static to the address family type.
So, all changes submitted to AF_BRIDGE override the link change
request type. The override only needs to happen if IFLA_PROTINFO
attributes are appended to the link change request.

This patch changes ao_override_rtm from a const integer to a
function pointer that allows for a link module to determine if
the override needs to actually happen.

Currently, only the bridge module uses this functionality. If
bridge flags are applied to a link (bdpu blocking, learning,
fast leave, etc...), these flags are nested in IFLA_PROTINFO. If
the flags are present, the link change request type will be
overridden as RTM_SETLINK.

This fixes the ability to set a bridge link up or down by using
the correct RTM_NEWLINK link change request type.

$ sudo src/nl-link-set -n br2 --state=down
Changed bridge br2 ether a6:e6:94:8c:61:ec
    <broadcast,multicast,up,running,lowerup> group 0

$ ip link show
br2: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue
    state DOWN mode DEFAULT group default qlen 1000

$ sudo src/nl-link-set -n br2 --state=up
Changed bridge br2 ether a6:e6:94:8c:61:ec
    <broadcast,multicast> group 0

$ ip link show
br2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
    state UNKNOWN mode DEFAULT group default qlen 1000

Signed-off-by: Jef Oliver <jef.oliver@intel.com>

Fixes: 55bc931a72

http://lists.infradead.org/pipermail/libnl/2017-November/002382.html
http://lists.infradead.org/pipermail/libnl/2017-November/002385.html
2017-11-29 17:10:09 +01:00
Thomas Haller be550df109 route/vlan: add capability to indicate heap overflow fix in rtnl_link_vlan_set_egress_map()
Without this fix/capablity, adding more then 4 mappings in
rtnl_link_vlan_set_egress_map() overflows the heap.
2017-10-23 12:10:30 +02:00
Thomas Haller b4802a17a7 nl: add "const" specifier for nla_policy argument of parse functions
Adding const to a function argument is generally not an API break
(at least, if the argument is a struct, like in this case).

Usually we declare the policy as static variables. The user should
be able to mark them as "const", so that the linker makes the policy
array read-only. Adjust the API to allow for that.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2017-10-09 13:51:29 +02:00
Thomas Haller 3fe3454b02 libnl-3.4.0 release
Signed-off-by: Thomas Haller <thaller@redhat.com>
2017-10-09 13:14:55 +02:00
Tobias Klauser 4e957ea615 cli: include sys/select.h for select(2)
Some of the cli tools use select(2) and its man page states:

  /* According to POSIX.1-2001, POSIX.1-2008 */
  #include <sys/select.h>

Do so and explicitly #include <sys/select.h> in <netlink/cli/utils.h>
instead of relying of getting select(2) via implicit includes. This is
also needed to make libnl compile for Android.

Based on a previous patch by Fredrik Fornwall.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

https://github.com/thom311/libnl/pull/151
2017-09-07 21:37:41 +02:00
David Ahern 760d74f99c route: Add support for MPLS encap
Add support for MPLS lwtunnel encapsulation.

Signed-off-by: David Ahern <dsahern@gmail.com>
2017-08-18 15:01:04 +02:00
David Ahern 0164d57aee route: Add support for lwtunnel encapsulations
Add framework to support lwtunnel encapsulations per nexthop.

Encapsulations types are expected to fill in the nh_encap_ops for
building and parsing messages, compare encapsulations in routes,
dumping the encapsulations and freeing memory.

Signed-off-by: David Ahern <dsahern@gmail.com>
2017-08-18 15:01:04 +02:00
David Ahern 000a792c7b Import lwtunnel encap files from kernel
Import lwtunnel and mpls_iptunnel.h from net-next tree as of commit
b217566a525ff24334d17635a865f44b68c2c583

Signed-off-by: David Ahern <dsahern@gmail.com>
2017-08-18 15:01:04 +02:00
David Ahern 63d02c3c58 route: Add support for ttl propagation in MPLS routes
Add support for RTA_TTL_PROPAGATE attribute on a per-route basis.
Used to enable/disable TTL propagation at LSP egress.

Signed-off-by: David Ahern <dsahern@gmail.com>
2017-08-18 15:01:04 +02:00
David Ahern 0a6d27ce90 route: Add support for MPLS address family
Add support for route in MPLS family. New attributes:
- RTA_NEWDST - label stack for a nexthop
- RTA_VIA - nexthop address (e.g., IPv4 or IPv6)

Other changes required:
- scope has to be universe for MPLS routes so fixup rtnl_route_guess_scope
- priority attribute can not be set for MPLS. Change rtnl_route_parse to
  not set the attribute by default for AF_MPLS.
- table attribute should not be set unless something other than the default
  table. For MPLS this attribute can not be set.

'/' is the separator in label stacks for consistency with iproute2.

Signed-off-by: David Ahern <dsahern@gmail.com>
2017-08-18 15:01:04 +02:00
David Ahern 665fccadca addr: Add implementations for mpls_ntop and mpls_pton
Implementations of mpls_ntop and mpls_pton taken from iproute2.

Signed-off-by: David Ahern <dsahern@gmail.com>
2017-08-18 15:01:04 +02:00