win-pvdrivers

changeset 114:64e4596aec1c

- Fixed RxBufferCheck so that more than 2 'chunks' in a packet will work, if it ever happens.
- Updated RxBufferCheck so that an incomplete packet will not cause an assert.
- Fixed ReturnPacket so that we extract the 'next buffer' from the current buffer before we free the current buffer (doing it the other way around doesn't work!)
- Removed my packet inspection code - hopefully won't need it anymore.
author James Harper <james.harper@bendigoit.com.au>
date Sat Jan 12 17:12:07 2008 +1100 (2008-01-12)
parents e96b7ebe0147
children 0d9e5303a8d2
files xennet/sources xennet/xennet.c
line diff
     1.1 --- a/xennet/sources	Fri Jan 11 11:47:58 2008 -0800
     1.2 +++ b/xennet/sources	Sat Jan 12 17:12:07 2008 +1100
     1.3 @@ -1,7 +1,7 @@
     1.4  TARGETNAME=XENNET
     1.5  TARGETTYPE=DRIVER
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7 -VERSION=0.5.0.75
     1.8 +VERSION=0.5.0.80
     1.9  KMDF_VERSION=1
    1.10  MSC_WARNING_LEVEL=/W4
    1.11  INF_NAME=xennet
     2.1 --- a/xennet/xennet.c	Fri Jan 11 11:47:58 2008 -0800
     2.2 +++ b/xennet/xennet.c	Sat Jan 12 17:12:07 2008 +1100
     2.3 @@ -360,94 +360,38 @@ XenNet_RxBufferFree(struct xennet_info *
     2.4    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
     2.5  }
     2.6  
     2.7 -static VOID
     2.8 -XenNet_ProcessReceivedTcpPacket(PNDIS_PACKET packet, PUCHAR buf, ULONG len)
     2.9 +VOID
    2.10 +XenNet_ReturnPacket(
    2.11 +  IN NDIS_HANDLE MiniportAdapterContext,
    2.12 +  IN PNDIS_PACKET Packet
    2.13 +  )
    2.14  {
    2.15 -  USHORT checksum = (buf[16] << 8) | buf[17];
    2.16 -  buf[16] = 0;
    2.17 -  buf[17] = 0;
    2.18 -}
    2.19 +  PNDIS_BUFFER buffer;
    2.20 +  PNDIS_BUFFER next_buffer;
    2.21 +  PVOID buff_va;
    2.22 +  UINT buff_len;
    2.23 +  UINT tot_buff_len;
    2.24  
    2.25 -static VOID
    2.26 -XenNet_ProcessReceivedIpPacket(PNDIS_PACKET packet, PUCHAR buf, ULONG len)
    2.27 -{
    2.28 -  UCHAR version;
    2.29 -  UCHAR header_len;
    2.30 -  UCHAR proto;
    2.31 -  USHORT total_len;
    2.32 +//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    2.33  
    2.34 -  if (len < 20)
    2.35 +  UNREFERENCED_PARAMETER(MiniportAdapterContext);
    2.36 +
    2.37 +  NdisGetFirstBufferFromPacketSafe(Packet, &buffer, &buff_va, &buff_len,
    2.38 +    &tot_buff_len, NormalPagePriority);
    2.39 +  ASSERT(tot_buff_len <= XN_MAX_PKT_SIZE);
    2.40 +
    2.41 +  while (buffer)
    2.42    {
    2.43 -    KdPrint((__DRIVER_NAME "     IP packet too small\n"));
    2.44 -    return;
    2.45 -  }
    2.46 -  version = buf[0] >> 4;
    2.47 -  if (version != 4)
    2.48 -  {
    2.49 -    KdPrint((__DRIVER_NAME "     IP version not IPv4 (version = %d)\n", version));
    2.50 -    return;
    2.51 -  }
    2.52 -
    2.53 -  KdPrint((__DRIVER_NAME "     %d.%d.%d.%d -> %d.%d.%d.%d\n",
    2.54 -    buf[12], buf[13], buf[14], buf[15],
    2.55 -    buf[16], buf[17], buf[18], buf[19]));
    2.56 -
    2.57 -  header_len = (buf[0] & 15) * 4;
    2.58 -  total_len = (buf[2] << 8) | buf[3];
    2.59 -
    2.60 -  if (total_len != len)
    2.61 -  {
    2.62 -    KdPrint((__DRIVER_NAME "     IP packet probably fragmented.\n"));
    2.63 -    return;
    2.64 +    NdisGetNextBuffer(buffer, &next_buffer);
    2.65 +    NdisQueryBufferSafe(buffer, &buff_va, &buff_len, NormalPagePriority);
    2.66 +    NdisFreeMemory(buff_va, 0, 0);
    2.67 +    NdisFreeBuffer(buffer);
    2.68 +    buffer = next_buffer;
    2.69    }
    2.70  
    2.71 -  // todo: check header checksum & fix if wrong
    2.72 -
    2.73 -  proto = buf[9];
    2.74 -
    2.75 -  switch (proto)
    2.76 -  {
    2.77 -  case 6: //tcp
    2.78 -    KdPrint((__DRIVER_NAME "     IP Proto = TCP\n"));
    2.79 -    XenNet_ProcessReceivedTcpPacket(packet, buf + header_len, len - header_len);
    2.80 -    break;
    2.81 -  case 17: //udp
    2.82 -    KdPrint((__DRIVER_NAME "     IP Proto = UDP\n"));
    2.83 -    break;
    2.84 -  default:
    2.85 -    KdPrint((__DRIVER_NAME "     IP Proto = %d\n", proto));
    2.86 -    break;
    2.87 -  }
    2.88 -}
    2.89 +  NdisFreePacket(Packet);
    2.90  
    2.91 -static VOID
    2.92 -XenNet_ProcessReceivedEthernetPacket(PNDIS_PACKET packet, PUCHAR buf, ULONG len)
    2.93 -{
    2.94 -  USHORT ethertype = (buf[12]) << 8 | buf[13];
    2.95 -
    2.96 -  if (len < 14)
    2.97 -  {
    2.98 -    KdPrint((__DRIVER_NAME "     Ethernet packet header too small (%d).\n", len));
    2.99 -    return;
   2.100 -  }
   2.101 -  if (ethertype < 0x600)
   2.102 -    return; // not Ethernet II
   2.103 -  switch (ethertype)
   2.104 -  {
   2.105 -  case 0x0800:
   2.106 -    KdPrint((__DRIVER_NAME "     EtherType = IP\n"));
   2.107 -    XenNet_ProcessReceivedIpPacket(packet, buf + 14, len - 14);
   2.108 -    break;
   2.109 -  case 0x0806:
   2.110 -    KdPrint((__DRIVER_NAME "     EtherType = ARP\n"));
   2.111 -    break;
   2.112 -  case 0x8100:
   2.113 -    KdPrint((__DRIVER_NAME "     EtherType = VLAN\n"));
   2.114 -    break;
   2.115 -  default:
   2.116 -    KdPrint((__DRIVER_NAME "     EtherType = %04x\n", ethertype));
   2.117 -    break;
   2.118 -  }
   2.119 +//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.120  }
   2.121  
   2.122  // Called at DISPATCH_LEVEL
   2.123 @@ -462,8 +406,10 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.124    KIRQL OldIrql;
   2.125    PNDIS_TCP_IP_CHECKSUM_PACKET_INFO csum_info;
   2.126    struct netif_rx_response *rxrsp = NULL;
   2.127 +  int more_frags = 0;
   2.128 +  NDIS_STATUS status;
   2.129 +
   2.130  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.131 -  NDIS_STATUS status;
   2.132  
   2.133    ASSERT(xi->connected);
   2.134  
   2.135 @@ -477,7 +423,7 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.136        rxrsp = RING_GET_RESPONSE(&xi->rx, cons);
   2.137        ASSERT(rxrsp->status > 0);
   2.138  
   2.139 -      if (!(rxrsp->flags & NETRXF_more_data)) // handling the packet's 1st buffer
   2.140 +      if (!more_frags) // handling the packet's 1st buffer
   2.141        {
   2.142          //  KdPrint((__DRIVER_NAME "     Got a packet\n"));
   2.143          NdisAllocatePacket(&status, &packet, xi->packet_pool);
   2.144 @@ -495,17 +441,17 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.145          }
   2.146  */
   2.147        }
   2.148 +
   2.149        buffer = xi->rx_buffers[rxrsp->id];
   2.150        xi->rx_buffers[rxrsp->id] = NULL;
   2.151        NdisAdjustBufferLength(buffer, rxrsp->status);
   2.152 -
   2.153        NdisChainBufferAtBack(packet, buffer);
   2.154  
   2.155        xi->XenInterface.GntTbl_EndAccess(xi->XenInterface.InterfaceHeader.Context,
   2.156          xi->grant_rx_ref[rxrsp->id]);
   2.157        xi->grant_rx_ref[rxrsp->id] = GRANT_INVALID_REF;
   2.158  
   2.159 -#if 1
   2.160 +#if 0
   2.161        KdPrint((__DRIVER_NAME "     Flags = %sNETRXF_data_validated|%sNETRXF_csum_blank|%sNETRXF_more_data|%sNETRXF_extra_info\n",
   2.162          (rxrsp->flags&NETRXF_data_validated)?"":"!",
   2.163          (rxrsp->flags&NETRXF_csum_blank)?"":"!",
   2.164 @@ -514,24 +460,27 @@ XenNet_RxBufferCheck(struct xennet_info 
   2.165  #endif
   2.166        ASSERT(!(rxrsp->flags & NETRXF_extra_info)); // not used on RX
   2.167  
   2.168 -      //XenNet_ProcessReceivedEthernetPacket(packet, buff_va, rxrsp->status);
   2.169 +      more_frags = rxrsp->flags & NETRXF_more_data;
   2.170  
   2.171        /* Packet done, pass it up */
   2.172 -      if (!(rxrsp->flags & NETRXF_more_data))
   2.173 +      if (!more_frags)
   2.174        {
   2.175          xi->stat_rx_ok++;
   2.176          NDIS_SET_PACKET_STATUS(packet, NDIS_STATUS_SUCCESS);
   2.177          NdisMIndicateReceivePacket(xi->adapter_handle, &packet, 1);
   2.178        }
   2.179      }
   2.180 -
   2.181 -    ASSERT(!(rxrsp->flags & NETRXF_more_data));
   2.182 -
   2.183      xi->rx.rsp_cons = prod;
   2.184  
   2.185      RING_FINAL_CHECK_FOR_RESPONSES(&xi->rx, moretodo);
   2.186    } while (moretodo);
   2.187  
   2.188 +  if (more_frags)
   2.189 +  {
   2.190 +    KdPrint((__DRIVER_NAME "     Missing fragments\n"));
   2.191 +    XenNet_ReturnPacket(xi, packet);
   2.192 +  }
   2.193 +
   2.194    KeReleaseSpinLock(&xi->rx_lock, OldIrql);
   2.195  
   2.196    /* Give netback more buffers */
   2.197 @@ -1442,39 +1391,6 @@ XenNet_SetInformation(
   2.198    return status;
   2.199  }
   2.200  
   2.201 -VOID
   2.202 -XenNet_ReturnPacket(
   2.203 -  IN NDIS_HANDLE MiniportAdapterContext,
   2.204 -  IN PNDIS_PACKET Packet
   2.205 -  )
   2.206 -{
   2.207 -  PNDIS_BUFFER buffer;
   2.208 -  PVOID buff_va;
   2.209 -  UINT buff_len;
   2.210 -  UINT tot_buff_len;
   2.211 -
   2.212 -//  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.213 -
   2.214 -  UNREFERENCED_PARAMETER(MiniportAdapterContext);
   2.215 -
   2.216 -  NdisGetFirstBufferFromPacketSafe(Packet, &buffer, &buff_va, &buff_len,
   2.217 -    &tot_buff_len, NormalPagePriority);
   2.218 -  ASSERT(tot_buff_len <= XN_MAX_PKT_SIZE);
   2.219 -
   2.220 -  while (buffer)
   2.221 -  {
   2.222 -    NdisQueryBufferSafe(buffer, &buff_va, &buff_len, NormalPagePriority);
   2.223 -    NdisFreeMemory(buff_va, 0, 0);
   2.224 -    NdisFreeBuffer(buffer);
   2.225 -    NdisGetNextBuffer(buffer, &buffer);
   2.226 -  }
   2.227 -
   2.228 -  NdisFreePacket(Packet);
   2.229 -
   2.230 -  //KdPrint((__FUNCTION__ " called\n"));
   2.231 -//  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.232 -}
   2.233 -
   2.234  PMDL
   2.235  XenNet_Linearize(PNDIS_PACKET Packet)
   2.236  {