Compare commits

...

5 Commits

Author SHA1 Message Date
Jan Vaclav
19e65c2843 merge: branch 'jv/fix-newt-error-handling'
nmtui: handle write() errors correctly in nmt_newt_edit_string

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1971
2024-06-26 10:56:55 +00:00
Beniamino Galvani
14eaf4e419 merge: branch 'bg/netlink-strict-check'
Enable strict check on the netlink socket

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1962
2024-06-26 07:54:02 +00:00
Beniamino Galvani
185932a1a2 platform: enable strict check on netlink socket dumps
In the future we might want to specify filters when requesting netlink
dumps; this requires that strict check is enabled on the socket.

When enabling strict check, we need to pass a full struct in the
netlink message, otherwise kernel ignores it.

This commit doesn't change behavior.
2024-06-26 09:52:50 +02:00
Beniamino Galvani
2b8d8fe92a platform: don't set RTM_F_LOOKUP_TABLE for IPv6
RTM_F_LOOKUP_TABLE is only needed for IPv4. IPv6 dumps with the flag
are rejected in strict mode.
2024-06-26 09:52:50 +02:00
Jan Vaclav
03f0375b09 nmtui: handle write() errors correctly in nmt_newt_edit_string
It might happen that write() returns -1, but the errno is not EINTR.
In that case, the length would be incremented by 1, and the data pointer
to the data being written would be moved back by 1 byte on every error.

Make it so that the function exits with an error if it indicates an error.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1971

Fixes: 3bda3fb60c ('nmtui: initial import of nmtui')
2024-06-24 11:12:38 +00:00
3 changed files with 50 additions and 10 deletions

View File

@ -337,6 +337,11 @@ struct _ifla_vf_vlan_info {
#define BRIDGE_VLAN_INFO_RANGE_END (1 << 4) /* VLAN is end of vlan range */
#endif
/* Appeared in kernel 4.2 dated August 2015 */
#ifndef RTM_F_LOOKUP_TABLE
#define RTM_F_LOOKUP_TABLE 0x1000 /* set rtm_table to FIB lookup result */
#endif
/*****************************************************************************/
#define PSCHED_TIME_UNITS_PER_SEC 1000000
@ -7784,17 +7789,42 @@ _nl_msg_new_dump_rtnl(NMPObjectType obj_type, int preferred_addr_family)
g_return_val_if_reached(NULL);
} break;
case NMP_OBJECT_TYPE_LINK:
{
struct ifinfomsg ifm = {};
if (nlmsg_append_struct(nlmsg, &ifm) < 0)
g_return_val_if_reached(NULL);
break;
}
case NMP_OBJECT_TYPE_IP4_ADDRESS:
case NMP_OBJECT_TYPE_IP6_ADDRESS:
case NMP_OBJECT_TYPE_IP4_ROUTE:
case NMP_OBJECT_TYPE_IP6_ROUTE:
case NMP_OBJECT_TYPE_ROUTING_RULE:
{
const struct rtgenmsg gmsg = {
.rtgen_family = preferred_addr_family,
struct ifaddrmsg ifm = {
.ifa_family = preferred_addr_family,
};
if (nlmsg_append_struct(nlmsg, &gmsg) < 0)
if (nlmsg_append_struct(nlmsg, &ifm) < 0)
g_return_val_if_reached(NULL);
break;
}
case NMP_OBJECT_TYPE_IP4_ROUTE:
case NMP_OBJECT_TYPE_IP6_ROUTE:
{
struct rtmsg rtm = {
.rtm_family = preferred_addr_family,
};
if (nlmsg_append_struct(nlmsg, &rtm) < 0)
g_return_val_if_reached(NULL);
break;
}
case NMP_OBJECT_TYPE_ROUTING_RULE:
{
struct fib_rule_hdr frh = {
.family = preferred_addr_family,
};
if (nlmsg_append_struct(nlmsg, &frh) < 0)
g_return_val_if_reached(NULL);
} break;
default:
@ -10307,7 +10337,7 @@ ip_route_get(NMPlatform *platform,
.r.rtm_family = addr_family,
.r.rtm_tos = 0,
.r.rtm_dst_len = IS_IPv4 ? 32 : 128,
.r.rtm_flags = 0x1000 /* RTM_F_LOOKUP_TABLE */,
.r.rtm_flags = IS_IPv4 ? RTM_F_LOOKUP_TABLE : 0,
};
nm_clear_pointer(&route, nmp_object_unref);

View File

@ -1152,6 +1152,7 @@ nl_socket_new(struct nl_sock **out_sk,
i_val = 1;
(void) setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_EXT_ACK, &i_val, sizeof(i_val));
(void) setsockopt(sk->s_fd, SOL_NETLINK, NETLINK_GET_STRICT_CHK, &i_val, sizeof(i_val));
if (NM_FLAGS_HAS(flags, NL_SOCKET_FLAGS_PASSCRED)) {
err = nl_socket_set_passcred(sk, 1);

View File

@ -416,9 +416,18 @@ nmt_newt_edit_string(const char *data)
len = data ? strlen(data) : 0;
while (len) {
do
nwrote = write(fd, data, len);
while (nwrote == -1 && errno == EINTR);
nwrote = write(fd, data, len);
if (nwrote == -1) {
if (errno == EINTR) {
continue;
}
nmt_newt_message_dialog(_("Could not write to temporary file: %s"),
nm_strerror_native(errno));
nm_close(fd);
goto done;
}
len -= nwrote;
data += nwrote;