Skip to content

Commit

Permalink
rds: Remove IPv6 dependency
Browse files Browse the repository at this point in the history
This patch removes the IPv6 dependency from RDS.

Signed-off-by: Ka-Cheong Poon <[email protected]>
Acked-by: Santosh Shilimkar <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
kcp-git authored and davem330 committed Aug 1, 2018
1 parent f394ad2 commit e65d4d9
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 26 deletions.
2 changes: 1 addition & 1 deletion net/rds/Kconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

config RDS
tristate "The RDS Protocol"
depends on INET && IPV6
depends on INET
---help---
The RDS (Reliable Datagram Sockets) protocol provides reliable,
sequenced delivery of datagrams over Infiniband or TCP.
Expand Down
32 changes: 19 additions & 13 deletions net/rds/af_rds.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,20 @@ static int rds_getname(struct socket *sock, struct sockaddr *uaddr,
return sizeof(*sin);
}

if (ipv6_addr_type(&rs->rs_conn_addr) &
IPV6_ADDR_MAPPED) {
sin = (struct sockaddr_in *)uaddr;
memset(sin, 0, sizeof(*sin));
sin->sin_family = AF_INET;
return sizeof(*sin);
#if IS_ENABLED(CONFIG_IPV6)
if (!(ipv6_addr_type(&rs->rs_conn_addr) &
IPV6_ADDR_MAPPED)) {
sin6 = (struct sockaddr_in6 *)uaddr;
memset(sin6, 0, sizeof(*sin6));
sin6->sin6_family = AF_INET6;
return sizeof(*sin6);
}
#endif

sin6 = (struct sockaddr_in6 *)uaddr;
memset(sin6, 0, sizeof(*sin6));
sin6->sin6_family = AF_INET6;
return sizeof(*sin6);
sin = (struct sockaddr_in *)uaddr;
memset(sin, 0, sizeof(*sin));
sin->sin_family = AF_INET;
return sizeof(*sin);
}
if (ipv6_addr_v4mapped(&rs->rs_bound_addr)) {
sin = (struct sockaddr_in *)uaddr;
Expand Down Expand Up @@ -501,9 +503,7 @@ static int rds_connect(struct socket *sock, struct sockaddr *uaddr,
{
struct sock *sk = sock->sk;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
struct rds_sock *rs = rds_sk_to_rs(sk);
int addr_type;
int ret = 0;

lock_sock(sk);
Expand All @@ -528,7 +528,11 @@ static int rds_connect(struct socket *sock, struct sockaddr *uaddr,
rs->rs_conn_port = sin->sin_port;
break;

case AF_INET6:
#if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: {
struct sockaddr_in6 *sin6;
int addr_type;

sin6 = (struct sockaddr_in6 *)uaddr;
if (addr_len < sizeof(struct sockaddr_in6)) {
ret = -EINVAL;
Expand Down Expand Up @@ -575,6 +579,8 @@ static int rds_connect(struct socket *sock, struct sockaddr *uaddr,
rs->rs_conn_addr = sin6->sin6_addr;
rs->rs_conn_port = sin6->sin6_port;
break;
}
#endif

default:
ret = -EAFNOSUPPORT;
Expand Down
4 changes: 3 additions & 1 deletion net/rds/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
struct in6_addr v6addr, *binding_addr;
struct rds_transport *trans;
__u32 scope_id = 0;
int addr_type;
int ret = 0;
__be16 port;

Expand All @@ -183,8 +182,10 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &v6addr);
binding_addr = &v6addr;
port = sin->sin_port;
#if IS_ENABLED(CONFIG_IPV6)
} else if (uaddr->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)uaddr;
int addr_type;

if (addr_len < sizeof(struct sockaddr_in6))
return -EINVAL;
Expand Down Expand Up @@ -212,6 +213,7 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
}
binding_addr = &sin6->sin6_addr;
port = sin6->sin6_port;
#endif
} else {
return -EINVAL;
}
Expand Down
26 changes: 24 additions & 2 deletions net/rds/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ static struct hlist_head *rds_conn_bucket(const struct in6_addr *laddr,
net_get_random_once(&rds6_hash_secret, sizeof(rds6_hash_secret));

lhash = (__force u32)laddr->s6_addr32[3];
#if IS_ENABLED(CONFIG_IPV6)
fhash = __ipv6_addr_jhash(faddr, rds6_hash_secret);
hash = __inet6_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);
#else
fhash = (__force u32)faddr->s6_addr32[3];
#endif
hash = __inet_ehashfn(lhash, 0, fhash, 0, rds_hash_secret);

return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK];
}
Expand Down Expand Up @@ -201,6 +205,8 @@ static struct rds_connection *__rds_conn_create(struct net *net,
conn->c_isv6 = !ipv6_addr_v4mapped(laddr);
conn->c_faddr = *faddr;
conn->c_dev_if = dev_if;

#if IS_ENABLED(CONFIG_IPV6)
/* If the local address is link local, set c_bound_if to be the
* index used for this connection. Otherwise, set it to 0 as
* the socket is not bound to an interface. c_bound_if is used
Expand All @@ -209,6 +215,7 @@ static struct rds_connection *__rds_conn_create(struct net *net,
if (ipv6_addr_type(laddr) & IPV6_ADDR_LINKLOCAL)
conn->c_bound_if = dev_if;
else
#endif
conn->c_bound_if = 0;

rds_conn_net_set(conn, net);
Expand Down Expand Up @@ -500,9 +507,11 @@ static void __rds_inc_msg_cp(struct rds_incoming *inc,
struct rds_info_iterator *iter,
void *saddr, void *daddr, int flip, bool isv6)
{
#if IS_ENABLED(CONFIG_IPV6)
if (isv6)
rds6_inc_info_copy(inc, iter, saddr, daddr, flip);
else
#endif
rds_inc_info_copy(inc, iter, *(__be32 *)saddr,
*(__be32 *)daddr, flip);
}
Expand Down Expand Up @@ -581,13 +590,15 @@ static void rds_conn_message_info(struct socket *sock, unsigned int len,
rds_conn_message_info_cmn(sock, len, iter, lens, want_send, false);
}

#if IS_ENABLED(CONFIG_IPV6)
static void rds6_conn_message_info(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
struct rds_info_lengths *lens,
int want_send)
{
rds_conn_message_info_cmn(sock, len, iter, lens, want_send, true);
}
#endif

static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
Expand All @@ -596,12 +607,14 @@ static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
rds_conn_message_info(sock, len, iter, lens, 1);
}

#if IS_ENABLED(CONFIG_IPV6)
static void rds6_conn_message_info_send(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
struct rds_info_lengths *lens)
{
rds6_conn_message_info(sock, len, iter, lens, 1);
}
#endif

static void rds_conn_message_info_retrans(struct socket *sock,
unsigned int len,
Expand All @@ -611,13 +624,15 @@ static void rds_conn_message_info_retrans(struct socket *sock,
rds_conn_message_info(sock, len, iter, lens, 0);
}

#if IS_ENABLED(CONFIG_IPV6)
static void rds6_conn_message_info_retrans(struct socket *sock,
unsigned int len,
struct rds_info_iterator *iter,
struct rds_info_lengths *lens)
{
rds6_conn_message_info(sock, len, iter, lens, 0);
}
#endif

void rds_for_each_conn_info(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
Expand Down Expand Up @@ -734,6 +749,7 @@ static int rds_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
return 1;
}

#if IS_ENABLED(CONFIG_IPV6)
static int rds6_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
{
struct rds6_info_connection *cinfo6 = buffer;
Expand Down Expand Up @@ -761,6 +777,7 @@ static int rds6_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
*/
return 1;
}
#endif

static void rds_conn_info(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
Expand All @@ -774,6 +791,7 @@ static void rds_conn_info(struct socket *sock, unsigned int len,
sizeof(struct rds_info_connection));
}

#if IS_ENABLED(CONFIG_IPV6)
static void rds6_conn_info(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
struct rds_info_lengths *lens)
Expand All @@ -785,6 +803,7 @@ static void rds6_conn_info(struct socket *sock, unsigned int len,
buffer,
sizeof(struct rds6_info_connection));
}
#endif

int rds_conn_init(void)
{
Expand All @@ -807,12 +826,13 @@ int rds_conn_init(void)
rds_conn_message_info_send);
rds_info_register_func(RDS_INFO_RETRANS_MESSAGES,
rds_conn_message_info_retrans);
#if IS_ENABLED(CONFIG_IPV6)
rds_info_register_func(RDS6_INFO_CONNECTIONS, rds6_conn_info);
rds_info_register_func(RDS6_INFO_SEND_MESSAGES,
rds6_conn_message_info_send);
rds_info_register_func(RDS6_INFO_RETRANS_MESSAGES,
rds6_conn_message_info_retrans);

#endif
return 0;
}

Expand All @@ -830,11 +850,13 @@ void rds_conn_exit(void)
rds_conn_message_info_send);
rds_info_deregister_func(RDS_INFO_RETRANS_MESSAGES,
rds_conn_message_info_retrans);
#if IS_ENABLED(CONFIG_IPV6)
rds_info_deregister_func(RDS6_INFO_CONNECTIONS, rds6_conn_info);
rds_info_deregister_func(RDS6_INFO_SEND_MESSAGES,
rds6_conn_message_info_send);
rds_info_deregister_func(RDS6_INFO_RETRANS_MESSAGES,
rds6_conn_message_info_retrans);
#endif
}

/*
Expand Down
31 changes: 26 additions & 5 deletions net/rds/ib.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ static int rds_ib_conn_info_visitor(struct rds_connection *conn,
return 1;
}

#if IS_ENABLED(CONFIG_IPV6)
/* IPv6 version of rds_ib_conn_info_visitor(). */
static int rds6_ib_conn_info_visitor(struct rds_connection *conn,
void *buffer)
Expand Down Expand Up @@ -357,6 +358,7 @@ static int rds6_ib_conn_info_visitor(struct rds_connection *conn,
}
return 1;
}
#endif

static void rds_ib_ic_info(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
Expand All @@ -370,6 +372,7 @@ static void rds_ib_ic_info(struct socket *sock, unsigned int len,
sizeof(struct rds_info_rdma_connection));
}

#if IS_ENABLED(CONFIG_IPV6)
/* IPv6 version of rds_ib_ic_info(). */
static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
struct rds_info_iterator *iter,
Expand All @@ -382,6 +385,7 @@ static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
buffer,
sizeof(struct rds6_info_rdma_connection));
}
#endif

/*
* Early RDS/IB was built to only bind to an address if there is an IPoIB
Expand All @@ -398,7 +402,9 @@ static int rds_ib_laddr_check(struct net *net, const struct in6_addr *addr,
{
int ret;
struct rdma_cm_id *cm_id;
#if IS_ENABLED(CONFIG_IPV6)
struct sockaddr_in6 sin6;
#endif
struct sockaddr_in sin;
struct sockaddr *sa;
bool isv4;
Expand All @@ -418,6 +424,7 @@ static int rds_ib_laddr_check(struct net *net, const struct in6_addr *addr,
sin.sin_addr.s_addr = addr->s6_addr32[3];
sa = (struct sockaddr *)&sin;
} else {
#if IS_ENABLED(CONFIG_IPV6)
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = *addr;
Expand All @@ -432,21 +439,30 @@ static int rds_ib_laddr_check(struct net *net, const struct in6_addr *addr,
if (ipv6_addr_type(addr) & IPV6_ADDR_LINKLOCAL) {
struct net_device *dev;

if (scope_id == 0)
return -EADDRNOTAVAIL;
if (scope_id == 0) {
ret = -EADDRNOTAVAIL;
goto out;
}

/* Use init_net for now as RDS is not network
* name space aware.
*/
dev = dev_get_by_index(&init_net, scope_id);
if (!dev)
return -EADDRNOTAVAIL;
if (!dev) {
ret = -EADDRNOTAVAIL;
goto out;
}
if (!ipv6_chk_addr(&init_net, addr, dev, 1)) {
dev_put(dev);
return -EADDRNOTAVAIL;
ret = -EADDRNOTAVAIL;
goto out;
}
dev_put(dev);
}
#else
ret = -EADDRNOTAVAIL;
goto out;
#endif
}

/* rdma_bind_addr will only succeed for IB & iWARP devices */
Expand All @@ -461,6 +477,7 @@ static int rds_ib_laddr_check(struct net *net, const struct in6_addr *addr,
addr, scope_id, ret,
cm_id->device ? cm_id->device->node_type : -1);

out:
rdma_destroy_id(cm_id);

return ret;
Expand Down Expand Up @@ -491,7 +508,9 @@ void rds_ib_exit(void)
rds_ib_set_unloading();
synchronize_rcu();
rds_info_deregister_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
#if IS_ENABLED(CONFIG_IPV6)
rds_info_deregister_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
#endif
rds_ib_unregister_client();
rds_ib_destroy_nodev_conns();
rds_ib_sysctl_exit();
Expand Down Expand Up @@ -553,7 +572,9 @@ int rds_ib_init(void)
rds_trans_register(&rds_ib_transport);

rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
#if IS_ENABLED(CONFIG_IPV6)
rds_info_register_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
#endif

goto out;

Expand Down
Loading

0 comments on commit e65d4d9

Please sign in to comment.