All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Jander <david@protonic.nl>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can <linux-can@vger.kernel.org>,
	Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
Subject: Re: j1939: bind() and connect()
Date: Wed, 16 Aug 2017 12:29:27 +0200	[thread overview]
Message-ID: <20170816122927.02b362af@erd980> (raw)
In-Reply-To: <69814fe9-0e29-96d7-9ae2-cc4a600f3729@pengutronix.de>

On Wed, 16 Aug 2017 12:06:50 +0200
Marc Kleine-Budde <mkl@pengutronix.de> wrote:

> On 08/16/2017 11:34 AM, Kurt Van Dijck wrote:
> >> Hello Kurt,
> >>
> >> I've a few questions about the j1939 socket model:
> >>
> >> - Should bind() be allowed to any interface, i.e. with can_ifindex == 0?
> >>
> >> I don't think so, but it's never checked for this.  
> > 
> > I'll explain a bit what I tried to accomplish:
> > * allow bind to any interface, for receive packets only (obviously)
> > * for rx/tx, only bind to 1 interface.  
> 
> Have you tested this? If I understand the code correctly
> j1939_ifindex_start() will not be called. So you will only receive
> packages from interfaces someone has other socket has bind() to, thus
> called j1939_ifindex_start(). And you'll stop receiving packages once
> the last socket on that interfaces is closed.
> 
> >> - Should a connect() without a previous bind() be allowed?
> >>
> >> It's not checked for, but the error handling in sk_connect doesn't take
> >> that into account.  
> > 
> > Like UDP will auto-bind to the first known local address ...
> > Then an application would not need to know the local address to use.  
> 
> Which will be:
> 
> > static int j1939sk_init(struct sock *sk)
> > {  
> [...]
> > 	jsk->addr.sa = J1939_NO_ADDR;
> > 	jsk->addr.da = J1939_NO_ADDR;
> > 	jsk->addr.pgn = J1939_NO_PGN;  
> [...]
> > }  
> 
> > static int j1939sk_connect(struct socket *sock, struct sockaddr *uaddr,
> > 			   int len, int flags)  
> [...]
> > 		j1939_name_local_get(priv, jsk->addr.src);
> > 		j1939_addr_local_get(priv, jsk->addr.sa);  
> 
> right? Does this work, as sendmsg tests:
> 
> > static int j1939sk_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
> > {  
> [...]
> > 	if (jsk->addr.sa == J1939_NO_ADDR && !jsk->addr.src)
> > 		/* no address assigned yet */
> > 		return -EBADFD;
> >   
> 
> >> - Should a second bind() be allowed on a previously bind() socket?  
> > 
> > Yes, definitely.
> > This is required to support dynamic addressing without possible losing
> > relevant messages.  
> 
> With changing the interface or not?
> 
> >> As far as I understand the code, there's some support, but when the
> >> interface is switched, j1939_ifindex_stop() is not called.
> >>
> >> - Should a second conect() be allowed on a previously connect() socket?  
> > 
> > Never thought on that. This would equally be necessary when the remote
> > changes SA, but I consider this not a core requirement, since changing
> > SA implies possible glitches in the upper applications anyway.
> > closing socket and reopening a new one is allowed in that case.  
> 
> So I'll add a check against a re-connect().

Hmmm... in theory, any node can change SA at any time due to a re-claim. I
always try to make this as transparent as possible to applications. The worst
that I would deem acceptable to happen is that a transport session times-out
and is transparently re-started, or a single message gets lost due to the
inherent race of switching address. Why is a re-connect necessary if one
connects to the NAME instead of the SA?

Best regards,

-- 
David Jander
Protonic Holland.

  reply	other threads:[~2017-08-16 10:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-14 17:37 j1939: bind() and connect() Marc Kleine-Budde
2017-08-15  8:14 ` Marc Kleine-Budde
2017-08-15  9:01   ` David Jander
2017-08-15  9:16     ` Marc Kleine-Budde
2017-08-15 10:24       ` David Jander
2017-08-16 21:08         ` Kurt Van Dijck
2017-08-17  7:35           ` Marc Kleine-Budde
2017-08-17  8:28             ` Kurt Van Dijck
2017-08-17  8:32               ` Marc Kleine-Budde
2017-08-16  9:34 ` Kurt Van Dijck
2017-08-16 10:06   ` Marc Kleine-Budde
2017-08-16 10:29     ` David Jander [this message]
2017-08-16 21:18       ` Kurt Van Dijck
2017-08-16 10:47     ` Marc Kleine-Budde

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=20170816122927.02b362af@erd980 \
    --to=david@protonic.nl \
    --cc=dev.kurt@vandijck-laurijssen.be \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.