OpenSDN source code
diag_pkt_handler.cc
Go to the documentation of this file.
1 /*
2  * * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * * Copyright Contributors to the OpenSDN project
4  * */
5 
6 #include <stdint.h>
7 #include "base/os.h"
8 #include <map>
9 #include "vr_defs.h"
10 #include "base/timer.h"
11 #include "cmn/agent_cmn.h"
12 #include "pkt/proto.h"
13 #include "pkt/proto_handler.h"
14 #include "diag/diag_pkt_handler.h"
15 #include "diag/diag.h"
16 #include "diag/diag_proto.h"
17 #include "diag/ping.h"
18 #include "diag/overlay_ping.h"
20 #include "oper/mirror_table.h"
21 #include <oper/bridge_route.h>
22 #include <oper/vxlan.h>
23 #include <netinet/icmp6.h>
25 
26 using namespace boost::posix_time;
28  AgentDiagPktData *ad = (AgentDiagPktData *)pkt_info_->data;
29  ad->op_ = htonl(AgentDiagPktData::DIAG_REPLY);
30 }
31 
33  uint8_t proto;
34  if (pkt_info_->ip) {
35  proto = pkt_info_->ip->ip_p;
36  } else {
37  proto = pkt_info_->ip6->ip6_nxt;
38  }
39  switch(proto) {
40  case IPPROTO_TCP:
41  pkt_info_->transp.tcp->th_sum = 0xffff;
42  break;
43 
44  case IPPROTO_UDP:
45  pkt_info_->transp.udp->uh_sum = 0xffff;
46  break;
47 
48  case IPPROTO_ICMP:
49  pkt_info_->transp.icmp->icmp_cksum = 0xffff;
50  break;
51  case IPPROTO_ICMPV6:
52  pkt_info_->transp.icmp6->icmp6_cksum = 0xffff;
53  break;
54 
55  default:
56  break;
57  }
58 }
59 
61  SetReply();
62  Swap();
63  SetDiagChkSum();
64 }
65 
67  BuildReply();
68  Send(GetInterfaceIndex(), GetVrfIndex(), AgentHdr::TX_ROUTE,
69  CMD_PARAM_PACKET_CTRL, CMD_PARAM_1_DIAG, PktHandler::DIAG);
70 }
71 
73  diag_table_->diag_proto()->IncrementDiagStats(GetInterfaceIndex(),
75  BuildReply();
76  Send(GetInterfaceIndex(), GetVrfIndex(), AgentHdr::TX_SWITCH,
77  CMD_PARAM_PACKET_CTRL, CMD_PARAM_1_DIAG, PktHandler::DIAG);
78  diag_table_->diag_proto()->IncrementDiagStats(GetInterfaceIndex(),
80 }
81 
83  if (pkt_info_->agent_hdr.cmd == AgentHdr::TRAP_ZERO_TTL ||
84  pkt_info_->agent_hdr.cmd == AgentHdr::TRAP_ICMP_ERROR)
85  return true;
86 
87  return false;
88 }
89 
91  if (pkt_info_->agent_hdr.cmd == AgentHdr::TRAP_ROUTER_ALERT)
92  return true;
93  return false;
94 }
95 
97 
98  uint32_t rabit = 0;
99  uint8_t ttl;
100  if (pkt_info_->ether_type == ETHERTYPE_IP) {
101  ttl = pkt_info_->ip->ip_ttl;
102  } else if (pkt_info_->ether_type == ETHERTYPE_IPV6) {
103  ttl = pkt_info_->ip6->ip6_ctlun.ip6_un1.ip6_un1_hlim;
104  } else {
105  return true;
106  }
107 
108  if (ttl == 0 ) {
109  if (pkt_info_->dport == VXLAN_UDP_DEST_PORT) {
110  VxlanHdr *vxlan = (VxlanHdr *)(pkt_info_->transp.udp + 1);
111  rabit = ntohl(vxlan->reserved) & OverlayPing::kVxlanRABit;
112  }
113 
114  if (rabit) {
115  SendOverlayResponse();
116  } else {
117  if (pkt_info_->ether_type == ETHERTYPE_IP) {
118  SendTimeExceededPacket();
119  } else {
120  SendTimeExceededV6Packet();
121  }
122  }
123  return true;
124  }
125  return HandleTraceRouteResponse();
126 }
127 
128 // Send time exceeded ICMP packet
130  // send IP header + 128 bytes from incoming pkt in the icmp response
131  uint16_t icmp_len = pkt_info_->ip->ip_hl * 4 + 128;
132  if (ntohs(pkt_info_->ip->ip_len) < icmp_len)
133  icmp_len = ntohs(pkt_info_->ip->ip_len);
134  boost::scoped_array<uint8_t> icmp_payload(new uint8_t[icmp_len]);
135  memcpy(icmp_payload.get(), pkt_info_->ip, icmp_len);
136  DiagEntry::DiagKey key = -1;
137  if (!ParseIcmpData(icmp_payload.get(), icmp_len, (uint16_t *)&key, true))
138  return;
139 
140  char *ptr = (char *)pkt_info_->pkt;
141  uint16_t buf_len = pkt_info_->max_pkt_len;
142 
143  // Retain the agent-header before ethernet header
144  uint16_t len = (char *)pkt_info_->eth - (char *)pkt_info_->pkt;
145 
146  Ip4Address src_ip(0);
147  VmInterface *vm_itf = dynamic_cast<VmInterface *>
148  (agent()->interface_table()->FindInterface(GetInterfaceIndex()));
149  if (vm_itf == NULL) {
150  src_ip = agent()->router_id();
151  } else {
152  if (vm_itf->vn() == NULL) {
153  return;
154  }
155  const VnIpam *ipam = vm_itf->vn()->GetIpam(pkt_info_->ip_saddr.to_v4());
156  if (ipam == NULL) {
157  return;
158  }
159  src_ip = ipam->default_gw.to_v4();
160  }
161 
162  // Form ICMP Packet with EthHdr - IP Header - ICMP Header
163  len += EthHdr(ptr + len, buf_len - len, agent()->vhost_interface()->mac(),
164  MacAddress(pkt_info_->eth->ether_shost), ETHERTYPE_IP,
166 
167  uint16_t ip_len = sizeof(iphdr) + 8 + icmp_len;
168  len += IpHdr(ptr + len, buf_len - len, ip_len,
169  htonl(src_ip.to_ulong()),
170  htonl(pkt_info_->ip_saddr.to_v4().to_ulong()),
171  IPPROTO_ICMP, DEFAULT_IP_ID, DEFAULT_IP_TTL);
172 
173  struct icmp *hdr = (struct icmp *) (ptr + len);
174  memset((uint8_t *)hdr, 0, 8);
175  hdr->icmp_type = ICMP_TIME_EXCEEDED;
176  hdr->icmp_code = ICMP_EXC_TTL;
177  memcpy(ptr + len + 8, icmp_payload.get(), icmp_len);
178  IcmpChecksum((char *)hdr, 8 + icmp_len);
179  len += 8 + icmp_len;
180 
181  pkt_info_->set_len(len);
182 
183  Send(GetInterfaceIndex(), pkt_info_->vrf, AgentHdr::TX_SWITCH,
185 }
186 
187 
189  uint8_t icmp_payload[icmp_payload_len];
190  uint16_t icmp_len = ntohs(pkt_info_->ip6->ip6_plen);
191 
192  if (icmp_len > icmp_payload_len)
193  icmp_len = icmp_payload_len;
194  memcpy(icmp_payload, pkt_info_->ip6, icmp_len);
195 
196  DiagEntry::DiagKey key = -1;
197  if (!ParseIcmpData(icmp_payload, icmp_len, (uint16_t *)&key, false))
198  return;
199 
200  char *buff = (char *)pkt_info_->pkt;
201  uint16_t buff_len = pkt_info_->max_pkt_len;
202  // Retain the agent-header before ethernet header
203 
204  uint16_t eth_len = EthHdr(buff, buff_len, GetInterfaceIndex(),
205  agent()->vhost_interface()->mac(),
206  MacAddress(pkt_info_->eth->ether_shost),
207  ETHERTYPE_IPV6);
208 
209  VmInterface *vm_itf = dynamic_cast<VmInterface *>
210  (agent()->interface_table()->FindInterface(GetInterfaceIndex()));
211  if (vm_itf == NULL || vm_itf->layer3_forwarding() == false ||
212  vm_itf->vn() == NULL) {
213  return;
214  }
215 
216  const VnIpam *ipam = vm_itf->vn()->GetIpam(pkt_info_->ip_saddr.to_v6());
217  if (ipam == NULL)
218  return ;
219 
220  pkt_info_->ip6 = (struct ip6_hdr *)(buff + eth_len);
221  Ip6Hdr(pkt_info_->ip6, icmp_len+ICMP_UNREACH_HDR_LEN, IPV6_ICMP_NEXT_HEADER,
222  DEFAULT_IP_TTL, ipam->default_gw.to_v6().to_bytes().data(),
223  pkt_info_->ip_saddr.to_v6().to_bytes().data());
224 
225  icmp6_hdr *icmp = pkt_info_->transp.icmp6 =
226  (icmp6_hdr *)(pkt_info_->pkt + eth_len
227  + sizeof(ip6_hdr));
228  icmp->icmp6_type = ICMP_TIME_EXCEEDED;
229  icmp->icmp6_code = ICMP_EXC_TTL;
230  icmp->icmp6_mtu = 0;
231  icmp->icmp6_cksum = 0;
232  icmp->icmp6_cksum =
233  Icmpv6Csum(ipam->default_gw.to_v6().to_bytes().data(),
234  pkt_info_->ip_saddr.to_v6().to_bytes().data(),
235  icmp, icmp_len);
236  memcpy(buff + sizeof(ip6_hdr) + eth_len+ICMP_UNREACH_HDR_LEN,
237  icmp_payload, icmp_len);
238  pkt_info_->set_len(icmp_len + sizeof(ip6_hdr) + eth_len+ICMP_UNREACH_HDR_LEN);
239 
240  uint16_t command =
241  (pkt_info_->agent_hdr.cmd == AgentHdr::TRAP_TOR_CONTROL_PKT) ?
243 
244  Send(GetInterfaceIndex(), pkt_info_->vrf, command,
246 
247 }
248 
250  uint8_t *data = (uint8_t *)(pkt_info_->transp.icmp) + 8;
251  uint16_t len = pkt_info_->len - (data - pkt_info_->pkt);
252  bool is_v4 = pkt_info_->ether_type == ETHERTYPE_IP;
253  DiagEntry::DiagKey key = -1;
254  // if it is Overlay packet get the key from Oam data
255  if (IsOverlayPingPacket()) {
256  OverlayOamPktData *oamdata = (OverlayOamPktData *) pkt_info_->data;
257  key = ntohs(oamdata->org_handle_);
258  } else {
259  if (!ParseIcmpData(data, len, (uint16_t *)&key, is_v4))
260  return true;
261  }
262 
263  DiagEntry *entry = diag_table_->Find(key);
264  if (!entry) return true;
265 
266  if (is_v4)
267  address_ = pkt_info_->ip_saddr.to_v4().to_string();
268  else {
269  address_ = pkt_info_->ip_saddr.to_v6().to_string();
270  }
271  entry->HandleReply(this);
272 
273  DiagEntryOp *op;
274  if (IsDone()) {
275  op = new DiagEntryOp(DiagEntryOp::DEL, entry);
276  } else {
277  op = new DiagEntryOp(DiagEntryOp::RETRY, entry);
278  }
279  entry->diag_table()->Enqueue(op);
280 
281  return true;
282 }
283 
284 bool DiagPktHandler::ParseIcmpData(const uint8_t *data, uint16_t data_len,
285  uint16_t *key, bool is_v4) {
286  if (data_len < sizeof(struct ip))
287  return false;
288  struct ip *ip_hdr = (struct ip *)(data);
289  *key = ntohs(ip_hdr->ip_id);
290  uint16_t len = sizeof(struct ip);
291  uint8_t protocol;
292 
293  if (ip_hdr->ip_src.s_addr == htonl(agent()->router_id().to_ulong()) ||
294  ip_hdr->ip_dst.s_addr == htonl(agent()->router_id().to_ulong())) {
295  // Check inner header
296  switch (ip_hdr->ip_p) {
297  case IPPROTO_GRE : {
298  if (data_len < len + sizeof(GreHdr))
299  return true;
300  len += sizeof(GreHdr);
301  break;
302  }
303 
304  case IPPROTO_UDP : {
305  if (data_len < len + sizeof(udphdr))
306  return true;
307  len += sizeof(udphdr);
308  break;
309  }
310 
311  default: {
312  return true;
313  }
314  }
315  len += sizeof(MplsHdr);
316  if (is_v4) {
317  if (data_len < len + sizeof(struct ip))
318  return true;
319  ip_hdr = (struct ip *)(data + len);
320  len += sizeof(struct ip);
321  protocol = ip_hdr->ip_p;
322  } else {
323  if (data_len < len + sizeof(struct ip6_hdr))
324  return true;
325  struct ip6_hdr *ip6_hdr = (struct ip6_hdr *)(data + len);
326  len += sizeof(struct ip6_hdr);
327  protocol = ip6_hdr->ip6_nxt;
328  }
329  switch (protocol) {
330  case IPPROTO_TCP:
331  len += sizeof(tcphdr);
332  break;
333 
334  case IPPROTO_UDP:
335  len += sizeof(udphdr);
336  break;
337 
338  case IPPROTO_ICMP:
339  len += 8;
340  break;
341  case IPPROTO_ICMPV6:
342  len += 8;
343  break;
344  default:
345  return true;
346  }
347  if (data_len < len + sizeof(AgentDiagPktData))
348  return true;
349 
350  AgentDiagPktData *agent_data = (AgentDiagPktData *)(data + len);
351  if (ntohl(agent_data->op_) == AgentDiagPktData::DIAG_REQUEST) {
352  agent_data->op_ = htonl(AgentDiagPktData::DIAG_REPLY);
353  } else if (ntohl(agent_data->op_) == AgentDiagPktData::DIAG_REPLY) {
354  *key = ntohs(agent_data->key_);
355  done_ = true;
356  }
357  }
358 
359  return true;
360 }
361 
363  bool isoverlay_packet = IsOverlayPingPacket();
364  AgentDiagPktData *ad = NULL;
365  AgentDiagPktData tempdata;
366 
367  if (IsTraceRoutePacket()) {
368  return HandleTraceRoutePacket();
369  }
370 
371  if (isoverlay_packet) {
372  // Process Overlay packet
373  // papulate diag data AgentDiagPktData here
374  memset((void*)&tempdata, 0, sizeof(AgentDiagPktData));
375  ad = &tempdata;
376  OverlayOamPktData *oamdata = (OverlayOamPktData *) pkt_info_->data;
378  ad->op_ = htonl(AgentDiagPktData::DIAG_REQUEST);
379  } else if (oamdata->msg_type_ == OverlayOamPktData::OVERLAY_ECHO_REPLY) {
380  ad->op_ = htonl(AgentDiagPktData::DIAG_REPLY);
381  }
382 
383  ad->key_ = oamdata->org_handle_;
384  } else {
385  ad = (AgentDiagPktData *)pkt_info_->data;
386  }
387 
388  if (!ad) {
389  //Ignore if packet doesnt have proper L4 header
390  return true;
391  }
392 
393  SegmentHealthCheckPkt *segment_hc_pkt = NULL;
394  DiagEntry::DiagKey key = ntohs(ad->key_);
395  DiagEntry *entry = diag_table_->Find(key);
396  if (entry) {
397  segment_hc_pkt = dynamic_cast< SegmentHealthCheckPkt * >(entry);
398  }
399  if (ntohl(ad->op_) == AgentDiagPktData::DIAG_REQUEST) {
400  //Request received swap the packet
401  //and dump the packet back
402  if (isoverlay_packet) {
403  // Reply packet with after setting the TLV content.
404  SendOverlayResponse();
405  return true;
406  }
407  if (segment_hc_pkt) {
408  SegmentHealthCheckReply();
409  } else {
410  Reply();
411  }
412  return true;
413  }
414 
415  if (ntohl(ad->op_) != AgentDiagPktData::DIAG_REPLY) {
416  return true;
417  }
418  //Reply for a query we sent
419  if (!entry) {
420  return true;
421  }
422  entry->HandleReply(this);
423 
424  if (segment_hc_pkt) {
425  /* No further processing required for Segment Health check packet */
426  return true;
427  }
428 
429  if (entry->GetSeqNo() == entry->GetMaxAttempts()) {
430  DiagEntryOp *op;
431  op = new DiagEntryOp(DiagEntryOp::DEL, entry);
432  entry->diag_table()->Enqueue(op);
433  } else {
434  entry->Retry();
435  }
436 
437  return true;
438 }
439 
440 void DiagPktHandler::TcpHdr(in_addr_t src, uint16_t sport, in_addr_t dst,
441  uint16_t dport, bool is_syn, uint32_t seq_no,
442  uint16_t len) {
443  struct tcphdr *tcp = pkt_info_->transp.tcp;
444  tcp->th_sport = htons(sport);
445  tcp->th_dport = htons(dport);
446 
447  if (is_syn) {
448  tcp->th_flags &= ~TH_ACK;
449  } else {
450  //If not sync, by default we are sending an ack
451  tcp->th_flags &= ~TH_SYN;
452  }
453 
454  tcp->th_seq = htons(seq_no);
455  tcp->th_ack = htons(seq_no + 1);
456  //Just a random number;
457  tcp->th_win = htons(1000);
458  tcp->th_off = 5;
459  tcp->th_sum = 0;
460  tcp->th_sum = TcpCsum(src, dst, len, tcp);
461 }
462 
463 void DiagPktHandler::TcpHdr(uint16_t len, const uint8_t *src, uint16_t sport,
464  const uint8_t *dest, uint16_t dport, bool is_syn,
465  uint32_t seq_no, uint8_t next_hdr){
466  struct tcphdr *tcp = pkt_info_->transp.tcp;
467  tcp->th_sport = htons(sport);
468  tcp->th_dport = htons(dport);
469 
470  if (is_syn) {
471  tcp->th_flags &= ~TH_ACK;
472  } else {
473  //If not sync, by default we are sending an ack
474  tcp->th_flags &= ~TH_SYN;
475  }
476 
477  tcp->th_seq = htons(seq_no);
478  tcp->th_ack = htons(seq_no + 1);
479  //Just a random number;
480  tcp->th_win = htons(1000);
481  tcp->th_off = 5;
482  tcp->th_sum = 0;
483  tcp->th_sum = Ipv6Csum(src, dest, len, next_hdr, (uint16_t *)tcp);
484 }
485 
486 uint16_t DiagPktHandler::TcpCsum(in_addr_t src, in_addr_t dest, uint16_t len,
487  tcphdr *tcp) {
488  uint32_t sum = 0;
489  PseudoTcpHdr phdr(src, dest, htons(len));
490  sum = Sum((uint16_t *)&phdr, sizeof(PseudoTcpHdr), sum);
491  return Csum((uint16_t *)tcp, len, sum);
492 }
493 
495  if (pkt_info_->ip_proto == IPPROTO_TCP) {
496  tcphdr *tcp = pkt_info_->transp.tcp;
497  TcpHdr(htonl(pkt_info_->ip_daddr.to_v4().to_ulong()),
498  ntohs(tcp->th_dport),
499  htonl(pkt_info_->ip_saddr.to_v4().to_ulong()),
500  ntohs(tcp->th_sport), false, ntohs(tcp->th_ack),
501  ntohs(pkt_info_->ip->ip_len) - sizeof(struct ip));
502  } else if (pkt_info_->ip_proto == IPPROTO_UDP) {
503  udphdr *udp = pkt_info_->transp.udp;
504  UdpHdr(ntohs(udp->uh_ulen), pkt_info_->ip_daddr.to_v4().to_ulong(),
505  ntohs(udp->uh_dport), pkt_info_->ip_saddr.to_v4().to_ulong(),
506  ntohs(udp->uh_sport));
507  } else if (pkt_info_->ip_proto == IPPROTO_ICMP) {
508  struct icmp *hdr = (struct icmp *) (pkt_info_->transp.icmp);
509  if (hdr->icmp_type == ICMP_ECHO) {
510  hdr->icmp_type = ICMP_ECHOREPLY;
511  hdr->icmp_code = 0;
512  }
513  /* We do not change sequence and identifier fields of ICMP header */
514  }
515 }
516 
518  if (pkt_info_->ip_proto == IPPROTO_TCP) {
519  tcphdr *tcp = pkt_info_->transp.tcp;
520  TcpHdr(ntohs(pkt_info_->ip6->ip6_ctlun.ip6_un1.ip6_un1_plen) - sizeof(struct ip6_hdr),
521  pkt_info_->ip_daddr.to_v6().to_bytes().data(), ntohs(tcp->th_dport),
522  pkt_info_->ip_saddr.to_v6().to_bytes().data(), ntohs(tcp->th_sport),
523  false, ntohs(tcp->th_ack), IPPROTO_TCP);
524  } else if (pkt_info_->ip_proto == IPPROTO_UDP) {
525  udphdr *udp = pkt_info_->transp.udp;
526  UdpHdr(ntohs(udp->uh_ulen), pkt_info_->ip_daddr.to_v6().to_bytes().data(),
527  ntohs(udp->uh_dport), pkt_info_->ip_saddr.to_v6().to_bytes().data(),
528  ntohs(udp->uh_sport), IPPROTO_UDP);
529  }
530 }
531 
533  //IpHdr expects IP address to be in network format
534  struct ip *ip = pkt_info_->ip;
535  IpHdr(ntohs(ip->ip_len), ip->ip_dst.s_addr,
536  ip->ip_src.s_addr, ip->ip_p, DEFAULT_IP_ID, DEFAULT_IP_TTL);
537 }
538 
540  //Ip6Hdr expects IPv6 address to be in network format
541  struct ip6_hdr *ip6 = pkt_info_->ip6;
542  Ip6Hdr(ip6, ntohl(ip6->ip6_ctlun.ip6_un1.ip6_un1_plen),
543  ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt, DEFAULT_IP_TTL,
544  pkt_info_->ip_daddr.to_v6().to_bytes().data(),
545  pkt_info_->ip_saddr.to_v6().to_bytes().data());
546 }
547 
549  struct ether_header *eth = pkt_info_->eth;
550  EthHdr(MacAddress(eth->ether_dhost), MacAddress(eth->ether_shost), ntohs(eth->ether_type));
551 }
552 
554  if (pkt_info_->ether_type == ETHERTYPE_IPV6) {
555  Swapv6L4();
556  SwapIp6Hdr();
557  } else {
558  SwapL4();
559  SwapIpHdr();
560  }
561  SwapEthHdr();
562 }
563 
566 
567  uint16_t type = ntohs(oamdata->oamtlv_.type_);
569  return;
570  }
571 
572  const int tlv_length = ntohs(oamdata->oamtlv_.length_);
573  // VXLAN VNI and IPv4 / IPv6 sender address
574  int parsed_tlv = (type == OamTlv::VXLAN_PING_IPv4) ? 8 : 20;
575 
576  VxLanId *vxlan =
577  Agent::GetInstance()->vxlan_table()->Find(pkt_info_->tunnel.vxlan_id);
578  if (!vxlan) {
579  return;
580  }
581 
582  const VrfNH *vrf_nh = dynamic_cast<const VrfNH *> (vxlan->nexthop());
583  if (!vrf_nh) {
584  return;
585  }
586 
587  const VrfEntry *vrf = vrf_nh->GetVrf();
588  if (!vrf || vrf->IsDeleted()) {
589  return;
590  }
591 
593  while (tlv_length - parsed_tlv >= (int) sizeof(SubTlv)) {
594  SubTlv *subtlv = (SubTlv *) (oamdata->oamtlv_.data_ + parsed_tlv);
595  parsed_tlv += sizeof(SubTlv);
596 
597  const int subtlv_length = ntohs(subtlv->length_);
598  if (ntohs(subtlv->type_) != SubTlv::END_SYSTEM_MAC) {
599  parsed_tlv += subtlv_length;
600  continue;
601  }
602 
603  int parsed_subtlv = 0;
604  // check that we have bytes for MAC (6) and return code (2)
605  while (subtlv_length - parsed_subtlv >=
606  (int) sizeof(SubTlv::EndSystemMac)) {
607  SubTlv::EndSystemMac *end_system_mac =
609  (oamdata->oamtlv_.data_ + parsed_tlv + parsed_subtlv);
610  MacAddress mac(end_system_mac->mac);
611  BridgeAgentRouteTable *table =
612  static_cast<BridgeAgentRouteTable *> (vrf->GetBridgeRouteTable());
613  if (table->FindRoute(mac, Peer::EVPN_PEER) != NULL ||
614  table->FindRoute(mac, Peer::LOCAL_VM_PORT_PEER) != NULL ||
615  table->FindRoute(mac, Peer::LOCAL_VM_PEER) != NULL) {
616  end_system_mac->return_code = htons(SubTlv::END_SYSTEM_PRESENT);
617  } else {
618  end_system_mac->return_code =
620  }
621  parsed_subtlv += sizeof(SubTlv::EndSystemMac);
622  }
623  parsed_tlv += subtlv_length;
624  }
625 }
626 
628  struct ether_header *eth = pkt_info_->tunnel.eth;
629  EthHdr((char *)eth, sizeof(struct ether_header), MacAddress(eth->ether_dhost),
630  MacAddress(eth->ether_shost), ntohs(eth->ether_type),
632  struct ip *ip = pkt_info_->tunnel.ip;
633  IpHdr((char *)ip, sizeof(struct ip), ntohs(ip->ip_len),ip->ip_dst.s_addr,
634  ip->ip_src.s_addr, ip->ip_p, DEFAULT_IP_ID, DEFAULT_IP_TTL);
635 }
636 
638  Agent *agent = Agent::GetInstance();
639  TunnelHdrSwap();
640 
641  OverlayOamPktData *oamdata = (OverlayOamPktData *) pkt_info_->data;
642  if (oamdata->reply_mode_ == OverlayOamPktData::DONT_REPLY) {
643  return ;
644  }
645 
646  SetReturnCode(oamdata);
647 
649  boost::posix_time::ptime
650  epoch(boost::gregorian::date(1970, boost::gregorian::Jan, 1));
651  boost::posix_time::ptime time = microsec_clock::universal_time();
652  boost::posix_time::time_duration td = time - epoch;
653  oamdata->timerecv_sec_ = htonl(td.total_seconds());
654  oamdata->timerecv_misec_ = htonl(td.total_microseconds() -
655  (td.total_seconds()*1000000));
656 
658  Interface *intf = static_cast<Interface *>
659  (agent->interface_table()->Find(&key1, true));
660  Send(intf->id(), agent->fabric_vrf()->vrf_id(),
661  AgentHdr::TX_SWITCH, CMD_PARAM_PACKET_CTRL,
662  CMD_PARAM_1_DIAG, PktHandler::DIAG);
663 }
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
AgentDBEntry * Find(const DBEntry *key, bool ret_del)
Definition: agent_db.cc:135
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
VxLanTable * vxlan_table() const
Definition: agent.h:538
VrfEntry * fabric_vrf() const
Definition: agent.h:918
static Agent * GetInstance()
Definition: agent.h:439
const std::string & fabric_interface_name() const
Definition: agent.h:1132
BridgeRouteEntry * FindRoute(const MacAddress &mac)
Definition: bridge_route.cc:73
bool IsDeleted() const
Definition: db_entry.h:49
Definition: diag.h:22
uint16_t DiagKey
Definition: diag.h:24
virtual void Retry()
Definition: diag.cc:85
uint32_t GetSeqNo()
Definition: diag.h:42
virtual void HandleReply(DiagPktHandler *handler)=0
DiagTable * diag_table() const
Definition: diag.h:49
uint32_t GetMaxAttempts()
Definition: diag.h:43
void TcpHdr(in_addr_t, uint16_t, in_addr_t, uint16_t, bool, uint32_t, uint16_t)
bool IsOverlayPingPacket()
void SegmentHealthCheckReply()
void SendTimeExceededPacket()
void SendTimeExceededV6Packet()
bool HandleTraceRouteResponse()
bool ParseIcmpData(const uint8_t *data, uint16_t data_len, uint16_t *key, bool is_v4)
bool HandleTraceRoutePacket()
virtual bool Run()
uint16_t TcpCsum(in_addr_t, in_addr_t, uint16_t, tcphdr *)
void SetReturnCode(OverlayOamPktData *oamdata)
@ REPLIES_SENT
Definition: diag_proto.h:28
@ REQUESTS_RECEIVED
Definition: diag_proto.h:27
void Enqueue(DiagEntryOp *op)
Definition: diag.cc:160
const uint32_t id() const
Definition: interface.h:126
static const uint32_t kVxlanRABit
Definition: overlay_ping.h:22
@ EVPN_PEER
Definition: peer.h:51
@ LOCAL_VM_PEER
Definition: peer.h:58
@ LOCAL_VM_PORT_PEER
Definition: peer.h:57
bool layer3_forwarding() const
const VnEntry * vn() const
static const uint32_t kInvalidVlanId
Definition: vm_interface.h:363
const VnIpam * GetIpam(const IpAddress &ip) const
Definition: vn.cc:653
Definition: vrf.h:90
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:335
const uint32_t vrf_id() const
Definition: vrf.h:103
const VrfEntry * GetVrf() const
Definition: nexthop.h:1445
Definition: vxlan.h:14
const NextHop * nexthop() const
Definition: vxlan.h:28
VxLanId * Find(uint32_t vxlan_id)
Definition: vxlan.cc:222
#define IPV6_ICMP_NEXT_HEADER
uint8_t type
Definition: load_balance.h:2
#define DEFAULT_IP_ID
Definition: pkt_handler.h:48
#define DEFAULT_IP_TTL
Definition: pkt_handler.h:44
#define VXLAN_UDP_DEST_PORT
Definition: pkt_handler.h:36
#define ICMP_UNREACH_HDR_LEN
Definition: pkt_handler.h:51
uint32_t op_
Definition: diag.h:83
DiagEntry::DiagKey key_
Definition: diag.h:84
@ DIAG_REQUEST
Definition: diag.h:76
@ TRAP_ROUTER_ALERT
Definition: pkt_handler.h:147
@ TRAP_ICMP_ERROR
Definition: pkt_handler.h:145
@ TRAP_ZERO_TTL
Definition: pkt_handler.h:144
@ TRAP_TOR_CONTROL_PKT
Definition: pkt_handler.h:143
@ DEL
Definition: diag.h:93
@ RETRY
Definition: diag.h:94
uint16_t type_
Definition: diag.h:151
@ VXLAN_PING_IPv4
Definition: diag.h:131
@ VXLAN_PING_IPv6
Definition: diag.h:132
uint16_t length_
Definition: diag.h:152
char data_[1]
Definition: diag.h:153
uint32_t org_handle_
Definition: diag.h:203
uint32_t timerecv_misec_
Definition: diag.h:208
uint8_t msg_type_
Definition: diag.h:199
@ OVERLAY_SEGMENT_NOT_PRESENT
Definition: diag.h:188
uint32_t timerecv_sec_
Definition: diag.h:207
OamTlv oamtlv_
Definition: diag.h:209
uint8_t return_code_
Definition: diag.h:201
uint8_t reply_mode_
Definition: diag.h:200
@ OVERLAY_ECHO_REPLY
Definition: diag.h:182
@ OVERLAY_ECHO_REQUEST
Definition: diag.h:181
uint8_t mac[6]
Definition: diag.h:174
uint16_t return_code
Definition: diag.h:175
Definition: diag.h:156
uint16_t length_
Definition: diag.h:171
@ END_SYSTEM_PRESENT
Definition: diag.h:166
@ END_SYSTEM_NOT_PRESENT
Definition: diag.h:167
@ END_SYSTEM_MAC
Definition: diag.h:158
uint16_t type_
Definition: diag.h:170
Definition: vn.h:29
IpAddress default_gw
Definition: vn.h:32
uint32_t reserved
Definition: pkt_handler.h:91