2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2008-08-22 12:06:12 +00:00
|
|
|
* ip_vs_proto_ah_esp.c: AH/ESP IPSec load balancing support for IPVS
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Authors: Julian Anastasov <ja@ssi.bg>, February 2002
|
|
|
|
* Wensong Zhang <wensong@linuxvirtualserver.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation;
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-30 21:29:44 +00:00
|
|
|
#define KMSG_COMPONENT "IPVS"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-12-27 04:43:12 +00:00
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/netfilter.h>
|
|
|
|
#include <linux/netfilter_ipv4.h>
|
|
|
|
|
|
|
|
#include <net/ip_vs.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
|
|
|
|
struct isakmp_hdr {
|
|
|
|
__u8 icookie[8];
|
|
|
|
__u8 rcookie[8];
|
|
|
|
__u8 np;
|
|
|
|
__u8 version;
|
|
|
|
__u8 xchgtype;
|
|
|
|
__u8 flags;
|
|
|
|
__u32 msgid;
|
|
|
|
__u32 length;
|
|
|
|
};
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PORT_ISAKMP 500
|
|
|
|
|
|
|
|
|
|
|
|
static struct ip_vs_conn *
|
2008-09-02 13:55:40 +00:00
|
|
|
ah_esp_conn_in_get(int af, const struct sk_buff *skb, struct ip_vs_protocol *pp,
|
|
|
|
const struct ip_vs_iphdr *iph, unsigned int proto_off,
|
2008-08-22 12:06:12 +00:00
|
|
|
int inverse)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ip_vs_conn *cp;
|
|
|
|
|
|
|
|
if (likely(!inverse)) {
|
2008-09-02 13:55:43 +00:00
|
|
|
cp = ip_vs_conn_in_get(af, IPPROTO_UDP,
|
|
|
|
&iph->saddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP),
|
2008-09-02 13:55:43 +00:00
|
|
|
&iph->daddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP));
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2008-09-02 13:55:43 +00:00
|
|
|
cp = ip_vs_conn_in_get(af, IPPROTO_UDP,
|
|
|
|
&iph->daddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP),
|
2008-09-02 13:55:43 +00:00
|
|
|
&iph->saddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cp) {
|
|
|
|
/*
|
|
|
|
* We are not sure if the packet is from our
|
|
|
|
* service, so our conn_schedule hook should return NF_ACCEPT
|
|
|
|
*/
|
2008-09-02 13:55:40 +00:00
|
|
|
IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for outin packet "
|
|
|
|
"%s%s %s->%s\n",
|
|
|
|
inverse ? "ICMP+" : "",
|
|
|
|
pp->name,
|
|
|
|
IP_VS_DBG_ADDR(af, &iph->saddr),
|
|
|
|
IP_VS_DBG_ADDR(af, &iph->daddr));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct ip_vs_conn *
|
2008-09-02 13:55:40 +00:00
|
|
|
ah_esp_conn_out_get(int af, const struct sk_buff *skb,
|
|
|
|
struct ip_vs_protocol *pp,
|
|
|
|
const struct ip_vs_iphdr *iph,
|
|
|
|
unsigned int proto_off,
|
|
|
|
int inverse)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct ip_vs_conn *cp;
|
|
|
|
|
|
|
|
if (likely(!inverse)) {
|
2008-09-02 13:55:43 +00:00
|
|
|
cp = ip_vs_conn_out_get(af, IPPROTO_UDP,
|
|
|
|
&iph->saddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP),
|
2008-09-02 13:55:43 +00:00
|
|
|
&iph->daddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP));
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2008-09-02 13:55:43 +00:00
|
|
|
cp = ip_vs_conn_out_get(af, IPPROTO_UDP,
|
|
|
|
&iph->daddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP),
|
2008-09-02 13:55:43 +00:00
|
|
|
&iph->saddr,
|
2007-03-07 05:19:10 +00:00
|
|
|
htons(PORT_ISAKMP));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cp) {
|
2008-09-02 13:55:40 +00:00
|
|
|
IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for inout packet "
|
|
|
|
"%s%s %s->%s\n",
|
|
|
|
inverse ? "ICMP+" : "",
|
|
|
|
pp->name,
|
|
|
|
IP_VS_DBG_ADDR(af, &iph->saddr),
|
|
|
|
IP_VS_DBG_ADDR(af, &iph->daddr));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2008-09-02 13:55:40 +00:00
|
|
|
ah_esp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_protocol *pp,
|
2008-08-22 12:06:12 +00:00
|
|
|
int *verdict, struct ip_vs_conn **cpp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/*
|
2008-08-22 12:06:12 +00:00
|
|
|
* AH/ESP is only related traffic. Pass the packet to IP stack.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
*verdict = NF_ACCEPT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-09-02 13:55:41 +00:00
|
|
|
ah_esp_debug_packet_v4(struct ip_vs_protocol *pp, const struct sk_buff *skb,
|
|
|
|
int offset, const char *msg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
struct iphdr _iph, *ih;
|
|
|
|
|
|
|
|
ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
|
|
|
|
if (ih == NULL)
|
2010-04-08 11:35:47 +00:00
|
|
|
sprintf(buf, "TRUNCATED");
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2010-04-08 11:35:47 +00:00
|
|
|
sprintf(buf, "%pI4->%pI4", &ih->saddr, &ih->daddr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-04-08 11:35:47 +00:00
|
|
|
pr_debug("%s: %s %s\n", msg, pp->name, buf);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 13:55:41 +00:00
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
static void
|
|
|
|
ah_esp_debug_packet_v6(struct ip_vs_protocol *pp, const struct sk_buff *skb,
|
|
|
|
int offset, const char *msg)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
struct ipv6hdr _iph, *ih;
|
|
|
|
|
|
|
|
ih = skb_header_pointer(skb, offset, sizeof(_iph), &_iph);
|
|
|
|
if (ih == NULL)
|
2010-04-08 11:35:47 +00:00
|
|
|
sprintf(buf, "TRUNCATED");
|
2008-09-02 13:55:41 +00:00
|
|
|
else
|
2010-04-08 11:35:47 +00:00
|
|
|
sprintf(buf, "%pI6->%pI6", &ih->saddr, &ih->daddr);
|
2008-09-02 13:55:41 +00:00
|
|
|
|
2010-04-08 11:35:47 +00:00
|
|
|
pr_debug("%s: %s %s\n", msg, pp->name, buf);
|
2008-09-02 13:55:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
ah_esp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
|
|
|
|
int offset, const char *msg)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
2008-09-16 15:11:11 +00:00
|
|
|
if (skb->protocol == htons(ETH_P_IPV6))
|
2008-09-02 13:55:41 +00:00
|
|
|
ah_esp_debug_packet_v6(pp, skb, offset, msg);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ah_esp_debug_packet_v4(pp, skb, offset, msg);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-22 12:06:12 +00:00
|
|
|
static void ah_esp_init(struct ip_vs_protocol *pp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* nothing to do now */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 12:06:12 +00:00
|
|
|
static void ah_esp_exit(struct ip_vs_protocol *pp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* nothing to do now */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 12:06:12 +00:00
|
|
|
#ifdef CONFIG_IP_VS_PROTO_AH
|
2005-04-16 22:20:36 +00:00
|
|
|
struct ip_vs_protocol ip_vs_protocol_ah = {
|
|
|
|
.name = "AH",
|
|
|
|
.protocol = IPPROTO_AH,
|
2008-04-29 10:21:23 +00:00
|
|
|
.num_states = 1,
|
2005-04-16 22:20:36 +00:00
|
|
|
.dont_defrag = 1,
|
2008-08-22 12:06:12 +00:00
|
|
|
.init = ah_esp_init,
|
|
|
|
.exit = ah_esp_exit,
|
|
|
|
.conn_schedule = ah_esp_conn_schedule,
|
|
|
|
.conn_in_get = ah_esp_conn_in_get,
|
|
|
|
.conn_out_get = ah_esp_conn_out_get,
|
2005-04-16 22:20:36 +00:00
|
|
|
.snat_handler = NULL,
|
|
|
|
.dnat_handler = NULL,
|
|
|
|
.csum_check = NULL,
|
|
|
|
.state_transition = NULL,
|
|
|
|
.register_app = NULL,
|
|
|
|
.unregister_app = NULL,
|
|
|
|
.app_conn_bind = NULL,
|
2008-08-22 12:06:12 +00:00
|
|
|
.debug_packet = ah_esp_debug_packet,
|
2005-04-16 22:20:36 +00:00
|
|
|
.timeout_change = NULL, /* ISAKMP */
|
|
|
|
.set_state_timeout = NULL,
|
|
|
|
};
|
2008-08-22 12:06:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_IP_VS_PROTO_ESP
|
|
|
|
struct ip_vs_protocol ip_vs_protocol_esp = {
|
|
|
|
.name = "ESP",
|
|
|
|
.protocol = IPPROTO_ESP,
|
|
|
|
.num_states = 1,
|
|
|
|
.dont_defrag = 1,
|
|
|
|
.init = ah_esp_init,
|
|
|
|
.exit = ah_esp_exit,
|
|
|
|
.conn_schedule = ah_esp_conn_schedule,
|
|
|
|
.conn_in_get = ah_esp_conn_in_get,
|
|
|
|
.conn_out_get = ah_esp_conn_out_get,
|
|
|
|
.snat_handler = NULL,
|
|
|
|
.dnat_handler = NULL,
|
|
|
|
.csum_check = NULL,
|
|
|
|
.state_transition = NULL,
|
|
|
|
.register_app = NULL,
|
|
|
|
.unregister_app = NULL,
|
|
|
|
.app_conn_bind = NULL,
|
|
|
|
.debug_packet = ah_esp_debug_packet,
|
|
|
|
.timeout_change = NULL, /* ISAKMP */
|
|
|
|
};
|
|
|
|
#endif
|