IPVS: Add 'af' args to protocol handler functions
[safe/jmp/linux-2.6] / net / ipv4 / ipvs / ip_vs_proto_ah_esp.c
1 /*
2  * ip_vs_proto_ah_esp.c:        AH/ESP IPSec load balancing support for IPVS
3  *
4  * Authors:     Julian Anastasov <ja@ssi.bg>, February 2002
5  *              Wensong Zhang <wensong@linuxvirtualserver.org>
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  *              version 2 as published by the Free Software Foundation;
10  *
11  */
12
13 #include <linux/in.h>
14 #include <linux/ip.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/netfilter.h>
18 #include <linux/netfilter_ipv4.h>
19
20 #include <net/ip_vs.h>
21
22
23 /* TODO:
24
25 struct isakmp_hdr {
26         __u8            icookie[8];
27         __u8            rcookie[8];
28         __u8            np;
29         __u8            version;
30         __u8            xchgtype;
31         __u8            flags;
32         __u32           msgid;
33         __u32           length;
34 };
35
36 */
37
38 #define PORT_ISAKMP     500
39
40
41 static struct ip_vs_conn *
42 ah_esp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,
43                    const struct ip_vs_iphdr *iph, unsigned int proto_off,
44                    int inverse)
45 {
46         struct ip_vs_conn *cp;
47
48         if (likely(!inverse)) {
49                 cp = ip_vs_conn_in_get(IPPROTO_UDP,
50                                        iph->saddr.ip,
51                                        htons(PORT_ISAKMP),
52                                        iph->daddr.ip,
53                                        htons(PORT_ISAKMP));
54         } else {
55                 cp = ip_vs_conn_in_get(IPPROTO_UDP,
56                                        iph->daddr.ip,
57                                        htons(PORT_ISAKMP),
58                                        iph->saddr.ip,
59                                        htons(PORT_ISAKMP));
60         }
61
62         if (!cp) {
63                 /*
64                  * We are not sure if the packet is from our
65                  * service, so our conn_schedule hook should return NF_ACCEPT
66                  */
67                 IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for outin packet "
68                               "%s%s %s->%s\n",
69                               inverse ? "ICMP+" : "",
70                               pp->name,
71                               IP_VS_DBG_ADDR(af, &iph->saddr),
72                               IP_VS_DBG_ADDR(af, &iph->daddr));
73         }
74
75         return cp;
76 }
77
78
79 static struct ip_vs_conn *
80 ah_esp_conn_out_get(int af, const struct sk_buff *skb,
81                     struct ip_vs_protocol *pp,
82                     const struct ip_vs_iphdr *iph,
83                     unsigned int proto_off,
84                     int inverse)
85 {
86         struct ip_vs_conn *cp;
87
88         if (likely(!inverse)) {
89                 cp = ip_vs_conn_out_get(IPPROTO_UDP,
90                                         iph->saddr.ip,
91                                         htons(PORT_ISAKMP),
92                                         iph->daddr.ip,
93                                         htons(PORT_ISAKMP));
94         } else {
95                 cp = ip_vs_conn_out_get(IPPROTO_UDP,
96                                         iph->daddr.ip,
97                                         htons(PORT_ISAKMP),
98                                         iph->saddr.ip,
99                                         htons(PORT_ISAKMP));
100         }
101
102         if (!cp) {
103                 IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for inout packet "
104                               "%s%s %s->%s\n",
105                               inverse ? "ICMP+" : "",
106                               pp->name,
107                               IP_VS_DBG_ADDR(af, &iph->saddr),
108                               IP_VS_DBG_ADDR(af, &iph->daddr));
109         }
110
111         return cp;
112 }
113
114
115 static int
116 ah_esp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,
117                      int *verdict, struct ip_vs_conn **cpp)
118 {
119         /*
120          * AH/ESP is only related traffic. Pass the packet to IP stack.
121          */
122         *verdict = NF_ACCEPT;
123         return 0;
124 }
125
126
127 static void
128 ah_esp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
129                     int offset, const char *msg)
130 {
131         char buf[256];
132         struct iphdr _iph, *ih;
133
134         ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
135         if (ih == NULL)
136                 sprintf(buf, "%s TRUNCATED", pp->name);
137         else
138                 sprintf(buf, "%s %u.%u.%u.%u->%u.%u.%u.%u",
139                         pp->name, NIPQUAD(ih->saddr),
140                         NIPQUAD(ih->daddr));
141
142         printk(KERN_DEBUG "IPVS: %s: %s\n", msg, buf);
143 }
144
145
146 static void ah_esp_init(struct ip_vs_protocol *pp)
147 {
148         /* nothing to do now */
149 }
150
151
152 static void ah_esp_exit(struct ip_vs_protocol *pp)
153 {
154         /* nothing to do now */
155 }
156
157
158 #ifdef CONFIG_IP_VS_PROTO_AH
159 struct ip_vs_protocol ip_vs_protocol_ah = {
160         .name =                 "AH",
161         .protocol =             IPPROTO_AH,
162         .num_states =           1,
163         .dont_defrag =          1,
164         .init =                 ah_esp_init,
165         .exit =                 ah_esp_exit,
166         .conn_schedule =        ah_esp_conn_schedule,
167         .conn_in_get =          ah_esp_conn_in_get,
168         .conn_out_get =         ah_esp_conn_out_get,
169         .snat_handler =         NULL,
170         .dnat_handler =         NULL,
171         .csum_check =           NULL,
172         .state_transition =     NULL,
173         .register_app =         NULL,
174         .unregister_app =       NULL,
175         .app_conn_bind =        NULL,
176         .debug_packet =         ah_esp_debug_packet,
177         .timeout_change =       NULL,           /* ISAKMP */
178         .set_state_timeout =    NULL,
179 };
180 #endif
181
182 #ifdef CONFIG_IP_VS_PROTO_ESP
183 struct ip_vs_protocol ip_vs_protocol_esp = {
184         .name =                 "ESP",
185         .protocol =             IPPROTO_ESP,
186         .num_states =           1,
187         .dont_defrag =          1,
188         .init =                 ah_esp_init,
189         .exit =                 ah_esp_exit,
190         .conn_schedule =        ah_esp_conn_schedule,
191         .conn_in_get =          ah_esp_conn_in_get,
192         .conn_out_get =         ah_esp_conn_out_get,
193         .snat_handler =         NULL,
194         .dnat_handler =         NULL,
195         .csum_check =           NULL,
196         .state_transition =     NULL,
197         .register_app =         NULL,
198         .unregister_app =       NULL,
199         .app_conn_bind =        NULL,
200         .debug_packet =         ah_esp_debug_packet,
201         .timeout_change =       NULL,           /* ISAKMP */
202 };
203 #endif