cli_opt_t

首先解释一下cli_opt_t的这个_t代表结构图可能是type的意思。同时还有很多i_ b_等作为前缀的变量,其中的I_表示int类型的变量 b表示bool类型的。依次类推。

正式进入主题。

typedef struct{

    int b_progress;

   int i_seek;

    hnd_t hin;

   hnd_t hout;

    FILE *qpfile;

cli_opt_t;

此结构体是记录一些与编码关系较小的设置信息的opt=option。结构体内部的变量都可以通过读取main()的参数获得。也就是argv。

b_progress表示一个bool类型的变量,看参数帮助 也就是x264--help你会知道,他是用来控制是否显示编码进度的一个东西。取值为0,1.

 

I_seek 整数类型 表示开始从哪一帧编码。因为不一定从这个文件的第一帧开始编码,这是可以控制的。

 

Hnd_t(hnd=handle)是一个空指针, void*在C语言里空指针是有几个特性的,他是一个一般化指针,可以指向任何一种类型,但却不能解引用,需要解引用的时候,需要进行强制转换。采用空指针的策略,应该是为了声明变量的简便和统一。

Hin 指向输入yuv文件的指针。

Hout 指向编码过后生成的文件的指针。

 

Qpfile 是一个指向文件类型的指针,他是文本文件,其每一行的格式是framenum frametype QP

用于强制指定某些帧或者全部帧的帧类型QP(quant param量化参数)的值

/* * fn CLI_RET cli_input_parse(char *buff, size_t blen, char *prompt) * brief get user input command and parse it * details * * param[in] * param[out] buff user input commands buffer prompt current prompt string to display * * return excute status * retval CLI_RET_OK, CLI_RET_ERROR * * note this is the main function for input-parser mod */ CLI_RET cli_input_parse(char *buff, size_t blen, char *prompt) { unsigned char c = 0; int arrow = 0; int break_out = 0; int y = 0; char *pCmd = NULL; /* disable canonical mode, no echo */ ioctl(0, FIOSETOPTIONS, OPT_RAW); ioctl(0, FIOSETOPTIONS, OPT_CRMOD); handlers_sets |= SET_RESET_TERM; /* init terminal */ buff[0] = 0; l_cursor_y = 0; l_cmd_len = 0; l_pCmd = buff; l_cmdSize = blen; cli_input_init(); /* put prompt */ cli_put_prompt(prompt); /* loop for read input char */ while (1) { fflush(stdout); if (cli_get_input(0, &c, 1) < 1) { break_out = -1; goto input_exit; break; } /* �����յ����Ƕ����Ʋ��� ��ô \r \n �������⡣��Ҫ������telnet����� by Li Chenglong*/ /*����"*/ /* parse input char */ switch(c) { case '\r': case '\n': cli_input_end(); putchar('\n'); break_out = 1; break; /* Control-a -- Beginning of line */ case 1: cli_cursor_backward(l_cursor); break; /* Control-b -- Move back one character */ case 2: cli_cursor_backward(1); break; /* Control-c -- stop get input */ case 3: putchar('\n'); memset(buff, 0, blen); cli_put_prompt(prompt); l_up_index = ((l_history_num - 1) % CLI_MAX_HISTORY_NUM); l_down_index = -1; break; /* Control-d -- Delete one character, or exit */ case 4: if (l_cmd_len == 0) { cli_input_end(); putchar('\n'); /* by Li Chenglong*/ cli_processLogOut(); } else { cli_input_delete(); } break; /* Control-e -- to the end of line */ case 5: cli_input_end(); break; /* Control-f -- Move forward one character */ case 6: cli_cursor_forward(); break; /* backspace and Control-h */ case '\b': case DEL: { cli_input_backspace(); break; } /* Control-k -- clear to the end of line */ case 11: *(l_pCmd + l_cursor) = 0; l_cmd_len = l_cursor; CLI_PRINT("\033[J"); break; /* Control-l -- clear screen */ case 12: CLI_PRINT("\033[1H\033[2J"); cli_redraw(0, l_cmd_len - l_cursor); break; /* input tab */ case '\t': /* have not login */ if (g_cli_mode == CLI_MODE_NONE) { break; } #ifdef __CMD_TABLE__ buff[l_cmd_len] = '\0'; cli_parseTab(buff, blen); l_cmd_len = strlen(buff); cli_redraw(l_cursor_y, 0); #endif break; /* Control-n -- Get next command in history */ case 14: arrow = CLI_DOWN_ARROW; goto history_redraw; break; /* Control-p -- Get previous command from history */ case 16: arrow = CLI_UP_ARROW; goto history_redraw; break; /* Control-U -- Clear line before cursor */ case 21: if (l_cursor) { CUTIL_STR_STRNCPY(l_pCmd, l_pCmd + l_cursor, l_cmdSize); cli_redraw(l_cursor_y, l_cmd_len -= l_cursor); } break; /*������ͨ�ù涨�Ŀ�ݲ�������man ascii �п����ҵ���ϸ������.*/ /*������vt100 �����ն�֧�ֵ�ESC ��������*/ /* VT100 --- control mode */ case ESC: { if (cli_get_input(fileno(stdin), &c, 1) < 1) { break_out = -1; goto input_exit; } if (c == '[' || c == 'O') { if (cli_get_input(fileno(stdin), &c, 1) < 1) { break_out = -1; goto input_exit; } } switch (c) { case '\n': case '\r': /* Enter */ l_cmd_len = 0; l_pCmd[l_cmd_len++] = ESC; break_out = 1; break; case 'A': /*up arrow*/ arrow = CLI_UP_ARROW; goto history_redraw; break; case 'B': arrow = CLI_DOWN_ARROW; history_redraw: pCmd = cli_load_history(arrow); if (!pCmd) { bzero(buff, blen); l_cursor = l_cursor_x = l_cursor_y = l_cmd_len = 0; putchar('\r'); cli_put_prompt(prompt); CLI_PRINT("\033[J"); } else { CUTIL_STR_STRNCPY(buff, pCmd, blen); y = l_cursor_y; l_cursor = l_cursor_x = l_cursor_y = 0; l_cmd_len = strlen(pCmd); cli_redraw(y, 0); } break; case 'C': cli_cursor_forward(); break; case 'D': cli_cursor_backward(1); break; /* Delete */ case '3': /* remove symbol ~ */ if (cli_get_input(fileno(stdin), &c, 1) < 1) { break_out = -1; goto input_exit; } cli_input_delete(); break; /* Home (Ctrl-A) */ case '1': case 'H': /*remove symbol ~*/ if (cli_get_input(fileno(stdin), &c, 1) < 1) { break_out = -1; goto input_exit; } cli_cursor_backward(l_cursor); break; /* End (Ctrl-E) */ case '4': case 'F': /*remove symbol ~*/ if (cli_get_input(fileno(stdin), &c, 1) < 1) { break_out = -1; goto input_exit; } cli_input_end(); break; case '2': case '5': case '6': /*remove symbol ~*/ if (cli_get_input(fileno(stdin), &c, 1) < 1) { break_out = -1; goto input_exit; } break; default: if (!(c >= '1' && c <= '9')) { c = 0; } CLI_BEEP(); break; } break; } default: /* normal characters */ if (c == 22) { if (cli_get_input(0, &c, 1) < 1) { break_out = -1; goto input_exit; } if (c == 0) { CLI_BEEP(); break; } } else if (!Isprint(c)) { break; } if (l_cmd_len > CLI_MAX_CMD_LEN - 2) { break; } l_cmd_len++; if (l_cursor == l_cmd_len - 1) /* append at the end of the line */ { *(l_pCmd + l_cursor) = c; *(l_pCmd + l_cursor + 1) = 0; cli_setout_char(0); } else /* insert otherwise */ { int sc = l_cursor; memmove(l_pCmd + sc + 1, l_pCmd + sc, l_cmd_len - sc); *(l_pCmd + sc) = c; sc++; cli_input_end(); cli_cursor_backward(l_cursor - sc); } break; } if (break_out == 1) { break; } } input_exit: /* reset terminal */ setTermSettings(0, (void *) &initialSettings); handlers_sets &= ~SET_RESET_TERM; if (break_out > 0) { buff[l_cmd_len] = '\0'; cli_save_history(buff); } cli_reset_term(); return CLI_RET_OK; }解释一下这个函数的作用,以及在这里是什么作用 /*just get input to the line end.*/ cli_input_parse(username, sizeof(username), "username:");
11-26
现在我修改了一个CLI指令,其主要分两步,先输入ip dhcp server pool XXX进入视图(这是与原本一致的),然后输入address XXX hardware-address XXX hardware-type ethernet on/off(必选) bind on/of note XXX,其中bind和note是可选的 这是我的CLI指令函数 STATUS cli_dhcpServerManualBindSetCpn(IN cli_env *pCliEnv, IN char *poolName, IN char *ip, IN char *clientId, IN char *mac, IN int type, IN char *enable, IN char *bind, IN char *note) { DBG_ALZ("+++++++++++ENTER cli_dhcpServerManualBindSetCpn++++++++++"); int ret=0; // MANUAL_BINDING manualBind = {}; OPTION optionList[DHCP_RESERV_OPT_NUM] = {0}; int optNum = 0; int enableFlag = 0; CFG_IMB_INST inst = {0}; mac = mac ? mac : ""; clientId = clientId ? clientId : ""; if(!ip||!poolName) { ret=ERR_BAD_PARAM; goto done; } if(type==0) { type=ETHERNET_BIND; } else if(type==1) { type=IEEE802_BIND; } if (NULL != enable && 0 == strcmp(enable, "on")) { enableFlag = 1; } else { enableFlag = 0; } if (NULL != bind && 0 == strcmp(bind, "on")) { safeStrncpy(inst.ipaddr, ip, sizeof(inst.ipaddr)); safeStrncpy(inst.enable, "on", sizeof(inst.enable)); safeStrncpy(inst.mac, mac, sizeof(inst.mac)); safeStrncpy(inst.zone, poolName, sizeof(inst.zone)); safeStrncpy(inst.bind, "0", sizeof(inst.bind)); APPL_IF_ERR_DONE(ret, dmCfgIMBInstAddSet(&inst, NULL)); } ret= uiDhcpServerManualBindSetWithOption(poolName, ip, clientId, mac, type, optionList, optNum, note, enableFlag); done: if(ret!=ERR_NO_ERROR) { cliPrintErrStr(pCliEnv,ret); } return ret; } 现在我需要对他做配置收集,这是原本CLI指令的配置收集 int uiDhcpServerCollectCb(TPCONFIG_COLLECTFUN_INPUT_T *pInput) { DEBUG_DHCPS("region[%d]\r\n", pInput->regionId); // 此为GLOBAL的配置收集回调函数,此处pInput->regionId 为 COLLECT_REGION_ID_E里的GLOBAL char *pStr = NULL; char ipStr[IP_ADDRESS_LENGTH] = {0}; char maskStr[IP_ADDRESS_LENGTH] = {0}; char parseKey[DHCP_SERVER_CONFIGDB_KEY_LEN_MAX] = {0}; DHCP_SERVER_POOL poolParam = {}; char outBuf[DHCPS_MAX_CLI_STR_LEN] = {0}; // 后面的outBuf是否会将已经赋值给Sds的历史值给覆盖掉????? UINT32 defPingPktNum = 0; UINT32 defPingTimeout = 0; UINT32 defLease = 0; APPL_IF_ERR_RET(uilibDhcpServerDefPingPacketNumGet(&defPingPktNum)); APPL_IF_ERR_RET(uilibDhcpServerDefPingTimeoutGet(&defPingTimeout)); APPL_IF_ERR_RET(uilibDhcpServerDefLeaseGet(&defLease)); // pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL]:pool if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL]) { DEBUG_DHCPS("collect DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL"); DHCPS_GLOBAL_CONFIG conf = {}; char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL]); TPCONFIG_ITER_FV(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL]) { if (PFM_ERR_C_OK == tpConfig_IterGetNumU8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL], &conf.dhcpsEnable, pKey, UC_DS_ENABLE)) { memset(outBuf, 0, sizeof(outBuf)); if (conf.dhcpsEnable) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "service dhcp server"); } else if (pInput->uShowAllCliMode) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "no service dhcp server"); } DEBUG_DHCPS("collect [%s]\r\n", outBuf); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL], &conf.extOption.acAddr.s_addr, pKey, UC_DS_CAP_WAP_IP)) { DEBUG_DHCPS("get_obj acAddr[%s]\r\n", inet_htoa(conf.extOption.acAddr)); memset(outBuf, 0, sizeof(outBuf)); if (conf.extOption.acAddr.s_addr != 0 && OK == Ipv4Int2Str(conf.extOption.acAddr.s_addr, ipStr)) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server extend-option capwap-ac-ip %s", ipStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } else if (conf.extOption.acAddr.s_addr == 0 && pInput->uShowAllCliMode) { // DEBUG_DHCPS("get_obj acAddr[%s]\r\n", inet_htoa(conf.extOption.acAddr)); memset(outBuf, 0, sizeof(outBuf)); if (conf.extOption.acAddr.s_addr != 0 && OK == Ipv4Int2Str(conf.extOption.acAddr.s_addr, ipStr)) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server extend-option capwap-ac-ip %s", ipStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } } // snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "network %s ", ipStr); } if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL], &pStr, pKey, UC_DS_VENDER_CLASEE)) { DEBUG_DHCPS("get_obj vendor class[%s]\r\n", pStr); memset(outBuf, 0, sizeof(outBuf)); if (pStr && strlen(pStr) > 0) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server extend-option vendor-class-id \"%s\"", pStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } else if (pInput->uShowAllCliMode) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server extend-option vendor-class-id \"\""); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } } if (PFM_ERR_C_OK == tpConfig_IterGetNumU8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL], &conf.pingConfig.pingPktNum, pKey, UC_DS_PING_PACKET_NUM)) { DEBUG_DHCPS("get_obj ping pkt num[%d]\r\n", conf.pingConfig.pingPktNum); memset(outBuf, 0, sizeof(outBuf)); if (conf.pingConfig.pingPktNum != defPingPktNum) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server ping packets %d", conf.pingConfig.pingPktNum); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } else if (pInput->uShowAllCliMode) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server ping packets %d", conf.pingConfig.pingPktNum); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_GLOBAL], &conf.pingConfig.pingTimeout, pKey, UC_DS_PING_PACKET_TIMEOUT)) { DEBUG_DHCPS("get_obj ping pkt timeout[%d]\r\n", conf.pingConfig.pingTimeout); memset(outBuf, 0, sizeof(outBuf)); if (conf.pingConfig.pingTimeout != defPingTimeout) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server ping timeout %d", conf.pingConfig.pingTimeout); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } else if (pInput->uShowAllCliMode) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server ping timeout %d", conf.pingConfig.pingTimeout); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } } } } if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_EXIP]) { DEBUG_DHCPS("collect DHCP_SERVER_GLOBAL_AREA_TBL_EXIP"); char endIpStr[IP_ADDRESS_LENGTH] = {}; char startIpStr[IP_ADDRESS_LENGTH] = {}; DHCPS_EXCLUDE_IP exIp = {}; TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_EXIP]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_EXIP]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } if (3 == sscanf(pKey, UC_DS_EXIP_TBL_FMT, &exIp.exStartIp.s_addr, &exIp.exEndIp.s_addr, exIp.vrfName)) { Ipv4Int2Str(exIp.exStartIp.s_addr, startIpStr); Ipv4Int2Str(exIp.exEndIp.s_addr, endIpStr); if (!VRF_IS_DEFAULT(exIp.vrfName)) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server excluded-address %s %s %s", startIpStr, endIpStr, exIp.vrfName); } else { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server excluded-address %s %s", startIpStr, endIpStr); } tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } } } if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { /* 此处pIter[0]对应的是tpConfig_colletFunReg注册时,ADD KEY的表顺序,如果只有1个表为0,如果有多个,需要模块自己维护顺序 迭代器取数据是不可逆的,循环一次后,再次使用迭代器进行循环就会失败,所以可以一次把数据全部取出,然后再进行字段的判断,如果想 重新初始化迭代器,请使用Rewind初始化后,可以再次从迭代器头开始循环 */ DEBUG_DHCPS("collect DHCP_SERVER_GLOBAL_AREA_TBL_POOL"); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL]) // 如果模块在这个区域只有一个表,不用使用TPCONFIG_ITER_KEY { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } DEBUG_DHCPS("pKey %s", pKey); sscanf(pKey, UC_DS_POOL_TBL_FMT, poolParam.name); memset(outBuf, 0, sizeof(outBuf)); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "ip dhcp server pool \"%s\"", poolParam.name); DEBUG_DHCPS("collect [%s]\r\n", outBuf); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ TPCONFIG_ITER_FV(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL]) { if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], &pStr, pKey, UC_DS_POOL_TBL_name)) { strncpy(poolParam.name, pStr, DHCPS_POOLNAME_LEN); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], &poolParam.ip.s_addr, pKey, UC_DS_POOL_TBL_ip)) { DEBUG_DHCPS("get_obj ip[%s]\r\n", inet_htoa(poolParam.ip)); // snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "network %s ", ipStr); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], &poolParam.mask.s_addr, pKey, UC_DS_POOL_TBL_mask)) { DEBUG_DHCPS("get_obj mask[%s]\r\n", inet_htoa(poolParam.mask)); } if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], &pStr, pKey, UC_DS_POOL_TBL_vrfName)) { strncpy(poolParam.vrfName, pStr, sizeof(poolParam.vrfName)); DEBUG_DHCPS("get_obj vrfName[%s]\r\n", poolParam.vrfName); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], (UINT32 *)&poolParam.lease, pKey, UC_DS_POOL_TBL_lease)) { DEBUG_DHCPS("get_obj lease[%d]\r\n", poolParam.lease); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], (UINT32 *)&poolParam.nextServer.s_addr, pKey, UC_DS_POOL_TBL_nextserver)) { DEBUG_DHCPS("get_obj nextServer[%s]\r\n", inet_htoa(poolParam.nextServer)); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], (UINT32 *)&poolParam.controllerIp.s_addr, pKey, UC_DS_POOL_TBL_ctrlip)) { DEBUG_DHCPS("get_obj controllerIp[%s]\r\n", inet_htoa(poolParam.controllerIp)); } if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], &pStr, pKey, UC_DS_POOL_TBL_dname)) { strncpy(poolParam.domainName, pStr, sizeof(poolParam.domainName)); DEBUG_DHCPS("get_obj domainName[%s]\r\n", poolParam.domainName); } if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], &pStr, pKey, UC_DS_POOL_TBL_bfile)) { strncpy(poolParam.bootFileName, pStr, sizeof(poolParam.bootFileName)); DEBUG_DHCPS("get_obj bootFileName[%s]\r\n", poolParam.bootFileName); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_POOL], (UINT8 *)&poolParam.netBiosNodeType, pKey, UC_DS_POOL_TBL_nbtype)) { DEBUG_DHCPS("get_obj netBiosNodeType[%d]\r\n", poolParam.netBiosNodeType); } } // 网段地址 if (poolParam.ip.s_addr != 0 && poolParam.mask.s_addr != 0) { if (OK != Ipv4Int2Str(poolParam.ip.s_addr, ipStr)) { return ERROR; } if (OK != Ipv4Int2Str(poolParam.mask.s_addr, maskStr)) { return ERROR; } memset(outBuf, 0, sizeof(outBuf)); if (DHCP_SERVER_VRF_IS_DEFUALT(poolParam.vrfName)) { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "network %s %s", ipStr, maskStr); } else { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "network %s %s %s", ipStr, maskStr, poolParam.vrfName); } tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (poolParam.lease != defLease || pInput->uShowAllCliMode) { memset(outBuf, 0, sizeof(outBuf)); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "lease %ld", poolParam.lease); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (poolParam.nextServer.s_addr != 0 || pInput->uShowAllCliMode) { memset(outBuf, 0, sizeof(outBuf)); memset(ipStr, 0, sizeof(ipStr)); Ipv4Int2Str(poolParam.nextServer.s_addr, ipStr); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "next-server %s ", ipStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (poolParam.controllerIp.s_addr != 0 || pInput->uShowAllCliMode) { memset(outBuf, 0, sizeof(outBuf)); memset(ipStr, 0, sizeof(ipStr)); Ipv4Int2Str(poolParam.controllerIp.s_addr, ipStr); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "controller-ip %s ", ipStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (strlen(poolParam.domainName) != 0 || pInput->uShowAllCliMode) { memset(outBuf, 0, sizeof(outBuf)); DEBUG_DHCPS("get_obj domainName[%s]\r\n", poolParam.domainName); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "domain-name \"%s\" ", poolParam.domainName); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (strlen(poolParam.bootFileName) != 0 || pInput->uShowAllCliMode) { memset(outBuf, 0, sizeof(outBuf)); DEBUG_DHCPS("get_obj bootFileName[%s]\r\n", poolParam.bootFileName); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "bootfile \"%s\" ", poolParam.bootFileName); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (poolParam.netBiosNodeType != 0) { memset(outBuf, 0, sizeof(outBuf)); DEBUG_DHCPS("get_obj netBiosNodeType[%d]\r\n", poolParam.netBiosNodeType); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "netbios-node-type "); if (NBN_SERVER_NODE_TYPE_B == poolParam.netBiosNodeType) { strcat(outBuf, "b-node"); } else if (NBN_SERVER_NODE_TYPE_P == poolParam.netBiosNodeType) { strcat(outBuf, "p-node"); } else if (NBN_SERVER_NODE_TYPE_M == poolParam.netBiosNodeType) { strcat(outBuf, "m-node"); } else if (NBN_SERVER_NODE_TYPE_H == poolParam.netBiosNodeType) { strcat(outBuf, "h-node"); } outBuf[strlen(outBuf)] = '\0'; tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (!DHCP_SERVER_VRF_IS_DEFUALT(poolParam.vrfName)) { memset(outBuf, 0, sizeof(outBuf)); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "vrf %s ", poolParam.vrfName); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { int section = 0; UINT32 startIp = 0;; UINT32 endIp = 0; char poolName[DHCPS_POOLNAME_LEN + 1] = {0}; char startIpStr[IP_ADDRESS_LENGTH] = {0}; char endIpStr[IP_ADDRESS_LENGTH] = {0}; memset(outBuf, 0, sizeof(outBuf)); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } strncpy(parseKey, pKey, sizeof(parseKey) - 1); APPL_IF_ERR_RET(dhcpPoolAboutKeyNameParse(parseKey, UC_DHCPS_ADDRESS_RANGE_TBL_FMT, poolName, &section)); if (strncmp(poolName, poolParam.name, DHCPS_POOLNAME_LEN) != 0) { DEBUG_DHCPS("not this pool 's range."); continue; } TPCONFIG_ITER_FV(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE]) { if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE], &startIp, pKey, UC_DHCPS_ADDRESS_RANGE_STARTIP)) { DEBUG_DHCPS("get_startIp[%d]", startIp); continue; } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE], &endIp, pKey, UC_DHCPS_ADDRESS_RANGE_ENDIP)) { DEBUG_DHCPS("get endIp[%d]", endIp); continue; } } memset(outBuf, 0, sizeof(outBuf)); memset(startIpStr, 0, sizeof(startIpStr)); memset(endIpStr, 0, sizeof(endIpStr)); Ipv4Int2Str(startIp, startIpStr); Ipv4Int2Str(endIp, endIpStr); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "range %d %s %s", section, startIpStr, endIpStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } tpConfig_objIterRewind(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_RANGE]); } // 静态绑定 if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { UINT32 bindIp = 0; MANUAL_BINDING bind = {}; char bindPoolName[DHCPS_POOLNAME_LEN] = {}; char ipStr[IP_ADDRESS_LENGTH] = {'\0'}; // char macAddr[MAC_ADDRESS_LENGTH + 6] = {'\0'}; char address[] = COLLECT_STR_MANUAL_ADDRESS; char hardwareAddress[] = COLLECT_STR_MANUAL_HARDWARE_ADDRESS; char typeEthernet[] = COLLECT_STR_MANUAL_TYPEETHERNET; char typeIeee802[] = COLLECT_STR_MANUAL_TYPEIEEE; char clientIdentifier[] = COLLECT_STR_MANUAL_CLIENT; char ascii[] = COLLECT_STR_MANUAL_ASCII; char tailstr[MAXOPT * 2 + 128 + 1] = {'\0'}; char tmpstr[MAXOPT * 2 + 128 + 1] = {'\0'}; INT8 num = 0; // int subindex = 0; memset(outBuf, 0, sizeof(outBuf)); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } // sscanf(pKey,UC_DS_MANUAL_BIND_ENTRY_FMT,bindPoolName,&bindIp); strncpy(parseKey, pKey, sizeof(parseKey) - 1); APPL_IF_ERR_RET(dhcpPoolAboutKeyNameParse(parseKey, UC_DS_MANUAL_BIND_ENTRY_FMT, bindPoolName, &bindIp)); if (strncmp(bindPoolName, poolParam.name, DHCPS_POOLNAME_LEN) != 0) { DEBUG_DHCPS("not this pool 's manual bind."); continue; } TPCONFIG_ITER_FV(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND]) { if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND], &pStr, pKey, UC_DS_MANUAL_BIND_POOL)) { strncpy(bind.poolName, pStr, DHCPS_POOLNAME_LEN); DEBUG_DHCPS("get_obj poolname[%s]\r\n", pStr); } if (PFM_ERR_C_OK == tpConfig_IterGetNumU32(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND], &bind.ip.s_addr, pKey, UC_DS_MANUAL_BIND_IP)) { DEBUG_DHCPS("get_obj ip[%s]\r\n", inet_htoa(bind.ip)); } // if (PFM_ERR_C_OK == tpConfig_IterGetNumI8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND], (INT8*)&bind.bindType, pKey, UC_DS_MANUAL_BIND_BINDTYPE)) if (PFM_ERR_C_OK == tpConfig_IterGetNumI8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND], (INT8 *)&num, pKey, UC_DS_MANUAL_BIND_BINDTYPE)) { bind.bindType = num; DEBUG_DHCPS("get_obj bindType[%d]\r\n", bind.bindType); } if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND], &pStr, pKey, UC_DS_MANUAL_BIND_CLIENT_ID_STR)) { strncpy(bind.cidStr, pStr, DHCPS_CID_STR_LEN_MAX); DEBUG_DHCPS("get_obj cidStr[%s]\r\n", pStr); } if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND], &pStr, pKey, UC_DS_MANUAL_BIND_MAC)) { strncpy(bind.macStr, pStr, MAC_ADDRESS_LENGTH); DEBUG_DHCPS("get_obj macStr[%s]\r\n", pStr); } } if (ETHERNET_BIND == bind.bindType || IEEE802_BIND == bind.bindType) { memset(ipStr, 0, sizeof(ipStr)); memset(outBuf, 0, sizeof(outBuf)); Ipv4Int2Str(bind.ip.s_addr, ipStr); DEBUG_DHCPS("mac address:%s.", bind.macStr); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "%s %s %s %s %s", address, ipStr, hardwareAddress, bind.macStr, (ETHERNET_BIND == bind.bindType) ? typeEthernet : typeIeee802); } else if (CLIENT_ID_ASCII == bind.bindType) { memset(ipStr, 0, sizeof(ipStr)); memset(outBuf, 0, sizeof(outBuf)); Ipv4Int2Str(bind.ip.s_addr, ipStr); dhcpClientIdStrGetCLI(bind.cidStr, tmpstr, tailstr); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "%s %s %s \"%s", address, ipStr, clientIdentifier, tmpstr); if (0 != strlen(tailstr)) { DEBUG_DHCPS("client id to be continued..."); strcat(outBuf, tailstr); } strcat(outBuf, "\""); strcat(outBuf, " "); strcat(outBuf, ascii); } else if (CLIENT_ID_HEX == bind.bindType) { memset(ipStr, 0, sizeof(ipStr)); memset(outBuf, 0, sizeof(outBuf)); Ipv4Int2Str(bind.ip.s_addr, ipStr); dhcpClientIdStrGetCLI(bind.cidStr, tmpstr, tailstr); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "%s %s %s \"%s", address, ipStr, clientIdentifier, tmpstr); if (0 != strlen(tailstr)) { DEBUG_DHCPS("client id to be continued..."); strcat(outBuf, tailstr); } strcat(outBuf, "\""); strcat(outBuf, " "); } tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } tpConfig_objIterRewind(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_MANUALBIND]); } // nbs if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_NBS]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { int first = 1; char nbsPoolName[DHCPS_POOLNAME_LEN + 1] = {}; UINT32 nbs = 0; char ipStr[IP_ADDRESS_LENGTH] = {}; memset(outBuf, 0, sizeof(outBuf)); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_NBS]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_NBS]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } // sscanf(pKey,UC_DHCPS_DNS_TBL_FMT,nbsPoolName,&nbs); strncpy(parseKey, pKey, sizeof(parseKey) - 1); APPL_IF_ERR_RET(dhcpPoolAboutKeyNameParse(parseKey, UC_DHCPS_DNS_TBL_FMT, nbsPoolName, &nbs)); if (strncmp(nbsPoolName, poolParam.name, DHCPS_POOLNAME_LEN) != 0) { DEBUG_DHCPS("not this pool 's nbs."); continue; } if (nbs != 0) { if (first == 0) { strcat(outBuf, ","); } else { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "netbios-name-server "); first = 0; } memset(ipStr, 0, sizeof(ipStr)); if (OK != Ipv4Int2Str(nbs, ipStr)) { return ERROR; } strcat(outBuf, ipStr); } } /* 遍历完全部条目一次打印 */ tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ tpConfig_objIterRewind(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_NBS]); } // dns if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DNS]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { int first = 1; char dnsPoolName[DHCPS_POOLNAME_LEN + 1] = {}; UINT32 dns = 0; char ipStr[IP_ADDRESS_LENGTH] = {}; memset(outBuf, 0, sizeof(outBuf)); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DNS]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DNS]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } strncpy(parseKey, pKey, sizeof(parseKey) - 1); APPL_IF_ERR_RET(dhcpPoolAboutKeyNameParse(parseKey, UC_DHCPS_DNS_TBL_FMT, dnsPoolName, &dns)); if (strncmp(dnsPoolName, poolParam.name, DHCPS_POOLNAME_LEN) != 0) { DEBUG_DHCPS("not this pool 's dns."); continue; } if (dns != 0) { if (first == 0) { strcat(outBuf, ","); } else { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "dns-server "); first = 0; } memset(ipStr, 0, sizeof(ipStr)); if (OK != Ipv4Int2Str(dns, ipStr)) { return ERROR; } strcat(outBuf, ipStr); } } /* 遍历完全部的条目一次打印 */ tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ tpConfig_objIterRewind(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DNS]); } // default gateway if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DFTGATEWAY]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { int first = 1; char gatewayPoolName[DHCPS_POOLNAME_LEN + 1] = {}; UINT32 dftGateway = 0; char ipStr[IP_ADDRESS_LENGTH] = {}; memset(outBuf, 0, sizeof(outBuf)); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DFTGATEWAY]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DFTGATEWAY]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } // sscanf(pKey,UC_DHCPS_DNS_TBL_FMT,gatewayPoolName,&dftGateway); strncpy(parseKey, pKey, sizeof(parseKey) - 1); APPL_IF_ERR_RET(dhcpPoolAboutKeyNameParse(parseKey, UC_DHCPS_DNS_TBL_FMT, gatewayPoolName, &dftGateway)); if (strncmp(gatewayPoolName, poolParam.name, DHCPS_POOLNAME_LEN) != 0) { DEBUG_DHCPS("not this pool 's default-gateway."); continue; } if (dftGateway != 0) { if (first == 0) { strcat(outBuf, ","); } else { snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "default-gateway "); first = 0; } memset(ipStr, 0, sizeof(ipStr)); if (OK != Ipv4Int2Str(dftGateway, ipStr)) { return ERROR; } strcat(outBuf, ipStr); } } /* 遍历完全部的gateway后一次打印全部gateway */ tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ tpConfig_objIterRewind(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_DFTGATEWAY]); } // option的收集 if (NULL != pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION]) // 如果KEY在DB里是没有数据的,此处迭代器会为NULL,需要判断一下 { const char *optionTypeStr[3] = {"HEX", "STRING", "IP"}; // 根据枚举类型的顺序 // char opValStr[DHCPS_MAX_OPTION_ASCII_LEN * 2 + 1] = {0}; char optionPoolName[DHCPS_POOLNAME_LEN] = {}; OPTION option = {}; memset(outBuf, 0, sizeof(outBuf)); TPCONFIG_ITER_KEY(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION]) { char *pKey = NULL; pKey = tpConfig_getKeyName(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION]); if (!pKey) { DEBUG_DHCPS("!pKey"); continue; } strncpy(parseKey, pKey, sizeof(parseKey) - 1); // sscanf(pKey,UC_DS_POOL_OPTION_TBL_FMT,optionPoolName,&option.code); APPL_IF_ERR_RET(dhcpPoolAboutKeyNameParse(parseKey, UC_DS_POOL_OPTION_TBL_FMT, optionPoolName, &option.code)); if (strncmp(optionPoolName, poolParam.name, DHCPS_POOLNAME_LEN) != 0) { DEBUG_DHCPS("not this pool 's option."); continue; } TPCONFIG_ITER_FV(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION]) { if (PFM_ERR_C_OK == tpConfig_IterGetStrPtr(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION], &pStr, pKey, UC_DS_POOL_OPTION_VAL)) { DEBUG_DHCPS("get_obj option-val[%s]", pStr); strncpy(option.valStr, pStr, DHCP_OPTION_STR_MAX_LEN); } else if (PFM_ERR_C_OK == tpConfig_IterGetNumU8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION], (UINT8 *)&option.code, pKey, UC_DS_POOL_OPTION_CODE)) { DEBUG_DHCPS("get_obj code[%d]", option.code); } else if (PFM_ERR_C_OK == tpConfig_IterGetNumU8(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION], (UINT8 *)&option.type, pKey, UC_DS_POOL_OPTION_TYPE)) { DEBUG_DHCPS("get_obj type[%d]", option.type); } } if (option.code == 0 || option.code == 138) { // 遵从老代码的处理,? continue; } // 开始组装命令 memset(outBuf, 0, sizeof(outBuf)); snprintf(outBuf, DHCPS_MAX_CLI_STR_LEN, "option %d %s \"%s\" ", option.code, optionTypeStr[option.type - 1], option.valStr); tpConfig_outputToSdsForCli(GLOBAL, 0, outBuf, TPCONFIG_HEADSPACE_YES); /* 如果区域内部没有区分区域的,直接使用0 */ } tpConfig_objIterRewind(pInput->pIter[DHCP_SERVER_GLOBAL_AREA_TBL_OPTION]); } tpConfig_outputToSdsForCli(GLOBAL, 0, "#", TPCONFIG_HEADSPACE_YES); DEBUG_DHCPS("########"); } } return ERR_NO_ERROR; } /* 配置收集各个key的注册;该函数在platform阶段注册 */ int cli_dhcp_server_collect_reg() { int ret = 0; /* 配置收集注册,每个key都需要注册 */ // ret=uiDhcpServerCollectReg(); return ret; } #endif 这是现在可参考的配置收集函数,我需要完成一个这样的配置收集函数 static int lanInterfaceBridgeCfgCollect(TPSTATE_NETIF_ST* netIfEntry, void* param) { int ret = ERR_NO_ERROR; int subIfIndex = 0; GATEWAY_IF_TYPE subIfType; char cliCmd[TPCONFIGCPN_CLI_CMD_LEN + 1] = {0}; CFG_ZONE_INST **zoneCfg = NULL; char vlanStr[VLAN_MAX_LENGTH] = {}; IF_ADDR allIp[NETIF_MAX_IPV4_ADDR_NUM] = {}; int ipCount = 0; char maskStr[IP_ADDRESS_MAX_LENGTH] = {"unassigned"}; char ipStr[IP_ADDRESS_MAX_LENGTH] = {}; int ifIndex = 0; IGMP_INTF_CONFIG_T igmpIntfCfg = {0}; APPL_ENSURE_RET_VAL(netIfEntry, ERR_BAD_PARAM); APPL_ENSURE_RET_VAL(param, ERR_BAD_PARAM); APPL_ENSURE_RET_VAL((netIfEntry->netIfId.ifType == NETIF_TYPE_GWVIRT), ERR_NO_ERROR); if (netIfEntry->netIfId.ifType == NETIF_TYPE_GWVIRT) { netIfGwVirtDataParse(netIfEntry->netIfId.ifData.data, &subIfIndex, &subIfType); if (GATEWAY_TYPE_BRIDGE != subIfType) { return ERR_NO_ERROR; } } TPCONFIG_COLLECTFUN_INPUT_T *pInput = (TPCONFIG_COLLECTFUN_INPUT_T *)param; char isolation[10]; char allowinternet[10]; if (((netIfEntry->isolation >> 0) & 0x3) == 2) { strcpy(isolation, "on"); } else { strcpy(isolation, "off"); } if (((netIfEntry->isolation >> 2) & 0x3) == 1){ strcpy(allowinternet, "on"); } else { strcpy(allowinternet, "off"); } tpConfig_outputToSdsForCli(pInput->regionId, 0, "#", TPCONFIG_HEADSPACE_NO); memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "interface bridge %d", subIfIndex); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_NO)); memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "description %s", netIfEntry->description); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); APPL_IF_ERR_DONE(ret, dmCfgZoneInstGetLstByField(CFG_ZONE_INST_F_IFNAME, netIfEntry->kernelName, &zoneCfg)); memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "zonename %s", zoneCfg[0]->zoneName); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); uilibNetIfVlanBitmapToString(netIfEntry->vlanListBitMap, vlanStr, NULL); memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "vlans %s", vlanStr); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); libNetIfIndexGet(netIfEntry->netIfId, &ifIndex); ret = libNetIfIpv4AllIpGet(LIB_NETIF_GETMODE_TPSTATE, ifIndex, allIp, &ipCount); if (ERR_NO_ERROR != ret) { goto done; } else { inet_ntop(AF_INET, &(V4_ADDR(allIp[0])), ipStr, IP_ADDRESS_MAX_LENGTH); ret = libNetIfMaskLenToStr(V4_SUBNET(allIp[0]), IP_ADDRESS_MAX_LENGTH, maskStr); } memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "ip address %s %s", ipStr, maskStr); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); ret = uiIgmpIntfCfgGet(netIfEntry->netIfId, &igmpIntfCfg); if (ret == ERR_NO_ERROR) { if(IGMP_NOT_CONFIGURED != igmpIntfCfg.adminMode) { memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, sizeof(cliCmd), "ip igmp"); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); } } if(IGMP_NOT_CONFIGURED != igmpIntfCfg.MrouteProxyType) { char proxyIntfType[GL_BUFLEN_64] = {}; char proxyIntfName[GL_BUFLEN_64] = {}; memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); uiMrouteGetIntfNameSplit(igmpIntfCfg.MrouteProxyType, igmpIntfCfg.MrouteProxyData, proxyIntfType, proxyIntfName, GL_BUFLEN_64); snprintf(cliCmd, sizeof(cliCmd), "ip igmp mroute-proxy %s %s", proxyIntfType, proxyIntfName); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); } memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "isolation %s", isolation); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "allowinternet %s", allowinternet); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_YES)); memset(cliCmd, 0, TPCONFIGCPN_CLI_CMD_LEN); snprintf(cliCmd, TPCONFIGCPN_CLI_CMD_LEN, "#"); PFM_IF_FAIL_DONE(ret, tpConfig_outputToSdsForCli(pInput->regionId, 0, cliCmd, TPCONFIG_HEADSPACE_NO)); done: dmCfgZoneInstListFree(zoneCfg); return ERR_NO_ERROR; }
最新发布
11-29
解析这段代码,注释,且告诉我dsd是做什么的。/****************************************************************************** * Copyright (c) 2015-2017 TP-Link Technologies CO.,LTD. * * 文件名称: dsd.c * 版 本: * 摘 要: * 作 者: * 创建时间: 2018-03-01 *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <time.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <libubox/uloop.h> #include <libubox/ustream.h> #include <libubox/utils.h> #include <libubox/usock.h> #include <libubus.h> #include <signal.h> #include <sys/wait.h> #include "thd_pool.h" #include "context.h" #include "ds_parser.h" #include "dsd.h" #include "common.h" #include "dsd_dbg.h" #ifndef IS_SLAVE_DECODER #include "json_uci_op.h" #endif #include "ubus_api.h" #include "error.h" #include "var.h" #include "http_client.h" #ifdef AUTH_ENCRYPT_EN #include "auth_encrypt.h" #endif LOCAL DS_MODULE_HEAD *model_root = NULL; LOCAL THD_POOL *thd_pool = NULL; DS_MODULE_HEAD *get_model_root() { return model_root; } LOCAL void handle_sock_connect(struct uloop_fd *fd, unsigned int events) { struct sockaddr_in cli_addr; U32 len = sizeof(struct sockaddr_in); S32 cli_fd = -1; struct timeval timeout = {0}; if (NULL == fd) { DSD_LOG(DSD_LOG_ERROR, "Invalid param."); return; } cli_fd = accept(fd->fd, (struct sockaddr *)&cli_addr, &len); if (cli_fd < 0) { DSD_LOG(DSD_LOG_DEBUG, "Failed to accept."); goto finish; } /* 设置接收超时时间 */ timeout.tv_sec = SOCK_IO_TIMEOUT; timeout.tv_usec = 0; if (OK != setsockopt(cli_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout))) { DSD_LOG(DSD_LOG_ERROR, "Setsockopt rcv timeout fail."); goto finish; } /* 设置发送超时时间 */ if (OK != setsockopt(cli_fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout))) { DSD_LOG(DSD_LOG_ERROR, "Setsockopt snd timeout fail."); goto finish; } if (OK != thd_pool_add_task(thd_pool, (FUNCPTR)ds_signal_handle, (void *)cli_fd)) { DSD_LOG(DSD_LOG_DEBUG, "Add task to queue failed."); make_error_response(cli_fd, SLP_ESYSBUSY); goto finish; } return; finish: if (cli_fd >= 0) { close(cli_fd); cli_fd = -1; } return; } void socket_accept_loop(int sock_fd) { struct sockaddr_in cli_addr; U32 len = sizeof(struct sockaddr_in); S32 cli_fd = -1; struct timeval timeout = {0}; if (sock_fd < 0) { DSD_LOG(DSD_LOG_ERROR, "Invalid params."); return; } while (1) { cli_fd = accept(sock_fd, (struct sockaddr *)&cli_addr, &len); if (cli_fd < 0) { DSD_LOG(DSD_LOG_DEBUG, "Failed to accept."); cli_fd = -1; continue; } /* 设置接收超时时间 */ timeout.tv_sec = SOCK_IO_TIMEOUT; timeout.tv_usec = 0; if (OK != setsockopt(cli_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout))) { DSD_LOG(DSD_LOG_ERROR, "Setsockopt rcv timeout fail."); SAFE_CLOSE(cli_fd); continue; } /* 设置发送超时时间 */ if (OK != setsockopt(cli_fd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout))) { DSD_LOG(DSD_LOG_ERROR, "Setsockopt snd timeout fail."); SAFE_CLOSE(cli_fd); continue; } fd_cloexec(cli_fd); if (OK != thd_pool_add_task(thd_pool, (FUNCPTR)ds_signal_handle, (void *)cli_fd)) { DSD_LOG(DSD_LOG_DEBUG, "Add task to queue failed."); make_error_response(cli_fd, SLP_ESYSBUSY); SAFE_CLOSE(cli_fd); continue; } } SAFE_CLOSE(cli_fd); return; } int unix_socket_init() { int fd = -1; const char *host = DSD_SERVER_SOCK; const char *port = "0"; unlink(host); fd = usock(USOCK_UNIX | USOCK_SERVER, host, port); if (fd < 0) { DSD_LOG(DSD_LOG_ERROR, "Failed to create unix sock."); return -1; } return fd; } LOCAL STATUS init_unix_socket() { static struct uloop_fd dsd_server = {0}; const char *host = DSD_SERVER_SOCK; const char *port = "0"; unlink(host); dsd_server.fd = usock(USOCK_UNIX | USOCK_SERVER, host, port); if (dsd_server.fd < 0) { DSD_LOG(DSD_LOG_ERROR, "Failed to create unix sock."); return ERROR; } dsd_server.cb = handle_sock_connect; uloop_init(); uloop_fd_add(&dsd_server, ULOOP_READ); return OK; } LOCAL int dsd_uloop_run(void) { uloop_run(); uloop_done(); return OK; } LOCAL void sigchld_handler(int sig) { pid_t pid; while((pid = waitpid(-1, NULL, WNOHANG)) > 0) { DSD_LOG(DSD_LOG_DEBUG, "child (%d) exit.", (int)pid); } return ; } LOCAL STATUS signal_init() { struct sigaction act; /* SIGPIPE ignore */ DSD_LOG(DSD_LOG_DEBUG, "SIGPIPE ignore."); act.sa_handler = SIG_IGN; sigemptyset(&act.sa_mask); //additional signals to block act.sa_flags = SA_RESETHAND | SA_NODEFER; if (0 != sigaction(SIGPIPE, &act, NULL)) { DSD_LOG(DSD_LOG_ERROR, "SIGPIPE ignore failed."); return ERROR; } DSD_LOG(DSD_LOG_DEBUG, "SIGCHLD capture."); act.sa_handler=sigchld_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_RESETHAND | SA_NODEFER; if (0 != sigaction(SIGCHLD, &act, NULL)) { DSD_LOG(DSD_LOG_ERROR, "fail to set SIGCHLD sigaction"); return ERROR; } return OK; } #ifdef VMS_HOST /* 启动时同步时间给解码器 */ void sync_date_to_nvd() { DS_HANDLE_CONTEXT *context = NULL; struct timespec start_time = {0}; struct timespec end_time = {0}; JSON_OBJPTR param; int ret; int retry = 10; int starttime = 30; const char *decoder_ip = NULL; JSON_OBJPTR login_data = NULL; JSON_OBJPTR login_para = NULL; JSON_OBJPTR resp_obj = NULL; char recv_buf[RECV_BUF_SIZE] = {0}; context = context_alloc(); if (!context) { DSD_LOG(DSD_LOG_ERROR, "Failed to alloc a free context."); return; } context->sock = -1; context->error_code = SLP_ESYSTEM; sleep(starttime); clock_gettime(CLOCK_MONOTONIC, &start_time); while(1) { ret = sync_date(context, param); if (0 == ret) { DSD_LOG(DSD_LOG_ERROR, "sync date to nvd success\n"); /*解码器是否处于出厂状态*/ decoder_ip = get_opt_value(context->ctx, "protocol", "static", "vice_ipaddr"); login_data = jso_new_obj(); jso_add_string(login_data, "method", "do"); login_para = jso_new_obj(); jso_add_string(login_para, "username", "admin"); jso_add_string(login_para, "password", ""); jso_obj_add(login_data, "login", login_para); jso_obj_url_coding(login_data, URL_ENCODING); jso_to_string(login_data, context->buffer, context->buf_len); DSD_LOG(DSD_LOG_DEBUG, "json_data : %s", context->buffer); ret = http_single_post((char*)decoder_ip, "80", NULL, URL_WITHOUT_STOK, URL_WITHOUT_DS, context->buffer, recv_buf, HTTP_COMMON_TIMEOUT_MS); DSD_LOG(DSD_LOG_DEBUG, "http_single_post recv_buf : %s", recv_buf); resp_obj = json_tokener_parse(recv_buf); if (NULL == resp_obj || is_error(resp_obj)) { DSD_LOG(DSD_LOG_ERROR, "parse json data failed"); resp_obj = NULL; break; } ret = json_object_get_int(json_object_object_get(resp_obj, "error_code")); if (SLP_ENONE != ret) { set_opt_value(context->ctx, "system", "basic", "vice_factory_default", "no"); DSD_LOG(DSD_LOG_DEBUG, "nvd is not factory status\n"); } break; } clock_gettime(CLOCK_MONOTONIC, &end_time); if(retry < (end_time.tv_sec - start_time.tv_sec)) { DSD_LOG(DSD_LOG_ERROR, "sync date to nvd fail\n"); break; } sleep(1); } context_free(context); if (NULL != resp_obj) { jso_free_obj(resp_obj); resp_obj = NULL; } if (NULL != login_data) { jso_free_obj(login_data); login_data = NULL; } } #endif int main(int argc, char *argv[]) { STATUS ret = 0; int sock_fd; extern char* optarg; int opt = 0; tplog_init(); reload_debug_mode(); if (get_debug_mode() == 0 || get_debug_mode() == 1) { set_dbg_level(DSD_LOG_MAX); } else { set_dbg_level(DSD_LOG_ERROR); } while((opt = getopt(argc, argv, "d")) != -1) { switch (opt) { case 'd': { set_dbg_level(DSD_LOG_DEBUG); break; } default: break; } } DSD_LOG(DSD_LOG_DEBUG, "Dsd started."); #ifdef AUTH_ENCRYPT_EN if (OK != rsa_encrypt_init()) { DSD_LOG(DSD_LOG_ERROR, "Signal handler init failed."); goto exit; } #endif if (OK != signal_init()) { DSD_LOG(DSD_LOG_ERROR, "Signal handler init failed."); goto exit; } model_root = model_init(); if (!model_root) { DSD_LOG(DSD_LOG_ERROR, "Init ds model failed."); goto exit; } ret = model_register(model_root); if (OK != ret) { DSD_LOG(DSD_LOG_ERROR, "Register ds model failed."); goto exit; } if (!context_init()) { DSD_LOG(DSD_LOG_ERROR, "Init context failed."); goto exit; } thd_pool = thd_pool_init(THD_MAX_NUM); if (!thd_pool) { DSD_LOG(DSD_LOG_ERROR, "Init thread pool failed."); goto exit; } // ret = ubus_init(); // if (ret != OK) // { // DSD_LOG(DSD_LOG_ERROR, "ubus async thread create error."); // goto exit; // } var_init(); // ret = init_unix_socket(); // if (OK != ret) // { // DSD_LOG(DSD_LOG_ERROR, "Init Unix domain socket failed."); // goto exit; // } // DSD_LOG(DSD_LOG_DEBUG, "Begin uloop run"); // dsd_uloop_run(); sock_fd = unix_socket_init(); if (sock_fd < 0) { DSD_LOG(DSD_LOG_ERROR, "Init Unix domain socket failed."); goto exit; } #ifdef VMS_HOST sync_date_to_nvd(); #endif socket_accept_loop(sock_fd); exit: #ifdef AUTH_ENCRYPT_EN rsa_encrypt_deinit(); #endif thd_pool_destroy(thd_pool); context_destory(); model_destory(model_root); tplog_uninit(); return OK; }
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值