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