Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
NetworkSetup.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2020 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19
20#ifndef NETWORKSETUP_H
21#define NETWORKSETUP_H
22
23#include "Netfilter.h"
24#include "NetworkingHelper.h"
25#include "rt_dobby_schema.h"
26#include <DobbyRdkPluginUtils.h>
27
28#include <arpa/inet.h>
29#include <map>
30#include <list>
31#include <string>
32#include <memory>
33#include <mutex>
34#include <vector>
35
36
37// -----------------------------------------------------------------------------
44namespace NetworkSetup
45{
46 bool setupBridgeDevice(const std::shared_ptr<DobbyRdkPluginUtils> &utils,
47 const std::shared_ptr<Netfilter> &netfilter,
48 const std::vector<std::string> &extIfaces);
49
50 bool createNetns(const std::string &containerId);
51
52 bool setupVeth(const std::shared_ptr<DobbyRdkPluginUtils> &utils,
53 const std::shared_ptr<Netfilter> &netfilter,
54 const std::shared_ptr<NetworkingHelper> &helper,
55 const std::string &rootfsPath,
56 const std::string &containerId,
57 const NetworkType networkType);
58
59 bool removeVethPair(const std::shared_ptr<Netfilter> &netfilter,
60 const std::shared_ptr<NetworkingHelper> &helper,
61 const std::string &vethName,
62 const NetworkType networkType,
63 const std::string &containerId);
64
65 bool removeBridgeDevice(const std::shared_ptr<Netfilter> &netfilter,
66 const std::vector<std::string> &extIfaces);
67
68 void addResolvMount(const std::shared_ptr<DobbyRdkPluginUtils> &utils,
69 const std::shared_ptr<rt_dobby_schema> &cfg);
70
71 void addNetworkNamespace(const std::shared_ptr<rt_dobby_schema> &cfg);
72};
73
74bool setupContainerNet(const std::shared_ptr<NetworkingHelper> &helper);
75
76pid_t spawnNetnsOwner(const std::string &containerId);
77
78void deleteNetns(const std::string &containerId);
79
80#endif // !defined(NETWORKSETUP_H)
Functions to set up networking for containers.
bool setupVeth(const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::shared_ptr< Netfilter > &netfilter, const std::shared_ptr< NetworkingHelper > &helper, const std::string &rootfsPath, const std::string &containerId, const NetworkType networkType)
Called from host namespace.
Definition NetworkSetup.cpp:716
bool removeBridgeDevice(const std::shared_ptr< Netfilter > &netfilter, const std::vector< std::string > &extIfaces)
Clear out the iptables rules set for the bridge device and brings the interface down.
Definition NetworkSetup.cpp:1002
void addResolvMount(const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::shared_ptr< rt_dobby_schema > &cfg)
Adds a mount to /etc/resolv.conf.
Definition NetworkSetup.cpp:1077
bool setupBridgeDevice(const std::shared_ptr< DobbyRdkPluginUtils > &utils, const std::shared_ptr< Netfilter > &netfilter, const std::vector< std::string > &extIfaces)
Called from host namespace.
Definition NetworkSetup.cpp:355
void addNetworkNamespace(const std::shared_ptr< rt_dobby_schema > &cfg)
Adds the 'network' namespace to the OCI config.
Definition NetworkSetup.cpp:1106
bool removeVethPair(const std::shared_ptr< Netfilter > &netfilter, const std::shared_ptr< NetworkingHelper > &helper, const std::string &vethName, const NetworkType networkType, const std::string &containerId)
Remove iptables entries for the container's veth and bring the veth pair down.
Definition NetworkSetup.cpp:916