Example #1
0
static int parse_proto(const char *proto) {
  if (strcmp(proto, "udp") == 0 || strcmp(proto, "UDP") == 0)
    return IPPROTO_UDP;
  else if (strcmp(proto, "tcp") == 0 || strcmp(proto, "TCP") == 0)
    return IPPROTO_TCP;
  else
    return parse_proto(DEF_PROTO);
}
Example #2
0
int trans_load(void)
{
	struct sr_module *mod;
	struct sr_module *prev = NULL, *next;
	cmd_export_t *cmd;
	char * proto_name;
	int proto = PROTO_NONE;
	api_proto_init abind;

	/* go through all protocol modules loaded and load only the ones
	 * that are prefixed with the PROTO_PREFIX token */
	for (mod=modules; mod && (next = mod->next, 1); mod = next) {
		if (strncmp(PROTO_PREFIX, mod->exports->name, PROTO_PREFIX_LEN) == 0) {
			proto_name = mod->exports->name + PROTO_PREFIX_LEN;
			if (parse_proto((unsigned char *)proto_name,
					strlen(proto_name), &proto) < 0) {
				LM_ERR("don't know any protocol <%s>\n", proto_name);
				return -1;
			}

			/* check if we have any listeners for that protocol */
			if (!protos[proto].listeners) {
				LM_WARN("protocol %s loaded, but no listeners defined! "
						"Skipping ...\n", proto_name);
				if (!prev)
					modules = mod->next;
				else
					prev->next = mod->next;

				/* we do not call the destroy_f because the module was not
				 * initialized yet here */
				pkg_free(mod);
				continue;
			}

			for (cmd = mod->exports->cmds; cmd && cmd->name; cmd++) {
				if (strcmp("proto_init", cmd->name)==0) {
					abind = (api_proto_init)cmd->function;
					if (abind(&protos[proto]) < 0) {
						LM_ERR("cannot load protocol's functions for %s\n",
								proto_name);
						return -1;
					}
					/* everything was fine, return */
					protos[proto].id = proto;
					protos[proto].name = proto_name;
					goto next;
				}
			}
			LM_ERR("No binding found for protocol %s\n", proto_name);
			return -1;
		}
next:
		prev = mod;
	}
	return 0;
}
int main(int argc, char *argv[])
{
	struct nl_cache *link_cache;
	int dev = 0;

	params.dp_fd = stdout;
	sock = nlt_alloc_socket();
	nlt_connect(sock, NETLINK_ROUTE);
	link_cache = nlt_alloc_link_cache(sock);
	cls = nlt_alloc_cls();

	for (;;) {
		int c, optidx = 0;
		enum {
			ARG_PROTO = 257,
			ARG_PRIO = 258,
			ARG_ID,
		};
		static struct option long_opts[] = {
			{ "format", 1, 0, 'f' },
			{ "help", 0, 0, 'h' },
			{ "version", 0, 0, 'v' },
			{ "dev", 1, 0, 'd' },
			{ "parent", 1, 0, 'p' },
			{ "proto", 1, 0, ARG_PROTO },
			{ "prio", 1, 0, ARG_PRIO },
			{ "id", 1, 0, ARG_ID },
			{ 0, 0, 0, 0 }
		};
	
		c = getopt_long(argc, argv, "+f:qhva:d:", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case '?': exit(NLE_INVAL);
		case 'f': params.dp_type = nlt_parse_dumptype(optarg); break;
		case 'h': print_usage(); break;
		case 'v': nlt_print_version(); break;
		case 'd': dev = 1; parse_dev(cls, link_cache, optarg); break;
		case 'p': parse_parent(cls, optarg); break;
		case ARG_PRIO: parse_prio(cls, optarg); break;
		case ARG_ID: parse_handle(cls, optarg); break;
		case ARG_PROTO: parse_proto(cls, optarg); break;
		}
 	}

	if (!dev)
		nl_cache_foreach(link_cache, print_cls, NULL);
	else
		print_cls(NULL, NULL);

	return 0;
}
Example #4
0
static mrb_value
mrb_ipvs_service_init(mrb_state *mrb, mrb_value self){
  int parse;
  mrb_value arg_opt = mrb_nil_value(),
            addr = mrb_nil_value(),
            proto = mrb_nil_value(), 
            sched_name = mrb_nil_value(),
            ops = mrb_nil_value(),
            obj = mrb_nil_value();
  mrb_int port,
          timeout,
          netmask;
  struct mrb_ipvs_entry *ie;

  ie = (struct mrb_ipvs_entry*)mrb_malloc(mrb, sizeof(*ie));
  memset(ie, 0, sizeof(struct mrb_ipvs_entry));

  mrb_get_args(mrb, "H", &arg_opt);
  if (mrb_nil_p(arg_opt)) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");

  addr = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "addr"));
  if (mrb_nil_p(addr)) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");

  proto = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "protocol"));
  if (mrb_nil_p(proto)) proto = mrb_str_new_cstr(mrb, DEF_PROTO);

  sched_name = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "sched_name"));
  if (mrb_nil_p(sched_name)) sched_name = mrb_str_new_cstr(mrb, DEF_SCHED);

  obj = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "port"));
  port = mrb_nil_p(obj) ? 0 : mrb_fixnum(obj);
  if (port < 0 || port > 65535) mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); 

  ops = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "ops"));
  timeout = mrb_fixnum(mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "timeout")));
  netmask = mrb_fixnum(mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "netmask")));

  ie->svc.protocol = parse_proto((char *) RSTRING_PTR(proto));

  parse = parse_service((char *) RSTRING_PTR(addr), &ie->svc);
  if (strrchr((char *) RSTRING_PTR(addr), ':') == NULL) ie->svc.port = htons(port);

  if (!(parse & SERVICE_ADDR))
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");

  strncpy(ie->svc.sched_name, (char *) RSTRING_PTR(sched_name), IP_VS_SCHEDNAME_MAXLEN);

  DATA_TYPE(self) = &mrb_ipvs_service_type;
  DATA_PTR(self) = ie;

  return self;
}
Example #5
0
/* setting a connection status command function*/
static struct mi_root* clusterer_set_status(struct mi_root *cmd, void *param)
{
	unsigned int cluster_id;
	unsigned int machine_id;
	unsigned int state;
	int proto;
	int rc;
	struct mi_node *node;
	struct mi_node *prot_node;

	LM_INFO("set status MI command received!\n");

	if (!cmd || !cmd->node.kids || !cmd->node.kids->value.s) {
		LM_DBG("no values specified\n");
		return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));
	}

	node = cmd->node.kids;

	if (!node->next || !node->next->value.s) {
		LM_DBG("only one value specified\n");
		return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));
	}

	if (!node->next->next || !node->next->next->value.s) {
		LM_DBG("no state specified\n");
		return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));
	}

	rc = str2int(&node->value, &cluster_id);

	if (rc == -1 || cluster_id == 0) {
		LM_DBG("the cluster_id parameter is not a valid digit\n");
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	}

	rc = str2int(&node->next->value, &machine_id);
	if (rc == -1 || machine_id == 0) {
		LM_DBG("the machine_id parameter is not a valid digit\n");
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	}

	rc = str2int(&node->next->next->value, &state);
	if (rc == -1 || (state != CLUSTERER_STATE_ON && state != CLUSTERER_STATE_PROBE)) {
		LM_DBG("the state parameter is not valid\n");
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	}

	prot_node = node->next->next->next;
	if (!prot_node || !prot_node->value.s) {
		LM_DBG("the protocol parameter is missing\n");
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	}

	if (parse_proto((unsigned char*) prot_node->value.s, prot_node->value.len, &proto) < 0) {
		LM_DBG("the protocol parameter is not valid\n");
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	}

	rc = set_state(cluster_id, machine_id, state, proto);

	if (rc == -1) {
		LM_DBG("cluster id or machine id are not smaller than 1\n");
		return init_mi_tree(400, MI_SSTR(MI_BAD_PARM));
	}

	if (rc == 1) {
		LM_DBG("there is no machine id %d in the cluster %d\n", machine_id, cluster_id);
	}

	return init_mi_tree(200, MI_SSTR(MI_OK));
}
int main(int argc, char *argv[])
{
	struct nl_sock *sock;
	struct rtnl_cls *cls;
	struct nl_cache *link_cache;
	struct rtnl_cls_ops *ops;
	struct cls_module *mod;
	struct nl_dump_params dp = {
		.dp_type = NL_DUMP_DETAILS,
		.dp_fd = stdout,
	};
	char *kind;
	int err, nlflags = NLM_F_CREATE;
 
	sock = nlt_alloc_socket();
	nlt_connect(sock, NETLINK_ROUTE);
	link_cache = nlt_alloc_link_cache(sock);
	cls = nlt_alloc_cls();

	for (;;) {
		int c, optidx = 0;
		enum {
			ARG_PROTO = 257,
			ARG_PRIO = 258,
			ARG_ID,
		};
		static struct option long_opts[] = {
			{ "quiet", 0, 0, 'q' },
			{ "help", 0, 0, 'h' },
			{ "version", 0, 0, 'v' },
			{ "dev", 1, 0, 'd' },
			{ "parent", 1, 0, 'p' },
			{ "proto", 1, 0, ARG_PROTO },
			{ "prio", 1, 0, ARG_PRIO },
			{ "id", 1, 0, ARG_ID },
			{ 0, 0, 0, 0 }
		};
	
		c = getopt_long(argc, argv, "+qhva:d:", long_opts, &optidx);
		if (c == -1)
			break;

		switch (c) {
		case '?': exit(NLE_INVAL);
		case 'q': quiet = 1; break;
		case 'h': print_usage(); break;
		case 'v': nlt_print_version(); break;
		case 'd': parse_dev(cls, link_cache, optarg); break;
		case 'p': parse_parent(cls, optarg); break;
		case ARG_PRIO: parse_prio(cls, optarg); break;
		case ARG_ID: parse_handle(cls, optarg); break;
		case ARG_PROTO: parse_proto(cls, optarg); break;
		}
 	}

	if (optind >= argc) {
		print_usage();
		fatal(EINVAL, "Missing classifier type");
	}

	kind = argv[optind++];
	if ((err = rtnl_cls_set_kind(cls, kind)) < 0)
		fatal(ENOENT, "Unknown classifier type \"%s\".", kind);
	
	ops = rtnl_cls_get_ops(cls);
	if (!(mod = lookup_cls_mod(ops)))
		fatal(ENOTSUP, "Classifier type \"%s\" not supported.", kind);

	mod->parse_argv(cls, argc, argv);

	printf("Adding ");
	nl_object_dump(OBJ_CAST(cls), &dp);

	if ((err = rtnl_cls_add(sock, cls, nlflags)) < 0)
		fatal(err, "Unable to add classifier: %s", nl_geterror(err));

	if (!quiet) {
		printf("Added ");
		nl_object_dump(OBJ_CAST(cls), &dp);
 	}

	return 0;
}
Example #7
0
File: main.c Project: Agochka/klibc
static int parse_device(struct netdev *dev, const char *ip)
{
	char *cp;
	int opt;
	int is_ip = 0;

	dprintf("IP-Config: parse_device: \"%s\"\n", ip);

	if (strncmp(ip, "ip=", 3) == 0) {
		ip += 3;
		is_ip = 1;
	} else if (strncmp(ip, "nfsaddrs=", 9) == 0) {
		ip += 9;
		is_ip = 1;	/* Not sure about this...? */
	}

	if (!strchr(ip, ':')) {
		/* Only one option, e.g. "ip=dhcp", or an interface name */
		if (is_ip) {
			dev->caps = parse_proto(ip);
			bringup_first = 1;
		} else {
			dev->name = ip;
		}
	} else {
		for (opt = 0; ip && *ip; ip = cp, opt++) {
			if ((cp = strchr(ip, ':'))) {
				*cp++ = '\0';
			}
			if (opt > 6) {
				fprintf(stderr,
					"%s: too many options for %s\n",
					progname, dev->name);
				longjmp(abort_buf, 1);
			}

			if (*ip == '\0')
				continue;
			dprintf("IP-Config: opt #%d: '%s'\n", opt, ip);
			switch (opt) {
			case 0:
				parse_addr(&dev->ip_addr, ip);
				dev->caps = 0;
				break;
			case 1:
				parse_addr(&dev->ip_server, ip);
				break;
			case 2:
				parse_addr(&dev->ip_gateway, ip);
				break;
			case 3:
				parse_addr(&dev->ip_netmask, ip);
				break;
			case 4:
				strncpy(dev->hostname, ip, SYS_NMLN - 1);
				dev->hostname[SYS_NMLN - 1] = '\0';
				memcpy(dev->reqhostname, dev->hostname,
				       SYS_NMLN);
				break;
			case 5:
				dev->name = ip;
				break;
			case 6:
				dev->caps = parse_proto(ip);
				break;
			}
		}
	}

	if (dev->name == NULL ||
	    dev->name[0] == '\0' || strcmp(dev->name, "all") == 0) {
		add_all_devices(dev);
		bringup_first = 1;
		return 0;
	}
	return 1;
}
Example #8
0
void Sagan_Search (_SaganProcSyslog *SaganProcSyslog_LOCAL, int type ) {

int i; 

char ip_src[MAXIP] = { 0 };
char ip_dst[MAXIP] = { 0 };

int   src_port = 0; 
int   dst_port = 0;
int   proto = 0; 

if ( type == 1 ) {

for (i=0; i<counters->search_nocase_count; i++) { 

ip_src[0] = '0';
ip_src[1] = '\0';

ip_dst[0] = '0';
ip_dst[1] = '\0';

if (strcasestr(SaganProcSyslog_LOCAL->syslog_message, SaganNocaseSearchlist[i].search )) { 
   
   counters->search_nocase_hit_count++;

#ifdef HAVE_LIBLOGNORM
if ( config->search_nocase_lognorm) {

   pthread_mutex_lock(&Lognorm_Mutex);

   sagan_normalize_liblognorm(SaganProcSyslog_LOCAL->syslog_message);

if (SaganNormalizeLiblognorm->ip_src[0] != '0') 
        strlcpy(ip_src, SaganNormalizeLiblognorm->ip_src, sizeof(ip_src));


if (SaganNormalizeLiblognorm->ip_dst[0] != '0')
        strlcpy(ip_dst, SaganNormalizeLiblognorm->ip_dst, sizeof(ip_dst));


   src_port = SaganNormalizeLiblognorm->src_port;
   dst_port = SaganNormalizeLiblognorm->dst_port;
   pthread_mutex_unlock(&Lognorm_Mutex);

   if ( ip_src[0] == '0' ) strlcpy(ip_src, SaganProcSyslog_LOCAL->syslog_host, sizeof(ip_src));
   if ( ip_dst[0] == '0' ) strlcpy(ip_dst, SaganProcSyslog_LOCAL->syslog_host, sizeof(ip_dst));
}
#endif

   if ( src_port == 0 ) src_port = config->sagan_port;
   if ( dst_port == 0 ) dst_port = config->sagan_port;

   if ( config->search_nocase_parse_src && ip_src[0] == '0' ) { 

	strlcpy(ip_src, parse_ip(SaganProcSyslog_LOCAL->syslog_message, config->search_nocase_parse_src), sizeof(ip_src));
	if ( ip_src[0] == '0' ) strlcpy(ip_src, SaganProcSyslog_LOCAL->syslog_host, sizeof(ip_src));
   }

   if ( config->search_nocase_parse_dst && ip_dst[0] == '0' ) {

        strlcpy(ip_dst, parse_ip(SaganProcSyslog_LOCAL->syslog_message, config->search_nocase_parse_dst), sizeof(ip_dst));
	if ( ip_dst[0] == '0' ) strlcpy(ip_dst, SaganProcSyslog_LOCAL->syslog_host, sizeof(ip_dst));
   }

   if ( config->search_nocase_parse_proto ) proto = parse_proto(SaganProcSyslog_LOCAL->syslog_message);
   if ( config->search_nocase_parse_proto_program ) proto = parse_proto_program(SaganProcSyslog_LOCAL->syslog_program);
   if ( proto == 0 ) proto = config->sagan_proto; 
   
   Sagan_Send_Alert(SaganProcSyslog_LOCAL, processor_info_search, ip_src, ip_dst, proto, 1, src_port, dst_port);

   }
 }
} else { 

for (i=0; i<counters->search_case_count; i++) {

ip_src[0] = '0';
ip_src[1] = '\0';

ip_dst[0] = '0';
ip_dst[1] = '\0';

if (strstr(SaganProcSyslog_LOCAL->syslog_message, SaganCaseSearchlist[i].search )) {

   counters->search_case_hit_count++;

#ifdef HAVE_LIBLOGNORM
if ( config->search_case_lognorm) { 

   pthread_mutex_lock(&Lognorm_Mutex);
   
   sagan_normalize_liblognorm(SaganProcSyslog_LOCAL->syslog_message);

if (SaganNormalizeLiblognorm->ip_src[0] != '0') 
        strlcpy(ip_src, SaganNormalizeLiblognorm->ip_src, sizeof(ip_src));

if (SaganNormalizeLiblognorm->ip_dst[0] != '0') 
        strlcpy(ip_dst, SaganNormalizeLiblognorm->ip_dst, sizeof(ip_dst));

   src_port = SaganNormalizeLiblognorm->src_port;
   dst_port = SaganNormalizeLiblognorm->dst_port;

   pthread_mutex_unlock(&Lognorm_Mutex);
}

#endif

   if ( src_port == 0 ) src_port = config->sagan_port;
   if ( dst_port == 0 ) dst_port = config->sagan_port;

   if ( config->search_case_parse_src && ip_src[0] == '0') {

        strlcpy(ip_src, parse_ip(SaganProcSyslog_LOCAL->syslog_message, config->search_nocase_parse_src), sizeof(ip_src));
        if ( ip_src[0] =='0' ) strlcpy(ip_src, SaganProcSyslog_LOCAL->syslog_host, sizeof(ip_src));
   }

   if ( config->search_case_parse_dst && ip_dst[0] == '0' ) {

        strlcpy(ip_dst, parse_ip(SaganProcSyslog_LOCAL->syslog_message, config->search_nocase_parse_dst), sizeof(ip_dst));
        if ( ip_dst[0] == '0' ) strlcpy(ip_dst, SaganProcSyslog_LOCAL->syslog_host, sizeof(ip_dst));
   }

   if ( config->search_nocase_parse_proto ) proto = parse_proto(SaganProcSyslog_LOCAL->syslog_message);
   if ( config->search_case_parse_proto_program ) proto = parse_proto_program(SaganProcSyslog_LOCAL->syslog_program);
   if ( proto == 0 ) proto = config->sagan_proto; 
 
   Sagan_Send_Alert(SaganProcSyslog_LOCAL, processor_info_search, ip_src, ip_dst, config->sagan_proto, 2, src_port, dst_port);
   }
  }
 }
}
Example #9
0
File: main.c Project: OPSF/uClinux
/*
 * parses [proto:]host[:port]
 * where proto= udp|tcp|tls
 * returns 0 on success and -1 on failure
 */
static int parse_phostport(char* s, char** host, int* hlen, int* port,
							int* proto)
{
	char* first; /* first ':' occurrence */
	char* second; /* second ':' occurrence */
	char* p;
	int bracket;
	char* tmp;
	
	first=second=0;
	bracket=0;
	
	/* find the first 2 ':', ignoring possible ipv6 addresses
	 * (substrings between [])
	 */
	for(p=s; *p; p++){
		switch(*p){
			case '[':
				bracket++;
				if (bracket>1) goto error_brackets;
				break;
			case ']':
				bracket--;
				if (bracket<0) goto error_brackets;
				break;
			case ':':
				if (bracket==0){
					if (first==0) first=p;
					else if( second==0) second=p;
					else goto error_colons;
				}
				break;
		}
	}
	if (p==s) return -1;
	if (*(p-1)==':') goto error_colons;
	
	if (first==0){ /* no ':' => only host */
		*host=s;
		*hlen=(int)(p-s);
		*port=0;
		*proto=0;
		return 0;
	}
	if (second){ /* 2 ':' found => check if valid */
		if (parse_proto((unsigned char*)s, first-s, proto)<0) goto error_proto;
		*port=strtol(second+1, &tmp, 10);
		if ((tmp==0)||(*tmp)||(tmp==second+1)) goto error_port;
		*host=first+1;
		*hlen=(int)(second-*host);
		return 0;
	}
	/* only 1 ':' found => it's either proto:host or host:port */
	*port=strtol(first+1, &tmp, 10);
	if ((tmp==0)||(*tmp)||(tmp==first+1)){
		/* invalid port => it's proto:host */
		if (parse_proto((unsigned char*)s, first-s, proto)<0) goto error_proto;
		*port=0;
		*host=first+1;
		*hlen=(int)(p-*host);
	}else{
		/* valid port => its host:port */
		*proto=0;
		*host=s;
		*hlen=(int)(first-*host);
	}
	return 0;
error_brackets:
	LOG(L_ERR, "ERROR: parse_phostport: too many brackets in %s\n", s);
	return -1;
error_colons:
	LOG(L_ERR, "ERROR: parse_phostport: too many colons in %s\n", s);
	return -1;
error_proto:
	LOG(L_ERR, "ERROR: parse_phostport: bad protocol in %s\n", s);
	return -1;
error_port:
	LOG(L_ERR, "ERROR: parse_phostport: bad port number in %s\n", s);
	return -1;
}
Example #10
0
int trans_load(void)
{
	int id;
	struct sr_module *mod;
	cmd_export_t *cmd;
	int found_all = 0;
	int found_proto;
	api_proto_init abind;
	struct proto_info pi;

	/* go through all protocol modules loaded and load only the ones
	 * that are prefixed with the PROTO_PREFIX token */
	for (mod = modules; mod; mod = mod->next) {
		if (strncmp(PROTO_PREFIX, mod->exports->name, PROTO_PREFIX_LEN) != 0)
			continue;
		found_proto = 0;
		/* we have a transport module here - check for protocols */
		for (cmd = mod->exports->cmds; cmd && cmd->name; cmd++) {
			if (strcmp("proto_init", cmd->name)==0) {
				abind = (api_proto_init)cmd->function;
				memset(&pi, 0, sizeof(pi));
				if (abind(&pi) < 0) {
					LM_ERR("cannot load protocol's functions for %s\n",
							cmd->name);
					return -1;
				}
				/* double check if it is a known/valid proto */
				if (pi.id < PROTO_FIRST || pi.id >= PROTO_OTHER) {
					LM_ERR("Unknown protocol id %d; check sip_protos structure!\n", pi.id);
					return -1;
				}
				/* double check the name of the proto */
				if (parse_proto((unsigned char *)pi.name, strlen(pi.name), &id) < 0) {
					LM_ERR("Cannot parse protocol %s\n", pi.name);
					return -1;
				}
				if (id != pi.id) {
					LM_ERR("Protocol ID mismatch %d != %d\n", id, pi.id);
					return -1;
				}
				/* check if already added */
				if (protos[id].id != PROTO_NONE) {
					LM_ERR("Protocol already loaded %s\n", pi.name);
					return -1;
				}
				/* all good now */
				found_all++;
				found_proto = 1;
				/* copy necessary info */
				protos[pi.id].id = pi.id;
				protos[pi.id].name = pi.name;
				protos[pi.id].default_port = pi.default_port;
				protos[pi.id].tran = pi.tran;
				protos[pi.id].net = pi.net;
			}
		}
		if (found_proto)
			continue;
		LM_ERR("No binding found for protocol %s\n", mod->exports->name);
		return -1;
	}
	/* return whether we found any protocol or not */
	return found_all;
}
Example #11
0
static mrb_value mrb_ipvs_service_init(mrb_state *mrb, mrb_value self) {
  int parse;
  mrb_value arg_opt = mrb_nil_value(), addr = mrb_nil_value(),
            proto = mrb_nil_value(), sched_name = mrb_nil_value(),
            obj = mrb_nil_value();
  // mrb_value arg_opt = mrb_nil_value(), addr = mrb_nil_value(),
  //           proto = mrb_nil_value(), sched_name = mrb_nil_value(),
  //           ops = mrb_nil_value(), obj = mrb_nil_value();
  mrb_int port;
  // mrb_int port, timeout, netmask;
  struct mrb_ipvs_service *ie;

  ie = (struct mrb_ipvs_service *)mrb_malloc(mrb, sizeof(*ie));
  memset(ie, 0, sizeof(struct mrb_ipvs_service));

  mrb_get_args(mrb, "H", &arg_opt);

  if (mrb_nil_p(arg_opt)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }

  addr = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "addr"));
  if (mrb_nil_p(addr)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }

  obj = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "port"));
  port = mrb_nil_p(obj) ? 0 : mrb_fixnum(obj);
  if (port < 0 || port > 65535) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid port value specified");
  }

  proto = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "protocol"));
  if (mrb_nil_p(proto)) {
    proto = mrb_str_new_cstr(mrb, DEF_PROTO);
  }

  sched_name = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "sched_name"));
  if (mrb_nil_p(sched_name)) {
    sched_name = mrb_str_new_cstr(mrb, DEF_SCHED);
  }

  // ops = mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb, "ops"));
  // timeout =
  //     mrb_fixnum(mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb,
  //     "timeout")));
  // netmask =
  //     mrb_fixnum(mrb_hash_get(mrb, arg_opt, mrb_str_new_cstr(mrb,
  //     "netmask")));

  ie->svc.protocol = parse_proto((char *)RSTRING_PTR(proto));

  parse = parse_service((char *)RSTRING_PTR(addr), &ie->svc);
  if (strrchr((char *)RSTRING_PTR(addr), ':') == NULL) {
    ie->svc.port = htons(port);
  }

  if (!(parse & SERVICE_ADDR)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument");
  }

  strncpy(ie->svc.sched_name, (char *)RSTRING_PTR(sched_name),
          IP_VS_SCHEDNAME_MAXLEN);

  mrb_data_init(self, ie, &mrb_ipvs_service_type);

  return self;
}