From 7f6b13b082e50ae1dcc57ddc06be5e3431c8d99a Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Mon, 6 Nov 2023 14:13:42 +0000 Subject: [PATCH] Update the logic to identify 'macvlan' device --- libbbfdm-api/dmapi.h | 1 + libbbfdm/dmtree/tr181/ethernet.c | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/libbbfdm-api/dmapi.h b/libbbfdm-api/dmapi.h index afcab7b7..cdae9c4a 100644 --- a/libbbfdm-api/dmapi.h +++ b/libbbfdm-api/dmapi.h @@ -59,6 +59,7 @@ do { \ #define DM_STRLEN(SRC) ((SRC != NULL) ? strlen(SRC) : 0) #define DM_STRSTR(STR, MATCH) ((STR != NULL && MATCH != NULL) ? strstr(STR, MATCH) : NULL) #define DM_STRCHR(STR, CHR) ((STR != NULL) ? strchr(STR, CHR) : NULL) +#define DM_STRRCHR(STR, CHR) ((STR != NULL) ? strrchr(STR, CHR) : NULL) #define DM_STRTOL(SRC) ((SRC != NULL) ? strtol(SRC, NULL, 10) : 0) #define DM_STRTOUL(SRC) ((SRC != NULL) ? strtoul(SRC, NULL, 10) : 0) #define DM_STRCMP(S1, S2) ((S1 != NULL && S2 != NULL) ? strcmp(S1, S2) : -1) diff --git a/libbbfdm/dmtree/tr181/ethernet.c b/libbbfdm/dmtree/tr181/ethernet.c index 17ba1404..b3cda37a 100644 --- a/libbbfdm/dmtree/tr181/ethernet.c +++ b/libbbfdm/dmtree/tr181/ethernet.c @@ -100,6 +100,23 @@ bool ethernet___name_exists_in_devices(char *name) return false; } +static bool is_mac_vlan_interface(char *device_name) +{ + struct uci_section *s = NULL; + char *type = NULL, *name = NULL; + + uci_foreach_sections("network", "device", s) { + + dmuci_get_value_by_section_string(s, "type", &type); + dmuci_get_value_by_section_string(s, "name", &name); + + if (DM_STRCMP(type, "macvlan") == 0 && DM_STRCMP(name, device_name) == 0) + return true; + } + + return false; +} + static void add_ethernet_link_section(char *device, char *macaddr) { struct uci_section *dmmap_s = NULL; @@ -144,13 +161,15 @@ static void dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_no DM_STRNCPY(dev_name, device, sizeof(dev_name)); - char *has_vid = DM_STRCHR(dev_name, '.'); + char *has_vid = DM_STRRCHR(dev_name, '.'); if (has_vid) *has_vid = '\0'; - char *is_mac_vlan = DM_STRCHR(dev_name, '_'); - if (is_mac_vlan) - *is_mac_vlan = '\0'; + if (is_mac_vlan_interface(dev_name)) { + char *p = DM_STRRCHR(dev_name, '_'); + if (p) + *p = '\0'; + } if (is_ethernet_link_exist(dev_name)) continue;