win-pvdrivers

diff xennet/xennet_common.c @ 1033:cb767700f91c

Correctly initialise pi values and set header size based on lookahead
author James Harper <james.harper@bendigoit.com.au>
date Sun Mar 03 13:49:54 2013 +1100 (2013-03-03)
parents 1ce315b193d1
children fba0ce4d9e54
line diff
     1.1 --- a/xennet/xennet_common.c	Sun Mar 03 12:19:31 2013 +1100
     1.2 +++ b/xennet/xennet_common.c	Sun Mar 03 13:49:54 2013 +1100
     1.3 @@ -131,11 +131,18 @@ XenNet_ParsePacketHeader(packet_info_t *
     1.4  
     1.5    pi->header_length = 0;
     1.6    pi->curr_mdl_offset = pi->first_mdl_offset;
     1.7 +  
     1.8 +  pi->ip_proto = 0;
     1.9 +  pi->ip_version = 0;
    1.10 +  pi->ip4_header_length = 0;
    1.11 +  pi->ip4_length = 0;
    1.12 +  pi->tcp_header_length = 0;
    1.13 +  pi->tcp_length = 0;
    1.14 +  pi->split_required = 0;
    1.15  
    1.16    XenNet_BuildHeader(pi, NULL, min_header_size);
    1.17    
    1.18 -  if (!XenNet_BuildHeader(pi, NULL, (ULONG)XN_HDR_SIZE))
    1.19 -  {
    1.20 +  if (!XenNet_BuildHeader(pi, NULL, (ULONG)XN_HDR_SIZE)) {
    1.21      //KdPrint((__DRIVER_NAME "     packet too small (Ethernet Header)\n"));
    1.22      pi->parse_result = PARSE_TOO_SMALL;
    1.23      return;
    1.24 @@ -143,40 +150,31 @@ XenNet_ParsePacketHeader(packet_info_t *
    1.25  
    1.26    if (pi->header[0] == 0xFF && pi->header[1] == 0xFF
    1.27        && pi->header[2] == 0xFF && pi->header[3] == 0xFF
    1.28 -      && pi->header[4] == 0xFF && pi->header[5] == 0xFF)
    1.29 -  {
    1.30 +      && pi->header[4] == 0xFF && pi->header[5] == 0xFF) {
    1.31      pi->is_broadcast = TRUE;
    1.32 -  }
    1.33 -  else if (pi->header[0] & 0x01)
    1.34 -  {
    1.35 +  } else if (pi->header[0] & 0x01) {
    1.36      pi->is_multicast = TRUE;
    1.37    }
    1.38  
    1.39 -  switch (GET_NET_PUSHORT(&pi->header[12])) // L2 protocol field
    1.40 -  {
    1.41 +  switch (GET_NET_PUSHORT(&pi->header[12])) { // L2 protocol field
    1.42    case 0x0800: /* IPv4 */
    1.43      //KdPrint((__DRIVER_NAME "     IP\n"));
    1.44 -    if (pi->header_length < (ULONG)(XN_HDR_SIZE + 20))
    1.45 -    {
    1.46 -      if (!XenNet_BuildHeader(pi, NULL, (ULONG)(XN_HDR_SIZE + 20)))
    1.47 -      {
    1.48 +    if (pi->header_length < (ULONG)(XN_HDR_SIZE + 20)) {
    1.49 +      if (!XenNet_BuildHeader(pi, NULL, (ULONG)(XN_HDR_SIZE + 20))) {
    1.50          KdPrint((__DRIVER_NAME "     packet too small (IP Header)\n"));
    1.51          pi->parse_result = PARSE_TOO_SMALL;
    1.52          return;
    1.53        }
    1.54      }
    1.55      pi->ip_version = (pi->header[XN_HDR_SIZE + 0] & 0xF0) >> 4;
    1.56 -    if (pi->ip_version != 4)
    1.57 -    {
    1.58 +    if (pi->ip_version != 4) {
    1.59        //KdPrint((__DRIVER_NAME "     ip_version = %d\n", pi->ip_version));
    1.60        pi->parse_result = PARSE_UNKNOWN_TYPE;
    1.61        return;
    1.62      }
    1.63      pi->ip4_header_length = (pi->header[XN_HDR_SIZE + 0] & 0x0F) << 2;
    1.64 -    if (pi->header_length < (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + 20))
    1.65 -    {
    1.66 -      if (!XenNet_BuildHeader(pi, NULL, (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + 20)))
    1.67 -      {
    1.68 +    if (pi->header_length < (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + 20)) {
    1.69 +      if (!XenNet_BuildHeader(pi, NULL, (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + 20))) {
    1.70          //KdPrint((__DRIVER_NAME "     packet too small (IP Header + IP Options + TCP Header)\n"));
    1.71          pi->parse_result = PARSE_TOO_SMALL;
    1.72          return;
    1.73 @@ -196,8 +194,7 @@ XenNet_ParsePacketHeader(packet_info_t *
    1.74    pi->ip_proto = pi->header[XN_HDR_SIZE + 9];
    1.75    pi->ip4_length = GET_NET_PUSHORT(&pi->header[XN_HDR_SIZE + 2]);
    1.76    pi->ip_has_options = (BOOLEAN)(pi->ip4_header_length > 20);
    1.77 -  switch (pi->ip_proto)
    1.78 -  {
    1.79 +  switch (pi->ip_proto) {
    1.80    case 6:  // TCP
    1.81    case 17: // UDP
    1.82      break;
    1.83 @@ -208,19 +205,16 @@ XenNet_ParsePacketHeader(packet_info_t *
    1.84    }
    1.85    pi->tcp_header_length = (pi->header[XN_HDR_SIZE + pi->ip4_header_length + 12] & 0xf0) >> 2;
    1.86  
    1.87 -  if (pi->header_length < (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + pi->tcp_header_length))
    1.88 -  {
    1.89 +  if (pi->header_length < (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + pi->tcp_header_length)) {
    1.90      /* we don't actually need the tcp options to analyse the header */
    1.91 -    if (!XenNet_BuildHeader(pi, NULL, (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + MIN_TCP_HEADER_LENGTH)))
    1.92 -    {
    1.93 +    if (!XenNet_BuildHeader(pi, NULL, (ULONG)(XN_HDR_SIZE + pi->ip4_header_length + MIN_TCP_HEADER_LENGTH))) {
    1.94        //KdPrint((__DRIVER_NAME "     packet too small (IP Header + IP Options + TCP Header (not including TCP Options))\n"));
    1.95        pi->parse_result = PARSE_TOO_SMALL;
    1.96        return;
    1.97      }
    1.98    }
    1.99  
   1.100 -  if ((ULONG)XN_HDR_SIZE + pi->ip4_length > pi->total_length)
   1.101 -  {
   1.102 +  if ((ULONG)XN_HDR_SIZE + pi->ip4_length > pi->total_length) {
   1.103      //KdPrint((__DRIVER_NAME "     XN_HDR_SIZE + ip4_length (%d) > total_length (%d)\n", XN_HDR_SIZE + pi->ip4_length, pi->total_length));
   1.104      pi->parse_result = PARSE_UNKNOWN_TYPE;
   1.105      return;