Skip to contentSkip to conversation

introduce infrastructure for support of switch chip datapath

RFC PATCH Superseded Jiri Pirko 12 participants 31 messages Mar 26, 2014 – Mar 31, 2014 11 messages not in the archive

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

v2 cover introduce infrastructure for support of switch chip datapath

This is second version of RFC. Here are the main differences from the first one:
-There is no special swdev of swport structure. The switch and its ports are
now represented only by net_device structures. There are couple of switch-specific ndos added (inserting and removing flows).

-Regarding the flows, driver marks skb with "missing flow" flag now. That would
give indication to a user (OVS datapath of af_packet userspace application). On the opposite direction, skb can be xmitted by a port.

-dummyswitch module has now rtnetlink iface for easy creation of dummy switches
and ports.

The basic idea is to introduce a generic infractructure to support various switch chips in kernel. Also the idea is to benefit of currently existing Open vSwitch userspace infrastructure.

The first two patches are just minor skb flag and packet_type modifications.

The third patch does a split of structures which are not specific to OVS into more generic ones that can be reused.

The fourth patch introduces the "switchdev" API itself. It should serve as a glue between chip drivers on the one side and the user on the other. That user might be OVS datapath but in future it might be just userspace application interacting via af_packet and Netlink iface.

The infrastructure is designed to be similar to for example linux bridge. There is one netdevice representing a switch chip and one netdevice per every port. These are bound together in classic slave-master way. The reason to reuse the netdevices for port representation is that userspace can use standard tools to get information about the ports, statistics, tcpdump, etc.

Note that the netdevices are just representations of the ports in the switch. Therefore **no actual data** goes though, only missed flow skbs and, if drivers supports it, when ETH_P_ALL packet_type is hooked on (tcpdump).

The fifth patch introduces a support for switchdev vports into OVS datapath. After that, userspace would be able to create a switchdev DP for a switch chip, to add switchdev ports to it and to use it in the same way as it would be OVS SW datapath.

The sixth patch adds a dummy switch module. It is just an example of switchdev driver implementation.

Jiri Pirko (6):
net: make packet_type->ak_packet_priv generic
skbuff: add "missed_flow" flag
openvswitch: split flow structures into ovs specific and generic ones
net: introduce switchdev API
openvswitch: Introduce support for switchdev based datapath
net: introduce dummy switch

 drivers/net/Kconfig                        |   7 +
 drivers/net/Makefile                       |   1 +
 drivers/net/dummyswitch.c                  | 235 +++++++++++++++++++++++++++++
 include/linux/filter.h                     |   1 +
 include/linux/netdevice.h                  |  26 +++-
 include/linux/skbuff.h                     |  13 ++
 include/linux/sw_flow.h                    | 105 +++++++++++++
 include/linux/switchdev.h                  |  30 ++++
 include/uapi/linux/if_link.h               |   9 ++
 include/uapi/linux/openvswitch.h           |   4 +
 net/Kconfig                                |  10 ++
 net/core/Makefile                          |   1 +
 net/core/dev.c                             |   4 +-
 net/core/filter.c                          |   3 +
 net/core/switchdev.c                       | 172 +++++++++++++++++++++
 net/openvswitch/Makefile                   |   4 +
 net/openvswitch/datapath.c                 |  90 +++++++----
 net/openvswitch/datapath.h                 |  12 +-
 net/openvswitch/dp_notify.c                |   3 +-
 net/openvswitch/flow.c                     |  14 +-
 net/openvswitch/flow.h                     | 123 +++------------
 net/openvswitch/flow_netlink.c             |  24 +--
 net/openvswitch/flow_netlink.h             |   4 +-
 net/openvswitch/flow_table.c               | 100 ++++++------
 net/openvswitch/flow_table.h               |  18 +--
 net/openvswitch/vport-gre.c                |   4 +-
 net/openvswitch/vport-internal_switchdev.c | 179 ++++++++++++++++++++++
 net/openvswitch/vport-internal_switchdev.h |  28 ++++
 net/openvswitch/vport-netdev.c             |   4 +-
 net/openvswitch/vport-switchportdev.c      | 205 +++++++++++++++++++++++++
 net/openvswitch/vport-switchportdev.h      |  24 +++
 net/openvswitch/vport-vxlan.c              |   2 +-
 net/openvswitch/vport.c                    |   6 +-
 net/openvswitch/vport.h                    |   4 +-
 net/packet/af_packet.c                     |  22 ++-
 35 files changed, 1269 insertions(+), 222 deletions(-)
 create mode 100644 drivers/net/dummyswitch.c
 create mode 100644 include/linux/sw_flow.h
 create mode 100644 include/linux/switchdev.h
 create mode 100644 net/core/switchdev.c
 create mode 100644 net/openvswitch/vport-internal_switchdev.c
 create mode 100644 net/openvswitch/vport-internal_switchdev.h
 create mode 100644 net/openvswitch/vport-switchportdev.c
 create mode 100644 net/openvswitch/vport-switchportdev.h
Signature · 1 line
1.8.5.3

A message that is not in the archive (sent off-list or not yet received): 1395851472-10524-1-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org

#2 lore raw

RFC PATCH v2 5/6 openvswitch: Introduce support for switchdev based datapath

---
 include/uapi/linux/openvswitch.h           |   4 +
 net/openvswitch/Makefile                   |   4 +
 net/openvswitch/datapath.c                 |  45 ++++++-
 net/openvswitch/datapath.h                 |   8 ++
 net/openvswitch/dp_notify.c                |   3 +-
 net/openvswitch/vport-internal_switchdev.c | 179 +++++++++++++++++++++++++
 net/openvswitch/vport-internal_switchdev.h |  28 ++++
 net/openvswitch/vport-netdev.c             |   4 +-
 net/openvswitch/vport-switchportdev.c      | 205 +++++++++++++++++++++++++++++
 net/openvswitch/vport-switchportdev.h      |  24 ++++
 net/openvswitch/vport.c                    |   4 +
 net/openvswitch/vport.h                    |   2 +
 12 files changed, 504 insertions(+), 6 deletions(-)
 create mode 100644 net/openvswitch/vport-internal_switchdev.c
 create mode 100644 net/openvswitch/vport-internal_switchdev.h
 create mode 100644 net/openvswitch/vport-switchportdev.c
 create mode 100644 net/openvswitch/vport-switchportdev.h
include/uapi/linux/openvswitch.h +4 -0
index 970553c..8df1a49 100644
@@ -189,6 +189,10 @@ enum ovs_vport_type {
 	OVS_VPORT_TYPE_INTERNAL, /* network device implemented by datapath */
 	OVS_VPORT_TYPE_GRE,      /* GRE tunnel. */
 	OVS_VPORT_TYPE_VXLAN,	 /* VXLAN tunnel. */
+	OVS_VPORT_TYPE_INTERNAL_SWITCHDEV, /* network device which represents
+					      a hardware switch */
+	OVS_VPORT_TYPE_SWITCHPORTDEV, /* network device which represents
+					 a port of a hardware switch */
 	__OVS_VPORT_TYPE_MAX
 };
 
net/openvswitch/Makefile +4 -0
index 3591cb5..6e9fb2a 100644
@@ -22,3 +22,7 @@ endif
 ifneq ($(CONFIG_OPENVSWITCH_GRE),)
 openvswitch-y += vport-gre.o
 endif
+
+ifneq ($(CONFIG_NET_SWITCHDEV),)
+openvswitch-y += vport-internal_switchdev.o vport-switchportdev.o
+endif
net/openvswitch/datapath.c +41 -4

104 lines not on this page · raw message

net/openvswitch/datapath.h +8 -0
index 5388cac..584999b 100644
@@ -58,6 +58,8 @@ struct dp_stats_percpu {
 	struct u64_stats_sync syncp;
 };
 
+struct dp_ops;
+
 /**
  * struct datapath - datapath for flow-based packet switching
  * @rcu: RCU callback head for deferred destruction.
@@ -90,6 +92,12 @@ struct datapath {
 #endif
 
 	u32 user_features;
+	const struct dp_ops *ops;
+};
+
+struct dp_ops {
+	int (*flow_insert)(struct datapath *dp, struct sw_flow *flow);
+	void (*flow_remove)(struct datapath *dp, struct sw_flow *flow);
 };
 
 /**
net/openvswitch/dp_notify.c +2 -1
index 2c631fe..7f9b6ae 100644
@@ -22,6 +22,7 @@
 
 #include "datapath.h"
 #include "vport-internal_dev.h"
+#include "vport-internal_switchdev.h"
 #include "vport-netdev.h"
 
 static void dp_detach_port_notify(struct vport *vport)
@@ -79,7 +80,7 @@ static int dp_device_event(struct notifier_block *unused, unsigned long event,
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 	struct vport *vport = NULL;
 
-	if (!ovs_is_internal_dev(dev))
+	if (!ovs_is_internal_dev(dev) && !ovs_is_internal_swdev(dev))
 		vport = ovs_netdev_get_vport(dev);
 
 	if (!vport)
net/openvswitch/vport-internal_switchdev.c new file +179 -0

179 lines not on this page · raw message

net/openvswitch/vport-internal_switchdev.h new file +28 -0
new file mode 100644
index 0000000..7f320ff
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014 Jiri Pirko <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ */
+
+#ifndef VPORT_INTERNAL_SWITCHDEV_H
+#define VPORT_INTERNAL_SWITCHDEV_H 1
+
+bool ovs_is_suitable_for_internal_swdev(struct net *net, const char *name);
+struct vport *ovs_internal_swdev_get_vport_by_dp(const struct datapath *dp);
+struct vport *ovs_internal_swdev_get_vport(const struct net_device *dev);
+bool ovs_is_internal_swdev(const struct net_device *dev);
+struct net_device *ovs_internal_swdev_get_netdev(struct vport *vport);
+
+#endif /* vport-internal_switchdev.h */
net/openvswitch/vport-netdev.c +3 -1
index d21f77d..3121b59 100644
@@ -31,6 +31,7 @@
 
 #include "datapath.h"
 #include "vport-internal_dev.h"
+#include "vport-internal_switchdev.h"
 #include "vport-netdev.h"
 
 /* Must be called with rcu_read_lock. */
@@ -107,7 +108,8 @@ static struct vport *netdev_create(const struct vport_parms *parms)
 
 	if (netdev_vport->dev->flags & IFF_LOOPBACK ||
 	    netdev_vport->dev->type != ARPHRD_ETHER ||
-	    ovs_is_internal_dev(netdev_vport->dev)) {
+	    ovs_is_internal_dev(netdev_vport->dev) ||
+	    ovs_is_internal_swdev(netdev_vport->dev)) {
 		err = -EINVAL;
 		goto error_put;
 	}
net/openvswitch/vport-switchportdev.c new file +205 -0

205 lines not on this page · raw message

net/openvswitch/vport-switchportdev.h new file +24 -0
new file mode 100644
index 0000000..b578794
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014 Jiri Pirko <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ */
+
+#ifndef VPORT_SWITCHPORTDEV_H
+#define VPORT_SWITCHPORTDEV_H 1
+
+bool ovs_is_suitable_for_switchportdev(struct net *net, const char *name);
+
+#endif /* vport-switchportdev.h */
net/openvswitch/vport.c +4 -0
index 81b083c..39aa836 100644
@@ -48,6 +48,10 @@ static const struct vport_ops *vport_ops_list[] = {
 #ifdef CONFIG_OPENVSWITCH_VXLAN
 	&ovs_vxlan_vport_ops,
 #endif
+#if IS_ENABLED(CONFIG_NET_SWITCHDEV)
+	&ovs_internal_swdev_vport_ops,
+	&ovs_swportdev_vport_ops,
+#endif
 };
 
 /* Protected by RCU read lock for reading, ovs_mutex for writing. */
net/openvswitch/vport.h +2 -0
index 0979304..100277f 100644
@@ -199,6 +199,8 @@ extern const struct vport_ops ovs_netdev_vport_ops;
 extern const struct vport_ops ovs_internal_vport_ops;
 extern const struct vport_ops ovs_gre_vport_ops;
 extern const struct vport_ops ovs_vxlan_vport_ops;
+extern const struct vport_ops ovs_internal_swdev_vport_ops;
+extern const struct vport_ops ovs_swportdev_vport_ops;
 
 static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb,
 				      const void *start, unsigned int len)
Signature · 1 line
1.8.5.3
#3 lore raw

RFC PATCH v2 6/6 net: introduce dummy switch

In reply to a message not in the archive

Dummy switch implementation using switchdev API

---
 drivers/net/Kconfig          |   7 ++
 drivers/net/Makefile         |   1 +
 drivers/net/dummyswitch.c    | 235 +++++++++++++++++++++++++++++++++++++++++++
 include/uapi/linux/if_link.h |   9 ++
 4 files changed, 252 insertions(+)
 create mode 100644 drivers/net/dummyswitch.c
drivers/net/Kconfig +7 -0
index 89402c3..a9629a7 100644
@@ -71,6 +71,13 @@ config DUMMY
 	  To compile this driver as a module, choose M here: the module
 	  will be called dummy.
 
+config NET_DUMMY_SWITCH
+	tristate "Dummy switch net driver support"
+	depends on NET_SWITCHDEV
+	---help---
+	  To compile this driver as a module, choose M here: the module
+	  will be called dummyswitch.
+
 config EQUALIZER
 	tristate "EQL (serial line load balancing) support"
 	---help---
drivers/net/Makefile +1 -0
index 3fef8a8..d5d4ce6 100644
@@ -7,6 +7,7 @@
 #
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_DUMMY) += dummy.o
+obj-$(CONFIG_NET_DUMMY_SWITCH) += dummyswitch.o
 obj-$(CONFIG_EQUALIZER) += eql.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACVLAN) += macvlan.o
drivers/net/dummyswitch.c new file +235 -0

235 lines not on this page · raw message

include/uapi/linux/if_link.h +9 -0
index 16410b6..ec14dd3 100644
@@ -544,4 +544,13 @@ enum {
 
 #define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1)
 
+/* DUMMYSWPORT section */
+enum {
+	IFLA_DUMMYSWPORT_UNSPEC,
+	IFLA_DUMMYSWPORT_MASTER,
+	__IFLA_DUMMYSWPORT_MAX,
+};
+
+#define IFLA_DUMMYSWPORT_MAX (__IFLA_DUMMYSWPORT_MAX - 1)
+
 #endif /* _UAPI_LINUX_IF_LINK_H */
Signature · 1 line
1.8.5.3
#4 lore raw
In reply to a message not in the archive

Jiri,

The flow extensions may be distracting - note there are many tables (L3, L2, etc) in such chips not just ACLs. And there's likely no OneWay(tm) to add a flow. My view is probably to solve or reach an agreement on the ports. Then resolve the different tables control/data exposure.
On the switchdev - You are still exposing it; do you expect these things to be created from user space? Probably thats one approach, but I would suspect the majority would result in the driver itself creating these devices after discovering the resources from the control interfaces (PCIE etc).

cheers,
jamal

Quoted 103 lines · Jiri Pirko

This is second version of RFC. Here are the main differences from the first one:

(quoted diff) +0 -3
-There is no special swdev of swport structure. The switch and its ports are
  now represented only by net_device structures. There are couple of switch-specific
  ndos added (inserting and removing flows).
 
-Regarding the flows, driver marks skb with "missing flow" flag now. That would
  give indication to a user (OVS datapath of af_packet userspace application).
  On the opposite direction, skb can be xmitted by a port.
 
-dummyswitch module has now rtnetlink iface for easy creation of dummy switches
  and ports.

The basic idea is to introduce a generic infractructure to support various switch chips in kernel. Also the idea is to benefit of currently existing Open vSwitch userspace infrastructure.

The first two patches are just minor skb flag and packet_type modifications.

The third patch does a split of structures which are not specific to OVS into more generic ones that can be reused.

The fourth patch introduces the "switchdev" API itself. It should serve as a glue between chip drivers on the one side and the user on the other. That user might be OVS datapath but in future it might be just userspace application interacting via af_packet and Netlink iface.

The infrastructure is designed to be similar to for example linux bridge. There is one netdevice representing a switch chip and one netdevice per every port. These are bound together in classic slave-master way. The reason to reuse the netdevices for port representation is that userspace can use standard tools to get information about the ports, statistics, tcpdump, etc.

Note that the netdevices are just representations of the ports in the switch. Therefore **no actual data** goes though, only missed flow skbs and, if drivers supports it, when ETH_P_ALL packet_type is hooked on (tcpdump).

The fifth patch introduces a support for switchdev vports into OVS datapath. After that, userspace would be able to create a switchdev DP for a switch chip, to add switchdev ports to it and to use it in the same way as it would be OVS SW datapath.

The sixth patch adds a dummy switch module. It is just an example of switchdev driver implementation.

Jiri Pirko (6):
net: make packet_type->ak_packet_priv generic
skbuff: add "missed_flow" flag
openvswitch: split flow structures into ovs specific and generic ones
net: introduce switchdev API
openvswitch: Introduce support for switchdev based datapath
net: introduce dummy switch

  drivers/net/Kconfig                        |   7 +
  drivers/net/Makefile                       |   1 +
  drivers/net/dummyswitch.c                  | 235 +++++++++++++++++++++++++++++
  include/linux/filter.h                     |   1 +
  include/linux/netdevice.h                  |  26 +++-
  include/linux/skbuff.h                     |  13 ++
  include/linux/sw_flow.h                    | 105 +++++++++++++
  include/linux/switchdev.h                  |  30 ++++
  include/uapi/linux/if_link.h               |   9 ++
  include/uapi/linux/openvswitch.h           |   4 +
  net/Kconfig                                |  10 ++
  net/core/Makefile                          |   1 +
  net/core/dev.c                             |   4 +-
  net/core/filter.c                          |   3 +
  net/core/switchdev.c                       | 172 +++++++++++++++++++++
  net/openvswitch/Makefile                   |   4 +
  net/openvswitch/datapath.c                 |  90 +++++++----
  net/openvswitch/datapath.h                 |  12 +-
  net/openvswitch/dp_notify.c                |   3 +-
  net/openvswitch/flow.c                     |  14 +-
  net/openvswitch/flow.h                     | 123 +++------------
  net/openvswitch/flow_netlink.c             |  24 +--
  net/openvswitch/flow_netlink.h             |   4 +-
  net/openvswitch/flow_table.c               | 100 ++++++------
  net/openvswitch/flow_table.h               |  18 +--
  net/openvswitch/vport-gre.c                |   4 +-
  net/openvswitch/vport-internal_switchdev.c | 179 ++++++++++++++++++++++
  net/openvswitch/vport-internal_switchdev.h |  28 ++++
  net/openvswitch/vport-netdev.c             |   4 +-
  net/openvswitch/vport-switchportdev.c      | 205 +++++++++++++++++++++++++
  net/openvswitch/vport-switchportdev.h      |  24 +++
  net/openvswitch/vport-vxlan.c              |   2 +-
  net/openvswitch/vport.c                    |   6 +-
  net/openvswitch/vport.h                    |   4 +-
  net/packet/af_packet.c                     |  22 ++-
  35 files changed, 1269 insertions(+), 222 deletions(-)

create mode 100644 drivers/net/dummyswitch.c
create mode 100644 include/linux/sw_flow.h
create mode 100644 include/linux/switchdev.h
create mode 100644 net/core/switchdev.c
create mode 100644 net/openvswitch/vport-internal_switchdev.c create mode 100644 net/openvswitch/vport-internal_switchdev.h create mode 100644 net/openvswitch/vport-switchportdev.c create mode 100644 net/openvswitch/vport-switchportdev.h

A message that is not in the archive (sent off-list or not yet received): 53334A3F.6020105-jkUAjuhPggJWk0Htik3J/[email protected]

#6 lore raw

2014-03-26 14:44 GMT-07:00 Jamal Hadi Salim <jhs-jkUAjuhPggJWk0Htik3J/[email protected]>:

Quoted 7 lines

Jiri,

The flow extensions may be distracting - note there are many tables (L3, L2, etc) in such chips not just ACLs. And there's likely no OneWay(tm) to add a flow. My view is probably to solve or reach an agreement on the ports. Then resolve the different tables control/data exposure.

Agreed.

Quoted 5 lines

On the switchdev - You are still exposing it; do you expect these things to be created from user space? Probably thats one approach, but I would suspect the majority would result in the driver itself creating these devices after discovering the resources from the control interfaces (PCIE etc).

It seems to me like, minus the strong MDIO dependency, DSA is probably the closest and most ready piece of software we have in the kernel to start building Ethernet switch port net_device as it already contains pretty much everything we want:

- per-port ethtool operations
- per-port xmit/rcv handlers
- existing drivers

The missing bits are roughly:

- adding IFF_SWITCH_PORT flags to the slave net_device created
- creating the switch master net_device: sw1
- creating the Switch CPU port net_device: sw1p<N>

Quoted 127 lines

cheers,
jamal

Quoted 119 lines · Jiri Pirko

This is second version of RFC. Here are the main differences from the first one:
-There is no special swdev of swport structure. The switch and its ports are
now represented only by net_device structures. There are couple of
switch-specific
ndos added (inserting and removing flows).

-Regarding the flows, driver marks skb with "missing flow" flag now. That would
give indication to a user (OVS datapath of af_packet userspace
application).
On the opposite direction, skb can be xmitted by a port.

-dummyswitch module has now rtnetlink iface for easy creation of dummy switches
and ports.

The basic idea is to introduce a generic infractructure to support various switch chips in kernel. Also the idea is to benefit of currently existing Open vSwitch userspace infrastructure.

The first two patches are just minor skb flag and packet_type modifications.

The third patch does a split of structures which are not specific to OVS into more generic ones that can be reused.

The fourth patch introduces the "switchdev" API itself. It should serve as a glue between chip drivers on the one side and the user on the other. That user might be OVS datapath but in future it might be just userspace application interacting via af_packet and Netlink iface.

The infrastructure is designed to be similar to for example linux bridge. There is one netdevice representing a switch chip and one netdevice per every
port. These are bound together in classic slave-master way. The reason to reuse the netdevices for port representation is that userspace can use standard tools to get information about the ports, statistics, tcpdump, etc.

Note that the netdevices are just representations of the ports in the switch.
Therefore **no actual data** goes though, only missed flow skbs and, if drivers
supports it, when ETH_P_ALL packet_type is hooked on (tcpdump).

The fifth patch introduces a support for switchdev vports into OVS datapath.
After that, userspace would be able to create a switchdev DP for a switch chip,
to add switchdev ports to it and to use it in the same way as it would be OVS SW datapath.

The sixth patch adds a dummy switch module. It is just an example of switchdev driver implementation.

Jiri Pirko (6):
net: make packet_type->ak_packet_priv generic
skbuff: add "missed_flow" flag
openvswitch: split flow structures into ovs specific and generic ones
net: introduce switchdev API
openvswitch: Introduce support for switchdev based datapath
net: introduce dummy switch

  drivers/net/Kconfig                        |   7 +
  drivers/net/Makefile                       |   1 +
  drivers/net/dummyswitch.c                  | 235
+++++++++++++++++++++++++++++
  include/linux/filter.h                     |   1 +
  include/linux/netdevice.h                  |  26 +++-
  include/linux/skbuff.h                     |  13 ++
  include/linux/sw_flow.h                    | 105 +++++++++++++
  include/linux/switchdev.h                  |  30 ++++
  include/uapi/linux/if_link.h               |   9 ++
  include/uapi/linux/openvswitch.h           |   4 +
  net/Kconfig                                |  10 ++
  net/core/Makefile                          |   1 +
  net/core/dev.c                             |   4 +-
  net/core/filter.c                          |   3 +
  net/core/switchdev.c                       | 172 +++++++++++++++++++++
  net/openvswitch/Makefile                   |   4 +
  net/openvswitch/datapath.c                 |  90 +++++++----
  net/openvswitch/datapath.h                 |  12 +-
  net/openvswitch/dp_notify.c                |   3 +-
  net/openvswitch/flow.c                     |  14 +-
  net/openvswitch/flow.h                     | 123 +++------------
  net/openvswitch/flow_netlink.c             |  24 +--
  net/openvswitch/flow_netlink.h             |   4 +-
  net/openvswitch/flow_table.c               | 100 ++++++------
  net/openvswitch/flow_table.h               |  18 +--
  net/openvswitch/vport-gre.c                |   4 +-
  net/openvswitch/vport-internal_switchdev.c | 179 ++++++++++++++++++++++
  net/openvswitch/vport-internal_switchdev.h |  28 ++++
  net/openvswitch/vport-netdev.c             |   4 +-
  net/openvswitch/vport-switchportdev.c      | 205
+++++++++++++++++++++++++
  net/openvswitch/vport-switchportdev.h      |  24 +++
  net/openvswitch/vport-vxlan.c              |   2 +-
  net/openvswitch/vport.c                    |   6 +-
  net/openvswitch/vport.h                    |   4 +-
  net/packet/af_packet.c                     |  22 ++-
  35 files changed, 1269 insertions(+), 222 deletions(-)

create mode 100644 drivers/net/dummyswitch.c
create mode 100644 include/linux/sw_flow.h
create mode 100644 include/linux/switchdev.h
create mode 100644 net/core/switchdev.c
create mode 100644 net/openvswitch/vport-internal_switchdev.c create mode 100644 net/openvswitch/vport-internal_switchdev.h create mode 100644 net/openvswitch/vport-switchportdev.c create mode 100644 net/openvswitch/vport-switchportdev.h

Signature · 1 line
Florian

A message that is not in the archive (sent off-list or not yet received): CAGVrzcaOph7=2WfMzTfqtwFkN1fu5uKJAH59aF7mqD4MwL7iOg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw
Quoted 26 lines · Wed, Mar 26, 2014 at 10:57:09PM CET, [email protected]…

2014-03-26 14:44 GMT-07:00 Jamal Hadi Salim <jhs-jkUAjuhPggJWk0Htik3J/[email protected]>:

Quoted 7 lines

Jiri,

The flow extensions may be distracting - note there are many tables (L3, L2, etc) in such chips not just ACLs. And there's likely no OneWay(tm) to add a flow. My view is probably to solve or reach an agreement on the ports. Then resolve the different tables control/data exposure.

Agreed.

Quoted 5 lines

On the switchdev - You are still exposing it; do you expect these things to be created from user space? Probably thats one approach, but I would suspect the majority would result in the driver itself creating these devices after discovering the resources from the control interfaces (PCIE etc).

It seems to me like, minus the strong MDIO dependency, DSA is probably the closest and most ready piece of software we have in the kernel to start building Ethernet switch port net_device as it already contains pretty much everything we want:

- per-port ethtool operations
- per-port xmit/rcv handlers
- existing drivers

Quoted 5 lines

The missing bits are roughly:

- adding IFF_SWITCH_PORT flags to the slave net_device created
- creating the switch master net_device: sw1
- creating the Switch CPU port net_device: sw1p<N>

Yep. DSA should be fairly easy to modify to use switchdev api.

Quoted 133 lines
Quoted 128 lines

cheers,
jamal

Quoted 119 lines · Jiri Pirko

This is second version of RFC. Here are the main differences from the first one:
-There is no special swdev of swport structure. The switch and its ports are
now represented only by net_device structures. There are couple of
switch-specific
ndos added (inserting and removing flows).

-Regarding the flows, driver marks skb with "missing flow" flag now. That would
give indication to a user (OVS datapath of af_packet userspace
application).
On the opposite direction, skb can be xmitted by a port.

-dummyswitch module has now rtnetlink iface for easy creation of dummy switches
and ports.

The basic idea is to introduce a generic infractructure to support various switch chips in kernel. Also the idea is to benefit of currently existing Open vSwitch userspace infrastructure.

The first two patches are just minor skb flag and packet_type modifications.

The third patch does a split of structures which are not specific to OVS into more generic ones that can be reused.

The fourth patch introduces the "switchdev" API itself. It should serve as a glue between chip drivers on the one side and the user on the other. That user might be OVS datapath but in future it might be just userspace application interacting via af_packet and Netlink iface.

The infrastructure is designed to be similar to for example linux bridge. There is one netdevice representing a switch chip and one netdevice per every
port. These are bound together in classic slave-master way. The reason to reuse the netdevices for port representation is that userspace can use standard tools to get information about the ports, statistics, tcpdump, etc.

Note that the netdevices are just representations of the ports in the switch.
Therefore **no actual data** goes though, only missed flow skbs and, if drivers
supports it, when ETH_P_ALL packet_type is hooked on (tcpdump).

The fifth patch introduces a support for switchdev vports into OVS datapath.
After that, userspace would be able to create a switchdev DP for a switch chip,
to add switchdev ports to it and to use it in the same way as it would be OVS SW datapath.

The sixth patch adds a dummy switch module. It is just an example of switchdev driver implementation.

Jiri Pirko (6):
net: make packet_type->ak_packet_priv generic
skbuff: add "missed_flow" flag
openvswitch: split flow structures into ovs specific and generic ones
net: introduce switchdev API
openvswitch: Introduce support for switchdev based datapath
net: introduce dummy switch

  drivers/net/Kconfig                        |   7 +
  drivers/net/Makefile                       |   1 +
  drivers/net/dummyswitch.c                  | 235
+++++++++++++++++++++++++++++
  include/linux/filter.h                     |   1 +
  include/linux/netdevice.h                  |  26 +++-
  include/linux/skbuff.h                     |  13 ++
  include/linux/sw_flow.h                    | 105 +++++++++++++
  include/linux/switchdev.h                  |  30 ++++
  include/uapi/linux/if_link.h               |   9 ++
  include/uapi/linux/openvswitch.h           |   4 +
  net/Kconfig                                |  10 ++
  net/core/Makefile                          |   1 +
  net/core/dev.c                             |   4 +-
  net/core/filter.c                          |   3 +
  net/core/switchdev.c                       | 172 +++++++++++++++++++++
  net/openvswitch/Makefile                   |   4 +
  net/openvswitch/datapath.c                 |  90 +++++++----
  net/openvswitch/datapath.h                 |  12 +-
  net/openvswitch/dp_notify.c                |   3 +-
  net/openvswitch/flow.c                     |  14 +-
  net/openvswitch/flow.h                     | 123 +++------------
  net/openvswitch/flow_netlink.c             |  24 +--
  net/openvswitch/flow_netlink.h             |   4 +-
  net/openvswitch/flow_table.c               | 100 ++++++------
  net/openvswitch/flow_table.h               |  18 +--
  net/openvswitch/vport-gre.c                |   4 +-
  net/openvswitch/vport-internal_switchdev.c | 179 ++++++++++++++++++++++
  net/openvswitch/vport-internal_switchdev.h |  28 ++++
  net/openvswitch/vport-netdev.c             |   4 +-
  net/openvswitch/vport-switchportdev.c      | 205
+++++++++++++++++++++++++
  net/openvswitch/vport-switchportdev.h      |  24 +++
  net/openvswitch/vport-vxlan.c              |   2 +-
  net/openvswitch/vport.c                    |   6 +-
  net/openvswitch/vport.h                    |   4 +-
  net/packet/af_packet.c                     |  22 ++-
  35 files changed, 1269 insertions(+), 222 deletions(-)

create mode 100644 drivers/net/dummyswitch.c
create mode 100644 include/linux/sw_flow.h
create mode 100644 include/linux/switchdev.h
create mode 100644 net/core/switchdev.c
create mode 100644 net/openvswitch/vport-internal_switchdev.c create mode 100644 net/openvswitch/vport-internal_switchdev.h create mode 100644 net/openvswitch/vport-switchportdev.c create mode 100644 net/openvswitch/vport-switchportdev.h

Signature · 1 line
Florian
#9 lore raw
In reply to a message not in the archive
Quoted 7 lines · Wed, Mar 26, 2014 at 10:44:31PM CET, jhs-jkUAjuhPggJWk0Htik3J/[email protected]…

Jiri,

The flow extensions may be distracting - note there are many tables (L3, L2, etc) in such chips not just ACLs. And there's likely no OneWay(tm) to add a flow. My view is probably to solve or reach an agreement on the ports. Then resolve the different tables control/data exposure.

Well, I think there are 2 main models to be considered:
1. OSV-like model, where everything is flows and that is the OneWay(tm) mode you mentioned :)
2. clasic switch setting-like model where you manually set up vlans, lag, whatever.

The phase one for me is 1. and that is what I'm trying to resolve with this patchset.

Quoted 1 line

From what I understand from the discussion, 2. is likely the model you

have in mind.

Quoted 5 lines

On the switchdev - You are still exposing it; do you expect these things to be created from user space? Probably thats one approach, but I would suspect the majority would result in the driver itself creating these devices after discovering the resources from the control interfaces (PCIE etc).

Sorry, I'm not sure I follow you question correctly.
The driver should create and register the switch and switch ports itself.

Quoted 110 lines

cheers,
jamal

Quoted 103 lines · Jiri Pirko

This is second version of RFC. Here are the main differences from the first one:

(quoted diff) +0 -3
-There is no special swdev of swport structure. The switch and its ports are
 now represented only by net_device structures. There are couple of switch-specific
 ndos added (inserting and removing flows).
 
-Regarding the flows, driver marks skb with "missing flow" flag now. That would
 give indication to a user (OVS datapath of af_packet userspace application).
 On the opposite direction, skb can be xmitted by a port.
 
-dummyswitch module has now rtnetlink iface for easy creation of dummy switches
 and ports.

The basic idea is to introduce a generic infractructure to support various switch chips in kernel. Also the idea is to benefit of currently existing Open vSwitch userspace infrastructure.

The first two patches are just minor skb flag and packet_type modifications.

The third patch does a split of structures which are not specific to OVS into more generic ones that can be reused.

The fourth patch introduces the "switchdev" API itself. It should serve as a glue between chip drivers on the one side and the user on the other. That user might be OVS datapath but in future it might be just userspace application interacting via af_packet and Netlink iface.

The infrastructure is designed to be similar to for example linux bridge. There is one netdevice representing a switch chip and one netdevice per every port. These are bound together in classic slave-master way. The reason to reuse the netdevices for port representation is that userspace can use standard tools to get information about the ports, statistics, tcpdump, etc.

Note that the netdevices are just representations of the ports in the switch. Therefore **no actual data** goes though, only missed flow skbs and, if drivers supports it, when ETH_P_ALL packet_type is hooked on (tcpdump).

The fifth patch introduces a support for switchdev vports into OVS datapath. After that, userspace would be able to create a switchdev DP for a switch chip, to add switchdev ports to it and to use it in the same way as it would be OVS SW datapath.

The sixth patch adds a dummy switch module. It is just an example of switchdev driver implementation.

Jiri Pirko (6):
net: make packet_type->ak_packet_priv generic
skbuff: add "missed_flow" flag
openvswitch: split flow structures into ovs specific and generic ones
net: introduce switchdev API
openvswitch: Introduce support for switchdev based datapath
net: introduce dummy switch

 drivers/net/Kconfig                        |   7 +
 drivers/net/Makefile                       |   1 +
 drivers/net/dummyswitch.c                  | 235 +++++++++++++++++++++++++++++
 include/linux/filter.h                     |   1 +
 include/linux/netdevice.h                  |  26 +++-
 include/linux/skbuff.h                     |  13 ++
 include/linux/sw_flow.h                    | 105 +++++++++++++
 include/linux/switchdev.h                  |  30 ++++
 include/uapi/linux/if_link.h               |   9 ++
 include/uapi/linux/openvswitch.h           |   4 +
 net/Kconfig                                |  10 ++
 net/core/Makefile                          |   1 +
 net/core/dev.c                             |   4 +-
 net/core/filter.c                          |   3 +
 net/core/switchdev.c                       | 172 +++++++++++++++++++++
 net/openvswitch/Makefile                   |   4 +
 net/openvswitch/datapath.c                 |  90 +++++++----
 net/openvswitch/datapath.h                 |  12 +-
 net/openvswitch/dp_notify.c                |   3 +-
 net/openvswitch/flow.c                     |  14 +-
 net/openvswitch/flow.h                     | 123 +++------------
 net/openvswitch/flow_netlink.c             |  24 +--
 net/openvswitch/flow_netlink.h             |   4 +-
 net/openvswitch/flow_table.c               | 100 ++++++------
 net/openvswitch/flow_table.h               |  18 +--
 net/openvswitch/vport-gre.c                |   4 +-
 net/openvswitch/vport-internal_switchdev.c | 179 ++++++++++++++++++++++
 net/openvswitch/vport-internal_switchdev.h |  28 ++++
 net/openvswitch/vport-netdev.c             |   4 +-
 net/openvswitch/vport-switchportdev.c      | 205 +++++++++++++++++++++++++
 net/openvswitch/vport-switchportdev.h      |  24 +++
 net/openvswitch/vport-vxlan.c              |   2 +-
 net/openvswitch/vport.c                    |   6 +-
 net/openvswitch/vport.h                    |   4 +-
 net/packet/af_packet.c                     |  22 ++-
 35 files changed, 1269 insertions(+), 222 deletions(-)
 create mode 100644 drivers/net/dummyswitch.c
 create mode 100644 include/linux/sw_flow.h
 create mode 100644 include/linux/switchdev.h
 create mode 100644 net/core/switchdev.c
 create mode 100644 net/openvswitch/vport-internal_switchdev.c
 create mode 100644 net/openvswitch/vport-internal_switchdev.h
 create mode 100644 net/openvswitch/vport-switchportdev.c
 create mode 100644 net/openvswitch/vport-switchportdev.h

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw
Quoted 8 lines · Jiri Pirko

Wed, Mar 26, 2014 at 10:44:31PM CET, jhs-jkUAjuhPggJWk0Htik3J/[email protected] wrote:

Well, I think there are 2 main models to be considered:
1. OSV-like model, where everything is flows and that is the OneWay(tm) mode you mentioned :)
2. clasic switch setting-like model where you manually set up vlans, lag, whatever.

Quoted 6 lines

The phase one for me is 1. and that is what I'm trying to resolve with this patchset.

From what I understand from the discussion, 2. is likely the model you
have in mind.

In my opinion there is no difference when setting the ACL table(s). We are going to need your .ndo for more than flows. Something in the stack is going to have to talk to those .ndo interfaces (I keep bringing up the concept of routing code for example). What i meant by no OneWay is i think it will depend on the chip - some will require more work than other. I do believe it is a longer discussion needed than the port resolving.

cheers,
jamal

#12 lore raw
Quoted 16 lines · Jamal Hadi Salim
Quoted 8 lines · Jiri Pirko

Wed, Mar 26, 2014 at 10:44:31PM CET, [email protected] wrote:

Well, I think there are 2 main models to be considered:
1. OSV-like model, where everything is flows and that is the OneWay(tm) mode you mentioned :)
2. clasic switch setting-like model where you manually set up vlans, lag, whatever.

Quoted 6 lines

The phase one for me is 1. and that is what I'm trying to resolve with this patchset.

From what I understand from the discussion, 2. is likely the model you have in mind.

Quoted 7 lines

In my opinion there is no difference when setting the ACL table(s). We are going to need your .ndo for more than flows. Something in the stack is going to have to talk to those .ndo interfaces (I keep bringing up the concept of routing code for example). What i meant by no OneWay is i think it will depend on the chip - some will require more work than other. I do believe it is a longer discussion needed than the port resolving.

There is definitely need beyond an ndo that is capable of adding flows. You mention routes. Another example would be devices capable of offloading iptables & nft rules.

But wouldn't you want to introduce an additional ndo to cover these?

What speaks against going with what Jiri proposes and adjust & extend as needed as we go along?

#13 lore raw
Quoted 6 lines · Thomas Graf

On 03/27/14 at 06:27am, Jamal Hadi Salim wrote:

There is definitely need beyond an ndo that is capable of adding flows. You mention routes. Another example would be devices capable of offloading iptables & nft rules.

nod.

Quoted 2 lines

But wouldn't you want to introduce an additional ndo to cover these?

We could - I just find it distracting at the current thread of discussion (the openwrt folks for example dont need any or most of that).

Quoted 3 lines

What speaks against going with what Jiri proposes and adjust & extend as needed as we go along?

I was hoping we knock these issue one at a time. The noise right now is around ports and stacking of ports etc. Which in my opinion is an easier topic to handle.
Jiri's patches on this can always come back in the discussion later.

cheers,
jamal

A message that is not in the archive (sent off-list or not yet received): 533408C0.8000608-jkUAjuhPggJWk0Htik3J/[email protected]

#15 lore raw
Quoted 12 lines · Jamal Hadi Salim
Quoted 2 lines · Thomas Graf

But wouldn't you want to introduce an additional ndo to cover these?

We could - I just find it distracting at the current thread of discussion (the openwrt folks for example dont need any or most of that).

Quoted 3 lines

What speaks against going with what Jiri proposes and adjust & extend as needed as we go along?

Quoted 5 lines

I was hoping we knock these issue one at a time. The noise right now is around ports and stacking of ports etc. Which in my opinion is an easier topic to handle.
Jiri's patches on this can always come back in the discussion later.

It seems like we reached pretty good consensus on the model. What remaining issues do you see with the port model proposed in v2?

#16 lore raw
Quoted 3 lines · Thomas Graf

It seems like we reached pretty good consensus on the model. What remaining issues do you see with the port model proposed in v2?

Are we really following the same thread?
I dont see any rallying behind Jiri's approach from the other folks who have their own code and way of approaching things. I am hoping we dont continue with the split that is there already.

cheers,
jamal

author
#17 lore raw
Quoted 11 lines · Thu, Mar 27, 2014 at 01:32:35PM CET, [email protected] wrote:
Quoted 3 lines · Thomas Graf

It seems like we reached pretty good consensus on the model. What remaining issues do you see with the port model proposed in v2?

Are we really following the same thread?
I dont see any rallying behind Jiri's approach from the other folks who have their own code and way of approaching things. I am hoping we dont continue with the split that is there already.

It is not a split. It is just a completion of a model. Adding missing parts. At least I see it that way.

Quoted 3 lines

cheers,
jamal

A message that is not in the archive (sent off-list or not yet received): [email protected]

#19 lore raw
Quoted 7 lines · Jiri Pirko
Quoted 6 lines · Thu, Mar 27, 2014 at 01:32:35PM CET, jhs-jkUAjuhPggJWk0Htik3J/[email protected]…
Quoted 3 lines · Thomas Graf

It seems like we reached pretty good consensus on the model. What remaining issues do you see with the port model proposed in v2?

Quoted 8 lines
Quoted 5 lines

Are we really following the same thread?
I dont see any rallying behind Jiri's approach from the other folks who have their own code and way of approaching things. I am hoping we dont continue with the split that is there already.

It is not a split. It is just a completion of a model. Adding missing parts. At least I see it that way.

I probably wouldn't call it a 'split' either. But, I agree with Jamal that we are nowhere near consensus so far.

John

Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
#20 lore raw
In reply to Thomas Graf

2014-03-27 4:02 GMT-07:00 Thomas Graf <[email protected]>:

Quoted 25 lines · Jamal Hadi Salim
Quoted 16 lines · Jiri Pirko
Quoted 8 lines

Wed, Mar 26, 2014 at 10:44:31PM CET, [email protected] wrote:

Well, I think there are 2 main models to be considered:
1. OSV-like model, where everything is flows and that is the OneWay(tm) mode you mentioned :)
2. clasic switch setting-like model where you manually set up vlans, lag, whatever.

Quoted 6 lines

The phase one for me is 1. and that is what I'm trying to resolve with this patchset.

From what I understand from the discussion, 2. is likely the model you have in mind.

Quoted 7 lines

In my opinion there is no difference when setting the ACL table(s). We are going to need your .ndo for more than flows. Something in the stack is going to have to talk to those .ndo interfaces (I keep bringing up the concept of routing code for example). What i meant by no OneWay is i think it will depend on the chip - some will require more work than other. I do believe it is a longer discussion needed than the port resolving.

Quoted 3 lines

There is definitely need beyond an ndo that is capable of adding flows. You mention routes. Another example would be devices capable of offloading iptables & nft rules.

Those devices usually require (at least for Broadcom) an entity identifying the flows and uploading flows offloading rules to the hardware. Although I do not think it hurts to keep those in mind to come up with the right design, my feeling is that they will require more intrusive modifications at the socket, route and forwarding path level if we want the Linux kernel to offer a consistent API across different hardware variations.

It is not clear to me at this point whether we want those special offloading devices to appear as separate net_device with specific flags to advertise their offloading features (NAT, IP routing...) or something else?

Quoted 3 lines

But wouldn't you want to introduce an additional ndo to cover these?

I would start with making sure everyone is on the same page regarding switches before we start building the conversation on NAT/IP-routing offloading, but it is good that you mention it.

Quoted 3 lines

What speaks against going with what Jiri proposes and adjust & extend as needed as we go along?

Signature · 1 line
Florian
#21 lore raw
Quoted 5 lines · Florian Fainelli

2014-03-27 4:02 GMT-07:00 Thomas Graf <[email protected]>:

Quoted 3 lines

There is definitely need beyond an ndo that is capable of adding flows. You mention routes. Another example would be devices capable of offloading iptables & nft rules.

Quoted 7 lines

Those devices usually require (at least for Broadcom) an entity identifying the flows and uploading flows offloading rules to the hardware. Although I do not think it hurts to keep those in mind to come up with the right design, my feeling is that they will require more intrusive modifications at the socket, route and forwarding path level if we want the Linux kernel to offer a consistent API across different hardware variations.

I absolutely agree. This is where the challenging bits start to appear ;-) I don't want to speak for Jiri but my understanding is that the flow focused approach early on is entirely because it is the easiest case to solve. Taking OVS as an example has the advantage of already being guarded by OpenFlow abstraction which by nature is very device oriented.

Quoted 4 lines

It is not clear to me at this point whether we want those special offloading devices to appear as separate net_device with specific flags to advertise their offloading features (NAT, IP routing...) or something else?

One lesson that could serve as an example which differs from TOE is the offloading provided by recent FC HBAs. The device looks like a regular SCSI device to the kernel but offers a full DCB engine to allow for FCoE. The DCB bits can and must be configured. By not representing that engine with a net_device we cannot configure the engine through the Netlink interface dcbnl. dcbnl can certainly be extended to allow taking a scsi id of some sort instead of a ifindex but it's far from ideal.

My take on this is that if it makes sense to use rtnl or ethtool to configure these offload engines then let's just go with a globally visible net_device and improve our capabilities system.

Quoted 6 lines
Quoted 2 lines

But wouldn't you want to introduce an additional ndo to cover these?

I would start with making sure everyone is on the same page regarding switches before we start building the conversation on NAT/IP-routing offloading, but it is good that you mention it.

Agreed

A message that is not in the archive (sent off-list or not yet received): 20140327172048.GC13573-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org

#23 lore raw
Quoted 14 lines · Thu, Mar 27, 2014 at 06:20:48PM CET, tgraf-G/[email protected] wrote:
Quoted 5 lines · Florian Fainelli

2014-03-27 4:02 GMT-07:00 Thomas Graf <tgraf-G/[email protected]>:

Quoted 3 lines

There is definitely need beyond an ndo that is capable of adding flows. You mention routes. Another example would be devices capable of offloading iptables & nft rules.

Quoted 7 lines

Those devices usually require (at least for Broadcom) an entity identifying the flows and uploading flows offloading rules to the hardware. Although I do not think it hurts to keep those in mind to come up with the right design, my feeling is that they will require more intrusive modifications at the socket, route and forwarding path level if we want the Linux kernel to offer a consistent API across different hardware variations.

Quoted 6 lines

I absolutely agree. This is where the challenging bits start to appear ;-) I don't want to speak for Jiri but my understanding is that the flow focused approach early on is entirely because it is the easiest case to solve. Taking OVS as an example has the advantage of already being guarded by OpenFlow abstraction which by nature is very device oriented.

Yep, exactly.

Quoted 27 lines
Quoted 5 lines

It is not clear to me at this point whether we want those special offloading devices to appear as separate net_device with specific flags to advertise their offloading features (NAT, IP routing...) or something else?

One lesson that could serve as an example which differs from TOE is the offloading provided by recent FC HBAs. The device looks like a regular SCSI device to the kernel but offers a full DCB engine to allow for FCoE. The DCB bits can and must be configured. By not representing that engine with a net_device we cannot configure the engine through the Netlink interface dcbnl. dcbnl can certainly be extended to allow taking a scsi id of some sort instead of a ifindex but it's far from ideal.

My take on this is that if it makes sense to use rtnl or ethtool to configure these offload engines then let's just go with a globally visible net_device and improve our capabilities system.

Quoted 6 lines
Quoted 2 lines

But wouldn't you want to introduce an additional ndo to cover these?

I would start with making sure everyone is on the same page regarding switches before we start building the conversation on NAT/IP-routing offloading, but it is good that you mention it.

Agreed

author
#24 lore raw

RFC PATCH v2 1/6 net: make packet_type->ak_packet_priv generic

In reply to Jiri Pirko

The priv is used now by af_packet. Rename it to make it useable for others as well. Also, introduce packet_id_match to move the sk matching from skb_loop_sk to af_packet code where it belongs.

---
 include/linux/netdevice.h |  2 +-
 net/core/dev.c            |  4 +---
 net/packet/af_packet.c    | 22 +++++++++++++++-------
 3 files changed, 17 insertions(+), 11 deletions(-)
include/linux/netdevice.h +1 -1
index 4b6d12c..6b70e6f 100644
@@ -1777,7 +1777,7 @@ struct packet_type {
 					 struct net_device *);
 	bool			(*id_match)(struct packet_type *ptype,
 					    struct sock *sk);
-	void			*af_packet_priv;
+	void			*priv;
 	struct list_head	list;
 };
 
net/core/dev.c +1 -3
index 55f8e64..61ce72d 100644
@@ -1719,13 +1719,11 @@ static inline int deliver_skb(struct sk_buff *skb,
 
 static inline bool skb_loop_sk(struct packet_type *ptype, struct sk_buff *skb)
 {
-	if (!ptype->af_packet_priv || !skb->sk)
+	if (!ptype->priv || !skb->sk)
 		return false;
 
 	if (ptype->id_match)
 		return ptype->id_match(ptype, skb->sk);
-	else if ((struct sock *)ptype->af_packet_priv == skb->sk)
-		return true;
 
 	return false;
 }
net/packet/af_packet.c +15 -7
index 2923044..a36ac08 100644
@@ -1343,7 +1343,7 @@ static bool fanout_has_flag(struct packet_fanout *f, u16 flag)
 static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
 			     struct packet_type *pt, struct net_device *orig_dev)
 {
-	struct packet_fanout *f = pt->af_packet_priv;
+	struct packet_fanout *f = pt->priv;
 	unsigned int num = f->num_members;
 	struct packet_sock *po;
 	unsigned int idx;
@@ -1425,7 +1425,7 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po)
 
 static bool match_fanout_group(struct packet_type *ptype, struct sock *sk)
 {
-	if (ptype->af_packet_priv == (void *)((struct packet_sock *)sk)->fanout)
+	if (ptype->priv == (void *)((struct packet_sock *)sk)->fanout)
 		return true;
 
 	return false;
@@ -1487,7 +1487,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
 		match->prot_hook.type = po->prot_hook.type;
 		match->prot_hook.dev = po->prot_hook.dev;
 		match->prot_hook.func = packet_rcv_fanout;
-		match->prot_hook.af_packet_priv = match;
+		match->prot_hook.priv = match;
 		match->prot_hook.id_match = match_fanout_group;
 		dev_add_pack(&match->prot_hook);
 		list_add(&match->list, &fanout_list);
@@ -1545,7 +1545,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
 	 *	field for just this event.
 	 */
 
-	sk = pt->af_packet_priv;
+	sk = pt->priv;
 
 	/*
 	 *	Yank back the headers [hope the device set this
@@ -1768,7 +1768,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
 	if (skb->pkt_type == PACKET_LOOPBACK)
 		goto drop;
 
-	sk = pt->af_packet_priv;
+	sk = pt->priv;
 	po = pkt_sk(sk);
 
 	if (!net_eq(dev_net(dev), sock_net(sk)))
@@ -1893,7 +1893,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
 	if (skb->pkt_type == PACKET_LOOPBACK)
 		goto drop;
 
-	sk = pt->af_packet_priv;
+	sk = pt->priv;
 	po = pkt_sk(sk);
 
 	if (!net_eq(dev_net(dev), sock_net(sk)))
@@ -2768,6 +2768,13 @@ static struct proto packet_proto = {
 	.obj_size = sizeof(struct packet_sock),
 };
 
+static bool packet_id_match(struct packet_type *ptype, struct sock *sk)
+{
+	if ((struct sock *) ptype->priv == sk)
+		return true;
+	return false;
+}
+
 /*
  *	Create a packet of type SOCK_PACKET.
  */
@@ -2824,7 +2831,8 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
 	if (sock->type == SOCK_PACKET)
 		po->prot_hook.func = packet_rcv_spkt;
 
-	po->prot_hook.af_packet_priv = sk;
+	po->prot_hook.id_match = packet_id_match,
+	po->prot_hook.priv = sk;
 
 	if (proto) {
 		po->prot_hook.type = proto;
Signature · 1 line
1.8.5.3
author
#25 lore raw

RFC PATCH v2 2/6 skbuff: add "missed_flow" flag

In reply to Jiri Pirko

This flag sets incoming switch device in order to let know that the flow which the skb is part of is missed. Listener may react to it appropriately,

---
 include/linux/filter.h |  1 +
 include/linux/skbuff.h | 13 +++++++++++++
 net/core/filter.c      |  3 +++
 3 files changed, 17 insertions(+)
include/linux/filter.h +1 -0
index e568c8e..38c7c04 100644
@@ -154,6 +154,7 @@ enum {
 	BPF_S_ANC_VLAN_TAG,
 	BPF_S_ANC_VLAN_TAG_PRESENT,
 	BPF_S_ANC_PAY_OFFSET,
+	BPF_S_ANC_MISSED_FLOW,
 };
 
 #endif /* __LINUX_FILTER_H__ */
include/linux/skbuff.h +13 -0
index 03db95a..0100c2f 100644
@@ -567,6 +567,7 @@ struct sk_buff {
 	 * headers if needed
 	 */
 	__u8			encapsulation:1;
+	__u8			missed_flow:1;
 	/* 6/8 bit hole (depending on ndisc_nodetype presence) */
 	kmemcheck_bitfield_end(flags2);
 
@@ -2993,5 +2994,17 @@ static inline unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
 			       skb_network_header(skb);
 	return hdr_len + skb_gso_transport_seglen(skb);
 }
+
+/**
+ * skb_mark_missed_flow - marks skb as a part of missed flow
+ * @skb: buffer
+ *
+ * Marks skb as a part of missed flow.
+ */
+static inline void skb_mark_missed_flow(struct sk_buff *skb)
+{
+	skb->missed_flow = 1;
+}
+
 #endif	/* __KERNEL__ */
 #endif	/* _LINUX_SKBUFF_H */
net/core/filter.c +3 -0
index ad30d62..048f11a 100644
@@ -350,6 +350,9 @@ load_b:
 		case BPF_S_ANC_PAY_OFFSET:
 			A = __skb_get_poff(skb);
 			continue;
+		case BPF_S_ANC_MISSED_FLOW:
+			A = !!skb->missed_flow;
+			continue;
 		case BPF_S_ANC_NLATTR: {
 			struct nlattr *nla;
 
Signature · 1 line
1.8.5.3

A message that is not in the archive (sent off-list or not yet received): 1395851472-10524-3-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org

#27 lore raw

Re: [patch net-next RFC v2 2/6] skbuff: add "missed_flow" flag

Quoted 16 lines · Jiri Pirko

This flag sets incoming switch device in order to let know that the flow which the skb is part of is missed. Listener may react to it appropriately,

---
 include/linux/filter.h |  1 +
 include/linux/skbuff.h | 13 +++++++++++++
 net/core/filter.c      |  3 +++
 3 files changed, 17 insertions(+)
include/linux/filter.h +0 -0
index e568c8e..38c7c04 100644

include/linux/filter.h enum { · line 157

Quoted 4 lines
include/linux/filter.h +1 -0
@@ -154,6 +154,7 @@ enum {
        BPF_S_ANC_VLAN_TAG,
        BPF_S_ANC_VLAN_TAG_PRESENT,
        BPF_S_ANC_PAY_OFFSET,
+       BPF_S_ANC_MISSED_FLOW,

Interesting use case for bpf...
looks like it's not connected to userspace.
Are you trying to extend ovs with switchdev api and bpf at once? How do you plan to use this bpf extension?

Thanks
Alexei

Quoted 54 lines
include/linux/filter.h +0 -0
 };
 
 #endif /* __LINUX_FILTER_H__ */
include/linux/skbuff.h +13 -0
index 03db95a..0100c2f 100644
@@ -567,6 +567,7 @@ struct sk_buff {
         * headers if needed
         */
        __u8                    encapsulation:1;
+       __u8                    missed_flow:1;
        /* 6/8 bit hole (depending on ndisc_nodetype presence) */
        kmemcheck_bitfield_end(flags2);
 
@@ -2993,5 +2994,17 @@ static inline unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
                               skb_network_header(skb);
        return hdr_len + skb_gso_transport_seglen(skb);
 }
+
+/**
+ * skb_mark_missed_flow - marks skb as a part of missed flow
+ * @skb: buffer
+ *
+ * Marks skb as a part of missed flow.
+ */
+static inline void skb_mark_missed_flow(struct sk_buff *skb)
+{
+       skb->missed_flow = 1;
+}
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SKBUFF_H */
net/core/filter.c +3 -1
index ad30d62..048f11a 100644
@@ -350,6 +350,9 @@ load_b:
                case BPF_S_ANC_PAY_OFFSET:
                        A = __skb_get_poff(skb);
                        continue;
+               case BPF_S_ANC_MISSED_FLOW:
+                       A = !!skb->missed_flow;
+                       continue;
                case BPF_S_ANC_NLATTR: {
                        struct nlattr *nla;
 
--

1.8.5.3

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

author
#28 lore raw

Re: [ovs-dev] [patch net-next RFC v2 2/6] skbuff: add "missed_flow" flag

Quoted 12 lines · Wed, Mar 26, 2014 at 05:59:12PM CET, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

This flag sets incoming switch device in order to let know that the flow which the skb is part of is missed. Listener may react to it appropriately,

---
 include/linux/filter.h |  1 +
 include/linux/skbuff.h | 13 +++++++++++++
 net/core/filter.c      |  3 +++
 3 files changed, 17 insertions(+)
Quoted 14 lines

include/linux/filter.h enum { · line 157

Quoted 9 lines
include/linux/filter.h +1 -0
index e568c8e..38c7c04 100644
@@ -154,6 +154,7 @@ enum {
        BPF_S_ANC_VLAN_TAG,
        BPF_S_ANC_VLAN_TAG_PRESENT,
        BPF_S_ANC_PAY_OFFSET,
+       BPF_S_ANC_MISSED_FLOW,

Interesting use case for bpf...
looks like it's not connected to userspace.
Are you trying to extend ovs with switchdev api and bpf at once? How do you plan to use this bpf extension?

The motive fot this is to provides a user (userspace app) possibility to get all skbs which were "flow-missed". He can adjust the filter so that only these can get through.

Quoted 58 lines

Thanks
Alexei

Quoted 54 lines
include/linux/filter.h +0 -0
 };
 
 #endif /* __LINUX_FILTER_H__ */
include/linux/skbuff.h +13 -0
index 03db95a..0100c2f 100644
@@ -567,6 +567,7 @@ struct sk_buff {
         * headers if needed
         */
        __u8                    encapsulation:1;
+       __u8                    missed_flow:1;
        /* 6/8 bit hole (depending on ndisc_nodetype presence) */
        kmemcheck_bitfield_end(flags2);
 
@@ -2993,5 +2994,17 @@ static inline unsigned int skb_gso_network_seglen(const struct sk_buff *skb)
                               skb_network_header(skb);
        return hdr_len + skb_gso_transport_seglen(skb);
 }
+
+/**
+ * skb_mark_missed_flow - marks skb as a part of missed flow
+ * @skb: buffer
+ *
+ * Marks skb as a part of missed flow.
+ */
+static inline void skb_mark_missed_flow(struct sk_buff *skb)
+{
+       skb->missed_flow = 1;
+}
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SKBUFF_H */
net/core/filter.c +3 -1
index ad30d62..048f11a 100644
@@ -350,6 +350,9 @@ load_b:
                case BPF_S_ANC_PAY_OFFSET:
                        A = __skb_get_poff(skb);
                        continue;
+               case BPF_S_ANC_MISSED_FLOW:
+                       A = !!skb->missed_flow;
+                       continue;
                case BPF_S_ANC_NLATTR: {
                        struct nlattr *nla;
 
--

1.8.5.3

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

#29 lore raw

Re: [patch net-next RFC v2 2/6] skbuff: add "missed_flow" flag

In reply to a message not in the archive
Quoted 28 lines · Jiri Pirko

This flag sets incoming switch device in order to let know that the flow which the skb is part of is missed. Listener may react to it appropriately,

---
  include/linux/filter.h |  1 +
  include/linux/skbuff.h | 13 +++++++++++++
  net/core/filter.c      |  3 +++
  3 files changed, 17 insertions(+)
include/linux/filter.h +1 -0
index e568c8e..38c7c04 100644
@@ -154,6 +154,7 @@ enum {
  	BPF_S_ANC_VLAN_TAG,
  	BPF_S_ANC_VLAN_TAG_PRESENT,
  	BPF_S_ANC_PAY_OFFSET,
+	BPF_S_ANC_MISSED_FLOW,
  };
 
  #endif /* __LINUX_FILTER_H__ */
include/linux/skbuff.h +0 -0
index 03db95a..0100c2f 100644

include/linux/skbuff.h struct sk_buff { · line 571

Quoted 5 lines
include/linux/skbuff.h +1 -0
@@ -567,6 +567,7 @@ struct sk_buff {
  	 * headers if needed
  	 */
  	__u8			encapsulation:1;
+	__u8			missed_flow:1;
  	/* 6/8 bit hole (depending on ndisc_nodetype presence) */

Please fix also the comment.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#31 lore raw

Re: [patch net-next RFC v2 2/6] skbuff: add "missed_flow" flag

Quoted 23 lines · Thu, Mar 27, 2014 at 11:31:42AM CET, nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@pub…
Quoted 22 lines · Jiri Pirko

This flag sets incoming switch device in order to let know that the flow which the skb is part of is missed. Listener may react to it appropriately,

---
 include/linux/filter.h |  1 +
 include/linux/skbuff.h | 13 +++++++++++++
 net/core/filter.c      |  3 +++
 3 files changed, 17 insertions(+)
include/linux/filter.h +1 -0
index e568c8e..38c7c04 100644
@@ -154,6 +154,7 @@ enum {
 	BPF_S_ANC_VLAN_TAG,
 	BPF_S_ANC_VLAN_TAG_PRESENT,
 	BPF_S_ANC_PAY_OFFSET,
+	BPF_S_ANC_MISSED_FLOW,
 };
 
Quoted 12 lines

include/linux/skbuff.h struct sk_buff { · line 571

Quoted 11 lines
include/linux/filter.h +0 -0
 #endif /* __LINUX_FILTER_H__ */
include/linux/skbuff.h +1 -0
index 03db95a..0100c2f 100644
@@ -567,6 +567,7 @@ struct sk_buff {
 	 * headers if needed
 	 */
 	__u8			encapsulation:1;
+	__u8			missed_flow:1;
 	/* 6/8 bit hole (depending on ndisc_nodetype presence) */

Please fix also the comment.

will do. Thanks.

#32 lore raw

Re: [patch net-next RFC v2 2/6] skbuff: add "missed_flow" flag

In reply to a message not in the archive

include/linux/skbuff.h struct sk_buff { · line 572

Quoted 11 lines
include/linux/skbuff.h +1 -0
index 03db95a..0100c2f 100644
@@ -567,6 +567,7 @@ struct sk_buff {
 	 * headers if needed
 	 */
 	__u8			encapsulation:1;
+	__u8			missed_flow:1;
 	/* 6/8 bit hole (depending on ndisc_nodetype presence) */
 	kmemcheck_bitfield_end(flags2);

Presumably you need to update the "6/8 bit hole" comment here.

Regards,
Neil

author
#33 lore raw

RFC PATCH v2 3/6 openvswitch: split flow structures into ovs specific and generic ones

In reply to Jiri Pirko

After this, flow related structures can be used in other code.

---
 include/linux/sw_flow.h        | 105 +++++++++++++++++++++++++++++++++++
 net/openvswitch/datapath.c     |  45 +++++++--------
 net/openvswitch/datapath.h     |   4 +-
 net/openvswitch/flow.c         |  14 ++---
 net/openvswitch/flow.h         | 123 +++++++++--------------------------------
 net/openvswitch/flow_netlink.c |  24 ++++----
 net/openvswitch/flow_netlink.h |   4 +-
 net/openvswitch/flow_table.c   | 100 +++++++++++++++++----------------
 net/openvswitch/flow_table.h   |  18 +++---
 net/openvswitch/vport-gre.c    |   4 +-
 net/openvswitch/vport-vxlan.c  |   2 +-
 net/openvswitch/vport.c        |   2 +-
 net/openvswitch/vport.h        |   2 +-
 13 files changed, 242 insertions(+), 205 deletions(-)
 create mode 100644 include/linux/sw_flow.h
include/linux/sw_flow.h new file +105 -0
new file mode 100644
index 0000000..e7b1ef9
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2007-2012 Nicira, Inc.
+ * Copyright (c) 2014 Jiri Pirko <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ */
+
+#ifndef _LINUX_SW_FLOW_H_
+#define _LINUX_SW_FLOW_H_
+
+struct sw_flow_key_ipv4_tunnel {
+	__be64 tun_id;
+	__be32 ipv4_src;
+	__be32 ipv4_dst;
+	__be16 tun_flags;
+	u8   ipv4_tos;
+	u8   ipv4_ttl;
+};
+
+struct sw_flow_key {
+	struct sw_flow_key_ipv4_tunnel tun_key;  /* Encapsulating tunnel key. */
+	struct {
+		u32	priority;	/* Packet QoS priority. */
+		u32	skb_mark;	/* SKB mark. */
+		u16	in_port;	/* Input switch port (or DP_MAX_PORTS). */
+	} phy;
+	struct {
+		u8     src[ETH_ALEN];	/* Ethernet source address. */
+		u8     dst[ETH_ALEN];	/* Ethernet destination address. */
+		__be16 tci;		/* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
+		__be16 type;		/* Ethernet frame type. */
+	} eth;
+	struct {
+		u8     proto;		/* IP protocol or lower 8 bits of ARP opcode. */
+		u8     tos;		/* IP ToS. */
+		u8     ttl;		/* IP TTL/hop limit. */
+		u8     frag;		/* One of OVS_FRAG_TYPE_*. */
+	} ip;
+	union {
+		struct {
+			struct {
+				__be32 src;	/* IP source address. */
+				__be32 dst;	/* IP destination address. */
+			} addr;
+			union {
+				struct {
+					__be16 src;		/* TCP/UDP/SCTP source port. */
+					__be16 dst;		/* TCP/UDP/SCTP destination port. */
+					__be16 flags;		/* TCP flags. */
+				} tp;
+				struct {
+					u8 sha[ETH_ALEN];	/* ARP source hardware address. */
+					u8 tha[ETH_ALEN];	/* ARP target hardware address. */
+				} arp;
+			};
+		} ipv4;
+		struct {
+			struct {
+				struct in6_addr src;	/* IPv6 source address. */
+				struct in6_addr dst;	/* IPv6 destination address. */
+			} addr;
+			__be32 label;			/* IPv6 flow label. */
+			struct {
+				__be16 src;		/* TCP/UDP/SCTP source port. */
+				__be16 dst;		/* TCP/UDP/SCTP destination port. */
+				__be16 flags;		/* TCP flags. */
+			} tp;
+			struct {
+				struct in6_addr target;	/* ND target address. */
+				u8 sll[ETH_ALEN];	/* ND source link layer address. */
+				u8 tll[ETH_ALEN];	/* ND target link layer address. */
+			} nd;
+		} ipv6;
+	};
+} __aligned(BITS_PER_LONG/8); /* Ensure that we can do comparisons as longs. */
+
+struct sw_flow_key_range {
+	unsigned short int start;
+	unsigned short int end;
+};
+
+struct sw_flow_mask {
+	struct sw_flow_key_range range;
+	struct sw_flow_key key;
+};
+
+struct sw_flow {
+	struct sw_flow_key key;
+	struct sw_flow_key unmasked_key;
+	struct sw_flow_mask *mask;
+};
+
+#endif /* _LINUX_SW_FLOW_H_ */
net/openvswitch/datapath.c +23 -22

143 lines not on this page · raw message

net/openvswitch/datapath.h +2 -2
index 0531738..5388cac 100644
@@ -100,9 +100,9 @@ struct datapath {
  * packet is not being tunneled.
  */
 struct ovs_skb_cb {
-	struct sw_flow		*flow;
+	struct ovs_flow		*flow;
 	struct sw_flow_key	*pkt_key;
-	struct ovs_key_ipv4_tunnel  *tun_key;
+	struct sw_flow_key_ipv4_tunnel  *tun_key;
 };
 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
 
net/openvswitch/flow.c +7 -7
index dda451f..e0c326a 100644
@@ -61,7 +61,7 @@ u64 ovs_flow_used_time(unsigned long flow_jiffies)
 
 #define TCP_FLAGS_BE16(tp) (*(__be16 *)&tcp_flag_word(tp) & htons(0x0FFF))
 
-void ovs_flow_stats_update(struct sw_flow *flow, struct sk_buff *skb)
+void ovs_flow_stats_update(struct ovs_flow *flow, struct sk_buff *skb)
 {
 	struct flow_stats *stats;
 	__be16 tcp_flags = 0;
@@ -71,10 +71,10 @@ void ovs_flow_stats_update(struct sw_flow *flow, struct sk_buff *skb)
 	else
 		stats = this_cpu_ptr(flow->stats.cpu_stats);
 
-	if ((flow->key.eth.type == htons(ETH_P_IP) ||
-	     flow->key.eth.type == htons(ETH_P_IPV6)) &&
-	    flow->key.ip.frag != OVS_FRAG_TYPE_LATER &&
-	    flow->key.ip.proto == IPPROTO_TCP &&
+	if ((flow->flow.key.eth.type == htons(ETH_P_IP) ||
+	     flow->flow.key.eth.type == htons(ETH_P_IPV6)) &&
+	    flow->flow.key.ip.frag != OVS_FRAG_TYPE_LATER &&
+	    flow->flow.key.ip.proto == IPPROTO_TCP &&
 	    likely(skb->len >= skb_transport_offset(skb) + sizeof(struct tcphdr))) {
 		tcp_flags = TCP_FLAGS_BE16(tcp_hdr(skb));
 	}
@@ -100,7 +100,7 @@ static void stats_read(struct flow_stats *stats,
 	spin_unlock(&stats->lock);
 }
 
-void ovs_flow_stats_get(struct sw_flow *flow, struct ovs_flow_stats *ovs_stats,
+void ovs_flow_stats_get(struct ovs_flow *flow, struct ovs_flow_stats *ovs_stats,
 			unsigned long *used, __be16 *tcp_flags)
 {
 	int cpu, cur_cpu;
@@ -139,7 +139,7 @@ static void stats_reset(struct flow_stats *stats)
 	spin_unlock(&stats->lock);
 }
 
-void ovs_flow_stats_clear(struct sw_flow *flow)
+void ovs_flow_stats_clear(struct ovs_flow *flow)
 {
 	int cpu, cur_cpu;
 
net/openvswitch/flow.h +25 -98

162 lines not on this page · raw message

net/openvswitch/flow_netlink.c +12 -12
index 4d000ac..179ab98 100644
@@ -46,7 +46,7 @@
 
 #include "flow_netlink.h"
 
-static void update_range__(struct sw_flow_match *match,
+static void update_range__(struct ovs_flow_match *match,
 			   size_t offset, size_t size, bool is_mask)
 {
 	struct sw_flow_key_range *range = NULL;
@@ -103,7 +103,7 @@ static u16 range_n_bytes(const struct sw_flow_key_range *range)
 	return range->end - range->start;
 }
 
-static bool match_validate(const struct sw_flow_match *match,
+static bool match_validate(const struct ovs_flow_match *match,
 			   u64 key_attrs, u64 mask_attrs)
 {
 	u64 key_expected = 1 << OVS_KEY_ATTR_ETHERNET;
@@ -339,7 +339,7 @@ static int parse_flow_nlattrs(const struct nlattr *attr,
 }
 
 static int ipv4_tun_from_nlattr(const struct nlattr *attr,
-				struct sw_flow_match *match, bool is_mask)
+				struct ovs_flow_match *match, bool is_mask)
 {
 	struct nlattr *a;
 	int rem;
@@ -428,8 +428,8 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
 }
 
 static int ipv4_tun_to_nlattr(struct sk_buff *skb,
-			      const struct ovs_key_ipv4_tunnel *tun_key,
-			      const struct ovs_key_ipv4_tunnel *output)
+			      const struct sw_flow_key_ipv4_tunnel *tun_key,
+			      const struct sw_flow_key_ipv4_tunnel *output)
 {
 	struct nlattr *nla;
 
@@ -463,7 +463,7 @@ static int ipv4_tun_to_nlattr(struct sk_buff *skb,
 }
 
 
-static int metadata_from_nlattrs(struct sw_flow_match *match,  u64 *attrs,
+static int metadata_from_nlattrs(struct ovs_flow_match *match,  u64 *attrs,
 				 const struct nlattr **a, bool is_mask)
 {
 	if (*attrs & (1 << OVS_KEY_ATTR_PRIORITY)) {
@@ -501,7 +501,7 @@ static int metadata_from_nlattrs(struct sw_flow_match *match,  u64 *attrs,
 	return 0;
 }
 
-static int ovs_key_from_nlattrs(struct sw_flow_match *match,  bool *exact_5tuple,
+static int ovs_key_from_nlattrs(struct ovs_flow_match *match,  bool *exact_5tuple,
 				u64 attrs, const struct nlattr **a,
 				bool is_mask)
 {
@@ -799,7 +799,7 @@ static void sw_flow_mask_set(struct sw_flow_mask *mask,
  * @mask: Optional. Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink
  * attribute specifies the mask field of the wildcarded flow.
  */
-int ovs_nla_get_match(struct sw_flow_match *match,
+int ovs_nla_get_match(struct ovs_flow_match *match,
 		      bool *exact_5tuple,
 		      const struct nlattr *key,
 		      const struct nlattr *mask)
@@ -922,11 +922,11 @@ int ovs_nla_get_match(struct sw_flow_match *match,
 int ovs_nla_get_flow_metadata(struct sw_flow *flow,
 			      const struct nlattr *attr)
 {
-	struct ovs_key_ipv4_tunnel *tun_key = &flow->key.tun_key;
+	struct sw_flow_key_ipv4_tunnel *tun_key = &flow->key.tun_key;
 	const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
 	u64 attrs = 0;
 	int err;
-	struct sw_flow_match match;
+	struct ovs_flow_match match;
 
 	flow->key.phy.in_port = DP_MAX_PORTS;
 	flow->key.phy.priority = 0;
@@ -1320,7 +1320,7 @@ static int validate_tp_port(const struct sw_flow_key *flow_key)
 	return -EINVAL;
 }
 
-void ovs_match_init(struct sw_flow_match *match,
+void ovs_match_init(struct ovs_flow_match *match,
 		    struct sw_flow_key *key,
 		    struct sw_flow_mask *mask)
 {
@@ -1339,7 +1339,7 @@ void ovs_match_init(struct sw_flow_match *match,
 static int validate_and_copy_set_tun(const struct nlattr *attr,
 				     struct sw_flow_actions **sfa)
 {
-	struct sw_flow_match match;
+	struct ovs_flow_match match;
 	struct sw_flow_key key;
 	int err, start;
 
net/openvswitch/flow_netlink.h +2 -2
index b31fbe2..f223929 100644
@@ -37,14 +37,14 @@
 
 #include "flow.h"
 
-void ovs_match_init(struct sw_flow_match *match,
+void ovs_match_init(struct ovs_flow_match *match,
 		    struct sw_flow_key *key, struct sw_flow_mask *mask);
 
 int ovs_nla_put_flow(const struct sw_flow_key *,
 		     const struct sw_flow_key *, struct sk_buff *);
 int ovs_nla_get_flow_metadata(struct sw_flow *flow,
 			      const struct nlattr *attr);
-int ovs_nla_get_match(struct sw_flow_match *match,
+int ovs_nla_get_match(struct ovs_flow_match *match,
 		      bool *exact_5tuple,
 		      const struct nlattr *,
 		      const struct nlattr *);
net/openvswitch/flow_table.c +52 -48

261 lines not on this page · raw message

net/openvswitch/flow_table.h +9 -9
index baaeb10..c6abd84 100644
@@ -55,28 +55,28 @@ struct flow_table {
 int ovs_flow_init(void);
 void ovs_flow_exit(void);
 
-struct sw_flow *ovs_flow_alloc(bool percpu_stats);
-void ovs_flow_free(struct sw_flow *, bool deferred);
+struct ovs_flow *ovs_flow_alloc(bool percpu_stats);
+void ovs_flow_free(struct ovs_flow *, bool deferred);
 
 int ovs_flow_tbl_init(struct flow_table *);
 int ovs_flow_tbl_count(struct flow_table *table);
 void ovs_flow_tbl_destroy(struct flow_table *table, bool deferred);
 int ovs_flow_tbl_flush(struct flow_table *flow_table);
 
-int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
+int ovs_flow_tbl_insert(struct flow_table *table, struct ovs_flow *flow,
 			struct sw_flow_mask *mask);
-void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
+void ovs_flow_tbl_remove(struct flow_table *table, struct ovs_flow *flow);
 int  ovs_flow_tbl_num_masks(const struct flow_table *table);
-struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
+struct ovs_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
 				       u32 *bucket, u32 *idx);
-struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
+struct ovs_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
 				    const struct sw_flow_key *,
 				    u32 *n_mask_hit);
-struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
+struct ovs_flow *ovs_flow_tbl_lookup(struct flow_table *,
 				    const struct sw_flow_key *);
 
-bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
-			       struct sw_flow_match *match);
+bool ovs_flow_cmp_unmasked_key(const struct ovs_flow *flow,
+			       struct ovs_flow_match *match);
 
 void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
 		       const struct sw_flow_mask *mask);
net/openvswitch/vport-gre.c +2 -2
index a3d6951..f940cbd 100644
@@ -63,7 +63,7 @@ static __be16 filter_tnl_flags(__be16 flags)
 static struct sk_buff *__build_header(struct sk_buff *skb,
 				      int tunnel_hlen)
 {
-	const struct ovs_key_ipv4_tunnel *tun_key = OVS_CB(skb)->tun_key;
+	const struct sw_flow_key_ipv4_tunnel *tun_key = OVS_CB(skb)->tun_key;
 	struct tnl_ptk_info tpi;
 
 	skb = gre_handle_offloads(skb, !!(tun_key->tun_flags & TUNNEL_CSUM));
@@ -92,7 +92,7 @@ static __be64 key_to_tunnel_id(__be32 key, __be32 seq)
 static int gre_rcv(struct sk_buff *skb,
 		   const struct tnl_ptk_info *tpi)
 {
-	struct ovs_key_ipv4_tunnel tun_key;
+	struct sw_flow_key_ipv4_tunnel tun_key;
 	struct ovs_net *ovs_net;
 	struct vport *vport;
 	__be64 key;
net/openvswitch/vport-vxlan.c +1 -1
index e797a50..e0be18e 100644
@@ -58,7 +58,7 @@ static inline struct vxlan_port *vxlan_vport(const struct vport *vport)
 /* Called with rcu_read_lock and BH disabled. */
 static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb, __be32 vx_vni)
 {
-	struct ovs_key_ipv4_tunnel tun_key;
+	struct sw_flow_key_ipv4_tunnel tun_key;
 	struct vport *vport = vs->data;
 	struct iphdr *iph;
 	__be64 key;
net/openvswitch/vport.c +1 -1
index 42c0f4a..81b083c 100644
@@ -337,7 +337,7 @@ int ovs_vport_get_options(const struct vport *vport, struct sk_buff *skb)
  * skb->data should point to the Ethernet header.
  */
 void ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
-		       struct ovs_key_ipv4_tunnel *tun_key)
+		       struct sw_flow_key_ipv4_tunnel *tun_key)
 {
 	struct pcpu_sw_netstats *stats;
 
net/openvswitch/vport.h +1 -1
index d7e50a1..0979304 100644
@@ -191,7 +191,7 @@ static inline struct vport *vport_from_priv(const void *priv)
 }
 
 void ovs_vport_receive(struct vport *, struct sk_buff *,
-		       struct ovs_key_ipv4_tunnel *);
+		       struct sw_flow_key_ipv4_tunnel *);
 
 /* List of statically compiled vport implementations.  Don't forget to also
  * add yours to the list at the top of vport.c. */
Signature · 1 line
1.8.5.3
author
#34 lore raw

RFC PATCH v2 4/6 net: introduce switchdev API

In reply to Jiri Pirko

switchdev API is designed to allow kernel support for various switch chips.

It is the responsibility of a driver to create netdevice instances which represents every port and for the switch master itself. Driver uses swdev_register and swportdev_register functions to make the core aware of the fact these netdevices are representing switch and switch ports.

---
 include/linux/netdevice.h |  24 +++++++
 include/linux/switchdev.h |  30 ++++++++
 net/Kconfig               |  10 +++
 net/core/Makefile         |   1 +
 net/core/switchdev.c      | 172 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 237 insertions(+)
 create mode 100644 include/linux/switchdev.h
 create mode 100644 net/core/switchdev.c
include/linux/netdevice.h +24 -0
index 6b70e6f..5ad80da 100644
@@ -49,6 +49,8 @@
 
 #include <linux/netdev_features.h>
 #include <linux/neighbour.h>
+#include <linux/sw_flow.h>
+
 #include <uapi/linux/netdevice.h>
 
 struct netpoll_info;
@@ -998,6 +1000,18 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
  *	Callback to use for xmit over the accelerated station. This
  *	is used in place of ndo_start_xmit on accelerated net
  *	devices.
+ *
+ * int (*ndo_swdev_flow_insert)(struct net_device *dev,
+ *				struct sw_flow *flow);
+ *	Called to insert a flow into switch device. If driver does
+ *	not implement this, it is assumed that the hw does not have
+ *	a capability to work with flows.
+ *
+ * int (*ndo_swdev_flow_remove)(struct net_device *dev,
+ *				struct sw_flow *flow);
+ *	Called to remove a flow from switch device. If driver does
+ *	not implement this, it is assumed that the hw does not have
+ *	a capability to work with flows.
  */
 struct net_device_ops {
 	int			(*ndo_init)(struct net_device *dev);
@@ -1145,6 +1159,12 @@ struct net_device_ops {
 	netdev_tx_t		(*ndo_dfwd_start_xmit) (struct sk_buff *skb,
 							struct net_device *dev,
 							void *priv);
+#if IS_ENABLED(CONFIG_NET_SWITCHDEV)
+	int			(*ndo_swdev_flow_insert)(struct net_device *dev,
+							 struct sw_flow *flow);
+	int			(*ndo_swdev_flow_remove)(struct net_device *dev,
+							 struct sw_flow *flow);
+#endif
 };
 
 /**
@@ -1205,6 +1225,8 @@ enum netdev_priv_flags {
 	IFF_SUPP_NOFCS			= 1<<19,
 	IFF_LIVE_ADDR_CHANGE		= 1<<20,
 	IFF_MACVLAN			= 1<<21,
+	IFF_SWITCH			= 1<<22,
+	IFF_SWITCH_PORT			= 1<<23,
 };
 
 #define IFF_802_1Q_VLAN			IFF_802_1Q_VLAN
@@ -1229,6 +1251,8 @@ enum netdev_priv_flags {
 #define IFF_SUPP_NOFCS			IFF_SUPP_NOFCS
 #define IFF_LIVE_ADDR_CHANGE		IFF_LIVE_ADDR_CHANGE
 #define IFF_MACVLAN			IFF_MACVLAN
+#define IFF_SWITCH			IFF_SWITCH
+#define IFF_SWITCH_PORT			IFF_SWITCH_PORT
 
 /*
  *	The DEVICE structure.
include/linux/switchdev.h new file +30 -0
new file mode 100644
index 0000000..e4aeaba
@@ -0,0 +1,30 @@
+/*
+ * include/linux/switchdev.h - Switch device API
+ * Copyright (c) 2014 Jiri Pirko <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#ifndef _LINUX_SWITCHDEV_H_
+#define _LINUX_SWITCHDEV_H_
+
+#include <linux/netdevice.h>
+#include <linux/sw_flow.h>
+
+bool swdev_dev_check(const struct net_device *dev);
+int swdev_flow_insert(struct net_device *dev, struct sw_flow *flow);
+int swdev_flow_remove(struct net_device *dev, struct sw_flow *flow);
+int __swdev_register(struct net_device *dev);
+int swdev_register(struct net_device *dev);
+void __swdev_unregister(struct net_device *dev);
+void swdev_unregister(struct net_device *dev);
+
+bool swportdev_dev_check(const struct net_device *dev);
+int __swportdev_register(struct net_device *port_dev, struct net_device *dev);
+int swportdev_register(struct net_device *port_dev, struct net_device *dev);
+void __swportdev_unregister(struct net_device *port_dev);
+void swportdev_unregister(struct net_device *port_dev);
+
+#endif /* _LINUX_SWITCHDEV_H_ */
net/Kconfig +10 -0
index e411046..e02ab8d 100644
@@ -285,6 +285,16 @@ config NET_FLOW_LIMIT
 	  with many clients some protection against DoS by a single (spoofed)
 	  flow that greatly exceeds average workload.
 
+config NET_SWITCHDEV
+	tristate "Switch device"
+	depends on INET
+	---help---
+	  This module provides glue for hardware switch chips so they can be
+	  accessed from userspace via Open vSwitch Netlink API. 
+
+	  To compile this code as a module, choose M here: the
+	  module will be called pktgen.
+
 menu "Network testing"
 
 config NET_PKTGEN
net/core/Makefile +1 -0
index 9628c20..426a619 100644
@@ -23,3 +23,4 @@ obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
 obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
 obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
+obj-$(CONFIG_NET_SWITCHDEV) += switchdev.o
net/core/switchdev.c new file +172 -0

172 lines not on this page · raw message

Signature · 1 line
1.8.5.3
#35 lore raw

Re: [patch net-next RFC v2 4/6] net: introduce switchdev API

Quoted 7 lines · Jiri Pirko

switchdev API is designed to allow kernel support for various switch chips.

It is the responsibility of a driver to create netdevice instances which represents every port and for the switch master itself. Driver uses swdev_register and swportdev_register functions to make the core aware of the fact these netdevices are representing switch and switch ports.

I like this even more than the previous approach.

net/core/switchdev.c line 54

Quoted 11 lines
net/core/switchdev.c new file +8 -0
+int __swdev_register(struct net_device *dev)
+{
+	if (dev->priv_flags & IFF_SWITCH) {
+		netdev_err(dev, "Device is already registered as a switch device\n");
+		return -EBUSY;
+	}
+	dev->priv_flags |= IFF_SWITCH;
+	netdev_info(dev, "Switch device registered\n");

Perhaps include name of device here?

Quoted 9 lines
net/core/switchdev.c new file +9 -0
+	return 0;
+}
+EXPORT_SYMBOL(__swdev_register);
+
+int swdev_register(struct net_device *dev)
+{
+	int err;
+
+	rtnl_lock();

net/core/switchdev.c line 73

Quoted 10 lines
net/core/switchdev.c new file +10 -0
+	err = __swdev_register(dev);
+	rtnl_unlock();
+	return err;
+}
+EXPORT_SYMBOL(swdev_register);
+
+void __swdev_unregister(struct net_device *dev)
+{
+	dev->priv_flags |= IFF_SWITCH;
+	netdev_info(dev, "Switch device unregistered\n");

Same here

Quoted 46 lines
net/core/switchdev.c new file +46 -0
+}
+EXPORT_SYMBOL(__swdev_unregister);
+
+void swdev_unregister(struct net_device *dev)
+{
+	rtnl_lock();
+	__swdev_unregister(dev);
+	rtnl_unlock();
+}
+EXPORT_SYMBOL(swdev_unregister);
+
+
+bool swportdev_dev_check(const struct net_device *port_dev)
+{
+	return port_dev->priv_flags & IFF_SWITCH_PORT;
+}
+EXPORT_SYMBOL(swportdev_dev_check);
+
+static rx_handler_result_t swportdev_handle_frame(struct sk_buff **pskb)
+{
+	struct sk_buff *skb = *pskb;
+
+	/* We don't care what comes from port device into rx path.
+	 * If there's something there, it is destined to ETH_P_ALL
+	 * handlers. So just consume it.
+	 */
+	dev_kfree_skb(skb);
+	return RX_HANDLER_CONSUMED;
+}
+
+int __swportdev_register(struct net_device *port_dev, struct net_device *dev)
+{
+	int err;
+
+	if (!(dev->priv_flags & IFF_SWITCH)) {
+		netdev_err(dev, "Device is not a switch device\n");
+		return -EINVAL;
+	}
+	if (port_dev->priv_flags & IFF_SWITCH_PORT) {
+		netdev_err(port_dev, "Device is already registered as a switch port\n");
+		return -EBUSY;
+	}
+	err = netdev_master_upper_dev_link(port_dev, dev);
+	if (err) {
+		netdev_err(dev, "Device %s failed to set upper link\n",
+			   port_dev->name);

net/core/switchdev.c line 129

Quoted 10 lines
net/core/switchdev.c new file +10 -0
+		return err;
+	}
+	err = netdev_rx_handler_register(port_dev, swportdev_handle_frame, NULL);
+	if (err) {
+		netdev_err(dev, "Device %s failed to register rx_handler\n",
+			   port_dev->name);
+		goto err_handler_register;
+	}
+	port_dev->priv_flags |= IFF_SWITCH_PORT;
+	netdev_info(port_dev, "Switch port device registered\n");

and here

net/core/switchdev.c line 138

Quoted 9 lines
net/core/switchdev.c new file +9 -0
+	return 0;
+
+err_handler_register:
+	netdev_upper_dev_unlink(port_dev, dev);
+	return err;
+}
+EXPORT_SYMBOL(__swportdev_register);
+
+int swportdev_register(struct net_device *port_dev, struct net_device *dev)

Maybe rename dev to switch_dev just to make it clear?

Quoted 37 lines
net/core/switchdev.c new file +34 -0
+{
+	int err;
+
+	rtnl_lock();
+	err = __swportdev_register(port_dev, dev);
+	rtnl_unlock();
+	return err;
+}
+EXPORT_SYMBOL(swportdev_register);
+
+void __swportdev_unregister(struct net_device *port_dev)
+{
+	struct net_device *dev;
+
+	dev = netdev_master_upper_dev_get(port_dev);
+	BUG_ON(!dev);
+	port_dev->priv_flags &= ~IFF_SWITCH_PORT;
+	netdev_rx_handler_unregister(port_dev);
+	netdev_upper_dev_unlink(port_dev, dev);
+	netdev_info(port_dev, "Switch port device unregistered\n");
+}
+EXPORT_SYMBOL(__swportdev_unregister);
+
+void swportdev_unregister(struct net_device *port_dev)
+{
+	rtnl_lock();
+	__swportdev_unregister(port_dev);
+	rtnl_unlock();
+}
+EXPORT_SYMBOL(swportdev_unregister);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Jiri Pirko <[email protected]>");
+MODULE_DESCRIPTION("Switch device API");
Signature · 1 line
1.8.5.3

A message that is not in the archive (sent off-list or not yet received): 20140327112339.GB1615-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org

#37 lore raw

Re: [patch net-next RFC v2 4/6] net: introduce switchdev API

Quoted 14 lines · Thu, Mar 27, 2014 at 12:23:39PM CET, tgraf-G/[email protected] wrote:
Quoted 7 lines · Jiri Pirko

switchdev API is designed to allow kernel support for various switch chips.

It is the responsibility of a driver to create netdevice instances which represents every port and for the switch master itself. Driver uses swdev_register and swportdev_register functions to make the core aware of the fact these netdevices are representing switch and switch ports.

I like this even more than the previous approach.

Quoted 2 lines
Quoted 10 lines

net/core/switchdev.c line 54

Quoted 8 lines
net/core/switchdev.c new file +8 -0
+int __swdev_register(struct net_device *dev)
+{
+	if (dev->priv_flags & IFF_SWITCH) {
+		netdev_err(dev, "Device is already registered as a switch device\n");
+		return -EBUSY;
+	}
+	dev->priv_flags |= IFF_SWITCH;
+	netdev_info(dev, "Switch device registered\n");

Perhaps include name of device here?

netdev_info already does that.

Quoted 82 lines
Quoted 10 lines
net/core/switchdev.c new file +9 -0
+	return 0;
+}
+EXPORT_SYMBOL(__swdev_register);
+
+int swdev_register(struct net_device *dev)
+{
+	int err;
+
+	rtnl_lock();

net/core/switchdev.c line 73

Quoted 10 lines
net/core/switchdev.c new file +10 -0
+	err = __swdev_register(dev);
+	rtnl_unlock();
+	return err;
+}
+EXPORT_SYMBOL(swdev_register);
+
+void __swdev_unregister(struct net_device *dev)
+{
+	dev->priv_flags |= IFF_SWITCH;
+	netdev_info(dev, "Switch device unregistered\n");

Same here

Quoted 46 lines
net/core/switchdev.c new file +46 -0
+}
+EXPORT_SYMBOL(__swdev_unregister);
+
+void swdev_unregister(struct net_device *dev)
+{
+	rtnl_lock();
+	__swdev_unregister(dev);
+	rtnl_unlock();
+}
+EXPORT_SYMBOL(swdev_unregister);
+
+
+bool swportdev_dev_check(const struct net_device *port_dev)
+{
+	return port_dev->priv_flags & IFF_SWITCH_PORT;
+}
+EXPORT_SYMBOL(swportdev_dev_check);
+
+static rx_handler_result_t swportdev_handle_frame(struct sk_buff **pskb)
+{
+	struct sk_buff *skb = *pskb;
+
+	/* We don't care what comes from port device into rx path.
+	 * If there's something there, it is destined to ETH_P_ALL
+	 * handlers. So just consume it.
+	 */
+	dev_kfree_skb(skb);
+	return RX_HANDLER_CONSUMED;
+}
+
+int __swportdev_register(struct net_device *port_dev, struct net_device *dev)
+{
+	int err;
+
+	if (!(dev->priv_flags & IFF_SWITCH)) {
+		netdev_err(dev, "Device is not a switch device\n");
+		return -EINVAL;
+	}
+	if (port_dev->priv_flags & IFF_SWITCH_PORT) {
+		netdev_err(port_dev, "Device is already registered as a switch port\n");
+		return -EBUSY;
+	}
+	err = netdev_master_upper_dev_link(port_dev, dev);
+	if (err) {
+		netdev_err(dev, "Device %s failed to set upper link\n",
+			   port_dev->name);

net/core/switchdev.c line 129

Quoted 10 lines
net/core/switchdev.c new file +10 -0
+		return err;
+	}
+	err = netdev_rx_handler_register(port_dev, swportdev_handle_frame, NULL);
+	if (err) {
+		netdev_err(dev, "Device %s failed to register rx_handler\n",
+			   port_dev->name);
+		goto err_handler_register;
+	}
+	port_dev->priv_flags |= IFF_SWITCH_PORT;
+	netdev_info(port_dev, "Switch port device registered\n");

and here

Quoted 11 lines

net/core/switchdev.c line 138

Quoted 9 lines
net/core/switchdev.c new file +9 -0
+	return 0;
+
+err_handler_register:
+	netdev_upper_dev_unlink(port_dev, dev);
+	return err;
+}
+EXPORT_SYMBOL(__swportdev_register);
+
+int swportdev_register(struct net_device *port_dev, struct net_device *dev)

Maybe rename dev to switch_dev just to make it clear?

That might be reasonable.

Quoted 38 lines
Quoted 38 lines
net/core/switchdev.c new file +34 -0
+{
+	int err;
+
+	rtnl_lock();
+	err = __swportdev_register(port_dev, dev);
+	rtnl_unlock();
+	return err;
+}
+EXPORT_SYMBOL(swportdev_register);
+
+void __swportdev_unregister(struct net_device *port_dev)
+{
+	struct net_device *dev;
+
+	dev = netdev_master_upper_dev_get(port_dev);
+	BUG_ON(!dev);
+	port_dev->priv_flags &= ~IFF_SWITCH_PORT;
+	netdev_rx_handler_unregister(port_dev);
+	netdev_upper_dev_unlink(port_dev, dev);
+	netdev_info(port_dev, "Switch port device unregistered\n");
+}
+EXPORT_SYMBOL(__swportdev_unregister);
+
+void swportdev_unregister(struct net_device *port_dev)
+{
+	rtnl_lock();
+	__swportdev_unregister(port_dev);
+	rtnl_unlock();
+}
+EXPORT_SYMBOL(swportdev_unregister);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Jiri Pirko <[email protected]>");
+MODULE_DESCRIPTION("Switch device API");
Signature · 1 line
1.8.5.3

A message that is not in the archive (sent off-list or not yet received): 1395851472-10524-5-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org

#39 lore raw

Re: [patch net-next RFC v2 4/6] net: introduce switchdev API

Quoted 8 lines
net/Kconfig +0 -0
index e411046..e02ab8d 100644
@@ -285,6 +285,16 @@ config NET_FLOW_LIMIT
 	  with many clients some protection against DoS by a single (spoofed)
 	  flow that greatly exceeds average workload.
 

net/Kconfig config NET_FLOW_LIMIT · line 297

Quoted 10 lines
net/Kconfig +10 -0
+config NET_SWITCHDEV
+	tristate "Switch device"
+	depends on INET
+	---help---
+	  This module provides glue for hardware switch chips so they can be
+	  accessed from userspace via Open vSwitch Netlink API.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called pktgen.
+

"pktgen" cut'n'paste typo.

Neil

#40 lore raw

Re: [patch net-next RFC v2 4/6] net: introduce switchdev API

In reply to a message not in the archive

Hi Jiri,

Apologies for possibly newbie questions here, but:

Quoted 5 lines
net/core/switchdev.c new file +5 -0
+bool swdev_dev_check(const struct net_device *dev)
+{
+	return dev->priv_flags & IFF_SWITCH;
+}
+EXPORT_SYMBOL(swdev_dev_check);

[...]

Quoted 1 line
(quoted diff) +1 -0
+	BUG_ON(!swdev_dev_check(dev));

[...]

Review

Quoted 7 lines
net/core/switchdev.c new file +4 -0
+int __swdev_register(struct net_device *dev)
+{
+	if (dev->priv_flags & IFF_SWITCH) {
+		netdev_err(dev, "Device is already registered as a switch

device\n");

(quoted diff) +2 -0
+		return -EBUSY;
+	}

[...]

1. What's the benefit of requiring and policing the IFF_SWITCH flag, and requiring a switch netdev to call swdev_register, as opposed to just checking whether the netdev provides the relevant ops?

net/core/switchdev.c line 68

Quoted 10 lines
net/core/switchdev.c new file +10 -0
+int swdev_register(struct net_device *dev)
+{
+	int err;
+
+	rtnl_lock();
+	err = __swdev_register(dev);
+	rtnl_unlock();
+	return err;
+}
+EXPORT_SYMBOL(swdev_register);

2. Why grab and release the rtnl lock, given that there appears to be nothing rtnl-related in between?

Regards,
Neil

author
#41 lore raw

RFC PATCH v2 1/1 iproute: add support for dummyswport

In reply to Jiri Pirko
---
 include/linux/if_link.h |  9 +++++++++
 ip/Makefile             |  3 ++-
 ip/iplink_dummyswport.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 ip/iplink_dummyswport.c
include/linux/if_link.h +9 -0
index f08505c..aa3d619 100644
@@ -542,4 +542,13 @@ enum {
 
 #define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1)
 
+/* DUMMYSWPORT section */
+enum {
+	IFLA_DUMMYSWPORT_UNSPEC,
+	IFLA_DUMMYSWPORT_MASTER,
+	__IFLA_DUMMYSWPORT_MAX,
+};
+
+#define IFLA_DUMMYSWPORT_MAX (__IFLA_DUMMYSWPORT_MAX - 1)
+
 #endif /* _LINUX_IF_LINK_H */
ip/Makefile +2 -1
index 713adf5..35546e5 100644
@@ -5,7 +5,8 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \
     iplink_vlan.o link_veth.o link_gre.o iplink_can.o \
     iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o \
     iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \
-    link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o
+    link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o \
+    iplink_dummyswport.o \
 
 RTMONOBJ=rtmon.o
 
ip/iplink_dummyswport.c new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
1.8.5.3