Filters and defragments packet and then passes the packet along to the packet_handler() function to determine whether we should pass the packet(s) along to the next plugin.
(self, packet: "Packet")
| 407 | |
| 408 | # NOTE: This was originally called '_packet_handler' |
| 409 | def consume_packet(self, packet: "Packet"): |
| 410 | """ |
| 411 | Filters and defragments packet and then passes the packet along to the packet_handler() |
| 412 | function to determine whether we should pass the packet(s) along to the next plugin. |
| 413 | """ |
| 414 | # First apply filter to packet. |
| 415 | if not self.filter(packet): |
| 416 | return |
| 417 | |
| 418 | with self.seen_packet_count.get_lock(): |
| 419 | self.seen_packet_count.value += 1 |
| 420 | |
| 421 | # Attempt to perform defragmentation |
| 422 | if self.defrag_ip and isinstance(packet.pkt.upper_layer, (ip.IP, ip6.IP6)): |
| 423 | defragpkt = self.ipdefrag(packet) |
| 424 | if not defragpkt: |
| 425 | # we do not yet have all of the packet fragments, so move |
| 426 | # on to next packet for now |
| 427 | return |
| 428 | else: |
| 429 | packet = defragpkt |
| 430 | |
| 431 | # call packet_handler and return its output |
| 432 | # decode.py will continue down the chain if it returns anything |
| 433 | try: |
| 434 | packet_handler_out = self.packet_handler(packet) |
| 435 | except Exception as e: |
| 436 | print_handler_exception(e, self, 'packet_handler') |
| 437 | return |
| 438 | failed_msg = ( |
| 439 | f"The output from {self.name} packet_handler must be of type dshell.Packet or a list of " |
| 440 | f"such objects! Handling connections or chaining from this plugin may not be possible." |
| 441 | ) |
| 442 | if isinstance(packet_handler_out, (list, tuple)): |
| 443 | for phout in packet_handler_out: |
| 444 | if isinstance(phout, Packet): |
| 445 | self._packet_queue.append(phout) |
| 446 | with self.handled_packet_count.get_lock(): |
| 447 | self.handled_packet_count.value += 1 |
| 448 | elif phout: |
| 449 | logger.warning(failed_msg) |
| 450 | elif isinstance(packet_handler_out, Packet): |
| 451 | self._packet_queue.append(packet_handler_out) |
| 452 | with self.handled_packet_count.get_lock(): |
| 453 | self.handled_packet_count.value += 1 |
| 454 | elif packet_handler_out: |
| 455 | logger.warning(failed_msg) |
| 456 | |
| 457 | def packet_handler(self, pkt: "Packet"): |
| 458 | """ |
no test coverage detected