Skip to content

Commit 25b9221

Browse files
Jon Maloydavem330
authored andcommitted
tipc: add SYN bit to connection setup messages
Messages intended for intitating a connection are currently indistinguishable from regular datagram messages. The TIPC protocol specification defines bit 17 in word 0 as a SYN bit to allow sanity check of such messages in the listening socket, but this has so far never been implemented. We do that in this commit. 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>
1 parent 39fdc9c commit 25b9221

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

net/tipc/msg.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ static inline void msg_set_non_seq(struct tipc_msg *m, u32 n)
216216
msg_set_bits(m, 0, 20, 1, n);
217217
}
218218

219+
static inline int msg_is_syn(struct tipc_msg *m)
220+
{
221+
return msg_bits(m, 0, 17, 1);
222+
}
223+
224+
static inline void msg_set_syn(struct tipc_msg *m, u32 d)
225+
{
226+
msg_set_bits(m, 0, 17, 1, d);
227+
}
228+
219229
static inline int msg_dest_droppable(struct tipc_msg *m)
220230
{
221231
return msg_bits(m, 0, 19, 1);

net/tipc/node.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
/* Optional capabilities supported by this code version
4646
*/
4747
enum {
48+
TIPC_SYN_BIT = (1),
4849
TIPC_BCAST_SYNCH = (1 << 1),
4950
TIPC_BCAST_STATE_NACK = (1 << 2),
5051
TIPC_BLOCK_FLOWCTL = (1 << 3),
@@ -53,11 +54,12 @@ enum {
5354
TIPC_LINK_PROTO_SEQNO = (1 << 6)
5455
};
5556

56-
#define TIPC_NODE_CAPABILITIES (TIPC_BCAST_SYNCH | \
57-
TIPC_BCAST_STATE_NACK | \
58-
TIPC_BCAST_RCAST | \
59-
TIPC_BLOCK_FLOWCTL | \
60-
TIPC_NODE_ID128 | \
57+
#define TIPC_NODE_CAPABILITIES (TIPC_SYN_BIT | \
58+
TIPC_BCAST_SYNCH | \
59+
TIPC_BCAST_STATE_NACK | \
60+
TIPC_BCAST_RCAST | \
61+
TIPC_BLOCK_FLOWCTL | \
62+
TIPC_NODE_ID128 | \
6163
TIPC_LINK_PROTO_SEQNO)
6264
#define INVALID_BEARER_ID -1
6365

net/tipc/socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
13191319
tsk->conn_type = dest->addr.name.name.type;
13201320
tsk->conn_instance = dest->addr.name.name.instance;
13211321
}
1322+
msg_set_syn(hdr, 1);
13221323
}
13231324

13241325
seq = &dest->addr.nameseq;
@@ -1478,6 +1479,7 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
14781479
struct net *net = sock_net(sk);
14791480
struct tipc_msg *msg = &tsk->phdr;
14801481

1482+
msg_set_syn(msg, 0);
14811483
msg_set_destnode(msg, peer_node);
14821484
msg_set_destport(msg, peer_port);
14831485
msg_set_type(msg, TIPC_CONN_MSG);
@@ -2006,6 +2008,9 @@ static bool tipc_sk_filter_connect(struct tipc_sock *tsk, struct sk_buff *skb)
20062008
return false;
20072009
case TIPC_LISTEN:
20082010
/* Accept only SYN message */
2011+
if (!msg_is_syn(hdr) &&
2012+
tipc_node_get_capabilities(net, onode) & TIPC_SYN_BIT)
2013+
return false;
20092014
if (!con_msg && !err)
20102015
return true;
20112016
return false;

0 commit comments

Comments
 (0)