{
/* use a netlink RTM_NEWLINK message to create the bridge */
const char *type = "bridge";
- int rc = -1;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
unsigned int recvbuflen;
- struct nl_msg *nl_msg;
struct nlattr *linkinfo;
+ VIR_AUTOPTR(virNetlinkMsg) nl_msg = NULL;
VIR_AUTOFREE(struct nlmsghdr *) resp = NULL;
nl_msg = nlmsg_alloc_simple(RTM_NEWLINK,
if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0,
NETLINK_ROUTE, 0) < 0) {
- goto cleanup;
+ return -1;
}
if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
/* fallback to ioctl if netlink doesn't support creating
* bridges
*/
- rc = virNetDevBridgeCreateWithIoctl(brname);
- goto cleanup;
+ return virNetDevBridgeCreateWithIoctl(brname);
}
# endif
virReportSystemError(-err->error,
_("error creating bridge interface %s"),
brname);
- goto cleanup;
+ return -1;
}
break;
goto malformed_resp;
}
- rc = 0;
- cleanup:
- nlmsg_free(nl_msg);
- return rc;
+ return 0;
malformed_resp:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
- goto cleanup;
+ return -1;
buffer_too_small:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("allocated netlink buffer is too small"));
- goto cleanup;
+ return -1;
}
virNetDevBridgeFDBAddDel(const virMacAddr *mac, const char *ifname,
unsigned int flags, bool isAdd)
{
- int ret = -1;
struct nlmsgerr *err;
unsigned int recvbuflen;
- struct nl_msg *nl_msg;
struct ndmsg ndm = { .ndm_family = PF_BRIDGE, .ndm_state = NUD_NOARP };
+ VIR_AUTOPTR(virNetlinkMsg) nl_msg = NULL;
VIR_AUTOFREE(struct nlmsghdr *) resp = NULL;
if (virNetDevGetIndex(ifname, &ndm.ndm_ifindex) < 0)
if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0,
NETLINK_ROUTE, 0) < 0) {
- goto cleanup;
+ return -1;
}
if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
goto malformed_resp;
if (err->error) {
virReportSystemError(-err->error,
_("error adding fdb entry for %s"), ifname);
- goto cleanup;
+ return -1;
}
break;
case NLMSG_DONE:
goto malformed_resp;
}
- ret = 0;
- cleanup:
- nlmsg_free(nl_msg);
- return ret;
+ return 0;
malformed_resp:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
- goto cleanup;
+ return -1;
buffer_too_small:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("allocated netlink buffer is too small"));
- goto cleanup;
+ return -1;
}