2 * ip_vs_proto_ah_esp.c: AH/ESP IPSec load balancing support for IPVS
4 * Authors: Julian Anastasov <ja@ssi.bg>, February 2002
5 * Wensong Zhang <wensong@linuxvirtualserver.org>
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;
13 #define KMSG_COMPONENT "IPVS"
14 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/netfilter.h>
21 #include <linux/netfilter_ipv4.h>
23 #include <net/ip_vs.h>
41 #define PORT_ISAKMP 500
44 ah_esp_conn_fill_param_proto(int af
, const struct ip_vs_iphdr
*iph
,
45 int inverse
, struct ip_vs_conn_param
*p
)
48 ip_vs_conn_fill_param(af
, IPPROTO_UDP
,
49 &iph
->saddr
, htons(PORT_ISAKMP
),
50 &iph
->daddr
, htons(PORT_ISAKMP
), p
);
52 ip_vs_conn_fill_param(af
, IPPROTO_UDP
,
53 &iph
->daddr
, htons(PORT_ISAKMP
),
54 &iph
->saddr
, htons(PORT_ISAKMP
), p
);
57 static struct ip_vs_conn
*
58 ah_esp_conn_in_get(int af
, const struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
59 const struct ip_vs_iphdr
*iph
, unsigned int proto_off
,
62 struct ip_vs_conn
*cp
;
63 struct ip_vs_conn_param p
;
65 ah_esp_conn_fill_param_proto(af
, iph
, inverse
, &p
);
66 cp
= ip_vs_conn_in_get(&p
);
69 * We are not sure if the packet is from our
70 * service, so our conn_schedule hook should return NF_ACCEPT
72 IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for outin packet "
74 inverse
? "ICMP+" : "",
76 IP_VS_DBG_ADDR(af
, &iph
->saddr
),
77 IP_VS_DBG_ADDR(af
, &iph
->daddr
));
84 static struct ip_vs_conn
*
85 ah_esp_conn_out_get(int af
, const struct sk_buff
*skb
,
86 struct ip_vs_protocol
*pp
,
87 const struct ip_vs_iphdr
*iph
,
88 unsigned int proto_off
,
91 struct ip_vs_conn
*cp
;
92 struct ip_vs_conn_param p
;
94 ah_esp_conn_fill_param_proto(af
, iph
, inverse
, &p
);
95 cp
= ip_vs_conn_out_get(&p
);
97 IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for inout packet "
99 inverse
? "ICMP+" : "",
101 IP_VS_DBG_ADDR(af
, &iph
->saddr
),
102 IP_VS_DBG_ADDR(af
, &iph
->daddr
));
110 ah_esp_conn_schedule(int af
, struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
111 int *verdict
, struct ip_vs_conn
**cpp
)
114 * AH/ESP is only related traffic. Pass the packet to IP stack.
116 *verdict
= NF_ACCEPT
;
120 static void ah_esp_init(struct ip_vs_protocol
*pp
)
122 /* nothing to do now */
126 static void ah_esp_exit(struct ip_vs_protocol
*pp
)
128 /* nothing to do now */
132 #ifdef CONFIG_IP_VS_PROTO_AH
133 struct ip_vs_protocol ip_vs_protocol_ah
= {
135 .protocol
= IPPROTO_AH
,
140 .conn_schedule
= ah_esp_conn_schedule
,
141 .conn_in_get
= ah_esp_conn_in_get
,
142 .conn_out_get
= ah_esp_conn_out_get
,
143 .snat_handler
= NULL
,
144 .dnat_handler
= NULL
,
146 .state_transition
= NULL
,
147 .register_app
= NULL
,
148 .unregister_app
= NULL
,
149 .app_conn_bind
= NULL
,
150 .debug_packet
= ip_vs_tcpudp_debug_packet
,
151 .timeout_change
= NULL
, /* ISAKMP */
152 .set_state_timeout
= NULL
,
156 #ifdef CONFIG_IP_VS_PROTO_ESP
157 struct ip_vs_protocol ip_vs_protocol_esp
= {
159 .protocol
= IPPROTO_ESP
,
164 .conn_schedule
= ah_esp_conn_schedule
,
165 .conn_in_get
= ah_esp_conn_in_get
,
166 .conn_out_get
= ah_esp_conn_out_get
,
167 .snat_handler
= NULL
,
168 .dnat_handler
= NULL
,
170 .state_transition
= NULL
,
171 .register_app
= NULL
,
172 .unregister_app
= NULL
,
173 .app_conn_bind
= NULL
,
174 .debug_packet
= ip_vs_tcpudp_debug_packet
,
175 .timeout_change
= NULL
, /* ISAKMP */