From d9fd9d04ae77b0a8cd546a9eec3b27a1295a11aa Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Mon, 19 Feb 2024 14:19:46 +0000 Subject: [PATCH] libbbfdm: handled dhcp option tag value (cherry picked from commit 3bdad6b0ce22be0b17f5b757568a09eb072e3cd6) --- libbbfdm/dmtree/tr181/dhcpv4.c | 76 +++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/libbbfdm/dmtree/tr181/dhcpv4.c b/libbbfdm/dmtree/tr181/dhcpv4.c index 5a8b8369..2861bdb7 100644 --- a/libbbfdm/dmtree/tr181/dhcpv4.c +++ b/libbbfdm/dmtree/tr181/dhcpv4.c @@ -865,59 +865,77 @@ static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *p 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; + char *p = NULL; while (fgets(line, sizeof(line), f) != NULL) { remove_new_line(line); - - sscanf(line, "%23s vcid=%127s clid=%127s ucid=%127s hostname=%127s paramlist=%255s", - macaddr, vcid, clid, ucid, hostname, paramlist); + sscanf(line, "%23s ", macaddr); if (DM_STRNCMP(macaddr, (char *)args->lease->hwaddr, 24) == 0) { + p = DM_STRSTR(line, "vcid="); + if (p) { + sscanf(p, "vcid=%127s ", vcid); + if (DM_LSTRCMP(vcid, "-") != 0) { + init_client_options_args(&curr_client_options_args, "60", dmstrdup(vcid)); - if (DM_LSTRCMP(vcid, "-") != 0) { - init_client_options_args(&curr_client_options_args, "60", dmstrdup(vcid)); + inst = handle_instance_without_section(dmctx, parent_node, ++id); - inst = handle_instance_without_section(dmctx, parent_node, ++id); - - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) - break; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) + break; + } } - if (DM_LSTRCMP(clid, "-") != 0) { - init_client_options_args(&curr_client_options_args, "61", dmstrdup(clid)); + p = DM_STRSTR(line, "clid="); + if (p) { + sscanf(p, "clid=%127s ", clid); + if (DM_LSTRCMP(clid, "-") != 0) { + init_client_options_args(&curr_client_options_args, "61", dmstrdup(clid)); - inst = handle_instance_without_section(dmctx, parent_node, ++id); + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) - break; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) + break; + } } - if (DM_LSTRCMP(ucid, "-") != 0) { - init_client_options_args(&curr_client_options_args, "77", dmstrdup(ucid)); + p = DM_STRSTR(line, "ucid="); + if (p) { + sscanf(p, "ucid=%127s ", ucid); + if (DM_LSTRCMP(ucid, "-") != 0) { + init_client_options_args(&curr_client_options_args, "77", dmstrdup(ucid)); - inst = handle_instance_without_section(dmctx, parent_node, ++id); + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) - break; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) + break; + } } - if (DM_LSTRCMP(hostname, "-") != 0) { - init_client_options_args(&curr_client_options_args, "12", dmstrdup(hostname)); + p = DM_STRSTR(line, "hostname="); + if (p) { + sscanf(p, "hostname=%127s ", hostname); + if (DM_LSTRCMP(hostname, "-") != 0) { + init_client_options_args(&curr_client_options_args, "12", dmstrdup(hostname)); - inst = handle_instance_without_section(dmctx, parent_node, ++id); + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) - break; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) + break; + } } - if (DM_LSTRCMP(paramlist, "-") != 0) { - init_client_options_args(&curr_client_options_args, "55", dmstrdup(paramlist)); + p = DM_STRSTR(line, "paramlist="); + if (p) { + sscanf(p, "paramlist=%255s ", paramlist); + if (DM_LSTRCMP(paramlist, "-") != 0) { + init_client_options_args(&curr_client_options_args, "55", dmstrdup(paramlist)); - inst = handle_instance_without_section(dmctx, parent_node, ++id); + inst = handle_instance_without_section(dmctx, parent_node, ++id); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) - break; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP) + break; + } } break;