Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/core/sm/networkmanager/itf/firewall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
StaticArray<OutputAccessConfig, cMaxNumFirewallRules> mOutput;
};

/**
* Masquerade rule identity.
*/
struct MasqueradeParams {

Check failure on line 59 in src/core/sm/networkmanager/itf/firewall.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make sure that moving an object of class "MasqueradeParams" is "noexcept" (for instance, by ensuring that moving base classes and member data is "noexcept").

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ-4QONhbmWQebViiCDl&open=AZ-4QONhbmWQebViiCDl&pullRequest=635
StaticString<cSubnetLen> mSubnet;
StaticString<cInterfaceLen> mOutIfName;
};

/**
* Firewall interface.
*
Expand All @@ -69,7 +77,8 @@

/**
* Starts the firewall: creates the `inet aos` table, base chains and
* netfilter hooks (forward filter, postrouting nat).
* netfilter hooks (forward filter, postrouting nat) when they are absent.
* Rules that are already there are left alone.
*
* @return Error.
*/
Expand All @@ -82,6 +91,21 @@
*/
virtual Error Stop() = 0;

/**
* Removes the instance chains and masquerade rules that no longer belong
* to anything known, keeping the rest in place.
*
* Called on start so that artifacts left by a crashed SM are reaped
* without touching the rules of the instances that kept running.
*
* @param knownInstanceIDs instance ids whose chains must be kept.
* @param knownMasquerades masquerade rules that must be kept.
* @return Error.
*/
virtual Error RemoveOrphans(
const Array<StaticString<cIDLen>>& knownInstanceIDs, const Array<MasqueradeParams>& knownMasquerades)
= 0;

/**
* Adds a per-instance chain with the given input/output access rules.
*
Expand Down
40 changes: 40 additions & 0 deletions src/core/sm/networkmanager/itf/interfacemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,45 @@
#ifndef AOS_CORE_SM_NETWORKMANAGER_ITF_INTERFACEMANAGER_HPP_
#define AOS_CORE_SM_NETWORKMANAGER_ITF_INTERFACEMANAGER_HPP_

#include <core/common/tools/enum.hpp>
#include <core/common/types/common.hpp>
#include <core/common/types/network.hpp>

namespace aos::sm::networkmanager {

/** @addtogroup sm Service Manager
* @{
*/

/**
* Link kind type.
*/
class LinkKindType {
public:
enum class Enum { eUnknown, eBridge, eVlan, eVeth };

static const Array<const char* const> GetStrings()

Check warning on line 27 in src/core/sm/networkmanager/itf/interfacemanager.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this "const" qualifier.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ_BlsNRKVFiZXqfN2Kb&open=AZ_BlsNRKVFiZXqfN2Kb&pullRequest=635
{
static const char* const sLinkKindStrings[] = {"unknown", "bridge", "vlan", "veth"};

Check warning on line 29 in src/core/sm/networkmanager/itf/interfacemanager.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "std::array" or "std::vector" instead of a C-style array.

See more on https://sonarcloud.io/project/issues?id=aosedge_aos_core_lib_cpp&issues=AZ_BlsNRKVFiZXqfN2Kc&open=AZ_BlsNRKVFiZXqfN2Kc&pullRequest=635

return Array<const char* const>(sLinkKindStrings, ArraySize(sLinkKindStrings));
};
};

using LinkKindEnum = LinkKindType::Enum;
using LinkKind = EnumStringer<LinkKindType>;

/**
* Network link attributes as seen on the system.
*/
struct LinkInfo {
StaticString<cInterfaceLen> mName;
LinkKind mKind;
StaticString<cInterfaceLen> mMaster;
uint64_t mVlanID {};
bool mUp {};
};

/**
* Network interface manager interface.
*/
Expand All @@ -25,6 +56,15 @@
*/
virtual ~InterfaceManagerItf() = default;

/**
* Returns link attributes as they are on the system.
*
* @param ifname interface name.
* @param[out] info link attributes.
* @return Error, eNotFound if the link doesn't exist.
*/
virtual Error GetLink(const String& ifname, LinkInfo& info) const = 0;

/**
* Removes interface.
*
Expand Down
8 changes: 8 additions & 0 deletions src/core/sm/networkmanager/itf/namespacemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class NamespaceManagerItf {
*/
virtual Error CreateNetworkNamespace(const String& ns) = 0;

/**
* Checks whether network namespace exists on the system.
*
* @param ns network namespace name.
* @return RetWithError<bool>.
*/
virtual RetWithError<bool> IsNetworkNamespaceExist(const String& ns) const = 0;

/**
* Returns network namespace path.
*
Expand Down
Loading
Loading