]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - net/socket.c
libceph: use kbasename() and kill ceph_file_part()
[linux.git] / net / socket.c
index 985ef06792d6e54c69d296f3e15baf89be972f9c..c2564eb25c6b8faf5c99504ef1d3c90f9bb57c73 100644 (file)
@@ -3356,3 +3356,49 @@ int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how)
        return sock->ops->shutdown(sock, how);
 }
 EXPORT_SYMBOL(kernel_sock_shutdown);
+
+/* This routine returns the IP overhead imposed by a socket i.e.
+ * the length of the underlying IP header, depending on whether
+ * this is an IPv4 or IPv6 socket and the length from IP options turned
+ * on at the socket. Assumes that the caller has a lock on the socket.
+ */
+u32 kernel_sock_ip_overhead(struct sock *sk)
+{
+       struct inet_sock *inet;
+       struct ip_options_rcu *opt;
+       u32 overhead = 0;
+       bool owned_by_user;
+#if IS_ENABLED(CONFIG_IPV6)
+       struct ipv6_pinfo *np;
+       struct ipv6_txoptions *optv6 = NULL;
+#endif /* IS_ENABLED(CONFIG_IPV6) */
+
+       if (!sk)
+               return overhead;
+
+       owned_by_user = sock_owned_by_user(sk);
+       switch (sk->sk_family) {
+       case AF_INET:
+               inet = inet_sk(sk);
+               overhead += sizeof(struct iphdr);
+               opt = rcu_dereference_protected(inet->inet_opt,
+                                               owned_by_user);
+               if (opt)
+                       overhead += opt->opt.optlen;
+               return overhead;
+#if IS_ENABLED(CONFIG_IPV6)
+       case AF_INET6:
+               np = inet6_sk(sk);
+               overhead += sizeof(struct ipv6hdr);
+               if (np)
+                       optv6 = rcu_dereference_protected(np->opt,
+                                                         owned_by_user);
+               if (optv6)
+                       overhead += (optv6->opt_flen + optv6->opt_nflen);
+               return overhead;
+#endif /* IS_ENABLED(CONFIG_IPV6) */
+       default: /* Returns 0 overhead if the socket is not ipv4 or ipv6 */
+               return overhead;
+       }
+}
+EXPORT_SYMBOL(kernel_sock_ip_overhead);