
10 changed files with 283 additions and 0 deletions
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de> |
||||
* Copyright (C) 2016 Martin Landsmann <martin.landsmann@haw-hamburg.de> |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @defgroup net_gnrc_ipv6_blacklist IPv6 address blacklist |
||||
* @ingroup net_gnrc_ipv6 |
||||
* @brief This refuses IPv6 addresses that are defined in this list. |
||||
* @{ |
||||
* |
||||
* @file |
||||
* @brief IPv6 blacklist definitions |
||||
* |
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> |
||||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de> |
||||
*/ |
||||
#ifndef GNRC_IPV6_BLACKLIST_H_ |
||||
#define GNRC_IPV6_BLACKLIST_H_ |
||||
|
||||
#include <stdbool.h> |
||||
|
||||
#include "net/ipv6/addr.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* Maximum size of the blacklist. |
||||
*/ |
||||
#ifndef GNRC_IPV6_BLACKLIST_SIZE |
||||
#define GNRC_IPV6_BLACKLIST_SIZE (8) |
||||
#endif |
||||
|
||||
/**
|
||||
* @brief Adds an IPv6 address to the blacklist. |
||||
* |
||||
* @param[in] addr An IPv6 address. |
||||
* |
||||
* @return 0, on success. |
||||
* @return -1, if blacklist is full. |
||||
*/ |
||||
int gnrc_ipv6_blacklist_add(const ipv6_addr_t *addr); |
||||
|
||||
/**
|
||||
* @brief Removes an IPv6 address from the blacklist. |
||||
* |
||||
* Addresses not in the blacklist will be ignored. |
||||
* |
||||
* @param[in] addr An IPv6 address. |
||||
*/ |
||||
void gnrc_ipv6_blacklist_del(const ipv6_addr_t *addr); |
||||
|
||||
/**
|
||||
* @brief Checks if an IPv6 address is blacklisted. |
||||
* |
||||
* @param[in] addr An IPv6 address. |
||||
* |
||||
* @return true, if @p addr is blacklisted. |
||||
* @return false, if @p addr is not blacklisted. |
||||
*/ |
||||
bool gnrc_ipv6_blacklisted(const ipv6_addr_t *addr); |
||||
|
||||
/**
|
||||
* @brief Prints the blacklist. |
||||
*/ |
||||
void gnrc_ipv6_blacklist_print(void); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GNRC_IPV6_BLACKLIST_H_ */ |
||||
/** @} */ |
@ -0,0 +1,3 @@
|
||||
MODULE = gnrc_ipv6_blacklist
|
||||
|
||||
include $(RIOTBASE)/Makefile.base |
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) Freie Universität Berlin |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @{ |
||||
* |
||||
* @file |
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> |
||||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de> |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
#include "bitfield.h" |
||||
|
||||
#include "net/gnrc/ipv6/blacklist.h" |
||||
|
||||
#define ENABLE_DEBUG (0) |
||||
#include "debug.h" |
||||
|
||||
ipv6_addr_t gnrc_ipv6_blacklist[GNRC_IPV6_BLACKLIST_SIZE]; |
||||
BITFIELD(gnrc_ipv6_blacklist_set, GNRC_IPV6_BLACKLIST_SIZE); |
||||
|
||||
#if ENABLE_DEBUG |
||||
static char addr_str[IPV6_ADDR_MAX_STR_LEN]; |
||||
#endif |
||||
|
||||
int gnrc_ipv6_blacklist_add(const ipv6_addr_t *addr) |
||||
{ |
||||
for (int i = 0; i < GNRC_IPV6_BLACKLIST_SIZE; i++) { |
||||
if (!bf_isset(gnrc_ipv6_blacklist_set, i)) { |
||||
bf_set(gnrc_ipv6_blacklist_set, i); |
||||
memcpy(&gnrc_ipv6_blacklist[i], addr, sizeof(*addr)); |
||||
DEBUG("IPv6 blacklist: blacklisted %s\n", |
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str))); |
||||
return 0; |
||||
} |
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
void gnrc_ipv6_blacklist_del(const ipv6_addr_t *addr) |
||||
{ |
||||
for (int i = 0; i < GNRC_IPV6_BLACKLIST_SIZE; i++) { |
||||
if (ipv6_addr_equal(addr, &gnrc_ipv6_blacklist[i])) { |
||||
bf_unset(gnrc_ipv6_blacklist_set, i); |
||||
DEBUG("IPv6 blacklist: unblacklisted %s\n", |
||||
ipv6_addr_to_str(addr_str, addr, sizeof(addr_str))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool gnrc_ipv6_blacklisted(const ipv6_addr_t *addr) |
||||
{ |
||||
for (int i = 0; i < GNRC_IPV6_BLACKLIST_SIZE; i++) { |
||||
if (bf_isset(gnrc_ipv6_blacklist_set, i) && |
||||
ipv6_addr_equal(addr, &gnrc_ipv6_blacklist[i])) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** @} */ |
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) Freie Universität Berlin |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @{ |
||||
* |
||||
* @file |
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> |
||||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de> |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include "bitfield.h" |
||||
#include "net/ipv6/addr.h" |
||||
|
||||
#include "net/gnrc/ipv6/blacklist.h" |
||||
|
||||
extern ipv6_addr_t gnrc_ipv6_blacklist[GNRC_IPV6_BLACKLIST_SIZE]; |
||||
extern BITFIELD(gnrc_ipv6_blacklist_set, GNRC_IPV6_BLACKLIST_SIZE); |
||||
|
||||
void gnrc_ipv6_blacklist_print(void) |
||||
{ |
||||
char addr_str[IPV6_ADDR_MAX_STR_LEN]; |
||||
for (int i = 0; i < GNRC_IPV6_BLACKLIST_SIZE; i++) { |
||||
if (bf_isset(gnrc_ipv6_blacklist_set, i)) { |
||||
puts(ipv6_addr_to_str(addr_str, &gnrc_ipv6_blacklist[i], sizeof(addr_str))); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** @} */ |
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) Freie Universität Berlin |
||||
* |
||||
* This file is subject to the terms and conditions of the GNU Lesser |
||||
* General Public License v2.1. See the file LICENSE in the top level |
||||
* directory for more details. |
||||
*/ |
||||
|
||||
/**
|
||||
* @{ |
||||
* |
||||
* @file |
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de> |
||||
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de> |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include "net/gnrc/ipv6/blacklist.h" |
||||
|
||||
static void _usage(char *cmd) |
||||
{ |
||||
printf("usage: * %s\n", cmd); |
||||
puts(" Lists all addresses in the blacklist."); |
||||
printf(" * %s add <addr>\n", cmd); |
||||
puts(" Adds <addr> to the blacklist."); |
||||
printf(" * %s del <addr>\n", cmd); |
||||
puts(" Deletes <addr> from the blacklist."); |
||||
printf(" * %s help\n", cmd); |
||||
puts(" Print this."); |
||||
} |
||||
|
||||
int _blacklist(int argc, char **argv) |
||||
{ |
||||
ipv6_addr_t addr; |
||||
if (argc < 2) { |
||||
gnrc_ipv6_blacklist_print(); |
||||
return 0; |
||||
} |
||||
else if (argc > 2) { |
||||
if (ipv6_addr_from_str(&addr, argv[2]) == NULL) { |
||||
_usage(argv[0]); |
||||
return 1; |
||||
} |
||||
} |
||||
if (strcmp("add", argv[1]) == 0) { |
||||
gnrc_ipv6_blacklist_add(&addr); |
||||
} |
||||
else if (strcmp("del", argv[1]) == 0) { |
||||
gnrc_ipv6_blacklist_del(&addr); |
||||
} |
||||
else if (strcmp("help", argv[1]) == 0) { |
||||
_usage(argv[0]); |
||||
} |
||||
else { |
||||
_usage(argv[0]); |
||||
return 1; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
/** @} */ |
Loading…
Reference in new issue