confd: Let products declare quirks of particular interfaces

Ideally, all drivers should behave the same. Alas, that is not the
world we live in. For quirks that we can not reliably probe for in any
other way, let products supply a JSON file that declares them.
This commit is contained in:
Tobias Waldekranz
2025-02-20 14:35:50 +01:00
parent ffab761274
commit f92d3846db
4 changed files with 24 additions and 0 deletions
+6
View File
@@ -126,6 +126,12 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
confd.root = json_load_file("/run/system.json", 0, NULL);
if (!confd.root)
goto err;
/* An optional file that contains hardware specific quirks for
* the network interfaces on running board.
*/
confd.ifquirks = json_load_file("/etc/product/interface-quirks.json", 0, NULL);
rc = ietf_interfaces_init(&confd);
if (rc)
goto err;
+1
View File
@@ -124,6 +124,7 @@ struct confd {
sr_subscription_ctx_t *sub;
sr_subscription_ctx_t *fsub; /* factory-default sub */
json_t *root;
json_t *ifquirks;
struct dagger netdag;
};
+15
View File
@@ -12,6 +12,21 @@
#include "ietf-interfaces.h"
bool iface_has_quirk(const char *ifname, const char *quirkname)
{
struct json_t *iface, *quirk;
if (!confd.ifquirks)
return false;
iface = json_object_get(confd.ifquirks, ifname);
if (!iface)
return false;
quirk = json_object_get(iface, quirkname);
return quirk ? json_is_true(quirk) : false;
}
static bool iface_is_phys(const char *ifname)
{
bool is_phys = false;
+2
View File
@@ -92,6 +92,8 @@ static inline bool is_member_port(struct lyd_node *cif)
return false;
}
bool iface_has_quirk(const char *ifname, const char *quirkname);
/* ieee802-ethernet-interface.c */
int netdag_gen_ethtool(struct dagger *net, struct lyd_node *cif, struct lyd_node *dif);