提交 ce5d17b3 编写于 作者: L Laine Stump 提交者: Cole Robinson

util: function to get local nl_pid used by netlink event socket

This value will be needed to set the src_pid when sending netlink
messages to lldpad. It is part of the solution to:

  https://bugzilla.redhat.com/show_bug.cgi?id=816465

Note that libnl's port generation algorithm guarantees that the
nl_socket_get_local_port() will always be > 0 (since it is "getpid() +
(n << 22>" where n is always < 1024), so it is okay to cast the
uint32_t to int (thus allowing us to use -1 as an error sentinel).
(cherry picked from commit c99e9375)
上级 443e37da
......@@ -1325,6 +1325,7 @@ virNetlinkCommand;
virNetlinkEventAddClient;
virNetlinkEventRemoveClient;
virNetlinkEventServiceIsRunning;
virNetlinkEventServiceLocalPid;
virNetlinkEventServiceStop;
virNetlinkEventServiceStart;
virNetlinkShutdown;
......
......@@ -368,6 +368,24 @@ virNetlinkEventServiceIsRunning(void)
return server != NULL;
}
/**
* virNetlinkEventServiceLocalPid:
*
* Returns the nl_pid value that was used to bind() the netlink socket
* used by the netlink event service, or -1 on error (netlink
* guarantees that this value will always be > 0).
*/
int virNetlinkEventServiceLocalPid(void)
{
if (!(server && server->netlinknh)) {
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s",
_("netlink event service not running"));
return -1;
}
return (int)nl_socket_get_local_port(server->netlinknh);
}
/**
* virNetlinkEventServiceStart:
*
......
......@@ -61,6 +61,11 @@ int virNetlinkEventServiceStart(void);
*/
bool virNetlinkEventServiceIsRunning(void);
/**
* virNetlinkEventServiceLocalPid: returns nl_pid used to bind() netlink socket
*/
int virNetlinkEventServiceLocalPid(void);
/**
* virNetlinkEventAddClient: register a callback for handling of netlink messages
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册