Commit 2566a509 authored by Thomas Graf's avatar Thomas Graf Committed by Thomas Graf

[NET]: Introduce INET_ECN_set_ce() function

Changes IP_ECN_set_ce() and IP6_ECN_set_ce() to return 0 if the CE
bits could not bet set because none of the ECT bits are set or 1
if the CE bits are already set or have been successfully set.

Introduces INET_ECN_set_ce(skb) to enable CE bits for all supported
protocols.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@mandriva.com>
parent a7834745
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _INET_ECN_H_ #define _INET_ECN_H_
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/skbuff.h>
#include <net/dsfield.h> #include <net/dsfield.h>
enum { enum {
...@@ -48,7 +49,7 @@ static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner) ...@@ -48,7 +49,7 @@ static inline __u8 INET_ECN_encapsulate(__u8 outer, __u8 inner)
(label) |= __constant_htons(INET_ECN_ECT_0 << 4); \ (label) |= __constant_htons(INET_ECN_ECT_0 << 4); \
} while (0) } while (0)
static inline void IP_ECN_set_ce(struct iphdr *iph) static inline int IP_ECN_set_ce(struct iphdr *iph)
{ {
u32 check = iph->check; u32 check = iph->check;
u32 ecn = (iph->tos + 1) & INET_ECN_MASK; u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
...@@ -61,7 +62,7 @@ static inline void IP_ECN_set_ce(struct iphdr *iph) ...@@ -61,7 +62,7 @@ static inline void IP_ECN_set_ce(struct iphdr *iph)
* INET_ECN_CE => 00 * INET_ECN_CE => 00
*/ */
if (!(ecn & 2)) if (!(ecn & 2))
return; return !ecn;
/* /*
* The following gives us: * The following gives us:
...@@ -72,6 +73,7 @@ static inline void IP_ECN_set_ce(struct iphdr *iph) ...@@ -72,6 +73,7 @@ static inline void IP_ECN_set_ce(struct iphdr *iph)
iph->check = check + (check>=0xFFFF); iph->check = check + (check>=0xFFFF);
iph->tos |= INET_ECN_CE; iph->tos |= INET_ECN_CE;
return 1;
} }
static inline void IP_ECN_clear(struct iphdr *iph) static inline void IP_ECN_clear(struct iphdr *iph)
...@@ -87,11 +89,12 @@ static inline void ipv4_copy_dscp(struct iphdr *outer, struct iphdr *inner) ...@@ -87,11 +89,12 @@ static inline void ipv4_copy_dscp(struct iphdr *outer, struct iphdr *inner)
struct ipv6hdr; struct ipv6hdr;
static inline void IP6_ECN_set_ce(struct ipv6hdr *iph) static inline int IP6_ECN_set_ce(struct ipv6hdr *iph)
{ {
if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph))) if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
return; return 0;
*(u32*)iph |= htonl(INET_ECN_CE << 20); *(u32*)iph |= htonl(INET_ECN_CE << 20);
return 1;
} }
static inline void IP6_ECN_clear(struct ipv6hdr *iph) static inline void IP6_ECN_clear(struct ipv6hdr *iph)
...@@ -105,4 +108,21 @@ static inline void ipv6_copy_dscp(struct ipv6hdr *outer, struct ipv6hdr *inner) ...@@ -105,4 +108,21 @@ static inline void ipv6_copy_dscp(struct ipv6hdr *outer, struct ipv6hdr *inner)
ipv6_change_dsfield(inner, INET_ECN_MASK, dscp); ipv6_change_dsfield(inner, INET_ECN_MASK, dscp);
} }
static inline int INET_ECN_set_ce(struct sk_buff *skb)
{
switch (skb->protocol) {
case __constant_htons(ETH_P_IP):
if (skb->nh.raw + sizeof(struct iphdr) <= skb->tail)
return IP_ECN_set_ce(skb->nh.iph);
break;
case __constant_htons(ETH_P_IPV6):
if (skb->nh.raw + sizeof(struct ipv6hdr) <= skb->tail)
return IP6_ECN_set_ce(skb->nh.ipv6h);
break;
}
return 0;
}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment