send.c (c1144d29f405ce1f4e6ede6482beb3d0d09750c6) | send.c (eee2fa6ab3225192d6d894c54a6fb02ac9efdff6) |
---|---|
1/* 2 * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: --- 695 unchanged lines hidden (view full) --- 704void rds_send_drop_acked(struct rds_connection *conn, u64 ack, 705 is_acked_func is_acked) 706{ 707 WARN_ON(conn->c_trans->t_mp_capable); 708 rds_send_path_drop_acked(&conn->c_path[0], ack, is_acked); 709} 710EXPORT_SYMBOL_GPL(rds_send_drop_acked); 711 | 1/* 2 * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: --- 695 unchanged lines hidden (view full) --- 704void rds_send_drop_acked(struct rds_connection *conn, u64 ack, 705 is_acked_func is_acked) 706{ 707 WARN_ON(conn->c_trans->t_mp_capable); 708 rds_send_path_drop_acked(&conn->c_path[0], ack, is_acked); 709} 710EXPORT_SYMBOL_GPL(rds_send_drop_acked); 711 |
712void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest) | 712void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in6 *dest) |
713{ 714 struct rds_message *rm, *tmp; 715 struct rds_connection *conn; 716 struct rds_conn_path *cp; 717 unsigned long flags; 718 LIST_HEAD(list); 719 720 /* get all the messages we're dropping under the rs lock */ 721 spin_lock_irqsave(&rs->rs_lock, flags); 722 723 list_for_each_entry_safe(rm, tmp, &rs->rs_send_queue, m_sock_item) { | 713{ 714 struct rds_message *rm, *tmp; 715 struct rds_connection *conn; 716 struct rds_conn_path *cp; 717 unsigned long flags; 718 LIST_HEAD(list); 719 720 /* get all the messages we're dropping under the rs lock */ 721 spin_lock_irqsave(&rs->rs_lock, flags); 722 723 list_for_each_entry_safe(rm, tmp, &rs->rs_send_queue, m_sock_item) { |
724 if (dest && (dest->sin_addr.s_addr != rm->m_daddr || 725 dest->sin_port != rm->m_inc.i_hdr.h_dport)) | 724 if (dest && 725 (!ipv6_addr_equal(&dest->sin6_addr, &rm->m_daddr) || 726 dest->sin6_port != rm->m_inc.i_hdr.h_dport)) |
726 continue; 727 728 list_move(&rm->m_sock_item, &list); 729 rds_send_sndbuf_remove(rs, rm); 730 clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags); 731 } 732 733 /* order flag updates with the rs lock */ --- 320 unchanged lines hidden (view full) --- 1054 } 1055 return 0; 1056} 1057 1058int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) 1059{ 1060 struct sock *sk = sock->sk; 1061 struct rds_sock *rs = rds_sk_to_rs(sk); | 727 continue; 728 729 list_move(&rm->m_sock_item, &list); 730 rds_send_sndbuf_remove(rs, rm); 731 clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags); 732 } 733 734 /* order flag updates with the rs lock */ --- 320 unchanged lines hidden (view full) --- 1055 } 1056 return 0; 1057} 1058 1059int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len) 1060{ 1061 struct sock *sk = sock->sk; 1062 struct rds_sock *rs = rds_sk_to_rs(sk); |
1063 DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name); |
|
1062 DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name); | 1064 DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name); |
1063 __be32 daddr; | |
1064 __be16 dport; 1065 struct rds_message *rm = NULL; 1066 struct rds_connection *conn; 1067 int ret = 0; 1068 int queued = 0, allocated_mr = 0; 1069 int nonblock = msg->msg_flags & MSG_DONTWAIT; 1070 long timeo = sock_sndtimeo(sk, nonblock); 1071 struct rds_conn_path *cpath; | 1065 __be16 dport; 1066 struct rds_message *rm = NULL; 1067 struct rds_connection *conn; 1068 int ret = 0; 1069 int queued = 0, allocated_mr = 0; 1070 int nonblock = msg->msg_flags & MSG_DONTWAIT; 1071 long timeo = sock_sndtimeo(sk, nonblock); 1072 struct rds_conn_path *cpath; |
1073 struct in6_addr daddr; 1074 __u32 scope_id = 0; |
|
1072 size_t total_payload_len = payload_len, rdma_payload_len = 0; 1073 bool zcopy = ((msg->msg_flags & MSG_ZEROCOPY) && 1074 sock_flag(rds_rs_to_sk(rs), SOCK_ZEROCOPY)); 1075 int num_sgs = ceil(payload_len, PAGE_SIZE); | 1075 size_t total_payload_len = payload_len, rdma_payload_len = 0; 1076 bool zcopy = ((msg->msg_flags & MSG_ZEROCOPY) && 1077 sock_flag(rds_rs_to_sk(rs), SOCK_ZEROCOPY)); 1078 int num_sgs = ceil(payload_len, PAGE_SIZE); |
1079 int namelen; |
|
1076 1077 /* Mirror Linux UDP mirror of BSD error message compatibility */ 1078 /* XXX: Perhaps MSG_MORE someday */ 1079 if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_CMSG_COMPAT | MSG_ZEROCOPY)) { 1080 ret = -EOPNOTSUPP; 1081 goto out; 1082 } 1083 | 1080 1081 /* Mirror Linux UDP mirror of BSD error message compatibility */ 1082 /* XXX: Perhaps MSG_MORE someday */ 1083 if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_CMSG_COMPAT | MSG_ZEROCOPY)) { 1084 ret = -EOPNOTSUPP; 1085 goto out; 1086 } 1087 |
1084 if (msg->msg_namelen) { 1085 /* XXX fail non-unicast destination IPs? */ 1086 if (msg->msg_namelen < sizeof(*usin) || usin->sin_family != AF_INET) { | 1088 namelen = msg->msg_namelen; 1089 if (namelen != 0) { 1090 if (namelen < sizeof(*usin)) { |
1087 ret = -EINVAL; 1088 goto out; 1089 } | 1091 ret = -EINVAL; 1092 goto out; 1093 } |
1090 daddr = usin->sin_addr.s_addr; 1091 dport = usin->sin_port; | 1094 switch (namelen) { 1095 case sizeof(*usin): 1096 if (usin->sin_family != AF_INET || 1097 usin->sin_addr.s_addr == htonl(INADDR_ANY) || 1098 usin->sin_addr.s_addr == htonl(INADDR_BROADCAST) || 1099 IN_MULTICAST(ntohl(usin->sin_addr.s_addr))) { 1100 ret = -EINVAL; 1101 goto out; 1102 } 1103 ipv6_addr_set_v4mapped(usin->sin_addr.s_addr, &daddr); 1104 dport = usin->sin_port; 1105 break; 1106 1107 case sizeof(*sin6): { 1108 ret = -EPROTONOSUPPORT; 1109 goto out; 1110 } 1111 1112 default: 1113 ret = -EINVAL; 1114 goto out; 1115 } |
1092 } else { 1093 /* We only care about consistency with ->connect() */ 1094 lock_sock(sk); 1095 daddr = rs->rs_conn_addr; 1096 dport = rs->rs_conn_port; | 1116 } else { 1117 /* We only care about consistency with ->connect() */ 1118 lock_sock(sk); 1119 daddr = rs->rs_conn_addr; 1120 dport = rs->rs_conn_port; |
1121 scope_id = rs->rs_bound_scope_id; |
|
1097 release_sock(sk); 1098 } 1099 1100 lock_sock(sk); | 1122 release_sock(sk); 1123 } 1124 1125 lock_sock(sk); |
1101 if (daddr == 0 || rs->rs_bound_addr == 0) { | 1126 if (ipv6_addr_any(&rs->rs_bound_addr) || ipv6_addr_any(&daddr)) { |
1102 release_sock(sk); | 1127 release_sock(sk); |
1103 ret = -ENOTCONN; /* XXX not a great errno */ | 1128 ret = -ENOTCONN; |
1104 goto out; | 1129 goto out; |
1130 } else if (namelen != 0) { 1131 /* Cannot send to an IPv4 address using an IPv6 source 1132 * address and cannot send to an IPv6 address using an 1133 * IPv4 source address. 1134 */ 1135 if (ipv6_addr_v4mapped(&daddr) ^ 1136 ipv6_addr_v4mapped(&rs->rs_bound_addr)) { 1137 release_sock(sk); 1138 ret = -EOPNOTSUPP; 1139 goto out; 1140 } |
|
1105 } 1106 release_sock(sk); 1107 1108 ret = rds_rdma_bytes(msg, &rdma_payload_len); 1109 if (ret) 1110 goto out; 1111 1112 total_payload_len += rdma_payload_len; --- 37 unchanged lines hidden (view full) --- 1150 goto out; 1151 } 1152 rm->data.op_active = 1; 1153 1154 rm->m_daddr = daddr; 1155 1156 /* rds_conn_create has a spinlock that runs with IRQ off. 1157 * Caching the conn in the socket helps a lot. */ | 1141 } 1142 release_sock(sk); 1143 1144 ret = rds_rdma_bytes(msg, &rdma_payload_len); 1145 if (ret) 1146 goto out; 1147 1148 total_payload_len += rdma_payload_len; --- 37 unchanged lines hidden (view full) --- 1186 goto out; 1187 } 1188 rm->data.op_active = 1; 1189 1190 rm->m_daddr = daddr; 1191 1192 /* rds_conn_create has a spinlock that runs with IRQ off. 1193 * Caching the conn in the socket helps a lot. */ |
1158 if (rs->rs_conn && rs->rs_conn->c_faddr == daddr) | 1194 if (rs->rs_conn && ipv6_addr_equal(&rs->rs_conn->c_faddr, &daddr)) |
1159 conn = rs->rs_conn; 1160 else { 1161 conn = rds_conn_create_outgoing(sock_net(sock->sk), | 1195 conn = rs->rs_conn; 1196 else { 1197 conn = rds_conn_create_outgoing(sock_net(sock->sk), |
1162 rs->rs_bound_addr, daddr, 1163 rs->rs_transport, 1164 sock->sk->sk_allocation); | 1198 &rs->rs_bound_addr, &daddr, 1199 rs->rs_transport, 1200 sock->sk->sk_allocation, 1201 scope_id); |
1165 if (IS_ERR(conn)) { 1166 ret = PTR_ERR(conn); 1167 goto out; 1168 } 1169 rs->rs_conn = conn; 1170 } 1171 1172 /* Parse any control messages the user may have included. */ --- 195 unchanged lines hidden --- | 1202 if (IS_ERR(conn)) { 1203 ret = PTR_ERR(conn); 1204 goto out; 1205 } 1206 rs->rs_conn = conn; 1207 } 1208 1209 /* Parse any control messages the user may have included. */ --- 195 unchanged lines hidden --- |