LNet/socklnd often uses __u32 to hold an ipv4 address.
As we want to extend socklnd to work with IPv6 addresses too,
this needs to change.
This patch changes many __u32s to variants of 'struct sockaddr'.
Library code from sunrpc is used for copying and comparing addresses
rpc_copy_addr() and rpc_cmp_addr()
and for extracting or setting the port:
rpc_get_port() and rpc_set_port().
The "%pIS" printf format is used for printing a sockaddr (works for
both IPv4 and IPv6), and "%pISp" for printing the address with the
port.
The __u32 is in host-byte-order, while addresses in sockaddr are
always network-order, so htonl and ntohl are used as needed.
When storing an address (e.g. in a structure), 'struct
sockaddr_storage' is used. When passing an address to a function,
'struct sockaddr' is used. When an address is known to be IPv4 (i.e.
when converting to or from __u32), 'struct sockaddr_in' is used.
The following functions are changed to take a 'struct sockaddr*'
argument:
lnet_connect()
lnet_connect_console_error()
lnet_sock_getaddr()
ksocknal_ip2iface()
ksocknal_ip2index()
ksocknal_create_route()
ksocknal_connecting()
ksocknal_close_peer_conns_locked()
ksocknal_peer_del_interface_locked()
The following structures have had fields changed to 'struct
sockaddr_storage'
struct ksock_interface:
ksni_ipaddr -> ksni_addr
struct ksock_conn
ksnc_myipaddr -> ksnc_myaddr
ksnc_ipaddr and ksnc_port -> ksnc_peeraddr
struct ksock_route
ksnr_myipaddr -> ksnr_myaddr
ksnr_ipaddr and ksnr_port -> ksnr_addr
Assorted strings have been joined onto a single line, and various
indented have been changed from space to tabs.
There should be no behaviour changes, though the structures mentioned
above will now be a little larger.
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I42d12260185638407b5b611391fc69bfd9f91754
Reviewed-on: https://review.whamcloud.com/37704
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Aurelien Degremont <degremoa@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
void lnet_register_lnd(const struct lnet_lnd *lnd);
void lnet_unregister_lnd(const struct lnet_lnd *lnd);
-struct socket *lnet_connect(lnet_nid_t peer_nid, int interface, __u32 peer_ip,
- int peer_port, struct net *ns);
+struct socket *lnet_connect(lnet_nid_t peer_nid, int interface,
+ struct sockaddr *peeraddr, struct net *ns);
void lnet_connect_console_error(int rc, lnet_nid_t peer_nid,
- __u32 peer_ip, int port);
+ struct sockaddr *sa);
int lnet_count_acceptor_nets(void);
int lnet_acceptor_timeout(void);
int lnet_acceptor_port(void);
int lnet_inet_enumerate(struct lnet_inetdev **dev_list, struct net *ns);
int lnet_sock_setbuf(struct socket *socket, int txbufsize, int rxbufsize);
int lnet_sock_getbuf(struct socket *socket, int *txbufsize, int *rxbufsize);
-int lnet_sock_getaddr(struct socket *socket, bool remote, __u32 *ip, int *port);
+int lnet_sock_getaddr(struct socket *socket, bool remote,
+ struct sockaddr_storage *peer);
int lnet_sock_write(struct socket *sock, void *buffer, int nob, int timeout);
int lnet_sock_read(struct socket *sock, void *buffer, int nob, int timeout);
#include <linux/inetdevice.h>
#include "socklnd.h"
+#include <linux/sunrpc/addr.h>
static const struct lnet_lnd the_ksocklnd;
struct ksock_nal_data ksocknal_data;
static struct ksock_interface *
-ksocknal_ip2iface(struct lnet_ni *ni, __u32 ip)
+ksocknal_ip2iface(struct lnet_ni *ni, struct sockaddr *addr)
{
struct ksock_net *net = ni->ni_data;
int i;
LASSERT(i < LNET_INTERFACES_NUM);
iface = &net->ksnn_interfaces[i];
- if (iface->ksni_ipaddr == ip)
+ if (rpc_cmp_addr((struct sockaddr *)&iface->ksni_addr, addr))
return iface;
}
return NULL;
}
-static int ksocknal_ip2index(__u32 ipaddress, struct lnet_ni *ni)
+static int ksocknal_ip2index(struct sockaddr *addr, struct lnet_ni *ni)
{
struct net_device *dev;
int ret = -1;
DECLARE_CONST_IN_IFADDR(ifa);
+ if (addr->sa_family != AF_INET)
+ /* No IPv6 support yet */
+ return ret;
+
rcu_read_lock();
for_each_netdev(ni->ni_net_ns, dev) {
int flags = dev_get_flags(dev);
continue;
in_dev_for_each_ifa_rcu(ifa, in_dev) {
- if (ntohl(ifa->ifa_local) == ipaddress)
+ if (ifa->ifa_local ==
+ ((struct sockaddr_in *)addr)->sin_addr.s_addr)
ret = dev->ifindex;
}
endfor_ifa(in_dev);
}
static struct ksock_route *
-ksocknal_create_route(__u32 ipaddr, int port)
+ksocknal_create_route(struct sockaddr *addr)
{
struct ksock_route *route;
refcount_set(&route->ksnr_refcount, 1);
route->ksnr_peer = NULL;
route->ksnr_retry_interval = 0; /* OK to connect at any time */
- route->ksnr_ipaddr = ipaddr;
+ rpc_copy_addr((struct sockaddr *)&route->ksnr_addr, addr);
+ rpc_set_port((struct sockaddr *)&route->ksnr_addr, rpc_get_port(addr));
route->ksnr_myiface = -1;
- route->ksnr_port = port;
route->ksnr_scheduled = 0;
route->ksnr_connecting = 0;
route->ksnr_connected = 0;
ksocknal_unlink_peer_locked(struct ksock_peer_ni *peer_ni)
{
int i;
- __u32 ip;
struct ksock_interface *iface;
for (i = 0; i < peer_ni->ksnp_n_passive_ips; i++) {
+ struct sockaddr_in sa = { .sin_family = AF_INET };
LASSERT(i < LNET_INTERFACES_NUM);
- ip = peer_ni->ksnp_passive_ips[i];
+ sa.sin_addr.s_addr = htonl(peer_ni->ksnp_passive_ips[i]);
- iface = ksocknal_ip2iface(peer_ni->ksnp_ni, ip);
+ iface = ksocknal_ip2iface(peer_ni->ksnp_ni,
+ (struct sockaddr *)&sa);
/*
* All IPs in peer_ni->ksnp_passive_ips[] come from the
* interface list, therefore the call must succeed.
ksnr_list);
*id = peer_ni->ksnp_id;
- rc = choose_ipv4_src(myip, route->ksnr_myiface,
- route->ksnr_ipaddr,
- ni->ni_net_ns);
- *peer_ip = route->ksnr_ipaddr;
- *port = route->ksnr_port;
+ if (route->ksnr_addr.ss_family == AF_INET) {
+ struct sockaddr_in *sa =
+ (void *)&route->ksnr_addr;
+ rc = choose_ipv4_src(
+ myip,
+ route->ksnr_myiface,
+ ntohl(sa->sin_addr.s_addr),
+ ni->ni_net_ns);
+ *peer_ip = ntohl(sa->sin_addr.s_addr);
+ *port = ntohs(sa->sin_port);
+ } else {
+ *myip = 0xFFFFFFFF;
+ *peer_ip = 0xFFFFFFFF;
+ *port = 0;
+ rc = -ENOTSUPP;
+ }
*conn_count = route->ksnr_conn_count;
*share_count = route->ksnr_share_count;
goto out;
struct ksock_peer_ni *peer_ni = route->ksnr_peer;
int type = conn->ksnc_type;
struct ksock_interface *iface;
- int conn_iface = ksocknal_ip2index(conn->ksnc_myipaddr,
- route->ksnr_peer->ksnp_ni);
+ int conn_iface =
+ ksocknal_ip2index((struct sockaddr *)&conn->ksnc_myaddr,
+ route->ksnr_peer->ksnp_ni);
conn->ksnc_route = route;
ksocknal_route_addref(route);
if (route->ksnr_myiface != conn_iface) {
if (route->ksnr_myiface < 0) {
/* route wasn't bound locally yet (the initial route) */
- CDEBUG(D_NET, "Binding %s %pI4h to interface %d\n",
+ CDEBUG(D_NET, "Binding %s %pIS to interface %d\n",
libcfs_id2str(peer_ni->ksnp_id),
- &route->ksnr_ipaddr,
+ &route->ksnr_addr,
conn_iface);
} else {
CDEBUG(D_NET,
- "Rebinding %s %pI4h from interface %d to %d\n",
+ "Rebinding %s %pIS from interface %d to %d\n",
libcfs_id2str(peer_ni->ksnp_id),
- &route->ksnr_ipaddr,
+ &route->ksnr_addr,
route->ksnr_myiface,
conn_iface);
list_for_each(tmp, &peer_ni->ksnp_routes) {
route2 = list_entry(tmp, struct ksock_route, ksnr_list);
- if (route2->ksnr_ipaddr == route->ksnr_ipaddr) {
+ if (rpc_cmp_addr((struct sockaddr *)&route2->ksnr_addr,
+ (struct sockaddr *)&route->ksnr_addr)) {
CERROR("Duplicate route %s %pI4h\n",
libcfs_id2str(peer_ni->ksnp_id),
- &route->ksnr_ipaddr);
+ &route->ksnr_addr);
LBUG();
}
}
list_for_each(tmp, &peer_ni->ksnp_conns) {
conn = list_entry(tmp, struct ksock_conn, ksnc_list);
- if (conn->ksnc_ipaddr != route->ksnr_ipaddr)
+ if (!rpc_cmp_addr((struct sockaddr *)&conn->ksnc_peeraddr,
+ (struct sockaddr *)&route->ksnr_addr))
continue;
ksocknal_associate_route_conn_locked(route, conn);
struct ksock_peer_ni *peer2;
struct ksock_route *route;
struct ksock_route *route2;
+ struct sockaddr_in sa = {.sin_family = AF_INET};
if (id.nid == LNET_NID_ANY ||
id.pid == LNET_PID_ANY)
if (IS_ERR(peer_ni))
return PTR_ERR(peer_ni);
- route = ksocknal_create_route (ipaddr, port);
+ sa.sin_addr.s_addr = htonl(ipaddr);
+ sa.sin_port = htons(port);
+ route = ksocknal_create_route((struct sockaddr *)&sa);
if (route == NULL) {
ksocknal_peer_decref(peer_ni);
return (-ENOMEM);
list_for_each(tmp, &peer_ni->ksnp_routes) {
route2 = list_entry(tmp, struct ksock_route, ksnr_list);
- if (route2->ksnr_ipaddr == ipaddr)
+ if (route2->ksnr_addr.ss_family == AF_INET &&
+ ((struct sockaddr_in *)&route2->ksnr_addr)->sin_addr.s_addr
+ == htonl(ipaddr))
break;
route2 = NULL;
list_for_each_entry_safe(route, rnxt, &peer_ni->ksnp_routes,
ksnr_list) {
/* no match */
- if (!(ip == 0 || route->ksnr_ipaddr == ip))
- continue;
+ if (ip) {
+ if (route->ksnr_addr.ss_family != AF_INET)
+ continue;
+ if (((struct sockaddr_in *)&route->ksnr_addr)
+ ->sin_addr.s_addr != htonl(ip))
+ continue;
+ }
route->ksnr_share_count = 0;
/* This deletes associated conns too */
ksocknal_local_ipvec(struct lnet_ni *ni, __u32 *ipaddrs)
{
struct ksock_net *net = ni->ni_data;
- int i;
+ int i, j;
int nip;
read_lock(&ksocknal_data.ksnd_global_lock);
nip = net->ksnn_ninterfaces;
LASSERT(nip <= LNET_INTERFACES_NUM);
+ for (i = 0, j = 0; i < nip; i++)
+ if (net->ksnn_interfaces[i].ksni_addr.ss_family == AF_INET) {
+ struct sockaddr_in *sa =
+ (void *)&net->ksnn_interfaces[i].ksni_addr;
+
+ ipaddrs[j] = ntohl(sa->sin_addr.s_addr);
+ LASSERT(ipaddrs[j] != 0);
+ j += 1;
+ }
+ nip = j;
+
+ read_unlock(&ksocknal_data.ksnd_global_lock);
/*
* Only offer interfaces for additional connections if I have
* more than one.
*/
- if (nip < 2) {
- read_unlock(&ksocknal_data.ksnd_global_lock);
- return 0;
- }
-
- for (i = 0; i < nip; i++) {
- ipaddrs[i] = net->ksnn_interfaces[i].ksni_ipaddr;
- LASSERT(ipaddrs[i] != 0);
- }
-
- read_unlock(&ksocknal_data.ksnd_global_lock);
- return nip;
+ return nip < 2 ? 0 : nip;
}
static int
int this_xor;
int this_netmatch;
int i;
+ struct sockaddr_in *sa;
+ __u32 ip;
- for (i = 0; i < nips; i++) {
- if (ips[i] == 0)
- continue;
+ sa = (struct sockaddr_in *)&iface->ksni_addr;
+ LASSERT(sa->sin_family == AF_INET);
+ ip = ntohl(sa->sin_addr.s_addr);
- this_xor = (ips[i] ^ iface->ksni_ipaddr);
- this_netmatch = ((this_xor & iface->ksni_netmask) == 0) ? 1 : 0;
+ for (i = 0; i < nips; i++) {
+ if (ips[i] == 0)
+ continue;
- if (!(best < 0 ||
- best_netmatch < this_netmatch ||
- (best_netmatch == this_netmatch &&
- best_xor > this_xor)))
- continue;
+ this_xor = ips[i] ^ ip;
+ this_netmatch = ((this_xor & iface->ksni_netmask) == 0) ? 1 : 0;
- best = i;
- best_netmatch = this_netmatch;
- best_xor = this_xor;
- }
+ if (!(best < 0 ||
+ best_netmatch < this_netmatch ||
+ (best_netmatch == this_netmatch &&
+ best_xor > this_xor)))
+ continue;
- LASSERT (best >= 0);
- return (best);
+ best = i;
+ best_netmatch = this_netmatch;
+ best_xor = this_xor;
+ }
+
+ LASSERT(best >= 0);
+ return best;
}
static int
* We don't forget interfaces we've stopped using; we might
* start using them again... */
- if (i < peer_ni->ksnp_n_passive_ips) {
- /* Old interface. */
- ip = peer_ni->ksnp_passive_ips[i];
- best_iface = ksocknal_ip2iface(peer_ni->ksnp_ni, ip);
+ if (i < peer_ni->ksnp_n_passive_ips) {
+ /* Old interface. */
+ struct sockaddr_in sa = { .sin_family = AF_INET};
+
+ sa.sin_addr.s_addr =
+ htonl(peer_ni->ksnp_passive_ips[i]);
+ best_iface = ksocknal_ip2iface(peer_ni->ksnp_ni,
+ (struct sockaddr *)&sa);
- /* peer_ni passive ips are kept up to date */
- LASSERT(best_iface != NULL);
+ /* peer_ni passive ips are kept up to date */
+ LASSERT(best_iface != NULL);
} else {
/* choose a new interface */
+ struct sockaddr_in *sa;
+
LASSERT (i == peer_ni->ksnp_n_passive_ips);
best_iface = NULL;
best_netmatch = 0;
best_npeers = 0;
- for (j = 0; j < net->ksnn_ninterfaces; j++) {
- iface = &net->ksnn_interfaces[j];
- ip = iface->ksni_ipaddr;
+ for (j = 0; j < net->ksnn_ninterfaces; j++) {
+ iface = &net->ksnn_interfaces[j];
+ sa = (void *)&iface->ksni_addr;
+ if (sa->sin_family != AF_INET)
+ continue;
+ ip = ntohl(sa->sin_addr.s_addr);
for (k = 0; k < peer_ni->ksnp_n_passive_ips; k++)
if (peer_ni->ksnp_passive_ips[k] == ip)
LASSERT(best_iface != NULL);
- best_iface->ksni_npeers++;
- ip = best_iface->ksni_ipaddr;
- peer_ni->ksnp_passive_ips[i] = ip;
- peer_ni->ksnp_n_passive_ips = i+1;
+ best_iface->ksni_npeers++;
+ sa = (void *)&best_iface->ksni_addr;
+ ip = ntohl(sa->sin_addr.s_addr);
+ peer_ni->ksnp_passive_ips[i] = ip;
+ peer_ni->ksnp_n_passive_ips = i+1;
}
/* mark the best matching peer_ni IP used */
LASSERT(npeer_ipaddrs <= LNET_INTERFACES_NUM);
- for (i = 0; i < npeer_ipaddrs; i++) {
- if (newroute != NULL) {
- newroute->ksnr_ipaddr = peer_ipaddrs[i];
- } else {
+ for (i = 0; i < npeer_ipaddrs; i++) {
+ if (newroute) {
+ struct sockaddr_in *sa = (void *)&newroute->ksnr_addr;
+
+ memset(sa, 0, sizeof(*sa));
+ sa->sin_family = AF_INET;
+ sa->sin_addr.s_addr = htonl(peer_ipaddrs[i]);
+ } else {
+ struct sockaddr_in sa = {.sin_family = AF_INET};
+
write_unlock_bh(global_lock);
- newroute = ksocknal_create_route(peer_ipaddrs[i], port);
- if (newroute == NULL)
- return;
+ sa.sin_addr.s_addr = htonl(peer_ipaddrs[i]);
+ sa.sin_port = htons(port);
+ newroute =
+ ksocknal_create_route((struct sockaddr *)&sa);
+ if (!newroute)
+ return;
write_lock_bh(global_lock);
- }
+ }
- if (peer_ni->ksnp_closing) {
- /* peer_ni got closed under me */
- break;
- }
+ if (peer_ni->ksnp_closing) {
+ /* peer_ni got closed under me */
+ break;
+ }
/* Already got a route? */
route = NULL;
list_for_each(rtmp, &peer_ni->ksnp_routes) {
route = list_entry(rtmp, struct ksock_route, ksnr_list);
- if (route->ksnr_ipaddr == newroute->ksnr_ipaddr)
+ if (rpc_cmp_addr(
+ (struct sockaddr *)&route->ksnr_addr,
+ (struct sockaddr *)&newroute->ksnr_addr))
break;
route = NULL;
/* Select interface to connect from */
for (j = 0; j < net->ksnn_ninterfaces; j++) {
+ __u32 iface_ip, route_ip;
+
iface = &net->ksnn_interfaces[j];
/* Using this interface already? */
}
if (route != NULL)
continue;
+ if (iface->ksni_addr.ss_family != AF_INET)
+ continue;
+ if (newroute->ksnr_addr.ss_family != AF_INET)
+ continue;
- this_netmatch = (((iface->ksni_ipaddr ^
- newroute->ksnr_ipaddr) &
+ iface_ip =
+ ntohl(((struct sockaddr_in *)
+ &iface->ksni_addr)->sin_addr.s_addr);
+ route_ip =
+ ntohl(((struct sockaddr_in *)
+ &newroute->ksnr_addr)->sin_addr.s_addr);
+
+ this_netmatch = (((iface_ip ^ route_ip) &
iface->ksni_netmask) == 0) ? 1 : 0;
if (!(best_iface == NULL ||
{
struct ksock_connreq *cr;
int rc;
- u32 peer_ip;
- int peer_port;
+ struct sockaddr_storage peer;
- rc = lnet_sock_getaddr(sock, true, &peer_ip, &peer_port);
+ rc = lnet_sock_getaddr(sock, true, &peer);
LASSERT(rc == 0); /* we succeeded before */
LIBCFS_ALLOC(cr, sizeof(*cr));
if (cr == NULL) {
- LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from "
- "%pI4h: memory exhausted\n", &peer_ip);
+ LCONSOLE_ERROR_MSG(0x12f,
+ "Dropping connection request from %pIS: memory exhausted\n",
+ &peer);
return -ENOMEM;
}
}
static int
-ksocknal_connecting(struct ksock_peer_ni *peer_ni, __u32 ipaddr)
+ksocknal_connecting(struct ksock_peer_ni *peer_ni, struct sockaddr *sa)
{
struct ksock_route *route;
list_for_each_entry(route, &peer_ni->ksnp_routes, ksnr_list) {
- if (route->ksnr_ipaddr == ipaddr)
+ if (rpc_cmp_addr((struct sockaddr *)&route->ksnr_addr, sa))
return route->ksnr_connecting;
}
return 0;
ksocknal_peer_addref(peer_ni);
peer_ni->ksnp_accepting++;
- /* Am I already connecting to this guy? Resolve in
- * favour of higher NID... */
- if (peerid.nid < ni->ni_nid &&
- ksocknal_connecting(peer_ni, conn->ksnc_ipaddr)) {
- rc = EALREADY;
- warn = "connection race resolution";
- goto failed_2;
- }
+ /* Am I already connecting to this guy? Resolve in
+ * favour of higher NID...
+ */
+ if (peerid.nid < ni->ni_nid &&
+ ksocknal_connecting(peer_ni, ((struct sockaddr *)
+ &conn->ksnc_peeraddr))) {
+ rc = EALREADY;
+ warn = "connection race resolution";
+ goto failed_2;
+ }
}
if (peer_ni->ksnp_closing ||
peer_ni->ksnp_incarnation = incarnation;
}
- if (peer_ni->ksnp_proto != conn->ksnc_proto ||
- peer_ni->ksnp_incarnation != incarnation) {
- /* peer_ni rebooted or I've got the wrong protocol version */
- ksocknal_close_peer_conns_locked(peer_ni, 0, 0);
+ if (peer_ni->ksnp_proto != conn->ksnc_proto ||
+ peer_ni->ksnp_incarnation != incarnation) {
+ /* peer_ni rebooted or I've got the wrong protocol version */
+ ksocknal_close_peer_conns_locked(peer_ni, NULL, 0);
- peer_ni->ksnp_proto = NULL;
- rc = ESTALE;
- warn = peer_ni->ksnp_incarnation != incarnation ?
- "peer_ni rebooted" :
- "wrong proto version";
- goto failed_2;
- }
+ peer_ni->ksnp_proto = NULL;
+ rc = ESTALE;
+ warn = peer_ni->ksnp_incarnation != incarnation ?
+ "peer_ni rebooted" :
+ "wrong proto version";
+ goto failed_2;
+ }
switch (rc) {
default:
/* Refuse to duplicate an existing connection, unless this is a
* loopback connection */
- if (conn->ksnc_ipaddr != conn->ksnc_myipaddr) {
+ if (!rpc_cmp_addr((struct sockaddr *)&conn->ksnc_peeraddr,
+ (struct sockaddr *)&conn->ksnc_myaddr)) {
list_for_each(tmp, &peer_ni->ksnp_conns) {
conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
- if (conn2->ksnc_ipaddr != conn->ksnc_ipaddr ||
- conn2->ksnc_myipaddr != conn->ksnc_myipaddr ||
- conn2->ksnc_type != conn->ksnc_type)
- continue;
+ if (!rpc_cmp_addr(
+ (struct sockaddr *)&conn2->ksnc_peeraddr,
+ (struct sockaddr *)&conn->ksnc_peeraddr) ||
+ !rpc_cmp_addr(
+ (struct sockaddr *)&conn2->ksnc_myaddr,
+ (struct sockaddr *)&conn->ksnc_myaddr) ||
+ conn2->ksnc_type != conn->ksnc_type)
+ continue;
/* Reply on a passive connection attempt so the peer_ni
* realises we're connected. */
* address the route connected to, the connection/route matching
* code below probably isn't going to work. */
if (active &&
- route->ksnr_ipaddr != conn->ksnc_ipaddr) {
- CERROR("Route %s %pI4h connected to %pI4h\n",
- libcfs_id2str(peer_ni->ksnp_id),
- &route->ksnr_ipaddr,
- &conn->ksnc_ipaddr);
+ !rpc_cmp_addr((struct sockaddr *)&route->ksnr_addr,
+ (struct sockaddr *)&conn->ksnc_peeraddr)) {
+ CERROR("Route %s %pIS connected to %pIS\n",
+ libcfs_id2str(peer_ni->ksnp_id),
+ &route->ksnr_addr,
+ &conn->ksnc_peeraddr);
}
/* Search for a route corresponding to the new connection and
list_for_each(tmp, &peer_ni->ksnp_routes) {
route = list_entry(tmp, struct ksock_route, ksnr_list);
- if (route->ksnr_ipaddr != conn->ksnc_ipaddr)
+ if (!rpc_cmp_addr((struct sockaddr *)&route->ksnr_addr,
+ (struct sockaddr *)&conn->ksnc_peeraddr))
continue;
ksocknal_associate_route_conn_locked(route, conn);
* socket callbacks.
*/
- CDEBUG(D_NET, "New conn %s p %d.x %pI4h -> %pI4h/%d"
+ CDEBUG(D_NET, "New conn %s p %d.x %pIS -> %pISp"
" incarnation:%lld sched[%d]\n",
libcfs_id2str(peerid), conn->ksnc_proto->pro_version,
- &conn->ksnc_myipaddr, &conn->ksnc_ipaddr,
- conn->ksnc_port, incarnation, cpt);
+ &conn->ksnc_myaddr, &conn->ksnc_peeraddr,
+ incarnation, cpt);
- if (active) {
- /* additional routes after interface exchange? */
- ksocknal_create_routes(peer_ni, conn->ksnc_port,
- hello->kshm_ips, hello->kshm_nips);
+ if (active) {
+ /* additional routes after interface exchange? */
+ ksocknal_create_routes(
+ peer_ni,
+ rpc_get_port((struct sockaddr *)&conn->ksnc_peeraddr),
+ hello->kshm_ips, hello->kshm_nips);
} else {
hello->kshm_nips = ksocknal_select_ips(peer_ni, hello->kshm_ips,
hello->kshm_nips);
case SOCKNAL_RX_LNET_PAYLOAD:
last_rcv = conn->ksnc_rx_deadline -
ksocknal_timeout();
- CERROR("Completing partial receive from %s[%d], "
- "ip %pI4h:%d, with error, wanted: %d, left: %d, "
- "last alive is %lld secs ago\n",
+ CERROR("Completing partial receive from %s[%d], ip %pISp, with error, wanted: %d, left: %d, last alive is %lld secs ago\n",
libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type,
- &conn->ksnc_ipaddr, conn->ksnc_port,
+ &conn->ksnc_peeraddr,
conn->ksnc_rx_nob_wanted, conn->ksnc_rx_nob_left,
ktime_get_seconds() - last_rcv);
if (conn->ksnc_lnet_msg)
LNET_MSG_STATUS_REMOTE_ERROR;
lnet_finalize(conn->ksnc_lnet_msg, -EIO);
break;
- case SOCKNAL_RX_LNET_HEADER:
- if (conn->ksnc_rx_started)
- CERROR("Incomplete receive of lnet header from %s, "
- "ip %pI4h:%d, with error, protocol: %d.x.\n",
- libcfs_id2str(conn->ksnc_peer->ksnp_id),
- &conn->ksnc_ipaddr, conn->ksnc_port,
- conn->ksnc_proto->pro_version);
- break;
+ case SOCKNAL_RX_LNET_HEADER:
+ if (conn->ksnc_rx_started)
+ CERROR("Incomplete receive of lnet header from %s, ip %pISp, with error, protocol: %d.x.\n",
+ libcfs_id2str(conn->ksnc_peer->ksnp_id),
+ &conn->ksnc_peeraddr,
+ conn->ksnc_proto->pro_version);
+ break;
case SOCKNAL_RX_KSM_HEADER:
if (conn->ksnc_rx_started)
- CERROR("Incomplete receive of ksock message from %s, "
- "ip %pI4h:%d, with error, protocol: %d.x.\n",
- libcfs_id2str(conn->ksnc_peer->ksnp_id),
- &conn->ksnc_ipaddr, conn->ksnc_port,
- conn->ksnc_proto->pro_version);
+ CERROR("Incomplete receive of ksock message from %s, ip %pISp, with error, protocol: %d.x.\n",
+ libcfs_id2str(conn->ksnc_peer->ksnp_id),
+ &conn->ksnc_peeraddr,
+ conn->ksnc_proto->pro_version);
break;
case SOCKNAL_RX_SLOP:
if (conn->ksnc_rx_started)
- CERROR("Incomplete receive of slops from %s, "
- "ip %pI4h:%d, with error\n",
- libcfs_id2str(conn->ksnc_peer->ksnp_id),
- &conn->ksnc_ipaddr, conn->ksnc_port);
+ CERROR("Incomplete receive of slops from %s, ip %pISp, with error\n",
+ libcfs_id2str(conn->ksnc_peer->ksnp_id),
+ &conn->ksnc_peeraddr);
break;
default:
LBUG ();
}
int
-ksocknal_close_peer_conns_locked(struct ksock_peer_ni *peer_ni, __u32 ipaddr, int why)
+ksocknal_close_peer_conns_locked(struct ksock_peer_ni *peer_ni,
+ struct sockaddr *addr, int why)
{
struct ksock_conn *conn;
struct ksock_conn *cnxt;
int count = 0;
list_for_each_entry_safe(conn, cnxt, &peer_ni->ksnp_conns, ksnc_list) {
- if (ipaddr == 0 ||
- conn->ksnc_ipaddr == ipaddr) {
- count++;
- ksocknal_close_conn_locked (conn, why);
- }
- }
+ if (!addr ||
+ rpc_cmp_addr(addr,
+ (struct sockaddr *)&conn->ksnc_peeraddr)) {
+ count++;
+ ksocknal_close_conn_locked(conn, why);
+ }
+ }
- return (count);
+ return count;
}
int
ksocknal_close_conn_and_siblings(struct ksock_conn *conn, int why)
{
struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
- u32 ipaddr = conn->ksnc_ipaddr;
int count;
write_lock_bh(&ksocknal_data.ksnd_global_lock);
- count = ksocknal_close_peer_conns_locked (peer_ni, ipaddr, why);
+ count = ksocknal_close_peer_conns_locked(
+ peer_ni, (struct sockaddr *)&conn->ksnc_peeraddr, why);
write_unlock_bh(&ksocknal_data.ksnd_global_lock);
- return (count);
+ return count;
}
int
int hi;
int i;
int count = 0;
+ struct sockaddr_in sa = {.sin_family = AF_INET};
write_lock_bh(&ksocknal_data.ksnd_global_lock);
hi = HASH_SIZE(ksocknal_data.ksnd_peers) - 1;
}
+ sa.sin_addr.s_addr = htonl(ipaddr);
for (i = lo; i <= hi; i++) {
hlist_for_each_entry_safe(peer_ni, pnxt,
&ksocknal_data.ksnd_peers[i],
id.pid == peer_ni->ksnp_id.pid)))
continue;
- count += ksocknal_close_peer_conns_locked(peer_ni,
- ipaddr, 0);
+ count += ksocknal_close_peer_conns_locked(
+ peer_ni,
+ ipaddr ? (struct sockaddr *)&sa : NULL, 0);
}
}
{
struct ksock_net *net = ni->ni_data;
struct ksock_interface *iface;
+ struct sockaddr_in sa = { .sin_family = AF_INET };
int rc;
int i;
int j;
write_lock_bh(&ksocknal_data.ksnd_global_lock);
- iface = ksocknal_ip2iface(ni, ipaddress);
+ sa.sin_addr.s_addr = htonl(ipaddress);
+ iface = ksocknal_ip2iface(ni, (struct sockaddr *)&sa);
if (iface != NULL) {
/* silently ignore dups */
rc = 0;
} else {
iface = &net->ksnn_interfaces[net->ksnn_ninterfaces++];
- iface->ksni_index = ksocknal_ip2index(ipaddress, ni);
- iface->ksni_ipaddr = ipaddress;
+ iface->ksni_index = ksocknal_ip2index((struct sockaddr *)&sa,
+ ni);
+ rpc_copy_addr((struct sockaddr *)&iface->ksni_addr,
+ (struct sockaddr *)&sa);
iface->ksni_netmask = netmask;
iface->ksni_nroutes = 0;
iface->ksni_npeers = 0;
}
list_for_each_entry_safe(conn, cnxt, &peer_ni->ksnp_conns, ksnc_list)
- if (conn->ksnc_myipaddr == ipaddr)
- ksocknal_close_conn_locked (conn, 0);
+ if (conn->ksnc_route->ksnr_myiface == index)
+ ksocknal_close_conn_locked (conn, 0);
}
static int
struct hlist_node *nxt;
struct ksock_peer_ni *peer_ni;
u32 this_ip;
+ struct sockaddr_in sa = {.sin_family = AF_INET };
int index;
int i;
int j;
- index = ksocknal_ip2index(ipaddress, ni);
+ sa.sin_addr.s_addr = htonl(ipaddress);
+ index = ksocknal_ip2index((struct sockaddr *)&sa, ni);
write_lock_bh(&ksocknal_data.ksnd_global_lock);
for (i = 0; i < net->ksnn_ninterfaces; i++) {
- this_ip = net->ksnn_interfaces[i].ksni_ipaddr;
+ struct sockaddr_in *sa =
+ (void *)&net->ksnn_interfaces[i].ksni_addr;
+
+ if (sa->sin_family != AF_INET)
+ continue;
+ this_ip = ntohl(sa->sin_addr.s_addr);
if (!(ipaddress == 0 ||
ipaddress == this_ip))
case IOC_LIBCFS_GET_INTERFACE: {
struct ksock_net *net = ni->ni_data;
struct ksock_interface *iface;
+ struct sockaddr_in *sa;
read_lock(&ksocknal_data.ksnd_global_lock);
rc = 0;
iface = &net->ksnn_interfaces[data->ioc_count];
- data->ioc_u32[0] = iface->ksni_ipaddr;
- data->ioc_u32[1] = iface->ksni_netmask;
- data->ioc_u32[2] = iface->ksni_npeers;
- data->ioc_u32[3] = iface->ksni_nroutes;
- }
+ sa = (void *)&iface->ksni_addr;
+ if (sa->sin_family == AF_INET)
+ data->ioc_u32[0] = ntohl(sa->sin_addr.s_addr);
+ else
+ data->ioc_u32[0] = 0xFFFFFFFF;
+ data->ioc_u32[1] = iface->ksni_netmask;
+ data->ioc_u32[2] = iface->ksni_npeers;
+ data->ioc_u32[3] = iface->ksni_nroutes;
+ }
read_unlock(&ksocknal_data.ksnd_global_lock);
return rc;
int rxmem;
int nagle;
struct ksock_conn *conn = ksocknal_get_conn_by_idx(ni, data->ioc_count);
+ struct sockaddr_in *psa = (void *)&conn->ksnc_peeraddr;
+ struct sockaddr_in *mysa = (void *)&conn->ksnc_myaddr;
if (conn == NULL)
return -ENOENT;
data->ioc_count = txmem;
data->ioc_nid = conn->ksnc_peer->ksnp_id.nid;
data->ioc_flags = nagle;
- data->ioc_u32[0] = conn->ksnc_ipaddr;
- data->ioc_u32[1] = conn->ksnc_port;
- data->ioc_u32[2] = conn->ksnc_myipaddr;
- data->ioc_u32[3] = conn->ksnc_type;
+ if (psa->sin_family == AF_INET)
+ data->ioc_u32[0] = ntohl(psa->sin_addr.s_addr);
+ else
+ data->ioc_u32[0] = 0xFFFFFFFF;
+ data->ioc_u32[1] = rpc_get_port((struct sockaddr *)
+ &conn->ksnc_peeraddr);
+ if (mysa->sin_family == AF_INET)
+ data->ioc_u32[2] = ntohl(mysa->sin_addr.s_addr);
+ else
+ data->ioc_u32[2] = 0xFFFFFFFF;
+ data->ioc_u32[3] = conn->ksnc_type;
data->ioc_u32[4] = conn->ksnc_scheduler->kss_cpt;
data->ioc_u32[5] = rxmem;
data->ioc_u32[6] = conn->ksnc_peer->ksnp_id.pid;
goto fail_1;
if (!ni->ni_interfaces[0]) {
+ struct sockaddr_in *sa;
+
ksi = &net->ksnn_interfaces[0];
+ sa = (void *)&ksi->ksni_addr;
/* Use the first discovered interface */
net->ksnn_ninterfaces = 1;
ni->ni_dev_cpt = ifaces[0].li_cpt;
- ksi->ksni_ipaddr = ifaces[0].li_ipaddr;
- ksi->ksni_index = ksocknal_ip2index(ksi->ksni_ipaddr, ni);
+ memset(sa, 0, sizeof(*sa));
+ sa->sin_family = AF_INET;
+ sa->sin_addr.s_addr = htonl(ifaces[0].li_ipaddr);
+ ksi->ksni_index = ksocknal_ip2index((struct sockaddr *)sa, ni);
ksi->ksni_netmask = ifaces[0].li_netmask;
strlcpy(ksi->ksni_name, ifaces[0].li_name,
sizeof(ksi->ksni_name));
}
for (j = 0; j < rc; j++) {
+ struct sockaddr_in *sa;
+
if (strcmp(ifaces[j].li_name,
ni->ni_interfaces[i]) != 0)
continue;
ksi =
&net->ksnn_interfaces[net->ksnn_ninterfaces];
+ sa = (void *)&ksi->ksni_addr;
ni->ni_dev_cpt = ifaces[j].li_cpt;
- ksi->ksni_ipaddr = ifaces[j].li_ipaddr;
- ksi->ksni_index =
- ksocknal_ip2index(ksi->ksni_ipaddr, ni);
+ memset(sa, 0, sizeof(*sa));
+ sa->sin_family = AF_INET;
+ sa->sin_addr.s_addr =
+ htonl(ifaces[j].li_ipaddr);
+ ksi->ksni_index = ksocknal_ip2index(
+ (struct sockaddr *)sa, ni);
ksi->ksni_netmask = ifaces[j].li_netmask;
strlcpy(ksi->ksni_name, ifaces[j].li_name,
sizeof(ksi->ksni_name));
goto fail_1;
LASSERT(ksi);
- ni->ni_nid = LNET_MKNID(LNET_NIDNET(ni->ni_nid), ksi->ksni_ipaddr);
+ LASSERT(ksi->ksni_addr.ss_family == AF_INET);
+ ni->ni_nid = LNET_MKNID(
+ LNET_NIDNET(ni->ni_nid),
+ ntohl(((struct sockaddr_in *)
+ &ksi->ksni_addr)->sin_addr.s_addr));
list_add(&net->ksnn_list, &ksocknal_data.ksnd_nets);
- ksocknal_data.ksnd_nnets++;
+ ksocknal_data.ksnd_nnets++;
- return 0;
+ return 0;
- fail_1:
- LIBCFS_FREE(net, sizeof(*net));
- fail_0:
- if (ksocknal_data.ksnd_nnets == 0)
- ksocknal_base_shutdown();
+fail_1:
+ LIBCFS_FREE(net, sizeof(*net));
+fail_0:
+ if (ksocknal_data.ksnd_nnets == 0)
+ ksocknal_base_shutdown();
- return -ENETDOWN;
+ return -ENETDOWN;
}
struct ksock_interface { /* in-use interface */
int ksni_index; /* Linux interface index */
- __u32 ksni_ipaddr; /* interface's IP address */
+ struct sockaddr_storage ksni_addr; /* interface's address */
__u32 ksni_netmask; /* interface's network mask */
int ksni_nroutes; /* # routes using (active) */
int ksni_npeers; /* # peers using (passive) */
refcount_t ksnc_sock_refcount; /* sock refcount */
struct ksock_sched *ksnc_scheduler; /* who schedules this
* connection */
- __u32 ksnc_myipaddr; /* my IP */
- __u32 ksnc_ipaddr; /* peer_ni's IP */
- int ksnc_port; /* peer_ni's port */
+ struct sockaddr_storage ksnc_myaddr; /* my address */
+ struct sockaddr_storage ksnc_peeraddr; /* peer_ni's address */
signed int ksnc_type:3; /* type of connection,
* should be signed
* value */
*/
time64_t ksnr_retry_interval;/* secs between retries */
int ksnr_myiface; /* interface index */
- __u32 ksnr_ipaddr; /* IP address to connect to */
- int ksnr_port; /* port to connect to */
+ struct sockaddr_storage ksnr_addr; /* IP address to connect to */
unsigned int ksnr_scheduled:1;/* scheduled for attention */
unsigned int ksnr_connecting:1;/* connection in progress */
unsigned int ksnr_connected:4;/* connections by type */
extern void ksocknal_terminate_conn(struct ksock_conn *conn);
extern void ksocknal_destroy_conn(struct ksock_conn *conn);
extern int ksocknal_close_peer_conns_locked(struct ksock_peer_ni *peer_ni,
- __u32 ipaddr, int why);
+ struct sockaddr *peer, int why);
extern int ksocknal_close_conn_and_siblings(struct ksock_conn *conn, int why);
int ksocknal_close_matching_conns(struct lnet_process_id id, __u32 ipaddr);
extern struct ksock_conn *ksocknal_find_conn_locked(struct ksock_peer_ni *peer_ni,
#include <libcfs/linux/linux-mem.h>
#include "socklnd.h"
+#include <linux/sunrpc/addr.h>
struct ksock_tx *
ksocknal_alloc_tx(int type, int size)
if (!conn->ksnc_closing) {
switch (rc) {
case -ECONNRESET:
- LCONSOLE_WARN("Host %pI4h reset our connection "
- "while we were sending data; it may have "
- "rebooted.\n",
- &conn->ksnc_ipaddr);
+ LCONSOLE_WARN("Host %pIS reset our connection while we were sending data; it may have rebooted.\n",
+ &conn->ksnc_peeraddr);
break;
default:
- LCONSOLE_WARN("There was an unexpected network error "
- "while writing to %pI4h: %d.\n",
- &conn->ksnc_ipaddr, rc);
+ LCONSOLE_WARN("There was an unexpected network error while writing to %pIS: %d.\n",
+ &conn->ksnc_peeraddr, rc);
break;
}
- CDEBUG(D_NET, "[%p] Error %d on write to %s ip %pI4h:%d\n",
+ CDEBUG(D_NET, "[%p] Error %d on write to %s ip %pISp\n",
conn, rc, libcfs_id2str(conn->ksnc_peer->ksnp_id),
- &conn->ksnc_ipaddr, conn->ksnc_port);
+ &conn->ksnc_peeraddr);
}
if (tx->tx_zc_checked)
* ksnc_sock... */
LASSERT(!conn->ksnc_closing);
- CDEBUG(D_NET, "Sending to %s ip %pI4h:%d\n",
+ CDEBUG(D_NET, "Sending to %s ip %pISp\n",
libcfs_id2str(conn->ksnc_peer->ksnp_id),
- &conn->ksnc_ipaddr, conn->ksnc_port);
+ &conn->ksnc_peeraddr);
ksocknal_tx_prep(conn, tx);
if ((ksocknal_route_mask() & ~route->ksnr_connected) == 0)
continue;
- if (!(route->ksnr_retry_interval == 0 || /* first attempt */
+ if (!(route->ksnr_retry_interval == 0 || /* first attempt */
now >= route->ksnr_timeout)) {
- CDEBUG(D_NET,
- "Too soon to retry route %pI4h "
- "(cnted %d, interval %lld, %lld secs later)\n",
- &route->ksnr_ipaddr,
- route->ksnr_connected,
- route->ksnr_retry_interval,
+ CDEBUG(D_NET,
+ "Too soon to retry route %pIS (cnted %d, interval %lld, %lld secs later)\n",
+ &route->ksnr_addr,
+ route->ksnr_connected,
+ route->ksnr_retry_interval,
route->ksnr_timeout - now);
- continue;
- }
+ continue;
+ }
return (route);
}
LASSERT(rc != -EAGAIN);
if (rc == 0)
- CDEBUG(D_NET, "[%p] EOF from %s "
- "ip %pI4h:%d\n", conn,
- libcfs_id2str(ksnp_id),
- &conn->ksnc_ipaddr,
- conn->ksnc_port);
+ CDEBUG(D_NET, "[%p] EOF from %s ip %pISp\n",
+ conn, libcfs_id2str(ksnp_id),
+ &conn->ksnc_peeraddr);
else if (!conn->ksnc_closing)
- CERROR("[%p] Error %d on read from %s "
- "ip %pI4h:%d\n", conn, rc,
- libcfs_id2str(ksnp_id),
- &conn->ksnc_ipaddr,
- conn->ksnc_port);
+ CERROR("[%p] Error %d on read from %s ip %pISp\n",
+ conn, rc, libcfs_id2str(ksnp_id),
+ &conn->ksnc_peeraddr);
/* it's not an error if conn is being closed */
ksocknal_close_conn_and_siblings (conn,
rc = lnet_sock_read(sock, &hello->kshm_magic,
sizeof(hello->kshm_magic), timeout);
- if (rc != 0) {
- CERROR("Error %d reading HELLO from %pI4h\n",
- rc, &conn->ksnc_ipaddr);
- LASSERT (rc < 0);
- return rc;
- }
+ if (rc != 0) {
+ CERROR("Error %d reading HELLO from %pIS\n",
+ rc, &conn->ksnc_peeraddr);
+ LASSERT(rc < 0);
+ return rc;
+ }
- if (hello->kshm_magic != LNET_PROTO_MAGIC &&
- hello->kshm_magic != __swab32(LNET_PROTO_MAGIC) &&
- hello->kshm_magic != le32_to_cpu (LNET_PROTO_TCP_MAGIC)) {
- /* Unexpected magic! */
- CERROR ("Bad magic(1) %#08x (%#08x expected) from "
- "%pI4h\n", __cpu_to_le32 (hello->kshm_magic),
- LNET_PROTO_TCP_MAGIC, &conn->ksnc_ipaddr);
- return -EPROTO;
- }
+ if (hello->kshm_magic != LNET_PROTO_MAGIC &&
+ hello->kshm_magic != __swab32(LNET_PROTO_MAGIC) &&
+ hello->kshm_magic != le32_to_cpu(LNET_PROTO_TCP_MAGIC)) {
+ /* Unexpected magic! */
+ CERROR("Bad magic(1) %#08x (%#08x expected) from %pIS\n",
+ __cpu_to_le32 (hello->kshm_magic),
+ LNET_PROTO_TCP_MAGIC, &conn->ksnc_peeraddr);
+ return -EPROTO;
+ }
rc = lnet_sock_read(sock, &hello->kshm_version,
sizeof(hello->kshm_version), timeout);
if (rc != 0) {
- CERROR("Error %d reading HELLO from %pI4h\n",
- rc, &conn->ksnc_ipaddr);
+ CERROR("Error %d reading HELLO from %pIS\n",
+ rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0);
return rc;
}
ksocknal_send_hello(ni, conn, ni->ni_nid, hello);
}
- CERROR("Unknown protocol version (%d.x expected) from %pI4h\n",
- conn->ksnc_proto->pro_version, &conn->ksnc_ipaddr);
+ CERROR("Unknown protocol version (%d.x expected) from %pIS\n",
+ conn->ksnc_proto->pro_version, &conn->ksnc_peeraddr);
return -EPROTO;
}
/* receive the rest of hello message anyway */
rc = conn->ksnc_proto->pro_recv_hello(conn, hello, timeout);
if (rc != 0) {
- CERROR("Error %d reading or checking hello from from %pI4h\n",
- rc, &conn->ksnc_ipaddr);
+ CERROR("Error %d reading or checking hello from from %pIS\n",
+ rc, &conn->ksnc_peeraddr);
LASSERT (rc < 0);
return rc;
}
*incarnation = hello->kshm_src_incarnation;
if (hello->kshm_src_nid == LNET_NID_ANY) {
- CERROR("Expecting a HELLO hdr with a NID, but got LNET_NID_ANY from %pI4h\n",
- &conn->ksnc_ipaddr);
+ CERROR("Expecting a HELLO hdr with a NID, but got LNET_NID_ANY from %pIS\n",
+ &conn->ksnc_peeraddr);
return -EPROTO;
}
- if (!active &&
- conn->ksnc_port > LNET_ACCEPTOR_MAX_RESERVED_PORT) {
- /* Userspace NAL assigns peer_ni process ID from socket */
- recv_id.pid = conn->ksnc_port | LNET_PID_USERFLAG;
- recv_id.nid = LNET_MKNID(LNET_NIDNET(ni->ni_nid), conn->ksnc_ipaddr);
- } else {
- recv_id.nid = hello->kshm_src_nid;
- recv_id.pid = hello->kshm_src_pid;
- }
+ if (!active &&
+ rpc_get_port((struct sockaddr *)&conn->ksnc_peeraddr) >
+ LNET_ACCEPTOR_MAX_RESERVED_PORT) {
+ /* Userspace NAL assigns peer_ni process ID from socket */
+ recv_id.pid = rpc_get_port((struct sockaddr *)
+ &conn->ksnc_peeraddr) |
+ LNET_PID_USERFLAG;
+ LASSERT(conn->ksnc_peeraddr.ss_family == AF_INET);
+ recv_id.nid = LNET_MKNID(
+ LNET_NIDNET(ni->ni_nid),
+ ntohl(((struct sockaddr_in *)
+ &conn->ksnc_peeraddr)->sin_addr.s_addr));
+ } else {
+ recv_id.nid = hello->kshm_src_nid;
+ recv_id.pid = hello->kshm_src_pid;
+ }
if (!active) {
*peerid = recv_id;
/* peer_ni determines type */
conn->ksnc_type = ksocknal_invert_type(hello->kshm_ctype);
if (conn->ksnc_type == SOCKLND_CONN_NONE) {
- CERROR("Unexpected type %d from %s ip %pI4h\n",
+ CERROR("Unexpected type %d from %s ip %pIS\n",
hello->kshm_ctype, libcfs_id2str(*peerid),
- &conn->ksnc_ipaddr);
+ &conn->ksnc_peeraddr);
return -EPROTO;
}
return 0;
}
- if (peerid->pid != recv_id.pid ||
- peerid->nid != recv_id.nid) {
- LCONSOLE_ERROR_MSG(0x130, "Connected successfully to %s on host"
- " %pI4h, but they claimed they were "
- "%s; please check your Lustre "
- "configuration.\n",
- libcfs_id2str(*peerid),
- &conn->ksnc_ipaddr,
- libcfs_id2str(recv_id));
- return -EPROTO;
- }
+ if (peerid->pid != recv_id.pid ||
+ peerid->nid != recv_id.nid) {
+ LCONSOLE_ERROR_MSG(0x130,
+ "Connected successfully to %s on host %pIS, but they claimed they were %s; please check your Lustre configuration.\n",
+ libcfs_id2str(*peerid),
+ &conn->ksnc_peeraddr,
+ libcfs_id2str(recv_id));
+ return -EPROTO;
+ }
if (hello->kshm_ctype == SOCKLND_CONN_NONE) {
/* Possible protocol mismatch or I lost the connection race */
}
if (ksocknal_invert_type(hello->kshm_ctype) != conn->ksnc_type) {
- CERROR("Mismatched types: me %d, %s ip %pI4h %d\n",
+ CERROR("Mismatched types: me %d, %s ip %pIS %d\n",
conn->ksnc_type, libcfs_id2str(*peerid),
- &conn->ksnc_ipaddr,
+ &conn->ksnc_peeraddr,
hello->kshm_ctype);
return -EPROTO;
}
if (ktime_get_seconds() >= deadline) {
rc = -ETIMEDOUT;
lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
- route->ksnr_ipaddr,
- route->ksnr_port);
+ (struct sockaddr *)
+ &route->ksnr_addr);
goto failed;
}
sock = lnet_connect(peer_ni->ksnp_id.nid,
route->ksnr_myiface,
- route->ksnr_ipaddr, route->ksnr_port,
+ (struct sockaddr *)&route->ksnr_addr,
peer_ni->ksnp_ni->ni_net_ns);
if (IS_ERR(sock)) {
rc = PTR_ERR(sock);
rc = ksocknal_create_conn(peer_ni->ksnp_ni, route, sock, type);
if (rc < 0) {
lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
- route->ksnr_ipaddr,
- route->ksnr_port);
+ (struct sockaddr *)
+ &route->ksnr_addr);
goto failed;
}
spin_unlock_bh(connd_lock);
dropped_lock = 1;
- if (ksocknal_connect(route)) {
- /* consecutive retry */
- if (cons_retry++ > SOCKNAL_INSANITY_RECONN) {
- CWARN("massive consecutive "
- "re-connecting to %pI4h\n",
- &route->ksnr_ipaddr);
- cons_retry = 0;
- }
- } else {
- cons_retry = 0;
- }
+ if (ksocknal_connect(route)) {
+ /* consecutive retry */
+ if (cons_retry++ > SOCKNAL_INSANITY_RECONN) {
+ CWARN("massive consecutive re-connecting to %pIS\n",
+ &route->ksnr_addr);
+ cons_retry = 0;
+ }
+ } else {
+ cons_retry = 0;
+ }
ksocknal_route_decref(route);
if (error != 0) {
ksocknal_conn_addref(conn);
- switch (error) {
- case ECONNRESET:
- CNETERR("A connection with %s "
- "(%pI4h:%d) was reset; "
- "it may have rebooted.\n",
- libcfs_id2str(peer_ni->ksnp_id),
- &conn->ksnc_ipaddr,
- conn->ksnc_port);
- break;
- case ETIMEDOUT:
- CNETERR("A connection with %s "
- "(%pI4h:%d) timed out; the "
- "network or node may be down.\n",
- libcfs_id2str(peer_ni->ksnp_id),
- &conn->ksnc_ipaddr,
- conn->ksnc_port);
- break;
- default:
- CNETERR("An unexpected network error %d "
- "occurred with %s "
- "(%pI4h:%d\n", error,
- libcfs_id2str(peer_ni->ksnp_id),
- &conn->ksnc_ipaddr,
- conn->ksnc_port);
- break;
- }
+ switch (error) {
+ case ECONNRESET:
+ CNETERR("A connection with %s (%pISp) was reset; it may have rebooted.\n",
+ libcfs_id2str(peer_ni->ksnp_id),
+ &conn->ksnc_peeraddr);
+ break;
+ case ETIMEDOUT:
+ CNETERR("A connection with %s (%pISp) timed out; the network or node may be down.\n",
+ libcfs_id2str(peer_ni->ksnp_id),
+ &conn->ksnc_peeraddr);
+ break;
+ default:
+ CNETERR("An unexpected network error %d occurred with %s (%pISp\n",
+ error,
+ libcfs_id2str(peer_ni->ksnp_id),
+ &conn->ksnc_peeraddr);
+ break;
+ }
- return (conn);
- }
+ return conn;
+ }
- if (conn->ksnc_rx_started &&
+ if (conn->ksnc_rx_started &&
ktime_get_seconds() >= conn->ksnc_rx_deadline) {
- /* Timed out incomplete incoming message */
- ksocknal_conn_addref(conn);
- CNETERR("Timeout receiving from %s (%pI4h:%d), "
- "state %d wanted %d left %d\n",
- libcfs_id2str(peer_ni->ksnp_id),
- &conn->ksnc_ipaddr,
- conn->ksnc_port,
- conn->ksnc_rx_state,
- conn->ksnc_rx_nob_wanted,
- conn->ksnc_rx_nob_left);
- return (conn);
- }
+ /* Timed out incomplete incoming message */
+ ksocknal_conn_addref(conn);
+ CNETERR("Timeout receiving from %s (%pISp), state %d wanted %d left %d\n",
+ libcfs_id2str(peer_ni->ksnp_id),
+ &conn->ksnc_peeraddr,
+ conn->ksnc_rx_state,
+ conn->ksnc_rx_nob_wanted,
+ conn->ksnc_rx_nob_left);
+ return conn;
+ }
if ((!list_empty(&conn->ksnc_tx_queue) ||
conn->ksnc_sock->sk->sk_wmem_queued != 0) &&
ktime_get_seconds() >= conn->ksnc_tx_deadline) {
- /* Timed out messages queued for sending or
- * buffered in the socket's send buffer */
- ksocknal_conn_addref(conn);
+ /* Timed out messages queued for sending or
+ * buffered in the socket's send buffer
+ */
+ ksocknal_conn_addref(conn);
list_for_each_entry(tx, &conn->ksnc_tx_queue,
tx_list)
tx->tx_hstatus =
LNET_MSG_STATUS_LOCAL_TIMEOUT;
- CNETERR("Timeout sending data to %s (%pI4h:%d) "
- "the network or that node may be down.\n",
- libcfs_id2str(peer_ni->ksnp_id),
- &conn->ksnc_ipaddr, conn->ksnc_port);
- return (conn);
- }
- }
+ CNETERR("Timeout sending data to %s (%pISp) the network or that node may be down.\n",
+ libcfs_id2str(peer_ni->ksnp_id),
+ &conn->ksnc_peeraddr);
+ return conn;
+ }
+ }
- return (NULL);
+ return (NULL);
}
static inline void
ksocknal_lib_get_conn_addrs(struct ksock_conn *conn)
{
int rc = lnet_sock_getaddr(conn->ksnc_sock, true,
- &conn->ksnc_ipaddr,
- &conn->ksnc_port);
+ &conn->ksnc_peeraddr);
- /* Didn't need the {get,put}connsock dance to deref ksnc_sock... */
- LASSERT (!conn->ksnc_closing);
+ /* Didn't need the {get,put}connsock dance to deref ksnc_sock... */
+ LASSERT(!conn->ksnc_closing);
- if (rc != 0) {
- CERROR ("Error %d getting sock peer_ni IP\n", rc);
- return rc;
- }
+ if (rc != 0) {
+ CERROR("Error %d getting sock peer_ni IP\n", rc);
+ return rc;
+ }
rc = lnet_sock_getaddr(conn->ksnc_sock, false,
- &conn->ksnc_myipaddr, NULL);
- if (rc != 0) {
- CERROR ("Error %d getting sock local IP\n", rc);
- return rc;
- }
+ &conn->ksnc_myaddr);
+ if (rc != 0) {
+ CERROR("Error %d getting sock local IP\n", rc);
+ return rc;
+ }
- return 0;
+ return 0;
}
int
hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
rc = lnet_sock_write(sock, hdr, sizeof(*hdr), lnet_acceptor_timeout());
- if (rc != 0) {
- CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
- rc, &conn->ksnc_ipaddr, conn->ksnc_port);
- goto out;
- }
+ if (rc != 0) {
+ CNETERR("Error %d sending HELLO hdr to %pISp\n",
+ rc, &conn->ksnc_peeraddr);
+ goto out;
+ }
if (hello->kshm_nips == 0)
goto out;
}
rc = lnet_sock_write(sock, hello->kshm_ips,
- hello->kshm_nips * sizeof(__u32),
- lnet_acceptor_timeout());
- if (rc != 0) {
- CNETERR("Error %d sending HELLO payload (%d)"
- " to %pI4h/%d\n", rc, hello->kshm_nips,
- &conn->ksnc_ipaddr, conn->ksnc_port);
+ hello->kshm_nips * sizeof(__u32),
+ lnet_acceptor_timeout());
+ if (rc != 0) {
+ CNETERR("Error %d sending HELLO payload (%d) to %pISp\n",
+ rc, hello->kshm_nips,
+ &conn->ksnc_peeraddr);
}
out:
LIBCFS_FREE(hdr, sizeof(*hdr));
rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
lnet_acceptor_timeout());
- if (rc != 0) {
- CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
- rc, &conn->ksnc_ipaddr, conn->ksnc_port);
- return rc;
- }
+ if (rc != 0) {
+ CNETERR("Error %d sending HELLO hdr to %pISp\n",
+ rc, &conn->ksnc_peeraddr);
+ return rc;
+ }
if (hello->kshm_nips == 0)
return 0;
rc = lnet_sock_write(sock, hello->kshm_ips,
- hello->kshm_nips * sizeof(__u32),
- lnet_acceptor_timeout());
- if (rc != 0) {
- CNETERR("Error %d sending HELLO payload (%d)"
- " to %pI4h/%d\n", rc, hello->kshm_nips,
- &conn->ksnc_ipaddr, conn->ksnc_port);
- }
+ hello->kshm_nips * sizeof(__u32),
+ lnet_acceptor_timeout());
+ if (rc != 0) {
+ CNETERR("Error %d sending HELLO payload (%d) to %pISp\n", rc,
+ hello->kshm_nips,
+ &conn->ksnc_peeraddr);
+ }
- return rc;
+ return rc;
}
static int
sizeof(*hdr) - offsetof(struct lnet_hdr, src_nid),
timeout);
if (rc != 0) {
- CERROR("Error %d reading rest of HELLO hdr from %pI4h\n",
- rc, &conn->ksnc_ipaddr);
+ CERROR("Error %d reading rest of HELLO hdr from %pIS\n",
+ rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
goto out;
}
- /* ...and check we got what we expected */
- if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
- CERROR ("Expecting a HELLO hdr,"
- " but got type %d from %pI4h\n",
- le32_to_cpu (hdr->type),
- &conn->ksnc_ipaddr);
- rc = -EPROTO;
- goto out;
- }
+ /* ...and check we got what we expected */
+ if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
+ CERROR("Expecting a HELLO hdr, but got type %d from %pIS\n",
+ le32_to_cpu(hdr->type),
+ &conn->ksnc_peeraddr);
+ rc = -EPROTO;
+ goto out;
+ }
hello->kshm_src_nid = le64_to_cpu (hdr->src_nid);
hello->kshm_src_pid = le32_to_cpu (hdr->src_pid);
sizeof (__u32);
if (hello->kshm_nips > LNET_INTERFACES_NUM) {
- CERROR("Bad nips %d from ip %pI4h\n",
- hello->kshm_nips, &conn->ksnc_ipaddr);
+ CERROR("Bad nips %d from ip %pIS\n",
+ hello->kshm_nips, &conn->ksnc_peeraddr);
rc = -EPROTO;
goto out;
}
rc = lnet_sock_read(sock, hello->kshm_ips,
hello->kshm_nips * sizeof(__u32), timeout);
if (rc != 0) {
- CERROR("Error %d reading IPs from ip %pI4h\n",
- rc, &conn->ksnc_ipaddr);
+ CERROR("Error %d reading IPs from ip %pIS\n",
+ rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
goto out;
}
hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
if (hello->kshm_ips[i] == 0) {
- CERROR("Zero IP[%d] from ip %pI4h\n",
- i, &conn->ksnc_ipaddr);
+ CERROR("Zero IP[%d] from ip %pIS\n",
+ i, &conn->ksnc_peeraddr);
rc = -EPROTO;
break;
}
offsetof(struct ksock_hello_msg, kshm_src_nid),
timeout);
if (rc != 0) {
- CERROR("Error %d reading HELLO from %pI4h\n",
- rc, &conn->ksnc_ipaddr);
+ CERROR("Error %d reading HELLO from %pIS\n",
+ rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
return rc;
}
}
if (hello->kshm_nips > LNET_INTERFACES_NUM) {
- CERROR("Bad nips %d from ip %pI4h\n",
- hello->kshm_nips, &conn->ksnc_ipaddr);
+ CERROR("Bad nips %d from ip %pIS\n",
+ hello->kshm_nips, &conn->ksnc_peeraddr);
return -EPROTO;
}
rc = lnet_sock_read(sock, hello->kshm_ips,
hello->kshm_nips * sizeof(__u32), timeout);
- if (rc != 0) {
- CERROR("Error %d reading IPs from ip %pI4h\n",
- rc, &conn->ksnc_ipaddr);
+ if (rc != 0) {
+ CERROR("Error %d reading IPs from ip %pIS\n",
+ rc, &conn->ksnc_peeraddr);
LASSERT(rc < 0 && rc != -EALREADY);
- return rc;
- }
+ return rc;
+ }
for (i = 0; i < (int) hello->kshm_nips; i++) {
if (conn->ksnc_flip)
__swab32s(&hello->kshm_ips[i]);
- if (hello->kshm_ips[i] == 0) {
- CERROR("Zero IP[%d] from ip %pI4h\n",
- i, &conn->ksnc_ipaddr);
- return -EPROTO;
- }
+ if (hello->kshm_ips[i] == 0) {
+ CERROR("Zero IP[%d] from ip %pIS\n",
+ i, &conn->ksnc_peeraddr);
+ return -EPROTO;
+ }
}
return 0;
#include <linux/completion.h>
#include <net/sock.h>
#include <lnet/lib-lnet.h>
+#include <linux/sunrpc/addr.h>
static int accept_port = 988;
static int accept_backlog = 127;
void
lnet_connect_console_error (int rc, lnet_nid_t peer_nid,
- __u32 peer_ip, int peer_port)
+ struct sockaddr *sa)
{
switch (rc) {
/* "normal" errors */
case -ECONNREFUSED:
- CNETERR("Connection to %s at host %pI4h on port %d was "
- "refused: check that Lustre is running on that node.\n",
- libcfs_nid2str(peer_nid), &peer_ip, peer_port);
+ CNETERR("Connection to %s at host %pISp was refused: check that Lustre is running on that node.\n",
+ libcfs_nid2str(peer_nid), sa);
break;
case -EHOSTUNREACH:
case -ENETUNREACH:
- CNETERR("Connection to %s at host %pI4h "
- "was unreachable: the network or that node may "
- "be down, or Lustre may be misconfigured.\n",
- libcfs_nid2str(peer_nid), &peer_ip);
+ CNETERR("Connection to %s at host %pIS was unreachable: the network or that node may be down, or Lustre may be misconfigured.\n",
+ libcfs_nid2str(peer_nid), sa);
break;
case -ETIMEDOUT:
- CNETERR("Connection to %s at host %pI4h on "
- "port %d took too long: that node may be hung "
- "or experiencing high load.\n",
- libcfs_nid2str(peer_nid), &peer_ip, peer_port);
+ CNETERR("Connection to %s at host %pISp took too long: that node may be hung or experiencing high load.\n",
+ libcfs_nid2str(peer_nid), sa);
break;
case -ECONNRESET:
- LCONSOLE_ERROR_MSG(0x11b, "Connection to %s at host %pI4h"
- " on port %d was reset: "
- "is it running a compatible version of "
- "Lustre and is %s one of its NIDs?\n",
- libcfs_nid2str(peer_nid), &peer_ip,
- peer_port, libcfs_nid2str(peer_nid));
+ LCONSOLE_ERROR_MSG(0x11b,
+ "Connection to %s at host %pISp was reset: is it running a compatible version of Lustre and is %s one of its NIDs?\n",
+ libcfs_nid2str(peer_nid), sa,
+ libcfs_nid2str(peer_nid));
break;
case -EPROTO:
- LCONSOLE_ERROR_MSG(0x11c, "Protocol error connecting to %s at "
- "host %pI4h on port %d: is it running "
- "a compatible version of Lustre?\n",
- libcfs_nid2str(peer_nid), &peer_ip,
- peer_port);
+ LCONSOLE_ERROR_MSG(0x11c,
+ "Protocol error connecting to %s at host %pISp: is it running a compatible version of Lustre?\n",
+ libcfs_nid2str(peer_nid), sa);
break;
case -EADDRINUSE:
- LCONSOLE_ERROR_MSG(0x11d, "No privileged ports available to "
- "connect to %s at host %pI4h on port "
- "%d\n", libcfs_nid2str(peer_nid),
- &peer_ip, peer_port);
+ LCONSOLE_ERROR_MSG(0x11d,
+ "No privileged ports available to connect to %s at host %pISp\n",
+ libcfs_nid2str(peer_nid), sa);
break;
default:
- LCONSOLE_ERROR_MSG(0x11e, "Unexpected error %d connecting to %s"
- " at host %pI4h on port %d\n", rc,
- libcfs_nid2str(peer_nid),
- &peer_ip, peer_port);
+ LCONSOLE_ERROR_MSG(0x11e,
+ "Unexpected error %d connecting to %s at host %pISp\n",
+ rc, libcfs_nid2str(peer_nid), sa);
break;
}
}
EXPORT_SYMBOL(lnet_connect_console_error);
struct socket *
-lnet_connect(lnet_nid_t peer_nid, int interface, __u32 peer_ip,
- int peer_port, struct net *ns)
+lnet_connect(lnet_nid_t peer_nid, int interface, struct sockaddr *peeraddr,
+ struct net *ns)
{
struct lnet_acceptor_connreq cr;
struct socket *sock;
BUILD_BUG_ON(sizeof(cr) > 16); /* not too big to be on the stack */
+ LASSERT(peeraddr->sa_family == AF_INET);
+
for (port = LNET_ACCEPTOR_MAX_RESERVED_PORT;
port >= LNET_ACCEPTOR_MIN_RESERVED_PORT;
--port) {
/* Iterate through reserved ports. */
- struct sockaddr_in paddr = {.sin_family = AF_INET};
-
- paddr.sin_addr.s_addr = htonl(peer_ip);
- paddr.sin_port = htons(peer_port);
- sock = lnet_sock_connect(interface, port,
- (struct sockaddr *)&paddr, ns);
+ sock = lnet_sock_connect(interface, port, peeraddr, ns);
if (IS_ERR(sock)) {
rc = PTR_ERR(sock);
if (rc == -EADDRINUSE || rc == -EADDRNOTAVAIL)
failed_sock:
sock_release(sock);
failed:
- lnet_connect_console_error(rc, peer_nid, peer_ip, peer_port);
+ lnet_connect_console_error(rc, peer_nid, peeraddr);
return ERR_PTR(rc);
}
EXPORT_SYMBOL(lnet_connect);
lnet_accept(struct socket *sock, __u32 magic)
{
struct lnet_acceptor_connreq cr;
- __u32 peer_ip;
- int peer_port;
+ struct sockaddr_storage peer;
int rc;
int flip;
struct lnet_ni *ni;
LASSERT(sizeof(cr) <= 16); /* not too big for the stack */
- rc = lnet_sock_getaddr(sock, true, &peer_ip, &peer_port);
+ rc = lnet_sock_getaddr(sock, true, &peer);
LASSERT(rc == 0); /* we succeeded before */
if (!lnet_accept_magic(magic, LNET_PROTO_ACCEPTOR_MAGIC)) {
accept_timeout);
if (rc != 0)
- CERROR("Error sending magic+version in response to LNET magic from %pI4h: %d\n",
- &peer_ip, rc);
+ CERROR("Error sending magic+version in response to LNET magic from %pIS: %d\n",
+ &peer, rc);
return -EPROTO;
}
else
str = "unrecognised";
- LCONSOLE_ERROR_MSG(0x11f, "Refusing connection from %pI4h"
+ LCONSOLE_ERROR_MSG(0x11f, "Refusing connection from %pIS"
" magic %08x: %s acceptor protocol\n",
- &peer_ip, magic, str);
+ &peer, magic, str);
return -EPROTO;
}
sizeof(cr.acr_version),
accept_timeout);
if (rc != 0) {
- CERROR("Error %d reading connection request version from "
- "%pI4h\n", rc, &peer_ip);
+ CERROR("Error %d reading connection request version from %pIS\n",
+ rc, &peer);
return -EIO;
}
accept_timeout);
if (rc != 0)
- CERROR("Error sending magic+version in response to version %d from %pI4h: %d\n",
- peer_version, &peer_ip, rc);
+ CERROR("Error sending magic+version in response to version %d from %pIS: %d\n",
+ peer_version, &peer, rc);
return -EPROTO;
}
offsetof(struct lnet_acceptor_connreq, acr_nid),
accept_timeout);
if (rc != 0) {
- CERROR("Error %d reading connection request from "
- "%pI4h\n", rc, &peer_ip);
+ CERROR("Error %d reading connection request from %pIS\n",
+ rc, &peer);
return -EIO;
}
ni->ni_nid != cr.acr_nid) { /* right NET, wrong NID! */
if (ni != NULL)
lnet_ni_decref(ni);
- LCONSOLE_ERROR_MSG(0x120, "Refusing connection from %pI4h "
- "for %s: No matching NI\n",
- &peer_ip, libcfs_nid2str(cr.acr_nid));
+ LCONSOLE_ERROR_MSG(0x120,
+ "Refusing connection from %pIS for %s: No matching NI\n",
+ &peer, libcfs_nid2str(cr.acr_nid));
return -EPERM;
}
if (ni->ni_net->net_lnd->lnd_accept == NULL) {
/* This catches a request for the loopback LND */
lnet_ni_decref(ni);
- LCONSOLE_ERROR_MSG(0x121, "Refusing connection from %pI4h "
- "for %s: NI doesn not accept IP connections\n",
- &peer_ip, libcfs_nid2str(cr.acr_nid));
+ LCONSOLE_ERROR_MSG(0x121,
+ "Refusing connection from %pIS for %s: NI doesn not accept IP connections\n",
+ &peer, libcfs_nid2str(cr.acr_nid));
return -EPERM;
}
CDEBUG(D_NET, "Accept %s from %pI4h\n",
- libcfs_nid2str(cr.acr_nid), &peer_ip);
+ libcfs_nid2str(cr.acr_nid), &peer);
rc = ni->ni_net->net_lnd->lnd_accept(ni, sock);
struct socket *newsock;
int rc;
__u32 magic;
- __u32 peer_ip;
- int peer_port;
+ struct sockaddr_storage peer;
int secure = (int)((uintptr_t)arg);
LASSERT(lnet_acceptor_state.pta_sock == NULL);
/* make sure we call lnet_sock_accept() again, until it fails */
atomic_set(&lnet_acceptor_state.pta_ready, 1);
- rc = lnet_sock_getaddr(newsock, true, &peer_ip, &peer_port);
+ rc = lnet_sock_getaddr(newsock, true, &peer);
if (rc != 0) {
CERROR("Can't determine new connection's address\n");
goto failed;
}
- if (secure && peer_port > LNET_ACCEPTOR_MAX_RESERVED_PORT) {
- CERROR("Refusing connection from %pI4h: "
- "insecure port %d\n", &peer_ip, peer_port);
+ if (secure &&
+ rpc_get_port((struct sockaddr *)&peer) >
+ LNET_ACCEPTOR_MAX_RESERVED_PORT) {
+ CERROR("Refusing connection from %pISp: insecure port.\n",
+ &peer);
goto failed;
}
rc = lnet_sock_read(newsock, &magic, sizeof(magic),
accept_timeout);
if (rc != 0) {
- CERROR("Error %d reading connection request from "
- "%pI4h\n", rc, &peer_ip);
+ CERROR("Error %d reading connection request from %pIS\n",
+ rc, &peer);
goto failed;
}
EXPORT_SYMBOL(lnet_sock_setbuf);
int
-lnet_sock_getaddr(struct socket *sock, bool remote, __u32 *ip, int *port)
+lnet_sock_getaddr(struct socket *sock, bool remote,
+ struct sockaddr_storage *peer)
{
- struct sockaddr_in sin;
int rc;
#ifndef HAVE_KERN_SOCK_GETNAME_2ARGS
- int len = sizeof(sin);
+ int len = sizeof(*peer);
#endif
if (remote)
rc = lnet_kernel_getpeername(sock,
- (struct sockaddr *)&sin, &len);
+ (struct sockaddr *)peer, &len);
else
rc = lnet_kernel_getsockname(sock,
- (struct sockaddr *)&sin, &len);
+ (struct sockaddr *)peer, &len);
if (rc < 0) {
CERROR("Error %d getting sock %s IP/port\n",
rc, remote ? "peer" : "local");
return rc;
}
- if (ip != NULL)
- *ip = ntohl(sin.sin_addr.s_addr);
-
- if (port != NULL)
- *port = ntohs(sin.sin_port);
-
return 0;
}
EXPORT_SYMBOL(lnet_sock_getaddr);