[Netadm-devel] gwc/gwclib confio.c,1.2,1.3 confproc.c,1.4,1.5
Status: Beta
Brought to you by:
linuxpark
From: linuxpark <lin...@us...> - 2006-02-26 16:43:33
|
Update of /cvsroot/netadm/gwc/gwclib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28685/gwclib Modified Files: confio.c confproc.c Log Message: MOD: modifiy saveconf/loadconf to be more flexible and use built-in api. renaming. Index: confio.c =================================================================== RCS file: /cvsroot/netadm/gwc/gwclib/confio.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** confio.c 31 Jan 2006 14:19:38 -0000 1.2 --- confio.c 26 Feb 2006 16:43:29 -0000 1.3 *************** *** 39,43 **** --- 39,45 ---- #include "slog.h" #include "sysutil.h" + #include "confproc.h" + extern qos_tos_t tostab[]; void prenc(FILE * fp, char *fmt, ...) *************** *** 71,74 **** --- 73,77 ---- loadconf(sm_t * csm, char *fn) { + fr_t fr; FILE *fp; int lines; *************** *** 83,86 **** --- 86,97 ---- i = 0; + csm->ifcnt = 0; + csm->tcifcnt = 0; + csm->cscnt = 0; + csm->ftcnt = 0; + csm->polcnt = 0; + csm->hpolcnt = 0; + csm->ridx_slot = 0; + if (access(fn, R_OK | W_OK) == -1) { out("%s Access error", fn); *************** *** 93,98 **** } - csm->ridx_slot = 0; - for (lines = 0;; lines++) { memset(line, 0, sizeof (line)); --- 104,107 ---- *************** *** 136,139 **** --- 145,149 ---- if (argc >= 0) argc++; + frinit(&fr); if (!strcmp(cmd, "[qry_state]")) { *************** *** 145,149 **** } csm->state = val; ! } else if (!strcmp (cmd, "[target]")) { int val = atoi (argv[0]); if (val < TARGET_GW || val > TARGET_CISCO_AP ) { --- 155,159 ---- } csm->state = val; ! } else if (!strcmp (cmd, "[target_type]")) { int val = atoi (argv[0]); if (val < TARGET_GW || val > TARGET_CISCO_AP ) { *************** *** 153,183 **** } csm->target = val; ! } else if (!strcmp(cmd, "[target_ip]")) { ! if (!str_inetaddr(argv[0], TRUE)) { ! out("invalid AP IP address:\"%s\"\n", ! argv[0]); ! return RET_ECONFIG; ! } ! if ((csm->ap.addr.s_addr = ! inet_addr(argv[0])) == (in_addr_t) - 1) { ! out("invalid AP IP address:\"%s\"\n", ! argv[0]); ! return RET_ECONFIG; ! } ! } else if (!strcmp(cmd, "[target_mask]")) { ! if (!str_isdigit(argv[0])) { ! out("invalid AP mask :\"%s\"\n", ! argv[0]); ! return RET_ECONFIG; ! } ! ! if (atoi(argv[0]) > 32) { ! out("invalid AP mask :\"%s\"\n", ! argv[0]); ! return RET_ECONFIG; ! } ! csm->ap.mask = atoi(argv[0]); ! ! } else if (!strcmp(cmd, "[snmp]")) { int val = atoi (argv[0]); --- 163,169 ---- } csm->target = val; ! } else if (!strcmp(cmd, "[target]")) { ! add_apinfo(argc, argv, 0, &fr); ! }else if (!strcmp(cmd, "[snmp]")) { int val = atoi (argv[0]); *************** *** 187,205 **** } csm->snmp = val; ! } else if (!strcmp(cmd, "[snmp_community]")) { ! ! if (strlen(argv[0]) > MAXCOMMNAME || ! (csm->snmp == SNMP_SUPPORT && (strlen(argv[0]) == 0))) { ! out("invalid commnunity :\"%s\"\n", argv[0]); ! return RET_ECONFIG; ! } ! strncpy(csm->community, argv[0], ! strlen(argv[0])); } else if (!strcmp(cmd, "[radio_idx]")) { csm->radiodev[csm->ridx_slot++].idx = atoi(argv[0]); ! } else if (!strcmp(cmd, "[interface]")) { strcpy(csm->dev[csm->ifcnt].if_name, argv[0]); strcpy(csm->dev[csm->ifcnt].if_hostname, --- 173,186 ---- } csm->snmp = val; ! add_snmpcomm(argc, argv, 0, &fr); } else if (!strcmp(cmd, "[snmp_community]")) { ! add_snmpcomm(argc, argv, 0, &fr); } else if (!strcmp(cmd, "[radio_idx]")) { + csm->radiodev[csm->ridx_slot++].idx = atoi(argv[0]); ! } else if (!strcmp(cmd, "[interface]")) { + strcpy(csm->dev[csm->ifcnt].if_name, argv[0]); strcpy(csm->dev[csm->ifcnt].if_hostname, *************** *** 220,298 **** csm->dev[csm->ifcnt].bw = atoi(argv[4]); csm->dev[csm->ifcnt++].root_id = atoi(argv[5]); ! } else if (!strcmp(cmd, "[tc_dev]")) { ! strcpy(csm->tc_dev[csm->tcifcnt].if_name, ! argv[0]); ! ! for (i = 0; i < csm->ifcnt; i++) { ! if (!strcmp ! (csm->dev[i].if_name, argv[0])) { ! csm->dev[i].bw = atoi(argv[1]); ! break; ! } ! } ! ++csm->tcifcnt; ! } else if (!strcmp(cmd, "[tc_class]")) { ! strcpy(csm->glass[csm->cscnt].name, argv[0]); ! csm->glass[csm->cscnt].bw = atoi(argv[1]); ! ! strcpy(csm->glass[csm->cscnt].if_name, argv[2]); ! for (i = 0; i < csm->tcifcnt; i++) { ! if (!strcmp ! (csm->tc_dev[i].if_name, argv[2])) { ! csm->tc_dev[i].bw += ! atoi(argv[1]); ! break; ! } ! } ! ++csm->cscnt; ! } else if (!strcmp(cmd, "[tc_filter]")) { ! strcpy(csm->filter[csm->ftcnt].name, argv[0]); ! csm->filter[csm->ftcnt].type = atoi(argv[1]); ! ! if (csm->filter[csm->ftcnt].type == ! APC_FILTER_TYPE_TOS) { ! csm->filter[csm->ftcnt].u.tos = ! atoi(argv[2]); ! } else { ! csm->filter[csm->ftcnt].u.proto.type = ! atoi(argv[2]); ! csm->filter[csm->ftcnt].u.proto.port = ! atoi(argv[3]); ! ! } ! ++csm->ftcnt; ! } else if (!strcmp(cmd, "[tc_policy]")) { ! strcpy(csm->pol[csm->polcnt].name, argv[0]); ! strcpy(csm->pol[csm->polcnt].filter_name, ! argv[1]); ! strcpy(csm->pol[csm->polcnt].class_name, ! argv[2]); ! csm->pol[csm->polcnt].mark_used = atoi(argv[3]); ! ! if (csm->pol[csm->polcnt].mark_used == USEMARK) { ! strcpy(csm->pol[csm->polcnt].mark_name, ! argv[4]); ! } ! ++csm->polcnt; } else if (!strcmp(cmd, "[host_policy]")) { ! strcpy(csm->hostpol[csm->hpolcnt].name, ! argv[0]); ! inet_pton(AF_INET, argv[1], ! &csm->hostpol[csm->hpolcnt].ip); ! csm->hostpol[csm->hpolcnt].flag = atoi(argv[2]); ! csm->hostpol[csm->hpolcnt].max_pktrate = ! atoi(argv[3]); ! ++csm->hpolcnt; } else if (!strcmp(cmd, "[auto_test]")) { ! csm->auto_test.sint_1 = atoi(argv[0]); ! csm->auto_test.sint_2 = atoi(argv[1]); ! csm->auto_test.mint_1 = atoi(argv[2]); ! csm->auto_test.mint_2 = atoi(argv[3]); ! csm->auto_test.ilevel = atoi(argv[4]); ! csm->auto_test.cnum = atoi(argv[5]); } ! } else { ! out("Found unknown config line '%s'\n", line); ! continue; } } --- 201,229 ---- csm->dev[csm->ifcnt].bw = atoi(argv[4]); csm->dev[csm->ifcnt++].root_id = atoi(argv[5]); ! ! } else if (!strcmp(cmd, "[qos_dev]")) { ! add_qos_maxbw(argc, argv, 0, &fr); ! } else if (!strcmp(cmd, "[qos_class]")) { ! add_qos_class(argc, argv, 0, &fr); ! } else if (!strcmp(cmd, "[qos_filter]")) { ! add_qos_filter(argc, argv, 0, &fr); ! } else if (!strcmp(cmd, "[qos_policy]")) { ! add_qos_pol(argc, argv, 0, &fr); } else if (!strcmp(cmd, "[host_policy]")) { ! add_fc_pol(argc, argv, 0, &fr); } else if (!strcmp(cmd, "[auto_test]")) { ! set_auto(argc, argv, 0, &fr); ! }else { ! out("Unknown section \"%s\"\n", tmp); } ! ! if (fr.errcnt) { ! printf("Total %d Error @%d: \"%s\"\n", fr.errcnt, lines, tmp); ! printf("%s", fr.errmsg); ! } ! free(tmp); ! }else { ! out("Unknown line \"%s\"\n", line); ! continue; } } *************** *** 307,316 **** saveconf(sm_t * csm) { - FILE *fp; - #if 0 time_t clock; ! #endif ! char fn[256]; bool backupdone = FALSE; int i; --- 238,246 ---- saveconf(sm_t * csm) { FILE *fp; time_t clock; ! char buf[MINBUF]; ! char fn[MINBUF]; ! bool backupdone = FALSE; int i; *************** *** 334,349 **** } ! fseek(fp, 0l, SEEK_SET); prenc(fp, "%s\n", CONFMAGIC); ! #if 0 prenc(fp, buf); time(&clock); prenc(fp, "# Last Updated: %s", ctime(&clock)); - #endif prenc(fp, "[%s]\t%d\n", STR_STATE, csm->state); ! prenc(fp, "[%s]\t%d\n", STR_TARGET, csm->target); ! prenc(fp, "[%s]\t%s\n", STR_AP_IP, inet_ntoa(csm->ap.addr)); ! prenc(fp, "[%s]\t%d\n", STR_AP_MASK, csm->ap.mask); prenc(fp, "[%s]\t%d\n", STR_SNMP, csm->snmp); prenc(fp, "[%s]\t%s\n", STR_COMMUNITY, csm->community); --- 264,278 ---- } ! //fseek(fp, 0l, SEEK_SET); prenc(fp, "%s\n", CONFMAGIC); ! prenc(fp, "#\n"); ! sprintf(buf, "#%s Configuration\n", SZSYSVERSION); prenc(fp, buf); time(&clock); prenc(fp, "# Last Updated: %s", ctime(&clock)); prenc(fp, "[%s]\t%d\n", STR_STATE, csm->state); ! prenc(fp, "[%s]\t%d\n", STR_TARGET_TYPE, csm->target); ! prenc(fp, "[%s]\t%s\t%d\n", STR_TARGET, inet_ntoa(csm->ap.addr), csm->ap.mask); prenc(fp, "[%s]\t%d\n", STR_SNMP, csm->snmp); prenc(fp, "[%s]\t%s\n", STR_COMMUNITY, csm->community); *************** *** 392,395 **** --- 321,325 ---- /* TC_FILTER */ for (i = 0; i < csm->ftcnt; i++) { + qos_tos_t *p; prenc(fp, "[%s]\t%s\t%d", STR_TC_FILTER, *************** *** 397,404 **** if (csm->filter[i].type == APC_FILTER_TYPE_TOS) { ! prenc(fp, "\t%d\n", csm->filter[i].u.tos); } else { ! prenc(fp, "\t%d\t%d\n", ! csm->filter[i].u.proto.type, csm->filter[i].u.proto.port); } --- 327,338 ---- if (csm->filter[i].type == APC_FILTER_TYPE_TOS) { ! for (p = tostab; p <= 0; p++ ) ! if ( p->tos == csm->filter[i].u.tos ) ! break; ! ! prenc(fp, "\t%s\n", p->name); } else { ! prenc(fp, "\t%s\t%d\n", ! csm->filter[i].u.proto.type == SYS_PROTO_TCP ? "TCP" : "UDP" , csm->filter[i].u.proto.port); } Index: confproc.c =================================================================== RCS file: /cvsroot/netadm/gwc/gwclib/confproc.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** confproc.c 25 Feb 2006 22:59:00 -0000 1.4 --- confproc.c 26 Feb 2006 16:43:29 -0000 1.5 *************** *** 64,79 **** */ qos_tos_t tostab[] = { ! {APC_TOS_TYPE_MD, "MD", "Minimize-Delay"} ! , ! {APC_TOS_TYPE_MT, "MT", "Maximize-Throughput"} ! , ! {APC_TOS_TYPE_MR, "MR", "Maximize-Reliability"} ! , ! {APC_TOS_TYPE_MMC, "MMC", "Minimize-Cost"} ! , ! {APC_TOS_TYPE_NS, "NS", "Normal-Service"} ! , ! {-1, ""} ! , {0} , --- 64,73 ---- */ qos_tos_t tostab[] = { ! {APC_TOS_TYPE_MD, "MD", "Minimize-Delay"}, ! {APC_TOS_TYPE_MT, "MT", "Maximize-Throughput"}, ! {APC_TOS_TYPE_MR, "MR", "Maximize-Reliability"}, ! {APC_TOS_TYPE_MMC, "MMC", "Minimize-Cost"}, ! {APC_TOS_TYPE_NS, "NS", "Normal-Service"}, ! {-1, ""}, {0} , |