OpenSDN source code
pkt_handler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include "base/os.h"
7 #include <sys/types.h>
8 #include <arpa/inet.h>
9 #include <netinet/in.h>
10 #include <netinet/ip6.h>
11 #include <netinet/icmp6.h>
12 
13 #include "init/agent_param.h"
14 #include "cmn/agent_cmn.h"
15 #include "diag/diag.h"
16 #include "base/address_util.h"
17 #include "oper/ecmp_load_balance.h"
18 #include "oper/interface_common.h"
19 #include "oper/nexthop.h"
20 #include "oper/route_common.h"
21 #include "oper/vrf.h"
22 #include "oper/tunnel_nh.h"
23 #include "pkt/control_interface.h"
24 #include "pkt/pkt_handler.h"
25 #include "pkt/proto.h"
26 #include "pkt/flow_table.h"
27 #include "pkt/flow_proto.h"
28 #include "pkt/pkt_types.h"
29 #include "pkt/pkt_init.h"
30 #include "cmn/agent_stats.h"
31 #include "pkt/packet_buffer.h"
32 #include "vr_types.h"
33 #include "vr_defs.h"
34 #include "vr_mpls.h"
35 
36 #define PKT_TRACE(obj, arg) \
37 do { \
38  std::ostringstream _str; \
39  _str << arg; \
40  Pkt##obj::TraceMsg(PacketTraceBuf, __FILE__, __LINE__, _str.str()); \
41 } while (false) \
42 
43 const std::size_t PktTrace::kPktMaxTraceSize;
44 
46 namespace {
47 inline bool IsBfdkeepalivePkt(const AgentHdr &hdr)
48 {
49  // For the BFD traped packets, BFD state info is available in 'cmd_param'
50  if ((hdr.cmd == AGENT_TRAP_BFD) && (hdr.cmd_param == 0xc0)) {
51  return true;
52  }
53  return false;
54 }
55 
56 } // namespace
57 
58 PktHandler::PktHandler(Agent *agent, PktModule *pkt_module) :
59  stats_(), agent_(agent), pkt_module_(pkt_module),
60  work_queue_(TaskScheduler::GetInstance()->GetTaskId("Agent::PktHandler"), 0,
61  boost::bind(&PktHandler::ProcessPacket, this, _1)),
62  work_queue_bfd_ka_(TaskScheduler::GetInstance()->GetTaskId("Agent::BFD_KA"), 0,
63  boost::bind(&PktHandler::ProcessBfdDataPacket, this, _1))
64  {
65  work_queue_.set_name("Packet Handler Queue");
67  // BFD keep alive packet processing
68  work_queue_bfd_ka_.set_name("Packet BFD Data Queue");
70  for (int i = 0; i < MAX_MODULES; ++i) {
71  if (i == PktHandler::DHCP || i == PktHandler::DHCPV6 ||
72  i == PktHandler::DNS)
73  pkt_trace_.at(i).set_pkt_trace_size(512);
74  else
75  pkt_trace_.at(i).set_pkt_trace_size(128);
76  }
77 }
78 
81 }
82 
84  proto_list_.at(type) = proto;
85  if (type == BFD) {
86  bfd_keepalive_proto_ = proto;
87  }
88 }
89 
90 uint32_t PktHandler::EncapHeaderLen() const {
92 }
93 
94 // Send packet to tap interface
95 void PktHandler::Send(const AgentHdr &hdr, const PacketBufferPtr &buff) {
96  stats_.PktSent(PktHandler::PktModuleName(buff->module()));
97  pkt_trace_.at(buff->module()).AddPktTrace(PktTrace::Out, buff->data_len(),
98  buff->data(), &hdr);
99  if (agent_->pkt()->control_interface()->Send(hdr, buff) <= 0) {
100  PKT_TRACE(Err, "Error sending packet");
101  }
102  return;
103 }
104 
106  const Interface *in = NULL;
107  const VmInterface *intf = NULL;
108  const Interface *pkt_in_intf = NULL;
109  bool ingress= false;
111  uint8_t protocol;
112 
113  const NextHop *nh =
115  if (!nh) {
116  return;
117  }
118 
119  if (nh->GetType() == NextHop::INTERFACE) {
120  const InterfaceNH *intf_nh = static_cast<const InterfaceNH *>(nh);
121  in = intf_nh->GetInterface();
122  } else if (nh->GetType() == NextHop::VLAN) {
123  const VlanNH *vlan_nh = static_cast<const VlanNH *>(nh);
124  in = vlan_nh->GetInterface();
125  } else if (nh->GetType() == NextHop::COMPOSITE) {
126  const CompositeNH *comp_nh = static_cast<const CompositeNH *>(nh);
127 
128  if (comp_nh->composite_nh_type() == Composite::LOCAL_ECMP) {
129  in = comp_nh->GetFirstLocalEcmpMemberInterface();
130  }
131  }
132 
133  if (in) {
134  intf = dynamic_cast<const VmInterface *>(in);
135  }
136 
137  if (!intf) {
138  return;
139  }
140 
141  if (intf->fat_flow_list().list_.size() == 0) {
142  return;
143  }
144 
145  if (intf->ExcludeFromFatFlow(pkt->family, pkt->ip_saddr, pkt->ip_daddr)) {
146  return;
147  }
148  uint16_t sport = pkt->sport;
149  if (pkt->ip_proto == IPPROTO_ICMP || pkt->ip_proto == IPPROTO_IGMP) {
150  sport = 0;
151  }
152 
153  protocol = pkt->ip_proto;
154  /*
155  * For ICMPv6 change the protocol to ICMP as the same value is used when it is
156  * stored in the fat flow rule
157  */
158  if (pkt->ip_proto == IPPROTO_ICMPV6) {
159  protocol = IPPROTO_ICMP;
160  }
161 
162  pkt->is_fat_flow_src_prefix = false;
163  pkt->is_fat_flow_dst_prefix = false;
164 
165  if (pkt->sport < pkt->dport) {
166  if (intf->IsFatFlowPortBased(protocol, sport, &ignore_addr)) {
167  pkt->dport = 0;
168  pkt->ignore_address = ignore_addr;
169  return;
170  }
171 
172  if (intf->IsFatFlowPortBased(protocol, pkt->dport, &ignore_addr)) {
173  pkt->sport = 0;
174  pkt->ignore_address = ignore_addr;
175  return;
176  }
177  } else {
178  if (intf->IsFatFlowPortBased(protocol, pkt->dport, &ignore_addr)) {
179  if (pkt->dport == pkt->sport) {
180  pkt->same_port_number = true;
181  }
182  pkt->sport = 0;
183  pkt->ignore_address = ignore_addr;
184  return;
185  }
186 
187  if (intf->IsFatFlowPortBased(protocol, sport, &ignore_addr)) {
188  pkt->dport = 0;
189  pkt->ignore_address = ignore_addr;
190  return;
191  }
192  }
193  /* If Fat-flow port is 0, then both source and destination ports have to
194  * be ignored */
195  if (intf->IsFatFlowPortBased(protocol, 0, &ignore_addr)) {
196  pkt->sport = 0;
197  pkt->dport = 0;
198  pkt->ignore_address = ignore_addr;
199  return;
200  }
201 
202  // Check for fat flow based on prefix aggregation
204  pkt->agent_hdr.ifindex);
205  ingress = PktFlowInfo::ComputeDirection(pkt_in_intf);
206  // set the src and dst prefix to src & dst ip to begin with
207  pkt->ip_ff_src_prefix = pkt->ip_saddr;
208  pkt->ip_ff_dst_prefix = pkt->ip_daddr;
209  intf->IsFatFlowPrefixAggregation(ingress, protocol,
210  (uint16_t *)&pkt->sport,
211  (uint16_t *) &pkt->dport,
212  &pkt->same_port_number,
213  &pkt->ip_ff_src_prefix,
214  &pkt->ip_ff_dst_prefix,
217  &pkt->ignore_address);
218 }
219 
221  const Interface *intrface) {
222  if (intrface->type() == Interface::VM_INTERFACE &&
223  pkt_info->ip_proto == IPPROTO_UDP &&
224  (pkt_info->dport == BFD_SINGLEHOP_CONTROL_PORT ||
225  pkt_info->dport == BFD_MULTIHOP_CONTROL_PORT ||
226  pkt_info->dport == BFD_ECHO_PORT)) {
227  return true;
228  }
229 
230  return false;
231 }
232 
234  const Interface *intrface) {
235  if (intrface->type() == Interface::VM_INTERFACE &&
236  pkt_info->ip_proto == IPPROTO_ICMP) {
237  if (pkt_info->icmp_chksum == 0xffff) {
238  return true;
239  }
240  return pkt_info->is_segment_hc_pkt;
241  }
242  return false;
243 }
244 
245 // Validate the BFD Keepalive packet received
247  PktInfo *pkt_info,
248  uint8_t *pkt) {
249 
250  PktType::Type pkt_type = PktType::INVALID;
251  pkt_info->agent_hdr = hdr;
252 
253  int len = 0, ret = 0;
254 
255  // Parse packet before computing forwarding mode. Packet is parsed
256  // independent of packet forwarding mode
257  len += ParseEthernetHeader(pkt_info, (pkt + len));
258  if (pkt_info->ether_type != ETHERTYPE_IP) {
260  return INVALID;
261  }
262 
263  // IP Packets
264  ret = ParseIpPacket(pkt_info, pkt_type, (pkt + len));
265  if(ret == -1) {
266  return INVALID;
267  }
268  len += ret;
269 
270  // Check if the BFD KA packet
271  if (pkt_info->ip_proto == IPPROTO_UDP &&
272  pkt_info->dport == BFD_SINGLEHOP_CONTROL_PORT &&
273  (pkt_info->data[0] & 0x20)) {
274  return BFD;
275  }
276 
277  return INVALID;
278 }
279 
280 // Process the packet received from tap interface
282  PktInfo *pkt_info,
283  uint8_t *pkt) {
284  PktType::Type pkt_type = PktType::INVALID;
285  Interface *intf = NULL;
286 
287  pkt_info->agent_hdr = hdr;
288  if (!IsValidInterface(hdr.ifindex, &intf)) {
289  return INVALID;
290  }
291 
292  // Parse packet before computing forwarding mode. Packet is parsed
293  // indepndent of packet forwarding mode
294  if (ParseUserPkt(pkt_info, intf, pkt_type, pkt) < 0) {
295  return INVALID;
296  }
297 
298  if (pkt_info->agent_hdr.cmd == AgentHdr::TRAP_TOR_CONTROL_PKT) {
299  // In case of a control packet from a TOR served by us, the ifindex
300  // is modified to index of the VM interface; validate this interface.
301  if (!IsValidInterface(pkt_info->agent_hdr.ifindex, &intf)) {
302  return INVALID;
303  }
304  }
305 
306  pkt_info->vrf = pkt_info->agent_hdr.vrf;
307 
308 
309  if (hdr.cmd == AgentHdr::TRAP_MAC_MOVE ||
310  hdr.cmd == AgentHdr::TRAP_MAC_LEARN ||
312  return MAC_LEARNING;
313  }
314 
315  bool is_flow_packet = IsFlowPacket(pkt_info);
316  // Look for DHCP packets if corresponding service is enabled
317  // Service processing over-rides ACL/Flow and forwarding configuration
318  if (!is_flow_packet && intf->dhcp_enabled() && (pkt_type == PktType::UDP)) {
319  if (pkt_info->ip && (pkt_info->dport == DHCP_SERVER_PORT ||
320  pkt_info->sport == DHCP_CLIENT_PORT)) {
321  return DHCP;
322  }
323  }
324  if (!is_flow_packet && intf->dhcp_enabled_v6() && (pkt_type == PktType::UDP)) {
325  if (pkt_info->ip6 && (pkt_info->dport == DHCPV6_SERVER_PORT ||
326  pkt_info->sport == DHCPV6_CLIENT_PORT)) {
327  return DHCPV6;
328  }
329  }
330 
331  // Handle ARP packet
332  if (pkt_type == PktType::ARP) {
333  return ARP;
334  }
335 
336  // Packets needing flow
337  if (is_flow_packet) {
338  CalculatePortIP(pkt_info);
339  if ((pkt_info->ip && pkt_info->family == Address::INET) ||
340  (pkt_info->ip6 && pkt_info->family == Address::INET6)) {
341  return FLOW;
342  } else {
343  PKT_TRACE(Err, "Flow trap for non-IP packet for interface "
344  "index <" << hdr.ifindex << ">");
346  return INVALID;
347  }
348  }
349 
350  // Look for DNS packets if corresponding service is enabled
351  // Service processing over-rides ACL/Flow
352  if (intf->dns_enabled() && (pkt_type == PktType::UDP)) {
353  if (pkt_info->dport == DNS_SERVER_PORT) {
354  return DNS;
355  }
356  }
357 
358  // Look for IP packets that need ARP resolution
359  if (pkt_info->ip && hdr.cmd == AgentHdr::TRAP_RESOLVE) {
360  return ARP;
361  }
362 
363  // send time exceeded ICMP messages to diag module
364  if (IsDiagPacket(pkt_info)) {
365  return DIAG;
366  }
367 
368  if (IsBFDHealthCheckPacket(pkt_info, intf)) {
369  return BFD;
370  }
371 
372  if (pkt_type == PktType::ICMP && IsSegmentHealthCheckPacket(pkt_info,
373  intf)) {
374  return DIAG;
375  }
376 
377  if (pkt_type == PktType::ICMP && IsGwPacket(intf, pkt_info->ip_daddr)) {
378  return ICMP;
379  }
380 
381  // Look for IP6 packets that need NDP resolution
382  if (pkt_info->ip6 && hdr.cmd == AgentHdr::TRAP_RESOLVE) {
383  return ICMPV6;
384  }
385 
386  if (pkt_type == PktType::ICMPV6) {
387  if (hdr.cmd == AgentHdr::TRAP_HANDLE_DF) {
388  return ICMPV6_ERROR;
389  }
390  return ICMPV6;
391  }
392 
393  if (pkt_type == PktType::IGMP) {
394  return IGMP;
395  }
396 
397  if(pkt_info->ip6 && hdr.cmd == AgentHdr::TRAP_HANDLE_DF) {
398  return ICMPV6_ERROR;
399  }
400 
401  if (pkt_info->ip && hdr.cmd == AgentHdr::TRAP_HANDLE_DF) {
402  return ICMP_ERROR;
403  }
404 
405  if (hdr.cmd == AgentHdr::TRAP_DIAG && (pkt_info->ip || pkt_info->ip6)) {
406  return DIAG;
407  }
408 
409  return INVALID;
410 }
411 
412 void PktHandler::HandleRcvPkt(const AgentHdr &hdr, const PacketBufferPtr &buff){
413  // Enqueue packets to a workqueue to decouple from ASIO and run in
414  // exclusion with DB
415  boost::shared_ptr<PacketBufferEnqueueItem>
416  info(new PacketBufferEnqueueItem(hdr, buff));
417 
418  // BFD Keepalive packets are enqueued to a seperate work queue
419  // so that its job run without dependence on dB tasks
420  if (IsBfdkeepalivePkt(hdr)) {
422  } else {
423  work_queue_.Enqueue(info);
424  }
425 }
426 
427 bool PktHandler::ProcessPacket(boost::shared_ptr<PacketBufferEnqueueItem> item) {
429  const AgentHdr &hdr = item->hdr;
430  const PacketBufferPtr &buff = item->buff;
431  boost::shared_ptr<PktInfo> pkt_info (new PktInfo(buff));
432  uint8_t *pkt = buff->data();
433  PktModuleName mod = ParsePacket(hdr, pkt_info.get(), pkt);
434  PktModuleEnqueue(mod, hdr, pkt_info, pkt);
435  if (mod == INVALID) {
436  pkt_info.reset();
437  }
438 
439  return true;
440 }
441 // Process BFD keepalives (BFD packets with state 'UP') in a seperate task
442 // that is independent of Db Task
443 bool PktHandler::ProcessBfdDataPacket(boost::shared_ptr<PacketBufferEnqueueItem> item) {
444  const AgentHdr &hdr = item->hdr;
445  const PacketBufferPtr &buff = item->buff;
446  uint8_t *pkt = buff->data();
447  PktModuleName mod;
448 
449  // In certain Agent restart race condition, Agent would restart but
450  // vrouter is not in sync yet with agent restart. In this condition
451  // there could be BFD packets from the prior session could be trapped
452  // in vrouter and injected to the Agent's PKT0 i/f So, don't process
453  // BFD packets received, prior to agent init done.
454  if (!bfd_keepalive_proto_ || (agent_->init_done() == false)) {
455  PKT_TRACE(Err, "BFD proto_list is not Initialized. Ignoring");
456  return true;
457  }
458 
459  boost::shared_ptr<PktInfo> pkt_info (new PktInfo(buff));
460  mod = ParseBfdDataPacket(hdr, pkt_info.get(), pkt);
461  if (mod == BFD) {
462  pkt_info->is_bfd_keepalive = true;
463  pkt_info->packet_buffer()->set_module(mod);
464  bfd_keepalive_proto_->Enqueue(pkt_info);
465  proto_list_.at(BFD)->ProcessStats(PktStatsType::PKT_RX_ENQUEUE);
466  } else {
468  pkt_info.reset();
469  }
470  return true;
471 }
472 
474  boost::shared_ptr<PktInfo> pkt_info,
475  uint8_t * pkt) {
476  pkt_info->packet_buffer()->set_module(mod);
477  stats_.PktRcvd(mod);
478  if (mod == INVALID) {
480  pkt_trace_.at(mod).AddPktTrace(PktTrace::In, pkt_info->len, pkt, &hdr);
481  return;
482  }
483  Enqueue(mod, pkt_info);
484 }
485 
486 // Compute L2/L3 forwarding mode for pacekt.
487 // Forwarding mode is L3 if,
488 // - Packet uses L3 label
489 // - DMAC in packet is VRRP Mac or VHOST MAC or receiving physical interface MAC
490 // Else forwarding mode is L2
492  const Interface *intf) const {
493  if (pkt_info->tunnel.type.GetType() == TunnelType::MPLS_GRE ||
494  pkt_info->tunnel.type.GetType() == TunnelType::MPLS_UDP) {
495  return pkt_info->l3_label;
496  }
497 
498  if (pkt_info->dmac == agent_->vrrp_mac()) {
499  return true;
500  }
501 
502  if (pkt_info->dmac == agent_->vhost_interface()->mac()) {
503  return true;
504  }
505 
506  if (intf && intf->type() == Interface::PHYSICAL &&
507  pkt_info->dmac == intf->mac()) {
508  return true;
509  }
510 
511  return false;
512 }
513 
514 void PktHandler::SetOuterIp(PktInfo *pkt_info, uint8_t *pkt) {
515  if (pkt_info->ether_type != ETHERTYPE_IP) {
516  return;
517  }
518  struct ip *ip_hdr = (struct ip *)pkt;
519  pkt_info->tunnel.ip = ip_hdr;
520  pkt_info->tunnel.ip_saddr = ntohl(ip_hdr->ip_src.s_addr);
521  pkt_info->tunnel.ip_daddr = ntohl(ip_hdr->ip_dst.s_addr);
522 }
523 
525  pkt_info->tunnel.eth = pkt_info->eth;
526 }
527 
528 
529 int PktHandler::ParseEthernetHeader(PktInfo *pkt_info, uint8_t *pkt) {
530  int len = 0;
531  pkt_info->eth = (struct ether_header *) (pkt + len);
532  pkt_info->smac = MacAddress(pkt_info->eth->ether_shost);
533  pkt_info->dmac = MacAddress(pkt_info->eth->ether_dhost);
534  pkt_info->ether_type = ntohs(pkt_info->eth->ether_type);
535  len += sizeof(struct ether_header);
536 
537  //strip service vlan and customer vlan in packet
538  while (pkt_info->ether_type == ETHERTYPE_VLAN ||
539  pkt_info->ether_type == ETHERTYPE_QINQ) {
540  pkt_info->ether_type = ntohs(*((uint16_t *)(pkt + len + 2)));
541  len += VLAN_HDR_LEN;
542  }
543 
544  if (pkt_info->ether_type == ETHERTYPE_PBB) {
545  //Parse inner payload
546  pkt_info->pbb_header = (uint32_t *)(pkt + len);
547  pkt_info->b_smac = pkt_info->smac;
548  pkt_info->b_dmac = pkt_info->dmac;
549  pkt_info->i_sid = ntohl(*(pkt_info->pbb_header)) & 0x00FFFFFF;
550  len += ParseEthernetHeader(pkt_info, pkt + len + PBB_HEADER_LEN);
551  }
552 
553  return len;
554 }
555 
557  uint8_t *pkt) {
558  int len = 0;
559  uint16_t ip_payload_len = 0;
560  if (pkt_info->ether_type == ETHERTYPE_IP) {
561  struct ip *ip = (struct ip *)(pkt + len);
562  pkt_info->ip = ip;
563  pkt_info->family = Address::INET;
564  pkt_info->ip_saddr = IpAddress(Ip4Address(ntohl(ip->ip_src.s_addr)));
565  pkt_info->ip_daddr = IpAddress(Ip4Address(ntohl(ip->ip_dst.s_addr)));
566  pkt_info->ip_proto = ip->ip_p;
567  pkt_info->ttl = ip->ip_ttl;
568  uint8_t ip_header_len = (ip->ip_hl << 2);
569  ip_payload_len = ip->ip_len - ip_header_len;
570  len += ip_header_len;
571  } else if (pkt_info->ether_type == ETHERTYPE_IPV6) {
572  pkt_info->family = Address::INET6;
573  ip6_hdr *ip = (ip6_hdr *)(pkt + len);
574  pkt_info->ip6 = ip;
575  pkt_info->ip = NULL;
576  Ip6Address::bytes_type addr;
577 
578  for (int i = 0; i < 16; i++) {
579  addr[i] = ip->ip6_src.s6_addr[i];
580  }
581  pkt_info->ip_saddr = IpAddress(Ip6Address(addr));
582 
583  for (int i = 0; i < 16; i++) {
584  addr[i] = ip->ip6_dst.s6_addr[i];
585  }
586  pkt_info->ip_daddr = IpAddress(Ip6Address(addr));
587  pkt_info->ttl = ip->ip6_hlim;
588 
589  uint8_t proto = ip->ip6_ctlun.ip6_un1.ip6_un1_nxt;
590  len += sizeof(ip6_hdr);
591  if (proto == IPPROTO_FRAGMENT) {
592  ip6_frag *nxt = (ip6_frag *)(pkt + len);
593  proto = nxt->ip6f_nxt;
594  len += sizeof(ip6_frag);
595  }
596 
597  pkt_info->ip_proto = proto;
598  } else {
599  LOG(ERROR,
600  "Error EthType = Non IP/IPv6. BackTrace: " << AgentBackTrace(1));
602  return -1;
603  }
604 
605  switch (pkt_info->ip_proto) {
606  case IPPROTO_UDP : {
607  pkt_info->transp.udp = (udphdr *) (pkt + len);
608  len += sizeof(udphdr);
609  pkt_info->data = (pkt + len);
610 
611  pkt_info->dport = ntohs(pkt_info->transp.udp->uh_dport);
612  pkt_info->sport = ntohs(pkt_info->transp.udp->uh_sport);
613  pkt_type = PktType::UDP;
614  break;
615  }
616 
617  case IPPROTO_TCP : {
618  pkt_info->transp.tcp = (tcphdr *) (pkt + len);
619  len += sizeof(tcphdr);
620  pkt_info->data = (pkt + len);
621 
622  pkt_info->dport = ntohs(pkt_info->transp.tcp->th_dport);
623  pkt_info->sport = ntohs(pkt_info->transp.tcp->th_sport);
624  pkt_info->tcp_ack = pkt_info->transp.tcp->th_flags & TH_ACK;
625  pkt_type = PktType::TCP;
626  break;
627  }
628 
629  case IPPROTO_SCTP : {
630  pkt_info->transp.sctp = (sctphdr *) (pkt + len);
631  len += sizeof(sctphdr);
632  pkt_info->data = (pkt + len);
633  pkt_info->dport = ntohs(pkt_info->transp.sctp->th_dport);
634  pkt_info->sport = ntohs(pkt_info->transp.sctp->th_sport);
635  pkt_type = PktType::SCTP;
636  break;
637  }
638 
639  case IPPROTO_ICMP: {
640  pkt_info->transp.icmp = (struct icmp *) (pkt + len);
641  pkt_type = PktType::ICMP;
642 
643  struct icmp *icmp = (struct icmp *)(pkt + len);
644  pkt_info->icmp_chksum = icmp->icmp_cksum;
645  pkt_info->dport = htons(icmp->icmp_type);
646  if (icmp->icmp_type == ICMP_ECHO || icmp->icmp_type == ICMP_ECHOREPLY) {
647  pkt_info->dport = ICMP_ECHOREPLY;
648  pkt_info->sport = htons(icmp->icmp_id);
649  pkt_info->data = (pkt + len + ICMP_MINLEN);
650  uint16_t icmp_payload_len = ip_payload_len - ICMP_MINLEN;
651  if (icmp_payload_len >= sizeof(AgentDiagPktData)) {
652  AgentDiagPktData *ad = (AgentDiagPktData *)pkt_info->data;
653  string value(ad->data_, (sizeof(ad->data_) - 1));
654  if (value.compare(0, (sizeof(ad->data_) - 1),
655  DiagTable::kDiagData) == 0) {
656  pkt_info->is_segment_hc_pkt = true;
657  }
658  }
659  } else if (IsFlowPacket(pkt_info) &&
660  ((icmp->icmp_type == ICMP_DEST_UNREACH) ||
661  (icmp->icmp_type == ICMP_TIME_EXCEEDED))) {
662  //Agent has to look at inner payload
663  //and recalculate the parameter
664  //Handle this only for packets requiring flow miss
665  if(ParseIpPacket(pkt_info, pkt_type, pkt + len + sizeof(icmp)) == -1) {
666  return -1;
667  }
668  //Swap the key parameter, which would be used as key
669  IpAddress src_ip = pkt_info->ip_saddr;
670  pkt_info->ip_saddr = pkt_info->ip_daddr;
671  pkt_info->ip_daddr = src_ip;
672  if (pkt_info->ip_proto != IPPROTO_ICMP) {
673  uint16_t port = pkt_info->sport;
674  pkt_info->sport = pkt_info->dport;
675  pkt_info->dport = port;
676  }
677  } else {
678  pkt_info->sport = 0;
679  }
680  break;
681  }
682 
683  case IPPROTO_ICMPV6: {
684  pkt_type = PktType::ICMPV6;
685  icmp6_hdr *icmp = (icmp6_hdr *)(pkt + len);
686  pkt_info->transp.icmp6 = icmp;
687 
688  pkt_info->dport = htons(icmp->icmp6_type);
689  if (icmp->icmp6_type == ICMP6_ECHO_REQUEST ||
690  icmp->icmp6_type == ICMP6_ECHO_REPLY) {
691  pkt_info->dport = ICMP6_ECHO_REPLY;
692  pkt_info->sport = htons(icmp->icmp6_id);
693  } else if (IsFlowPacket(pkt_info) &&
694  icmp->icmp6_type < ICMP6_ECHO_REQUEST) {
695  //Agent has to look at inner payload
696  //and recalculate the parameter
697  //Handle this only for packets requiring flow miss
698  if(ParseIpPacket(pkt_info, pkt_type, pkt + len + sizeof(icmp)) == -1) {
699  return -1;
700  }
701  //Swap the key parameter, which would be used as key
702  IpAddress src_ip = pkt_info->ip_saddr;
703  pkt_info->ip_saddr = pkt_info->ip_daddr;
704  pkt_info->ip_daddr = src_ip;
705  if (pkt_info->ip_proto != IPPROTO_ICMPV6) {
706  uint16_t port = pkt_info->sport;
707  pkt_info->sport = pkt_info->dport;
708  pkt_info->dport = port;
709  }
710  } else {
711  pkt_info->sport = 0;
712  }
713  break;
714  }
715 
716  case IPPROTO_IGMP: {
717  pkt_info->transp.igmp = (struct igmp *) (pkt + len);
718  pkt_type = PktType::IGMP;
719 
720  pkt_info->dport = 0;
721  pkt_info->sport = 0;
722  pkt_info->data = (pkt + len);
723  break;
724  }
725 
726  default: {
727  pkt_type = PktType::IP;
728  pkt_info->dport = 0;
729  pkt_info->sport = 0;
730  break;
731  }
732  }
733 
734  return len;
735 }
736 
737 int PktHandler::ParseControlWord(PktInfo *pkt_info, uint8_t *pkt,
738  const MplsLabel *mpls) {
739  uint32_t ret = 0;
740  if (mpls->IsFabricMulticastReservedLabel() == true) {
741  //Check if there is a control word
742  uint32_t *control_word = (uint32_t *)(pkt);
743  if (*control_word == kMulticastControlWord) {
744  pkt_info->l3_label = false;
745  ret += kMulticastControlWordSize + sizeof(VxlanHdr) +
746  sizeof(udphdr) + sizeof(ip);
747  }
748  } else if (pkt_info->l3_label == false) {
749  bool layer2_control_word = false;
750  const InterfaceNH *intf_nh =
751  dynamic_cast<const InterfaceNH *>(mpls->nexthop());
752  if (intf_nh && intf_nh->layer2_control_word()) {
753  layer2_control_word = true;
754  }
755 
756  const CompositeNH *comp_nh =
757  dynamic_cast<const CompositeNH *>(mpls->nexthop());
758  if (comp_nh && comp_nh->layer2_control_word()) {
759  layer2_control_word = true;
760  }
761 
762  const VrfNH *vrf_nh =
763  dynamic_cast<const VrfNH *>(mpls->nexthop());
764  if (vrf_nh && vrf_nh->layer2_control_word()) {
765  layer2_control_word = true;
766  }
767 
768  //Check if there is a control word
769  uint32_t *control_word = (uint32_t *)(pkt);
770  if (layer2_control_word && *control_word == kMulticastControlWord) {
772  }
773  }
774 
775  return ret;
776 }
777 
778 int PktHandler::ParseMplsHdr(PktInfo *pkt_info, uint8_t *pkt) {
779  MplsHdr *hdr = (MplsHdr *)(pkt);
780 
781  // MPLS Header validation. Check for,
782  // - There is single label
783  uint32_t mpls_host = ntohl(hdr->hdr);
784  pkt_info->tunnel.label = (mpls_host & 0xFFFFF000) >> 12;
785  uint32_t ret = sizeof(MplsHdr);
786 
787  if ((mpls_host & 0x100) == 0) {
788  // interpret outer label 0xffffff as no label
789  if (((mpls_host & 0xFFFFF000) >> 12) !=
792  PKT_TRACE(Err, "Unexpected MPLS Label Stack. Ignoring");
793  return -1;
794  }
795  hdr = (MplsHdr *) (pkt + 4);
796  mpls_host = ntohl(hdr->hdr);
797  pkt_info->tunnel.label = (mpls_host & 0xFFFFF000) >> 12;
798  if ((mpls_host & 0x100) == 0) {
800  PKT_TRACE(Err, "Unexpected MPLS Label Stack. Ignoring");
801  return -1;
802  }
803  ret += sizeof(MplsHdr);
804 
805  }
806 
807  uint32_t label = pkt_info->tunnel.label;
808  MplsLabelKey mpls_key(label);
809 
810  const MplsLabel *mpls = static_cast<const MplsLabel *>(
811  agent_->mpls_table()->FindActiveEntry(&mpls_key));
812  if (mpls == NULL) {
813  PKT_TRACE(Err, "Invalid MPLS Label <" << label << ">. Ignoring");
815  return -1;
816  }
817 
818  pkt_info->l3_label = true;
819  const InterfaceNH *nh = dynamic_cast<const InterfaceNH *>(mpls->nexthop());
820  if (nh && nh->IsBridge()) {
821  pkt_info->l3_label = false;
822  }
823 
824  const CompositeNH *cnh = dynamic_cast<const CompositeNH *>(mpls->nexthop());
825  if (cnh && cnh->composite_nh_type() != Composite::LOCAL_ECMP) {
826  pkt_info->l3_label = false;
827  }
828 
829  const VrfNH *vrf_nh = dynamic_cast<const VrfNH *>(mpls->nexthop());
830  if (vrf_nh && vrf_nh->bridge_nh() == true) {
831  pkt_info->l3_label = false;
832  }
833 
834  ret += ParseControlWord(pkt_info, pkt + ret, mpls);
835  return ret;
836 }
837 
838 // Parse MPLSoGRE header
839 int PktHandler::ParseMPLSoGRE(PktInfo *pkt_info, uint8_t *pkt) {
840  GreHdr *gre = (GreHdr *)(pkt);
841  if (gre->protocol != ntohs(VR_GRE_PROTO_MPLS)) {
842  PKT_TRACE(Err, "Non-MPLS protocol <" << ntohs(gre->protocol) <<
843  "> in GRE header");
844  return -1;
845  }
846 
847  int len = sizeof(GreHdr);
848 
849  int tmp;
850  tmp = ParseMplsHdr(pkt_info, (pkt + len));
851  if (tmp < 0) {
852  return tmp;
853  }
854  len += tmp;
855 
856  if (pkt_info->l3_label == false) {
857  tmp = ParseEthernetHeader(pkt_info, (pkt + len));
858  if (tmp < 0)
859  return tmp;
860  len += tmp;
861  }
862 
864  return (len);
865 }
866 
867 int PktHandler::ParseMPLSoUDP(PktInfo *pkt_info, uint8_t *pkt) {
868  int len = ParseMplsHdr(pkt_info, pkt);
869  if (len < 0) {
870  return len;
871  }
872 
873  if (pkt_info->l3_label == false) {
874  len += ParseEthernetHeader(pkt_info, (pkt + len));
875  }
876 
878  return len;
879 }
880 
881 int PktHandler::ParseVxlan(PktInfo *pkt_info, uint8_t *pkt) {
882  VxlanHdr *vxlan = (VxlanHdr *)(pkt);
883  pkt_info->tunnel.vxlan_id = htonl(vxlan->vxlan_id) >> 8;
884 
885  int len = sizeof(vxlan);
886  len += ParseEthernetHeader(pkt_info, (pkt + len));
887 
889  pkt_info->l3_label = false;
890  return len;
891 }
892 
893 int PktHandler::ParseUDPTunnels(PktInfo *pkt_info, uint8_t *pkt) {
894  int len = 0;
895  if (pkt_info->dport == VXLAN_UDP_DEST_PORT)
896  len = ParseVxlan(pkt_info, (pkt + len));
897  else if (pkt_info->dport == MPLS_OVER_UDP_DEST_PORT ||
898  pkt_info->dport == IANA_MPLS_OVER_UDP_DEST_PORT)
899  len = ParseMPLSoUDP(pkt_info, (pkt + len));
900 
901  return len;
902 }
903 
905  // For ICMP, IGMP, make sure IP is IPv4, else fail the parsing
906  // so that we don't go ahead and access the ip header later
907  if (((pkt_info->ip_proto == IPPROTO_ICMP) ||
908  (pkt_info->ip_proto == IPPROTO_IGMP)) && (!pkt_info->ip)) {
909  return false;
910  }
911  // If ip proto is ICMPv6, then make sure IP is IPv6, else fail
912  // the parsing so that we don't go ahead and access the ip6 header
913  // later
914  if ((pkt_info->ip_proto == IPPROTO_ICMPV6) && (!pkt_info->ip6)) {
915  return false;
916  }
917  return true;
918 }
919 
921  PktType::Type &pkt_type, uint8_t *pkt) {
922  int len = 0, ret = 0;
923  bool pkt_ok;
924 
925  // get to the actual packet header
926  len += ParseEthernetHeader(pkt_info, (pkt + len));
927 
928  // Parse payload
929  if (pkt_info->ether_type == ETHERTYPE_ARP) {
930  pkt_info->arp = (ether_arp *) (pkt + len);
931  pkt_type = PktType::ARP;
932  union {
933  uint8_t data[sizeof(in_addr_t)];
934  in_addr_t addr;
935  } bytes;
936  memcpy(bytes.data, pkt_info->arp->arp_spa, sizeof(in_addr_t));
937  in_addr_t spa = ntohl(bytes.addr);
938  pkt_info->ip_saddr = IpAddress(Ip4Address(spa));
939  return len;
940  }
941 
942  // Identify NON-IP Packets
943  if (pkt_info->ether_type != ETHERTYPE_IP &&
944  pkt_info->ether_type != ETHERTYPE_IPV6) {
945  pkt_info->data = (pkt + len);
946  pkt_type = PktType::NON_IP;
947  return len;
948  }
949  // Copy IP fields from outer header assuming tunnel is present. If tunnel
950  // is not present, the values here will be ignored
951  SetOuterMac(pkt_info);
952  SetOuterIp(pkt_info, (pkt + len));
953 
954  // IP Packets
955  ret = ParseIpPacket(pkt_info, pkt_type, (pkt + len));
956  if(ret == -1) {
957  return -1;
958  }
959  len += ret;
960 
961  if (!ValidateIpPacket(pkt_info)) {
963  return -1;
964  }
965 
966  // If packet is an IP fragment and not flow trap, ignore it
967  if (IgnoreFragmentedPacket(pkt_info)) {
969  return -1;
970  }
971 
972  // If it is a packet from TOR that we serve, dont parse any further
973  if (IsManagedTORPacket(intf, pkt_info, pkt_type, (pkt + len), &pkt_ok)) {
974  return len;
975  } else if (!pkt_ok) {
976  // invalid pkt received from tor
978  return -1;
979  }
980 
981  if (IsDiagPacket(pkt_info) &&
982  (pkt_info->agent_hdr.cmd != AgentHdr::TRAP_ROUTER_ALERT)) {
983  return len;
984  }
985 
986  // If tunneling is not enabled on interface or if it is a DHCP packet,
987  // dont parse any further
988 // if (intf->IsTunnelEnabled() == false || IsDHCPPacket(pkt_info)) {
989  if (intf->IsTunnelEnabled() == false) {
991  return len;
992  }
993  else if (IsDHCPPacket(pkt_info)) {
994  return len;
995  }
996 
997  int tunnel_len = 0;
998  // Do tunnel processing only if IP-DA is ours
999  if (pkt_info->family == Address::INET &&
1000  pkt_info->ip_daddr.to_v4() == agent_->router_id()) {
1001  // Look for supported headers
1002  switch (pkt_info->ip_proto) {
1003  case IPPROTO_GRE :
1004  // Parse MPLSoGRE tunnel
1005  tunnel_len = ParseMPLSoGRE(pkt_info, (pkt + len));
1006  break;
1007 
1008  case IPPROTO_UDP:
1009  // Parse MPLSoUDP tunnel
1010  tunnel_len = ParseUDPTunnels(pkt_info, (pkt + len));
1011  break;
1012 
1013  default:
1014  break;
1015  }
1016  }
1017 
1018  if (tunnel_len < 0) {
1019  // Found tunnel packet, but error in decoding
1020  pkt_type = PktType::INVALID;
1022  return tunnel_len;
1023  }
1024 
1025  if (tunnel_len == 0) {
1026  return len;
1027  }
1028 
1029  len += tunnel_len;
1030 
1031  // Find IPv4/IPv6 Packet based on first nibble in payload
1032  if (((pkt + len)[0] & 0x60) == 0x60) {
1033  pkt_info->ether_type = ETHERTYPE_IPV6;
1034  } else {
1035  pkt_info->ether_type = ETHERTYPE_IP;
1036  }
1037 
1038 
1039  ret = ParseIpPacket(pkt_info, pkt_type, (pkt + len));
1040  if(ret == -1) {
1041  return -1;
1042  }
1043  len += ret;
1044 
1045  // validate inner iphdr
1046  if (!ValidateIpPacket(pkt_info)) {
1048  return -1;
1049  }
1050 
1051  return len;
1052 }
1053 
1054 // Enqueue an inter-task message to the specified module
1056  if (mod < MAX_MODULES) {
1057  boost::shared_ptr<PktInfo> pkt_info(new PktInfo(mod, msg));
1058  if (!(proto_list_.at(mod)->Enqueue(pkt_info))) {
1059  PKT_TRACE(Err, "Threshold exceeded while enqueuing IPC Message <" <<
1060  mod << ">");
1061  }
1062  }
1063 }
1064 
1066  if (pkt_info->ip) {
1067  uint16_t offset = htons(pkt_info->ip->ip_off);
1068  if (((offset & IP_MF) || (offset & IP_OFFMASK)) &&
1069  !IsFlowPacket(pkt_info))
1070  return true;
1071  } else if (pkt_info->ip6) {
1072  uint8_t proto = pkt_info->ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
1073  if (proto == IPPROTO_FRAGMENT) {
1074  if (IsFlowPacket(pkt_info) ||
1075  pkt_info->agent_hdr.cmd == AgentHdr::TRAP_HANDLE_DF) {
1076  return false;
1077  } else {
1078  return true;
1079  }
1080  }
1081  }
1082 
1083  return false;
1084 }
1085 
1087  // Do not consider source port in case we are looking at UDP tunnel header
1088  if (pkt_info->dport == VXLAN_UDP_DEST_PORT ||
1089  pkt_info->dport == MPLS_OVER_UDP_DEST_PORT ||
1090  pkt_info->dport == IANA_MPLS_OVER_UDP_DEST_PORT) {
1091  return false;
1092  }
1093 
1094  if (pkt_info->dport == DHCP_SERVER_PORT ||
1095  pkt_info->sport == DHCP_CLIENT_PORT) {
1096  // we dont handle DHCPv6 coming from fabric
1097  return true;
1098  }
1099  return false;
1100 }
1101 
1102 bool PktHandler::IsToRDevice(uint32_t vrf_id, const IpAddress &ip) {
1103  if (agent()->tsn_enabled() == false)
1104  return false;
1105 
1106  if (ip.is_v4() == false)
1107  return false;
1108  Ip4Address ip4 = ip.to_v4();
1109 
1110  VrfEntry *vrf = agent()->vrf_table()->FindVrfFromId(vrf_id);
1111  if (vrf == NULL)
1112  return false;
1113 
1114  BridgeAgentRouteTable *table = static_cast<BridgeAgentRouteTable *>
1115  (vrf->GetBridgeRouteTable());
1116  if (table == NULL)
1117  return false;
1118 
1120  if (rt == NULL)
1121  return false;
1122 
1123  const CompositeNH *nh = dynamic_cast<const CompositeNH *>
1124  (rt->GetActiveNextHop());
1125  if (nh == NULL)
1126  return false;
1127 
1128  ComponentNHList::const_iterator it = nh->begin();
1129  while (it != nh->end()) {
1130  const CompositeNH *tor_nh = dynamic_cast<const CompositeNH *>
1131  ((*it)->nh());
1132  if (tor_nh == NULL) {
1133  it++;
1134  continue;
1135  }
1136 
1137  if (tor_nh->composite_nh_type() != Composite::TOR &&
1138  tor_nh->composite_nh_type() != Composite::EVPN) {
1139  it++;
1140  continue;
1141  }
1142 
1143  ComponentNHList::const_iterator tor_it = tor_nh->begin();
1144  while (tor_it != tor_nh->end()) {
1145  const TunnelNH *tun_nh = dynamic_cast<const TunnelNH *>
1146  ((*tor_it)->nh());
1147  if (tun_nh == NULL) {
1148  tor_it++;
1149  continue;
1150  }
1151  if (*tun_nh->GetDip() == ip4) {
1152  return true;
1153  }
1154  tor_it++;
1155  }
1156 
1157  it++;
1158  }
1159 
1160  return false;
1161 }
1162 
1163 // We can receive DHCP / DNS packets on physical port from TOR ports managed
1164 // by a TOR services node. Check if the source mac is the mac address of a
1165 // VM interface available in the node.
1167  PktType::Type &pkt_type, uint8_t *pkt, bool *pkt_ok) {
1168  *pkt_ok = true;
1169  if (intf->type() != Interface::PHYSICAL) {
1170  return false;
1171  }
1172 
1173  if (pkt_type != PktType::UDP || pkt_info->dport != VXLAN_UDP_DEST_PORT)
1174  return false;
1175 
1176  // Get VXLAN id and point to original L2 frame after the VXLAN header
1177  pkt += 8;
1178 
1179  // get to the actual packet header
1180  pkt += ParseEthernetHeader(pkt_info, pkt);
1181 
1182  ether_addr addr;
1183  memcpy(addr.ether_addr_octet, pkt_info->eth->ether_shost, ETH_ALEN);
1184  MacAddress address(addr);
1185  const VrfEntry *vrf = agent_->vrf_table()->
1186  FindVrfFromId(pkt_info->agent_hdr.vrf);
1187  if (vrf == NULL)
1188  return false;
1189  BridgeAgentRouteTable *bridge_table =
1190  dynamic_cast<BridgeAgentRouteTable *>(vrf->GetBridgeRouteTable());
1191  if(bridge_table == NULL) {
1192  LOG(ERROR,
1193  "Error bridge_table == NULL. BackTrace: " << AgentBackTrace(1));
1194  _Exit(0);
1195  }
1196  const VmInterface *vm_intf = bridge_table->FindVmFromDhcpBinding(address);
1197  if (vm_intf == NULL) {
1198  return false;
1199  }
1200 
1201  if (IsToRDevice(vm_intf->vrf_id(), pkt_info->ip_saddr) == false) {
1202  return false;
1203  }
1204 
1205  // update agent_hdr to reflect the VM interface data
1206  // cmd_param is set to physical interface id
1208  pkt_info->agent_hdr.cmd_param = pkt_info->agent_hdr.ifindex;
1209  pkt_info->agent_hdr.ifindex = vm_intf->id();
1210 
1211  // Parse payload
1212  if (pkt_info->ether_type == ETHERTYPE_ARP) {
1213  pkt_info->arp = (ether_arp *) pkt;
1214  pkt_type = PktType::ARP;
1215  return true;
1216  }
1217 
1218  // Identify NON-IP Packets
1219  if (pkt_info->ether_type != ETHERTYPE_IP &&
1220  pkt_info->ether_type != ETHERTYPE_IPV6) {
1221  pkt_info->data = pkt;
1222  pkt_type = PktType::NON_IP;
1223  return true;
1224  }
1225 
1226  // IP Packets
1227  if(ParseIpPacket(pkt_info, pkt_type, pkt) == -1) {
1228  *pkt_ok = false; //Don't process any further
1229  return false;
1230  }
1231  if (!ValidateIpPacket(pkt_info)) {
1232  *pkt_ok = false;
1233  return false;
1234  }
1235  return true;
1236 }
1237 
1239  if (pkt_info->agent_hdr.cmd == AgentHdr::TRAP_FLOW_MISS ||
1241  return true;
1242  }
1243  return false;
1244 }
1245 
1246 bool PktHandler::IsFlowPacket(const AgentHdr &agent_hdr) {
1247  if (agent_hdr.cmd == AgentHdr::TRAP_FLOW_MISS ||
1248  agent_hdr.cmd == AgentHdr::TRAP_FLOW_ACTION_HOLD) {
1249  return true;
1250  }
1251  return false;
1252 }
1253 
1255  if (pkt_info->agent_hdr.cmd == AgentHdr::TRAP_ZERO_TTL ||
1257  || pkt_info->agent_hdr.cmd == AgentHdr::TRAP_ROUTER_ALERT)
1258  return true;
1259  return false;
1260 }
1261 
1262 // Check if the packet is destined to the VM's default GW
1263 bool PktHandler::IsGwPacket(const Interface *intf, const IpAddress &dst_ip) {
1264  if (!intf || intf->type() != Interface::VM_INTERFACE)
1265  return false;
1266 
1267  const VmInterface *vm_intf = static_cast<const VmInterface *>(intf);
1268  if (vm_intf->vmi_type() != VmInterface::GATEWAY) {
1269  //Gateway interface doesnt have IP address
1270  if (dst_ip.is_v6() && vm_intf->primary_ip6_addr().is_unspecified())
1271  return false;
1272  else if (dst_ip.is_v4() && vm_intf->primary_ip_addr().is_unspecified())
1273  return false;
1274  }
1275  const VnEntry *vn = vm_intf->vn();
1276  if (vn) {
1277  const std::vector<VnIpam> &ipam = vn->GetVnIpam();
1278  for (unsigned int i = 0; i < ipam.size(); ++i) {
1279  if (dst_ip.is_v4()) {
1280  if (!ipam[i].IsV4()) {
1281  continue;
1282  }
1283  if (ipam[i].default_gw == dst_ip ||
1284  ipam[i].dns_server == dst_ip) {
1285  return true;
1286  }
1287  } else {
1288  if (!ipam[i].IsV6()) {
1289  continue;
1290  }
1291  if (ipam[i].default_gw == dst_ip ||
1292  ipam[i].dns_server == dst_ip) {
1293  return true;
1294  }
1295  }
1296 
1297  }
1298  }
1299 
1300  return false;
1301 }
1302 
1303 bool PktHandler::IsValidInterface(uint32_t ifindex, Interface **intrface) {
1304  Interface *intf = agent_->interface_table()->FindInterface(ifindex);
1305  if (intf == NULL) {
1306  PKT_TRACE(Err, "Invalid interface index <" << ifindex << ">");
1308  return false;
1309  }
1310 
1311  *intrface = intf;
1312  return true;
1313 }
1314 
1316  if (!cb.empty()) {
1317  PktTrace &pkt(pkt_trace_.at(mod));
1318  pkt.Iterate(cb);
1319  }
1320 }
1321 
1323  if (mod < MAX_MODULES)
1324  received[mod]++;
1325 }
1326 
1328  if (mod < MAX_MODULES)
1329  sent[mod]++;
1330 }
1331 
1333  if (mod < MAX_MODULES)
1334  q_threshold_exceeded[mod]++;
1335 }
1336 
1338 
1340  module(PktHandler::INVALID),
1341  pkt(buff->data()), len(buff->data_len()), max_pkt_len(buff->buffer_len()),
1342  data(), ipc(), family(Address::UNSPEC), type(PktType::INVALID), agent_hdr(),
1343  ether_type(-1), ip_saddr(), ip_daddr(), ip_proto(), sport(), dport(),
1344  ttl(0), icmp_chksum(0), tcp_ack(false), tunnel(),
1345  l3_label(false), is_bfd_keepalive(false), is_segment_hc_pkt(false),
1346  ignore_address(VmInterface::IGNORE_NONE), same_port_number(false),
1347  is_fat_flow_src_prefix(false), ip_ff_src_prefix(),
1348  is_fat_flow_dst_prefix(false), ip_ff_dst_prefix(),
1349  eth(), arp(), ip(), ip6(), packet_buffer_(buff) {
1350  transp.tcp = 0;
1351 }
1352 
1353 PktInfo::PktInfo(const PacketBufferPtr &buff, const AgentHdr &hdr) :
1354  pkt(buff->data()), len(buff->data_len()), max_pkt_len(buff->buffer_len()),
1355  data(), ipc(), family(Address::UNSPEC), type(PktType::INVALID),
1356  agent_hdr(hdr), ether_type(-1), ip_saddr(), ip_daddr(), ip_proto(), sport(),
1357  dport(), ttl(0), icmp_chksum(0), tcp_ack(false), tunnel(),
1358  l3_label(false), is_bfd_keepalive(false), is_segment_hc_pkt(false),
1359  ignore_address(VmInterface::IGNORE_NONE), same_port_number(false),
1360  is_fat_flow_src_prefix(false), ip_ff_src_prefix(),
1361  is_fat_flow_dst_prefix(false), ip_ff_dst_prefix(),
1362  eth(), arp(), ip(), ip6(), packet_buffer_(buff) {
1363  transp.tcp = 0;
1364 }
1365 
1366 PktInfo::PktInfo(Agent *agent, uint32_t buff_len, PktHandler::PktModuleName mod,
1367  uint32_t mdata) :
1368  module(mod),
1369  len(), max_pkt_len(), data(), ipc(), family(Address::UNSPEC),
1370  type(PktType::INVALID), agent_hdr(), ether_type(-1), ip_saddr(), ip_daddr(),
1371  ip_proto(), sport(), dport(), ttl(0), icmp_chksum(0), tcp_ack(false),
1372  tunnel(), l3_label(false), is_bfd_keepalive(false), is_segment_hc_pkt(false),
1373  ignore_address(VmInterface::IGNORE_NONE), same_port_number(false),
1374  is_fat_flow_src_prefix(false), ip_ff_src_prefix(),
1375  is_fat_flow_dst_prefix(false), ip_ff_dst_prefix(),
1376  eth(),arp(), ip(), ip6() {
1377 
1379  (module, buff_len, mdata);
1380  pkt = packet_buffer_->data();
1381  len = packet_buffer_->data_len();
1382  max_pkt_len = packet_buffer_->buffer_len();
1383 
1384  transp.tcp = 0;
1385 }
1386 
1388  module(mod),
1389  pkt(), len(), max_pkt_len(0), data(), ipc(msg), family(Address::UNSPEC),
1390  type(PktType::MESSAGE), agent_hdr(), ether_type(-1), ip_saddr(), ip_daddr(),
1391  ip_proto(), sport(), dport(), ttl(0), icmp_chksum(0), tcp_ack(false),
1392  tunnel(), l3_label(false), is_bfd_keepalive(false), is_segment_hc_pkt(false),
1393  ignore_address(VmInterface::IGNORE_NONE), same_port_number(false),
1394  is_fat_flow_src_prefix(false), ip_ff_src_prefix(),
1395  is_fat_flow_dst_prefix(false), ip_ff_dst_prefix(),
1396  eth(), arp(), ip(), ip6(), packet_buffer_() {
1397  transp.tcp = 0;
1398 }
1399 
1401 }
1402 
1404  return agent_hdr;
1405 }
1406 
1408  packet_buffer_.reset();
1409 }
1410 
1411 void PktInfo::AllocPacketBuffer(Agent *agent, uint32_t module, uint16_t len,
1412  uint32_t mdata) {
1414  (module, len, mdata);
1415  pkt = packet_buffer_->data();
1416  len = packet_buffer_->data_len();
1417  max_pkt_len = packet_buffer_->buffer_len();
1418 }
1419 
1420 void PktInfo::set_len(uint32_t x) {
1421  packet_buffer_->set_len(x);
1422  len = x;
1423 }
1424 
1426  eth = (struct ether_header *)(pkt);
1427  ip = (struct ip *)(eth + 1);
1428  transp.tcp = (struct tcphdr *)(ip + 1);
1429 }
1430 
1431 std::size_t PktInfo::hash(const Agent *agent,
1432  const EcmpLoadBalance &ecmp_load_balance) const {
1433  std::size_t seed = 0;
1434  // Bug: 1687879
1435  // Consider that source compute has 2 member ECMP - compute-1 and compute-2
1436  // Compute-1 is chosed in hash is even and Compute-2 is chosen if hash
1437  // is add.
1438  //
1439  // On Compute-1, the hash computation uses same 5-tuple and will always
1440  // result in even number. As a result, flows from Compute-1 will go to
1441  // even-numbered ECMP members and never odd-numbered members.
1442  // If Compute-2 happens to have only 2 members, all flows go to ecmp-index
1443  // 0 and never to 1
1444  //
1445  // Solution:
1446  // We need to ensure that hash computed in Compute-1 and Compute-2 are
1447  // different. We also want to have same hash on agent restarts. So, include
1448  // vhost-ip also to compute hash
1449  if (agent->params()->flow_use_rid_in_hash()) {
1450  boost::hash_combine(seed, agent->router_id().to_ulong());
1451  }
1452 
1453  if (family == Address::INET) {
1454  if (ecmp_load_balance.is_source_ip_set()) {
1455  boost::hash_combine(seed, ip_saddr.to_v4().to_ulong());
1456  }
1457  if (ecmp_load_balance.is_destination_ip_set()) {
1458  boost::hash_combine(seed, ip_daddr.to_v4().to_ulong());
1459  }
1460  } else if (family == Address::INET6) {
1461  if (ecmp_load_balance.is_source_ip_set()) {
1462  uint32_t words[4];
1463  memcpy(words, ip_saddr.to_v6().to_bytes().data(), sizeof(words));
1464  boost::hash_combine(seed, words[0]);
1465  boost::hash_combine(seed, words[1]);
1466  boost::hash_combine(seed, words[2]);
1467  boost::hash_combine(seed, words[3]);
1468  }
1469 
1470  if (ecmp_load_balance.is_destination_ip_set()) {
1471  uint32_t words[4];
1472  memcpy(words, ip_daddr.to_v6().to_bytes().data(), sizeof(words));
1473  boost::hash_combine(seed, words[0]);
1474  boost::hash_combine(seed, words[1]);
1475  boost::hash_combine(seed, words[2]);
1476  boost::hash_combine(seed, words[3]);
1477  }
1478  } else {
1479  assert(0);
1480  }
1481  if (ecmp_load_balance.is_ip_protocol_set()) {
1482  boost::hash_combine(seed, ip_proto);
1483  }
1484  if (ecmp_load_balance.is_source_port_set()) {
1485  boost::hash_combine(seed, sport);
1486  }
1487  if (ecmp_load_balance.is_destination_port_set()) {
1488  boost::hash_combine(seed, dport);
1489  }
1490 
1491  // When only the sport changes by 2, its observed that only the lower 32
1492  // bits of hash changes. Just hash combine upper and lower 32 bit numbers
1493  // to randomize in case of incremental sport numbers
1494  std::size_t hash = 0;
1495  boost::hash_combine(hash, (seed & 0xFFFFFFFF));
1496  boost::hash_combine(hash, (seed >> 16));
1497  return hash;
1498 }
1499 
1501  if (ip_proto == IPPROTO_UDP) {
1502  return ntohs(transp.udp->uh_ulen) - sizeof(udphdr);
1503  }
1504  return 0;
1505 }
1506 
1508  const PktInfo *pkt) {
1509  pkt_trace_.at(module).AddPktTrace(PktTrace::In, pkt->len, pkt->pkt,
1510  &pkt->agent_hdr);
1511 }
1512 
1514  boost::shared_ptr<PktInfo> pkt_info) {
1515  if (!(proto_list_.at(module)->Enqueue(pkt_info))) {
1516  stats_.PktQThresholdExceeded(module);
1517  }
1518  return;
1519 }
1520 
1522 void PktTrace::Pkt::Copy(Direction d, std::size_t l, uint8_t *msg,
1523  std::size_t pkt_trace_size, const AgentHdr *hdr) {
1524  uint16_t hdr_len = sizeof(AgentHdr);
1525  dir = d;
1526  len = l + hdr_len;
1527  memcpy(pkt, hdr, hdr_len);
1528  memcpy(pkt + hdr_len, msg, std::min(l, (pkt_trace_size - hdr_len)));
1529 }
1530 
1531 void PktTrace::AddPktTrace(Direction dir, std::size_t len, uint8_t *msg,
1532  const AgentHdr *hdr) {
1533  if (num_buffers_) {
1534  end_ = (end_ + 1) % num_buffers_;
1535  pkt_buffer_[end_].Copy(dir, len, msg, pkt_trace_size_, hdr);
1536  count_ = std::min((count_ + 1), (uint32_t) num_buffers_);
1537  }
1538 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
std::string AgentBackTrace(int skip=1)
Definition: agent.cc:1200
#define DNS_SERVER_PORT
Definition: bind_util.h:29
@ INET
Definition: address.h:27
@ INET6
Definition: address.h:28
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
bool flow_use_rid_in_hash() const
Definition: agent_param.h:433
const NextHop * GetActiveNextHop() const
Definition: agent_route.cc:883
void incr_pkt_fragments_dropped()
Definition: agent_stats.h:141
void incr_pkt_invalid_frm_tor()
Definition: agent_stats.h:153
void incr_pkt_invalid_ip_pkt()
Definition: agent_stats.h:147
void incr_pkt_dropped()
Definition: agent_stats.h:165
void incr_pkt_drop_due_to_invalid_ethertype()
Definition: agent_stats.h:159
void incr_pkt_drop_due_to_decode_error()
Definition: agent_stats.h:156
void incr_pkt_invalid_interface()
Definition: agent_stats.h:135
uint64_t pkt_drop_due_to_flow_trap() const
Definition: agent_stats.h:163
void incr_pkt_exceptions()
Definition: agent_stats.h:129
void incr_pkt_drop_due_to_disable_tnl()
Definition: agent_stats.h:150
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
bool MeasureQueueDelay()
Definition: agent.cc:1149
bool init_done() const
Definition: agent.h:1222
AgentParam * params() const
Definition: agent.h:1227
VrfTable * vrf_table() const
Definition: agent.h:488
NextHopTable * nexthop_table() const
Definition: agent.h:478
static const MacAddress & vrrp_mac()
Definition: agent.h:442
static Agent * GetInstance()
Definition: agent.h:439
const Interface * vhost_interface() const
Definition: agent.h:938
AgentStats * stats() const
Definition: agent.cc:885
Ip4Address router_id() const
Definition: agent.h:669
PktModule * pkt() const
Definition: agent.cc:969
MplsTable * mpls_table() const
Definition: agent.h:513
BridgeRouteEntry * FindRoute(const MacAddress &mac)
Definition: bridge_route.cc:73
const VmInterface * FindVmFromDhcpBinding(const MacAddress &mac)
bool layer2_control_word() const
Definition: nexthop.h:1919
ComponentNHList::const_iterator end() const
Definition: nexthop.h:1812
COMPOSITETYPE composite_nh_type() const
Definition: nexthop.h:1843
const Interface * GetFirstLocalEcmpMemberInterface() const
Definition: nexthop.cc:1838
ComponentNHList::const_iterator begin() const
Definition: nexthop.h:1808
virtual uint32_t EncapsulationLength() const =0
virtual int Send(const AgentHdr &hdr, const PacketBufferPtr &pkt)=0
static const std::string kDiagData
Definition: diag.h:108
bool is_ip_protocol_set() const
bool is_destination_port_set() const
bool is_destination_ip_set() const
bool is_source_ip_set() const
bool is_source_port_set() const
bool IsBridge() const
Definition: nexthop.h:1300
const Interface * GetInterface() const
Definition: nexthop.h:1294
bool layer2_control_word() const
Definition: nexthop.h:1360
const Interface * FindInterface(size_t index) const
Definition: interface.cc:323
@ VM_INTERFACE
Definition: interface.h:38
@ PHYSICAL
Definition: interface.h:32
const MacAddress & mac() const
Definition: interface.h:134
bool dhcp_enabled() const
Definition: interface.h:127
uint32_t vrf_id() const
Definition: interface.cc:621
bool IsTunnelEnabled() const
Definition: interface.h:112
bool dns_enabled() const
Definition: interface.h:129
bool dhcp_enabled_v6() const
Definition: interface.h:128
Type type() const
Definition: interface.h:115
const uint32_t id() const
Definition: interface.h:126
static const MacAddress & BroadcastMac()
Definition: mac_address.h:153
Definition: mpls.h:53
const NextHop * nexthop() const
Definition: mpls.h:81
bool IsFabricMulticastReservedLabel() const
Definition: mpls.cc:136
static const uint32_t kInvalidLabel
Definition: mpls.h:102
NextHop * FindNextHop(size_t index)
Definition: nexthop.cc:3448
@ VLAN
Definition: nexthop.h:356
@ COMPOSITE
Definition: nexthop.h:355
@ INTERFACE
Definition: nexthop.h:352
Type GetType() const
Definition: nexthop.h:406
PacketBufferPtr Allocate(uint32_t module, uint16_t len, uint32_t mdata)
static bool ComputeDirection(const Interface *intf)
uint32_t EncapHeaderLen() const
Definition: pkt_handler.cc:90
int ParseMplsHdr(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:778
bool IgnoreFragmentedPacket(PktInfo *pkt_info)
PktStats stats_
Definition: pkt_handler.h:365
bool IsManagedTORPacket(Interface *intf, PktInfo *pkt_info, PktType::Type &pkt_type, uint8_t *pkt, bool *pkt_ok)
int ParseUDPTunnels(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:893
int ParseControlWord(PktInfo *pkt_info, uint8_t *pkt, const MplsLabel *mpls)
Definition: pkt_handler.cc:737
Agent * agent() const
Definition: pkt_handler.h:317
int ParseVxlan(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:881
void SetOuterMac(PktInfo *pkt_info)
Definition: pkt_handler.cc:524
void PktModuleEnqueue(PktModuleName mod, const AgentHdr &hdr, boost::shared_ptr< PktInfo > pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:473
void Send(const AgentHdr &hdr, const PacketBufferPtr &buff)
Definition: pkt_handler.cc:95
PktModuleName ParseBfdDataPacket(const AgentHdr &hdr, PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:246
bool IsGwPacket(const Interface *intf, const IpAddress &dst_ip)
int ParseEthernetHeader(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:529
Proto * bfd_keepalive_proto_
Definition: pkt_handler.h:363
bool IsSegmentHealthCheckPacket(const PktInfo *pkt_info, const Interface *interface)
Definition: pkt_handler.cc:233
virtual ~PktHandler()
Definition: pkt_handler.cc:79
PktHandlerQueue work_queue_bfd_ka_
Definition: pkt_handler.h:372
void CalculatePortIP(PktInfo *pkt_info)
Definition: pkt_handler.cc:105
void SetOuterIp(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:514
bool ValidateIpPacket(PktInfo *pkt_info)
Definition: pkt_handler.cc:904
boost::function< void(PktTrace::Pkt &)> PktTraceCallback
Definition: pkt_handler.h:227
bool IsValidInterface(uint32_t ifindex, Interface **interface)
int ParseIpPacket(PktInfo *pkt_info, PktType::Type &pkt_type, uint8_t *ptr)
Definition: pkt_handler.cc:556
static const uint32_t kMulticastControlWord
Definition: pkt_handler.h:229
int ParseMPLSoUDP(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:867
bool IsBFDHealthCheckPacket(const PktInfo *pkt_info, const Interface *interface)
Definition: pkt_handler.cc:220
int ParseMPLSoGRE(PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:839
void HandleRcvPkt(const AgentHdr &hdr, const PacketBufferPtr &buff)
Definition: pkt_handler.cc:412
bool IsDiagPacket(PktInfo *pkt_info)
void AddPktTrace(PktModuleName module, PktTrace::Direction dir, const PktInfo *pkt)
void Enqueue(PktModuleName module, boost::shared_ptr< PktInfo > pkt_info)
int ParseUserPkt(PktInfo *pkt_info, Interface *intf, PktType::Type &pkt_type, uint8_t *pkt)
Definition: pkt_handler.cc:920
boost::array< PktTrace, MAX_MODULES > pkt_trace_
Definition: pkt_handler.h:366
Agent * agent_
Definition: pkt_handler.h:369
PktHandler(Agent *, PktModule *pkt_module)
Definition: pkt_handler.cc:58
boost::array< Proto *, MAX_MODULES > proto_list_
Definition: pkt_handler.h:362
bool ComputeForwardingMode(PktInfo *pkt_info, const Interface *intf) const
Definition: pkt_handler.cc:491
void SendMessage(PktModuleName mod, InterTaskMsg *msg)
bool ProcessPacket(boost::shared_ptr< PacketBufferEnqueueItem > item)
Definition: pkt_handler.cc:427
PktModuleName ParsePacket(const AgentHdr &hdr, PktInfo *pkt_info, uint8_t *pkt)
Definition: pkt_handler.cc:281
void Register(PktModuleName type, RcvQueueFunc cb)
static const uint32_t kMulticastControlWordSize
Definition: pkt_handler.h:230
bool ProcessBfdDataPacket(boost::shared_ptr< PacketBufferEnqueueItem > item)
Definition: pkt_handler.cc:443
bool IsToRDevice(uint32_t vrf_id, const IpAddress &ip)
PktHandlerQueue work_queue_
Definition: pkt_handler.h:371
bool IsDHCPPacket(PktInfo *pkt_info)
bool IsFlowPacket(PktInfo *pkt_info)
void PktTraceIterate(PktModuleName mod, PktTraceCallback cb)
PacketBufferManager * packet_buffer_manager() const
Definition: pkt_init.h:34
ControlInterface * control_interface() const
Definition: pkt_init.h:47
uint32_t count_
Definition: pkt_trace.h:79
static const std::size_t kPktMaxTraceSize
Definition: pkt_trace.h:15
std::vector< Pkt > pkt_buffer_
Definition: pkt_trace.h:82
std::size_t pkt_trace_size_
Definition: pkt_trace.h:81
void AddPktTrace(Direction dir, std::size_t len, uint8_t *msg, const AgentHdr *hdr)
std::size_t pkt_trace_size() const
Definition: pkt_trace.h:60
uint32_t end_
Definition: pkt_trace.h:78
std::size_t num_buffers_
Definition: pkt_trace.h:80
void Iterate(Cb cb)
Definition: pkt_trace.h:50
virtual bool Enqueue(boost::shared_ptr< PktInfo > msg)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
const Ip4Address * GetDip() const
Definition: tunnel_nh.h:38
@ MPLS_UDP
Definition: nexthop.h:243
@ MPLS_GRE
Definition: nexthop.h:242
Type GetType() const
Definition: nexthop.h:304
void SetType(TunnelType::Type type)
Definition: nexthop.h:305
const Interface * GetInterface() const
Definition: nexthop.h:1544
bool IsFatFlowPrefixAggregation(bool ingress, uint8_t protocol, uint16_t *sport, uint16_t *dport, bool *same_port_num, IpAddress *SrcIP, IpAddress *DstIP, bool *is_src_prefix, bool *is_dst_prefix, FatFlowIgnoreAddressType *ignore_addr) const
VmInterface::VmiType vmi_type() const
bool IsFatFlowPortBased(uint8_t protocol, uint16_t port, FatFlowIgnoreAddressType *ignore_addr) const
const FatFlowList & fat_flow_list() const
const VnEntry * vn() const
const Ip4Address & primary_ip_addr() const
bool ExcludeFromFatFlow(Address::Family family, const IpAddress &sip, const IpAddress &dip) const
const Ip6Address & primary_ip6_addr() const
Definition: vn.h:152
const std::vector< VnIpam > & GetVnIpam() const
Definition: vn.h:172
Definition: vrf.h:90
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:335
bool layer2_control_word() const
Definition: nexthop.h:1462
bool bridge_nh() const
Definition: nexthop.h:1449
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:885
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:249
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:153
void set_measure_busy_time(bool val) const
Definition: queue_task.h:380
void set_name(const std::string &name)
Definition: queue_task.h:308
@ INVALID
Definition: globals.h:150
uint8_t type
Definition: load_balance.h:2
#define LOG(_Level, _Msg)
Definition: logging.h:35
Definition: bfd_client.h:10
boost::shared_ptr< PacketBuffer > PacketBufferPtr
Definition: packet_buffer.h:19
#define PKT_TRACE(obj, arg)
Definition: pkt_handler.cc:36
#define MPLS_OVER_UDP_DEST_PORT
Definition: pkt_handler.h:38
#define ETHERTYPE_PBB
Definition: pkt_handler.h:54
#define DHCP_CLIENT_PORT
Definition: pkt_handler.h:30
#define BFD_ECHO_PORT
Definition: pkt_handler.h:34
#define DHCP_SERVER_PORT
Definition: pkt_handler.h:29
#define IANA_MPLS_OVER_UDP_DEST_PORT
Definition: pkt_handler.h:37
#define VXLAN_UDP_DEST_PORT
Definition: pkt_handler.h:36
#define DHCPV6_CLIENT_PORT
Definition: pkt_handler.h:32
#define PBB_HEADER_LEN
Definition: pkt_handler.h:55
#define DHCPV6_SERVER_PORT
Definition: pkt_handler.h:31
#define BFD_MULTIHOP_CONTROL_PORT
Definition: pkt_handler.h:35
#define BFD_SINGLEHOP_CONTROL_PORT
Definition: pkt_handler.h:33
#define ETHERTYPE_QINQ
Definition: pkt_handler.h:53
#define VLAN_HDR_LEN
Definition: pkt_handler.h:49
char data_[8]
Definition: diag.h:86
uint32_t cmd_param
Definition: pkt_handler.h:183
uint32_t ifindex
Definition: pkt_handler.h:180
uint32_t nh
Definition: pkt_handler.h:189
uint16_t cmd
Definition: pkt_handler.h:182
uint32_t vrf
Definition: pkt_handler.h:181
@ TRAP_MAC_MOVE
Definition: pkt_handler.h:149
@ TRAP_ROUTER_ALERT
Definition: pkt_handler.h:147
@ TRAP_ICMP_ERROR
Definition: pkt_handler.h:145
@ TRAP_FLOW_MISS
Definition: pkt_handler.h:137
@ TRAP_MAC_LEARN
Definition: pkt_handler.h:148
@ TRAP_RESOLVE
Definition: pkt_handler.h:136
@ TRAP_MAC_IP_LEARNING
Definition: pkt_handler.h:150
@ TRAP_FLOW_ACTION_HOLD
Definition: pkt_handler.h:146
@ TRAP_HANDLE_DF
Definition: pkt_handler.h:142
@ TRAP_ZERO_TTL
Definition: pkt_handler.h:144
@ TRAP_TOR_CONTROL_PKT
Definition: pkt_handler.h:143
@ LOCAL_ECMP
Definition: nexthop.h:1594
uint16_t protocol
Definition: pkt_handler.h:76
uint32_t hdr
Definition: pkt_handler.h:83
void PktRcvd(PktModuleName mod)
uint32_t received[MAX_MODULES]
Definition: pkt_handler.h:253
void PktQThresholdExceeded(PktModuleName mod)
void PktSent(PktModuleName mod)
PktInfo(Agent *agent, uint32_t buff_len, PktHandler::PktModuleName module, uint32_t mdata)
uint8_t * pkt
Definition: pkt_handler.h:379
struct ip6_hdr * ip6
Definition: pkt_handler.h:424
MacAddress dmac
Definition: pkt_handler.h:393
uint32_t i_sid
Definition: pkt_handler.h:404
uint32_t vrf
Definition: pkt_handler.h:391
void reset_packet_buffer()
uint32_t dport
Definition: pkt_handler.h:398
IpAddress ip_daddr
Definition: pkt_handler.h:395
IpAddress ip_ff_src_prefix
Definition: pkt_handler.h:415
std::size_t hash(const Agent *agent, const EcmpLoadBalance &ecmp_has_fields_to_use) const
void UpdateHeaderPtr()
bool is_fat_flow_dst_prefix
Definition: pkt_handler.h:416
struct icmp * icmp
Definition: pkt_handler.h:428
struct udphdr * udp
Definition: pkt_handler.h:427
uint32_t sport
Definition: pkt_handler.h:397
uint16_t icmp_chksum
Definition: pkt_handler.h:400
uint8_t * data
Definition: pkt_handler.h:383
IpAddress ip_saddr
Definition: pkt_handler.h:394
bool same_port_number
Definition: pkt_handler.h:413
uint16_t len
Definition: pkt_handler.h:380
TunnelInfo tunnel
Definition: pkt_handler.h:407
MacAddress smac
Definition: pkt_handler.h:392
struct ether_arp * arp
Definition: pkt_handler.h:422
virtual ~PktInfo()
void AllocPacketBuffer(Agent *agent, uint32_t module, uint16_t len, uint32_t mdata)
uint32_t ttl
Definition: pkt_handler.h:399
uint32_t GetUdpPayloadLength() const
bool is_segment_hc_pkt
Definition: pkt_handler.h:411
struct ether_header * eth
Definition: pkt_handler.h:420
Address::Family family
Definition: pkt_handler.h:386
bool is_fat_flow_src_prefix
Definition: pkt_handler.h:414
IpAddress ip_ff_dst_prefix
Definition: pkt_handler.h:417
struct ip * ip
Definition: pkt_handler.h:423
MacAddress b_smac
Definition: pkt_handler.h:402
union PktInfo::@8 transp
bool l3_label
Definition: pkt_handler.h:408
bool tcp_ack
Definition: pkt_handler.h:406
uint8_t ip_proto
Definition: pkt_handler.h:396
struct igmp * igmp
Definition: pkt_handler.h:431
MacAddress b_dmac
Definition: pkt_handler.h:403
uint16_t max_pkt_len
Definition: pkt_handler.h:381
uint32_t * pbb_header
Definition: pkt_handler.h:421
uint16_t ether_type
Definition: pkt_handler.h:389
PacketBufferPtr packet_buffer_
Definition: pkt_handler.h:456
void set_len(uint32_t len)
const AgentHdr & GetAgentHdr() const
PktHandler::PktModuleName module
Definition: pkt_handler.h:378
struct icmp6_hdr * icmp6
Definition: pkt_handler.h:429
AgentHdr agent_hdr
Definition: pkt_handler.h:388
VmInterface::FatFlowIgnoreAddressType ignore_address
Definition: pkt_handler.h:412
struct tcphdr * tcp
Definition: pkt_handler.h:426
struct sctphdr * sctp
Definition: pkt_handler.h:430
uint8_t pkt[kPktMaxTraceSize]
Definition: pkt_trace.h:28
void Copy(Direction d, std::size_t l, uint8_t *msg, std::size_t pkt_trace_size, const AgentHdr *hdr)
std::size_t len
Definition: pkt_trace.h:27
Direction dir
Definition: pkt_trace.h:26
struct ether_header * eth
Definition: pkt_handler.h:217
TunnelType type
Definition: pkt_handler.h:211
uint32_t vxlan_id
Definition: pkt_handler.h:213
struct ip * ip
Definition: pkt_handler.h:218
uint32_t ip_saddr
Definition: pkt_handler.h:215
uint32_t ip_daddr
Definition: pkt_handler.h:216
uint32_t label
Definition: pkt_handler.h:212
uint32_t vxlan_id
Definition: pkt_handler.h:92
u_int16_t th_dport
Definition: pkt_handler.h:123
u_int16_t th_sport
Definition: pkt_handler.h:122