Line data Source code
1 : /*
2 : * Copyright (c) 2020 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 : /**
19 : * @file
20 : * This file implements the utility class for the CHIP Message Layer.
21 : */
22 :
23 : #include <errno.h>
24 :
25 : #include <messaging/ErrorCategory.h>
26 :
27 : #include <inet/InetError.h>
28 : #include <system/SystemConfig.h>
29 : #include <system/SystemError.h>
30 :
31 : namespace chip {
32 : namespace Messaging {
33 :
34 0 : bool IsIgnoredMulticastSendError(CHIP_ERROR err)
35 : {
36 0 : return err == CHIP_NO_ERROR ||
37 : #if CHIP_SYSTEM_CONFIG_USE_LWIP
38 : err == System::MapErrorLwIP(ERR_RTE)
39 : #else
40 0 : err == CHIP_ERROR_POSIX(ENETUNREACH) || err == CHIP_ERROR_POSIX(EADDRNOTAVAIL)
41 : #endif
42 : ;
43 : }
44 :
45 0 : CHIP_ERROR FilterUDPSendError(CHIP_ERROR err, bool isMulticast)
46 : {
47 : // Don't report certain types of routing errors when they occur while sending multicast packets.
48 : // These may indicate that the underlying interface doesn't support multicast (e.g. the loopback
49 : // interface on linux) or that the selected interface doesn't have an appropriate source address.
50 0 : if (isMulticast)
51 : {
52 : #if CHIP_SYSTEM_CONFIG_USE_LWIP
53 : if (err == System::MapErrorLwIP(ERR_RTE))
54 : {
55 : err = CHIP_NO_ERROR;
56 : }
57 : #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
58 :
59 : #if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
60 0 : if (err == CHIP_ERROR_POSIX(ENETUNREACH) || err == CHIP_ERROR_POSIX(EADDRNOTAVAIL))
61 : {
62 0 : err = CHIP_NO_ERROR;
63 : }
64 : #endif
65 : }
66 :
67 0 : return err;
68 : }
69 :
70 : /**
71 : * Checks if error, while sending, is critical enough to report to the application.
72 : *
73 : * @param[in] err The #CHIP_ERROR being checked for criticality.
74 : *
75 : * @return true if the error is NOT critical; false otherwise.
76 : *
77 : */
78 1606 : bool IsSendErrorNonCritical(CHIP_ERROR err)
79 : {
80 4818 : return (err == CHIP_ERROR_NOT_IMPLEMENTED || err == CHIP_ERROR_OUTBOUND_MESSAGE_TOO_BIG || err == CHIP_ERROR_MESSAGE_TOO_LONG ||
81 4818 : err == CHIP_ERROR_NO_MEMORY || CHIP_CONFIG_IsPlatformErrorNonCritical(err));
82 : }
83 :
84 : } // namespace Messaging
85 : } // namespace chip
|