Browse Source

net/gnrc/eth: enable filtering of L2 addresses

master
Hauke Petersen 6 years ago
parent
commit
31dfe382a3
  1. 3
      cpu/native/netdev_tap/netdev_tap.c
  2. 23
      drivers/netdev_eth/netdev_eth.c
  3. 7
      sys/net/gnrc/link_layer/netdev/gnrc_netdev_eth.c

3
cpu/native/netdev_tap/netdev_tap.c

@ -144,7 +144,8 @@ static int _set(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
_set_promiscous(dev, ((bool *)value)[0]);
break;
default:
return -ENOTSUP;
res = netdev_eth_set(dev, opt, value, value_len);
break;
}
return res;

23
drivers/netdev_eth/netdev_eth.c

@ -87,6 +87,15 @@ int netdev_eth_get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
res = sizeof(uintptr_t);
break;
}
#endif
#ifdef MODULE_L2FILTER
case NETOPT_L2FILTER:
{
assert(max_len >= sizeof(l2filter_t **));
*((l2filter_t **)value) = dev->filter;
res = sizeof(l2filter_t **);
break;
}
#endif
default:
{
@ -100,15 +109,27 @@ int netdev_eth_get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
int netdev_eth_set(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
{
#ifndef MODULE_L2FILTER
(void)dev;
#endif
(void)value;
(void)value_len;
int res = 0;
switch (opt) {
#ifdef MODULE_L2FILTER
case NETOPT_L2FILTER:
res = l2filter_add(dev->filter, value, value_len);
break;
case NETOPT_L2FILTER_RM:
res = l2filter_rm(dev->filter, value, value_len);
break;
#endif
default:
return -ENOTSUP;
res = -ENOTSUP;
break;
}
return res;

7
sys/net/gnrc/link_layer/netdev/gnrc_netdev_eth.c

@ -72,6 +72,13 @@ static gnrc_pktsnip_t *_recv(gnrc_netdev_t *gnrc_netdev)
ethernet_hdr_t *hdr = (ethernet_hdr_t *)eth_hdr->data;
#ifdef MODULE_L2FILTER
if (!l2filter_pass(dev->filter, hdr->src, ETHERNET_ADDR_LEN)) {
DEBUG("gnrc_netdev_eth: incoming packet filtered by l2filter\n");
goto safe_out;
}
#endif
/* set payload type from ethertype */
pkt->type = gnrc_nettype_from_ethertype(byteorder_ntohs(hdr->type));

Loading…
Cancel
Save