ipv6: add complete rcu protection around np->opt
[pandora-kernel.git] / include / net / ipv6.h
index 77763c6..25f0491 100644 (file)
@@ -191,6 +191,7 @@ extern rwlock_t ip6_ra_lock;
  */
 
 struct ipv6_txoptions {
+       atomic_t                refcnt;
        /* Length of this structure */
        int                     tot_len;
 
@@ -203,7 +204,7 @@ struct ipv6_txoptions {
        struct ipv6_opt_hdr     *dst0opt;
        struct ipv6_rt_hdr      *srcrt; /* Routing Header */
        struct ipv6_opt_hdr     *dst1opt;
-
+       struct rcu_head         rcu;
        /* Option buffer, as read by IPV6_PKTOPTIONS, starts here. */
 };
 
@@ -229,6 +230,24 @@ struct ipv6_fl_socklist {
        struct ip6_flowlabel    *fl;
 };
 
+static inline struct ipv6_txoptions *txopt_get(const struct ipv6_pinfo *np)
+{
+       struct ipv6_txoptions *opt;
+
+       rcu_read_lock();
+       opt = rcu_dereference(np->opt);
+       if (opt && !atomic_inc_not_zero(&opt->refcnt))
+               opt = NULL;
+       rcu_read_unlock();
+       return opt;
+}
+
+static inline void txopt_put(struct ipv6_txoptions *opt)
+{
+       if (opt && atomic_dec_and_test(&opt->refcnt))
+               kfree_rcu(opt, rcu);
+}
+
 extern struct ip6_flowlabel    *fl6_sock_lookup(struct sock *sk, __be32 label);
 extern struct ipv6_txoptions   *fl6_merge_options(struct ipv6_txoptions * opt_space,
                                                   struct ip6_flowlabel * fl,