lokinet/llarp/net/traffic_policy.hpp

72 lines
1.6 KiB
C++
Raw Normal View History

2021-04-14 15:07:06 +00:00
#pragma once
2023-10-19 21:59:57 +00:00
#include <oxenc/bt.h>
#include <set>
2021-04-14 15:07:06 +00:00
#include "ip_range.hpp"
#include "ip_packet.hpp"
#include "llarp/util/status.hpp"
namespace llarp::net
{
/// information about an IP protocol
struct ProtocolInfo
{
/// ip protocol byte of this protocol
IPProtocol protocol;
/// the layer 3 port if applicable
std::optional<nuint16_t> port;
2023-10-03 20:00:23 +00:00
ProtocolInfo(std::string buf);
void
bt_encode(oxenc::bt_list_producer& btlp) const;
2021-04-14 15:07:06 +00:00
bool
BDecode(llarp_buffer_t* buf);
util::StatusObject
ExtractStatus() const;
/// returns true if an ip packet looks like it matches this protocol info
/// returns false otherwise
bool
MatchesPacket(const IPPacket& pkt) const;
bool
operator<(const ProtocolInfo& other) const
{
return std::tie(protocol, port) < std::tie(other.protocol, other.port);
2021-04-14 15:07:06 +00:00
}
ProtocolInfo() = default;
explicit ProtocolInfo(std::string_view spec);
};
/// information about what traffic an endpoint will carry
struct TrafficPolicy
{
/// ranges that are explicitly allowed
std::set<IPRange> ranges;
/// protocols that are explicity allowed
std::set<ProtocolInfo> protocols;
void
bt_encode(oxenc::bt_dict_producer& btdp) const;
2023-10-03 20:00:23 +00:00
void
bt_decode(oxenc::bt_dict_consumer& btdc);
2021-04-14 15:07:06 +00:00
bool
BDecode(llarp_buffer_t* buf);
util::StatusObject
ExtractStatus() const;
/// returns true if we allow the traffic in this ip packet
/// returns false otherwise
bool
AllowsTraffic(const IPPacket& pkt) const;
};
} // namespace llarp::net