From: Florian Fainelli <f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Jiri Pirko <jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: ryazanov.s.a-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
jasowang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
john.r.fastabend-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
Neil.Jerram-QnUH15yq9NYqDJ6do+/SaQ@public.gmane.org,
edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
andy-QlMahl40kYEqcZcGjlUOXw@public.gmane.org,
dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org,
nbd-p3rKhJxN3npAfugRpC6u6w@public.gmane.org,
ronye-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
jeffrey.t.kirsher-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org,
buytenh-OLH4Qvv75CYX/NnBR394Jw@public.gmane.org,
alexander.h.duyck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
simon.horman-wFxRvT7yatFl57MIdRCFDg@public.gmane.org,
roopa-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org,
jhs-jkUAjuhPggJWk0Htik3J/w@public.gmane.org,
aviadr-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org,
vyasevic-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org,
stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org,
dborkman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org,
davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org
Subject: Re: [patch net-next v2 5/9] net: introduce dummy switch
Date: Fri, 19 Sep 2014 22:21:00 -0700 [thread overview]
Message-ID: <541D0EBC.6010103@gmail.com> (raw)
In-Reply-To: <1411134590-4586-6-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
On 09/19/14 06:49, Jiri Pirko wrote:
> Dummy switch implementation using switchdev interface
This really looks like a DSA driver that has 0 ports, and is not
attached to an useful network interface, and which is registering its
own set of rtnl operations for a purpose that is unclear to me.
I think registering these rtnl ops is misleading as it leads to a false
idea that this is allowed, and that people are actually encouraged to do
that for custom switch drivers, and this completely defeats the purpose
of coming up with a generic API.
If we are to go that route anyway, I really prefer the way Felix did it
in swconfig, and the fake switch driver did do something useful being
attached to the loopback interface:
http://lists.openwall.net/netdev/2013/10/22/103
http://patchwork.ozlabs.org/patch/285478/
>
> Signed-off-by: Jiri Pirko <jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
> ---
> drivers/net/Kconfig | 7 +++
> drivers/net/Makefile | 1 +
> drivers/net/dummyswitch.c | 130 +++++++++++++++++++++++++++++++++++++++++++
> include/uapi/linux/if_link.h | 9 +++
> 4 files changed, 147 insertions(+)
> create mode 100644 drivers/net/dummyswitch.c
>
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index c6f6f69..7822c74 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -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---
> diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> index 61aefdd..3c835ba 100644
> --- a/drivers/net/Makefile
> +++ b/drivers/net/Makefile
> @@ -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
> diff --git a/drivers/net/dummyswitch.c b/drivers/net/dummyswitch.c
> new file mode 100644
> index 0000000..e7a48f4
> --- /dev/null
> +++ b/drivers/net/dummyswitch.c
> @@ -0,0 +1,130 @@
> +/*
> + * drivers/net/dummyswitch.c - Dummy switch device
> + * Copyright (c) 2014 Jiri Pirko <jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
> + *
> + * 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.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/netdevice.h>
> +#include <linux/etherdevice.h>
> +#include <net/rtnetlink.h>
> +
> +struct dummyswport_priv {
> + struct netdev_phys_item_id psid;
> +};
> +
> +static netdev_tx_t dummyswport_start_xmit(struct sk_buff *skb,
> + struct net_device *dev)
> +{
> + dev_kfree_skb(skb);
> + return NETDEV_TX_OK;
> +}
> +
> +static int dummyswport_swdev_id_get(struct net_device *dev,
> + struct netdev_phys_item_id *psid)
> +{
> + struct dummyswport_priv *dsp = netdev_priv(dev);
> +
> + memcpy(psid, &dsp->psid, sizeof(*psid));
> + return 0;
> +}
> +
> +static int dummyswport_change_carrier(struct net_device *dev, bool new_carrier)
> +{
> + if (new_carrier)
> + netif_carrier_on(dev);
> + else
> + netif_carrier_off(dev);
> + return 0;
> +}
> +
> +static const struct net_device_ops dummyswport_netdev_ops = {
> + .ndo_start_xmit = dummyswport_start_xmit,
> + .ndo_swdev_id_get = dummyswport_swdev_id_get,
> + .ndo_change_carrier = dummyswport_change_carrier,
> +};
> +
> +static void dummyswport_setup(struct net_device *dev)
> +{
> + ether_setup(dev);
> +
> + /* Initialize the device structure. */
> + dev->netdev_ops = &dummyswport_netdev_ops;
> + dev->destructor = free_netdev;
> +
> + /* Fill in device structure with ethernet-generic values. */
> + dev->tx_queue_len = 0;
> + dev->flags |= IFF_NOARP;
> + dev->flags &= ~IFF_MULTICAST;
> + dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
> + dev->features |= NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO;
> + dev->features |= NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_LLTX;
> + eth_hw_addr_random(dev);
> +}
> +
> +static int dummyswport_validate(struct nlattr *tb[], struct nlattr *data[])
> +{
> + if (tb[IFLA_ADDRESS])
> + return -EINVAL;
> + if (!data || !data[IFLA_DUMMYSWPORT_PHYS_SWITCH_ID])
> + return -EINVAL;
> + return 0;
> +}
> +
> +static int dummyswport_newlink(struct net *src_net, struct net_device *dev,
> + struct nlattr *tb[], struct nlattr *data[])
> +{
> + struct dummyswport_priv *dsp = netdev_priv(dev);
> + int err;
> +
> + dsp->psid.id_len = nla_len(data[IFLA_DUMMYSWPORT_PHYS_SWITCH_ID]);
> + memcpy(dsp->psid.id, nla_data(data[IFLA_DUMMYSWPORT_PHYS_SWITCH_ID]),
> + dsp->psid.id_len);
> +
> + err = register_netdevice(dev);
> + if (err)
> + return err;
> +
> + netif_carrier_on(dev);
> +
> + return 0;
> +}
> +
> +static const struct nla_policy dummyswport_policy[IFLA_DUMMYSWPORT_MAX + 1] = {
> + [IFLA_DUMMYSWPORT_PHYS_SWITCH_ID] = { .type = NLA_BINARY,
> + .len = MAX_PHYS_ITEM_ID_LEN },
> +};
> +
> +static struct rtnl_link_ops dummyswport_link_ops __read_mostly = {
> + .kind = "dummyswport",
> + .priv_size = sizeof(struct dummyswport_priv),
> + .setup = dummyswport_setup,
> + .validate = dummyswport_validate,
> + .newlink = dummyswport_newlink,
> + .policy = dummyswport_policy,
> + .maxtype = IFLA_DUMMYSWPORT_MAX,
> +};
> +
> +static int __init dummysw_module_init(void)
> +{
> + return rtnl_link_register(&dummyswport_link_ops);
> +}
> +
> +static void __exit dummysw_module_exit(void)
> +{
> + rtnl_link_unregister(&dummyswport_link_ops);
> +}
> +
> +module_init(dummysw_module_init);
> +module_exit(dummysw_module_exit);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_AUTHOR("Jiri Pirko <jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>");
> +MODULE_DESCRIPTION("Dummy switch device");
> +MODULE_ALIAS_RTNL_LINK("dummyswport");
> diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> index c5ca3b9..bd24d69 100644
> --- a/include/uapi/linux/if_link.h
> +++ b/include/uapi/linux/if_link.h
> @@ -574,4 +574,13 @@ enum {
>
> #define IFLA_HSR_MAX (__IFLA_HSR_MAX - 1)
>
> +/* DUMMYSWPORT section */
> +enum {
> + IFLA_DUMMYSWPORT_UNSPEC,
> + IFLA_DUMMYSWPORT_PHYS_SWITCH_ID,
> + __IFLA_DUMMYSWPORT_MAX,
> +};
> +
> +#define IFLA_DUMMYSWPORT_MAX (__IFLA_DUMMYSWPORT_MAX - 1)
> +
> #endif /* _UAPI_LINUX_IF_LINK_H */
>
next prev parent reply other threads:[~2014-09-20 5:21 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 13:49 [patch net-next v2 0/9] introduce rocker switch driver with hardware accelerated datapath api Jiri Pirko
2014-09-19 13:49 ` [patch net-next v2 1/9] net: rename netdev_phys_port_id to more generic name Jiri Pirko
[not found] ` <1411134590-4586-2-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
2014-09-19 13:54 ` Jeff Kirsher
[not found] ` <1411134590-4586-1-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
2014-09-19 13:49 ` [patch net-next v2 2/9] net: introduce generic switch devices support Jiri Pirko
2014-09-19 14:15 ` [patch net-next v2 0/9] introduce rocker switch driver with hardware accelerated datapath api David Laight
[not found] ` <063D6719AE5E284EB5DD2968C1650D6D17495CC6-VkEWCZq2GCInGFn1LkZF6NBPR1lH4CV8@public.gmane.org>
2014-09-19 14:20 ` Jiri Pirko
2014-09-20 5:37 ` Florian Fainelli
2014-09-19 13:49 ` [patch net-next v2 3/9] rtnl: expose physical switch id for particular device Jiri Pirko
2014-09-19 13:49 ` [patch net-next v2 4/9] net-sysfs: " Jiri Pirko
2014-09-19 13:49 ` [patch net-next v2 5/9] net: introduce dummy switch Jiri Pirko
[not found] ` <1411134590-4586-6-git-send-email-jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org>
2014-09-20 5:21 ` Florian Fainelli [this message]
2014-09-20 7:37 ` Jiri Pirko
2014-09-19 13:49 ` [patch net-next v2 6/9] switchdev: add basic support for flow matching and actions Jiri Pirko
2014-09-20 5:32 ` Florian Fainelli
2014-09-20 7:28 ` Jiri Pirko
2014-09-19 13:49 ` [patch net-next v2 7/9] switchdev: add swdev features Jiri Pirko
2014-09-19 13:49 ` [patch net-next v2 8/9] switchdev: introduce Netlink API Jiri Pirko
2014-09-19 15:25 ` Jamal Hadi Salim
2014-09-19 15:49 ` Jiri Pirko
2014-09-19 17:57 ` Jamal Hadi Salim
2014-09-19 22:12 ` John Fastabend
2014-09-19 22:18 ` Jamal Hadi Salim
2014-09-20 5:39 ` Florian Fainelli
2014-09-20 8:25 ` Jiri Pirko
2014-09-20 8:17 ` Jiri Pirko
2014-09-20 10:19 ` Jamal Hadi Salim
2014-09-20 11:01 ` Thomas Graf
2014-09-20 11:32 ` Jamal Hadi Salim
2014-09-20 11:51 ` Thomas Graf
[not found] ` <20140920115140.GA3777-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org>
2014-09-20 12:35 ` Jamal Hadi Salim
2014-09-22 7:53 ` Jiri Pirko
[not found] ` <20140922075337.GA1828-6KJVSR23iU488b5SBfVpbw@public.gmane.org>
2014-09-22 11:48 ` Jamal Hadi Salim
2014-09-20 5:36 ` Florian Fainelli
2014-09-20 8:14 ` Jiri Pirko
2014-09-20 10:53 ` Thomas Graf
2014-09-20 22:50 ` Alexei Starovoitov
2014-09-22 8:13 ` Thomas Graf
2014-09-22 15:10 ` Tom Herbert
2014-09-22 22:17 ` Thomas Graf
[not found] ` <20140922221727.GA4708-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org>
2014-09-22 22:40 ` Tom Herbert
2014-09-22 22:53 ` Thomas Graf
2014-09-22 23:07 ` Tom Herbert
2014-09-23 1:36 ` John Fastabend
2014-09-23 7:19 ` Thomas Graf
2014-09-23 11:09 ` Jamal Hadi Salim
[not found] ` <CA+mtBx9ZVQ5r5Hzy9-uEnk+iu+HKkOP4+VANC06Xf8VvTxktwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-09-23 9:18 ` Thomas Graf
2014-09-23 1:54 ` Alexei Starovoitov
2014-09-23 2:16 ` Tom Herbert
2014-09-23 4:11 ` Andy Gospodarek
2014-09-23 10:11 ` Thomas Graf
2014-09-23 15:32 ` Or Gerlitz
2014-09-24 13:32 ` Thomas Graf
2014-09-26 20:03 ` Or Gerlitz
2014-09-26 21:02 ` Thomas Graf
2014-09-23 9:52 ` Thomas Graf
2014-09-20 3:41 ` Roopa Prabhu
2014-09-20 8:09 ` Jiri Pirko
2014-09-20 12:39 ` Roopa Prabhu
2014-09-20 8:10 ` Scott Feldman
2014-09-20 10:31 ` Jamal Hadi Salim
[not found] ` <DDC24110-C3F5-470F-B9BE-1D1792415D1E-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
2014-09-20 12:51 ` Roopa Prabhu
2014-09-20 17:21 ` Scott Feldman
2014-09-20 17:38 ` Jiri Pirko
2014-09-21 1:30 ` Roopa Prabhu
2014-09-19 13:49 ` [patch net-next v2 9/9] rocker: introduce rocker switch driver Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=541D0EBC.6010103@gmail.com \
--to=f.fainelli-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=Neil.Jerram-QnUH15yq9NYqDJ6do+/SaQ@public.gmane.org \
--cc=alexander.h.duyck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=andy-QlMahl40kYEqcZcGjlUOXw@public.gmane.org \
--cc=aviadr-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org \
--cc=buytenh-OLH4Qvv75CYX/NnBR394Jw@public.gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=dborkman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
--cc=edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=jasowang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=jeffrey.t.kirsher-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=jhs-jkUAjuhPggJWk0Htik3J/w@public.gmane.org \
--cc=jiri-rHqAuBHg3fBzbRFIqnYvSA@public.gmane.org \
--cc=john.r.fastabend-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=nbd-p3rKhJxN3npAfugRpC6u6w@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org \
--cc=nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org \
--cc=ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=ronye-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=roopa-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org \
--cc=ryazanov.s.a-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=simon.horman-wFxRvT7yatFl57MIdRCFDg@public.gmane.org \
--cc=stephen-OTpzqLSitTUnbdJkjeBofR2eb7JE58TQ@public.gmane.org \
--cc=vyasevic-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).