Skip to content

Commit

Permalink
Fix an issue that IP DSCP and ECN are not properly parsed and stored …
Browse files Browse the repository at this point in the history
…in packet_info.
  • Loading branch information
CHIBA Yasunobu committed Jul 12, 2013
1 parent 33f1527 commit 5ba97e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/lib/ipv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@
#define IPV4_H


#include <netinet/ip.h>
#include "buffer.h"
#include "byteorder.h"


#if !defined( IPTOS_DSCP_MASK )
#define IPTOS_DSCP_MASK 0xfc
#endif

#define IPTOS_DSCP_SHIFT 2


typedef struct {
Expand Down
14 changes: 8 additions & 6 deletions src/lib/packet_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ typedef struct {
uint8_t vlan_cfi;
uint16_t vlan_vid;
uint8_t vlan_pcp;
uint8_t ip_dscp;
/*
* TODO not set in packet parsing but necessary to compile ofdp.
*/
uint8_t ip_ecn;
uint8_t ip_proto;

uint8_t snap_llc[ SNAP_LLC_LENGTH ];
uint8_t snap_oui[ SNAP_OUI_LENGTH ];
Expand All @@ -143,9 +137,15 @@ typedef struct {
uint8_t arp_tha[ ETH_ADDRLEN ];
uint32_t arp_tpa;

uint8_t ip_proto;
uint8_t ip_dscp;
uint8_t ip_ecn;

uint8_t ipv4_version;
uint8_t ipv4_ihl;
uint8_t ipv4_tos;
uint8_t ipv4_dscp;
uint8_t ipv4_ecn;
uint16_t ipv4_tot_len;
uint16_t ipv4_id;
uint16_t ipv4_frag_off;
Expand All @@ -157,6 +157,8 @@ typedef struct {

uint8_t ipv6_version;
uint8_t ipv6_tc;
uint8_t ipv6_dscp;
uint8_t ipv6_ecn;
uint32_t ipv6_flowlabel;
uint16_t ipv6_plen;
uint16_t ipv6_nexthdr;
Expand Down
8 changes: 8 additions & 0 deletions src/lib/packet_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ parse_ipv4( buffer *buf ) {
packet_info->ipv4_version = ipv4_header->version;
packet_info->ipv4_ihl = ipv4_header->ihl;
packet_info->ipv4_tos = ipv4_header->tos;
packet_info->ipv4_dscp = ( IPTOS_DSCP_MASK & ipv4_header->tos ) >> IPTOS_DSCP_SHIFT;
packet_info->ipv4_ecn = IPTOS_ECN_MASK & ipv4_header->tos;
packet_info->ipv4_tot_len = ntohs( ipv4_header->tot_len );
packet_info->ipv4_id = ntohs( ipv4_header->id );
packet_info->ipv4_frag_off = ntohs( ipv4_header->frag_off );
Expand Down Expand Up @@ -260,6 +262,8 @@ parse_ipv6( buffer *buf ) {
uint32_t hdrctl = ntohl( ipv6_header->hdrctl );
packet_info->ipv6_version = ( uint8_t )( hdrctl >> 28 );
packet_info->ipv6_tc = ( uint8_t )( hdrctl >> 20 & 0xFF );
packet_info->ipv6_dscp = ( IPTOS_DSCP_MASK & packet_info->ipv6_tc ) >> IPTOS_DSCP_SHIFT;
packet_info->ipv6_ecn = IPTOS_ECN_MASK & packet_info->ipv6_tc;
packet_info->ipv6_flowlabel = hdrctl & 0xFFFFF;
packet_info->ipv6_plen = ntohs( ipv6_header->plen );
packet_info->ipv6_nexthdr = ipv6_header->nexthdr;
Expand Down Expand Up @@ -726,9 +730,13 @@ parse_packet( buffer *buf ) {
return true;
}
packet_info->ip_proto = packet_info->ipv4_protocol;
packet_info->ip_dscp = packet_info->ipv4_dscp;
packet_info->ip_ecn = packet_info->ipv4_ecn;
}
else if ( packet_info->format & NW_IPV6 ) {
packet_info->ip_proto = packet_info->ipv6_protocol;
packet_info->ip_dscp = packet_info->ipv6_dscp;
packet_info->ip_ecn = packet_info->ipv6_ecn;
}
else {
// Not IPv4/v6 type
Expand Down
3 changes: 3 additions & 0 deletions src/lib/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#define TCP_H


#include "byteorder.h"


typedef struct tcp_header {
uint16_t src_port;
uint16_t dst_port;
Expand Down

0 comments on commit 5ba97e5

Please sign in to comment.