Android-cuttlefish cvd tool
nft_rule.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_NFT_RULE_H_
18#define ALLOCD_NET_NFT_RULE_H_
19
20#include <string>
21#include <string_view>
22
23#include "allocd/net/nftables.h"
25
26namespace cuttlefish {
27
28class NftRule {
29 public:
30 // `tag` is a caller-supplied unique identifier (e.g. an interface name).
31 static Result<NftRule> Create(Nftables& nft, std::string_view family,
32 std::string_view table, std::string_view chain,
33 std::string_view content, std::string_view tag);
34
35 ~NftRule();
36
37 NftRule(NftRule&& r) noexcept;
38 NftRule& operator=(NftRule&& r) = delete;
39 NftRule(const NftRule& r) = delete;
40 NftRule& operator=(const NftRule& r) = delete;
41
42 private:
43 NftRule(Nftables* nft, std::string_view family, std::string_view table,
44 std::string_view chain, std::string comment);
45
46 Nftables* nft_ = nullptr;
47 std::string family_;
48 std::string table_;
49 std::string chain_;
50 std::string comment_;
51};
52
53} // namespace cuttlefish
54
55#endif // ALLOCD_NET_NFT_RULE_H_
Definition: nft_rule.h:28
NftRule & operator=(const NftRule &r)=delete
~NftRule()
Definition: nft_rule.cc:61
NftRule(NftRule &&r) noexcept
Definition: nft_rule.cc:54
NftRule & operator=(NftRule &&r)=delete
std::string family_
Definition: nft_rule.h:47
std::string table_
Definition: nft_rule.h:48
std::string chain_
Definition: nft_rule.h:49
std::string comment_
Definition: nft_rule.h:50
Nftables * nft_
Definition: nft_rule.h:46
NftRule(const NftRule &r)=delete
static Result< NftRule > Create(Nftables &nft, std::string_view family, std::string_view table, std::string_view chain, std::string_view content, std::string_view tag)
Definition: nft_rule.cc:37
Definition: nftables.h:28
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30