win-pvdrivers

changeset 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 306c10cdcba1
children aa7329b5211b
files xennet/xennet_common.c xennet/xennet_rx.c
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;
     2.1 --- a/xennet/xennet_rx.c	Sun Mar 03 12:19:31 2013 +1100
     2.2 +++ b/xennet/xennet_rx.c	Sun Mar 03 13:49:54 2013 +1100
     2.3 @@ -408,9 +408,11 @@ XenNet_MakePacket(struct xennet_info *xi
     2.4      }
     2.5      header_va = (PUCHAR)(header_buf + 1);
     2.6      NdisMoveMemory(header_va, pi->header, pi->header_length);
     2.7 -    //KdPrint((__DRIVER_NAME "     header_length = %d, current_lookahead = %d\n", pi->header_length, xi->current_lookahead));
     2.8 -    //KdPrint((__DRIVER_NAME "     ip4_header_length = %d\n", pi->ip4_header_length));
     2.9 -    //KdPrint((__DRIVER_NAME "     tcp_header_length = %d\n", pi->tcp_header_length));
    2.10 +    //if (pi->ip_proto == 50) {
    2.11 +    //  FUNCTION_MSG("header_length = %d, current_lookahead = %d\n", pi->header_length, xi->current_lookahead);
    2.12 +    //  FUNCTION_MSG("ip4_header_length = %d\n", pi->ip4_header_length);
    2.13 +    //  FUNCTION_MSG("tcp_header_length = %d\n", pi->tcp_header_length);
    2.14 +    //}
    2.15      /* make sure only the header is in the first buffer (or the entire packet, but that is done in the above case) */
    2.16      XenNet_BuildHeader(pi, header_va, MAX_ETH_HEADER_LENGTH + pi->ip4_header_length + pi->tcp_header_length);
    2.17      header_extra = pi->header_length - (MAX_ETH_HEADER_LENGTH + pi->ip4_header_length + pi->tcp_header_length);
    2.18 @@ -432,6 +434,7 @@ XenNet_MakePacket(struct xennet_info *xi
    2.19      #endif
    2.20  
    2.21      if (pi->split_required) {
    2.22 +      /* must be ip4 */
    2.23        ULONG tcp_length;
    2.24        USHORT new_ip4_length;
    2.25        tcp_length = (USHORT)min(pi->mss, pi->tcp_remaining);
    2.26 @@ -453,7 +456,9 @@ XenNet_MakePacket(struct xennet_info *xi
    2.27        ULONG in_buffer_length;
    2.28        ULONG out_length;
    2.29        
    2.30 -      //KdPrint((__DRIVER_NAME "     in loop - out_remaining = %d, curr_buffer = %p, curr_pb = %p\n", out_remaining, pi->curr_mdl, pi->curr_pb));
    2.31 +      //if (pi->ip_proto == 50) {
    2.32 +      //  FUNCTION_MSG("in loop - out_remaining = %d, curr_buffer = %p, curr_pb = %p\n", out_remaining, pi->curr_mdl, pi->curr_pb);
    2.33 +      //}
    2.34        if (!pi->curr_mdl || !pi->curr_pb) {
    2.35          KdPrint((__DRIVER_NAME "     out of buffers for packet\n"));
    2.36          //KdPrint((__DRIVER_NAME "     out_remaining = %d, curr_buffer = %p, curr_pb = %p\n", out_remaining, pi->curr_mdl, pi->curr_pb));
    2.37 @@ -617,13 +622,9 @@ static VOID
    2.38  XenNet_MakePackets(struct xennet_info *xi, rx_context_t *rc, packet_info_t *pi)
    2.39  {
    2.40    UCHAR psh;
    2.41 -  //PNDIS_BUFFER buffer;
    2.42    shared_buffer_t *page_buf;
    2.43  
    2.44 -  //FUNCTION_ENTER();
    2.45 -
    2.46 -  XenNet_ParsePacketHeader(pi, NULL, 0);
    2.47 -  //pi->split_required = FALSE;
    2.48 +  XenNet_ParsePacketHeader(pi, NULL, XN_HDR_SIZE + xi->current_lookahead);
    2.49  
    2.50    if (!XenNet_FilterAcceptPacket(xi, pi)) {
    2.51      goto done;