Beispiel #1
0
int
parse_pair(struct tapif* tapif,char* key,char* value)
{
  struct addrinfo addr;
  uint8_t* p;

  if (key == 0 || *key == 0)
    return -1;

#define PARSE_IP4(ip_addr)                                        \
  do {                                                            \
    if (value == 0 || *value == 0)                                \
      return -1;                                                  \
    if (parse_address(value,&addr,AF_INET) != 0)                  \
      return -1;                                                  \
    p = (uint8_t*)&((struct sockaddr_in*)addr.ai_addr)->sin_addr; \
    IP4_ADDR(&(ip_addr),*p,*(p+1),*(p+2),*(p+3));                 \
    return 0;                                                     \
  } while(0)

  if (!strcmp(key,"name")) {
    if (value == 0 || *value == 0)
      return -1;
    tapif->name = value;
    return 0;
  } else if (!strcmp(key,"addr")) {
    PARSE_IP4(tapif->ip_addr);
  } else if (!strcmp(key,"netmask")) {
    PARSE_IP4(tapif->netmask);
  } else if (!strcmp(key,"gw")) {
    PARSE_IP4(tapif->gw);
  } else {
    return -1;
  }
}
Beispiel #2
0
static int
parse_vxlan_pair(void *opts, char* key, char* value)
{
	struct vxlan_peer *peer = (struct vxlan_peer *)opts;
	struct addrinfo addr;
	uint8_t* p;

	if (key == 0 || *key == 0)
		return -1;

#define PARSE_IP4(ip_addr)						\
	do {								\
		if (value == 0 || *value == 0)				\
			return -1;					\
		if (parse_address(value, &addr, AF_INET) != 0)		\
			return -1;					\
		p = (uint8_t*)&((struct sockaddr_in*)addr.ai_addr)->sin_addr; \
		IP4_ADDR(&(ip_addr), *p, *(p+1), *(p+2), *(p+3));	\
	} while(0)

	if (!strcmp(key,"addr")) {
		PARSE_IP4(peer->ip_addr);
		return 0;
	} else if (!strcmp(key,"port")) {
		peer->port = atoi(value);
		return 0;
	} else {
		return -1;
	}
#undef PARSE_IP4
}
Beispiel #3
0
static int
parse_port_pair(void *opts, char* key, char* value)
{
	struct net *net = (struct net *)opts;
	struct addrinfo addr;
	uint8_t* p;

	if (key == 0 || *key == 0)
		return -1;

#define PARSE_IP4(ip_addr)						\
	do {								\
		if (value == 0 || *value == 0)				\
			return -1;					\
		if (parse_address(value, &addr, AF_INET) != 0)		\
			return -1;					\
		p = (uint8_t*)&((struct sockaddr_in*)addr.ai_addr)->sin_addr; \
		IP4_ADDR(&(ip_addr), *p, *(p+1), *(p+2), *(p+3));	\
	} while(0)

	if (!strcmp(key,"port_id")) {
		if (value == 0 || *value == 0)
			return -1;
		net->port_id = rte_str_to_size(value);
		return 0;
	} else if (!strcmp(key,"name")) {
		if (value == 0 || *value == 0)
			return -1;
		net->name = value;
		return 0;
	} else if (!strcmp(key,"addr")) {
		PARSE_IP4(net->ip_addr);
		return 0;
	} else if (!strcmp(key,"netmask")) {
		PARSE_IP4(net->netmask);
		return 0;
	} else if (!strcmp(key,"gw")) {
		PARSE_IP4(net->gw);
		return 0;
	} else {
		return -1;
	}
#undef PARSE_IP4
}