Skip to content

Commit 2320bcd

Browse files
Tuong Liendavem330
authored andcommitted
tipc: fix changeover issues due to large packet
In conjunction with changing the interfaces' MTU (e.g. especially in the case of a bonding) where the TIPC links are brought up and down in a short time, a couple of issues were detected with the current link changeover mechanism: 1) When one link is up but immediately forced down again, the failover procedure will be carried out in order to failover all the messages in the link's transmq queue onto the other working link. The link and node state is also set to FAILINGOVER as part of the process. The message will be transmited in form of a FAILOVER_MSG, so its size is plus of 40 bytes (= the message header size). There is no problem if the original message size is not larger than the link's MTU - 40, and indeed this is the max size of a normal payload messages. However, in the situation above, because the link has just been up, the messages in the link's transmq are almost SYNCH_MSGs which had been generated by the link synching procedure, then their size might reach the max value already! When the FAILOVER_MSG is built on the top of such a SYNCH_MSG, its size will exceed the link's MTU. As a result, the messages are dropped silently and the failover procedure will never end up, the link will not be able to exit the FAILINGOVER state, so cannot be re-established. 2) The same scenario above can happen more easily in case the MTU of the links is set differently or when changing. In that case, as long as a large message in the failure link's transmq queue was built and fragmented with its link's MTU > the other link's one, the issue will happen (there is no need of a link synching in advance). 3) The link synching procedure also faces with the same issue but since the link synching is only started upon receipt of a SYNCH_MSG, dropping the message will not result in a state deadlock, but it is not expected as design. The 1) & 3) issues are resolved by the last commit that only a dummy SYNCH_MSG (i.e. without data) is generated at the link synching, so the size of a FAILOVER_MSG if any then will never exceed the link's MTU. For the 2) issue, the only solution is trying to fragment the messages in the failure link's transmq queue according to the working link's MTU so they can be failovered then. A new function is made to accomplish this, it will still be a TUNNEL PROTOCOL/FAILOVER MSG but if the original message size is too large, it will be fragmented & reassembled at the receiving side. Acked-by: Ying Xue <ying.xue@windriver.com> Acked-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4929a93 commit 2320bcd

3 files changed

Lines changed: 155 additions & 15 deletions

File tree

‎net/tipc/link.c‎

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ struct tipc_link {
180180

181181
/* Fragmentation/reassembly */
182182
struct sk_buff *reasm_buf;
183+
struct sk_buff *reasm_tnlmsg;
183184

184185
/* Broadcast */
185186
u16 ackers;
@@ -897,8 +898,10 @@ void tipc_link_reset(struct tipc_link *l)
897898
l->backlog[TIPC_CRITICAL_IMPORTANCE].len = 0;
898899
l->backlog[TIPC_SYSTEM_IMPORTANCE].len = 0;
899900
kfree_skb(l->reasm_buf);
901+
kfree_skb(l->reasm_tnlmsg);
900902
kfree_skb(l->failover_reasm_skb);
901903
l->reasm_buf = NULL;
904+
l->reasm_tnlmsg = NULL;
902905
l->failover_reasm_skb = NULL;
903906
l->rcv_unacked = 0;
904907
l->snd_nxt = 1;
@@ -940,6 +943,9 @@ int tipc_link_xmit(struct tipc_link *l, struct sk_buff_head *list,
940943
int rc = 0;
941944

942945
if (unlikely(msg_size(hdr) > mtu)) {
946+
pr_warn("Too large msg, purging xmit list %d %d %d %d %d!\n",
947+
skb_queue_len(list), msg_user(hdr),
948+
msg_type(hdr), msg_size(hdr), mtu);
943949
skb_queue_purge(list);
944950
return -EMSGSIZE;
945951
}
@@ -1233,47 +1239,64 @@ static int tipc_link_tnl_rcv(struct tipc_link *l, struct sk_buff *skb,
12331239
struct sk_buff_head *inputq)
12341240
{
12351241
struct sk_buff **reasm_skb = &l->failover_reasm_skb;
1242+
struct sk_buff **reasm_tnlmsg = &l->reasm_tnlmsg;
12361243
struct sk_buff_head *fdefq = &l->failover_deferdq;
12371244
struct tipc_msg *hdr = buf_msg(skb);
12381245
struct sk_buff *iskb;
12391246
int ipos = 0;
12401247
int rc = 0;
12411248
u16 seqno;
12421249

1243-
/* SYNCH_MSG */
1244-
if (msg_type(hdr) == SYNCH_MSG)
1245-
goto drop;
1250+
if (msg_type(hdr) == SYNCH_MSG) {
1251+
kfree_skb(skb);
1252+
return 0;
1253+
}
12461254

1247-
/* FAILOVER_MSG */
1248-
if (!tipc_msg_extract(skb, &iskb, &ipos)) {
1249-
pr_warn_ratelimited("Cannot extract FAILOVER_MSG, defq: %d\n",
1250-
skb_queue_len(fdefq));
1251-
return rc;
1255+
/* Not a fragment? */
1256+
if (likely(!msg_nof_fragms(hdr))) {
1257+
if (unlikely(!tipc_msg_extract(skb, &iskb, &ipos))) {
1258+
pr_warn_ratelimited("Unable to extract msg, defq: %d\n",
1259+
skb_queue_len(fdefq));
1260+
return 0;
1261+
}
1262+
kfree_skb(skb);
1263+
} else {
1264+
/* Set fragment type for buf_append */
1265+
if (msg_fragm_no(hdr) == 1)
1266+
msg_set_type(hdr, FIRST_FRAGMENT);
1267+
else if (msg_fragm_no(hdr) < msg_nof_fragms(hdr))
1268+
msg_set_type(hdr, FRAGMENT);
1269+
else
1270+
msg_set_type(hdr, LAST_FRAGMENT);
1271+
1272+
if (!tipc_buf_append(reasm_tnlmsg, &skb)) {
1273+
/* Successful but non-complete reassembly? */
1274+
if (*reasm_tnlmsg || link_is_bc_rcvlink(l))
1275+
return 0;
1276+
pr_warn_ratelimited("Unable to reassemble tunnel msg\n");
1277+
return tipc_link_fsm_evt(l, LINK_FAILURE_EVT);
1278+
}
1279+
iskb = skb;
12521280
}
12531281

12541282
do {
12551283
seqno = buf_seqno(iskb);
1256-
12571284
if (unlikely(less(seqno, l->drop_point))) {
12581285
kfree_skb(iskb);
12591286
continue;
12601287
}
1261-
12621288
if (unlikely(seqno != l->drop_point)) {
12631289
__tipc_skb_queue_sorted(fdefq, seqno, iskb);
12641290
continue;
12651291
}
12661292

12671293
l->drop_point++;
1268-
12691294
if (!tipc_data_input(l, iskb, inputq))
12701295
rc |= tipc_link_input(l, iskb, inputq, reasm_skb);
12711296
if (unlikely(rc))
12721297
break;
12731298
} while ((iskb = __tipc_skb_dequeue(fdefq, l->drop_point)));
12741299

1275-
drop:
1276-
kfree_skb(skb);
12771300
return rc;
12781301
}
12791302

@@ -1663,15 +1686,18 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
16631686
struct sk_buff *skb, *tnlskb;
16641687
struct tipc_msg *hdr, tnlhdr;
16651688
struct sk_buff_head *queue = &l->transmq;
1666-
struct sk_buff_head tmpxq, tnlq;
1689+
struct sk_buff_head tmpxq, tnlq, frags;
16671690
u16 pktlen, pktcnt, seqno = l->snd_nxt;
1691+
bool pktcnt_need_update = false;
16681692
u16 syncpt;
1693+
int rc;
16691694

16701695
if (!tnl)
16711696
return;
16721697

16731698
skb_queue_head_init(&tnlq);
16741699
skb_queue_head_init(&tmpxq);
1700+
skb_queue_head_init(&frags);
16751701

16761702
/* At least one packet required for safe algorithm => add dummy */
16771703
skb = tipc_msg_create(TIPC_LOW_IMPORTANCE, TIPC_DIRECT_MSG,
@@ -1727,6 +1753,39 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
17271753
if (queue == &l->backlogq)
17281754
msg_set_seqno(hdr, seqno++);
17291755
pktlen = msg_size(hdr);
1756+
1757+
/* Tunnel link MTU is not large enough? This could be
1758+
* due to:
1759+
* 1) Link MTU has just changed or set differently;
1760+
* 2) Or FAILOVER on the top of a SYNCH message
1761+
*
1762+
* The 2nd case should not happen if peer supports
1763+
* TIPC_TUNNEL_ENHANCED
1764+
*/
1765+
if (pktlen > tnl->mtu - INT_H_SIZE) {
1766+
if (mtyp == FAILOVER_MSG &&
1767+
(tnl->peer_caps & TIPC_TUNNEL_ENHANCED)) {
1768+
rc = tipc_msg_fragment(skb, &tnlhdr, tnl->mtu,
1769+
&frags);
1770+
if (rc) {
1771+
pr_warn("%sunable to frag msg: rc %d\n",
1772+
link_co_err, rc);
1773+
return;
1774+
}
1775+
pktcnt += skb_queue_len(&frags) - 1;
1776+
pktcnt_need_update = true;
1777+
skb_queue_splice_tail_init(&frags, &tnlq);
1778+
continue;
1779+
}
1780+
/* Unluckily, peer doesn't have TIPC_TUNNEL_ENHANCED
1781+
* => Just warn it and return!
1782+
*/
1783+
pr_warn_ratelimited("%stoo large msg <%d, %d>: %d!\n",
1784+
link_co_err, msg_user(hdr),
1785+
msg_type(hdr), msg_size(hdr));
1786+
return;
1787+
}
1788+
17301789
msg_set_size(&tnlhdr, pktlen + INT_H_SIZE);
17311790
tnlskb = tipc_buf_acquire(pktlen + INT_H_SIZE, GFP_ATOMIC);
17321791
if (!tnlskb) {
@@ -1742,6 +1801,12 @@ void tipc_link_tnl_prepare(struct tipc_link *l, struct tipc_link *tnl,
17421801
goto tnl;
17431802
}
17441803

1804+
if (pktcnt_need_update)
1805+
skb_queue_walk(&tnlq, skb) {
1806+
hdr = buf_msg(skb);
1807+
msg_set_msgcnt(hdr, pktcnt);
1808+
}
1809+
17451810
tipc_link_xmit(tnl, &tnlq, xmitq);
17461811

17471812
if (mtyp == FAILOVER_MSG) {

‎net/tipc/msg.c‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,65 @@ bool tipc_msg_validate(struct sk_buff **_skb)
243243
return true;
244244
}
245245

246+
/**
247+
* tipc_msg_fragment - build a fragment skb list for TIPC message
248+
*
249+
* @skb: TIPC message skb
250+
* @hdr: internal msg header to be put on the top of the fragments
251+
* @pktmax: max size of a fragment incl. the header
252+
* @frags: returned fragment skb list
253+
*
254+
* Returns 0 if the fragmentation is successful, otherwise: -EINVAL
255+
* or -ENOMEM
256+
*/
257+
int tipc_msg_fragment(struct sk_buff *skb, const struct tipc_msg *hdr,
258+
int pktmax, struct sk_buff_head *frags)
259+
{
260+
int pktno, nof_fragms, dsz, dmax, eat;
261+
struct tipc_msg *_hdr;
262+
struct sk_buff *_skb;
263+
u8 *data;
264+
265+
/* Non-linear buffer? */
266+
if (skb_linearize(skb))
267+
return -ENOMEM;
268+
269+
data = (u8 *)skb->data;
270+
dsz = msg_size(buf_msg(skb));
271+
dmax = pktmax - INT_H_SIZE;
272+
if (dsz <= dmax || !dmax)
273+
return -EINVAL;
274+
275+
nof_fragms = dsz / dmax + 1;
276+
for (pktno = 1; pktno <= nof_fragms; pktno++) {
277+
if (pktno < nof_fragms)
278+
eat = dmax;
279+
else
280+
eat = dsz % dmax;
281+
/* Allocate a new fragment */
282+
_skb = tipc_buf_acquire(INT_H_SIZE + eat, GFP_ATOMIC);
283+
if (!_skb)
284+
goto error;
285+
skb_orphan(_skb);
286+
__skb_queue_tail(frags, _skb);
287+
/* Copy header & data to the fragment */
288+
skb_copy_to_linear_data(_skb, hdr, INT_H_SIZE);
289+
skb_copy_to_linear_data_offset(_skb, INT_H_SIZE, data, eat);
290+
data += eat;
291+
/* Update the fragment's header */
292+
_hdr = buf_msg(_skb);
293+
msg_set_fragm_no(_hdr, pktno);
294+
msg_set_nof_fragms(_hdr, nof_fragms);
295+
msg_set_size(_hdr, INT_H_SIZE + eat);
296+
}
297+
return 0;
298+
299+
error:
300+
__skb_queue_purge(frags);
301+
__skb_queue_head_init(frags);
302+
return -ENOMEM;
303+
}
304+
246305
/**
247306
* tipc_msg_build - create buffer chain containing specified header and data
248307
* @mhdr: Message header, to be prepended to data

‎net/tipc/msg.h‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,12 +721,26 @@ static inline void msg_set_last_bcast(struct tipc_msg *m, u32 n)
721721
msg_set_bits(m, 4, 16, 0xffff, n);
722722
}
723723

724+
static inline u32 msg_nof_fragms(struct tipc_msg *m)
725+
{
726+
return msg_bits(m, 4, 0, 0xffff);
727+
}
728+
729+
static inline void msg_set_nof_fragms(struct tipc_msg *m, u32 n)
730+
{
731+
msg_set_bits(m, 4, 0, 0xffff, n);
732+
}
733+
734+
static inline u32 msg_fragm_no(struct tipc_msg *m)
735+
{
736+
return msg_bits(m, 4, 16, 0xffff);
737+
}
738+
724739
static inline void msg_set_fragm_no(struct tipc_msg *m, u32 n)
725740
{
726741
msg_set_bits(m, 4, 16, 0xffff, n);
727742
}
728743

729-
730744
static inline u16 msg_next_sent(struct tipc_msg *m)
731745
{
732746
return msg_bits(m, 4, 0, 0xffff);
@@ -1045,6 +1059,8 @@ bool tipc_msg_bundle(struct sk_buff *skb, struct tipc_msg *msg, u32 mtu);
10451059
bool tipc_msg_make_bundle(struct sk_buff **skb, struct tipc_msg *msg,
10461060
u32 mtu, u32 dnode);
10471061
bool tipc_msg_extract(struct sk_buff *skb, struct sk_buff **iskb, int *pos);
1062+
int tipc_msg_fragment(struct sk_buff *skb, const struct tipc_msg *hdr,
1063+
int pktmax, struct sk_buff_head *frags);
10481064
int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
10491065
int offset, int dsz, int mtu, struct sk_buff_head *list);
10501066
bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err);

0 commit comments

Comments
 (0)