Ejemplo n.º 1
0
	struct lisp_db *
ms_init_db()
{
	struct prefix p;
	struct db_node *dn;
	struct lisp_db *db;
	db = calloc(1, sizeof(struct lisp_db));

	//make new tree
	db->lisp_db4 = db_table_init(&ms_free_node);
	db->lisp_db6 = db_table_init(&ms_free_node);

	//assign 0.0.0.0/0 as root of ipv4 tree
	str2prefix("0.0.0.0/0",&p);
	apply_mask(&p);
	dn = db_node_get(db->lisp_db4,&p);
	assert(dn == (db->lisp_db4->top));
	dn->flags = ms_new_node_ex(_ROOT);

	//and 0::/0 as root of ipv6 tree
	str2prefix("0::/0",&p);
	apply_mask(&p);
	dn = db_node_get(db->lisp_db6,&p);
	assert(dn == (db->lisp_db6->top));
	dn->flags = ms_new_node_ex(_ROOT);

	return db;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	s32 opt,ret;
	mpls_echo_params_t param =
	{
		.flag = MPLS_PARAM_OP_SIG,
		.mode = MPLS_PARAM_PING,
		.size = 0,
		.count= 5,
		.interval=1,
		.p = { 0 },
		.quit = NULL 
	} ;
	param.p.family = AF_INET ;
	param.p.u.prefix4.s_addr = htonl(0x08080808);
	param.p.prefixlen = 32 ;

	while( (opt = getopt_long (argc, argv, longoptc , longopts, 0)) > 0 )
	{
		switch(opt)
		{
			case 'c' : 
				MP_GET_NUM(param.count,"count",optarg,0,0x10000);
				break;
			case 'i' :
				MP_GET_NUM(param.interval,"interval",optarg,0,61);
				break;
			case 'T' :
				MP_GET_NUM(param.iph_ttl,"ttl",optarg,0,256);
				break;
			case 'p' :
				MP_GET_NUM(param.size,"packet-size",optarg,0,MPLS_ECHO_MAXSIZ);
				break;
			case 't' :
				param.count = 0x10000 ;
				break;
			case 'h' :
				printf(	"Usage: mpls_ping [OPTION] A.B.C.D/M\r\n"
						"   -c,--count          ping times\r\n"
						"   -i,--interval       ping interval\r\n"
						"   -T,--TTL            ip ttl\r\n"
						"   -p,--packet-size    packet-size\r\n"
						"   -t,--test           ping until CTRL+C\r\n"
						"   -h,--help           display this and exit\r\n"
				);
				return 0 ;
		}
	}

	if( optind != argc -1 || !str2prefix(argv[optind],&param.p) )
	{
		printf("Invalid lsp %s\r\n",argv[optind]);
		return 1;
	}

	ret = mpls_echo(&param);
	

	return -ret ;
}
Ejemplo n.º 3
0
static void check_lookup_result(struct list *list, va_list arglist)
{
	char *prefix_str;
	unsigned int prefix_count = 0;

	printf("Searching results\n");
	while ((prefix_str = va_arg(arglist, char *))) {
		struct listnode *listnode;
		struct bgp_node *bnode;
		struct prefix p;
		bool found = false;

		prefix_count++;
		printf("Searching for %s\n", prefix_str);

		if (str2prefix(prefix_str, &p) <= 0)
			assert(0);

		for (ALL_LIST_ELEMENTS_RO(list, listnode, bnode)) {
			if (prefix_same(&bnode->p, &p))
				found = true;
		}

		assert(found);
	}

	printf("Checking for unexpected result items\n");
	printf("Expecting %d found %d\n", prefix_count, listcount(list));
	assert(prefix_count == listcount(list));
}
Ejemplo n.º 4
0
	int
cli_request_get_eid(uint32_t id, struct prefix *p)
{
	assert(id < MAX_INCOMING_QUEUE);
	char *eid;

	eid = incoming_messages[id].eid;
	str2prefix(eid, p);

	return (TRUE);
}
Ejemplo n.º 5
0
/**
 * context: {}
 * tokens: {prefix, type}
 */
int cli_net_add_subnet(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  ip_pfx_t prefix;
  const char * arg;
  uint8_t type;
  net_subnet_t * subnet;
  int result;

  // Subnet prefix
  arg= cli_get_arg_value(cmd, 0);
  if ((str2prefix(arg, &prefix))) {
    cli_set_user_error(cli_get(), "could not add subnet (invalid prefix)");
    return CLI_ERROR_COMMAND_FAILED;
  }

  // Check the prefix length (!= 32)
  // THE CHECK FOR PREFIX LENGTH SHOULD BE MOVED TO THE NETWORK MGMT PART.
  if (prefix.mask == 32) {
    cli_set_user_error(cli_get(), "could not add subnet (invalid subnet)");
    return CLI_ERROR_COMMAND_FAILED;
  }

  // Subnet type: transit / stub ?
  arg= cli_get_arg_value(cmd, 1);
  if (!strcmp(arg, "transit"))
    type= NET_SUBNET_TYPE_TRANSIT;
  else if (!strcmp(arg, "stub"))
    type = NET_SUBNET_TYPE_STUB;
  else {
    cli_set_user_error(cli_get(), "invalid subnet type \"%s\"", arg);
    return CLI_ERROR_COMMAND_FAILED;
  }

  // Create new subnet
  subnet= subnet_create(prefix.network, prefix.mask, type);

  // Add the subnet
  result= network_add_subnet(network_get_default(), subnet);
  if (result != ESUCCESS) {
    subnet_destroy(&subnet);
    cli_set_user_error(cli_get(), "could not add subnet (%s)",
		       network_strerror(result));
    return CLI_ERROR_COMMAND_FAILED;
  }

  return CLI_SUCCESS;
}
Ejemplo n.º 6
0
int if_address_add_v6(struct ctrl_client * ctrl_client, struct rfpbuf * buffer)
{
  const struct rfp_ipv6_address * address = buffer->data;
  struct interface * ifp = if_lookup_by_index(ctrl_client->if_list, address->ifindex);
  struct connected * ifc;

  struct prefix p;

  memcpy(&p.u.prefix, &address->p, 16);
  p.prefixlen = address->prefixlen;
  p.family = AF_INET6;

  ifc = connected_add_by_prefix(ifp, &p, NULL);
  if(ifc == NULL)
    return 1;

  if(IS_OSPF6_SIBLING_DEBUG_MSG)
  {
    char prefix_str[INET6_ADDRSTRLEN+3]; // three extra chars for slash + two digits
    if(prefix2str(ifc->address, prefix_str, INET6_ADDRSTRLEN) != 1)
    {   
      zlog_debug("v6 addr: %s", prefix_str, ifc->address->prefixlen);
    }   
  }

//  check here for:
//    1. prefix matches
//    2. extract hostnum from host portion of address
//    3. if hostnum matches, this is the internal interface that should be recorded

  char inter_target_str[INET6_ADDRSTRLEN+3]; // three extra chars for slash + two digits
  struct prefix inter_target_p;

  sprintf(inter_target_str, "2001:db8:beef:10::%x/64", ctrl_client->hostnum);
  str2prefix(inter_target_str, &inter_target_p);
  
  // link up the internal connected address with a pointer at ctrl_client
  if(prefix_same(ifc->address, &inter_target_p))
  {
    ctrl_client->inter_con = ifc;
  }
  
  // since connected address is AF_INET6, needs to be updated
  ospf6_interface_connected_route_update(ifc->ifp);

  return 0;
}
Ejemplo n.º 7
0
/**
 * context: {}
 * tokens : {prefix}
 * options: {--output=FILE,--exact-match,--preserve-dups}
 */
static int cli_bgp_topology_recordroute(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  ip_pfx_t prefix;
  gds_stream_t * stream= gdsout;
  const char * arg= cli_get_arg_value(cmd, 0);
  int result;
  uint8_t options= 0;

  // Destination prefix
  if (str2prefix(arg, &prefix) < 0) {
    cli_set_user_error(cli_get(), "invalid prefix \"%s\"", arg);
    return CLI_ERROR_COMMAND_FAILED;
  }

  // Optional output file ?
  arg= cli_get_opt_value(cmd, "output");
  if (arg != NULL) {
    stream= stream_create_file(arg);
    if (stream == NULL) {
      cli_set_user_error(cli_get(), "unable to create \"%s\"", arg);
      return CLI_ERROR_COMMAND_FAILED;
    }
  }

  if (cli_has_opt_value(cmd, "exact-match"))
    options|= AS_RECORD_ROUTE_OPT_EXACT_MATCH;
  if (cli_has_opt_value(cmd, "preserve-dups"))
    options|= AS_RECORD_ROUTE_OPT_PRESERVE_DUPS;

  // Record routes
  result= aslevel_topo_record_route(stream, prefix, options);
  if (result != ASLEVEL_SUCCESS) {
    cli_set_user_error(cli_get(), "could not record route (%s)",
		       aslevel_strerror(result));
    return CLI_ERROR_COMMAND_FAILED;
  }

  if (stream != gdsout)
    stream_destroy(&stream);

  return CLI_SUCCESS;
}
Ejemplo n.º 8
0
static s32 bgp_api_parse_aggregate_packet(WS_ENV * ws_env,u16 type, u8 * pre, u8 as_set, u8 summary_only)
{
    web_bgp_aggregate_info_t info;
    if( !str2prefix( (s8*)pre, &info.p ) )
        goto parse_packet_error ;

    apply_mask (&info.p);
    info.as_set = as_set;
    info.summary_only = summary_only ;

    if( socket_api_put(type,&info,sizeof(web_bgp_aggregate_info_t)) < 0)
        goto socket_api_put_error ;

    return WS_OK;
parse_packet_error:
    socket_api_close();
    return ws_send_soap_error(ws_env,"aggregate parse packet error!") ;
socket_api_put_error:
    socket_api_close();
    return ws_send_soap_error(ws_env,"send packet error!") ;
}
Ejemplo n.º 9
0
static int cli_peer_readv(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  bgp_peer_t * peer= _peer_from_context(ctx);
  bgp_router_t* router= peer->router;
  const char * arg= cli_get_arg_value(cmd, 0);
  ip_pfx_t prefix;

  /* Get prefix */
  if (!strcmp(arg, "*")) {
    prefix.mask= 0;
  } else if (!str2prefix(arg, &prefix)) {
  } else {
    cli_set_user_error(cli_get(), "invalid prefix|* \"%s\"", arg);
    return CLI_ERROR_COMMAND_FAILED;
  }

  /* Re-advertise */
  if (bgp_router_peer_readv_prefix(router, peer, prefix)) {
    cli_set_user_error(cli_get(), "could not re-advertise");
    return CLI_ERROR_COMMAND_FAILED;
  }

  return CLI_SUCCESS;
}
Ejemplo n.º 10
0
static void do_test(struct bgp_table *table, const char *prefix,
		    uint32_t maxlen, ...)
{
	va_list arglist;
	struct list *list = list_new();
	struct prefix p;

	list->del = (void (*)(void *))bgp_unlock_node;

	va_start(arglist, maxlen);
	printf("\nDoing lookup for %s-%d\n", prefix, maxlen);
	if (str2prefix(prefix, &p) <= 0)
		assert(0);
	bgp_table_range_lookup(table, &p, maxlen, list);
	print_range_result(list);

	check_lookup_result(list, arglist);

	list_delete(&list);

	va_end(arglist);

	printf("Checks successfull\n");
}
Ejemplo n.º 11
0
/* General fucntion for static route. */
int
zebra_static_ipv4 (struct vty *vty, int add_cmd,
		   char *dest_str, char *mask_str, char *gate_str,
		   char *distance_str)
{
  int ret;
  u_char distance;
  struct prefix p;
  struct in_addr gate;
  struct in_addr mask;
  char *ifname;
  
  ret = str2prefix (dest_str, &p);
  if (ret <= 0)
    {
      vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
      return CMD_WARNING;
    }

  /* Cisco like mask notation. */
  if (mask_str)
    {
      ret = inet_aton (mask_str, &mask);
      if (ret == 0)
	{
	  vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
	  return CMD_WARNING;
	}
      p.prefixlen = ip_masklen (mask);
    }

  /* Apply mask for given prefix. */
  apply_mask (&p);

  /* Administrative distance. */
  if (distance_str)
    distance = atoi (distance_str);
  else
    distance = ZEBRA_STATIC_DISTANCE_DEFAULT;

  /* Null0 static route.  */
  if (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0)
    {
      if (add_cmd)
	static_add_ipv4 (&p, NULL, NULL, distance, 0);
      else
	static_delete_ipv4 (&p, NULL, NULL, distance, 0);
      return CMD_SUCCESS;
    }

  /* When gateway is A.B.C.D format, gate is treated as nexthop
     address other case gate is treated as interface name. */
  ret = inet_aton (gate_str, &gate);
  if (ret)
    ifname = NULL;
  else
    ifname = gate_str;

  if (add_cmd)
    static_add_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0);
  else
    static_delete_ipv4 (&p, ifname ? NULL : &gate, ifname, distance, 0);

  return CMD_SUCCESS;
}
Ejemplo n.º 12
0
        vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE);

  return 0;
}

/* RIPng enable on specified interface or matched network. */
DEFUN (ripng_network,
       ripng_network_cmd,
       "network IF_OR_ADDR",
       "RIPng enable on specified interface or network.\n"
       "Interface or address")
{
  int ret;
  struct prefix p;

  ret = str2prefix (argv[0], &p);

  /* Given string is IPv6 network or interface name. */
  if (ret)
    ret = ripng_enable_network_add (&p);
  else
    ret = ripng_enable_if_add (argv[0]);

  if (ret < 0)
    {
      vty_out (vty, "There is same network configuration %s%s", argv[0],
	       VTY_NEWLINE);
      return CMD_WARNING;
    }

  return CMD_SUCCESS;
Ejemplo n.º 13
0
bool
str2operand(operand_t *op, char const *str)
{
    int val, tag, size;
    bool rex_used;
    uint64_t ival;
    char const *ptr = str;
    char *wptr;

    while (*ptr++ == ' ');
    ptr--;

    {
        char strcopy[strlen(ptr)+1];
        opertype_t type;
        strlcpy(strcopy, ptr, sizeof strcopy);
        wptr = strcopy + strlen(strcopy) - 1;
        while (*wptr == ' ') {
            wptr--;
        }
        *(++wptr) = '\0';
        ptr = strcopy;

        type = str_op_get_type(ptr);

        switch (type) {
        case op_reg:
            if (!str2reg(ptr, &val, &tag, &size, &rex_used)) {
                return false;
            }
            op->type = type;
            op->size = size;
            ASSERT(op->size == size);
            op->val.reg = val;
            ASSERT(op->val.reg == val);
            op->tag.reg = tag;
            op->rex_used = rex_used;
            ASSERT(op->rex_used == rex_used);
            return true;
        case op_imm:
            if (!str2imm(ptr, &ival, &tag, &size)) {
                return false;
            }
            op->type = type;
            op->size = size;
            op->val.imm = ival;
            op->tag.imm = tag;
            return true;
        case op_seg:
            if (!str2seg(ptr, &val, &tag)) {
                return false;
            }
            op->type = type;
            op->size = 0;
            op->val.seg = val;
            ASSERT(op->val.seg == val);
            op->tag.seg = tag;
            return true;
        case op_prefix:
            if (!str2prefix(ptr, &val, &tag)) {
                return false;
            }
            op->type = type;
            op->size = 0;
            op->val.prefix = val;
            op->tag.prefix = tag;
            return true;
        default:
            ASSERT(0);
            break;
        }
        return false;
    }
}
Ejemplo n.º 14
0
	void *
cli_start_communication(void *context)
{
	char line[2048];
	char *params[100];
	char *token;
	uint32_t rid;
	int i = 0;

	while (fgets(line, sizeof line, stdin) != NULL) {
		line[strlen(line)-1] = '\0';
		token = strtok (line, " ");

		while (token != NULL) {
			params[i++] = token;
			token = strtok (NULL, " ,");
		}

		if (!i)
			continue;

		/* == GET  a mapping */
		/* Map-Request <eid> <nonce> */
		if (strcasecmp("map-request", params[0]) == 0 && i == 3) {
			rid = cli_request_add(params[1], (uint64_t)atoi(params[2]));
			generic_process_request(rid, &cli_fct);
		}
		/* == Stop the CLI */
		/* quit */
		if (strcasecmp("quit", params[0]) == 0) {
			cli_fct.stop_communication(NULL);
			return (NULL);
		}
		/* == Register a new mapping */
		/* example:
		   =======
		   map-register 6.6.6.6/24  version 65 A true TTL 56 -rloc address 127.0.0.1 priority 1 weight 100 m_priority 255 m_priority 0 reachable false -rloc address6 fe80::226:bbff:fe0e:882c priority 2  weight 100 m_priority 255 m_priority 0 reachable true
		   map-register 1.2.3.4/32 ACT 2 TTL 5 A true
		   map-request 6.6.6.6 123567
		   map-request 1.2.3.4 098765
		  */
		/* Map-Register <eid>  */
		if (strcasecmp("map-register", params[0]) == 0) {
			void *_mapping;
			struct prefix p1;
			struct mapping_flags *mflags;
			struct map_entry *entry = NULL;
			int j = 1;

			printf("p1:%s\n", params[j]);
			str2prefix (params[j], &p1);
			apply_mask(&p1);
			_mapping = generic_mapping_new(&p1);
			j++;
			int prev = 0;
			int count = 0;
			void *ptr = NULL;
			mflags = calloc(1, sizeof(struct mapping_flags));


			while (j < i - 1) {
					if (0 == strcasecmp(params[j], "-rloc")) {
					j++;
					if (prev && count > 0) {
						printf("ADD RLOC\n");
						assert(entry != NULL);
						generic_mapping_add_rloc(_mapping, entry);
						prev = 0;
					}
					printf("new rloc\n");
					entry = calloc(1, sizeof(struct map_entry));
					printf("%p\n", entry);
					continue;
				}else if (0 == strcasecmp(params[j], "priority")) {
					entry->priority = atoi(params[j+1]);
				}else if (0 == strcasecmp(params[j], "m_priority")) {
					entry->m_priority = atoi(params[j+1]);
				}else if (0 == strcasecmp(params[j], "weight")) {
					entry->weight = atoi(params[j+1]);
				}else if (0 == strcasecmp(params[j], "m_weight")) {
					entry->m_weight = atoi(params[j+1]);
				}else if (0 == strcasecmp(params[j], "reachable")) {
					entry->r = (strcasecmp(params[j+1], "true")==0);
				}else if (0 == strcasecmp(params[j], "local")) {
					entry->L = (strcasecmp(params[j+1], "true")==0);
				}else if (0 == strcasecmp(params[j], "rloc-probing")) {
					entry->p = (strcasecmp(params[j+1], "true")==0);
				}else if (0 == strcasecmp(params[j], "address")) {
					entry->rloc.sa.sa_family = AF_INET;
					ptr = &(entry->rloc.sin.sin_addr);
				}else if (0 == strcasecmp(params[j], "address6")) {
					entry->rloc.sa.sa_family = AF_INET6;
					ptr = &entry->rloc.sin6.sin6_addr;
				} /* mapping flags*/
				else if (0 == strcasecmp(params[j], "act")) {
					mflags->act = atoi(params[j+1]);
				}else if (0 == strcasecmp(params[j], "a")) {
					mflags->A = (strcasecmp(params[j+1], "true")==0);
				}else if (0 == strcasecmp(params[j], "version")) {
					mflags->version = atoi(params[j+1]);
				}else if (0 == strcasecmp(params[j], "ttl")) {
					mflags->ttl = atoi(params[j+1]);
				}
				/* an RLOC */
				if (ptr) {
					count++;
					inet_pton(entry->rloc.sa.sa_family, params[j+1], ptr);
					ptr = NULL;
				}

				//printf("%s -> %s\n", params[j], params[j+1]);
				j = j+2;
				prev = 1;
			}

			if (prev && count > 0) {
				printf("ADD RLOC\n");
				generic_mapping_add_rloc(_mapping, entry);
				prev = 0;
			}

			generic_mapping_set_flags(_mapping, mflags);
		}

		if (strcasecmp("map-database", params[0]) == 0) {
			assert(ms_db->lisp_db4);
			assert(ms_db->lisp_db6);
			list_db(ms_db->lisp_db4);
			list_db(ms_db->lisp_db6);
		}
		if (strcasecmp("reload", params[0]) == 0) {
			reconfigure();
		}

		if (strcasecmp("help", params[0]) == 0) {
			printf("""\t•map-database\n");
			printf("\t•map-register\n");
			printf("\t\tExample:\n \t\t\t map-register 6.6.6.6/24  version 65 A true TTL 56 \\ \n \t\t\t-rloc address 127.0.0.1 priority 1 weight 100 m_priority 255 m_priority 0 reachable false \\ \n \t\t\t -rloc address6 fe80::226:bbff:fe0e:882c priority 2 weight 100 m_priority 255 m_priority 0 reachable true\n");
			printf("\t•map-request\n");
			printf("\t\ttexample:\n \t\t\tmap-request 6.6.6.6 123567\n");
			printf("\t•reload\n");
		}
	}
	return (NULL);
}