can: gw: make routing to the incoming CAN interface configurable
authorOliver Hartkopp <socketcan@hartkopp.net>
Thu, 17 Jan 2013 17:43:41 +0000 (18:43 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Sat, 26 Jan 2013 15:59:01 +0000 (16:59 +0100)
Introduce new configuration flag CGW_FLAGS_CAN_IIF_TX_OK to configure if a
CAN sk_buff that has been routed with can-gw is allowed to be send back to
the originating CAN interface.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
include/uapi/linux/can/gw.h
net/can/gw.c

index 8e1db18c3cb6d7091840be90c20289f19b81d724..0505c7f8621338ecd12df9dd044e307077d26b9b 100644 (file)
@@ -51,6 +51,7 @@ enum {
 
 #define CGW_FLAGS_CAN_ECHO 0x01
 #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02
+#define CGW_FLAGS_CAN_IIF_TX_OK 0x04
 
 #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */
 
index 574dda78eb0f0d747eeeb44fb9da74be9618068f..37a3efb7cc9d164767b4dbf70167d73ff248661f 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/skbuff.h>
 #include <linux/can.h>
 #include <linux/can/core.h>
+#include <linux/can/skb.h>
 #include <linux/can/gw.h>
 #include <net/rtnetlink.h>
 #include <net/net_namespace.h>
@@ -347,6 +348,13 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
                return;
        }
 
+       /* is sending the skb back to the incoming interface not allowed? */
+       if (!(gwj->flags & CGW_FLAGS_CAN_IIF_TX_OK) &&
+           skb_headroom(skb) == sizeof(struct can_skb_priv) &&
+           (((struct can_skb_priv *)(skb->head))->ifindex ==
+            gwj->dst.dev->ifindex))
+               return;
+
        /*
         * clone the given skb, which has not been done in can_rcv()
         *