diff --git a/net/ipc_router/Kconfig b/net/ipc_router/Kconfig index 30cd45a702082da40bd5c4b6d3df9081122cca21..9121667f1a361400f0caf08d2d3213efdc757104 100644 --- a/net/ipc_router/Kconfig +++ b/net/ipc_router/Kconfig @@ -23,3 +23,13 @@ config IPC_ROUTER_SECURITY once configured with the security rules will ensure that the sender of the message to a service belongs to the relevant Linux group as configured by the security script. + +config IPC_ROUTER_NODE_ID + depends on IPC_ROUTER + int "IPC router local NODE ID" + default 1 + help + This option allows to configure the IPC Router NODE ID dynamically. + The NODE defined here is used as the local NODE ID by IPC Router + core and publish the same NODE ID to other NODES present in the + network. diff --git a/net/ipc_router/ipc_router_core.c b/net/ipc_router/ipc_router_core.c index 34031088cfd8e76c4902e31936ca3878caa80881..1a6b539f252e96e9cd6768cc9d58fce71b8b46ec 100644 --- a/net/ipc_router/ipc_router_core.c +++ b/net/ipc_router/ipc_router_core.c @@ -137,6 +137,7 @@ struct msm_ipc_router_xprt_info { struct msm_ipc_router_xprt *xprt; u32 remote_node_id; u32 initialized; + u32 hello_sent; struct list_head pkt_list; struct wakeup_source ws; struct mutex rx_lock_lhb2; /* lock for xprt rx operations */ @@ -2494,12 +2495,36 @@ static void do_version_negotiation(struct msm_ipc_router_xprt_info *xprt_info, } } +static int send_hello_msg(struct msm_ipc_router_xprt_info *xprt_info) +{ + int rc = 0; + union rr_control_msg ctl; + + if (!xprt_info->hello_sent) { + xprt_info->hello_sent = 1; + /* Send a HELLO message */ + memset(&ctl, 0, sizeof(ctl)); + ctl.hello.cmd = IPC_ROUTER_CTRL_CMD_HELLO; + ctl.hello.checksum = IPC_ROUTER_HELLO_MAGIC; + ctl.hello.versions = (uint32_t)IPC_ROUTER_VER_BITMASK; + ctl.hello.checksum = ipc_router_calc_checksum(&ctl); + rc = ipc_router_send_ctl_msg(xprt_info, &ctl, + IPC_ROUTER_DUMMY_DEST_NODE); + if (rc < 0) { + xprt_info->hello_sent = 0; + IPC_RTR_ERR("%s: Error sending HELLO message\n", + __func__); + return rc; + } + } + return rc; +} + static int process_hello_msg(struct msm_ipc_router_xprt_info *xprt_info, union rr_control_msg *msg, struct rr_header_v1 *hdr) { int i, rc = 0; - union rr_control_msg ctl; struct msm_ipc_routing_table_entry *rt_entry; if (!hdr) @@ -2514,19 +2539,10 @@ static int process_hello_msg(struct msm_ipc_router_xprt_info *xprt_info, kref_put(&rt_entry->ref, ipc_router_release_rtentry); do_version_negotiation(xprt_info, msg); - /* Send a reply HELLO message */ - memset(&ctl, 0, sizeof(ctl)); - ctl.hello.cmd = IPC_ROUTER_CTRL_CMD_HELLO; - ctl.hello.checksum = IPC_ROUTER_HELLO_MAGIC; - ctl.hello.versions = (u32)IPC_ROUTER_VER_BITMASK; - ctl.hello.checksum = ipc_router_calc_checksum(&ctl); - rc = ipc_router_send_ctl_msg(xprt_info, &ctl, - IPC_ROUTER_DUMMY_DEST_NODE); - if (rc < 0) { - IPC_RTR_ERR("%s: Error sending reply HELLO message\n", - __func__); + rc = send_hello_msg(xprt_info); + if (rc < 0) return rc; - } + xprt_info->initialized = 1; /* Send list of servers from the local node and from nodes @@ -4068,6 +4084,7 @@ static int msm_ipc_router_add_xprt(struct msm_ipc_router_xprt *xprt) xprt_info->xprt = xprt; xprt_info->initialized = 0; + xprt_info->hello_sent = 0; xprt_info->remote_node_id = -1; INIT_LIST_HEAD(&xprt_info->pkt_list); mutex_init(&xprt_info->rx_lock_lhb2); @@ -4109,6 +4126,7 @@ static int msm_ipc_router_add_xprt(struct msm_ipc_router_xprt *xprt) up_write(&routing_table_lock_lha3); xprt->priv = xprt_info; + send_hello_msg(xprt_info); return 0; } diff --git a/net/ipc_router/ipc_router_private.h b/net/ipc_router/ipc_router_private.h index 3ec9818129826050883f4315d414aa76853257e0..6e0c4bebc05cf10b5f21f4104b91b10a5ad2c1f5 100644 --- a/net/ipc_router/ipc_router_private.h +++ b/net/ipc_router/ipc_router_private.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2016, 2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -37,7 +37,7 @@ #define IPC_ROUTER_ADDRESS 0x0000FFFF -#define IPC_ROUTER_NID_LOCAL 1 +#define IPC_ROUTER_NID_LOCAL CONFIG_IPC_ROUTER_NODE_ID #define MAX_IPC_PKT_SIZE 66000 #define IPC_ROUTER_LOW_RX_QUOTA 5