blob: cd398de010cc8715fa587955b1ec0c557dce6c55 [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{
34 struct ip_vs_service *svc;
35 struct udphdr _udph, *uh;
Julius Volz3c2e0502008-09-02 15:55:38 +020036 struct ip_vs_iphdr iph;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Julius Volz51ef3482008-09-02 15:55:40 +020038 ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
Julius Volz3c2e0502008-09-02 15:55:38 +020039
40 uh = skb_header_pointer(skb, iph.len, sizeof(_udph), &_udph);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 if (uh == NULL) {
42 *verdict = NF_DROP;
43 return 0;
44 }
45
Julius Volz51ef3482008-09-02 15:55:40 +020046 svc = ip_vs_service_get(af, skb->mark, iph.protocol,
Julius Volz3c2e0502008-09-02 15:55:38 +020047 &iph.daddr, uh->dest);
48 if (svc) {
Julian Anastasov190ecd22010-10-17 16:24:37 +030049 int ignored;
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (ip_vs_todrop()) {
52 /*
53 * It seems that we are very loaded.
54 * We have to drop this packet :(
55 */
56 ip_vs_service_put(svc);
57 *verdict = NF_DROP;
58 return 0;
59 }
60
61 /*
62 * Let the virtual server select a real server for the
63 * incoming connection, and create a connection entry.
64 */
Julian Anastasov190ecd22010-10-17 16:24:37 +030065 *cpp = ip_vs_schedule(svc, skb, pp, &ignored);
Hans Schillstroma5959d52010-11-19 14:25:10 +010066 if (!*cpp && ignored <= 0) {
67 if (!ignored)
68 *verdict = ip_vs_leave(svc, skb, pp);
69 else {
70 ip_vs_service_put(svc);
71 *verdict = NF_DROP;
72 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return 0;
74 }
75 ip_vs_service_put(svc);
76 }
Hans Schillstroma5959d52010-11-19 14:25:10 +010077 /* NF_ACCEPT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return 1;
79}
80
81
82static inline void
Julius Volz0bbdd422008-09-02 15:55:42 +020083udp_fast_csum_update(int af, struct udphdr *uhdr,
84 const union nf_inet_addr *oldip,
85 const union nf_inet_addr *newip,
Al Viro014d7302006-09-28 14:29:52 -070086 __be16 oldport, __be16 newport)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Julius Volz0bbdd422008-09-02 15:55:42 +020088#ifdef CONFIG_IP_VS_IPV6
89 if (af == AF_INET6)
90 uhdr->check =
91 csum_fold(ip_vs_check_diff16(oldip->ip6, newip->ip6,
92 ip_vs_check_diff2(oldport, newport,
93 ~csum_unfold(uhdr->check))));
94 else
95#endif
96 uhdr->check =
97 csum_fold(ip_vs_check_diff4(oldip->ip, newip->ip,
98 ip_vs_check_diff2(oldport, newport,
99 ~csum_unfold(uhdr->check))));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (!uhdr->check)
Al Virof6ab0282006-11-16 02:36:50 -0800101 uhdr->check = CSUM_MANGLED_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Simon Horman503e81f2008-09-08 12:04:21 +1000104static inline void
105udp_partial_csum_update(int af, struct udphdr *uhdr,
106 const union nf_inet_addr *oldip,
107 const union nf_inet_addr *newip,
108 __be16 oldlen, __be16 newlen)
109{
110#ifdef CONFIG_IP_VS_IPV6
111 if (af == AF_INET6)
112 uhdr->check =
Julian Anastasov5bc90682010-10-17 16:14:31 +0300113 ~csum_fold(ip_vs_check_diff16(oldip->ip6, newip->ip6,
Simon Horman503e81f2008-09-08 12:04:21 +1000114 ip_vs_check_diff2(oldlen, newlen,
Julian Anastasov5bc90682010-10-17 16:14:31 +0300115 csum_unfold(uhdr->check))));
Simon Horman503e81f2008-09-08 12:04:21 +1000116 else
117#endif
118 uhdr->check =
Julian Anastasov5bc90682010-10-17 16:14:31 +0300119 ~csum_fold(ip_vs_check_diff4(oldip->ip, newip->ip,
Simon Horman503e81f2008-09-08 12:04:21 +1000120 ip_vs_check_diff2(oldlen, newlen,
Julian Anastasov5bc90682010-10-17 16:14:31 +0300121 csum_unfold(uhdr->check))));
Simon Horman503e81f2008-09-08 12:04:21 +1000122}
123
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125static int
Herbert Xu3db05fe2007-10-15 00:53:15 -0700126udp_snat_handler(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
128{
129 struct udphdr *udph;
Julius Volz0bbdd422008-09-02 15:55:42 +0200130 unsigned int udphoff;
Simon Horman503e81f2008-09-08 12:04:21 +1000131 int oldlen;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300132 int payload_csum = 0;
Julius Volz0bbdd422008-09-02 15:55:42 +0200133
134#ifdef CONFIG_IP_VS_IPV6
135 if (cp->af == AF_INET6)
136 udphoff = sizeof(struct ipv6hdr);
137 else
138#endif
139 udphoff = ip_hdrlen(skb);
Simon Horman503e81f2008-09-08 12:04:21 +1000140 oldlen = skb->len - udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 /* csum_check requires unshared skb */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700143 if (!skb_make_writable(skb, udphoff+sizeof(*udph)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return 0;
145
146 if (unlikely(cp->app != NULL)) {
Julian Anastasov8b27b102010-10-17 16:17:20 +0300147 int ret;
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /* Some checks before mangling */
Julius Volz0bbdd422008-09-02 15:55:42 +0200150 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 return 0;
152
153 /*
154 * Call application helper if needed
155 */
Julian Anastasov8b27b102010-10-17 16:17:20 +0300156 if (!(ret = ip_vs_app_pkt_out(cp, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return 0;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300158 /* ret=2: csum update is needed after payload mangling */
159 if (ret == 1)
160 oldlen = skb->len - udphoff;
161 else
162 payload_csum = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 }
164
Julius Volz0bbdd422008-09-02 15:55:42 +0200165 udph = (void *)skb_network_header(skb) + udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 udph->source = cp->vport;
167
168 /*
169 * Adjust UDP checksums
170 */
Simon Horman503e81f2008-09-08 12:04:21 +1000171 if (skb->ip_summed == CHECKSUM_PARTIAL) {
172 udp_partial_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
Harvey Harrisonca620592008-11-06 23:09:56 -0800173 htons(oldlen),
174 htons(skb->len - udphoff));
Julian Anastasov8b27b102010-10-17 16:17:20 +0300175 } else if (!payload_csum && (udph->check != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 /* Only port and addr are changed, do fast csum update */
Julius Volz0bbdd422008-09-02 15:55:42 +0200177 udp_fast_csum_update(cp->af, udph, &cp->daddr, &cp->vaddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 cp->dport, cp->vport);
Herbert Xu3db05fe2007-10-15 00:53:15 -0700179 if (skb->ip_summed == CHECKSUM_COMPLETE)
Julian Anastasov8b27b102010-10-17 16:17:20 +0300180 skb->ip_summed = (cp->app && pp->csum_check) ?
181 CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 } else {
183 /* full checksum calculation */
184 udph->check = 0;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700185 skb->csum = skb_checksum(skb, udphoff, skb->len - udphoff, 0);
Julius Volz0bbdd422008-09-02 15:55:42 +0200186#ifdef CONFIG_IP_VS_IPV6
187 if (cp->af == AF_INET6)
188 udph->check = csum_ipv6_magic(&cp->vaddr.in6,
189 &cp->caddr.in6,
190 skb->len - udphoff,
191 cp->protocol, skb->csum);
192 else
193#endif
194 udph->check = csum_tcpudp_magic(cp->vaddr.ip,
195 cp->caddr.ip,
196 skb->len - udphoff,
197 cp->protocol,
198 skb->csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (udph->check == 0)
Al Virof6ab0282006-11-16 02:36:50 -0800200 udph->check = CSUM_MANGLED_0;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300201 skb->ip_summed = CHECKSUM_UNNECESSARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 IP_VS_DBG(11, "O-pkt: %s O-csum=%d (+%zd)\n",
203 pp->name, udph->check,
204 (char*)&(udph->check) - (char*)udph);
205 }
206 return 1;
207}
208
209
210static int
Herbert Xu3db05fe2007-10-15 00:53:15 -0700211udp_dnat_handler(struct sk_buff *skb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 struct ip_vs_protocol *pp, struct ip_vs_conn *cp)
213{
214 struct udphdr *udph;
Julius Volz0bbdd422008-09-02 15:55:42 +0200215 unsigned int udphoff;
Simon Horman503e81f2008-09-08 12:04:21 +1000216 int oldlen;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300217 int payload_csum = 0;
Julius Volz0bbdd422008-09-02 15:55:42 +0200218
219#ifdef CONFIG_IP_VS_IPV6
220 if (cp->af == AF_INET6)
221 udphoff = sizeof(struct ipv6hdr);
222 else
223#endif
224 udphoff = ip_hdrlen(skb);
Simon Horman503e81f2008-09-08 12:04:21 +1000225 oldlen = skb->len - udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 /* csum_check requires unshared skb */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700228 if (!skb_make_writable(skb, udphoff+sizeof(*udph)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return 0;
230
231 if (unlikely(cp->app != NULL)) {
Julian Anastasov8b27b102010-10-17 16:17:20 +0300232 int ret;
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /* Some checks before mangling */
Julius Volz0bbdd422008-09-02 15:55:42 +0200235 if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237
238 /*
239 * Attempt ip_vs_app call.
240 * It will fix ip_vs_conn
241 */
Julian Anastasov8b27b102010-10-17 16:17:20 +0300242 if (!(ret = ip_vs_app_pkt_in(cp, skb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return 0;
Julian Anastasov8b27b102010-10-17 16:17:20 +0300244 /* ret=2: csum update is needed after payload mangling */
245 if (ret == 1)
246 oldlen = skb->len - udphoff;
247 else
248 payload_csum = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
Julius Volz0bbdd422008-09-02 15:55:42 +0200251 udph = (void *)skb_network_header(skb) + udphoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 udph->dest = cp->dport;
253
254 /*
255 * Adjust UDP checksums
256 */
Simon Horman503e81f2008-09-08 12:04:21 +1000257 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Julian Anastasov5bc90682010-10-17 16:14:31 +0300258 udp_partial_csum_update(cp->af, udph, &cp->vaddr, &cp->daddr,
Harvey Harrisonca620592008-11-06 23:09:56 -0800259 htons(oldlen),
260 htons(skb->len - udphoff));
Julian Anastasov8b27b102010-10-17 16:17:20 +0300261 } else if (!payload_csum && (udph->check != 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 /* Only port and addr are changed, do fast csum update */
Julius Volz0bbdd422008-09-02 15:55:42 +0200263 udp_fast_csum_update(cp->af, udph, &cp->vaddr, &cp->daddr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 cp->vport, cp->dport);
Herbert Xu3db05fe2007-10-15 00:53:15 -0700265 if (skb->ip_summed == CHECKSUM_COMPLETE)
Julian Anastasov8b27b102010-10-17 16:17:20 +0300266 skb->ip_summed = (cp->app && pp->csum_check) ?
267 CHECKSUM_UNNECESSARY : CHECKSUM_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 } else {
269 /* full checksum calculation */
270 udph->check = 0;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700271 skb->csum = skb_checksum(skb, udphoff, skb->len - udphoff, 0);
Julius Volz0bbdd422008-09-02 15:55:42 +0200272#ifdef CONFIG_IP_VS_IPV6
273 if (cp->af == AF_INET6)
274 udph->check = csum_ipv6_magic(&cp->caddr.in6,
275 &cp->daddr.in6,
276 skb->len - udphoff,
277 cp->protocol, skb->csum);
278 else
279#endif
280 udph->check = csum_tcpudp_magic(cp->caddr.ip,
281 cp->daddr.ip,
282 skb->len - udphoff,
283 cp->protocol,
284 skb->csum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (udph->check == 0)
Al Virof6ab0282006-11-16 02:36:50 -0800286 udph->check = CSUM_MANGLED_0;
Herbert Xu3db05fe2007-10-15 00:53:15 -0700287 skb->ip_summed = CHECKSUM_UNNECESSARY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289 return 1;
290}
291
292
293static int
Julius Volz51ef3482008-09-02 15:55:40 +0200294udp_csum_check(int af, struct sk_buff *skb, struct ip_vs_protocol *pp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 struct udphdr _udph, *uh;
Julius Volz51ef3482008-09-02 15:55:40 +0200297 unsigned int udphoff;
298
299#ifdef CONFIG_IP_VS_IPV6
300 if (af == AF_INET6)
301 udphoff = sizeof(struct ipv6hdr);
302 else
303#endif
304 udphoff = ip_hdrlen(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 uh = skb_header_pointer(skb, udphoff, sizeof(_udph), &_udph);
307 if (uh == NULL)
308 return 0;
309
310 if (uh->check != 0) {
311 switch (skb->ip_summed) {
312 case CHECKSUM_NONE:
313 skb->csum = skb_checksum(skb, udphoff,
314 skb->len - udphoff, 0);
Patrick McHardy84fa7932006-08-29 16:44:56 -0700315 case CHECKSUM_COMPLETE:
Julius Volz51ef3482008-09-02 15:55:40 +0200316#ifdef CONFIG_IP_VS_IPV6
317 if (af == AF_INET6) {
318 if (csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
319 &ipv6_hdr(skb)->daddr,
320 skb->len - udphoff,
321 ipv6_hdr(skb)->nexthdr,
322 skb->csum)) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300323 IP_VS_DBG_RL_PKT(0, af, pp, skb, 0,
Julius Volz51ef3482008-09-02 15:55:40 +0200324 "Failed checksum for");
325 return 0;
326 }
327 } else
328#endif
329 if (csum_tcpudp_magic(ip_hdr(skb)->saddr,
330 ip_hdr(skb)->daddr,
331 skb->len - udphoff,
332 ip_hdr(skb)->protocol,
333 skb->csum)) {
Julian Anastasov0d796412010-10-17 16:46:17 +0300334 IP_VS_DBG_RL_PKT(0, af, pp, skb, 0,
Julius Volz51ef3482008-09-02 15:55:40 +0200335 "Failed checksum for");
336 return 0;
337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 break;
339 default:
Patrick McHardy84fa7932006-08-29 16:44:56 -0700340 /* No need to checksum. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
342 }
343 }
344 return 1;
345}
346
347
348/*
349 * Note: the caller guarantees that only one of register_app,
350 * unregister_app or app_conn_bind is called each time.
351 */
352
353#define UDP_APP_TAB_BITS 4
354#define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
355#define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
356
357static struct list_head udp_apps[UDP_APP_TAB_SIZE];
358static DEFINE_SPINLOCK(udp_app_lock);
359
Al Viro75e7ce62006-11-14 21:13:28 -0800360static inline __u16 udp_app_hashkey(__be16 port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Al Viro75e7ce62006-11-14 21:13:28 -0800362 return (((__force u16)port >> UDP_APP_TAB_BITS) ^ (__force u16)port)
363 & UDP_APP_TAB_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366
367static int udp_register_app(struct ip_vs_app *inc)
368{
369 struct ip_vs_app *i;
Al Viro75e7ce62006-11-14 21:13:28 -0800370 __u16 hash;
371 __be16 port = inc->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 int ret = 0;
373
374 hash = udp_app_hashkey(port);
375
376
377 spin_lock_bh(&udp_app_lock);
378 list_for_each_entry(i, &udp_apps[hash], p_list) {
379 if (i->port == port) {
380 ret = -EEXIST;
381 goto out;
382 }
383 }
384 list_add(&inc->p_list, &udp_apps[hash]);
385 atomic_inc(&ip_vs_protocol_udp.appcnt);
386
387 out:
388 spin_unlock_bh(&udp_app_lock);
389 return ret;
390}
391
392
393static void
394udp_unregister_app(struct ip_vs_app *inc)
395{
396 spin_lock_bh(&udp_app_lock);
397 atomic_dec(&ip_vs_protocol_udp.appcnt);
398 list_del(&inc->p_list);
399 spin_unlock_bh(&udp_app_lock);
400}
401
402
403static int udp_app_conn_bind(struct ip_vs_conn *cp)
404{
405 int hash;
406 struct ip_vs_app *inc;
407 int result = 0;
408
409 /* Default binding: bind app only for NAT */
410 if (IP_VS_FWD_METHOD(cp) != IP_VS_CONN_F_MASQ)
411 return 0;
412
413 /* Lookup application incarnations and bind the right one */
414 hash = udp_app_hashkey(cp->vport);
415
416 spin_lock(&udp_app_lock);
417 list_for_each_entry(inc, &udp_apps[hash], p_list) {
418 if (inc->port == cp->vport) {
419 if (unlikely(!ip_vs_app_inc_get(inc)))
420 break;
421 spin_unlock(&udp_app_lock);
422
Hannes Eder1e3e2382009-08-02 11:05:41 +0000423 IP_VS_DBG_BUF(9, "%s(): Binding conn %s:%u->"
Julius Volzcfc78c52008-09-02 15:55:53 +0200424 "%s:%u to app %s on port %u\n",
425 __func__,
426 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
427 ntohs(cp->cport),
428 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
429 ntohs(cp->vport),
430 inc->name, ntohs(inc->port));
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 cp->app = inc;
433 if (inc->init_conn)
434 result = inc->init_conn(inc, cp);
435 goto out;
436 }
437 }
438 spin_unlock(&udp_app_lock);
439
440 out:
441 return result;
442}
443
444
445static int udp_timeouts[IP_VS_UDP_S_LAST+1] = {
446 [IP_VS_UDP_S_NORMAL] = 5*60*HZ,
447 [IP_VS_UDP_S_LAST] = 2*HZ,
448};
449
Jan Engelhardt36cbd3d2009-08-05 10:42:58 -0700450static const char *const udp_state_name_table[IP_VS_UDP_S_LAST+1] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 [IP_VS_UDP_S_NORMAL] = "UDP",
452 [IP_VS_UDP_S_LAST] = "BUG!",
453};
454
455
456static int
457udp_set_state_timeout(struct ip_vs_protocol *pp, char *sname, int to)
458{
459 return ip_vs_set_state_timeout(pp->timeout_table, IP_VS_UDP_S_LAST,
460 udp_state_name_table, sname, to);
461}
462
463static const char * udp_state_name(int state)
464{
465 if (state >= IP_VS_UDP_S_LAST)
466 return "ERR!";
467 return udp_state_name_table[state] ? udp_state_name_table[state] : "?";
468}
469
470static int
471udp_state_transition(struct ip_vs_conn *cp, int direction,
472 const struct sk_buff *skb,
473 struct ip_vs_protocol *pp)
474{
475 cp->timeout = pp->timeout_table[IP_VS_UDP_S_NORMAL];
476 return 1;
477}
478
479static void udp_init(struct ip_vs_protocol *pp)
480{
481 IP_VS_INIT_HASH_TABLE(udp_apps);
482 pp->timeout_table = udp_timeouts;
483}
484
485static void udp_exit(struct ip_vs_protocol *pp)
486{
487}
488
489
490struct ip_vs_protocol ip_vs_protocol_udp = {
491 .name = "UDP",
492 .protocol = IPPROTO_UDP,
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700493 .num_states = IP_VS_UDP_S_LAST,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .dont_defrag = 0,
495 .init = udp_init,
496 .exit = udp_exit,
497 .conn_schedule = udp_conn_schedule,
Simon Horman5c0d2372010-08-02 17:12:44 +0200498 .conn_in_get = ip_vs_conn_in_get_proto,
499 .conn_out_get = ip_vs_conn_out_get_proto,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .snat_handler = udp_snat_handler,
501 .dnat_handler = udp_dnat_handler,
502 .csum_check = udp_csum_check,
503 .state_transition = udp_state_transition,
504 .state_name = udp_state_name,
505 .register_app = udp_register_app,
506 .unregister_app = udp_unregister_app,
507 .app_conn_bind = udp_app_conn_bind,
508 .debug_packet = ip_vs_tcpudp_debug_packet,
509 .timeout_change = NULL,
510 .set_state_timeout = udp_set_state_timeout,
511};