Commit c4e446bf authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

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: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6ebf71ba
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/tcp.h> /* TCP_NODELAY */ #include <linux/tcp.h> /* TCP_NODELAY */
#include <net/ip.h>
#include <net/ipv6.h> /* ipv6_addr_v4mapped() */ #include <net/ipv6.h> /* ipv6_addr_v4mapped() */
#include <scsi/iscsi_proto.h> #include <scsi/iscsi_proto.h>
#include <target/target_core_base.h> #include <target/target_core_base.h>
...@@ -855,7 +856,7 @@ int iscsit_setup_np( ...@@ -855,7 +856,7 @@ int iscsit_setup_np(
struct sockaddr_storage *sockaddr) struct sockaddr_storage *sockaddr)
{ {
struct socket *sock = NULL; struct socket *sock = NULL;
int backlog = ISCSIT_TCP_BACKLOG, ret, opt = 0, len; int backlog = ISCSIT_TCP_BACKLOG, ret, len;
switch (np->np_network_transport) { switch (np->np_network_transport) {
case ISCSI_TCP: case ISCSI_TCP:
...@@ -900,15 +901,7 @@ int iscsit_setup_np( ...@@ -900,15 +901,7 @@ int iscsit_setup_np(
if (np->np_network_transport == ISCSI_TCP) if (np->np_network_transport == ISCSI_TCP)
tcp_sock_set_nodelay(sock->sk); tcp_sock_set_nodelay(sock->sk);
sock_set_reuseaddr(sock->sk); sock_set_reuseaddr(sock->sk);
ip_sock_set_freebind(sock->sk);
opt = 1;
ret = kernel_setsockopt(sock, IPPROTO_IP, IP_FREEBIND,
(char *)&opt, sizeof(opt));
if (ret < 0) {
pr_err("kernel_setsockopt() for IP_FREEBIND"
" failed\n");
goto fail;
}
ret = kernel_bind(sock, (struct sockaddr *)&np->np_sockaddr, len); ret = kernel_bind(sock, (struct sockaddr *)&np->np_sockaddr, len);
if (ret < 0) { if (ret < 0) {
......
...@@ -765,6 +765,7 @@ static inline bool inetdev_valid_mtu(unsigned int mtu) ...@@ -765,6 +765,7 @@ static inline bool inetdev_valid_mtu(unsigned int mtu)
return likely(mtu >= IPV4_MIN_MTU); return likely(mtu >= IPV4_MIN_MTU);
} }
void ip_sock_set_freebind(struct sock *sk);
void ip_sock_set_tos(struct sock *sk, int val); void ip_sock_set_tos(struct sock *sk, int val);
#endif /* _IP_H */ #endif /* _IP_H */
...@@ -581,6 +581,14 @@ void ip_sock_set_tos(struct sock *sk, int val) ...@@ -581,6 +581,14 @@ void ip_sock_set_tos(struct sock *sk, int val)
} }
EXPORT_SYMBOL(ip_sock_set_tos); EXPORT_SYMBOL(ip_sock_set_tos);
void ip_sock_set_freebind(struct sock *sk)
{
lock_sock(sk);
inet_sk(sk)->freebind = true;
release_sock(sk);
}
EXPORT_SYMBOL(ip_sock_set_freebind);
/* /*
* Socket option code for IP. This is the end of the line after any * Socket option code for IP. This is the end of the line after any
* TCP,UDP etc options on an IP socket. * TCP,UDP etc options on an IP socket.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment