From 858ce410250bae8c5043b8277aa3941dd528d577 Mon Sep 17 00:00:00 2001 From: Cheyenne Wills Date: Fri, 3 Jul 2020 10:33:51 -0600 Subject: [PATCH 2/4] LINUX 5.8: Replace kernel_setsockopt with new funcs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linux 5.8-rc1 commit 'net: remove kernel_setsockopt' (5a892ff2facb) retires the kernel_setsockopt function. In prior kernel commits new functions (ip_sock_set_*) were added to replace the specific functions performed by kernel_setsockopt. Define new config test 'HAVE_IP_SOCK_SET' if the 'ip_sock_set' functions are available. The config define 'HAVE_KERNEL_SETSOCKOPT' is no longer set in Linux 5.8. Create wrapper functions that replace the kernel_setsockopt calls with calls to the appropriate Linux kernel function(s) (depending on what functions the kernel supports). Remove the unused 'kernel_getsockopt' function (used for building with pre 2.6.19 kernels). For reference Linux 2.6.19 introduced kernel_setsockopt Linux 5.8 removed kernel_setsockopt and replaced the functionality with a set of new functions (ip_sock_set_*) Reviewed-on: https://gerrit.openafs.org/14247 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk (cherry picked from commit c48072b9800759ef1682b91ff1e962f6904a2594) Change-Id: I2724fad06b1882149d2066d13eced55eff5ee695 Reviewed-on: https://gerrit.openafs.org/14267 Tested-by: BuildBot Reviewed-by: Michael Laß Reviewed-by: Stephan Wiesand --- src/afs/LINUX/osi_compat.h | 43 +++++++++++++++++++++++++------------ src/cf/linux-kernel-func.m4 | 6 ++++++ src/rx/LINUX/rx_knet.c | 11 +++------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/afs/LINUX/osi_compat.h b/src/afs/LINUX/osi_compat.h index 4999b89b9..620b3730c 100644 --- a/src/afs/LINUX/osi_compat.h +++ b/src/afs/LINUX/osi_compat.h @@ -314,9 +314,22 @@ zero_user_segment(struct page *pp, unsigned int from1, unsigned int to1) } #endif -#ifndef HAVE_LINUX_KERNEL_SETSOCKOPT +#if defined(HAVE_LINUX_IP_SOCK_SET) +# include +/* ip_sock_set_* introduced in linux 5.8 */ +static inline void +afs_linux_sock_set_mtu_discover(struct socket *sockp, int pmtu) +{ + ip_sock_set_mtu_discover(sockp->sk, pmtu); +} +static inline void +afs_linux_sock_set_recverr(struct socket *sockp) +{ + ip_sock_set_recverr(sockp->sk); +} +#else +# if !defined(HAVE_LINUX_KERNEL_SETSOCKOPT) /* Available from 2.6.19 */ - static inline int kernel_setsockopt(struct socket *sockp, int level, int name, char *val, unsigned int len) { @@ -329,20 +342,22 @@ kernel_setsockopt(struct socket *sockp, int level, int name, char *val, return ret; } +# endif /* !HAVE_LINUX_KERNEL_SETSOCKOPT */ -static inline int -kernel_getsockopt(struct socket *sockp, int level, int name, char *val, - int *len) { - mm_segment_t old_fs = get_fs(); - int ret; - - set_fs(get_ds()); - ret = sockp->ops->getsockopt(sockp, level, name, val, len); - set_fs(old_fs); - - return ret; +static inline void +afs_linux_sock_set_mtu_discover(struct socket *sockp, int pmtu) +{ + kernel_setsockopt(sockp, SOL_IP, IP_MTU_DISCOVER, (char *)&pmtu, + sizeof(pmtu)); } -#endif +static inline void +afs_linux_sock_set_recverr(struct socket *sockp) +{ + int recverr = 1; + kernel_setsockopt(sockp, SOL_IP, IP_RECVERR, (char *)&recverr, + sizeof(recverr)); +} +#endif /* !HAVE_LINUX_IP_SOCK_SET */ #ifdef HAVE_TRY_TO_FREEZE static inline int diff --git a/src/cf/linux-kernel-func.m4 b/src/cf/linux-kernel-func.m4 index 07627db52..78ff48294 100644 --- a/src/cf/linux-kernel-func.m4 +++ b/src/cf/linux-kernel-func.m4 @@ -151,6 +151,12 @@ AC_CHECK_LINUX_FUNC([lru_cache_add_file], [#include ], [lru_cache_add_file(NULL);]) +dnl Linux 5.8 replaced kernel_setsockopt with helper functions +dnl e.g. ip_sock_set_mtu_discover, ip_sock_set_recverr +AC_CHECK_LINUX_FUNC([ip_sock_set], + [#include ], + [ip_sock_set_mtu_discover(NULL, 0);]) + dnl Consequences - things which get set as a result of the dnl above tests AS_IF([test "x$ac_cv_linux_func_d_alloc_anon" = "xno"], diff --git a/src/rx/LINUX/rx_knet.c b/src/rx/LINUX/rx_knet.c index 9fbb563f3..50607c8f5 100644 --- a/src/rx/LINUX/rx_knet.c +++ b/src/rx/LINUX/rx_knet.c @@ -34,7 +34,6 @@ #include #include #endif - #include "osi_compat.h" /* rxk_NewSocket @@ -76,14 +75,10 @@ rxk_NewSocketHost(afs_uint32 ahost, short aport) return NULL; } - kernel_setsockopt(sockp, SOL_IP, IP_MTU_DISCOVER, (char *)&pmtu, - sizeof(pmtu)); + afs_linux_sock_set_mtu_discover(sockp, pmtu); + #ifdef AFS_RXERRQ_ENV - { - int recverr = 1; - kernel_setsockopt(sockp, SOL_IP, IP_RECVERR, (char *)&recverr, - sizeof(recverr)); - } + afs_linux_sock_set_recverr(sockp); #endif return (osi_socket *)sockp; } -- 2.27.0