mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jaroslav Beran <jara.beran@gmail.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	"David S. Miller" <davem@davemloft.net>,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Jaroslav Beran <jara.beran@gmail.com>
Subject: [PATCH] can: return error from can_send() in BUS-OFF state
Date: Wed,  6 Nov 2019 23:03:02 +0100	[thread overview]
Message-ID: <20191106220302.27698-1-jara.beran@gmail.com> (raw)

When a CAN node reaches BUS-OFF state, its netdev state
is set to __LINK_STATE_NOCARRIER and qdisc ->enqueue() starts
dropping frames and returning NET_XMIT_CN that is turned to 0
by net_xmit_errno(). So can_send() returns success to a sender
even if his frame is lost.

As this behavior is inappropriate for a node in BUS-OFF state,
this patch adds a check for no-carrier condition and returns
-ENETUNREACH in such case.

Signed-off-by: Jaroslav Beran <jara.beran@gmail.com>
---
 net/can/af_can.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 5518a7d9eed9..68c56241733b 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -189,6 +189,7 @@ static int can_create(struct net *net, struct socket *sock, int protocol,
  * Return:
  *  0 on success
  *  -ENETDOWN when the selected interface is down
+ *  -ENETUNREACH when the node is in BUS-OFF state
  *  -ENOBUFS on full driver queue (see net_xmit_errno())
  *  -ENOMEM when local loopback failed at calling skb_clone()
  *  -EPERM when trying to send on a non-CAN interface
@@ -233,6 +234,11 @@ int can_send(struct sk_buff *skb, int loop)
 		goto inval_skb;
 	}
 
+	if (unlikely(!netif_carrier_ok(skb->dev))) {
+		err = -ENETUNREACH;
+		goto inval_skb;
+	}
+
 	skb->ip_summed = CHECKSUM_UNNECESSARY;
 
 	skb_reset_mac_header(skb);
-- 
2.23.0


                 reply	other threads:[~2019-11-06 22:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191106220302.27698-1-jara.beran@gmail.com \
    --to=jara.beran@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /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

all inboxes | Powered by JetHome®