blob: 1d8501aa07351a42d17d860624528c392e27b0f9 [file] [log] [blame]
Sreeram Ramachandran8f95def2014-05-12 11:20:12 -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
17#include "FwmarkClient.h"
18#include "netd_client/FwmarkCommands.h"
19
20#include <sys/socket.h>
21
22namespace {
23
24typedef int (*ConnectFunctionType)(int, const sockaddr*, socklen_t);
25
26ConnectFunctionType libcConnect = 0;
27
28int netdClientConnect(int sockfd, const sockaddr* addr, socklen_t addrlen) {
29 if (FwmarkClient::shouldSetFwmark(sockfd, addr)) {
30 char data[] = {FWMARK_COMMAND_ON_CONNECT};
31 if (!FwmarkClient().send(data, sizeof(data), sockfd)) {
32 return -1;
33 }
34 }
35 return libcConnect(sockfd, addr, addrlen);
36}
37
38} // namespace
39
40extern "C" void netdClientInitConnect(ConnectFunctionType* function) {
41 if (function && *function) {
42 libcConnect = *function;
43 *function = netdClientConnect;
44 }
45}