---
title: llarp/vpn/egres_packet_router.hpp

---

# llarp/vpn/egres_packet_router.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::vpn](Namespaces/namespacellarp_1_1vpn.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::vpn::EgresLayer4Handler](Classes/structllarp_1_1vpn_1_1EgresLayer4Handler.md)**  |
| class | **[llarp::vpn::EgresPacketRouter](Classes/classllarp_1_1vpn_1_1EgresPacketRouter.md)**  |




## Source code

```cpp
#pragma once
#include <llarp/net/net_int.hpp>
#include <llarp/net/ip_packet.hpp>
#include <llarp/endpoint_base.hpp>
#include <functional>
#include <unordered_map>

namespace llarp::vpn
{
  using AddressVariant_t = llarp::EndpointBase::AddressVariant_t;
  using EgresPacketHandlerFunc = std::function<void(AddressVariant_t, net::IPPacket)>;

  struct EgresLayer4Handler
  {
    virtual ~EgresLayer4Handler() = default;

    virtual void
    HandleIPPacketFrom(AddressVariant_t from, net::IPPacket pkt) = 0;

    virtual void AddSubHandler(nuint16_t, EgresPacketHandlerFunc){};
    virtual void RemoveSubHandler(nuint16_t){};
  };

  class EgresPacketRouter
  {
    EgresPacketHandlerFunc m_BaseHandler;
    std::unordered_map<uint8_t, std::unique_ptr<EgresLayer4Handler>> m_IPProtoHandler;

   public:
    explicit EgresPacketRouter(EgresPacketHandlerFunc baseHandler);

    void
    HandleIPPacketFrom(AddressVariant_t, net::IPPacket pkt);

    void
    AddIProtoHandler(uint8_t proto, EgresPacketHandlerFunc func);

    void
    AddUDPHandler(huint16_t localport, EgresPacketHandlerFunc func);

    void
    RemoveUDPHandler(huint16_t localport);
  };
}  // namespace llarp::vpn
```


-------------------------------

Updated on 2022-11-04 at 14:36:39 +0000
