libbbfdm: moved Device.Ethernet. to plugin

This commit is contained in:
Amit Kumar 2024-03-15 08:30:05 +00:00 committed by Vivek Kumar Dutta
parent 71afbfca60
commit fde8eb8edf
8 changed files with 12 additions and 2121 deletions

View file

@ -104,3 +104,4 @@ All supported tools are presented in this file[BBFDM Tools](./tools/README.md)
| Device.FAST. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |
| Device.ATM. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |
| Device.PTM. | dslmngr | https://dev.iopsys.eu/hal/dslmngr.git |
| Device.Ethernet. | ethmngr | https://dev.iopsys.eu/hal/ethmngr.git |

View file

@ -15,7 +15,6 @@
#include "times.h"
#include "upnp.h"
#include "ip.h"
#include "ethernet.h"
#include "bridging.h"
#include "wifi.h"
#include "dhcpv4.h"
@ -91,7 +90,6 @@ DMOBJ tDeviceObj[] = {
{"WiFi", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tWiFiObj, tWiFiParams, NULL, BBFDM_BOTH, NULL},
{"Bridging", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tBridgingObj, tBridgingParams, NULL, BBFDM_BOTH, NULL},
{"IP", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tIPObj, tIPParams, NULL, BBFDM_BOTH, NULL},
{"Ethernet", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tEthernetObj, tEthernetParams, NULL, BBFDM_BOTH, NULL},
{"DHCPv4", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/dhcp.sh,/etc/config/dhcp", NULL, NULL, NULL, tDHCPv4Obj, tDHCPv4Params, NULL, BBFDM_BOTH, NULL},
{"DHCPv6", &DMREAD, NULL, NULL, "file:/lib/netifd/proto/dhcpv6.sh,/etc/config/dhcp", NULL, NULL, NULL, tDHCPv6Obj, tDHCPv6Params, NULL, BBFDM_BOTH, NULL},
{"NAT", &DMREAD, NULL, NULL, "file:/etc/config/firewall", NULL, NULL, NULL, tNATObj, tNATParams, NULL, BBFDM_BOTH, NULL},

File diff suppressed because it is too large Load diff

View file

@ -1,31 +0,0 @@
/*
* Copyright (C) 2019 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*
*/
#ifndef __ETHERNET_H
#define __ETHERNET_H
#include "libbbfdm-api/dmcommon.h"
extern DMOBJ tEthernetObj[];
extern DMLEAF tEthernetParams[];
extern DMOBJ tEthernetInterfaceObj[];
extern DMLEAF tEthernetInterfaceParams[];
extern DMLEAF tEthernetInterfaceStatsParams[];
extern DMOBJ tEthernetLinkObj[];
extern DMLEAF tEthernetLinkParams[];
extern DMLEAF tEthernetLinkStatsParams[];
extern DMOBJ tEthernetVLANTerminationObj[];
extern DMLEAF tEthernetVLANTerminationParams[];
extern DMLEAF tEthernetVLANTerminationStatsParams[];
extern DMLEAF tEthernetRMONStatsParams[];
#endif //__ETHERNET_H

View file

@ -1,307 +0,0 @@
/*
* Copyright (C) 2023 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
*
*/
#include "ethernet.h"
/*************************************************************
* ENTRY METHOD
**************************************************************/
static int browseEthernetMACVLANInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
char *inst = NULL;
synchronize_specific_config_sections_with_dmmap_eq("network", "device", "dmmap_network", "type", "macvlan", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "mac_vlan_instance", "mac_vlan_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int addObjEthernetMACVLAN(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_network = NULL;
char device_name[32];
snprintf(device_name, sizeof(device_name), "mac_vlan_%s", *instance);
// Add device section
dmuci_add_section("network", "device", &s);
dmuci_rename_section_by_section(s, device_name);
dmuci_set_value_by_section(s, "type", "macvlan");
// Add device section in dmmap_network file
dmuci_add_section_bbfdm("dmmap_network", "device", &dmmap_network);
dmuci_set_value_by_section(dmmap_network, "section_name", device_name);
dmuci_set_value_by_section(dmmap_network, "mac_vlan_instance", *instance);
return 0;
}
static int delObjEthernetMACVLAN(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
switch (del_action) {
case DEL_INST:
// Update Ethernet MAC VLAN Top Layers
ethernet___Update_MAC_VLAN_Top_Layers(refparam, "");
// Remove device section
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
// Remove device section in dmmap_network file
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
static int get_EthernetMACVLAN_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
static int set_EthernetMACVLAN_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
bool b;
switch (action) {
case VALUECHECK:
if (bbfdm_validate_boolean(ctx, value))
return FAULT_9007;
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
}
static int get_EthernetMACVLAN_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *device = NULL;
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &device);
return get_net_device_status(device, value);
}
static int get_EthernetMACVLAN_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return bbf_get_alias(ctx, ((struct dmmap_dup *)data)->dmmap_section, "mac_vlan_alias", instance, value);
}
static int set_EthernetMACVLAN_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
return bbf_set_alias(ctx, ((struct dmmap_dup *)data)->dmmap_section, "mac_vlan_alias", instance, value);
}
static int get_EthernetMACVLAN_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", value);
return 0;
}
static int get_EthernetMACVLAN_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "LowerLayers", value);
if ((*value)[0] == '\0') {
char *linker = NULL;
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ifname", &linker);
if (!linker || *linker == '\0')
return 0;
adm_entry_get_reference_param(ctx, "Device.Ethernet.VLANTermination.*.Name", linker, value);
if (DM_STRLEN(*value))
goto end;
adm_entry_get_reference_param(ctx, "Device.Ethernet.Link.*.Name", linker, value);
end:
// Store LowerLayers value
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "LowerLayers", *value);
} else {
if (!adm_entry_object_exists(ctx, *value))
*value = "";
}
return 0;
}
static int set_EthernetMACVLAN_LowerLayers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char *allowed_objects[] = {
"Device.Ethernet.VLANTermination.",
"Device.Ethernet.Link.",
NULL};
struct dm_reference reference = {0};
char name[32] = {0};
bbf_get_reference_args(value, &reference);
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string_list(ctx, reference.path, -1, -1, 1024, -1, -1, NULL, NULL))
return FAULT_9007;
if (dm_validate_allowed_objects(ctx, &reference, allowed_objects))
return FAULT_9007;
break;
case VALUESET:
// Store LowerLayers value under dmmap section
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "LowerLayers", reference.path);
// Update ifname option
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", reference.value);
if (DM_STRLEN(reference.value)) {
char *dev_name = ethernet___get_ethernet_interface_name(reference.value);
snprintf(name, sizeof(name), "%s_%s", dev_name, instance);
}
// Update name option
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", name);
// Update Ethernet MAC VLAN Top Layers
ethernet___Update_MAC_VLAN_Top_Layers(refparam, name);
break;
}
return 0;
}
static int get_EthernetMACVLAN_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "macaddr", value);
return 0;
}
static int set_EthernetMACVLAN_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
switch (action) {
case VALUECHECK:
if (bbfdm_validate_string(ctx, value, -1, 17, NULL, MACAddress))
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "macaddr", value);
break;
}
return 0;
}
static int eth_macvlan_sysfs(const struct uci_section *data, const char *name, char **value)
{
char *device;
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &device);
return get_net_device_sysfs(device, name, value);
}
static int get_EthernetMACVLANStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/tx_bytes", value);
}
static int get_EthernetMACVLANStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/rx_bytes", value);
}
static int get_EthernetMACVLANStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/tx_packets", value);
}
static int get_EthernetMACVLANStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/rx_packets", value);
}
static int get_EthernetMACVLANStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/tx_errors", value);
}
static int get_EthernetMACVLANStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/rx_errors", value);
}
static int get_EthernetMACVLANStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/tx_dropped", value);
}
static int get_EthernetMACVLANStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/rx_dropped", value);
}
static int get_EthernetMACVLANStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_macvlan_sysfs(data, "statistics/multicast", value);
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
DMOBJ tIOPSYS_EthernetObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys, version*/
{BBF_VENDOR_PREFIX"MACVLAN", &DMWRITE, addObjEthernetMACVLAN, delObjEthernetMACVLAN, NULL, browseEthernetMACVLANInst, NULL, NULL, tEthernetMACVLANObj, tEthernetMACVLANParams, NULL, BBFDM_BOTH, NULL},
{0}
};
DMLEAF tEthernetMACVLANParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
{"Enable", &DMWRITE, DMT_BOOL, get_EthernetMACVLAN_Enable, set_EthernetMACVLAN_Enable, BBFDM_BOTH},
{"Status", &DMREAD, DMT_STRING, get_EthernetMACVLAN_Status, NULL, BBFDM_BOTH},
{"Alias", &DMWRITE, DMT_STRING, get_EthernetMACVLAN_Alias, set_EthernetMACVLAN_Alias, BBFDM_BOTH},
{"Name", &DMREAD, DMT_STRING, get_EthernetMACVLAN_Name, NULL, BBFDM_BOTH, DM_FLAG_LINKER},
{"LowerLayers", &DMWRITE, DMT_STRING, get_EthernetMACVLAN_LowerLayers, set_EthernetMACVLAN_LowerLayers, BBFDM_BOTH, DM_FLAG_REFERENCE},
{"MACAddress", &DMWRITE, DMT_STRING, get_EthernetMACVLAN_MACAddress, set_EthernetMACVLAN_MACAddress, BBFDM_BOTH},
{0}
};
DMOBJ tEthernetMACVLANObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys, version*/
{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tEthernetMACVLANStatsParams, NULL, BBFDM_BOTH, NULL},
{0}
};
DMLEAF tEthernetMACVLANStatsParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
{"BytesSent", &DMREAD, DMT_UNLONG, get_EthernetMACVLANStats_BytesSent, NULL, BBFDM_BOTH},
{"BytesReceived", &DMREAD, DMT_UNLONG, get_EthernetMACVLANStats_BytesReceived, NULL, BBFDM_BOTH},
{"PacketsSent", &DMREAD, DMT_UNLONG, get_EthernetMACVLANStats_PacketsSent, NULL, BBFDM_BOTH},
{"PacketsReceived", &DMREAD, DMT_UNLONG, get_EthernetMACVLANStats_PacketsReceived, NULL, BBFDM_BOTH},
{"ErrorsSent", &DMREAD, DMT_UNINT, get_EthernetMACVLANStats_ErrorsSent, NULL, BBFDM_BOTH},
{"ErrorsReceived", &DMREAD, DMT_UNINT, get_EthernetMACVLANStats_ErrorsReceived, NULL, BBFDM_BOTH},
{"DiscardPacketsSent", &DMREAD, DMT_UNINT, get_EthernetMACVLANStats_DiscardPacketsSent, NULL, BBFDM_BOTH},
{"DiscardPacketsReceived", &DMREAD, DMT_UNINT, get_EthernetMACVLANStats_DiscardPacketsReceived, NULL, BBFDM_BOTH},
{"MulticastPacketsReceived", &DMREAD, DMT_UNLONG, get_EthernetMACVLANStats_MulticastPacketsReceived, NULL, BBFDM_BOTH},
{0}
};

View file

@ -1,22 +0,0 @@
/*
* Copyright (C) 2023 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
*
*/
#ifndef __IOPSYS_ETHERNET_H
#define __IOPSYS_ETHERNET_H
#include "dmlayer.h"
extern DMOBJ tIOPSYS_EthernetObj[];
extern DMLEAF tEthernetMACVLANParams[];
extern DMOBJ tEthernetMACVLANObj[];
extern DMLEAF tEthernetMACVLANStatsParams[];
#endif //__IOPSYS_ETHERNET_H

View file

@ -12,7 +12,6 @@
#include "device.h"
#include "deviceinfo.h"
#include "bridging.h"
#include "ethernet.h"
#include "ip.h"
#include "times.h"
#include "wifi.h"
@ -22,7 +21,6 @@ DM_MAP_OBJ tDynamicObj[] = {
/* parentobj, nextobject, parameter */
{"Device.", tIOPSYS_DeviceObj, NULL},
{"Device.DeviceInfo.", NULL, tIOPSYS_DeviceInfoParams},
{"Device.Ethernet.", tIOPSYS_EthernetObj, NULL},
{"Device.Time.", NULL, tIOPSYS_TimeParams},
{"Device.Bridging.Bridge.{i}.Port.{i}.", NULL, tIOPSYS_BridgingBridgePortParams},
{"Device.WiFi.AccessPoint.{i}.", NULL, tIOPSYS_WiFiAccessPointParams},

View file

@ -181,6 +181,16 @@
"bbf_plugin/ptm.c",
"bbf_plugin/plugin.c"
]
},
{
"repo": "https://dev.iopsys.eu/hal/ethmngr.git",
"proto": "git",
"version": "devel",
"dm_files": [
"bbf_plugin/ethernet.c",
"bbf_plugin/vendor_ethernet.c",
"bbf_plugin/dmlayer.c"
]
}
],
"output": {