Exemple #1
0
static uint8_t
bridge_output(uip_lladdr_t * dest)
{
  int isBroadcast = IS_BROADCAST_ADDR(dest);
  int wsnDest = 0;
  if(!isBroadcast) {
    LOG6LBR_LLADDR_PRINTF(PACKET, PF_OUT, dest, "bridge_output: Sending packet to ");
  } else {
    LOG6LBR_PRINTF(PACKET, PF_OUT, "bridge_output: Sending packet to Broadcast\n");
  }
  if(isBroadcast) {
    //Obviously we can not guess the target segment for a multicast packet
    //So we have to check the packet source prefix (and match it on the Ethernet segment prefix)
    //or, in case of link-local packet, check packet type and/or packet data
    if((UIP_IP_BUF->proto == UIP_PROTO_ICMP6
        && UIP_ICMP_BUF->type == ICMP6_RA)
       || (UIP_IP_BUF->proto == UIP_PROTO_ICMP6
           && UIP_ICMP_BUF->type == ICMP6_NS
           && uip_ipaddr_prefixcmp(&wsn_net_prefix,
                                   &UIP_ND6_NS_BUF->tgtipaddr, 64))
       || uip_ipaddr_prefixcmp(&wsn_net_prefix, &UIP_IP_BUF->srcipaddr, 64)) {
      wsnDest = 1;
    }
  }
  if(wsnDest || IS_EUI64_ADDR(dest)) {
		wireless_output(NULL, dest);
  } else {
	eth_output(NULL, dest);
  }
  return 0;
}
Exemple #2
0
static uint8_t
bridge_output(const uip_lladdr_t * dest)
{
  int isBroadcast = IS_BROADCAST_ADDR(dest);
  if(!isBroadcast) {
    LOG6LBR_LLADDR_PRINTF(PACKET, PF_OUT, dest, "bridge_output: Sending packet to ");
  } else {
    LOG6LBR_PRINTF(PACKET, PF_OUT, "bridge_output: Sending packet to Broadcast\n");
  }
  //Filter WSN vs Ethernet segment traffic
  if(IS_EUI48_ADDR(dest)) {
    eth_output(NULL, dest);
  } else if(IS_EUI64_ADDR(dest)) {
    wireless_output(NULL, dest);
  } else {
    if (UIP_IP_BUF->proto != UIP_PROTO_ICMP6 || UIP_ICMP_BUF->type != ICMP6_NA) {
      wireless_output(NULL, dest);
    }
    eth_output(NULL, dest);
  }
  return 0;
}
static uint8_t
bridge_output(const uip_lladdr_t * dest)
{
	uint8_t isEthOutput = UIP_TRANSMITTED_INTERFACE_TYPE & UIP_ETH_INTERFACE_MASK;
	uint8_t isWirelessOutput = UIP_TRANSMITTED_INTERFACE_TYPE & UIP_LN_INTERFACE_MASK;

	//Filter WSN vs Ethernet segment traffic
	if(isEthOutput) {
		eth_output(NULL, dest);
	}
	if( isWirelessOutput) {
		wireless_output(NULL, dest);
	}
	return 0;
}
Exemple #4
0
static uint8_t
bridge_output(uip_lladdr_t * dest)
{
  int ethernetDest = 0;
  if(uip_len == 0) {
    LOG6LBR_ERROR("Trying to send empty packet\n");
    return 0;
  }
  if(!IS_BROADCAST_ADDR(dest)) {
    LOG6LBR_LLADDR_PRINTF(PACKET, PF_OUT, dest, "bridge_output: Sending packet to ");
  } else {
    LOG6LBR_PRINTF(PACKET, PF_OUT, "bridge_output: Sending packet to Broadcast\n");
  }
  if(IS_BROADCAST_ADDR(dest)) {
    //Obviously we can not guess the target segment for a multicast packet
    //So we have to check the packet source prefix (and match it on the Ethernet segment prefix)
    //or, in case of link-local packet, check packet type and/or packet data
    if((UIP_IP_BUF->proto == UIP_PROTO_ICMP6
        && UIP_ICMP_BUF->type == ICMP6_RA)
       || (UIP_IP_BUF->proto == UIP_PROTO_ICMP6
           && UIP_ICMP_BUF->type == ICMP6_NS
           && uip_ipaddr_prefixcmp(&eth_net_prefix,
                                   &UIP_ND6_NS_BUF->tgtipaddr, 64))
       || uip_ipaddr_prefixcmp(&eth_net_prefix, &UIP_IP_BUF->srcipaddr, 64)) {
      ethernetDest = 1;
    }
  }
  if(ethernetDest || IS_EUI48_ADDR(dest)) {
    eth_output(NULL, dest);
  } else {
#if CETIC_6LBR_ONE_ITF
	eth_output(&wsn_mac_addr, dest);
#else
	wireless_output(NULL, dest);
#endif
  }
  return 0;
}
Exemple #5
0
void
eth_input(void)
{
#if CETIC_6LBR_TRANSPARENTBRIDGE || CETIC_6LBR_ONE_ITF || CETIC_6LBR_6LR
  uip_lladdr_t srcAddr;
#endif
  uip_lladdr_t destAddr;
  int processFrame = 0;
  int forwardFrame = 0;

  //Packet type filtering
  //---------------------
  //Keep only IPv6 traffic
  if(BUF->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) {
    LOG6LBR_PRINTF(PACKET, PF_IN, "eth_input: Dropping packet type=0x%04x\n", uip_ntohs(BUF->type));
    uip_len = 0;
    return;
  }
  //Packet source Filtering
  //-----------------------
  /* IPv6 uses 33-33-xx-xx-xx-xx prefix for multicast ND stuff */
  if((BUF->dest.addr[0] == 0x33) && (BUF->dest.addr[1] == 0x33)) {
    forwardFrame = 1;
    processFrame = 1;
    rimeaddr_copy((rimeaddr_t *) & destAddr, &rimeaddr_null);
  } else if((BUF->dest.addr[0] == 0xFF)
            && (BUF->dest.addr[1] == 0xFF)
            && (BUF->dest.addr[2] == 0xFF)
            && (BUF->dest.addr[3] == 0xFF)
            && (BUF->dest.addr[4] == 0xFF)
            && (BUF->dest.addr[5] == 0xFF)) {
    /* IPv6 does not use broadcast addresses, hence this should not happen */
    LOG6LBR_PRINTF(PACKET, PF_IN, "eth_input: Dropping broadcast packet\n");
    uip_len = 0;
    return;
  } else {
    /* Complex Address Translation */
    if(mac_createSicslowpanLongAddr(&(BUF->dest.addr[0]), &destAddr) == 0) {
      LOG6LBR_WARN("eth_input: Address translation failed\n");
      uip_len = 0;
      return;
    }
  }

  //Packet content rewriting
  //------------------------
  //Some IP packets have link layer in them, need to change them around!
  uint8_t transReturn = mac_translateIPLinkLayer(ll_802154_type);

  if(transReturn != 0) {
    LOG6LBR_WARN("eth_input: IPTranslation returns %d\n", transReturn);
  }

  //Destination filtering
  //---------------------
  if(memcmp((uint8_t *) & eth_mac_addr, BUF->dest.addr, 6) == 0) {
    processFrame = 1;
  } else {
#if CETIC_6LBR_TRANSPARENTBRIDGE
    //Not for us, forward it directly
    forwardFrame = 1;
#endif
  }

  //Handle packet
  //-------------
#if CETIC_6LBR_TRANSPARENTBRIDGE
  if(forwardFrame) {
    mac_createSicslowpanLongAddr(&(BUF->src.addr[0]), &srcAddr);
#if CETIC_6LBR_LEARN_RPL_MAC
    if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type == ICMP6_RPL) {
      uint8_t *buffer = UIP_ICMP_PAYLOAD;
      uint16_t rank = (uint16_t)buffer[2] << 8 | buffer[2 + 1];
      if ( rank == RPL_MIN_HOPRANKINC ) {
    	platform_set_wsn_mac((rimeaddr_t *) &srcAddr);
        rpl_mac_known=1;
      }
    }
    if (!rpl_mac_known) {
      //Rpl Relay not yet configured, drop packet
      uip_len = 0;
      return;
    }
    if(rimeaddr_cmp((rimeaddr_t *) &srcAddr, &rimeaddr_node_addr) != 0) {
      //Only forward RplRoot packets
      LOG6LBR_LLADDR_PRINTF(PACKET, PF_IN, &destAddr, "eth_input: Forwarding frame to ");
      wireless_output(NULL, &destAddr);
    }
#else
    LOG6LBR_LLADDR_PRINTF(PACKET, PF_IN, &destAddr, "eth_input: Forwarding frame to ");
    wireless_output(&srcAddr, &destAddr);
#endif
  }
#endif
  if(processFrame) {
    LOG6LBR_PRINTF(PACKET, PF_IN, "eth_input: Processing frame\n");
#if CETIC_6LBR_ONE_ITF || CETIC_6LBR_6LR
  //RPL uses source packet address to populate its neighbor table
  //In this two modes RPL packets are incoming from Eth interface
  mac_createSicslowpanLongAddr(&(BUF->src.addr[0]), &srcAddr);
  packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (rimeaddr_t *) &srcAddr);
#endif
    send_to_uip();
  } else {
    //Drop packet
    uip_len = 0;
  }
}
Exemple #6
0
static uint8_t
bridge_output(const uip_lladdr_t * dest)
{
  int ethernetDest = 0;
  int wsnDest = 0;
  if(uip_len == 0) {
    LOG6LBR_ERROR("Trying to send empty packet\n");
    return 0;
  }
  if(!IS_BROADCAST_ADDR(dest)) {
    LOG6LBR_LLADDR_PRINTF(PACKET, PF_OUT, dest, "bridge_output: Sending packet to ");
  } else {
    LOG6LBR_PRINTF(PACKET, PF_OUT, "bridge_output: Sending packet to Broadcast\n");
  }

  if(uip_ipaddr_prefixcmp(&eth_net_prefix, &UIP_IP_BUF->destipaddr, 64)) {
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &eth_net_prefix, "dest prefix eth : ");
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &UIP_IP_BUF->destipaddr, "dest eth : ");
    //Packet destinated to the Ethernet subnet
    ethernetDest = 1;
  } else if(uip_ipaddr_prefixcmp(&wsn_net_prefix, &UIP_IP_BUF->destipaddr, 64)) {
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &wsn_net_prefix, "dest prefix wsn : ");
    LOG6LBR_6ADDR_PRINTF(PACKET, PF_OUT, &UIP_IP_BUF->destipaddr, "dest prefix wsn : ");
    //Packet destinated to the WSN subnet
    wsnDest = 1;
  } else if(IS_EUI64_ADDR(dest)) {
    //Destination unknown but next-hop is in WSN subnet
    wsnDest = 1;
  } else if (IS_EUI48_ADDR(dest)) {
    //Destination unknown but next-hop is in Ethernet subnet
    ethernetDest = 1;
  } else {
    //Obviously we can not guess the target segment for a multicast packet
    //So we have to check the packet source prefix (and match it on the Ethernet segment prefix)
    //or, in case of link-local packet, check packet type and/or packet data
#if UIP_CONF_IPV6_RPL
    //in RPL mode, RA and RS packets are used to configure the Ethernet subnet
    if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 &&
        (UIP_ICMP_BUF->type == ICMP6_RA || UIP_ICMP_BUF->type == ICMP6_RS)) {
      ethernetDest = 1;
    } else if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6
        && UIP_ICMP_BUF->type == ICMP6_NS
        && uip_ipaddr_prefixcmp(&eth_net_prefix,
                                &UIP_ND6_NS_BUF->tgtipaddr, 64)) {
      ethernetDest = 1;
#else
    //in NDP mode, RA and RS packets are used to configure the WSN subnet
    if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 &&
        (UIP_ICMP_BUF->type == ICMP6_RA || UIP_ICMP_BUF->type == ICMP6_RS)) {
      wsnDest = 1;
    } else if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6
        && UIP_ICMP_BUF->type == ICMP6_NS
        && uip_ipaddr_prefixcmp(&wsn_net_prefix,
                                &UIP_ND6_NS_BUF->tgtipaddr, 64)) {
      wsnDest = 1;
#endif
    } else if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 &&
        UIP_ICMP_BUF->type == ICMP6_RPL) {
      //RPL packets are always for WSN subnet
      wsnDest = 1;
    } else if(uip_ipaddr_prefixcmp(&eth_net_prefix, &UIP_IP_BUF->srcipaddr, 64)) {
      //Packet type unknown, but source is from Ethernet subnet
      ethernetDest = 1;
    } else if(uip_ipaddr_prefixcmp(&wsn_net_prefix, &UIP_IP_BUF->srcipaddr, 64)) {
      //Packet type unknown, but source is from WSN subnet
      wsnDest = 1;
    } else {
      // We could not guess the destination, forward to both
      ethernetDest = 1;
      wsnDest = 1;
    }
  }
  if(wsnDest) {
#if CETIC_6LBR_ONE_ITF
    eth_output(&wsn_mac_addr, dest);
#else
    wireless_output(NULL, dest);
#endif
  }
  if(ethernetDest) {
    eth_output(NULL, dest);
  }
  return 0;
}
#endif

/*---------------------------------------------------------------------------*/

void
packet_filter_init(void)
{
  wireless_outputfunc = tcpip_get_outputfunc();
  tcpip_set_outputfunc(bridge_output);

  tcpip_inputfunc = tcpip_get_inputfunc();

  tcpip_set_inputfunc(wireless_input);
}