All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bernhard Fischer <rep.dot.nop@gmail.com>
To: shemminger@linux-foundation.org
Cc: buytenh@gnu.org, rep.dot.nop@gmail.com,
	bridge@lists.linux-foundation.org
Subject: [Bridge] [RFA, PATCH] enable transition to sysfs-only bridge manipulation
Date: Fri, 2 May 2008 11:01:38 +0200	[thread overview]
Message-ID: <20080502090138.GA15508@mx.loc> (raw)

[-- Attachment #1: Type: text/plain, Size: 399 bytes --]

Hi,

It was rumored that the ioctl interface for bridges is deprecated.
There is, however, one crucial gap when trying to implement brctl
without using any ioctl: AFAICS it is impossible to create a bridge via
sysfs.

The attached quick.. erm patch strives to fill this gap.
Some further details are at the top of the patchlet which received only
cursory testing, fwiw.

Thanks and cheers,
Bernhard

[-- Attachment #2: linux-2.6.25-brctrl-sysfs-fixup.01.diff --]
[-- Type: text/x-diff, Size: 3319 bytes --]

enable transition to sysfs-only bridge manipulation

  All bridge-operations except the creation of a bridge are
  already operable via sysfs. The attached patchlet provides means to fill
  this gap in order to completely deprecate the ioctl interface to bridges.
  $ echo add mybr0 > /sys/class/bridge/ctrl
  $ echo add mybr1 > /sys/class/bridge/ctrl
  $ echo del mybr1 > /sys/class/bridge/ctrl


add/remove: 3/0 grow/shrink: 4/0 up/down: 490/0 (490)
function                                     old     new   delta
brctl                                          -     230    +230
init_module                                  186     265     +79
br_init                                      186     265     +79
cleanup_module                               103     142     +39
br_deinit                                    103     142     +39
class_attr_ctrl                                -      20     +20
br_class                                       -       4      +4

Signed-off-by:  Bernhard Fischer <rep.dot.nop@gmail.com>

diff -rdup linux-2.6.25.oorig/net/bridge/br.c linux-2.6.25/net/bridge/br.c
--- linux-2.6.25.oorig/net/bridge/br.c	2008-04-17 04:49:44.000000000 +0200
+++ linux-2.6.25/net/bridge/br.c	2008-05-02 10:28:40.000000000 +0200
@@ -20,11 +20,91 @@
 #include <linux/init.h>
 #include <linux/llc.h>
 #include <net/llc.h>
+#include <linux/ctype.h> /* isspace() */
 
 #include "br_private.h"
 
 int (*br_should_route_hook)(struct sk_buff *skb);
 
+#ifdef CONFIG_SYSFS
+static ssize_t brctl(struct class *cls, const char *buf, size_t buf_len)
+{
+	unsigned op_add;
+	size_t sz = buf_len;
+	char *br;
+	int ret;
+
+	if (sz < 3)
+		goto err;
+
+	if (buf[0] == 'a')
+		op_add = 1;
+	else if (buf[0] == 'd')
+		op_add = 0;
+	else
+		goto err;
+
+	if (buf[buf_len - 1] == '\n')
+		--sz;
+
+	/* skip to bridge name */
+	while (!isspace(*buf)) {
+		++buf;
+		--sz;
+	}
+	while (isspace(*buf)) {
+		++buf;
+		--sz;
+	}
+	if (!buf || !sz)
+		goto err;
+	br = kzalloc(sz, GFP_KERNEL);
+	if (!br)
+		return -ENOMEM;
+	strncpy(br, buf, sz);
+
+	if (op_add)
+		ret = br_add_bridge(br);
+	else
+		ret = br_del_bridge(br);
+	kfree(br);
+	return (ret < 0) ? ret : buf_len;
+err:
+	return -EINVAL;
+}
+static struct class *br_class;
+static CLASS_ATTR(ctrl, 0200, NULL, brctl);
+static inline int br_sysfs_init(void)
+{
+	int ret;
+
+	br_class = class_create(THIS_MODULE, "bridge");
+	if (IS_ERR(br_class))
+		return PTR_ERR(br_class);
+
+	ret = class_create_file(br_class, &class_attr_ctrl);
+	if (ret < 0) {
+		class_destroy(br_class);
+		br_class = NULL;
+	}
+	return ret;
+}
+static inline void br_sysfs_fini(void)
+{
+	if (br_class) {
+		class_remove_file(br_class, &class_attr_ctrl);
+		class_destroy(br_class);
+		br_class = NULL;
+	}
+}
+#else
+static inline int br_sysfs_init(void)
+{
+	return 0;
+}
+static inline void br_sysfs_fini(void) {;}
+#endif
+
 static struct llc_sap *br_stp_sap;
 
 static int __init br_init(void)
@@ -53,6 +133,10 @@ static int __init br_init(void)
 	if (err)
 		goto err_out3;
 
+	err = br_sysfs_init();
+	if (err)
+		goto err_out3;
+
 	brioctl_set(br_ioctl_deviceless_stub);
 	br_handle_frame_hook = br_handle_frame;
 
@@ -73,6 +157,7 @@ err_out:
 
 static void __exit br_deinit(void)
 {
+	br_sysfs_fini();
 	rcu_assign_pointer(br_stp_sap->rcv_func, NULL);
 
 	br_netlink_fini();

             reply	other threads:[~2008-05-02  9:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02  9:01 Bernhard Fischer [this message]
2008-05-02 15:17 ` [Bridge] [RFA, PATCH] enable transition to sysfs-only bridge manipulation Stephen Hemminger
2008-05-02 16:30   ` Bernhard Fischer

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=20080502090138.GA15508@mx.loc \
    --to=rep.dot.nop@gmail.com \
    --cc=bridge@lists.linux-foundation.org \
    --cc=buytenh@gnu.org \
    --cc=shemminger@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.