X25: Add if_x25.h and x25 to device identifiers
[safe/jmp/linux-2.6] / include / net / xfrm.h
index bed7d43..1913af6 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/in6.h>
 #include <linux/mutex.h>
 #include <linux/audit.h>
+#include <linux/slab.h>
 
 #include <net/sock.h>
 #include <net/dst.h>
 #include <net/route.h>
 #include <net/ipv6.h>
 #include <net/ip6_fib.h>
+#include <net/flow.h>
+
+#include <linux/interrupt.h>
+
 #ifdef CONFIG_XFRM_STATISTICS
 #include <net/snmp.h>
 #endif
        MODULE_ALIAS("xfrm-type-" __stringify(family) "-" __stringify(proto))
 
 #ifdef CONFIG_XFRM_STATISTICS
-DECLARE_SNMP_STAT(struct linux_xfrm_mib, xfrm_statistics);
-#define XFRM_INC_STATS(field)          SNMP_INC_STATS(xfrm_statistics, field)
-#define XFRM_INC_STATS_BH(field)       SNMP_INC_STATS_BH(xfrm_statistics, field)
-#define XFRM_INC_STATS_USER(field)     SNMP_INC_STATS_USER(xfrm_statistics, field)
+#define XFRM_INC_STATS(net, field)     SNMP_INC_STATS((net)->mib.xfrm_statistics, field)
+#define XFRM_INC_STATS_BH(net, field)  SNMP_INC_STATS_BH((net)->mib.xfrm_statistics, field)
+#define XFRM_INC_STATS_USER(net, field)        SNMP_INC_STATS_USER((net)-mib.xfrm_statistics, field)
 #else
-#define XFRM_INC_STATS(field)
-#define XFRM_INC_STATS_BH(field)
-#define XFRM_INC_STATS_USER(field)
+#define XFRM_INC_STATS(net, field)     ((void)(net))
+#define XFRM_INC_STATS_BH(net, field)  ((void)(net))
+#define XFRM_INC_STATS_USER(net, field)        ((void)(net))
 #endif
 
-extern struct sock *xfrm_nl;
-extern u32 sysctl_xfrm_aevent_etime;
-extern u32 sysctl_xfrm_aevent_rseqth;
-extern int sysctl_xfrm_larval_drop;
-extern u32 sysctl_xfrm_acq_expires;
-
 extern struct mutex xfrm_cfg_mutex;
 
 /* Organization of SPD aka "XFRM rules"
@@ -117,12 +115,25 @@ extern struct mutex xfrm_cfg_mutex;
       metrics. Plus, it will be made via sk->sk_dst_cache. Solved.
  */
 
-/* Full description of state of transformer. */
-struct xfrm_state
-{
-       /* Note: bydst is re-used during gc */
+struct xfrm_state_walk {
        struct list_head        all;
-       struct hlist_node       bydst;
+       u8                      state;
+       union {
+               u8              dying;
+               u8              proto;
+       };
+       u32                     seq;
+};
+
+/* Full description of state of transformer. */
+struct xfrm_state {
+#ifdef CONFIG_NET_NS
+       struct net              *xs_net;
+#endif
+       union {
+               struct hlist_node       gclist;
+               struct hlist_node       bydst;
+       };
        struct hlist_node       bysrc;
        struct hlist_node       byspi;
 
@@ -131,15 +142,12 @@ struct xfrm_state
 
        struct xfrm_id          id;
        struct xfrm_selector    sel;
+       struct xfrm_mark        mark;
 
        u32                     genid;
 
-       /* Key manger bits */
-       struct {
-               u8              state;
-               u8              dying;
-               u32             seq;
-       } km;
+       /* Key manager bits */
+       struct xfrm_state_walk  km;
 
        /* Parameters of this state. */
        struct {
@@ -157,7 +165,7 @@ struct xfrm_state
        struct xfrm_lifetime_cfg lft;
 
        /* Data for transformer */
-       struct xfrm_algo        *aalg;
+       struct xfrm_algo_auth   *aalg;
        struct xfrm_algo        *ealg;
        struct xfrm_algo        *calg;
        struct xfrm_algo_aead   *aead;
@@ -196,7 +204,7 @@ struct xfrm_state
        struct xfrm_stats       stats;
 
        struct xfrm_lifetime_cur curlft;
-       struct timer_list       timer;
+       struct tasklet_hrtimer  mtimer;
 
        /* Last used time */
        unsigned long           lastused;
@@ -205,6 +213,7 @@ struct xfrm_state
         * transformer. */
        const struct xfrm_type  *type;
        struct xfrm_mode        *inner_mode;
+       struct xfrm_mode        *inner_mode_iaf;
        struct xfrm_mode        *outer_mode;
 
        /* Security context */
@@ -215,6 +224,11 @@ struct xfrm_state
        void                    *data;
 };
 
+static inline struct net *xs_net(struct xfrm_state *x)
+{
+       return read_pnet(&x->xs_net);
+}
+
 /* xflags - make enum if more show up */
 #define XFRM_TIME_DEFER        1
 
@@ -228,8 +242,7 @@ enum {
 };
 
 /* callback structure passed from either netlink or pfkey */
-struct km_event
-{
+struct km_event {
        union {
                u32 hard;
                u32 proto;
@@ -241,6 +254,7 @@ struct km_event
        u32     seq;
        u32     pid;
        u32     event;
+       struct net *net;
 };
 
 struct net_device;
@@ -249,11 +263,11 @@ struct xfrm_dst;
 struct xfrm_policy_afinfo {
        unsigned short          family;
        struct dst_ops          *dst_ops;
-       void                    (*garbage_collect)(void);
-       struct dst_entry        *(*dst_lookup)(int tos, xfrm_address_t *saddr,
+       void                    (*garbage_collect)(struct net *net);
+       struct dst_entry        *(*dst_lookup)(struct net *net, int tos,
+                                              xfrm_address_t *saddr,
                                               xfrm_address_t *daddr);
-       int                     (*get_saddr)(xfrm_address_t *saddr, xfrm_address_t *daddr);
-       struct dst_entry        *(*find_bundle)(struct flowi *fl, struct xfrm_policy *policy);
+       int                     (*get_saddr)(struct net *net, xfrm_address_t *saddr, xfrm_address_t *daddr);
        void                    (*decode_session)(struct sk_buff *skb,
                                                  struct flowi *fl,
                                                  int reverse);
@@ -262,7 +276,8 @@ struct xfrm_policy_afinfo {
                                             struct dst_entry *dst,
                                             int nfheader_len);
        int                     (*fill_dst)(struct xfrm_dst *xdst,
-                                           struct net_device *dev);
+                                           struct net_device *dev,
+                                           struct flowi *fl);
 };
 
 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
@@ -302,12 +317,11 @@ extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
 
 extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
 
-struct xfrm_type
-{
+struct xfrm_type {
        char                    *description;
        struct module           *owner;
-       __u8                    proto;
-       __u8                    flags;
+       u8                      proto;
+       u8                      flags;
 #define XFRM_TYPE_NON_FRAGMENT 1
 #define XFRM_TYPE_REPLAY_PROT  2
 #define XFRM_TYPE_LOCAL_COADDR 4
@@ -388,8 +402,28 @@ enum {
 extern int xfrm_register_mode(struct xfrm_mode *mode, int family);
 extern int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
 
-struct xfrm_tmpl
+static inline int xfrm_af2proto(unsigned int family)
 {
+       switch(family) {
+       case AF_INET:
+               return IPPROTO_IPIP;
+       case AF_INET6:
+               return IPPROTO_IPV6;
+       default:
+               return 0;
+       }
+}
+
+static inline struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipproto)
+{
+       if ((ipproto == IPPROTO_IPIP && x->props.family == AF_INET) ||
+           (ipproto == IPPROTO_IPV6 && x->props.family == AF_INET6))
+               return x->inner_mode;
+       else
+               return x->inner_mode_iaf;
+}
+
+struct xfrm_tmpl {
 /* id in template is interpreted as:
  * daddr - destination of tunnel, may be zero for transport mode.
  * spi   - zero to acquire spi. Not zero if spi is static, then
@@ -403,29 +437,43 @@ struct xfrm_tmpl
 
        unsigned short          encap_family;
 
-       __u32                   reqid;
+       u32                     reqid;
 
 /* Mode: transport, tunnel etc. */
-       __u8                    mode;
+       u8                      mode;
 
 /* Sharing mode: unique, this session only, this user only etc. */
-       __u8                    share;
+       u8                      share;
 
 /* May skip this transfomration if no SA is found */
-       __u8                    optional;
+       u8                      optional;
+
+/* Skip aalgos/ealgos/calgos checks. */
+       u8                      allalgs;
 
 /* Bit mask of algos allowed for acquisition */
-       __u32                   aalgos;
-       __u32                   ealgos;
-       __u32                   calgos;
+       u32                     aalgos;
+       u32                     ealgos;
+       u32                     calgos;
 };
 
 #define XFRM_MAX_DEPTH         6
 
-struct xfrm_policy
-{
-       struct xfrm_policy      *next;
-       struct list_head        bytype;
+struct xfrm_policy_walk_entry {
+       struct list_head        all;
+       u8                      dead;
+};
+
+struct xfrm_policy_walk {
+       struct xfrm_policy_walk_entry walk;
+       u8 type;
+       u32 seq;
+};
+
+struct xfrm_policy {
+#ifdef CONFIG_NET_NS
+       struct net              *xp_net;
+#endif
        struct hlist_node       bydst;
        struct hlist_node       byidx;
 
@@ -434,23 +482,36 @@ struct xfrm_policy
        atomic_t                refcnt;
        struct timer_list       timer;
 
+       struct flow_cache_object flo;
+       atomic_t                genid;
        u32                     priority;
        u32                     index;
+       struct xfrm_mark        mark;
        struct xfrm_selector    selector;
        struct xfrm_lifetime_cfg lft;
        struct xfrm_lifetime_cur curlft;
-       struct dst_entry       *bundles;
-       u16                     family;
+       struct xfrm_policy_walk_entry walk;
        u8                      type;
        u8                      action;
        u8                      flags;
-       u8                      dead;
        u8                      xfrm_nr;
-       /* XXX 1 byte hole, try to pack */
+       u16                     family;
        struct xfrm_sec_ctx     *security;
        struct xfrm_tmpl        xfrm_vec[XFRM_MAX_DEPTH];
 };
 
+static inline struct net *xp_net(struct xfrm_policy *xp)
+{
+       return read_pnet(&xp->xp_net);
+}
+
+struct xfrm_kmaddress {
+       xfrm_address_t          local;
+       xfrm_address_t          remote;
+       u32                     reserved;
+       u16                     family;
+};
+
 struct xfrm_migrate {
        xfrm_address_t          old_daddr;
        xfrm_address_t          old_saddr;
@@ -480,8 +541,7 @@ struct xfrm_migrate {
 /* default seq threshold size */
 #define XFRM_AE_SEQT_SIZE              2
 
-struct xfrm_mgr
-{
+struct xfrm_mgr {
        struct list_head        list;
        char                    *id;
        int                     (*notify)(struct xfrm_state *x, struct km_event *c);
@@ -489,15 +549,13 @@ struct xfrm_mgr
        struct xfrm_policy      *(*compile_policy)(struct sock *sk, int opt, u8 *data, int len, int *dir);
        int                     (*new_mapping)(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport);
        int                     (*notify_policy)(struct xfrm_policy *x, int dir, struct km_event *c);
-       int                     (*report)(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr);
-       int                     (*migrate)(struct xfrm_selector *sel, u8 dir, u8 type, struct xfrm_migrate *m, int num_bundles);
+       int                     (*report)(struct net *net, u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr);
+       int                     (*migrate)(struct xfrm_selector *sel, u8 dir, u8 type, struct xfrm_migrate *m, int num_bundles, struct xfrm_kmaddress *k);
 };
 
 extern int xfrm_register_km(struct xfrm_mgr *km);
 extern int xfrm_unregister_km(struct xfrm_mgr *km);
 
-extern unsigned int xfrm_policy_count[XFRM_POLICY_MAX*2];
-
 /*
  * This structure is used for the duration where packets are being
  * transformed by IPsec.  As soon as the packet leaves IPsec the
@@ -532,6 +590,9 @@ struct xfrm_mode_skb_cb {
        __be16 id;
        __be16 frag_off;
 
+       /* IP header length (excluding options or extension headers). */
+       u8 ihl;
+
        /* TOS for IPv4, class for IPv6. */
        u8 tos;
 
@@ -541,6 +602,9 @@ struct xfrm_mode_skb_cb {
        /* Protocol for IPv4, NH for IPv6. */
        u8 protocol;
 
+       /* Option length for IPv4, zero for IPv6. */
+       u8 optlen;
+
        /* Used by IPv6 only, zero for IPv4. */
        u8 flow_lbl[3];
 };
@@ -564,10 +628,10 @@ struct xfrm_spi_skb_cb {
 #define XFRM_SPI_SKB_CB(__skb) ((struct xfrm_spi_skb_cb *)&((__skb)->cb[0]))
 
 /* Audit Information */
-struct xfrm_audit
-{
-       u32     loginuid;
+struct xfrm_audit {
        u32     secid;
+       uid_t   loginuid;
+       u32     sessionid;
 };
 
 #ifdef CONFIG_AUDITSYSCALL
@@ -585,13 +649,13 @@ static inline struct audit_buffer *xfrm_audit_start(const char *op)
        return audit_buf;
 }
 
-static inline void xfrm_audit_helper_usrinfo(u32 auid, u32 secid,
+static inline void xfrm_audit_helper_usrinfo(uid_t auid, u32 ses, u32 secid,
                                             struct audit_buffer *audit_buf)
 {
        char *secctx;
        u32 secctx_len;
 
-       audit_log_format(audit_buf, " auid=%u", auid);
+       audit_log_format(audit_buf, " auid=%u ses=%u", auid, ses);
        if (secid != 0 &&
            security_secid_to_secctx(secid, &secctx, &secctx_len) == 0) {
                audit_log_format(audit_buf, " subj=%s", secctx);
@@ -601,13 +665,13 @@ static inline void xfrm_audit_helper_usrinfo(u32 auid, u32 secid,
 }
 
 extern void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
-                                 u32 auid, u32 secid);
+                                 u32 auid, u32 ses, u32 secid);
 extern void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
-                                 u32 auid, u32 secid);
+                                 u32 auid, u32 ses, u32 secid);
 extern void xfrm_audit_state_add(struct xfrm_state *x, int result,
-                                u32 auid, u32 secid);
+                                u32 auid, u32 ses, u32 secid);
 extern void xfrm_audit_state_delete(struct xfrm_state *x, int result,
-                                   u32 auid, u32 secid);
+                                   u32 auid, u32 ses, u32 secid);
 extern void xfrm_audit_state_replay_overflow(struct xfrm_state *x,
                                             struct sk_buff *skb);
 extern void xfrm_audit_state_notfound_simple(struct sk_buff *skb, u16 family);
@@ -616,14 +680,46 @@ extern void xfrm_audit_state_notfound(struct sk_buff *skb, u16 family,
 extern void xfrm_audit_state_icvfail(struct xfrm_state *x,
                                     struct sk_buff *skb, u8 proto);
 #else
-#define xfrm_audit_policy_add(x, r, a, s)      do { ; } while (0)
-#define xfrm_audit_policy_delete(x, r, a, s)   do { ; } while (0)
-#define xfrm_audit_state_add(x, r, a, s)       do { ; } while (0)
-#define xfrm_audit_state_delete(x, r, a, s)    do { ; } while (0)
-#define xfrm_audit_state_replay_overflow(x, s) do { ; } while (0)
-#define xfrm_audit_state_notfound_simple(s, f) do { ; } while (0)
-#define xfrm_audit_state_notfound(s, f, sp, sq)        do { ; } while (0)
-#define xfrm_audit_state_icvfail(x, s, p)      do { ; } while (0)
+
+static inline void xfrm_audit_policy_add(struct xfrm_policy *xp, int result,
+                                 u32 auid, u32 ses, u32 secid)
+{
+}
+
+static inline void xfrm_audit_policy_delete(struct xfrm_policy *xp, int result,
+                                 u32 auid, u32 ses, u32 secid)
+{
+}
+
+static inline void xfrm_audit_state_add(struct xfrm_state *x, int result,
+                                u32 auid, u32 ses, u32 secid)
+{
+}
+
+static inline void xfrm_audit_state_delete(struct xfrm_state *x, int result,
+                                   u32 auid, u32 ses, u32 secid)
+{
+}
+
+static inline void xfrm_audit_state_replay_overflow(struct xfrm_state *x,
+                                            struct sk_buff *skb)
+{
+}
+
+static inline void xfrm_audit_state_notfound_simple(struct sk_buff *skb,
+                                     u16 family)
+{
+}
+
+static inline void xfrm_audit_state_notfound(struct sk_buff *skb, u16 family,
+                                     __be32 net_spi, __be32 net_seq)
+{
+}
+
+static inline void xfrm_audit_state_icvfail(struct xfrm_state *x,
+                                    struct sk_buff *skb, u8 proto)
+{
+}
 #endif /* CONFIG_AUDITSYSCALL */
 
 static inline void xfrm_pol_hold(struct xfrm_policy *policy)
@@ -640,19 +736,12 @@ static inline void xfrm_pol_put(struct xfrm_policy *policy)
                xfrm_policy_destroy(policy);
 }
 
-#ifdef CONFIG_XFRM_SUB_POLICY
 static inline void xfrm_pols_put(struct xfrm_policy **pols, int npols)
 {
        int i;
        for (i = npols - 1; i >= 0; --i)
                xfrm_pol_put(pols[i]);
 }
-#else
-static inline void xfrm_pols_put(struct xfrm_policy **pols, int npols)
-{
-       xfrm_pol_put(pols[0]);
-}
-#endif
 
 extern void __xfrm_state_destroy(struct xfrm_state *);
 
@@ -679,7 +768,7 @@ static __inline__ int addr_match(void *token1, void *token2, int prefixlen)
        int pdw;
        int pbi;
 
-       pdw = prefixlen >> 5;     /* num of whole __u32 in prefix */
+       pdw = prefixlen >> 5;     /* num of whole u32 in prefix */
        pbi = prefixlen &  0x1f;  /* num of bits in incomplete u32 in prefix */
 
        if (pdw)
@@ -776,27 +865,32 @@ static inline int xfrm_sec_ctx_match(struct xfrm_sec_ctx *s1, struct xfrm_sec_ct
  * bundles differing by session id. All the bundles grow from a parent
  * policy rule.
  */
-struct xfrm_dst
-{
+struct xfrm_dst {
        union {
                struct dst_entry        dst;
                struct rtable           rt;
                struct rt6_info         rt6;
        } u;
        struct dst_entry *route;
+       struct flow_cache_object flo;
+       struct xfrm_policy *pols[XFRM_POLICY_TYPE_MAX];
+       int num_pols, num_xfrms;
 #ifdef CONFIG_XFRM_SUB_POLICY
        struct flowi *origin;
        struct xfrm_selector *partner;
 #endif
-       u32 genid;
+       u32 xfrm_genid;
+       u32 policy_genid;
        u32 route_mtu_cached;
        u32 child_mtu_cached;
        u32 route_cookie;
        u32 path_cookie;
 };
 
+#ifdef CONFIG_XFRM
 static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
 {
+       xfrm_pols_put(xdst->pols, xdst->num_pols);
        dst_release(xdst->route);
        if (likely(xdst->u.dst.xfrm))
                xfrm_state_put(xdst->u.dst.xfrm);
@@ -807,11 +901,11 @@ static inline void xfrm_dst_destroy(struct xfrm_dst *xdst)
        xdst->partner = NULL;
 #endif
 }
+#endif
 
 extern void xfrm_dst_ifdown(struct dst_entry *dst, struct net_device *dev);
 
-struct sec_path
-{
+struct sec_path {
        atomic_t                refcnt;
        int                     len;
        struct xfrm_state       *xvec[XFRM_MAX_DEPTH];
@@ -890,13 +984,14 @@ static inline int __xfrm_policy_check2(struct sock *sk, int dir,
                                       struct sk_buff *skb,
                                       unsigned int family, int reverse)
 {
+       struct net *net = dev_net(skb->dev);
        int ndir = dir | (reverse ? XFRM_POLICY_MASK + 1 : 0);
 
        if (sk && sk->sk_policy[XFRM_POLICY_IN])
                return __xfrm_policy_check(sk, ndir, skb, family);
 
-       return  (!xfrm_policy_count[dir] && !skb->sp) ||
-               (skb->dst->flags & DST_NOPOLICY) ||
+       return  (!net->xfrm.policy_count[dir] && !skb->sp) ||
+               (skb_dst(skb)->flags & DST_NOPOLICY) ||
                __xfrm_policy_check(sk, ndir, skb, family);
 }
 
@@ -947,8 +1042,10 @@ extern int __xfrm_route_forward(struct sk_buff *skb, unsigned short family);
 
 static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family)
 {
-       return  !xfrm_policy_count[XFRM_POLICY_OUT] ||
-               (skb->dst->flags & DST_NOXFRM) ||
+       struct net *net = dev_net(skb->dev);
+
+       return  !net->xfrm.policy_count[XFRM_POLICY_OUT] ||
+               (skb_dst(skb)->flags & DST_NOXFRM) ||
                __xfrm_route_forward(skb, family);
 }
 
@@ -1165,7 +1262,7 @@ struct xfrm_algo_desc {
 /* XFRM tunnel handlers.  */
 struct xfrm_tunnel {
        int (*handler)(struct sk_buff *skb);
-       int (*err_handler)(struct sk_buff *skb, __u32 info);
+       int (*err_handler)(struct sk_buff *skb, u32 info);
 
        struct xfrm_tunnel *next;
        int priority;
@@ -1174,26 +1271,15 @@ struct xfrm_tunnel {
 struct xfrm6_tunnel {
        int (*handler)(struct sk_buff *skb);
        int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
-                          int type, int code, int offset, __be32 info);
+                          u8 type, u8 code, int offset, __be32 info);
        struct xfrm6_tunnel *next;
        int priority;
 };
 
-struct xfrm_state_walk {
-       struct xfrm_state *state;
-       int count;
-       u8 proto;
-};
-
-struct xfrm_policy_walk {
-       struct xfrm_policy *policy;
-       int count;
-       u8 type, cur_type;
-};
-
 extern void xfrm_init(void);
-extern void xfrm4_init(void);
-extern void xfrm_state_init(void);
+extern void xfrm4_init(int rt_hash_size);
+extern int xfrm_state_init(struct net *net);
+extern void xfrm_state_fini(struct net *net);
 extern void xfrm4_state_init(void);
 #ifdef CONFIG_XFRM
 extern int xfrm6_init(void);
@@ -1212,32 +1298,30 @@ static inline void xfrm6_fini(void)
 #endif
 
 #ifdef CONFIG_XFRM_STATISTICS
-extern int xfrm_proc_init(void);
+extern int xfrm_proc_init(struct net *net);
+extern void xfrm_proc_fini(struct net *net);
 #endif
 
-static inline void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto)
-{
-       walk->proto = proto;
-       walk->state = NULL;
-       walk->count = 0;
-}
-
-static inline void xfrm_state_walk_done(struct xfrm_state_walk *walk)
+extern int xfrm_sysctl_init(struct net *net);
+#ifdef CONFIG_SYSCTL
+extern void xfrm_sysctl_fini(struct net *net);
+#else
+static inline void xfrm_sysctl_fini(struct net *net)
 {
-       if (walk->state != NULL) {
-               xfrm_state_put(walk->state);
-               walk->state = NULL;
-       }
 }
+#endif
 
-extern int xfrm_state_walk(struct xfrm_state_walk *walk,
+extern void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto);
+extern int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
                           int (*func)(struct xfrm_state *, int, void*), void *);
-extern struct xfrm_state *xfrm_state_alloc(void);
+extern void xfrm_state_walk_done(struct xfrm_state_walk *walk);
+extern struct xfrm_state *xfrm_state_alloc(struct net *net);
 extern struct xfrm_state *xfrm_state_find(xfrm_address_t *daddr, xfrm_address_t *saddr, 
                                          struct flowi *fl, struct xfrm_tmpl *tmpl,
                                          struct xfrm_policy *pol, int *err,
                                          unsigned short family);
-extern struct xfrm_state * xfrm_stateonly_find(xfrm_address_t *daddr,
+extern struct xfrm_state *xfrm_stateonly_find(struct net *net, u32 mark,
+                                              xfrm_address_t *daddr,
                                               xfrm_address_t *saddr,
                                               unsigned short family,
                                               u8 mode, u8 proto, u32 reqid);
@@ -1245,8 +1329,14 @@ extern int xfrm_state_check_expire(struct xfrm_state *x);
 extern void xfrm_state_insert(struct xfrm_state *x);
 extern int xfrm_state_add(struct xfrm_state *x);
 extern int xfrm_state_update(struct xfrm_state *x);
-extern struct xfrm_state *xfrm_state_lookup(xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family);
-extern struct xfrm_state *xfrm_state_lookup_byaddr(xfrm_address_t *daddr, xfrm_address_t *saddr, u8 proto, unsigned short family);
+extern struct xfrm_state *xfrm_state_lookup(struct net *net, u32 mark,
+                                           xfrm_address_t *daddr, __be32 spi,
+                                           u8 proto, unsigned short family);
+extern struct xfrm_state *xfrm_state_lookup_byaddr(struct net *net, u32 mark,
+                                                  xfrm_address_t *daddr,
+                                                  xfrm_address_t *saddr,
+                                                  u8 proto,
+                                                  unsigned short family);
 #ifdef CONFIG_XFRM_SUB_POLICY
 extern int xfrm_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src,
                          int n, unsigned short family);
@@ -1283,11 +1373,12 @@ struct xfrmk_spdinfo {
        u32 spdhmcnt;
 };
 
-extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq);
+extern struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 mark,
+                                             u32 seq);
 extern int xfrm_state_delete(struct xfrm_state *x);
-extern int xfrm_state_flush(u8 proto, struct xfrm_audit *audit_info);
-extern void xfrm_sad_getinfo(struct xfrmk_sadinfo *si);
-extern void xfrm_spd_getinfo(struct xfrmk_spdinfo *si);
+extern int xfrm_state_flush(struct net *net, u8 proto, struct xfrm_audit *audit_info);
+extern void xfrm_sad_getinfo(struct net *net, struct xfrmk_sadinfo *si);
+extern void xfrm_spd_getinfo(struct net *net, struct xfrmk_spdinfo *si);
 extern int xfrm_replay_check(struct xfrm_state *x,
                             struct sk_buff *skb, __be32 seq);
 extern void xfrm_replay_advance(struct xfrm_state *x, __be32 seq);
@@ -1300,6 +1391,7 @@ extern int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi,
 extern int xfrm_input_resume(struct sk_buff *skb, int nexthdr);
 extern int xfrm_output_resume(struct sk_buff *skb, int err);
 extern int xfrm_output(struct sk_buff *skb);
+extern int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb);
 extern int xfrm4_extract_header(struct sk_buff *skb);
 extern int xfrm4_extract_input(struct xfrm_state *x, struct sk_buff *skb);
 extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
@@ -1326,9 +1418,9 @@ extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
                            xfrm_address_t *saddr, u8 proto);
 extern int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
 extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
-extern __be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr);
-extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr);
-extern __be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr);
+extern __be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
+extern void xfrm6_tunnel_free_spi(struct net *net, xfrm_address_t *saddr);
+extern __be32 xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr);
 extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
 extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
 extern int xfrm6_output(struct sk_buff *skb);
@@ -1352,56 +1444,46 @@ static inline int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
 }
 #endif
 
-struct xfrm_policy *xfrm_policy_alloc(gfp_t gfp);
-
-static inline void xfrm_policy_walk_init(struct xfrm_policy_walk *walk, u8 type)
-{
-       walk->cur_type = XFRM_POLICY_TYPE_MAIN;
-       walk->type = type;
-       walk->policy = NULL;
-       walk->count = 0;
-}
+struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp);
 
-static inline void xfrm_policy_walk_done(struct xfrm_policy_walk *walk)
-{
-       if (walk->policy != NULL) {
-               xfrm_pol_put(walk->policy);
-               walk->policy = NULL;
-       }
-}
-
-extern int xfrm_policy_walk(struct xfrm_policy_walk *walk,
+extern void xfrm_policy_walk_init(struct xfrm_policy_walk *walk, u8 type);
+extern int xfrm_policy_walk(struct net *net, struct xfrm_policy_walk *walk,
        int (*func)(struct xfrm_policy *, int, int, void*), void *);
+extern void xfrm_policy_walk_done(struct xfrm_policy_walk *walk);
 int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl);
-struct xfrm_policy *xfrm_policy_bysel_ctx(u8 type, int dir,
+struct xfrm_policy *xfrm_policy_bysel_ctx(struct net *net, u32 mark,
+                                         u8 type, int dir,
                                          struct xfrm_selector *sel,
                                          struct xfrm_sec_ctx *ctx, int delete,
                                          int *err);
-struct xfrm_policy *xfrm_policy_byid(u8, int dir, u32 id, int delete, int *err);
-int xfrm_policy_flush(u8 type, struct xfrm_audit *audit_info);
+struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir, u32 id, int delete, int *err);
+int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info);
 u32 xfrm_get_acqseq(void);
 extern int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi);
-struct xfrm_state * xfrm_find_acq(u8 mode, u32 reqid, u8 proto,
-                                 xfrm_address_t *daddr, xfrm_address_t *saddr,
-                                 int create, unsigned short family);
+struct xfrm_state *xfrm_find_acq(struct net *net, struct xfrm_mark *mark,
+                                u8 mode, u32 reqid, u8 proto,
+                                xfrm_address_t *daddr,
+                                xfrm_address_t *saddr, int create,
+                                unsigned short family);
 extern int xfrm_sk_policy_insert(struct sock *sk, int dir, struct xfrm_policy *pol);
 extern int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *xdst,
                          struct flowi *fl, int family, int strict);
 
 #ifdef CONFIG_XFRM_MIGRATE
 extern int km_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
-                     struct xfrm_migrate *m, int num_bundles);
+                     struct xfrm_migrate *m, int num_bundles,
+                     struct xfrm_kmaddress *k);
 extern struct xfrm_state * xfrm_migrate_state_find(struct xfrm_migrate *m);
 extern struct xfrm_state * xfrm_state_migrate(struct xfrm_state *x,
                                              struct xfrm_migrate *m);
 extern int xfrm_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
-                       struct xfrm_migrate *m, int num_bundles);
+                       struct xfrm_migrate *m, int num_bundles,
+                       struct xfrm_kmaddress *k);
 #endif
 
-extern wait_queue_head_t km_waitq;
 extern int km_new_mapping(struct xfrm_state *x, xfrm_address_t *ipaddr, __be16 sport);
 extern void km_policy_expired(struct xfrm_policy *pol, int dir, int hard, u32 pid);
-extern int km_report(u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr);
+extern int km_report(struct net *net, u8 proto, struct xfrm_selector *sel, xfrm_address_t *addr);
 
 extern void xfrm_input_init(void);
 extern int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq);
@@ -1425,16 +1507,13 @@ struct scatterlist;
 typedef int (icv_update_fn_t)(struct hash_desc *, struct scatterlist *,
                              unsigned int);
 
-extern int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *tfm,
-                       int offset, int len, icv_update_fn_t icv_update);
-
 static inline int xfrm_addr_cmp(xfrm_address_t *a, xfrm_address_t *b,
                                int family)
 {
        switch (family) {
        default:
        case AF_INET:
-               return (__force __u32)a->a4 - (__force __u32)b->a4;
+               return (__force u32)a->a4 - (__force u32)b->a4;
        case AF_INET6:
                return ipv6_addr_cmp((struct in6_addr *)a,
                                     (struct in6_addr *)b);
@@ -1446,30 +1525,42 @@ static inline int xfrm_policy_id2dir(u32 index)
        return index & 7;
 }
 
-static inline int xfrm_aevent_is_on(void)
+#ifdef CONFIG_XFRM
+static inline int xfrm_aevent_is_on(struct net *net)
 {
        struct sock *nlsk;
        int ret = 0;
 
        rcu_read_lock();
-       nlsk = rcu_dereference(xfrm_nl);
+       nlsk = rcu_dereference(net->xfrm.nlsk);
        if (nlsk)
                ret = netlink_has_listeners(nlsk, XFRMNLGRP_AEVENTS);
        rcu_read_unlock();
        return ret;
 }
+#endif
 
 static inline int xfrm_alg_len(struct xfrm_algo *alg)
 {
        return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
 }
 
+static inline int xfrm_alg_auth_len(struct xfrm_algo_auth *alg)
+{
+       return sizeof(*alg) + ((alg->alg_key_len + 7) / 8);
+}
+
 #ifdef CONFIG_XFRM_MIGRATE
 static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig)
 {
        return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL);
 }
 
+static inline struct xfrm_algo_auth *xfrm_algo_auth_clone(struct xfrm_algo_auth *orig)
+{
+       return kmemdup(orig, xfrm_alg_auth_len(orig), GFP_KERNEL);
+}
+
 static inline void xfrm_states_put(struct xfrm_state **states, int n)
 {
        int i;
@@ -1485,9 +1576,31 @@ static inline void xfrm_states_delete(struct xfrm_state **states, int n)
 }
 #endif
 
+#ifdef CONFIG_XFRM
 static inline struct xfrm_state *xfrm_input_state(struct sk_buff *skb)
 {
        return skb->sp->xvec[skb->sp->len - 1];
 }
+#endif
+
+static inline int xfrm_mark_get(struct nlattr **attrs, struct xfrm_mark *m)
+{
+       if (attrs[XFRMA_MARK])
+               memcpy(m, nla_data(attrs[XFRMA_MARK]), sizeof(m));
+       else
+               m->v = m->m = 0;
+
+       return m->v & m->m;
+}
+
+static inline int xfrm_mark_put(struct sk_buff *skb, struct xfrm_mark *m)
+{
+       if (m->m | m->v)
+               NLA_PUT(skb, XFRMA_MARK, sizeof(struct xfrm_mark), m);
+       return 0;
+
+nla_put_failure:
+       return -1;
+}
 
 #endif /* _NET_XFRM_H */