49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Copyright (c) 2008-2016 Solarflare Communications Inc.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Redistribution and use in source and binary forms, with or without
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * modification, are permitted provided that the following conditions are met:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 1. Redistributions of source code must retain the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright notice,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * this list of conditions and the following disclaimer in the documentation
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * and/or other materials provided with the distribution.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * The views and conclusions contained in the software and documentation are
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * those of the authors and should not be interpreted as representing official
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * policies, either expressed or implied, of the FreeBSD Project.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * Parse packet headers and return:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * etherhpp Ethernet MAC header
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * iphpp IPv4 header (NULL for non-IPv4 packet)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * thpp TCP header (NULL for non-TCP packet)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * offp Offset to TCP payload
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * sizep Size of TCP payload
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * dportp TCP/UDP/SCTP dest. port (network order), otherwise zero
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore * sportp TCP/UDP/SCTP source port, (network order) otherwise zero
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoresfxge_pkthdr_parse(mblk_t *mp, struct ether_header **etherhpp,
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore sfxge_packet_type_t pkt_type = SFXGE_PACKET_TYPE_UNKNOWN;
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab the MAC header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((MBLKL(mp) < etherhs) && (pullupmsg(mp, etherhs) == 0))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore etherhp = (struct ether_header *)(mp->b_rptr);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore etherhs = sizeof (struct ether_vlan_header);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((MBLKL(mp) < etherhs) && (pullupmsg(mp, etherhs) == 0))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore ethervhp = (struct ether_vlan_header *)(mp->b_rptr);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Skip over the MAC header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab the IP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((MBLKL(mp) < len) && (pullupmsg(mp, len) == 0))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Get the size of the packet */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Skip over the IP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab the TCP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((MBLKL(mp) < len) && (pullupmsg(mp, len) == 0))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Skip over the TCP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab the UDP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((MBLKL(mp) < len) && (pullupmsg(mp, len) == 0))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Skip over the UDP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Grab the SCTP header */
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore if ((MBLKL(mp) < len) && (pullupmsg(mp, len) == 0))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore shp = (struct sctp_hdr *)(mp->b_rptr + off);
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore /* Skip over the SCTP header */