]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
link: Support for AF_BRIDGE address family
authorThomas Graf <tgraf@suug.ch>
Thu, 11 Nov 2010 15:02:48 +0000 (16:02 +0100)
committerThomas Graf <tgraf@suug.ch>
Thu, 11 Nov 2010 15:02:48 +0000 (16:02 +0100)
Supports parsing of IFLA_PROTINFO returned when dumping with PF_BRIDGE

lib/Makefile.am
lib/route/link/bridge.c [new file with mode: 0644]

index 6cfce33168c959acbf0c6c0516b5d11c168a5310..c1277be8bd4d8d14bd288fe5ee765473c61dbd8c 100644 (file)
@@ -59,6 +59,7 @@ libnl_route_la_SOURCES = \
        route/cls/ematch/meta.c \
        \
        route/link/api.c route/link/vlan.c \
+       route/link/bridge.c \
        \
        route/sch/blackhole.c route/sch/cbq.c route/sch/dsmark.c \
        route/sch/fifo.c route/sch/htb.c route/sch/netem.c route/sch/prio.c \
diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c
new file mode 100644 (file)
index 0000000..4e4da58
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * lib/route/link/bridge.c     AF_BRIDGE link oeprations
+ *
+ *     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) 2010 Thomas Graf <tgraf@suug.ch>
+ */
+
+/**
+ * @ingroup link
+ * @defgroup link_bridge Bridge Specifics
+ * @brief
+ *
+ * @{
+ */
+
+#include <netlink-local.h>
+#include <netlink/netlink.h>
+#include <netlink/attr.h>
+#include <netlink/route/rtnl.h>
+#include <netlink/route/link/api.h>
+
+struct bridge_data
+{
+       uint8_t                 b_port_state;
+};
+
+static void *bridge_alloc(struct rtnl_link *link)
+{
+       return calloc(1, sizeof(struct bridge_data));
+}
+
+static void *bridge_clone(struct rtnl_link *link, void *data)
+{
+       struct bridge_data *bd;
+
+       if ((bd = bridge_alloc(link)))
+               memcpy(bd, data, sizeof(*bd));
+
+       return bd;
+}
+
+static void bridge_free(struct rtnl_link *link, void *data)
+{
+       free(data);
+}
+
+static int bridge_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
+                                void *data)
+{
+       struct bridge_data *bd = data;
+
+       bd->b_port_state = nla_get_u8(attr);
+
+       return 0;
+}
+
+static void bridge_dump_details(struct rtnl_link *link,
+                               struct nl_dump_params *p, void *data)
+{
+       struct bridge_data *bd = data;
+
+       nl_dump(p, "port-state %u ", bd->b_port_state);
+}
+
+static const struct nla_policy protinfo_policy = {
+       .type                   = NLA_U8,
+};
+
+static struct rtnl_link_af_ops bridge_ops = {
+       .ao_family                      = AF_BRIDGE,
+       .ao_alloc                       = &bridge_alloc,
+       .ao_clone                       = &bridge_clone,
+       .ao_free                        = &bridge_free,
+       .ao_parse_protinfo              = &bridge_parse_protinfo,
+       .ao_dump[NL_DUMP_DETAILS]       = &bridge_dump_details,
+       .ao_protinfo_policy             = &protinfo_policy,
+};
+
+static void __init bridge_init(void)
+{
+       rtnl_link_af_register(&bridge_ops);
+}
+
+static void __exit bridge_exit(void)
+{
+       rtnl_link_af_unregister(&bridge_ops);
+}
+
+/** @} */