// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 #ifndef GWLBTUN_GENEVEHANDLER_H #define GWLBTUN_GENEVEHANDLER_H #include #include #include #include #include #include "UDPPacketReceiver.h" #include "TunInterface.h" #include "GenevePacket.h" #include "PacketHeaderV4.h" #include "PacketHeaderV6.h" #include "utils.h" typedef std::function ghCallback; // Data we need to send with the packet back to GWLB, including the Geneve header and outer UDP header information. class GwlbData { public: GwlbData(GenevePacket &gp, struct in_addr *srcAddr, uint16_t srcPort, struct in_addr *dstAddr, uint16_t dstPort); struct in_addr srcAddr; uint16_t srcPort; struct in_addr dstAddr; uint16_t dstPort; GenevePacket gp; int seenCount; time_t lastSeen; }; class GeneveHandler { public: GeneveHandler(ghCallback createCallback, ghCallback destroyCallback, int destroyTimeout, ThreadConfig udpThreads, ThreadConfig tunThreads); ~GeneveHandler(); std::string check(); bool healthy; // Updated by check() private: void udpReceiverCallback(unsigned char *pktbuf, ssize_t pktlen, struct in_addr *srcAddr, uint16_t srcPort, struct in_addr *dstAddr, uint16_t dstPort); void tunReceiverCallback(uint64_t, unsigned char *pktbuf, ssize_t pktlen); // Storage, keyed by ENI id. std::shared_mutex eniIdLock; // Used to access elements of the 3 unordered maps below. std::unordered_map> tunnelIn; #ifndef NO_RETURN_TRAFFIC // Socket used by all threads for sending int sendingSock; std::unordered_map> tunnelOut; std::unordered_map> gwlbV4CookiesMutex; // These mutexes protect the gwlbV4Cookies below. std::unordered_map> gwlbV4Cookies; std::unordered_map> gwlbV6CookiesMutex; // These mutexes protect the gwlbV4Cookies below. std::unordered_map> gwlbV6Cookies; #endif std::vector tunints; UDPPacketReceiver udpRcvr; ghCallback createCallback; ghCallback destroyCallback; int destroyTimeout; ThreadConfig tunThreadConfig; }; #endif //GWLBTUN_GENEVEHANDLER_H