sd-netlink,sd-device: drop old kernels (<4.2) support

NETLINK_LIST_MEMBERSHIPS is supported since kernel v4.2, specifically
b42be38b27

Our baseline on the kernel is v5.4. Let's drop unnecessary conditions.
This commit is contained in:
Yu Watanabe
2025-04-14 05:42:24 +09:00
parent d3d375a686
commit 6dbf2c1beb
4 changed files with 3 additions and 21 deletions

View File

@@ -1819,8 +1819,6 @@ int netlink_socket_get_multicast_groups(int fd, size_t *ret_len, uint32_t **ret_
assert(fd >= 0);
/* This returns ENOPROTOOPT if the kernel is older than 4.2. */
if (getsockopt(fd, SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS, NULL, &len) < 0)
return -errno;

View File

@@ -305,7 +305,7 @@ _public_ int sd_device_monitor_stop(sd_device_monitor *m) {
/* Save multicast groups. */
r = netlink_socket_get_multicast_groups(m->sock, &m->multicast_group_len, &m->multicast_groups);
if (r < 0 && r != -ENOPROTOOPT)
if (r < 0)
return r;
/* Leave from all multicast groups to prevent the buffer is filled. */

View File

@@ -71,7 +71,6 @@ struct sd_netlink {
int protocol;
Hashmap *broadcast_group_refs;
bool broadcast_group_dont_leave:1; /* until we can rely on 4.2 */
OrderedSet *rqueue;
Hashmap *rqueue_by_serial;

View File

@@ -24,10 +24,6 @@ static int broadcast_groups_get(sd_netlink *nl) {
assert(nl->fd >= 0);
r = netlink_socket_get_multicast_groups(nl->fd, &len, &groups);
if (r == -ENOPROTOOPT) {
nl->broadcast_group_dont_leave = true;
return 0;
}
if (r < 0)
return r;
@@ -106,18 +102,6 @@ int socket_broadcast_group_ref(sd_netlink *nl, unsigned group) {
return broadcast_group_join(nl, group);
}
static int broadcast_group_leave(sd_netlink *nl, unsigned group) {
assert(nl);
assert(nl->fd >= 0);
assert(group > 0);
if (nl->broadcast_group_dont_leave)
return 0;
/* group is "unsigned", but netlink(7) says the argument for NETLINK_DROP_MEMBERSHIP is "int" */
return setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, group);
}
int socket_broadcast_group_unref(sd_netlink *nl, unsigned group) {
unsigned n_ref;
int r;
@@ -138,7 +122,8 @@ int socket_broadcast_group_unref(sd_netlink *nl, unsigned group) {
/* still refs left */
return 0;
return broadcast_group_leave(nl, group);
/* group is "unsigned", but netlink(7) says the argument for NETLINK_DROP_MEMBERSHIP is "int" */
return setsockopt_int(nl->fd, SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, group);
}
/* returns the number of bytes sent, or a negative error code */