blob: 5ab54f648654e4a7e02618180d0a85ebb91be76d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ip_vs_proto_udp.c: UDP load balancing support for IPVS
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Eder9aada7a2009-07-30 14:29:44 -070016#define KMSG_COMPONENT "IPVS"
17#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
18
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020019#include <linux/in.h>
20#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/kernel.h>
Herbert Xuaf1e1cf2007-10-14 00:39:33 -070022#include <linux/netfilter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/netfilter_ipv4.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020024#include <linux/udp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <net/ip_vs.h>
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -030027#include <net/ip.h>
Stephen Rothwell63f2c042008-09-12 23:23:50 -070028#include <net/ip6_checksum.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int
Julius Volz51ef3482008-09-02 15:55:40 +020031udp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 int *verdict, struct ip_vs_conn **cpp)
33{
Hans Schillstromfc723252011-01-03 14:44:43 +010034 struct net *net;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 struct ip_vs_service *svc;
36 struct udphdr _udph, *uh;
Julius Volz3c2e0502008-09-02 15:55:38 +020037 struct ip_vs_iphdr iph;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Julius Volz51ef3482008-09-02 15:55:40 +020039 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
Julius Volz3c2e0502008-09-02 15:55:38 +020040
41 uh = skb_header_pointer(skb, iph.len, sizeof(_udph), &_udph);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 if (uh == NULL) {
43 *verdict = NF_DROP;
44 return 0;
45 }
Hans Schillstromfc723252011-01-03 14:44:43 +010046 net = skb_net(skb);
47 svc = ip_vs_service_get(net, af, skb->mark, iph.protocol,
Julius Volz3c2e0502008-09-02 15:55:38 +020048 &iph.daddr, uh->dest);
49 if (svc) {
Julian Anastasov190ecd22010-10-17 16:24:37 +030050 int ignored;
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 if (ip_vs_todrop()) {
53 /*
54 * It seems that we are very loaded.
55 * We have to drop this packet :(
56 */
57 ip_vs_service_put(svc);
58 *verdict = NF_DROP;
59 return 0;
60 }
61
62 /*
63 * Let the virtual server select a real server for the
64 * incoming connection, and create a connection entry.
65 */
Julian Anastasov190ecd22010-10-17 16:24:37 +030066 *cpp = ip_vs_schedule(svc, skb, pp, &ignored);
Hans Schillstroma5959d52010-11-19 14:25:10 +010067 if (!*cpp && ignored <= 0) {
68 if (!ignored)
69 *verdict = ip_vs_leave(svc, skb, pp);
70 else {
71 ip_vs_service_put(svc);
72 *verdict = NF_DROP;
73 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return 0;
75 }
76 ip_vs_service_put(svc);
77 }
Hans Schillstroma5959d52010-11-19 14:25:10 +010078 /* NF_ACCEPT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return 1;
80}
81
82
83static inline void
Julius Volz0bbdd422008-09-02 15:55:42 +020084udp_fast_csum_update(int af, struct udphdr *uhdr,
85 const union nf_inet_addr *oldip,
86 const union nf_inet_addr *newip,
Al Viro014d7302006-09-28 14:29:52 -070087 __be16 oldport, __be16 newport)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Julius Volz0bbdd422008-09-02 15:55:42 +020089#ifdef CONFIG_IP_VS_IPV6
90 if (af == AF_INET6)
91 uhdr->check =
92 csum_fold(ip_vs_check_diff16(oldip->ip6, newip->ip6,
93 ip_vs_check_diff2(oldport, newport,
94 ~csum_unfold(uhdr->check))));
95 else
96#endif
97 uhdr->check =
98 csum_fold(ip_vs_check_diff4(oldip->ip, newip->ip,
99 ip_vs_check_diff2(oldport, newport,
100 ~csum_unfold(uhdr->check))));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 if (!uhdr->check)
Al Virof6ab0282006-11-16 02:36:50 -0800102 uhdr->check = CSUM_MANGLED_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Simon Horman503e81f2008-09-08 12:04:21 +1000105static inline void
106udp_partial_csum_update(int af, struct udphdr *uhdr,
107 const union nf_inet_addr *oldip,
108 const union nf_inet_addr *newip,
109 __be16 oldlen, __be16 newlen)
110{
111#ifdef CONFIG_IP_VS_IPV6
112 if (af == AF_INET6)
113 uhdr->check =
Julian Anastasov5bc90682010-10-17 16:14:31 +0300114 ~csum_fold(ip_vs_check_diff16(oldip->ip6, newip->ip6,
Simon Horman503e81f2008-09-08 12:04:21 +1000115 ip_vs_check_diff2(oldlen, newlen,
Julian Anastasov5bc90682010-10-17 16:14:31 +0300116 csum_unfold(uhdr->check))));
Simon Horman503e81f2008-09-08 12:04:21 +1000117 else
118#endif
119 uhdr->check =
Julian Anastasov5bc90682010-10-17 16:14:31 +0300120 ~csum_fold(ip_vs_check_diff4(oldip->ip, newip->ip,
Simon Horman503e81f2008-09-08 12:04:21 +1000121 ip_vs_check_diff2(oldlen, newlen,
Julian Anastasov5bc90682010-10-17 16:14:31 +0300122 csum_unfold(uhdr->check))));
Simon Horman503e81f2008-09-08 12:04:21 +1000123}
124
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static int
Herbert Xu3db05fe2007-10-15 00:53:15 -0700127udp_snat_handler(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
129{
130 struct udphdr *udph;
Julius Volz0bbdd422008-09-02 15:55:42 +0200131 unsigned int udphoff;
Simon Horman503e81f2008-09-08 12:04:21 +1000132 int oldlen;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300133 int payload_csum = 0;
Julius Volz0bbdd422008-09-02 15:55:42 +0200134
135#ifdef CONFIG_IP_VS_IPV6
136 if (cp->af == AF_INET6)
137 udphoff = sizeof(struct ipv6hdr);
138 else
139#endif
140 udphoff = ip_hdrlen(skb);
Simon Horman503e81f2008-09-08 12:04:21 +1000141 oldlen = skb->len - udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* csum_check requires unshared skb */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700144 if (!skb_make_writable(skb, udphoff+sizeof(*udph)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return 0;
146
147 if (unlikely(cp->app != NULL)) {
Julian Anastasov8b27b102010-10-17 16:17:20 +0300148 int ret;
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* Some checks before mangling */
Julius Volz0bbdd422008-09-02 15:55:42 +0200151 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 return 0;
153
154 /*
155 * Call application helper if needed
156 */
Julian Anastasov8b27b102010-10-17 16:17:20 +0300157 if (!(ret = ip_vs_app_pkt_out(cp, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return 0;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300159 /* ret=2: csum update is needed after payload mangling */
160 if (ret == 1)
161 oldlen = skb->len - udphoff;
162 else
163 payload_csum = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
Julius Volz0bbdd422008-09-02 15:55:42 +0200166 udph = (void *)skb_network_header(skb) + udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 udph->source = cp->vport;
168
169 /*
170 * Adjust UDP checksums
171 */
Simon Horman503e81f2008-09-08 12:04:21 +1000172 if (skb->ip_summed == CHECKSUM_PARTIAL) {
173 udp_partial_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
Harvey Harrisonca620592008-11-06 23:09:56 -0800174 htons(oldlen),
175 htons(skb->len - udphoff));
Julian Anastasov8b27b102010-10-17 16:17:20 +0300176 } else if (!payload_csum && (udph->check != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* Only port and addr are changed, do fast csum update */
Julius Volz0bbdd422008-09-02 15:55:42 +0200178 udp_fast_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 cp->dport, cp->vport);
Herbert Xu3db05fe2007-10-15 00:53:15 -0700180 if (skb->ip_summed == CHECKSUM_COMPLETE)
Julian Anastasov8b27b102010-10-17 16:17:20 +0300181 skb->ip_summed = (cp->app && pp->csum_check) ?
182 CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 } else {
184 /* full checksum calculation */
185 udph->check = 0;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700186 skb->csum = skb_checksum(skb, udphoff, skb->len - udphoff, 0);
Julius Volz0bbdd422008-09-02 15:55:42 +0200187#ifdef CONFIG_IP_VS_IPV6
188 if (cp->af == AF_INET6)
189 udph->check = csum_ipv6_magic(&cp->vaddr.in6,
190 &cp->caddr.in6,
191 skb->len - udphoff,
192 cp->protocol, skb->csum);
193 else
194#endif
195 udph->check = csum_tcpudp_magic(cp->vaddr.ip,
196 cp->caddr.ip,
197 skb->len - udphoff,
198 cp->protocol,
199 skb->csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 if (udph->check == 0)
Al Virof6ab0282006-11-16 02:36:50 -0800201 udph->check = CSUM_MANGLED_0;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300202 skb->ip_summed = CHECKSUM_UNNECESSARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 IP_VS_DBG(11, "O-pkt: %s O-csum=%d (+%zd)\n",
204 pp->name, udph->check,
205 (char*)&(udph->check) - (char*)udph);
206 }
207 return 1;
208}
209
210
211static int
Herbert Xu3db05fe2007-10-15 00:53:15 -0700212udp_dnat_handler(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
214{
215 struct udphdr *udph;
Julius Volz0bbdd422008-09-02 15:55:42 +0200216 unsigned int udphoff;
Simon Horman503e81f2008-09-08 12:04:21 +1000217 int oldlen;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300218 int payload_csum = 0;
Julius Volz0bbdd422008-09-02 15:55:42 +0200219
220#ifdef CONFIG_IP_VS_IPV6
221 if (cp->af == AF_INET6)
222 udphoff = sizeof(struct ipv6hdr);
223 else
224#endif
225 udphoff = ip_hdrlen(skb);
Simon Horman503e81f2008-09-08 12:04:21 +1000226 oldlen = skb->len - udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* csum_check requires unshared skb */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700229 if (!skb_make_writable(skb, udphoff+sizeof(*udph)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return 0;
231
232 if (unlikely(cp->app != NULL)) {
Julian Anastasov8b27b102010-10-17 16:17:20 +0300233 int ret;
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 /* Some checks before mangling */
Julius Volz0bbdd422008-09-02 15:55:42 +0200236 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return 0;
238
239 /*
240 * Attempt ip_vs_app call.
241 * It will fix ip_vs_conn
242 */
Julian Anastasov8b27b102010-10-17 16:17:20 +0300243 if (!(ret = ip_vs_app_pkt_in(cp, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return 0;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300245 /* ret=2: csum update is needed after payload mangling */
246 if (ret == 1)
247 oldlen = skb->len - udphoff;
248 else
249 payload_csum = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251
Julius Volz0bbdd422008-09-02 15:55:42 +0200252 udph = (void *)skb_network_header(skb) + udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 udph->dest = cp->dport;
254
255 /*
256 * Adjust UDP checksums
257 */
Simon Horman503e81f2008-09-08 12:04:21 +1000258 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Julian Anastasov5bc90682010-10-17 16:14:31 +0300259 udp_partial_csum_update(cp->af, udph, &cp->vaddr, &cp->daddr,
Harvey Harrisonca620592008-11-06 23:09:56 -0800260 htons(oldlen),
261 htons(skb->len - udphoff));
Julian Anastasov8b27b102010-10-17 16:17:20 +0300262 } else if (!payload_csum && (udph->check != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /* Only port and addr are changed, do fast csum update */
Julius Volz0bbdd422008-09-02 15:55:42 +0200264 udp_fast_csum_update(cp->af, udph, &cp->vaddr, &cp->daddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 cp->vport, cp->dport);
Herbert Xu3db05fe2007-10-15 00:53:15 -0700266 if (skb->ip_summed == CHECKSUM_COMPLETE)
Julian Anastasov8b27b102010-10-17 16:17:20 +0300267 skb->ip_summed = (cp->app && pp->csum_check) ?
268 CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 } else {
270 /* full checksum calculation */
271 udph->check = 0;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700272 skb->csum = skb_checksum(skb, udphoff, skb->len - udphoff, 0);
Julius Volz0bbdd422008-09-02 15:55:42 +0200273#ifdef CONFIG_IP_VS_IPV6
274 if (cp->af == AF_INET6)
275 udph->check = csum_ipv6_magic(&cp->caddr.in6,
276 &cp->daddr.in6,
277 skb->len - udphoff,
278 cp->protocol, skb->csum);
279 else
280#endif
281 udph->check = csum_tcpudp_magic(cp->caddr.ip,
282 cp->daddr.ip,
283 skb->len - udphoff,
284 cp->protocol,
285 skb->csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (udph->check == 0)
Al Virof6ab0282006-11-16 02:36:50 -0800287 udph->check = CSUM_MANGLED_0;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700288 skb->ip_summed = CHECKSUM_UNNECESSARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290 return 1;
291}
292
293
294static int
Julius Volz51ef3482008-09-02 15:55:40 +0200295udp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
297 struct udphdr _udph, *uh;
Julius Volz51ef3482008-09-02 15:55:40 +0200298 unsigned int udphoff;
299
300#ifdef CONFIG_IP_VS_IPV6
301 if (af == AF_INET6)
302 udphoff = sizeof(struct ipv6hdr);
303 else
304#endif
305 udphoff = ip_hdrlen(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 uh = skb_header_pointer(skb, udphoff, sizeof(_udph), &_udph);
308 if (uh == NULL)
309 return 0;
310
311 if (uh->check != 0) {
312 switch (skb->ip_summed) {
313 case CHECKSUM_NONE:
314 skb->csum = skb_checksum(skb, udphoff,
315 skb->len - udphoff, 0);
Patrick McHardy84fa7932006-08-29 16:44:56 -0700316 case CHECKSUM_COMPLETE:
Julius Volz51ef3482008-09-02 15:55:40 +0200317#ifdef CONFIG_IP_VS_IPV6
318 if (af == AF_INET6) {
319 if (csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
320 &ipv6_hdr(skb)->daddr,
321 skb->len - udphoff,
322 ipv6_hdr(skb)->nexthdr,
323 skb->csum)) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300324 IP_VS_DBG_RL_PKT(0, af, pp, skb, 0,
Julius Volz51ef3482008-09-02 15:55:40 +0200325 "Failed checksum for");
326 return 0;
327 }
328 } else
329#endif
330 if (csum_tcpudp_magic(ip_hdr(skb)->saddr,
331 ip_hdr(skb)->daddr,
332 skb->len - udphoff,
333 ip_hdr(skb)->protocol,
334 skb->csum)) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300335 IP_VS_DBG_RL_PKT(0, af, pp, skb, 0,
Julius Volz51ef3482008-09-02 15:55:40 +0200336 "Failed checksum for");
337 return 0;
338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 break;
340 default:
Patrick McHardy84fa7932006-08-29 16:44:56 -0700341 /* No need to checksum. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 break;
343 }
344 }
345 return 1;
346}
347
348
349/*
350 * Note: the caller guarantees that only one of register_app,
351 * unregister_app or app_conn_bind is called each time.
352 */
353
354#define UDP_APP_TAB_BITS 4
355#define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
356#define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
357
358static struct list_head udp_apps[UDP_APP_TAB_SIZE];
359static DEFINE_SPINLOCK(udp_app_lock);
360
Al Viro75e7ce62006-11-14 21:13:28 -0800361static inline __u16 udp_app_hashkey(__be16 port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Al Viro75e7ce62006-11-14 21:13:28 -0800363 return (((__force u16)port >> UDP_APP_TAB_BITS) ^ (__force u16)port)
364 & UDP_APP_TAB_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
366
367
368static int udp_register_app(struct ip_vs_app *inc)
369{
370 struct ip_vs_app *i;
Al Viro75e7ce62006-11-14 21:13:28 -0800371 __u16 hash;
372 __be16 port = inc->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 int ret = 0;
374
375 hash = udp_app_hashkey(port);
376
377
378 spin_lock_bh(&udp_app_lock);
379 list_for_each_entry(i, &udp_apps[hash], p_list) {
380 if (i->port == port) {
381 ret = -EEXIST;
382 goto out;
383 }
384 }
385 list_add(&inc->p_list, &udp_apps[hash]);
386 atomic_inc(&ip_vs_protocol_udp.appcnt);
387
388 out:
389 spin_unlock_bh(&udp_app_lock);
390 return ret;
391}
392
393
394static void
395udp_unregister_app(struct ip_vs_app *inc)
396{
397 spin_lock_bh(&udp_app_lock);
398 atomic_dec(&ip_vs_protocol_udp.appcnt);
399 list_del(&inc->p_list);
400 spin_unlock_bh(&udp_app_lock);
401}
402
403
404static int udp_app_conn_bind(struct ip_vs_conn *cp)
405{
406 int hash;
407 struct ip_vs_app *inc;
408 int result = 0;
409
410 /* Default binding: bind app only for NAT */
411 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
412 return 0;
413
414 /* Lookup application incarnations and bind the right one */
415 hash = udp_app_hashkey(cp->vport);
416
417 spin_lock(&udp_app_lock);
418 list_for_each_entry(inc, &udp_apps[hash], p_list) {
419 if (inc->port == cp->vport) {
420 if (unlikely(!ip_vs_app_inc_get(inc)))
421 break;
422 spin_unlock(&udp_app_lock);
423
Hannes Eder1e3e2382009-08-02 11:05:41 +0000424 IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->"
Julius Volzcfc78c52008-09-02 15:55:53 +0200425 "%s:%u to app %s on port %u\n",
426 __func__,
427 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
428 ntohs(cp->cport),
429 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
430 ntohs(cp->vport),
431 inc->name, ntohs(inc->port));
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 cp->app = inc;
434 if (inc->init_conn)
435 result = inc->init_conn(inc, cp);
436 goto out;
437 }
438 }
439 spin_unlock(&udp_app_lock);
440
441 out:
442 return result;
443}
444
445
446static int udp_timeouts[IP_VS_UDP_S_LAST+1] = {
447 [IP_VS_UDP_S_NORMAL] = 5*60*HZ,
448 [IP_VS_UDP_S_LAST] = 2*HZ,
449};
450
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700451static const char *const udp_state_name_table[IP_VS_UDP_S_LAST+1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 [IP_VS_UDP_S_NORMAL] = "UDP",
453 [IP_VS_UDP_S_LAST] = "BUG!",
454};
455
456
457static int
458udp_set_state_timeout(struct ip_vs_protocol *pp, char *sname, int to)
459{
460 return ip_vs_set_state_timeout(pp->timeout_table, IP_VS_UDP_S_LAST,
461 udp_state_name_table, sname, to);
462}
463
464static const char * udp_state_name(int state)
465{
466 if (state >= IP_VS_UDP_S_LAST)
467 return "ERR!";
468 return udp_state_name_table[state] ? udp_state_name_table[state] : "?";
469}
470
471static int
472udp_state_transition(struct ip_vs_conn *cp, int direction,
473 const struct sk_buff *skb,
474 struct ip_vs_protocol *pp)
475{
476 cp->timeout = pp->timeout_table[IP_VS_UDP_S_NORMAL];
477 return 1;
478}
479
480static void udp_init(struct ip_vs_protocol *pp)
481{
482 IP_VS_INIT_HASH_TABLE(udp_apps);
483 pp->timeout_table = udp_timeouts;
484}
485
486static void udp_exit(struct ip_vs_protocol *pp)
487{
488}
489
490
491struct ip_vs_protocol ip_vs_protocol_udp = {
492 .name = "UDP",
493 .protocol = IPPROTO_UDP,
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700494 .num_states = IP_VS_UDP_S_LAST,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .dont_defrag = 0,
496 .init = udp_init,
497 .exit = udp_exit,
498 .conn_schedule = udp_conn_schedule,
Simon Horman5c0d2372010-08-02 17:12:44 +0200499 .conn_in_get = ip_vs_conn_in_get_proto,
500 .conn_out_get = ip_vs_conn_out_get_proto,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .snat_handler = udp_snat_handler,
502 .dnat_handler = udp_dnat_handler,
503 .csum_check = udp_csum_check,
504 .state_transition = udp_state_transition,
505 .state_name = udp_state_name,
506 .register_app = udp_register_app,
507 .unregister_app = udp_unregister_app,
508 .app_conn_bind = udp_app_conn_bind,
509 .debug_packet = ip_vs_tcpudp_debug_packet,
510 .timeout_change = NULL,
511 .set_state_timeout = udp_set_state_timeout,
512};