blob: 5320d39976e1ddc90b5d5f2d997b60226b4ea0d3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Julius Volz409a1962008-08-22 14:06:12 +02002 * ip_vs_proto_ah_esp.c: AH/ESP IPSec load balancing support for IPVS
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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
Hannes Eder9aada7a2009-07-30 14:29:44 -070013#define KMSG_COMPONENT "IPVS"
14#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020016#include <linux/in.h>
17#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/netfilter.h>
21#include <linux/netfilter_ipv4.h>
22
23#include <net/ip_vs.h>
24
25
26/* TODO:
27
28struct isakmp_hdr {
29 __u8 icookie[8];
30 __u8 rcookie[8];
31 __u8 np;
32 __u8 version;
33 __u8 xchgtype;
34 __u8 flags;
35 __u32 msgid;
36 __u32 length;
37};
38
39*/
40
41#define PORT_ISAKMP 500
42
Simon Hormanf11017e2010-08-22 21:37:52 +090043static void
Eric W. Biederman19913de2015-09-21 13:01:43 -050044ah_esp_conn_fill_param_proto(struct netns_ipvs *ipvs, int af,
Alex Gartrell802c41a2015-08-26 09:40:32 -070045 const struct ip_vs_iphdr *iph,
Hans Schillstrom6e67e582011-01-03 14:44:57 +010046 struct ip_vs_conn_param *p)
Simon Hormanf11017e2010-08-22 21:37:52 +090047{
Alex Gartrell802c41a2015-08-26 09:40:32 -070048 if (likely(!ip_vs_iph_inverse(iph)))
Eric W. Biederman19913de2015-09-21 13:01:43 -050049 ip_vs_conn_fill_param(ipvs, af, IPPROTO_UDP,
Simon Hormanf11017e2010-08-22 21:37:52 +090050 &iph->saddr, htons(PORT_ISAKMP),
51 &iph->daddr, htons(PORT_ISAKMP), p);
52 else
Eric W. Biederman19913de2015-09-21 13:01:43 -050053 ip_vs_conn_fill_param(ipvs, af, IPPROTO_UDP,
Simon Hormanf11017e2010-08-22 21:37:52 +090054 &iph->daddr, htons(PORT_ISAKMP),
55 &iph->saddr, htons(PORT_ISAKMP), p);
56}
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static struct ip_vs_conn *
Eric W. Biedermanab161972015-09-21 13:02:38 -050059ah_esp_conn_in_get(struct netns_ipvs *ipvs, int af, const struct sk_buff *skb,
Alex Gartrell802c41a2015-08-26 09:40:32 -070060 const struct ip_vs_iphdr *iph)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 struct ip_vs_conn *cp;
Simon Hormanf11017e2010-08-22 21:37:52 +090063 struct ip_vs_conn_param p;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Eric W. Biederman19913de2015-09-21 13:01:43 -050065 ah_esp_conn_fill_param_proto(ipvs, af, iph, &p);
Simon Hormanf11017e2010-08-22 21:37:52 +090066 cp = ip_vs_conn_in_get(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 if (!cp) {
68 /*
69 * We are not sure if the packet is from our
70 * service, so our conn_schedule hook should return NF_ACCEPT
71 */
Julius Volz51ef3482008-09-02 15:55:40 +020072 IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for outin packet "
73 "%s%s %s->%s\n",
Alex Gartrell802c41a2015-08-26 09:40:32 -070074 ip_vs_iph_icmp(iph) ? "ICMP+" : "",
Hans Schillstrom93304192011-01-03 14:44:51 +010075 ip_vs_proto_get(iph->protocol)->name,
Julius Volz51ef3482008-09-02 15:55:40 +020076 IP_VS_DBG_ADDR(af, &iph->saddr),
77 IP_VS_DBG_ADDR(af, &iph->daddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
79
80 return cp;
81}
82
83
84static struct ip_vs_conn *
Eric W. Biederman0cf705c8c2015-09-21 13:02:39 -050085ah_esp_conn_out_get(struct netns_ipvs *ipvs, int af, const struct sk_buff *skb,
Alex Gartrell802c41a2015-08-26 09:40:32 -070086 const struct ip_vs_iphdr *iph)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 struct ip_vs_conn *cp;
Simon Hormanf11017e2010-08-22 21:37:52 +090089 struct ip_vs_conn_param p;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Eric W. Biederman19913de2015-09-21 13:01:43 -050091 ah_esp_conn_fill_param_proto(ipvs, af, iph, &p);
Simon Hormanf11017e2010-08-22 21:37:52 +090092 cp = ip_vs_conn_out_get(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (!cp) {
Julius Volz51ef3482008-09-02 15:55:40 +020094 IP_VS_DBG_BUF(12, "Unknown ISAKMP entry for inout packet "
95 "%s%s %s->%s\n",
Alex Gartrell802c41a2015-08-26 09:40:32 -070096 ip_vs_iph_icmp(iph) ? "ICMP+" : "",
Hans Schillstrom93304192011-01-03 14:44:51 +010097 ip_vs_proto_get(iph->protocol)->name,
Julius Volz51ef3482008-09-02 15:55:40 +020098 IP_VS_DBG_ADDR(af, &iph->saddr),
99 IP_VS_DBG_ADDR(af, &iph->daddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
102 return cp;
103}
104
105
106static int
Eric W. Biedermand8f44c32015-09-21 13:02:43 -0500107ah_esp_conn_schedule(struct netns_ipvs *ipvs, int af, struct sk_buff *skb,
108 struct ip_vs_proto_data *pd,
Jesper Dangaard Brouerd4383f02012-09-26 14:07:17 +0200109 int *verdict, struct ip_vs_conn **cpp,
110 struct ip_vs_iphdr *iph)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 /*
Julius Volz409a1962008-08-22 14:06:12 +0200113 * AH/ESP is only related traffic. Pass the packet to IP stack.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 */
115 *verdict = NF_ACCEPT;
116 return 0;
117}
118
Julius Volz409a1962008-08-22 14:06:12 +0200119#ifdef CONFIG_IP_VS_PROTO_AH
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120struct ip_vs_protocol ip_vs_protocol_ah = {
121 .name = "AH",
122 .protocol = IPPROTO_AH,
Julian Anastasov2ad17de2008-04-29 03:21:23 -0700123 .num_states = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .dont_defrag = 1,
Hans Schillstrom88fe2d32011-01-03 14:44:50 +0100125 .init = NULL,
126 .exit = NULL,
Julius Volz409a1962008-08-22 14:06:12 +0200127 .conn_schedule = ah_esp_conn_schedule,
128 .conn_in_get = ah_esp_conn_in_get,
129 .conn_out_get = ah_esp_conn_out_get,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .snat_handler = NULL,
131 .dnat_handler = NULL,
132 .csum_check = NULL,
133 .state_transition = NULL,
134 .register_app = NULL,
135 .unregister_app = NULL,
136 .app_conn_bind = NULL,
Julian Anastasov0d796412010-10-17 16:46:17 +0300137 .debug_packet = ip_vs_tcpudp_debug_packet,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .timeout_change = NULL, /* ISAKMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
Julius Volz409a1962008-08-22 14:06:12 +0200140#endif
141
142#ifdef CONFIG_IP_VS_PROTO_ESP
143struct ip_vs_protocol ip_vs_protocol_esp = {
144 .name = "ESP",
145 .protocol = IPPROTO_ESP,
146 .num_states = 1,
147 .dont_defrag = 1,
Hans Schillstrom88fe2d32011-01-03 14:44:50 +0100148 .init = NULL,
149 .exit = NULL,
Julius Volz409a1962008-08-22 14:06:12 +0200150 .conn_schedule = ah_esp_conn_schedule,
151 .conn_in_get = ah_esp_conn_in_get,
152 .conn_out_get = ah_esp_conn_out_get,
153 .snat_handler = NULL,
154 .dnat_handler = NULL,
155 .csum_check = NULL,
156 .state_transition = NULL,
157 .register_app = NULL,
158 .unregister_app = NULL,
159 .app_conn_bind = NULL,
Julian Anastasov0d796412010-10-17 16:46:17 +0300160 .debug_packet = ip_vs_tcpudp_debug_packet,
Julius Volz409a1962008-08-22 14:06:12 +0200161 .timeout_change = NULL, /* ISAKMP */
162};
163#endif