aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-05-03 15:51:17 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-03 15:51:17 -0400
commite34b1638d02bef8c3278af30ee73077c5babc082 (patch)
treef8ce3ae55f12a36bc4361d9ee515b3f301051c65 /net/tipc
parent2b84af94a3932b1dcb716d1898edb18b7325dbea (diff)
parent10724cc7bb7832b482df049c20fd824d928c5eaa (diff)
Merge branch 'tipc-next'
Jon Maloy says: ==================== tipc: redesign socket-level flow control The socket-level flow control in TIPC has long been due for a major overhaul. This series fixes this. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/core.c8
-rw-r--r--net/tipc/msg.h14
-rw-r--r--net/tipc/node.c21
-rw-r--r--net/tipc/node.h6
-rw-r--r--net/tipc/socket.c144
-rw-r--r--net/tipc/socket.h17
6 files changed, 145 insertions, 65 deletions
diff --git a/net/tipc/core.c b/net/tipc/core.c
index e2bdb07a49a2..fe1b062c4f18 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -112,11 +112,9 @@ static int __init tipc_init(void)
112 112
113 pr_info("Activated (version " TIPC_MOD_VER ")\n"); 113 pr_info("Activated (version " TIPC_MOD_VER ")\n");
114 114
115 sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << 115 sysctl_tipc_rmem[0] = RCVBUF_MIN;
116 TIPC_LOW_IMPORTANCE; 116 sysctl_tipc_rmem[1] = RCVBUF_DEF;
117 sysctl_tipc_rmem[1] = TIPC_CONN_OVERLOAD_LIMIT >> 4 << 117 sysctl_tipc_rmem[2] = RCVBUF_MAX;
118 TIPC_CRITICAL_IMPORTANCE;
119 sysctl_tipc_rmem[2] = TIPC_CONN_OVERLOAD_LIMIT;
120 118
121 err = tipc_netlink_start(); 119 err = tipc_netlink_start();
122 if (err) 120 if (err)
diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index 58bf51541813..024da8af91f0 100644
--- a/net/tipc/msg.h
+++ b/net/tipc/msg.h
@@ -743,16 +743,26 @@ static inline void msg_set_msgcnt(struct tipc_msg *m, u16 n)
743 msg_set_bits(m, 9, 16, 0xffff, n); 743 msg_set_bits(m, 9, 16, 0xffff, n);
744} 744}
745 745
746static inline u32 msg_bcast_tag(struct tipc_msg *m) 746static inline u32 msg_conn_ack(struct tipc_msg *m)
747{ 747{
748 return msg_bits(m, 9, 16, 0xffff); 748 return msg_bits(m, 9, 16, 0xffff);
749} 749}
750 750
751static inline void msg_set_bcast_tag(struct tipc_msg *m, u32 n) 751static inline void msg_set_conn_ack(struct tipc_msg *m, u32 n)
752{ 752{
753 msg_set_bits(m, 9, 16, 0xffff, n); 753 msg_set_bits(m, 9, 16, 0xffff, n);
754} 754}
755 755
756static inline u32 msg_adv_win(struct tipc_msg *m)
757{
758 return msg_bits(m, 9, 0, 0xffff);
759}
760
761static inline void msg_set_adv_win(struct tipc_msg *m, u32 n)
762{
763 msg_set_bits(m, 9, 0, 0xffff, n);
764}
765
756static inline u32 msg_max_pkt(struct tipc_msg *m) 766static inline u32 msg_max_pkt(struct tipc_msg *m)
757{ 767{
758 return msg_bits(m, 9, 16, 0xffff) * 4; 768 return msg_bits(m, 9, 16, 0xffff) * 4;
diff --git a/net/tipc/node.c b/net/tipc/node.c
index c29915688230..29cc85319327 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/node.c: TIPC node management routines 2 * net/tipc/node.c: TIPC node management routines
3 * 3 *
4 * Copyright (c) 2000-2006, 2012-2015, Ericsson AB 4 * Copyright (c) 2000-2006, 2012-2016, Ericsson AB
5 * Copyright (c) 2005-2006, 2010-2014, Wind River Systems 5 * Copyright (c) 2005-2006, 2010-2014, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -191,6 +191,20 @@ int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel)
191 tipc_node_put(n); 191 tipc_node_put(n);
192 return mtu; 192 return mtu;
193} 193}
194
195u16 tipc_node_get_capabilities(struct net *net, u32 addr)
196{
197 struct tipc_node *n;
198 u16 caps;
199
200 n = tipc_node_find(net, addr);
201 if (unlikely(!n))
202 return TIPC_NODE_CAPABILITIES;
203 caps = n->capabilities;
204 tipc_node_put(n);
205 return caps;
206}
207
194/* 208/*
195 * A trivial power-of-two bitmask technique is used for speed, since this 209 * A trivial power-of-two bitmask technique is used for speed, since this
196 * operation is done for every incoming TIPC packet. The number of hash table 210 * operation is done for every incoming TIPC packet. The number of hash table
@@ -304,8 +318,11 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u16 capabilities)
304 318
305 spin_lock_bh(&tn->node_list_lock); 319 spin_lock_bh(&tn->node_list_lock);
306 n = tipc_node_find(net, addr); 320 n = tipc_node_find(net, addr);
307 if (n) 321 if (n) {
322 /* Same node may come back with new capabilities */
323 n->capabilities = capabilities;
308 goto exit; 324 goto exit;
325 }
309 n = kzalloc(sizeof(*n), GFP_ATOMIC); 326 n = kzalloc(sizeof(*n), GFP_ATOMIC);
310 if (!n) { 327 if (!n) {
311 pr_warn("Node creation failed, no memory\n"); 328 pr_warn("Node creation failed, no memory\n");
diff --git a/net/tipc/node.h b/net/tipc/node.h
index f39d9d06e8bb..8264b3d97dc4 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -45,10 +45,11 @@
45/* Optional capabilities supported by this code version 45/* Optional capabilities supported by this code version
46 */ 46 */
47enum { 47enum {
48 TIPC_BCAST_SYNCH = (1 << 1) 48 TIPC_BCAST_SYNCH = (1 << 1),
49 TIPC_BLOCK_FLOWCTL = (2 << 1)
49}; 50};
50 51
51#define TIPC_NODE_CAPABILITIES TIPC_BCAST_SYNCH 52#define TIPC_NODE_CAPABILITIES (TIPC_BCAST_SYNCH | TIPC_BLOCK_FLOWCTL)
52#define INVALID_BEARER_ID -1 53#define INVALID_BEARER_ID -1
53 54
54void tipc_node_stop(struct net *net); 55void tipc_node_stop(struct net *net);
@@ -70,6 +71,7 @@ void tipc_node_broadcast(struct net *net, struct sk_buff *skb);
70int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port); 71int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port);
71void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port); 72void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port);
72int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel); 73int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel);
74u16 tipc_node_get_capabilities(struct net *net, u32 addr);
73int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb); 75int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb);
74int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb); 76int tipc_nl_node_dump_link(struct sk_buff *skb, struct netlink_callback *cb);
75int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info); 77int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info);
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 3eeb50a27b89..12628890c219 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -96,8 +96,11 @@ struct tipc_sock {
96 uint conn_timeout; 96 uint conn_timeout;
97 atomic_t dupl_rcvcnt; 97 atomic_t dupl_rcvcnt;
98 bool link_cong; 98 bool link_cong;
99 uint sent_unacked; 99 u16 snt_unacked;
100 uint rcv_unacked; 100 u16 snd_win;
101 u16 peer_caps;
102 u16 rcv_unacked;
103 u16 rcv_win;
101 struct sockaddr_tipc remote; 104 struct sockaddr_tipc remote;
102 struct rhash_head node; 105 struct rhash_head node;
103 struct rcu_head rcu; 106 struct rcu_head rcu;
@@ -227,9 +230,29 @@ static struct tipc_sock *tipc_sk(const struct sock *sk)
227 return container_of(sk, struct tipc_sock, sk); 230 return container_of(sk, struct tipc_sock, sk);
228} 231}
229 232
230static int tsk_conn_cong(struct tipc_sock *tsk) 233static bool tsk_conn_cong(struct tipc_sock *tsk)
231{ 234{
232 return tsk->sent_unacked >= TIPC_FLOWCTRL_WIN; 235 return tsk->snt_unacked >= tsk->snd_win;
236}
237
238/* tsk_blocks(): translate a buffer size in bytes to number of
239 * advertisable blocks, taking into account the ratio truesize(len)/len
240 * We can trust that this ratio is always < 4 for len >= FLOWCTL_BLK_SZ
241 */
242static u16 tsk_adv_blocks(int len)
243{
244 return len / FLOWCTL_BLK_SZ / 4;
245}
246
247/* tsk_inc(): increment counter for sent or received data
248 * - If block based flow control is not supported by peer we
249 * fall back to message based ditto, incrementing the counter
250 */
251static u16 tsk_inc(struct tipc_sock *tsk, int msglen)
252{
253 if (likely(tsk->peer_caps & TIPC_BLOCK_FLOWCTL))
254 return ((msglen / FLOWCTL_BLK_SZ) + 1);
255 return 1;
233} 256}
234 257
235/** 258/**
@@ -377,9 +400,12 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
377 sk->sk_write_space = tipc_write_space; 400 sk->sk_write_space = tipc_write_space;
378 sk->sk_destruct = tipc_sock_destruct; 401 sk->sk_destruct = tipc_sock_destruct;
379 tsk->conn_timeout = CONN_TIMEOUT_DEFAULT; 402 tsk->conn_timeout = CONN_TIMEOUT_DEFAULT;
380 tsk->sent_unacked = 0;
381 atomic_set(&tsk->dupl_rcvcnt, 0); 403 atomic_set(&tsk->dupl_rcvcnt, 0);
382 404
405 /* Start out with safe limits until we receive an advertised window */
406 tsk->snd_win = tsk_adv_blocks(RCVBUF_MIN);
407 tsk->rcv_win = tsk->snd_win;
408
383 if (sock->state == SS_READY) { 409 if (sock->state == SS_READY) {
384 tsk_set_unreturnable(tsk, true); 410 tsk_set_unreturnable(tsk, true);
385 if (sock->type == SOCK_DGRAM) 411 if (sock->type == SOCK_DGRAM)
@@ -775,7 +801,7 @@ static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb)
775 struct sock *sk = &tsk->sk; 801 struct sock *sk = &tsk->sk;
776 struct tipc_msg *hdr = buf_msg(skb); 802 struct tipc_msg *hdr = buf_msg(skb);
777 int mtyp = msg_type(hdr); 803 int mtyp = msg_type(hdr);
778 int conn_cong; 804 bool conn_cong;
779 805
780 /* Ignore if connection cannot be validated: */ 806 /* Ignore if connection cannot be validated: */
781 if (!tsk_peer_msg(tsk, hdr)) 807 if (!tsk_peer_msg(tsk, hdr))
@@ -789,7 +815,9 @@ static void tipc_sk_proto_rcv(struct tipc_sock *tsk, struct sk_buff *skb)
789 return; 815 return;
790 } else if (mtyp == CONN_ACK) { 816 } else if (mtyp == CONN_ACK) {
791 conn_cong = tsk_conn_cong(tsk); 817 conn_cong = tsk_conn_cong(tsk);
792 tsk->sent_unacked -= msg_msgcnt(hdr); 818 tsk->snt_unacked -= msg_conn_ack(hdr);
819 if (tsk->peer_caps & TIPC_BLOCK_FLOWCTL)
820 tsk->snd_win = msg_adv_win(hdr);
793 if (conn_cong) 821 if (conn_cong)
794 sk->sk_write_space(sk); 822 sk->sk_write_space(sk);
795 } else if (mtyp != CONN_PROBE_REPLY) { 823 } else if (mtyp != CONN_PROBE_REPLY) {
@@ -1020,12 +1048,14 @@ static int __tipc_send_stream(struct socket *sock, struct msghdr *m, size_t dsz)
1020 u32 dnode; 1048 u32 dnode;
1021 uint mtu, send, sent = 0; 1049 uint mtu, send, sent = 0;
1022 struct iov_iter save; 1050 struct iov_iter save;
1051 int hlen = MIN_H_SIZE;
1023 1052
1024 /* Handle implied connection establishment */ 1053 /* Handle implied connection establishment */
1025 if (unlikely(dest)) { 1054 if (unlikely(dest)) {
1026 rc = __tipc_sendmsg(sock, m, dsz); 1055 rc = __tipc_sendmsg(sock, m, dsz);
1056 hlen = msg_hdr_sz(mhdr);
1027 if (dsz && (dsz == rc)) 1057 if (dsz && (dsz == rc))
1028 tsk->sent_unacked = 1; 1058 tsk->snt_unacked = tsk_inc(tsk, dsz + hlen);
1029 return rc; 1059 return rc;
1030 } 1060 }
1031 if (dsz > (uint)INT_MAX) 1061 if (dsz > (uint)INT_MAX)
@@ -1054,7 +1084,7 @@ next:
1054 if (likely(!tsk_conn_cong(tsk))) { 1084 if (likely(!tsk_conn_cong(tsk))) {
1055 rc = tipc_node_xmit(net, &pktchain, dnode, portid); 1085 rc = tipc_node_xmit(net, &pktchain, dnode, portid);
1056 if (likely(!rc)) { 1086 if (likely(!rc)) {
1057 tsk->sent_unacked++; 1087 tsk->snt_unacked += tsk_inc(tsk, send + hlen);
1058 sent += send; 1088 sent += send;
1059 if (sent == dsz) 1089 if (sent == dsz)
1060 return dsz; 1090 return dsz;
@@ -1118,6 +1148,13 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
1118 sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv); 1148 sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv);
1119 tipc_node_add_conn(net, peer_node, tsk->portid, peer_port); 1149 tipc_node_add_conn(net, peer_node, tsk->portid, peer_port);
1120 tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid); 1150 tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid);
1151 tsk->peer_caps = tipc_node_get_capabilities(net, peer_node);
1152 if (tsk->peer_caps & TIPC_BLOCK_FLOWCTL)
1153 return;
1154
1155 /* Fall back to message based flow control */
1156 tsk->rcv_win = FLOWCTL_MSG_WIN;
1157 tsk->snd_win = FLOWCTL_MSG_WIN;
1121} 1158}
1122 1159
1123/** 1160/**
@@ -1214,7 +1251,7 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
1214 return 0; 1251 return 0;
1215} 1252}
1216 1253
1217static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) 1254static void tipc_sk_send_ack(struct tipc_sock *tsk)
1218{ 1255{
1219 struct net *net = sock_net(&tsk->sk); 1256 struct net *net = sock_net(&tsk->sk);
1220 struct sk_buff *skb = NULL; 1257 struct sk_buff *skb = NULL;
@@ -1230,7 +1267,14 @@ static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack)
1230 if (!skb) 1267 if (!skb)
1231 return; 1268 return;
1232 msg = buf_msg(skb); 1269 msg = buf_msg(skb);
1233 msg_set_msgcnt(msg, ack); 1270 msg_set_conn_ack(msg, tsk->rcv_unacked);
1271 tsk->rcv_unacked = 0;
1272
1273 /* Adjust to and advertize the correct window limit */
1274 if (tsk->peer_caps & TIPC_BLOCK_FLOWCTL) {
1275 tsk->rcv_win = tsk_adv_blocks(tsk->sk.sk_rcvbuf);
1276 msg_set_adv_win(msg, tsk->rcv_win);
1277 }
1234 tipc_node_xmit_skb(net, skb, dnode, msg_link_selector(msg)); 1278 tipc_node_xmit_skb(net, skb, dnode, msg_link_selector(msg));
1235} 1279}
1236 1280
@@ -1288,7 +1332,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, size_t buf_len,
1288 long timeo; 1332 long timeo;
1289 unsigned int sz; 1333 unsigned int sz;
1290 u32 err; 1334 u32 err;
1291 int res; 1335 int res, hlen;
1292 1336
1293 /* Catch invalid receive requests */ 1337 /* Catch invalid receive requests */
1294 if (unlikely(!buf_len)) 1338 if (unlikely(!buf_len))
@@ -1313,6 +1357,7 @@ restart:
1313 buf = skb_peek(&sk->sk_receive_queue); 1357 buf = skb_peek(&sk->sk_receive_queue);
1314 msg = buf_msg(buf); 1358 msg = buf_msg(buf);
1315 sz = msg_data_sz(msg); 1359 sz = msg_data_sz(msg);
1360 hlen = msg_hdr_sz(msg);
1316 err = msg_errcode(msg); 1361 err = msg_errcode(msg);
1317 1362
1318 /* Discard an empty non-errored message & try again */ 1363 /* Discard an empty non-errored message & try again */
@@ -1335,7 +1380,7 @@ restart:
1335 sz = buf_len; 1380 sz = buf_len;
1336 m->msg_flags |= MSG_TRUNC; 1381 m->msg_flags |= MSG_TRUNC;
1337 } 1382 }
1338 res = skb_copy_datagram_msg(buf, msg_hdr_sz(msg), m, sz); 1383 res = skb_copy_datagram_msg(buf, hlen, m, sz);
1339 if (res) 1384 if (res)
1340 goto exit; 1385 goto exit;
1341 res = sz; 1386 res = sz;
@@ -1347,15 +1392,15 @@ restart:
1347 res = -ECONNRESET; 1392 res = -ECONNRESET;
1348 } 1393 }
1349 1394
1350 /* Consume received message (optional) */ 1395 if (unlikely(flags & MSG_PEEK))
1351 if (likely(!(flags & MSG_PEEK))) { 1396 goto exit;
1352 if ((sock->state != SS_READY) && 1397
1353 (++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) { 1398 if (likely(sock->state != SS_READY)) {
1354 tipc_sk_send_ack(tsk, tsk->rcv_unacked); 1399 tsk->rcv_unacked += tsk_inc(tsk, hlen + sz);
1355 tsk->rcv_unacked = 0; 1400 if (unlikely(tsk->rcv_unacked >= (tsk->rcv_win / 4)))
1356 } 1401 tipc_sk_send_ack(tsk);
1357 tsk_advance_rx_queue(sk);
1358 } 1402 }
1403 tsk_advance_rx_queue(sk);
1359exit: 1404exit:
1360 release_sock(sk); 1405 release_sock(sk);
1361 return res; 1406 return res;
@@ -1384,7 +1429,7 @@ static int tipc_recv_stream(struct socket *sock, struct msghdr *m,
1384 int sz_to_copy, target, needed; 1429 int sz_to_copy, target, needed;
1385 int sz_copied = 0; 1430 int sz_copied = 0;
1386 u32 err; 1431 u32 err;
1387 int res = 0; 1432 int res = 0, hlen;
1388 1433
1389 /* Catch invalid receive attempts */ 1434 /* Catch invalid receive attempts */
1390 if (unlikely(!buf_len)) 1435 if (unlikely(!buf_len))
@@ -1410,6 +1455,7 @@ restart:
1410 buf = skb_peek(&sk->sk_receive_queue); 1455 buf = skb_peek(&sk->sk_receive_queue);
1411 msg = buf_msg(buf); 1456 msg = buf_msg(buf);
1412 sz = msg_data_sz(msg); 1457 sz = msg_data_sz(msg);
1458 hlen = msg_hdr_sz(msg);
1413 err = msg_errcode(msg); 1459 err = msg_errcode(msg);
1414 1460
1415 /* Discard an empty non-errored message & try again */ 1461 /* Discard an empty non-errored message & try again */
@@ -1434,8 +1480,7 @@ restart:
1434 needed = (buf_len - sz_copied); 1480 needed = (buf_len - sz_copied);
1435 sz_to_copy = (sz <= needed) ? sz : needed; 1481 sz_to_copy = (sz <= needed) ? sz : needed;
1436 1482
1437 res = skb_copy_datagram_msg(buf, msg_hdr_sz(msg) + offset, 1483 res = skb_copy_datagram_msg(buf, hlen + offset, m, sz_to_copy);
1438 m, sz_to_copy);
1439 if (res) 1484 if (res)
1440 goto exit; 1485 goto exit;
1441 1486
@@ -1457,20 +1502,18 @@ restart:
1457 res = -ECONNRESET; 1502 res = -ECONNRESET;
1458 } 1503 }
1459 1504
1460 /* Consume received message (optional) */ 1505 if (unlikely(flags & MSG_PEEK))
1461 if (likely(!(flags & MSG_PEEK))) { 1506 goto exit;
1462 if (unlikely(++tsk->rcv_unacked >= TIPC_CONNACK_INTV)) { 1507
1463 tipc_sk_send_ack(tsk, tsk->rcv_unacked); 1508 tsk->rcv_unacked += tsk_inc(tsk, hlen + sz);
1464 tsk->rcv_unacked = 0; 1509 if (unlikely(tsk->rcv_unacked >= (tsk->rcv_win / 4)))
1465 } 1510 tipc_sk_send_ack(tsk);
1466 tsk_advance_rx_queue(sk); 1511 tsk_advance_rx_queue(sk);
1467 }
1468 1512
1469 /* Loop around if more data is required */ 1513 /* Loop around if more data is required */
1470 if ((sz_copied < buf_len) && /* didn't get all requested data */ 1514 if ((sz_copied < buf_len) && /* didn't get all requested data */
1471 (!skb_queue_empty(&sk->sk_receive_queue) || 1515 (!skb_queue_empty(&sk->sk_receive_queue) ||
1472 (sz_copied < target)) && /* and more is ready or required */ 1516 (sz_copied < target)) && /* and more is ready or required */
1473 (!(flags & MSG_PEEK)) && /* and aren't just peeking at data */
1474 (!err)) /* and haven't reached a FIN */ 1517 (!err)) /* and haven't reached a FIN */
1475 goto restart; 1518 goto restart;
1476 1519
@@ -1602,30 +1645,33 @@ static bool filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
1602/** 1645/**
1603 * rcvbuf_limit - get proper overload limit of socket receive queue 1646 * rcvbuf_limit - get proper overload limit of socket receive queue
1604 * @sk: socket 1647 * @sk: socket
1605 * @buf: message 1648 * @skb: message
1606 * 1649 *
1607 * For all connection oriented messages, irrespective of importance, 1650 * For connection oriented messages, irrespective of importance,
1608 * the default overload value (i.e. 67MB) is set as limit. 1651 * default queue limit is 2 MB.
1609 * 1652 *
1610 * For all connectionless messages, by default new queue limits are 1653 * For connectionless messages, queue limits are based on message
1611 * as belows: 1654 * importance as follows:
1612 * 1655 *
1613 * TIPC_LOW_IMPORTANCE (4 MB) 1656 * TIPC_LOW_IMPORTANCE (2 MB)
1614 * TIPC_MEDIUM_IMPORTANCE (8 MB) 1657 * TIPC_MEDIUM_IMPORTANCE (4 MB)
1615 * TIPC_HIGH_IMPORTANCE (16 MB) 1658 * TIPC_HIGH_IMPORTANCE (8 MB)
1616 * TIPC_CRITICAL_IMPORTANCE (32 MB) 1659 * TIPC_CRITICAL_IMPORTANCE (16 MB)
1617 * 1660 *
1618 * Returns overload limit according to corresponding message importance 1661 * Returns overload limit according to corresponding message importance
1619 */ 1662 */
1620static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *buf) 1663static unsigned int rcvbuf_limit(struct sock *sk, struct sk_buff *skb)
1621{ 1664{
1622 struct tipc_msg *msg = buf_msg(buf); 1665 struct tipc_sock *tsk = tipc_sk(sk);
1666 struct tipc_msg *hdr = buf_msg(skb);
1667
1668 if (unlikely(!msg_connected(hdr)))
1669 return sk->sk_rcvbuf << msg_importance(hdr);
1623 1670
1624 if (msg_connected(msg)) 1671 if (likely(tsk->peer_caps & TIPC_BLOCK_FLOWCTL))
1625 return sysctl_tipc_rmem[2]; 1672 return sk->sk_rcvbuf;
1626 1673
1627 return sk->sk_rcvbuf >> TIPC_CRITICAL_IMPORTANCE << 1674 return FLOWCTL_MSG_LIM;
1628 msg_importance(msg);
1629} 1675}
1630 1676
1631/** 1677/**
@@ -1748,7 +1794,7 @@ static void tipc_sk_enqueue(struct sk_buff_head *inputq, struct sock *sk,
1748 1794
1749 /* Try backlog, compensating for double-counted bytes */ 1795 /* Try backlog, compensating for double-counted bytes */
1750 dcnt = &tipc_sk(sk)->dupl_rcvcnt; 1796 dcnt = &tipc_sk(sk)->dupl_rcvcnt;
1751 if (sk->sk_backlog.len) 1797 if (!sk->sk_backlog.len)
1752 atomic_set(dcnt, 0); 1798 atomic_set(dcnt, 0);
1753 lim = rcvbuf_limit(sk, skb) + atomic_read(dcnt); 1799 lim = rcvbuf_limit(sk, skb) + atomic_read(dcnt);
1754 if (likely(!sk_add_backlog(sk, skb, lim))) 1800 if (likely(!sk_add_backlog(sk, skb, lim)))
diff --git a/net/tipc/socket.h b/net/tipc/socket.h
index 4241f22069dc..06fb5944cf76 100644
--- a/net/tipc/socket.h
+++ b/net/tipc/socket.h
@@ -1,6 +1,6 @@
1/* net/tipc/socket.h: Include file for TIPC socket code 1/* net/tipc/socket.h: Include file for TIPC socket code
2 * 2 *
3 * Copyright (c) 2014-2015, Ericsson AB 3 * Copyright (c) 2014-2016, Ericsson AB
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
@@ -38,10 +38,17 @@
38#include <net/sock.h> 38#include <net/sock.h>
39#include <net/genetlink.h> 39#include <net/genetlink.h>
40 40
41#define TIPC_CONNACK_INTV 256 41/* Compatibility values for deprecated message based flow control */
42#define TIPC_FLOWCTRL_WIN (TIPC_CONNACK_INTV * 2) 42#define FLOWCTL_MSG_WIN 512
43#define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \ 43#define FLOWCTL_MSG_LIM ((FLOWCTL_MSG_WIN * 2 + 1) * SKB_TRUESIZE(MAX_MSG_SIZE))
44 SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE)) 44
45#define FLOWCTL_BLK_SZ 1024
46
47/* Socket receive buffer sizes */
48#define RCVBUF_MIN (FLOWCTL_BLK_SZ * 512)
49#define RCVBUF_DEF (FLOWCTL_BLK_SZ * 1024 * 2)
50#define RCVBUF_MAX (FLOWCTL_BLK_SZ * 1024 * 16)
51
45int tipc_socket_init(void); 52int tipc_socket_init(void);
46void tipc_socket_stop(void); 53void tipc_socket_stop(void);
47void tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq); 54void tipc_sk_rcv(struct net *net, struct sk_buff_head *inputq);