Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv4: add ip_sock_set_freebind

Add a helper to directly set the IP_FREEBIND sockopt from kernel space
without going through a fake uaccess.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Christoph Hellwig and committed by
David S. Miller
c4e446bf 6ebf71ba

+12 -10
+3 -10
drivers/target/iscsi/iscsi_target_login.c
··· 15 15 #include <linux/sched/signal.h> 16 16 #include <linux/idr.h> 17 17 #include <linux/tcp.h> /* TCP_NODELAY */ 18 + #include <net/ip.h> 18 19 #include <net/ipv6.h> /* ipv6_addr_v4mapped() */ 19 20 #include <scsi/iscsi_proto.h> 20 21 #include <target/target_core_base.h> ··· 856 855 struct sockaddr_storage *sockaddr) 857 856 { 858 857 struct socket *sock = NULL; 859 - int backlog = ISCSIT_TCP_BACKLOG, ret, opt = 0, len; 858 + int backlog = ISCSIT_TCP_BACKLOG, ret, len; 860 859 861 860 switch (np->np_network_transport) { 862 861 case ISCSI_TCP: ··· 901 900 if (np->np_network_transport == ISCSI_TCP) 902 901 tcp_sock_set_nodelay(sock->sk); 903 902 sock_set_reuseaddr(sock->sk); 904 - 905 - opt = 1; 906 - ret = kernel_setsockopt(sock, IPPROTO_IP, IP_FREEBIND, 907 - (char *)&opt, sizeof(opt)); 908 - if (ret < 0) { 909 - pr_err("kernel_setsockopt() for IP_FREEBIND" 910 - " failed\n"); 911 - goto fail; 912 - } 903 + ip_sock_set_freebind(sock->sk); 913 904 914 905 ret = kernel_bind(sock, (struct sockaddr *)&np->np_sockaddr, len); 915 906 if (ret < 0) {
+1
include/net/ip.h
··· 765 765 return likely(mtu >= IPV4_MIN_MTU); 766 766 } 767 767 768 + void ip_sock_set_freebind(struct sock *sk); 768 769 void ip_sock_set_tos(struct sock *sk, int val); 769 770 770 771 #endif /* _IP_H */
+8
net/ipv4/ip_sockglue.c
··· 581 581 } 582 582 EXPORT_SYMBOL(ip_sock_set_tos); 583 583 584 + void ip_sock_set_freebind(struct sock *sk) 585 + { 586 + lock_sock(sk); 587 + inet_sk(sk)->freebind = true; 588 + release_sock(sk); 589 + } 590 + EXPORT_SYMBOL(ip_sock_set_freebind); 591 + 584 592 /* 585 593 * Socket option code for IP. This is the end of the line after any 586 594 * TCP,UDP etc options on an IP socket.