4 #include <linux/xfrm.h>
5 #include <linux/spinlock.h>
6 #include <linux/list.h>
7 #include <linux/skbuff.h>
8 #include <linux/netdevice.h>
9 #include <linux/crypto.h>
10 #include <linux/pfkeyv2.h>
11 #include <linux/in6.h>
15 #include <net/route.h>
17 #include <net/ip6_fib.h>
19 #define XFRM_ALIGN8(len) (((len) + 7) & ~7)
21 extern struct semaphore xfrm_cfg_sem
;
23 /* Organization of SPD aka "XFRM rules"
24 ------------------------------------
27 - policy rule, struct xfrm_policy (=SPD entry)
28 - bundle of transformations, struct dst_entry == struct xfrm_dst (=SA bundle)
29 - instance of a transformer, struct xfrm_state (=SA)
30 - template to clone xfrm_state, struct xfrm_tmpl
32 SPD is plain linear list of xfrm_policy rules, ordered by priority.
33 (To be compatible with existing pfkeyv2 implementations,
34 many rules with priority of 0x7fffffff are allowed to exist and
35 such rules are ordered in an unpredictable way, thanks to bsd folks.)
37 Lookup is plain linear search until the first match with selector.
39 If "action" is "block", then we prohibit the flow, otherwise:
40 if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
41 policy entry has list of up to XFRM_MAX_DEPTH transformations,
42 described by templates xfrm_tmpl. Each template is resolved
43 to a complete xfrm_state (see below) and we pack bundle of transformations
44 to a dst_entry returned to requestor.
46 dst -. xfrm .-> xfrm_state #1
47 |---. child .-> dst -. xfrm .-> xfrm_state #2
48 |---. child .-> dst -. xfrm .-> xfrm_state #3
51 Bundles are cached at xrfm_policy struct (field ->bundles).
54 Resolution of xrfm_tmpl
55 -----------------------
57 1. ->mode Mode: transport or tunnel
58 2. ->id.proto Protocol: AH/ESP/IPCOMP
59 3. ->id.daddr Remote tunnel endpoint, ignored for transport mode.
60 Q: allow to resolve security gateway?
61 4. ->id.spi If not zero, static SPI.
62 5. ->saddr Local tunnel endpoint, ignored for transport mode.
63 6. ->algos List of allowed algos. Plain bitmask now.
64 Q: ealgos, aalgos, calgos. What a mess...
65 7. ->share Sharing mode.
66 Q: how to implement private sharing mode? To add struct sock* to
69 Having this template we search through SAD searching for entries
70 with appropriate mode/proto/algo, permitted by selector.
71 If no appropriate entry found, it is requested from key manager.
74 Q: How to find all the bundles referring to a physical path for
75 PMTU discovery? Seems, dst should contain list of all parents...
76 and enter to infinite locking hierarchy disaster.
77 No! It is easier, we will not search for them, let them find us.
78 We add genid to each dst plus pointer to genid of raw IP route,
79 pmtu disc will update pmtu on raw IP route and increase its genid.
80 dst_check() will see this for top level and trigger resyncing
81 metrics. Plus, it will be made via sk->sk_dst_cache. Solved.
84 /* Full description of state of transformer. */
87 /* Note: bydst is re-used during gc */
88 struct list_head bydst
;
89 struct list_head byspi
;
95 struct xfrm_selector sel
;
104 /* Parameters of this state. */
109 u8 aalgo
, ealgo
, calgo
;
112 xfrm_address_t saddr
;
117 struct xfrm_lifetime_cfg lft
;
119 /* Data for transformer */
120 struct xfrm_algo
*aalg
;
121 struct xfrm_algo
*ealg
;
122 struct xfrm_algo
*calg
;
124 /* Data for encapsulator */
125 struct xfrm_encap_tmpl
*encap
;
127 /* IPComp needs an IPIP tunnel for handling uncompressed packets */
128 struct xfrm_state
*tunnel
;
130 /* If a tunnel, number of users + 1 */
131 atomic_t tunnel_users
;
133 /* State for replay detection */
134 struct xfrm_replay_state replay
;
137 struct xfrm_stats stats
;
139 struct xfrm_lifetime_cur curlft
;
140 struct timer_list timer
;
142 /* Reference to data common to all the instances of this
144 struct xfrm_type
*type
;
146 /* Private data of this transformer, format is opaque,
147 * interpreted by xfrm_type methods. */
162 struct xfrm_policy_afinfo
{
163 unsigned short family
;
165 struct xfrm_type_map
*type_map
;
166 struct dst_ops
*dst_ops
;
167 void (*garbage_collect
)(void);
168 int (*dst_lookup
)(struct xfrm_dst
**dst
, struct flowi
*fl
);
169 struct dst_entry
*(*find_bundle
)(struct flowi
*fl
, struct xfrm_policy
*policy
);
170 int (*bundle_create
)(struct xfrm_policy
*policy
,
171 struct xfrm_state
**xfrm
,
174 struct dst_entry
**dst_p
);
175 void (*decode_session
)(struct sk_buff
*skb
,
179 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo
*afinfo
);
180 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo
*afinfo
);
182 #define XFRM_ACQ_EXPIRES 30
185 struct xfrm_state_afinfo
{
186 unsigned short family
;
188 struct list_head
*state_bydst
;
189 struct list_head
*state_byspi
;
190 void (*init_tempsel
)(struct xfrm_state
*x
, struct flowi
*fl
,
191 struct xfrm_tmpl
*tmpl
,
192 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
);
193 struct xfrm_state
*(*state_lookup
)(xfrm_address_t
*daddr
, u32 spi
, u8 proto
);
194 struct xfrm_state
*(*find_acq
)(u8 mode
, u32 reqid
, u8 proto
,
195 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
199 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo
*afinfo
);
200 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo
*afinfo
);
202 extern void xfrm_state_delete_tunnel(struct xfrm_state
*x
);
204 struct xfrm_decap_state
;
208 struct module
*owner
;
211 int (*init_state
)(struct xfrm_state
*x
, void *args
);
212 void (*destructor
)(struct xfrm_state
*);
213 int (*input
)(struct xfrm_state
*, struct xfrm_decap_state
*, struct sk_buff
*skb
);
214 int (*post_input
)(struct xfrm_state
*, struct xfrm_decap_state
*, struct sk_buff
*skb
);
215 int (*output
)(struct xfrm_state
*, struct sk_buff
*pskb
);
216 /* Estimate maximal size of result of transformation of a dgram */
217 u32 (*get_max_size
)(struct xfrm_state
*, int size
);
220 struct xfrm_type_map
{
222 struct xfrm_type
*map
[256];
225 extern int xfrm_register_type(struct xfrm_type
*type
, unsigned short family
);
226 extern int xfrm_unregister_type(struct xfrm_type
*type
, unsigned short family
);
227 extern struct xfrm_type
*xfrm_get_type(u8 proto
, unsigned short family
);
228 extern void xfrm_put_type(struct xfrm_type
*type
);
232 /* id in template is interpreted as:
233 * daddr - destination of tunnel, may be zero for transport mode.
234 * spi - zero to acquire spi. Not zero if spi is static, then
235 * daddr must be fixed too.
236 * proto - AH/ESP/IPCOMP
240 /* Source address of tunnel. Ignored, if it is not a tunnel. */
241 xfrm_address_t saddr
;
245 /* Mode: transport/tunnel */
248 /* Sharing mode: unique, this session only, this user only etc. */
251 /* May skip this transfomration if no SA is found */
254 /* Bit mask of algos allowed for acquisition */
260 #define XFRM_MAX_DEPTH 4
264 struct xfrm_policy
*next
;
265 struct list_head list
;
267 /* This lock only affects elements except for entry. */
270 struct timer_list timer
;
274 struct xfrm_selector selector
;
275 struct xfrm_lifetime_cfg lft
;
276 struct xfrm_lifetime_cur curlft
;
277 struct dst_entry
*bundles
;
283 struct xfrm_tmpl xfrm_vec
[XFRM_MAX_DEPTH
];
286 #define XFRM_KM_TIMEOUT 30
290 struct list_head list
;
292 int (*notify
)(struct xfrm_state
*x
, int event
);
293 int (*acquire
)(struct xfrm_state
*x
, struct xfrm_tmpl
*, struct xfrm_policy
*xp
, int dir
);
294 struct xfrm_policy
*(*compile_policy
)(u16 family
, int opt
, u8
*data
, int len
, int *dir
);
295 int (*new_mapping
)(struct xfrm_state
*x
, xfrm_address_t
*ipaddr
, u16 sport
);
296 int (*notify_policy
)(struct xfrm_policy
*x
, int dir
, int event
);
299 extern int xfrm_register_km(struct xfrm_mgr
*km
);
300 extern int xfrm_unregister_km(struct xfrm_mgr
*km
);
303 extern struct xfrm_policy
*xfrm_policy_list
[XFRM_POLICY_MAX
*2];
305 static inline void xfrm_pol_hold(struct xfrm_policy
*policy
)
307 if (likely(policy
!= NULL
))
308 atomic_inc(&policy
->refcnt
);
311 extern void __xfrm_policy_destroy(struct xfrm_policy
*policy
);
313 static inline void xfrm_pol_put(struct xfrm_policy
*policy
)
315 if (atomic_dec_and_test(&policy
->refcnt
))
316 __xfrm_policy_destroy(policy
);
319 #define XFRM_DST_HSIZE 1024
322 unsigned __xfrm4_dst_hash(xfrm_address_t
*addr
)
326 h
= (h
^ (h
>>16)) % XFRM_DST_HSIZE
;
331 unsigned __xfrm6_dst_hash(xfrm_address_t
*addr
)
334 h
= ntohl(addr
->a6
[2]^addr
->a6
[3]);
335 h
= (h
^ (h
>>16)) % XFRM_DST_HSIZE
;
340 unsigned xfrm_dst_hash(xfrm_address_t
*addr
, unsigned short family
)
344 return __xfrm4_dst_hash(addr
);
346 return __xfrm6_dst_hash(addr
);
352 unsigned __xfrm4_spi_hash(xfrm_address_t
*addr
, u32 spi
, u8 proto
)
355 h
= ntohl(addr
->a4
^spi
^proto
);
356 h
= (h
^ (h
>>10) ^ (h
>>20)) % XFRM_DST_HSIZE
;
361 unsigned __xfrm6_spi_hash(xfrm_address_t
*addr
, u32 spi
, u8 proto
)
364 h
= ntohl(addr
->a6
[2]^addr
->a6
[3]^spi
^proto
);
365 h
= (h
^ (h
>>10) ^ (h
>>20)) % XFRM_DST_HSIZE
;
370 unsigned xfrm_spi_hash(xfrm_address_t
*addr
, u32 spi
, u8 proto
, unsigned short family
)
374 return __xfrm4_spi_hash(addr
, spi
, proto
);
376 return __xfrm6_spi_hash(addr
, spi
, proto
);
381 extern void __xfrm_state_destroy(struct xfrm_state
*);
383 static inline void xfrm_state_put(struct xfrm_state
*x
)
385 if (atomic_dec_and_test(&x
->refcnt
))
386 __xfrm_state_destroy(x
);
389 static inline void xfrm_state_hold(struct xfrm_state
*x
)
391 atomic_inc(&x
->refcnt
);
394 static __inline__
int addr_match(void *token1
, void *token2
, int prefixlen
)
401 pdw
= prefixlen
>> 5; /* num of whole __u32 in prefix */
402 pbi
= prefixlen
& 0x1f; /* num of bits in incomplete u32 in prefix */
405 if (memcmp(a1
, a2
, pdw
<< 2))
411 mask
= htonl((0xffffffff) << (32 - pbi
));
413 if ((a1
[pdw
] ^ a2
[pdw
]) & mask
)
421 u16
xfrm_flowi_sport(struct flowi
*fl
)
428 port
= fl
->fl_ip_sport
;
432 port
= htons(fl
->fl_icmp_type
);
441 u16
xfrm_flowi_dport(struct flowi
*fl
)
448 port
= fl
->fl_ip_dport
;
452 port
= htons(fl
->fl_icmp_code
);
461 __xfrm4_selector_match(struct xfrm_selector
*sel
, struct flowi
*fl
)
463 return addr_match(&fl
->fl4_dst
, &sel
->daddr
, sel
->prefixlen_d
) &&
464 addr_match(&fl
->fl4_src
, &sel
->saddr
, sel
->prefixlen_s
) &&
465 !((xfrm_flowi_dport(fl
) ^ sel
->dport
) & sel
->dport_mask
) &&
466 !((xfrm_flowi_sport(fl
) ^ sel
->sport
) & sel
->sport_mask
) &&
467 (fl
->proto
== sel
->proto
|| !sel
->proto
) &&
468 (fl
->oif
== sel
->ifindex
|| !sel
->ifindex
);
472 __xfrm6_selector_match(struct xfrm_selector
*sel
, struct flowi
*fl
)
474 return addr_match(&fl
->fl6_dst
, &sel
->daddr
, sel
->prefixlen_d
) &&
475 addr_match(&fl
->fl6_src
, &sel
->saddr
, sel
->prefixlen_s
) &&
476 !((xfrm_flowi_dport(fl
) ^ sel
->dport
) & sel
->dport_mask
) &&
477 !((xfrm_flowi_sport(fl
) ^ sel
->sport
) & sel
->sport_mask
) &&
478 (fl
->proto
== sel
->proto
|| !sel
->proto
) &&
479 (fl
->oif
== sel
->ifindex
|| !sel
->ifindex
);
483 xfrm_selector_match(struct xfrm_selector
*sel
, struct flowi
*fl
,
484 unsigned short family
)
488 return __xfrm4_selector_match(sel
, fl
);
490 return __xfrm6_selector_match(sel
, fl
);
495 /* A struct encoding bundle of transformations to apply to some set of flow.
497 * dst->child points to the next element of bundle.
498 * dst->xfrm points to an instanse of transformer.
500 * Due to unfortunate limitations of current routing cache, which we
501 * have no time to fix, it mirrors struct rtable and bound to the same
502 * routing key, including saddr,daddr. However, we can have many of
503 * bundles differing by session id. All the bundles grow from a parent
509 struct xfrm_dst
*next
;
510 struct dst_entry dst
;
514 struct dst_entry
*route
;
515 u32 route_mtu_cached
;
516 u32 child_mtu_cached
;
519 /* Decapsulation state, used by the input to store data during
520 * decapsulation procedure, to be used later (during the policy
523 struct xfrm_decap_state
{
528 struct sec_decap_state
{
529 struct xfrm_state
*xvec
;
530 struct xfrm_decap_state decap
;
537 struct sec_decap_state x
[XFRM_MAX_DEPTH
];
540 static inline struct sec_path
*
541 secpath_get(struct sec_path
*sp
)
544 atomic_inc(&sp
->refcnt
);
548 extern void __secpath_destroy(struct sec_path
*sp
);
551 secpath_put(struct sec_path
*sp
)
553 if (sp
&& atomic_dec_and_test(&sp
->refcnt
))
554 __secpath_destroy(sp
);
557 extern struct sec_path
*secpath_dup(struct sec_path
*src
);
560 secpath_reset(struct sk_buff
*skb
)
563 secpath_put(skb
->sp
);
569 __xfrm4_state_addr_cmp(struct xfrm_tmpl
*tmpl
, struct xfrm_state
*x
)
571 return (tmpl
->saddr
.a4
&&
572 tmpl
->saddr
.a4
!= x
->props
.saddr
.a4
);
576 __xfrm6_state_addr_cmp(struct xfrm_tmpl
*tmpl
, struct xfrm_state
*x
)
578 return (!ipv6_addr_any((struct in6_addr
*)&tmpl
->saddr
) &&
579 ipv6_addr_cmp((struct in6_addr
*)&tmpl
->saddr
, (struct in6_addr
*)&x
->props
.saddr
));
583 xfrm_state_addr_cmp(struct xfrm_tmpl
*tmpl
, struct xfrm_state
*x
, unsigned short family
)
587 return __xfrm4_state_addr_cmp(tmpl
, x
);
589 return __xfrm6_state_addr_cmp(tmpl
, x
);
596 extern int __xfrm_policy_check(struct sock
*, int dir
, struct sk_buff
*skb
, unsigned short family
);
598 static inline int xfrm_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
, unsigned short family
)
600 if (sk
&& sk
->sk_policy
[XFRM_POLICY_IN
])
601 return __xfrm_policy_check(sk
, dir
, skb
, family
);
603 return (!xfrm_policy_list
[dir
] && !skb
->sp
) ||
604 (skb
->dst
->flags
& DST_NOPOLICY
) ||
605 __xfrm_policy_check(sk
, dir
, skb
, family
);
608 static inline int xfrm4_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
)
610 return xfrm_policy_check(sk
, dir
, skb
, AF_INET
);
613 static inline int xfrm6_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
)
615 return xfrm_policy_check(sk
, dir
, skb
, AF_INET6
);
619 extern int __xfrm_route_forward(struct sk_buff
*skb
, unsigned short family
);
621 static inline int xfrm_route_forward(struct sk_buff
*skb
, unsigned short family
)
623 return !xfrm_policy_list
[XFRM_POLICY_OUT
] ||
624 (skb
->dst
->flags
& DST_NOXFRM
) ||
625 __xfrm_route_forward(skb
, family
);
628 static inline int xfrm4_route_forward(struct sk_buff
*skb
)
630 return xfrm_route_forward(skb
, AF_INET
);
633 static inline int xfrm6_route_forward(struct sk_buff
*skb
)
635 return xfrm_route_forward(skb
, AF_INET6
);
638 extern int __xfrm_sk_clone_policy(struct sock
*sk
);
640 static inline int xfrm_sk_clone_policy(struct sock
*sk
)
642 if (unlikely(sk
->sk_policy
[0] || sk
->sk_policy
[1]))
643 return __xfrm_sk_clone_policy(sk
);
647 extern void xfrm_policy_delete(struct xfrm_policy
*pol
, int dir
);
649 static inline void xfrm_sk_free_policy(struct sock
*sk
)
651 if (unlikely(sk
->sk_policy
[0] != NULL
)) {
652 xfrm_policy_delete(sk
->sk_policy
[0], XFRM_POLICY_MAX
);
653 sk
->sk_policy
[0] = NULL
;
655 if (unlikely(sk
->sk_policy
[1] != NULL
)) {
656 xfrm_policy_delete(sk
->sk_policy
[1], XFRM_POLICY_MAX
+1);
657 sk
->sk_policy
[1] = NULL
;
663 static inline void xfrm_sk_free_policy(struct sock
*sk
) {}
664 static inline int xfrm_sk_clone_policy(struct sock
*sk
) { return 0; }
665 static inline int xfrm6_route_forward(struct sk_buff
*skb
) { return 1; }
666 static inline int xfrm4_route_forward(struct sk_buff
*skb
) { return 1; }
667 static inline int xfrm6_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
)
671 static inline int xfrm4_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
)
675 static inline int xfrm_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
, unsigned short family
)
682 xfrm_address_t
*xfrm_flowi_daddr(struct flowi
*fl
, unsigned short family
)
686 return (xfrm_address_t
*)&fl
->fl4_dst
;
688 return (xfrm_address_t
*)&fl
->fl6_dst
;
694 xfrm_address_t
*xfrm_flowi_saddr(struct flowi
*fl
, unsigned short family
)
698 return (xfrm_address_t
*)&fl
->fl4_src
;
700 return (xfrm_address_t
*)&fl
->fl6_src
;
705 static __inline__
int
706 __xfrm4_state_addr_check(struct xfrm_state
*x
,
707 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
709 if (daddr
->a4
== x
->id
.daddr
.a4
&&
710 (saddr
->a4
== x
->props
.saddr
.a4
|| !saddr
->a4
|| !x
->props
.saddr
.a4
))
715 static __inline__
int
716 __xfrm6_state_addr_check(struct xfrm_state
*x
,
717 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
719 if (!ipv6_addr_cmp((struct in6_addr
*)daddr
, (struct in6_addr
*)&x
->id
.daddr
) &&
720 (!ipv6_addr_cmp((struct in6_addr
*)saddr
, (struct in6_addr
*)&x
->props
.saddr
)||
721 ipv6_addr_any((struct in6_addr
*)saddr
) ||
722 ipv6_addr_any((struct in6_addr
*)&x
->props
.saddr
)))
727 static __inline__
int
728 xfrm_state_addr_check(struct xfrm_state
*x
,
729 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
730 unsigned short family
)
734 return __xfrm4_state_addr_check(x
, daddr
, saddr
);
736 return __xfrm6_state_addr_check(x
, daddr
, saddr
);
741 static inline int xfrm_state_kern(struct xfrm_state
*x
)
743 return atomic_read(&x
->tunnel_users
);
747 * xfrm algorithm information
749 struct xfrm_algo_auth_info
{
754 struct xfrm_algo_encr_info
{
759 struct xfrm_algo_comp_info
{
763 struct xfrm_algo_desc
{
767 struct xfrm_algo_auth_info auth
;
768 struct xfrm_algo_encr_info encr
;
769 struct xfrm_algo_comp_info comp
;
771 struct sadb_alg desc
;
774 /* XFRM tunnel handlers. */
776 int (*handler
)(struct sk_buff
*skb
);
777 void (*err_handler
)(struct sk_buff
*skb
, void *info
);
780 struct xfrm6_tunnel
{
781 int (*handler
)(struct sk_buff
**pskb
, unsigned int *nhoffp
);
782 void (*err_handler
)(struct sk_buff
*skb
, struct inet6_skb_parm
*opt
,
783 int type
, int code
, int offset
, __u32 info
);
786 extern void xfrm_init(void);
787 extern void xfrm4_init(void);
788 extern void xfrm6_init(void);
789 extern void xfrm6_fini(void);
790 extern void xfrm_state_init(void);
791 extern void xfrm4_state_init(void);
792 extern void xfrm4_state_fini(void);
793 extern void xfrm6_state_init(void);
794 extern void xfrm6_state_fini(void);
796 extern int xfrm_state_walk(u8 proto
, int (*func
)(struct xfrm_state
*, int, void*), void *);
797 extern struct xfrm_state
*xfrm_state_alloc(void);
798 extern struct xfrm_state
*xfrm_state_find(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
799 struct flowi
*fl
, struct xfrm_tmpl
*tmpl
,
800 struct xfrm_policy
*pol
, int *err
,
801 unsigned short family
);
802 extern int xfrm_state_check_expire(struct xfrm_state
*x
);
803 extern void xfrm_state_insert(struct xfrm_state
*x
);
804 extern int xfrm_state_add(struct xfrm_state
*x
);
805 extern int xfrm_state_update(struct xfrm_state
*x
);
806 extern struct xfrm_state
*xfrm_state_lookup(xfrm_address_t
*daddr
, u32 spi
, u8 proto
, unsigned short family
);
807 extern struct xfrm_state
*xfrm_find_acq_byseq(u32 seq
);
808 extern void xfrm_state_delete(struct xfrm_state
*x
);
809 extern void xfrm_state_flush(u8 proto
);
810 extern int xfrm_replay_check(struct xfrm_state
*x
, u32 seq
);
811 extern void xfrm_replay_advance(struct xfrm_state
*x
, u32 seq
);
812 extern int xfrm_state_check(struct xfrm_state
*x
, struct sk_buff
*skb
);
813 extern int xfrm_state_mtu(struct xfrm_state
*x
, int mtu
);
814 extern int xfrm4_rcv(struct sk_buff
*skb
);
815 extern int xfrm4_output(struct sk_buff
*skb
);
816 extern int xfrm4_tunnel_register(struct xfrm_tunnel
*handler
);
817 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel
*handler
);
818 extern int xfrm6_rcv_spi(struct sk_buff
**pskb
, unsigned int *nhoffp
, u32 spi
);
819 extern int xfrm6_rcv(struct sk_buff
**pskb
, unsigned int *nhoffp
);
820 extern int xfrm6_tunnel_register(struct xfrm6_tunnel
*handler
);
821 extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel
*handler
);
822 extern u32
xfrm6_tunnel_alloc_spi(xfrm_address_t
*saddr
);
823 extern void xfrm6_tunnel_free_spi(xfrm_address_t
*saddr
);
824 extern u32
xfrm6_tunnel_spi_lookup(xfrm_address_t
*saddr
);
825 extern int xfrm6_output(struct sk_buff
*skb
);
828 extern int xfrm4_rcv_encap(struct sk_buff
*skb
, __u16 encap_type
);
829 extern int xfrm_user_policy(struct sock
*sk
, int optname
, u8 __user
*optval
, int optlen
);
830 extern int xfrm_dst_lookup(struct xfrm_dst
**dst
, struct flowi
*fl
, unsigned short family
);
832 static inline int xfrm_user_policy(struct sock
*sk
, int optname
, u8 __user
*optval
, int optlen
)
837 static inline int xfrm4_rcv_encap(struct sk_buff
*skb
, __u16 encap_type
)
839 /* should not happen */
843 static inline int xfrm_dst_lookup(struct xfrm_dst
**dst
, struct flowi
*fl
, unsigned short family
)
849 struct xfrm_policy
*xfrm_policy_alloc(int gfp
);
850 extern int xfrm_policy_walk(int (*func
)(struct xfrm_policy
*, int, int, void*), void *);
851 int xfrm_policy_insert(int dir
, struct xfrm_policy
*policy
, int excl
);
852 struct xfrm_policy
*xfrm_policy_bysel(int dir
, struct xfrm_selector
*sel
,
854 struct xfrm_policy
*xfrm_policy_byid(int dir
, u32 id
, int delete);
855 void xfrm_policy_flush(void);
856 u32
xfrm_get_acqseq(void);
857 void xfrm_alloc_spi(struct xfrm_state
*x
, u32 minspi
, u32 maxspi
);
858 struct xfrm_state
* xfrm_find_acq(u8 mode
, u32 reqid
, u8 proto
,
859 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
860 int create
, unsigned short family
);
861 extern void xfrm_policy_flush(void);
862 extern int xfrm_sk_policy_insert(struct sock
*sk
, int dir
, struct xfrm_policy
*pol
);
863 extern int xfrm_flush_bundles(void);
864 extern int xfrm_bundle_ok(struct xfrm_dst
*xdst
, struct flowi
*fl
, int family
);
865 extern void xfrm_init_pmtu(struct dst_entry
*dst
);
867 extern wait_queue_head_t km_waitq
;
868 extern int km_new_mapping(struct xfrm_state
*x
, xfrm_address_t
*ipaddr
, u16 sport
);
869 extern void km_policy_expired(struct xfrm_policy
*pol
, int dir
, int hard
);
871 extern void xfrm_input_init(void);
872 extern int xfrm_parse_spi(struct sk_buff
*skb
, u8 nexthdr
, u32
*spi
, u32
*seq
);
874 extern void xfrm_probe_algs(void);
875 extern int xfrm_count_auth_supported(void);
876 extern int xfrm_count_enc_supported(void);
877 extern struct xfrm_algo_desc
*xfrm_aalg_get_byidx(unsigned int idx
);
878 extern struct xfrm_algo_desc
*xfrm_ealg_get_byidx(unsigned int idx
);
879 extern struct xfrm_algo_desc
*xfrm_aalg_get_byid(int alg_id
);
880 extern struct xfrm_algo_desc
*xfrm_ealg_get_byid(int alg_id
);
881 extern struct xfrm_algo_desc
*xfrm_calg_get_byid(int alg_id
);
882 extern struct xfrm_algo_desc
*xfrm_aalg_get_byname(char *name
, int probe
);
883 extern struct xfrm_algo_desc
*xfrm_ealg_get_byname(char *name
, int probe
);
884 extern struct xfrm_algo_desc
*xfrm_calg_get_byname(char *name
, int probe
);
887 typedef void (icv_update_fn_t
)(struct crypto_tfm
*, struct scatterlist
*, unsigned int);
889 extern void skb_icv_walk(const struct sk_buff
*skb
, struct crypto_tfm
*tfm
,
890 int offset
, int len
, icv_update_fn_t icv_update
);
892 static inline int xfrm_addr_cmp(xfrm_address_t
*a
, xfrm_address_t
*b
,
898 return a
->a4
- b
->a4
;
900 return ipv6_addr_cmp((struct in6_addr
*)a
,
901 (struct in6_addr
*)b
);
905 #endif /* _NET_XFRM_H */