move get_net_device_status function to dmcommon.c file

This commit is contained in:
Amin Ben Ramdhane 2021-02-11 19:14:27 +01:00
parent b90c069971
commit 679083337d
6 changed files with 30 additions and 32 deletions

View file

@ -10,7 +10,6 @@
*/
#include "dmentry.h"
#include "ethernet.h"
#include "atm.h"
struct atm_args
@ -231,7 +230,7 @@ static int set_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *i
/*#Device.ATM.Link.{i}.Status!SYSFS:/sys/class/net/@Name/operstate*/
static int get_atm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_device_status(((struct atm_args *)data)->ifname, value);
return get_net_device_status(((struct atm_args *)data)->ifname, value);
}
/*************************************************************

View file

@ -94,32 +94,6 @@ void get_bridge_port_linker(struct dmctx *ctx, char *intf_name, char **value)
}
}
int get_device_status(const char *device, char **value)
{
char *operstate = NULL;
get_net_device_sysfs(device, "operstate", &operstate);
if (operstate == NULL || *operstate == '\0') {
*value = "Down";
return 0;
}
if (strcmp(operstate, "up") == 0)
*value = "Up";
else if (strcmp(operstate, "unknown") == 0)
*value = "Unknown";
else if (strcmp(operstate, "notpresent") == 0)
*value = "NotPresent";
else if (strcmp(operstate, "lowerlayerdown") == 0)
*value = "LowerLayerDown";
else if (strcmp(operstate, "dormant") == 0)
*value = "Dormant";
else
*value = "Down";
return 0;
}
static int eth_iface_sysfs(const struct uci_section *data, const char *name, char **value)
{
char *device;
@ -619,7 +593,7 @@ static int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void
/*#Device.Ethernet.Interface.{i}.Status!SYSFS:/sys/class/net/@Name/operstate*/
static int get_EthernetInterface_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_device_status(((struct eth_port_args *)data)->ifname, value);
return get_net_device_status(((struct eth_port_args *)data)->ifname, value);
}
/*#Device.Ethernet.Interface.{i}.Alias!UCI:dmmap_ports/ethport,@i-1/eth_port_alias*/

View file

@ -30,6 +30,5 @@ extern DMLEAF tEthernetRMONStatsParams[];
void get_bridge_port_linker(struct dmctx *ctx, char *intf_name, char **value);
int is_vlan_termination_section(const char *name);
int get_device_status(const char *device, char **value);
#endif //__ETHERNET_H

View file

@ -10,7 +10,6 @@
*/
#include "dmentry.h"
#include "ethernet.h"
#include "ptm.h"
struct ptm_args
@ -128,7 +127,7 @@ static int set_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *i
/*#Device.PTM.Link.{i}.Status!SYSFS:/sys/class/net/@Name/operstate*/
static int get_ptm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_device_status(((struct ptm_args *)data)->ifname, value);
return get_net_device_status(((struct ptm_args *)data)->ifname, value);
}
/*************************************************************

View file

@ -1036,6 +1036,32 @@ int get_net_device_sysfs(const char *device, const char *name, char **value)
return 0;
}
int get_net_device_status(const char *device, char **value)
{
char *operstate = NULL;
get_net_device_sysfs(device, "operstate", &operstate);
if (operstate == NULL || *operstate == '\0') {
*value = "Down";
return 0;
}
if (strcmp(operstate, "up") == 0)
*value = "Up";
else if (strcmp(operstate, "unknown") == 0)
*value = "Unknown";
else if (strcmp(operstate, "notpresent") == 0)
*value = "NotPresent";
else if (strcmp(operstate, "lowerlayerdown") == 0)
*value = "LowerLayerDown";
else if (strcmp(operstate, "dormant") == 0)
*value = "Dormant";
else
*value = "Down";
return 0;
}
int get_net_iface_sysfs(const char *uci_iface, const char *name, char **value)
{
const char *device = get_device((char *)uci_iface);

View file

@ -266,6 +266,7 @@ struct uci_section *is_dmmap_section_exist_eq(char* package, char* section, char
int dm_read_sysfs_file(const char *file, char *dst, unsigned len);
int get_net_iface_sysfs(const char *uci_iface, const char *name, char **value);
int get_net_device_sysfs(const char *device, const char *name, char **value);
int get_net_device_status(const char *device, char **value);
char *get_device_from_wifi_iface(const char *wifi_iface, const char *wifi_section);
int dm_time_format(time_t ts, char **dst);
void convert_string_to_hex(const char *str, char *hex);