~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/netfilter/ipvs/ip_vs_pe.c

Version: ~ [ linux-5.1-rc5 ] ~ [ linux-5.0.7 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.34 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.111 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.168 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #define KMSG_COMPONENT "IPVS"
  2 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  3 
  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>
 10 
 11 #include <net/ip_vs.h>
 12 
 13 /* IPVS pe list */
 14 static LIST_HEAD(ip_vs_pe);
 15 
 16 /* lock for service table */
 17 static DEFINE_SPINLOCK(ip_vs_pe_lock);
 18 
 19 /* Bind a service with a pe */
 20 void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe)
 21 {
 22         svc->pe = pe;
 23 }
 24 
 25 /* Unbind a service from its pe */
 26 void ip_vs_unbind_pe(struct ip_vs_service *svc)
 27 {
 28         svc->pe = NULL;
 29 }
 30 
 31 /* Get pe in the pe list by name */
 32 struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name)
 33 {
 34         struct ip_vs_pe *pe;
 35 
 36         IP_VS_DBG(10, "%s(): pe_name \"%s\"\n", __func__,
 37                   pe_name);
 38 
 39         spin_lock_bh(&ip_vs_pe_lock);
 40 
 41         list_for_each_entry(pe, &ip_vs_pe, n_list) {
 42                 /* Test and get the modules atomically */
 43                 if (pe->module &&
 44                     !try_module_get(pe->module)) {
 45                         /* This pe is just deleted */
 46                         continue;
 47                 }
 48                 if (strcmp(pe_name, pe->name)==0) {
 49                         /* HIT */
 50                         spin_unlock_bh(&ip_vs_pe_lock);
 51                         return pe;
 52                 }
 53                 if (pe->module)
 54                         module_put(pe->module);
 55         }
 56 
 57         spin_unlock_bh(&ip_vs_pe_lock);
 58         return NULL;
 59 }
 60 
 61 /* Lookup pe and try to load it if it doesn't exist */
 62 struct ip_vs_pe *ip_vs_pe_getbyname(const char *name)
 63 {
 64         struct ip_vs_pe *pe;
 65 
 66         /* Search for the pe by name */
 67         pe = __ip_vs_pe_getbyname(name);
 68 
 69         /* If pe not found, load the module and search again */
 70         if (!pe) {
 71                 request_module("ip_vs_pe_%s", name);
 72                 pe = __ip_vs_pe_getbyname(name);
 73         }
 74 
 75         return pe;
 76 }
 77 
 78 /* Register a pe in the pe list */
 79 int register_ip_vs_pe(struct ip_vs_pe *pe)
 80 {
 81         struct ip_vs_pe *tmp;
 82 
 83         /* increase the module use count */
 84         ip_vs_use_count_inc();
 85 
 86         spin_lock_bh(&ip_vs_pe_lock);
 87 
 88         if (!list_empty(&pe->n_list)) {
 89                 spin_unlock_bh(&ip_vs_pe_lock);
 90                 ip_vs_use_count_dec();
 91                 pr_err("%s(): [%s] pe already linked\n",
 92                        __func__, pe->name);
 93                 return -EINVAL;
 94         }
 95 
 96         /* Make sure that the pe with this name doesn't exist
 97          * in the pe list.
 98          */
 99         list_for_each_entry(tmp, &ip_vs_pe, n_list) {
100                 if (strcmp(tmp->name, pe->name) == 0) {
101                         spin_unlock_bh(&ip_vs_pe_lock);
102                         ip_vs_use_count_dec();
103                         pr_err("%s(): [%s] pe already existed "
104                                "in the system\n", __func__, pe->name);
105                         return -EINVAL;
106                 }
107         }
108         /* Add it into the d-linked pe list */
109         list_add(&pe->n_list, &ip_vs_pe);
110         spin_unlock_bh(&ip_vs_pe_lock);
111 
112         pr_info("[%s] pe registered.\n", pe->name);
113 
114         return 0;
115 }
116 EXPORT_SYMBOL_GPL(register_ip_vs_pe);
117 
118 /* Unregister a pe from the pe list */
119 int unregister_ip_vs_pe(struct ip_vs_pe *pe)
120 {
121         spin_lock_bh(&ip_vs_pe_lock);
122         if (list_empty(&pe->n_list)) {
123                 spin_unlock_bh(&ip_vs_pe_lock);
124                 pr_err("%s(): [%s] pe is not in the list. failed\n",
125                        __func__, pe->name);
126                 return -EINVAL;
127         }
128 
129         /* Remove it from the d-linked pe list */
130         list_del(&pe->n_list);
131         spin_unlock_bh(&ip_vs_pe_lock);
132 
133         /* decrease the module use count */
134         ip_vs_use_count_dec();
135 
136         pr_info("[%s] pe unregistered.\n", pe->name);
137 
138         return 0;
139 }
140 EXPORT_SYMBOL_GPL(unregister_ip_vs_pe);
141 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp