bonding: push Netlink bits into separate file
authorJiri Pirko <jiri@resnulli.us>
Fri, 18 Oct 2013 15:43:33 +0000 (17:43 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 19 Oct 2013 22:58:45 +0000 (18:58 -0400)
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/Makefile
drivers/net/bonding/bond_main.c
drivers/net/bonding/bond_netlink.c [new file with mode: 0644]
drivers/net/bonding/bonding.h

index 4c21bf6b8b2f015abfaf77b414d3e5b7670026f2..09e8b2c83afe645c19d4a0d19cc0f6df02d8ffdf 100644 (file)
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_BONDING) += bonding.o
 
-bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o
+bonding-objs := bond_main.o bond_3ad.o bond_alb.o bond_sysfs.o bond_debugfs.o bond_netlink.o
 
 proc-$(CONFIG_PROC_FS) += bond_procfs.o
 bonding-objs += $(proc-y)
index dfb4f6dd5de0603a5183b7d1f8addc5794b0a96e..a113e4212486dd33843e64a2ca86514b4ed3ef03 100644 (file)
@@ -3951,7 +3951,7 @@ static void bond_destructor(struct net_device *bond_dev)
        free_netdev(bond_dev);
 }
 
-static void bond_setup(struct net_device *bond_dev)
+void bond_setup(struct net_device *bond_dev)
 {
        struct bonding *bond = netdev_priv(bond_dev);
 
@@ -4451,32 +4451,11 @@ static int bond_init(struct net_device *bond_dev)
        return 0;
 }
 
-static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
-{
-       if (tb[IFLA_ADDRESS]) {
-               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
-                       return -EINVAL;
-               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
-                       return -EADDRNOTAVAIL;
-       }
-       return 0;
-}
-
-static unsigned int bond_get_num_tx_queues(void)
+unsigned int bond_get_num_tx_queues(void)
 {
        return tx_queues;
 }
 
-static struct rtnl_link_ops bond_link_ops __read_mostly = {
-       .kind                   = "bond",
-       .priv_size              = sizeof(struct bonding),
-       .setup                  = bond_setup,
-       .validate               = bond_validate,
-       .get_num_tx_queues      = bond_get_num_tx_queues,
-       .get_num_rx_queues      = bond_get_num_tx_queues, /* Use the same number
-                                                            as for TX queues */
-};
-
 /* Create a new bond based on the specified name and bonding parameters.
  * If name is NULL, obtain a suitable "bond%d" name for us.
  * Caller must NOT hold rtnl_lock; we need to release it here before we
@@ -4563,7 +4542,7 @@ static int __init bonding_init(void)
        if (res)
                goto out;
 
-       res = rtnl_link_register(&bond_link_ops);
+       res = bond_netlink_init();
        if (res)
                goto err_link;
 
@@ -4579,7 +4558,7 @@ static int __init bonding_init(void)
 out:
        return res;
 err:
-       rtnl_link_unregister(&bond_link_ops);
+       bond_netlink_fini();
 err_link:
        unregister_pernet_subsys(&bond_net_ops);
        goto out;
@@ -4592,7 +4571,7 @@ static void __exit bonding_exit(void)
 
        bond_destroy_debugfs();
 
-       rtnl_link_unregister(&bond_link_ops);
+       bond_netlink_fini();
        unregister_pernet_subsys(&bond_net_ops);
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
@@ -4609,4 +4588,3 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
-MODULE_ALIAS_RTNL_LINK("bond");
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
new file mode 100644 (file)
index 0000000..3e5c5f8
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * drivers/net/bond/bond_netlink.c - Netlink interface for bonding
+ * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
+ *
+ * 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.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/if_link.h>
+#include <linux/if_ether.h>
+#include <net/netlink.h>
+#include <net/rtnetlink.h>
+#include "bonding.h"
+
+static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
+{
+       if (tb[IFLA_ADDRESS]) {
+               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
+                       return -EINVAL;
+               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
+                       return -EADDRNOTAVAIL;
+       }
+       return 0;
+}
+
+struct rtnl_link_ops bond_link_ops __read_mostly = {
+       .kind                   = "bond",
+       .priv_size              = sizeof(struct bonding),
+       .setup                  = bond_setup,
+       .validate               = bond_validate,
+       .get_num_tx_queues      = bond_get_num_tx_queues,
+       .get_num_rx_queues      = bond_get_num_tx_queues, /* Use the same number
+                                                            as for TX queues */
+};
+
+int __init bond_netlink_init(void)
+{
+       return rtnl_link_register(&bond_link_ops);
+}
+
+void __exit bond_netlink_fini(void)
+{
+       rtnl_link_unregister(&bond_link_ops);
+}
+
+MODULE_ALIAS_RTNL_LINK("bond");
index bb5c731e2560880b81dc9cd1fac2c5888cd135fa..a2a353bf9ea669c502e69840ad7229bfc0d4e718 100644 (file)
@@ -418,6 +418,10 @@ void bond_debug_register(struct bonding *bond);
 void bond_debug_unregister(struct bonding *bond);
 void bond_debug_reregister(struct bonding *bond);
 const char *bond_mode_name(int mode);
+void bond_setup(struct net_device *bond_dev);
+unsigned int bond_get_num_tx_queues(void);
+int bond_netlink_init(void);
+void bond_netlink_fini(void);
 
 struct bond_net {
        struct net *            net;    /* Associated network namespace */
@@ -505,4 +509,7 @@ extern const struct bond_parm_tbl fail_over_mac_tbl[];
 extern const struct bond_parm_tbl pri_reselect_tbl[];
 extern struct bond_parm_tbl ad_select_tbl[];
 
+/* exported from bond_netlink.c */
+extern struct rtnl_link_ops bond_link_ops;
+
 #endif /* _LINUX_BONDING_H */