diff options
| author | Jiri Pirko <jiri@mellanox.com> | 2019-11-12 11:44:00 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-11-14 09:21:37 +0100 |
| commit | d5f798b079efa4c95ac265a974e12d0c07685757 (patch) | |
| tree | 559f0aec3537eeea9d13fc275a9edd0538d10199 /executor | |
| parent | 048f2d494ee4a016e2386c28bf8cccdd87896cbd (diff) | |
executor: push out devlink generic netlink id getter into a separate function
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/common_linux.h | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h index 5dbd5a56c..2fcf588bf 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -450,16 +450,13 @@ const int kInitNetNsFd = 239; // see kMaxFd #define DEVLINK_ATTR_DEV_NAME 2 #define DEVLINK_ATTR_NETNS_FD 137 -static void netlink_devlink_netns_move(const char* bus_name, const char* dev_name, int netns_fd) +static int netlink_devlink_id_get(int sock) { struct genlmsghdr genlhdr; struct nlattr* attr; - int sock, err, n; + int err, n; uint16 id = 0; - sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); - if (sock == -1) - fail("socket(AF_NETLINK) failed\n"); memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); @@ -467,7 +464,7 @@ static void netlink_devlink_netns_move(const char* bus_name, const char* dev_nam err = netlink_send_ext(sock, GENL_ID_CTRL, &n); if (err) { debug("netlink: failed to get devlink family id: %s\n", strerror(err)); - goto error; + return -1; } attr = (struct nlattr*)(nlmsg.buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg.buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { @@ -478,9 +475,27 @@ static void netlink_devlink_netns_move(const char* bus_name, const char* dev_nam } if (!id) { debug("netlink: failed to parse message for devlink family id\n"); - goto error; + return -1; } recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0); /* recv ack */ + + return id; +} + +static void netlink_devlink_netns_move(const char* bus_name, const char* dev_name, int netns_fd) +{ + struct genlmsghdr genlhdr; + int sock; + int id; + + sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + if (sock == -1) + fail("socket(AF_NETLINK) failed\n"); + + id = netlink_devlink_id_get(sock); + if (id == -1) + goto error; + memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = DEVLINK_CMD_RELOAD; netlink_init(id, 0, &genlhdr, sizeof(genlhdr)); |
