Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _NET_XFRM_H |
| 2 | #define _NET_XFRM_H |
| 3 | |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 4 | #include <linux/compiler.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 5 | #include <linux/in.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/xfrm.h> |
| 7 | #include <linux/spinlock.h> |
| 8 | #include <linux/list.h> |
| 9 | #include <linux/skbuff.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 10 | #include <linux/socket.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/crypto.h> |
| 12 | #include <linux/pfkeyv2.h> |
| 13 | #include <linux/in6.h> |
| 14 | |
| 15 | #include <net/sock.h> |
| 16 | #include <net/dst.h> |
| 17 | #include <net/route.h> |
| 18 | #include <net/ipv6.h> |
| 19 | #include <net/ip6_fib.h> |
| 20 | |
| 21 | #define XFRM_ALIGN8(len) (((len) + 7) & ~7) |
| 22 | |
| 23 | extern struct semaphore xfrm_cfg_sem; |
| 24 | |
| 25 | /* Organization of SPD aka "XFRM rules" |
| 26 | ------------------------------------ |
| 27 | |
| 28 | Basic objects: |
| 29 | - policy rule, struct xfrm_policy (=SPD entry) |
| 30 | - bundle of transformations, struct dst_entry == struct xfrm_dst (=SA bundle) |
| 31 | - instance of a transformer, struct xfrm_state (=SA) |
| 32 | - template to clone xfrm_state, struct xfrm_tmpl |
| 33 | |
| 34 | SPD is plain linear list of xfrm_policy rules, ordered by priority. |
| 35 | (To be compatible with existing pfkeyv2 implementations, |
| 36 | many rules with priority of 0x7fffffff are allowed to exist and |
| 37 | such rules are ordered in an unpredictable way, thanks to bsd folks.) |
| 38 | |
| 39 | Lookup is plain linear search until the first match with selector. |
| 40 | |
| 41 | If "action" is "block", then we prohibit the flow, otherwise: |
| 42 | if "xfrms_nr" is zero, the flow passes untransformed. Otherwise, |
| 43 | policy entry has list of up to XFRM_MAX_DEPTH transformations, |
| 44 | described by templates xfrm_tmpl. Each template is resolved |
| 45 | to a complete xfrm_state (see below) and we pack bundle of transformations |
| 46 | to a dst_entry returned to requestor. |
| 47 | |
| 48 | dst -. xfrm .-> xfrm_state #1 |
| 49 | |---. child .-> dst -. xfrm .-> xfrm_state #2 |
| 50 | |---. child .-> dst -. xfrm .-> xfrm_state #3 |
| 51 | |---. child .-> NULL |
| 52 | |
| 53 | Bundles are cached at xrfm_policy struct (field ->bundles). |
| 54 | |
| 55 | |
| 56 | Resolution of xrfm_tmpl |
| 57 | ----------------------- |
| 58 | Template contains: |
| 59 | 1. ->mode Mode: transport or tunnel |
| 60 | 2. ->id.proto Protocol: AH/ESP/IPCOMP |
| 61 | 3. ->id.daddr Remote tunnel endpoint, ignored for transport mode. |
| 62 | Q: allow to resolve security gateway? |
| 63 | 4. ->id.spi If not zero, static SPI. |
| 64 | 5. ->saddr Local tunnel endpoint, ignored for transport mode. |
| 65 | 6. ->algos List of allowed algos. Plain bitmask now. |
| 66 | Q: ealgos, aalgos, calgos. What a mess... |
| 67 | 7. ->share Sharing mode. |
| 68 | Q: how to implement private sharing mode? To add struct sock* to |
| 69 | flow id? |
| 70 | |
| 71 | Having this template we search through SAD searching for entries |
| 72 | with appropriate mode/proto/algo, permitted by selector. |
| 73 | If no appropriate entry found, it is requested from key manager. |
| 74 | |
| 75 | PROBLEMS: |
| 76 | Q: How to find all the bundles referring to a physical path for |
| 77 | PMTU discovery? Seems, dst should contain list of all parents... |
| 78 | and enter to infinite locking hierarchy disaster. |
| 79 | No! It is easier, we will not search for them, let them find us. |
| 80 | We add genid to each dst plus pointer to genid of raw IP route, |
| 81 | pmtu disc will update pmtu on raw IP route and increase its genid. |
| 82 | dst_check() will see this for top level and trigger resyncing |
| 83 | metrics. Plus, it will be made via sk->sk_dst_cache. Solved. |
| 84 | */ |
| 85 | |
| 86 | /* Full description of state of transformer. */ |
| 87 | struct xfrm_state |
| 88 | { |
| 89 | /* Note: bydst is re-used during gc */ |
| 90 | struct list_head bydst; |
| 91 | struct list_head byspi; |
| 92 | |
| 93 | atomic_t refcnt; |
| 94 | spinlock_t lock; |
| 95 | |
| 96 | struct xfrm_id id; |
| 97 | struct xfrm_selector sel; |
| 98 | |
| 99 | /* Key manger bits */ |
| 100 | struct { |
| 101 | u8 state; |
| 102 | u8 dying; |
| 103 | u32 seq; |
| 104 | } km; |
| 105 | |
| 106 | /* Parameters of this state. */ |
| 107 | struct { |
| 108 | u32 reqid; |
| 109 | u8 mode; |
| 110 | u8 replay_window; |
| 111 | u8 aalgo, ealgo, calgo; |
| 112 | u8 flags; |
| 113 | u16 family; |
| 114 | xfrm_address_t saddr; |
| 115 | int header_len; |
| 116 | int trailer_len; |
| 117 | } props; |
| 118 | |
| 119 | struct xfrm_lifetime_cfg lft; |
| 120 | |
| 121 | /* Data for transformer */ |
| 122 | struct xfrm_algo *aalg; |
| 123 | struct xfrm_algo *ealg; |
| 124 | struct xfrm_algo *calg; |
| 125 | |
| 126 | /* Data for encapsulator */ |
| 127 | struct xfrm_encap_tmpl *encap; |
| 128 | |
| 129 | /* IPComp needs an IPIP tunnel for handling uncompressed packets */ |
| 130 | struct xfrm_state *tunnel; |
| 131 | |
| 132 | /* If a tunnel, number of users + 1 */ |
| 133 | atomic_t tunnel_users; |
| 134 | |
| 135 | /* State for replay detection */ |
| 136 | struct xfrm_replay_state replay; |
| 137 | |
| 138 | /* Statistics */ |
| 139 | struct xfrm_stats stats; |
| 140 | |
| 141 | struct xfrm_lifetime_cur curlft; |
| 142 | struct timer_list timer; |
| 143 | |
| 144 | /* Reference to data common to all the instances of this |
| 145 | * transformer. */ |
| 146 | struct xfrm_type *type; |
| 147 | |
Trent Jaeger | df71837 | 2005-12-13 23:12:27 -0800 | [diff] [blame] | 148 | /* Security context */ |
| 149 | struct xfrm_sec_ctx *security; |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* Private data of this transformer, format is opaque, |
| 152 | * interpreted by xfrm_type methods. */ |
| 153 | void *data; |
| 154 | }; |
| 155 | |
| 156 | enum { |
| 157 | XFRM_STATE_VOID, |
| 158 | XFRM_STATE_ACQ, |
| 159 | XFRM_STATE_VALID, |
| 160 | XFRM_STATE_ERROR, |
| 161 | XFRM_STATE_EXPIRED, |
| 162 | XFRM_STATE_DEAD |
| 163 | }; |
| 164 | |
Jamal Hadi Salim | 26b15da | 2005-06-18 22:42:13 -0700 | [diff] [blame] | 165 | /* callback structure passed from either netlink or pfkey */ |
| 166 | struct km_event |
| 167 | { |
Herbert Xu | bf08867 | 2005-06-18 22:44:00 -0700 | [diff] [blame] | 168 | union { |
| 169 | u32 hard; |
| 170 | u32 proto; |
| 171 | u32 byid; |
| 172 | } data; |
| 173 | |
Jamal Hadi Salim | 26b15da | 2005-06-18 22:42:13 -0700 | [diff] [blame] | 174 | u32 seq; |
| 175 | u32 pid; |
| 176 | u32 event; |
| 177 | }; |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | struct xfrm_type; |
| 180 | struct xfrm_dst; |
| 181 | struct xfrm_policy_afinfo { |
| 182 | unsigned short family; |
| 183 | rwlock_t lock; |
| 184 | struct xfrm_type_map *type_map; |
| 185 | struct dst_ops *dst_ops; |
| 186 | void (*garbage_collect)(void); |
| 187 | int (*dst_lookup)(struct xfrm_dst **dst, struct flowi *fl); |
| 188 | struct dst_entry *(*find_bundle)(struct flowi *fl, struct xfrm_policy *policy); |
| 189 | int (*bundle_create)(struct xfrm_policy *policy, |
| 190 | struct xfrm_state **xfrm, |
| 191 | int nx, |
| 192 | struct flowi *fl, |
| 193 | struct dst_entry **dst_p); |
| 194 | void (*decode_session)(struct sk_buff *skb, |
| 195 | struct flowi *fl); |
| 196 | }; |
| 197 | |
| 198 | extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo); |
| 199 | extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo); |
Jamal Hadi Salim | 26b15da | 2005-06-18 22:42:13 -0700 | [diff] [blame] | 200 | extern void km_policy_notify(struct xfrm_policy *xp, int dir, struct km_event *c); |
| 201 | extern void km_state_notify(struct xfrm_state *x, struct km_event *c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | #define XFRM_ACQ_EXPIRES 30 |
| 204 | |
| 205 | struct xfrm_tmpl; |
| 206 | struct xfrm_state_afinfo { |
| 207 | unsigned short family; |
| 208 | rwlock_t lock; |
| 209 | struct list_head *state_bydst; |
| 210 | struct list_head *state_byspi; |
Herbert Xu | d094cd8 | 2005-06-20 13:19:41 -0700 | [diff] [blame] | 211 | int (*init_flags)(struct xfrm_state *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | void (*init_tempsel)(struct xfrm_state *x, struct flowi *fl, |
| 213 | struct xfrm_tmpl *tmpl, |
| 214 | xfrm_address_t *daddr, xfrm_address_t *saddr); |
| 215 | struct xfrm_state *(*state_lookup)(xfrm_address_t *daddr, u32 spi, u8 proto); |
| 216 | struct xfrm_state *(*find_acq)(u8 mode, u32 reqid, u8 proto, |
| 217 | xfrm_address_t *daddr, xfrm_address_t *saddr, |
| 218 | int create); |
| 219 | }; |
| 220 | |
| 221 | extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo); |
| 222 | extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo); |
| 223 | |
| 224 | extern void xfrm_state_delete_tunnel(struct xfrm_state *x); |
| 225 | |
| 226 | struct xfrm_decap_state; |
| 227 | struct xfrm_type |
| 228 | { |
| 229 | char *description; |
| 230 | struct module *owner; |
| 231 | __u8 proto; |
| 232 | |
Herbert Xu | 72cb696 | 2005-06-20 13:18:08 -0700 | [diff] [blame] | 233 | int (*init_state)(struct xfrm_state *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | void (*destructor)(struct xfrm_state *); |
| 235 | int (*input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb); |
| 236 | int (*post_input)(struct xfrm_state *, struct xfrm_decap_state *, struct sk_buff *skb); |
| 237 | int (*output)(struct xfrm_state *, struct sk_buff *pskb); |
| 238 | /* Estimate maximal size of result of transformation of a dgram */ |
| 239 | u32 (*get_max_size)(struct xfrm_state *, int size); |
| 240 | }; |
| 241 | |
| 242 | struct xfrm_type_map { |
| 243 | rwlock_t lock; |
| 244 | struct xfrm_type *map[256]; |
| 245 | }; |
| 246 | |
| 247 | extern int xfrm_register_type(struct xfrm_type *type, unsigned short family); |
| 248 | extern int xfrm_unregister_type(struct xfrm_type *type, unsigned short family); |
| 249 | extern struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family); |
| 250 | extern void xfrm_put_type(struct xfrm_type *type); |
| 251 | |
| 252 | struct xfrm_tmpl |
| 253 | { |
| 254 | /* id in template is interpreted as: |
| 255 | * daddr - destination of tunnel, may be zero for transport mode. |
| 256 | * spi - zero to acquire spi. Not zero if spi is static, then |
| 257 | * daddr must be fixed too. |
| 258 | * proto - AH/ESP/IPCOMP |
| 259 | */ |
| 260 | struct xfrm_id id; |
| 261 | |
| 262 | /* Source address of tunnel. Ignored, if it is not a tunnel. */ |
| 263 | xfrm_address_t saddr; |
| 264 | |
| 265 | __u32 reqid; |
| 266 | |
| 267 | /* Mode: transport/tunnel */ |
| 268 | __u8 mode; |
| 269 | |
| 270 | /* Sharing mode: unique, this session only, this user only etc. */ |
| 271 | __u8 share; |
| 272 | |
| 273 | /* May skip this transfomration if no SA is found */ |
| 274 | __u8 optional; |
| 275 | |
| 276 | /* Bit mask of algos allowed for acquisition */ |
| 277 | __u32 aalgos; |
| 278 | __u32 ealgos; |
| 279 | __u32 calgos; |
| 280 | }; |
| 281 | |
| 282 | #define XFRM_MAX_DEPTH 4 |
| 283 | |
| 284 | struct xfrm_policy |
| 285 | { |
| 286 | struct xfrm_policy *next; |
| 287 | struct list_head list; |
| 288 | |
| 289 | /* This lock only affects elements except for entry. */ |
| 290 | rwlock_t lock; |
| 291 | atomic_t refcnt; |
| 292 | struct timer_list timer; |
| 293 | |
| 294 | u32 priority; |
| 295 | u32 index; |
| 296 | struct xfrm_selector selector; |
| 297 | struct xfrm_lifetime_cfg lft; |
| 298 | struct xfrm_lifetime_cur curlft; |
| 299 | struct dst_entry *bundles; |
| 300 | __u16 family; |
| 301 | __u8 action; |
| 302 | __u8 flags; |
| 303 | __u8 dead; |
| 304 | __u8 xfrm_nr; |
Trent Jaeger | df71837 | 2005-12-13 23:12:27 -0800 | [diff] [blame] | 305 | struct xfrm_sec_ctx *security; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH]; |
| 307 | }; |
| 308 | |
| 309 | #define XFRM_KM_TIMEOUT 30 |
| 310 | |
| 311 | struct xfrm_mgr |
| 312 | { |
| 313 | struct list_head list; |
| 314 | char *id; |
Jamal Hadi Salim | 26b15da | 2005-06-18 22:42:13 -0700 | [diff] [blame] | 315 | int (*notify)(struct xfrm_state *x, struct km_event *c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | int (*acquire)(struct xfrm_state *x, struct xfrm_tmpl *, struct xfrm_policy *xp, int dir); |
| 317 | struct xfrm_policy *(*compile_policy)(u16 family, int opt, u8 *data, int len, int *dir); |
| 318 | int (*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport); |
Jamal Hadi Salim | 26b15da | 2005-06-18 22:42:13 -0700 | [diff] [blame] | 319 | int (*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | extern int xfrm_register_km(struct xfrm_mgr *km); |
| 323 | extern int xfrm_unregister_km(struct xfrm_mgr *km); |
| 324 | |
| 325 | |
| 326 | extern struct xfrm_policy *xfrm_policy_list[XFRM_POLICY_MAX*2]; |
| 327 | |
| 328 | static inline void xfrm_pol_hold(struct xfrm_policy *policy) |
| 329 | { |
| 330 | if (likely(policy != NULL)) |
| 331 | atomic_inc(&policy->refcnt); |
| 332 | } |
| 333 | |
| 334 | extern void __xfrm_policy_destroy(struct xfrm_policy *policy); |
| 335 | |
| 336 | static inline void xfrm_pol_put(struct xfrm_policy *policy) |
| 337 | { |
| 338 | if (atomic_dec_and_test(&policy->refcnt)) |
| 339 | __xfrm_policy_destroy(policy); |
| 340 | } |
| 341 | |
| 342 | #define XFRM_DST_HSIZE 1024 |
| 343 | |
| 344 | static __inline__ |
| 345 | unsigned __xfrm4_dst_hash(xfrm_address_t *addr) |
| 346 | { |
| 347 | unsigned h; |
| 348 | h = ntohl(addr->a4); |
| 349 | h = (h ^ (h>>16)) % XFRM_DST_HSIZE; |
| 350 | return h; |
| 351 | } |
| 352 | |
| 353 | static __inline__ |
| 354 | unsigned __xfrm6_dst_hash(xfrm_address_t *addr) |
| 355 | { |
| 356 | unsigned h; |
| 357 | h = ntohl(addr->a6[2]^addr->a6[3]); |
| 358 | h = (h ^ (h>>16)) % XFRM_DST_HSIZE; |
| 359 | return h; |
| 360 | } |
| 361 | |
| 362 | static __inline__ |
| 363 | unsigned xfrm_dst_hash(xfrm_address_t *addr, unsigned short family) |
| 364 | { |
| 365 | switch (family) { |
| 366 | case AF_INET: |
| 367 | return __xfrm4_dst_hash(addr); |
| 368 | case AF_INET6: |
| 369 | return __xfrm6_dst_hash(addr); |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static __inline__ |
| 375 | unsigned __xfrm4_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto) |
| 376 | { |
| 377 | unsigned h; |
| 378 | h = ntohl(addr->a4^spi^proto); |
| 379 | h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE; |
| 380 | return h; |
| 381 | } |
| 382 | |
| 383 | static __inline__ |
| 384 | unsigned __xfrm6_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto) |
| 385 | { |
| 386 | unsigned h; |
| 387 | h = ntohl(addr->a6[2]^addr->a6[3]^spi^proto); |
| 388 | h = (h ^ (h>>10) ^ (h>>20)) % XFRM_DST_HSIZE; |
| 389 | return h; |
| 390 | } |
| 391 | |
| 392 | static __inline__ |
| 393 | unsigned xfrm_spi_hash(xfrm_address_t *addr, u32 spi, u8 proto, unsigned short family) |
| 394 | { |
| 395 | switch (family) { |
| 396 | case AF_INET: |
| 397 | return __xfrm4_spi_hash(addr, spi, proto); |
| 398 | case AF_INET6: |
| 399 | return __xfrm6_spi_hash(addr, spi, proto); |
| 400 | } |
| 401 | return 0; /*XXX*/ |
| 402 | } |
| 403 | |
| 404 | extern void __xfrm_state_destroy(struct xfrm_state *); |
| 405 | |
| 406 | static inline void xfrm_state_put(struct xfrm_state *x) |
| 407 | { |
| 408 | if (atomic_dec_and_test(&x->refcnt)) |
| 409 | __xfrm_state_destroy(x); |
| 410 | } |
| 411 | |
| 412 | static inline void xfrm_state_hold(struct xfrm_state *x) |
| 413 | { |
| 414 | atomic_inc(&x->refcnt); |
| 415 | } |
| 416 | |
| 417 | static __inline__ int addr_match(void *token1, void *token2, int prefixlen) |
| 418 | { |
| 419 | __u32 *a1 = token1; |
| 420 | __u32 *a2 = token2; |
| 421 | int pdw; |
| 422 | int pbi; |
| 423 | |
| 424 | pdw = prefixlen >> 5; /* num of whole __u32 in prefix */ |
| 425 | pbi = prefixlen & 0x1f; /* num of bits in incomplete u32 in prefix */ |
| 426 | |
| 427 | if (pdw) |
| 428 | if (memcmp(a1, a2, pdw << 2)) |
| 429 | return 0; |
| 430 | |
| 431 | if (pbi) { |
| 432 | __u32 mask; |
| 433 | |
| 434 | mask = htonl((0xffffffff) << (32 - pbi)); |
| 435 | |
| 436 | if ((a1[pdw] ^ a2[pdw]) & mask) |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | return 1; |
| 441 | } |
| 442 | |
| 443 | static __inline__ |
| 444 | u16 xfrm_flowi_sport(struct flowi *fl) |
| 445 | { |
| 446 | u16 port; |
| 447 | switch(fl->proto) { |
| 448 | case IPPROTO_TCP: |
| 449 | case IPPROTO_UDP: |
| 450 | case IPPROTO_SCTP: |
| 451 | port = fl->fl_ip_sport; |
| 452 | break; |
| 453 | case IPPROTO_ICMP: |
| 454 | case IPPROTO_ICMPV6: |
| 455 | port = htons(fl->fl_icmp_type); |
| 456 | break; |
| 457 | default: |
| 458 | port = 0; /*XXX*/ |
| 459 | } |
| 460 | return port; |
| 461 | } |
| 462 | |
| 463 | static __inline__ |
| 464 | u16 xfrm_flowi_dport(struct flowi *fl) |
| 465 | { |
| 466 | u16 port; |
| 467 | switch(fl->proto) { |
| 468 | case IPPROTO_TCP: |
| 469 | case IPPROTO_UDP: |
| 470 | case IPPROTO_SCTP: |
| 471 | port = fl->fl_ip_dport; |
| 472 | break; |
| 473 | case IPPROTO_ICMP: |
| 474 | case IPPROTO_ICMPV6: |
| 475 | port = htons(fl->fl_icmp_code); |
| 476 | break; |
| 477 | default: |
| 478 | port = 0; /*XXX*/ |
| 479 | } |
| 480 | return port; |
| 481 | } |
| 482 | |
| 483 | static inline int |
| 484 | __xfrm4_selector_match(struct xfrm_selector *sel, struct flowi *fl) |
| 485 | { |
| 486 | return addr_match(&fl->fl4_dst, &sel->daddr, sel->prefixlen_d) && |
| 487 | addr_match(&fl->fl4_src, &sel->saddr, sel->prefixlen_s) && |
| 488 | !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) && |
| 489 | !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) && |
| 490 | (fl->proto == sel->proto || !sel->proto) && |
| 491 | (fl->oif == sel->ifindex || !sel->ifindex); |
| 492 | } |
| 493 | |
| 494 | static inline int |
| 495 | __xfrm6_selector_match(struct xfrm_selector *sel, struct flowi *fl) |
| 496 | { |
| 497 | return addr_match(&fl->fl6_dst, &sel->daddr, sel->prefixlen_d) && |
| 498 | addr_match(&fl->fl6_src, &sel->saddr, sel->prefixlen_s) && |
| 499 | !((xfrm_flowi_dport(fl) ^ sel->dport) & sel->dport_mask) && |
| 500 | !((xfrm_flowi_sport(fl) ^ sel->sport) & sel->sport_mask) && |
| 501 | (fl->proto == sel->proto || !sel->proto) && |
| 502 | (fl->oif == sel->ifindex || !sel->ifindex); |
| 503 | } |
| 504 | |
| 505 | static inline int |
| 506 | xfrm_selector_match(struct xfrm_selector *sel, struct flowi *fl, |
| 507 | unsigned short family) |
| 508 | { |
| 509 | switch (family) { |
| 510 | case AF_INET: |
| 511 | return __xfrm4_selector_match(sel, fl); |
| 512 | case AF_INET6: |
| 513 | return __xfrm6_selector_match(sel, fl); |
| 514 | } |
| 515 | return 0; |
| 516 | } |
| 517 | |
Trent Jaeger | df71837 | 2005-12-13 23:12:27 -0800 | [diff] [blame] | 518 | #ifdef CONFIG_SECURITY_NETWORK_XFRM |
| 519 | /* If neither has a context --> match |
| 520 | * Otherwise, both must have a context and the sids, doi, alg must match |
| 521 | */ |
| 522 | static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2) |
| 523 | { |
| 524 | return ((!s1 && !s2) || |
| 525 | (s1 && s2 && |
| 526 | (s1->ctx_sid == s2->ctx_sid) && |
| 527 | (s1->ctx_doi == s2->ctx_doi) && |
| 528 | (s1->ctx_alg == s2->ctx_alg))); |
| 529 | } |
| 530 | #else |
| 531 | static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ctx *s2) |
| 532 | { |
| 533 | return 1; |
| 534 | } |
| 535 | #endif |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* A struct encoding bundle of transformations to apply to some set of flow. |
| 538 | * |
| 539 | * dst->child points to the next element of bundle. |
| 540 | * dst->xfrm points to an instanse of transformer. |
| 541 | * |
| 542 | * Due to unfortunate limitations of current routing cache, which we |
| 543 | * have no time to fix, it mirrors struct rtable and bound to the same |
| 544 | * routing key, including saddr,daddr. However, we can have many of |
| 545 | * bundles differing by session id. All the bundles grow from a parent |
| 546 | * policy rule. |
| 547 | */ |
| 548 | struct xfrm_dst |
| 549 | { |
| 550 | union { |
| 551 | struct xfrm_dst *next; |
| 552 | struct dst_entry dst; |
| 553 | struct rtable rt; |
| 554 | struct rt6_info rt6; |
| 555 | } u; |
| 556 | struct dst_entry *route; |
| 557 | u32 route_mtu_cached; |
| 558 | u32 child_mtu_cached; |
Hideaki YOSHIFUJI | 92d63de | 2005-05-26 12:58:04 -0700 | [diff] [blame] | 559 | u32 route_cookie; |
| 560 | u32 path_cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | }; |
| 562 | |
Herbert Xu | aabc976 | 2005-05-03 16:27:10 -0700 | [diff] [blame] | 563 | static inline void xfrm_dst_destroy(struct xfrm_dst *xdst) |
| 564 | { |
| 565 | dst_release(xdst->route); |
| 566 | if (likely(xdst->u.dst.xfrm)) |
| 567 | xfrm_state_put(xdst->u.dst.xfrm); |
| 568 | } |
| 569 | |
| 570 | extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev); |
| 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | /* Decapsulation state, used by the input to store data during |
| 573 | * decapsulation procedure, to be used later (during the policy |
| 574 | * check |
| 575 | */ |
| 576 | struct xfrm_decap_state { |
| 577 | char decap_data[20]; |
| 578 | __u16 decap_type; |
| 579 | }; |
| 580 | |
| 581 | struct sec_decap_state { |
| 582 | struct xfrm_state *xvec; |
| 583 | struct xfrm_decap_state decap; |
| 584 | }; |
| 585 | |
| 586 | struct sec_path |
| 587 | { |
| 588 | atomic_t refcnt; |
| 589 | int len; |
| 590 | struct sec_decap_state x[XFRM_MAX_DEPTH]; |
| 591 | }; |
| 592 | |
| 593 | static inline struct sec_path * |
| 594 | secpath_get(struct sec_path *sp) |
| 595 | { |
| 596 | if (sp) |
| 597 | atomic_inc(&sp->refcnt); |
| 598 | return sp; |
| 599 | } |
| 600 | |
| 601 | extern void __secpath_destroy(struct sec_path *sp); |
| 602 | |
| 603 | static inline void |
| 604 | secpath_put(struct sec_path *sp) |
| 605 | { |
| 606 | if (sp && atomic_dec_and_test(&sp->refcnt)) |
| 607 | __secpath_destroy(sp); |
| 608 | } |
| 609 | |
| 610 | extern struct sec_path *secpath_dup(struct sec_path *src); |
| 611 | |
| 612 | static inline void |
| 613 | secpath_reset(struct sk_buff *skb) |
| 614 | { |
| 615 | #ifdef CONFIG_XFRM |
| 616 | secpath_put(skb->sp); |
| 617 | skb->sp = NULL; |
| 618 | #endif |
| 619 | } |
| 620 | |
| 621 | static inline int |
| 622 | __xfrm4_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x) |
| 623 | { |
| 624 | return (tmpl->saddr.a4 && |
| 625 | tmpl->saddr.a4 != x->props.saddr.a4); |
| 626 | } |
| 627 | |
| 628 | static inline int |
| 629 | __xfrm6_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x) |
| 630 | { |
| 631 | return (!ipv6_addr_any((struct in6_addr*)&tmpl->saddr) && |
| 632 | ipv6_addr_cmp((struct in6_addr *)&tmpl->saddr, (struct in6_addr*)&x->props.saddr)); |
| 633 | } |
| 634 | |
| 635 | static inline int |
| 636 | xfrm_state_addr_cmp(struct xfrm_tmpl *tmpl, struct xfrm_state *x, unsigned short family) |
| 637 | { |
| 638 | switch (family) { |
| 639 | case AF_INET: |
| 640 | return __xfrm4_state_addr_cmp(tmpl, x); |
| 641 | case AF_INET6: |
| 642 | return __xfrm6_state_addr_cmp(tmpl, x); |
| 643 | } |
| 644 | return !0; |
| 645 | } |
| 646 | |
| 647 | #ifdef CONFIG_XFRM |
| 648 | |
| 649 | extern int __xfrm_policy_check(struct sock *, int dir, struct sk_buff *skb, unsigned short family); |
| 650 | |
| 651 | static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family) |
| 652 | { |
| 653 | if (sk && sk->sk_policy[XFRM_POLICY_IN]) |
| 654 | return __xfrm_policy_check(sk, dir, skb, family); |
| 655 | |
| 656 | return (!xfrm_policy_list[dir] && !skb->sp) || |
| 657 | (skb->dst->flags & DST_NOPOLICY) || |
| 658 | __xfrm_policy_check(sk, dir, skb, family); |
| 659 | } |
| 660 | |
| 661 | static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb) |
| 662 | { |
| 663 | return xfrm_policy_check(sk, dir, skb, AF_INET); |
| 664 | } |
| 665 | |
| 666 | static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb) |
| 667 | { |
| 668 | return xfrm_policy_check(sk, dir, skb, AF_INET6); |
| 669 | } |
| 670 | |
Patrick McHardy | 3e3850e | 2006-01-06 23:04:54 -0800 | [diff] [blame^] | 671 | extern int xfrm_decode_session(struct sk_buff *skb, struct flowi *fl, unsigned short family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family); |
| 673 | |
| 674 | static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) |
| 675 | { |
| 676 | return !xfrm_policy_list[XFRM_POLICY_OUT] || |
| 677 | (skb->dst->flags & DST_NOXFRM) || |
| 678 | __xfrm_route_forward(skb, family); |
| 679 | } |
| 680 | |
| 681 | static inline int xfrm4_route_forward(struct sk_buff *skb) |
| 682 | { |
| 683 | return xfrm_route_forward(skb, AF_INET); |
| 684 | } |
| 685 | |
| 686 | static inline int xfrm6_route_forward(struct sk_buff *skb) |
| 687 | { |
| 688 | return xfrm_route_forward(skb, AF_INET6); |
| 689 | } |
| 690 | |
| 691 | extern int __xfrm_sk_clone_policy(struct sock *sk); |
| 692 | |
| 693 | static inline int xfrm_sk_clone_policy(struct sock *sk) |
| 694 | { |
| 695 | if (unlikely(sk->sk_policy[0] || sk->sk_policy[1])) |
| 696 | return __xfrm_sk_clone_policy(sk); |
| 697 | return 0; |
| 698 | } |
| 699 | |
Herbert Xu | 4666faa | 2005-06-18 22:43:22 -0700 | [diff] [blame] | 700 | extern int xfrm_policy_delete(struct xfrm_policy *pol, int dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | static inline void xfrm_sk_free_policy(struct sock *sk) |
| 703 | { |
| 704 | if (unlikely(sk->sk_policy[0] != NULL)) { |
| 705 | xfrm_policy_delete(sk->sk_policy[0], XFRM_POLICY_MAX); |
| 706 | sk->sk_policy[0] = NULL; |
| 707 | } |
| 708 | if (unlikely(sk->sk_policy[1] != NULL)) { |
| 709 | xfrm_policy_delete(sk->sk_policy[1], XFRM_POLICY_MAX+1); |
| 710 | sk->sk_policy[1] = NULL; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | #else |
| 715 | |
| 716 | static inline void xfrm_sk_free_policy(struct sock *sk) {} |
| 717 | static inline int xfrm_sk_clone_policy(struct sock *sk) { return 0; } |
| 718 | static inline int xfrm6_route_forward(struct sk_buff *skb) { return 1; } |
| 719 | static inline int xfrm4_route_forward(struct sk_buff *skb) { return 1; } |
| 720 | static inline int xfrm6_policy_check(struct sock *sk, int dir, struct sk_buff *skb) |
| 721 | { |
| 722 | return 1; |
| 723 | } |
| 724 | static inline int xfrm4_policy_check(struct sock *sk, int dir, struct sk_buff *skb) |
| 725 | { |
| 726 | return 1; |
| 727 | } |
| 728 | static inline int xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, unsigned short family) |
| 729 | { |
| 730 | return 1; |
| 731 | } |
| 732 | #endif |
| 733 | |
| 734 | static __inline__ |
| 735 | xfrm_address_t *xfrm_flowi_daddr(struct flowi *fl, unsigned short family) |
| 736 | { |
| 737 | switch (family){ |
| 738 | case AF_INET: |
| 739 | return (xfrm_address_t *)&fl->fl4_dst; |
| 740 | case AF_INET6: |
| 741 | return (xfrm_address_t *)&fl->fl6_dst; |
| 742 | } |
| 743 | return NULL; |
| 744 | } |
| 745 | |
| 746 | static __inline__ |
| 747 | xfrm_address_t *xfrm_flowi_saddr(struct flowi *fl, unsigned short family) |
| 748 | { |
| 749 | switch (family){ |
| 750 | case AF_INET: |
| 751 | return (xfrm_address_t *)&fl->fl4_src; |
| 752 | case AF_INET6: |
| 753 | return (xfrm_address_t *)&fl->fl6_src; |
| 754 | } |
| 755 | return NULL; |
| 756 | } |
| 757 | |
| 758 | static __inline__ int |
| 759 | __xfrm4_state_addr_check(struct xfrm_state *x, |
| 760 | xfrm_address_t *daddr, xfrm_address_t *saddr) |
| 761 | { |
| 762 | if (daddr->a4 == x->id.daddr.a4 && |
| 763 | (saddr->a4 == x->props.saddr.a4 || !saddr->a4 || !x->props.saddr.a4)) |
| 764 | return 1; |
| 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | static __inline__ int |
| 769 | __xfrm6_state_addr_check(struct xfrm_state *x, |
| 770 | xfrm_address_t *daddr, xfrm_address_t *saddr) |
| 771 | { |
| 772 | if (!ipv6_addr_cmp((struct in6_addr *)daddr, (struct in6_addr *)&x->id.daddr) && |
| 773 | (!ipv6_addr_cmp((struct in6_addr *)saddr, (struct in6_addr *)&x->props.saddr)|| |
| 774 | ipv6_addr_any((struct in6_addr *)saddr) || |
| 775 | ipv6_addr_any((struct in6_addr *)&x->props.saddr))) |
| 776 | return 1; |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | static __inline__ int |
| 781 | xfrm_state_addr_check(struct xfrm_state *x, |
| 782 | xfrm_address_t *daddr, xfrm_address_t *saddr, |
| 783 | unsigned short family) |
| 784 | { |
| 785 | switch (family) { |
| 786 | case AF_INET: |
| 787 | return __xfrm4_state_addr_check(x, daddr, saddr); |
| 788 | case AF_INET6: |
| 789 | return __xfrm6_state_addr_check(x, daddr, saddr); |
| 790 | } |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | static inline int xfrm_state_kern(struct xfrm_state *x) |
| 795 | { |
| 796 | return atomic_read(&x->tunnel_users); |
| 797 | } |
| 798 | |
| 799 | /* |
| 800 | * xfrm algorithm information |
| 801 | */ |
| 802 | struct xfrm_algo_auth_info { |
| 803 | u16 icv_truncbits; |
| 804 | u16 icv_fullbits; |
| 805 | }; |
| 806 | |
| 807 | struct xfrm_algo_encr_info { |
| 808 | u16 blockbits; |
| 809 | u16 defkeybits; |
| 810 | }; |
| 811 | |
| 812 | struct xfrm_algo_comp_info { |
| 813 | u16 threshold; |
| 814 | }; |
| 815 | |
| 816 | struct xfrm_algo_desc { |
| 817 | char *name; |
| 818 | u8 available:1; |
| 819 | union { |
| 820 | struct xfrm_algo_auth_info auth; |
| 821 | struct xfrm_algo_encr_info encr; |
| 822 | struct xfrm_algo_comp_info comp; |
| 823 | } uinfo; |
| 824 | struct sadb_alg desc; |
| 825 | }; |
| 826 | |
| 827 | /* XFRM tunnel handlers. */ |
| 828 | struct xfrm_tunnel { |
| 829 | int (*handler)(struct sk_buff *skb); |
Patrick McHardy | 0303770 | 2005-07-19 14:03:34 -0700 | [diff] [blame] | 830 | void (*err_handler)(struct sk_buff *skb, __u32 info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | }; |
| 832 | |
| 833 | struct xfrm6_tunnel { |
Patrick McHardy | 951dbc8 | 2006-01-06 23:02:34 -0800 | [diff] [blame] | 834 | int (*handler)(struct sk_buff **pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | void (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt, |
| 836 | int type, int code, int offset, __u32 info); |
| 837 | }; |
| 838 | |
| 839 | extern void xfrm_init(void); |
| 840 | extern void xfrm4_init(void); |
| 841 | extern void xfrm6_init(void); |
| 842 | extern void xfrm6_fini(void); |
| 843 | extern void xfrm_state_init(void); |
| 844 | extern void xfrm4_state_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | extern void xfrm6_state_init(void); |
| 846 | extern void xfrm6_state_fini(void); |
| 847 | |
| 848 | extern int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), void *); |
| 849 | extern struct xfrm_state *xfrm_state_alloc(void); |
| 850 | extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr, |
| 851 | struct flowi *fl, struct xfrm_tmpl *tmpl, |
| 852 | struct xfrm_policy *pol, int *err, |
| 853 | unsigned short family); |
| 854 | extern int xfrm_state_check_expire(struct xfrm_state *x); |
| 855 | extern void xfrm_state_insert(struct xfrm_state *x); |
| 856 | extern int xfrm_state_add(struct xfrm_state *x); |
| 857 | extern int xfrm_state_update(struct xfrm_state *x); |
| 858 | extern struct xfrm_state *xfrm_state_lookup(xfrm_address_t *daddr, u32 spi, u8 proto, unsigned short family); |
| 859 | extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq); |
Jamal Hadi Salim | 26b15da | 2005-06-18 22:42:13 -0700 | [diff] [blame] | 860 | extern int xfrm_state_delete(struct xfrm_state *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | extern void xfrm_state_flush(u8 proto); |
| 862 | extern int xfrm_replay_check(struct xfrm_state *x, u32 seq); |
| 863 | extern void xfrm_replay_advance(struct xfrm_state *x, u32 seq); |
| 864 | extern int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb); |
| 865 | extern int xfrm_state_mtu(struct xfrm_state *x, int mtu); |
Herbert Xu | 72cb696 | 2005-06-20 13:18:08 -0700 | [diff] [blame] | 866 | extern int xfrm_init_state(struct xfrm_state *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | extern int xfrm4_rcv(struct sk_buff *skb); |
| 868 | extern int xfrm4_output(struct sk_buff *skb); |
| 869 | extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler); |
| 870 | extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler); |
Patrick McHardy | 951dbc8 | 2006-01-06 23:02:34 -0800 | [diff] [blame] | 871 | extern int xfrm6_rcv_spi(struct sk_buff **pskb, u32 spi); |
| 872 | extern int xfrm6_rcv(struct sk_buff **pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler); |
| 874 | extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler); |
| 875 | extern u32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr); |
| 876 | extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr); |
| 877 | extern u32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr); |
| 878 | extern int xfrm6_output(struct sk_buff *skb); |
| 879 | |
| 880 | #ifdef CONFIG_XFRM |
| 881 | extern int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type); |
| 882 | extern int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen); |
| 883 | extern int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family); |
| 884 | #else |
| 885 | static inline int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen) |
| 886 | { |
| 887 | return -ENOPROTOOPT; |
| 888 | } |
| 889 | |
| 890 | static inline int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type) |
| 891 | { |
| 892 | /* should not happen */ |
| 893 | kfree_skb(skb); |
| 894 | return 0; |
| 895 | } |
| 896 | static inline int xfrm_dst_lookup(struct xfrm_dst **dst, struct flowi *fl, unsigned short family) |
| 897 | { |
| 898 | return -EINVAL; |
| 899 | } |
| 900 | #endif |
| 901 | |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 902 | struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | extern int xfrm_policy_walk(int (*func)(struct xfrm_policy *, int, int, void*), void *); |
| 904 | int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl); |
Trent Jaeger | df71837 | 2005-12-13 23:12:27 -0800 | [diff] [blame] | 905 | struct xfrm_policy *xfrm_policy_bysel_ctx(int dir, struct xfrm_selector *sel, |
| 906 | struct xfrm_sec_ctx *ctx, int delete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | struct xfrm_policy *xfrm_policy_byid(int dir, u32 id, int delete); |
| 908 | void xfrm_policy_flush(void); |
| 909 | u32 xfrm_get_acqseq(void); |
| 910 | void xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi); |
| 911 | struct xfrm_state * xfrm_find_acq(u8 mode, u32 reqid, u8 proto, |
| 912 | xfrm_address_t *daddr, xfrm_address_t *saddr, |
| 913 | int create, unsigned short family); |
| 914 | extern void xfrm_policy_flush(void); |
| 915 | extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol); |
| 916 | extern int xfrm_flush_bundles(void); |
David S. Miller | 399c180 | 2005-12-19 14:23:23 -0800 | [diff] [blame] | 917 | extern void xfrm_flush_all_bundles(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | extern int xfrm_bundle_ok(struct xfrm_dst *xdst, struct flowi *fl, int family); |
| 919 | extern void xfrm_init_pmtu(struct dst_entry *dst); |
| 920 | |
| 921 | extern wait_queue_head_t km_waitq; |
| 922 | extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, u16 sport); |
| 923 | extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard); |
| 924 | |
| 925 | extern void xfrm_input_init(void); |
| 926 | extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, u32 *spi, u32 *seq); |
| 927 | |
| 928 | extern void xfrm_probe_algs(void); |
| 929 | extern int xfrm_count_auth_supported(void); |
| 930 | extern int xfrm_count_enc_supported(void); |
| 931 | extern struct xfrm_algo_desc *xfrm_aalg_get_byidx(unsigned int idx); |
| 932 | extern struct xfrm_algo_desc *xfrm_ealg_get_byidx(unsigned int idx); |
| 933 | extern struct xfrm_algo_desc *xfrm_aalg_get_byid(int alg_id); |
| 934 | extern struct xfrm_algo_desc *xfrm_ealg_get_byid(int alg_id); |
| 935 | extern struct xfrm_algo_desc *xfrm_calg_get_byid(int alg_id); |
| 936 | extern struct xfrm_algo_desc *xfrm_aalg_get_byname(char *name, int probe); |
| 937 | extern struct xfrm_algo_desc *xfrm_ealg_get_byname(char *name, int probe); |
| 938 | extern struct xfrm_algo_desc *xfrm_calg_get_byname(char *name, int probe); |
| 939 | |
| 940 | struct crypto_tfm; |
| 941 | typedef void (icv_update_fn_t)(struct crypto_tfm *, struct scatterlist *, unsigned int); |
| 942 | |
| 943 | extern void skb_icv_walk(const struct sk_buff *skb, struct crypto_tfm *tfm, |
| 944 | int offset, int len, icv_update_fn_t icv_update); |
| 945 | |
| 946 | static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b, |
| 947 | int family) |
| 948 | { |
| 949 | switch (family) { |
| 950 | default: |
| 951 | case AF_INET: |
| 952 | return a->a4 - b->a4; |
| 953 | case AF_INET6: |
| 954 | return ipv6_addr_cmp((struct in6_addr *)a, |
| 955 | (struct in6_addr *)b); |
| 956 | } |
| 957 | } |
| 958 | |
Herbert Xu | 77d8d7a | 2005-10-05 12:15:12 -0700 | [diff] [blame] | 959 | static inline int xfrm_policy_id2dir(u32 index) |
| 960 | { |
| 961 | return index & 7; |
| 962 | } |
| 963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | #endif /* _NET_XFRM_H */ |