Skip to content

Commit

Permalink
Merge branch 'net-qrtr-Nameserver-fixes'
Browse files Browse the repository at this point in the history
Bjorn Andersson says:

====================
net: qrtr: Nameserver fixes

The need to respond to the HELLO message from the firmware was lost in the
translation from the user space implementation of the nameserver. Fixing this
also means we can remove the FIXME related to launching the ns.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Mar 4, 2020
2 parents 30a87f1 + 71046ab commit e762ae5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
56 changes: 31 additions & 25 deletions net/qrtr/ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,38 @@ static int server_del(struct qrtr_node *node, unsigned int port)
return 0;
}

static int say_hello(struct sockaddr_qrtr *dest)
{
struct qrtr_ctrl_pkt pkt;
struct msghdr msg = { };
struct kvec iv;
int ret;

iv.iov_base = &pkt;
iv.iov_len = sizeof(pkt);

memset(&pkt, 0, sizeof(pkt));
pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);

msg.msg_name = (struct sockaddr *)dest;
msg.msg_namelen = sizeof(*dest);

ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
if (ret < 0)
pr_err("failed to send hello msg\n");

return ret;
}

/* Announce the list of servers registered on the local node */
static int ctrl_cmd_hello(struct sockaddr_qrtr *sq)
{
int ret;

ret = say_hello(sq);
if (ret < 0)
return ret;

return announce_servers(sq);
}

Expand Down Expand Up @@ -566,29 +595,6 @@ static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from,
}
}

static int say_hello(void)
{
struct qrtr_ctrl_pkt pkt;
struct msghdr msg = { };
struct kvec iv;
int ret;

iv.iov_base = &pkt;
iv.iov_len = sizeof(pkt);

memset(&pkt, 0, sizeof(pkt));
pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO);

msg.msg_name = (struct sockaddr *)&qrtr_ns.bcast_sq;
msg.msg_namelen = sizeof(qrtr_ns.bcast_sq);

ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt));
if (ret < 0)
pr_err("failed to send hello msg\n");

return ret;
}

static void qrtr_ns_worker(struct work_struct *work)
{
const struct qrtr_ctrl_pkt *pkt;
Expand Down Expand Up @@ -687,7 +693,7 @@ static void qrtr_ns_data_ready(struct sock *sk)
queue_work(qrtr_ns.workqueue, &qrtr_ns.work);
}

void qrtr_ns_init(struct work_struct *work)
void qrtr_ns_init(void)
{
struct sockaddr_qrtr sq;
int ret;
Expand Down Expand Up @@ -725,7 +731,7 @@ void qrtr_ns_init(struct work_struct *work)
if (!qrtr_ns.workqueue)
goto err_sock;

ret = say_hello();
ret = say_hello(&qrtr_ns.bcast_sq);
if (ret < 0)
goto err_wq;

Expand Down
10 changes: 1 addition & 9 deletions net/qrtr/qrtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <linux/termios.h> /* For TIOCINQ/OUTQ */
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/workqueue.h>

#include <net/sock.h>

Expand Down Expand Up @@ -110,8 +109,6 @@ static DEFINE_MUTEX(qrtr_node_lock);
static DEFINE_IDR(qrtr_ports);
static DEFINE_MUTEX(qrtr_port_lock);

static struct delayed_work qrtr_ns_work;

/**
* struct qrtr_node - endpoint node
* @ep_lock: lock for endpoint management and callbacks
Expand Down Expand Up @@ -1263,19 +1260,14 @@ static int __init qrtr_proto_init(void)
return rc;
}

/* FIXME: Currently, this 2s delay is required to catch the NEW_SERVER
* messages from routers. But the fix could be somewhere else.
*/
INIT_DELAYED_WORK(&qrtr_ns_work, qrtr_ns_init);
schedule_delayed_work(&qrtr_ns_work, msecs_to_jiffies(2000));
qrtr_ns_init();

return rc;
}
postcore_initcall(qrtr_proto_init);

static void __exit qrtr_proto_fini(void)
{
cancel_delayed_work_sync(&qrtr_ns_work);
qrtr_ns_remove();
sock_unregister(qrtr_family.family);
proto_unregister(&qrtr_proto);
Expand Down
2 changes: 1 addition & 1 deletion net/qrtr/qrtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep);

int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len);

void qrtr_ns_init(struct work_struct *work);
void qrtr_ns_init(void);

void qrtr_ns_remove(void);

Expand Down

0 comments on commit e762ae5

Please sign in to comment.