platform: extend netlink processing of messages for different protocols
Later, the same loop should also handle genl.
This commit is contained in:
@@ -9241,11 +9241,11 @@ rtnl_event_handler(int fd, GIOCondition io_condition, gpointer user_data)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* copied from libnl3's recvmsgs() */
|
||||
static int
|
||||
event_handler_recvmsgs(NMPlatform *platform, gboolean handle_events)
|
||||
_netlink_recv_handle(NMPlatform *platform, int netlink_protocol, gboolean handle_events)
|
||||
{
|
||||
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform);
|
||||
struct nl_sock *sk;
|
||||
int n;
|
||||
int err = 0;
|
||||
gboolean multipart = 0;
|
||||
@@ -9255,10 +9255,15 @@ event_handler_recvmsgs(NMPlatform *platform, gboolean handle_events)
|
||||
struct sockaddr_nl nla;
|
||||
struct ucred creds;
|
||||
gboolean creds_has;
|
||||
const char *log_prefix;
|
||||
|
||||
nm_assert(netlink_protocol == NETLINK_ROUTE);
|
||||
sk = priv->sk_rtnl;
|
||||
log_prefix = "rtnl";
|
||||
|
||||
continue_reading:
|
||||
|
||||
n = _netlink_recv(platform, priv->sk_rtnl, &nla, &creds, &creds_has);
|
||||
n = _netlink_recv(platform, sk, &nla, &creds, &creds_has);
|
||||
if (n < 0) {
|
||||
if (n == -NME_NL_MSG_TRUNC && !handle_events)
|
||||
goto continue_reading;
|
||||
@@ -9267,9 +9272,9 @@ continue_reading:
|
||||
|
||||
if (!creds_has || creds.pid) {
|
||||
if (!creds_has)
|
||||
_LOGT("netlink: recvmsg: received message without credentials");
|
||||
_LOGT("%s: recvmsg: received message without credentials", log_prefix);
|
||||
else
|
||||
_LOGT("netlink: recvmsg: received non-kernel message (pid %d)", creds.pid);
|
||||
_LOGT("%s: recvmsg: received non-kernel message (pid %d)", log_prefix, creds.pid);
|
||||
err = 0;
|
||||
goto stop;
|
||||
}
|
||||
@@ -9284,13 +9289,13 @@ continue_reading:
|
||||
const char *extack_msg = NULL;
|
||||
|
||||
msg = nlmsg_alloc_convert(hdr);
|
||||
|
||||
nlmsg_set_proto(msg, NETLINK_ROUTE);
|
||||
nlmsg_set_proto(msg, netlink_protocol);
|
||||
nlmsg_set_src(msg, &nla);
|
||||
nlmsg_set_creds(msg, &creds);
|
||||
|
||||
_LOGt("netlink: recvmsg: new message %s",
|
||||
nl_nlmsghdr_to_str(NETLINK_ROUTE, hdr, buf_nlmsghdr, sizeof(buf_nlmsghdr)));
|
||||
_LOGt("%s: recvmsg: new message %s",
|
||||
log_prefix,
|
||||
nl_nlmsghdr_to_str(netlink_protocol, hdr, buf_nlmsghdr, sizeof(buf_nlmsghdr)));
|
||||
|
||||
if (hdr->nlmsg_flags & NLM_F_MULTI)
|
||||
multipart = TRUE;
|
||||
@@ -9309,6 +9314,9 @@ continue_reading:
|
||||
/* FIXME: implement */
|
||||
}
|
||||
|
||||
switch (netlink_protocol) {
|
||||
case NETLINK_ROUTE:
|
||||
{
|
||||
seq_result = WAIT_FOR_NL_RESPONSE_RESULT_RESPONSE_UNKNOWN;
|
||||
|
||||
if (hdr->nlmsg_type == NLMSG_DONE) {
|
||||
@@ -9365,7 +9373,8 @@ continue_reading:
|
||||
}
|
||||
|
||||
/* Error message reported back from kernel. */
|
||||
_LOGD("netlink: recvmsg: error message from kernel: %s (%d)%s%s%s for request %d",
|
||||
_LOGD(
|
||||
"netlink: recvmsg: error message from kernel: %s (%d)%s%s%s for request %d",
|
||||
nm_strerror_native(errsv),
|
||||
errsv,
|
||||
NM_PRINT_FMT_QUOTED(extack_msg, " \"", extack_msg, "\"", ""),
|
||||
@@ -9398,6 +9407,11 @@ continue_reading:
|
||||
}
|
||||
|
||||
event_seq_check(platform, seq_number, seq_result, extack_msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
nm_assert_not_reached();
|
||||
}
|
||||
|
||||
if (abort_parsing)
|
||||
goto stop;
|
||||
@@ -9450,7 +9464,7 @@ event_handler_read_netlink(NMPlatform *platform, gboolean wait_for_acks)
|
||||
for (;;) {
|
||||
int nle;
|
||||
|
||||
nle = event_handler_recvmsgs(platform, TRUE);
|
||||
nle = _netlink_recv_handle(platform, NETLINK_ROUTE, TRUE);
|
||||
|
||||
if (nle < 0) {
|
||||
switch (nle) {
|
||||
@@ -9475,7 +9489,7 @@ event_handler_read_netlink(NMPlatform *platform, gboolean wait_for_acks)
|
||||
}
|
||||
_reason;
|
||||
}));
|
||||
event_handler_recvmsgs(platform, FALSE);
|
||||
_netlink_recv_handle(platform, NETLINK_ROUTE, FALSE);
|
||||
delayed_action_wait_for_nl_response_complete_all(
|
||||
platform,
|
||||
WAIT_FOR_NL_RESPONSE_RESULT_FAILED_RESYNC);
|
||||
|
Reference in New Issue
Block a user