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 | { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 51 | unsigned int hash = IP_VS_PROTO_HASH(pp->protocol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 62 | /* |
| 63 | * register an ipvs protocols netns related data |
| 64 | */ |
| 65 | static int |
Eric W. Biederman | c70bd680 | 2015-09-21 13:02:35 -0500 | [diff] [blame] | 66 | register_ip_vs_proto_netns(struct netns_ipvs *ipvs, struct ip_vs_protocol *pp) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 67 | { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 68 | unsigned int hash = IP_VS_PROTO_HASH(pp->protocol); |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 69 | struct ip_vs_proto_data *pd = |
Sasha Levin | 9615e61e | 2012-04-14 12:37:47 -0400 | [diff] [blame] | 70 | kzalloc(sizeof(struct ip_vs_proto_data), GFP_KERNEL); |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 71 | |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 72 | if (!pd) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 73 | return -ENOMEM; |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 74 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 75 | pd->pp = pp; /* For speed issues */ |
| 76 | pd->next = ipvs->proto_data_table[hash]; |
| 77 | ipvs->proto_data_table[hash] = pd; |
| 78 | atomic_set(&pd->appcnt, 0); /* Init app counter */ |
| 79 | |
Hans Schillstrom | 582b8e3 | 2012-04-26 09:45:35 +0200 | [diff] [blame] | 80 | if (pp->init_netns != NULL) { |
Eric W. Biederman | 1281a9c2 | 2015-09-21 13:02:36 -0500 | [diff] [blame] | 81 | int ret = pp->init_netns(ipvs, pd); |
Hans Schillstrom | 582b8e3 | 2012-04-26 09:45:35 +0200 | [diff] [blame] | 82 | if (ret) { |
| 83 | /* unlink an free proto data */ |
| 84 | ipvs->proto_data_table[hash] = pd->next; |
| 85 | kfree(pd); |
| 86 | return ret; |
| 87 | } |
| 88 | } |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * unregister an ipvs protocol |
| 95 | */ |
| 96 | static int unregister_ip_vs_protocol(struct ip_vs_protocol *pp) |
| 97 | { |
| 98 | struct ip_vs_protocol **pp_p; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 99 | unsigned int hash = IP_VS_PROTO_HASH(pp->protocol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | pp_p = &ip_vs_proto_table[hash]; |
| 102 | for (; *pp_p; pp_p = &(*pp_p)->next) { |
| 103 | if (*pp_p == pp) { |
| 104 | *pp_p = pp->next; |
| 105 | if (pp->exit != NULL) |
| 106 | pp->exit(pp); |
| 107 | return 0; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return -ESRCH; |
| 112 | } |
| 113 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 114 | /* |
| 115 | * unregister an ipvs protocols netns data |
| 116 | */ |
| 117 | static int |
Eric W. Biederman | c70bd680 | 2015-09-21 13:02:35 -0500 | [diff] [blame] | 118 | unregister_ip_vs_proto_netns(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 119 | { |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 120 | struct ip_vs_proto_data **pd_p; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 121 | unsigned int hash = IP_VS_PROTO_HASH(pd->pp->protocol); |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 122 | |
| 123 | pd_p = &ipvs->proto_data_table[hash]; |
| 124 | for (; *pd_p; pd_p = &(*pd_p)->next) { |
| 125 | if (*pd_p == pd) { |
| 126 | *pd_p = pd->next; |
| 127 | if (pd->pp->exit_netns != NULL) |
Eric W. Biederman | 1281a9c2 | 2015-09-21 13:02:36 -0500 | [diff] [blame] | 128 | pd->pp->exit_netns(ipvs, pd); |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 129 | kfree(pd); |
| 130 | return 0; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return -ESRCH; |
| 135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * get ip_vs_protocol object by its proto. |
| 139 | */ |
| 140 | struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto) |
| 141 | { |
| 142 | struct ip_vs_protocol *pp; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 143 | unsigned int hash = IP_VS_PROTO_HASH(proto); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | for (pp = ip_vs_proto_table[hash]; pp; pp = pp->next) { |
| 146 | if (pp->protocol == proto) |
| 147 | return pp; |
| 148 | } |
| 149 | |
| 150 | return NULL; |
| 151 | } |
Hannes Eder | 9c3e1c3 | 2010-07-23 12:42:58 +0200 | [diff] [blame] | 152 | EXPORT_SYMBOL(ip_vs_proto_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 154 | /* |
| 155 | * get ip_vs_protocol object data by netns and proto |
| 156 | */ |
Eric W. Biederman | 18d6ade | 2015-09-21 13:02:01 -0500 | [diff] [blame] | 157 | struct ip_vs_proto_data * |
| 158 | ip_vs_proto_data_get(struct netns_ipvs *ipvs, unsigned short proto) |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 159 | { |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 160 | struct ip_vs_proto_data *pd; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 161 | unsigned int hash = IP_VS_PROTO_HASH(proto); |
Hans Schillstrom | 252c641 | 2011-01-03 14:44:46 +0100 | [diff] [blame] | 162 | |
| 163 | for (pd = ipvs->proto_data_table[hash]; pd; pd = pd->next) { |
| 164 | if (pd->pp->protocol == proto) |
| 165 | return pd; |
| 166 | } |
| 167 | |
| 168 | return NULL; |
| 169 | } |
| 170 | EXPORT_SYMBOL(ip_vs_proto_data_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * Propagate event for state change to all protocols |
| 174 | */ |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 175 | void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 177 | struct ip_vs_proto_data *pd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | int i; |
| 179 | |
| 180 | for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) { |
Hans Schillstrom | 9330419 | 2011-01-03 14:44:51 +0100 | [diff] [blame] | 181 | for (pd = ipvs->proto_data_table[i]; pd; pd = pd->next) { |
| 182 | if (pd->pp->timeout_change) |
| 183 | pd->pp->timeout_change(pd, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 | int * |
| 190 | ip_vs_create_timeout_table(int *table, int size) |
| 191 | { |
Julian Anastasov | 41cff6d | 2012-04-13 16:49:37 +0300 | [diff] [blame] | 192 | return kmemdup(table, size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | /* |
| 197 | * Set timeout value for state specified by name |
| 198 | */ |
| 199 | int |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 200 | ip_vs_set_state_timeout(int *table, int num, const char *const *names, |
| 201 | const char *name, int to) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
| 203 | int i; |
| 204 | |
| 205 | if (!table || !name || !to) |
| 206 | return -EINVAL; |
| 207 | |
| 208 | for (i = 0; i < num; i++) { |
| 209 | if (strcmp(names[i], name)) |
| 210 | continue; |
| 211 | table[i] = to * HZ; |
| 212 | return 0; |
| 213 | } |
| 214 | return -ENOENT; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | const char * ip_vs_state_name(__u16 proto, int state) |
| 219 | { |
| 220 | struct ip_vs_protocol *pp = ip_vs_proto_get(proto); |
| 221 | |
| 222 | if (pp == NULL || pp->state_name == NULL) |
Julian Anastasov | 2ad17de | 2008-04-29 03:21:23 -0700 | [diff] [blame] | 223 | return (IPPROTO_IP == proto) ? "NONE" : "ERR!"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return pp->state_name(state); |
| 225 | } |
| 226 | |
| 227 | |
Sven Wegener | 77eb851 | 2008-09-05 14:43:00 +0200 | [diff] [blame] | 228 | static void |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 229 | ip_vs_tcpudp_debug_packet_v4(struct ip_vs_protocol *pp, |
| 230 | const struct sk_buff *skb, |
| 231 | int offset, |
| 232 | const char *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
| 234 | char buf[128]; |
| 235 | struct iphdr _iph, *ih; |
| 236 | |
| 237 | ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph); |
| 238 | if (ih == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 239 | sprintf(buf, "TRUNCATED"); |
YOSHIFUJI Hideaki | 5661df7 | 2007-12-12 03:53:11 +0900 | [diff] [blame] | 240 | else if (ih->frag_off & htons(IP_OFFSET)) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 241 | sprintf(buf, "%pI4->%pI4 frag", &ih->saddr, &ih->daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | else { |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 243 | __be16 _ports[2], *pptr; |
| 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | pptr = skb_header_pointer(skb, offset + ih->ihl*4, |
| 246 | sizeof(_ports), _ports); |
| 247 | if (pptr == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 248 | sprintf(buf, "TRUNCATED %pI4->%pI4", |
| 249 | &ih->saddr, &ih->daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | else |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 251 | sprintf(buf, "%pI4:%u->%pI4:%u", |
Harvey Harrison | 14d5e83 | 2008-10-31 00:54:29 -0700 | [diff] [blame] | 252 | &ih->saddr, ntohs(pptr[0]), |
| 253 | &ih->daddr, ntohs(pptr[1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 256 | pr_debug("%s: %s %s\n", msg, pp->name, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 259 | #ifdef CONFIG_IP_VS_IPV6 |
Sven Wegener | 77eb851 | 2008-09-05 14:43:00 +0200 | [diff] [blame] | 260 | static void |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 261 | ip_vs_tcpudp_debug_packet_v6(struct ip_vs_protocol *pp, |
| 262 | const struct sk_buff *skb, |
| 263 | int offset, |
| 264 | const char *msg) |
| 265 | { |
| 266 | char buf[192]; |
| 267 | struct ipv6hdr _iph, *ih; |
| 268 | |
| 269 | ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph); |
| 270 | if (ih == NULL) |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 271 | sprintf(buf, "TRUNCATED"); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 272 | else if (ih->nexthdr == IPPROTO_FRAGMENT) |
Jesper Dangaard Brouer | 120b9c1 | 2012-09-26 14:05:53 +0200 | [diff] [blame] | 273 | sprintf(buf, "%pI6c->%pI6c frag", &ih->saddr, &ih->daddr); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 274 | else { |
| 275 | __be16 _ports[2], *pptr; |
| 276 | |
| 277 | pptr = skb_header_pointer(skb, offset + sizeof(struct ipv6hdr), |
| 278 | sizeof(_ports), _ports); |
| 279 | if (pptr == NULL) |
Jesper Dangaard Brouer | 120b9c1 | 2012-09-26 14:05:53 +0200 | [diff] [blame] | 280 | sprintf(buf, "TRUNCATED %pI6c->%pI6c", |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 281 | &ih->saddr, &ih->daddr); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 282 | else |
Jesper Dangaard Brouer | 120b9c1 | 2012-09-26 14:05:53 +0200 | [diff] [blame] | 283 | sprintf(buf, "%pI6c:%u->%pI6c:%u", |
Harvey Harrison | 38ff4fa | 2008-10-28 16:08:13 -0700 | [diff] [blame] | 284 | &ih->saddr, ntohs(pptr[0]), |
| 285 | &ih->daddr, ntohs(pptr[1])); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Patrick McHardy | 3d91c1a | 2010-04-08 13:35:47 +0200 | [diff] [blame] | 288 | pr_debug("%s: %s %s\n", msg, pp->name, buf); |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 289 | } |
| 290 | #endif |
| 291 | |
| 292 | |
| 293 | void |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 294 | ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 295 | const struct sk_buff *skb, |
| 296 | int offset, |
| 297 | const char *msg) |
| 298 | { |
| 299 | #ifdef CONFIG_IP_VS_IPV6 |
Julian Anastasov | 0d79641 | 2010-10-17 16:46:17 +0300 | [diff] [blame] | 300 | if (af == AF_INET6) |
Julius Volz | 3b047d9 | 2008-09-02 15:55:41 +0200 | [diff] [blame] | 301 | ip_vs_tcpudp_debug_packet_v6(pp, skb, offset, msg); |
| 302 | else |
| 303 | #endif |
| 304 | ip_vs_tcpudp_debug_packet_v4(pp, skb, offset, msg); |
| 305 | } |
| 306 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 307 | /* |
| 308 | * per network name-space init |
| 309 | */ |
Eric W. Biederman | 7d1f88e | 2015-09-21 13:02:58 -0500 | [diff] [blame] | 310 | int __net_init ip_vs_protocol_net_init(struct netns_ipvs *ipvs) |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 311 | { |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 312 | int i, ret; |
| 313 | static struct ip_vs_protocol *protos[] = { |
Hans Schillstrom | 4a85b96 | 2011-01-03 14:44:47 +0100 | [diff] [blame] | 314 | #ifdef CONFIG_IP_VS_PROTO_TCP |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 315 | &ip_vs_protocol_tcp, |
Hans Schillstrom | 4a85b96 | 2011-01-03 14:44:47 +0100 | [diff] [blame] | 316 | #endif |
Hans Schillstrom | 78b16bd | 2011-01-03 14:44:48 +0100 | [diff] [blame] | 317 | #ifdef CONFIG_IP_VS_PROTO_UDP |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 318 | &ip_vs_protocol_udp, |
Hans Schillstrom | 78b16bd | 2011-01-03 14:44:48 +0100 | [diff] [blame] | 319 | #endif |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 320 | #ifdef CONFIG_IP_VS_PROTO_SCTP |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 321 | &ip_vs_protocol_sctp, |
Hans Schillstrom | 9d93487 | 2011-01-03 14:44:49 +0100 | [diff] [blame] | 322 | #endif |
Hans Schillstrom | 88fe2d3 | 2011-01-03 14:44:50 +0100 | [diff] [blame] | 323 | #ifdef CONFIG_IP_VS_PROTO_AH |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 324 | &ip_vs_protocol_ah, |
Hans Schillstrom | 88fe2d3 | 2011-01-03 14:44:50 +0100 | [diff] [blame] | 325 | #endif |
| 326 | #ifdef CONFIG_IP_VS_PROTO_ESP |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 327 | &ip_vs_protocol_esp, |
Hans Schillstrom | 88fe2d3 | 2011-01-03 14:44:50 +0100 | [diff] [blame] | 328 | #endif |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | for (i = 0; i < ARRAY_SIZE(protos); i++) { |
Eric W. Biederman | c70bd680 | 2015-09-21 13:02:35 -0500 | [diff] [blame] | 332 | ret = register_ip_vs_proto_netns(ipvs, protos[i]); |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 333 | if (ret < 0) |
| 334 | goto cleanup; |
| 335 | } |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 336 | return 0; |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 337 | |
| 338 | cleanup: |
Eric W. Biederman | 7d1f88e | 2015-09-21 13:02:58 -0500 | [diff] [blame] | 339 | ip_vs_protocol_net_cleanup(ipvs); |
Sasha Levin | 7118c07 | 2012-04-14 12:37:46 -0400 | [diff] [blame] | 340 | return ret; |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Eric W. Biederman | 7d1f88e | 2015-09-21 13:02:58 -0500 | [diff] [blame] | 343 | void __net_exit ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs) |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 344 | { |
Hans Schillstrom | 4a85b96 | 2011-01-03 14:44:47 +0100 | [diff] [blame] | 345 | struct ip_vs_proto_data *pd; |
| 346 | int i; |
| 347 | |
| 348 | /* unregister all the ipvs proto data for this netns */ |
| 349 | for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) { |
| 350 | while ((pd = ipvs->proto_data_table[i]) != NULL) |
Eric W. Biederman | c70bd680 | 2015-09-21 13:02:35 -0500 | [diff] [blame] | 351 | unregister_ip_vs_proto_netns(ipvs, pd); |
Hans Schillstrom | 4a85b96 | 2011-01-03 14:44:47 +0100 | [diff] [blame] | 352 | } |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Sven Wegener | 048cf48 | 2008-08-10 18:24:35 +0000 | [diff] [blame] | 355 | int __init ip_vs_protocol_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
| 357 | char protocols[64]; |
| 358 | #define REGISTER_PROTOCOL(p) \ |
| 359 | do { \ |
| 360 | register_ip_vs_protocol(p); \ |
| 361 | strcat(protocols, ", "); \ |
| 362 | strcat(protocols, (p)->name); \ |
| 363 | } while (0) |
| 364 | |
| 365 | protocols[0] = '\0'; |
| 366 | protocols[2] = '\0'; |
| 367 | #ifdef CONFIG_IP_VS_PROTO_TCP |
| 368 | REGISTER_PROTOCOL(&ip_vs_protocol_tcp); |
| 369 | #endif |
| 370 | #ifdef CONFIG_IP_VS_PROTO_UDP |
| 371 | REGISTER_PROTOCOL(&ip_vs_protocol_udp); |
| 372 | #endif |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 373 | #ifdef CONFIG_IP_VS_PROTO_SCTP |
| 374 | REGISTER_PROTOCOL(&ip_vs_protocol_sctp); |
| 375 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | #ifdef CONFIG_IP_VS_PROTO_AH |
| 377 | REGISTER_PROTOCOL(&ip_vs_protocol_ah); |
| 378 | #endif |
| 379 | #ifdef CONFIG_IP_VS_PROTO_ESP |
| 380 | REGISTER_PROTOCOL(&ip_vs_protocol_esp); |
| 381 | #endif |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 382 | pr_info("Registered protocols (%s)\n", &protocols[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | |
| 388 | void ip_vs_protocol_cleanup(void) |
| 389 | { |
| 390 | struct ip_vs_protocol *pp; |
| 391 | int i; |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | /* unregister all the ipvs protocols */ |
| 394 | for (i = 0; i < IP_VS_PROTO_TAB_SIZE; i++) { |
| 395 | while ((pp = ip_vs_proto_table[i]) != NULL) |
| 396 | unregister_ip_vs_protocol(pp); |
| 397 | } |
| 398 | } |