net: introduce keepalive function in struct proto
authorUrsula Braun <ubraun@linux.vnet.ibm.com>
Mon, 9 Jan 2017 15:55:12 +0000 (16:55 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Jan 2017 21:07:37 +0000 (16:07 -0500)
Direct call of tcp_set_keepalive() function from protocol-agnostic
sock_setsockopt() function in net/core/sock.c violates network
layering. And newly introduced protocol (SMC-R) will need its own
keepalive function. Therefore, add "keepalive" function pointer
to "struct proto", and call it from sock_setsockopt() via this pointer.

Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com>
Reviewed-by: Utz Bacher <utz.bacher@de.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h
net/core/sock.c
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_timer.c
net/ipv6/tcp_ipv6.c

index f0e867f58722f344494c98cbdbe49d7ec875099a..99deda67eba0ef7f0a8699db740c3b9b357ce271 100644 (file)
@@ -1024,6 +1024,7 @@ struct proto {
        int                     (*getsockopt)(struct sock *sk, int level,
                                        int optname, char __user *optval,
                                        int __user *option);
+       void                    (*keepalive)(struct sock *sk, int valbool);
 #ifdef CONFIG_COMPAT
        int                     (*compat_setsockopt)(struct sock *sk,
                                        int level,
index f560e0826009851e79a1f8a8b90f4ded3cfc382d..5018703ee2c2e12bf5c154aa52a187d85212e534 100644 (file)
@@ -762,11 +762,8 @@ set_rcvbuf:
                goto set_rcvbuf;
 
        case SO_KEEPALIVE:
-#ifdef CONFIG_INET
-               if (sk->sk_protocol == IPPROTO_TCP &&
-                   sk->sk_type == SOCK_STREAM)
-                       tcp_set_keepalive(sk, valbool);
-#endif
+               if (sk->sk_prot->keepalive)
+                       sk->sk_prot->keepalive(sk, valbool);
                sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
                break;
 
index 7e4be4f361f3097db4c005cab6cbec0ed2f18a43..56d756ecfb597855065299b0f8b14d73ddfcdbf3 100644 (file)
@@ -2376,6 +2376,7 @@ struct proto tcp_prot = {
        .shutdown               = tcp_shutdown,
        .setsockopt             = tcp_setsockopt,
        .getsockopt             = tcp_getsockopt,
+       .keepalive              = tcp_set_keepalive,
        .recvmsg                = tcp_recvmsg,
        .sendmsg                = tcp_sendmsg,
        .sendpage               = tcp_sendpage,
index 3705075f42c34b4ce5102bd858d5ed55ed7dd4cc..29a9bd5f1225e96aef9052d69e19b3407f727e83 100644 (file)
@@ -617,6 +617,7 @@ void tcp_set_keepalive(struct sock *sk, int val)
        else if (!val)
                inet_csk_delete_keepalive_timer(sk);
 }
+EXPORT_SYMBOL_GPL(tcp_set_keepalive);
 
 
 static void tcp_keepalive_timer (unsigned long data)
index a4cdf6a34c304ea519bae28db1d5c4ad6d971817..228965dca3c529b1c80994d254fb59a8a19f3089 100644 (file)
@@ -1889,6 +1889,7 @@ struct proto tcpv6_prot = {
        .shutdown               = tcp_shutdown,
        .setsockopt             = tcp_setsockopt,
        .getsockopt             = tcp_getsockopt,
+       .keepalive              = tcp_set_keepalive,
        .recvmsg                = tcp_recvmsg,
        .sendmsg                = tcp_sendmsg,
        .sendpage               = tcp_sendpage,