diff mbox series

[v8,net-next,6/8] ipv6tlvs: opt_update function

Message ID 1556579063-1367-7-git-send-email-tom@quantonium.net
State Superseded
Delegated to: David Miller
Headers show
Series exthdrs: Make ext. headers & options useful - Part I | expand

Commit Message

Tom Herbert April 29, 2019, 11:04 p.m. UTC
Add a utility function to replace socket's options with a new set.

Signed-off-by: Tom Herbert <tom@quantonium.net>
---
 include/net/ipv6.h       |  2 ++
 net/ipv6/ipv6_sockglue.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 8c19c6f..a8c1e6c 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -379,6 +379,8 @@  struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
 					  struct ipv6_opt_hdr *newopt);
 struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
 					  struct ipv6_txoptions *opt);
+int ipv6_opt_update(struct sock *sk, struct ipv6_txoptions *opt,
+		    int which, struct ipv6_opt_hdr *new);
 
 /*
  *     Parsing tlv encoded headers.
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 5045818..b8ef0ea 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -118,6 +118,22 @@  struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
 	return opt;
 }
 
+int ipv6_opt_update(struct sock *sk, struct ipv6_txoptions *opt,
+		    int which, struct ipv6_opt_hdr *new)
+{
+	opt = ipv6_renew_options(sk, opt, which, new);
+	if (IS_ERR(opt))
+		return PTR_ERR(opt);
+
+	opt = ipv6_update_options(sk, opt);
+	if (opt) {
+		atomic_sub(opt->tot_len, &sk->sk_omem_alloc);
+		txopt_put(opt);
+	}
+
+	return 0;
+}
+
 static bool setsockopt_needs_rtnl(int optname)
 {
 	switch (optname) {