Android-cuttlefish cvd tool
nftables_nft.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 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#ifndef ALLOCD_NET_NFTABLES_NFT_H_
18#define ALLOCD_NET_NFTABLES_NFT_H_
19
20#include <stdint.h>
21
22#include <string>
23#include <string_view>
24
25#include "allocd/net/nftables.h"
27
28namespace cuttlefish {
29
30class NftablesNft : public Nftables {
31 public:
32 NftablesNft() = default;
33 ~NftablesNft() override = default;
34
35 // Returns the resolved path to the `nft` binary, or an error if it is not
36 // available. Static so callers can probe for nft support without having to
37 // construct an instance.
39
40 Result<void> EnsureTable(std::string_view family,
41 std::string_view table) override;
42 Result<void> DeleteTable(std::string_view family,
43 std::string_view table) override;
44 Result<void> EnsureChain(std::string_view family, std::string_view table,
45 std::string_view chain,
46 std::string_view content) override;
47 Result<uint64_t> AddRule(std::string_view family, std::string_view table,
48 std::string_view chain, std::string_view content,
49 std::string_view comment) override;
50 Result<void> DeleteRule(std::string_view family, std::string_view table,
51 std::string_view chain, uint64_t handle) override;
52 Result<void> DeleteRulesByComment(std::string_view family,
53 std::string_view table,
54 std::string_view chain,
55 std::string_view comment) override;
56};
57
58} // namespace cuttlefish
59
60#endif // ALLOCD_NET_NFTABLES_NFT_H_
Definition: nftables_nft.h:30
static Result< std::string > BinaryPath()
Definition: nftables_nft.cc:58
Result< void > DeleteRulesByComment(std::string_view family, std::string_view table, std::string_view chain, std::string_view comment) override
Definition: nftables_nft.cc:166
Result< void > DeleteRule(std::string_view family, std::string_view table, std::string_view chain, uint64_t handle) override
Definition: nftables_nft.cc:147
Result< void > EnsureChain(std::string_view family, std::string_view table, std::string_view chain, std::string_view content) override
Definition: nftables_nft.cc:91
~NftablesNft() override=default
Result< void > DeleteTable(std::string_view family, std::string_view table) override
Definition: nftables_nft.cc:78
Result< uint64_t > AddRule(std::string_view family, std::string_view table, std::string_view chain, std::string_view content, std::string_view comment) override
Definition: nftables_nft.cc:112
Result< void > EnsureTable(std::string_view family, std::string_view table) override
Definition: nftables_nft.cc:65
Definition: nftables.h:28
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30