All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Marc Kleine-Budde <mkl@pengutronix.de>,
	linux-can@vger.kernel.org, kernel@pengutronix.de,
	dev.kurt@vandijck-laurijssen.be
Subject: Re: [PATCH 09/14] can: raw: use struct sock::sk_bound_dev_if instead of struct raw_sock::ifindex
Date: Fri, 25 Aug 2017 10:43:39 +0200	[thread overview]
Message-ID: <e1a150f8-7a0b-b327-86ac-e66cf3d817ef@hartkopp.net> (raw)
In-Reply-To: <20170824141126.GD21548@airbook.vandijck-laurijssen.be>



On 08/24/2017 04:11 PM, Kurt Van Dijck wrote:
>>> This patch removes the struct raw_sock::ifindex from the CAN raw socket
>>> and uses the already existing sock::sk_bound_dev_if instead.
>>
>> I would like to omit this patch.
>>
>> 1. It does NOT increase the readability ;-)
>>
>> ifindex points out that we are handling an interface index.
>> sk_bound_dev_if could be anything.
> 
> See http://elixir.free-electrons.com/linux/v4.12.8/source/net/core/sock.c#L617
> sk_bound_dev_if may be a difficult name, but could not be anything.
> It allow to use SO_BINDTODEVICE (man 7 socket) to work properly for can raw sockets too.

When ro->ifindex = 0 it can still be bound in the case of CAN sockets.
There is a different semantic as ifindex = zero means 'all CAN 
interfaces' and not 'no interface'.

So I would really wonder whether SO_BINDTODEVICE (man 7 socket) would 
ever work properly for can raw sockets too.

Thanks for the reference to sock.c - it just proved my guts feeling.

Regards,
Oliver

> 
>>
>> 2. I have bad feelings on using data structures from the general networking
>> code as I had various discussions with e.g. iif in struct netdevice so that
>> we needed to store our CAN specific incoming interface in a separated space
>> before skb->data.
> 
> sock::sk_bound_dev_if happens to be semantically identical to raw_sock::ifindex.
> The grounds for discussions are IMHO very limited in this matter.
> It also helps to check for the net device being a CAN device first.
> 
> Kind regards,
> Kurt
>>
>> Regards,
>> Oliver
>>
>>>
>>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>>> ---
>>>   net/can/raw.c | 33 +++++++++++++++------------------
>>>   1 file changed, 15 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/net/can/raw.c b/net/can/raw.c
>>> index 864c80dbdb72..80a1545bf51a 100644
>>> --- a/net/can/raw.c
>>> +++ b/net/can/raw.c
>>> @@ -83,7 +83,6 @@ struct uniqframe {
>>>   struct raw_sock {
>>>   	struct sock sk;
>>>   	int bound;
>>> -	int ifindex;
>>>   	struct notifier_block notifier;
>>>   	int loopback;
>>>   	int recv_own_msgs;
>>> @@ -279,7 +278,7 @@ static int raw_notifier(struct notifier_block *nb,
>>>   	if (dev->type != ARPHRD_CAN)
>>>   		return NOTIFY_DONE;
>>> -	if (ro->ifindex != dev->ifindex)
>>> +	if (sk->sk_bound_dev_if != dev->ifindex)
>>>   		return NOTIFY_DONE;
>>>   	switch (msg) {
>>> @@ -293,7 +292,7 @@ static int raw_notifier(struct notifier_block *nb,
>>>   		if (ro->count > 1)
>>>   			kfree(ro->filter);
>>> -		ro->ifindex = 0;
>>> +		sk->sk_bound_dev_if = 0;
>>>   		ro->bound   = 0;
>>>   		ro->count   = 0;
>>>   		release_sock(sk);
>>> @@ -318,7 +317,6 @@ static int raw_init(struct sock *sk)
>>>   	struct raw_sock *ro = raw_sk(sk);
>>>   	ro->bound            = 0;
>>> -	ro->ifindex          = 0;
>>>   	/* set default filter to single entry dfilter */
>>>   	ro->dfilter.can_id   = 0;
>>> @@ -361,10 +359,10 @@ static int raw_release(struct socket *sock)
>>>   	/* remove current filters & unregister */
>>>   	if (ro->bound) {
>>> -		if (ro->ifindex) {
>>> +		if (sk->sk_bound_dev_if) {
>>>   			struct net_device *dev;
>>> -			dev = dev_get_by_index(sock_net(sk), ro->ifindex);
>>> +			dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
>>>   			if (dev) {
>>>   				raw_disable_allfilters(dev_net(dev), dev, sk);
>>>   				dev_put(dev);
>>> @@ -376,7 +374,7 @@ static int raw_release(struct socket *sock)
>>>   	if (ro->count > 1)
>>>   		kfree(ro->filter);
>>> -	ro->ifindex = 0;
>>> +	sk->sk_bound_dev_if = 0;
>>>   	ro->bound   = 0;
>>>   	ro->count   = 0;
>>>   	free_percpu(ro->uniq);
>>> @@ -404,7 +402,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
>>>   	lock_sock(sk);
>>> -	if (ro->bound && addr->can_ifindex == ro->ifindex)
>>> +	if (ro->bound && addr->can_ifindex == sk->sk_bound_dev_if)
>>>   		goto out;
>>>   	if (addr->can_ifindex) {
>>> @@ -438,11 +436,11 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
>>>   	if (!err) {
>>>   		if (ro->bound) {
>>>   			/* unregister old filters */
>>> -			if (ro->ifindex) {
>>> +			if (sk->sk_bound_dev_if) {
>>>   				struct net_device *dev;
>>>   				dev = dev_get_by_index(sock_net(sk),
>>> -						       ro->ifindex);
>>> +						       sk->sk_bound_dev_if);
>>>   				if (dev) {
>>>   					raw_disable_allfilters(dev_net(dev),
>>>   							       dev, sk);
>>> @@ -451,7 +449,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
>>>   			} else
>>>   				raw_disable_allfilters(sock_net(sk), NULL, sk);
>>>   		}
>>> -		ro->ifindex = ifindex;
>>> +		sk->sk_bound_dev_if = ifindex;
>>>   		ro->bound = 1;
>>>   	}
>>> @@ -472,14 +470,13 @@ static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
>>>   {
>>>   	struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
>>>   	struct sock *sk = sock->sk;
>>> -	struct raw_sock *ro = raw_sk(sk);
>>>   	if (peer)
>>>   		return -EOPNOTSUPP;
>>>   	memset(addr, 0, sizeof(*addr));
>>>   	addr->can_family  = AF_CAN;
>>> -	addr->can_ifindex = ro->ifindex;
>>> +	addr->can_ifindex = sk->sk_bound_dev_if;
>>>   	*len = sizeof(*addr);
>>> @@ -524,8 +521,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
>>>   		lock_sock(sk);
>>> -		if (ro->bound && ro->ifindex)
>>> -			dev = dev_get_by_index(sock_net(sk), ro->ifindex);
>>> +		if (ro->bound && sk->sk_bound_dev_if)
>>> +			dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
>>>   		if (ro->bound) {
>>>   			/* (try to) register the new filters */
>>> @@ -578,8 +575,8 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
>>>   		lock_sock(sk);
>>> -		if (ro->bound && ro->ifindex)
>>> -			dev = dev_get_by_index(sock_net(sk), ro->ifindex);
>>> +		if (ro->bound && sk->sk_bound_dev_if)
>>> +			dev = dev_get_by_index(sock_net(sk), sk->sk_bound_dev_if);
>>>   		/* remove current error mask */
>>>   		if (ro->bound) {
>>> @@ -743,7 +740,7 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
>>>   		ifindex = addr->can_ifindex;
>>>   	} else
>>> -		ifindex = ro->ifindex;
>>> +		ifindex = sk->sk_bound_dev_if;
>>>   	if (ro->fd_frames) {
>>>   		if (unlikely(size != CANFD_MTU && size != CAN_MTU))
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-08-25  8:43 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 17:44 [00/14] can: cleanup of af_can/raw + simplifying of ndev->ml_priv handling Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 01/14] can: af_can: can_pernet_init(): add missing error handling for kzalloc returning NULL Marc Kleine-Budde
2017-08-24 12:42   ` Oliver Hartkopp
2017-08-25  8:31     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 02/14] can: give structs holding the CAN statistics a sensible name Marc Kleine-Budde
2017-08-24 12:58   ` Oliver Hartkopp
2017-08-25 13:08     ` Marc Kleine-Budde
2017-08-25 17:32       ` Oliver Hartkopp
2017-08-28  7:25         ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 03/14] can: af_can: give struct holding the CAN per device receive lists " Marc Kleine-Budde
2017-08-24 12:59   ` Oliver Hartkopp
2017-08-28 10:58     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 04/14] can: af_can: give variable " Marc Kleine-Budde
2017-08-24 13:03   ` Oliver Hartkopp
2017-08-28 13:39     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 05/14] can: proc: " Marc Kleine-Budde
2017-08-24 13:05   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 06/14] can: af_can: rename find_rcv_list() to can_rcv_list_find() Marc Kleine-Budde
2017-08-24 13:11   ` Oliver Hartkopp
2017-08-28 11:53     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 07/14] can: af_can: give variable holding the CAN receiver and the receiver list a sensible name Marc Kleine-Budde
2017-08-24 13:27   ` Oliver Hartkopp
2017-08-28 15:24     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 08/14] can: af_can: can_rx_register(): use max() instead of open coding it Marc Kleine-Budde
2017-08-24 13:28   ` Oliver Hartkopp
2017-08-28 15:24     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 09/14] can: raw: use struct sock::sk_bound_dev_if instead of struct raw_sock::ifindex Marc Kleine-Budde
2017-08-24 13:39   ` Oliver Hartkopp
2017-08-24 14:11     ` Kurt Van Dijck
2017-08-25  8:43       ` Oliver Hartkopp [this message]
2017-08-25  9:34         ` Kurt Van Dijck
2017-08-25 17:54           ` Oliver Hartkopp
2017-08-25 18:46             ` Kurt Van Dijck
2017-08-27 14:27               ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 10/14] can: raw: raw_bind: bail out if can_family is not AF_CAN Marc Kleine-Budde
2017-08-24 13:40   ` Oliver Hartkopp
2017-08-28 15:25     ` Marc Kleine-Budde
2017-08-02 17:44 ` [PATCH 11/14] can: af_can: can_pernet_exit(): no need to iterate over and cleanup registered CAN devices Marc Kleine-Budde
2017-08-24 13:48   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 12/14] can: introduce CAN midlayer private and allocate it automatically Marc Kleine-Budde
2017-08-24 13:51   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 13/14] can: make use of preallocated can_ml_priv for per device struct can_dev_rcv_lists Marc Kleine-Budde
2017-08-24 13:55   ` Oliver Hartkopp
2017-08-02 17:44 ` [PATCH 14/14] can: af_can: remove NULL-ptr checks from users of can_dev_rcv_lists_find() Marc Kleine-Budde
2017-08-24 13:58   ` Oliver Hartkopp
2017-08-03  5:03 ` [00/14] can: cleanup of af_can/raw + simplifying of ndev->ml_priv handling Oliver Hartkopp
2017-08-03  7:39   ` Marc Kleine-Budde
2017-08-17 11:57   ` Marc Kleine-Budde
2017-08-17 12:57     ` Oliver Hartkopp
2017-08-17 13:02       ` Marc Kleine-Budde
2017-08-17 13:03         ` Marc Kleine-Budde
2017-08-17 13:06           ` Marc Kleine-Budde
2017-08-17 13:13             ` Oliver Hartkopp
2017-08-17 13:17               ` Marc Kleine-Budde
2017-08-17 13:54                 ` Oliver Hartkopp
2017-08-17 14:08                   ` Marc Kleine-Budde
2017-08-24 12:31                     ` Oliver Hartkopp
2017-08-17 13:08         ` Oliver Hartkopp

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=e1a150f8-7a0b-b327-86ac-e66cf3d817ef@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=dev.kurt@vandijck-laurijssen.be \
    --cc=kernel@pengutronix.de \
    --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.