blob: 463ef369042ac448d29694576859c6a8e7178271 [file] [log] [blame]
Sreeram Ramachandran8205a612014-05-13 17:24:03 -07001/*
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 Ramachandran72c53932014-05-18 15:18:36 -070017#include "private/NetdClientDispatch.h"
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070018
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070019#include <sys/socket.h>
20
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070021#ifdef __i386__
22#define __socketcall __attribute__((__cdecl__))
23#else
24#define __socketcall
25#endif
26
Sreeram Ramachandran903b7882014-05-19 13:39:57 -070027extern "C" __socketcall int __accept4(int, sockaddr*, socklen_t*, int);
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070028extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070029extern "C" __socketcall int __sendmmsg(int, const mmsghdr*, unsigned int, int);
30extern "C" __socketcall ssize_t __sendmsg(int, const msghdr*, unsigned int);
31extern "C" __socketcall int __sendto(int, const void*, size_t, int, const sockaddr*, socklen_t);
Sreeram Ramachandran903b7882014-05-19 13:39:57 -070032extern "C" __socketcall int __socket(int, int, int);
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070033
Paul Jensen5240b562014-05-15 14:43:07 -040034static unsigned fallBackNetIdForResolv(unsigned netId) {
35 return netId;
36}
37
Luke Huange3ed8922018-11-19 16:59:08 +080038static int fallBackDnsOpenProxy() {
39 return -1;
40}
41
Sreeram Ramachandran72c53932014-05-18 15:18:36 -070042// 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 Ramachandran903b7882014-05-19 13:39:57 -070045 __accept4,
Sreeram Ramachandran8f0cd8a2014-05-13 15:40:26 -070046 __connect,
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070047 __sendmmsg,
48 __sendmsg,
49 __sendto,
Sreeram Ramachandran903b7882014-05-19 13:39:57 -070050 __socket,
Paul Jensen5240b562014-05-15 14:43:07 -040051 fallBackNetIdForResolv,
Luke Huange3ed8922018-11-19 16:59:08 +080052 fallBackDnsOpenProxy,
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070053};
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070054
55int accept4(int fd, sockaddr* addr, socklen_t* addr_length, int flags) {
56 return __netdClientDispatch.accept4(fd, addr, addr_length, flags);
57}
58
59int connect(int fd, const sockaddr* addr, socklen_t addr_length) {
60 return __netdClientDispatch.connect(fd, addr, addr_length);
61}
62
63int sendmmsg(int fd, const struct mmsghdr* msgs, unsigned int msg_count, int flags) {
64 return __netdClientDispatch.sendmmsg(fd, msgs, msg_count, flags);
65}
66
67ssize_t sendmsg(int fd, const struct msghdr* msg, int flags) {
68 return __netdClientDispatch.sendmsg(fd, msg, flags);
69}
70
71ssize_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
76int socket(int domain, int type, int protocol) {
77 return __netdClientDispatch.socket(domain, type, protocol);
78}