patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / net / ipv4 / esp4.c
1 #include <linux/config.h>
2 #include <linux/module.h>
3 #include <net/inet_ecn.h>
4 #include <net/ip.h>
5 #include <net/xfrm.h>
6 #include <net/esp.h>
7 #include <asm/scatterlist.h>
8 #include <linux/crypto.h>
9 #include <linux/pfkeyv2.h>
10 #include <linux/random.h>
11 #include <net/icmp.h>
12 #include <net/udp.h>
13
14 #define MAX_SG_ONSTACK 4
15
16 /* decapsulation data for use when post-processing */
17 struct esp_decap_data {
18         xfrm_address_t  saddr;
19         __u16           sport;
20         __u8            proto;
21 };
22
23 int esp_output(struct sk_buff **pskb)
24 {
25         int err;
26         struct dst_entry *dst = (*pskb)->dst;
27         struct xfrm_state *x  = dst->xfrm;
28         struct iphdr *iph, *top_iph;
29         struct ip_esp_hdr *esph;
30         struct crypto_tfm *tfm;
31         struct esp_data *esp;
32         struct sk_buff *trailer;
33         struct udphdr *uh = NULL;
34         u32 *udpdata32;
35         struct xfrm_encap_tmpl *encap = NULL;
36         int blksize;
37         int clen;
38         int alen;
39         int nfrags;
40         union {
41                 struct iphdr    iph;
42                 char            buf[60];
43         } tmp_iph;
44
45         if ((*pskb)->ip_summed == CHECKSUM_HW) {
46                 err = skb_checksum_help(pskb, 0);
47                 if (err)
48                         goto error_nolock;
49         }
50
51         spin_lock_bh(&x->lock);
52         err = xfrm_check_output(x, *pskb, AF_INET);
53         if (err)
54                 goto error;
55         err = -ENOMEM;
56
57         /* Strip IP header in transport mode. Save it. */
58         if (!x->props.mode) {
59                 iph = (*pskb)->nh.iph;
60                 memcpy(&tmp_iph, iph, iph->ihl*4);
61                 __skb_pull(*pskb, iph->ihl*4);
62         }
63         /* Now skb is pure payload to encrypt */
64
65         /* Round to block size */
66         clen = (*pskb)->len;
67
68         esp = x->data;
69         alen = esp->auth.icv_trunc_len;
70         tfm = esp->conf.tfm;
71         blksize = (crypto_tfm_alg_blocksize(tfm) + 3) & ~3;
72         clen = (clen + 2 + blksize-1)&~(blksize-1);
73         if (esp->conf.padlen)
74                 clen = (clen + esp->conf.padlen-1)&~(esp->conf.padlen-1);
75
76         if ((nfrags = skb_cow_data(*pskb, clen-(*pskb)->len+alen, &trailer)) < 0)
77                 goto error;
78
79         /* Fill padding... */
80         do {
81                 int i;
82                 for (i=0; i<clen-(*pskb)->len - 2; i++)
83                         *(u8*)(trailer->tail + i) = i+1;
84         } while (0);
85         *(u8*)(trailer->tail + clen-(*pskb)->len - 2) = (clen - (*pskb)->len)-2;
86         pskb_put(*pskb, trailer, clen - (*pskb)->len);
87
88         encap = x->encap;
89
90         iph = (*pskb)->nh.iph;
91         if (x->props.mode) {
92                 top_iph = (struct iphdr*)skb_push(*pskb, x->props.header_len);
93                 esph = (struct ip_esp_hdr*)(top_iph+1);
94                 if (encap && encap->encap_type) {
95                         switch (encap->encap_type) {
96                         case UDP_ENCAP_ESPINUDP:
97                                 uh = (struct udphdr*) esph;
98                                 esph = (struct ip_esp_hdr*)(uh+1);
99                                 top_iph->protocol = IPPROTO_UDP;
100                                 break;
101                         case UDP_ENCAP_ESPINUDP_NON_IKE:
102                                 uh = (struct udphdr*) esph;
103                                 udpdata32 = (u32*)(uh+1);
104                                 udpdata32[0] = udpdata32[1] = 0;
105                                 esph = (struct ip_esp_hdr*)(udpdata32+2);
106                                 alen += 2;
107                                 top_iph->protocol = IPPROTO_UDP;
108                                 break;
109                         default:
110                                 printk(KERN_INFO
111                                        "esp_output(): Unhandled encap: %u\n",
112                                        encap->encap_type);
113                                 top_iph->protocol = IPPROTO_ESP;
114                                 break;
115                         }
116                 } else
117                         top_iph->protocol = IPPROTO_ESP;
118                 *(u8*)(trailer->tail - 1) = IPPROTO_IPIP;
119                 top_iph->ihl = 5;
120                 top_iph->version = 4;
121                 top_iph->tos = iph->tos;        /* DS disclosed */
122                 if (x->props.flags & XFRM_STATE_NOECN)
123                         IP_ECN_clear(top_iph);
124                 top_iph->tot_len = htons((*pskb)->len + alen);
125                 top_iph->frag_off = iph->frag_off&htons(IP_DF);
126                 if (!(top_iph->frag_off))
127                         ip_select_ident(top_iph, dst, 0);
128                 top_iph->ttl = iph->ttl;        /* TTL disclosed */
129                 top_iph->check = 0;
130                 top_iph->saddr = x->props.saddr.a4;
131                 top_iph->daddr = x->id.daddr.a4;
132                 memset(&(IPCB(*pskb)->opt), 0, sizeof(struct ip_options));
133         } else {
134                 esph = (struct ip_esp_hdr*)skb_push(*pskb, x->props.header_len);
135                 top_iph = (struct iphdr*)skb_push(*pskb, iph->ihl*4);
136                 memcpy(top_iph, &tmp_iph, iph->ihl*4);
137                 if (encap && encap->encap_type) {
138                         switch (encap->encap_type) {
139                         case UDP_ENCAP_ESPINUDP:
140                                 uh = (struct udphdr*) esph;
141                                 esph = (struct ip_esp_hdr*)(uh+1);
142                                 top_iph->protocol = IPPROTO_UDP;
143                                 break;
144                         case UDP_ENCAP_ESPINUDP_NON_IKE:
145                                 uh = (struct udphdr*) esph;
146                                 udpdata32 = (u32*)(uh+1);
147                                 udpdata32[0] = udpdata32[1] = 0;
148                                 esph = (struct ip_esp_hdr*)(udpdata32+2);
149                                 alen += 2;
150                                 top_iph->protocol = IPPROTO_UDP;
151                                 break;
152                         default:
153                                 printk(KERN_INFO
154                                        "esp_output(): Unhandled encap: %u\n",
155                                        encap->encap_type);
156                                 top_iph->protocol = IPPROTO_ESP;
157                                 break;
158                         }
159                 } else
160                         top_iph->protocol = IPPROTO_ESP;
161                 iph = &tmp_iph.iph;
162                 top_iph->tot_len = htons((*pskb)->len + alen);
163                 top_iph->check = 0;
164                 top_iph->frag_off = iph->frag_off;
165                 *(u8*)(trailer->tail - 1) = iph->protocol;
166         }
167
168         /* this is non-NULL only with UDP Encapsulation */
169         if (encap && uh) {
170                 uh->source = encap->encap_sport;
171                 uh->dest = encap->encap_dport;
172                 uh->len = htons((*pskb)->len + alen - sizeof(struct iphdr));
173                 uh->check = 0;
174         }
175
176         esph->spi = x->id.spi;
177         esph->seq_no = htonl(++x->replay.oseq);
178
179         if (esp->conf.ivlen)
180                 crypto_cipher_set_iv(tfm, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm));
181
182         do {
183                 struct scatterlist sgbuf[nfrags>MAX_SG_ONSTACK ? 0 : nfrags];
184                 struct scatterlist *sg = sgbuf;
185
186                 if (unlikely(nfrags > MAX_SG_ONSTACK)) {
187                         sg = kmalloc(sizeof(struct scatterlist)*nfrags, GFP_ATOMIC);
188                         if (!sg)
189                                 goto error;
190                 }
191                 skb_to_sgvec(*pskb, sg, esph->enc_data+esp->conf.ivlen-(*pskb)->data, clen);
192                 crypto_cipher_encrypt(tfm, sg, sg, clen);
193                 if (unlikely(sg != sgbuf))
194                         kfree(sg);
195         } while (0);
196
197         if (esp->conf.ivlen) {
198                 memcpy(esph->enc_data, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm));
199                 crypto_cipher_get_iv(tfm, esp->conf.ivec, crypto_tfm_alg_ivsize(tfm));
200         }
201
202         if (esp->auth.icv_full_len) {
203                 esp->auth.icv(esp, *pskb, (u8*)esph-(*pskb)->data,
204                               sizeof(struct ip_esp_hdr) + esp->conf.ivlen+clen, trailer->tail);
205                 pskb_put(*pskb, trailer, alen);
206         }
207
208         ip_send_check(top_iph);
209
210         (*pskb)->nh.raw = (*pskb)->data;
211
212         x->curlft.bytes += (*pskb)->len;
213         x->curlft.packets++;
214         spin_unlock_bh(&x->lock);
215         if (((*pskb)->dst = dst_pop(dst)) == NULL) {
216                 err = -EHOSTUNREACH;
217                 goto error_nolock;
218         }
219         return NET_XMIT_BYPASS;
220
221 error:
222         spin_unlock_bh(&x->lock);
223 error_nolock:
224         kfree_skb(*pskb);
225         return err;
226 }
227
228 /*
229  * Note: detecting truncated vs. non-truncated authentication data is very
230  * expensive, so we only support truncated data, which is the recommended
231  * and common case.
232  */
233 int esp_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)
234 {
235         struct iphdr *iph;
236         struct ip_esp_hdr *esph;
237         struct esp_data *esp = x->data;
238         struct sk_buff *trailer;
239         int blksize = crypto_tfm_alg_blocksize(esp->conf.tfm);
240         int alen = esp->auth.icv_trunc_len;
241         int elen = skb->len - sizeof(struct ip_esp_hdr) - esp->conf.ivlen - alen;
242         int nfrags;
243         int encap_len = 0;
244
245         if (!pskb_may_pull(skb, sizeof(struct ip_esp_hdr)))
246                 goto out;
247
248         if (elen <= 0 || (elen & (blksize-1)))
249                 goto out;
250
251         /* If integrity check is required, do this. */
252         if (esp->auth.icv_full_len) {
253                 u8 sum[esp->auth.icv_full_len];
254                 u8 sum1[alen];
255                 
256                 esp->auth.icv(esp, skb, 0, skb->len-alen, sum);
257
258                 if (skb_copy_bits(skb, skb->len-alen, sum1, alen))
259                         BUG();
260
261                 if (unlikely(memcmp(sum, sum1, alen))) {
262                         x->stats.integrity_failed++;
263                         goto out;
264                 }
265         }
266
267         if ((nfrags = skb_cow_data(skb, 0, &trailer)) < 0)
268                 goto out;
269
270         skb->ip_summed = CHECKSUM_NONE;
271
272         esph = (struct ip_esp_hdr*)skb->data;
273         iph = skb->nh.iph;
274
275         /* Get ivec. This can be wrong, check against another impls. */
276         if (esp->conf.ivlen)
277                 crypto_cipher_set_iv(esp->conf.tfm, esph->enc_data, crypto_tfm_alg_ivsize(esp->conf.tfm));
278
279         {
280                 u8 nexthdr[2];
281                 struct scatterlist sgbuf[nfrags>MAX_SG_ONSTACK ? 0 : nfrags];
282                 struct scatterlist *sg = sgbuf;
283                 u8 workbuf[60];
284                 int padlen;
285
286                 if (unlikely(nfrags > MAX_SG_ONSTACK)) {
287                         sg = kmalloc(sizeof(struct scatterlist)*nfrags, GFP_ATOMIC);
288                         if (!sg)
289                                 goto out;
290                 }
291                 skb_to_sgvec(skb, sg, sizeof(struct ip_esp_hdr) + esp->conf.ivlen, elen);
292                 crypto_cipher_decrypt(esp->conf.tfm, sg, sg, elen);
293                 if (unlikely(sg != sgbuf))
294                         kfree(sg);
295
296                 if (skb_copy_bits(skb, skb->len-alen-2, nexthdr, 2))
297                         BUG();
298
299                 padlen = nexthdr[0];
300                 if (padlen+2 >= elen)
301                         goto out;
302
303                 /* ... check padding bits here. Silly. :-) */ 
304
305                 if (x->encap && decap && decap->decap_type) {
306                         struct esp_decap_data *encap_data;
307                         struct udphdr *uh = (struct udphdr *) (iph+1);
308
309                         encap_data = (struct esp_decap_data *) (decap->decap_data);
310                         encap_data->proto = 0;
311
312                         switch (decap->decap_type) {
313                         case UDP_ENCAP_ESPINUDP:
314                         case UDP_ENCAP_ESPINUDP_NON_IKE:
315
316                                 if ((void*)uh == (void*)esph) {
317                                         printk(KERN_DEBUG
318                                                "esp_input(): Got ESP; expecting ESPinUDP\n");
319                                         break;
320                                 }
321
322                                 encap_data->proto = AF_INET;
323                                 encap_data->saddr.a4 = iph->saddr;
324                                 encap_data->sport = uh->source;
325                                 encap_len = (void*)esph - (void*)uh;
326                                 if (encap_len != sizeof(*uh))
327                                   printk(KERN_DEBUG
328                                          "esp_input(): UDP -> ESP: too much room: %d\n",
329                                          encap_len);
330                                 break;
331
332                         default:
333                                 printk(KERN_INFO
334                                "esp_input(): processing unknown encap type: %u\n",
335                                        decap->decap_type);
336                                 break;
337                         }
338                 }
339
340                 iph->protocol = nexthdr[1];
341                 pskb_trim(skb, skb->len - alen - padlen - 2);
342                 memcpy(workbuf, skb->nh.raw, iph->ihl*4);
343                 skb->h.raw = skb_pull(skb, sizeof(struct ip_esp_hdr) + esp->conf.ivlen);
344                 skb->nh.raw += encap_len + sizeof(struct ip_esp_hdr) + esp->conf.ivlen;
345                 memcpy(skb->nh.raw, workbuf, iph->ihl*4);
346                 skb->nh.iph->tot_len = htons(skb->len);
347         }
348
349         return 0;
350
351 out:
352         return -EINVAL;
353 }
354
355 int esp_post_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)
356 {
357   
358         if (x->encap) {
359                 struct xfrm_encap_tmpl *encap;
360                 struct esp_decap_data *decap_data;
361
362                 encap = x->encap;
363                 decap_data = (struct esp_decap_data *)(decap->decap_data);
364
365                 /* first, make sure that the decap type == the encap type */
366                 if (encap->encap_type != decap->decap_type)
367                         return -EINVAL;
368
369                 /* Next, if we don't have an encap type, then ignore it */
370                 if (!encap->encap_type)
371                         return 0;
372
373                 switch (encap->encap_type) {
374                 case UDP_ENCAP_ESPINUDP:
375                 case UDP_ENCAP_ESPINUDP_NON_IKE:
376                         /*
377                          * 1) if the NAT-T peer's IP or port changed then
378                          *    advertize the change to the keying daemon.
379                          *    This is an inbound SA, so just compare
380                          *    SRC ports.
381                          */
382                         if (decap_data->proto == AF_INET &&
383                             (decap_data->saddr.a4 != x->props.saddr.a4 ||
384                              decap_data->sport != encap->encap_sport)) {
385                                 xfrm_address_t ipaddr;
386
387                                 ipaddr.a4 = decap_data->saddr.a4;
388                                 km_new_mapping(x, &ipaddr, decap_data->sport);
389                                         
390                                 /* XXX: perhaps add an extra
391                                  * policy check here, to see
392                                  * if we should allow or
393                                  * reject a packet from a
394                                  * different source
395                                  * address/port.
396                                  */
397                         }
398                 
399                         /*
400                          * 2) ignore UDP/TCP checksums in case
401                          *    of NAT-T in Transport Mode, or
402                          *    perform other post-processing fixes
403                          *    as per * draft-ietf-ipsec-udp-encaps-06,
404                          *    section 3.1.2
405                          */
406                         if (!x->props.mode)
407                                 skb->ip_summed = CHECKSUM_UNNECESSARY;
408
409                         break;
410                 default:
411                         printk(KERN_INFO
412                                "esp4_post_input(): Unhandled encap type: %u\n",
413                                encap->encap_type);
414                         break;
415                 }
416         }
417         return 0;
418 }
419
420 static u32 esp4_get_max_size(struct xfrm_state *x, int mtu)
421 {
422         struct esp_data *esp = x->data;
423         u32 blksize = crypto_tfm_alg_blocksize(esp->conf.tfm);
424
425         if (x->props.mode) {
426                 mtu = (mtu + 2 + blksize-1)&~(blksize-1);
427         } else {
428                 /* The worst case. */
429                 mtu += 2 + blksize;
430         }
431         if (esp->conf.padlen)
432                 mtu = (mtu + esp->conf.padlen-1)&~(esp->conf.padlen-1);
433
434         return mtu + x->props.header_len + esp->auth.icv_trunc_len;
435 }
436
437 void esp4_err(struct sk_buff *skb, u32 info)
438 {
439         struct iphdr *iph = (struct iphdr*)skb->data;
440         struct ip_esp_hdr *esph = (struct ip_esp_hdr*)(skb->data+(iph->ihl<<2));
441         struct xfrm_state *x;
442
443         if (skb->h.icmph->type != ICMP_DEST_UNREACH ||
444             skb->h.icmph->code != ICMP_FRAG_NEEDED)
445                 return;
446
447         x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, esph->spi, IPPROTO_ESP, AF_INET);
448         if (!x)
449                 return;
450         NETDEBUG(printk(KERN_DEBUG "pmtu discovery on SA ESP/%08x/%08x\n",
451                         ntohl(esph->spi), ntohl(iph->daddr)));
452         xfrm_state_put(x);
453 }
454
455 void esp_destroy(struct xfrm_state *x)
456 {
457         struct esp_data *esp = x->data;
458
459         if (!esp)
460                 return;
461
462         if (esp->conf.tfm) {
463                 crypto_free_tfm(esp->conf.tfm);
464                 esp->conf.tfm = NULL;
465         }
466         if (esp->conf.ivec) {
467                 kfree(esp->conf.ivec);
468                 esp->conf.ivec = NULL;
469         }
470         if (esp->auth.tfm) {
471                 crypto_free_tfm(esp->auth.tfm);
472                 esp->auth.tfm = NULL;
473         }
474         if (esp->auth.work_icv) {
475                 kfree(esp->auth.work_icv);
476                 esp->auth.work_icv = NULL;
477         }
478         kfree(esp);
479 }
480
481 int esp_init_state(struct xfrm_state *x, void *args)
482 {
483         struct esp_data *esp = NULL;
484
485         /* null auth and encryption can have zero length keys */
486         if (x->aalg) {
487                 if (x->aalg->alg_key_len > 512)
488                         goto error;
489         }
490         if (x->ealg == NULL)
491                 goto error;
492
493         esp = kmalloc(sizeof(*esp), GFP_KERNEL);
494         if (esp == NULL)
495                 return -ENOMEM;
496
497         memset(esp, 0, sizeof(*esp));
498
499         if (x->aalg) {
500                 struct xfrm_algo_desc *aalg_desc;
501
502                 esp->auth.key = x->aalg->alg_key;
503                 esp->auth.key_len = (x->aalg->alg_key_len+7)/8;
504                 esp->auth.tfm = crypto_alloc_tfm(x->aalg->alg_name, 0);
505                 if (esp->auth.tfm == NULL)
506                         goto error;
507                 esp->auth.icv = esp_hmac_digest;
508
509                 aalg_desc = xfrm_aalg_get_byname(x->aalg->alg_name);
510                 BUG_ON(!aalg_desc);
511
512                 if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
513                     crypto_tfm_alg_digestsize(esp->auth.tfm)) {
514                         NETDEBUG(printk(KERN_INFO "ESP: %s digestsize %u != %hu\n",
515                                x->aalg->alg_name,
516                                crypto_tfm_alg_digestsize(esp->auth.tfm),
517                                aalg_desc->uinfo.auth.icv_fullbits/8));
518                         goto error;
519                 }
520
521                 esp->auth.icv_full_len = aalg_desc->uinfo.auth.icv_fullbits/8;
522                 esp->auth.icv_trunc_len = aalg_desc->uinfo.auth.icv_truncbits/8;
523
524                 esp->auth.work_icv = kmalloc(esp->auth.icv_full_len, GFP_KERNEL);
525                 if (!esp->auth.work_icv)
526                         goto error;
527         }
528         esp->conf.key = x->ealg->alg_key;
529         esp->conf.key_len = (x->ealg->alg_key_len+7)/8;
530         if (x->props.ealgo == SADB_EALG_NULL)
531                 esp->conf.tfm = crypto_alloc_tfm(x->ealg->alg_name, CRYPTO_TFM_MODE_ECB);
532         else
533                 esp->conf.tfm = crypto_alloc_tfm(x->ealg->alg_name, CRYPTO_TFM_MODE_CBC);
534         if (esp->conf.tfm == NULL)
535                 goto error;
536         esp->conf.ivlen = crypto_tfm_alg_ivsize(esp->conf.tfm);
537         esp->conf.padlen = 0;
538         if (esp->conf.ivlen) {
539                 esp->conf.ivec = kmalloc(esp->conf.ivlen, GFP_KERNEL);
540                 if (unlikely(esp->conf.ivec == NULL))
541                         goto error;
542                 get_random_bytes(esp->conf.ivec, esp->conf.ivlen);
543         }
544         crypto_cipher_setkey(esp->conf.tfm, esp->conf.key, esp->conf.key_len);
545         x->props.header_len = sizeof(struct ip_esp_hdr) + esp->conf.ivlen;
546         if (x->props.mode)
547                 x->props.header_len += sizeof(struct iphdr);
548         if (x->encap) {
549                 struct xfrm_encap_tmpl *encap = x->encap;
550
551                 if (encap->encap_type) {
552                         switch (encap->encap_type) {
553                         case UDP_ENCAP_ESPINUDP:
554                                 x->props.header_len += sizeof(struct udphdr);
555                                 break;
556                         case UDP_ENCAP_ESPINUDP_NON_IKE:
557                                 x->props.header_len += sizeof(struct udphdr) + 2 * sizeof(u32);
558                                 break;
559                         default:
560                                 printk (KERN_INFO
561                                 "esp_init_state(): Unhandled encap type: %u\n",
562                                         encap->encap_type);
563                                 break;
564                         }
565                 }
566         }
567         x->data = esp;
568         x->props.trailer_len = esp4_get_max_size(x, 0) - x->props.header_len;
569         return 0;
570
571 error:
572         if (esp) {
573                 if (esp->auth.tfm)
574                         crypto_free_tfm(esp->auth.tfm);
575                 if (esp->auth.work_icv)
576                         kfree(esp->auth.work_icv);
577                 if (esp->conf.tfm)
578                         crypto_free_tfm(esp->conf.tfm);
579                 kfree(esp);
580         }
581         return -EINVAL;
582 }
583
584 static struct xfrm_type esp_type =
585 {
586         .description    = "ESP4",
587         .owner          = THIS_MODULE,
588         .proto          = IPPROTO_ESP,
589         .init_state     = esp_init_state,
590         .destructor     = esp_destroy,
591         .get_max_size   = esp4_get_max_size,
592         .input          = esp_input,
593         .post_input     = esp_post_input,
594         .output         = esp_output
595 };
596
597 static struct inet_protocol esp4_protocol = {
598         .handler        =       xfrm4_rcv,
599         .err_handler    =       esp4_err,
600         .no_policy      =       1,
601 };
602
603 static int __init esp4_init(void)
604 {
605         struct xfrm_decap_state decap;
606
607         if (sizeof(struct esp_decap_data)  <
608             sizeof(decap.decap_data)) {
609                 extern void decap_data_too_small(void);
610
611                 decap_data_too_small();
612         }
613
614         if (xfrm_register_type(&esp_type, AF_INET) < 0) {
615                 printk(KERN_INFO "ip esp init: can't add xfrm type\n");
616                 return -EAGAIN;
617         }
618         if (inet_add_protocol(&esp4_protocol, IPPROTO_ESP) < 0) {
619                 printk(KERN_INFO "ip esp init: can't add protocol\n");
620                 xfrm_unregister_type(&esp_type, AF_INET);
621                 return -EAGAIN;
622         }
623         return 0;
624 }
625
626 static void __exit esp4_fini(void)
627 {
628         if (inet_del_protocol(&esp4_protocol, IPPROTO_ESP) < 0)
629                 printk(KERN_INFO "ip esp close: can't remove protocol\n");
630         if (xfrm_unregister_type(&esp_type, AF_INET) < 0)
631                 printk(KERN_INFO "ip esp close: can't remove xfrm type\n");
632 }
633
634 module_init(esp4_init);
635 module_exit(esp4_fini);
636 MODULE_LICENSE("GPL");