NetPacket::IPv6(3p)

NAME
NetPacket::IPv6 - Assemble and disassemble IPv6 (Internet Protocol version 6) packets.

VERSION
version 1.7.2

SYNOPSIS
  use NetPacket::IPv6;

  $ip_obj = NetPacket::IPv6->decode($raw_pkt);
  $ip_pkt = NetPacket::IPv6->encode($ip_obj);
  $ip_data = NetPacket::IPv6::strip($raw_pkt);

DESCRIPTION
"NetPacket::IPv6" provides a set of routines for assembling and disassembling packets using IPv6 (Internet Protocol version 6).

  Methods

"NetPacket::IPv6->decode([RAW PACKET])"
    Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method.

"NetPacket::IPv6->encode()"
    Return an IPv6 packet encoded with the instance data specified. This will infer the total length of the packet automatically from the payload length and length of any extension headers.

"NetPacket::IPv6->pseudo_header([PACKET LENGTH], [PROTOCOL])"
    Return an IPv6 "pseudo-header" suitable for computing checksums for certain upper-level protocols.

  Functions

"NetPacket::IPv6::strip([RAW PACKET])"
    Return the encapsulated data (or payload) contained in the IPv6 packet. This data is suitable to be used as input for other "NetPacket::*" modules.

    This function is equivalent to creating an object using the decode() constructor and returning the "data" field of that object.

NetPacket::IPv6::ipv6_extheader([TYPE])
    Return whether the IP protocol type is an IPv6 extension header.

  Instance data
The instance data for the "NetPacket::IPv6" object consists of the following fields.

ver The IP version number of this packet.

traffic_class
    The traffic class of this packet, equivalent to the type-of-service field for IPv4.

flow_label
    The flow label of this packet.

len The payload length (including any extension headers) in bytes for this packet.

proto
    The IP protocol number for this packet.

hop_limit
    The hop limit for this packet, equivalent to the time-to-live field for IPv4.

src_ip
    The source IP address for this packet in colon-separated hextet notation.

dest_ip
    The destination IP address for this packet in colon-separated hextet notation.

extheaders
    Array of any extension headers for this packet, as a hashref containing the fields described below. An ESP (Encapsulating Security Payload) header will not be represented here; as it and any further extension headers and the payload data will be encrypted, it will be instead represented as the packet payload data itself, with a protocol number of 50 ("IPv6_EXTHEADER_ESP").

data
    The encapsulated data (payload) for this IPv6 packet.

Extension headers may contain the following fields.

type
    The extension header type number.

len The extension header length, in 8-byte units, minus the first 8-byte unit. (For Authentication extension headers, this length is in 4-byte units, minus the first two 4-byte units.)

data
    The remaining contents of the extension header following the next-header and length bytes.

  Exports

default
    none

tags
    The following tags group together related exportable items.

    ":protos"
    ":tos"
    ":misc"
        Re-exported from NetPacket::IP for convenience.

    ":extheaders"
        IPv6_EXTHEADER_HOPBYHOP IPv6_EXTHEADER_ROUTING IPv6_EXTHEADER_FRAGMENT IPv6_EXTHEADER_ESP IPv6_EXTHEADER_AUTH IPv6_EXTHEADER_NONEXT IPv6_EXTHEADER_DESTOPT IPv6_EXTHEADER_MOBILITY IPv6_EXTHEADER_HOSTIDENT IPv6_EXTHEADER_SHIM6 IPv6_EXTHEADER_TESTING1 IPv6_EXTHEADER_TESTING2

    ":versions"
        IP_VERSION_IPv6

    ":strip"
        Import the strip function "ipv6_strip".

    ":ALL"
        All the above exportable items.

EXAMPLE
The following script dumps IPv6 frames by IP address and protocol to standard output.

  #!/usr/bin/perl -w

  use strict;
  use Net::PcapUtils;
  use NetPacket::Ethernet qw(:strip);
  use NetPacket::IPv6;

  sub process_pkt {
      my ($user, $hdr, $pkt) = @_;

      my $ip_obj = NetPacket::IPv6->decode(eth_strip($pkt));
      print("$ip_obj->{src_ip}:$ip_obj->{dest_ip} $ip_obj->{proto}\n");
  }

  Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip6');

TODO

More specific keys for well-defined extension headers.
Parse routing extension headers to correctly compute upper-level checksums.

COPYRIGHT
Copyright (c) 2018 Dan Book.

This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.

AUTHOR
Dan Book <dbook@cpan.org>