aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuw Davies <huw@codeweavers.com>2016-06-27 15:02:50 -0400
committerPaul Moore <paul@paul-moore.com>2016-06-27 15:02:50 -0400
commite67ae213c72f72be50561c060ae17e92426651da (patch)
treefbcab23819aeb1ebddfe02c30743c37589794e22
parentd7cce01504a0ccb95b5007d846560cfccbc1947f (diff)
ipv6: Add ipv6_renew_options_kern() that accepts a kernel mem pointer.
The functionality is equivalent to ipv6_renew_options() except that the newopt pointer is in kernel, not user, memory The kernel memory implementation will be used by the CALIPSO network labelling engine, which needs to be able to set IPv6 hop-by-hop options. Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
-rw-r--r--include/net/ipv6.h6
-rw-r--r--net/ipv6/exthdrs.c49
2 files changed, 55 insertions, 0 deletions
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index d0aeb97aec5d..887313d978d0 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -308,6 +308,12 @@ struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
308 int newtype, 308 int newtype,
309 struct ipv6_opt_hdr __user *newopt, 309 struct ipv6_opt_hdr __user *newopt,
310 int newoptlen); 310 int newoptlen);
311struct ipv6_txoptions *
312ipv6_renew_options_kern(struct sock *sk,
313 struct ipv6_txoptions *opt,
314 int newtype,
315 struct ipv6_opt_hdr *newopt,
316 int newoptlen);
311struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space, 317struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
312 struct ipv6_txoptions *opt); 318 struct ipv6_txoptions *opt);
313 319
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index ea7c4d64a00a..d5fd3e799f86 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -758,6 +758,27 @@ static int ipv6_renew_option(void *ohdr,
758 return 0; 758 return 0;
759} 759}
760 760
761/**
762 * ipv6_renew_options - replace a specific ext hdr with a new one.
763 *
764 * @sk: sock from which to allocate memory
765 * @opt: original options
766 * @newtype: option type to replace in @opt
767 * @newopt: new option of type @newtype to replace (user-mem)
768 * @newoptlen: length of @newopt
769 *
770 * Returns a new set of options which is a copy of @opt with the
771 * option type @newtype replaced with @newopt.
772 *
773 * @opt may be NULL, in which case a new set of options is returned
774 * containing just @newopt.
775 *
776 * @newopt may be NULL, in which case the specified option type is
777 * not copied into the new set of options.
778 *
779 * The new set of options is allocated from the socket option memory
780 * buffer of @sk.
781 */
761struct ipv6_txoptions * 782struct ipv6_txoptions *
762ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt, 783ipv6_renew_options(struct sock *sk, struct ipv6_txoptions *opt,
763 int newtype, 784 int newtype,
@@ -830,6 +851,34 @@ out:
830 return ERR_PTR(err); 851 return ERR_PTR(err);
831} 852}
832 853
854/**
855 * ipv6_renew_options_kern - replace a specific ext hdr with a new one.
856 *
857 * @sk: sock from which to allocate memory
858 * @opt: original options
859 * @newtype: option type to replace in @opt
860 * @newopt: new option of type @newtype to replace (kernel-mem)
861 * @newoptlen: length of @newopt
862 *
863 * See ipv6_renew_options(). The difference is that @newopt is
864 * kernel memory, rather than user memory.
865 */
866struct ipv6_txoptions *
867ipv6_renew_options_kern(struct sock *sk, struct ipv6_txoptions *opt,
868 int newtype, struct ipv6_opt_hdr *newopt,
869 int newoptlen)
870{
871 struct ipv6_txoptions *ret_val;
872 const mm_segment_t old_fs = get_fs();
873
874 set_fs(KERNEL_DS);
875 ret_val = ipv6_renew_options(sk, opt, newtype,
876 (struct ipv6_opt_hdr __user *)newopt,
877 newoptlen);
878 set_fs(old_fs);
879 return ret_val;
880}
881
833struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space, 882struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
834 struct ipv6_txoptions *opt) 883 struct ipv6_txoptions *opt)
835{ 884{