libptpmgmt 2.0
libptpmgmt library that provides the functionality of linuxptp pmc
Loading...
Searching...
No Matches
cfg.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-3.0-or-later
2 SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3
16#ifndef __PTPMGMT_CFG_H
17#define __PTPMGMT_CFG_H
18
19#ifdef __cplusplus
20#include <map>
21#include "bin.h"
22
23__PTPMGMT_NAMESPACE_BEGIN
24
25class SaFile;
26
34{
35 private:
36 #ifndef SWIG
38 class ConfigSection
39 {
40 public:
41 enum {
42 val_base_val,
43 transportSpecific_val = val_base_val,
44 domainNumber_val,
45 udp6_scope_val,
46 udp_ttl_val,
47 socket_priority_val,
48 network_transport_val,
49 active_key_id_val,
50 spp_val,
51 allow_unauth_val,
52 str_base_val,
53 uds_address_val = str_base_val,
54 sa_file_val,
55 bin_base_val,
56 ptp_dst_mac_val = bin_base_val,
57 p2p_dst_mac_val,
58 last_val,
59 };
60 /* new values must be add to ranges[] */
61 struct range_t {
62 const char *name;
63 const char *defStr;
64 uint32_t defVal;
65 uint32_t min;
66 uint32_t max;
67 };
68 /* ranges and default value */
69 static const range_t ranges[];
70 /* String values */
71 std::string m_str_vals[bin_base_val - str_base_val];
72 /* Binaries values */
73 Binary m_bin_vals[last_val - bin_base_val];
74 /* integer values */
75 uint32_t m_vals[str_base_val - val_base_val];
76 /* Determine if a value is set in the configuration file.
77 * Relevant for non global sections. */
78 bool m_set[last_val] = { false };
79
80 void setGlobal();
81 bool set_val(char *line);
82 };
83 std::map<std::string, ConfigSection> cfgSec;
84 ConfigSection *cfgGlobal; /* Not the owner, just a shortcut */
85 void clear_sections();
86
87 uint32_t get_num(int idx, const std::string &section) const;
88 const std::string &get_str(int idx, const std::string &section) const;
89 const Binary &get_bin(int idx, const std::string &section) const;
90 bool is_global(int idx, const std::string &section) const;
92 #endif
93 public:
94 ConfigFile();
100 bool read_cfg(const std::string &file);
107 uint8_t transportSpecific(const std::string &section = "") const;
114 uint8_t domainNumber(const std::string &section = "") const;
121 uint8_t udp6_scope(const std::string &section = "") const;
128 uint8_t udp_ttl(const std::string &section = "") const;
135 uint8_t socket_priority(const std::string &section = "") const;
142 uint8_t network_transport(const std::string &section = "") const;
149 uint32_t active_key_id(const std::string &section = "") const;
156 uint8_t spp(const std::string &section = "") const;
163 uint8_t allow_unauth(const std::string &section = "") const;
170 bool haveSpp(const std::string &section = "") const;
177 const std::string &uds_address(const std::string &section = "") const;
184 const std::string &sa_file(const std::string &section = "") const;
191 const Binary &ptp_dst_mac(const std::string &section = "") const;
198 const Binary &p2p_dst_mac(const std::string &section = "") const;
199};
200
217
224class Spp
225{
226 private:
227 #ifndef SWIG
228 struct key_t {
229 HMAC_t type = HMAC_SHA256;
230 Binary key;
231 size_t mac_size = 0;
232 void operator()(HMAC_t _t, const Binary &_k, size_t _m) {
233 type = _t;
234 key = _k;
235 mac_size = _m;
236 }
237 };
238 std::map<uint32_t, key_t> m_keys;
239 int8_t m_own_id;
240 protected:
242 bool set_val(char *line);
243 void set(long id) { m_own_id = (uint8_t)id; m_keys.clear(); }
244 friend class SaFile;
246 #endif
247 public:
257 bool addKey(uint32_t id, HMAC_t type, const Binary &value, size_t digest,
258 bool replace = true);
264 bool have(uint32_t key) const;
270 size_t mac_size(uint32_t key) const;
276 const Binary &key(uint32_t key) const;
281 size_t keys() const;
287 HMAC_t htype(uint32_t key) const;
292 uint8_t ownID() const;
297 Spp(uint8_t id);
298 Spp();
299};
300
308{
309 private:
310 std::map<uint8_t, Spp> m_spps;
311 public:
317 bool read_sa(const std::string &file);
327 bool read_sa(const ConfigFile &cfg, const std::string &section = "");
333 bool have(uint8_t spp) const;
340 bool have(uint8_t spp, uint32_t key) const;
346 const Spp &spp(uint8_t spp) const;
347};
348
349__PTPMGMT_NAMESPACE_END
350#else /* __cplusplus */
351#include "c/cfg.h"
352#endif /* __cplusplus */
353
354#endif /* __PTPMGMT_CFG_H */
Provide Binary class.
C interface to configuration class.
HMAC_t
Authentication key type.
Definition cfg.h:206
@ HMAC_AES256
Definition cfg.h:215
@ HMAC_SHA256
Definition cfg.h:207
@ HMAC_AES128
Definition cfg.h:211
Definition bin.h:27
Hold configuration parameters.
Definition cfg.h:34
const std::string & sa_file(const std::string &section="") const
const Binary & p2p_dst_mac(const std::string &section="") const
uint8_t socket_priority(const std::string &section="") const
bool read_cfg(const std::string &file)
uint8_t udp_ttl(const std::string &section="") const
const std::string & uds_address(const std::string &section="") const
uint8_t transportSpecific(const std::string &section="") const
uint8_t udp6_scope(const std::string &section="") const
uint32_t active_key_id(const std::string &section="") const
const Binary & ptp_dst_mac(const std::string &section="") const
uint8_t network_transport(const std::string &section="") const
bool haveSpp(const std::string &section="") const
uint8_t allow_unauth(const std::string &section="") const
uint8_t spp(const std::string &section="") const
uint8_t domainNumber(const std::string &section="") const
authentication security association file
Definition cfg.h:308
bool have(uint8_t spp, uint32_t key) const
bool have(uint8_t spp) const
const Spp & spp(uint8_t spp) const
bool read_sa(const std::string &file)
bool read_sa(const ConfigFile &cfg, const std::string &section="")
authentication security parameters
Definition cfg.h:225
Spp(uint8_t id)
bool addKey(uint32_t id, HMAC_t type, const Binary &value, size_t digest, bool replace=true)
uint8_t ownID() const
const Binary & key(uint32_t key) const
bool have(uint32_t key) const
HMAC_t htype(uint32_t key) const
size_t mac_size(uint32_t key) const
size_t keys() const