Exemple #1
0
void
rpki_reset_session(void)
{
  RPKI_DEBUG("Resetting RPKI Session");
  if (rtr_is_running)
    {
      rtr_mgr_stop(rtr_config);
      rtr_mgr_free(rtr_config);
      rtr_is_running = 0;
    }
  rpki_start();
}
Exemple #2
0
void
rpki_finish(void)
{
  RPKI_DEBUG("Stopping");
  struct rtr_mgr_group *groups;
  unsigned int length;
  groups = rtr_config->groups;
  length = rtr_config->len;

  rtr_mgr_stop(rtr_config);
  rtr_mgr_free(rtr_config);
  rtr_is_running = 0;
  free_rtr_mgr_groups(groups, length);
  delete_cache_group_list();
}
Exemple #3
0
int main(void)
	{
	//create a TCP transport socket
	int retval = 0;
	struct tr_socket tr_tcp;
	char tcp_host[] = "rpki-validator.realmv6.org";
	char tcp_port[] = "8282";

	struct tr_tcp_config tcp_config = {
	tcp_host, //IP
	tcp_port, //Port
	NULL      //Source address
	};
	tr_tcp_init(&tcp_config, &tr_tcp);

	struct rtr_socket rtr_tcp;

	rtr_tcp.tr_socket = &tr_tcp;

	struct rtr_mgr_group groups[1];

	groups[0].sockets = malloc(sizeof(struct rtr_socket *));
	groups[0].sockets_len = 1;
	groups[0].sockets[0] = &rtr_tcp;
	groups[0].preference = 1;

	struct tr_socket tr_tcp2;
	struct rtr_socket rtr_tcp2;
	struct rtr_mgr_group group2;

	tr_tcp_init(&tcp_config, &tr_tcp2);
	rtr_tcp2.tr_socket = &tr_tcp2;
	group2.sockets = malloc(sizeof(struct rtr_socket *));
	group2.sockets_len = 1;
	group2.sockets[0] = &rtr_tcp2;
	group2.preference = 2;

	struct rtr_mgr_config *conf;

	rtr_mgr_init(&conf, groups, 1, 30, 600, 600, NULL, NULL, &connection_status_callback, NULL);

	//start the connection manager
	rtr_mgr_start(conf);

	int sleep_counter = 0;
	// wait 20 sec till at least one group is fully synchronized with the server
	// otherwise EXIT_FAILURE.
	while (!rtr_mgr_conf_in_sync(conf)) {
		sleep_counter++;
		if (connection_status == RTR_MGR_ERROR || sleep_counter > connection_timeout)
			return EXIT_FAILURE;

		sleep(1);
	}

	assert(conf->len == 1);

	retval = rtr_mgr_add_group(conf, &group2);
	assert(retval == RTR_SUCCESS);

	//checking behavior in case the group preference already exists
	//by adding the same group twice.
	retval = rtr_mgr_add_group(conf, &group2);
	assert(retval == RTR_INVALID_PARAM);

	tommy_node *node = tommy_list_head(&conf->groups->list);
	struct rtr_mgr_group_node *group_node = node->data;
	struct rtr_mgr_group_node *group_node2 = node->next->data;

	assert(group_node->group->preference == 1);
	assert(group_node2->group->preference == 2);
	assert(conf->len == 2);

	rtr_mgr_remove_group(conf, 1);

	node = tommy_list_head(&conf->groups->list);
	group_node = node->data;
	assert(group_node->group->preference == 2);
	assert(conf->len == 1);

	struct tr_socket tr_tcp3;
	struct rtr_socket rtr_tcp3;
	struct rtr_mgr_group group3;

	tr_tcp_init(&tcp_config, &tr_tcp3);
	rtr_tcp3.tr_socket = &tr_tcp3;
	group3.sockets = malloc(sizeof(struct rtr_socket *));
	group3.sockets_len = 1;
	group3.sockets[0] = &rtr_tcp3;
	group3.preference = 3;

	struct tr_socket tr_tcp4;
	struct rtr_socket rtr_tcp4;
	struct rtr_mgr_group group4;

	tr_tcp_init(&tcp_config, &tr_tcp4);
	rtr_tcp4.tr_socket = &tr_tcp4;
	group4.sockets = malloc(sizeof(struct rtr_socket *));
	group4.sockets_len = 1;
	group4.sockets[0] = &rtr_tcp4;
	group4.preference = 4;

	rtr_mgr_add_group(conf, &group4);

	// remove group 2 so group 4 becomes the active group.
	rtr_mgr_remove_group(conf, 2);

	// add group 3 which has a higher preference than group 4
	// and check whether it will be set as the active group.
	rtr_mgr_add_group(conf, &group3);

	node = tommy_list_head(&conf->groups->list);
	group_node = node->data;
	assert(group_node->group->preference == 3);

	//try to remove non-existent group
	retval = rtr_mgr_remove_group(conf, 10);
	assert(retval == RTR_ERROR);

	struct tr_socket tr_tcp5;
	struct rtr_socket rtr_tcp5;
	struct rtr_mgr_group group5;

	tr_tcp_init(&tcp_config, &tr_tcp5);
	rtr_tcp5.tr_socket = &tr_tcp5;
	group5.sockets = malloc(sizeof(struct rtr_socket *));
	group5.sockets_len = 1;
	group5.sockets[0] = &rtr_tcp5;
	group5.preference = 5;

	//add 100 groups
	for (int i = 0; i < 100; i++) {
		retval = rtr_mgr_add_group(conf, &group5);
		group5.preference++;
		assert(retval == RTR_SUCCESS);
	}

	//remove 100 groups
	for (int i = 104; i >= 5; i--) {
		retval = rtr_mgr_remove_group(conf, i);
		assert(retval == RTR_SUCCESS);
	}

	rtr_mgr_remove_group(conf, 4);

	//try to remove last remainig group.
	retval = rtr_mgr_remove_group(conf, 3);
	assert(retval == RTR_ERROR);

	rtr_mgr_stop(conf);
	rtr_mgr_free(conf);
	free(groups[0].sockets);
	free(group2.sockets);
	free(group3.sockets);
	free(group4.sockets);
	free(group5.sockets);
}
Exemple #4
0
int main(int argc, char *argv[])
{
	/* check arguments, need hostname/IP and port of cache-server */
	if (argc < 3) {
		printf("Usage: %s [host] [port]\n", argv[0]);
		return EXIT_FAILURE;
	}

	struct tr_socket tr_tcp;
	struct tr_tcp_config tcp_config = { argv[1], argv[2], NULL };
	struct rtr_socket rtr_tcp;
	struct rtr_mgr_config *conf;
	struct rtr_mgr_group groups[1];

	/* init a TCP transport and create rtr socket */
	tr_tcp_init(&tcp_config, &tr_tcp);
	rtr_tcp.tr_socket = &tr_tcp;

	/* create a rtr_mgr_group array with 1 element */
	groups[0].sockets = malloc(1 * sizeof(struct rtr_socket *));
	groups[0].sockets_len = 1;
	groups[0].sockets[0] = &rtr_tcp;
	groups[0].preference = 1;

	if (rtr_mgr_init(&conf, groups, 1, 30, 600, 600, NULL, NULL,
			 &connection_status_callback, NULL) < 0)
		return EXIT_FAILURE;

	rtr_mgr_start(conf);

	char input[256];
	int sleep_counter = 0;

	/* wait till at least one rtr_mgr_group is synchronized with server */
	while (!rtr_mgr_conf_in_sync(conf)) {
		if (connection_error(connection_status))
			return EXIT_FAILURE;

		sleep(1);
		sleep_counter++;
		if (sleep_counter >= connection_timeout) {
			/*
			 * Wait for input before printing "timeout",
			 * to avoid "broken pipee error while communicating
			 * with the Python program
			 */
			if (fgets(input, 256, stdin))
				;
			printf("timeout\n");
			fflush(stdout);
			return EXIT_FAILURE;
		}
	}

	char ip[128];
	int mask;
	int asn;
	int counter;
	/* loop for input */
	while (1) {
		int input_len;
		int spaces;

		/* recheck connection, exit on failure */
		if (connection_error(connection_status))
			return EXIT_FAILURE;

		/* try reading from stdin, exit on failure */
		if (!fgets(input, 256, stdin)) {
			printf("input error\n");
			return EXIT_FAILURE;
		}

		/* remove newline, if present */
		input_len = strlen(input) - 1;
		if (input[input_len] == '\n')
			input[input_len] = '\0';

		/* check if there are exactly 3 arguments */
		spaces = 0;
		for (counter = 0; counter < input_len; counter++) {
			if (input[counter] == ' ' &&
			    input[counter + 1] != ' ' &&
			    input[counter + 1] != '\0' && counter != 0)
				spaces++;
		}

		/* check input matching pattern */
		if (spaces != 2) {
			printf("Arguments required: IP Mask ASN\n");
			fflush(stdout);
			continue;
		}

		char delims[] = " ";
		char *input_tok = NULL;

		input_tok = strtok(input, delims);
		strcpy(ip, input_tok);
		input_tok = strtok(NULL, delims);
		mask = atoi(input_tok);
		input_tok = strtok(NULL, delims); asn = atoi(input_tok);

		struct lrtr_ip_addr pref;
		enum pfxv_state result;
		struct pfx_record *reason = NULL;
		unsigned int reason_len = 0;

		lrtr_ip_str_to_addr(ip, &pref);
		/* do validation */
		pfx_table_validate_r(groups[0].sockets[0]->pfx_table, &reason,
				     &reason_len, asn, &pref, mask, &result);

		int validity_code = -1;
		/* translate validation result */
		if (result == BGP_PFXV_STATE_VALID)
			validity_code = 0;
		else if (result == BGP_PFXV_STATE_NOT_FOUND)
			validity_code = 1;
		else if (result == BGP_PFXV_STATE_INVALID)
			validity_code = 2;

		/* IP Mask BGP-ASN| */
		printf("%s %d %d|", ip, mask, asn);

		/* ROA-ASN IP MaskMin MaskMax, ... */
		if (reason && (reason_len > 0)) {
			unsigned int i;

			for (i = 0; i < reason_len; i++) {
				char tmp[100];

				lrtr_ip_addr_to_str(&reason[i].prefix,
						    tmp, sizeof(tmp));
				printf("%u %s %u %u",
				       reason[i].asn, tmp,
				       reason[i].min_len,
				       reason[i].max_len);
				if ((i + 1) < reason_len)
					printf(",");
			}
		}

		/* |validity_code */
		printf("|%d", validity_code);

		printf("\n");
		fflush(stdout);
	}

	rtr_mgr_stop(conf);
	rtr_mgr_free(conf);
	free(groups[0].sockets);

	return EXIT_SUCCESS;
}
//int validatePrefix(char* ip, int mask, int asn){
int main(int argc, char *argv[]) {
	if(argc<3) {
		printf("Usage: %s [host] [port]\n", argv[0]);
		return 0;
	}
	//create a TCP transport socket
	tr_socket tr_tcp1;
	tr_tcp_config tcp_config1 = { argv[1], //IP, old: "rpki.realmv6.org"
			argv[2] //Port, old: "42420"
			};
	tr_tcp_init(&tcp_config1, &tr_tcp1);

	//create 3 rtr_sockets and associate them with the transprort sockets
	rtr_socket rtr_tcp1;
	rtr_tcp1.tr_socket = &tr_tcp1;

	//create a rtr_mgr_group array with 1 element
	rtr_mgr_group groups[1];
	//The first group contains both TCP RTR sockets
	groups[0].sockets = malloc(1 * sizeof(rtr_socket*));
	groups[0].sockets_len = 1;
	groups[0].sockets[0] = &rtr_tcp1;
	groups[0].preference = 1; //Preference value of this group
	//create a rtr_mgr_config struct that stores the group
	rtr_mgr_config conf;
	conf.groups = groups;
	conf.len = 1; //1 element in the groups array
	//initialize all rtr_sockets in the server pool with the same settings
	rtr_mgr_init(&conf, 240, 520, NULL);
	//start the connection manager
	rtr_mgr_start(&conf);
	//wait till at least one rtr_mgr_group is fully synchronized with the server
	while (!rtr_mgr_conf_in_sync(&conf))
		sleep(1);

	char ip[128];
	int mask;
	int asn;
	int counter;
	int spaces;

	while (1) {
		char input[256];
		int inputLength;

		fgets(input, 256, stdin);
		// Remove newline, if present
		inputLength = strlen(input) - 1;
		if (input[inputLength] == '\n')
			input[inputLength] = '\0';


		// Check if there are exactly 3 arguments
		spaces = 0;
		for (counter = 0; counter < inputLength; counter++) {
			if (input[counter] == ' '
					&& input[counter+1] != ' '
					&& input[counter+1] != '\0'
					&& counter != 0) {
				spaces++;
			}
		}

		if (spaces != 2) {
			//break;
			//printf("Arguments required: IP, Mask, ASN, %d\n", spaces);
			//fflush(stdout);
			printf("Next\n");
			continue;
		}

		char delims[] = " ";
		char *inputToken = NULL;
		inputToken = strtok(input, delims);
		strcpy(ip, inputToken);

		inputToken = strtok(NULL, delims);
		mask = atoi(inputToken);

		inputToken = strtok(NULL, delims);
		asn = atoi(inputToken);

		//validate the BGP-Route ip/mask, origin ASN: asn
		ip_addr pref;
		ip_str_to_addr(ip, &pref);
		pfxv_state result;
		pfx_record* reason = NULL;
		unsigned int reason_len = 0;
		//rtr_mgr_validate(&conf, asn, &pref, mask, &result);
		pfx_table_validate_r(conf.groups[0].sockets[0]->pfx_table, &reason,
				&reason_len, asn, &pref, mask, &result);
		int validityNr = 0;

		if (result == BGP_PFXV_STATE_NOT_FOUND) {
			validityNr = -1;
		} else if (result == BGP_PFXV_STATE_INVALID) {
			validityNr = 0;
		} else if (result == BGP_PFXV_STATE_VALID) {
			validityNr = 1;
		}
		
		// |ValidityNr
		printf("%d|", validityNr);
		
		// IP Mask BGP-ASN|
		printf("%s %d %d", ip, mask, asn);
		
		if(validityNr>=0)
			printf("|");

		// ROA-ASN IP MaskMin MaskMax, ..
		if (reason != NULL && reason_len > 0) {
			unsigned int i;
			for (i = 0; i < reason_len; i++) {
				char tmp[100];
				ip_addr_to_str(&(reason[i].prefix), tmp, sizeof(tmp));
				printf("%u %s %u %u", reason[i].asn, tmp,
						reason[i].min_len, reason[i].max_len);
				if ((i + 1) < reason_len)
					printf(",");
			}
		}

		

		printf("\n");
		fflush(stdout);
	}
	rtr_mgr_stop(&conf);
	rtr_mgr_free(&conf);
	free(groups[0].sockets);
}