summaryrefslogtreecommitdiffstats
path: root/include/libnetlink.h
Commit message (Collapse)AuthorAgeFilesLines
* libnetlink: parse_rtattr_nested should allow NLA_F_NESTED flagPetr Machata2020-01-181-1/+2
| | | | | | | | | | | | | | In kernel commit 8cb081746c03 ("netlink: make validation more configurable for future strictness"), Linux started implicitly flagging nests with NLA_F_NESTED, unless the nest is created with nla_nest_start_noflag(). The ETS code uses nla_nest_start() where possible, so it does not work with the current iproute2 code. Have libnetlink catch up by admitting the flag in the attribute. Signed-off-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* ipnetns: enable to dump nsid conversion tableNicolas Dichtel2019-10-141-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch enables to dump/get nsid from a netns into another netns. Example: $ ./test.sh + ip netns add foo + ip netns add bar + touch /var/run/netns/init_net + mount --bind /proc/1/ns/net /var/run/netns/init_net + ip netns set init_net 11 + ip netns set foo 12 + ip netns set bar 13 + ip netns init_net (id: 11) bar (id: 13) foo (id: 12) + ip -n foo netns set init_net 21 + ip -n foo netns set foo 22 + ip -n foo netns set bar 23 + ip -n foo netns init_net (id: 21) bar (id: 23) foo (id: 22) + ip -n bar netns set init_net 31 + ip -n bar netns set foo 32 + ip -n bar netns set bar 33 + ip -n bar netns init_net (id: 31) bar (id: 33) foo (id: 32) + ip netns list-id target-nsid 12 nsid 21 current-nsid 11 (iproute2 netns name: init_net) nsid 22 current-nsid 12 (iproute2 netns name: foo) nsid 23 current-nsid 13 (iproute2 netns name: bar) + ip -n foo netns list-id target-nsid 21 nsid 11 current-nsid 21 (iproute2 netns name: init_net) nsid 12 current-nsid 22 (iproute2 netns name: foo) nsid 13 current-nsid 23 (iproute2 netns name: bar) + ip -n bar netns list-id target-nsid 33 nsid 32 nsid 32 current-nsid 32 (iproute2 netns name: foo) + ip -n bar netns list-id target-nsid 31 nsid 32 nsid 12 current-nsid 32 (iproute2 netns name: foo) + ip netns list-id nsid 13 nsid 13 (iproute2 netns name: bar) CC: Petr Oros <poros@redhat.com> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Tested-by: Petr Oros <poros@redhat.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* Merge branch 'master' into nextDavid Ahern2019-06-211-0/+1
|\ | | | | | | | | | | | | Conflicts: include/uapi/linux/snmp.h Signed-off-by: David Ahern <dsahern@gmail.com>
| * devlink: mnlg: Catch returned error value of dumpit commandsMoshe Shemesh2019-06-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Devlink commands which implements the dumpit callback may return error. The netlink function netlink_dump() sends the errno value as the payload of the message, while answering user space with NLMSG_DONE. To enable receiving errno value for dumpit commands we have to check for it in the message. If it is a negative value then the dump returned an error so we should set errno accordingly and check for ext_ack in case it was set. Fixes: 049c58539f5d ("devlink: mnlg: Add support for extended ack") Signed-off-by: Moshe Shemesh <moshe@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* | libnetlink: Add helper to create nexthop dump requestDavid Ahern2019-06-111-0/+4
| | | | | | | | | | | | Add rtnl_nexthopdump_req to initiate a dump request of nexthop objects. Signed-off-by: David Ahern <dsahern@gmail.com>
* | libnetlink: Add helper to add a group via setsockoptDavid Ahern2019-06-111-1/+2
|/ | | | | | | | groups > 31 have to be joined using the setsockopt. Since the nexthop group is 32, add a helper to allow 'ip monitor' to listen for nexthop messages. Signed-off-by: David Ahern <dsahern@gmail.com>
* bridge: fdb: Fix FDB dump with strict checking disabledIdo Schimmel2019-02-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | While iproute2 correctly uses ifinfomsg struct as the ancillary header when requesting an FDB dump on old kernels, it sets the message type to RTM_GETLINK. This results in wrong reply being returned. Fix this by using RTM_GETNEIGH instead. Before: $ bridge fdb show brport dummy0 Not RTM_NEWNEIGH: 00000158 00000010 00000002 After: $ bridge fdb show brport dummy0 2a:0b:41:1c:92:d3 vlan 1 master br0 permanent 2a:0b:41:1c:92:d3 master br0 permanent 33:33:00:00:00:01 self permanent 01:00:5e:00:00:01 self permanent Fixes: 05880354c2cf ("bridge: fdb: Fix filtering with strict checking disabled") Signed-off-by: Ido Schimmel <idosch@mellanox.com> Reported-by: LiLiang <liali@redhat.com> Acked-by: David Ahern <dsahern@gmail.com> Acked-by: Ivan Vecera <ivecera@redhat.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* libnetlink: Add RTNL_HANDLE_F_STRICT_CHK flagDavid Ahern2019-01-041-0/+1
| | | | | | | | | | | Add RTNL_HANDLE_F_STRICT_CHK flag and set in rth flags to let know commands know if the kernel supports strict checking. Extracted from patch from Ido to fix filtering with strict checking enabled. Cc: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Add filter function to rtnl_neighdump_reqDavid Ahern2019-01-041-1/+2
| | | | | | | Add filter function to rtnl_neighdump_req and a buffer to the request for the filter functions to append attributes. Signed-off-by: David Ahern <dsahern@gmail.com>
* ip bridge: Set NETLINK_GET_STRICT_CHK on socketDavid Ahern2018-12-271-0/+1
| | | | | | | | | | | iproute2 has been updated for the new strict policy in the kernel. Add a helper to call setsockopt to enable the feature. Add a call to ip.c and bridge.c The setsockopt fails on older kernels and the error can be safely ignored - any new fields or attributes are ignored by the older kernel. Signed-off-by: David Ahern <dsahern@gmail.com>
* ip address: Set device index in dump requestDavid Ahern2018-12-271-1/+2
| | | | | | | | | Add a filter function to rtnl_addrdump_req to set device index in the address dump request if the user is filtering addresses by device. In addition, add a new ipaddr_link_get to do a single RTM_GETLINK request instead of a device dump yet still store the data in the linfo list. Signed-off-by: David Ahern <dsahern@gmail.com>
* ip route: Remove rtnl_rtcache_requestDavid Ahern2018-12-271-3/+4
| | | | | | | Add a filter option to rtnl_routedump_req and use it to set rtm_flags removing the need for rtnl_rtcache_request for dump requests. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlnk: unused and local functions cleanupStephen Hemminger2018-11-191-7/+0
| | | | | | | rntl_talk_extack and parse_rtattr_index not used in current code. rtnl_dump_filter_l is only used in this file. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* Tree wide: Drop sockaddr_nl argDavid Ahern2018-10-221-4/+2
| | | | | | | | No function, filter, or print function uses the sockaddr_nl arg, so just drop it. Signed-off-by: David Ahern <dsahern@gmail.com> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
* libnetlink: Add helper for getting a __s32 from netlink msgsJesus Sanchez-Palencia2018-10-071-0/+4
| | | | | | | | This function retrieves a signed 32-bit integer from a netlink message and returns it. Signed-off-by: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* include: Add helper to retrieve a __s64 from a netlink msgVinicius Costa Gomes2018-10-071-0/+7
| | | | | | | | This allows signed 64-bit integers to be retrieved from a netlink message. Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Rename rtnl_wilddump_stats_req_filter to rtnl_statsdump_req_filterDavid Ahern2018-10-021-2/+1
| | | | | | | | rtnl_wilddump_stats_req_filter only takes RTM_GETSTATS as the type argument so rename to rtnl_statsdump_req_filter for consistency with other request functions and hardcode the type argument. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Rename rtnl_wilddump_* to rtnl_linkdump_*David Ahern2018-10-021-4/+3
| | | | | | | | | | | Rename rtnl_wilddump_req_filter to rtnl_linkdump_req_filter, rtnl_wilddump_request to rtnl_linkdump_req and rtnl_wilddump_req_filter_fn to rtnl_linkdump_req_filter_fn. In all cases drop the type argument which at this point is only RTM_GETLINK and hardcode in the functions. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETNSID dumps to use rtnl_nsiddump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | Add rtnl_nsiddump_req for namespace id dumps using the proper rtgenmsg as the header. Convert existing RTM_GETNSID dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETNEIGHTBL dumps to use rtnl_neightbldump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | Add rtnl_neightbldump_req for neighbor table dumps using the proper ndtmsg as the header. Convert existing RTM_GETNEIGHTBL dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETNEIGH dumps to use rtnl_neighdump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | | Add rtnl_neighdump_req for neighbor dumps using the proper ndmsg as the header. Convert existing rtnl_wilddump_request for RTM_GETNEIGH to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETRULE dumps to use rtnl_ruledump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | Add rtnl_ruledump_req for fib fule dumps using the proper fib_rule_hdr as the header. Convert existing RTM_GETRULE dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETNETCONF dumps to use rtnl_netconfdump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | Add rtnl_netconfdump_req for netconf dumps using the proper netconfmsg as the header. Convert existing RTM_GETNETCONF dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETMDB dumps to use rtnl_mdbdump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | Add rtnl_mdbdump_req for mdb dumps using the proper br_port_msg as the header. Convert existing RTM_GETMDB dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETADDRLABEL dumps to use rtnl_addrlbldump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | | Add rtnl_addrlbldump_req for address label dumps using the proper ifaddrlblmsg as the header. Convert existing RTM_GETADDRALBEL dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETROUTE dumps to use rtnl_routedump_reqDavid Ahern2018-10-021-0/+2
| | | | | | | Add rtnl_routedump_req for route dumps using the proper rtmsg as the header. Convert existing RTM_GETROUTE dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* libnetlink: Convert GETADDR dumps to use rtnl_addrdump_reqDavid Ahern2018-10-021-0/+4
| | | | | | | Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg as the header. Convert existing RTM_GETADDR dumps to use it. Signed-off-by: David Ahern <dsahern@gmail.com>
* devlink: mnlg: Add support for extended ackArkadi Sharshevsky2018-02-231-0/+1
| | | | | | | | Add support for extended ack. Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* lib/libnetlink: Add a new function rtnl_talk_iovChris Mi2018-01-141-0/+3
| | | | | | | | | rtnl_talk can only send a single message to kernel. Add a new function rtnl_talk_iov that can send multiple messages to kernel. rtnl_talk_iov takes struct iovec * and iovlen as arguments. Signed-off-by: Chris Mi <chrism@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
* SPDX license identifiersStephen Hemminger2017-11-241-0/+1
| | | | | | | For all files in iproute2 which do not have an obvious license identification, mark them with SPDK GPL-2 Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* lib/libnetlink: update rtnl_talk to support malloc buff at run timeHangbin Liu2017-10-261-3/+3
| | | | | | | | | | | | | | | | | | This is an update for 460c03f3f3cc ("iplink: double the buffer size also in iplink_get()"). After update, we will not need to double the buffer size every time when VFs number increased. With call like rtnl_talk(&rth, &req.n, NULL, 0), we can simply remove the length parameter. With call like rtnl_talk(&rth, nlh, nlh, sizeof(req), I add a new variable answer to avoid overwrite data in nlh, because it may has more info after nlh. also this will avoid nlh buffer not enough issue. We need to free answer after using. Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Phil Sutter <phil@nwl.cc>
* iproute: Add support for extended ack to rtnl_talkStephen Hemminger2017-08-041-0/+6
| | | | | | | | | | | | | Add support for extended ack error reporting via libmnl. Add a new function rtnl_talk_extack that takes a callback as an input arg. If a netlink response contains extack attributes, the callback is is invoked with the the err string, offset in the message and a pointer to the message returned by the kernel. If iproute2 is built without libmnl, it will still work but extended error reports from kernel will not be available. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
* ip address: Export ip_linkaddr_listDavid Ahern2017-05-301-0/+10
| | | | | | | | | | | | | | | | | | | ipaddr_list_flush_or_save generates a list of nlmsg's for links and optionally for addresses. Move the code into ip_linkaddr_list and export it along with the supporting infrastructure. API to use this function is: struct nlmsg_chain linfo = { NULL, NULL}; struct nlmsg_chain ainfo = { NULL, NULL}; ip_linkaddr_list(family, filter_req, &linfo, &ainfo); ... error checking and code looping over linfo/ainfo ... free_nlmsg_chain(&linfo); free_nlmsg_chain(&ainfo); Signed-off-by: David Ahern <dsahern@gmail.com>
* netlink: Add flag to suppress print of nlmsg errorDavid Ahern2017-04-141-0/+1
| | | | | | | | | | | | | Allow callers of the dump API to handle nlmsg errors (e.g., an unsupported feature). Setting RTNL_HANDLE_F_SUPPRESS_NLERR in the rtnl_handle avoids unnecessary messages to the users in some case. For example, RTNETLINK answers: Operation not supported when probing for support of a new feature. Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
* libnetlink: Add variant of rtnl_talk that does not display RTNETLINK answers ↵David Ahern2016-12-131-0/+3
| | | | | | | | | | | | | | error iplink_vrf has 2 functions used to validate a user given device name is a VRF device and to return the table id. If the user string is not a device name ip commands with a vrf keyword show a confusing error message: "RTNETLINK answers: No such device". Add a variant of rtnl_talk that does not display the "RTNETLINK answers" message and update iplink_vrf to use it. Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
* libnetlink: Introduce rta_getattr_be*()Amir Vadai2016-12-021-0/+9
| | | | | | | Add the utility functions rta_getattr_be16() and rta_getattr_be32(), and change existing code to use it. Signed-off-by: Amir Vadai <amir@vadai.me>
* bridge: vlan: add support to display per-vlan statisticsNikolay Aleksandrov2016-08-291-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds support for the stats argument to the bridge vlan command which will display the per-vlan statistics and the device each vlan belongs to with its flags. The supported command filtering options are dev and vid. Also the man page is updated to explain the new option. The patch uses the new RTM_GETSTATS interface with a filter_mask to dump all bridges and ports vlans. Later we can add support for using the per-device dump and filter it in the kernel instead. Example: $ bridge -s vlan show port vlan id br0 1 Egress Untagged RX: 2536 bytes 20 packets TX: 2536 bytes 20 packets 101 RX: 43158 bytes 50 packets TX: 43158 bytes 50 packets eth1 1 Egress Untagged RX: 2536 bytes 20 packets TX: 2536 bytes 20 packets 100 RX: 0 bytes 0 packets TX: 0 bytes 0 packets 101 RX: 43158 bytes 50 packets TX: 43158 bytes 50 packets 102 RX: 16897 bytes 93 packets TX: 0 bytes 0 packets The format is the same as bridge vlan show but with stats, even though under the hood the calls done to the kernel are different. Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
* ip link: Add support for kernel side filteringDavid Ahern2016-05-181-0/+6
| | | | | | | | | Kernel gained support for filtering link dumps with commit dc599f76c22b ("net: Add support for filtering link dump by master device and kind"). Add support to ip link command. If a user passes master device or kind to ip link command they are added to the link dump request message. Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
* scrub out whitespace issuesStephen Hemminger2016-03-271-17/+15
| | | | Run script that removes trailing whitespace everywhere.
* libnetlink: introduce nc_flagsPhil Sutter2015-11-291-1/+6
| | | | | | Allow for a filter to ignore certain nlmsg_flags. Signed-off-by: Phil Sutter <phil@nwl.cc>
* Merge branch 'master' into net-nextStephen Hemminger2015-10-161-0/+10
|\
| * libnetlink: introduce rta_nest and u8, u16, u64 helpers for nesting within ↵Roopa Prabhu2015-10-161-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | rtattr This patch introduces two new api's rta_nest and rta_nest_end to nest attributes inside a rta attribute represented by 'struct rtattr' as required to construct a nexthop. Also adds rta_addattr* variants for u8, u16 and u64 as needed to support encapsulation. Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: Thomas Graf <tgraf@suug.ch> Acked-by: Jiri Benc <jbenc@redhat.com>
* | ip neigh: Add support for filtering dumps by master deviceDavid Ahern2015-10-121-0/+2
|/ | | | | | | | | Add support for filtering neighbor dumps by master device. Kernel side support provided by commit 21fdd092acc7. Since the feature is not available in older kernels the user is given a warning message if the kernel does not support the request. Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
* remove unnecessary externStephen Hemminger2015-08-131-39/+42
| | | | No need for extern on function prototypes.
* Merge branch 'master' into net-nextStephen Hemminger2015-05-281-2/+2
|\ | | | | | | | | | | Conflicts: include/linux/tcp.h lib/libnetlink.c
| * libnetlink: add size argument to rtnl_talkStephen Hemminger2015-05-271-2/+2
| | | | | | | | | | | | | | | | There have been several instances where response from kernel has overrun the stack buffer from the caller. Avoid future problems by passing a size argument. Also drop the unused peer and group arguments to rtnl_talk.
* | ipmonitor: allows to monitor in several netnsNicolas Dichtel2015-05-211-0/+4
| | | | | | | | | | | | | | With this patch, it's now possible to listen in all netns that have an nsid assigned into the netns where the socket is opened. Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
* | libnetlink: introduce rtnl_listen_filter_tNicolas Dichtel2015-05-211-2/+9
|/ | | | | | There is no functional change with this commit. It only prepares the next one. Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
* ipnetns: allow to get and set netns idsNicolas Dichtel2015-02-211-0/+8
| | | | | | | | | | | | | | | The kernel now provides ids for peer netns. This patch implements a new command 'set' to assign an id. When netns are listed, if an id is assigned, it is now displayed. Example: $ ip netns add foo $ ip netns set foo 1 $ ip netns foo (id: 1) init_net Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
* Add define for nlmsg_types with timestampVadim Kochan2015-01-131-0/+4
| | | | | | Add #define for nlmsg_type = 15 Signed-off-by: Vadim Kochan <vadim4j@gmail.com>