[TCP/DCCP]: Introduce net_xmit_eval
authorGerrit Renker <gerrit@erg.abdn.ac.uk>
Tue, 14 Nov 2006 13:21:36 +0000 (11:21 -0200)
committerDavid S. Miller <davem@sunset.davemloft.net>
Sun, 3 Dec 2006 05:22:27 +0000 (21:22 -0800)
Throughout the TCP/DCCP (and tunnelling) code, it often happens that the
return code of a transmit function needs to be tested against NET_XMIT_CN
which is a value that does not indicate a strict error condition.

This patch uses a macro for these recurring situations which is consistent
with the already existing macro net_xmit_errno, saving on duplicated code.

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
include/linux/netdevice.h
include/net/ipip.h
net/dccp/ipv4.c
net/dccp/ipv6.c
net/dccp/output.c
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_output.c
net/ipv6/ip6_tunnel.c
net/ipv6/tcp_ipv6.c

index 4e967b2..caa3c25 100644 (file)
@@ -66,6 +66,10 @@ struct netpoll_info;
 #define NET_RX_CN_HIGH         4   /* The storm is here */
 #define NET_RX_BAD             5  /* packet dropped due to kernel error */
 
+/* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
+ * indicates that the device will soon be dropping packets, or already drops
+ * some packets of the same priority; prompting us to send less aggressively. */
+#define net_xmit_eval(e)       ((e) == NET_XMIT_CN? 0 : (e))
 #define net_xmit_errno(e)      ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
 
 #endif
index f490c3c..8405885 100644 (file)
@@ -35,7 +35,7 @@ struct ip_tunnel
        ip_send_check(iph);                                             \
                                                                        \
        err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev, dst_output);\
-       if (err == NET_XMIT_SUCCESS || err == NET_XMIT_CN) {            \
+       if (net_xmit_eval(err) == 0) {                                  \
                stats->tx_bytes += pkt_len;                             \
                stats->tx_packets++;                                    \
        } else {                                                        \
index bc400b2..61c0901 100644 (file)
@@ -501,8 +501,7 @@ static int dccp_v4_send_response(struct sock *sk, struct request_sock *req,
                err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr,
                                            ireq->rmt_addr,
                                            ireq->opt);
-               if (err == NET_XMIT_CN)
-                       err = 0;
+               err = net_xmit_eval(err);
        }
 
 out:
@@ -571,7 +570,7 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
                                    rxskb->nh.iph->saddr, NULL);
        bh_unlock_sock(dccp_v4_ctl_socket->sk);
 
-       if (err == NET_XMIT_CN || err == 0) {
+       if (net_xmit_eval(err) == 0) {
                DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS);
                DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS);
        }
index 8d6ddb6..2165b17 100644 (file)
@@ -294,8 +294,7 @@ static int dccp_v6_send_response(struct sock *sk, struct request_sock *req,
                                                         &ireq6->rmt_addr);
                ipv6_addr_copy(&fl.fl6_dst, &ireq6->rmt_addr);
                err = ip6_xmit(sk, skb, &fl, opt, 0);
-               if (err == NET_XMIT_CN)
-                       err = 0;
+               err = net_xmit_eval(err);
        }
 
 done:
index 0994b13..ef22f3c 100644 (file)
@@ -125,16 +125,7 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
 
                memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
                err = icsk->icsk_af_ops->queue_xmit(skb, sk, 0);
-               if (err <= 0)
-                       return err;
-
-               /* NET_XMIT_CN is special. It does not guarantee,
-                * that this packet is lost. It tells that device
-                * is about to start to drop packets or already
-                * drops some packets of the same priority and
-                * invokes us to send less aggressively.
-                */
-               return err == NET_XMIT_CN ? 0 : err;
+               return net_xmit_eval(err);
        }
        return -ENOBUFS;
 }
@@ -426,8 +417,7 @@ int dccp_send_reset(struct sock *sk, enum dccp_reset_codes code)
                if (skb != NULL) {
                        memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
                        err = inet_csk(sk)->icsk_af_ops->queue_xmit(skb, sk, 0);
-                       if (err == NET_XMIT_CN)
-                               err = 0;
+                       return net_xmit_eval(err);
                }
        }
 
index 2eb5884..0ad0904 100644 (file)
@@ -662,8 +662,7 @@ static int tcp_v4_send_synack(struct sock *sk, struct request_sock *req,
                err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr,
                                            ireq->rmt_addr,
                                            ireq->opt);
-               if (err == NET_XMIT_CN)
-                       err = 0;
+               err = net_xmit_eval(err);
        }
 
 out:
index f63e99a..6a8581a 100644 (file)
@@ -484,13 +484,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
 
        tcp_enter_cwr(sk);
 
-       /* NET_XMIT_CN is special. It does not guarantee,
-        * that this packet is lost. It tells that device
-        * is about to start to drop packets or already
-        * drops some packets of the same priority and
-        * invokes us to send less aggressively.
-        */
-       return err == NET_XMIT_CN ? 0 : err;
+       return net_xmit_eval(err);
 
 #undef SYSCTL_FLAG_TSTAMPS
 #undef SYSCTL_FLAG_WSCALE
index 4919f92..80a1190 100644 (file)
@@ -748,7 +748,7 @@ ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
        err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, 
                      skb->dst->dev, dst_output);
 
-       if (err == NET_XMIT_SUCCESS || err == NET_XMIT_CN) {
+       if (net_xmit_eval(err) == 0) {
                stats->tx_bytes += pkt_len;
                stats->tx_packets++;
        } else {
index 9a8e690..9a88395 100644 (file)
@@ -502,8 +502,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req,
 
                ipv6_addr_copy(&fl.fl6_dst, &treq->rmt_addr);
                err = ip6_xmit(sk, skb, &fl, opt, 0);
-               if (err == NET_XMIT_CN)
-                       err = 0;
+               err = net_xmit_eval(err);
        }
 
 done: