Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Netlink.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 2016 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 * File: Netlink.h
21 *
22 */
23#ifndef NETLINK_H
24#define NETLINK_H
25
26#include <DobbyRdkPluginUtils.h>
27
28#include <string>
29#include <mutex>
30#include <memory>
31#include <array>
32#include <list>
33
34#include <arpa/inet.h>
35
36struct nl_sock;
37
38class NlLink;
39
40
41// -----------------------------------------------------------------------------
54{
55public:
56 Netlink();
57 ~Netlink();
58
59public:
60 bool isValid() const;
61
62public:
63 bool ifaceUp(const std::string& ifaceName);
64 bool ifaceDown(const std::string& ifaceName);
65
66 bool ifaceIsUp(const std::string& ifaceName) const;
67 bool ifaceExists(const std::string& ifaceName) const;
68
69 bool setIfaceAddress(const std::string& ifaceName,
70 const in_addr_t address, const in_addr_t netmask);
71 bool setIfaceAddress(const std::string& ifaceName,
72 const struct in6_addr address, const int netmask);
73
74 bool setIfaceForwarding(const std::string& ifaceName, bool enable);
75 bool setIfaceForwarding6(const std::shared_ptr<DobbyRdkPluginUtils> &utils,
76 const std::string& ifaceName, bool enable);
77
78 bool setIfaceRouteLocalNet(const std::string& ifaceName, bool enable);
79
80 bool setIfaceAcceptRa(const std::shared_ptr<DobbyRdkPluginUtils> &utils,
81 const std::string& ifaceName, int value);
82
83 bool setIfaceMAC(const std::string& ifaceName,
84 const std::array<uint8_t, 6>& address);
85 std::array<uint8_t, 6> getIfaceMAC(const std::string& ifaceName);
86
88 {
89 int index;
90 char name[16];
91 uint8_t mac[6];
92 };
93
94 std::list<BridgePortDetails> getAttachedIfaces(const std::string& bridgeName);
95
96public:
97 bool createBridge(const std::string& bridgeName);
98 bool destroyBridge(const std::string& bridgeName);
99
100 bool addIfaceToBridge(const std::string& bridgeName,
101 const std::string& ifaceName);
102 bool delIfaceFromBridge(const std::string& bridgeName,
103 const std::string& ifaceName);
104
105public:
106 std::string createVeth(const std::string& peerVethName,
107 pid_t peerPid,
108 std::vector<std::string> &takenVeths);
109 bool checkVeth(const std::string& vethName);
110
111public:
112 bool addRoute(const std::string& iface, const in_addr_t destination,
113 const in_addr_t netmask, const in_addr_t gateway);
114 bool addRoute(const std::string& iface, const struct in6_addr destination,
115 const int netmask, const struct in6_addr gateway);
116
117 bool addArpEntry(const std::string &iface, in_addr_t address,
118 const std::array<uint8_t, 6> &mac);
119
120 bool delArpEntry(const std::string &iface, in_addr_t address);
121
122private:
123 bool applyChangesToLink(const std::string& ifaceName,
124 const NlLink& changes);
125
126 bool setLinkAddress(const NlLink& link,
127 const in_addr_t address, const in_addr_t netmask);
128 bool setLinkAddress(const NlLink& link,
129 const struct in6_addr address, const int netmask);
130
131 bool setIfaceConfig(const std::string& ifaceName, const unsigned int configId,
132 const uint32_t value);
133
134
135 std::string getAvailableVethName(const int startIndex) const;
136
137private:
138 struct nl_sock* mSocket;
139 int mSysClassNetDirFd;
140 mutable std::mutex mLock;
141};
142
143
144#endif // !defined(NETLINK_H)