]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
tipc: add SYN bit to connection setup messages
authorJon Maloy <jon.maloy@ericsson.com>
Fri, 28 Sep 2018 18:23:21 +0000 (20:23 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 29 Sep 2018 18:24:22 +0000 (11:24 -0700)
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>
net/tipc/msg.h
net/tipc/node.h
net/tipc/socket.c

index a4e944d593942042ce1b506d42a4c585e8aafc62..cd64d7b2a0fe2d030024f26ae42551291e8d058d 100644 (file)
@@ -216,6 +216,16 @@ static inline void msg_set_non_seq(struct tipc_msg *m, u32 n)
        msg_set_bits(m, 0, 20, 1, n);
 }
 
+static inline int msg_is_syn(struct tipc_msg *m)
+{
+       return msg_bits(m, 0, 17, 1);
+}
+
+static inline void msg_set_syn(struct tipc_msg *m, u32 d)
+{
+       msg_set_bits(m, 0, 17, 1, d);
+}
+
 static inline int msg_dest_droppable(struct tipc_msg *m)
 {
        return msg_bits(m, 0, 19, 1);
index 48b3298a248d493e083cb4e39adeebe3ab3f38a5..03f5efb62cfba24bfc44dc6975e0b3cf14105619 100644 (file)
@@ -45,6 +45,7 @@
 /* Optional capabilities supported by this code version
  */
 enum {
+       TIPC_SYN_BIT          = (1),
        TIPC_BCAST_SYNCH      = (1 << 1),
        TIPC_BCAST_STATE_NACK = (1 << 2),
        TIPC_BLOCK_FLOWCTL    = (1 << 3),
@@ -53,11 +54,12 @@ enum {
        TIPC_LINK_PROTO_SEQNO = (1 << 6)
 };
 
-#define TIPC_NODE_CAPABILITIES (TIPC_BCAST_SYNCH       |  \
-                               TIPC_BCAST_STATE_NACK  |  \
-                               TIPC_BCAST_RCAST       |  \
-                               TIPC_BLOCK_FLOWCTL     |  \
-                               TIPC_NODE_ID128        |  \
+#define TIPC_NODE_CAPABILITIES (TIPC_SYN_BIT           |  \
+                               TIPC_BCAST_SYNCH       |   \
+                               TIPC_BCAST_STATE_NACK  |   \
+                               TIPC_BCAST_RCAST       |   \
+                               TIPC_BLOCK_FLOWCTL     |   \
+                               TIPC_NODE_ID128        |   \
                                TIPC_LINK_PROTO_SEQNO)
 #define INVALID_BEARER_ID -1
 
index 094cfdc1e2b6e0f6caa3370c3d347e23af994bda..89d6dc0f456dfeef4be66d41b021df9bb6667c35 100644 (file)
@@ -1319,6 +1319,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
                        tsk->conn_type = dest->addr.name.name.type;
                        tsk->conn_instance = dest->addr.name.name.instance;
                }
+               msg_set_syn(hdr, 1);
        }
 
        seq = &dest->addr.nameseq;
@@ -1478,6 +1479,7 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
        struct net *net = sock_net(sk);
        struct tipc_msg *msg = &tsk->phdr;
 
+       msg_set_syn(msg, 0);
        msg_set_destnode(msg, peer_node);
        msg_set_destport(msg, peer_port);
        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)
                return false;
        case TIPC_LISTEN:
                /* Accept only SYN message */
+               if (!msg_is_syn(hdr) &&
+                   tipc_node_get_capabilities(net, onode) & TIPC_SYN_BIT)
+                       return false;
                if (!con_msg && !err)
                        return true;
                return false;