summaryrefslogtreecommitdiff
path: root/common/src/nx_ip_fragment_disable.c
blob: 60d580760b0b5702408d179d4976df106de6ba18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2025-present Eclipse ThreadX Contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** NetX Component                                                        */
/**                                                                       */
/**   Internet Protocol (IP)                                              */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define NX_SOURCE_CODE


/* Include necessary system files.  */

#include "nx_api.h"
#include "nx_ip.h"
#include "nx_packet.h"



/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_ip_fragment_disable                             PORTABLE C      */
/*                                                           6.4.3        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function disables IP fragment assembly processing and releases */
/*    all partial fragments being assembled.                              */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    ip_ptr                                Pointer to IP instance        */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                                Completion status             */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _nx_packet_release                    Release packet                */
/*    tx_mutex_get                          Get protection mutex          */
/*    tx_mutex_put                          Put protection mutex          */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application                                                         */
/*                                                                        */
/**************************************************************************/
UINT  _nx_ip_fragment_disable(NX_IP *ip_ptr)
{
#ifndef NX_DISABLE_FRAGMENTATION
TX_INTERRUPT_SAVE_AREA

#ifndef NX_FRAGMENT_IMMEDIATE_ASSEMBLY
NX_PACKET *new_fragment_head;
#endif /* NX_FRAGMENT_IMMEDIATE_ASSEMBLY */
NX_PACKET *assemble_head;
NX_PACKET *next_packet;
NX_PACKET *release_packet;


    /* If trace is enabled, insert this event into the trace buffer.  */
    NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_FRAGMENT_DISABLE, ip_ptr, 0, 0, 0, NX_TRACE_IP_EVENTS, 0, 0);

    /* Get mutex protection.  */
    tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);

    /* Disable interrupts temporarily.  */
    TX_DISABLE

    /* Clear the IP fragment processing routine pointer.  */
    ip_ptr -> nx_ip_fragment_processing =  NX_NULL;

    /* Clear the IP fragment assembly routine pointer.  */
    ip_ptr -> nx_ip_fragment_assembly =  NX_NULL;

    /* Clear the IP fragment timeout routine pointer.  */
    ip_ptr -> nx_ip_fragment_timeout_check =  NX_NULL;

    /* Pickup the fragment list pointer.  */
#ifndef NX_FRAGMENT_IMMEDIATE_ASSEMBLY
    new_fragment_head = ip_ptr -> nx_ip_received_fragment_head;
#else
    NX_ASSERT(ip_ptr -> nx_ip_received_fragment_head == NX_NULL);
#endif /* NX_FRAGMENT_IMMEDIATE_ASSEMBLY */
    assemble_head =     ip_ptr -> nx_ip_fragment_assembly_head;

    /* Clear the IP structure lists.  */
    ip_ptr -> nx_ip_received_fragment_head =  NX_NULL;
    ip_ptr -> nx_ip_received_fragment_tail =  NX_NULL;
    ip_ptr -> nx_ip_fragment_assembly_head =  NX_NULL;
    ip_ptr -> nx_ip_fragment_assembly_tail =  NX_NULL;

    /* Restore interrupts.  */
    TX_RESTORE

    /* Release mutex protection.  */
    tx_mutex_put(&(ip_ptr -> nx_ip_protection));

#ifndef NX_FRAGMENT_IMMEDIATE_ASSEMBLY
    /* Now walk through the receive and assembly lists to free the packets.  */
    next_packet =  new_fragment_head;
    while (next_packet)
    {

        /* Set the release packet to this packet.  */
        release_packet =  next_packet;

        /* Move next packet to the next in the list.  */
        next_packet =  next_packet -> nx_packet_queue_next;

        /* Release the current packet.  */
        _nx_packet_release(release_packet);
    }
#endif /* NX_FRAGMENT_IMMEDIATE_ASSEMBLY */

    /* Now walk through the assemble list and release all packets.  */
    while (assemble_head)
    {

        /* Walk through the list of packets being assembled for this packet and release them.  */
        next_packet =  assemble_head;
        assemble_head =  next_packet -> nx_packet_queue_next;
        while (next_packet)
        {

            /* Set the release packet to this packet.  */
            release_packet =  next_packet;

            /* Move next packet to the next in the list.  */
            next_packet =  next_packet -> nx_packet_union_next.nx_packet_fragment_next;

            /* Reset tcp_queue_next before releasing. */
            /*lint -e{923} suppress cast of ULONG to pointer.  */
            release_packet -> nx_packet_union_next.nx_packet_tcp_queue_next = (NX_PACKET *)NX_PACKET_ALLOCATED;

            /* Release the current packet.  */
            _nx_packet_release(release_packet);
        }
    }

    /* Return success to the caller.  */
    return(NX_SUCCESS);
#else /* NX_DISABLE_FRAGMENTATION */
    NX_PARAMETER_NOT_USED(ip_ptr);

    return(NX_NOT_ENABLED);

#endif /* NX_DISABLE_FRAGMENTATION */
}