virNetDevLinkDump should have been in virnetlink.c, but that file
didn't exist yet when the function was created. It didn't really
matter until now - I found that having virnetlink.h included by
virnetdev.h caused build problems when trying to #include virnetdev.h
in a .c file in src/conf (due to missing directory in -I). Rather than
fix that to further institutionalize the incorrect placement of this
one function, this patch moves the function.
---
src/libvirt_private.syms | 2 +-
src/util/virnetdev.c | 134 +-
src/util/virnetdev.h | 6 --
src/util/virnetdevvportprofile.c | 4 +-
src/util/virnetlink.c| 135 +++
src/util/virnetlink.h| 5 ++
6 files changed, 145 insertions(+), 141 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 501c23e..00fa673 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1872,7 +1872,6 @@ virNetDevGetVirtualFunctionInfo;
virNetDevGetVirtualFunctions;
virNetDevGetVLanID;
virNetDevIsVirtualFunction;
-virNetDevLinkDump;
virNetDevReplaceMacAddress;
virNetDevReplaceNetConfig;
virNetDevRestoreMacAddress;
@@ -1986,6 +1985,7 @@ virNetDevVPortProfileOpTypeToString;
# util/virnetlink.h
virNetlinkCommand;
virNetlinkDelLink;
+virNetlinkDumpLink;
virNetlinkEventAddClient;
virNetlinkEventRemoveClient;
virNetlinkEventServiceIsRunning;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 5a4ccc6..4cd51cb 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -23,6 +23,7 @@
#include
#include "virnetdev.h"
+#include "virnetlink.h"
#include "virmacaddr.h"
#include "virfile.h"
#include "virerror.h"
@@ -2086,124 +2087,6 @@ static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1]
= {
.maxlen = sizeof(struct ifla_vf_vlan) },
};
-/**
- * virNetDevLinkDump:
- *
- * @ifname: The name of the interface; only use if ifindex <= 0
- * @ifindex: The interface index; may be <= 0 if ifname is given
- * @data:Gets a pointer to the raw data from netlink.
- MUST BE FREED BY CALLER!
- * @nlattr: Pointer to a pointer of netlink attributes that will contain
- * the results
- * @src_pid: pid used for nl_pid of the local end of the netlink message
- * (0 == "use getpid()")
- * @dst_pid: pid of destination nl_pid if the kernel
- * is not the target of the netlink message but it is to be
- * sent to another process (0 if sending to the kernel)
- *
- * Get information from netlink about an interface given its name or index.
- *
- * Returns 0 on success, -1 on fatal error.
- */
-int
-virNetDevLinkDump(const char *ifname, int ifindex,
- void **nlData, struct nlattr **tb,
- uint32_t src_pid, uint32_t dst_pid)
-{
-int rc = -1;
-struct nlmsghdr *resp = NULL;
-struct nlmsgerr *err;
-struct ifinfomsg ifinfo = {
-.ifi_family = AF_UNSPEC,
-.ifi_index = ifindex
-};
-unsigned int recvbuflen;
-struct nl_msg *nl_msg;
-
-if (ifname && ifindex <= 0 && virNetDevGetIndex(ifname, ) < 0)
-return -1;
-
-ifinfo.ifi_index = ifindex;
-
-nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
-if (!nl_msg) {
-virReportOOMError();
-return -1;
-}
-
-if (nlmsg_append(nl_msg, , sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
-goto buffer_too_small;
-
-if (ifname) {
-if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
-goto buffer_too_small;
-}
-
-# ifdef RTEXT_FILTER_VF
-/* if this filter exists in the kernel's netlink implementation,
- * we need to set it, otherwise the response message will not
- * contain the IFLA_VFINFO_LIST that we're looking for.
- */
-{
-uint32_t ifla_ext_mask = RTEXT_FILTER_VF;
-
-if (nla_put(nl_msg, IFLA_EXT_MASK,
-sizeof(ifla_ext_mask), _ext_mask) < 0) {
-goto buffer_too_small;
-}
-}
-# endif
-
-if (virNetlinkCommand(nl_msg, , ,
- src_pid, dst_pid, NETLINK_ROUTE, 0) < 0)
-goto cleanup;
-
-if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
-goto malformed_resp;
-
-switch (resp->nlmsg_type) {
-case NLMSG_ERROR:
-err = (struct nlmsgerr *)NLMSG_DATA(resp);
-if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
-goto malformed_resp;
-
-if (err->error) {
-virReportSystemError(-err->error,
- _("error dumping %s (%d) interface"),
- ifname, ifindex);
-goto cleanup;
-}
-break;
-
-case GENL_ID_CTRL:
-case NLMSG_DONE:
-rc = nlmsg_parse(resp, sizeof(struct ifinfomsg),
- tb, IFLA_MAX, NULL);
-if (rc < 0)
-goto malformed_resp;
-