6 #include <netinet/udp.h>
7 #include <netinet/tcp.h>
8 #include <netinet/icmp6.h>
16 #include "diag/diag_types.h"
23 const std::string &context,
25 TraceRouteResp *resp =
new TraceRouteResp();
26 resp->set_hop(address);
28 resp->set_context(context);
35 DiagEntry(trace_route_req->get_source_ip(), trace_route_req->get_dest_ip(),
36 trace_route_req->get_protocol(), trace_route_req->get_source_port(),
37 trace_route_req->get_dest_port(), trace_route_req->get_vrf_name(),
38 trace_route_req->get_interval() * 100,
39 trace_route_req->get_max_attempts(), diag_table),
40 done_(false), ttl_(2),
41 max_ttl_(trace_route_req->get_max_hops()),
42 context_(trace_route_req->context()) {
80 uint8_t *msg = pkt_info->packet_buffer()->data();
90 pkt_info->UpdateHeaderPtr();
93 len +=
sizeof(tcphdr);
102 len +=
sizeof(udphdr);
118 len +=
sizeof(
struct ip);
119 pkt_handler->
IpHdr(len, ntohl(
sip_.to_v4().to_ulong()),
120 ntohl(
dip_.to_v4().to_ulong()),
122 len +=
sizeof(ether_header);
126 pkt_info->eth = (
struct ether_header *)(pkt_handler->
pkt_info()->
pkt);
127 pkt_info->ip6 = (
struct ip6_hdr *)(pkt_info->eth + 1);
130 pkt_info->transp.tcp = (
struct tcphdr *)(pkt_info->ip6 + 1);
131 len +=
sizeof(tcphdr);
133 pkt_handler->
TcpHdr(len+
sizeof(tcphdr),
136 false, rand(), IPPROTO_TCP);
141 pkt_info->transp.udp = (
struct udphdr *)(pkt_info->ip6 + 1);
142 len +=
sizeof(udphdr);
144 pkt_handler->
UdpHdr(len +
sizeof(udphdr),
160 len +=
sizeof(
struct ip6_hdr);
161 pkt_handler->
Ip6Hdr(pkt_info->ip6,
162 len +
sizeof(udphdr) +
sizeof(
struct ip6_hdr),
163 IPPROTO_UDP,
ttl_,
sip_.to_v6().to_bytes().data(),
164 dip_.to_v6().to_bytes().data());
165 len +=
sizeof(ether_header);
221 void TraceRouteReq::HandleRequest()
const {
223 boost::system::error_code ec;
227 IpAddress sip(IpAddress::from_string(get_source_ip(), ec));
229 err_str =
"Invalid source IP";
233 IpAddress dip(IpAddress::from_string(get_dest_ip(), ec));
235 err_str =
"Invalid destination IP";
239 uint8_t proto = get_protocol();
240 if (proto != IPPROTO_TCP && proto != IPPROTO_UDP && proto != IPPROTO_ICMP) {
241 err_str =
"Invalid protocol - Supported protocols are TCP, UDP and ICMP";
246 err_str =
"Invalid VRF";
263 err_str =
"Source VM is not present in this server";
285 TraceRouteErrResp *resp =
new TraceRouteErrResp;
286 resp->set_error_response(err_str);
287 resp->set_context(context());
const Interface * GetInterface() const
uint32_t GetMaxAttempts()
static Agent * GetInstance()
virtual void HandleReply(DiagPktHandler *handler)
VrfEntry * FindVrfFromName(const string &name)
const uint32_t id() const
const Interface * vhost_interface() const
boost::asio::ip::address IpAddress
static const MacAddress & vrrp_mac()
void set_len(uint32_t len)
static const int kBufferSize
InetUnicastRouteEntry * FindRoute(const IpAddress &ip)
const MacAddress & mac() const
Base class for all Route entries in agent.
TraceRoute(const TraceRouteReq *req, DiagTable *diag_table)
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable(const std::string &vrf_name)
void RequestTimedOut(uint32_t seqno)
int EthHdr(const MacAddress &src, const MacAddress &dest, const uint16_t proto)
virtual void SendRequest()
const NextHop * GetActiveNextHop() const
Ip4Address router_id() const
EventManager * event_manager() const
void Send(uint32_t itf, uint32_t vrf, uint16_t, PktHandler::PktModuleName)
PktInfo * pkt_info() const
const uint32_t vrf_id() const
void TcpHdr(in_addr_t, uint16_t, in_addr_t, uint16_t, bool, uint32_t, uint16_t)
void Ip6Hdr(ip6_hdr *ip, uint16_t plen, uint8_t next_header, uint8_t hlim, uint8_t *src, uint8_t *dest)
VrfTable * vrf_table() const
void UdpHdr(uint16_t len, in_addr_t src, uint16_t src_port, in_addr_t dest, uint16_t dest_port)
static void SendSandeshReply(const std::string &address, const std::string &context, bool more)
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable(const std::string &vrf_name)
const std::string & GetAddress() const
void FillHeader(AgentDiagPktData *data)
void IpHdr(uint16_t len, in_addr_t src, in_addr_t dest, uint8_t protocol, uint16_t id, uint8_t ttl)