Skip to content

Commit

Permalink
Fix the interpretation of priority nibbles in ipv6 header
Browse files Browse the repository at this point in the history
The higher nibble of the priority is in the higher nibble of the
first byte and the lower nibble is in the lower nibble of the
second byte. The earlier interpretation was plain reverse of this
scheme. Also, DSCP is the most significant 6 bits of the ipv6
priority.

Change-Id: I815e35d9955382fb21ab686be9f20754a7df0d52
Closes-Bug: #1614042
  • Loading branch information
anandhk-juniper committed Sep 2, 2016
1 parent 025a739 commit 9c84165
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions include/vr_packet.h
Expand Up @@ -474,30 +474,30 @@ struct vr_ip6_pseudo {
struct vr_ip6 {
#ifdef __KERNEL__
#if defined(__LITTLE_ENDIAN_BITFIELD)
uint8_t ip6_priority_l:4,
ip6_version:4;
uint8_t ip6_priority_h:4,
ip6_flow_l:4;
ip6_version:4;
uint8_t ip6_flow_h:4,
ip6_priority_l:4;
#elif defined(__BIG_ENDIAN_BITFIELD)
uint8_t ip6_version:4,
ip6_priority_l:4;
uint8_t ip6_flow_l:4,
ip6_prioirty_h:4;
ip6_priority_h:4;
uint8_t ip6_priority_l:4,
ip6_flow_h:4;
#endif
#else
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
uint8_t ip6_priority_l:4,
ip6_version:4;
uint8_t ip6_priority_h:4,
ip6_flow_l:4;
ip6_version:4;
uint8_t ip6_flow_h:4,
ip6_priority_l:4;
#elif (__BYTE_ORDER == __BIG_ENDIAN)
uint8_t ip6_version:4,
ip6_priority_l:4;
uint8_t ip6_flow_l:4,
ip6_prioirty_h:4;
ip6_priority_h:4;
uint8_t ip6_priority_l:4,
ip6_flow_h:4;
#endif
#endif
uint16_t ip6_flow_h;
uint16_t ip6_flow_l;
uint16_t ip6_plen;
uint8_t ip6_nxt;
uint8_t ip6_hlim;
Expand All @@ -511,14 +511,14 @@ struct vr_ip6 {
static inline uint8_t
vr_inet6_get_tos(struct vr_ip6 *ip6h)
{
return (((ip6h->ip6_priority_h << 4) | (ip6h->ip6_priority_l)) & 0x3F);
return ((((ip6h->ip6_priority_h << 4) | (ip6h->ip6_priority_l)) >> 2) & 0x3F);
}

static inline void
vr_inet6_set_tos(struct vr_ip6 *ip6h, uint8_t tos)
{
ip6h->ip6_priority_h = (tos >> 4) & 0x3;
ip6h->ip6_priority_l = (tos & 0xF);
ip6h->ip6_priority_h = ((tos << 2) >> 4);
ip6h->ip6_priority_l = ((tos << 2) & 0xF);

return;
}
Expand Down

0 comments on commit 9c84165

Please sign in to comment.