win-pvdrivers

changeset 774:a3f0201d7fa0

Updates to packet filter code. Resolves NDISTest errors.
author James Harper <james.harper@bendigoit.com.au>
date Mon Feb 01 21:43:12 2010 +1100 (2010-02-01)
parents aa428237f288
children 31c56358c9fc
files xennet/xennet.c xennet/xennet_oid.c xennet/xennet_rx.c
line diff
     1.1 --- a/xennet/xennet.c	Mon Feb 01 19:31:47 2010 +1100
     1.2 +++ b/xennet/xennet.c	Mon Feb 01 21:43:12 2010 +1100
     1.3 @@ -475,7 +475,7 @@ XenNet_Init(
     1.4  
     1.5    NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
     1.6      &xi->lower_do, NULL, NULL);
     1.7 -  xi->packet_filter = NDIS_PACKET_TYPE_PROMISCUOUS;
     1.8 +  xi->packet_filter = 0;
     1.9  
    1.10    status = IoGetDeviceProperty(xi->pdo, DevicePropertyDeviceDescription,
    1.11      NAME_SIZE, xi->dev_desc, &length);
     2.1 --- a/xennet/xennet_oid.c	Mon Feb 01 19:31:47 2010 +1100
     2.2 +++ b/xennet/xennet_oid.c	Mon Feb 01 21:43:12 2010 +1100
     2.3 @@ -227,7 +227,7 @@ XenNet_QueryInformation(
     2.4        len = xi->multicast_list_size * 6;
     2.5        break;
     2.6      case OID_802_3_MAXIMUM_LIST_SIZE:
     2.7 -      temp_data = MULTICAST_LIST_MAX_SIZE; /* no mcast support, but to return 0 is an error */
     2.8 +      temp_data = MULTICAST_LIST_MAX_SIZE;
     2.9        break;
    2.10      case OID_TCP_TASK_OFFLOAD:
    2.11        KdPrint(("Get OID_TCP_TASK_OFFLOAD\n"));
    2.12 @@ -599,8 +599,7 @@ XenNet_SetInformation(
    2.13              (ULONG)multicast_list[i * 6 + 0], (ULONG)multicast_list[i * 6 + 1], 
    2.14              (ULONG)multicast_list[i * 6 + 2], (ULONG)multicast_list[i * 6 + 3], 
    2.15              (ULONG)multicast_list[i * 6 + 4], (ULONG)multicast_list[i * 6 + 5]));
    2.16 -          status = NDIS_STATUS_MULTICAST_FULL;
    2.17 -          break;
    2.18 +          /* the docs say that we should return NDIS_STATUS_MULTICAST_FULL if we get an invalid multicast address but I'm not sure if that's the case... */
    2.19          }
    2.20        }
    2.21        memcpy(xi->multicast_list, InformationBuffer, InformationBufferLength);
     3.1 --- a/xennet/xennet_rx.c	Mon Feb 01 19:31:47 2010 +1100
     3.2 +++ b/xennet/xennet_rx.c	Mon Feb 01 21:43:12 2010 +1100
     3.3 @@ -449,30 +449,74 @@ XenNet_MakePackets(
     3.4    packet_info_t *pi = &xi->rxpi;
     3.5    PNDIS_BUFFER buffer;
     3.6    shared_buffer_t *page_buf;
     3.7 +  BOOLEAN accept_packet = FALSE;
     3.8 +  BOOLEAN is_multicast = FALSE;
     3.9 +  BOOLEAN is_my_multicast = FALSE;
    3.10 +  BOOLEAN is_broadcast = FALSE;
    3.11 +  BOOLEAN is_directed = FALSE;
    3.12  
    3.13    //FUNCTION_ENTER();
    3.14  
    3.15    parse_result = XenNet_ParsePacketHeader(pi, NULL, 0);
    3.16    
    3.17    //KdPrint((__DRIVER_NAME "     ip4_length = %d, tcp_length = %d\n", pi->ip4_length, pi->tcp_length));
    3.18 -
    3.19 -  if ((xi->packet_filter & NDIS_PACKET_TYPE_MULTICAST)
    3.20 -    && !(xi->packet_filter & NDIS_PACKET_TYPE_ALL_MULTICAST)
    3.21 -    && (pi->header[0] & 0x01)
    3.22 -    && !(pi->header[0] == 0xFF && pi->header[1] == 0xFF && pi->header[2] == 0xFF
    3.23 -        && pi->header[3] == 0xFF && pi->header[4] == 0xFF && pi->header[5] == 0xFF))
    3.24 +  
    3.25 +  if (pi->header[0] == 0xFF && pi->header[1] == 0xFF
    3.26 +      && pi->header[2] == 0xFF && pi->header[3] == 0xFF
    3.27 +      && pi->header[4] == 0xFF && pi->header[5] == 0xFF)
    3.28    {
    3.29 +    is_broadcast = TRUE;
    3.30 +  }
    3.31 +  else if (pi->header[0] & 0x01)
    3.32 +  {
    3.33 +    is_multicast = TRUE;
    3.34      for (i = 0; i < xi->multicast_list_size; i++)
    3.35      {
    3.36        if (memcmp(xi->multicast_list[i], pi->header, 6) == 0)
    3.37          break;
    3.38      }
    3.39 -    if (i == xi->multicast_list_size)
    3.40 +    if (i < xi->multicast_list_size)
    3.41      {
    3.42 -      //KdPrint((__DRIVER_NAME "     Packet not for my MAC address\n"));
    3.43 -      goto done;
    3.44 -    }
    3.45 +      is_my_multicast = TRUE;
    3.46 +    }    
    3.47    }
    3.48 +  if (memcmp(xi->curr_mac_addr, pi->header, ETH_ALEN) == 0)
    3.49 +  {
    3.50 +    is_directed = TRUE;
    3.51 +  }
    3.52 +
    3.53 +  if (!accept_packet && (xi->packet_filter & NDIS_PACKET_TYPE_PROMISCUOUS))
    3.54 +  {
    3.55 +    //KdPrint((__DRIVER_NAME "     Accepting packet because NDIS_PACKET_TYPE_PROMISCUOUS\n"));
    3.56 +    accept_packet = TRUE;
    3.57 +  }
    3.58 +  if (!accept_packet && is_broadcast && (xi->packet_filter & NDIS_PACKET_TYPE_BROADCAST))
    3.59 +  {
    3.60 +    //KdPrint((__DRIVER_NAME "     Accepting packet because NDIS_PACKET_TYPE_BROADCAST\n"));
    3.61 +    accept_packet = TRUE;
    3.62 +  }
    3.63 +  if (!accept_packet && is_multicast && (xi->packet_filter & NDIS_PACKET_TYPE_ALL_MULTICAST))
    3.64 +  {
    3.65 +    //KdPrint((__DRIVER_NAME "     Accepting packet because NDIS_PACKET_TYPE_ALL_MULTICAST\n"));
    3.66 +    accept_packet = TRUE;
    3.67 +  }
    3.68 +  if (!accept_packet && is_my_multicast && (xi->packet_filter & NDIS_PACKET_TYPE_MULTICAST))
    3.69 +  {
    3.70 +    //KdPrint((__DRIVER_NAME "     Accepting packet because NDIS_PACKET_TYPE_MULTICAST\n"));
    3.71 +    accept_packet = TRUE;
    3.72 +  }
    3.73 +  if (!accept_packet && is_directed && (xi->packet_filter & NDIS_PACKET_TYPE_DIRECTED))
    3.74 +  {
    3.75 +    //KdPrint((__DRIVER_NAME "     Accepting packet because NDIS_PACKET_TYPE_DIRECTED\n"));
    3.76 +    accept_packet = TRUE;
    3.77 +  }
    3.78 +
    3.79 +  if (!accept_packet)
    3.80 +  {
    3.81 +    //KdPrint((__DRIVER_NAME "     Not accepting packet\n"));
    3.82 +    goto done;
    3.83 +  }
    3.84 +
    3.85    switch (pi->ip_proto)
    3.86    {
    3.87    case 6:  // TCP