Skip to content

Commit 4b9d07a

Browse files
Ursula Braundavem330
authored andcommitted
net: introduce keepalive function in struct proto
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 <[email protected]> Reviewed-by: Utz Bacher <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c8584b3 commit 4b9d07a

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

include/net/sock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ struct proto {
10241024
int (*getsockopt)(struct sock *sk, int level,
10251025
int optname, char __user *optval,
10261026
int __user *option);
1027+
void (*keepalive)(struct sock *sk, int valbool);
10271028
#ifdef CONFIG_COMPAT
10281029
int (*compat_setsockopt)(struct sock *sk,
10291030
int level,

net/core/sock.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
762762
goto set_rcvbuf;
763763

764764
case SO_KEEPALIVE:
765-
#ifdef CONFIG_INET
766-
if (sk->sk_protocol == IPPROTO_TCP &&
767-
sk->sk_type == SOCK_STREAM)
768-
tcp_set_keepalive(sk, valbool);
769-
#endif
765+
if (sk->sk_prot->keepalive)
766+
sk->sk_prot->keepalive(sk, valbool);
770767
sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
771768
break;
772769

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,6 +2376,7 @@ struct proto tcp_prot = {
23762376
.shutdown = tcp_shutdown,
23772377
.setsockopt = tcp_setsockopt,
23782378
.getsockopt = tcp_getsockopt,
2379+
.keepalive = tcp_set_keepalive,
23792380
.recvmsg = tcp_recvmsg,
23802381
.sendmsg = tcp_sendmsg,
23812382
.sendpage = tcp_sendpage,

net/ipv4/tcp_timer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ void tcp_set_keepalive(struct sock *sk, int val)
617617
else if (!val)
618618
inet_csk_delete_keepalive_timer(sk);
619619
}
620+
EXPORT_SYMBOL_GPL(tcp_set_keepalive);
620621

621622

622623
static void tcp_keepalive_timer (unsigned long data)

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ struct proto tcpv6_prot = {
18891889
.shutdown = tcp_shutdown,
18901890
.setsockopt = tcp_setsockopt,
18911891
.getsockopt = tcp_getsockopt,
1892+
.keepalive = tcp_set_keepalive,
18921893
.recvmsg = tcp_recvmsg,
18931894
.sendmsg = tcp_sendmsg,
18941895
.sendpage = tcp_sendpage,

0 commit comments

Comments
 (0)