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>
14 #include <linux/mutex.h>
18 #include <net/route.h>
20 #include <net/ip6_fib.h>
22 #define XFRM_ALIGN8(len) (((len) + 7) & ~7)
24 extern struct sock *xfrm_nl;
25 extern u32 sysctl_xfrm_aevent_etime;
26 extern u32 sysctl_xfrm_aevent_rseqth;
28 extern struct mutex xfrm_cfg_mutex;
30 /* Organization of SPD aka "XFRM rules"
31 ------------------------------------
34 - policy rule, struct xfrm_policy (=SPD entry)
35 - bundle of transformations, struct dst_entry == struct xfrm_dst (=SA bundle)
36 - instance of a transformer, struct xfrm_state (=SA)
37 - template to clone xfrm_state, struct xfrm_tmpl
39 SPD is plain linear list of xfrm_policy rules, ordered by priority.
40 (To be compatible with existing pfkeyv2 implementations,
41 many rules with priority of 0x7fffffff are allowed to exist and
42 such rules are ordered in an unpredictable way, thanks to bsd folks.)
44 Lookup is plain linear search until the first match with selector.
46 If "action" is "block", then we prohibit the flow, otherwise:
47 if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
48 policy entry has list of up to XFRM_MAX_DEPTH transformations,
49 described by templates xfrm_tmpl. Each template is resolved
50 to a complete xfrm_state (see below) and we pack bundle of transformations
51 to a dst_entry returned to requestor.
53 dst -. xfrm .-> xfrm_state #1
54 |---. child .-> dst -. xfrm .-> xfrm_state #2
55 |---. child .-> dst -. xfrm .-> xfrm_state #3
58 Bundles are cached at xrfm_policy struct (field ->bundles).
61 Resolution of xrfm_tmpl
62 -----------------------
64 1. ->mode Mode: transport or tunnel
65 2. ->id.proto Protocol: AH/ESP/IPCOMP
66 3. ->id.daddr Remote tunnel endpoint, ignored for transport mode.
67 Q: allow to resolve security gateway?
68 4. ->id.spi If not zero, static SPI.
69 5. ->saddr Local tunnel endpoint, ignored for transport mode.
70 6. ->algos List of allowed algos. Plain bitmask now.
71 Q: ealgos, aalgos, calgos. What a mess...
72 7. ->share Sharing mode.
73 Q: how to implement private sharing mode? To add struct sock* to
76 Having this template we search through SAD searching for entries
77 with appropriate mode/proto/algo, permitted by selector.
78 If no appropriate entry found, it is requested from key manager.
81 Q: How to find all the bundles referring to a physical path for
82 PMTU discovery? Seems, dst should contain list of all parents...
83 and enter to infinite locking hierarchy disaster.
84 No! It is easier, we will not search for them, let them find us.
85 We add genid to each dst plus pointer to genid of raw IP route,
86 pmtu disc will update pmtu on raw IP route and increase its genid.
87 dst_check() will see this for top level and trigger resyncing
88 metrics. Plus, it will be made via sk->sk_dst_cache. Solved.
91 /* Full description of state of transformer. */
94 /* Note: bydst is re-used during gc */
95 struct list_head bydst;
96 struct list_head byspi;
102 struct xfrm_selector sel;
104 /* Key manger bits */
111 /* Parameters of this state. */
116 u8 aalgo, ealgo, calgo;
119 xfrm_address_t saddr;
124 struct xfrm_lifetime_cfg lft;
126 /* Data for transformer */
127 struct xfrm_algo *aalg;
128 struct xfrm_algo *ealg;
129 struct xfrm_algo *calg;
131 /* Data for encapsulator */
132 struct xfrm_encap_tmpl *encap;
134 /* IPComp needs an IPIP tunnel for handling uncompressed packets */
135 struct xfrm_state *tunnel;
137 /* If a tunnel, number of users + 1 */
138 atomic_t tunnel_users;
140 /* State for replay detection */
141 struct xfrm_replay_state replay;
143 /* Replay detection state at the time we sent the last notification */
144 struct xfrm_replay_state preplay;
146 /* internal flag that only holds state for delayed aevent at the
151 /* Replay detection notification settings */
155 /* Replay detection notification timer */
156 struct timer_list rtimer;
159 struct xfrm_stats stats;
161 struct xfrm_lifetime_cur curlft;
162 struct timer_list timer;
164 /* Reference to data common to all the instances of this
166 struct xfrm_type *type;
168 /* Security context */
169 struct xfrm_sec_ctx *security;
171 /* Private data of this transformer, format is opaque,
172 * interpreted by xfrm_type methods. */
176 /* xflags - make enum if more show up */
177 #define XFRM_TIME_DEFER 1
188 /* callback structure passed from either netlink or pfkey */
205 struct xfrm_policy_afinfo {
206 unsigned short family;
207 struct xfrm_type *type_map[256];
208 struct dst_ops *dst_ops;
209 void (*garbage_collect)(void);
210 int (*dst_lookup)(struct xfrm_dst **dst, struct flowi *fl);
211 struct dst_entry *(*find_bundle)(struct flowi *fl, struct xfrm_policy *policy);
212 int (*bundle_create)(struct xfrm_policy *policy,
213 struct xfrm_state **xfrm,
216 struct dst_entry **dst_p);
217 void (*decode_session)(struct sk_buff *skb,
221 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
222 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
223 extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c);
224 extern void km_state_notify(struct xfrm_state *x, struct km_event *c);
225 #define XFRM_ACQ_EXPIRES 30
228 extern int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
229 extern void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
230 extern int __xfrm_state_delete(struct xfrm_state *x);
232 struct xfrm_state_afinfo {
233 unsigned short family;
234 struct list_head *state_bydst;
235 struct list_head *state_byspi;
236 int (*init_flags)(struct xfrm_state *x);
237 void (*init_tempsel)(struct xfrm_state *x, struct flowi *fl,
238 struct xfrm_tmpl *tmpl,
239 xfrm_address_t *daddr, xfrm_address_t *saddr);
240 struct xfrm_state *(*state_lookup)(xfrm_address_t *daddr, u32 spi, u8 proto);
241 struct xfrm_state *(*find_acq)(u8 mode, u32 reqid, u8 proto,
242 xfrm_address_t *daddr, xfrm_address_t *saddr,
246 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
247 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
249 extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
254 struct module *owner;
257 int (*init_state)(struct xfrm_state *x);
258 void (*destructor)(struct xfrm_state *);
259 int (*input)(struct xfrm_state *, struct sk_buff *skb);
260 int (*output)(struct xfrm_state *, struct sk_buff *pskb);
261 /* Estimate maximal size of result of transformation of a dgram */
262 u32 (*get_max_size)(struct xfrm_state *, int size);
265 extern int xfrm_register_type(struct xfrm_type *type, unsigned short family);
266 extern int xfrm_unregister_type(struct xfrm_type *type, unsigned short family);
267 extern struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family);
268 extern void xfrm_put_type(struct xfrm_type *type);
272 /* id in template is interpreted as:
273 * daddr - destination of tunnel, may be zero for transport mode.
274 * spi - zero to acquire spi. Not zero if spi is static, then
275 * daddr must be fixed too.
276 * proto - AH/ESP/IPCOMP
280 /* Source address of tunnel. Ignored, if it is not a tunnel. */
281 xfrm_address_t saddr;
285 /* Mode: transport/tunnel */
288 /* Sharing mode: unique, this session only, this user only etc. */
291 /* May skip this transfomration if no SA is found */
294 /* Bit mask of algos allowed for acquisition */
300 #define XFRM_MAX_DEPTH 4
304 struct xfrm_policy *next;
305 struct list_head list;
307 /* This lock only affects elements except for entry. */
310 struct timer_list timer;
314 struct xfrm_selector selector;
315 struct xfrm_lifetime_cfg lft;
316 struct xfrm_lifetime_cur curlft;
317 struct dst_entry *bundles;
323 struct xfrm_sec_ctx *security;
324 struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
327 #define XFRM_KM_TIMEOUT 30
329 #define XFRM_REPLAY_SEQ 1
330 #define XFRM_REPLAY_OSEQ 2
331 #define XFRM_REPLAY_SEQ_MASK 3
333 #define XFRM_REPLAY_UPDATE XFRM_AE_CR
334 #define XFRM_REPLAY_TIMEOUT XFRM_AE_CE
336 /* default aevent timeout in units of 100ms */
337 #define XFRM_AE_ETIME 10
338 /* Async Event timer multiplier */
339 #define XFRM_AE_ETH_M 10
340 /* default seq threshold size */
341 #define XFRM_AE_SEQT_SIZE 2
345 struct list_head list;
347 int (*notify)(struct xfrm_state *x, struct km_event *c);
348 int (*acquire)(struct xfrm_state *x, struct xfrm_tmpl *, struct xfrm_policy *xp, int dir);
349 struct xfrm_policy *(*compile_policy)(u16 family, int opt, u8 *data, int len, int *dir);
350 int (*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
351 int (*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c);
354 extern int xfrm_register_km(struct xfrm_mgr *km);
355 extern int xfrm_unregister_km(struct xfrm_mgr *km);
358 extern struct xfrm_policy *xfrm_policy_list[XFRM_POLICY_MAX*2];
360 static inline void xfrm_pol_hold(struct xfrm_policy *policy)
362 if (likely(policy != NULL))
363 atomic_inc(&policy->refcnt);
366 extern void __xfrm_policy_destroy(struct xfrm_policy *policy);
368 static inline void xfrm_pol_put(struct xfrm_policy *policy)
370 if (atomic_dec_and_test(&policy->refcnt))
371 __xfrm_policy_destroy(policy);
374 #define XFRM_DST_HSIZE 1024
377 unsigned __xfrm4_dst_hash(xfrm_address_t *addr)
381 h = (h ^ (h>>16)) % XFRM_DST_HSIZE;
386 unsigned __xfrm6_dst_hash(xfrm_address_t *addr)
389 h = ntohl(addr->a6[2]^addr->a6[3]);
390 h = (h ^ (h>>16)) % XFRM_DST_HSIZE;
395 unsigned xfrm_dst_hash(xfrm_address_t *addr, unsigned short family)
399 return __xfrm4_dst_hash(addr);
401 return __xfrm6_dst_hash(addr);
407 unsigned __xfrm4_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto)
410 h = ntohl(addr->a4^spi^proto);
411 h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE;
416 unsigned __xfrm6_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto)
419 h = ntohl(addr->a6[2]^addr->a6[3]^spi^proto);
420 h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE;
425 unsigned xfrm_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto, unsigned short family)
429 return __xfrm4_spi_hash(addr, spi, proto);
431 return __xfrm6_spi_hash(addr, spi, proto);
436 extern void __xfrm_state_destroy(struct xfrm_state *);
438 static inline void __xfrm_state_put(struct xfrm_state *x)
440 atomic_dec(&x->refcnt);
443 static inline void xfrm_state_put(struct xfrm_state *x)
445 if (atomic_dec_and_test(&x->refcnt))
446 __xfrm_state_destroy(x);
449 static inline void xfrm_state_hold(struct xfrm_state *x)
451 atomic_inc(&x->refcnt);
454 static __inline__ int addr_match(void *token1, void *token2, int prefixlen)
461 pdw = prefixlen >> 5; /* num of whole __u32 in prefix */
462 pbi = prefixlen & 0x1f; /* num of bits in incomplete u32 in prefix */
465 if (memcmp(a1, a2, pdw << 2))
471 mask = htonl((0xffffffff) << (32 - pbi));
473 if ((a1[pdw] ^ a2[pdw]) & mask)
481 u16 xfrm_flowi_sport(struct flowi *fl)
488 port = fl->fl_ip_sport;
492 port = htons(fl->fl_icmp_type);
501 u16 xfrm_flowi_dport(struct flowi *fl)
508 port = fl->fl_ip_dport;
512 port = htons(fl->fl_icmp_code);
521 __xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl)
523 return addr_match(&fl->fl4_dst, &sel->daddr, sel->prefixlen_d) &&
524 addr_match(&fl->fl4_src, &sel->saddr, sel->prefixlen_s) &&
525 !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
526 !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
527 (fl->proto == sel->proto || !sel->proto) &&
528 (fl->oif == sel->ifindex || !sel->ifindex);
532 __xfrm6_selector_match(struct xfrm_selector *sel, struct flowi *fl)
534 return addr_match(&fl->fl6_dst, &sel->daddr, sel->prefixlen_d) &&
535 addr_match(&fl->fl6_src, &sel->saddr, sel->prefixlen_s) &&
536 !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
537 !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
538 (fl->proto == sel->proto || !sel->proto) &&
539 (fl->oif == sel->ifindex || !sel->ifindex);
543 xfrm_selector_match(struct xfrm_selector *sel, struct flowi *fl,
544 unsigned short family)
548 return __xfrm4_selector_match(sel, fl);
550 return __xfrm6_selector_match(sel, fl);
555 #ifdef CONFIG_SECURITY_NETWORK_XFRM
556 /* If neither has a context --> match
557 * Otherwise, both must have a context and the sids, doi, alg must match
559 static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2)
561 return ((!s1 && !s2) ||
563 (s1->ctx_sid == s2->ctx_sid) &&
564 (s1->ctx_doi == s2->ctx_doi) &&
565 (s1->ctx_alg == s2->ctx_alg)));
568 static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2)
574 /* A struct encoding bundle of transformations to apply to some set of flow.
576 * dst->child points to the next element of bundle.
577 * dst->xfrm points to an instanse of transformer.
579 * Due to unfortunate limitations of current routing cache, which we
580 * have no time to fix, it mirrors struct rtable and bound to the same
581 * routing key, including saddr,daddr. However, we can have many of
582 * bundles differing by session id. All the bundles grow from a parent
588 struct xfrm_dst *next;
589 struct dst_entry dst;
593 struct dst_entry *route;
594 u32 route_mtu_cached;
595 u32 child_mtu_cached;
600 static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
602 dst_release(xdst->route);
603 if (likely(xdst->u.dst.xfrm))
604 xfrm_state_put(xdst->u.dst.xfrm);
607 extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
613 struct xfrm_state *xvec[XFRM_MAX_DEPTH];
616 static inline struct sec_path *
617 secpath_get(struct sec_path *sp)
620 atomic_inc(&sp->refcnt);
624 extern void __secpath_destroy(struct sec_path *sp);
627 secpath_put(struct sec_path *sp)
629 if (sp && atomic_dec_and_test(&sp->refcnt))
630 __secpath_destroy(sp);
633 extern struct sec_path *secpath_dup(struct sec_path *src);
636 secpath_reset(struct sk_buff *skb)
639 secpath_put(skb->sp);
645 __xfrm4_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x)
647 return (tmpl->saddr.a4 &&
648 tmpl->saddr.a4 != x->props.saddr.a4);
652 __xfrm6_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x)
654 return (!ipv6_addr_any((struct in6_addr*)&tmpl->saddr) &&
655 ipv6_addr_cmp((struct in6_addr *)&tmpl->saddr, (struct in6_addr*)&x->props.saddr));
659 xfrm_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x, unsigned short family)
663 return __xfrm4_state_addr_cmp(tmpl, x);
665 return __xfrm6_state_addr_cmp(tmpl, x);
672 extern int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb, unsigned short family);
674 static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family)
676 if (sk && sk->sk_policy[XFRM_POLICY_IN])
677 return __xfrm_policy_check(sk, dir, skb, family);
679 return (!xfrm_policy_list[dir] && !skb->sp) ||
680 (skb->dst->flags & DST_NOPOLICY) ||
681 __xfrm_policy_check(sk, dir, skb, family);
684 static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
686 return xfrm_policy_check(sk, dir, skb, AF_INET);
689 static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
691 return xfrm_policy_check(sk, dir, skb, AF_INET6);
694 extern int xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family);
695 extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family);
697 static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family)
699 return !xfrm_policy_list[XFRM_POLICY_OUT] ||
700 (skb->dst->flags & DST_NOXFRM) ||
701 __xfrm_route_forward(skb, family);
704 static inline int xfrm4_route_forward(struct sk_buff *skb)
706 return xfrm_route_forward(skb, AF_INET);
709 static inline int xfrm6_route_forward(struct sk_buff *skb)
711 return xfrm_route_forward(skb, AF_INET6);
714 extern int __xfrm_sk_clone_policy(struct sock *sk);
716 static inline int xfrm_sk_clone_policy(struct sock *sk)
718 if (unlikely(sk->sk_policy[0] || sk->sk_policy[1]))
719 return __xfrm_sk_clone_policy(sk);
723 extern int xfrm_policy_delete(struct xfrm_policy *pol, int dir);
725 static inline void xfrm_sk_free_policy(struct sock *sk)
727 if (unlikely(sk->sk_policy[0] != NULL)) {
728 xfrm_policy_delete(sk->sk_policy[0], XFRM_POLICY_MAX);
729 sk->sk_policy[0] = NULL;
731 if (unlikely(sk->sk_policy[1] != NULL)) {
732 xfrm_policy_delete(sk->sk_policy[1], XFRM_POLICY_MAX+1);
733 sk->sk_policy[1] = NULL;
739 static inline void xfrm_sk_free_policy(struct sock *sk) {}
740 static inline int xfrm_sk_clone_policy(struct sock *sk) { return 0; }
741 static inline int xfrm6_route_forward(struct sk_buff *skb) { return 1; }
742 static inline int xfrm4_route_forward(struct sk_buff *skb) { return 1; }
743 static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
747 static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
751 static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family)
758 xfrm_address_t *xfrm_flowi_daddr(struct flowi *fl, unsigned short family)
762 return (xfrm_address_t *)&fl->fl4_dst;
764 return (xfrm_address_t *)&fl->fl6_dst;
770 xfrm_address_t *xfrm_flowi_saddr(struct flowi *fl, unsigned short family)
774 return (xfrm_address_t *)&fl->fl4_src;
776 return (xfrm_address_t *)&fl->fl6_src;
781 static __inline__ int
782 __xfrm4_state_addr_check(struct xfrm_state *x,
783 xfrm_address_t *daddr, xfrm_address_t *saddr)
785 if (daddr->a4 == x->id.daddr.a4 &&
786 (saddr->a4 == x->props.saddr.a4 || !saddr->a4 || !x->props.saddr.a4))
791 static __inline__ int
792 __xfrm6_state_addr_check(struct xfrm_state *x,
793 xfrm_address_t *daddr, xfrm_address_t *saddr)
795 if (!ipv6_addr_cmp((struct in6_addr *)daddr, (struct in6_addr *)&x->id.daddr) &&
796 (!ipv6_addr_cmp((struct in6_addr *)saddr, (struct in6_addr *)&x->props.saddr)||
797 ipv6_addr_any((struct in6_addr *)saddr) ||
798 ipv6_addr_any((struct in6_addr *)&x->props.saddr)))
803 static __inline__ int
804 xfrm_state_addr_check(struct xfrm_state *x,
805 xfrm_address_t *daddr, xfrm_address_t *saddr,
806 unsigned short family)
810 return __xfrm4_state_addr_check(x, daddr, saddr);
812 return __xfrm6_state_addr_check(x, daddr, saddr);
817 static inline int xfrm_state_kern(struct xfrm_state *x)
819 return atomic_read(&x->tunnel_users);
823 * xfrm algorithm information
825 struct xfrm_algo_auth_info {
830 struct xfrm_algo_encr_info {
835 struct xfrm_algo_comp_info {
839 struct xfrm_algo_desc {
843 struct xfrm_algo_auth_info auth;
844 struct xfrm_algo_encr_info encr;
845 struct xfrm_algo_comp_info comp;
847 struct sadb_alg desc;
850 /* XFRM tunnel handlers. */
852 int (*handler)(struct sk_buff *skb);
853 int (*err_handler)(struct sk_buff *skb, __u32 info);
855 struct xfrm_tunnel *next;
859 struct xfrm6_tunnel {
860 int (*handler)(struct sk_buff *skb);
861 int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
862 int type, int code, int offset, __u32 info);
864 struct xfrm6_tunnel *next;
868 extern void xfrm_init(void);
869 extern void xfrm4_init(void);
870 extern void xfrm6_init(void);
871 extern void xfrm6_fini(void);
872 extern void xfrm_state_init(void);
873 extern void xfrm4_state_init(void);
874 extern void xfrm6_state_init(void);
875 extern void xfrm6_state_fini(void);
877 extern int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), void *);
878 extern struct xfrm_state *xfrm_state_alloc(void);
879 extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
880 struct flowi *fl, struct xfrm_tmpl *tmpl,
881 struct xfrm_policy *pol, int *err,
882 unsigned short family);
883 extern int xfrm_state_check_expire(struct xfrm_state *x);
884 extern void xfrm_state_insert(struct xfrm_state *x);
885 extern int xfrm_state_add(struct xfrm_state *x);
886 extern int xfrm_state_update(struct xfrm_state *x);
887 extern struct xfrm_state *xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family);
888 extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq);
889 extern int xfrm_state_delete(struct xfrm_state *x);
890 extern void xfrm_state_flush(u8 proto);
891 extern int xfrm_replay_check(struct xfrm_state *x, u32 seq);
892 extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq);
893 extern void xfrm_replay_notify(struct xfrm_state *x, int event);
894 extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb);
895 extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
896 extern int xfrm_init_state(struct xfrm_state *x);
897 extern int xfrm4_rcv(struct sk_buff *skb);
898 extern int xfrm4_output(struct sk_buff *skb);
899 extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler);
900 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler);
901 extern int xfrm6_rcv_spi(struct sk_buff *skb, u32 spi);
902 extern int xfrm6_rcv(struct sk_buff **pskb);
903 extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler);
904 extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler);
905 extern u32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr);
906 extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr);
907 extern u32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr);
908 extern int xfrm6_output(struct sk_buff *skb);
911 extern int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type);
912 extern int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen);
913 extern int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family);
915 static inline int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
920 static inline int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
922 /* should not happen */
926 static inline int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family)
932 struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp);
933 extern int xfrm_policy_walk(int (*func)(struct xfrm_policy *, int, int, void*), void *);
934 int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl);
935 struct xfrm_policy *xfrm_policy_bysel_ctx(int dir, struct xfrm_selector *sel,
936 struct xfrm_sec_ctx *ctx, int delete);
937 struct xfrm_policy *xfrm_policy_byid(int dir, u32 id, int delete);
938 void xfrm_policy_flush(void);
939 u32 xfrm_get_acqseq(void);
940 void xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);
941 struct xfrm_state * xfrm_find_acq(u8 mode, u32 reqid, u8 proto,
942 xfrm_address_t *daddr, xfrm_address_t *saddr,
943 int create, unsigned short family);
944 extern void xfrm_policy_flush(void);
945 extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol);
946 extern int xfrm_flush_bundles(void);
947 extern void xfrm_flush_all_bundles(void);
948 extern int xfrm_bundle_ok(struct xfrm_dst *xdst, struct flowi *fl, int family);
949 extern void xfrm_init_pmtu(struct dst_entry *dst);
951 extern wait_queue_head_t km_waitq;
952 extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
953 extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid);
955 extern void xfrm_input_init(void);
956 extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq);
958 extern void xfrm_probe_algs(void);
959 extern int xfrm_count_auth_supported(void);
960 extern int xfrm_count_enc_supported(void);
961 extern struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx);
962 extern struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx);
963 extern struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id);
964 extern struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id);
965 extern struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id);
966 extern struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe);
967 extern struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe);
968 extern struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe);
971 typedef void (icv_update_fn_t)(struct crypto_tfm *, struct scatterlist *, unsigned int);
973 extern void skb_icv_walk(const struct sk_buff *skb, struct crypto_tfm *tfm,
974 int offset, int len, icv_update_fn_t icv_update);
976 static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b,
982 return a->a4 - b->a4;
984 return ipv6_addr_cmp((struct in6_addr *)a,
985 (struct in6_addr *)b);
989 static inline int xfrm_policy_id2dir(u32 index)
994 static inline int xfrm_aevent_is_on(void)
1000 nlsk = rcu_dereference(xfrm_nl);
1002 ret = netlink_has_listeners(nlsk, XFRMNLGRP_AEVENTS);
1007 static inline void xfrm_aevent_doreplay(struct xfrm_state *x)
1009 if (xfrm_aevent_is_on())
1010 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
1014 #endif /* _NET_XFRM_H */