2 * xfrm_output.c - Common IPsec encapsulation code.
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/errno.h>
13 #include <linux/module.h>
14 #include <linux/netdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/spinlock.h>
17 #include <linux/time.h>
21 static int xfrm_state_check_space(struct xfrm_state
*x
, struct sk_buff
*skb
)
23 int nhead
= x
->props
.header_len
+ LL_RESERVED_SPACE(skb
->dst
->dev
)
27 return pskb_expand_head(skb
, nhead
, 0, GFP_ATOMIC
);
29 /* Check tail too... */
33 static int xfrm_state_check(struct xfrm_state
*x
, struct sk_buff
*skb
)
35 int err
= xfrm_state_check_expire(x
);
38 err
= xfrm_state_check_space(x
, skb
);
43 int xfrm_output(struct sk_buff
*skb
)
45 struct dst_entry
*dst
= skb
->dst
;
46 struct xfrm_state
*x
= dst
->xfrm
;
49 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
50 err
= skb_checksum_help(skb
);
56 spin_lock_bh(&x
->lock
);
57 err
= xfrm_state_check(x
, skb
);
61 if (x
->type
->flags
& XFRM_TYPE_REPLAY_PROT
) {
62 XFRM_SKB_CB(skb
)->seq
= ++x
->replay
.oseq
;
63 xfrm_aevent_doreplay(x
);
66 err
= x
->mode
->output(x
, skb
);
70 err
= x
->type
->output(x
, skb
);
74 x
->curlft
.bytes
+= skb
->len
;
77 if (x
->props
.mode
== XFRM_MODE_ROUTEOPTIMIZATION
)
78 x
->lastused
= get_seconds();
80 spin_unlock_bh(&x
->lock
);
82 skb_reset_network_header(skb
);
84 if (!(skb
->dst
= dst_pop(dst
))) {
90 } while (x
&& (x
->props
.mode
!= XFRM_MODE_TUNNEL
));
97 spin_unlock_bh(&x
->lock
);
100 EXPORT_SYMBOL_GPL(xfrm_output
);