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>
12 #include <linux/slab.h>
16 #include <net/route.h>
18 #include <net/ip6_fib.h>
20 #define XFRM_ALIGN8(len) (((len) + 7) & ~7)
22 extern struct semaphore xfrm_cfg_sem
;
24 /* Organization of SPD aka "XFRM rules"
25 ------------------------------------
28 - policy rule, struct xfrm_policy (=SPD entry)
29 - bundle of transformations, struct dst_entry == struct xfrm_dst (=SA bundle)
30 - instance of a transformer, struct xfrm_state (=SA)
31 - template to clone xfrm_state, struct xfrm_tmpl
33 SPD is plain linear list of xfrm_policy rules, ordered by priority.
34 (To be compatible with existing pfkeyv2 implementations,
35 many rules with priority of 0x7fffffff are allowed to exist and
36 such rules are ordered in an unpredictable way, thanks to bsd folks.)
38 Lookup is plain linear search until the first match with selector.
40 If "action" is "block", then we prohibit the flow, otherwise:
41 if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
42 policy entry has list of up to XFRM_MAX_DEPTH transformations,
43 described by templates xfrm_tmpl. Each template is resolved
44 to a complete xfrm_state (see below) and we pack bundle of transformations
45 to a dst_entry returned to requestor.
47 dst -. xfrm .-> xfrm_state #1
48 |---. child .-> dst -. xfrm .-> xfrm_state #2
49 |---. child .-> dst -. xfrm .-> xfrm_state #3
52 Bundles are cached at xrfm_policy struct (field ->bundles).
55 Resolution of xrfm_tmpl
56 -----------------------
58 1. ->mode Mode: transport or tunnel
59 2. ->id.proto Protocol: AH/ESP/IPCOMP
60 3. ->id.daddr Remote tunnel endpoint, ignored for transport mode.
61 Q: allow to resolve security gateway?
62 4. ->id.spi If not zero, static SPI.
63 5. ->saddr Local tunnel endpoint, ignored for transport mode.
64 6. ->algos List of allowed algos. Plain bitmask now.
65 Q: ealgos, aalgos, calgos. What a mess...
66 7. ->share Sharing mode.
67 Q: how to implement private sharing mode? To add struct sock* to
70 Having this template we search through SAD searching for entries
71 with appropriate mode/proto/algo, permitted by selector.
72 If no appropriate entry found, it is requested from key manager.
75 Q: How to find all the bundles referring to a physical path for
76 PMTU discovery? Seems, dst should contain list of all parents...
77 and enter to infinite locking hierarchy disaster.
78 No! It is easier, we will not search for them, let them find us.
79 We add genid to each dst plus pointer to genid of raw IP route,
80 pmtu disc will update pmtu on raw IP route and increase its genid.
81 dst_check() will see this for top level and trigger resyncing
82 metrics. Plus, it will be made via sk->sk_dst_cache. Solved.
85 /* Full description of state of transformer. */
88 /* Note: bydst is re-used during gc */
89 struct list_head bydst
;
90 struct list_head byspi
;
96 struct xfrm_selector sel
;
105 /* 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 rtable
*rt
, 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
);
181 extern struct xfrm_policy_afinfo
*xfrm_policy_get_afinfo(unsigned short family
);
182 extern void xfrm_policy_put_afinfo(struct xfrm_policy_afinfo
*afinfo
);
184 #define XFRM_ACQ_EXPIRES 30
187 struct xfrm_state_afinfo
{
188 unsigned short family
;
190 struct list_head
*state_bydst
;
191 struct list_head
*state_byspi
;
192 void (*init_tempsel
)(struct xfrm_state
*x
, struct flowi
*fl
,
193 struct xfrm_tmpl
*tmpl
,
194 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
);
195 struct xfrm_state
*(*state_lookup
)(xfrm_address_t
*daddr
, u32 spi
, u8 proto
);
196 struct xfrm_state
*(*find_acq
)(u8 mode
, u16 reqid
, u8 proto
,
197 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
201 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo
*afinfo
);
202 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo
*afinfo
);
203 extern struct xfrm_state_afinfo
*xfrm_state_get_afinfo(unsigned short family
);
204 extern void xfrm_state_put_afinfo(struct xfrm_state_afinfo
*afinfo
);
206 extern void xfrm_state_delete_tunnel(struct xfrm_state
*x
);
208 struct xfrm_decap_state
;
212 struct module
*owner
;
215 int (*init_state
)(struct xfrm_state
*x
, void *args
);
216 void (*destructor
)(struct xfrm_state
*);
217 int (*input
)(struct xfrm_state
*, struct xfrm_decap_state
*, struct sk_buff
*skb
);
218 int (*post_input
)(struct xfrm_state
*, struct xfrm_decap_state
*, struct sk_buff
*skb
);
219 int (*output
)(struct sk_buff
*skb
);
220 /* Estimate maximal size of result of transformation of a dgram */
221 u32 (*get_max_size
)(struct xfrm_state
*, int size
);
224 struct xfrm_type_map
{
226 struct xfrm_type
*map
[256];
229 extern int xfrm_register_type(struct xfrm_type
*type
, unsigned short family
);
230 extern int xfrm_unregister_type(struct xfrm_type
*type
, unsigned short family
);
231 extern struct xfrm_type
*xfrm_get_type(u8 proto
, unsigned short family
);
232 extern void xfrm_put_type(struct xfrm_type
*type
);
236 /* id in template is interpreted as:
237 * daddr - destination of tunnel, may be zero for transport mode.
238 * spi - zero to acquire spi. Not zero if spi is static, then
239 * daddr must be fixed too.
240 * proto - AH/ESP/IPCOMP
244 /* Source address of tunnel. Ignored, if it is not a tunnel. */
245 xfrm_address_t saddr
;
249 /* Mode: transport/tunnel */
252 /* Sharing mode: unique, this session only, this user only etc. */
255 /* May skip this transfomration if no SA is found */
258 /* Bit mask of algos allowed for acquisition */
264 #define XFRM_MAX_DEPTH 4
268 struct xfrm_policy
*next
;
269 struct list_head list
;
271 /* This lock only affects elements except for entry. */
274 struct timer_list timer
;
278 struct xfrm_selector selector
;
279 struct xfrm_lifetime_cfg lft
;
280 struct xfrm_lifetime_cur curlft
;
281 struct dst_entry
*bundles
;
287 struct xfrm_tmpl xfrm_vec
[XFRM_MAX_DEPTH
];
292 struct list_head list
;
294 int (*notify
)(struct xfrm_state
*x
, int event
);
295 int (*acquire
)(struct xfrm_state
*x
, struct xfrm_tmpl
*, struct xfrm_policy
*xp
, int dir
);
296 struct xfrm_policy
*(*compile_policy
)(u16 family
, int opt
, u8
*data
, int len
, int *dir
);
297 int (*new_mapping
)(struct xfrm_state
*x
, xfrm_address_t
*ipaddr
, u16 sport
);
300 extern int xfrm_register_km(struct xfrm_mgr
*km
);
301 extern int xfrm_unregister_km(struct xfrm_mgr
*km
);
304 #define XFRM_FLOWCACHE_HASH_SIZE 1024
306 static inline u32
__flow_hash4(struct flowi
*fl
)
308 u32 hash
= fl
->fl4_src
^ fl
->fl_ip_sport
;
310 hash
= ((hash
& 0xF0F0F0F0) >> 4) | ((hash
& 0x0F0F0F0F) << 4);
312 hash
^= fl
->fl4_dst
^ fl
->fl_ip_dport
;
313 hash
^= (hash
>> 10);
314 hash
^= (hash
>> 20);
315 return hash
& (XFRM_FLOWCACHE_HASH_SIZE
-1);
318 static inline u32
__flow_hash6(struct flowi
*fl
)
320 u32 hash
= fl
->fl6_src
.s6_addr32
[2] ^
321 fl
->fl6_src
.s6_addr32
[3] ^
324 hash
= ((hash
& 0xF0F0F0F0) >> 4) | ((hash
& 0x0F0F0F0F) << 4);
326 hash
^= fl
->fl6_dst
.s6_addr32
[2] ^
327 fl
->fl6_dst
.s6_addr32
[3] ^
329 hash
^= (hash
>> 10);
330 hash
^= (hash
>> 20);
331 return hash
& (XFRM_FLOWCACHE_HASH_SIZE
-1);
334 static inline u32
flow_hash(struct flowi
*fl
, unsigned short family
)
338 return __flow_hash4(fl
);
340 return __flow_hash6(fl
);
345 extern struct xfrm_policy
*xfrm_policy_list
[XFRM_POLICY_MAX
*2];
347 static inline void xfrm_pol_hold(struct xfrm_policy
*policy
)
349 if (likely(policy
!= NULL
))
350 atomic_inc(&policy
->refcnt
);
353 extern void __xfrm_policy_destroy(struct xfrm_policy
*policy
);
355 static inline void xfrm_pol_put(struct xfrm_policy
*policy
)
357 if (atomic_dec_and_test(&policy
->refcnt
))
358 __xfrm_policy_destroy(policy
);
361 #define XFRM_DST_HSIZE 1024
364 unsigned __xfrm4_dst_hash(xfrm_address_t
*addr
)
368 h
= (h
^ (h
>>16)) % XFRM_DST_HSIZE
;
373 unsigned __xfrm6_dst_hash(xfrm_address_t
*addr
)
376 h
= ntohl(addr
->a6
[2]^addr
->a6
[3]);
377 h
= (h
^ (h
>>16)) % XFRM_DST_HSIZE
;
382 unsigned xfrm_dst_hash(xfrm_address_t
*addr
, unsigned short family
)
386 return __xfrm4_dst_hash(addr
);
388 return __xfrm6_dst_hash(addr
);
394 unsigned __xfrm4_spi_hash(xfrm_address_t
*addr
, u32 spi
, u8 proto
)
397 h
= ntohl(addr
->a4
^spi
^proto
);
398 h
= (h
^ (h
>>10) ^ (h
>>20)) % XFRM_DST_HSIZE
;
403 unsigned __xfrm6_spi_hash(xfrm_address_t
*addr
, u32 spi
, u8 proto
)
406 h
= ntohl(addr
->a6
[2]^addr
->a6
[3]^spi
^proto
);
407 h
= (h
^ (h
>>10) ^ (h
>>20)) % XFRM_DST_HSIZE
;
412 unsigned xfrm_spi_hash(xfrm_address_t
*addr
, u32 spi
, u8 proto
, unsigned short family
)
416 return __xfrm4_spi_hash(addr
, spi
, proto
);
418 return __xfrm6_spi_hash(addr
, spi
, proto
);
423 extern void __xfrm_state_destroy(struct xfrm_state
*);
425 static inline void xfrm_state_put(struct xfrm_state
*x
)
427 if (atomic_dec_and_test(&x
->refcnt
))
428 __xfrm_state_destroy(x
);
431 static inline void xfrm_state_hold(struct xfrm_state
*x
)
433 atomic_inc(&x
->refcnt
);
436 static __inline__
int addr_match(void *token1
, void *token2
, int prefixlen
)
443 pdw
= prefixlen
>> 5; /* num of whole __u32 in prefix */
444 pbi
= prefixlen
& 0x1f; /* num of bits in incomplete u32 in prefix */
447 if (memcmp(a1
, a2
, pdw
<< 2))
453 mask
= htonl((0xffffffff) << (32 - pbi
));
455 if ((a1
[pdw
] ^ a2
[pdw
]) & mask
)
463 __xfrm4_selector_match(struct xfrm_selector
*sel
, struct flowi
*fl
)
465 return addr_match(&fl
->fl4_dst
, &sel
->daddr
, sel
->prefixlen_d
) &&
466 addr_match(&fl
->fl4_src
, &sel
->saddr
, sel
->prefixlen_s
) &&
467 !((fl
->fl_ip_dport
^sel
->dport
)&sel
->dport_mask
) &&
468 !((fl
->fl_ip_sport
^sel
->sport
)&sel
->sport_mask
) &&
469 (fl
->proto
== sel
->proto
|| !sel
->proto
) &&
470 (fl
->oif
== sel
->ifindex
|| !sel
->ifindex
);
474 __xfrm6_selector_match(struct xfrm_selector
*sel
, struct flowi
*fl
)
476 return addr_match(&fl
->fl6_dst
, &sel
->daddr
, sel
->prefixlen_d
) &&
477 addr_match(&fl
->fl6_src
, &sel
->saddr
, sel
->prefixlen_s
) &&
478 !((fl
->fl_ip_dport
^sel
->dport
)&sel
->dport_mask
) &&
479 !((fl
->fl_ip_sport
^sel
->sport
)&sel
->sport_mask
) &&
480 (fl
->proto
== sel
->proto
|| !sel
->proto
) &&
481 (fl
->oif
== sel
->ifindex
|| !sel
->ifindex
);
485 xfrm_selector_match(struct xfrm_selector
*sel
, struct flowi
*fl
,
486 unsigned short family
)
490 return __xfrm4_selector_match(sel
, fl
);
492 return __xfrm6_selector_match(sel
, fl
);
497 /* placeholder until xfrm6_tunnel.c is written */
498 static inline int xfrm6_tunnel_check_size(struct sk_buff
*skb
)
501 /* A struct encoding bundle of transformations to apply to some set of flow.
503 * dst->child points to the next element of bundle.
504 * dst->xfrm points to an instanse of transformer.
506 * Due to unfortunate limitations of current routing cache, which we
507 * have no time to fix, it mirrors struct rtable and bound to the same
508 * routing key, including saddr,daddr. However, we can have many of
509 * bundles differing by session id. All the bundles grow from a parent
515 struct xfrm_dst
*next
;
516 struct dst_entry dst
;
522 /* Decapsulation state, used by the input to store data during
523 * decapsulation procedure, to be used later (during the policy
526 struct xfrm_decap_state
{
531 struct sec_decap_state
{
532 struct xfrm_state
*xvec
;
533 struct xfrm_decap_state decap
;
541 struct sec_decap_state x
[XFRM_MAX_DEPTH
];
544 static inline struct sec_path
*
545 secpath_get(struct sec_path
*sp
)
548 atomic_inc(&sp
->refcnt
);
552 extern void __secpath_destroy(struct sec_path
*sp
);
555 secpath_put(struct sec_path
*sp
)
557 if (sp
&& atomic_dec_and_test(&sp
->refcnt
))
558 __secpath_destroy(sp
);
562 __xfrm4_state_addr_cmp(struct xfrm_tmpl
*tmpl
, struct xfrm_state
*x
)
564 return (tmpl
->saddr
.a4
&&
565 tmpl
->saddr
.a4
!= x
->props
.saddr
.a4
);
569 __xfrm6_state_addr_cmp(struct xfrm_tmpl
*tmpl
, struct xfrm_state
*x
)
571 return (!ipv6_addr_any((struct in6_addr
*)&tmpl
->saddr
) &&
572 ipv6_addr_cmp((struct in6_addr
*)&tmpl
->saddr
, (struct in6_addr
*)&x
->props
.saddr
));
576 xfrm_state_addr_cmp(struct xfrm_tmpl
*tmpl
, struct xfrm_state
*x
, unsigned short family
)
580 return __xfrm4_state_addr_cmp(tmpl
, x
);
582 return __xfrm6_state_addr_cmp(tmpl
, x
);
587 extern int __xfrm_policy_check(struct sock
*, int dir
, struct sk_buff
*skb
, unsigned short family
);
589 static inline int xfrm_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
, unsigned short family
)
591 if (sk
&& sk
->sk_policy
[XFRM_POLICY_IN
])
592 return __xfrm_policy_check(sk
, dir
, skb
, family
);
594 return !xfrm_policy_list
[dir
] ||
595 (skb
->dst
->flags
& DST_NOPOLICY
) ||
596 __xfrm_policy_check(sk
, dir
, skb
, family
);
599 static inline int xfrm4_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
)
601 return xfrm_policy_check(sk
, dir
, skb
, AF_INET
);
604 static inline int xfrm6_policy_check(struct sock
*sk
, int dir
, struct sk_buff
*skb
)
606 return xfrm_policy_check(sk
, dir
, skb
, AF_INET6
);
610 extern int __xfrm_route_forward(struct sk_buff
*skb
, unsigned short family
);
612 static inline int xfrm_route_forward(struct sk_buff
*skb
, unsigned short family
)
614 return !xfrm_policy_list
[XFRM_POLICY_OUT
] ||
615 (skb
->dst
->flags
& DST_NOXFRM
) ||
616 __xfrm_route_forward(skb
, family
);
619 static inline int xfrm4_route_forward(struct sk_buff
*skb
)
621 return xfrm_route_forward(skb
, AF_INET
);
624 static inline int xfrm6_route_forward(struct sk_buff
*skb
)
626 return xfrm_route_forward(skb
, AF_INET6
);
629 extern int __xfrm_sk_clone_policy(struct sock
*sk
);
631 static inline int xfrm_sk_clone_policy(struct sock
*sk
)
633 if (unlikely(sk
->sk_policy
[0] || sk
->sk_policy
[1]))
634 return __xfrm_sk_clone_policy(sk
);
638 extern void __xfrm_sk_free_policy(struct xfrm_policy
*, int dir
);
640 static inline void xfrm_sk_free_policy(struct sock
*sk
)
642 if (unlikely(sk
->sk_policy
[0] != NULL
)) {
643 __xfrm_sk_free_policy(sk
->sk_policy
[0], 0);
644 sk
->sk_policy
[0] = NULL
;
646 if (unlikely(sk
->sk_policy
[1] != NULL
)) {
647 __xfrm_sk_free_policy(sk
->sk_policy
[1], 1);
648 sk
->sk_policy
[1] = NULL
;
653 xfrm_address_t
*xfrm_flowi_daddr(struct flowi
*fl
, unsigned short family
)
657 return (xfrm_address_t
*)&fl
->fl4_dst
;
659 return (xfrm_address_t
*)&fl
->fl6_dst
;
665 xfrm_address_t
*xfrm_flowi_saddr(struct flowi
*fl
, unsigned short family
)
669 return (xfrm_address_t
*)&fl
->fl4_src
;
671 return (xfrm_address_t
*)&fl
->fl6_src
;
676 static __inline__
int
677 __xfrm4_state_addr_check(struct xfrm_state
*x
,
678 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
680 if (daddr
->a4
== x
->id
.daddr
.a4
&&
681 (saddr
->a4
== x
->props
.saddr
.a4
|| !saddr
->a4
|| !x
->props
.saddr
.a4
))
686 static __inline__
int
687 __xfrm6_state_addr_check(struct xfrm_state
*x
,
688 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
)
690 if (!ipv6_addr_cmp((struct in6_addr
*)daddr
, (struct in6_addr
*)&x
->id
.daddr
) &&
691 (!ipv6_addr_cmp((struct in6_addr
*)saddr
, (struct in6_addr
*)&x
->props
.saddr
)||
692 ipv6_addr_any((struct in6_addr
*)saddr
) ||
693 ipv6_addr_any((struct in6_addr
*)&x
->props
.saddr
)))
698 static __inline__
int
699 xfrm_state_addr_check(struct xfrm_state
*x
,
700 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
701 unsigned short family
)
705 return __xfrm4_state_addr_check(x
, daddr
, saddr
);
707 return __xfrm6_state_addr_check(x
, daddr
, saddr
);
712 static inline int xfrm_state_kern(struct xfrm_state
*x
)
714 return atomic_read(&x
->tunnel_users
);
718 * xfrm algorithm information
720 struct xfrm_algo_auth_info
{
725 struct xfrm_algo_encr_info
{
730 struct xfrm_algo_comp_info
{
734 struct xfrm_algo_desc
{
738 struct xfrm_algo_auth_info auth
;
739 struct xfrm_algo_encr_info encr
;
740 struct xfrm_algo_comp_info comp
;
742 struct sadb_alg desc
;
745 /* XFRM tunnel handlers. */
747 int (*handler
)(struct sk_buff
*skb
);
748 void (*err_handler
)(struct sk_buff
*skb
, void *info
);
751 extern void xfrm_init(void);
752 extern void xfrm4_init(void);
753 extern void xfrm4_fini(void);
754 extern void xfrm6_init(void);
755 extern void xfrm6_fini(void);
756 extern void xfrm_state_init(void);
757 extern void xfrm4_state_init(void);
758 extern void xfrm4_state_fini(void);
759 extern void xfrm6_state_init(void);
760 extern void xfrm6_state_fini(void);
762 extern int xfrm_state_walk(u8 proto
, int (*func
)(struct xfrm_state
*, int, void*), void *);
763 extern struct xfrm_state
*xfrm_state_alloc(void);
764 extern struct xfrm_state
*xfrm_state_find(xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
765 struct flowi
*fl
, struct xfrm_tmpl
*tmpl
,
766 struct xfrm_policy
*pol
, int *err
,
767 unsigned short family
);
768 extern int xfrm_state_check_expire(struct xfrm_state
*x
);
769 extern void xfrm_state_insert(struct xfrm_state
*x
);
770 extern int xfrm_state_add(struct xfrm_state
*x
);
771 extern int xfrm_state_update(struct xfrm_state
*x
);
772 extern int xfrm_state_check_space(struct xfrm_state
*x
, struct sk_buff
*skb
);
773 extern struct xfrm_state
*xfrm_state_lookup(xfrm_address_t
*daddr
, u32 spi
, u8 proto
, unsigned short family
);
774 extern struct xfrm_state
*xfrm_find_acq_byseq(u32 seq
);
775 extern void xfrm_state_delete(struct xfrm_state
*x
);
776 extern void xfrm_state_flush(u8 proto
);
777 extern int xfrm_replay_check(struct xfrm_state
*x
, u32 seq
);
778 extern void xfrm_replay_advance(struct xfrm_state
*x
, u32 seq
);
779 extern int xfrm_check_selectors(struct xfrm_state
**x
, int n
, struct flowi
*fl
);
780 extern int xfrm_check_output(struct xfrm_state
*x
, struct sk_buff
*skb
, unsigned short family
);
781 extern int xfrm4_rcv(struct sk_buff
*skb
);
782 extern int xfrm4_rcv_encap(struct sk_buff
*skb
, __u16 encap_type
);
783 extern int xfrm4_tunnel_register(struct xfrm_tunnel
*handler
);
784 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel
*handler
);
785 extern int xfrm4_tunnel_check_size(struct sk_buff
*skb
);
786 extern int xfrm6_rcv(struct sk_buff
**pskb
, unsigned int *nhoffp
);
787 extern int xfrm_user_policy(struct sock
*sk
, int optname
, u8
*optval
, int optlen
);
789 void xfrm_policy_init(void);
790 void xfrm4_policy_init(void);
791 void xfrm6_policy_init(void);
792 struct xfrm_policy
*xfrm_policy_alloc(int gfp
);
793 extern int xfrm_policy_walk(int (*func
)(struct xfrm_policy
*, int, int, void*), void *);
794 int xfrm_policy_insert(int dir
, struct xfrm_policy
*policy
, int excl
);
795 struct xfrm_policy
*xfrm_policy_bysel(int dir
, struct xfrm_selector
*sel
,
797 struct xfrm_policy
*xfrm_policy_byid(int dir
, u32 id
, int delete);
798 void xfrm_policy_flush(void);
799 u32
xfrm_get_acqseq(void);
800 void xfrm_alloc_spi(struct xfrm_state
*x
, u32 minspi
, u32 maxspi
);
801 struct xfrm_state
* xfrm_find_acq(u8 mode
, u16 reqid
, u8 proto
,
802 xfrm_address_t
*daddr
, xfrm_address_t
*saddr
,
803 int create
, unsigned short family
);
804 extern void xfrm_policy_flush(void);
805 extern void xfrm_policy_kill(struct xfrm_policy
*);
806 extern int xfrm_sk_policy_insert(struct sock
*sk
, int dir
, struct xfrm_policy
*pol
);
807 extern struct xfrm_policy
*xfrm_sk_policy_lookup(struct sock
*sk
, int dir
, struct flowi
*fl
);
808 extern int xfrm_flush_bundles(struct xfrm_state
*x
);
809 extern int xfrm_dst_lookup(struct xfrm_dst
**dst
, struct flowi
*fl
, unsigned short family
);
811 extern wait_queue_head_t km_waitq
;
812 extern void km_warn_expired(struct xfrm_state
*x
);
813 extern void km_expired(struct xfrm_state
*x
);
814 extern int km_query(struct xfrm_state
*x
, struct xfrm_tmpl
*, struct xfrm_policy
*pol
);
815 extern int km_new_mapping(struct xfrm_state
*x
, xfrm_address_t
*ipaddr
, u16 sport
);
817 extern void xfrm4_input_init(void);
818 extern void xfrm6_input_init(void);
819 extern int xfrm_parse_spi(struct sk_buff
*skb
, u8 nexthdr
, u32
*spi
, u32
*seq
);
821 extern void xfrm_probe_algs(void);
822 extern int xfrm_count_auth_supported(void);
823 extern int xfrm_count_enc_supported(void);
824 extern struct xfrm_algo_desc
*xfrm_aalg_get_byidx(unsigned int idx
);
825 extern struct xfrm_algo_desc
*xfrm_ealg_get_byidx(unsigned int idx
);
826 extern struct xfrm_algo_desc
*xfrm_calg_get_byidx(unsigned int idx
);
827 extern struct xfrm_algo_desc
*xfrm_aalg_get_byid(int alg_id
);
828 extern struct xfrm_algo_desc
*xfrm_ealg_get_byid(int alg_id
);
829 extern struct xfrm_algo_desc
*xfrm_calg_get_byid(int alg_id
);
830 extern struct xfrm_algo_desc
*xfrm_aalg_get_byname(char *name
);
831 extern struct xfrm_algo_desc
*xfrm_ealg_get_byname(char *name
);
832 extern struct xfrm_algo_desc
*xfrm_calg_get_byname(char *name
);
835 typedef void (icv_update_fn_t
)(struct crypto_tfm
*, struct scatterlist
*, unsigned int);
837 extern void skb_icv_walk(const struct sk_buff
*skb
, struct crypto_tfm
*tfm
,
838 int offset
, int len
, icv_update_fn_t icv_update
);
840 #endif /* _NET_XFRM_H */