From: Daniel P. Berrange berra...@redhat.com
Move the low level macvlan creation APIs into the
virnetdevmacvlan.c file where they more naturally
belong
* util/interface.c, util/interface.h: Remove virNetDevMacVLanCreate
and virNetDevMacVLanDelete
* util/virnetdevmacvlan.c, util/virnetdevmacvlan.h: Add
virNetDevMacVLanCreate and virNetDevMacVLanDelete
---
src/util/interface.c| 270 ---
src/util/interface.h| 12 --
src/util/virnetdevmacvlan.c | 256 -
src/util/virnetdevmacvlan.h | 12 ++
4 files changed, 264 insertions(+), 286 deletions(-)
diff --git a/src/util/interface.c b/src/util/interface.c
index a1c56f5..e757c6f 100644
--- a/src/util/interface.c
+++ b/src/util/interface.c
@@ -312,276 +312,6 @@ ifaceGetIPAddress(const char *ifname ATTRIBUTE_UNUSED,
#endif /* __linux__ */
-/**
- * virNetDevMacVLanCreate:
- *
- * @ifname: The name the interface is supposed to have; optional parameter
- * @type: The type of device, i.e., macvtap
- * @macaddress: The MAC address of the device
- * @srcdev: The name of the 'link' device
- * @macvlan_mode: The macvlan mode to use
- * @retry: Pointer to integer that will be '1' upon return if an interface
- * with the same name already exists and it is worth to try
- * again with a different name
- *
- * Create a macvtap device with the given properties.
- *
- * Returns 0 on success, -1 on fatal error.
- */
-#if defined(__linux__) WITH_MACVTAP
-int
-virNetDevMacVLanCreate(const char *ifname,
- const char *type,
- const unsigned char *macaddress,
- const char *srcdev,
- uint32_t macvlan_mode,
- int *retry)
-{
-int rc = 0;
-struct nlmsghdr *resp;
-struct nlmsgerr *err;
-struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
-int ifindex;
-unsigned char *recvbuf = NULL;
-unsigned int recvbuflen;
-struct nl_msg *nl_msg;
-struct nlattr *linkinfo, *info_data;
-
-if (ifaceGetIndex(true, srcdev, ifindex) 0)
-return -1;
-
-*retry = 0;
-
-nl_msg = nlmsg_alloc_simple(RTM_NEWLINK,
-NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL);
-if (!nl_msg) {
-virReportOOMError();
-return -1;
-}
-
-if (nlmsg_append(nl_msg, ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) 0)
-goto buffer_too_small;
-
-if (nla_put_u32(nl_msg, IFLA_LINK, ifindex) 0)
-goto buffer_too_small;
-
-if (nla_put(nl_msg, IFLA_ADDRESS, VIR_MAC_BUFLEN, macaddress) 0)
-goto buffer_too_small;
-
-if (ifname
-nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) 0)
-goto buffer_too_small;
-
-if (!(linkinfo = nla_nest_start(nl_msg, IFLA_LINKINFO)))
-goto buffer_too_small;
-
-if (nla_put(nl_msg, IFLA_INFO_KIND, strlen(type), type) 0)
-goto buffer_too_small;
-
-if (macvlan_mode 0) {
-if (!(info_data = nla_nest_start(nl_msg, IFLA_INFO_DATA)))
-goto buffer_too_small;
-
-if (nla_put(nl_msg, IFLA_MACVLAN_MODE, sizeof(macvlan_mode),
-macvlan_mode) 0)
-goto buffer_too_small;
-
-nla_nest_end(nl_msg, info_data);
-}
-
-nla_nest_end(nl_msg, linkinfo);
-
-if (nlComm(nl_msg, recvbuf, recvbuflen, 0) 0) {
-rc = -1;
-goto cleanup;
-}
-
-if (recvbuflen NLMSG_LENGTH(0) || recvbuf == NULL)
-goto malformed_resp;
-
-resp = (struct nlmsghdr *)recvbuf;
-
-switch (resp-nlmsg_type) {
-case NLMSG_ERROR:
-err = (struct nlmsgerr *)NLMSG_DATA(resp);
-if (resp-nlmsg_len NLMSG_LENGTH(sizeof(*err)))
-goto malformed_resp;
-
-switch (err-error) {
-
-case 0:
-break;
-
-case -EEXIST:
-*retry = 1;
-rc = -1;
-break;
-
-default:
-virReportSystemError(-err-error,
- _(error creating %s type of interface),
- type);
-rc = -1;
-}
-break;
-
-case NLMSG_DONE:
-break;
-
-default:
-goto malformed_resp;
-}
-
-cleanup:
-nlmsg_free(nl_msg);
-
-VIR_FREE(recvbuf);
-
-return rc;
-
-malformed_resp:
-nlmsg_free(nl_msg);
-
-ifaceError(VIR_ERR_INTERNAL_ERROR, %s,
- _(malformed netlink response message));
-VIR_FREE(recvbuf);
-return -1;
-
-buffer_too_small:
-nlmsg_free(nl_msg);
-
-ifaceError(VIR_ERR_INTERNAL_ERROR, %s,
- _(allocated netlink buffer is too small));
-return -1;
-}
-
-#else
-
-int virNetDevMacVLanCreate(const char *ifname ATTRIBUTE_UNUSED,
- const char *type ATTRIBUTE_UNUSED,
- const unsigned char *macaddress ATTRIBUTE_UNUSED,
- const char *srcdev