diff options
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r-- | net/tipc/socket.c | 123 |
1 files changed, 82 insertions, 41 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index ea33eab4fb9d..70eaceae1f8c 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -36,12 +36,12 @@ | |||
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "ref.h" | 38 | #include "ref.h" |
39 | #include "port.h" | ||
40 | #include "name_table.h" | 39 | #include "name_table.h" |
41 | #include "node.h" | 40 | #include "node.h" |
42 | #include "link.h" | 41 | #include "link.h" |
43 | #include <linux/export.h> | 42 | #include <linux/export.h> |
44 | #include "config.h" | 43 | #include "config.h" |
44 | #include "socket.h" | ||
45 | 45 | ||
46 | #define SS_LISTENING -1 /* socket is listening */ | 46 | #define SS_LISTENING -1 /* socket is listening */ |
47 | #define SS_READY -2 /* socket is connectionless */ | 47 | #define SS_READY -2 /* socket is connectionless */ |
@@ -114,24 +114,65 @@ static struct proto tipc_proto_kern; | |||
114 | * - port reference | 114 | * - port reference |
115 | */ | 115 | */ |
116 | 116 | ||
117 | #include "socket.h" | 117 | static u32 tsk_peer_node(struct tipc_port *p_ptr) |
118 | { | ||
119 | return msg_destnode(&p_ptr->phdr); | ||
120 | } | ||
121 | |||
122 | static u32 tsk_peer_port(struct tipc_port *p_ptr) | ||
123 | { | ||
124 | return msg_destport(&p_ptr->phdr); | ||
125 | } | ||
126 | |||
127 | static bool tsk_unreliable(struct tipc_port *port) | ||
128 | { | ||
129 | return msg_src_droppable(&port->phdr) != 0; | ||
130 | } | ||
131 | |||
132 | static void tsk_set_unreliable(struct tipc_port *port, bool unreliable) | ||
133 | { | ||
134 | msg_set_src_droppable(&port->phdr, unreliable ? 1 : 0); | ||
135 | } | ||
136 | |||
137 | static bool tsk_unreturnable(struct tipc_port *port) | ||
138 | { | ||
139 | return msg_dest_droppable(&port->phdr) != 0; | ||
140 | } | ||
141 | |||
142 | static void tsk_set_unreturnable(struct tipc_port *port, bool unreturnable) | ||
143 | { | ||
144 | msg_set_dest_droppable(&port->phdr, unreturnable ? 1 : 0); | ||
145 | } | ||
146 | |||
147 | static int tsk_importance(struct tipc_port *port) | ||
148 | { | ||
149 | return msg_importance(&port->phdr); | ||
150 | } | ||
151 | |||
152 | static int tsk_set_importance(struct tipc_port *port, int imp) | ||
153 | { | ||
154 | if (imp > TIPC_CRITICAL_IMPORTANCE) | ||
155 | return -EINVAL; | ||
156 | msg_set_importance(&port->phdr, (u32)imp); | ||
157 | return 0; | ||
158 | } | ||
118 | 159 | ||
119 | /** | 160 | /** |
120 | * advance_rx_queue - discard first buffer in socket receive queue | 161 | * tsk_advance_rx_queue - discard first buffer in socket receive queue |
121 | * | 162 | * |
122 | * Caller must hold socket lock | 163 | * Caller must hold socket lock |
123 | */ | 164 | */ |
124 | static void advance_rx_queue(struct sock *sk) | 165 | static void tsk_advance_rx_queue(struct sock *sk) |
125 | { | 166 | { |
126 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); | 167 | kfree_skb(__skb_dequeue(&sk->sk_receive_queue)); |
127 | } | 168 | } |
128 | 169 | ||
129 | /** | 170 | /** |
130 | * reject_rx_queue - reject all buffers in socket receive queue | 171 | * tsk_rej_rx_queue - reject all buffers in socket receive queue |
131 | * | 172 | * |
132 | * Caller must hold socket lock | 173 | * Caller must hold socket lock |
133 | */ | 174 | */ |
134 | static void reject_rx_queue(struct sock *sk) | 175 | static void tsk_rej_rx_queue(struct sock *sk) |
135 | { | 176 | { |
136 | struct sk_buff *buf; | 177 | struct sk_buff *buf; |
137 | u32 dnode; | 178 | u32 dnode; |
@@ -142,14 +183,14 @@ static void reject_rx_queue(struct sock *sk) | |||
142 | } | 183 | } |
143 | } | 184 | } |
144 | 185 | ||
145 | /* tipc_sk_peer_msg - verify if message was sent by connected port's peer | 186 | /* tsk_peer_msg - verify if message was sent by connected port's peer |
146 | * | 187 | * |
147 | * Handles cases where the node's network address has changed from | 188 | * Handles cases where the node's network address has changed from |
148 | * the default of <0.0.0> to its configured setting. | 189 | * the default of <0.0.0> to its configured setting. |
149 | */ | 190 | */ |
150 | static bool tipc_sk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) | 191 | static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) |
151 | { | 192 | { |
152 | u32 peer_port = tipc_port_peerport(&tsk->port); | 193 | u32 peer_port = tsk_peer_port(&tsk->port); |
153 | u32 orig_node; | 194 | u32 orig_node; |
154 | u32 peer_node; | 195 | u32 peer_node; |
155 | 196 | ||
@@ -160,7 +201,7 @@ static bool tipc_sk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) | |||
160 | return false; | 201 | return false; |
161 | 202 | ||
162 | orig_node = msg_orignode(msg); | 203 | orig_node = msg_orignode(msg); |
163 | peer_node = tipc_port_peernode(&tsk->port); | 204 | peer_node = tsk_peer_node(&tsk->port); |
164 | 205 | ||
165 | if (likely(orig_node == peer_node)) | 206 | if (likely(orig_node == peer_node)) |
166 | return true; | 207 | return true; |
@@ -258,9 +299,9 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
258 | atomic_set(&tsk->dupl_rcvcnt, 0); | 299 | atomic_set(&tsk->dupl_rcvcnt, 0); |
259 | 300 | ||
260 | if (sock->state == SS_READY) { | 301 | if (sock->state == SS_READY) { |
261 | tipc_port_set_unreturnable(port, true); | 302 | tsk_set_unreturnable(port, true); |
262 | if (sock->type == SOCK_DGRAM) | 303 | if (sock->type == SOCK_DGRAM) |
263 | tipc_port_set_unreliable(port, true); | 304 | tsk_set_unreliable(port, true); |
264 | } | 305 | } |
265 | return 0; | 306 | return 0; |
266 | } | 307 | } |
@@ -373,7 +414,7 @@ static int tipc_release(struct socket *sock) | |||
373 | * Reject all unreceived messages, except on an active connection | 414 | * Reject all unreceived messages, except on an active connection |
374 | * (which disconnects locally & sends a 'FIN+' to peer) | 415 | * (which disconnects locally & sends a 'FIN+' to peer) |
375 | */ | 416 | */ |
376 | dnode = tipc_port_peernode(port); | 417 | dnode = tsk_peer_node(port); |
377 | while (sock->state != SS_DISCONNECTING) { | 418 | while (sock->state != SS_DISCONNECTING) { |
378 | buf = __skb_dequeue(&sk->sk_receive_queue); | 419 | buf = __skb_dequeue(&sk->sk_receive_queue); |
379 | if (buf == NULL) | 420 | if (buf == NULL) |
@@ -398,7 +439,7 @@ static int tipc_release(struct socket *sock) | |||
398 | if (port->connected) { | 439 | if (port->connected) { |
399 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, | 440 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, |
400 | SHORT_H_SIZE, 0, dnode, tipc_own_addr, | 441 | SHORT_H_SIZE, 0, dnode, tipc_own_addr, |
401 | tipc_port_peerport(port), | 442 | tsk_peer_port(port), |
402 | port->ref, TIPC_ERR_NO_PORT); | 443 | port->ref, TIPC_ERR_NO_PORT); |
403 | if (buf) | 444 | if (buf) |
404 | tipc_link_xmit(buf, dnode, port->ref); | 445 | tipc_link_xmit(buf, dnode, port->ref); |
@@ -502,8 +543,8 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, | |||
502 | if ((sock->state != SS_CONNECTED) && | 543 | if ((sock->state != SS_CONNECTED) && |
503 | ((peer != 2) || (sock->state != SS_DISCONNECTING))) | 544 | ((peer != 2) || (sock->state != SS_DISCONNECTING))) |
504 | return -ENOTCONN; | 545 | return -ENOTCONN; |
505 | addr->addr.id.ref = tipc_port_peerport(&tsk->port); | 546 | addr->addr.id.ref = tsk_peer_port(&tsk->port); |
506 | addr->addr.id.node = tipc_port_peernode(&tsk->port); | 547 | addr->addr.id.node = tsk_peer_node(&tsk->port); |
507 | } else { | 548 | } else { |
508 | addr->addr.id.ref = tsk->port.ref; | 549 | addr->addr.id.ref = tsk->port.ref; |
509 | addr->addr.id.node = tipc_own_addr; | 550 | addr->addr.id.node = tipc_own_addr; |
@@ -699,7 +740,7 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode, | |||
699 | int conn_cong; | 740 | int conn_cong; |
700 | 741 | ||
701 | /* Ignore if connection cannot be validated: */ | 742 | /* Ignore if connection cannot be validated: */ |
702 | if (!tipc_sk_peer_msg(tsk, msg)) | 743 | if (!tsk_peer_msg(tsk, msg)) |
703 | goto exit; | 744 | goto exit; |
704 | 745 | ||
705 | port->probing_state = TIPC_CONN_OK; | 746 | port->probing_state = TIPC_CONN_OK; |
@@ -986,7 +1027,7 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock, | |||
986 | } | 1027 | } |
987 | 1028 | ||
988 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); | 1029 | timeo = sock_sndtimeo(sk, m->msg_flags & MSG_DONTWAIT); |
989 | dnode = tipc_port_peernode(port); | 1030 | dnode = tsk_peer_node(port); |
990 | 1031 | ||
991 | next: | 1032 | next: |
992 | mtu = port->max_pkt; | 1033 | mtu = port->max_pkt; |
@@ -1161,8 +1202,8 @@ static void tipc_sk_send_ack(struct tipc_port *port, uint ack) | |||
1161 | { | 1202 | { |
1162 | struct sk_buff *buf = NULL; | 1203 | struct sk_buff *buf = NULL; |
1163 | struct tipc_msg *msg; | 1204 | struct tipc_msg *msg; |
1164 | u32 peer_port = tipc_port_peerport(port); | 1205 | u32 peer_port = tsk_peer_port(port); |
1165 | u32 dnode = tipc_port_peernode(port); | 1206 | u32 dnode = tsk_peer_node(port); |
1166 | 1207 | ||
1167 | if (!port->connected) | 1208 | if (!port->connected) |
1168 | return; | 1209 | return; |
@@ -1260,7 +1301,7 @@ restart: | |||
1260 | 1301 | ||
1261 | /* Discard an empty non-errored message & try again */ | 1302 | /* Discard an empty non-errored message & try again */ |
1262 | if ((!sz) && (!err)) { | 1303 | if ((!sz) && (!err)) { |
1263 | advance_rx_queue(sk); | 1304 | tsk_advance_rx_queue(sk); |
1264 | goto restart; | 1305 | goto restart; |
1265 | } | 1306 | } |
1266 | 1307 | ||
@@ -1298,7 +1339,7 @@ restart: | |||
1298 | tipc_sk_send_ack(port, tsk->rcv_unacked); | 1339 | tipc_sk_send_ack(port, tsk->rcv_unacked); |
1299 | tsk->rcv_unacked = 0; | 1340 | tsk->rcv_unacked = 0; |
1300 | } | 1341 | } |
1301 | advance_rx_queue(sk); | 1342 | tsk_advance_rx_queue(sk); |
1302 | } | 1343 | } |
1303 | exit: | 1344 | exit: |
1304 | release_sock(sk); | 1345 | release_sock(sk); |
@@ -1360,7 +1401,7 @@ restart: | |||
1360 | 1401 | ||
1361 | /* Discard an empty non-errored message & try again */ | 1402 | /* Discard an empty non-errored message & try again */ |
1362 | if ((!sz) && (!err)) { | 1403 | if ((!sz) && (!err)) { |
1363 | advance_rx_queue(sk); | 1404 | tsk_advance_rx_queue(sk); |
1364 | goto restart; | 1405 | goto restart; |
1365 | } | 1406 | } |
1366 | 1407 | ||
@@ -1409,7 +1450,7 @@ restart: | |||
1409 | tipc_sk_send_ack(port, tsk->rcv_unacked); | 1450 | tipc_sk_send_ack(port, tsk->rcv_unacked); |
1410 | tsk->rcv_unacked = 0; | 1451 | tsk->rcv_unacked = 0; |
1411 | } | 1452 | } |
1412 | advance_rx_queue(sk); | 1453 | tsk_advance_rx_queue(sk); |
1413 | } | 1454 | } |
1414 | 1455 | ||
1415 | /* Loop around if more data is required */ | 1456 | /* Loop around if more data is required */ |
@@ -1480,12 +1521,12 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf) | |||
1480 | switch ((int)sock->state) { | 1521 | switch ((int)sock->state) { |
1481 | case SS_CONNECTED: | 1522 | case SS_CONNECTED: |
1482 | /* Accept only connection-based messages sent by peer */ | 1523 | /* Accept only connection-based messages sent by peer */ |
1483 | if (tipc_sk_peer_msg(tsk, msg)) { | 1524 | if (tsk_peer_msg(tsk, msg)) { |
1484 | if (unlikely(msg_errcode(msg))) { | 1525 | if (unlikely(msg_errcode(msg))) { |
1485 | sock->state = SS_DISCONNECTING; | 1526 | sock->state = SS_DISCONNECTING; |
1486 | port->connected = 0; | 1527 | port->connected = 0; |
1487 | /* let timer expire on it's own */ | 1528 | /* let timer expire on it's own */ |
1488 | tipc_node_remove_conn(tipc_port_peernode(port), | 1529 | tipc_node_remove_conn(tsk_peer_node(port), |
1489 | port->ref); | 1530 | port->ref); |
1490 | } | 1531 | } |
1491 | retval = TIPC_OK; | 1532 | retval = TIPC_OK; |
@@ -1919,13 +1960,13 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1919 | * Reject any stray messages received by new socket | 1960 | * Reject any stray messages received by new socket |
1920 | * before the socket lock was taken (very, very unlikely) | 1961 | * before the socket lock was taken (very, very unlikely) |
1921 | */ | 1962 | */ |
1922 | reject_rx_queue(new_sk); | 1963 | tsk_rej_rx_queue(new_sk); |
1923 | 1964 | ||
1924 | /* Connect new socket to it's peer */ | 1965 | /* Connect new socket to it's peer */ |
1925 | tipc_sk_finish_conn(new_port, msg_origport(msg), msg_orignode(msg)); | 1966 | tipc_sk_finish_conn(new_port, msg_origport(msg), msg_orignode(msg)); |
1926 | new_sock->state = SS_CONNECTED; | 1967 | new_sock->state = SS_CONNECTED; |
1927 | 1968 | ||
1928 | tipc_port_set_importance(new_port, msg_importance(msg)); | 1969 | tsk_set_importance(new_port, msg_importance(msg)); |
1929 | if (msg_named(msg)) { | 1970 | if (msg_named(msg)) { |
1930 | new_port->conn_type = msg_nametype(msg); | 1971 | new_port->conn_type = msg_nametype(msg); |
1931 | new_port->conn_instance = msg_nameinst(msg); | 1972 | new_port->conn_instance = msg_nameinst(msg); |
@@ -1938,7 +1979,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1938 | if (!msg_data_sz(msg)) { | 1979 | if (!msg_data_sz(msg)) { |
1939 | struct msghdr m = {NULL,}; | 1980 | struct msghdr m = {NULL,}; |
1940 | 1981 | ||
1941 | advance_rx_queue(sk); | 1982 | tsk_advance_rx_queue(sk); |
1942 | tipc_send_packet(NULL, new_sock, &m, 0); | 1983 | tipc_send_packet(NULL, new_sock, &m, 0); |
1943 | } else { | 1984 | } else { |
1944 | __skb_dequeue(&sk->sk_receive_queue); | 1985 | __skb_dequeue(&sk->sk_receive_queue); |
@@ -1990,11 +2031,11 @@ restart: | |||
1990 | tipc_link_xmit(buf, dnode, port->ref); | 2031 | tipc_link_xmit(buf, dnode, port->ref); |
1991 | tipc_node_remove_conn(dnode, port->ref); | 2032 | tipc_node_remove_conn(dnode, port->ref); |
1992 | } else { | 2033 | } else { |
1993 | dnode = tipc_port_peernode(port); | 2034 | dnode = tsk_peer_node(port); |
1994 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, | 2035 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, |
1995 | TIPC_CONN_MSG, SHORT_H_SIZE, | 2036 | TIPC_CONN_MSG, SHORT_H_SIZE, |
1996 | 0, dnode, tipc_own_addr, | 2037 | 0, dnode, tipc_own_addr, |
1997 | tipc_port_peerport(port), | 2038 | tsk_peer_port(port), |
1998 | port->ref, TIPC_CONN_SHUTDOWN); | 2039 | port->ref, TIPC_CONN_SHUTDOWN); |
1999 | tipc_link_xmit(buf, dnode, port->ref); | 2040 | tipc_link_xmit(buf, dnode, port->ref); |
2000 | } | 2041 | } |
@@ -2040,8 +2081,8 @@ static void tipc_sk_timeout(unsigned long ref) | |||
2040 | bh_unlock_sock(sk); | 2081 | bh_unlock_sock(sk); |
2041 | goto exit; | 2082 | goto exit; |
2042 | } | 2083 | } |
2043 | peer_port = tipc_port_peerport(port); | 2084 | peer_port = tsk_peer_port(port); |
2044 | peer_node = tipc_port_peernode(port); | 2085 | peer_node = tsk_peer_node(port); |
2045 | 2086 | ||
2046 | if (port->probing_state == TIPC_CONN_PROBING) { | 2087 | if (port->probing_state == TIPC_CONN_PROBING) { |
2047 | /* Previous probe not answered -> self abort */ | 2088 | /* Previous probe not answered -> self abort */ |
@@ -2132,8 +2173,8 @@ static int tipc_sk_show(struct tipc_port *port, char *buf, | |||
2132 | ret = tipc_snprintf(buf, len, "%-10u:", port->ref); | 2173 | ret = tipc_snprintf(buf, len, "%-10u:", port->ref); |
2133 | 2174 | ||
2134 | if (port->connected) { | 2175 | if (port->connected) { |
2135 | u32 dport = tipc_port_peerport(port); | 2176 | u32 dport = tsk_peer_port(port); |
2136 | u32 destnode = tipc_port_peernode(port); | 2177 | u32 destnode = tsk_peer_node(port); |
2137 | 2178 | ||
2138 | ret += tipc_snprintf(buf + ret, len - ret, | 2179 | ret += tipc_snprintf(buf + ret, len - ret, |
2139 | " connected to <%u.%u.%u:%u>", | 2180 | " connected to <%u.%u.%u:%u>", |
@@ -2248,16 +2289,16 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt, | |||
2248 | 2289 | ||
2249 | switch (opt) { | 2290 | switch (opt) { |
2250 | case TIPC_IMPORTANCE: | 2291 | case TIPC_IMPORTANCE: |
2251 | res = tipc_port_set_importance(port, value); | 2292 | res = tsk_set_importance(port, value); |
2252 | break; | 2293 | break; |
2253 | case TIPC_SRC_DROPPABLE: | 2294 | case TIPC_SRC_DROPPABLE: |
2254 | if (sock->type != SOCK_STREAM) | 2295 | if (sock->type != SOCK_STREAM) |
2255 | tipc_port_set_unreliable(port, value); | 2296 | tsk_set_unreliable(port, value); |
2256 | else | 2297 | else |
2257 | res = -ENOPROTOOPT; | 2298 | res = -ENOPROTOOPT; |
2258 | break; | 2299 | break; |
2259 | case TIPC_DEST_DROPPABLE: | 2300 | case TIPC_DEST_DROPPABLE: |
2260 | tipc_port_set_unreturnable(port, value); | 2301 | tsk_set_unreturnable(port, value); |
2261 | break; | 2302 | break; |
2262 | case TIPC_CONN_TIMEOUT: | 2303 | case TIPC_CONN_TIMEOUT: |
2263 | tipc_sk(sk)->conn_timeout = value; | 2304 | tipc_sk(sk)->conn_timeout = value; |
@@ -2307,13 +2348,13 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt, | |||
2307 | 2348 | ||
2308 | switch (opt) { | 2349 | switch (opt) { |
2309 | case TIPC_IMPORTANCE: | 2350 | case TIPC_IMPORTANCE: |
2310 | value = tipc_port_importance(port); | 2351 | value = tsk_importance(port); |
2311 | break; | 2352 | break; |
2312 | case TIPC_SRC_DROPPABLE: | 2353 | case TIPC_SRC_DROPPABLE: |
2313 | value = tipc_port_unreliable(port); | 2354 | value = tsk_unreliable(port); |
2314 | break; | 2355 | break; |
2315 | case TIPC_DEST_DROPPABLE: | 2356 | case TIPC_DEST_DROPPABLE: |
2316 | value = tipc_port_unreturnable(port); | 2357 | value = tsk_unreturnable(port); |
2317 | break; | 2358 | break; |
2318 | case TIPC_CONN_TIMEOUT: | 2359 | case TIPC_CONN_TIMEOUT: |
2319 | value = tipc_sk(sk)->conn_timeout; | 2360 | value = tipc_sk(sk)->conn_timeout; |