[PATCH] link: add ifb device support

Cong Wang xiyou.wangcong at gmail.com
Mon Jul 21 12:27:32 PDT 2014


Cc: Thomas Graf <tgraf at suug.ch>
Cc: Thomas Haller <thaller at redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong at gmail.com>
---
 lib/Makefile.am         |  2 +-
 lib/route/link/ifb.c    | 40 ++++++++++++++++++++++++++++++++++++++++
 tests/.gitignore        |  1 +
 tests/Makefile.am       |  2 ++
 tests/test-create-ifb.c | 29 +++++++++++++++++++++++++++++
 5 files changed, 73 insertions(+), 1 deletion(-)
 create mode 100644 lib/route/link/ifb.c
 create mode 100644 tests/test-create-ifb.c

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 4953d21..ee9c00d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -80,7 +80,7 @@ libnl_route_3_la_SOURCES = \
 	route/link/bonding.c route/link/can.c route/link/macvlan.c \
 	route/link/vxlan.c route/link/veth.c route/link/ipip.c \
 	route/link/ipgre.c route/link/sit.c route/link/ipvti.c \
-	route/link/ip6tnl.c \
+	route/link/ip6tnl.c route/link/ifb.c \
 	\
 	route/qdisc/blackhole.c route/qdisc/cbq.c route/qdisc/dsmark.c \
 	route/qdisc/fifo.c route/qdisc/htb.c route/qdisc/netem.c \
diff --git a/lib/route/link/ifb.c b/lib/route/link/ifb.c
new file mode 100644
index 0000000..524f5c6
--- /dev/null
+++ b/lib/route/link/ifb.c
@@ -0,0 +1,40 @@
+/*
+ * lib/route/link/ifb.c	IFB Interfaces
+ *
+ *	This library is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU Lesser General Public
+ *	License as published by the Free Software Foundation version 2.1
+ *	of the License.
+ *
+ * Copyright (c) 2014 Cong Wang <xiyou.wangcong at gmail.com>
+ */
+
+/**
+ * @ingroup link
+ * @defgroup ifb Intermediate Functional Block
+ *
+ * @details
+ * \b Link Type Name: "ifb"
+ *
+ * @{
+ */
+
+#include <netlink-private/netlink.h>
+#include <netlink/netlink.h>
+#include <netlink-private/route/link/api.h>
+
+static struct rtnl_link_info_ops ifb_info_ops = {
+	.io_name		= "ifb",
+};
+
+static void __init ifb_init(void)
+{
+	rtnl_link_register_info(&ifb_info_ops);
+}
+
+static void __exit ifb_exit(void)
+{
+	rtnl_link_unregister_info(&ifb_info_ops);
+}
+
+/** @} */
diff --git a/tests/.gitignore b/tests/.gitignore
index 6b77cac..7894d5a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -15,6 +15,7 @@
 /test-create-veth
 /test-create-vlan
 /test-create-vxlan
+/test-create-ifb
 /test-delete-link
 /test-genl
 /test-nf-cache-mngr
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 255033d..85d93b8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@ check_PROGRAMS = \
 	test-create-ipip \
 	test-create-ipvti \
 	test-create-sit \
+	test-create-ifb \
 	test-delete-link \
 	test-socket-creation \
 	test-complex-HTB-with-hash-filters \
@@ -52,6 +53,7 @@ test_create_vlan_SOURCES = test-create-vlan.c
 test_create_vxlan_SOURCES = test-create-vxlan.c
 test_create_veth_SOURCES = test-create-veth.c
 test_create_bridge_SOURCES = test-create-bridge.c
+test_create_ifb_SOURCES = test-create-ifb.c
 test_delete_link_SOURCES = test-delete-link.c
 test_genl_SOURCES = test-genl.c
 test_nf_cache_mngr_SOURCES = test-nf-cache-mngr.c
diff --git a/tests/test-create-ifb.c b/tests/test-create-ifb.c
new file mode 100644
index 0000000..99336f5
--- /dev/null
+++ b/tests/test-create-ifb.c
@@ -0,0 +1,29 @@
+#include <netlink/netlink.h>
+#include <netlink/route/link.h>
+
+int main(int argc, char *argv[])
+{
+	struct rtnl_link *link;
+	struct nl_sock *sk;
+	int err;
+
+	sk = nl_socket_alloc();
+	if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
+		nl_perror(err, "Unable to connect socket");
+		return err;
+	}
+
+	link = rtnl_link_alloc();
+	rtnl_link_set_type(link, "ifb");
+	rtnl_link_set_name(link, "ifb1");
+
+	if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
+		nl_perror(err, "Unable to add link");
+		return err;
+	}
+
+	rtnl_link_put(link);
+	nl_close(sk);
+
+	return 0;
+}
-- 
1.8.3.1




More information about the libnl mailing list