]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/netfilter/ipvs/ip_vs_pe.c
1 #define KMSG_COMPONENT "IPVS"
2 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
4 #include <linux/module.h>
5 #include <linux/spinlock.h>
6 #include <linux/interrupt.h>
7 #include <asm/string.h>
8 #include <linux/kmod.h>
9 #include <linux/sysctl.h>
11 #include <net/ip_vs.h>
14 static LIST_HEAD(ip_vs_pe
);
16 /* semaphore for IPVS PEs. */
17 static DEFINE_MUTEX(ip_vs_pe_mutex
);
19 /* Get pe in the pe list by name */
20 struct ip_vs_pe
*__ip_vs_pe_getbyname(const char *pe_name
)
24 IP_VS_DBG(10, "%s(): pe_name \"%s\"\n", __func__
,
28 list_for_each_entry_rcu(pe
, &ip_vs_pe
, n_list
) {
29 /* Test and get the modules atomically */
31 !try_module_get(pe
->module
)) {
32 /* This pe is just deleted */
35 if (strcmp(pe_name
, pe
->name
)==0) {
40 module_put(pe
->module
);
47 /* Lookup pe and try to load it if it doesn't exist */
48 struct ip_vs_pe
*ip_vs_pe_getbyname(const char *name
)
52 /* Search for the pe by name */
53 pe
= __ip_vs_pe_getbyname(name
);
55 /* If pe not found, load the module and search again */
57 request_module("ip_vs_pe_%s", name
);
58 pe
= __ip_vs_pe_getbyname(name
);
64 /* Register a pe in the pe list */
65 int register_ip_vs_pe(struct ip_vs_pe
*pe
)
69 /* increase the module use count */
70 ip_vs_use_count_inc();
72 mutex_lock(&ip_vs_pe_mutex
);
73 /* Make sure that the pe with this name doesn't exist
76 list_for_each_entry(tmp
, &ip_vs_pe
, n_list
) {
77 if (strcmp(tmp
->name
, pe
->name
) == 0) {
78 mutex_unlock(&ip_vs_pe_mutex
);
79 ip_vs_use_count_dec();
80 pr_err("%s(): [%s] pe already existed "
81 "in the system\n", __func__
, pe
->name
);
85 /* Add it into the d-linked pe list */
86 list_add_rcu(&pe
->n_list
, &ip_vs_pe
);
87 mutex_unlock(&ip_vs_pe_mutex
);
89 pr_info("[%s] pe registered.\n", pe
->name
);
93 EXPORT_SYMBOL_GPL(register_ip_vs_pe
);
95 /* Unregister a pe from the pe list */
96 int unregister_ip_vs_pe(struct ip_vs_pe
*pe
)
98 mutex_lock(&ip_vs_pe_mutex
);
99 /* Remove it from the d-linked pe list */
100 list_del_rcu(&pe
->n_list
);
101 mutex_unlock(&ip_vs_pe_mutex
);
103 /* decrease the module use count */
104 ip_vs_use_count_dec();
106 pr_info("[%s] pe unregistered.\n", pe
->name
);
110 EXPORT_SYMBOL_GPL(unregister_ip_vs_pe
);