]>
git.ipfire.org Git - thirdparty/kernel/stable.git/blob - net/netfilter/ipvs/ip_vs_pe.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 #define KMSG_COMPONENT "IPVS"
3 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
5 #include <linux/module.h>
6 #include <linux/spinlock.h>
7 #include <linux/interrupt.h>
8 #include <asm/string.h>
9 #include <linux/kmod.h>
10 #include <linux/sysctl.h>
12 #include <net/ip_vs.h>
15 static LIST_HEAD(ip_vs_pe
);
17 /* semaphore for IPVS PEs. */
18 static DEFINE_MUTEX(ip_vs_pe_mutex
);
20 /* Get pe in the pe list by name */
21 struct ip_vs_pe
*__ip_vs_pe_getbyname(const char *pe_name
)
25 IP_VS_DBG(10, "%s(): pe_name \"%s\"\n", __func__
,
29 list_for_each_entry_rcu(pe
, &ip_vs_pe
, n_list
) {
30 /* Test and get the modules atomically */
32 !try_module_get(pe
->module
)) {
33 /* This pe is just deleted */
36 if (strcmp(pe_name
, pe
->name
)==0) {
41 module_put(pe
->module
);
48 /* Lookup pe and try to load it if it doesn't exist */
49 struct ip_vs_pe
*ip_vs_pe_getbyname(const char *name
)
53 /* Search for the pe by name */
54 pe
= __ip_vs_pe_getbyname(name
);
56 /* If pe not found, load the module and search again */
58 request_module("ip_vs_pe_%s", name
);
59 pe
= __ip_vs_pe_getbyname(name
);
65 /* Register a pe in the pe list */
66 int register_ip_vs_pe(struct ip_vs_pe
*pe
)
70 /* increase the module use count */
71 ip_vs_use_count_inc();
73 mutex_lock(&ip_vs_pe_mutex
);
74 /* Make sure that the pe with this name doesn't exist
77 list_for_each_entry(tmp
, &ip_vs_pe
, n_list
) {
78 if (strcmp(tmp
->name
, pe
->name
) == 0) {
79 mutex_unlock(&ip_vs_pe_mutex
);
80 ip_vs_use_count_dec();
81 pr_err("%s(): [%s] pe already existed "
82 "in the system\n", __func__
, pe
->name
);
86 /* Add it into the d-linked pe list */
87 list_add_rcu(&pe
->n_list
, &ip_vs_pe
);
88 mutex_unlock(&ip_vs_pe_mutex
);
90 pr_info("[%s] pe registered.\n", pe
->name
);
94 EXPORT_SYMBOL_GPL(register_ip_vs_pe
);
96 /* Unregister a pe from the pe list */
97 int unregister_ip_vs_pe(struct ip_vs_pe
*pe
)
99 mutex_lock(&ip_vs_pe_mutex
);
100 /* Remove it from the d-linked pe list */
101 list_del_rcu(&pe
->n_list
);
102 mutex_unlock(&ip_vs_pe_mutex
);
104 /* decrease the module use count */
105 ip_vs_use_count_dec();
107 pr_info("[%s] pe unregistered.\n", pe
->name
);
111 EXPORT_SYMBOL_GPL(unregister_ip_vs_pe
);