Skip to content

Commit e74a386

Browse files
Jon Paul Maloydavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 34f65db commit e74a386

File tree

5 files changed

+45
-77
lines changed

5 files changed

+45
-77
lines changed

net/tipc/bcast.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,6 @@ int tipc_bcast_init(struct net *net)
412412
return -ENOMEM;
413413
}
414414

415-
void tipc_bcast_reinit(struct net *net)
416-
{
417-
tipc_link_reinit(tipc_bc_sndlink(net), tipc_own_addr(net));
418-
}
419-
420415
void tipc_bcast_stop(struct net *net)
421416
{
422417
struct tipc_net *tn = net_generic(net, tipc_net_id);

net/tipc/bcast.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct tipc_node_map;
4646
extern const char tipc_bclink_name[];
4747

4848
int tipc_bcast_init(struct net *net);
49-
void tipc_bcast_reinit(struct net *net);
5049
void tipc_bcast_stop(struct net *net);
5150
void tipc_bcast_add_peer(struct net *net, struct tipc_link *l,
5251
struct sk_buff_head *xmitq);

net/tipc/link.c

Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* net/tipc/link.c: TIPC link code
33
*
4-
* Copyright (c) 1996-2007, 2012-2015, Ericsson AB
4+
* Copyright (c) 1996-2007, 2012-2016, Ericsson AB
55
* Copyright (c) 2004-2007, 2010-2013, Wind River Systems
66
* All rights reserved.
77
*
@@ -127,6 +127,7 @@ struct tipc_link {
127127

128128
/* Management and link supervision data */
129129
u32 peer_session;
130+
u32 session;
130131
u32 peer_bearer_id;
131132
u32 bearer_id;
132133
u32 tolerance;
@@ -136,11 +137,7 @@ struct tipc_link {
136137
u16 peer_caps;
137138
bool active;
138139
u32 silent_intv_cnt;
139-
struct {
140-
unchar hdr[INT_H_SIZE];
141-
unchar body[TIPC_MAX_IF_NAME];
142-
} proto_msg;
143-
struct tipc_msg *pmsg;
140+
char if_name[TIPC_MAX_IF_NAME];
144141
u32 priority;
145142
char net_plane;
146143

@@ -215,10 +212,11 @@ enum {
215212
* Interval between NACKs when packets arrive out of order
216213
*/
217214
#define TIPC_NACK_INTV (TIPC_MIN_LINK_WIN * 2)
218-
/*
219-
* Out-of-range value for link session numbers
215+
216+
/* Wildcard value for link session numbers. When it is known that
217+
* peer endpoint is down, any session number must be accepted.
220218
*/
221-
#define WILDCARD_SESSION 0x10000
219+
#define ANY_SESSION 0x10000
222220

223221
/* Link FSM states:
224222
*/
@@ -398,16 +396,6 @@ char *tipc_link_name(struct tipc_link *l)
398396
return l->name;
399397
}
400398

401-
static u32 link_own_addr(struct tipc_link *l)
402-
{
403-
return msg_prevnode(l->pmsg);
404-
}
405-
406-
void tipc_link_reinit(struct tipc_link *l, u32 addr)
407-
{
408-
msg_set_prevnode(l->pmsg, addr);
409-
}
410-
411399
/**
412400
* tipc_link_create - create a new link
413401
* @n: pointer to associated node
@@ -441,29 +429,22 @@ bool tipc_link_create(struct net *net, char *if_name, int bearer_id,
441429
struct tipc_link **link)
442430
{
443431
struct tipc_link *l;
444-
struct tipc_msg *hdr;
445432

446433
l = kzalloc(sizeof(*l), GFP_ATOMIC);
447434
if (!l)
448435
return false;
449436
*link = l;
450-
l->pmsg = (struct tipc_msg *)&l->proto_msg;
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);
437+
l->session = session;
456438

457439
/* Note: peer i/f name is completed by reset/activate message */
458440
sprintf(l->name, "%u.%u.%u:%s-%u.%u.%u:unknown",
459441
tipc_zone(ownnode), tipc_cluster(ownnode), tipc_node(ownnode),
460442
if_name, tipc_zone(peer), tipc_cluster(peer), tipc_node(peer));
461-
strcpy((char *)msg_data(hdr), if_name);
462-
443+
strcpy(l->if_name, if_name);
463444
l->addr = peer;
464445
l->peer_caps = peer_caps;
465446
l->net = net;
466-
l->peer_session = WILDCARD_SESSION;
447+
l->peer_session = ANY_SESSION;
467448
l->bearer_id = bearer_id;
468449
l->tolerance = tolerance;
469450
l->net_plane = net_plane;
@@ -790,7 +771,7 @@ static int link_schedule_user(struct tipc_link *link, struct sk_buff_head *list)
790771
struct tipc_msg *msg = buf_msg(skb_peek(list));
791772
int imp = msg_importance(msg);
792773
u32 oport = msg_origport(msg);
793-
u32 addr = link_own_addr(link);
774+
u32 addr = tipc_own_addr(link->net);
794775
struct sk_buff *skb;
795776

796777
/* This really cannot happen... */
@@ -839,16 +820,9 @@ void link_prepare_wakeup(struct tipc_link *l)
839820

840821
void tipc_link_reset(struct tipc_link *l)
841822
{
842-
/* Link is down, accept any session */
843-
l->peer_session = WILDCARD_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 */
823+
l->peer_session = ANY_SESSION;
824+
l->session++;
849825
l->mtu = l->advertised_mtu;
850-
851-
/* Clean up all queues and counters: */
852826
__skb_queue_purge(&l->transmq);
853827
__skb_queue_purge(&l->deferdq);
854828
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)
11561130

11571131
/* Broadcast ACK must be sent via a unicast link => defer to caller */
11581132
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)
11601134
return 0;
11611135
l->rcv_unacked = 0;
11621136
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,
12681242
u16 rcvgap, int tolerance, int priority,
12691243
struct sk_buff_head *xmitq)
12701244
{
1271-
struct sk_buff *skb = NULL;
1272-
struct tipc_msg *hdr = l->pmsg;
1245+
struct sk_buff *skb;
1246+
struct tipc_msg *hdr;
1247+
struct sk_buff_head *dfq = &l->deferdq;
12731248
bool node_up = link_is_up(l->bc_rcvlink);
12741249

12751250
/* Don't send protocol message during reset or link failover */
12761251
if (tipc_link_is_blocked(l))
12771252
return;
12781253

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);
12801269
msg_set_net_plane(hdr, l->net_plane);
12811270
msg_set_next_sent(hdr, l->snd_nxt);
12821271
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,
12861275
msg_set_linkprio(hdr, priority);
12871276
msg_set_redundant_link(hdr, node_up);
12881277
msg_set_seq_gap(hdr, 0);
1289-
1290-
/* Compatibility: created msg must not be in sequence with pkt flow */
12911278
msg_set_seqno(hdr, l->snd_nxt + U16_MAX / 2);
12921279

12931280
if (mtyp == STATE_MSG) {
1294-
if (!tipc_link_is_up(l))
1295-
return;
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-
}
1281+
msg_set_seq_gap(hdr, rcvgap);
1282+
msg_set_size(hdr, INT_H_SIZE);
13041283
msg_set_probe(hdr, probe);
1305-
if (probe)
1306-
l->stats.sent_probes++;
13071284
l->stats.sent_states++;
13081285
l->rcv_unacked = 0;
13091286
} else {
13101287
/* RESET_MSG or ACTIVATE_MSG */
13111288
msg_set_max_pkt(hdr, l->advertised_mtu);
1312-
msg_set_ack(hdr, l->rcv_nxt - 1);
1313-
msg_set_next_sent(hdr, 1);
1289+
strcpy(msg_data(hdr), l->if_name);
13141290
}
1315-
skb = tipc_buf_acquire(msg_size(hdr));
1316-
if (!skb)
1317-
return;
1318-
skb_copy_to_linear_data(skb, hdr, msg_size(hdr));
1291+
if (probe)
1292+
l->stats.sent_probes++;
1293+
if (rcvgap)
1294+
l->stats.sent_nacks++;
13191295
skb->priority = TC_PRIO_CONTROL;
13201296
__skb_queue_tail(xmitq, skb);
13211297
}
@@ -1340,7 +1316,7 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
13401316

13411317
/* At least one packet required for safe algorithm => add dummy */
13421318
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),
13441320
0, 0, TIPC_ERR_NO_PORT);
13451321
if (!skb) {
13461322
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,
13511327
__skb_queue_purge(&tmpxq);
13521328

13531329
/* 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,
13551331
mtyp, INT_H_SIZE, l->addr);
13561332
pktcnt = skb_queue_len(&l->transmq) + skb_queue_len(&l->backlogq);
13571333
msg_set_msgcnt(&tnlhdr, pktcnt);
@@ -1410,15 +1386,15 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
14101386
if (tipc_link_is_blocked(l) || !xmitq)
14111387
goto exit;
14121388

1413-
if (link_own_addr(l) > msg_prevnode(hdr))
1389+
if (tipc_own_addr(l->net) > msg_prevnode(hdr))
14141390
l->net_plane = msg_net_plane(hdr);
14151391

14161392
switch (mtyp) {
14171393
case RESET_MSG:
14181394

14191395
/* Ignore duplicate RESET with old session number */
14201396
if ((less_eq(msg_session(hdr), l->peer_session)) &&
1421-
(l->peer_session != WILDCARD_SESSION))
1397+
(l->peer_session != ANY_SESSION))
14221398
break;
14231399
/* fall thru' */
14241400

@@ -1515,7 +1491,7 @@ static bool tipc_link_build_bc_proto_msg(struct tipc_link *l, bool bcast,
15151491
u16 gap_to = peers_snd_nxt - 1;
15161492

15171493
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);
15191495
if (!skb)
15201496
return false;
15211497
hdr = buf_msg(skb);
@@ -1670,7 +1646,7 @@ int tipc_link_bc_nack_rcv(struct tipc_link *l, struct sk_buff *skb,
16701646
if (mtyp != STATE_MSG)
16711647
return 0;
16721648

1673-
if (dnode == link_own_addr(l)) {
1649+
if (dnode == tipc_own_addr(l->net)) {
16741650
tipc_link_bc_ack_rcv(l, acked, xmitq);
16751651
rc = tipc_link_retrans(l->bc_sndlink, from, to, xmitq);
16761652
l->stats.recv_nacks++;

net/tipc/link.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
8686
struct sk_buff_head *namedq,
8787
struct tipc_link *bc_sndlink,
8888
struct tipc_link **link);
89-
void tipc_link_reinit(struct tipc_link *l, u32 addr);
9089
void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
9190
int mtyp, struct sk_buff_head *xmitq);
9291
void tipc_link_build_reset_msg(struct tipc_link *l, struct sk_buff_head *xmitq);

net/tipc/net.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ int tipc_net_start(struct net *net, u32 addr)
116116
tn->own_addr = addr;
117117
tipc_named_reinit(net);
118118
tipc_sk_reinit(net);
119-
tipc_bcast_reinit(net);
120119

121120
tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr,
122121
TIPC_ZONE_SCOPE, 0, tn->own_addr);

0 commit comments

Comments
 (0)