From db6d7395f442a906767e69e4c8d814cec410e9d8 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Fri, 8 Mar 2024 12:21:04 +0100 Subject: [PATCH] Update docs and align the remaining objects to generic data structure --- docs/guide/bbfdmd_dm_integration.md | 12 +- .../guide/libbbfdm-api_obj_param_extension.md | 205 +++++- libbbfdm/dmtree/tr181/dhcpv4.c | 643 +++++++++--------- libbbfdm/dmtree/tr181/dhcpv4.h | 6 + libbbfdm/dmtree/tr181/dhcpv6.c | 344 +++++----- .../dmtree/vendor/iopsys/x_iopsys_eu_igmp.c | 365 ++++------ .../dmtree/vendor/iopsys/x_iopsys_eu_igmp.h | 3 + .../dmtree/vendor/iopsys/x_iopsys_eu_mld.c | 96 ++- 8 files changed, 871 insertions(+), 803 deletions(-) diff --git a/docs/guide/bbfdmd_dm_integration.md b/docs/guide/bbfdmd_dm_integration.md index 0a839606..cd8534fc 100644 --- a/docs/guide/bbfdmd_dm_integration.md +++ b/docs/guide/bbfdmd_dm_integration.md @@ -45,6 +45,7 @@ inputs |BBF_OPERATE |path | NA | NA | NA | |BBF_SCHEMA |paramter ||$ref(type) |writable(0/1) |unique keys | |BBF_INSTANCES |parameter | NA |NA |NA | + |BBF_EVENT |path | NA | NA | NA | int cmd command to API to tell how the data model is to be read, possible values are @@ -53,9 +54,10 @@ inputs BBF_SET_VALUE - Set value of specified parameters in the data model BBF_ADD_OBJECT - Add object in a multi instance parameter in the data model BBF_DEL_OBJECT - Delete object from a multi instance parameter in the data model - BBF_OPERATE - execute the specified command - BBF_SCHEMA - Read all the parameter type parameter from data model. - BBF_INSTANCES - Read all the instance of multi instance parameter from data model. + BBF_OPERATE - execute the specified command + BBF_SCHEMA - Read all the parameter type parameter from data model. + BBF_INSTANCES - Read all the instance of multi instance parameter from data model. + BBF_EVENT - execute the specified event return int fault @@ -201,11 +203,11 @@ Example: ```bash static int get_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, (((struct wifi_enp_args *)data)->sections)->dmmap_section, "endpointalias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "endpointalias", instance, value); } static int set_WiFiEndPoint_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, (((struct wifi_enp_args *)data)->sections)->dmmap_section, "endpointalias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "endpointalias", instance, value); } ``` diff --git a/docs/guide/libbbfdm-api_obj_param_extension.md b/docs/guide/libbbfdm-api_obj_param_extension.md index f93d373d..bfdd9a2c 100644 --- a/docs/guide/libbbfdm-api_obj_param_extension.md +++ b/docs/guide/libbbfdm-api_obj_param_extension.md @@ -110,10 +110,9 @@ Each object in the **DMOBJ** table contains the following arguments: | `dynamicleaf` | Pointer to the next of **DMLEAF** which contains a list of the child parameters using json files, shared libraries and vendor extension | | `nextobj` | Pointer to a **DMOBJ** array which contains a list of the child objects | | `leaf` | Pointer to a **DMLEAF** array which contains a list of the child parameters | -| `linker` | This argument is used for LowerLayer parameters or to make reference to other instance object in the tree | +| `linker` | This argument is deprecated and should be `NULL` | | `bbfdm_type` | The bbfdm type of the object. Could be **BBFDM_CWMP**, **BBFDM_USP**, **BBFDM_BOTH** or **BBFDM_NONE**.If it's **BBFDM_BOTH** then we can see this object in all protocols (CWMP, USP,...) | -| `uniqueKeys` | The unique key parameters defined for the object. | - +| `uniqueKeys` | This argument is deprecated and should be `NULL` | ### Leaf definition @@ -130,7 +129,7 @@ Each leaf in the **DMLEAF** table can be a **Parameter**, **Command** or **Event | `getvalue` | The function which return the value of this parameter | | `setvalue` | The function which set the value of this parameter | | `bbfdm_type` | The bbfdm type of the parameter. Could be **BBFDM_CWMP**, **BBFDM_USP**, **BBFDM_BOTH** or **BBFDM_NONE**.If it's **BBFDM_BOTH** then we can see this parameter in all protocols (CWMP, USP,...) | - +| `dm_falgs` | An enumeration value used to specify the displayed parameter value. Could be **DM_FLAG_REFERENCE**, **DM_FLAG_UNIQUE**, **DM_FLAG_LINKER** or **DM_FLAG_SECURE**. | #### 2.Command definition @@ -152,7 +151,7 @@ Each leaf in the **DMLEAF** table can be a **Parameter**, **Command** or **Event | `permission` | The permission of the event. It should be **DMREAD** | | `type` | Type of the event, It should be **DMT_EVENT** | | `getvalue` | The function which return the parameter arguments of the event | -| `setvalue` | The function which call the operation of the event, It should be **NULL** | +| `setvalue` | The function which call the operation of the event | | `bbfdm_type` | The bbfdm type of the event. It should be **BBFDM_USP** as long as events are only defined in USP protocol. | @@ -162,17 +161,205 @@ The browse function allow to go over all instances of the current object and lin In this function, there are two functions that need to be defined: -- function to retrieve the instances: it can be +- function to retrieve the instances: it can be: * `handle_instance` function: allow to retrieve/attribute the instances number/alias from uci config sections depending of the request and the instance mode. * `handle_instance_without_section` function: allow to attribute the instances number/alias with constant values. -- function to link the instances: we need to call `DM_LINK_INST_OBJ()` function for each instance in order to link the instance to the data model tree. we also need to specify the `data`of this instance level. This `data` could be use later in the sub object and parameters functions (Get/Set/Add/Delete/Operate/Event). +- function to link the instances: To link each instance to the data model tree, it's necessary to call `DM_LINK_INST_OBJ()` API for every instance. Additionally, it's recommended to utilize the generic structure `(struct dm_data *)` as the passed `data` at each instance level. This structure will be utilized later in functions related to sub-objects and parameters (Get/Set/Add/Delete/Operate/Event). > Note1: the browse function is only developed for multi-instances objects. -> Note2: you can read the next section `BBF API` below to find the definition of the functions used in the browse. +> Note2: you can use [bbf_test plugin](../../test/bbf_test/bbf_test.c) as a reference in order to develop any new object/leaf/browse. -> Note3: you can use [bbf_test plugin](../../test/bbf_test/bbf_test.c) as a reference in order to develop any new object/leaf/browse. +> Note3: Extending the object list below using `JSON` Plugin is prohibited because the `data` passed in `DM_LINK_INST_OBJ()` API differs from the generic structure `(struct dm_data *)`. To accomplish this task, you have two options: either update the required object to utilize the generic structure in the passed data, or alternatively, use the `DotSo` plugin. +- Device.ATM.Link.{i}. +- Device.ATM.Link.{i}.Stats. +- Device.Bridging.Bridge.{i}. +- Device.Bridging.Bridge.{i}.Port.{i}. +- Device.Bridging.Bridge.{i}.Port.{i}.Stats. +- Device.Bridging.Bridge.{i}.STP. +- Device.Bridging.Bridge.{i}.VLAN.{i}. +- Device.Bridging.Bridge.{i}.VLANPort.{i}. +- Device.Bridging.ProviderBridge.{i}. +- Device.DHCPv4.Server.Pool.{i}. +- Device.DHCPv4.Server.Pool.{i}.Client.{i}. +- Device.DHCPv4.Server.Pool.{i}.Client.{i}.IPv4Address.{i}. +- Device.DHCPv4.Server.Pool.{i}.Client.{i}.Option.{i}. +- Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}. +- Device.DHCPv6.Server.Pool.{i}.Client.{i}. +- Device.DHCPv6.Server.Pool.{i}.Client.{i}.IPv6Address.{i}. +- Device.DHCPv6.Server.Pool.{i}.Client.{i}.IPv6Prefix.{i}. +- Device.DNS.Client.Server.{i}. +- Device.DNS.Relay.Forwarding.{i}. +- Device.DNS.SD.Service.{i}. +- Device.DNS.SD.Service.{i}.TextRecord.{i}. +- Device.DSL.Channel.{i}. +- Device.DSL.Channel.{i}.Stats. +- Device.DSL.Channel.{i}.Stats.CurrentDay. +- Device.DSL.Channel.{i}.Stats.LastShowtime. +- Device.DSL.Channel.{i}.Stats.QuarterHour. +- Device.DSL.Channel.{i}.Stats.Showtime. +- Device.DSL.Channel.{i}.Stats.Total. +- Device.DSL.Line.{i}. +- Device.DSL.Line.{i}.Stats. +- Device.DSL.Line.{i}.Stats.CurrentDay. +- Device.DSL.Line.{i}.Stats.LastShowtime. +- Device.DSL.Line.{i}.Stats.QuarterHour. +- Device.DSL.Line.{i}.Stats.Showtime. +- Device.DSL.Line.{i}.Stats.Total. +- Device.DeviceInfo.FirmwareImage.{i}. +- Device.DeviceInfo.MemoryStatus. +- Device.DeviceInfo.ProcessStatus. +- Device.DeviceInfo.ProcessStatus.Process.{i}. +- Device.DeviceInfo.Processor.{i}. +- Device.DeviceInfo.VendorConfigFile.{i}. +- Device.DynamicDNS.Client.{i}. +- Device.DynamicDNS.Client.{i}.Hostname.{i}. +- Device.DynamicDNS.Server.{i}. +- Device.Ethernet.Interface.{i}. +- Device.Ethernet.Interface.{i}.Stats. +- Device.Ethernet.Link.{i}. +- Device.Ethernet.Link.{i}.Stats. +- Device.Ethernet.RMONStats.{i}. +- Device.Ethernet.VLANTermination.{i}. +- Device.Ethernet.VLANTermination.{i}.Stats. +- Device.Ethernet.X_IOPSYS_EU_MACVLAN.{i}. +- Device.Ethernet.X_IOPSYS_EU_MACVLAN.{i}.Stats. +- Device.FAST.Line.{i}. +- Device.FAST.Line.{i}.Stats. +- Device.FAST.Line.{i}.Stats.CurrentDay. +- Device.FAST.Line.{i}.Stats.LastShowtime. +- Device.FAST.Line.{i}.Stats.QuarterHour. +- Device.FAST.Line.{i}.Stats.Showtime. +- Device.FAST.Line.{i}.Stats.Total. +- Device.Firewall.Chain.{i}. +- Device.Firewall.Chain.{i}.Rule.{i}. +- Device.Firewall.Level.{i}. +- Device.Hosts.AccessControl.{i}. +- Device.Hosts.AccessControl.{i}.Schedule.{i}. +- Device.Hosts.Host.{i}. +- Device.Hosts.Host.{i}.IPv4Address.{i}. +- Device.Hosts.Host.{i}.IPv6Address.{i}. +- Device.Hosts.Host.{i}.WANStats. +- Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}. +- Device.IEEE1905.AL.Interface.{i}. +- Device.IEEE1905.AL.Interface.{i}.Link.{i}. +- Device.IEEE1905.AL.Interface.{i}.Link.{i}.Metric. +- Device.IEEE1905.AL.Interface.{i}.VendorProperties.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.BridgingTuple.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.IEEE1905Neighbor.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.IEEE1905Neighbor.{i}.Metric.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.IPv4Address.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.IPv6Address.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.Interface.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.NonIEEE1905Neighbor.{i}. +- Device.IEEE1905.AL.NetworkTopology.IEEE1905Device.{i}.VendorProperties.{i}. +- Device.IP.Interface.{i}. +- Device.IP.Interface.{i}.IPv4Address.{i}. +- Device.IP.Interface.{i}.IPv6Address.{i}. +- Device.IP.Interface.{i}.IPv6Prefix.{i}. +- Device.IP.Interface.{i}.Stats. +- Device.IP.Interface.{i}.TWAMPReflector.{i}. +- Device.InterfaceStack.{i}. +- Device.NAT.PortTrigger.{i}. +- Device.NAT.PortTrigger.{i}.Rule.{i}. +- Device.PPP.Interface.{i}. +- Device.PPP.Interface.{i}.IPCP. +- Device.PPP.Interface.{i}.IPv6CP. +- Device.PPP.Interface.{i}.PPPoE. +- Device.PPP.Interface.{i}.Stats. +- Device.PTM.Link.{i}. +- Device.PTM.Link.{i}.Stats. +- Device.PeriodicStatistics.SampleSet.{i}. +- Device.PeriodicStatistics.SampleSet.{i}.Parameter.{i}. +- Device.QoS.QueueStats.{i}. +- Device.Routing.RouteInformation.InterfaceSetting.{i}. +- Device.Routing.Router.{i}. +- Device.Routing.Router.{i}.IPv4Forwarding.{i}. +- Device.Routing.Router.{i}.IPv6Forwarding.{i}. +- Device.SSH.AuthorizedKey.{i}. +- Device.SSH.Server.{i}.Session.{i}. +- Device.Security.Certificate.{i}. +- Device.Services.VoiceService.{i}. +- Device.Services.VoiceService.{i}.CallControl. +- Device.Services.VoiceService.{i}.CallControl.CallingFeatures. +- Device.Services.VoiceService.{i}.CallControl.CallingFeatures.Set.{i}. +- Device.Services.VoiceService.{i}.CallControl.CallingFeatures.Set.{i}.SCREJ.{i}. +- Device.Services.VoiceService.{i}.CallControl.Extension.{i}. +- Device.Services.VoiceService.{i}.CallControl.Group.{i}. +- Device.Services.VoiceService.{i}.CallControl.IncomingMap.{i}. +- Device.Services.VoiceService.{i}.CallControl.Line.{i}. +- Device.Services.VoiceService.{i}.CallControl.Line.{i}.Stats. +- Device.Services.VoiceService.{i}.CallControl.Line.{i}.Stats.DSP. +- Device.Services.VoiceService.{i}.CallControl.Line.{i}.Stats.IncomingCalls. +- Device.Services.VoiceService.{i}.CallControl.Line.{i}.Stats.OutgoingCalls. +- Device.Services.VoiceService.{i}.CallControl.Line.{i}.Stats.RTP. +- Device.Services.VoiceService.{i}.CallControl.NumberingPlan.{i}. +- Device.Services.VoiceService.{i}.CallControl.NumberingPlan.{i}.PrefixInfo.{i}. +- Device.Services.VoiceService.{i}.CallControl.OutgoingMap.{i}. +- Device.Services.VoiceService.{i}.CallLog.{i}. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Destination. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Destination.DSP. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Destination.DSP.ReceiveCodec. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Destination.DSP.TransmitCodec. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Destination.RTP. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Source. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Source.DSP. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Source.DSP.ReceiveCodec. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Source.DSP.TransmitCodec. +- Device.Services.VoiceService.{i}.CallLog.{i}.Session.{i}.Source.RTP. +- Device.Services.VoiceService.{i}.Capabilities. +- Device.Services.VoiceService.{i}.Capabilities.Codec.{i}. +- Device.Services.VoiceService.{i}.Capabilities.POTS. +- Device.Services.VoiceService.{i}.Capabilities.SIP. +- Device.Services.VoiceService.{i}.Capabilities.SIP.Client. +- Device.Services.VoiceService.{i}.CodecProfile.{i}. +- Device.Services.VoiceService.{i}.DECT. +- Device.Services.VoiceService.{i}.DECT.Base.{i}. +- Device.Services.VoiceService.{i}.DECT.Portable.{i}. +- Device.Services.VoiceService.{i}.POTS. +- Device.Services.VoiceService.{i}.POTS.FXS.{i}. +- Device.Services.VoiceService.{i}.POTS.FXS.{i}.VoiceProcessing. +- Device.Services.VoiceService.{i}.ReservedPorts. +- Device.Services.VoiceService.{i}.SIP. +- Device.Services.VoiceService.{i}.SIP.Client.{i}. +- Device.Services.VoiceService.{i}.SIP.Network.{i}. +- Device.Services.VoiceService.{i}.SIP.Network.{i}.FQDNServer.{i}. +- Device.Services.VoiceService.{i}.VoIPProfile.{i}. +- Device.Services.VoiceService.{i}.VoIPProfile.{i}.RTP. +- Device.Services.VoiceService.{i}.VoIPProfile.{i}.RTP.RTCP. +- Device.Services.VoiceService.{i}.VoIPProfile.{i}.RTP.SRTP. +- Device.SoftwareModules.DeploymentUnit.{i}. +- Device.SoftwareModules.ExecEnv.{i}. +- Device.SoftwareModules.ExecutionUnit.{i}. +- Device.Time.Client.{i}. +- Device.Time.Client.{i}.Stats. +- Device.Time.Server.{i}. +- Device.Time.Server.{i}.Stats. +- Device.UPnP.Description.DeviceDescription.{i}. +- Device.UPnP.Description.DeviceInstance.{i}. +- Device.UPnP.Description.ServiceInstance.{i}. +- Device.UPnP.Discovery.Device.{i}. +- Device.UPnP.Discovery.RootDevice.{i}. +- Device.UPnP.Discovery.Service.{i}. +- Device.USB.Interface.{i}. +- Device.USB.Interface.{i}.Stats. +- Device.USB.Port.{i}. +- Device.USB.USBHosts.Host.{i}. +- Device.USB.USBHosts.Host.{i}.Device.{i}. +- Device.USB.USBHosts.Host.{i}.Device.{i}.Configuration.{i}. +- Device.USB.USBHosts.Host.{i}.Device.{i}.Configuration.{i}.Interface.{i}. +- Device.UserInterface.HTTPAccess.{i}. +- Device.UserInterface.HTTPAccess.{i}.Session.{i}. +- Device.Users.Group.{i}. +- Device.Users.Role.{i}. +- Device.Users.SupportedShell.{i}. +- Device.Users.User.{i}. +- Device.XMPP.Connection.{i}. +- Device.XMPP.Connection.{i}.Server.{i}. +- Device.XMPP.Connection.{i}.Stats. diff --git a/libbbfdm/dmtree/tr181/dhcpv4.c b/libbbfdm/dmtree/tr181/dhcpv4.c index 66bd4839..c7cf0629 100644 --- a/libbbfdm/dmtree/tr181/dhcpv4.c +++ b/libbbfdm/dmtree/tr181/dhcpv4.c @@ -48,37 +48,6 @@ struct client_args { const struct dhcp_lease *lease; }; -struct client_options_args { - char *tag; - char *value; -}; - -struct dhcp_client_args { - struct uci_section *iface_s; - struct uci_section *dmmap_s; -}; - -struct dhcp_client_option_args { - struct uci_section *client_sect; - struct uci_section *dmmap_sect; - char *option_tag; - char *value; -}; - -/* Returns dnsmasq section name belongs to LAN network */ -char *get_dnsmasq_section_name(void) -{ - struct uci_section *s = NULL; - - uci_foreach_sections("dhcp", "dnsmasq", s) { - char *sec = section_name(s); - if (DM_STRCMP(sec, "dns_client") != 0) - return sec; - } - - return ""; -} - /************************************************************* * INIT **************************************************************/ @@ -100,7 +69,7 @@ static inline void init_dhcp_client_args(struct client_args *args, const struct args->lease = lease; } -static inline void init_client_options_args(struct client_options_args *args, char *tag, char *val) +static inline void init_client_options_args(struct option_args *args, char *tag, char *val) { args->tag = tag; args->value = val; @@ -109,6 +78,20 @@ static inline void init_client_options_args(struct client_options_args *args, ch /************************************************************* * COMMON FUNCTIONS **************************************************************/ +/* Returns dnsmasq section name belongs to LAN network */ +static char *get_dnsmasq_section_name(void) +{ + struct uci_section *s = NULL; + + uci_foreach_sections("dhcp", "dnsmasq", s) { + char *sec = section_name(s); + if (DM_STRCMP(sec, "dns_client") != 0) + return sec; + } + + return ""; +} + static struct uci_section *exist_other_section_same_order(struct uci_section *dmmap_sect, char *package, char *sect_type, char *order) { struct uci_section *s = NULL; @@ -900,7 +883,7 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p return 0; const struct client_args *args = (struct client_args *)prev_data; - struct client_options_args curr_client_options_args = {0}; + struct option_args curr_client_options_args = {0}; char line[2048], macaddr[24]={0}, vcid[128]={0}, clid[128]={0}, ucid[128]={0}, hostname[128]={0}, paramlist[256]={0}; char *inst = NULL; int id = 0; @@ -987,25 +970,25 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p /*#Device.DHCPv4.Client.{i}.!UCI:network/interface/dmmap_dhcp_client*/ static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dhcp_client_args curr_dhcp_client_args = {0}; - struct uci_section *s = NULL; + struct dm_data curr_data = {0}; + struct uci_section *dmmap_s = NULL; char *inst = NULL; dmmap_synchronizeDHCPv4Client(dmctx, parent_node, prev_data, prev_instance); - uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", s) { + uci_path_foreach_sections(bbfdm, "dmmap_dhcp_client", "interface", dmmap_s) { struct uci_section *iface_s = NULL; char *iface_name = NULL; - dmuci_get_value_by_section_string(s, "iface_name", &iface_name); + dmuci_get_value_by_section_string(dmmap_s, "iface_name", &iface_name); if (DM_STRLEN(iface_name)) get_config_section_of_dmmap_section("network", "interface", iface_name, &iface_s); - curr_dhcp_client_args.iface_s = iface_s; - curr_dhcp_client_args.dmmap_s = s; + curr_data.config_section = iface_s; + curr_data.dmmap_section = dmmap_s; - inst = handle_instance(dmctx, parent_node, s, "bbf_dhcpv4client_instance", "bbf_dhcpv4client_alias"); + inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv4client_instance", "bbf_dhcpv4client_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_client_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -1013,40 +996,40 @@ static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *dhcp_client_s = ((struct dhcp_client_args *)prev_data)->iface_s; - struct dhcp_client_option_args dhcp_client_opt_args = {0}; - struct uci_section *dhcp_client_dmmap_s = NULL; - char *dhcp_client_key = NULL, *inst = NULL; - char value[256] = {0}; + struct option_args curr_option_args = {0}; + struct dm_data curr_data = {0}; + struct uci_section *dmmap_s = NULL; + char *key = NULL, *inst = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_args *)prev_data)->dmmap_s, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->dmmap_section, "dhcp_client_key", &key); - if (dhcp_client_s) { + if (((struct dm_data *)prev_data)->config_section) { char *vendorid = NULL, *clientid = NULL, *hostname = NULL, *sendopts = NULL; + char value[256] = {0}; - dmuci_get_value_by_section_string(dhcp_client_s, "vendorid", &vendorid); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->config_section, "vendorid", &vendorid); if (DM_STRLEN(vendorid)) { // vendorid (option 60) convert_str_option_to_hex(60, vendorid, value, sizeof(value)); - create_dhcp_client_option_instance("send_option", dhcp_client_key, "60", value); + create_dhcp_client_option_instance("send_option", key, "60", value); } - dmuci_get_value_by_section_string(dhcp_client_s, "clientid", &clientid); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->config_section, "clientid", &clientid); if (DM_STRLEN(clientid)) { // clientid (option 61) convert_str_option_to_hex(61, clientid, value, sizeof(value)); - create_dhcp_client_option_instance("send_option", dhcp_client_key, "61", value); + create_dhcp_client_option_instance("send_option", key, "61", value); } - dmuci_get_value_by_section_string(dhcp_client_s, "hostname", &hostname); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->config_section, "hostname", &hostname); if (DM_STRLEN(hostname)) { // hostname (option 12) convert_str_option_to_hex(12, hostname, value, sizeof(value)); - create_dhcp_client_option_instance("send_option", dhcp_client_key, "12", value); + create_dhcp_client_option_instance("send_option", key, "12", value); } // sendopts option - dmuci_get_value_by_section_string(dhcp_client_s, "sendopts", &sendopts); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->config_section, "sendopts", &sendopts); if (DM_STRLEN(sendopts)) { // sendopts (other options) char *pch = NULL, *spch = NULL; @@ -1061,25 +1044,23 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_ if (!DM_STRLEN(tag) || !DM_STRLEN(tag)) continue; - create_dhcp_client_option_instance("send_option", dhcp_client_key, tag, value); + create_dhcp_client_option_instance("send_option", key, tag, value); } } } - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "send_option", "dhcp_client_key", dhcp_client_key, dhcp_client_dmmap_s) { - char *option_tag = NULL, *option_value = NULL; + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "send_option", "dhcp_client_key", key, dmmap_s) { - dmuci_get_value_by_section_string(dhcp_client_dmmap_s, "option_tag", &option_tag); - dmuci_get_value_by_section_string(dhcp_client_dmmap_s, "option_value", &option_value); + dmuci_get_value_by_section_string(dmmap_s, "option_tag", &curr_option_args.tag); + dmuci_get_value_by_section_string(dmmap_s, "option_value", &curr_option_args.value); - dhcp_client_opt_args.client_sect = dhcp_client_s; - dhcp_client_opt_args.dmmap_sect = dhcp_client_dmmap_s; - dhcp_client_opt_args.option_tag = option_tag; - dhcp_client_opt_args.value = option_value; + curr_data.config_section = ((struct dm_data *)prev_data)->config_section; + curr_data.dmmap_section = dmmap_s; + curr_data.additional_data = &curr_option_args; - inst = handle_instance(dmctx, parent_node, dhcp_client_dmmap_s, "bbf_dhcpv4_sentopt_instance", "bbf_dhcpv4_sentopt_alias"); + inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv4_sentopt_instance", "bbf_dhcpv4_sentopt_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcp_client_opt_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } @@ -1088,39 +1069,37 @@ static int browseDHCPv4ClientSentOptionInst(struct dmctx *dmctx, DMNODE *parent_ static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct uci_section *dhcp_client_s = ((struct dhcp_client_args *)prev_data)->iface_s; - struct uci_section *dhcp_client_dmmap_s = NULL; - struct dhcp_client_option_args dhcp_client_opt_args = {0}; - char *dhcp_client_key = NULL, *inst = NULL; + struct option_args curr_option_args = {0}; + struct uci_section *dmmap_s = NULL; + struct dm_data curr_data = {0}; + char *key = NULL, *inst = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_args *)prev_data)->dmmap_s, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->dmmap_section, "dhcp_client_key", &key); - if (dhcp_client_s) { + if (((struct dm_data *)prev_data)->config_section) { char *reqopts = NULL; - dmuci_get_value_by_section_string(dhcp_client_s, "reqopts", &reqopts); + dmuci_get_value_by_section_string(((struct dm_data *)prev_data)->config_section, "reqopts", &reqopts); if (DM_STRLEN(reqopts)) { // reqopts option char *pch = NULL, *spch = NULL; for (pch = strtok_r(reqopts, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) - create_dhcp_client_option_instance("req_option", dhcp_client_key, pch, ""); + create_dhcp_client_option_instance("req_option", key, pch, ""); } } - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "req_option", "dhcp_client_key", dhcp_client_key, dhcp_client_dmmap_s) { - char *tag = NULL; + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp_client", "req_option", "dhcp_client_key", key, dmmap_s) { - dmuci_get_value_by_section_string(dhcp_client_dmmap_s, "option_tag", &tag); + dmuci_get_value_by_section_string(dmmap_s, "option_tag", &curr_option_args.tag); - dhcp_client_opt_args.client_sect = dhcp_client_s; - dhcp_client_opt_args.dmmap_sect = dhcp_client_dmmap_s; - dhcp_client_opt_args.option_tag = tag; - dhcp_client_opt_args.value = ""; + curr_data.config_section = ((struct dm_data *)prev_data)->config_section; + curr_data.dmmap_section = dmmap_s; + curr_data.additional_data = &curr_option_args; - inst = handle_instance(dmctx, parent_node, dhcp_client_dmmap_s, "bbf_dhcpv4_reqtopt_instance", "bbf_dhcpv4_reqtopt_alias"); + inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv4_reqtopt_instance", "bbf_dhcpv4_reqtopt_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcp_client_opt_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } @@ -1129,18 +1108,18 @@ static int browseDHCPv4ClientReqOptionInst(struct dmctx *dmctx, DMNODE *parent_n static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dhcp_args *curr_dhcp_args = (struct dhcp_args *)prev_data; - struct uci_list *dhcp_options_list = NULL; - struct uci_section *dmmap_sect = NULL; - char *inst = NULL, *dhcpv4_tag, *dhcpv4_value; - struct dhcp_client_option_args dhcp_client_opt_args = {0}; + struct option_args curr_option_args = {0}; + struct uci_list *options_list = NULL; + struct uci_section *dmmap_s = NULL; + struct dm_data curr_data = {0}; + char *inst = NULL; - dmuci_get_value_by_section_list(curr_dhcp_args->sections->config_section, "dhcp_option", &dhcp_options_list); + dmuci_get_value_by_section_list(((struct dhcp_args *)prev_data)->sections->config_section, "dhcp_option", &options_list); - if (dhcp_options_list != NULL) { + if (options_list != NULL) { struct uci_element *e = NULL; - uci_foreach_element(dhcp_options_list, e) { + uci_foreach_element(options_list, e) { char buf[512] = {0}; snprintf(buf, sizeof(buf), "%s", e->name); @@ -1148,27 +1127,27 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_ if (p) *p = 0; - if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcp", "servpool_option", section_name(curr_dhcp_args->sections->config_section), "option_tag", buf)) == NULL) { - dmuci_add_section_bbfdm("dmmap_dhcp", "servpool_option", &dmmap_sect); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", buf); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(curr_dhcp_args->sections->config_section)); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_value", p ? p + 1 : ""); + if ((dmmap_s = get_dup_section_in_dmmap_eq("dmmap_dhcp", "servpool_option", section_name(((struct dhcp_args *)prev_data)->sections->config_section), "option_tag", buf)) == NULL) { + dmuci_add_section_bbfdm("dmmap_dhcp", "servpool_option", &dmmap_s); + dmuci_set_value_by_section_bbfdm(dmmap_s, "option_tag", buf); + dmuci_set_value_by_section_bbfdm(dmmap_s, "section_name", section_name(((struct dhcp_args *)prev_data)->sections->config_section)); + dmuci_set_value_by_section_bbfdm(dmmap_s, "option_value", p ? p + 1 : ""); } } } - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp", "servpool_option", "section_name", section_name(curr_dhcp_args->sections->config_section), dmmap_sect) { - dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &dhcpv4_tag); - dmuci_get_value_by_section_string(dmmap_sect, "option_value", &dhcpv4_value); + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcp", "servpool_option", "section_name", section_name(((struct dhcp_args *)prev_data)->sections->config_section), dmmap_s) { - dhcp_client_opt_args.client_sect = curr_dhcp_args->sections->config_section; - dhcp_client_opt_args.dmmap_sect = dmmap_sect; - dhcp_client_opt_args.option_tag = dhcpv4_tag; - dhcp_client_opt_args.value = dhcpv4_value; + dmuci_get_value_by_section_string(dmmap_s, "option_tag", &curr_option_args.tag); + dmuci_get_value_by_section_string(dmmap_s, "option_value", &curr_option_args.value); - inst = handle_instance(dmctx, parent_node, dmmap_sect, "bbf_dhcpv4_servpool_option_instance", "bbf_dhcpv4_servpool_option_alias"); + curr_data.config_section = ((struct dhcp_args *)prev_data)->sections->config_section; + curr_data.dmmap_section = dmmap_s; + curr_data.additional_data = &curr_option_args; - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcp_client_opt_args, inst) == DM_STOP) + inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv4_servpool_option_instance", "bbf_dhcpv4_servpool_option_alias"); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -1177,7 +1156,7 @@ static int browseDHCPv4ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_ /*#Device.DHCPv4.Relay.Forwarding.{i}.!UCI:network/interface/dmmap_dhcp_relay*/ static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dhcp_client_args curr_dhcp_relay_args = {0}; + struct dm_data curr_data = {0}; struct uci_section *dmmap_s = NULL; char *inst = NULL; @@ -1190,12 +1169,12 @@ static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_n if (DM_STRLEN(iface_name)) get_config_section_of_dmmap_section("network", "interface", iface_name, &iface_s); - curr_dhcp_relay_args.iface_s = iface_s; - curr_dhcp_relay_args.dmmap_s = dmmap_s; + curr_data.config_section = iface_s; + curr_data.dmmap_section = dmmap_s; inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv4relay_instance", "bbf_dhcpv4relay_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_relay_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -1304,22 +1283,22 @@ static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, cha switch (del_action) { case DEL_INST: - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dmmap_s, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &dhcp_client_key); - if (((struct dhcp_client_args *)data)->iface_s) { + if (((struct dm_data *)data)->config_section) { char *ip_instance = NULL; - struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(((struct dhcp_client_args *)data)->iface_s)); + struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(((struct dm_data *)data)->config_section)); dmuci_get_value_by_section_string(dmmap_s, "ip_int_instance", &ip_instance); if (dmmap_s && DM_STRLEN(ip_instance) == 0) { - dmuci_delete_by_section(((struct dhcp_client_args *)data)->iface_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); } else { - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "proto", "none"); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "clientid", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "vendorid", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "hostname", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "sendopts", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "reqopts", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", "none"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "clientid", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "vendorid", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "hostname", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", ""); } } @@ -1331,7 +1310,7 @@ static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, cha dmuci_delete_by_section(s, NULL, NULL); } - dmuci_delete_by_section(((struct dhcp_client_args *)data)->dmmap_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_client", "interface", stmp, s) { @@ -1378,17 +1357,16 @@ static int delObjDHCPv4Client(char *refparam, struct dmctx *ctx, void *data, cha static int addObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void *data, char **instance) { - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args *)data; struct uci_section *dmmap_sect = NULL; - char *dhcp_client_key = NULL; + char *key = NULL; - dmuci_get_value_by_section_string(dhcp_client_args->dmmap_s, "dhcp_client_key", &dhcp_client_key); - char *option_tag = generate_tag_option("dmmap_dhcp_client", "send_option", "dhcp_client_key", dhcp_client_key, "option_tag"); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &key); + char *tag = generate_tag_option("dmmap_dhcp_client", "send_option", "dhcp_client_key", key, "option_tag"); dmuci_add_section_bbfdm("dmmap_dhcp_client", "send_option", &dmmap_sect); dmuci_set_value_by_section(dmmap_sect, "enable", "0"); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", option_tag); - dmuci_set_value_by_section(dmmap_sect, "dhcp_client_key", dhcp_client_key); + dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", tag); + dmuci_set_value_by_section(dmmap_sect, "dhcp_client_key", key); dmuci_set_value_by_section_bbfdm(dmmap_sect, "bbf_dhcpv4_sentopt_instance", *instance); return 0; } @@ -1400,33 +1378,34 @@ static int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void switch (del_action) { case DEL_INST: - if (((struct dhcp_client_option_args *)data)->client_sect) { - char *option_name = get_dhcp_option_name(DM_STRTOL(((struct dhcp_client_option_args *)data)->option_tag)); + if (((struct dm_data *)data)->config_section) { + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; + char *option_name = get_dhcp_option_name(DM_STRTOL(option->tag)); if (DM_LSTRCMP(option_name, "sendopts") == 0) { char *sendopts = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", &sendopts); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "sendopts", &sendopts); if (DM_STRLEN(sendopts)) { - sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(((struct dhcp_client_option_args *)data)->option_tag)); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "sendopts", sendopts); + sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(option->tag)); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", sendopts); } } else { - dmuci_set_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, option_name, ""); + dmuci_set_value_by_section(((struct dm_data *) data)->config_section, option_name, ""); } } - dmuci_delete_by_section(((struct dhcp_client_option_args *)data)->dmmap_sect, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: - if (((struct dhcp_client_args *)data)->iface_s) { - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "clientid", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "vendorid", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "hostname", ""); - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "sendopts", ""); + if (((struct dm_data *)data)->config_section) { + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "clientid", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "vendorid", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "hostname", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", ""); } - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dmmap_s, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &dhcp_client_key); uci_path_foreach_option_eq_safe(bbfdm, "dmmap_dhcp_client", "send_option", "dhcp_client_key", dhcp_client_key, stmp, s) { dmuci_delete_by_section(s, NULL, NULL); @@ -1438,17 +1417,16 @@ static int delObjDHCPv4ClientSentOption(char *refparam, struct dmctx *ctx, void static int addObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void *data, char **instance) { - struct dhcp_client_args *dhcp_client_args = (struct dhcp_client_args *)data; struct uci_section *dmmap_sect = NULL; - char *dhcp_client_key = NULL; + char *key = NULL; - dmuci_get_value_by_section_string(dhcp_client_args->dmmap_s, "dhcp_client_key", &dhcp_client_key); - char *option_tag = generate_tag_option("dmmap_dhcp_client", "req_option", "dhcp_client_key", dhcp_client_key, "option_tag"); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &key); + char *tag = generate_tag_option("dmmap_dhcp_client", "req_option", "dhcp_client_key", key, "option_tag"); dmuci_add_section_bbfdm("dmmap_dhcp_client", "req_option", &dmmap_sect); dmuci_set_value_by_section(dmmap_sect, "enable", "0"); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", option_tag); - dmuci_set_value_by_section(dmmap_sect, "dhcp_client_key", dhcp_client_key); + dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", tag); + dmuci_set_value_by_section(dmmap_sect, "dhcp_client_key", key); dmuci_set_value_by_section_bbfdm(dmmap_sect, "bbf_dhcpv4_sentopt_instance", *instance); return 0; } @@ -1460,23 +1438,24 @@ static int delObjDHCPv4ClientReqOption(char *refparam, struct dmctx *ctx, void * switch (del_action) { case DEL_INST: - if (((struct dhcp_client_option_args *)data)->client_sect) { + if (((struct dm_data *)data)->config_section) { char *reqopts = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &reqopts); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "reqopts", &reqopts); if (reqopts && *reqopts) { - reqopts = remove_str_from_str_list(reqopts, " ", ((struct dhcp_client_option_args*) data)->option_tag); - dmuci_set_value_by_section(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", reqopts); + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; + reqopts = remove_str_from_str_list(reqopts, " ", option->tag); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", reqopts); } } - dmuci_delete_by_section(((struct dhcp_client_option_args *)data)->dmmap_sect, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: - if (((struct dhcp_client_args *)data)->iface_s) - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "reqopts", ""); + if (((struct dm_data *)data)->config_section) + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", ""); - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dmmap_s, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &dhcp_client_key); uci_path_foreach_option_eq_safe(bbfdm, "dmmap_dhcp_client", "req_option", "dhcp_client_key", dhcp_client_key, stmp, s) { dmuci_delete_by_section(s, NULL, NULL); @@ -1506,15 +1485,16 @@ static int delObjDHCPv4ServerPoolOption(char *refparam, struct dmctx *ctx, void switch (del_action) { case DEL_INST: - dmuci_get_value_by_section_list(((struct dhcp_client_option_args*) data)->client_sect, "dhcp_option", &dhcp_options_list); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &dhcp_options_list); if (dhcp_options_list != NULL) { + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char tag_value[128] = {0}; - snprintf(tag_value, sizeof(tag_value), "%s,%s", ((struct dhcp_client_option_args*) data)->option_tag, ((struct dhcp_client_option_args*) data)->value); - dmuci_del_list_value_by_section(((struct dhcp_client_option_args*) data)->client_sect, "dhcp_option", tag_value); + snprintf(tag_value, sizeof(tag_value), "%s,%s", option->tag, option->value); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", tag_value); } - dmuci_delete_by_section(((struct dhcp_client_option_args*) data)->dmmap_sect, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: dmuci_set_value_by_section((((struct dhcp_args *)data)->sections)->config_section, "dhcp_option", ""); @@ -1544,10 +1524,10 @@ static int delObjDHCPv4RelayForwarding(char *refparam, struct dmctx *ctx, void * switch (del_action) { case DEL_INST: - dmuci_delete_by_section(((struct dhcp_client_args *)data)->dmmap_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); - if (((struct dhcp_client_args *)data)->iface_s) - dmuci_set_value_by_section(((struct dhcp_client_args *)data)->iface_s, "proto", "none"); + if (((struct dm_data *)data)->config_section) + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", "none"); break; case DEL_ALL: uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcp_relay", "interface", stmp, s) { @@ -2303,14 +2283,14 @@ static int get_DHCPv4ServerPoolClientIPv4Address_IPAddress(char *refparam, struc static int get_DHCPv4ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct client_options_args *)data)->tag; + *value = ((struct option_args *)data)->tag; return 0; } static int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - const char *tag_option = ((struct client_options_args *)data)->tag; - const char *tag_value = ((struct client_options_args *)data)->value; + const char *tag_option = ((struct option_args *)data)->tag; + const char *tag_value = ((struct option_args *)data)->value; char hex[256] = {0}; if (DM_STRLEN(tag_option) && DM_STRLEN(tag_value)) @@ -2330,17 +2310,15 @@ static int get_DHCPv4_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, v /*#Device.DHCPv4.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ static int get_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcp_client_args *dhcpv4_client = (struct dhcp_client_args *)data; char *disabled = NULL; - dmuci_get_value_by_section_string(dhcpv4_client->iface_s ? dhcpv4_client->iface_s : dhcpv4_client->dmmap_s, "disabled", &disabled); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section ? ((struct dm_data *)data)->config_section : ((struct dm_data *)data)->dmmap_section, "disabled", &disabled); *value = (disabled[0] == '1') ? "0" : "1"; return 0; } static int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_args *dhcpv4_client = (struct dhcp_client_args *)data; bool b; switch (action) { @@ -2348,11 +2326,11 @@ static int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data if (bbfdm_validate_boolean(ctx, value)) return FAULT_9007; - if (dhcpv4_client->iface_s) { + if (((struct dm_data *)data)->config_section) { struct uci_section *dmmap_s = NULL; char *ip_inst = NULL; - get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(dhcpv4_client->iface_s), &dmmap_s); + get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dm_data *)data)->config_section), &dmmap_s); dmuci_get_value_by_section_string(dmmap_s, "ip_int_instance", &ip_inst); if (DM_STRLEN(ip_inst)) return FAULT_9007; @@ -2361,9 +2339,9 @@ static int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data return 0; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(dhcpv4_client->dmmap_s, "disabled", b ? "0" : "1"); - if (dhcpv4_client->iface_s) - dmuci_set_value_by_section(dhcpv4_client->iface_s, "disabled", b ? "0" : "1"); + dmuci_set_value_by_section(((struct dm_data *)data)->dmmap_section, "disabled", b ? "0" : "1"); + if (((struct dm_data *)data)->config_section) + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "disabled", b ? "0" : "1"); return 0; } return 0; @@ -2371,27 +2349,27 @@ static int set_DHCPv4Client_Enable(char *refparam, struct dmctx *ctx, void *data static int get_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcp_client_args *)data)->dmmap_s, "bbf_dhcpv4client_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4client_alias", instance, value); } static int set_DHCPv4Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcp_client_args *)data)->dmmap_s, "bbf_dhcpv4client_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4client_alias", instance, value); } static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface_name = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dmmap_s, "iface_name", &iface_name); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "iface_name", &iface_name); adm_entry_get_reference_param(ctx, "Device.IP.Interface.*.Name", iface_name, value); - if (DM_STRLEN(*value) == 0 && ((struct dhcp_client_args *)data)->iface_s) { + if (DM_STRLEN(*value) == 0 && ((struct dm_data *)data)->config_section) { struct uci_section *s = NULL; char *device = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->iface_s, "device", &device); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "device", &device); if (DM_STRLEN(device) == 0) return 0; @@ -2405,10 +2383,9 @@ static int get_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_args *dhcpv4_client = (struct dhcp_client_args *)data; char *allowed_objects[] = {"Device.IP.Interface.", NULL}; struct dm_reference reference = {0}; - char *dhcp_client_key = NULL; + char *key = NULL; bbf_get_reference_args(value, &reference); @@ -2422,25 +2399,25 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d break; case VALUESET: - if (dhcpv4_client->iface_s) { + if (((struct dm_data *)data)->config_section) { char *ip_instance = NULL; - struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(dhcpv4_client->iface_s)); + struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(((struct dm_data *)data)->config_section)); dmuci_get_value_by_section_string(dmmap_s, "ip_int_instance", &ip_instance); if (dmmap_s && DM_STRLEN(ip_instance) == 0) { - dmuci_delete_by_section(dhcpv4_client->iface_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); } else { - dmuci_set_value_by_section(dhcpv4_client->iface_s, "proto", "none"); - dmuci_set_value_by_section(dhcpv4_client->iface_s, "clientid", ""); - dmuci_set_value_by_section(dhcpv4_client->iface_s, "vendorid", ""); - dmuci_set_value_by_section(dhcpv4_client->iface_s, "hostname", ""); - dmuci_set_value_by_section(dhcpv4_client->iface_s, "sendopts", ""); - dmuci_set_value_by_section(dhcpv4_client->iface_s, "reqopts", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", "none"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "clientid", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "vendorid", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "hostname", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", ""); } } // Update iface_name option - dmuci_set_value_by_section_bbfdm(dhcpv4_client->dmmap_s, "iface_name", reference.value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "iface_name", reference.value); if (DM_STRLEN(reference.value)) { struct uci_section *interface_s = NULL; @@ -2469,24 +2446,24 @@ static int set_DHCPv4Client_Interface(char *refparam, struct dmctx *ctx, void *d dmuci_set_value_by_section(interface_s, "device", curr_device); // Update iface_name option - dmuci_set_value_by_section_bbfdm(dhcpv4_client->dmmap_s, "iface_name", buf); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "iface_name", buf); } // Update proto option of config section dmuci_set_value_by_section(interface_s, "proto", "dhcp"); // Update dmmap section - dmuci_set_value_by_section_bbfdm(dhcpv4_client->dmmap_s, "iface_name", reference.value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "iface_name", reference.value); - dmuci_get_value_by_section_string(dhcpv4_client->dmmap_s, "dhcp_client_key", &dhcp_client_key); - if (!DM_STRLEN(dhcp_client_key)) + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &key); + if (!DM_STRLEN(key)) break; // Added the enabled options for sendopts - create_dhcp_sent_option_list(interface_s, dhcp_client_key); + create_dhcp_sent_option_list(interface_s, key); // Added the enabled options for reqopts - create_dhcp_req_option_list(interface_s, dhcp_client_key); + create_dhcp_req_option_list(interface_s, key); } break; @@ -2505,7 +2482,7 @@ static int get_DHCPv4Client_Status(char *refparam, struct dmctx *ctx, void *data /*#Device.DHCPv4.Client.{i}.DHCPStatus!UBUS:network.interface/status/interface,@Name/ipv4-address[@i-1].address*/ static int get_DHCPv4Client_DHCPStatus(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; if (dhcpv4_s) { json_object *res = NULL; @@ -2530,7 +2507,7 @@ static int get_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, static int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; bool b; switch (action) { @@ -2552,12 +2529,12 @@ static int set_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, static int get_DHCPv4Client_IPAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; char *ipaddr = ""; if (dhcpv4_s) { - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->iface_s, "ipaddr", &ipaddr); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "ipaddr", &ipaddr); if (!ipaddr || *ipaddr == 0) { json_object *res = NULL; @@ -2576,12 +2553,12 @@ static int get_DHCPv4Client_IPAddress(char *refparam, struct dmctx *ctx, void *d static int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; char *mask = ""; if (dhcpv4_s) { - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->iface_s, "netmask", &mask); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "netmask", &mask); if (!mask || *mask == 0) { json_object *res = NULL; @@ -2602,7 +2579,7 @@ static int get_DHCPv4Client_SubnetMask(char *refparam, struct dmctx *ctx, void * /*#Device.DHCPv4.Client.{i}.IPRouters!UBUS:network.interface/status/interface,@Name/route[@i-1].nexthop*/ static int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; if (dhcpv4_s) { json_object *res = NULL, *route = NULL, *arrobj = NULL; @@ -2631,7 +2608,7 @@ static int get_DHCPv4Client_IPRouters(char *refparam, struct dmctx *ctx, void *d /*#Device.DHCPv4.Client.{i}.DNSServers!UBUS:network.interface/status/interface,@Name/dns-server*/ static int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; if (dhcpv4_s) { json_object *res = NULL; @@ -2647,7 +2624,7 @@ static int get_DHCPv4Client_DNSServers(char *refparam, struct dmctx *ctx, void * /*#Device.DHCPv4.Client.{i}.LeaseTimeRemaining!UBUS:network.interface/status/interface,@Name/data.leasetime*/ static int get_DHCPv4Client_LeaseTimeRemaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; if (dhcpv4_s) { json_object *res = NULL; @@ -2687,13 +2664,13 @@ static int get_DHCPv4Client_ReqOptionNumberOfEntries(char *refparam, struct dmct static int get_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->dmmap_sect, "enable", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "enable", value); return 0; } static int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char *option_name = NULL; bool b; @@ -2705,33 +2682,33 @@ static int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, case VALUESET: string_to_bool(value, &b); - if (dhcp_client_s->client_sect) { - option_name = get_dhcp_option_name(DM_STRTOL(dhcp_client_s->option_tag)); + if (((struct dm_data *)data)->config_section) { + option_name = get_dhcp_option_name(DM_STRTOL(option->tag)); if (DM_LSTRCMP(option_name, "sendopts") == 0) { char *sendopts = NULL; - dmuci_get_value_by_section_string(dhcp_client_s->client_sect, "sendopts", &sendopts); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "sendopts", &sendopts); if (b) { char tag_value[128] = {0}; - snprintf(tag_value, sizeof(tag_value), "%s:%s", dhcp_client_s->option_tag, dhcp_client_s->value); + snprintf(tag_value, sizeof(tag_value), "%s:%s", option->tag, option->value); sendopts = add_str_to_str_list(sendopts, " ", tag_value); } else { - sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(dhcp_client_s->option_tag)); + sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(option->tag)); } - dmuci_set_value_by_section(dhcp_client_s->client_sect, "sendopts", sendopts); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", sendopts); } else { char str[256] = {0}; - convert_hex_to_string(dhcp_client_s->value, str, sizeof(str)); - dmuci_set_value_by_section(dhcp_client_s->client_sect, option_name, b ? (DM_STRTOL(dhcp_client_s->option_tag) == DHCP_OPTION_CLIENTID) ? dhcp_client_s->value : str : ""); + convert_hex_to_string(option->value, str, sizeof(str)); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, option_name, b ? (DM_STRTOL(option->tag) == DHCP_OPTION_CLIENTID) ? option->value : str : ""); } } - dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->dmmap_sect, "enable", b ? "1" : "0"); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "enable", b ? "1" : "0"); break; } return 0; @@ -2739,23 +2716,23 @@ static int set_DHCPv4ClientSentOption_Enable(char *refparam, struct dmctx *ctx, static int get_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcp_client_option_args *)data)->dmmap_sect, "bbf_dhcpv4_sentopt_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4_sentopt_alias", instance, value); } static int set_DHCPv4ClientSentOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcp_client_option_args *)data)->dmmap_sect, "bbf_dhcpv4_sentopt_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4_sentopt_alias", instance, value); } static int get_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct dhcp_client_option_args *)data)->option_tag; + *value = ((struct option_args *)((struct dm_data *)data)->additional_data)->tag; return 0; } static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char *dhcp_client_key = NULL; switch (action) { @@ -2763,51 +2740,51 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1","254"}}, 1)) return FAULT_9007; - if (DM_STRCMP(dhcp_client_s->option_tag, value) == 0) + if (DM_STRCMP(option->tag, value) == 0) break; - dmuci_get_value_by_section_string(dhcp_client_s->dmmap_sect, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &dhcp_client_key); if (tag_option_exists("dmmap_dhcp_client", "send_option", "dhcp_client_key", dhcp_client_key, "option_tag", value)) return FAULT_9007; break; case VALUESET: - if (dhcp_client_s->client_sect) { + if (((struct dm_data *)data)->config_section) { char *enable = NULL; - dmuci_get_value_by_section_string(dhcp_client_s->dmmap_sect, "enable", &enable); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "enable", &enable); if (DM_STRCMP(enable, "1") == 0) { char *option_name = NULL; char *sendopts = NULL; char str[256] = {0}; - dmuci_get_value_by_section_string(dhcp_client_s->client_sect, "sendopts", &sendopts); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "sendopts", &sendopts); // Remove the old option - option_name = get_dhcp_option_name(DM_STRTOL(dhcp_client_s->option_tag)); + option_name = get_dhcp_option_name(DM_STRTOL(option->tag)); if (DM_LSTRCMP(option_name, "sendopts") == 0) { - sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(dhcp_client_s->option_tag)); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "sendopts", sendopts); + sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(option->tag)); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", sendopts); } else { - dmuci_set_value_by_section(dhcp_client_s->client_sect, option_name, ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, option_name, ""); } // Add the new option option_name = get_dhcp_option_name(DM_STRTOL(value)); if (DM_LSTRCMP(option_name, "sendopts") == 0) { - snprintf(str, sizeof(str), "%s:%s", value, dhcp_client_s->value); + snprintf(str, sizeof(str), "%s:%s", value, option->value); sendopts = add_str_to_str_list(sendopts, " ", str); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "sendopts", sendopts); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", sendopts); } else { - convert_hex_to_string(dhcp_client_s->value, str, sizeof(str)); - dmuci_set_value_by_section(dhcp_client_s->client_sect, option_name, (DM_STRTOL(value) == DHCP_OPTION_CLIENTID) ? dhcp_client_s->value : str); + convert_hex_to_string(option->value, str, sizeof(str)); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, option_name, (DM_STRTOL(value) == DHCP_OPTION_CLIENTID) ? option->value : str); } } } - dmuci_set_value_by_section_bbfdm(dhcp_client_s->dmmap_sect, "option_tag", value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_tag", value); break; } return 0; @@ -2815,13 +2792,13 @@ static int set_DHCPv4ClientSentOption_Tag(char *refparam, struct dmctx *ctx, voi static int get_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct dhcp_client_option_args *)data)->value; + *value = ((struct option_args *)((struct dm_data *)data)->additional_data)->value; return 0; } static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; switch (action) { case VALUECHECK: @@ -2829,40 +2806,40 @@ static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, v return FAULT_9007; break; case VALUESET: - if (dhcp_client_s->client_sect) { + if (((struct dm_data *)data)->config_section) { char *enable = NULL; - dmuci_get_value_by_section_string(dhcp_client_s->dmmap_sect, "enable", &enable); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "enable", &enable); if (DM_STRCMP(enable, "1") == 0) { char *option_name = NULL; char *sendopts = NULL; char str[256] = {0}; - dmuci_get_value_by_section_string(dhcp_client_s->client_sect, "sendopts", &sendopts); - option_name = get_dhcp_option_name(DM_STRTOL(dhcp_client_s->option_tag)); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "sendopts", &sendopts); + option_name = get_dhcp_option_name(DM_STRTOL(option->tag)); // Remove the old option if (DM_LSTRCMP(option_name, "sendopts") == 0) { - sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(dhcp_client_s->option_tag)); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "sendopts", sendopts); + sendopts = remove_option_from_str_list(sendopts, DM_STRTOL(option->tag)); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", sendopts); } else { - dmuci_set_value_by_section(dhcp_client_s->client_sect, option_name, ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, option_name, ""); } // Add the new option if (DM_LSTRCMP(option_name, "sendopts") == 0) { - snprintf(str, sizeof(str), "%s:%s", dhcp_client_s->option_tag, value); + snprintf(str, sizeof(str), "%s:%s", option->tag, value); sendopts = add_str_to_str_list(sendopts, " ", str); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "sendopts", sendopts); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "sendopts", sendopts); } else { convert_hex_to_string(value, str, sizeof(str)); - dmuci_set_value_by_section(dhcp_client_s->client_sect, option_name, (DM_STRTOL(dhcp_client_s->option_tag) == DHCP_OPTION_CLIENTID) ? value : str); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, option_name, (DM_STRTOL(option->tag) == DHCP_OPTION_CLIENTID) ? value : str); } } } - dmuci_set_value_by_section_bbfdm(dhcp_client_s->dmmap_sect, "option_value", value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_value", value); break; } return 0; @@ -2870,13 +2847,13 @@ static int set_DHCPv4ClientSentOption_Value(char *refparam, struct dmctx *ctx, v static int get_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->dmmap_sect, "enable", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "enable", value); return 0; } static int set_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char *reqopts = NULL; bool b; @@ -2887,20 +2864,20 @@ static int set_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, v break; case VALUESET: string_to_bool(value, &b); - if (dhcp_client_s->client_sect) { - dmuci_get_value_by_section_string(dhcp_client_s->client_sect, "reqopts", &reqopts); + if (((struct dm_data *)data)->config_section) { + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "reqopts", &reqopts); if (b) { - if (!value_exits_in_str_list(reqopts, " ", dhcp_client_s->option_tag)) { - reqopts = add_str_to_str_list(reqopts, " ", dhcp_client_s->option_tag); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "reqopts", reqopts); + if (!value_exits_in_str_list(reqopts, " ", option->tag)) { + reqopts = add_str_to_str_list(reqopts, " ", option->tag); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", reqopts); } } else { - reqopts = remove_str_from_str_list(reqopts, " ", dhcp_client_s->option_tag); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "reqopts", reqopts); + reqopts = remove_str_from_str_list(reqopts, " ", option->tag); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", reqopts); } } - dmuci_set_value_by_section_bbfdm(((struct dhcp_client_option_args *)data)->dmmap_sect, "enable", b ? "1" : "0"); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "enable", b ? "1" : "0"); break; } return 0; @@ -2908,23 +2885,23 @@ static int set_DHCPv4ClientReqOption_Enable(char *refparam, struct dmctx *ctx, v static int get_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcp_client_option_args *)data)->dmmap_sect, "bbf_dhcpv4_reqtopt_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4_reqtopt_alias", instance, value); } static int set_DHCPv4ClientReqOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcp_client_option_args *)data)->dmmap_sect, "bbf_dhcpv4_reqtopt_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4_reqtopt_alias", instance, value); } static int get_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = ((struct dhcp_client_option_args *)data)->option_tag; + *value = ((struct option_args *)((struct dm_data *)data)->additional_data)->tag; return 0; } static int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char *dhcp_client_key = NULL; switch (action) { @@ -2932,34 +2909,34 @@ static int set_DHCPv4ClientReqOption_Tag(char *refparam, struct dmctx *ctx, void if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1","254"}}, 1)) return FAULT_9007; - if (DM_STRCMP(dhcp_client_s->option_tag, value) == 0) + if (DM_STRCMP(option->tag, value) == 0) break; - dmuci_get_value_by_section_string(dhcp_client_s->dmmap_sect, "dhcp_client_key", &dhcp_client_key); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "dhcp_client_key", &dhcp_client_key); if (tag_option_exists("dmmap_dhcp_client", "req_option", "dhcp_client_key", dhcp_client_key, "option_tag", value)) return FAULT_9007; break; case VALUESET: - if (dhcp_client_s->client_sect) { + if (((struct dm_data *)data)->config_section) { bool tag_enabled = false; char *reqopts = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_option_args *)data)->client_sect, "reqopts", &reqopts); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "reqopts", &reqopts); - if (value_exits_in_str_list(reqopts, " ", dhcp_client_s->option_tag)) { - reqopts = remove_str_from_str_list(reqopts, " ", dhcp_client_s->option_tag); + if (value_exits_in_str_list(reqopts, " ", option->tag)) { + reqopts = remove_str_from_str_list(reqopts, " ", option->tag); tag_enabled = true; } if (tag_enabled) { reqopts = add_str_to_str_list(reqopts, " ", value); - dmuci_set_value_by_section(dhcp_client_s->client_sect, "reqopts", reqopts); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", reqopts); } } - dmuci_set_value_by_section_bbfdm(dhcp_client_s->dmmap_sect, "option_tag", value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_tag", value); break; } return 0; @@ -3008,17 +2985,17 @@ static int get_DHCPv4Server_PoolNumberOfEntries(char *refparam, struct dmctx *ct static int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; - struct uci_list *dhcp_option_list = NULL; + struct uci_list *option_list = NULL; - dmuci_get_value_by_section_list(dhcp_client_s->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list != NULL) { + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &option_list); + if (option_list != NULL) { + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; struct uci_element *e = NULL; size_t length; - uci_foreach_element(dhcp_option_list, e) { + uci_foreach_element(option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { *value = "1"; return 0; } @@ -3030,8 +3007,8 @@ static int get_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, static int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; - struct uci_list *dhcp_option_list = NULL; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; + struct uci_list *option_list = NULL; char opt_value[128] = {0}; bool option_enabled = false, b; @@ -3042,50 +3019,50 @@ static int set_DHCPv4ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, break; case VALUESET: string_to_bool(value, &b); - dmuci_get_value_by_section_list(dhcp_client_s->client_sect, "dhcp_option", &dhcp_option_list); - snprintf(opt_value, sizeof(opt_value), "%s,%s", dhcp_client_s->option_tag, dhcp_client_s->value); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &option_list); + snprintf(opt_value, sizeof(opt_value), "%s,%s", option->tag, option->value); - if (dhcp_option_list != NULL) { + if (option_list != NULL) { struct uci_element *e = NULL; size_t length; - uci_foreach_element(dhcp_option_list, e) { + uci_foreach_element(option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { option_enabled = true; if (!b) - dmuci_del_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", opt_value); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", opt_value); break; } } } if(!option_enabled && b) - dmuci_add_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", opt_value); + dmuci_add_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", opt_value); } return 0; } static int get_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcp_client_option_args *)data)->dmmap_sect, "bbf_dhcpv4_servpool_option_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4_servpool_option_alias", instance, value); } static int set_DHCPv4ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcp_client_option_args *)data)->dmmap_sect, "bbf_dhcpv4_servpool_option_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4_servpool_option_alias", instance, value); } static int get_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(((struct dhcp_client_option_args *)data)->option_tag); + *value = dmstrdup(((struct option_args *)((struct dm_data *)data)->additional_data)->tag); return 0; } static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; - struct uci_list *dhcp_option_list = NULL; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; + struct uci_list *option_list = NULL; bool option_enabled = false; switch (action) { @@ -3093,23 +3070,23 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"1","254"}}, 1)) return FAULT_9007; - if (dhcp_client_s->option_tag && DM_STRCMP(dhcp_client_s->option_tag, value) == 0) + if (option->tag && DM_STRCMP(option->tag, value) == 0) break; - if (tag_option_exists("dmmap_dhcp", "servpool_option", "section_name", section_name(dhcp_client_s->client_sect), "option_tag", value)) + if (tag_option_exists("dmmap_dhcp", "servpool_option", "section_name", section_name(((struct dm_data *)data)->config_section), "option_tag", value)) return FAULT_9007; break; case VALUESET: - dmuci_get_value_by_section_list(dhcp_client_s->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &option_list); - if (dhcp_option_list != NULL) { + if (option_list != NULL) { struct uci_element *e = NULL; size_t length; - uci_foreach_element(dhcp_option_list, e) { + uci_foreach_element(option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { option_enabled = true; break; } @@ -3119,13 +3096,13 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi if (option_enabled) { char new_tag_value[128] = {0}, old_tag_value[128] = {0}; - snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", dhcp_client_s->option_tag, dhcp_client_s->value); - snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", value, dhcp_client_s->value); - dmuci_del_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", old_tag_value); - dmuci_add_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", new_tag_value); + snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", option->tag, option->value); + snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", value, option->value); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", old_tag_value); + dmuci_add_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", new_tag_value); } - dmuci_set_value_by_section_bbfdm(dhcp_client_s->dmmap_sect, "option_tag", value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_tag", value); break; } return 0; @@ -3133,12 +3110,11 @@ static int set_DHCPv4ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi static int get_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - const char *tag_option = ((struct dhcp_client_option_args *)data)->option_tag; - const char *tag_value = ((struct dhcp_client_option_args *)data)->value; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char hex[256] = {0}; - if (DM_STRLEN(tag_option) && DM_STRLEN(tag_value)) - convert_str_option_to_hex(DM_STRTOL(tag_option), tag_value, hex, sizeof(hex)); + if (DM_STRLEN(option->tag) && DM_STRLEN(option->value)) + convert_str_option_to_hex(DM_STRTOL(option->tag), option->value, hex, sizeof(hex)); *value = (*hex) ? dmstrdup(hex) : ""; return 0; @@ -3146,8 +3122,8 @@ static int get_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v static int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_option_args *dhcp_client_s = (struct dhcp_client_option_args *)data; - struct uci_list *dhcp_option_list = NULL; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; + struct uci_list *option_list = NULL; char res[256] = {0}; bool option_enabled = false; @@ -3157,33 +3133,33 @@ static int set_DHCPv4ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v return FAULT_9007; break; case VALUESET: - dmuci_get_value_by_section_list(dhcp_client_s->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &option_list); - if (dhcp_option_list != NULL) { + if (option_list != NULL) { struct uci_element *e = NULL; size_t length; - uci_foreach_element(dhcp_option_list, e) { + uci_foreach_element(option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcp_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { option_enabled = true; break; } } } - convert_hex_option_to_string(DM_STRTOL(dhcp_client_s->option_tag), value, res, sizeof(res)); + convert_hex_option_to_string(DM_STRTOL(option->tag), value, res, sizeof(res)); if (option_enabled) { char new_tag_value[512] = {0}, old_tag_value[128] = {0}; - snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", dhcp_client_s->option_tag, dhcp_client_s->value); - snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", dhcp_client_s->option_tag, res); - dmuci_del_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", old_tag_value); - dmuci_add_list_value_by_section(dhcp_client_s->client_sect, "dhcp_option", new_tag_value); + snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", option->tag, option->value); + snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", option->tag, res); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", old_tag_value); + dmuci_add_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", new_tag_value); } - dmuci_set_value_by_section_bbfdm(dhcp_client_s->dmmap_sect, "option_value", res); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_value", res); break; } return 0; @@ -3236,17 +3212,15 @@ static int get_DHCPv4Relay_ForwardingNumberOfEntries(char *refparam, struct dmct /*#Device.DHCPv4.Relay.Forwarding.{i}.Enable!UCI:network/interface,@i-1/disabled*/ static int get_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcp_client_args *dhcp_relay = (struct dhcp_client_args *)data; char *disabled = NULL; - dmuci_get_value_by_section_string(dhcp_relay->iface_s ? dhcp_relay->iface_s : dhcp_relay->dmmap_s, "disabled", &disabled); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section ? ((struct dm_data *)data)->config_section : ((struct dm_data *)data)->dmmap_section, "disabled", &disabled); *value = (disabled[0] == '1') ? "0" : "1"; return 0; } static int set_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_args *dhcp_relay = (struct dhcp_client_args *)data; bool b; switch (action) { @@ -3256,9 +3230,9 @@ static int set_DHCPv4RelayForwarding_Enable(char *refparam, struct dmctx *ctx, v return 0; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(dhcp_relay->dmmap_s, "disabled", b ? "0" : "1"); - if (dhcp_relay->iface_s) - dmuci_set_value_by_section(dhcp_relay->iface_s, "disabled", b ? "0" : "1"); + dmuci_set_value_by_section(((struct dm_data *)data)->dmmap_section, "disabled", b ? "0" : "1"); + if (((struct dm_data *)data)->config_section) + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "disabled", b ? "0" : "1"); break; } return 0; @@ -3274,19 +3248,19 @@ static int get_DHCPv4RelayForwarding_Status(char *refparam, struct dmctx *ctx, v static int get_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcp_client_args *)data)->dmmap_s, "bbf_dhcpv4relay_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4relay_alias", instance, value); } static int set_DHCPv4RelayForwarding_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcp_client_args *)data)->dmmap_s, "bbf_dhcpv4relay_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv4relay_alias", instance, value); } static int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface_name = NULL; - dmuci_get_value_by_section_string(((struct dhcp_client_args *)data)->dmmap_s, "iface_name", &iface_name); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "iface_name", &iface_name); adm_entry_get_reference_param(ctx, "Device.IP.Interface.*.Name", iface_name, value); return 0; @@ -3294,7 +3268,6 @@ static int get_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_client_args *dhcp_relay = (struct dhcp_client_args *)data; char *allowed_objects[] = {"Device.IP.Interface.", NULL}; struct dm_reference reference = {0}; struct uci_section *interface_s = NULL; @@ -3312,7 +3285,7 @@ static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx break; case VALUESET: - dmuci_get_value_by_section_string(dhcp_relay->dmmap_s, "iface_name", &curr_iface_name); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "iface_name", &curr_iface_name); // Get the corresponding network config if (DM_STRLEN(reference.value)) @@ -3322,17 +3295,17 @@ static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx if (interface_s && (strcmp(section_name(interface_s), curr_iface_name) == 0)) break; - dmuci_set_value_by_section(dhcp_relay->iface_s, "proto", "none"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", "none"); if (DM_STRLEN(reference.value) == 0) { - dmuci_set_value_by_section_bbfdm(dhcp_relay->dmmap_s, "added_by_controller", "1"); - dmuci_set_value_by_section_bbfdm(dhcp_relay->dmmap_s, "iface_name", ""); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "added_by_controller", "1"); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "iface_name", ""); } else { // Update proto option of config section dmuci_set_value_by_section(interface_s, "proto", "relay"); // Update dmmap section - dmuci_set_value_by_section_bbfdm(dhcp_relay->dmmap_s, "iface_name", reference.value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "iface_name", reference.value); } break; } @@ -3342,7 +3315,7 @@ static int set_DHCPv4RelayForwarding_Interface(char *refparam, struct dmctx *ctx /*#Device.DHCPv4.Relay.Forwarding.{i}.VendorClassID!UCI:network/interface,@i-1/vendorclass*/ static int get_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcp_relay_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcp_relay_s = ((struct dm_data *)data)->config_section; if (dhcp_relay_s) { char *relay_network = NULL; @@ -3359,7 +3332,7 @@ static int get_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx static int set_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *dhcp_relay_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcp_relay_s = ((struct dm_data *)data)->config_section; switch (action) { case VALUECHECK: @@ -3385,7 +3358,7 @@ static int set_DHCPv4RelayForwarding_VendorClassID(char *refparam, struct dmctx /*#Device.DHCPv4.Relay.Forwarding.{i}.Chaddr!UCI:network/interface,@i-1/mac*/ static int get_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcp_relay_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcp_relay_s = ((struct dm_data *)data)->config_section; if (dhcp_relay_s) { char *relay_network = NULL; @@ -3416,7 +3389,7 @@ static int set_DHCPv4RelayForwarding_Chaddr(char *refparam, struct dmctx *ctx, v /*#Device.DHCPv4.Relay.Forwarding.{i}.UserClassID!UCI:network/interface,@i-1/userclass*/ static int get_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcp_relay_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcp_relay_s = ((struct dm_data *)data)->config_section; if (dhcp_relay_s) { char *relay_network = NULL; @@ -3441,7 +3414,7 @@ static int get_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *c static int set_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *dhcp_relay_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcp_relay_s = ((struct dm_data *)data)->config_section; switch (action) { @@ -3474,7 +3447,7 @@ static int set_DHCPv4RelayForwarding_UserClassID(char *refparam, struct dmctx *c *************************************************************/ static int operate_DHCPv4Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *dhcpv4_s = ((struct dhcp_client_args *)data)->iface_s; + struct uci_section *dhcpv4_s = ((struct dm_data *)data)->config_section; if (dhcpv4_s) { char *if_name = section_name(dhcpv4_s); diff --git a/libbbfdm/dmtree/tr181/dhcpv4.h b/libbbfdm/dmtree/tr181/dhcpv4.h index 011863d8..0aa46663 100644 --- a/libbbfdm/dmtree/tr181/dhcpv4.h +++ b/libbbfdm/dmtree/tr181/dhcpv4.h @@ -37,6 +37,12 @@ extern DMOBJ tDHCPv4RelayObj[]; extern DMLEAF tDHCPv4RelayParams[]; extern DMLEAF tDHCPv4RelayForwardingParams[]; +struct option_args +{ + char *tag; + char *value; +}; + int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order); int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, char **value); bool tag_option_exists(char *dmmap_package, char *section, char *opt_check, char *value_check, char *tag_name, char *tag_value); diff --git a/libbbfdm/dmtree/tr181/dhcpv6.c b/libbbfdm/dmtree/tr181/dhcpv6.c index eb1555cf..113583e8 100644 --- a/libbbfdm/dmtree/tr181/dhcpv6.c +++ b/libbbfdm/dmtree/tr181/dhcpv6.c @@ -12,19 +12,6 @@ #include "dhcpv4.h" #include "dhcpv6.h" - -struct dhcpv6_client_args -{ - struct uci_section *iface_s; - struct uci_section *dmmap_s; -}; - -struct dhcpv6_args -{ - struct dmmap_dup *dhcp_sections; - char *interface; -}; - struct clientv6_args { json_object *client; @@ -32,13 +19,6 @@ struct clientv6_args int idx; }; -struct dhcpv6_client_option_args { - struct uci_section *client_sect; - struct uci_section *dmmap_sect; - char *option_tag; - char *value; -}; - /************************************************************* * COMMON FUNCTIONS **************************************************************/ @@ -129,21 +109,14 @@ static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_objec return 0; } -static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct dmmap_dup *s, char *interface) -{ - args->dhcp_sections = s; - args->interface = interface; - return 0; -} - /************************************************************* * ENTRY METHOD **************************************************************/ /*#Device.DHCPv6.Client.{i}.!UCI:network/interface/dmmap_dhcpv6*/ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dhcpv6_client_args curr_dhcpv6_client_args = {0}; struct uci_section *dmmap_s = NULL; + struct dm_data curr_data = {0}; char *inst = NULL; dmmap_synchronizeDHCPv6Client(dmctx, parent_node, prev_data, prev_instance); @@ -155,12 +128,12 @@ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void if (DM_STRLEN(iface_name)) get_config_section_of_dmmap_section("network", "interface", iface_name, &iface_s); - curr_dhcpv6_client_args.iface_s = iface_s; - curr_dhcpv6_client_args.dmmap_s = dmmap_s; + curr_data.config_section = iface_s; + curr_data.dmmap_section = dmmap_s; inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv6client_instance", "bbf_dhcpv6client_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcpv6_client_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -170,28 +143,27 @@ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *ignore = NULL, *interface, *inst = NULL, *v; - struct dhcpv6_args curr_dhcp6_args = {0}; - struct dmmap_dup *p = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); synchronize_specific_config_sections_with_dmmap("dhcp", "dhcp", "dmmap_dhcpv6", &dup_list); - list_for_each_entry(p, &dup_list, list) { + list_for_each_entry(curr_data, &dup_list, list) { // skip the section if option ignore = '1' - dmuci_get_value_by_section_string(p->config_section, "ignore", &ignore); + dmuci_get_value_by_section_string(curr_data->config_section, "ignore", &ignore); if (ignore && DM_LSTRCMP(ignore, "1") == 0) continue; - dmuci_get_value_by_section_string(p->config_section, "interface", &interface); - init_dhcpv6_args(&curr_dhcp6_args, p, interface); + dmuci_get_value_by_section_string(curr_data->config_section, "interface", &interface); + curr_data->additional_data = (void *)interface; - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias"); - dmuci_get_value_by_section_string(p->dmmap_section, "order", &v); + dmuci_get_value_by_section_string(curr_data->dmmap_section, "order", &v); if (v == NULL || DM_STRLEN(v) == 0) - set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", p->dmmap_section, p->config_section, 0, inst); + set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", curr_data->dmmap_section, curr_data->config_section, 0, inst); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp6_args, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } free_dmmap_config_dup_list(&dup_list); @@ -201,13 +173,13 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dhcpv6_args *dhcp_arg= (struct dhcpv6_args *)prev_data; + struct dm_data *dhcp_arg= (struct dm_data *)prev_data; json_object *res = NULL, *res1 = NULL, *jobj = NULL, *dev_obj = NULL, *net_obj = NULL; struct clientv6_args curr_dhcp_client_args = {0}; int i = 0; char *inst = NULL, *device; - char *if_name = section_name(dhcp_arg->dhcp_sections->config_section); + char *if_name = section_name(dhcp_arg->config_section); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", if_name, String}}, 1, &res1); if (!res1) return 0; device = dmjson_get_value(res1, 1, "device"); @@ -232,44 +204,44 @@ static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dhcpv6_args *curr_dhcp_args = (struct dhcpv6_args *)prev_data; - struct uci_list *dhcp_options_list = NULL; + struct option_args curr_option_args = {0}; + struct uci_list *options_list = NULL; + struct dm_data curr_data = {0}; struct uci_element *e = NULL; - struct uci_section *dmmap_sect = NULL; - char **dhcpv6_option = NULL, *inst = NULL, *dhcpv6_tag, *dhcpv6_value; + struct uci_section *dmmap_s = NULL; + char **option = NULL, *inst = NULL; size_t length = 0; - struct dhcpv6_client_option_args dhcpv6_client_opt_args = {0}; - dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sections->config_section, "dhcp_option", &dhcp_options_list); + dmuci_get_value_by_section_list(((struct dm_data *)prev_data)->config_section, "dhcp_option", &options_list); - if (dhcp_options_list != NULL) { - uci_foreach_element(dhcp_options_list, e) { + if (options_list != NULL) { + uci_foreach_element(options_list, e) { - dhcpv6_option = strsplit(e->name, ",", &length); - if (!dhcpv6_option) + option = strsplit(e->name, ",", &length); + if (!option) continue; - if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(curr_dhcp_args->dhcp_sections->config_section), "option_tag", dhcpv6_option[0])) == NULL) { - dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", dhcpv6_option[0]); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sections->config_section)); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_value", length > 1 ? dhcpv6_option[1] : ""); + if ((dmmap_s = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(((struct dm_data *)prev_data)->config_section), "option_tag", option[0])) == NULL) { + dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_s); + dmuci_set_value_by_section_bbfdm(dmmap_s, "option_tag", option[0]); + dmuci_set_value_by_section_bbfdm(dmmap_s, "section_name", section_name(((struct dm_data *)prev_data)->config_section)); + dmuci_set_value_by_section_bbfdm(dmmap_s, "option_value", length > 1 ? option[1] : ""); } } } - uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sections->config_section), dmmap_sect) { - dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &dhcpv6_tag); - dmuci_get_value_by_section_string(dmmap_sect, "option_value", &dhcpv6_value); + uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(((struct dm_data *)prev_data)->config_section), dmmap_s) { - dhcpv6_client_opt_args.client_sect = curr_dhcp_args->dhcp_sections->config_section; - dhcpv6_client_opt_args.dmmap_sect = dmmap_sect; - dhcpv6_client_opt_args.option_tag = dhcpv6_tag; - dhcpv6_client_opt_args.value = dhcpv6_value; + dmuci_get_value_by_section_string(dmmap_s, "option_tag", &curr_option_args.tag); + dmuci_get_value_by_section_string(dmmap_s, "option_value", &curr_option_args.value); - inst = handle_instance(dmctx, parent_node, dmmap_sect, "bbf_dhcpv6_servpool_option_instance", "bbf_dhcpv6_servpool_option_alias"); + curr_data.config_section = ((struct dm_data *)prev_data)->config_section; + curr_data.dmmap_section = dmmap_s; + curr_data.additional_data = &curr_option_args; - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcpv6_client_opt_args, inst) == DM_STOP) + inst = handle_instance(dmctx, parent_node, dmmap_s, "bbf_dhcpv6_servpool_option_instance", "bbf_dhcpv6_servpool_option_alias"); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -342,20 +314,20 @@ static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha switch (del_action) { case DEL_INST: - dmuci_delete_by_section(((struct dhcpv6_client_args *)data)->dmmap_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); - if (((struct dhcpv6_client_args *)data)->iface_s) { + if (((struct dm_data *)data)->config_section) { char *ip_instance = NULL; - struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(((struct dhcpv6_client_args *)data)->iface_s)); + struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(((struct dm_data *)data)->config_section)); dmuci_get_value_by_section_string(dmmap_s, "ip_int_instance", &ip_instance); if (dmmap_s && DM_STRLEN(ip_instance) == 0) { - dmuci_delete_by_section(((struct dhcpv6_client_args *)data)->iface_s, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); } else { - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->iface_s, "proto", "none"); - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->iface_s, "reqaddress", ""); - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->iface_s, "reqprefix", ""); - dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->iface_s, "reqopts", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "proto", "none"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqaddress", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqprefix", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "reqopts", ""); } } break; @@ -414,8 +386,8 @@ static int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, switch (del_action) { case DEL_INST: - dmuci_delete_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, NULL, NULL); - dmuci_delete_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: uci_foreach_sections_safe("dhcp", "dhcp", stmp, s) { @@ -438,12 +410,12 @@ static int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, static int addObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance) { - struct dhcpv6_args *dhcpv6_arg = (struct dhcpv6_args *)data; + struct dm_data *dhcpv6_arg = (struct dm_data *)data; struct uci_section *dmmap_sect; dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect); - dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(dhcpv6_arg->dhcp_sections->config_section)); - char *option_tag = generate_tag_option("dmmap_dhcpv6", "servpool_option", "section_name", section_name(dhcpv6_arg->dhcp_sections->config_section), "option_tag"); + dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(dhcpv6_arg->config_section)); + char *option_tag = generate_tag_option("dmmap_dhcpv6", "servpool_option", "section_name", section_name(dhcpv6_arg->config_section), "option_tag"); dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", option_tag); dmuci_set_value_by_section_bbfdm(dmmap_sect, "bbf_dhcpv6_servpool_option_instance", *instance); return 0; @@ -456,18 +428,19 @@ static int delObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void switch (del_action) { case DEL_INST: - dmuci_get_value_by_section_list(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", &dhcp_options_list); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &dhcp_options_list); if (dhcp_options_list != NULL) { + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; char tag_value[128] = {0}; - snprintf(tag_value, sizeof(tag_value), "%s,%s", ((struct dhcpv6_client_option_args *)data)->option_tag, ((struct dhcpv6_client_option_args *)data)->value); - dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", tag_value); + snprintf(tag_value, sizeof(tag_value), "%s,%s", option->tag, option->value); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", tag_value); } - dmuci_delete_by_section(((struct dhcpv6_client_option_args *)data)->dmmap_sect, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); break; case DEL_ALL: - dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcp_option", ""); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", ""); uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcpv6", "servpool_option", stmp, s) { dmuci_delete_by_section(s, NULL, NULL); } @@ -489,17 +462,17 @@ static int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, v /*#Device.DHCPv6.Client.{i}.Enable!UCI:network/interface,@i-1/disabled*/ static int get_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; char *disabled = NULL; - dmuci_get_value_by_section_string(dhcpv6_client->iface_s ? dhcpv6_client->iface_s : dhcpv6_client->dmmap_s, "disabled", &disabled); + dmuci_get_value_by_section_string(dhcpv6_client->config_section ? dhcpv6_client->config_section : dhcpv6_client->dmmap_section, "disabled", &disabled); *value = (disabled[0] == '1') ? "0" : "1"; return 0; } static int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; bool b; switch (action) { @@ -509,9 +482,9 @@ static int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data return 0; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(dhcpv6_client->dmmap_s, "disabled", b ? "0" : "1"); - if (dhcpv6_client->iface_s) - dmuci_set_value_by_section(dhcpv6_client->iface_s, "disabled", b ? "0" : "1"); + dmuci_set_value_by_section(dhcpv6_client->dmmap_section, "disabled", b ? "0" : "1"); + if (dhcpv6_client->config_section) + dmuci_set_value_by_section(dhcpv6_client->config_section, "disabled", b ? "0" : "1"); return 0; } return 0; @@ -519,27 +492,27 @@ static int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data static int get_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcpv6_client_args *)data)->dmmap_s, "bbf_dhcpv6client_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv6client_alias", instance, value); } static int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcpv6_client_args *)data)->dmmap_s, "bbf_dhcpv6client_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv6client_alias", instance, value); } static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface_name = NULL; - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dmmap_s, "iface_name", &iface_name); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "iface_name", &iface_name); adm_entry_get_reference_param(ctx, "Device.IP.Interface.*.Name", iface_name, value); - if (DM_STRLEN(*value) == 0 && ((struct dhcpv6_client_args *)data)->iface_s) { + if (DM_STRLEN(*value) == 0 && ((struct dm_data *)data)->config_section) { struct uci_section *s = NULL; char *device = NULL; - dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->iface_s, "device", &device); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "device", &device); if (DM_STRLEN(device) == 0) return 0; @@ -553,7 +526,7 @@ static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; char *allowed_objects[] = {"Device.IP.Interface.", NULL}; struct dm_reference reference = {0}; @@ -569,23 +542,23 @@ static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d break; case VALUESET: - if (dhcpv6_client->iface_s) { + if (dhcpv6_client->config_section) { char *ip_instance = NULL; - struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(dhcpv6_client->iface_s)); + struct uci_section *dmmap_s = get_dup_section_in_dmmap("dmmap_network", "interface", section_name(dhcpv6_client->config_section)); dmuci_get_value_by_section_string(dmmap_s, "ip_int_instance", &ip_instance); if (dmmap_s && DM_STRLEN(ip_instance) == 0) { - dmuci_delete_by_section(dhcpv6_client->iface_s, NULL, NULL); + dmuci_delete_by_section(dhcpv6_client->config_section, NULL, NULL); } else { - dmuci_set_value_by_section(dhcpv6_client->iface_s, "proto", "none"); - dmuci_set_value_by_section(dhcpv6_client->iface_s, "reqaddress", ""); - dmuci_set_value_by_section(dhcpv6_client->iface_s, "reqprefix", ""); - dmuci_set_value_by_section(dhcpv6_client->iface_s, "reqopts", ""); + dmuci_set_value_by_section(dhcpv6_client->config_section, "proto", "none"); + dmuci_set_value_by_section(dhcpv6_client->config_section, "reqaddress", ""); + dmuci_set_value_by_section(dhcpv6_client->config_section, "reqprefix", ""); + dmuci_set_value_by_section(dhcpv6_client->config_section, "reqopts", ""); } } // Update iface_name option - dmuci_set_value_by_section_bbfdm(dhcpv6_client->dmmap_s, "iface_name", reference.value); + dmuci_set_value_by_section_bbfdm(dhcpv6_client->dmmap_section, "iface_name", reference.value); if (DM_STRLEN(reference.value)) { struct uci_section *interface_s = NULL; @@ -617,16 +590,16 @@ static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d dmuci_set_value_by_section(interface_s, "device", curr_device); // Update iface_name option - dmuci_set_value_by_section_bbfdm(dhcpv6_client->dmmap_s, "iface_name", buf); + dmuci_set_value_by_section_bbfdm(dhcpv6_client->dmmap_section, "iface_name", buf); } // Update proto option of config section dmuci_set_value_by_section(interface_s, "proto", "dhcpv6"); // Get the current value of requested parameters - dmuci_get_value_by_section_string(dhcpv6_client->dmmap_s, "reqaddress", &reqaddress); - dmuci_get_value_by_section_string(dhcpv6_client->dmmap_s, "reqprefix", &reqprefix); - dmuci_get_value_by_section_string(dhcpv6_client->dmmap_s, "reqopts", &reqopts); + dmuci_get_value_by_section_string(dhcpv6_client->dmmap_section, "reqaddress", &reqaddress); + dmuci_get_value_by_section_string(dhcpv6_client->dmmap_section, "reqprefix", &reqprefix); + dmuci_get_value_by_section_string(dhcpv6_client->dmmap_section, "reqopts", &reqopts); // Set requested parameters dmuci_set_value_by_section(interface_s, "reqaddress", reqaddress); @@ -649,7 +622,7 @@ static int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data /*#Device.DHCPv6.Client.{i}.DUID!UBUS:network.interface/status/interface,@Name/data.passthru*/ static int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->iface_s; + struct uci_section *dhcpv6_s = ((struct dm_data *)data)->config_section; if (dhcpv6_s) { json_object *res = NULL; @@ -663,17 +636,17 @@ static int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, /*#Device.DHCPv6.Client.{i}.RequestAddresses!UCI:network/interface,@i-1/reqaddress*/ static int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; char *reqaddress = NULL; - dmuci_get_value_by_section_string(dhcpv6_client->iface_s ? dhcpv6_client->iface_s : dhcpv6_client->dmmap_s, "reqaddress", &reqaddress); + dmuci_get_value_by_section_string(dhcpv6_client->config_section ? dhcpv6_client->config_section : dhcpv6_client->dmmap_section, "reqaddress", &reqaddress); *value = (reqaddress && DM_LSTRCMP(reqaddress, "none") == 0) ? "0" : "1"; return 0; } static int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; bool b; switch (action) { @@ -683,9 +656,9 @@ static int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, return 0; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(dhcpv6_client->dmmap_s, "reqaddress", b ? "force" : "none"); - if (dhcpv6_client->iface_s) - dmuci_set_value_by_section(dhcpv6_client->iface_s, "reqaddress", b ? "force" : "none"); + dmuci_set_value_by_section(dhcpv6_client->dmmap_section, "reqaddress", b ? "force" : "none"); + if (dhcpv6_client->config_section) + dmuci_set_value_by_section(dhcpv6_client->config_section, "reqaddress", b ? "force" : "none"); break; } return 0; @@ -694,17 +667,17 @@ static int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx, /*#Device.DHCPv6.Client.{i}.RequestPrefixes!UCI:network/interface,@i-1/reqprefix*/ static int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; char *reqprefix = NULL; - dmuci_get_value_by_section_string(dhcpv6_client->iface_s ? dhcpv6_client->iface_s : dhcpv6_client->dmmap_s, "reqprefix", &reqprefix); + dmuci_get_value_by_section_string(dhcpv6_client->config_section ? dhcpv6_client->config_section : dhcpv6_client->dmmap_section, "reqprefix", &reqprefix); *value = (reqprefix && DM_LSTRCMP(reqprefix, "auto") == 0) ? "1" : "0"; return 0; } static int set_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; bool b; switch (action) { @@ -714,9 +687,9 @@ static int set_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, v return 0; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section(dhcpv6_client->dmmap_s, "reqprefix", b ? "auto" : "no"); - if (dhcpv6_client->iface_s) - dmuci_set_value_by_section(dhcpv6_client->iface_s, "reqprefix", b ? "auto" : "no"); + dmuci_set_value_by_section(dhcpv6_client->dmmap_section, "reqprefix", b ? "auto" : "no"); + if (dhcpv6_client->config_section) + dmuci_set_value_by_section(dhcpv6_client->config_section, "reqprefix", b ? "auto" : "no"); return 0; } return 0; @@ -730,7 +703,7 @@ static int get_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->iface_s; + struct uci_section *dhcpv6_s = ((struct dm_data *)data)->config_section; bool b; switch (action) { @@ -753,15 +726,15 @@ static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, /*#Device.DHCPv6.Client.{i}.RequestedOptions!UCI:network/interface,@i-1/reqopts*/ static int get_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; - dmuci_get_value_by_section_string(dhcpv6_client->iface_s ? dhcpv6_client->iface_s : dhcpv6_client->dmmap_s, "reqopts", value); + dmuci_get_value_by_section_string(dhcpv6_client->config_section ? dhcpv6_client->config_section : dhcpv6_client->dmmap_section, "reqopts", value); return 0; } static int set_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_args *dhcpv6_client = (struct dhcpv6_client_args *)data; + struct dm_data *dhcpv6_client = (struct dm_data *)data; switch (action) { case VALUECHECK: @@ -769,9 +742,9 @@ static int set_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section(dhcpv6_client->dmmap_s, "reqopts", value); - if (dhcpv6_client->iface_s) - dmuci_set_value_by_section(dhcpv6_client->iface_s, "reqopts", value); + dmuci_set_value_by_section(dhcpv6_client->dmmap_section, "reqopts", value); + if (dhcpv6_client->config_section) + dmuci_set_value_by_section(dhcpv6_client->config_section, "reqopts", value); break; } return 0; @@ -814,7 +787,7 @@ static int get_DHCPv6Server_PoolNumberOfEntries(char *refparam, struct dmctx *ct /*#Device.DHCPv6.Server.Pool.{i}.Enable!UCI:dhcp/dhcp,@i-1/dhcpv6*/ static int get_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dhcpv6", value); *value = (*value && DM_LSTRCMP(*value, "disabled") == 0) ? "0" : "1"; return 0; } @@ -830,7 +803,7 @@ static int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void * return 0; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", b ? "server" : "disabled"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "dhcpv6", b ? "server" : "disabled"); return 0; } return 0; @@ -839,7 +812,7 @@ static int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void * /*#Device.DHCPv6.Server.Pool.{i}.Status!UCI:dhcp/dhcp,@i-1/dhcpv6*/ static int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "dhcpv6", value); *value = (*value && DM_LSTRCMP(*value, "disabled") == 0) ? "Disabled" : "Enabled"; return 0; } @@ -847,17 +820,17 @@ static int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void * /*#Device.DHCPv6.Server.Pool.{i}.Alias!UCI:dmmap_dhcpv6/dhcp,@i-1/dhcpv6_serv_pool_alias*/ static int get_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, (((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, "dhcpv6_serv_pool_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "dhcpv6_serv_pool_alias", instance, value); } static int set_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, (((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, "dhcpv6_serv_pool_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "dhcpv6_serv_pool_alias", instance, value); } static int get_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, "order", value); + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "order", value); return 0; } @@ -869,7 +842,7 @@ static int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *d return FAULT_9007; break; case VALUESET: - set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", (((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, (((struct dhcpv6_args *)data)->dhcp_sections)->config_section, 1, value); + set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", ((struct dm_data *)data)->dmmap_section, ((struct dm_data *)data)->config_section, 1, value); break; } return 0; @@ -877,7 +850,7 @@ static int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *d static int get_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - adm_entry_get_reference_param(ctx, "Device.IP.Interface.*.Name", ((struct dhcpv6_args *)data)->interface, value); + adm_entry_get_reference_param(ctx, "Device.IP.Interface.*.Name", (char *)((struct dm_data *)data)->additional_data, value); return 0; } @@ -898,7 +871,7 @@ static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, voi break; case VALUESET: - dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "interface", reference.value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "interface", reference.value); break; } return 0; @@ -909,7 +882,7 @@ static int get_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, { char hex[256] = {0}, *vcid = NULL; - struct uci_section *vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface); + struct uci_section *vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", (char *)((struct dm_data *)data)->additional_data); dmuci_get_value_by_section_string(vendorclassidclassifier, "vendorclass", &vcid); if (vcid && *vcid) @@ -932,10 +905,10 @@ static int set_DHCPv6ServerPool_VendorClassID(char *refparam, struct dmctx *ctx, case VALUESET: convert_hex_to_string(value, res, sizeof(res)); - vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", ((struct dhcpv6_args *)data)->interface); + vendorclassidclassifier = get_dhcpv6_classifier("vendorclass", (char *)((struct dm_data *)data)->additional_data); if (!vendorclassidclassifier) { dmuci_add_section("dhcp", "vendorclass", &vendorclassidclassifier); - dmuci_set_value_by_section(vendorclassidclassifier, "networkid", ((struct dhcpv6_args *)data)->interface); + dmuci_set_value_by_section(vendorclassidclassifier, "networkid", (char *)((struct dm_data *)data)->additional_data); } dmuci_set_value_by_section(vendorclassidclassifier, "vendorclass", res); break; @@ -948,7 +921,7 @@ static int get_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, v { char hex[256] = {0}, *ucid = NULL; - struct uci_section *userclassidclassifier = get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface); + struct uci_section *userclassidclassifier = get_dhcpv6_classifier("userclass", (char *)((struct dm_data *)data)->additional_data); dmuci_get_value_by_section_string(userclassidclassifier, "userclass", &ucid); if (ucid && *ucid) @@ -971,10 +944,10 @@ static int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, v case VALUESET: convert_hex_to_string(value, res, sizeof(res)); - userclassidclassifier = get_dhcpv6_classifier("userclass", ((struct dhcpv6_args *)data)->interface); + userclassidclassifier = get_dhcpv6_classifier("userclass", (char *)((struct dm_data *)data)->additional_data); if (!userclassidclassifier) { dmuci_add_section("dhcp", "userclass", &userclassidclassifier); - dmuci_set_value_by_section(userclassidclassifier, "networkid", ((struct dhcpv6_args *)data)->interface); + dmuci_set_value_by_section(userclassidclassifier, "networkid", (char *)((struct dm_data *)data)->additional_data); } dmuci_set_value_by_section(userclassidclassifier, "userclass", res); break; @@ -984,7 +957,7 @@ static int set_DHCPv6ServerPool_UserClassID(char *refparam, struct dmctx *ctx, v static int get_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *classifier_s = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface); + struct uci_section *classifier_s = get_dhcpv6_classifier("mac", (char *)((struct dm_data *)data)->additional_data); if (classifier_s == NULL) { *value = ""; return 0; @@ -1008,7 +981,7 @@ static int set_DHCPv6ServerPool_SourceAddress(char *refparam, struct dmctx *ctx, static int get_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *classifier_s = get_dhcpv6_classifier("mac", ((struct dhcpv6_args *)data)->interface); + struct uci_section *classifier_s = get_dhcpv6_classifier("mac", (char *)((struct dm_data *)data)->additional_data); if (classifier_s == NULL) { *value = ""; return 0; @@ -1155,29 +1128,30 @@ static int get_DHCPv6ServerPoolClientIPv6Prefix_ValidLifetime(char *refparam, st static int get_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcpv6_client_option_args *dhcpv6_client_s = (struct dhcpv6_client_option_args *)data; - struct uci_list *dhcp_option_list; + struct uci_list *option_list; - dmuci_get_value_by_section_list(dhcpv6_client_s->client_sect, "dhcp_option", &dhcp_option_list); - if (dhcp_option_list != NULL) { + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &option_list); + if (option_list != NULL) { + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; struct uci_element *e = NULL; size_t length; - uci_foreach_element(dhcp_option_list, e) { + uci_foreach_element(option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { *value = "1"; return 0; } } } - *value= "0"; + + *value = "0"; return 0; } static int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_option_args *dhcpv6_client_s = (struct dhcpv6_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; struct uci_list *dhcp_option_list = NULL; char opt_value[128] = {0}; bool option_enabled = false, b; @@ -1189,8 +1163,8 @@ static int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, break; case VALUESET: string_to_bool(value, &b); - dmuci_get_value_by_section_list(dhcpv6_client_s->client_sect, "dhcp_option", &dhcp_option_list); - snprintf(opt_value, sizeof(opt_value), "%s,%s", dhcpv6_client_s->option_tag, dhcpv6_client_s->value); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &dhcp_option_list); + snprintf(opt_value, sizeof(opt_value), "%s,%s", option->tag, option->value); if (dhcp_option_list != NULL) { struct uci_element *e = NULL; @@ -1198,40 +1172,40 @@ static int set_DHCPv6ServerPoolOption_Enable(char *refparam, struct dmctx *ctx, uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { option_enabled = true; if (!b) - dmuci_del_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", opt_value); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", opt_value); break; } } } if(!option_enabled && b) - dmuci_add_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", opt_value); + dmuci_add_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", opt_value); } return 0; } static int get_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return bbf_get_alias(ctx, ((struct dhcpv6_client_option_args *)data)->dmmap_sect, "bbf_dhcpv6_servpool_option_alias", instance, value); + return bbf_get_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv6_servpool_option_alias", instance, value); } static int set_DHCPv6ServerPoolOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return bbf_set_alias(ctx, ((struct dhcpv6_client_option_args *)data)->dmmap_sect, "bbf_dhcpv6_servpool_option_alias", instance, value); + return bbf_set_alias(ctx, ((struct dm_data *)data)->dmmap_section, "bbf_dhcpv6_servpool_option_alias", instance, value); } static int get_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(((struct dhcpv6_client_option_args *)data)->option_tag); + *value = dmstrdup(((struct option_args *)((struct dm_data *)data)->additional_data)->tag); return 0; } static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_option_args *dhcpv6_client_s = (struct dhcpv6_client_option_args *)data; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; struct uci_list *dhcp_option_list = NULL; bool option_enabled = false; @@ -1240,16 +1214,16 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi if (bbfdm_validate_unsignedInt(ctx, value, RANGE_ARGS{{"0","65535"}}, 1)) return FAULT_9007; - if (dhcpv6_client_s->option_tag && DM_STRCMP(dhcpv6_client_s->option_tag, value) == 0) + if (option->tag && DM_STRCMP(option->tag, value) == 0) break; - char *name = section_name(dhcpv6_client_s->client_sect); + char *name = section_name(((struct dm_data *)data)->config_section); if (tag_option_exists("dmmap_dhcpv6", "servpool_option", "section_name", name, "option_tag", value)) return FAULT_9007; break; case VALUESET: - dmuci_get_value_by_section_list(dhcpv6_client_s->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &dhcp_option_list); if (dhcp_option_list != NULL) { struct uci_element *e = NULL; @@ -1257,7 +1231,7 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi uci_foreach_element(dhcp_option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { option_enabled = true; break; } @@ -1267,13 +1241,13 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi if (option_enabled) { char new_tag_value[128] = {0}, old_tag_value[128] = {0}; - snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", dhcpv6_client_s->option_tag, dhcpv6_client_s->value); - snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", value, dhcpv6_client_s->value); - dmuci_del_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", old_tag_value); - dmuci_add_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", new_tag_value); + snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", option->tag, option->value); + snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", value, option->value); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", old_tag_value); + dmuci_add_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", new_tag_value); } - dmuci_set_value_by_section_bbfdm(dhcpv6_client_s->dmmap_sect, "option_tag", value); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_tag", value); break; } return 0; @@ -1281,7 +1255,7 @@ static int set_DHCPv6ServerPoolOption_Tag(char *refparam, struct dmctx *ctx, voi static int get_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - const char *tag_value = ((struct dhcpv6_client_option_args *)data)->value; + const char *tag_value = ((struct option_args *)((struct dm_data *)data)->additional_data)->value; char hex[256] = {0}; if (tag_value && *tag_value) @@ -1293,8 +1267,8 @@ static int get_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcpv6_client_option_args *dhcpv6_client_s = (struct dhcpv6_client_option_args *)data; - struct uci_list *dhcp_option_list = NULL; + struct option_args *option = (struct option_args *)((struct dm_data *)data)->additional_data; + struct uci_list *option_list = NULL; char res[256] = {0}; bool option_enabled = false; @@ -1304,15 +1278,15 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v return FAULT_9007; break; case VALUESET: - dmuci_get_value_by_section_list(dhcpv6_client_s->client_sect, "dhcp_option", &dhcp_option_list); + dmuci_get_value_by_section_list(((struct dm_data *)data)->config_section, "dhcp_option", &option_list); - if (dhcp_option_list != NULL) { + if (option_list != NULL) { struct uci_element *e = NULL; size_t length; - uci_foreach_element(dhcp_option_list, e) { + uci_foreach_element(option_list, e) { char **buf = strsplit(e->name, ",", &length); - if (buf && *buf && DM_STRCMP(buf[0], dhcpv6_client_s->option_tag) == 0) { + if (buf && *buf && DM_STRCMP(buf[0], option->tag) == 0) { option_enabled = true; break; } @@ -1324,13 +1298,13 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v if (option_enabled) { char new_tag_value[512] = {0}, old_tag_value[128] = {0}; - snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", dhcpv6_client_s->option_tag, dhcpv6_client_s->value); - snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", dhcpv6_client_s->option_tag, res); - dmuci_del_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", old_tag_value); - dmuci_add_list_value_by_section(dhcpv6_client_s->client_sect, "dhcp_option", new_tag_value); + snprintf(old_tag_value, sizeof(old_tag_value), "%s,%s", option->tag, option->value); + snprintf(new_tag_value, sizeof(new_tag_value), "%s,%s", option->tag, res); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", old_tag_value); + dmuci_add_list_value_by_section(((struct dm_data *)data)->config_section, "dhcp_option", new_tag_value); } - dmuci_set_value_by_section_bbfdm(dhcpv6_client_s->dmmap_sect, "option_value", res); + dmuci_set_value_by_section_bbfdm(((struct dm_data *)data)->dmmap_section, "option_value", res); break; } return 0; @@ -1341,7 +1315,7 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v *************************************************************/ static int operate_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->iface_s; + struct uci_section *dhcpv6_s = ((struct dm_data *)data)->config_section; if (dhcpv6_s) { char *if_name = section_name(dhcpv6_s); diff --git a/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.c b/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.c index 7ee36249..7840a77e 100644 --- a/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.c +++ b/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.c @@ -117,7 +117,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_iface(char *package, char *v; uci_foreach_option_eq(package, section_type, "proto", proto, s) { - if (strcmp(section_name(s), section_name((struct uci_section *)data)) != 0) + if (strcmp(section_name(s), section_name(((struct dm_data *)data)->config_section)) != 0) continue; // The list snooping_interface and proxy_interface in the uci file corresponds to the @@ -160,7 +160,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package, char *v, *s_name; uci_foreach_option_eq(package, section_type, "proto", proto, s) { - if (strcmp(section_name(s), section_name((struct uci_section *)data)) != 0) + if (strcmp(section_name(s), section_name(((struct dm_data *)data)->config_section)) != 0) continue; /* * create/update corresponding dmmap section that have same config_section link and using param_value_array @@ -296,41 +296,29 @@ void sync_dmmap_bool_to_uci_list(struct uci_section *s, char *section, char *val int del_proxy_obj(void *data, char *proto, unsigned char del_action) { - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - int found = 0; + struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL; switch (del_action) { case DEL_INST: // first delete all filter child nodes related to this object - del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_filter", "section_name", section_name(((struct dm_data *)data)->config_section)); // Now delete all interface child nodes related to this object - del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section)); // Now delete the proxy node - get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name((struct uci_section *)data), &dmmap_section); - dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); break; case DEL_ALL: - uci_foreach_option_eq("mcast", "proxy", "proto", proto, s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(s), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } + uci_foreach_option_eq_safe("mcast", "proxy", "proto", proto, stmp, s) { + get_dmmap_section_of_config_section("dmmap_mcast", "proxy", section_name(s), &dmmap_section); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + + dmuci_delete_by_section(s, NULL, NULL); + } break; } return 0; @@ -338,13 +326,14 @@ int del_proxy_obj(void *data, char *proto, unsigned char del_action) static int add_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char **instance) { - struct uci_section *dmmap = NULL, *s = NULL; + struct uci_section *dmmap = NULL, *s = NULL; char s_name[32]; snprintf(s_name, sizeof(s_name), "igmp_proxy_%s", *instance); dmuci_add_section("mcast", "proxy", &s); dmuci_rename_section_by_section(s, s_name); + dmuci_set_value_by_section(s, "enable", "0"); dmuci_set_value_by_section(s, "proto", "igmp"); dmuci_set_value_by_section(s, "last_member_query_interval", "10"); @@ -368,16 +357,16 @@ static int del_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, cha static int browse_igmp_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - char *inst = NULL; - struct dmmap_dup *p = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); + char *inst = NULL; synchronize_specific_config_sections_with_dmmap_cont("mcast", "proxy", "dmmap_mcast", "proto", "igmp", &dup_list); - list_for_each_entry(p, &dup_list, list) { + list_for_each_entry(curr_data, &dup_list, list) { - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "proxy_instance", "proxy_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "proxy_instance", "proxy_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } @@ -394,6 +383,7 @@ static int add_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data, dmuci_add_section("mcast", "snooping", &s); dmuci_rename_section_by_section(s, s_name); + dmuci_set_value_by_section(s, "enable", "0"); dmuci_set_value_by_section(s, "proto", "igmp"); dmuci_set_value_by_section(s, "last_member_query_interval", "10"); @@ -411,40 +401,28 @@ static int add_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data, int del_snooping_obj(void *data, char *proto, unsigned char del_action) { - struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL; - int found = 0; + struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL; switch (del_action) { case DEL_INST: // first delete all filter child nodes related to this object - del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter", "section_name", section_name(((struct dm_data *)data)->config_section)); // Now delete all interface child nodes related to this object - del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_interface", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_interface", "section_name", section_name(((struct dm_data *)data)->config_section)); - get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name((struct uci_section *)data), &dmmap_section); - dmuci_delete_by_section(dmmap_section, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); - dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); break; case DEL_ALL: - uci_foreach_option_eq("mcast", "snooping", "proto", proto, s) { - if (found != 0) { - get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name(s), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; - } - if (ss != NULL) { - get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name(ss), &dmmap_section); - if (dmmap_section != NULL) - dmuci_delete_by_section(dmmap_section, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } + uci_foreach_option_eq_safe("mcast", "snooping", "proto", proto, stmp, s) { + get_dmmap_section_of_config_section("dmmap_mcast", "snooping", section_name(s), &dmmap_section); + dmuci_delete_by_section(dmmap_section, NULL, NULL); + + dmuci_delete_by_section(s, NULL, NULL); + } break; } return 0; @@ -457,16 +435,16 @@ static int del_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data, static int browse_igmp_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - char *inst = NULL; - struct dmmap_dup *p = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); + char *inst = NULL; synchronize_specific_config_sections_with_dmmap_cont("mcast", "snooping", "dmmap_mcast", "proto", "igmp", &dup_list); - list_for_each_entry(p, &dup_list, list) { + list_for_each_entry(curr_data, &dup_list, list) { - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "snooping_instance", "snooping_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "snooping_instance", "snooping_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } free_dmmap_config_dup_list(&dup_list); @@ -475,44 +453,37 @@ static int browse_igmp_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, v static int get_igmps_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_option_eq("mcast", "snooping", "proto", "igmp", s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_igmp_snooping_inst); dmasprintf(value, "%d", cnt); return 0; } static int get_igmpp_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_option_eq("mcast", "proxy", "proto", "igmp", s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_igmp_proxy_inst); dmasprintf(value, "%d", cnt); return 0; } static int browse_igmp_cgrp_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - //perform ubus call to mcast stats and browse through each igmp group json object - json_object *res = NULL, *jobj = NULL, *arrobj = NULL, *group_obj = NULL; - char *inst = NULL; + json_object *res = NULL; dmubus_call("mcast", "stats", UBUS_ARGS{0}, 0, &res); if (res) { + json_object *jobj = NULL, *arrobj = NULL, *group_obj = NULL; + struct dm_data curr_data = {0}; + char *inst = NULL; int i = 0, id = 0; jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "snooping"); dmjson_foreach_obj_in_array(jobj, arrobj, group_obj, i, 1, "groups") { + + curr_data.json_object = group_obj; + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)group_obj, inst) == DM_STOP) + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } } @@ -524,7 +495,7 @@ static int add_igmps_filter_obj(char *refparam, struct dmctx *ctx, void *data, c struct uci_section *dmmap_igmps_filter = NULL; dmuci_add_section_bbfdm("dmmap_mcast", "snooping_filter", &dmmap_igmps_filter); - dmuci_set_value_by_section(dmmap_igmps_filter, "section_name", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_igmps_filter, "section_name", section_name(((struct dm_data *)data)->config_section)); dmuci_set_value_by_section(dmmap_igmps_filter, "enable", "0"); dmuci_set_value_by_section(dmmap_igmps_filter, "filter_instance", *instance); return 0; @@ -539,7 +510,7 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i switch (del_action) { case DEL_INST: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { @@ -549,7 +520,7 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i } if (found) { - dmuci_del_list_value_by_section((struct uci_section *)data, "filter", ip_addr); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "filter", ip_addr); break; } } @@ -557,14 +528,14 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i break; case DEL_ALL: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr); if (ip_addr[0] != '\0') { - dmuci_del_list_value_by_section((struct uci_section *)data, "filter", ip_addr); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "filter", ip_addr); } } - del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "snooping_filter", "section_name", section_name(((struct dm_data *)data)->config_section)); break; } @@ -573,18 +544,16 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i int browse_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *section_type, char *option_name, char *option_value) { - struct dmmap_dup *p = NULL; - char *inst = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); + char *inst = NULL; synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", section_type, prev_data, "dmmap_mcast", option_name, option_value, &dup_list); - list_for_each_entry(p, &dup_list, list) { - if (!p->config_section) - break; + list_for_each_entry(curr_data, &dup_list, list) { - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "filter_instance", "filter_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "filter_instance", "filter_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } @@ -599,32 +568,14 @@ static int browse_igmps_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, vo int get_mcasts_filter_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", "section_name", - section_name((struct uci_section *)data), s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_mlds_filter_inst); dmasprintf(value, "%d", cnt); return 0; } static int get_igmp_cgrps_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - int cnt = 0; - json_object *res = NULL, *jobj = NULL, *arrobj = NULL, *group_obj = NULL; - - dmubus_call("mcast", "stats", UBUS_ARGS{0}, 0, &res); - if (res) { - int i = 0; - - jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "snooping"); - dmjson_foreach_obj_in_array(jobj, arrobj, group_obj, i, 1, "groups") { - cnt++; - } - } + int cnt = get_number_of_entries(ctx, data, instance, browse_igmp_cgrp_inst); dmasprintf(value, "%d", cnt); return 0; } @@ -635,7 +586,7 @@ int get_mcasts_filter_enable(char *refparam, struct dmctx *ctx, void *data, char char *f_inst, *f_enable = NULL; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", - "section_name", section_name((struct uci_section *)data), f_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), f_sec) { dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "enable", &f_enable); @@ -665,13 +616,13 @@ int set_mcasts_filter_enable(char *refparam, struct dmctx *ctx, void *data, char case VALUESET: string_to_bool(value, &b); uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", - "section_name", section_name((struct uci_section *)data), f_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), f_sec) { dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "ipaddr", &ip_addr); dmuci_set_value_by_section(f_sec, "enable", (b) ? "1" : "0"); if (ip_addr[0] != '\0') { - sync_dmmap_bool_to_uci_list((struct uci_section *)data, + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "filter", ip_addr, b); } break; @@ -689,7 +640,7 @@ int get_mcasts_filter_address(char *refparam, struct dmctx *ctx, void *data, cha char *f_inst, *ip_addr = NULL; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr); @@ -720,13 +671,13 @@ int set_mcasts_filter_address(char *refparam, struct dmctx *ctx, void *data, cha break; case VALUESET: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "snooping_filter", - "section_name", section_name((struct uci_section *)data), s) { + "section_name", section_name(((struct dm_data *)data)->config_section), s) { dmuci_get_value_by_section_string(s, "filter_instance", &s_inst); if (DM_STRCMP(s_inst, instance) == 0) { dmuci_set_value_by_section(s, "ipaddr", value); dmuci_get_value_by_section_string(s, "enable", &up); string_to_bool(up, &b); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "filter", value, b); break; } @@ -740,7 +691,7 @@ int set_mcasts_filter_address(char *refparam, struct dmctx *ctx, void *data, cha int get_mcast_snooping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enable", "0"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "enable", "0"); return 0; } @@ -755,7 +706,7 @@ int set_mcast_snooping_enable(char *refparam, struct dmctx *ctx, void *data, cha break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enable", (b) ? "1" : "0"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "enable", (b) ? "1" : "0"); break; } @@ -765,7 +716,7 @@ int set_mcast_snooping_enable(char *refparam, struct dmctx *ctx, void *data, cha static int get_igmp_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "version", &val); *value = (DM_LSTRCMP(val, "3") == 0) ? "V3" : "V2"; return 0; } @@ -778,7 +729,7 @@ static int set_igmp_version(char *refparam, struct dmctx *ctx, void *data, char return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "version", (DM_LSTRCMP(value, "V2") == 0) ? "2" : "3"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "version", (DM_LSTRCMP(value, "V2") == 0) ? "2" : "3"); break; } @@ -788,7 +739,7 @@ static int set_igmp_version(char *refparam, struct dmctx *ctx, void *data, char int get_mcast_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "snooping_mode", &val); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "snooping_mode", &val); if (DM_LSTRCMP(val, "1") == 0) *value = "Standard"; @@ -819,7 +770,7 @@ int set_mcast_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char else DM_STRNCPY(val, "0", sizeof(val)); - dmuci_set_value_by_section((struct uci_section *)data, "snooping_mode", val); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "snooping_mode", val); break; } @@ -828,7 +779,7 @@ int set_mcast_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char int get_mcasts_last_mq_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "last_member_query_interval", "10"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "last_member_query_interval", "10"); return 0; } @@ -840,7 +791,7 @@ int set_mcasts_last_mq_interval(char *refparam, struct dmctx *ctx, void *data, c return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "last_member_query_interval", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "last_member_query_interval", value); break; } @@ -849,7 +800,7 @@ int set_mcasts_last_mq_interval(char *refparam, struct dmctx *ctx, void *data, c int get_mcasts_fast_leave(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "fast_leave", "1"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "fast_leave", "1"); return 0; } @@ -864,7 +815,7 @@ int set_mcasts_fast_leave(char *refparam, struct dmctx *ctx, void *data, char *i break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "fast_leave", (b) ? "1" : "0"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "fast_leave", (b) ? "1" : "0"); break; } @@ -873,7 +824,7 @@ int set_mcasts_fast_leave(char *refparam, struct dmctx *ctx, void *data, char *i int get_mcast_snooping_robustness(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "robustness", "2"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "robustness", "2"); return 0; } @@ -886,7 +837,7 @@ int set_mcast_snooping_robustness(char *refparam, struct dmctx *ctx, void *data, return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "robustness", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "robustness", value); break; } @@ -895,7 +846,7 @@ int set_mcast_snooping_robustness(char *refparam, struct dmctx *ctx, void *data, int get_mcast_snooping_aggregation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "aggregation", "1"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "aggregation", "1"); return 0; } @@ -910,7 +861,7 @@ int set_mcast_snooping_aggregation(char *refparam, struct dmctx *ctx, void *data break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "aggregation", (b) ? "1" : "0"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "aggregation", (b) ? "1" : "0"); break; } @@ -922,7 +873,7 @@ int get_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char val[16] = {0}; // taking 16 here is same as that is size of linux names usually supported char *val1; - dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &val1); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "interface", &val1); // The value is linux interface name so it would be br-wan for example, but the network // section would be wan, so extract wan from br-wan @@ -958,7 +909,7 @@ int set_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data, if (get_mcast_snooping_interface_val(&reference, ifname, sizeof(ifname)) != 0) return -1; - dmuci_set_value_by_section((struct uci_section *)data, "interface", ifname); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "interface", ifname); break; } @@ -970,7 +921,7 @@ static int add_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data struct uci_section *dmmap_igmpp_interface = NULL; dmuci_add_section_bbfdm("dmmap_mcast", "proxy_interface", &dmmap_igmpp_interface); - dmuci_set_value_by_section(dmmap_igmpp_interface, "section_name", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_igmpp_interface, "section_name", section_name(((struct dm_data *)data)->config_section)); dmuci_set_value_by_section(dmmap_igmpp_interface, "upstream", "0"); dmuci_set_value_by_section(dmmap_igmpp_interface, "snooping_mode", "0"); dmuci_set_value_by_section(dmmap_igmpp_interface, "iface_instance", *instance); @@ -996,10 +947,10 @@ static void get_igmpp_iface_del_key_val(char *key, size_t key_size, char *if_nam static void del_igmpp_iface_val(char *upstream, void *data, char *pch) { if (DM_LSTRCMP(upstream, "1") == 0) { - dmuci_del_list_value_by_section((struct uci_section *)data, + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "upstream_interface", pch); } else { - dmuci_del_list_value_by_section((struct uci_section *)data, + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "downstream_interface", pch); } } @@ -1010,7 +961,7 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data switch (del_action) { case DEL_INST: - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section), igmpp_s) { char *f_inst = NULL, *if_name = NULL, *upstream = NULL; int found = 0; @@ -1041,7 +992,7 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data } break; case DEL_ALL: - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section), igmpp_s) { char *if_name = NULL, *upstream = NULL; dmuci_get_value_by_section_string(igmpp_s, "ifname", &if_name); @@ -1060,7 +1011,7 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data } } - del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section)); break; } @@ -1069,18 +1020,16 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data int browse_proxy_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *proto) { - struct dmmap_dup *p = NULL; - char *inst = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); + char *inst = NULL; synchronize_specific_config_sections_with_dmmap_mcast_iface("mcast", "proxy", prev_data, "dmmap_mcast", "proxy_interface", proto, &dup_list); - list_for_each_entry(p, &dup_list, list) { - if (!p->config_section) - break; + list_for_each_entry(curr_data, &dup_list, list) { - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "iface_instance", "iface_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "iface_instance", "iface_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } @@ -1098,7 +1047,7 @@ static int add_igmpp_filter_obj(char *refparam, struct dmctx *ctx, void *data, c struct uci_section *dmmap_igmpp_filter = NULL; dmuci_add_section_bbfdm("dmmap_mcast", "proxy_filter", &dmmap_igmpp_filter); - dmuci_set_value_by_section(dmmap_igmpp_filter, "section_name", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_igmpp_filter, "section_name", section_name(((struct dm_data *)data)->config_section)); dmuci_set_value_by_section(dmmap_igmpp_filter, "enable", "0"); dmuci_set_value_by_section(dmmap_igmpp_filter, "filter_instance", *instance); return 0; @@ -1113,7 +1062,7 @@ int del_mcastp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i switch (del_action) { case DEL_INST: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { @@ -1123,7 +1072,7 @@ int del_mcastp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i } if (found) { - dmuci_del_list_value_by_section((struct uci_section *)data, + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "filter", ip_addr); break; } @@ -1132,15 +1081,15 @@ int del_mcastp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i break; case DEL_ALL: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "ipaddr", &ip_addr); if (ip_addr[0] != '\0') - dmuci_del_list_value_by_section((struct uci_section *)data, + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "filter", ip_addr); } del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_filter", "section_name", - section_name((struct uci_section *)data)); + section_name(((struct dm_data *)data)->config_section)); break; } @@ -1155,14 +1104,7 @@ static int browse_igmpp_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, vo int get_mcastp_interface_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", - section_name((struct uci_section *)data), s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_mldp_interface_inst); dmasprintf(value, "%d", cnt); return 0; } @@ -1173,7 +1115,7 @@ int get_mcastp_filter_enable(char *refparam, struct dmctx *ctx, void *data, char char *f_inst, *f_enable = NULL; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", - "section_name", section_name((struct uci_section *)data), f_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), f_sec) { dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "enable", &f_enable); @@ -1203,12 +1145,12 @@ int set_mcastp_filter_enable(char *refparam, struct dmctx *ctx, void *data, char case VALUESET: string_to_bool(value, &b); uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", - "section_name", section_name((struct uci_section *)data), f_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), f_sec) { dmuci_get_value_by_section_string(f_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(f_sec, "ipaddr", &ip_addr); dmuci_set_value_by_section(f_sec, "enable", (b) ? "1" : "0"); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "filter", ip_addr, b); break; } @@ -1225,7 +1167,7 @@ int get_mcastp_filter_address(char *refparam, struct dmctx *ctx, void *data, cha char *f_inst; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "filter_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ipaddr", value); @@ -1248,13 +1190,13 @@ static int set_igmpp_filter_address(char *refparam, struct dmctx *ctx, void *dat return FAULT_9007; break; case VALUESET: - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", section_name((struct uci_section *)data), igmp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", section_name(((struct dm_data *)data)->config_section), igmp_s) { dmuci_get_value_by_section_string(igmp_s, "filter_instance", &s_inst); if (DM_STRCMP(s_inst, instance) == 0) { dmuci_set_value_by_section(igmp_s, "ipaddr", value); dmuci_get_value_by_section_string(igmp_s, "enable", &up); string_to_bool(up, &b); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, "filter", value, b); + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "filter", value, b); break; } } @@ -1266,15 +1208,18 @@ static int set_igmpp_filter_address(char *refparam, struct dmctx *ctx, void *dat static int browse_igmp_cgrp_assoc_dev_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - //parse and browse through prev_data(it will be json object containing group address and details of its clients) - - int i = 0, id = 0; json_object *arrobj = NULL, *client_jobj = NULL; + struct dm_data curr_data = {0}; char *inst = NULL; + int i = 0, id = 0; + + dmjson_foreach_obj_in_array(((struct dm_data *)prev_data)->json_object, arrobj, client_jobj, i, 1, "clients") { + + curr_data.json_object = client_jobj; - dmjson_foreach_obj_in_array((struct json_object *)prev_data, arrobj, client_jobj, i, 1, "clients") { inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)client_jobj, inst) == DM_STOP) + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_data, inst) == DM_STOP) break; } return 0; @@ -1296,32 +1241,27 @@ static int browse_igmpp_cgrp_stats_inst(struct dmctx *dmctx, DMNODE *parent_node static int get_igmp_cgrp_gaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "groupaddr"); + *value = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "groupaddr"); return 0; } static int get_igmp_cgrp_assoc_dev_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - int i = 0, cnt = 0; - json_object *arrobj = NULL, *client_obj = NULL; - - dmjson_foreach_obj_in_array((json_object *)data, arrobj, client_obj, i, 1, "clients") { - cnt++; - } + int cnt = get_number_of_entries(ctx, data, instance, browse_igmp_cgrp_assoc_dev_inst); dmasprintf(value, "%d", cnt); return 0; } static int get_igmp_cgrp_adev_iface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *ifname = dmjson_get_value((json_object *)data, 1, "device"); + char *ifname = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "device"); adm_entry_get_reference_param(ctx, "Device.Ethernet.Interface.*.Name", ifname, value); return 0; } static int get_igmp_cgrp_adev_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *ipaddr = dmjson_get_value((json_object *)data, 1, "ipaddr"); + char *ipaddr = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "ipaddr"); char *linker = get_host_linker(ipaddr); adm_entry_get_reference_param(ctx, "Device.Hosts.Host.*.PhysAddress", linker, value); @@ -1330,7 +1270,7 @@ static int get_igmp_cgrp_adev_host(char *refparam, struct dmctx *ctx, void *data static int get_igmp_cgrp_adev_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value((json_object *)data, 1, "timeout"); + *value = dmjson_get_value(((struct dm_data *)data)->json_object, 1, "timeout"); return 0; } @@ -1410,7 +1350,7 @@ static int get_igmpp_cgrp_stats_lrcvd(char *refparam, struct dmctx *ctx, void *d int get_mcast_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enable", "0"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "enable", "0"); return 0; } int set_mcast_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) @@ -1424,7 +1364,7 @@ int set_mcast_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char * break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "enable", (b) ? "1" : "0"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "enable", (b) ? "1" : "0"); break; } @@ -1433,25 +1373,25 @@ int set_mcast_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char * int get_mcast_proxy_robustness(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "robustness", "2"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "robustness", "2"); return 0; } int get_mcastp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "query_interval", "125"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "query_interval", "125"); return 0; } int get_mcastp_q_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "query_response_interval", "100"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "query_response_interval", "100"); return 0; } int get_mcastp_last_mq_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "last_member_query_interval", "10"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "last_member_query_interval", "10"); return 0; } @@ -1463,7 +1403,7 @@ int set_mcastp_query_interval(char *refparam, struct dmctx *ctx, void *data, cha return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "query_interval", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "query_interval", value); break; } @@ -1479,7 +1419,7 @@ int set_mcastp_q_response_interval(char *refparam, struct dmctx *ctx, void *data return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "query_response_interval", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "query_response_interval", value); break; } @@ -1495,7 +1435,7 @@ int set_mcastp_last_mq_interval(char *refparam, struct dmctx *ctx, void *data, c return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "last_member_query_interval", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "last_member_query_interval", value); break; } @@ -1511,7 +1451,7 @@ int set_mcast_proxy_robustness(char *refparam, struct dmctx *ctx, void *data, ch return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "robustness", value); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "robustness", value); break; } @@ -1520,13 +1460,13 @@ int set_mcast_proxy_robustness(char *refparam, struct dmctx *ctx, void *data, ch int get_mcast_proxy_aggregation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "aggregation", "1"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "aggregation", "1"); return 0; } int get_mcast_proxy_fast_leave(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "fast_leave", "1"); + *value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "fast_leave", "1"); return 0; } @@ -1541,7 +1481,7 @@ int set_mcast_proxy_fast_leave(char *refparam, struct dmctx *ctx, void *data, ch break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "fast_leave", (b) ? "1" : "0"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "fast_leave", (b) ? "1" : "0"); break; } @@ -1559,7 +1499,7 @@ int set_mcast_proxy_aggregation(char *refparam, struct dmctx *ctx, void *data, c break; case VALUESET: string_to_bool(value, &b); - dmuci_set_value_by_section((struct uci_section *)data, "aggregation", (b) ? "1" : "0"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "aggregation", (b) ? "1" : "0"); break; } @@ -1568,14 +1508,7 @@ int set_mcast_proxy_aggregation(char *refparam, struct dmctx *ctx, void *data, c int get_mcastp_filter_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", "section_name", - section_name((struct uci_section *)data), s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_mldp_filter_inst); dmasprintf(value, "%d", cnt); return 0; } @@ -1675,7 +1608,7 @@ static void set_igmpp_iface_val(void *data, char *instance, char *linker, char * bool b, is_bridge_interface = false; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { @@ -1708,16 +1641,16 @@ static void set_igmpp_iface_val(void *data, char *instance, char *linker, char * // Delete the previous upstream_interface/downstream_interface from the uci // file as it is updated in dmmap file, and will be updated after sync in // sync_proxy_interface_sections function - dmuci_del_list_value_by_section((struct uci_section *)data, + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, (b) ? "upstream_interface" : "downstream_interface" , device_name); - sync_proxy_interface_sections((struct uci_section *)data, + sync_proxy_interface_sections(((struct dm_data *)data)->config_section, "downstream_interface", interface_linker, !b); // Now update the proxy_interface list - sync_proxy_interface_sections((struct uci_section *)data, + sync_proxy_interface_sections(((struct dm_data *)data)->config_section, "upstream_interface", interface_linker, b); - update_snooping_mode((struct uci_section *)data); + update_snooping_mode(((struct dm_data *)data)->config_section); break; } } @@ -1785,7 +1718,7 @@ static int get_igmpp_interface_iface(char *refparam, struct dmctx *ctx, void *da char sec_name[16] = {0}; int found = 0; - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), igmpp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section), igmpp_s) { dmuci_get_value_by_section_string(igmpp_s, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(igmpp_s, "ifname", &igmpp_ifname); @@ -1853,7 +1786,7 @@ static int set_igmpp_interface_upstream(char *refparam, struct dmctx *ctx, void case VALUESET: string_to_bool(value, &b); uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { // The interface is a part of downstream or upstream list in the @@ -1878,9 +1811,9 @@ static int set_igmpp_interface_upstream(char *refparam, struct dmctx *ctx, void } dmuci_set_value_by_section(d_sec, "upstream", (b) ? "1" : "0"); - sync_proxy_interface_sections((struct uci_section *)data, "downstream_interface", key, !b); - sync_proxy_interface_sections((struct uci_section *)data, "upstream_interface", key, b); - update_snooping_mode((struct uci_section *)data); + sync_proxy_interface_sections(((struct dm_data *)data)->config_section, "downstream_interface", key, !b); + sync_proxy_interface_sections(((struct dm_data *)data)->config_section, "upstream_interface", key, b); + update_snooping_mode(((struct dm_data *)data)->config_section); break; } @@ -1898,7 +1831,7 @@ int get_mcastp_interface_upstream(char *refparam, struct dmctx *ctx, void *data, char *f_inst, *up = NULL; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "upstream", &up); @@ -1916,7 +1849,7 @@ int get_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, c char *f_inst, *val = NULL; uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "snooping_mode", &val); @@ -1957,7 +1890,7 @@ int set_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, c strcpy(val, "0"); uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "upstream", &up); @@ -1965,7 +1898,7 @@ int set_mcastp_iface_snoop_mode(char *refparam, struct dmctx *ctx, void *data, c string_to_bool(up, &b); if (!b) { - dmuci_set_value_by_section((struct uci_section *)data, "snooping_mode", val); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "snooping_mode", val); } break; } diff --git a/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.h b/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.h index 1f74faf2..33d3a9e9 100644 --- a/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.h +++ b/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_igmp.h @@ -95,5 +95,8 @@ void synchronize_specific_config_sections_with_dmmap_mcast_iface(char *package, void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package, char *section_type, void *data, char *dmmap_package, char *dmmap_sec, char *proto, struct list_head *dup_list); +int browse_mlds_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browse_mldp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browse_mldp_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); #endif //__IOPSYS_IGMP_H diff --git a/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_mld.c b/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_mld.c index b6dba18f..0e98e994 100644 --- a/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_mld.c +++ b/libbbfdm/dmtree/vendor/iopsys/x_iopsys_eu_mld.c @@ -21,11 +21,12 @@ static int add_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char dmuci_add_section("mcast", "proxy", &s); dmuci_rename_section_by_section(s, s_name); + dmuci_set_value_by_section(s, "enable", "0"); dmuci_set_value_by_section(s, "proto", "mld"); dmuci_set_value_by_section(s, "last_member_query_interval", "10"); - dmuci_set_value_by_section(s, "query_interval", "125"); - dmuci_set_value_by_section(s, "query_response_interval", "100"); + dmuci_set_value_by_section(s, "query_interval", "125"); + dmuci_set_value_by_section(s, "query_response_interval", "100"); dmuci_set_value_by_section(s, "version", "2"); dmuci_set_value_by_section(s, "robustness", "2"); dmuci_set_value_by_section(s, "aggregation", "0"); @@ -44,16 +45,16 @@ static int del_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char static int browse_mld_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - char *inst = NULL; - struct dmmap_dup *p = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); + char *inst = NULL; synchronize_specific_config_sections_with_dmmap_cont("mcast", "proxy", "dmmap_mcast", "proto", "mld", &dup_list); - list_for_each_entry(p, &dup_list, list) { + list_for_each_entry(curr_data, &dup_list, list) { - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "proxy_instance", "proxy_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "proxy_instance", "proxy_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } @@ -63,13 +64,14 @@ static int browse_mld_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void static int add_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, char **instance) { - struct uci_section *dmmap = NULL, *s = NULL; + struct uci_section *dmmap = NULL, *s = NULL; char s_name[32]; snprintf(s_name, sizeof(s_name), "mld_snoop_%s", *instance); dmuci_add_section("mcast", "snooping", &s); dmuci_rename_section_by_section(s, s_name); + dmuci_set_value_by_section(s, "enable", "0"); dmuci_set_value_by_section(s, "proto", "mld"); dmuci_set_value_by_section(s, "last_member_query_interval", "10"); @@ -92,16 +94,16 @@ static int del_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, c static int browse_mld_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - char *inst = NULL; - struct dmmap_dup *p = NULL; + struct dm_data *curr_data = NULL; LIST_HEAD(dup_list); + char *inst = NULL; synchronize_specific_config_sections_with_dmmap_cont("mcast", "snooping", "dmmap_mcast", "proto", "mld", &dup_list); - list_for_each_entry(p, &dup_list, list) { + list_for_each_entry(curr_data, &dup_list, list) { - inst = handle_instance(dmctx, parent_node, p->dmmap_section, "snooping_instance", "snooping_alias"); + inst = handle_instance(dmctx, parent_node, curr_data->dmmap_section, "snooping_instance", "snooping_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP) + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_data, inst) == DM_STOP) break; } free_dmmap_config_dup_list(&dup_list); @@ -110,26 +112,14 @@ static int browse_mld_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, vo static int get_mlds_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_option_eq("mcast", "snooping", "proto", "mld", s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_mld_snooping_inst); dmasprintf(value, "%d", cnt); return 0; } static int get_mldp_no_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct uci_section *s = NULL; - int cnt = 0; - - uci_foreach_option_eq("mcast", "proxy", "proto", "mld", s) { - cnt++; - } - + int cnt = get_number_of_entries(ctx, data, instance, browse_mld_proxy_inst); dmasprintf(value, "%d", cnt); return 0; } @@ -153,13 +143,13 @@ static int add_mlds_filter_obj(char *refparam, struct dmctx *ctx, void *data, ch struct uci_section *dmmap_mlds_filter = NULL; dmuci_add_section_bbfdm("dmmap_mcast", "snooping_filter", &dmmap_mlds_filter); - dmuci_set_value_by_section(dmmap_mlds_filter, "section_name", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_mlds_filter, "section_name", section_name(((struct dm_data *)data)->config_section)); dmuci_set_value_by_section(dmmap_mlds_filter, "enable", "0"); dmuci_set_value_by_section(dmmap_mlds_filter, "filter_instance", *instance); return 0; } -static int browse_mlds_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +int browse_mlds_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { return browse_filter_inst(dmctx, parent_node, prev_data, "snooping", "snooping_filter", "mld"); } @@ -167,7 +157,7 @@ static int browse_mlds_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, voi static int get_mld_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val; - dmuci_get_value_by_section_string((struct uci_section *)data, "version", &val); + dmuci_get_value_by_section_string(((struct dm_data *)data)->config_section, "version", &val); *value = (DM_LSTRCMP(val, "1") == 0) ? "V1" : "V2"; return 0; } @@ -180,7 +170,7 @@ static int set_mld_version(char *refparam, struct dmctx *ctx, void *data, char * return FAULT_9007; break; case VALUESET: - dmuci_set_value_by_section((struct uci_section *)data, "version", (DM_LSTRCMP(value, "V2") == 0) ? "2" : "1"); + dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "version", (DM_LSTRCMP(value, "V2") == 0) ? "2" : "1"); break; } @@ -192,7 +182,7 @@ static int add_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, struct uci_section *dmmap_mldp_interface = NULL; dmuci_add_section_bbfdm("dmmap_mcast", "proxy_interface", &dmmap_mldp_interface); - dmuci_set_value_by_section(dmmap_mldp_interface, "section_name", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_mldp_interface, "section_name", section_name(((struct dm_data *)data)->config_section)); dmuci_set_value_by_section(dmmap_mldp_interface, "upstream", "0"); dmuci_set_value_by_section(dmmap_mldp_interface, "snooping_mode", "0"); dmuci_set_value_by_section(dmmap_mldp_interface, "iface_instance", *instance); @@ -205,7 +195,7 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, switch (del_action) { case DEL_INST: - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section), mldp_s) { char *f_inst = NULL, *if_name = NULL, *upstream = NULL; int found = 0; @@ -220,16 +210,16 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, if (found) { if (upstream && DM_LSTRCMP(upstream, "1") == 0) - dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", if_name); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "upstream_interface", if_name); else - dmuci_del_list_value_by_section((struct uci_section *)data, "downstream_interface", if_name); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "downstream_interface", if_name); break; } } break; case DEL_ALL: - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section), mldp_s) { char *if_name = NULL, *upstream = NULL; dmuci_get_value_by_section_string(mldp_s, "ifname", &if_name); @@ -237,20 +227,20 @@ static int del_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, if (if_name[0] != '\0') { if (DM_LSTRCMP(upstream, "1") == 0) - dmuci_del_list_value_by_section((struct uci_section *)data, "upstream_interface", if_name); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "upstream_interface", if_name); else - dmuci_del_list_value_by_section((struct uci_section *)data, "downstream_interface", if_name); + dmuci_del_list_value_by_section(((struct dm_data *)data)->config_section, "downstream_interface", if_name); } } - del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data)); + del_dmmap_sec_with_opt_eq("dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section)); break; } return 0; } -static int browse_mldp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +int browse_mldp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { return browse_proxy_interface_inst(dmctx, parent_node, prev_data, "mld"); } @@ -260,13 +250,13 @@ static int add_mldp_filter_obj(char *refparam, struct dmctx *ctx, void *data, ch struct uci_section *dmmap_mldp_filter = NULL; dmuci_add_section_bbfdm("dmmap_mcast", "proxy_filter", &dmmap_mldp_filter); - dmuci_set_value_by_section(dmmap_mldp_filter, "section_name", section_name((struct uci_section *)data)); + dmuci_set_value_by_section(dmmap_mldp_filter, "section_name", section_name(((struct dm_data *)data)->config_section)); dmuci_set_value_by_section(dmmap_mldp_filter, "enable", "0"); dmuci_set_value_by_section(dmmap_mldp_filter, "filter_instance", *instance); return 0; } -static int browse_mldp_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +int browse_mldp_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { return browse_filter_inst(dmctx, parent_node, prev_data, "proxy", "proxy_filter", "mld"); } @@ -284,13 +274,13 @@ static int set_mldp_filter_address(char *refparam, struct dmctx *ctx, void *data break; case VALUESET: uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_filter", - "section_name", section_name((struct uci_section *)data), s) { + "section_name", section_name(((struct dm_data *)data)->config_section), s) { dmuci_get_value_by_section_string(s, "filter_instance", &s_inst); if (DM_STRCMP(s_inst, instance) == 0) { dmuci_set_value_by_section(s, "ipaddr", value); dmuci_get_value_by_section_string(s, "enable", &up); string_to_bool(up, &b); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, "filter", value, b); + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "filter", value, b); break; } } @@ -477,17 +467,17 @@ static int set_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat } uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_set_value_by_section(d_sec, "ifname", interface_linker); dmuci_get_value_by_section_string(d_sec, "upstream", &up); string_to_bool(up, &b); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, "downstream_interface", interface_linker, !b); + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "downstream_interface", interface_linker, !b); // Now update the proxy_interface list - sync_dmmap_bool_to_uci_list((struct uci_section *)data, "upstream_interface", interface_linker, b); - update_snooping_mode((struct uci_section *)data); + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "upstream_interface", interface_linker, b); + update_snooping_mode(((struct dm_data *)data)->config_section); break; } } @@ -505,7 +495,7 @@ static int get_mldp_interface_iface(char *refparam, struct dmctx *ctx, void *dat char sec_name[16] = {0}; int found = 0; - uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name((struct uci_section *)data), mldp_s) { + uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", "section_name", section_name(((struct dm_data *)data)->config_section), mldp_s) { dmuci_get_value_by_section_string(mldp_s, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(mldp_s, "ifname", &mldp_ifname); @@ -581,15 +571,15 @@ static int set_mldp_interface_upstream(char *refparam, struct dmctx *ctx, void * case VALUESET: string_to_bool(value, &b); uci_path_foreach_option_eq(bbfdm, "dmmap_mcast", "proxy_interface", - "section_name", section_name((struct uci_section *)data), d_sec) { + "section_name", section_name(((struct dm_data *)data)->config_section), d_sec) { dmuci_get_value_by_section_string(d_sec, "iface_instance", &f_inst); if (DM_STRCMP(instance, f_inst) == 0) { dmuci_get_value_by_section_string(d_sec, "ifname", &ifname); dmuci_set_value_by_section(d_sec, "upstream", (b) ? "1" : "0"); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, "downstream_interface", ifname, !b); - sync_dmmap_bool_to_uci_list((struct uci_section *)data, "upstream_interface", ifname, b); - update_snooping_mode((struct uci_section *)data); + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "downstream_interface", ifname, !b); + sync_dmmap_bool_to_uci_list(((struct dm_data *)data)->config_section, "upstream_interface", ifname, b); + update_snooping_mode(((struct dm_data *)data)->config_section); break; }