10031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall/*
20031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * Copyright (C) 2012 The Android Open Source Project
30031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
40031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * Licensed under the Apache License, Version 2.0 (the "License");
50031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * you may not use this file except in compliance with the License.
60031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * You may obtain a copy of the License at
70031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
80031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *      http://www.apache.org/licenses/LICENSE-2.0
90031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
100031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * Unless required by applicable law or agreed to in writing, software
110031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * distributed under the License is distributed on an "AS IS" BASIS,
120031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * See the License for the specific language governing permissions and
140031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * limitations under the License.
150031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall */
160031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
170031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall/*
180031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * MODUS OPERANDI
190031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * --------------
200031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
210031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * IPTABLES command sequence:
220031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
230031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * iptables -F
240031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
258c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t raw -F idletimer_PREROUTING
268c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t mangle -F idletimer_POSTROUTING
270031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
280031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
298c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t raw -N idletimer_PREROUTING
308c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t mangle -N idletimer_POSTROUTING
310031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
328c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t raw -D PREROUTING -j idletimer_PREROUTING
338c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t mangle -D POSTROUTING -j idletimer_POSTROUTING
340031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
350031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
368c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t raw -I PREROUTING -j idletimer_PREROUTING
378c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t mangle -I POSTROUTING -j idletimer_POSTROUTING
380031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
390031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * # For notifications to work the lable name must match the name of a valid interface.
400031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * # If the label name does match an interface, the rules will be a no-op.
410031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
428c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t raw -A idletimer_PREROUTING -i rmnet0 -j IDLETIMER  --timeout 5 --label test-chain --send_nl_msg 1
438c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -t mangle -A idletimer_POSTROUTING -o rmnet0 -j IDLETIMER  --timeout 5 --label test-chain --send_nl_msg 1
440031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
458c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -nxvL -t raw
468c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * iptables -nxvL -t mangle
470031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
480031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * =================
490031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
500031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * ndc command sequence
510031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * ------------------
520031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * ndc idletimer enable
5398f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai * ndc idletimer add <iface> <timeout> <class label>
5498f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai * ndc idletimer remove <iface> <timeout> <class label>
550031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
560031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * Monitor effect on the iptables chains after each step using:
578c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *     iptables -nxvL -t raw
588c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *     iptables -nxvL -t mangle
590031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
600031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * Remember that the timeout value has to be same at the time of the
610031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * removal.
620031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
638c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * =================
648c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
658c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * Verifying the iptables rule
668c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * ---------------------------
678c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * We want to make sure the iptable rules capture every packet. It can be
688c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * verified with tcpdump. First take a note of the pkts count for the two rules:
698c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
708c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * adb shell iptables -t mangle -L idletimer_mangle_POSTROUTING -v && adb shell iptables -t raw -L idletimer_raw_PREROUTING -v
718c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
728c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * And then, before any network traffics happen on the device, run tcpdump:
738c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
748c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * adb shell tcpdump | tee tcpdump.log
758c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
768c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * After a while run iptables commands again, you could then count the number
778c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * of incoming and outgoing packets captured by tcpdump, and compare that with
788c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * the numbers reported by iptables command. There shouldn't be too much
798c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * difference on these numbers, i.e., with 2000 packets captured it should
808c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * differ by less than 5.
818c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
828c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai * =================
838c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai *
840031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * Note that currently if the name of the iface is incorrect, iptables
850031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * will setup rules without checking if it is the name of a valid
860031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * interface (although no notifications will ever be received).  It is
870031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * the responsibility of code in Java land to ensure that the interface name
880031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * is correct. The benefit of this, is that idletimers can be setup on
890031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * interfaces than come and go.
900031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
910031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * A remove should be called for each add command issued during cleanup, as duplicate
920031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall * entries of the rule may exist and will all have to removed.
930031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall *
940031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall */
950031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
961c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma#define LOG_NDEBUG 0
971c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma
980031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <stdlib.h>
990031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <errno.h>
1000031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <sys/socket.h>
1010031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <sys/stat.h>
102001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand#include <sys/wait.h>
1030031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <fcntl.h>
1040031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <netinet/in.h>
1050031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <arpa/inet.h>
1060031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <string.h>
1070031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <cutils/properties.h>
1080031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1090031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#define LOG_TAG "IdletimerController"
1100031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include <cutils/log.h>
111001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand#include <logwrap/logwrap.h>
1120031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1130031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include "IdletimerController.h"
1140031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall#include "NetdConstants.h"
1150031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1168c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Baiconst char* IdletimerController::LOCAL_RAW_PREROUTING = "idletimer_raw_PREROUTING";
1178c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Baiconst char* IdletimerController::LOCAL_MANGLE_POSTROUTING = "idletimer_mangle_POSTROUTING";
1188e188ed5c989ddcc07f0f5e9839493c22d17e7b6Jeff Sharkey
1190031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP AbgrallIdletimerController::IdletimerController() {
1200031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1210031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1220031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP AbgrallIdletimerController::~IdletimerController() {
1230031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1240031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall/* return 0 or non-zero */
125001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchandint IdletimerController::runIpxtablesCmd(int argc, const char **argv) {
1261c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    int resIpv4, resIpv6;
1271c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma
1281c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    // Running for IPv4
1291c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    argv[0] = IPTABLES_PATH;
1301c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    resIpv4 = android_fork_execvp(argc, (char **)argv, NULL, false, false);
1311c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma
1321c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    // Running for IPv6
1331c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    argv[0] = IP6TABLES_PATH;
1341c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    resIpv6 = android_fork_execvp(argc, (char **)argv, NULL, false, false);
1351c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma
1361c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma#if !LOG_NDEBUG
1371c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    std::string full_cmd = argv[0];
1381c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    argc--; argv++;
1391c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    for (; argc; argc--, argv++) {
1401c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma        full_cmd += " ";
1411c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma        full_cmd += argv[0];
1421c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    }
1431c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    ALOGV("runCmd(%s) res_ipv4=%d, res_ipv6=%d", full_cmd.c_str(), resIpv4, resIpv6);
1441c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma#endif
1451c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma
1461c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma    return (resIpv4 == 0 && resIpv6 == 0) ? 0 : -1;
1470031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1480031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1490031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrallbool IdletimerController::setupIptablesHooks() {
1500031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall    return true;
1510031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1520031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1530031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrallint IdletimerController::setDefaults() {
1548c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai  int res;
155001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  const char *cmd1[] = {
1561c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma      NULL, // To be filled inside runIpxtablesCmd
15794b2ab92f6e886d24092781159714be75c9f3954Paul Jensen      "-w",
158001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-t",
159001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "raw",
160001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-F",
161001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      LOCAL_RAW_PREROUTING
162001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  };
163001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  res = runIpxtablesCmd(ARRAY_SIZE(cmd1), cmd1);
1648c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai
1658c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai  if (res)
1668c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai    return res;
1678c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai
168001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  const char *cmd2[] = {
1691c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma      NULL, // To be filled inside runIpxtablesCmd
17094b2ab92f6e886d24092781159714be75c9f3954Paul Jensen      "-w",
171001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-t",
172001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "mangle",
173001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-F",
174001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      LOCAL_MANGLE_POSTROUTING
175001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  };
176001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  res = runIpxtablesCmd(ARRAY_SIZE(cmd2), cmd2);
177001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand
1788c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai  return res;
1790031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1800031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1810031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrallint IdletimerController::enableIdletimerControl() {
1820031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall    int res = setDefaults();
1830031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall    return res;
1840031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1850031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1860031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrallint IdletimerController::disableIdletimerControl() {
1870031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall    int res = setDefaults();
1880031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall    return res;
1890031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
1900031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
1910031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrallint IdletimerController::modifyInterfaceIdletimer(IptOp op, const char *iface,
19298f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai                                                  uint32_t timeout,
19398f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai                                                  const char *classLabel) {
1940031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall  int res;
195001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  char timeout_str[11]; //enough to store any 32-bit unsigned decimal
196001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand
19769261cb65186e27dfbdc1e3eec796437f9968ff9JP Abgrall  if (!isIfaceName(iface)) {
19869261cb65186e27dfbdc1e3eec796437f9968ff9JP Abgrall    errno = ENOENT;
19969261cb65186e27dfbdc1e3eec796437f9968ff9JP Abgrall    return -1;
20069261cb65186e27dfbdc1e3eec796437f9968ff9JP Abgrall  }
20169261cb65186e27dfbdc1e3eec796437f9968ff9JP Abgrall
202001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  snprintf(timeout_str, sizeof(timeout_str), "%u", timeout);
203001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand
204001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  const char *cmd1[] = {
2051c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma      NULL, // To be filled inside runIpxtablesCmd
20694b2ab92f6e886d24092781159714be75c9f3954Paul Jensen      "-w",
207001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-t",
208001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "raw",
209001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      (op == IptOpAdd) ? "-A" : "-D",
210001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      LOCAL_RAW_PREROUTING,
211001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-i",
212001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      iface,
213001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-j",
214001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "IDLETIMER",
215001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "--timeout",
216001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      timeout_str,
217001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "--label",
218001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      classLabel,
219001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "--send_nl_msg",
220001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "1"
221001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  };
222001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  res = runIpxtablesCmd(ARRAY_SIZE(cmd1), cmd1);
2230031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
2248c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai  if (res)
2258c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai    return res;
2268c54ec5de3818ff0c0cfc735c817be2516454415Haoyu Bai
227001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  const char *cmd2[] = {
2281c2c27f0482f14d08fdc9a27972c7d73499c4622Ashish Sharma      NULL, // To be filled inside runIpxtablesCmd
22994b2ab92f6e886d24092781159714be75c9f3954Paul Jensen      "-w",
230001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-t",
231001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "mangle",
232001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      (op == IptOpAdd) ? "-A" : "-D",
233001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      LOCAL_MANGLE_POSTROUTING,
234001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-o",
235001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      iface,
236001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "-j",
237001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "IDLETIMER",
238001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "--timeout",
239001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      timeout_str,
240001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "--label",
241001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      classLabel,
242001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "--send_nl_msg",
243001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand      "1"
244001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  };
245001f0a436e9fe0353dccd98ee34b91095d9ed1a1Rom Lemarchand  res = runIpxtablesCmd(ARRAY_SIZE(cmd2), cmd2);
2460031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
2470031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall  return res;
2480031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
2490031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
25098f65d32b1530b4da6050e38d52f955710577efbHaoyu Baiint IdletimerController::addInterfaceIdletimer(const char *iface,
25198f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai                                               uint32_t timeout,
25298f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai                                               const char *classLabel) {
25398f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai  return modifyInterfaceIdletimer(IptOpAdd, iface, timeout, classLabel);
2540031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
2550031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
25698f65d32b1530b4da6050e38d52f955710577efbHaoyu Baiint IdletimerController::removeInterfaceIdletimer(const char *iface,
25798f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai                                                  uint32_t timeout,
25898f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai                                                  const char *classLabel) {
25998f65d32b1530b4da6050e38d52f955710577efbHaoyu Bai  return modifyInterfaceIdletimer(IptOpDelete, iface, timeout, classLabel);
2600031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall}
261