Exemplo n.º 1
0
Arquivo: scan.c Projeto: irrdnet/irrd
/* JMH - The serial number file is important only for mirrors
 *       and for authoritative databases.  If its not there, starting
 *	 from zero is fine.  This function could happily be void,
 *	 except that we can use it as a existance test for the file
 *	 and that it contains a valid u_long
 */
int scan_irr_serial (irr_database_t *database) {
  char tmp[BUFSIZE], file[BUFSIZE];
  FILE *fp;
  uint32_t serial = 0;
  int ret_code = 0;

  strcpy (tmp, database->name);
  convert_toupper (tmp);

  sprintf (file, "%s/%s.CURRENTSERIAL", IRR.database_dir, tmp);
  fp = fopen (file, "r");

  if (fp != NULL) {
    memset (tmp, 0, sizeof (tmp));
    if (fgets (tmp, sizeof (tmp), fp) != NULL) {
      if (convert_to_32 (tmp, &serial) == 1) {
	database->serial_number = serial;
	ret_code = 1;
      }
      else
        database->serial_number = 0;
    }
    fclose (fp);
  }

  return ret_code;
}
Exemplo n.º 2
0
Arquivo: scan.c Projeto: irrdnet/irrd
/* Write to disk the current serial value for DB (db->name).
 *
 * Function was rewritten to return a value to indicate if
 * there were any errors in writing the serial value and also
 * to avoid buffering issues.  This is part of our support for 
 * atomic transactions.
 *
 * Note: Later we should write the current serial value as the
 * first line in the DB in a fixed field.  The original choice to
 * have a seperate current serial file was (IMHO) a poor choice.
 *
 * Input:
 *  -pointer to the DB struct so we know the name of the DB 
 *   and the current serial value to write to disk (db)
 *
 * Return:
 *  -1 if the current serial value was written to disk without error.
 *  -0 otherwise.
 */
int write_irr_serial (irr_database_t *db) {
  int ret_code = 0;
  char dbname[BUFSIZE], file[BUFSIZE], serial[20];
  int fd;

  /* make the current serial file name */
  strcpy (dbname, db->name);
  convert_toupper (dbname);
  sprintf (file, "%s/%s.CURRENTSERIAL", IRR.database_dir, dbname);

  /* now write the current serial to file */
  if ((fd = open (file, O_WRONLY|O_TRUNC|O_CREAT, 0644)) >= 0) {
    sprintf (serial, "%u", db->serial_number);
    if (write (fd, serial, strlen (serial)) > 0)  {
      SetStatusString (IRR.statusfile, dbname, "currentserial", serial);
      ret_code = 1;
    } else
      trace (ERROR, default_trace, "write_irr_serial (): file write error: (%s)\n",
	     strerror (errno));

    close (fd);
  }
  else
    trace (ERROR, default_trace, "write_irr_serial (): file open error: (%s)\n",
	   strerror (errno));

  return ret_code;
}
Exemplo n.º 3
0
Arquivo: scan.c Projeto: irrdnet/irrd
void write_irr_serial_export (uint32_t serial, irr_database_t *database) {
  char db[BUFSIZE], file[BUFSIZE], serial_out[20];
  FILE *fp;

  if (database->export_filename != NULL) 
    strcpy (db, database->export_filename);
  else
    strcpy (db, database->name);
  convert_toupper(db);

  sprintf (file, "%s/%s.CURRENTSERIAL", IRR.ftp_dir, db);
  if ((fp = fopen (file, "w")) != NULL) {
    sprintf (serial_out, "%u", serial);
    fwrite (serial_out, 1, strlen (serial_out), fp);
    fclose (fp);
  }
  SetStatusString (IRR.statusfile, db, "lastexport", serial_out);
}
Exemplo n.º 4
0
/* as-set/route-set expansion !ias-bar */
void irr_set_expand (irr_connection_t *irr, char *name)
{
    irr_database_t *database;
    time_t start_time;
    GArray *array;
    GQueue *stack;
    GHashTable *hash_member_examined;
    member_examined_hash_t *member_examined_ptr;
    LINKED_LIST *ll_setlist;
    char *set_name, *last_set_name, *mstr, *db;
    char *range_op, abuf[BUFSIZE];
    char *lasts = NULL;
    int i, first, dup, expand_flag = NO_EXPAND;
    hash_spec_t *hash_spec;

    if (strchr(name, ',') != NULL) {
        strtok_r(name, ",", &lasts);
        /* check if we are expanding a route-set */
        if ( (set_name = strchr(name, ':')) != NULL)
            set_name++;
        else
            set_name = name;
        if (!strncasecmp (set_name, "rs-", 3))
            expand_flag = ROUTE_SET_EXPAND;
        else
            expand_flag = OTHER_EXPAND;
    }

    start_time = time(NULL);
    convert_toupper (name);
    stack = g_queue_new();
    hash_member_examined = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)HashMemberExaminedDestroy);
    ll_setlist = LL_Create (LL_DestroyFunction, free, NULL);
    mstr = rpsl_macro_expand_add (" ", name, irr, NULL);
    g_queue_push_head(stack, mstr);
    member_examined_ptr = irrd_malloc(sizeof(member_examined_hash_t));
    member_examined_ptr->key = strdup(name);
    g_hash_table_insert(hash_member_examined, member_examined_ptr->key, member_examined_ptr);

    while (!g_queue_is_empty(stack)) {
        if ( IRR.expansion_timeout > 0 ) {
            if ( (time(NULL) - start_time) > IRR.expansion_timeout ) {
                trace (ERROR, default_trace, "irr_set_expand(): Set expansion timeout\n");
                sprintf(abuf, "Expansion maximum CPU time exceeded: %d seconds", IRR.expansion_timeout);
                irr_send_error(irr, abuf);
                goto getout;
            }
        }
        mstr = (char *) g_queue_pop_head(stack);
        /* might want to check the examined list to see if this set name
           has been examined already */
        first = 1;
        lasts = NULL;
        range_op = strtok_r (mstr, ",", &lasts);
        if (!strcmp (range_op, " ")) range_op = NULL;
        set_name = strtok_r (NULL, ",", &lasts);

        irr_lock_all(irr); /* lock db's while searching */
        while ((db = strtok_r (NULL, ",", &lasts)) != NULL) {
            if ((database = find_database (db)) == NULL) {
                trace (ERROR, default_trace, "irr_set_expand(): Database not found %s\n", db);
                sprintf(abuf, "Database not found: %s", db);
                irr_send_error(irr, abuf);
                goto getout;
            }
            make_setobj_key (abuf, set_name);
            if ((hash_spec = fetch_hash_spec (database, abuf, UNPACK)) != NULL) {
                first = 0;
                update_members_list (database, range_op, AF_INET, expand_flag,
                                     hash_member_examined, ll_setlist, hash_spec->ll_1,
                                     stack, irr);
                mbrs_by_ref_set (database, range_op, AF_INET, expand_flag, ll_setlist,
                                 set_name, hash_spec->ll_2, irr);
                Delete_hash_spec (hash_spec);
            }
            if (first == 0)
                break;
        }
        irr_unlock_all(irr);
        free (mstr);
    }

    first = 1;
    dup = 0;
    i = 0;
    last_set_name = "";
    array = g_array_sized_new(FALSE, TRUE, sizeof(char*), ll_setlist->count);
    LL_ContIterate (ll_setlist, set_name) {
        g_array_append_val(array, set_name);
    }