blob: 872a2a4022b254c45e7be4ca3bac2b3331837fee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _NET_XFRM_H
2#define _NET_XFRM_H
3
Herbert Xuaabc9762005-05-03 16:27:10 -07004#include <linux/compiler.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -02005#include <linux/in.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/xfrm.h>
7#include <linux/spinlock.h>
8#include <linux/list.h>
9#include <linux/skbuff.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020010#include <linux/socket.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/pfkeyv2.h>
Masahide NAKAMURA57947082006-09-22 15:06:24 -070012#include <linux/ipsec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/in6.h>
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -080014#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#include <net/sock.h>
17#include <net/dst.h>
18#include <net/route.h>
19#include <net/ipv6.h>
20#include <net/ip6_fib.h>
21
22#define XFRM_ALIGN8(len) (((len) + 7) & ~7)
Herbert Xub59f45d2006-05-27 23:05:54 -070023#define MODULE_ALIAS_XFRM_MODE(family, encap) \
24 MODULE_ALIAS("xfrm-mode-" __stringify(family) "-" __stringify(encap))
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -080026extern struct sock *xfrm_nl;
27extern u32 sysctl_xfrm_aevent_etime;
28extern u32 sysctl_xfrm_aevent_rseqth;
29
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -080030extern struct mutex xfrm_cfg_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/* Organization of SPD aka "XFRM rules"
33 ------------------------------------
34
35 Basic objects:
36 - policy rule, struct xfrm_policy (=SPD entry)
37 - bundle of transformations, struct dst_entry == struct xfrm_dst (=SA bundle)
38 - instance of a transformer, struct xfrm_state (=SA)
39 - template to clone xfrm_state, struct xfrm_tmpl
40
41 SPD is plain linear list of xfrm_policy rules, ordered by priority.
42 (To be compatible with existing pfkeyv2 implementations,
43 many rules with priority of 0x7fffffff are allowed to exist and
44 such rules are ordered in an unpredictable way, thanks to bsd folks.)
45
46 Lookup is plain linear search until the first match with selector.
47
48 If "action" is "block", then we prohibit the flow, otherwise:
49 if "xfrms_nr" is zero, the flow passes untransformed. Otherwise,
50 policy entry has list of up to XFRM_MAX_DEPTH transformations,
51 described by templates xfrm_tmpl. Each template is resolved
52 to a complete xfrm_state (see below) and we pack bundle of transformations
53 to a dst_entry returned to requestor.
54
55 dst -. xfrm .-> xfrm_state #1
56 |---. child .-> dst -. xfrm .-> xfrm_state #2
57 |---. child .-> dst -. xfrm .-> xfrm_state #3
58 |---. child .-> NULL
59
60 Bundles are cached at xrfm_policy struct (field ->bundles).
61
62
63 Resolution of xrfm_tmpl
64 -----------------------
65 Template contains:
66 1. ->mode Mode: transport or tunnel
67 2. ->id.proto Protocol: AH/ESP/IPCOMP
68 3. ->id.daddr Remote tunnel endpoint, ignored for transport mode.
69 Q: allow to resolve security gateway?
70 4. ->id.spi If not zero, static SPI.
71 5. ->saddr Local tunnel endpoint, ignored for transport mode.
72 6. ->algos List of allowed algos. Plain bitmask now.
73 Q: ealgos, aalgos, calgos. What a mess...
74 7. ->share Sharing mode.
75 Q: how to implement private sharing mode? To add struct sock* to
76 flow id?
77
78 Having this template we search through SAD searching for entries
79 with appropriate mode/proto/algo, permitted by selector.
80 If no appropriate entry found, it is requested from key manager.
81
82 PROBLEMS:
83 Q: How to find all the bundles referring to a physical path for
84 PMTU discovery? Seems, dst should contain list of all parents...
85 and enter to infinite locking hierarchy disaster.
86 No! It is easier, we will not search for them, let them find us.
87 We add genid to each dst plus pointer to genid of raw IP route,
88 pmtu disc will update pmtu on raw IP route and increase its genid.
89 dst_check() will see this for top level and trigger resyncing
90 metrics. Plus, it will be made via sk->sk_dst_cache. Solved.
91 */
92
93/* Full description of state of transformer. */
94struct xfrm_state
95{
96 /* Note: bydst is re-used during gc */
97 struct list_head bydst;
Masahide NAKAMURA6c44e6b2006-08-23 17:53:57 -070098 struct list_head bysrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 struct list_head byspi;
100
101 atomic_t refcnt;
102 spinlock_t lock;
103
104 struct xfrm_id id;
105 struct xfrm_selector sel;
106
107 /* Key manger bits */
108 struct {
109 u8 state;
110 u8 dying;
111 u32 seq;
112 } km;
113
114 /* Parameters of this state. */
115 struct {
116 u32 reqid;
117 u8 mode;
118 u8 replay_window;
119 u8 aalgo, ealgo, calgo;
120 u8 flags;
121 u16 family;
122 xfrm_address_t saddr;
123 int header_len;
124 int trailer_len;
125 } props;
126
127 struct xfrm_lifetime_cfg lft;
128
129 /* Data for transformer */
130 struct xfrm_algo *aalg;
131 struct xfrm_algo *ealg;
132 struct xfrm_algo *calg;
133
134 /* Data for encapsulator */
135 struct xfrm_encap_tmpl *encap;
136
Noriaki TAKAMIYA060f02a2006-08-23 18:18:55 -0700137 /* Data for care-of address */
138 xfrm_address_t *coaddr;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* IPComp needs an IPIP tunnel for handling uncompressed packets */
141 struct xfrm_state *tunnel;
142
143 /* If a tunnel, number of users + 1 */
144 atomic_t tunnel_users;
145
146 /* State for replay detection */
147 struct xfrm_replay_state replay;
148
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -0800149 /* Replay detection state at the time we sent the last notification */
150 struct xfrm_replay_state preplay;
151
Jamal Hadi Salim27170962006-04-14 15:03:05 -0700152 /* internal flag that only holds state for delayed aevent at the
153 * moment
154 */
155 u32 xflags;
156
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -0800157 /* Replay detection notification settings */
158 u32 replay_maxage;
159 u32 replay_maxdiff;
160
161 /* Replay detection notification timer */
162 struct timer_list rtimer;
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 /* Statistics */
165 struct xfrm_stats stats;
166
167 struct xfrm_lifetime_cur curlft;
168 struct timer_list timer;
169
170 /* Reference to data common to all the instances of this
171 * transformer. */
172 struct xfrm_type *type;
Herbert Xub59f45d2006-05-27 23:05:54 -0700173 struct xfrm_mode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Trent Jaegerdf718372005-12-13 23:12:27 -0800175 /* Security context */
176 struct xfrm_sec_ctx *security;
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 /* Private data of this transformer, format is opaque,
179 * interpreted by xfrm_type methods. */
180 void *data;
181};
182
Jamal Hadi Salim27170962006-04-14 15:03:05 -0700183/* xflags - make enum if more show up */
184#define XFRM_TIME_DEFER 1
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186enum {
187 XFRM_STATE_VOID,
188 XFRM_STATE_ACQ,
189 XFRM_STATE_VALID,
190 XFRM_STATE_ERROR,
191 XFRM_STATE_EXPIRED,
192 XFRM_STATE_DEAD
193};
194
Jamal Hadi Salim26b15da2005-06-18 22:42:13 -0700195/* callback structure passed from either netlink or pfkey */
196struct km_event
197{
Herbert Xubf088672005-06-18 22:44:00 -0700198 union {
199 u32 hard;
200 u32 proto;
201 u32 byid;
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -0800202 u32 aevent;
Herbert Xubf088672005-06-18 22:44:00 -0700203 } data;
204
Jamal Hadi Salim26b15da2005-06-18 22:42:13 -0700205 u32 seq;
206 u32 pid;
207 u32 event;
208};
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210struct xfrm_type;
211struct xfrm_dst;
212struct xfrm_policy_afinfo {
213 unsigned short family;
Herbert Xu73654d62006-05-27 23:06:33 -0700214 struct xfrm_type *type_map[IPPROTO_MAX];
Herbert Xub59f45d2006-05-27 23:05:54 -0700215 struct xfrm_mode *mode_map[XFRM_MODE_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 struct dst_ops *dst_ops;
217 void (*garbage_collect)(void);
218 int (*dst_lookup)(struct xfrm_dst **dst, struct flowi *fl);
219 struct dst_entry *(*find_bundle)(struct flowi *fl, struct xfrm_policy *policy);
220 int (*bundle_create)(struct xfrm_policy *policy,
221 struct xfrm_state **xfrm,
222 int nx,
223 struct flowi *fl,
224 struct dst_entry **dst_p);
225 void (*decode_session)(struct sk_buff *skb,
226 struct flowi *fl);
227};
228
229extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
230extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
Jamal Hadi Salim26b15da2005-06-18 22:42:13 -0700231extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c);
232extern void km_state_notify(struct xfrm_state *x, struct km_event *c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#define XFRM_ACQ_EXPIRES 30
234
235struct xfrm_tmpl;
Jamal Hadi Salim980ebd22006-03-20 19:16:40 -0800236extern int km_query(struct xfrm_state *x, struct xfrm_tmpl *t, struct xfrm_policy *pol);
Jamal Hadi Salim53bc6b42006-03-20 19:17:03 -0800237extern void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
238extern int __xfrm_state_delete(struct xfrm_state *x);
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240struct xfrm_state_afinfo {
241 unsigned short family;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 struct list_head *state_bydst;
Masahide NAKAMURA6c44e6b2006-08-23 17:53:57 -0700243 struct list_head *state_bysrc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 struct list_head *state_byspi;
Herbert Xud094cd82005-06-20 13:19:41 -0700245 int (*init_flags)(struct xfrm_state *x);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 void (*init_tempsel)(struct xfrm_state *x, struct flowi *fl,
247 struct xfrm_tmpl *tmpl,
248 xfrm_address_t *daddr, xfrm_address_t *saddr);
249 struct xfrm_state *(*state_lookup)(xfrm_address_t *daddr, u32 spi, u8 proto);
Masahide NAKAMURAeb2971b2006-08-23 17:56:04 -0700250 struct xfrm_state *(*state_lookup_byaddr)(xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 struct xfrm_state *(*find_acq)(u8 mode, u32 reqid, u8 proto,
252 xfrm_address_t *daddr, xfrm_address_t *saddr,
253 int create);
254};
255
256extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
257extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
258
259extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261struct xfrm_type
262{
263 char *description;
264 struct module *owner;
265 __u8 proto;
Masahide NAKAMURA1b5c2292006-08-23 18:11:50 -0700266 __u8 flags;
267#define XFRM_TYPE_NON_FRAGMENT 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Herbert Xu72cb6962005-06-20 13:18:08 -0700269 int (*init_state)(struct xfrm_state *x);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 void (*destructor)(struct xfrm_state *);
Herbert Xue6956332006-04-01 00:52:46 -0800271 int (*input)(struct xfrm_state *, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 int (*output)(struct xfrm_state *, struct sk_buff *pskb);
Masahide NAKAMURAaee5adb2006-08-23 17:57:28 -0700273 int (*hdr_offset)(struct xfrm_state *, struct sk_buff *, u8 **);
Masahide NAKAMURA99505a82006-08-23 18:10:33 -0700274 xfrm_address_t *(*local_addr)(struct xfrm_state *, xfrm_address_t *);
275 xfrm_address_t *(*remote_addr)(struct xfrm_state *, xfrm_address_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* Estimate maximal size of result of transformation of a dgram */
277 u32 (*get_max_size)(struct xfrm_state *, int size);
278};
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280extern int xfrm_register_type(struct xfrm_type *type, unsigned short family);
281extern int xfrm_unregister_type(struct xfrm_type *type, unsigned short family);
282extern struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family);
283extern void xfrm_put_type(struct xfrm_type *type);
284
Herbert Xub59f45d2006-05-27 23:05:54 -0700285struct xfrm_mode {
286 int (*input)(struct xfrm_state *x, struct sk_buff *skb);
287 int (*output)(struct sk_buff *skb);
288
289 struct module *owner;
290 unsigned int encap;
291};
292
293extern int xfrm_register_mode(struct xfrm_mode *mode, int family);
294extern int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
295extern struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family);
296extern void xfrm_put_mode(struct xfrm_mode *mode);
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298struct xfrm_tmpl
299{
300/* id in template is interpreted as:
301 * daddr - destination of tunnel, may be zero for transport mode.
302 * spi - zero to acquire spi. Not zero if spi is static, then
303 * daddr must be fixed too.
304 * proto - AH/ESP/IPCOMP
305 */
306 struct xfrm_id id;
307
308/* Source address of tunnel. Ignored, if it is not a tunnel. */
309 xfrm_address_t saddr;
310
311 __u32 reqid;
312
Masahide NAKAMURA7e49e6d2006-09-22 15:05:15 -0700313/* Mode: transport, tunnel etc. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 __u8 mode;
315
316/* Sharing mode: unique, this session only, this user only etc. */
317 __u8 share;
318
319/* May skip this transfomration if no SA is found */
320 __u8 optional;
321
322/* Bit mask of algos allowed for acquisition */
323 __u32 aalgos;
324 __u32 ealgos;
325 __u32 calgos;
326};
327
Masahide NAKAMURA622dc822006-08-23 17:52:01 -0700328#define XFRM_MAX_DEPTH 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330struct xfrm_policy
331{
332 struct xfrm_policy *next;
333 struct list_head list;
334
335 /* This lock only affects elements except for entry. */
336 rwlock_t lock;
337 atomic_t refcnt;
338 struct timer_list timer;
339
340 u32 priority;
341 u32 index;
342 struct xfrm_selector selector;
343 struct xfrm_lifetime_cfg lft;
344 struct xfrm_lifetime_cur curlft;
345 struct dst_entry *bundles;
346 __u16 family;
347 __u8 action;
348 __u8 flags;
349 __u8 dead;
350 __u8 xfrm_nr;
Trent Jaegerdf718372005-12-13 23:12:27 -0800351 struct xfrm_sec_ctx *security;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
353};
354
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -0800355#define XFRM_KM_TIMEOUT 30
356/* which seqno */
357#define XFRM_REPLAY_SEQ 1
358#define XFRM_REPLAY_OSEQ 2
359#define XFRM_REPLAY_SEQ_MASK 3
360/* what happened */
361#define XFRM_REPLAY_UPDATE XFRM_AE_CR
362#define XFRM_REPLAY_TIMEOUT XFRM_AE_CE
363
364/* default aevent timeout in units of 100ms */
365#define XFRM_AE_ETIME 10
366/* Async Event timer multiplier */
367#define XFRM_AE_ETH_M 10
368/* default seq threshold size */
369#define XFRM_AE_SEQT_SIZE 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371struct xfrm_mgr
372{
373 struct list_head list;
374 char *id;
Jamal Hadi Salim26b15da2005-06-18 22:42:13 -0700375 int (*notify)(struct xfrm_state *x, struct km_event *c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 int (*acquire)(struct xfrm_state *x, struct xfrm_tmpl *, struct xfrm_policy *xp, int dir);
Venkat Yekkiralacb969f02006-07-24 23:32:20 -0700377 struct xfrm_policy *(*compile_policy)(struct sock *sk, int opt, u8 *data, int len, int *dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 int (*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
Jamal Hadi Salim26b15da2005-06-18 22:42:13 -0700379 int (*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380};
381
382extern int xfrm_register_km(struct xfrm_mgr *km);
383extern int xfrm_unregister_km(struct xfrm_mgr *km);
384
385
386extern struct xfrm_policy *xfrm_policy_list[XFRM_POLICY_MAX*2];
387
388static inline void xfrm_pol_hold(struct xfrm_policy *policy)
389{
390 if (likely(policy != NULL))
391 atomic_inc(&policy->refcnt);
392}
393
394extern void __xfrm_policy_destroy(struct xfrm_policy *policy);
395
396static inline void xfrm_pol_put(struct xfrm_policy *policy)
397{
398 if (atomic_dec_and_test(&policy->refcnt))
399 __xfrm_policy_destroy(policy);
400}
401
402#define XFRM_DST_HSIZE 1024
403
404static __inline__
405unsigned __xfrm4_dst_hash(xfrm_address_t *addr)
406{
407 unsigned h;
408 h = ntohl(addr->a4);
409 h = (h ^ (h>>16)) % XFRM_DST_HSIZE;
410 return h;
411}
412
413static __inline__
414unsigned __xfrm6_dst_hash(xfrm_address_t *addr)
415{
416 unsigned h;
417 h = ntohl(addr->a6[2]^addr->a6[3]);
418 h = (h ^ (h>>16)) % XFRM_DST_HSIZE;
419 return h;
420}
421
422static __inline__
423unsigned xfrm_dst_hash(xfrm_address_t *addr, unsigned short family)
424{
425 switch (family) {
426 case AF_INET:
427 return __xfrm4_dst_hash(addr);
428 case AF_INET6:
429 return __xfrm6_dst_hash(addr);
430 }
431 return 0;
432}
433
434static __inline__
Masahide NAKAMURA6c44e6b2006-08-23 17:53:57 -0700435unsigned __xfrm4_src_hash(xfrm_address_t *addr)
436{
437 return __xfrm4_dst_hash(addr);
438}
439
440static __inline__
441unsigned __xfrm6_src_hash(xfrm_address_t *addr)
442{
443 return __xfrm6_dst_hash(addr);
444}
445
446static __inline__
447unsigned xfrm_src_hash(xfrm_address_t *addr, unsigned short family)
448{
449 switch (family) {
450 case AF_INET:
451 return __xfrm4_src_hash(addr);
452 case AF_INET6:
453 return __xfrm6_src_hash(addr);
454 }
455 return 0;
456}
457
458static __inline__
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459unsigned __xfrm4_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto)
460{
461 unsigned h;
462 h = ntohl(addr->a4^spi^proto);
463 h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE;
464 return h;
465}
466
467static __inline__
468unsigned __xfrm6_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto)
469{
470 unsigned h;
471 h = ntohl(addr->a6[2]^addr->a6[3]^spi^proto);
472 h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE;
473 return h;
474}
475
476static __inline__
477unsigned xfrm_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto, unsigned short family)
478{
479 switch (family) {
480 case AF_INET:
481 return __xfrm4_spi_hash(addr, spi, proto);
482 case AF_INET6:
483 return __xfrm6_spi_hash(addr, spi, proto);
484 }
485 return 0; /*XXX*/
486}
487
488extern void __xfrm_state_destroy(struct xfrm_state *);
489
Herbert Xu21380b82006-02-22 14:47:13 -0800490static inline void __xfrm_state_put(struct xfrm_state *x)
491{
492 atomic_dec(&x->refcnt);
493}
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495static inline void xfrm_state_put(struct xfrm_state *x)
496{
497 if (atomic_dec_and_test(&x->refcnt))
498 __xfrm_state_destroy(x);
499}
500
501static inline void xfrm_state_hold(struct xfrm_state *x)
502{
503 atomic_inc(&x->refcnt);
504}
505
506static __inline__ int addr_match(void *token1, void *token2, int prefixlen)
507{
508 __u32 *a1 = token1;
509 __u32 *a2 = token2;
510 int pdw;
511 int pbi;
512
513 pdw = prefixlen >> 5; /* num of whole __u32 in prefix */
514 pbi = prefixlen & 0x1f; /* num of bits in incomplete u32 in prefix */
515
516 if (pdw)
517 if (memcmp(a1, a2, pdw << 2))
518 return 0;
519
520 if (pbi) {
521 __u32 mask;
522
523 mask = htonl((0xffffffff) << (32 - pbi));
524
525 if ((a1[pdw] ^ a2[pdw]) & mask)
526 return 0;
527 }
528
529 return 1;
530}
531
532static __inline__
533u16 xfrm_flowi_sport(struct flowi *fl)
534{
535 u16 port;
536 switch(fl->proto) {
537 case IPPROTO_TCP:
538 case IPPROTO_UDP:
539 case IPPROTO_SCTP:
540 port = fl->fl_ip_sport;
541 break;
542 case IPPROTO_ICMP:
543 case IPPROTO_ICMPV6:
544 port = htons(fl->fl_icmp_type);
545 break;
546 default:
547 port = 0; /*XXX*/
548 }
549 return port;
550}
551
552static __inline__
553u16 xfrm_flowi_dport(struct flowi *fl)
554{
555 u16 port;
556 switch(fl->proto) {
557 case IPPROTO_TCP:
558 case IPPROTO_UDP:
559 case IPPROTO_SCTP:
560 port = fl->fl_ip_dport;
561 break;
562 case IPPROTO_ICMP:
563 case IPPROTO_ICMPV6:
564 port = htons(fl->fl_icmp_code);
565 break;
566 default:
567 port = 0; /*XXX*/
568 }
569 return port;
570}
571
572static inline int
573__xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl)
574{
575 return addr_match(&fl->fl4_dst, &sel->daddr, sel->prefixlen_d) &&
576 addr_match(&fl->fl4_src, &sel->saddr, sel->prefixlen_s) &&
577 !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
578 !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
579 (fl->proto == sel->proto || !sel->proto) &&
580 (fl->oif == sel->ifindex || !sel->ifindex);
581}
582
583static inline int
584__xfrm6_selector_match(struct xfrm_selector *sel, struct flowi *fl)
585{
586 return addr_match(&fl->fl6_dst, &sel->daddr, sel->prefixlen_d) &&
587 addr_match(&fl->fl6_src, &sel->saddr, sel->prefixlen_s) &&
588 !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) &&
589 !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) &&
590 (fl->proto == sel->proto || !sel->proto) &&
591 (fl->oif == sel->ifindex || !sel->ifindex);
592}
593
594static inline int
595xfrm_selector_match(struct xfrm_selector *sel, struct flowi *fl,
596 unsigned short family)
597{
598 switch (family) {
599 case AF_INET:
600 return __xfrm4_selector_match(sel, fl);
601 case AF_INET6:
602 return __xfrm6_selector_match(sel, fl);
603 }
604 return 0;
605}
606
Trent Jaegerdf718372005-12-13 23:12:27 -0800607#ifdef CONFIG_SECURITY_NETWORK_XFRM
608/* If neither has a context --> match
609 * Otherwise, both must have a context and the sids, doi, alg must match
610 */
611static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2)
612{
613 return ((!s1 && !s2) ||
614 (s1 && s2 &&
615 (s1->ctx_sid == s2->ctx_sid) &&
616 (s1->ctx_doi == s2->ctx_doi) &&
617 (s1->ctx_alg == s2->ctx_alg)));
618}
619#else
620static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2)
621{
622 return 1;
623}
624#endif
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626/* A struct encoding bundle of transformations to apply to some set of flow.
627 *
628 * dst->child points to the next element of bundle.
629 * dst->xfrm points to an instanse of transformer.
630 *
631 * Due to unfortunate limitations of current routing cache, which we
632 * have no time to fix, it mirrors struct rtable and bound to the same
633 * routing key, including saddr,daddr. However, we can have many of
634 * bundles differing by session id. All the bundles grow from a parent
635 * policy rule.
636 */
637struct xfrm_dst
638{
639 union {
640 struct xfrm_dst *next;
641 struct dst_entry dst;
642 struct rtable rt;
643 struct rt6_info rt6;
644 } u;
645 struct dst_entry *route;
646 u32 route_mtu_cached;
647 u32 child_mtu_cached;
Hideaki YOSHIFUJI92d63dec2005-05-26 12:58:04 -0700648 u32 route_cookie;
649 u32 path_cookie;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650};
651
Herbert Xuaabc9762005-05-03 16:27:10 -0700652static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
653{
654 dst_release(xdst->route);
655 if (likely(xdst->u.dst.xfrm))
656 xfrm_state_put(xdst->u.dst.xfrm);
657}
658
659extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661struct sec_path
662{
663 atomic_t refcnt;
664 int len;
Herbert Xudbe5b4a2006-04-01 00:54:16 -0800665 struct xfrm_state *xvec[XFRM_MAX_DEPTH];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666};
667
668static inline struct sec_path *
669secpath_get(struct sec_path *sp)
670{
671 if (sp)
672 atomic_inc(&sp->refcnt);
673 return sp;
674}
675
676extern void __secpath_destroy(struct sec_path *sp);
677
678static inline void
679secpath_put(struct sec_path *sp)
680{
681 if (sp && atomic_dec_and_test(&sp->refcnt))
682 __secpath_destroy(sp);
683}
684
685extern struct sec_path *secpath_dup(struct sec_path *src);
686
687static inline void
688secpath_reset(struct sk_buff *skb)
689{
690#ifdef CONFIG_XFRM
691 secpath_put(skb->sp);
692 skb->sp = NULL;
693#endif
694}
695
696static inline int
697__xfrm4_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x)
698{
699 return (tmpl->saddr.a4 &&
700 tmpl->saddr.a4 != x->props.saddr.a4);
701}
702
703static inline int
704__xfrm6_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x)
705{
706 return (!ipv6_addr_any((struct in6_addr*)&tmpl->saddr) &&
707 ipv6_addr_cmp((struct in6_addr *)&tmpl->saddr, (struct in6_addr*)&x->props.saddr));
708}
709
710static inline int
711xfrm_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x, unsigned short family)
712{
713 switch (family) {
714 case AF_INET:
715 return __xfrm4_state_addr_cmp(tmpl, x);
716 case AF_INET6:
717 return __xfrm6_state_addr_cmp(tmpl, x);
718 }
719 return !0;
720}
721
722#ifdef CONFIG_XFRM
723
724extern int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb, unsigned short family);
725
726static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family)
727{
728 if (sk && sk->sk_policy[XFRM_POLICY_IN])
729 return __xfrm_policy_check(sk, dir, skb, family);
730
731 return (!xfrm_policy_list[dir] && !skb->sp) ||
732 (skb->dst->flags & DST_NOPOLICY) ||
733 __xfrm_policy_check(sk, dir, skb, family);
734}
735
736static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
737{
738 return xfrm_policy_check(sk, dir, skb, AF_INET);
739}
740
741static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
742{
743 return xfrm_policy_check(sk, dir, skb, AF_INET6);
744}
745
Patrick McHardy3e3850e2006-01-06 23:04:54 -0800746extern int xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family);
748
749static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family)
750{
751 return !xfrm_policy_list[XFRM_POLICY_OUT] ||
752 (skb->dst->flags & DST_NOXFRM) ||
753 __xfrm_route_forward(skb, family);
754}
755
756static inline int xfrm4_route_forward(struct sk_buff *skb)
757{
758 return xfrm_route_forward(skb, AF_INET);
759}
760
761static inline int xfrm6_route_forward(struct sk_buff *skb)
762{
763 return xfrm_route_forward(skb, AF_INET6);
764}
765
766extern int __xfrm_sk_clone_policy(struct sock *sk);
767
768static inline int xfrm_sk_clone_policy(struct sock *sk)
769{
770 if (unlikely(sk->sk_policy[0] || sk->sk_policy[1]))
771 return __xfrm_sk_clone_policy(sk);
772 return 0;
773}
774
Herbert Xu4666faa2005-06-18 22:43:22 -0700775extern int xfrm_policy_delete(struct xfrm_policy *pol, int dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777static inline void xfrm_sk_free_policy(struct sock *sk)
778{
779 if (unlikely(sk->sk_policy[0] != NULL)) {
780 xfrm_policy_delete(sk->sk_policy[0], XFRM_POLICY_MAX);
781 sk->sk_policy[0] = NULL;
782 }
783 if (unlikely(sk->sk_policy[1] != NULL)) {
784 xfrm_policy_delete(sk->sk_policy[1], XFRM_POLICY_MAX+1);
785 sk->sk_policy[1] = NULL;
786 }
787}
788
789#else
790
791static inline void xfrm_sk_free_policy(struct sock *sk) {}
792static inline int xfrm_sk_clone_policy(struct sock *sk) { return 0; }
793static inline int xfrm6_route_forward(struct sk_buff *skb) { return 1; }
794static inline int xfrm4_route_forward(struct sk_buff *skb) { return 1; }
795static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
796{
797 return 1;
798}
799static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb)
800{
801 return 1;
802}
803static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family)
804{
805 return 1;
806}
807#endif
808
809static __inline__
810xfrm_address_t *xfrm_flowi_daddr(struct flowi *fl, unsigned short family)
811{
812 switch (family){
813 case AF_INET:
814 return (xfrm_address_t *)&fl->fl4_dst;
815 case AF_INET6:
816 return (xfrm_address_t *)&fl->fl6_dst;
817 }
818 return NULL;
819}
820
821static __inline__
822xfrm_address_t *xfrm_flowi_saddr(struct flowi *fl, unsigned short family)
823{
824 switch (family){
825 case AF_INET:
826 return (xfrm_address_t *)&fl->fl4_src;
827 case AF_INET6:
828 return (xfrm_address_t *)&fl->fl6_src;
829 }
830 return NULL;
831}
832
833static __inline__ int
834__xfrm4_state_addr_check(struct xfrm_state *x,
835 xfrm_address_t *daddr, xfrm_address_t *saddr)
836{
837 if (daddr->a4 == x->id.daddr.a4 &&
838 (saddr->a4 == x->props.saddr.a4 || !saddr->a4 || !x->props.saddr.a4))
839 return 1;
840 return 0;
841}
842
843static __inline__ int
844__xfrm6_state_addr_check(struct xfrm_state *x,
845 xfrm_address_t *daddr, xfrm_address_t *saddr)
846{
847 if (!ipv6_addr_cmp((struct in6_addr *)daddr, (struct in6_addr *)&x->id.daddr) &&
848 (!ipv6_addr_cmp((struct in6_addr *)saddr, (struct in6_addr *)&x->props.saddr)||
849 ipv6_addr_any((struct in6_addr *)saddr) ||
850 ipv6_addr_any((struct in6_addr *)&x->props.saddr)))
851 return 1;
852 return 0;
853}
854
855static __inline__ int
856xfrm_state_addr_check(struct xfrm_state *x,
857 xfrm_address_t *daddr, xfrm_address_t *saddr,
858 unsigned short family)
859{
860 switch (family) {
861 case AF_INET:
862 return __xfrm4_state_addr_check(x, daddr, saddr);
863 case AF_INET6:
864 return __xfrm6_state_addr_check(x, daddr, saddr);
865 }
866 return 0;
867}
868
869static inline int xfrm_state_kern(struct xfrm_state *x)
870{
871 return atomic_read(&x->tunnel_users);
872}
873
Masahide NAKAMURA57947082006-09-22 15:06:24 -0700874static inline int xfrm_id_proto_match(u8 proto, u8 userproto)
875{
Masahide NAKAMURAdc00a522006-08-23 17:49:52 -0700876 return (!userproto || proto == userproto ||
877 (userproto == IPSEC_PROTO_ANY && (proto == IPPROTO_AH ||
878 proto == IPPROTO_ESP ||
879 proto == IPPROTO_COMP)));
Masahide NAKAMURA57947082006-09-22 15:06:24 -0700880}
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882/*
883 * xfrm algorithm information
884 */
885struct xfrm_algo_auth_info {
886 u16 icv_truncbits;
887 u16 icv_fullbits;
888};
889
890struct xfrm_algo_encr_info {
891 u16 blockbits;
892 u16 defkeybits;
893};
894
895struct xfrm_algo_comp_info {
896 u16 threshold;
897};
898
899struct xfrm_algo_desc {
900 char *name;
Herbert Xu04ff1262006-08-13 08:50:00 +1000901 char *compat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 u8 available:1;
903 union {
904 struct xfrm_algo_auth_info auth;
905 struct xfrm_algo_encr_info encr;
906 struct xfrm_algo_comp_info comp;
907 } uinfo;
908 struct sadb_alg desc;
909};
910
911/* XFRM tunnel handlers. */
912struct xfrm_tunnel {
913 int (*handler)(struct sk_buff *skb);
Herbert Xud2acc342006-03-28 01:12:13 -0800914 int (*err_handler)(struct sk_buff *skb, __u32 info);
915
916 struct xfrm_tunnel *next;
917 int priority;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918};
919
920struct xfrm6_tunnel {
Herbert Xud2acc342006-03-28 01:12:13 -0800921 int (*handler)(struct sk_buff *skb);
922 int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
923 int type, int code, int offset, __u32 info);
924
925 struct xfrm6_tunnel *next;
926 int priority;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927};
928
929extern void xfrm_init(void);
930extern void xfrm4_init(void);
931extern void xfrm6_init(void);
932extern void xfrm6_fini(void);
933extern void xfrm_state_init(void);
934extern void xfrm4_state_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935extern void xfrm6_state_init(void);
936extern void xfrm6_state_fini(void);
937
938extern int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), void *);
939extern struct xfrm_state *xfrm_state_alloc(void);
940extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr,
941 struct flowi *fl, struct xfrm_tmpl *tmpl,
942 struct xfrm_policy *pol, int *err,
943 unsigned short family);
944extern int xfrm_state_check_expire(struct xfrm_state *x);
945extern void xfrm_state_insert(struct xfrm_state *x);
946extern int xfrm_state_add(struct xfrm_state *x);
947extern int xfrm_state_update(struct xfrm_state *x);
948extern struct xfrm_state *xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family);
Masahide NAKAMURAeb2971b2006-08-23 17:56:04 -0700949extern struct xfrm_state *xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq);
Jamal Hadi Salim26b15da2005-06-18 22:42:13 -0700951extern int xfrm_state_delete(struct xfrm_state *x);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952extern void xfrm_state_flush(u8 proto);
953extern int xfrm_replay_check(struct xfrm_state *x, u32 seq);
954extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq);
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -0800955extern void xfrm_replay_notify(struct xfrm_state *x, int event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb);
957extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
Herbert Xu72cb6962005-06-20 13:18:08 -0700958extern int xfrm_init_state(struct xfrm_state *x);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959extern int xfrm4_rcv(struct sk_buff *skb);
960extern int xfrm4_output(struct sk_buff *skb);
961extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler);
962extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler);
Herbert Xud2acc342006-03-28 01:12:13 -0800963extern int xfrm6_rcv_spi(struct sk_buff *skb, u32 spi);
Patrick McHardy951dbc82006-01-06 23:02:34 -0800964extern int xfrm6_rcv(struct sk_buff **pskb);
Masahide NAKAMURAfbd9a5b2006-08-23 18:08:21 -0700965extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
966 xfrm_address_t *saddr, u8 proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler);
968extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler);
969extern u32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr);
970extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr);
971extern u32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr);
972extern int xfrm6_output(struct sk_buff *skb);
Masahide NAKAMURAaee5adb2006-08-23 17:57:28 -0700973extern int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
974 u8 **prevhdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976#ifdef CONFIG_XFRM
977extern int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type);
978extern int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen);
979extern int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family);
980#else
981static inline int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
982{
983 return -ENOPROTOOPT;
984}
985
986static inline int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
987{
988 /* should not happen */
989 kfree_skb(skb);
990 return 0;
991}
992static inline int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family)
993{
994 return -EINVAL;
995}
996#endif
997
Al Virodd0fc662005-10-07 07:46:04 +0100998struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999extern int xfrm_policy_walk(int (*func)(struct xfrm_policy *, int, int, void*), void *);
1000int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl);
Trent Jaegerdf718372005-12-13 23:12:27 -08001001struct xfrm_policy *xfrm_policy_bysel_ctx(int dir, struct xfrm_selector *sel,
1002 struct xfrm_sec_ctx *ctx, int delete);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003struct xfrm_policy *xfrm_policy_byid(int dir, u32 id, int delete);
1004void xfrm_policy_flush(void);
1005u32 xfrm_get_acqseq(void);
1006void xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);
1007struct xfrm_state * xfrm_find_acq(u8 mode, u32 reqid, u8 proto,
1008 xfrm_address_t *daddr, xfrm_address_t *saddr,
1009 int create, unsigned short family);
1010extern void xfrm_policy_flush(void);
1011extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol);
1012extern int xfrm_flush_bundles(void);
David S. Miller399c1802005-12-19 14:23:23 -08001013extern void xfrm_flush_all_bundles(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014extern int xfrm_bundle_ok(struct xfrm_dst *xdst, struct flowi *fl, int family);
1015extern void xfrm_init_pmtu(struct dst_entry *dst);
1016
1017extern wait_queue_head_t km_waitq;
1018extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport);
Jamal Hadi Salim6c5c8ca2006-03-20 19:17:25 -08001019extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021extern void xfrm_input_init(void);
1022extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq);
1023
1024extern void xfrm_probe_algs(void);
1025extern int xfrm_count_auth_supported(void);
1026extern int xfrm_count_enc_supported(void);
1027extern struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx);
1028extern struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx);
1029extern struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id);
1030extern struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id);
1031extern struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id);
1032extern struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe);
1033extern struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe);
1034extern struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe);
1035
Herbert Xu07d4ee52006-08-20 14:24:50 +10001036struct hash_desc;
Herbert Xu9409f382006-08-06 19:49:12 +10001037struct scatterlist;
Herbert Xu07d4ee52006-08-20 14:24:50 +10001038typedef int (icv_update_fn_t)(struct hash_desc *, struct scatterlist *,
1039 unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Herbert Xu07d4ee52006-08-20 14:24:50 +10001041extern int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *tfm,
1042 int offset, int len, icv_update_fn_t icv_update);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b,
1045 int family)
1046{
1047 switch (family) {
1048 default:
1049 case AF_INET:
1050 return a->a4 - b->a4;
1051 case AF_INET6:
1052 return ipv6_addr_cmp((struct in6_addr *)a,
1053 (struct in6_addr *)b);
1054 }
1055}
1056
Herbert Xu77d8d7a2005-10-05 12:15:12 -07001057static inline int xfrm_policy_id2dir(u32 index)
1058{
1059 return index & 7;
1060}
1061
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -08001062static inline int xfrm_aevent_is_on(void)
1063{
Patrick McHardybe336902006-03-20 22:40:54 -08001064 struct sock *nlsk;
1065 int ret = 0;
1066
1067 rcu_read_lock();
1068 nlsk = rcu_dereference(xfrm_nl);
1069 if (nlsk)
1070 ret = netlink_has_listeners(nlsk, XFRMNLGRP_AEVENTS);
1071 rcu_read_unlock();
1072 return ret;
Jamal Hadi Salimf8cd5482006-03-20 19:15:11 -08001073}
1074
1075static inline void xfrm_aevent_doreplay(struct xfrm_state *x)
1076{
1077 if (xfrm_aevent_is_on())
1078 xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
1079}
1080
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082#endif /* _NET_XFRM_H */