From: "Rémi Denis-Courmont" <remi@remlab.net>
To: Kumar A Sanghvi <kumar.sanghvi@stericsson.com>
Cc: remi.denis-courmont@nokia.com, davem@davemloft.net,
netdev@vger.kernel.org, linus.walleij@stericsson.com,
gulshan.karmani@stericsson.com, sudeep.divakaran@stericsson.com
Subject: Re: [PATCH] Phonet: 'connect' socket implementation for Pipe controller
Date: Tue, 12 Oct 2010 19:30:30 +0300 [thread overview]
Message-ID: <201010121930.32116.remi@remlab.net> (raw)
In-Reply-To: <1286897211-3198-1-git-send-email-kumar.sanghvi@stericsson.com>
Hello,
Just a few comments...
Le mardi 12 octobre 2010 18:26:51 Kumar A Sanghvi, vous avez écrit :
> diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
> index def6cfa..b60b28c 100644
> --- a/include/net/phonet/pep.h
> +++ b/include/net/phonet/pep.h
> @@ -802,6 +682,42 @@ static void pipe_destruct(struct sock *sk)
> skb_queue_purge(&pn->ctrlreq_queue);
> }
>
> +#ifdef CONFIG_PHONET_PIPECTRLR
> +static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
> +{
> + struct pep_sock *pn = pep_sk(sk);
> + static u8 host_pref_rx_fc[3] = {3, 2, 1}, host_req_tx_fc[3] = {3, 2, 1};
Why is this 'static' ? Doesn't that break concurrent uses?
> + u8 remote_pref_rx_fc[3], remote_req_tx_fc[3];
> + u8 negotiated_rx_fc, negotiated_tx_fc;
> + int ret;
> +
> + pipe_get_flow_info(sk, skb, remote_pref_rx_fc,
> + remote_req_tx_fc);
> + negotiated_tx_fc = pipe_negotiate_fc(remote_req_tx_fc,
> + host_pref_rx_fc,
> + sizeof(host_pref_rx_fc));
> + negotiated_rx_fc = pipe_negotiate_fc(host_req_tx_fc,
> + remote_pref_rx_fc,
> + sizeof(host_pref_rx_fc));
> +
> + pn->pipe_state = PIPE_DISABLED;
> + sk->sk_state = TCP_SYN_RECV;
> + sk->sk_backlog_rcv = pipe_do_rcv;
> + sk->sk_destruct = pipe_destruct;
> + pn->rx_credits = 0;
> + pn->rx_fc = negotiated_rx_fc;
> + pn->tx_fc = negotiated_tx_fc;
> + sk->sk_state_change(sk);
> +
> + ret = pipe_handler_send_created_ind(sk,
> + PNS_PIPE_CREATED_IND_UTID,
> + PNS_PIPE_CREATED_IND
> + );
> +
> + return ret;
> +}
> +#endif
> +
> static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
> {
> struct sock *newsk;
> diff --git a/net/phonet/socket.c b/net/phonet/socket.c
> index aca8fba..123a374 100644
> --- a/net/phonet/socket.c
> +++ b/net/phonet/socket.c
> @@ -225,6 +225,102 @@ static int pn_socket_autobind(struct socket *sock)
> return 0; /* socket was already bound */
> }
>
> +static int pn_socket_connect(struct socket *sock, struct sockaddr *addr,
> + int len, int flags)
> +{
> + struct sock *sk = sock->sk;
> + struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
> + long timeo;
> + int err;
> +
> + lock_sock(sk);
> +
> + if (len < sizeof(struct sockaddr_pn))
> + return -EINVAL;
> + if (spn->spn_family != AF_PHONET)
> + return -EAFNOSUPPORT;
You should move lock_sock(sk); here, I think.
> +
> + switch (sock->state) {
> + case SS_UNCONNECTED:
> + sk->sk_state = TCP_CLOSE;
> + break;
> + case SS_CONNECTING:
> + switch (sk->sk_state) {
> + case TCP_SYN_RECV:
> + sock->state = SS_CONNECTED;
> + err = -EISCONN;
> + goto out;
> + case TCP_CLOSE:
> + err = -EALREADY;
> + if (flags & O_NONBLOCK)
> + goto out;
> + goto wait_connect;
> + break;
I think the kernel policy is against redumdant break statements.
> + }
> + break;
> + case SS_CONNECTED:
> + switch (sk->sk_state) {
> + case TCP_SYN_RECV:
> + err = -EISCONN;
> + goto out;
> + case TCP_CLOSE:
> + sock->state = SS_UNCONNECTED;
> + break;
> + }
> + break;
> + case SS_DISCONNECTING:
> + case SS_FREE:
> + break;
> + }
> + sk->sk_state = TCP_CLOSE;
> + sock->state = SS_UNCONNECTED;
This is dead code...
> + sk_stream_kill_queues(sk);
> +
> +
> + sock->state = SS_CONNECTING;
...because of this ^ .
> + err = sk->sk_prot->connect(sk, addr, len);
> + if (err < 0) {
> + sock->state = SS_UNCONNECTED;
> + sk->sk_state = TCP_CLOSE;
> + goto out;
> + }
> +
> + err = -EINPROGRESS;
> +wait_connect:
> + if (sk->sk_state != TCP_SYN_RECV && (flags & O_NONBLOCK))
> + goto out;
> +
> + timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
> + release_sock(sk);
> +
> + err = -ERESTARTSYS;
> + timeo = wait_event_interruptible_timeout(*sk_sleep(sk),
> + sk->sk_state != TCP_CLOSE,
> + timeo);
> +
> + lock_sock(sk);
> + if (timeo < 0)
> + goto out; /* -ERESTARTSYS */
> +
> + err = -ETIMEDOUT;
> + if (timeo == 0 && sk->sk_state != TCP_SYN_RECV)
> + goto out;
> +
> + if (sk->sk_state != TCP_SYN_RECV) {
> + sock->state = SS_UNCONNECTED;
> + err = sock_error(sk);
> + if (!err)
> + err = -ECONNREFUSED;
> + goto out;
> + }
> + sock->state = SS_CONNECTED;
> + err = 0;
> +
> +out:
> + release_sock(sk);
> + return err;
> +}
> +
> static int pn_socket_accept(struct socket *sock, struct socket *newsock,
> int flags)
> {
--
Rémi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis
next prev parent reply other threads:[~2010-10-12 16:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-12 15:26 [PATCH] Phonet: 'connect' socket implementation for Pipe controller Kumar A Sanghvi
2010-10-12 16:30 ` Rémi Denis-Courmont [this message]
2010-10-13 4:32 ` Kumar SANGHVI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201010121930.32116.remi@remlab.net \
--to=remi@remlab.net \
--cc=davem@davemloft.net \
--cc=gulshan.karmani@stericsson.com \
--cc=kumar.sanghvi@stericsson.com \
--cc=linus.walleij@stericsson.com \
--cc=netdev@vger.kernel.org \
--cc=remi.denis-courmont@nokia.com \
--cc=sudeep.divakaran@stericsson.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).