netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor
@ 2019-11-13 15:44 Cris Forno
  2019-11-13 17:21 ` Thomas Falcon
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Cris Forno @ 2019-11-13 15:44 UTC (permalink / raw)
  To: netdev; +Cc: tlfalcon, Cris Forno

Currently, when ibmveth receive a loopback packet, it reports an
ambiguous error message "tx: h_send_logical_lan failed with rc=-4"
because the hypervisor rejects those types of packets. This fix
detects loopback packet and assures the source packet's MAC address
matches the driver's MAC address before transmitting to the
hypervisor.

Signed-off-by: Cris Forno <cforno12@linux.vnet.ibm.com>
---
 drivers/net/ethernet/ibm/ibmveth.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index d654c23..e8bb6c7 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1011,6 +1011,29 @@ static int ibmveth_send(struct ibmveth_adapter *adapter,
 	return 0;
 }
 
+static int ibmveth_is_packet_unsupported(struct sk_buff *skb,
+					 struct net_device *netdev)
+{
+	int ret = 0;
+	struct ethhdr *ether_header;
+
+	ether_header = eth_hdr(skb);
+
+	if (ether_addr_equal(ether_header->h_dest, netdev->dev_addr)) {
+		netdev_err(netdev, "veth doesn't support loopback packets, dropping packet.\n");
+		netdev->stats.tx_dropped++;
+		ret = -EOPNOTSUPP;
+	}
+
+	if (!ether_addr_equal(ether_header->h_source, netdev->dev_addr)) {
+		netdev_err(netdev, "source packet MAC address does not match veth device's, dropping packet.\n");
+		netdev->stats.tx_dropped++;
+		ret = -EOPNOTSUPP;
+	}
+
+	return ret;
+}
+
 static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
 				      struct net_device *netdev)
 {
@@ -1022,6 +1045,9 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
 	dma_addr_t dma_addr;
 	unsigned long mss = 0;
 
+	if (ibmveth_is_packet_unsupported(skb, netdev))
+		goto out;
+
 	/* veth doesn't handle frag_list, so linearize the skb.
 	 * When GRO is enabled SKB's can have frag_list.
 	 */
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor
  2019-11-13 15:44 [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor Cris Forno
@ 2019-11-13 17:21 ` Thomas Falcon
  2019-11-13 20:23 ` David Miller
  2019-11-13 20:28 ` Florian Fainelli
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Falcon @ 2019-11-13 17:21 UTC (permalink / raw)
  To: Cris Forno, netdev

On 11/13/19 9:44 AM, Cris Forno wrote:
> Currently, when ibmveth receive a loopback packet, it reports an
> ambiguous error message "tx: h_send_logical_lan failed with rc=-4"
> because the hypervisor rejects those types of packets. This fix
> detects loopback packet and assures the source packet's MAC address
> matches the driver's MAC address before transmitting to the
> hypervisor.
>
> Signed-off-by: Cris Forno <cforno12@linux.vnet.ibm.com>

Thanks, Cris!

Reviewed-by: Thomas Falcon <tlfalcon@linux.ibm.com>

> ---
>   drivers/net/ethernet/ibm/ibmveth.c | 26 ++++++++++++++++++++++++++
>   1 file changed, 26 insertions(+)
>
> diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
> index d654c23..e8bb6c7 100644
> --- a/drivers/net/ethernet/ibm/ibmveth.c
> +++ b/drivers/net/ethernet/ibm/ibmveth.c
> @@ -1011,6 +1011,29 @@ static int ibmveth_send(struct ibmveth_adapter *adapter,
>   	return 0;
>   }
>   
> +static int ibmveth_is_packet_unsupported(struct sk_buff *skb,
> +					 struct net_device *netdev)
> +{
> +	int ret = 0;
> +	struct ethhdr *ether_header;
> +
> +	ether_header = eth_hdr(skb);
> +
> +	if (ether_addr_equal(ether_header->h_dest, netdev->dev_addr)) {
> +		netdev_err(netdev, "veth doesn't support loopback packets, dropping packet.\n");
> +		netdev->stats.tx_dropped++;
> +		ret = -EOPNOTSUPP;
> +	}
> +
> +	if (!ether_addr_equal(ether_header->h_source, netdev->dev_addr)) {
> +		netdev_err(netdev, "source packet MAC address does not match veth device's, dropping packet.\n");
> +		netdev->stats.tx_dropped++;
> +		ret = -EOPNOTSUPP;
> +	}
> +
> +	return ret;
> +}
> +
>   static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
>   				      struct net_device *netdev)
>   {
> @@ -1022,6 +1045,9 @@ static netdev_tx_t ibmveth_start_xmit(struct sk_buff *skb,
>   	dma_addr_t dma_addr;
>   	unsigned long mss = 0;
>   
> +	if (ibmveth_is_packet_unsupported(skb, netdev))
> +		goto out;
> +
>   	/* veth doesn't handle frag_list, so linearize the skb.
>   	 * When GRO is enabled SKB's can have frag_list.
>   	 */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor
  2019-11-13 15:44 [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor Cris Forno
  2019-11-13 17:21 ` Thomas Falcon
@ 2019-11-13 20:23 ` David Miller
  2019-11-13 20:28 ` Florian Fainelli
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-11-13 20:23 UTC (permalink / raw)
  To: cforno12; +Cc: netdev, tlfalcon

From: Cris Forno <cforno12@linux.vnet.ibm.com>
Date: Wed, 13 Nov 2019 09:44:07 -0600

> @@ -1011,6 +1011,29 @@ static int ibmveth_send(struct ibmveth_adapter *adapter,
>  	return 0;
>  }
>  
> +static int ibmveth_is_packet_unsupported(struct sk_buff *skb,
> +					 struct net_device *netdev)
> +{
> +	int ret = 0;
> +	struct ethhdr *ether_header;

Please use reverse christmas tree ordering for these local variables.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor
  2019-11-13 15:44 [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor Cris Forno
  2019-11-13 17:21 ` Thomas Falcon
  2019-11-13 20:23 ` David Miller
@ 2019-11-13 20:28 ` Florian Fainelli
  2 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2019-11-13 20:28 UTC (permalink / raw)
  To: Cris Forno, netdev; +Cc: tlfalcon

On 11/13/19 7:44 AM, Cris Forno wrote:
> Currently, when ibmveth receive a loopback packet, it reports an
> ambiguous error message "tx: h_send_logical_lan failed with rc=-4"
> because the hypervisor rejects those types of packets. This fix
> detects loopback packet and assures the source packet's MAC address
> matches the driver's MAC address before transmitting to the
> hypervisor.
> 
> Signed-off-by: Cris Forno <cforno12@linux.vnet.ibm.com>
> ---
>  drivers/net/ethernet/ibm/ibmveth.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
> index d654c23..e8bb6c7 100644
> --- a/drivers/net/ethernet/ibm/ibmveth.c
> +++ b/drivers/net/ethernet/ibm/ibmveth.c
> @@ -1011,6 +1011,29 @@ static int ibmveth_send(struct ibmveth_adapter *adapter,
>  	return 0;
>  }
>  
> +static int ibmveth_is_packet_unsupported(struct sk_buff *skb,
> +					 struct net_device *netdev)
> +{
> +	int ret = 0;
> +	struct ethhdr *ether_header;
> +
> +	ether_header = eth_hdr(skb);
> +
> +	if (ether_addr_equal(ether_header->h_dest, netdev->dev_addr)) {
> +		netdev_err(netdev, "veth doesn't support loopback packets, dropping packet.\n");

These error messages should probably be demoted to netdev_dbg() prints,
you would want a maliciously written program to spam your kernel log.
-- 
Florian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-13 20:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 15:44 [PATCH net-next] ibmveth: Detect unsupported packets before sending to the hypervisor Cris Forno
2019-11-13 17:21 ` Thomas Falcon
2019-11-13 20:23 ` David Miller
2019-11-13 20:28 ` Florian Fainelli

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).