Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020-2023 Project CHIP Authors
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 : #include <inet/InetInterfaceImpl.h>
18 : #include <lib/core/CHIPConfig.h>
19 :
20 : #if CHIP_MEMORY_SANITIZER_ENABLED
21 : #include <sanitizer/msan_interface.h>
22 : #endif
23 :
24 : #if (CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK) && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
25 : #include <net/if.h>
26 : namespace chip {
27 : namespace Inet {
28 104 : struct if_nameindex * if_nameindexImpl()
29 : {
30 104 : struct if_nameindex * result = if_nameindex();
31 : #if CHIP_MEMORY_SANITIZER_ENABLED
32 : if (result)
33 : {
34 : // if_nameindex() lives in libc, which is not MSan-instrumented, and the structs it returns are populated
35 : // from kernel data MSan cannot observe. Manually unpoisoning the result is the only way to avoid false positives.
36 : for (size_t i = 0;; i++)
37 : {
38 : __msan_unpoison(&result[i], sizeof(result[i]));
39 : if (result[i].if_index == 0)
40 : break;
41 : __msan_unpoison(result[i].if_name, IF_NAMESIZE);
42 : }
43 : }
44 : #endif
45 104 : return result;
46 : }
47 104 : void if_freenameindexImpl(struct if_nameindex * inArray)
48 : {
49 104 : if_freenameindex(inArray);
50 104 : }
51 : } // namespace Inet
52 : } // namespace chip
53 : #endif
|