aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/xfrm.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/xfrm.h')
-rw-r--r--include/net/xfrm.h137
1 files changed, 86 insertions, 51 deletions
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 223e90a44824..ac52f33f3e4a 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -12,6 +12,7 @@
12#include <linux/in6.h> 12#include <linux/in6.h>
13#include <linux/mutex.h> 13#include <linux/mutex.h>
14#include <linux/audit.h> 14#include <linux/audit.h>
15#include <linux/slab.h>
15 16
16#include <net/sock.h> 17#include <net/sock.h>
17#include <net/dst.h> 18#include <net/dst.h>
@@ -19,6 +20,9 @@
19#include <net/route.h> 20#include <net/route.h>
20#include <net/ipv6.h> 21#include <net/ipv6.h>
21#include <net/ip6_fib.h> 22#include <net/ip6_fib.h>
23
24#include <linux/interrupt.h>
25
22#ifdef CONFIG_XFRM_STATISTICS 26#ifdef CONFIG_XFRM_STATISTICS
23#include <net/snmp.h> 27#include <net/snmp.h>
24#endif 28#endif
@@ -121,8 +125,7 @@ struct xfrm_state_walk {
121}; 125};
122 126
123/* Full description of state of transformer. */ 127/* Full description of state of transformer. */
124struct xfrm_state 128struct xfrm_state {
125{
126#ifdef CONFIG_NET_NS 129#ifdef CONFIG_NET_NS
127 struct net *xs_net; 130 struct net *xs_net;
128#endif 131#endif
@@ -138,6 +141,7 @@ struct xfrm_state
138 141
139 struct xfrm_id id; 142 struct xfrm_id id;
140 struct xfrm_selector sel; 143 struct xfrm_selector sel;
144 struct xfrm_mark mark;
141 145
142 u32 genid; 146 u32 genid;
143 147
@@ -160,7 +164,7 @@ struct xfrm_state
160 struct xfrm_lifetime_cfg lft; 164 struct xfrm_lifetime_cfg lft;
161 165
162 /* Data for transformer */ 166 /* Data for transformer */
163 struct xfrm_algo *aalg; 167 struct xfrm_algo_auth *aalg;
164 struct xfrm_algo *ealg; 168 struct xfrm_algo *ealg;
165 struct xfrm_algo *calg; 169 struct xfrm_algo *calg;
166 struct xfrm_algo_aead *aead; 170 struct xfrm_algo_aead *aead;
@@ -199,7 +203,7 @@ struct xfrm_state
199 struct xfrm_stats stats; 203 struct xfrm_stats stats;
200 204
201 struct xfrm_lifetime_cur curlft; 205 struct xfrm_lifetime_cur curlft;
202 struct timer_list timer; 206 struct tasklet_hrtimer mtimer;
203 207
204 /* Last used time */ 208 /* Last used time */
205 unsigned long lastused; 209 unsigned long lastused;
@@ -237,8 +241,7 @@ enum {
237}; 241};
238 242
239/* callback structure passed from either netlink or pfkey */ 243/* callback structure passed from either netlink or pfkey */
240struct km_event 244struct km_event {
241{
242 union { 245 union {
243 u32 hard; 246 u32 hard;
244 u32 proto; 247 u32 proto;
@@ -273,7 +276,8 @@ struct xfrm_policy_afinfo {
273 struct dst_entry *dst, 276 struct dst_entry *dst,
274 int nfheader_len); 277 int nfheader_len);
275 int (*fill_dst)(struct xfrm_dst *xdst, 278 int (*fill_dst)(struct xfrm_dst *xdst,
276 struct net_device *dev); 279 struct net_device *dev,
280 struct flowi *fl);
277}; 281};
278 282
279extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo); 283extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
@@ -313,12 +317,11 @@ extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
313 317
314extern void xfrm_state_delete_tunnel(struct xfrm_state *x); 318extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
315 319
316struct xfrm_type 320struct xfrm_type {
317{
318 char *description; 321 char *description;
319 struct module *owner; 322 struct module *owner;
320 __u8 proto; 323 u8 proto;
321 __u8 flags; 324 u8 flags;
322#define XFRM_TYPE_NON_FRAGMENT 1 325#define XFRM_TYPE_NON_FRAGMENT 1
323#define XFRM_TYPE_REPLAY_PROT 2 326#define XFRM_TYPE_REPLAY_PROT 2
324#define XFRM_TYPE_LOCAL_COADDR 4 327#define XFRM_TYPE_LOCAL_COADDR 4
@@ -420,8 +423,7 @@ static inline struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipp
420 return x->inner_mode_iaf; 423 return x->inner_mode_iaf;
421} 424}
422 425
423struct xfrm_tmpl 426struct xfrm_tmpl {
424{
425/* id in template is interpreted as: 427/* id in template is interpreted as:
426 * daddr - destination of tunnel, may be zero for transport mode. 428 * daddr - destination of tunnel, may be zero for transport mode.
427 * spi - zero to acquire spi. Not zero if spi is static, then 429 * spi - zero to acquire spi. Not zero if spi is static, then
@@ -435,24 +437,24 @@ struct xfrm_tmpl
435 437
436 unsigned short encap_family; 438 unsigned short encap_family;
437 439
438 __u32 reqid; 440 u32 reqid;
439 441
440/* Mode: transport, tunnel etc. */ 442/* Mode: transport, tunnel etc. */
441 __u8 mode; 443 u8 mode;
442 444
443/* Sharing mode: unique, this session only, this user only etc. */ 445/* Sharing mode: unique, this session only, this user only etc. */
444 __u8 share; 446 u8 share;
445 447
446/* May skip this transfomration if no SA is found */ 448/* May skip this transfomration if no SA is found */
447 __u8 optional; 449 u8 optional;
448 450
449/* Skip aalgos/ealgos/calgos checks. */ 451/* Skip aalgos/ealgos/calgos checks. */
450 __u8 allalgs; 452 u8 allalgs;
451 453
452/* Bit mask of algos allowed for acquisition */ 454/* Bit mask of algos allowed for acquisition */
453 __u32 aalgos; 455 u32 aalgos;
454 __u32 ealgos; 456 u32 ealgos;
455 __u32 calgos; 457 u32 calgos;
456}; 458};
457 459
458#define XFRM_MAX_DEPTH 6 460#define XFRM_MAX_DEPTH 6
@@ -468,8 +470,7 @@ struct xfrm_policy_walk {
468 u32 seq; 470 u32 seq;
469}; 471};
470 472
471struct xfrm_policy 473struct xfrm_policy {
472{
473#ifdef CONFIG_NET_NS 474#ifdef CONFIG_NET_NS
474 struct net *xp_net; 475 struct net *xp_net;
475#endif 476#endif
@@ -483,6 +484,7 @@ struct xfrm_policy
483 484
484 u32 priority; 485 u32 priority;
485 u32 index; 486 u32 index;
487 struct xfrm_mark mark;
486 struct xfrm_selector selector; 488 struct xfrm_selector selector;
487 struct xfrm_lifetime_cfg lft; 489 struct xfrm_lifetime_cfg lft;
488 struct xfrm_lifetime_cur curlft; 490 struct xfrm_lifetime_cur curlft;
@@ -538,8 +540,7 @@ struct xfrm_migrate {
538/* default seq threshold size */ 540/* default seq threshold size */
539#define XFRM_AE_SEQT_SIZE 2 541#define XFRM_AE_SEQT_SIZE 2
540 542
541struct xfrm_mgr 543struct xfrm_mgr {
542{
543 struct list_head list; 544 struct list_head list;
544 char *id; 545 char *id;
545 int (*notify)(struct xfrm_state *x, struct km_event *c); 546 int (*notify)(struct xfrm_state *x, struct km_event *c);
@@ -626,8 +627,7 @@ struct xfrm_spi_skb_cb {
626#define XFRM_SPI_SKB_CB(__skb) ((struct xfrm_spi_skb_cb *)&((__skb)->cb[0])) 627#define XFRM_SPI_SKB_CB(__skb) ((struct xfrm_spi_skb_cb *)&((__skb)->cb[0]))
627 628
628/* Audit Information */ 629/* Audit Information */
629struct xfrm_audit 630struct xfrm_audit {
630{
631 u32 secid; 631 u32 secid;
632 uid_t loginuid; 632 uid_t loginuid;
633 u32 sessionid; 633 u32 sessionid;
@@ -774,7 +774,7 @@ static __inline__ int addr_match(void *token1, void *token2, int prefixlen)
774 int pdw; 774 int pdw;
775 int pbi; 775 int pbi;
776 776
777 pdw = prefixlen >> 5; /* num of whole __u32 in prefix */ 777 pdw = prefixlen >> 5; /* num of whole u32 in prefix */
778 pbi = prefixlen & 0x1f; /* num of bits in incomplete u32 in prefix */ 778 pbi = prefixlen & 0x1f; /* num of bits in incomplete u32 in prefix */
779 779
780 if (pdw) 780 if (pdw)
@@ -871,8 +871,7 @@ static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ct
871 * bundles differing by session id. All the bundles grow from a parent 871 * bundles differing by session id. All the bundles grow from a parent
872 * policy rule. 872 * policy rule.
873 */ 873 */
874struct xfrm_dst 874struct xfrm_dst {
875{
876 union { 875 union {
877 struct dst_entry dst; 876 struct dst_entry dst;
878 struct rtable rt; 877 struct rtable rt;
@@ -907,8 +906,7 @@ static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
907 906
908extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev); 907extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
909 908
910struct sec_path 909struct sec_path {
911{
912 atomic_t refcnt; 910 atomic_t refcnt;
913 int len; 911 int len;
914 struct xfrm_state *xvec[XFRM_MAX_DEPTH]; 912 struct xfrm_state *xvec[XFRM_MAX_DEPTH];
@@ -1265,7 +1263,7 @@ struct xfrm_algo_desc {
1265/* XFRM tunnel handlers. */ 1263/* XFRM tunnel handlers. */
1266struct xfrm_tunnel { 1264struct xfrm_tunnel {
1267 int (*handler)(struct sk_buff *skb); 1265 int (*handler)(struct sk_buff *skb);
1268 int (*err_handler)(struct sk_buff *skb, __u32 info); 1266 int (*err_handler)(struct sk_buff *skb, u32 info);
1269 1267
1270 struct xfrm_tunnel *next; 1268 struct xfrm_tunnel *next;
1271 int priority; 1269 int priority;
@@ -1323,7 +1321,7 @@ extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t
1323 struct flowi *fl, struct xfrm_tmpl *tmpl, 1321 struct flowi *fl, struct xfrm_tmpl *tmpl,
1324 struct xfrm_policy *pol, int *err, 1322 struct xfrm_policy *pol, int *err,
1325 unsigned short family); 1323 unsigned short family);
1326extern struct xfrm_state * xfrm_stateonly_find(struct net *net, 1324extern struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark,
1327 xfrm_address_t *daddr, 1325 xfrm_address_t *daddr,
1328 xfrm_address_t *saddr, 1326 xfrm_address_t *saddr,
1329 unsigned short family, 1327 unsigned short family,
@@ -1332,8 +1330,14 @@ extern int xfrm_state_check_expire(struct xfrm_state *x);
1332extern void xfrm_state_insert(struct xfrm_state *x); 1330extern void xfrm_state_insert(struct xfrm_state *x);
1333extern int xfrm_state_add(struct xfrm_state *x); 1331extern int xfrm_state_add(struct xfrm_state *x);
1334extern int xfrm_state_update(struct xfrm_state *x); 1332extern int xfrm_state_update(struct xfrm_state *x);
1335extern struct xfrm_state *xfrm_state_lookup(struct net *net, xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family); 1333extern struct xfrm_state *xfrm_state_lookup(struct net *net, u32 mark,
1336extern struct xfrm_state *xfrm_state_lookup_byaddr(struct net *net, xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family); 1334 xfrm_address_t *daddr, __be32 spi,
1335 u8 proto, unsigned short family);
1336extern struct xfrm_state *xfrm_state_lookup_byaddr(struct net *net, u32 mark,
1337 xfrm_address_t *daddr,
1338 xfrm_address_t *saddr,
1339 u8 proto,
1340 unsigned short family);
1337#ifdef CONFIG_XFRM_SUB_POLICY 1341#ifdef CONFIG_XFRM_SUB_POLICY
1338extern int xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, 1342extern int xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src,
1339 int n, unsigned short family); 1343 int n, unsigned short family);
@@ -1370,11 +1374,12 @@ struct xfrmk_spdinfo {
1370 u32 spdhmcnt; 1374 u32 spdhmcnt;
1371}; 1375};
1372 1376
1373extern struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 seq); 1377extern struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 mark,
1378 u32 seq);
1374extern int xfrm_state_delete(struct xfrm_state *x); 1379extern int xfrm_state_delete(struct xfrm_state *x);
1375extern int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info); 1380extern int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info);
1376extern void xfrm_sad_getinfo(struct xfrmk_sadinfo *si); 1381extern void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si);
1377extern void xfrm_spd_getinfo(struct xfrmk_spdinfo *si); 1382extern void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si);
1378extern int xfrm_replay_check(struct xfrm_state *x, 1383extern int xfrm_replay_check(struct xfrm_state *x,
1379 struct sk_buff *skb, __be32 seq); 1384 struct sk_buff *skb, __be32 seq);
1380extern void xfrm_replay_advance(struct xfrm_state *x, __be32 seq); 1385extern void xfrm_replay_advance(struct xfrm_state *x, __be32 seq);
@@ -1414,9 +1419,9 @@ extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
1414 xfrm_address_t *saddr, u8 proto); 1419 xfrm_address_t *saddr, u8 proto);
1415extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family); 1420extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
1416extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family); 1421extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
1417extern __be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr); 1422extern __be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
1418extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr); 1423extern void xfrm6_tunnel_free_spi(struct net *net, xfrm_address_t *saddr);
1419extern __be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr); 1424extern __be32 xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr);
1420extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb); 1425extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1421extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb); 1426extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
1422extern int xfrm6_output(struct sk_buff *skb); 1427extern int xfrm6_output(struct sk_buff *skb);
@@ -1447,17 +1452,20 @@ extern int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
1447 int (*func)(struct xfrm_policy *, int, int, void*), void *); 1452 int (*func)(struct xfrm_policy *, int, int, void*), void *);
1448extern void xfrm_policy_walk_done(struct xfrm_policy_walk *walk); 1453extern void xfrm_policy_walk_done(struct xfrm_policy_walk *walk);
1449int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl); 1454int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl);
1450struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u8 type, int dir, 1455struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark,
1456 u8 type, int dir,
1451 struct xfrm_selector *sel, 1457 struct xfrm_selector *sel,
1452 struct xfrm_sec_ctx *ctx, int delete, 1458 struct xfrm_sec_ctx *ctx, int delete,
1453 int *err); 1459 int *err);
1454struct xfrm_policy *xfrm_policy_byid(struct net *net, u8, int dir, u32 id, int delete, int *err); 1460struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir, u32 id, int delete, int *err);
1455int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info); 1461int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info);
1456u32 xfrm_get_acqseq(void); 1462u32 xfrm_get_acqseq(void);
1457extern int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi); 1463extern int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);
1458struct xfrm_state * xfrm_find_acq(struct net *net, u8 mode, u32 reqid, u8 proto, 1464struct xfrm_state *xfrm_find_acq(struct net *net, struct xfrm_mark *mark,
1459 xfrm_address_t *daddr, xfrm_address_t *saddr, 1465 u8 mode, u32 reqid, u8 proto,
1460 int create, unsigned short family); 1466 xfrm_address_t *daddr,
1467 xfrm_address_t *saddr, int create,
1468 unsigned short family);
1461extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol); 1469extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol);
1462extern int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *xdst, 1470extern int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *xdst,
1463 struct flowi *fl, int family, int strict); 1471 struct flowi *fl, int family, int strict);
@@ -1500,16 +1508,13 @@ struct scatterlist;
1500typedef int (icv_update_fn_t)(struct hash_desc *, struct scatterlist *, 1508typedef int (icv_update_fn_t)(struct hash_desc *, struct scatterlist *,
1501 unsigned int); 1509 unsigned int);
1502 1510
1503extern int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *tfm,
1504 int offset, int len, icv_update_fn_t icv_update);
1505
1506static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b, 1511static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b,
1507 int family) 1512 int family)
1508{ 1513{
1509 switch (family) { 1514 switch (family) {
1510 default: 1515 default:
1511 case AF_INET: 1516 case AF_INET:
1512 return (__force __u32)a->a4 - (__force __u32)b->a4; 1517 return (__force u32)a->a4 - (__force u32)b->a4;
1513 case AF_INET6: 1518 case AF_INET6:
1514 return ipv6_addr_cmp((struct in6_addr *)a, 1519 return ipv6_addr_cmp((struct in6_addr *)a,
1515 (struct in6_addr *)b); 1520 (struct in6_addr *)b);
@@ -1541,12 +1546,22 @@ static inline int xfrm_alg_len(struct xfrm_algo *alg)
1541 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8); 1546 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
1542} 1547}
1543 1548
1549static inline int xfrm_alg_auth_len(struct xfrm_algo_auth *alg)
1550{
1551 return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
1552}
1553
1544#ifdef CONFIG_XFRM_MIGRATE 1554#ifdef CONFIG_XFRM_MIGRATE
1545static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig) 1555static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig)
1546{ 1556{
1547 return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL); 1557 return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL);
1548} 1558}
1549 1559
1560static inline struct xfrm_algo_auth *xfrm_algo_auth_clone(struct xfrm_algo_auth *orig)
1561{
1562 return kmemdup(orig, xfrm_alg_auth_len(orig), GFP_KERNEL);
1563}
1564
1550static inline void xfrm_states_put(struct xfrm_state **states, int n) 1565static inline void xfrm_states_put(struct xfrm_state **states, int n)
1551{ 1566{
1552 int i; 1567 int i;
@@ -1569,4 +1584,24 @@ static inline struct xfrm_state *xfrm_input_state(struct sk_buff *skb)
1569} 1584}
1570#endif 1585#endif
1571 1586
1587static inline int xfrm_mark_get(struct nlattr **attrs, struct xfrm_mark *m)
1588{
1589 if (attrs[XFRMA_MARK])
1590 memcpy(m, nla_data(attrs[XFRMA_MARK]), sizeof(m));
1591 else
1592 m->v = m->m = 0;
1593
1594 return m->v & m->m;
1595}
1596
1597static inline int xfrm_mark_put(struct sk_buff *skb, struct xfrm_mark *m)
1598{
1599 if (m->m | m->v)
1600 NLA_PUT(skb, XFRMA_MARK, sizeof(struct xfrm_mark), m);
1601 return 0;
1602
1603nla_put_failure:
1604 return -1;
1605}
1606
1572#endif /* _NET_XFRM_H */ 1607#endif /* _NET_XFRM_H */