Blame view
net/netfilter/ipvs/ip_vs_pe.c
2.38 KB
8be67a661 IPVS: management ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#define KMSG_COMPONENT "IPVS" #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt #include <linux/module.h> #include <linux/spinlock.h> #include <linux/interrupt.h> #include <asm/string.h> #include <linux/kmod.h> #include <linux/sysctl.h> #include <net/ip_vs.h> /* IPVS pe list */ static LIST_HEAD(ip_vs_pe); |
60b6aa3b3 ipvs: convert loc... |
15 16 |
/* semaphore for IPVS PEs. */ static DEFINE_MUTEX(ip_vs_pe_mutex); |
8be67a661 IPVS: management ... |
17 |
|
8be67a661 IPVS: management ... |
18 |
/* Get pe in the pe list by name */ |
fe5e7a1ef IPVS: Backup, Add... |
19 |
struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name) |
8be67a661 IPVS: management ... |
20 21 |
{ struct ip_vs_pe *pe; |
fe5e7a1ef IPVS: Backup, Add... |
22 23 |
IP_VS_DBG(10, "%s(): pe_name \"%s\" ", __func__, |
8be67a661 IPVS: management ... |
24 |
pe_name); |
60b6aa3b3 ipvs: convert loc... |
25 26 |
rcu_read_lock(); list_for_each_entry_rcu(pe, &ip_vs_pe, n_list) { |
8be67a661 IPVS: management ... |
27 28 29 30 31 32 33 34 |
/* Test and get the modules atomically */ if (pe->module && !try_module_get(pe->module)) { /* This pe is just deleted */ continue; } if (strcmp(pe_name, pe->name)==0) { /* HIT */ |
60b6aa3b3 ipvs: convert loc... |
35 |
rcu_read_unlock(); |
8be67a661 IPVS: management ... |
36 37 |
return pe; } |
982f40513 netfilter: Deleti... |
38 |
module_put(pe->module); |
8be67a661 IPVS: management ... |
39 |
} |
60b6aa3b3 ipvs: convert loc... |
40 |
rcu_read_unlock(); |
8be67a661 IPVS: management ... |
41 |
|
8be67a661 IPVS: management ... |
42 43 44 45 |
return NULL; } /* Lookup pe and try to load it if it doesn't exist */ |
e9e5eee87 IPVS: Add persist... |
46 |
struct ip_vs_pe *ip_vs_pe_getbyname(const char *name) |
8be67a661 IPVS: management ... |
47 48 49 50 |
{ struct ip_vs_pe *pe; /* Search for the pe by name */ |
e9e5eee87 IPVS: Add persist... |
51 |
pe = __ip_vs_pe_getbyname(name); |
8be67a661 IPVS: management ... |
52 53 54 55 |
/* If pe not found, load the module and search again */ if (!pe) { request_module("ip_vs_pe_%s", name); |
e9e5eee87 IPVS: Add persist... |
56 |
pe = __ip_vs_pe_getbyname(name); |
8be67a661 IPVS: management ... |
57 58 59 60 |
} return pe; } |
8be67a661 IPVS: management ... |
61 62 63 64 65 66 67 |
/* Register a pe in the pe list */ int register_ip_vs_pe(struct ip_vs_pe *pe) { struct ip_vs_pe *tmp; /* increase the module use count */ ip_vs_use_count_inc(); |
60b6aa3b3 ipvs: convert loc... |
68 |
mutex_lock(&ip_vs_pe_mutex); |
8be67a661 IPVS: management ... |
69 70 71 72 73 |
/* Make sure that the pe with this name doesn't exist * in the pe list. */ list_for_each_entry(tmp, &ip_vs_pe, n_list) { if (strcmp(tmp->name, pe->name) == 0) { |
60b6aa3b3 ipvs: convert loc... |
74 |
mutex_unlock(&ip_vs_pe_mutex); |
8be67a661 IPVS: management ... |
75 76 77 78 79 80 81 82 |
ip_vs_use_count_dec(); pr_err("%s(): [%s] pe already existed " "in the system ", __func__, pe->name); return -EINVAL; } } /* Add it into the d-linked pe list */ |
60b6aa3b3 ipvs: convert loc... |
83 84 |
list_add_rcu(&pe->n_list, &ip_vs_pe); mutex_unlock(&ip_vs_pe_mutex); |
8be67a661 IPVS: management ... |
85 86 87 88 89 90 91 92 93 94 95 |
pr_info("[%s] pe registered. ", pe->name); return 0; } EXPORT_SYMBOL_GPL(register_ip_vs_pe); /* Unregister a pe from the pe list */ int unregister_ip_vs_pe(struct ip_vs_pe *pe) { |
60b6aa3b3 ipvs: convert loc... |
96 |
mutex_lock(&ip_vs_pe_mutex); |
8be67a661 IPVS: management ... |
97 |
/* Remove it from the d-linked pe list */ |
60b6aa3b3 ipvs: convert loc... |
98 99 |
list_del_rcu(&pe->n_list); mutex_unlock(&ip_vs_pe_mutex); |
8be67a661 IPVS: management ... |
100 101 102 103 104 105 106 107 108 109 |
/* decrease the module use count */ ip_vs_use_count_dec(); pr_info("[%s] pe unregistered. ", pe->name); return 0; } EXPORT_SYMBOL_GPL(unregister_ip_vs_pe); |