1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Component                                                        */
16 /**                                                                       */
17 /**   Packet Pool Mangement (Packet)                                      */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 #include "nx_api.h"
27 #include "nx_ip.h"
28 
29 #ifdef NX_IPSEC_ENABLE
30 #include "nx_ipsec.h"
31 #endif /* NX_IPSEC_ENABLE */
32 
33 /* Bring in externs for caller checking code.  */
34 
35 NX_CALLER_CHECKING_EXTERNS
36 
37 
38 /**************************************************************************/
39 /*                                                                        */
40 /*  FUNCTION                                               RELEASE        */
41 /*                                                                        */
42 /*    _nxe_ip_max_payload_size_find                       PORTABLE C      */
43 /*                                                           6.1          */
44 /*  AUTHOR                                                                */
45 /*                                                                        */
46 /*    Yuxin Zhou, Microsoft Corporation                                   */
47 /*                                                                        */
48 /*  DESCRIPTION                                                           */
49 /*                                                                        */
50 /*    This function checks for errors in the max IP payload computation   */
51 /*    service.                                                            */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    ip_ptr                                Pointer to IP instance        */
56 /*    src_address                           Packet Source Address         */
57 /*    dest_address                          Packet Destination Address    */
58 /*    protocol                              Protocol type                 */
59 /*    src_port                              Source port number, in host   */
60 /*                                            byte order.                 */
61 /*    dest_port                             Destination port number,      */
62 /*                                            in host byte order.         */
63 /*    start_offset_ptr                      Pointer to storage space that */
64 /*                                            contains amount of offset   */
65 /*                                            for payload.                */
66 /*    payload_length_ptr                    Pointer to storage space that */
67 /*                                            indicates the amount of     */
68 /*                                            payload data that would not */
69 /*                                            cause IP fragmentation.     */
70 /*                                                                        */
71 /*  OUTPUT                                                                */
72 /*                                                                        */
73 /*    status                                Completion Code.              */
74 /*                                                                        */
75 /*  CALLS                                                                 */
76 /*                                                                        */
77 /*    _nx_max_payload_size_get              The acutal function that      */
78 /*                                            computes the max payload    */
79 /*                                            size.                       */
80 /*                                                                        */
81 /*  CALLED BY                                                             */
82 /*                                                                        */
83 /*    Application                                                         */
84 /*                                                                        */
85 /*  RELEASE HISTORY                                                       */
86 /*                                                                        */
87 /*    DATE              NAME                      DESCRIPTION             */
88 /*                                                                        */
89 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
90 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
91 /*                                            resulting in version 6.1    */
92 /*                                                                        */
93 /**************************************************************************/
94 
_nxe_ip_max_payload_size_find(NX_IP * ip_ptr,NXD_ADDRESS * dest_address,UINT if_index,UINT src_port,UINT dest_port,ULONG protocol,ULONG * start_offset_ptr,ULONG * payload_length_ptr)95 UINT _nxe_ip_max_payload_size_find(NX_IP *ip_ptr,
96                                    NXD_ADDRESS *dest_address,
97                                    UINT if_index,
98                                    UINT src_port,
99                                    UINT dest_port,
100                                    ULONG protocol,
101                                    ULONG *start_offset_ptr,
102                                    ULONG *payload_length_ptr)
103 {
104 
105     /* Check for valid pointer to an IP instance.  */
106     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID))
107     {
108         return(NX_PTR_ERROR);
109     }
110 
111     /* Destination address must be valid. */
112     if (dest_address == NX_NULL)
113     {
114         return(NX_PTR_ERROR);
115     }
116 
117     if ((dest_address -> nxd_ip_version != NX_IP_VERSION_V4) &&
118         (dest_address -> nxd_ip_version != NX_IP_VERSION_V6))
119     {
120         return(NX_IP_ADDRESS_ERROR);
121     }
122 
123     if ((protocol != NX_PROTOCOL_UDP) &&
124         (protocol != NX_PROTOCOL_TCP))
125     {
126         return(NX_NOT_SUPPORTED);
127     }
128 
129     /* Check for appropriate caller.  */
130     NX_INIT_AND_THREADS_CALLER_CHECKING
131 
132     return(_nx_ip_max_payload_size_find(ip_ptr, dest_address, if_index, src_port, dest_port,
133                                         protocol, start_offset_ptr, payload_length_ptr));
134 }
135 
136