Line data Source code
1 : /*
2 : * Copyright (c) 2022 Project CHIP Authors
3 : * All rights reserved.
4 : *
5 : * Licensed under the Apache License, Version 2.0 (the "License");
6 : * you may not use this file except in compliance with the License.
7 : * You may obtain a copy of the License at
8 : *
9 : * http://www.apache.org/licenses/LICENSE-2.0
10 : *
11 : * Unless required by applicable law or agreed to in writing, software
12 : * distributed under the License is distributed on an "AS IS" BASIS,
13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : * See the License for the specific language governing permissions and
15 : * limitations under the License.
16 : */
17 :
18 : #pragma once
19 :
20 : #include <inet/IPPacketInfo.h>
21 : #include <system/SystemPacketBuffer.h>
22 :
23 : namespace chip {
24 : namespace Inet {
25 :
26 : /**
27 : * @brief Filter for UDP Packets going into and out of UDPEndPoint queue.
28 : *
29 : * NOTE: This is only used by some low-level implementations of UDPEndPoint
30 : */
31 : class EndpointQueueFilter
32 : {
33 : public:
34 : enum FilterOutcome
35 : {
36 : kAllowPacket = 0,
37 : kDropPacket = 1,
38 : };
39 :
40 1 : virtual ~EndpointQueueFilter() {}
41 :
42 : /**
43 : * @brief Run filter prior to inserting in queue.
44 : *
45 : * If filter returns `kAllowPacket`, packet will be enqueued, and `FilterAfterDequeue` will
46 : * be called when it gets dequeued. If filter returns `kDropPacket`, packet will be dropped
47 : * rather than enqueued and `FilterAfterDequeue` method will not be called.
48 : *
49 : * WARNING: This is likely called from non-Matter-eventloop context, from network layer code.
50 : * Be extremely careful about accessing any system data which may belong to Matter
51 : * stack from this method.
52 : *
53 : * @param endpoint - pointer to endpoint instance (platform-dependent, which is why it's void)
54 : * @param pktInfo - info about source/dest of packet
55 : * @param pktPayload - payload content of packet
56 : *
57 : * @return kAllowPacket to allow packet to enqueue or kDropPacket to drop the packet
58 : */
59 0 : virtual FilterOutcome FilterBeforeEnqueue(const void * endpoint, const IPPacketInfo & pktInfo,
60 : const chip::System::PacketBufferHandle & pktPayload)
61 : {
62 0 : return FilterOutcome::kAllowPacket;
63 : }
64 :
65 : /**
66 : * @brief Run filter after dequeuing, prior to processing.
67 : *
68 : * If filter returns `kAllowPacket`, packet will be processed after dequeuing. If filter returns
69 : * `kDropPacket`, packet will be dropped and not processed, even though it was dequeued.
70 : *
71 : * WARNING: This is called from Matter thread context. Be extremely careful about accessing any
72 : * data which may belong to different threads from this method.
73 : *
74 : * @param endpoint - pointer to endpoint instance (platform-dependent, which is why it's void)
75 : * @param pktInfo - info about source/dest of packet
76 : * @param pktPayload - payload content of packet
77 : *
78 : * @return kAllowPacket to allow packet to be processed or kDropPacket to drop the packet
79 : */
80 0 : virtual FilterOutcome FilterAfterDequeue(const void * endpoint, const IPPacketInfo & pktInfo,
81 : const chip::System::PacketBufferHandle & pktPayload)
82 : {
83 0 : return FilterOutcome::kAllowPacket;
84 : }
85 : };
86 :
87 : } // namespace Inet
88 : } // namespace chip
|