Line data Source code
1 : /* 2 : * * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved. 3 : * * Copyright Contributors to the OpenSDN project 4 : * */ 5 : #ifndef vnsw_agent_diag_diag_pkt_handler_hpp 6 : #define vnsw_agent_diag_diag_pkt_handler_hpp 7 : 8 : #include <boost/date_time/posix_time/posix_time.hpp> 9 : #include <base/logging.h> 10 : #include <base/address.h> 11 : #include <base/timer.h> 12 : 13 : #include <cmn/agent_cmn.h> 14 : #include <cmn/agent.h> 15 : 16 : struct AgentDiagPktData; 17 : struct OverlayOamPktData; 18 : struct PktInfo; 19 : 20 : // Pseudo header for TCP checksum 21 : struct PseudoTcpHdr { 22 : in_addr_t src; 23 : in_addr_t dest; 24 : uint8_t res; 25 : uint8_t prot; 26 : uint16_t len; 27 0 : PseudoTcpHdr(in_addr_t s, in_addr_t d, uint16_t l) : 28 0 : src(s), dest(d), res(0), prot(6), len(l) { } 29 : }; 30 : 31 : class DiagPktHandler : public ProtoHandler { 32 : public: 33 : static const uint8_t icmp_payload_len = 128; 34 0 : DiagPktHandler(Agent *agent, boost::shared_ptr<PktInfo> info, 35 0 : boost::asio::io_context &io) : 36 0 : ProtoHandler(agent, info, io), done_(false), 37 0 : diag_table_(agent->diag_table()) {} 38 : virtual bool Run(); 39 : void SetReply(); 40 : void SetDiagChkSum(); 41 : void SetDiagChkSumV6(); 42 : void Reply(); 43 : void SendOverlayResponse(); 44 0 : const std::string &GetAddress() const { return address_; } 45 0 : uint8_t* GetData() { 46 0 : return (pkt_info_->data); 47 : } 48 0 : bool IsDone() const { return done_; } 49 0 : void set_done(bool done) { done_ = done; } 50 : void TcpHdr(in_addr_t, uint16_t, in_addr_t, uint16_t, bool , uint32_t, uint16_t); 51 : void TcpHdr(uint16_t len, const uint8_t *src, uint16_t sport, 52 : const uint8_t *dest, uint16_t dport, bool is_syn, 53 : uint32_t seq_no, uint8_t next_hdr); 54 : private: 55 : bool IsTraceRoutePacket(); 56 : bool IsOverlayPingPacket(); 57 : void SetReturnCode(OverlayOamPktData *oamdata); 58 : bool HandleTraceRoutePacket(); 59 : void SendTimeExceededPacket(); 60 : void SendTimeExceededV6Packet(); 61 : bool HandleTraceRouteResponse(); 62 : bool ParseIcmpData(const uint8_t *data, uint16_t data_len, 63 : uint16_t *key, bool is_v4); 64 : uint16_t TcpCsum(in_addr_t, in_addr_t, uint16_t , tcphdr *); 65 : void Swap(); 66 : void TunnelHdrSwap(); 67 : void SwapL4(); 68 : void Swapv6L4(); 69 : void SwapIpHdr(); 70 : void SwapIp6Hdr(); 71 : void SwapEthHdr(); 72 : void BuildReply(); 73 : void SegmentHealthCheckReply(); 74 : 75 : bool done_; 76 : DiagTable *diag_table_; 77 : std::string address_; 78 : }; 79 : 80 : #endif