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 <cutils/log.h>
21 #include "NetdConstants.h"
23 const char * const OEM_SCRIPT_PATH = "/system/bin/oem-iptables-init.sh";
24 const char * const IPTABLES_PATH = "/system/bin/iptables";
25 const char * const IP6TABLES_PATH = "/system/bin/ip6tables";
26 const char * const TC_PATH = "/system/bin/tc";
27 const char * const IP_PATH = "/system/bin/ip";
28 const char * const ADD = "add";
29 const char * const DEL = "del";
31 static void logExecError(const char* argv[], int res) {
32 const char** argp = argv;
33 std::string args = "";
39 ALOGE("exec() res=%d for %s", res, args.c_str());
42 static int execIptables(IptablesTarget target, bool silent, va_list args) {
43 /* Read arguments from incoming va_list; we expect the list to be NULL terminated. */
44 std::list<const char*> argsList;
45 argsList.push_back(NULL);
48 arg = va_arg(args, const char *);
49 argsList.push_back(arg);
53 const char* argv[argsList.size()];
54 std::list<const char*>::iterator it;
55 for (it = argsList.begin(); it != argsList.end(); it++, i++) {
60 if (target == V4 || target == V4V6) {
61 argv[0] = IPTABLES_PATH;
62 int localRes = fork_and_execve(argv[0], argv);
65 logExecError(argv, localRes);
70 if (target == V6 || target == V4V6) {
71 argv[0] = IP6TABLES_PATH;
72 int localRes = fork_and_execve(argv[0], argv);
75 logExecError(argv, localRes);
83 int execIptables(IptablesTarget target, ...) {
85 va_start(args, target);
86 int res = execIptables(target, false, args);
91 int execIptablesSilently(IptablesTarget target, ...) {
93 va_start(args, target);
94 int res = execIptables(target, true, args);