Sreeram Ramachandran | 8205a61 | 2014-05-13 17:24:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Sreeram Ramachandran | 72c5393 | 2014-05-18 15:18:36 -0700 | [diff] [blame] | 17 | #include "private/NetdClientDispatch.h" |
Sreeram Ramachandran | 8205a61 | 2014-05-13 17:24:03 -0700 | [diff] [blame] | 18 | |
Elliott Hughes | 5c6a3f9 | 2019-06-13 14:24:45 -0700 | [diff] [blame^] | 19 | #include <sys/socket.h> |
| 20 | |
Sreeram Ramachandran | 8205a61 | 2014-05-13 17:24:03 -0700 | [diff] [blame] | 21 | #ifdef __i386__ |
| 22 | #define __socketcall __attribute__((__cdecl__)) |
| 23 | #else |
| 24 | #define __socketcall |
| 25 | #endif |
| 26 | |
Sreeram Ramachandran | 903b788 | 2014-05-19 13:39:57 -0700 | [diff] [blame] | 27 | extern "C" __socketcall int __accept4(int, sockaddr*, socklen_t*, int); |
Sreeram Ramachandran | 8205a61 | 2014-05-13 17:24:03 -0700 | [diff] [blame] | 28 | extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t); |
Elliott Hughes | 5c6a3f9 | 2019-06-13 14:24:45 -0700 | [diff] [blame^] | 29 | extern "C" __socketcall int __sendmmsg(int, const mmsghdr*, unsigned int, int); |
| 30 | extern "C" __socketcall ssize_t __sendmsg(int, const msghdr*, unsigned int); |
| 31 | extern "C" __socketcall int __sendto(int, const void*, size_t, int, const sockaddr*, socklen_t); |
Sreeram Ramachandran | 903b788 | 2014-05-19 13:39:57 -0700 | [diff] [blame] | 32 | extern "C" __socketcall int __socket(int, int, int); |
Sreeram Ramachandran | 8205a61 | 2014-05-13 17:24:03 -0700 | [diff] [blame] | 33 | |
Paul Jensen | 5240b56 | 2014-05-15 14:43:07 -0400 | [diff] [blame] | 34 | static unsigned fallBackNetIdForResolv(unsigned netId) { |
| 35 | return netId; |
| 36 | } |
| 37 | |
Luke Huang | e3ed892 | 2018-11-19 16:59:08 +0800 | [diff] [blame] | 38 | static int fallBackDnsOpenProxy() { |
| 39 | return -1; |
| 40 | } |
| 41 | |
Sreeram Ramachandran | 72c5393 | 2014-05-18 15:18:36 -0700 | [diff] [blame] | 42 | // This structure is modified only at startup (when libc.so is loaded) and never |
| 43 | // afterwards, so it's okay that it's read later at runtime without a lock. |
| 44 | __LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = { |
Sreeram Ramachandran | 903b788 | 2014-05-19 13:39:57 -0700 | [diff] [blame] | 45 | __accept4, |
Sreeram Ramachandran | 8f0cd8a | 2014-05-13 15:40:26 -0700 | [diff] [blame] | 46 | __connect, |
Elliott Hughes | 5c6a3f9 | 2019-06-13 14:24:45 -0700 | [diff] [blame^] | 47 | __sendmmsg, |
| 48 | __sendmsg, |
| 49 | __sendto, |
Sreeram Ramachandran | 903b788 | 2014-05-19 13:39:57 -0700 | [diff] [blame] | 50 | __socket, |
Paul Jensen | 5240b56 | 2014-05-15 14:43:07 -0400 | [diff] [blame] | 51 | fallBackNetIdForResolv, |
Luke Huang | e3ed892 | 2018-11-19 16:59:08 +0800 | [diff] [blame] | 52 | fallBackDnsOpenProxy, |
Sreeram Ramachandran | 8205a61 | 2014-05-13 17:24:03 -0700 | [diff] [blame] | 53 | }; |
Elliott Hughes | 5c6a3f9 | 2019-06-13 14:24:45 -0700 | [diff] [blame^] | 54 | |
| 55 | int accept4(int fd, sockaddr* addr, socklen_t* addr_length, int flags) { |
| 56 | return __netdClientDispatch.accept4(fd, addr, addr_length, flags); |
| 57 | } |
| 58 | |
| 59 | int connect(int fd, const sockaddr* addr, socklen_t addr_length) { |
| 60 | return __netdClientDispatch.connect(fd, addr, addr_length); |
| 61 | } |
| 62 | |
| 63 | int sendmmsg(int fd, const struct mmsghdr* msgs, unsigned int msg_count, int flags) { |
| 64 | return __netdClientDispatch.sendmmsg(fd, msgs, msg_count, flags); |
| 65 | } |
| 66 | |
| 67 | ssize_t sendmsg(int fd, const struct msghdr* msg, int flags) { |
| 68 | return __netdClientDispatch.sendmsg(fd, msg, flags); |
| 69 | } |
| 70 | |
| 71 | ssize_t sendto(int fd, const void* buf, size_t n, int flags, |
| 72 | const struct sockaddr* dst_addr, socklen_t dst_addr_length) { |
| 73 | return __netdClientDispatch.sendto(fd, buf, n, flags, dst_addr, dst_addr_length); |
| 74 | } |
| 75 | |
| 76 | int socket(int domain, int type, int protocol) { |
| 77 | return __netdClientDispatch.socket(domain, type, protocol); |
| 78 | } |