aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2016-03-03 14:23:21 -0500
committerDavid S. Miller <davem@davemloft.net>2016-03-06 23:01:20 -0500
commite74a386d70c793ef44678b44b021c99094b28c47 (patch)
tree9aad55ccddd9755bdf9ea80d3e6e3fe01cab505c /net/tipc
parent34f65dbb6c7572b826d836d62b99de32ecf2af48 (diff)
tipc: remove pre-allocated message header in link struct
Until now, we have kept a pre-allocated protocol message header aggregated into struct tipc_link. Apart from adding unnecessary footprint to the link instances, this requires extra code both to initialize and re-initialize it. We now remove this sub-optimization. This change also makes it possible to clean up the function tipc_build_proto_msg() and remove a couple of small functions that were accessing the mentioned header. In particular, we can replace all occurrences of the local function call link_own_addr(link) with the generic tipc_own_addr(net). Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/bcast.c5
-rw-r--r--net/tipc/bcast.h1
-rw-r--r--net/tipc/link.c114
-rw-r--r--net/tipc/link.h1
-rw-r--r--net/tipc/net.c1
5 files changed, 45 insertions, 77 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index e401108360a2..ae469b37d852 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -412,11 +412,6 @@ enomem:
412 return -ENOMEM; 412 return -ENOMEM;
413} 413}
414 414
415void tipc_bcast_reinit(struct net *net)
416{
417 tipc_link_reinit(tipc_bc_sndlink(net), tipc_own_addr(net));
418}
419
420void tipc_bcast_stop(struct net *net) 415void tipc_bcast_stop(struct net *net)
421{ 416{
422 struct tipc_net *tn = net_generic(net, tipc_net_id); 417 struct tipc_net *tn = net_generic(net, tipc_net_id);
diff --git a/net/tipc/bcast.h b/net/tipc/bcast.h
index 1944c6c00bb9..d5e79b3767fd 100644
--- a/net/tipc/bcast.h
+++ b/net/tipc/bcast.h
@@ -46,7 +46,6 @@ struct tipc_node_map;
46extern const char tipc_bclink_name[]; 46extern const char tipc_bclink_name[];
47 47
48int tipc_bcast_init(struct net *net); 48int tipc_bcast_init(struct net *net);
49void tipc_bcast_reinit(struct net *net);
50void tipc_bcast_stop(struct net *net); 49void tipc_bcast_stop(struct net *net);
51void tipc_bcast_add_peer(struct net *net, struct tipc_link *l, 50void tipc_bcast_add_peer(struct net *net, struct tipc_link *l,
52 struct sk_buff_head *xmitq); 51 struct sk_buff_head *xmitq);
diff --git a/net/tipc/link.c b/net/tipc/link.c
index e31d92f80572..fc2fa833749e 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/link.c: TIPC link code 2 * net/tipc/link.c: TIPC link code
3 * 3 *
4 * Copyright (c) 1996-2007, 2012-2015, Ericsson AB 4 * Copyright (c) 1996-2007, 2012-2016, Ericsson AB
5 * Copyright (c) 2004-2007, 2010-2013, Wind River Systems 5 * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
@@ -127,6 +127,7 @@ struct tipc_link {
127 127
128 /* Management and link supervision data */ 128 /* Management and link supervision data */
129 u32 peer_session; 129 u32 peer_session;
130 u32 session;
130 u32 peer_bearer_id; 131 u32 peer_bearer_id;
131 u32 bearer_id; 132 u32 bearer_id;
132 u32 tolerance; 133 u32 tolerance;
@@ -136,11 +137,7 @@ struct tipc_link {
136 u16 peer_caps; 137 u16 peer_caps;
137 bool active; 138 bool active;
138 u32 silent_intv_cnt; 139 u32 silent_intv_cnt;
139 struct { 140 char if_name[TIPC_MAX_IF_NAME];
140 unchar hdr[INT_H_SIZE];
141 unchar body[TIPC_MAX_IF_NAME];
142 } proto_msg;
143 struct tipc_msg *pmsg;
144 u32 priority; 141 u32 priority;
145 char net_plane; 142 char net_plane;
146 143
@@ -215,10 +212,11 @@ enum {
215 * Interval between NACKs when packets arrive out of order 212 * Interval between NACKs when packets arrive out of order
216 */ 213 */
217#define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2) 214#define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2)
218/* 215
219 * Out-of-range value for link session numbers 216/* Wildcard value for link session numbers. When it is known that
217 * peer endpoint is down, any session number must be accepted.
220 */ 218 */
221#define WILDCARD_SESSION 0x10000 219#define ANY_SESSION 0x10000
222 220
223/* Link FSM states: 221/* Link FSM states:
224 */ 222 */
@@ -398,16 +396,6 @@ char *tipc_link_name(struct tipc_link *l)
398 return l->name; 396 return l->name;
399} 397}
400 398
401static u32 link_own_addr(struct tipc_link *l)
402{
403 return msg_prevnode(l->pmsg);
404}
405
406void tipc_link_reinit(struct tipc_link *l, u32 addr)
407{
408 msg_set_prevnode(l->pmsg, addr);
409}
410
411/** 399/**
412 * tipc_link_create - create a new link 400 * tipc_link_create - create a new link
413 * @n: pointer to associated node 401 * @n: pointer to associated node
@@ -441,29 +429,22 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
441 struct tipc_link **link) 429 struct tipc_link **link)
442{ 430{
443 struct tipc_link *l; 431 struct tipc_link *l;
444 struct tipc_msg *hdr;
445 432
446 l = kzalloc(sizeof(*l), GFP_ATOMIC); 433 l = kzalloc(sizeof(*l), GFP_ATOMIC);
447 if (!l) 434 if (!l)
448 return false; 435 return false;
449 *link = l; 436 *link = l;
450 l->pmsg = (struct tipc_msg *)&l->proto_msg; 437 l->session = session;
451 hdr = l->pmsg;
452 tipc_msg_init(ownnode, hdr, LINK_PROTOCOL, RESET_MSG, INT_H_SIZE, peer);
453 msg_set_size(hdr, sizeof(l->proto_msg));
454 msg_set_session(hdr, session);
455 msg_set_bearer_id(hdr, l->bearer_id);
456 438
457 /* Note: peer i/f name is completed by reset/activate message */ 439 /* Note: peer i/f name is completed by reset/activate message */
458 sprintf(l->name, "%u.%u.%u:%s-%u.%u.%u:unknown", 440 sprintf(l->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
459 tipc_zone(ownnode), tipc_cluster(ownnode), tipc_node(ownnode), 441 tipc_zone(ownnode), tipc_cluster(ownnode), tipc_node(ownnode),
460 if_name, tipc_zone(peer), tipc_cluster(peer), tipc_node(peer)); 442 if_name, tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
461 strcpy((char *)msg_data(hdr), if_name); 443 strcpy(l->if_name, if_name);
462
463 l->addr = peer; 444 l->addr = peer;
464 l->peer_caps = peer_caps; 445 l->peer_caps = peer_caps;
465 l->net = net; 446 l->net = net;
466 l->peer_session = WILDCARD_SESSION; 447 l->peer_session = ANY_SESSION;
467 l->bearer_id = bearer_id; 448 l->bearer_id = bearer_id;
468 l->tolerance = tolerance; 449 l->tolerance = tolerance;
469 l->net_plane = net_plane; 450 l->net_plane = net_plane;
@@ -790,7 +771,7 @@ static int link_schedule_user(struct tipc_link *link, struct sk_buff_head *list)
790 struct tipc_msg *msg = buf_msg(skb_peek(list)); 771 struct tipc_msg *msg = buf_msg(skb_peek(list));
791 int imp = msg_importance(msg); 772 int imp = msg_importance(msg);
792 u32 oport = msg_origport(msg); 773 u32 oport = msg_origport(msg);
793 u32 addr = link_own_addr(link); 774 u32 addr = tipc_own_addr(link->net);
794 struct sk_buff *skb; 775 struct sk_buff *skb;
795 776
796 /* This really cannot happen... */ 777 /* This really cannot happen... */
@@ -839,16 +820,9 @@ void link_prepare_wakeup(struct tipc_link *l)
839 820
840void tipc_link_reset(struct tipc_link *l) 821void tipc_link_reset(struct tipc_link *l)
841{ 822{
842 /* Link is down, accept any session */ 823 l->peer_session = ANY_SESSION;
843 l->peer_session = WILDCARD_SESSION; 824 l->session++;
844
845 /* If peer is up, it only accepts an incremented session number */
846 msg_set_session(l->pmsg, msg_session(l->pmsg) + 1);
847
848 /* Prepare for renewed mtu size negotiation */
849 l->mtu = l->advertised_mtu; 825 l->mtu = l->advertised_mtu;
850
851 /* Clean up all queues and counters: */
852 __skb_queue_purge(&l->transmq); 826 __skb_queue_purge(&l->transmq);
853 __skb_queue_purge(&l->deferdq); 827 __skb_queue_purge(&l->deferdq);
854 skb_queue_splice_init(&l->wakeupq, l->inputq); 828 skb_queue_splice_init(&l->wakeupq, l->inputq);
@@ -1156,7 +1130,7 @@ int tipc_link_build_ack_msg(struct tipc_link *l, struct sk_buff_head *xmitq)
1156 1130
1157 /* Broadcast ACK must be sent via a unicast link => defer to caller */ 1131 /* Broadcast ACK must be sent via a unicast link => defer to caller */
1158 if (link_is_bc_rcvlink(l)) { 1132 if (link_is_bc_rcvlink(l)) {
1159 if (((l->rcv_nxt ^ link_own_addr(l)) & 0xf) != 0xf) 1133 if (((l->rcv_nxt ^ tipc_own_addr(l->net)) & 0xf) != 0xf)
1160 return 0; 1134 return 0;
1161 l->rcv_unacked = 0; 1135 l->rcv_unacked = 0;
1162 return TIPC_LINK_SND_BC_ACK; 1136 return TIPC_LINK_SND_BC_ACK;
@@ -1268,15 +1242,30 @@ static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1268 u16 rcvgap, int tolerance, int priority, 1242 u16 rcvgap, int tolerance, int priority,
1269 struct sk_buff_head *xmitq) 1243 struct sk_buff_head *xmitq)
1270{ 1244{
1271 struct sk_buff *skb = NULL; 1245 struct sk_buff *skb;
1272 struct tipc_msg *hdr = l->pmsg; 1246 struct tipc_msg *hdr;
1247 struct sk_buff_head *dfq = &l->deferdq;
1273 bool node_up = link_is_up(l->bc_rcvlink); 1248 bool node_up = link_is_up(l->bc_rcvlink);
1274 1249
1275 /* Don't send protocol message during reset or link failover */ 1250 /* Don't send protocol message during reset or link failover */
1276 if (tipc_link_is_blocked(l)) 1251 if (tipc_link_is_blocked(l))
1277 return; 1252 return;
1278 1253
1279 msg_set_type(hdr, mtyp); 1254 if (!tipc_link_is_up(l) && (mtyp == STATE_MSG))
1255 return;
1256
1257 if (!skb_queue_empty(dfq))
1258 rcvgap = buf_seqno(skb_peek(dfq)) - l->rcv_nxt;
1259
1260 skb = tipc_msg_create(LINK_PROTOCOL, mtyp, INT_H_SIZE,
1261 TIPC_MAX_IF_NAME, l->addr,
1262 tipc_own_addr(l->net), 0, 0, 0);
1263 if (!skb)
1264 return;
1265
1266 hdr = buf_msg(skb);
1267 msg_set_session(hdr, l->session);
1268 msg_set_bearer_id(hdr, l->bearer_id);
1280 msg_set_net_plane(hdr, l->net_plane); 1269 msg_set_net_plane(hdr, l->net_plane);
1281 msg_set_next_sent(hdr, l->snd_nxt); 1270 msg_set_next_sent(hdr, l->snd_nxt);
1282 msg_set_ack(hdr, l->rcv_nxt - 1); 1271 msg_set_ack(hdr, l->rcv_nxt - 1);
@@ -1286,36 +1275,23 @@ static void tipc_link_build_proto_msg(struct tipc_link *l, int mtyp, bool probe,
1286 msg_set_linkprio(hdr, priority); 1275 msg_set_linkprio(hdr, priority);
1287 msg_set_redundant_link(hdr, node_up); 1276 msg_set_redundant_link(hdr, node_up);
1288 msg_set_seq_gap(hdr, 0); 1277 msg_set_seq_gap(hdr, 0);
1289
1290 /* Compatibility: created msg must not be in sequence with pkt flow */
1291 msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2); 1278 msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
1292 1279
1293 if (mtyp == STATE_MSG) { 1280 if (mtyp == STATE_MSG) {
1294 if (!tipc_link_is_up(l)) 1281 msg_set_seq_gap(hdr, rcvgap);
1295 return; 1282 msg_set_size(hdr, INT_H_SIZE);
1296
1297 /* Override rcvgap if there are packets in deferred queue */
1298 if (!skb_queue_empty(&l->deferdq))
1299 rcvgap = buf_seqno(skb_peek(&l->deferdq)) - l->rcv_nxt;
1300 if (rcvgap) {
1301 msg_set_seq_gap(hdr, rcvgap);
1302 l->stats.sent_nacks++;
1303 }
1304 msg_set_probe(hdr, probe); 1283 msg_set_probe(hdr, probe);
1305 if (probe)
1306 l->stats.sent_probes++;
1307 l->stats.sent_states++; 1284 l->stats.sent_states++;
1308 l->rcv_unacked = 0; 1285 l->rcv_unacked = 0;
1309 } else { 1286 } else {
1310 /* RESET_MSG or ACTIVATE_MSG */ 1287 /* RESET_MSG or ACTIVATE_MSG */
1311 msg_set_max_pkt(hdr, l->advertised_mtu); 1288 msg_set_max_pkt(hdr, l->advertised_mtu);
1312 msg_set_ack(hdr, l->rcv_nxt - 1); 1289 strcpy(msg_data(hdr), l->if_name);
1313 msg_set_next_sent(hdr, 1);
1314 } 1290 }
1315 skb = tipc_buf_acquire(msg_size(hdr)); 1291 if (probe)
1316 if (!skb) 1292 l->stats.sent_probes++;
1317 return; 1293 if (rcvgap)
1318 skb_copy_to_linear_data(skb, hdr, msg_size(hdr)); 1294 l->stats.sent_nacks++;
1319 skb->priority = TC_PRIO_CONTROL; 1295 skb->priority = TC_PRIO_CONTROL;
1320 __skb_queue_tail(xmitq, skb); 1296 __skb_queue_tail(xmitq, skb);
1321} 1297}
@@ -1340,7 +1316,7 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
1340 1316
1341 /* At least one packet required for safe algorithm => add dummy */ 1317 /* At least one packet required for safe algorithm => add dummy */
1342 skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG, 1318 skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
1343 BASIC_H_SIZE, 0, l->addr, link_own_addr(l), 1319 BASIC_H_SIZE, 0, l->addr, tipc_own_addr(l->net),
1344 0, 0, TIPC_ERR_NO_PORT); 1320 0, 0, TIPC_ERR_NO_PORT);
1345 if (!skb) { 1321 if (!skb) {
1346 pr_warn("%sunable to create tunnel packet\n", link_co_err); 1322 pr_warn("%sunable to create tunnel packet\n", link_co_err);
@@ -1351,7 +1327,7 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
1351 __skb_queue_purge(&tmpxq); 1327 __skb_queue_purge(&tmpxq);
1352 1328
1353 /* Initialize reusable tunnel packet header */ 1329 /* Initialize reusable tunnel packet header */
1354 tipc_msg_init(link_own_addr(l), &tnlhdr, TUNNEL_PROTOCOL, 1330 tipc_msg_init(tipc_own_addr(l->net), &tnlhdr, TUNNEL_PROTOCOL,
1355 mtyp, INT_H_SIZE, l->addr); 1331 mtyp, INT_H_SIZE, l->addr);
1356 pktcnt = skb_queue_len(&l->transmq) + skb_queue_len(&l->backlogq); 1332 pktcnt = skb_queue_len(&l->transmq) + skb_queue_len(&l->backlogq);
1357 msg_set_msgcnt(&tnlhdr, pktcnt); 1333 msg_set_msgcnt(&tnlhdr, pktcnt);
@@ -1410,7 +1386,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
1410 if (tipc_link_is_blocked(l) || !xmitq) 1386 if (tipc_link_is_blocked(l) || !xmitq)
1411 goto exit; 1387 goto exit;
1412 1388
1413 if (link_own_addr(l) > msg_prevnode(hdr)) 1389 if (tipc_own_addr(l->net) > msg_prevnode(hdr))
1414 l->net_plane = msg_net_plane(hdr); 1390 l->net_plane = msg_net_plane(hdr);
1415 1391
1416 switch (mtyp) { 1392 switch (mtyp) {
@@ -1418,7 +1394,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
1418 1394
1419 /* Ignore duplicate RESET with old session number */ 1395 /* Ignore duplicate RESET with old session number */
1420 if ((less_eq(msg_session(hdr), l->peer_session)) && 1396 if ((less_eq(msg_session(hdr), l->peer_session)) &&
1421 (l->peer_session != WILDCARD_SESSION)) 1397 (l->peer_session != ANY_SESSION))
1422 break; 1398 break;
1423 /* fall thru' */ 1399 /* fall thru' */
1424 1400
@@ -1515,7 +1491,7 @@ static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast,
1515 u16 gap_to = peers_snd_nxt - 1; 1491 u16 gap_to = peers_snd_nxt - 1;
1516 1492
1517 skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE, 1493 skb = tipc_msg_create(BCAST_PROTOCOL, STATE_MSG, INT_H_SIZE,
1518 0, l->addr, link_own_addr(l), 0, 0, 0); 1494 0, l->addr, tipc_own_addr(l->net), 0, 0, 0);
1519 if (!skb) 1495 if (!skb)
1520 return false; 1496 return false;
1521 hdr = buf_msg(skb); 1497 hdr = buf_msg(skb);
@@ -1670,7 +1646,7 @@ int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb,
1670 if (mtyp != STATE_MSG) 1646 if (mtyp != STATE_MSG)
1671 return 0; 1647 return 0;
1672 1648
1673 if (dnode == link_own_addr(l)) { 1649 if (dnode == tipc_own_addr(l->net)) {
1674 tipc_link_bc_ack_rcv(l, acked, xmitq); 1650 tipc_link_bc_ack_rcv(l, acked, xmitq);
1675 rc = tipc_link_retrans(l->bc_sndlink, from, to, xmitq); 1651 rc = tipc_link_retrans(l->bc_sndlink, from, to, xmitq);
1676 l->stats.recv_nacks++; 1652 l->stats.recv_nacks++;
diff --git a/net/tipc/link.h b/net/tipc/link.h
index b4ee9d6e181d..6a94175ee20a 100644
--- a/net/tipc/link.h
+++ b/net/tipc/link.h
@@ -86,7 +86,6 @@ bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
86 struct sk_buff_head *namedq, 86 struct sk_buff_head *namedq,
87 struct tipc_link *bc_sndlink, 87 struct tipc_link *bc_sndlink,
88 struct tipc_link **link); 88 struct tipc_link **link);
89void tipc_link_reinit(struct tipc_link *l, u32 addr);
90void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl, 89void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
91 int mtyp, struct sk_buff_head *xmitq); 90 int mtyp, struct sk_buff_head *xmitq);
92void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq); 91void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq);
diff --git a/net/tipc/net.c b/net/tipc/net.c
index 77bf9113c7a7..86d68b352bd6 100644
--- a/net/tipc/net.c
+++ b/net/tipc/net.c
@@ -116,7 +116,6 @@ int tipc_net_start(struct net *net, u32 addr)
116 tn->own_addr = addr; 116 tn->own_addr = addr;
117 tipc_named_reinit(net); 117 tipc_named_reinit(net);
118 tipc_sk_reinit(net); 118 tipc_sk_reinit(net);
119 tipc_bcast_reinit(net);
120 119
121 tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr, 120 tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr,
122 TIPC_ZONE_SCOPE, 0, tn->own_addr); 121 TIPC_ZONE_SCOPE, 0, tn->own_addr);