4 #include <linux/compiler.h>
6 #include <linux/xfrm.h>
7 #include <linux/spinlock.h>
8 #include <linux/list.h>
9 #include <linux/skbuff.h>
10 #include <linux/socket.h>
11 #include <linux/crypto.h>
12 #include <linux/pfkeyv2.h>
13 #include <linux/in6.h>
17 #include <net/route.h>
19 #include <net/ip6_fib.h>
21 #define XFRM_ALIGN8(len) (((len) + 7) & ~7)
23 extern struct sock *xfrm_nl;
24 extern u32 sysctl_xfrm_aevent_etime;
25 extern u32 sysctl_xfrm_aevent_rseqth;
27 extern struct semaphore xfrm_cfg_sem;
29 /* Organization of SPD aka "XFRM rules"
30 ------------------------------------
33 - policy rule, struct xfrm_policy (=SPD entry)
34 - bundle of transformations, struct dst_entry == struct xfrm_dst (=SA bundle)
35 - instance of a transformer, struct xfrm_state (=SA)
36 - template to clone xfrm_state, struct xfrm_tmpl
38 SPD is plain linear list of xfrm_policy rules, ordered by priority.
39 (To be compatible with existing pfkeyv2 implementations,
40 many rules with priority of 0x7fffffff are allowed to exist and
41 such rules are ordered in an unpredictable way, thanks to bsd folks.)
43 Lookup is plain linear search until the first match with selector.
45 If "action" is "block", then we prohibit the flow, otherwise:
46 if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
47 policy entry has list of up to XFRM_MAX_DEPTH transformations,
48 described by templates xfrm_tmpl. Each template is resolved
49 to a complete xfrm_state (see below) and we pack bundle of transformations
50 to a dst_entry returned to requestor.
52 dst -. xfrm .-> xfrm_state #1
53 |---. child .-> dst -. xfrm .-> xfrm_state #2
54 |---. child .-> dst -. xfrm .-> xfrm_state #3
57 Bundles are cached at xrfm_policy struct (field ->bundles).
60 Resolution of xrfm_tmpl
61 -----------------------
63 1. ->mode Mode: transport or tunnel
64 2. ->id.proto Protocol: AH/ESP/IPCOMP
65 3. ->id.daddr Remote tunnel endpoint, ignored for transport mode.
66 Q: allow to resolve security gateway?
67 4. ->id.spi If not zero, static SPI.
68 5. ->saddr Local tunnel endpoint, ignored for transport mode.
69 6. ->algos List of allowed algos. Plain bitmask now.
70 Q: ealgos, aalgos, calgos. What a mess...
71 7. ->share Sharing mode.
72 Q: how to implement private sharing mode? To add struct sock* to
75 Having this template we search through SAD searching for entries
76 with appropriate mode/proto/algo, permitted by selector.
77 If no appropriate entry found, it is requested from key manager.
80 Q: How to find all the bundles referring to a physical path for
81 PMTU discovery? Seems, dst should contain list of all parents...
82 and enter to infinite locking hierarchy disaster.
83 No! It is easier, we will not search for them, let them find us.
84 We add genid to each dst plus pointer to genid of raw IP route,
85 pmtu disc will update pmtu on raw IP route and increase its genid.
86 dst_check() will see this for top level and trigger resyncing
87 metrics. Plus, it will be made via sk->sk_dst_cache. Solved.
90 /* Full description of state of transformer. */
93 /* Note: bydst is re-used during gc */
94 struct list_head bydst;
95 struct list_head byspi;
101 struct xfrm_selector sel;
103 /* Key manger bits */
110 /* Parameters of this state. */
115 u8 aalgo, ealgo, calgo;
118 xfrm_address_t saddr;
123 struct xfrm_lifetime_cfg lft;
125 /* Data for transformer */
126 struct xfrm_algo *aalg;
127 struct xfrm_algo *ealg;
128 struct xfrm_algo *calg;
130 /* Data for encapsulator */
131 struct xfrm_encap_tmpl *encap;
133 /* IPComp needs an IPIP tunnel for handling uncompressed packets */
134 struct xfrm_state *tunnel;
136 /* If a tunnel, number of users + 1 */
137 atomic_t tunnel_users;
139 /* State for replay detection */
140 struct xfrm_replay_state replay;
142 /* Replay detection state at the time we sent the last notification */
143 struct xfrm_replay_state preplay;
145 /* Replay detection notification settings */
149 /* Replay detection notification timer */
150 struct timer_list rtimer;
153 struct xfrm_stats stats;
155 struct xfrm_lifetime_cur curlft;
156 struct timer_list timer;
158 /* Reference to data common to all the instances of this
160 struct xfrm_type *type;
162 /* Security context */
163 struct xfrm_sec_ctx *security;
165 /* Private data of this transformer, format is opaque,
166 * interpreted by xfrm_type methods. */
179 /* callback structure passed from either netlink or pfkey */
196 struct xfrm_policy_afinfo {
197 unsigned short family;
199 struct xfrm_type_map *type_map;
200 struct dst_ops *dst_ops;
201 void (*garbage_collect)(void);
202 int (*dst_lookup)(struct xfrm_dst **dst, struct flowi *fl);
203 struct dst_entry *(*find_bundle)(struct flowi *fl, struct xfrm_policy *policy);
204 int (*bundle_create)(struct xfrm_policy *policy,
205 struct xfrm_state **xfrm,
208 struct dst_entry **dst_p);
209 void (*decode_session)(struct sk_buff *skb,
213 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
214 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
215 extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c);
216 extern void km_state_notify(struct xfrm_state *x, struct km_event *c);
218 #define XFRM_ACQ_EXPIRES 30
221 struct xfrm_state_afinfo {
222 unsigned short family;
224 struct list_head *state_bydst;
225 struct list_head *state_byspi;
226 int (*init_flags)(struct xfrm_state *x);
227 void (*init_tempsel)(struct xfrm_state *x, struct flowi *fl,
228 struct xfrm_tmpl *tmpl,
229 xfrm_address_t *daddr, xfrm_address_t *saddr);
230 struct xfrm_state *(*state_lookup)(xfrm_address_t *daddr, u32 spi, u8 proto);
231 struct xfrm_state *(*find_acq)(u8 mode, u32 reqid, u8 proto,
232 xfrm_address_t *daddr, xfrm_address_t *saddr,
236 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
237 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
239 extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
241 struct xfrm_decap_state;
245 struct module *owner;
248 int (*init_state)(struct xfrm_state *x);
249 void (*destructor)(struct xfrm_state *);
250 int (*input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb);
251 int (*output)(struct xfrm_state *, struct sk_buff *pskb);
252 /* Estimate maximal size of result of transformation of a dgram */
253 u32 (*get_max_size)(struct xfrm_state *, int size);
256 struct xfrm_type_map {
258 struct xfrm_type *map[256];
261 extern int xfrm_register_type(struct xfrm_type *type, unsigned short family);
262 extern int xfrm_unregister_type(struct xfrm_type *type, unsigned short family);
263 extern struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family);
264 extern void xfrm_put_type(struct xfrm_type *type);
268 /* id in template is interpreted as:
269 * daddr - destination of tunnel, may be zero for transport mode.
270 * spi - zero to acquire spi. Not zero if spi is static, then
271 * daddr must be fixed too.
272 * proto - AH/ESP/IPCOMP
276 /* Source address of tunnel. Ignored, if it is not a tunnel. */
277 xfrm_address_t saddr;
281 /* Mode: transport/tunnel */
284 /* Sharing mode: unique, this session only, this user only etc. */
287 /* May skip this transfomration if no SA is found */
290 /* Bit mask of algos allowed for acquisition */
296 #define XFRM_MAX_DEPTH 4
300 struct xfrm_policy *next;
301 struct list_head list;
303 /* This lock only affects elements except for entry. */
306 struct timer_list timer;
310 struct xfrm_selector selector;
311 struct xfrm_lifetime_cfg lft;
312 struct xfrm_lifetime_cur curlft;
313 struct dst_entry *bundles;
319 struct xfrm_sec_ctx *security;
320 struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
323 #define XFRM_KM_TIMEOUT 30
325 #define XFRM_REPLAY_SEQ 1
326 #define XFRM_REPLAY_OSEQ 2
327 #define XFRM_REPLAY_SEQ_MASK 3
329 #define XFRM_REPLAY_UPDATE XFRM_AE_CR
330 #define XFRM_REPLAY_TIMEOUT XFRM_AE_CE
332 /* default aevent timeout in units of 100ms */
333 #define XFRM_AE_ETIME 10
334 /* Async Event timer multiplier */
335 #define XFRM_AE_ETH_M 10
336 /* default seq threshold size */
337 #define XFRM_AE_SEQT_SIZE 2
341 struct list_head list;
343 int (*notify)(struct xfrm_state *x, struct km_event *c);
344 int (*acquire)(struct xfrm_state *x, struct xfrm_tmpl *, struct xfrm_policy *xp, int dir);
345 struct xfrm_policy *(*compile_policy)(u16 family, int opt, u8 *data, int len, int *dir);
346 int (*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
347 int (*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c);
350 extern int xfrm_register_km(struct xfrm_mgr *km);
351 extern int xfrm_unregister_km(struct xfrm_mgr *km);
354 extern struct xfrm_policy *xfrm_policy_list[XFRM_POLICY_MAX*2];
356 static inline void xfrm_pol_hold(struct xfrm_policy *policy)
358 if (likely(policy != NULL))
359 atomic_inc(&policy->refcnt);
362 extern void __xfrm_policy_destroy(struct xfrm_policy *policy);
364 static inline void xfrm_pol_put(struct xfrm_policy *policy)
366 if (atomic_dec_and_test(&policy->refcnt))
367 __xfrm_policy_destroy(policy);
370 #define XFRM_DST_HSIZE 1024
373 unsigned __xfrm4_dst_hash(xfrm_address_t *addr)
377 h = (h ^ (h>>16)) % XFRM_DST_HSIZE;
382 unsigned __xfrm6_dst_hash(xfrm_address_t *addr)
385 h = ntohl(addr->a6[2]^addr->a6[3]);
386 h = (h ^ (h>>16)) % XFRM_DST_HSIZE;
391 unsigned xfrm_dst_hash(xfrm_address_t *addr, unsigned short family)
395 return __xfrm4_dst_hash(addr);
397 return __xfrm6_dst_hash(addr);
403 unsigned __xfrm4_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto)
406 h = ntohl(addr->a4^spi^proto);
407 h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE;
412 unsigned __xfrm6_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto)
415 h = ntohl(addr->a6[2]^addr->a6[3]^spi^proto);
416 h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE;
421 unsigned xfrm_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto, unsigned short family)
425 return __xfrm4_spi_hash(addr, spi, proto);
427 return __xfrm6_spi_hash(addr, spi, proto);
432 extern void __xfrm_state_destroy(struct xfrm_state *);
434 static inline void __xfrm_state_put(struct xfrm_state *x)
436 atomic_dec(&x->refcnt);
439 static inline void xfrm_state_put(struct xfrm_state *x)
441 if (atomic_dec_and_test(&x->refcnt))
442 __xfrm_state_destroy(x);
445 static inline void xfrm_state_hold(struct xfrm_state *x)
447 atomic_inc(&x->refcnt);
450 static __inline__ int addr_match(void *token1, void *token2, int prefixlen)
457 pdw = prefixlen >> 5; /* num of whole __u32 in prefix */
458 pbi = prefixlen & 0x1f; /* num of bits in incomplete u32 in prefix */
461 if (memcmp(a1, a2, pdw << 2))
467 mask = htonl((0xffffffff) << (32 - pbi));
469 if ((a1[pdw] ^ a2[pdw]) & mask)
477 u16 xfrm_flowi_sport(struct flowi *fl)
484 port = fl->fl_ip_sport;
488 port = htons(fl->fl_icmp_type);
497 u16 xfrm_flowi_dport(struct flowi *fl)
504 port = fl->fl_ip_dport;
508 port = htons(fl->fl_icmp_code);
517 __xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl)
519 return addr_match(&fl->fl4_dst, &sel->daddr, sel->prefixlen_d) &&
520 addr_match(&fl->fl4_src, &sel->saddr, sel->prefixlen_s) &&
521 !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
522 !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
523 (fl->proto == sel->proto || !sel->proto) &&
524 (fl->oif == sel->ifindex || !sel->ifindex);
528 __xfrm6_selector_match(struct xfrm_selector *sel, struct flowi *fl)
530 return addr_match(&fl->fl6_dst, &sel->daddr, sel->prefixlen_d) &&
531 addr_match(&fl->fl6_src, &sel->saddr, sel->prefixlen_s) &&
532 !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
533 !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
534 (fl->proto == sel->proto || !sel->proto) &&
535 (fl->oif == sel->ifindex || !sel->ifindex);
539 xfrm_selector_match(struct xfrm_selector *sel, struct flowi *fl,
540 unsigned short family)
544 return __xfrm4_selector_match(sel, fl);
546 return __xfrm6_selector_match(sel, fl);
551 #ifdef CONFIG_SECURITY_NETWORK_XFRM
552 /* If neither has a context --> match
553 * Otherwise, both must have a context and the sids, doi, alg must match
555 static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2)
557 return ((!s1 && !s2) ||
559 (s1->ctx_sid == s2->ctx_sid) &&
560 (s1->ctx_doi == s2->ctx_doi) &&
561 (s1->ctx_alg == s2->ctx_alg)));
564 static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2)
570 /* A struct encoding bundle of transformations to apply to some set of flow.
572 * dst->child points to the next element of bundle.
573 * dst->xfrm points to an instanse of transformer.
575 * Due to unfortunate limitations of current routing cache, which we
576 * have no time to fix, it mirrors struct rtable and bound to the same
577 * routing key, including saddr,daddr. However, we can have many of
578 * bundles differing by session id. All the bundles grow from a parent
584 struct xfrm_dst *next;
585 struct dst_entry dst;
589 struct dst_entry *route;
590 u32 route_mtu_cached;
591 u32 child_mtu_cached;
596 static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
598 dst_release(xdst->route);
599 if (likely(xdst->u.dst.xfrm))
600 xfrm_state_put(xdst->u.dst.xfrm);
603 extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
605 /* Decapsulation state, used by the input to store data during
606 * decapsulation procedure, to be used later (during the policy
609 struct xfrm_decap_state {
614 struct sec_decap_state {
615 struct xfrm_state *xvec;
616 struct xfrm_decap_state decap;
623 struct sec_decap_state x[XFRM_MAX_DEPTH];
626 static inline struct sec_path *
627 secpath_get(struct sec_path *sp)
630 atomic_inc(&sp->refcnt);
634 extern void __secpath_destroy(struct sec_path *sp);
637 secpath_put(struct sec_path *sp)
639 if (sp && atomic_dec_and_test(&sp->refcnt))
640 __secpath_destroy(sp);
643 extern struct sec_path *secpath_dup(struct sec_path *src);
646 secpath_reset(struct sk_buff *skb)
649 secpath_put(skb->sp);
655 __xfrm4_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x)
657 return (tmpl->saddr.a4 &&
658 tmpl->saddr.a4 != x->props.saddr.a4);
662 __xfrm6_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x)
664 return (!ipv6_addr_any((struct in6_addr*)&tmpl->saddr) &&
665 ipv6_addr_cmp((struct in6_addr *)&tmpl->saddr, (struct in6_addr*)&x->props.saddr));
669 xfrm_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x, unsigned short family)
673 return __xfrm4_state_addr_cmp(tmpl, x);
675 return __xfrm6_state_addr_cmp(tmpl, x);
682 extern int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb, unsigned short family);
684 static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family)
686 if (sk && sk->sk_policy[XFRM_POLICY_IN])
687 return __xfrm_policy_check(sk, dir, skb, family);
689 return (!xfrm_policy_list[dir] && !skb->sp) ||
690 (skb->dst->flags & DST_NOPOLICY) ||
691 __xfrm_policy_check(sk, dir, skb, family);
694 static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
696 return xfrm_policy_check(sk, dir, skb, AF_INET);
699 static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
701 return xfrm_policy_check(sk, dir, skb, AF_INET6);
704 extern int xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family);
705 extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family);
707 static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family)
709 return !xfrm_policy_list[XFRM_POLICY_OUT] ||
710 (skb->dst->flags & DST_NOXFRM) ||
711 __xfrm_route_forward(skb, family);
714 static inline int xfrm4_route_forward(struct sk_buff *skb)
716 return xfrm_route_forward(skb, AF_INET);
719 static inline int xfrm6_route_forward(struct sk_buff *skb)
721 return xfrm_route_forward(skb, AF_INET6);
724 extern int __xfrm_sk_clone_policy(struct sock *sk);
726 static inline int xfrm_sk_clone_policy(struct sock *sk)
728 if (unlikely(sk->sk_policy[0] || sk->sk_policy[1]))
729 return __xfrm_sk_clone_policy(sk);
733 extern int xfrm_policy_delete(struct xfrm_policy *pol, int dir);
735 static inline void xfrm_sk_free_policy(struct sock *sk)
737 if (unlikely(sk->sk_policy[0] != NULL)) {
738 xfrm_policy_delete(sk->sk_policy[0], XFRM_POLICY_MAX);
739 sk->sk_policy[0] = NULL;
741 if (unlikely(sk->sk_policy[1] != NULL)) {
742 xfrm_policy_delete(sk->sk_policy[1], XFRM_POLICY_MAX+1);
743 sk->sk_policy[1] = NULL;
749 static inline void xfrm_sk_free_policy(struct sock *sk) {}
750 static inline int xfrm_sk_clone_policy(struct sock *sk) { return 0; }
751 static inline int xfrm6_route_forward(struct sk_buff *skb) { return 1; }
752 static inline int xfrm4_route_forward(struct sk_buff *skb) { return 1; }
753 static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
757 static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
761 static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family)
768 xfrm_address_t *xfrm_flowi_daddr(struct flowi *fl, unsigned short family)
772 return (xfrm_address_t *)&fl->fl4_dst;
774 return (xfrm_address_t *)&fl->fl6_dst;
780 xfrm_address_t *xfrm_flowi_saddr(struct flowi *fl, unsigned short family)
784 return (xfrm_address_t *)&fl->fl4_src;
786 return (xfrm_address_t *)&fl->fl6_src;
791 static __inline__ int
792 __xfrm4_state_addr_check(struct xfrm_state *x,
793 xfrm_address_t *daddr, xfrm_address_t *saddr)
795 if (daddr->a4 == x->id.daddr.a4 &&
796 (saddr->a4 == x->props.saddr.a4 || !saddr->a4 || !x->props.saddr.a4))
801 static __inline__ int
802 __xfrm6_state_addr_check(struct xfrm_state *x,
803 xfrm_address_t *daddr, xfrm_address_t *saddr)
805 if (!ipv6_addr_cmp((struct in6_addr *)daddr, (struct in6_addr *)&x->id.daddr) &&
806 (!ipv6_addr_cmp((struct in6_addr *)saddr, (struct in6_addr *)&x->props.saddr)||
807 ipv6_addr_any((struct in6_addr *)saddr) ||
808 ipv6_addr_any((struct in6_addr *)&x->props.saddr)))
813 static __inline__ int
814 xfrm_state_addr_check(struct xfrm_state *x,
815 xfrm_address_t *daddr, xfrm_address_t *saddr,
816 unsigned short family)
820 return __xfrm4_state_addr_check(x, daddr, saddr);
822 return __xfrm6_state_addr_check(x, daddr, saddr);
827 static inline int xfrm_state_kern(struct xfrm_state *x)
829 return atomic_read(&x->tunnel_users);
833 * xfrm algorithm information
835 struct xfrm_algo_auth_info {
840 struct xfrm_algo_encr_info {
845 struct xfrm_algo_comp_info {
849 struct xfrm_algo_desc {
853 struct xfrm_algo_auth_info auth;
854 struct xfrm_algo_encr_info encr;
855 struct xfrm_algo_comp_info comp;
857 struct sadb_alg desc;
860 /* XFRM tunnel handlers. */
862 int (*handler)(struct sk_buff *skb);
863 void (*err_handler)(struct sk_buff *skb, __u32 info);
866 struct xfrm6_tunnel {
867 int (*handler)(struct sk_buff **pskb);
868 void (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
869 int type, int code, int offset, __u32 info);
872 extern void xfrm_init(void);
873 extern void xfrm4_init(void);
874 extern void xfrm6_init(void);
875 extern void xfrm6_fini(void);
876 extern void xfrm_state_init(void);
877 extern void xfrm4_state_init(void);
878 extern void xfrm6_state_init(void);
879 extern void xfrm6_state_fini(void);
881 extern int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), void *);
882 extern struct xfrm_state *xfrm_state_alloc(void);
883 extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
884 struct flowi *fl, struct xfrm_tmpl *tmpl,
885 struct xfrm_policy *pol, int *err,
886 unsigned short family);
887 extern int xfrm_state_check_expire(struct xfrm_state *x);
888 extern void xfrm_state_insert(struct xfrm_state *x);
889 extern int xfrm_state_add(struct xfrm_state *x);
890 extern int xfrm_state_update(struct xfrm_state *x);
891 extern struct xfrm_state *xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family);
892 extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq);
893 extern int xfrm_state_delete(struct xfrm_state *x);
894 extern void xfrm_state_flush(u8 proto);
895 extern int xfrm_replay_check(struct xfrm_state *x, u32 seq);
896 extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq);
897 extern void xfrm_replay_notify(struct xfrm_state *x, int event);
898 extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb);
899 extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
900 extern int xfrm_init_state(struct xfrm_state *x);
901 extern int xfrm4_rcv(struct sk_buff *skb);
902 extern int xfrm4_output(struct sk_buff *skb);
903 extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler);
904 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler);
905 extern int xfrm6_rcv_spi(struct sk_buff **pskb, u32 spi);
906 extern int xfrm6_rcv(struct sk_buff **pskb);
907 extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler);
908 extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler);
909 extern u32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr);
910 extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr);
911 extern u32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr);
912 extern int xfrm6_output(struct sk_buff *skb);
915 extern int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type);
916 extern int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen);
917 extern int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family);
919 static inline int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
924 static inline int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
926 /* should not happen */
930 static inline int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family)
936 struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp);
937 extern int xfrm_policy_walk(int (*func)(struct xfrm_policy *, int, int, void*), void *);
938 int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl);
939 struct xfrm_policy *xfrm_policy_bysel_ctx(int dir, struct xfrm_selector *sel,
940 struct xfrm_sec_ctx *ctx, int delete);
941 struct xfrm_policy *xfrm_policy_byid(int dir, u32 id, int delete);
942 void xfrm_policy_flush(void);
943 u32 xfrm_get_acqseq(void);
944 void xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);
945 struct xfrm_state * xfrm_find_acq(u8 mode, u32 reqid, u8 proto,
946 xfrm_address_t *daddr, xfrm_address_t *saddr,
947 int create, unsigned short family);
948 extern void xfrm_policy_flush(void);
949 extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol);
950 extern int xfrm_flush_bundles(void);
951 extern void xfrm_flush_all_bundles(void);
952 extern int xfrm_bundle_ok(struct xfrm_dst *xdst, struct flowi *fl, int family);
953 extern void xfrm_init_pmtu(struct dst_entry *dst);
955 extern wait_queue_head_t km_waitq;
956 extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
957 extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard);
959 extern void xfrm_input_init(void);
960 extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq);
962 extern void xfrm_probe_algs(void);
963 extern int xfrm_count_auth_supported(void);
964 extern int xfrm_count_enc_supported(void);
965 extern struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx);
966 extern struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx);
967 extern struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id);
968 extern struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id);
969 extern struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id);
970 extern struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe);
971 extern struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe);
972 extern struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe);
975 typedef void (icv_update_fn_t)(struct crypto_tfm *, struct scatterlist *, unsigned int);
977 extern void skb_icv_walk(const struct sk_buff *skb, struct crypto_tfm *tfm,
978 int offset, int len, icv_update_fn_t icv_update);
980 static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b,
986 return a->a4 - b->a4;
988 return ipv6_addr_cmp((struct in6_addr *)a,
989 (struct in6_addr *)b);
993 static inline int xfrm_policy_id2dir(u32 index)
998 static inline int xfrm_aevent_is_on(void)
1000 return netlink_has_listeners(xfrm_nl,XFRMNLGRP_AEVENTS);
1003 static inline void xfrm_aevent_doreplay(struct xfrm_state *x)
1005 if (xfrm_aevent_is_on())
1006 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
1010 #endif /* _NET_XFRM_H */