2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <sys/types.h>
25 #define LOG_TAG "OemIptablesHook"
26 #include <cutils/log.h>
27 #include <logwrap/logwrap.h>
28 #include "NetdConstants.h"
30 static int runIptablesCmd(int argc, const char **argv) {
33 res = android_fork_execvp(argc, (char **)argv, NULL, false, false);
37 static bool oemCleanupHooks() {
38 const char *cmd1[] = {
44 runIptablesCmd(ARRAY_SIZE(cmd1), cmd1);
46 const char *cmd2[] = {
52 runIptablesCmd(ARRAY_SIZE(cmd2), cmd2);
54 const char *cmd3[] = {
62 runIptablesCmd(ARRAY_SIZE(cmd3), cmd3);
66 static bool oemInitChains() {
67 int ret = system(OEM_SCRIPT_PATH);
68 if ((-1 == ret) || (0 != WEXITSTATUS(ret))) {
69 ALOGE("%s failed: %s", OEM_SCRIPT_PATH, strerror(errno));
77 void setupOemIptablesHook() {
78 if (0 == access(OEM_SCRIPT_PATH, R_OK | X_OK)) {
79 // The call to oemCleanupHooks() is superfluous when done on bootup,
80 // but is needed for the case where netd has crashed/stopped and is
82 if (oemCleanupHooks() && oemInitChains()) {
83 ALOGI("OEM iptable hook installed.");