blob: be5fb1197dda07363bab3bc0ae1823953bb58d5a [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
Josh Gaob7eccd42019-11-06 13:15:00 -080021#include "private/bionic_fdtrack.h"
22
Elliott Hughesdc6e2fb2024-06-25 16:40:41 +000023extern "C" int __accept4(int, sockaddr*, socklen_t*, int);
24extern "C" int __connect(int, const sockaddr*, socklen_t);
25extern "C" int __sendmmsg(int, const mmsghdr*, unsigned int, int);
26extern "C" ssize_t __sendmsg(int, const msghdr*, unsigned int);
27extern "C" int __sendto(int, const void*, size_t, int, const sockaddr*, socklen_t);
28extern "C" int __socket(int, int, int);
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070029
Paul Jensen5240b562014-05-15 14:43:07 -040030static unsigned fallBackNetIdForResolv(unsigned netId) {
31 return netId;
32}
33
Luke Huange3ed8922018-11-19 16:59:08 +080034static int fallBackDnsOpenProxy() {
35 return -1;
36}
37
Sreeram Ramachandran72c53932014-05-18 15:18:36 -070038// This structure is modified only at startup (when libc.so is loaded) and never
39// afterwards, so it's okay that it's read later at runtime without a lock.
40__LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
Sreeram Ramachandran903b7882014-05-19 13:39:57 -070041 __accept4,
Sreeram Ramachandran8f0cd8a2014-05-13 15:40:26 -070042 __connect,
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070043 __sendmmsg,
44 __sendmsg,
45 __sendto,
Sreeram Ramachandran903b7882014-05-19 13:39:57 -070046 __socket,
Paul Jensen5240b562014-05-15 14:43:07 -040047 fallBackNetIdForResolv,
Luke Huange3ed8922018-11-19 16:59:08 +080048 fallBackDnsOpenProxy,
Sreeram Ramachandran8205a612014-05-13 17:24:03 -070049};
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070050
51int accept4(int fd, sockaddr* addr, socklen_t* addr_length, int flags) {
Josh Gaob7eccd42019-11-06 13:15:00 -080052 return FDTRACK_CREATE(__netdClientDispatch.accept4(fd, addr, addr_length, flags));
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070053}
54
55int connect(int fd, const sockaddr* addr, socklen_t addr_length) {
56 return __netdClientDispatch.connect(fd, addr, addr_length);
57}
58
59int sendmmsg(int fd, const struct mmsghdr* msgs, unsigned int msg_count, int flags) {
60 return __netdClientDispatch.sendmmsg(fd, msgs, msg_count, flags);
61}
62
63ssize_t sendmsg(int fd, const struct msghdr* msg, int flags) {
64 return __netdClientDispatch.sendmsg(fd, msg, flags);
65}
66
67ssize_t sendto(int fd, const void* buf, size_t n, int flags,
68 const struct sockaddr* dst_addr, socklen_t dst_addr_length) {
69 return __netdClientDispatch.sendto(fd, buf, n, flags, dst_addr, dst_addr_length);
70}
71
72int socket(int domain, int type, int protocol) {
Josh Gaob7eccd42019-11-06 13:15:00 -080073 return FDTRACK_CREATE(__netdClientDispatch.socket(domain, type, protocol));
Elliott Hughes5c6a3f92019-06-13 14:24:45 -070074}