2018-05-28 16:28:51 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/retroshare: rsbanlist.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2011-2011 by Robert Fernie <retroshare@lunamutt.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2015-05-26 17:17:09 -04:00
|
|
|
#pragma once
|
|
|
|
|
2015-05-27 07:53:08 -04:00
|
|
|
#include "util/rsnet.h"
|
2015-05-26 17:17:09 -04:00
|
|
|
|
|
|
|
class RsBanList;
|
|
|
|
extern RsBanList *rsBanList ;
|
|
|
|
|
2015-05-27 17:30:40 -04:00
|
|
|
#define RSBANLIST_ORIGIN_UNKNOWN 0
|
|
|
|
#define RSBANLIST_ORIGIN_SELF 1
|
|
|
|
#define RSBANLIST_ORIGIN_FRIEND 2
|
|
|
|
#define RSBANLIST_ORIGIN_FOF 3
|
|
|
|
|
|
|
|
#define RSBANLIST_REASON_UNKNOWN 0
|
|
|
|
#define RSBANLIST_REASON_USER 1
|
|
|
|
#define RSBANLIST_REASON_DHT 2
|
2015-05-28 17:44:43 -04:00
|
|
|
#define RSBANLIST_REASON_AUTO_RANGE 3
|
2015-05-27 17:30:40 -04:00
|
|
|
|
2015-05-30 05:29:43 -04:00
|
|
|
// These are flags. Can be combined.
|
|
|
|
|
|
|
|
#define RSBANLIST_CHECKING_FLAGS_NONE 0x00
|
|
|
|
#define RSBANLIST_CHECKING_FLAGS_BLACKLIST 0x01
|
|
|
|
#define RSBANLIST_CHECKING_FLAGS_WHITELIST 0x02
|
|
|
|
|
|
|
|
// These are not flags. Cannot be combined. Used to give the reson for acceptance/denial of connections.
|
|
|
|
|
|
|
|
#define RSBANLIST_CHECK_RESULT_UNKNOWN 0x00
|
|
|
|
#define RSBANLIST_CHECK_RESULT_NOCHECK 0x01
|
|
|
|
#define RSBANLIST_CHECK_RESULT_BLACKLISTED 0x02
|
|
|
|
#define RSBANLIST_CHECK_RESULT_NOT_WHITELISTED 0x03
|
|
|
|
#define RSBANLIST_CHECK_RESULT_ACCEPTED 0x04
|
|
|
|
|
2015-05-30 16:29:06 -04:00
|
|
|
#define RSBANLIST_TYPE_PEERLIST 1
|
|
|
|
#define RSBANLIST_TYPE_BLACKLIST 2
|
|
|
|
#define RSBANLIST_TYPE_WHITELIST 3
|
|
|
|
|
2015-05-29 16:49:37 -04:00
|
|
|
class RsTlvBanListEntry ;
|
|
|
|
|
2015-05-26 17:17:09 -04:00
|
|
|
class BanListPeer
|
|
|
|
{
|
|
|
|
public:
|
2015-05-28 17:44:43 -04:00
|
|
|
BanListPeer() ;
|
|
|
|
|
2015-05-29 16:49:37 -04:00
|
|
|
void toRsTlvBanListEntry(RsTlvBanListEntry& e) const ;
|
|
|
|
void fromRsTlvBanListEntry(const RsTlvBanListEntry& e) ;
|
2015-05-28 17:44:43 -04:00
|
|
|
|
2015-05-26 17:17:09 -04:00
|
|
|
struct sockaddr_storage addr;
|
2015-05-27 17:30:40 -04:00
|
|
|
uint8_t masked_bytes ; // 0 = []/32. 1=[]/24, 2=[]/16
|
|
|
|
uint32_t reason; // User, DHT
|
|
|
|
uint32_t level; // LOCAL, FRIEND, FoF.
|
2015-05-26 17:17:09 -04:00
|
|
|
bool state ; // true=>active, false=>just stored but inactive
|
2015-05-27 17:30:40 -04:00
|
|
|
int connect_attempts ; // recorded by the BanList service
|
|
|
|
time_t mTs;
|
|
|
|
std::string comment ; //
|
2015-05-26 17:17:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class RsBanList
|
|
|
|
{
|
2015-05-27 17:30:40 -04:00
|
|
|
public:
|
|
|
|
virtual void enableIPFiltering(bool b) =0;
|
|
|
|
virtual bool ipFilteringEnabled() =0;
|
|
|
|
|
2015-05-30 09:57:10 -04:00
|
|
|
// addIpRange()/removeIpRange()
|
|
|
|
// addr: full IPv4 address. Port is ignored.
|
|
|
|
// masked_bytes: 0=full IP, 1="/24", 2="/16"
|
2015-05-30 16:29:06 -04:00
|
|
|
// list_type: RSBANLIST_TYPE_WHITELIST or RSBANLIST_TYPE_BLACKLIST
|
2015-05-30 09:57:10 -04:00
|
|
|
// comment: anything, user-based.
|
|
|
|
|
2015-06-03 11:14:26 -04:00
|
|
|
virtual bool addIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type,const std::string& comment) =0;
|
|
|
|
virtual bool removeIpRange(const struct sockaddr_storage& addr,int masked_bytes,uint32_t list_type) =0;
|
2015-05-30 09:57:10 -04:00
|
|
|
|
|
|
|
// isAddressAccepted()
|
|
|
|
// addr: full IPv4 address. Port is ignored.
|
|
|
|
// checking flags: any combination of RSBANLIST_CHECKING_FLAGS_BLACKLIST and RSBANLIST_CHECKING_FLAGS_WHITELIST
|
|
|
|
// check_result: returned result of the check in RSBANLIST_CHECK_RESULT_*
|
|
|
|
// returned value: true=address is accepted, false=address is rejected.
|
2015-05-29 14:03:14 -04:00
|
|
|
|
2015-05-31 15:52:51 -04:00
|
|
|
virtual bool isAddressAccepted(const struct sockaddr_storage& addr,uint32_t checking_flags,uint32_t *check_result=NULL) =0;
|
2015-05-30 09:57:10 -04:00
|
|
|
|
|
|
|
virtual void getBannedIps(std::list<BanListPeer>& list) =0;
|
|
|
|
virtual void getWhiteListedIps(std::list<BanListPeer>& list) =0;
|
2015-05-28 17:44:43 -04:00
|
|
|
|
|
|
|
virtual bool autoRangeEnabled() =0;
|
|
|
|
virtual void enableAutoRange(bool b) =0 ;
|
|
|
|
|
|
|
|
virtual int autoRangeLimit() =0;
|
|
|
|
virtual void setAutoRangeLimit(int n)=0;
|
|
|
|
|
|
|
|
virtual void enableIPsFromFriends(bool b) =0;
|
|
|
|
virtual bool IPsFromFriendsEnabled() =0;
|
|
|
|
|
|
|
|
virtual void enableIPsFromDHT(bool b) =0;
|
|
|
|
virtual bool iPsFromDHTEnabled() =0;
|
|
|
|
|
2015-05-26 17:17:09 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|