Home | History | Annotate | Download | only in Ip6Dxe
      1 /** @file
      2   IP6 internal functions and definitions to process the incoming packets.
      3 
      4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
      5 
      6   This program and the accompanying materials
      7   are licensed and made available under the terms and conditions of the BSD License
      8   which accompanies this distribution.  The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.php.
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #ifndef __EFI_IP6_INPUT_H__
     17 #define __EFI_IP6_INPUT_H__
     18 
     19 #define IP6_MIN_HEADLEN       40
     20 #define IP6_MAX_HEADLEN       120
     21 ///
     22 /// 8(ESP header) + 16(max IV) + 16(max padding) + 2(ESP tail) + 12(max ICV) = 54
     23 ///
     24 #define IP6_MAX_IPSEC_HEADLEN 54
     25 
     26 
     27 #define IP6_ASSEMLE_HASH_SIZE 127
     28 ///
     29 /// Lift time in seconds.
     30 ///
     31 #define IP6_FRAGMENT_LIFE     60
     32 #define IP6_MAX_PACKET_SIZE   65535
     33 
     34 
     35 #define IP6_GET_CLIP_INFO(Packet) ((IP6_CLIP_INFO *) ((Packet)->ProtoData))
     36 
     37 #define IP6_ASSEMBLE_HASH(Dst, Src, Id)  \
     38           ((*((UINT32 *) (Dst)) + *((UINT32 *) (Src)) + (Id)) % IP6_ASSEMLE_HASH_SIZE)
     39 
     40 #define IP6_RXDATA_WRAP_SIZE(NumFrag) \
     41           (sizeof (IP6_RXDATA_WRAP) + sizeof (EFI_IP6_FRAGMENT_DATA) * ((NumFrag) - 1))
     42 
     43 //
     44 // Per packet information for input process. LinkFlag specifies whether
     45 // the packet is received as Link layer unicast, multicast or broadcast.
     46 // The CastType is the IP layer cast type, such as IP multicast or unicast.
     47 // Start, End and Length are staffs used to assemble the packets. Start
     48 // is the sequence number of the first byte of data in the packet. Length
     49 // is the number of bytes of data. End = Start + Length, that is, the
     50 // sequence number of last byte + 1. Each assembled packet has a count down
     51 // life. If it isn't consumed before Life reaches zero, the packet is released.
     52 //
     53 typedef struct {
     54   UINT32                    LinkFlag;
     55   INT32                     CastType;
     56   INT32                     Start;
     57   INT32                     End;
     58   INT32                     Length;
     59   UINT32                    Life;
     60   EFI_STATUS                Status;
     61   UINT32                    Id;
     62   UINT16                    HeadLen;
     63   UINT8                     NextHeader;
     64   UINT8                     LastFrag;
     65   UINT32                    FormerNextHeader;
     66 } IP6_CLIP_INFO;
     67 
     68 //
     69 // Structure used to assemble IP packets.
     70 //
     71 typedef struct {
     72   LIST_ENTRY                Link;
     73   LIST_ENTRY                Fragments;  // List of all the fragments of this packet
     74 
     75   //
     76   // Identity of one IP6 packet. Each fragment of a packet has
     77   // the same (Dst, Src, Id).
     78   //
     79   EFI_IPv6_ADDRESS          Dst;
     80   EFI_IPv6_ADDRESS          Src;
     81   UINT32                    Id;
     82 
     83   UINT32                    TotalLen;
     84   UINT32                    CurLen;
     85   UINT32                    Life;       // Count down life for the packet.
     86 
     87   EFI_IP6_HEADER            *Head;      // IP head of the first fragment
     88   IP6_CLIP_INFO             *Info;      // Per packet information of the first fragment
     89   NET_BUF                   *Packet;    // The first fragment of the packet
     90 } IP6_ASSEMBLE_ENTRY;
     91 
     92 //
     93 // Each Ip service instance has an assemble table to reassemble
     94 // the packets before delivery to its children. It is organized
     95 // as hash table.
     96 //
     97 typedef struct {
     98   LIST_ENTRY  Bucket[IP6_ASSEMLE_HASH_SIZE];
     99 } IP6_ASSEMBLE_TABLE;
    100 
    101 /**
    102   The IP6 input routine. It is called by the IP6_INTERFACE when an
    103   IP6 fragment is received from MNP.
    104 
    105   @param[in]  Packet             The IP6 packet received.
    106   @param[in]  IoStatus           The return status of receive request.
    107   @param[in]  Flag               The link layer flag for the packet received, such
    108                                  as multicast.
    109   @param[in]  Context            The IP6 service instance that own the MNP.
    110 
    111 **/
    112 VOID
    113 Ip6AcceptFrame (
    114   IN NET_BUF                *Packet,
    115   IN EFI_STATUS             IoStatus,
    116   IN UINT32                 Flag,
    117   IN VOID                   *Context
    118   );
    119 
    120 /**
    121   Deliver the received packets to upper layer if there are both received
    122   requests and enqueued packets. If the enqueued packet is shared, it will
    123   duplicate it to a non-shared packet, release the shared packet, then
    124   deliver the non-shared packet up.
    125 
    126   @param[in]  IpInstance         The IP child to deliver the packet up.
    127 
    128   @retval EFI_OUT_OF_RESOURCES   Failed to allocate resources to deliver the
    129                                  packets.
    130   @retval EFI_SUCCESS            All the enqueued packets that can be delivered
    131                                  are delivered up.
    132 
    133 **/
    134 EFI_STATUS
    135 Ip6InstanceDeliverPacket (
    136   IN IP6_PROTOCOL           *IpInstance
    137   );
    138 
    139 /**
    140   The work function to locate the IPsec protocol to process the inbound or
    141   outbound IP packets. The process routine handles the packet with the following
    142   actions: bypass the packet, discard the packet, or protect the packet.
    143 
    144   @param[in]       IpSb          The IP6 service instance.
    145   @param[in, out]  Head          The caller-supplied IP6 header.
    146   @param[in, out]  LastHead      The next header field of last IP header.
    147   @param[in, out]  Netbuf        The IP6 packet to be processed by IPsec.
    148   @param[in, out]  ExtHdrs       The caller-supplied options.
    149   @param[in, out]  ExtHdrsLen    The length of the option.
    150   @param[in]       Direction     The directionality in an SPD entry,
    151                                  EfiIPsecInBound, or EfiIPsecOutBound.
    152   @param[in]       Context       The token's wrap.
    153 
    154   @retval EFI_SUCCESS            The IPsec protocol is not available or disabled.
    155   @retval EFI_SUCCESS            The packet was bypassed, and all buffers remain the same.
    156   @retval EFI_SUCCESS            The packet was protected.
    157   @retval EFI_ACCESS_DENIED      The packet was discarded.
    158   @retval EFI_OUT_OF_RESOURCES   There are not suffcient resources to complete the operation.
    159   @retval EFI_BUFFER_TOO_SMALL   The number of non-empty blocks is bigger than the
    160                                  number of input data blocks when building a fragment table.
    161 
    162 **/
    163 EFI_STATUS
    164 Ip6IpSecProcessPacket (
    165   IN     IP6_SERVICE            *IpSb,
    166   IN OUT EFI_IP6_HEADER         **Head,
    167   IN OUT UINT8                  *LastHead,
    168   IN OUT NET_BUF                **Netbuf,
    169   IN OUT UINT8                  **ExtHdrs,
    170   IN OUT UINT32                 *ExtHdrsLen,
    171   IN     EFI_IPSEC_TRAFFIC_DIR  Direction,
    172   IN     VOID                   *Context
    173   );
    174 
    175 /**
    176   Initialize an already allocated assemble table. This is generally
    177   the assemble table embedded in the IP6 service instance.
    178 
    179   @param[in, out]  Table    The assemble table to initialize.
    180 
    181 **/
    182 VOID
    183 Ip6CreateAssembleTable (
    184   IN OUT IP6_ASSEMBLE_TABLE *Table
    185   );
    186 
    187 /**
    188   Clean up the assemble table: remove all the fragments
    189   and assemble entries.
    190 
    191   @param[in, out]  Table    The assemble table to clean up.
    192 
    193 **/
    194 VOID
    195 Ip6CleanAssembleTable (
    196   IN OUT IP6_ASSEMBLE_TABLE *Table
    197   );
    198 
    199 /**
    200   Demultiple the packet. the packet delivery is processed in two
    201   passes. The first pass will enque a shared copy of the packet
    202   to each IP6 child that accepts the packet. The second pass will
    203   deliver a non-shared copy of the packet to each IP6 child that
    204   has pending receive requests. Data is copied if more than one
    205   child wants to consume the packet bacause each IP child need
    206   its own copy of the packet to make changes.
    207 
    208   @param[in]  IpSb          The IP6 service instance that received the packet.
    209   @param[in]  Head          The header of the received packet.
    210   @param[in]  Packet        The data of the received packet.
    211 
    212   @retval EFI_NOT_FOUND     No IP child accepts the packet.
    213   @retval EFI_SUCCESS       The packet is enqueued or delivered to some IP
    214                             children.
    215 
    216 **/
    217 EFI_STATUS
    218 Ip6Demultiplex (
    219   IN IP6_SERVICE            *IpSb,
    220   IN EFI_IP6_HEADER         *Head,
    221   IN NET_BUF                *Packet
    222   );
    223 
    224 /**
    225   Timeout the fragmented, enqueued, and transmitted packets.
    226 
    227   @param[in]  IpSb          The IP6 service instance to timeout.
    228 
    229 **/
    230 VOID
    231 Ip6PacketTimerTicking (
    232   IN IP6_SERVICE            *IpSb
    233   );
    234 
    235 #endif
    236