int loadrosopts(opt_t *opts) { ros::NodeHandle private_nh("~"); for (opt_t *opt = opts; opt->var != NULL; opt++) { std::string value; std::string key(opt->name); std::replace(key.begin(), key.end(), '-', '_'); private_nh.param(key, value, value); if (value.empty()) continue; if (!str2opt(opt, value.c_str())) trace(1,"loadrosopts: invalid option value '%s' (%s), %d\n", value.c_str(), opt->name, value.length()); } return 1; }
/* load options ---------------------------------------------------------------- * load options from file * args : char *file I options file * opt_t *opts IO options table * (terminated with table[i].name="") * return : status (1:ok,0:error) *-----------------------------------------------------------------------------*/ extern int loadopts(const char *file, opt_t *opts) { FILE *fp; opt_t *opt; char buff[2048],*p; int n=0; trace(3,"loadopts: file=%s\n",file); if (!(fp=fopen(file,"r"))) { trace(1,"loadopts: options file open error (%s)\n",file); return 0; } while (fgets(buff,sizeof(buff),fp)) { n++; chop(buff); if (buff[0]=='\0') continue; if (!(p=strstr(buff,"="))) { fprintf(stderr,"invalid option %s (%s:%d)\n",buff,file,n); continue; } *p++='\0'; chop(buff); if (!(opt=searchopt(buff,opts))) continue; if (!str2opt(opt,p)) { fprintf(stderr,"invalid option value %s (%s:%d)\n",buff,file,n); continue; } } fclose(fp); return 1; }
static void do_modify(int argc, char *argv[], const char *use) { vrrp_vr_conf_t conf; vrrp_err_t err; uint32_t modify_mask = 0, mask; char *endp; int c; while ((c = getopt_long(argc, argv, ":i:p:o:", lopts, NULL)) != EOF) { switch (c) { case 'i': if (modify_mask & VRRP_CONF_INTERVAL) err_exit("duplicate '-i' option"); modify_mask |= VRRP_CONF_INTERVAL; conf.vvc_adver_int = (uint32_t)strtol(optarg, &endp, 0); if ((*endp) != '\0' || conf.vvc_adver_int < VRRP_MAX_ADVER_INT_MIN || conf.vvc_adver_int > VRRP_MAX_ADVER_INT_MAX || (conf.vvc_adver_int == 0 && errno != 0)) { err_exit("invalid advertisement interval"); } break; case 'o': mask = 0; if (str2opt(optarg, &mask, &conf.vvc_preempt, &conf.vvc_accept) != 0) { err_exit("Invalid options"); } if (mask & modify_mask & VRRP_CONF_PREEMPT) err_exit("duplicate '-o preempt' option"); else if (mask & modify_mask & VRRP_CONF_ACCEPT) err_exit("duplicate '-o accept' option"); modify_mask |= mask; break; case 'p': if (modify_mask & VRRP_CONF_PRIORITY) err_exit("duplicate '-p' option"); modify_mask |= VRRP_CONF_PRIORITY; conf.vvc_pri = strtol(optarg, &endp, 0); if ((*endp) != '\0' || conf.vvc_pri < VRRP_PRI_MIN || conf.vvc_pri > VRRP_PRI_OWNER || (conf.vvc_pri == 0 && errno != 0)) { err_exit("invalid priority"); } break; default: opterr_exit(optopt, c, use); } } if (argc - optind > 1) err_exit("usage: %s", gettext(use)); if (optind != argc - 1) err_exit("VRRP name not specified."); if (strlcpy(conf.vvc_name, argv[optind], sizeof (conf.vvc_name)) >= sizeof (conf.vvc_name)) { err_exit("invalid router name %s", argv[optind]); } if ((modify_mask & VRRP_CONF_ACCEPT) && !conf.vvc_accept && (modify_mask & VRRP_CONF_PRIORITY) && conf.vvc_pri == VRRP_PRI_OWNER) { err_exit("accept_mode must be true for virtual IP owner"); } if (modify_mask == 0) usage(); err = vrrp_modify(vrrp_vh, &conf, modify_mask); if (err != VRRP_SUCCESS) err_exit("modify-router failed: %s", vrrp_err2str(err)); }
static void do_create(int argc, char *argv[], const char *usage) { vrrp_vr_conf_t conf; int c; uint32_t create_mask = 0, mask; char *endp; vrrp_err_t err; /* * default value */ bzero(&conf, sizeof (vrrp_vr_conf_t)); conf.vvc_vrid = VRRP_VRID_NONE; conf.vvc_af = AF_UNSPEC; conf.vvc_pri = VRRP_PRI_DEFAULT; conf.vvc_adver_int = VRRP_MAX_ADVER_INT_DFLT; conf.vvc_preempt = B_TRUE; conf.vvc_accept = B_TRUE; conf.vvc_enabled = B_TRUE; while ((c = getopt_long(argc, argv, ":V:l:p:i:o:A:f", lopts, NULL)) != EOF) { switch (c) { case 'l': if (strlcpy(conf.vvc_link, optarg, sizeof (conf.vvc_link)) >= sizeof (conf.vvc_link)) { err_exit("invalid data-link name %s", optarg); } break; case 'i': if (create_mask & VRRP_CONF_INTERVAL) err_exit("duplicate '-i' option"); create_mask |= VRRP_CONF_INTERVAL; conf.vvc_adver_int = (uint32_t)strtol(optarg, &endp, 0); if ((*endp) != '\0' || conf.vvc_adver_int < VRRP_MAX_ADVER_INT_MIN || conf.vvc_adver_int > VRRP_MAX_ADVER_INT_MAX || (conf.vvc_adver_int == 0 && errno != 0)) { err_exit("invalid advertisement interval"); } break; case 'p': if (create_mask & VRRP_CONF_PRIORITY) err_exit("duplicate '-p' option"); create_mask |= VRRP_CONF_PRIORITY; conf.vvc_pri = strtol(optarg, &endp, 0); if ((*endp) != '\0' || conf.vvc_pri < VRRP_PRI_MIN || conf.vvc_pri > VRRP_PRI_OWNER || (conf.vvc_pri == 0 && errno != 0)) { err_exit("invalid priority"); } break; case 'o': mask = 0; if (str2opt(optarg, &mask, &conf.vvc_preempt, &conf.vvc_accept) != 0) { err_exit("invalid options: %s", optarg); } if (mask & create_mask & VRRP_CONF_PREEMPT) err_exit("duplicate '-o preempt' option"); else if (mask & create_mask & VRRP_CONF_ACCEPT) err_exit("duplicate '-o accept' option"); create_mask |= mask; break; case 'V': if (conf.vvc_vrid != VRRP_VRID_NONE) err_exit("duplicate '-V' option"); conf.vvc_vrid = strtol(optarg, &endp, 0); if ((*endp) != '\0' || conf.vvc_vrid < VRRP_VRID_MIN || conf.vvc_vrid > VRRP_VRID_MAX || (conf.vvc_vrid == 0 && errno != 0)) { err_exit("invalid VRID"); } break; case 'A': if (conf.vvc_af != AF_UNSPEC) err_exit("duplicate '-A' option"); if (strcmp(optarg, "inet") == 0) conf.vvc_af = AF_INET; else if (strcmp(optarg, "inet6") == 0) conf.vvc_af = AF_INET6; else err_exit("invalid address family"); break; default: opterr_exit(optopt, c, usage); } } if (argc - optind > 1) err_exit("usage: %s", gettext(usage)); if (optind != argc - 1) err_exit("VRRP name not specified"); if (strlcpy(conf.vvc_name, argv[optind], sizeof (conf.vvc_name)) >= sizeof (conf.vvc_name)) { err_exit("Invalid router name %s", argv[optind]); } if (conf.vvc_vrid == VRRP_VRID_NONE) err_exit("VRID not specified"); if (conf.vvc_af == AF_UNSPEC) err_exit("address family not specified"); if (strlen(conf.vvc_link) == 0) err_exit("link name not specified"); if (!conf.vvc_accept && conf.vvc_pri == VRRP_PRI_OWNER) err_exit("accept_mode must be true for virtual IP owner"); done: if ((err = vrrp_create(vrrp_vh, &conf)) == VRRP_SUCCESS) return; err_exit("create-router failed: %s", vrrp_err2str(err)); }