Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ip_vs_proto.c: transport protocol load balancing support for IPVS |
| 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Authors: Wensong Zhang <wensong@linuxvirtualserver.org> |
| 5 | * Julian Anastasov <ja@ssi.bg> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * Changes: |
| 13 | * |
| 14 | */ |
| 15 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 16 | #define KMSG_COMPONENT "IPVS" |
| 17 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/skbuff.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/in.h> |
| 24 | #include <linux/ip.h> |
| 25 | #include <net/protocol.h> |
| 26 | #include <net/tcp.h> |
| 27 | #include <net/udp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/stat.h> |
| 29 | #include <linux/proc_fs.h> |
| 30 | |
| 31 | #include <net/ip_vs.h> |
| 32 | |
| 33 | |
| 34 | /* |
| 35 | * IPVS protocols can only be registered/unregistered when the ipvs |
| 36 | * module is loaded/unloaded, so no lock is needed in accessing the |
| 37 | * ipvs protocol table. |
| 38 | */ |
| 39 | |
| 40 | #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ |
| 41 | #define IP_VS_PROTO_HASH(proto) ((proto) & (IP_VS_PROTO_TAB_SIZE-1)) |
| 42 | |
| 43 | static struct ip_vs_protocol *ip_vs_proto_table[IP_VS_PROTO_TAB_SIZE]; |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * register an ipvs protocol |
| 48 | */ |
Sven Wegener | 048cf48 | 2008-08-10 18:24:35 +0000 | [diff] [blame] | 49 | static int __used __init register_ip_vs_protocol(struct ip_vs_protocol *pp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | unsigned hash = IP_VS_PROTO_HASH(pp->protocol); |
| 52 | |
| 53 | pp->next = ip_vs_proto_table[hash]; |
| 54 | ip_vs_proto_table[hash] = pp; |
| 55 | |
| 56 | if (pp->init != NULL) |
| 57 | pp->init(pp); |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
Changli Gao | 091bb34 | 2011-01-21 18:02:13 +0800 | [diff] [blame] | 62 | #if defined(CONFIG_IP_VS_PROTO_TCP) || defined(CONFIG_IP_VS_PROTO_UDP) || \ |
| 63 | defined(CONFIG_IP_VS_PROTO_SCTP) || defined(CONFIG_IP_VS_PROTO_AH) || \ |
| 64 | defined(CONFIG_IP_VS_PROTO_ESP) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 65 | /* |
| 66 | * register an ipvs protocols netns related data |
| 67 | */ |
| 68 | static int |
| 69 | register_ip_vs_proto_netns(struct net *net, struct ip_vs_protocol *pp) |
| 70 | { |
| 71 | struct netns_ipvs *ipvs = net_ipvs(net); |
| 72 | unsigned hash = IP_VS_PROTO_HASH(pp->protocol); |
| 73 | struct ip_vs_proto_data *pd = |
| 74 | kzalloc(sizeof(struct ip_vs_proto_data), GFP_ATOMIC); |
| 75 | |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 76 | if (!pd) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 77 | return -ENOMEM; |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 78 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 79 | pd->pp = pp; /* For speed issues */ |
| 80 | pd->next = ipvs->proto_data_table[hash]; |
| 81 | ipvs->proto_data_table[hash] = pd; |
| 82 | atomic_set(&pd->appcnt, 0); /* Init app counter */ |
| 83 | |
| 84 | if (pp->init_netns != NULL) |
| 85 | pp->init_netns(net, pd); |
| 86 | |
| 87 | return 0; |
| 88 | } |
Changli Gao | 091bb34 | 2011-01-21 18:02:13 +0800 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * unregister an ipvs protocol |
| 93 | */ |
| 94 | static int unregister_ip_vs_protocol(struct ip_vs_protocol *pp) |
| 95 | { |
| 96 | struct ip_vs_protocol **pp_p; |
| 97 | unsigned hash = IP_VS_PROTO_HASH(pp->protocol); |
| 98 | |
| 99 | pp_p = &ip_vs_proto_table[hash]; |
| 100 | for (; *pp_p; pp_p = &(*pp_p)->next) { |
| 101 | if (*pp_p == pp) { |
| 102 | *pp_p = pp->next; |
| 103 | if (pp->exit != NULL) |
| 104 | pp->exit(pp); |
| 105 | return 0; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return -ESRCH; |
| 110 | } |
| 111 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 112 | /* |
| 113 | * unregister an ipvs protocols netns data |
| 114 | */ |
| 115 | static int |
| 116 | unregister_ip_vs_proto_netns(struct net *net, struct ip_vs_proto_data *pd) |
| 117 | { |
| 118 | struct netns_ipvs *ipvs = net_ipvs(net); |
| 119 | struct ip_vs_proto_data **pd_p; |
| 120 | unsigned hash = IP_VS_PROTO_HASH(pd->pp->protocol); |
| 121 | |
| 122 | pd_p = &ipvs->proto_data_table[hash]; |
| 123 | for (; *pd_p; pd_p = &(*pd_p)->next) { |
| 124 | if (*pd_p == pd) { |
| 125 | *pd_p = pd->next; |
| 126 | if (pd->pp->exit_netns != NULL) |
| 127 | pd->pp->exit_netns(net, pd); |
| 128 | kfree(pd); |
| 129 | return 0; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return -ESRCH; |
| 134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * get ip_vs_protocol object by its proto. |
| 138 | */ |
| 139 | struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto) |
| 140 | { |
| 141 | struct ip_vs_protocol *pp; |
| 142 | unsigned hash = IP_VS_PROTO_HASH(proto); |
| 143 | |
| 144 | for (pp = ip_vs_proto_table[hash]; pp; pp = pp->next) { |
| 145 | if (pp->protocol == proto) |
| 146 | return pp; |
| 147 | } |
| 148 | |
| 149 | return NULL; |
| 150 | } |
Hannes Eder | 9c3e1c3 | 2010-07-23 12:42:58 +0200 | [diff] [blame] | 151 | EXPORT_SYMBOL(ip_vs_proto_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 153 | /* |
| 154 | * get ip_vs_protocol object data by netns and proto |
| 155 | */ |
| 156 | struct ip_vs_proto_data * |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 157 | __ipvs_proto_data_get(struct netns_ipvs *ipvs, unsigned short proto) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 158 | { |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 159 | struct ip_vs_proto_data *pd; |
| 160 | unsigned hash = IP_VS_PROTO_HASH(proto); |
| 161 | |
| 162 | for (pd = ipvs->proto_data_table[hash]; pd; pd = pd->next) { |
| 163 | if (pd->pp->protocol == proto) |
| 164 | return pd; |
| 165 | } |
| 166 | |
| 167 | return NULL; |
| 168 | } |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 169 | |
| 170 | struct ip_vs_proto_data * |
| 171 | ip_vs_proto_data_get(struct net *net, unsigned short proto) |
| 172 | { |
| 173 | struct netns_ipvs *ipvs = net_ipvs(net); |
| 174 | |
| 175 | return __ipvs_proto_data_get(ipvs, proto); |
| 176 | } |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 177 | EXPORT_SYMBOL(ip_vs_proto_data_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Propagate event for state change to all protocols |
| 181 | */ |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 182 | void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 184 | struct ip_vs_proto_data *pd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | int i; |
| 186 | |
| 187 | for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) { |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 188 | for (pd = ipvs->proto_data_table[i]; pd; pd = pd->next) { |
| 189 | if (pd->pp->timeout_change) |
| 190 | pd->pp->timeout_change(pd, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
| 196 | int * |
| 197 | ip_vs_create_timeout_table(int *table, int size) |
| 198 | { |
Arnaldo Carvalho de Melo | 8b2ed4b | 2006-11-21 01:17:18 -0200 | [diff] [blame] | 199 | return kmemdup(table, size, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | |
| 203 | /* |
| 204 | * Set timeout value for state specified by name |
| 205 | */ |
| 206 | int |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 207 | ip_vs_set_state_timeout(int *table, int num, const char *const *names, |
| 208 | const char *name, int to) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | int i; |
| 211 | |
| 212 | if (!table || !name || !to) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | for (i = 0; i < num; i++) { |
| 216 | if (strcmp(names[i], name)) |
| 217 | continue; |
| 218 | table[i] = to * HZ; |
| 219 | return 0; |
| 220 | } |
| 221 | return -ENOENT; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | const char * ip_vs_state_name(__u16 proto, int state) |
| 226 | { |
| 227 | struct ip_vs_protocol *pp = ip_vs_proto_get(proto); |
| 228 | |
| 229 | if (pp == NULL || pp->state_name == NULL) |
Julian Anastasov | 2ad17de | 2008-04-29 03:21:23 -0700 | [diff] [blame] | 230 | return (IPPROTO_IP == proto) ? "NONE" : "ERR!"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | return pp->state_name(state); |
| 232 | } |
| 233 | |
| 234 | |
Sven Wegener | 77eb851 | 2008-09-05 14:43:00 +0200 | [diff] [blame] | 235 | static void |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 236 | ip_vs_tcpudp_debug_packet_v4(struct ip_vs_protocol *pp, |
| 237 | const struct sk_buff *skb, |
| 238 | int offset, |
| 239 | const char *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
| 241 | char buf[128]; |
| 242 | struct iphdr _iph, *ih; |
| 243 | |
| 244 | ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph); |
| 245 | if (ih == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 246 | sprintf(buf, "TRUNCATED"); |
YOSHIFUJI Hideaki | 5661df7 | 2007-12-12 03:53:11 +0900 | [diff] [blame] | 247 | else if (ih->frag_off & htons(IP_OFFSET)) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 248 | sprintf(buf, "%pI4->%pI4 frag", &ih->saddr, &ih->daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | else { |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 250 | __be16 _ports[2], *pptr; |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | pptr = skb_header_pointer(skb, offset + ih->ihl*4, |
| 253 | sizeof(_ports), _ports); |
| 254 | if (pptr == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 255 | sprintf(buf, "TRUNCATED %pI4->%pI4", |
| 256 | &ih->saddr, &ih->daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | else |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 258 | sprintf(buf, "%pI4:%u->%pI4:%u", |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 259 | &ih->saddr, ntohs(pptr[0]), |
| 260 | &ih->daddr, ntohs(pptr[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 263 | pr_debug("%s: %s %s\n", msg, pp->name, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 266 | #ifdef CONFIG_IP_VS_IPV6 |
Sven Wegener | 77eb851 | 2008-09-05 14:43:00 +0200 | [diff] [blame] | 267 | static void |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 268 | ip_vs_tcpudp_debug_packet_v6(struct ip_vs_protocol *pp, |
| 269 | const struct sk_buff *skb, |
| 270 | int offset, |
| 271 | const char *msg) |
| 272 | { |
| 273 | char buf[192]; |
| 274 | struct ipv6hdr _iph, *ih; |
| 275 | |
| 276 | ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph); |
| 277 | if (ih == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 278 | sprintf(buf, "TRUNCATED"); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 279 | else if (ih->nexthdr == IPPROTO_FRAGMENT) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 280 | sprintf(buf, "%pI6->%pI6 frag", &ih->saddr, &ih->daddr); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 281 | else { |
| 282 | __be16 _ports[2], *pptr; |
| 283 | |
| 284 | pptr = skb_header_pointer(skb, offset + sizeof(struct ipv6hdr), |
| 285 | sizeof(_ports), _ports); |
| 286 | if (pptr == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 287 | sprintf(buf, "TRUNCATED %pI6->%pI6", |
| 288 | &ih->saddr, &ih->daddr); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 289 | else |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 290 | sprintf(buf, "%pI6:%u->%pI6:%u", |
Harvey Harrison | 38ff4fa | 2008-10-28 16:08:13 -0700 | [diff] [blame] | 291 | &ih->saddr, ntohs(pptr[0]), |
| 292 | &ih->daddr, ntohs(pptr[1])); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 295 | pr_debug("%s: %s %s\n", msg, pp->name, buf); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 296 | } |
| 297 | #endif |
| 298 | |
| 299 | |
| 300 | void |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 301 | ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 302 | const struct sk_buff *skb, |
| 303 | int offset, |
| 304 | const char *msg) |
| 305 | { |
| 306 | #ifdef CONFIG_IP_VS_IPV6 |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 307 | if (af == AF_INET6) |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 308 | ip_vs_tcpudp_debug_packet_v6(pp, skb, offset, msg); |
| 309 | else |
| 310 | #endif |
| 311 | ip_vs_tcpudp_debug_packet_v4(pp, skb, offset, msg); |
| 312 | } |
| 313 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 314 | /* |
| 315 | * per network name-space init |
| 316 | */ |
Hans Schillstrom | 503cf15 | 2011-05-01 18:50:16 +0200 | [diff] [blame] | 317 | int __net_init ip_vs_protocol_net_init(struct net *net) |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 318 | { |
Hans Schillstrom | 4a85b96 | 2011-01-03 14:44:47 +0100 | [diff] [blame] | 319 | #ifdef CONFIG_IP_VS_PROTO_TCP |
| 320 | register_ip_vs_proto_netns(net, &ip_vs_protocol_tcp); |
| 321 | #endif |
Hans Schillstrom | 78b16bd | 2011-01-03 14:44:48 +0100 | [diff] [blame] | 322 | #ifdef CONFIG_IP_VS_PROTO_UDP |
| 323 | register_ip_vs_proto_netns(net, &ip_vs_protocol_udp); |
| 324 | #endif |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 325 | #ifdef CONFIG_IP_VS_PROTO_SCTP |
| 326 | register_ip_vs_proto_netns(net, &ip_vs_protocol_sctp); |
| 327 | #endif |
Hans Schillstrom | 88fe2d3 | 2011-01-03 14:44:50 +0100 | [diff] [blame] | 328 | #ifdef CONFIG_IP_VS_PROTO_AH |
| 329 | register_ip_vs_proto_netns(net, &ip_vs_protocol_ah); |
| 330 | #endif |
| 331 | #ifdef CONFIG_IP_VS_PROTO_ESP |
| 332 | register_ip_vs_proto_netns(net, &ip_vs_protocol_esp); |
| 333 | #endif |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
Hans Schillstrom | 503cf15 | 2011-05-01 18:50:16 +0200 | [diff] [blame] | 337 | void __net_exit ip_vs_protocol_net_cleanup(struct net *net) |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 338 | { |
Hans Schillstrom | 4a85b96 | 2011-01-03 14:44:47 +0100 | [diff] [blame] | 339 | struct netns_ipvs *ipvs = net_ipvs(net); |
| 340 | struct ip_vs_proto_data *pd; |
| 341 | int i; |
| 342 | |
| 343 | /* unregister all the ipvs proto data for this netns */ |
| 344 | for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) { |
| 345 | while ((pd = ipvs->proto_data_table[i]) != NULL) |
| 346 | unregister_ip_vs_proto_netns(net, pd); |
| 347 | } |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 348 | } |
| 349 | |
Sven Wegener | 048cf48 | 2008-08-10 18:24:35 +0000 | [diff] [blame] | 350 | int __init ip_vs_protocol_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | { |
| 352 | char protocols[64]; |
| 353 | #define REGISTER_PROTOCOL(p) \ |
| 354 | do { \ |
| 355 | register_ip_vs_protocol(p); \ |
| 356 | strcat(protocols, ", "); \ |
| 357 | strcat(protocols, (p)->name); \ |
| 358 | } while (0) |
| 359 | |
| 360 | protocols[0] = '\0'; |
| 361 | protocols[2] = '\0'; |
| 362 | #ifdef CONFIG_IP_VS_PROTO_TCP |
| 363 | REGISTER_PROTOCOL(&ip_vs_protocol_tcp); |
| 364 | #endif |
| 365 | #ifdef CONFIG_IP_VS_PROTO_UDP |
| 366 | REGISTER_PROTOCOL(&ip_vs_protocol_udp); |
| 367 | #endif |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 368 | #ifdef CONFIG_IP_VS_PROTO_SCTP |
| 369 | REGISTER_PROTOCOL(&ip_vs_protocol_sctp); |
| 370 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | #ifdef CONFIG_IP_VS_PROTO_AH |
| 372 | REGISTER_PROTOCOL(&ip_vs_protocol_ah); |
| 373 | #endif |
| 374 | #ifdef CONFIG_IP_VS_PROTO_ESP |
| 375 | REGISTER_PROTOCOL(&ip_vs_protocol_esp); |
| 376 | #endif |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 377 | pr_info("Registered protocols (%s)\n", &protocols[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | void ip_vs_protocol_cleanup(void) |
| 384 | { |
| 385 | struct ip_vs_protocol *pp; |
| 386 | int i; |
| 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* unregister all the ipvs protocols */ |
| 389 | for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) { |
| 390 | while ((pp = ip_vs_proto_table[i]) != NULL) |
| 391 | unregister_ip_vs_protocol(pp); |
| 392 | } |
| 393 | } |