ARM64: dts: rockchip: enable tsadc node for rk3366-tb
[firefly-linux-kernel-4.4.55.git] / net / ipv4 / tcp.c
index cab28756a96ba28d743ba7204327eff0b650ab1e..7c0465202cc5191b51298a8b6a9eb591898fb437 100644 (file)
 
 #include <asm/uaccess.h>
 #include <asm/ioctls.h>
+#include <asm/unaligned.h>
 #include <net/busy_poll.h>
 
 int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;
@@ -942,7 +943,7 @@ new_segment:
 
                i = skb_shinfo(skb)->nr_frags;
                can_coalesce = skb_can_coalesce(skb, i, page, offset);
-               if (!can_coalesce && i >= MAX_SKB_FRAGS) {
+               if (!can_coalesce && i >= sysctl_max_skb_frags) {
                        tcp_mark_push(tp, skb);
                        goto new_segment;
                }
@@ -1215,7 +1216,7 @@ new_segment:
 
                        if (!skb_can_coalesce(skb, i, pfrag->page,
                                              pfrag->offset)) {
-                               if (i == MAX_SKB_FRAGS || !sg) {
+                               if (i == sysctl_max_skb_frags || !sg) {
                                        tcp_mark_push(tp, skb);
                                        goto new_segment;
                                }
@@ -1289,7 +1290,8 @@ out_nopush:
        release_sock(sk);
 
        if (copied + copied_syn)
-               uid_stat_tcp_snd(current_uid(), copied + copied_syn);
+               uid_stat_tcp_snd(from_kuid(&init_user_ns, current_uid()),
+                                copied + copied_syn);
        return copied + copied_syn;
 
 do_fault:
@@ -1564,7 +1566,8 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
        if (copied > 0) {
                tcp_recv_skb(sk, seq, &offset);
                tcp_cleanup_rbuf(sk, copied);
-               uid_stat_tcp_rcv(current_uid(), copied);
+               uid_stat_tcp_rcv(from_kuid(&init_user_ns, current_uid()),
+                                copied);
        }
        return copied;
 }
@@ -1900,7 +1903,8 @@ skip_copy:
        release_sock(sk);
 
        if (copied > 0)
-               uid_stat_tcp_rcv(current_uid(), copied);
+               uid_stat_tcp_rcv(from_kuid(&init_user_ns, current_uid()),
+                                copied);
        return copied;
 
 out:
@@ -1910,7 +1914,8 @@ out:
 recv_urg:
        err = tcp_recv_urg(sk, msg, len, flags);
        if (err > 0)
-               uid_stat_tcp_rcv(current_uid(), err);
+               uid_stat_tcp_rcv(from_kuid(&init_user_ns, current_uid()),
+                                err);
        goto out;
 
 recv_sndq:
@@ -2650,6 +2655,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
        const struct inet_connection_sock *icsk = inet_csk(sk);
        u32 now = tcp_time_stamp;
        unsigned int start;
+       u64 rate64;
        u32 rate;
 
        memset(info, 0, sizeof(*info));
@@ -2715,15 +2721,17 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
        info->tcpi_total_retrans = tp->total_retrans;
 
        rate = READ_ONCE(sk->sk_pacing_rate);
-       info->tcpi_pacing_rate = rate != ~0U ? rate : ~0ULL;
+       rate64 = rate != ~0U ? rate : ~0ULL;
+       put_unaligned(rate64, &info->tcpi_pacing_rate);
 
        rate = READ_ONCE(sk->sk_max_pacing_rate);
-       info->tcpi_max_pacing_rate = rate != ~0U ? rate : ~0ULL;
+       rate64 = rate != ~0U ? rate : ~0ULL;
+       put_unaligned(rate64, &info->tcpi_max_pacing_rate);
 
        do {
                start = u64_stats_fetch_begin_irq(&tp->syncp);
-               info->tcpi_bytes_acked = tp->bytes_acked;
-               info->tcpi_bytes_received = tp->bytes_received;
+               put_unaligned(tp->bytes_acked, &info->tcpi_bytes_acked);
+               put_unaligned(tp->bytes_received, &info->tcpi_bytes_received);
        } while (u64_stats_fetch_retry_irq(&tp->syncp, start));
        info->tcpi_segs_out = tp->segs_out;
        info->tcpi_segs_in = tp->segs_in;
@@ -3093,6 +3101,52 @@ void tcp_done(struct sock *sk)
 }
 EXPORT_SYMBOL_GPL(tcp_done);
 
+int tcp_abort(struct sock *sk, int err)
+{
+       if (!sk_fullsock(sk)) {
+               if (sk->sk_state == TCP_NEW_SYN_RECV) {
+                       struct request_sock *req = inet_reqsk(sk);
+
+                       local_bh_disable();
+                       inet_csk_reqsk_queue_drop_and_put(req->rsk_listener,
+                                                         req);
+                       local_bh_enable();
+                       return 0;
+               }
+               sock_gen_put(sk);
+               return -EOPNOTSUPP;
+       }
+
+       /* Don't race with userspace socket closes such as tcp_close. */
+       lock_sock(sk);
+
+       if (sk->sk_state == TCP_LISTEN) {
+               tcp_set_state(sk, TCP_CLOSE);
+               inet_csk_listen_stop(sk);
+       }
+
+       /* Don't race with BH socket closes such as inet_csk_listen_stop. */
+       local_bh_disable();
+       bh_lock_sock(sk);
+
+       if (!sock_flag(sk, SOCK_DEAD)) {
+               sk->sk_err = err;
+               /* This barrier is coupled with smp_rmb() in tcp_poll() */
+               smp_wmb();
+               sk->sk_error_report(sk);
+               if (tcp_need_reset(sk->sk_state))
+                       tcp_send_active_reset(sk, GFP_ATOMIC);
+               tcp_done(sk);
+       }
+
+       bh_unlock_sock(sk);
+       local_bh_enable();
+       release_sock(sk);
+       sock_put(sk);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(tcp_abort);
+
 extern struct tcp_congestion_ops tcp_reno;
 
 static __initdata unsigned long thash_entries;
@@ -3210,7 +3264,7 @@ static int tcp_is_local(struct net *net, __be32 addr) {
        return rt->dst.dev && (rt->dst.dev->flags & IFF_LOOPBACK);
 }
 
-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+#if defined(CONFIG_IPV6)
 static int tcp_is_local6(struct net *net, struct in6_addr *addr) {
        struct rt6_info *rt6 = rt6_lookup(net, addr, addr, 0, 0);
        return rt6 && rt6->dst.dev && (rt6->dst.dev->flags & IFF_LOOPBACK);
@@ -3229,7 +3283,7 @@ int tcp_nuke_addr(struct net *net, struct sockaddr *addr)
 
        struct in_addr *in;
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
-       struct in6_addr *in6;
+       struct in6_addr *in6 = NULL;
 #endif
        if (family == AF_INET) {
                in = &((struct sockaddr_in *)addr)->sin_addr;
@@ -3278,13 +3332,13 @@ restart:
                                        continue;
                        }
 
-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+#if defined(CONFIG_IPV6)
                        if (family == AF_INET6) {
                                struct in6_addr *s6;
                                if (!inet->pinet6)
                                        continue;
 
-                               s6 = &inet->pinet6->rcv_saddr;
+                               s6 = &sk->sk_v6_rcv_saddr;
                                if (ipv6_addr_type(s6) == IPV6_ADDR_MAPPED)
                                        continue;
 
@@ -3315,3 +3369,4 @@ restart:
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(tcp_nuke_addr);