diff options
| author | Maciej Żenczykowski <maze@google.com> | 2019-12-24 15:27:14 -0800 |
|---|---|---|
| committer | Maciej Żenczykowski <maze@google.com> | 2019-12-27 13:47:00 -0800 |
| commit | dec83c74cacd37d0c25352e331748b55fcfa87c1 (patch) | |
| tree | 3e7d3bf8cb6bc7c66d9a0fc46a7d7b6a3874ab64 /server/BandwidthControllerTest.cpp | |
| parent | f007de6e7e953a87a7e279fb97f19028baa16143 (diff) | |
BandwidthController - consistently use -j not --jump throughout
There's already uses of -j in places, and that's the output from
iptables-save and it's shorter.
Generated via:
sed -i -r 's@--jump@-j@g' server/BandwidthControllerTest.cpp
sed -i -r 's@--jump@-j@g' server/BandwidthController.cpp
Test:
git grep '[-]-jump' -- now comes up empty
atest bpf_module_test clatd_test libbpf_android_test libnetdbpf_test
netd_integration_test netd_unit_test netdutils_test
resolv_integration_test resolv_unit_test
Bug: 136696213
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I06b8ea544f681911472c9b60336b31532c408a6f
Diffstat (limited to 'server/BandwidthControllerTest.cpp')
| -rw-r--r-- | server/BandwidthControllerTest.cpp | 137 |
1 files changed, 67 insertions, 70 deletions
diff --git a/server/BandwidthControllerTest.cpp b/server/BandwidthControllerTest.cpp index 9337ac5d..0966b7ff 100644 --- a/server/BandwidthControllerTest.cpp +++ b/server/BandwidthControllerTest.cpp @@ -61,12 +61,12 @@ const std::string ACCOUNT_RULES_WITHOUT_BPF = "-A bw_OUTPUT -o ipsec+ -j RETURN\n" "-A bw_OUTPUT -m policy --pol ipsec --dir out -j RETURN\n" "-A bw_OUTPUT -m owner --socket-exists\n" - "-A bw_costly_shared --jump bw_penalty_box\n" + "-A bw_costly_shared -j bw_penalty_box\n" "\n" - "-A bw_penalty_box --jump bw_happy_box\n" - "-A bw_happy_box --jump bw_data_saver\n" + "-A bw_penalty_box -j bw_happy_box\n" + "-A bw_happy_box -j bw_data_saver\n" "-A bw_data_saver -j RETURN\n" - "-I bw_happy_box -m owner --uid-owner 0-9999 --jump RETURN\n" + "-I bw_happy_box -m owner --uid-owner 0-9999 -j RETURN\n" "COMMIT\n" "*raw\n" "-A bw_raw_PREROUTING -i ipsec+ -j RETURN\n" @@ -92,11 +92,11 @@ const std::string ACCOUNT_RULES_WITH_BPF = "-A bw_OUTPUT -o ipsec+ -j RETURN\n" "-A bw_OUTPUT -m policy --pol ipsec --dir out -j RETURN\n" "\n" - "-A bw_costly_shared --jump bw_penalty_box\n" + + "-A bw_costly_shared -j bw_penalty_box\n" + StringPrintf("-I bw_penalty_box -m bpf --object-pinned %s -j REJECT\n", XT_BPF_BLACKLIST_PROG_PATH) + - "-A bw_penalty_box --jump bw_happy_box\n" - "-A bw_happy_box --jump bw_data_saver\n" + "-A bw_penalty_box -j bw_happy_box\n" + "-A bw_happy_box -j bw_data_saver\n" "-A bw_data_saver -j RETURN\n" + StringPrintf("-I bw_happy_box -m bpf --object-pinned %s -j RETURN\n", XT_BPF_WHITELIST_PROG_PATH) + @@ -276,21 +276,21 @@ TEST_F(BandwidthControllerTest, TestDisableBandwidthControl) { TEST_F(BandwidthControllerTest, TestEnableDataSaver) { mBw.enableDataSaver(true); std::string expected4 = - "*filter\n" - ":bw_data_saver -\n" - "-A bw_data_saver --jump REJECT\n" - "COMMIT\n"; + "*filter\n" + ":bw_data_saver -\n" + "-A bw_data_saver -j REJECT\n" + "COMMIT\n"; std::string expected6 = - "*filter\n" - ":bw_data_saver -\n" - "-A bw_data_saver -p icmpv6 --icmpv6-type packet-too-big -j RETURN\n" - "-A bw_data_saver -p icmpv6 --icmpv6-type router-solicitation -j RETURN\n" - "-A bw_data_saver -p icmpv6 --icmpv6-type router-advertisement -j RETURN\n" - "-A bw_data_saver -p icmpv6 --icmpv6-type neighbour-solicitation -j RETURN\n" - "-A bw_data_saver -p icmpv6 --icmpv6-type neighbour-advertisement -j RETURN\n" - "-A bw_data_saver -p icmpv6 --icmpv6-type redirect -j RETURN\n" - "-A bw_data_saver --jump REJECT\n" - "COMMIT\n"; + "*filter\n" + ":bw_data_saver -\n" + "-A bw_data_saver -p icmpv6 --icmpv6-type packet-too-big -j RETURN\n" + "-A bw_data_saver -p icmpv6 --icmpv6-type router-solicitation -j RETURN\n" + "-A bw_data_saver -p icmpv6 --icmpv6-type router-advertisement -j RETURN\n" + "-A bw_data_saver -p icmpv6 --icmpv6-type neighbour-solicitation -j RETURN\n" + "-A bw_data_saver -p icmpv6 --icmpv6-type neighbour-advertisement -j RETURN\n" + "-A bw_data_saver -p icmpv6 --icmpv6-type redirect -j RETURN\n" + "-A bw_data_saver -j REJECT\n" + "COMMIT\n"; expectIptablesRestoreCommands({ {V4, expected4}, {V6, expected6}, @@ -298,11 +298,10 @@ TEST_F(BandwidthControllerTest, TestEnableDataSaver) { mBw.enableDataSaver(false); std::string expected = { - "*filter\n" - ":bw_data_saver -\n" - "-A bw_data_saver --jump RETURN\n" - "COMMIT\n" - }; + "*filter\n" + ":bw_data_saver -\n" + "-A bw_data_saver -j RETURN\n" + "COMMIT\n"}; expectIptablesRestoreCommands({ {V4, expected}, {V6, expected}, @@ -315,16 +314,16 @@ const std::vector<std::string> makeInterfaceQuotaCommands(const std::string& ifa const char* c_chain = chain.c_str(); const char* c_iface = iface.c_str(); std::vector<std::string> cmds = { - "*filter", - StringPrintf(":%s -", c_chain), - StringPrintf("-A %s -j bw_penalty_box", c_chain), - StringPrintf("-I bw_INPUT %d -i %s --jump %s", ruleIndex, c_iface, c_chain), - StringPrintf("-I bw_OUTPUT %d -o %s --jump %s", ruleIndex, c_iface, c_chain), - StringPrintf("-A bw_FORWARD -i %s --jump %s", c_iface, c_chain), - StringPrintf("-A bw_FORWARD -o %s --jump %s", c_iface, c_chain), - StringPrintf("-A %s -m quota2 ! --quota %" PRIu64 " --name %s --jump REJECT", c_chain, - quota, c_iface), - "COMMIT\n", + "*filter", + StringPrintf(":%s -", c_chain), + StringPrintf("-A %s -j bw_penalty_box", c_chain), + StringPrintf("-I bw_INPUT %d -i %s -j %s", ruleIndex, c_iface, c_chain), + StringPrintf("-I bw_OUTPUT %d -o %s -j %s", ruleIndex, c_iface, c_chain), + StringPrintf("-A bw_FORWARD -i %s -j %s", c_iface, c_chain), + StringPrintf("-A bw_FORWARD -o %s -j %s", c_iface, c_chain), + StringPrintf("-A %s -m quota2 ! --quota %" PRIu64 " --name %s -j REJECT", c_chain, + quota, c_iface), + "COMMIT\n", }; return {Join(cmds, "\n")}; } @@ -334,14 +333,14 @@ const std::vector<std::string> removeInterfaceQuotaCommands(const std::string& i const char* c_chain = chain.c_str(); const char* c_iface = iface.c_str(); std::vector<std::string> cmds = { - "*filter", - StringPrintf("-D bw_INPUT -i %s --jump %s", c_iface, c_chain), - StringPrintf("-D bw_OUTPUT -o %s --jump %s", c_iface, c_chain), - StringPrintf("-D bw_FORWARD -i %s --jump %s", c_iface, c_chain), - StringPrintf("-D bw_FORWARD -o %s --jump %s", c_iface, c_chain), - StringPrintf("-F %s", c_chain), - StringPrintf("-X %s", c_chain), - "COMMIT\n", + "*filter", + StringPrintf("-D bw_INPUT -i %s -j %s", c_iface, c_chain), + StringPrintf("-D bw_OUTPUT -o %s -j %s", c_iface, c_chain), + StringPrintf("-D bw_FORWARD -i %s -j %s", c_iface, c_chain), + StringPrintf("-D bw_FORWARD -o %s -j %s", c_iface, c_chain), + StringPrintf("-F %s", c_chain), + StringPrintf("-X %s", c_chain), + "COMMIT\n", }; return {Join(cmds, "\n")}; } @@ -372,15 +371,15 @@ const std::vector<std::string> makeInterfaceSharedQuotaCommands(const std::strin const char* c_chain = chain.c_str(); const char* c_iface = iface.c_str(); std::vector<std::string> cmds = { - "*filter", - StringPrintf("-I bw_INPUT %d -i %s --jump %s", ruleIndex, c_iface, c_chain), - StringPrintf("-I bw_OUTPUT %d -o %s --jump %s", ruleIndex, c_iface, c_chain), - StringPrintf("-A bw_FORWARD -i %s --jump %s", c_iface, c_chain), - StringPrintf("-A bw_FORWARD -o %s --jump %s", c_iface, c_chain), + "*filter", + StringPrintf("-I bw_INPUT %d -i %s -j %s", ruleIndex, c_iface, c_chain), + StringPrintf("-I bw_OUTPUT %d -o %s -j %s", ruleIndex, c_iface, c_chain), + StringPrintf("-A bw_FORWARD -i %s -j %s", c_iface, c_chain), + StringPrintf("-A bw_FORWARD -o %s -j %s", c_iface, c_chain), }; if (insertQuota) { - cmds.push_back(StringPrintf( - "-I %s -m quota2 ! --quota %" PRIu64 " --name shared --jump REJECT", c_chain, quota)); + cmds.push_back(StringPrintf("-I %s -m quota2 ! --quota %" PRIu64 " --name shared -j REJECT", + c_chain, quota)); } cmds.push_back("COMMIT\n"); return {Join(cmds, "\n")}; @@ -392,15 +391,15 @@ const std::vector<std::string> removeInterfaceSharedQuotaCommands(const std::str const char* c_chain = chain.c_str(); const char* c_iface = iface.c_str(); std::vector<std::string> cmds = { - "*filter", - StringPrintf("-D bw_INPUT -i %s --jump %s", c_iface, c_chain), - StringPrintf("-D bw_OUTPUT -o %s --jump %s", c_iface, c_chain), - StringPrintf("-D bw_FORWARD -i %s --jump %s", c_iface, c_chain), - StringPrintf("-D bw_FORWARD -o %s --jump %s", c_iface, c_chain), + "*filter", + StringPrintf("-D bw_INPUT -i %s -j %s", c_iface, c_chain), + StringPrintf("-D bw_OUTPUT -o %s -j %s", c_iface, c_chain), + StringPrintf("-D bw_FORWARD -i %s -j %s", c_iface, c_chain), + StringPrintf("-D bw_FORWARD -o %s -j %s", c_iface, c_chain), }; if (deleteQuota) { - cmds.push_back(StringPrintf( - "-D %s -m quota2 ! --quota %" PRIu64 " --name shared --jump REJECT", c_chain, quota)); + cmds.push_back(StringPrintf("-D %s -m quota2 ! --quota %" PRIu64 " --name shared -j REJECT", + c_chain, quota)); } cmds.push_back("COMMIT\n"); return {Join(cmds, "\n")}; @@ -515,22 +514,20 @@ TEST_F(BandwidthControllerTest, ManipulateSpecialApps) { std::vector<const char *> appUids = { "1000", "1001", "10012" }; std::vector<std::string> expected = { - "*filter\n" - "-I bw_happy_box -m owner --uid-owner 1000 --jump RETURN\n" - "-I bw_happy_box -m owner --uid-owner 1001 --jump RETURN\n" - "-I bw_happy_box -m owner --uid-owner 10012 --jump RETURN\n" - "COMMIT\n" - }; + "*filter\n" + "-I bw_happy_box -m owner --uid-owner 1000 -j RETURN\n" + "-I bw_happy_box -m owner --uid-owner 1001 -j RETURN\n" + "-I bw_happy_box -m owner --uid-owner 10012 -j RETURN\n" + "COMMIT\n"}; EXPECT_EQ(0, mBw.addNiceApps(appUids.size(), const_cast<char**>(&appUids[0]))); expectIptablesRestoreCommands(expected); expected = { - "*filter\n" - "-D bw_penalty_box -m owner --uid-owner 1000 --jump REJECT\n" - "-D bw_penalty_box -m owner --uid-owner 1001 --jump REJECT\n" - "-D bw_penalty_box -m owner --uid-owner 10012 --jump REJECT\n" - "COMMIT\n" - }; + "*filter\n" + "-D bw_penalty_box -m owner --uid-owner 1000 -j REJECT\n" + "-D bw_penalty_box -m owner --uid-owner 1001 -j REJECT\n" + "-D bw_penalty_box -m owner --uid-owner 10012 -j REJECT\n" + "COMMIT\n"}; EXPECT_EQ(0, mBw.removeNaughtyApps(appUids.size(), const_cast<char**>(&appUids[0]))); expectIptablesRestoreCommands(expected); } |
