Skip to contentSkip to conversation

Fix and complete CAN namespace support

PATCH In review Oliver Hartkopp 2 participants 14 messages Apr 25, 2017

Subsystems (4)
lore
Share & tools
lore

Oliver Hartkopp

author maintainer
#0 lore raw

cover Fix and complete CAN namespace support

Hello Dave,

unfortunately the initial network namespace support by Mario Kicherer (8e8cda6d737d) slipped into net-next without further review and Marc pushed the code without my Acked-by. Due to the fact that this code was in net-next now I spent some nights to fix, clean up, finalize and test the missing pieces for the namespace support for the CAN subsystem in net/can.

As Marc is currently *VERY* unresponsive on the mailing list due to his 'real' job I send this patch set directly to you to make sure it gets through the current merge window. We are already in -rc8 and I would like to avoid to push an incomplete functionality - that has to be fixed - to Linus.

This patch set is based on the latest net-next.

Thanks,
Oliver

Oliver Hartkopp (8):
can: fix memory leak in initial namespace support
can: remove obsolete pernet_operations definitions
can: remove obsolete definitions
can: complete initial namespace support
can: network namespace support for CAN_BCM protocol
can: network namespace support for CAN gateway
can: add Virtual CAN Tunnel driver (vxcan)
can: enable module auto loading for virtual CAN interfaces

 drivers/net/can/Kconfig        |  18 +++
 drivers/net/can/Makefile       |   1 +
 drivers/net/can/vcan.c         |   7 +-
 drivers/net/can/vxcan.c        | 316 +++++++++++++++++++++++++++++++++++++++++
 include/linux/can/core.h       |   4 +-
 include/net/netns/can.h        |   9 ++
 include/uapi/linux/can/vxcan.h |  12 ++
 net/can/af_can.c               |  77 +++++-----
 net/can/af_can.h               |   9 --
 net/can/bcm.c                  |  90 +++++++-----
 net/can/gw.c                   |  72 ++++++----
 net/can/proc.c                 | 141 +++++++++---------
 12 files changed, 580 insertions(+), 176 deletions(-)
 create mode 100644 drivers/net/can/vxcan.c
 create mode 100644 include/uapi/linux/can/vxcan.h
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 1/8 can: fix memory leak in initial namespace support

The can_rx_alldev_list is a per-net data structure now and allocated in can_pernet_init(). Make sure the memory is free'd in can_pernet_exit() too.

---
 net/can/af_can.c | 2 ++
 1 file changed, 2 insertions(+)
net/can/af_can.c +2 -0
index abf7d854a94d..2c935babe466 100644
@@ -903,6 +903,8 @@ static void can_pernet_exit(struct net *net)
 		}
 	}
 	rcu_read_unlock();
+
+	kfree(net->can.can_rx_alldev_list);
 }
 
 /*
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH 2/8 can: remove obsolete pernet_operations definitions

In reply to Oliver Hartkopp

The namespace support for the CAN subsystem does not need any additional memory. So when ".size = 0" there's no extra memory allocated by the system. And therefore ".id" is obsolete too.

---
 net/can/af_can.c | 4 ----
 1 file changed, 4 deletions(-)
net/can/af_can.c +0 -4
index 2c935babe466..421b60fc42c3 100644
@@ -75,8 +75,6 @@ static int stats_timer __read_mostly = 1;
 module_param(stats_timer, int, S_IRUGO);
 MODULE_PARM_DESC(stats_timer, "enable timer for statistics (default:on)");
 
-static int can_net_id;
-
 static struct kmem_cache *rcv_cache __read_mostly;
 
 /* table of registered CAN protocols */
@@ -935,8 +933,6 @@ static struct notifier_block can_netdev_notifier __read_mostly = {
 static struct pernet_operations can_pernet_ops __read_mostly = {
 	.init = can_pernet_init,
 	.exit = can_pernet_exit,
-	.id = &can_net_id,
-	.size = 0,
 };
 
 static __init int can_init(void)
Signature · 1 line
2.11.0
author maintainer
#3 lore raw

PATCH 3/8 can: remove obsolete definitions

In reply to Oliver Hartkopp

can_rx_alldev_list is a per-net data structure now. Remove it's definition here and can_rx_dev_list too.

---
 net/can/af_can.h | 4 ----
 1 file changed, 4 deletions(-)
net/can/af_can.h +0 -4
index f273c9d9b129..84a35e97c5e0 100644
@@ -110,9 +110,6 @@ struct s_pstats {
 	unsigned long rcv_entries_max;
 };
 
-/* receive filters subscribed for 'all' CAN devices */
-extern struct dev_rcv_lists can_rx_alldev_list;
-
 /* function prototypes for the CAN networklayer procfs (proc.c) */
 void can_init_proc(struct net *net);
 void can_remove_proc(struct net *net);
@@ -122,6 +119,5 @@ void can_stat_update(unsigned long data);
 extern struct timer_list can_stattimer;    /* timer for statistics update */
 extern struct s_stats    can_stats;        /* packet statistics */
 extern struct s_pstats   can_pstats;       /* receive list statistics */
-extern struct hlist_head can_rx_dev_list;  /* rx dispatcher structures */
 
 #endif /* AF_CAN_H */
Signature · 1 line
2.11.0
author maintainer
#4 lore raw

PATCH 4/8 can: complete initial namespace support

In reply to Oliver Hartkopp

The statistics and its proc output was not implemented as per-net in the initial network namespace support by Mario Kicherer (8e8cda6d737d). This patch adds the missing per-net statistics for the CAN subsystem.

---
 include/linux/can/core.h |   4 +-
 include/net/netns/can.h  |   5 ++
 net/can/af_can.c         |  71 +++++++++++++-----------
 net/can/af_can.h         |   5 --
 net/can/proc.c           | 141 +++++++++++++++++++++++++----------------------
 5 files changed, 121 insertions(+), 105 deletions(-)
include/linux/can/core.h +2 -2
index 319a0da827b8..c9a17bb1221c 100644
@@ -5,7 +5,7 @@
  *
  * Authors: Oliver Hartkopp <[email protected]>
  *          Urs Thuermann   <[email protected]>
- * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * Copyright (c) 2002-2017 Volkswagen Group Electronic Research
  * All rights reserved.
  *
  */
@@ -17,7 +17,7 @@
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
 
-#define CAN_VERSION "20120528"
+#define CAN_VERSION "20170425"
 
 /* increment this number each time you change some user-space interface */
 #define CAN_ABI_VERSION "9"
include/net/netns/can.h +5 -0
index e8beba772f1a..574157dbc43a 100644
@@ -8,6 +8,8 @@
 #include <linux/spinlock.h>
 
 struct dev_rcv_lists;
+struct s_stats;
+struct s_pstats;
 
 struct netns_can {
 #if IS_ENABLED(CONFIG_PROC_FS)
@@ -26,6 +28,9 @@ struct netns_can {
 	/* receive filters subscribed for 'all' CAN devices */
 	struct dev_rcv_lists *can_rx_alldev_list;
 	spinlock_t can_rcvlists_lock;
+	struct timer_list can_stattimer;/* timer for statistics update */
+	struct s_stats *can_stats;	/* packet statistics */
+	struct s_pstats *can_pstats;	/* receive list statistics */
 };
 
 #endif /* __NETNS_CAN_H__ */
net/can/af_can.c +38 -33

174 lines not on this page · raw message

net/can/af_can.h +0 -5
index 84a35e97c5e0..d0ef45bb2a72 100644
@@ -115,9 +115,4 @@ void can_init_proc(struct net *net);
 void can_remove_proc(struct net *net);
 void can_stat_update(unsigned long data);
 
-/* structures and variables from af_can.c needed in proc.c for reading */
-extern struct timer_list can_stattimer;    /* timer for statistics update */
-extern struct s_stats    can_stats;        /* packet statistics */
-extern struct s_pstats   can_pstats;       /* receive list statistics */
-
 #endif /* AF_CAN_H */
net/can/proc.c +76 -65

257 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#5 lore raw

PATCH 5/8 can: network namespace support for CAN_BCM protocol

In reply to Oliver Hartkopp

The CAN_BCM protocol and its procfs entries were not implemented as per-net in the initial network namespace support by Mario Kicherer (8e8cda6d737d). This patch adds the missing per-net functionality for the CAN BCM.

---
 include/net/netns/can.h |  1 +
 net/can/bcm.c           | 90 +++++++++++++++++++++++++++++++------------------
 2 files changed, 58 insertions(+), 33 deletions(-)
include/net/netns/can.h +1 -0
index 574157dbc43a..0f3c31aab8a8 100644
@@ -23,6 +23,7 @@ struct netns_can {
 	struct proc_dir_entry *pde_rcvlist_sff;
 	struct proc_dir_entry *pde_rcvlist_eff;
 	struct proc_dir_entry *pde_rcvlist_err;
+	struct proc_dir_entry *bcmproc_dir;
 #endif
 
 	/* receive filters subscribed for 'all' CAN devices */
net/can/bcm.c +57 -33

268 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#6 lore raw

PATCH 6/8 can: network namespace support for CAN gateway

In reply to Oliver Hartkopp

The CAN gateway was not implemented as per-net in the initial network namespace support by Mario Kicherer (8e8cda6d737d).
This patch enables the CAN gateway to be used in different namespaces.

---
 include/net/netns/can.h |  3 +++
 net/can/gw.c            | 72 ++++++++++++++++++++++++++++++-------------------
 2 files changed, 47 insertions(+), 28 deletions(-)
include/net/netns/can.h +3 -0
index 0f3c31aab8a8..b106e6ae2e5b 100644
@@ -32,6 +32,9 @@ struct netns_can {
 	struct timer_list can_stattimer;/* timer for statistics update */
 	struct s_stats *can_stats;	/* packet statistics */
 	struct s_pstats *can_pstats;	/* receive list statistics */
+
+	/* CAN GW per-net gateway jobs */
+	struct hlist_head cgw_list;
 };
 
 #endif /* __NETNS_CAN_H__ */
net/can/gw.c +44 -28

216 lines not on this page · raw message

Signature · 1 line
2.11.0
author maintainer
#7 lore raw

PATCH 7/8 can: add Virtual CAN Tunnel driver (vxcan)

In reply to Oliver Hartkopp

Similar to the virtual ethernet driver veth, vxcan implements a local CAN traffic tunnel between two virtual CAN network devices. See Kconfig entry for details.

---
 drivers/net/can/Kconfig        |  18 +++
 drivers/net/can/Makefile       |   1 +
 drivers/net/can/vxcan.c        | 316 +++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/can/vxcan.h |  12 ++
 4 files changed, 347 insertions(+)
 create mode 100644 drivers/net/can/vxcan.c
 create mode 100644 include/uapi/linux/can/vxcan.h
drivers/net/can/Kconfig +18 -0
index 22570ea3a8d2..61c2fcf7f880 100644
@@ -9,6 +9,24 @@ config CAN_VCAN
 	  This driver can also be built as a module.  If so, the module
 	  will be called vcan.
 
+config CAN_VXCAN
+	tristate "Virtual CAN Tunnel (vxcan)"
+	---help---
+	  Similar to the virtual ethernet driver veth, vxcan implements a
+	  local CAN traffic tunnel between two virtual CAN network devices.
+	  When creating a vxcan, two vxcan devices are created as pair.
+	  When one end receives the packet it appears on its pair and vice
+	  versa. The vxcan can be used for cross namespace communication.
+
+	  In opposite to vcan loopback devices the vxcan only forwards CAN
+	  frames to its pair and does *not* provide a local echo of sent
+	  CAN frames. To disable a potential echo in af_can.c the vxcan driver
+	  announces IFF_ECHO in the interface flags. To have a clean start
+	  in each namespace the CAN GW hop counter is set to zero.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called vxcan.
+
 config CAN_SLCAN
 	tristate "Serial / USB serial CAN Adaptors (slcan)"
 	depends on TTY
drivers/net/can/Makefile +1 -0
index 0da4f2f5c7e3..18cc6543b711 100644
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_CAN_VCAN)		+= vcan.o
+obj-$(CONFIG_CAN_VXCAN)		+= vxcan.o
 obj-$(CONFIG_CAN_SLCAN)		+= slcan.o
 
 obj-$(CONFIG_CAN_DEV)		+= can-dev.o
drivers/net/can/vxcan.c new file +316 -0

316 lines not on this page · raw message

include/uapi/linux/can/vxcan.h new file +12 -0
new file mode 100644
index 000000000000..ffb0b7156f7e
@@ -0,0 +1,12 @@
+#ifndef _UAPI_CAN_VXCAN_H
+#define _UAPI_CAN_VXCAN_H
+
+enum {
+	VXCAN_INFO_UNSPEC,
+	VXCAN_INFO_PEER,
+
+	__VXCAN_INFO_MAX
+#define VXCAN_INFO_MAX	(__VXCAN_INFO_MAX - 1)
+};
+
+#endif
Signature · 1 line
2.11.0
author maintainer
#8 lore raw

PATCH 8/8 can: enable module auto loading for virtual CAN interfaces

In reply to Oliver Hartkopp

Autoload the vcan module when a vcan instance is to be created by 'ip link add type vcan'

---
 drivers/net/can/vcan.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/can/vcan.c +5 -2
index 674f367087c5..facca33d53e9 100644
@@ -1,7 +1,7 @@
 /*
  * vcan.c - Virtual CAN interface
  *
- * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * Copyright (c) 2002-2017 Volkswagen Group Electronic Research
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -50,9 +50,12 @@
 #include <linux/slab.h>
 #include <net/rtnetlink.h>
 
+#define DRV_NAME "vcan"
+
 MODULE_DESCRIPTION("virtual CAN interface");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("Urs Thuermann <[email protected]>");
+MODULE_ALIAS_RTNL_LINK(DRV_NAME);
 
 
 /*
@@ -164,7 +167,7 @@ static void vcan_setup(struct net_device *dev)
 }
 
 static struct rtnl_link_ops vcan_link_ops __read_mostly = {
-	.kind	= "vcan",
+	.kind	= DRV_NAME,
 	.setup	= vcan_setup,
 };
 
Signature · 1 line
2.11.0
#9 lore raw
In reply to Oliver Hartkopp
Quoted 9 lines · Oliver Hartkopp

Hello Dave,

unfortunately the initial network namespace support by Mario Kicherer (8e8cda6d737d) slipped into net-next without further review and Marc pushed the code without my Acked-by. Due to the fact that this code was in net-next now I spent some nights to fix, clean up, finalize and test the missing pieces for the namespace support for the CAN subsystem in net/can.

As Marc is currently *VERY* unresponsive on the mailing list due to his 'real'

... and holidays :) But I'm back in the office now.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
author maintainer
#10 lore raw
Quoted 9 lines · Marc Kleine-Budde
Quoted 8 lines · Oliver Hartkopp

Hello Dave,

unfortunately the initial network namespace support by Mario Kicherer (8e8cda6d737d) slipped into net-next without further review and Marc pushed the code without my Acked-by. Due to the fact that this code was in net-next now I spent some nights to fix, clean up, finalize and test the missing pieces for the namespace support for the CAN subsystem in net/can.

Quoted 3 lines
Quoted 1 line

As Marc is currently *VERY* unresponsive on the mailing list due to his 'real'

... and holidays :) But I'm back in the office now.

I created a cleaned patch series to provide more detailed and proper patches. And these patches are based on Dave's net-next as you did not push your latest changes in mkl/linux-can-next to the public on week ago.

When you manage to get this series integrated today then it would be ok for me. Otherwise we should Dave take this series directly.

Thanks,
Oliver

#11 lore raw
In reply to Marc Kleine-Budde
Quoted 9 lines · Marc Kleine-Budde
Quoted 8 lines · Oliver Hartkopp

Hello Dave,

unfortunately the initial network namespace support by Mario Kicherer (8e8cda6d737d) slipped into net-next without further review and Marc pushed the code without my Acked-by. Due to the fact that this code was in net-next now I spent some nights to fix, clean up, finalize and test the missing pieces for the namespace support for the CAN subsystem in net/can.

Quoted 3 lines
Quoted 1 line

As Marc is currently *VERY* unresponsive on the mailing list due to his 'real'

... and holidays :) But I'm back in the office now.

FYI:
This series is included in the latest pull request:

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git
tags/linux-can-next-for-4.12-20170425

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
author maintainer
#12 lore raw
Quoted 6 lines · Marc Kleine-Budde

FYI:
This series is included in the latest pull request:

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git
tags/linux-can-next-for-4.12-20170425

Ok, thanks!

Sorry for pushing a bit harder this time. But I wanted to make sure that we don't get incomplete stuff into the merge window.

Regards,
Oliver

#13 lore raw
Quoted 5 lines · Oliver Hartkopp
Quoted 3 lines · Marc Kleine-Budde

FYI:
This series is included in the latest pull request:

Quoted 8 lines
Quoted 3 lines

git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git
tags/linux-can-next-for-4.12-20170425

Ok, thanks!

Sorry for pushing a bit harder this time. But I wanted to make sure that we don't get incomplete stuff into the merge window.

np :D

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |