Example #1
0
/**
 * Update zone list.
 *
 */
ods_status
zonelist_update(zonelist_type* zl, const char* zlfile)
{
    zonelist_type* new_zlist = NULL;
    allocator_type* tmp_alloc = NULL;
    time_t st_mtime = 0;
    ods_status status = ODS_STATUS_OK;
    char* datestamp = NULL;

    ods_log_debug("[%s] update zone list", zl_str);
    if (!zl|| !zl->zones || !zlfile) {
        return ODS_STATUS_ASSERT_ERR;
    }
    /* is the file updated? */
    st_mtime = ods_file_lastmodified(zlfile);
    if (st_mtime <= zl->last_modified) {
        (void)time_datestamp(zl->last_modified, "%Y-%m-%d %T", &datestamp);
        ods_log_debug("[%s] zonelist file %s is unchanged since %s",
                      zl_str, zlfile, datestamp?datestamp:"Unknown");
        free((void*)datestamp);
        return ODS_STATUS_UNCHANGED;
    }
    /* create new zonelist */
    tmp_alloc = allocator_create(malloc, free);
    if (!tmp_alloc) {
        return ODS_STATUS_MALLOC_ERR;
    }
    new_zlist = zonelist_create(tmp_alloc);
    if (!new_zlist) {
        ods_log_error("[%s] unable to update zonelist: zonelist_create() "
                      "failed", zl_str);
        allocator_cleanup(tmp_alloc);
        return ODS_STATUS_ERR;
    }
    /* read zonelist */
    status = zonelist_read(new_zlist, zlfile);
    if (status == ODS_STATUS_OK) {
        zl->just_removed = 0;
        zl->just_added = 0;
        zl->just_updated = 0;
        new_zlist->last_modified = st_mtime;
        zonelist_merge(zl, new_zlist);
        (void)time_datestamp(zl->last_modified, "%Y-%m-%d %T", &datestamp);
        ods_log_debug("[%s] file %s is modified since %s", zl_str, zlfile,
                      datestamp?datestamp:"Unknown");
        free((void*)datestamp);
    } else {
        ods_log_error("[%s] unable to update zonelist: read file %s failed "
                      "(%s)", zl_str, zlfile, ods_status2str(status));
    }
    zonelist_free(new_zlist);
    allocator_cleanup(tmp_alloc);
    return status;
}
/**
 * Create query.
 *
 */
query_type*
query_create(void)
{
    allocator_type* allocator = NULL;
    query_type* q = NULL;
    allocator = allocator_create(malloc, free);
    if (!allocator) {
        return NULL;
    }
    q = (query_type*) allocator_alloc(allocator, sizeof(query_type));
    if (!q) {
        allocator_cleanup(allocator);
        return NULL;
    }
    q->allocator = allocator;
    q->buffer = NULL;
    q->tsig_rr = NULL;
    q->buffer = buffer_create(allocator, PACKET_BUFFER_SIZE);
    if (!q->buffer) {
        query_cleanup(q);
        return NULL;
    }
    q->tsig_rr = tsig_rr_create(allocator);
    if (!q->tsig_rr) {
        query_cleanup(q);
        return NULL;
    }
    q->edns_rr = edns_rr_create(allocator);
    if (!q->edns_rr) {
        query_cleanup(q);
        return NULL;
    }
    query_reset(q, UDP_MAX_MESSAGE_LEN, 0);
    return q;
}
Example #3
0
/**
 * Create a new task.
 *
 */
task_type*
task_create(task_id what, time_t when, void* zone)
{
    allocator_type* allocator = NULL;
    task_type* task = NULL;

    if (!zone) {
        return NULL;
    }
    allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] unable to create task: allocator_create() failed",
            task_str);
        return NULL;
    }
    task = (task_type*) allocator_alloc(allocator, sizeof(task_type));
    if (!task) {
        ods_log_error("[%s] unable to create task: allocator_alloc() failed",
            task_str);
        allocator_cleanup(allocator);
        return NULL;
    }
    task->allocator = allocator;
    task->what = what;
    task->interrupt = TASK_NONE;
    task->halted = TASK_NONE;
    task->when = when;
    task->halted_when = 0;
    task->backoff = 0;
    task->flush = 0;
    task->zone = zone;
    return task;
}
Example #4
0
static int __init mymodule(void) {
  int error =  1;
  int free_pages = nr_free_pages();//get the nr of free pages

#ifdef DEBUG_NOT_NOW
  printk(KERN_ALERT "Nr of Inactive Clean pages=%d\n",count_free_pages() );
#endif

if(free_pages > TARGET_PAGES) { //if there are available free pages
   if( !(fill_contiguous(TARGET_PAGES) ) )
    goto out_free;
#ifdef OOPS  
   if(nr_r_contiguous) 
     my_free(index); //free off the non contiguous part
#endif 
     reserve_pages(r_contiguous_array,nr_r_contiguous,1); //reserve
 
   if(allocator_initialise(r_contiguous_array,nr_r_contiguous)) {
#ifdef DEBUG
     printk(KERN_ALERT "Failed to initialise the allocator device:\n");
#endif
     goto out_free_allocator;
   }
 
   
}
  error = 0;
  goto out;
 out_free_allocator:
  allocator_cleanup(); //cleanup the allocator
  out_free:
  destroy_contiguous(&v_contiguous_list);
 out:
  return error;
}
Example #5
0
static void __exit mymodule_cleanup(void) {
  allocator_cleanup(); //cleanup the allocator
  reserve_pages(r_contiguous_array,nr_r_contiguous,0); //unreserve
  destroy_contiguous(&v_contiguous_list);
  my_free_pages(vmalloc_addr);
  return ;
}
/**
 * Create a new 'instant' duration.
 *
 */
duration_type*
duration_create(void)
{
    duration_type* duration;
    allocator_type* allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] cannot create: no allocator available",
            duration_str);
        return NULL;
    }

    duration = (duration_type*) allocator_alloc(allocator,
        sizeof(duration_type));
    if (!duration) {
        ods_log_error("[%s] cannot create: allocator failed", duration_str);
        allocator_cleanup(allocator);
        return NULL;
    }
    duration->allocator = allocator;
    duration->years = 0;
    duration->months = 0;
    duration->weeks = 0;
    duration->days = 0;
    duration->hours = 0;
    duration->minutes = 0;
    duration->seconds = 0;
    return duration;
}
/**
 * Clean up zone.
 *
 */
void
zone_cleanup(zone_type* zone)
{
    allocator_type* allocator;
    lock_basic_type zone_lock;
    lock_basic_type xfr_lock;
    if (!zone) {
        return;
    }
    allocator = zone->allocator;
    zone_lock = zone->zone_lock;
    xfr_lock = zone->xfr_lock;
    ldns_rdf_deep_free(zone->apex);
    adapter_cleanup(zone->adinbound);
    adapter_cleanup(zone->adoutbound);
    namedb_cleanup(zone->db);
    ixfr_cleanup(zone->ixfr);
    xfrd_cleanup(zone->xfrd);
    notify_cleanup(zone->notify);
    signconf_cleanup(zone->signconf);
    stats_cleanup(zone->stats);
    allocator_deallocate(allocator, (void*) zone->notify_command);
    allocator_deallocate(allocator, (void*) zone->notify_args);
    allocator_deallocate(allocator, (void*) zone->policy_name);
    allocator_deallocate(allocator, (void*) zone->signconf_filename);
    allocator_deallocate(allocator, (void*) zone->name);
    allocator_deallocate(allocator, (void*) zone);
    allocator_cleanup(allocator);
    lock_basic_destroy(&xfr_lock);
    lock_basic_destroy(&zone_lock);
    return;
}
/**
 * Create engine.
 *
 */
static engine_type*
engine_create(void)
{
    engine_type* engine;
    allocator_type* allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] unable to create engine: allocator_create() "
            "failed", engine_str);
        return NULL;
    }
    engine = (engine_type*) allocator_alloc(allocator, sizeof(engine_type));
    if (!engine) {
        ods_log_error("[%s] unable to create engine: allocator_alloc() "
            "failed", engine_str);
        allocator_cleanup(allocator);
        return NULL;
    }
    engine->allocator = allocator;
    engine->config = NULL;
    engine->workers = NULL;
    engine->drudgers = NULL;
    engine->cmdhandler = NULL;
    engine->cmdhandler_done = 0;
    engine->dnshandler = NULL;
    engine->xfrhandler = NULL;
    engine->pid = -1;
    engine->uid = -1;
    engine->gid = -1;
    engine->daemonize = 0;
    engine->need_to_exit = 0;
    engine->need_to_reload = 0;
    lock_basic_init(&engine->signal_lock);
    lock_basic_set(&engine->signal_cond);
    lock_basic_lock(&engine->signal_lock);
    engine->signal = SIGNAL_INIT;
    lock_basic_unlock(&engine->signal_lock);
    engine->zonelist = zonelist_create(engine->allocator);
    if (!engine->zonelist) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->taskq = schedule_create(engine->allocator);
    if (!engine->taskq) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->signq = fifoq_create(engine->allocator);
    if (!engine->signq) {
        engine_cleanup(engine);
        return NULL;
    }
    return engine;
}
Example #9
0
/**
 * Clean up task.
 *
 */
void
task_cleanup(task_type* task)
{
    allocator_type* allocator;
    if (!task) {
        return;
    }
    allocator = task->allocator;
    allocator_deallocate(allocator, (void*) task);
    allocator_cleanup(allocator);
    return;
}
/**
 * Clean up duration.
 *
 */
void
duration_cleanup(duration_type* duration)
{
    allocator_type* allocator;

    if (!duration) {
        return;
    }
    allocator = duration->allocator;
    allocator_deallocate(allocator, (void*) duration);
    allocator_cleanup(allocator);
    return;
}
/**
 * Cleanup query.
 *
 */
void
query_cleanup(query_type* q)
{
    allocator_type* allocator = NULL;
    if (!q) {
        return;
    }
    allocator = q->allocator;
    buffer_cleanup(q->buffer, allocator);
    tsig_rr_cleanup(q->tsig_rr);
    allocator_deallocate(allocator, (void*)q);
    allocator_cleanup(allocator);
    return;
}
Example #12
0
/**
 * Clean up DNS input adapter.
 *
 */
void
dnsin_cleanup(dnsin_type* addns)
{
    allocator_type* allocator = NULL;
    if (!addns) {
        return;
    }
    allocator = addns->allocator;
    acl_cleanup(addns->request_xfr, allocator);
    acl_cleanup(addns->allow_notify, allocator);
    tsig_cleanup(addns->tsig, allocator);
    allocator_deallocate(allocator, (void*) addns);
    allocator_cleanup(allocator);
    return;
}
Example #13
0
/**
 * Clean up DNS output adapter.
 *
 */
void
dnsout_cleanup(dnsout_type* addns)
{
    allocator_type* allocator = NULL;
    if (!addns) {
        return;
    }
    allocator = addns->allocator;
    acl_cleanup(addns->provide_xfr, allocator);
    acl_cleanup(addns->do_notify, allocator);
    tsig_cleanup(addns->tsig, allocator);
    allocator_deallocate(allocator, (void*) addns);
    allocator_cleanup(allocator);
    return;
}
/**
 * Create notify structure.
 *
 */
notify_type*
notify_create(void* xfrhandler, void* zone)
{
    notify_type* notify = NULL;
    allocator_type* allocator = NULL;
    if (!xfrhandler || !zone) {
        return NULL;
    }
    allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] unable to create notify structure: "
            "allocator_create() failed", notify_str);
        return NULL;
    }
    notify = (notify_type*) allocator_alloc(allocator, sizeof(notify_type));
    if (!notify) {
        ods_log_error("[%s] unable to create notify structure: "
            " allocator_alloc() failed", notify_str);
        allocator_cleanup(allocator);
        return NULL;
    }
    notify->allocator = allocator;
    notify->zone = zone;
    notify->xfrhandler = xfrhandler;
    notify->waiting_next = NULL;
    notify->secondary = NULL;
    notify->soa = NULL;
    notify->tsig_rr = tsig_rr_create(allocator);
    if (!notify->tsig_rr) {
        notify_cleanup(notify);
        return NULL;
    }
    notify->retry = 0;
    notify->query_id = 0;
    notify->is_waiting = 0;
    notify->handler.fd = -1;
    notify->timeout.tv_sec = 0;
    notify->timeout.tv_nsec = 0;
    notify->handler.timeout = NULL;
    notify->handler.user_data = notify;
    notify->handler.event_types =
        NETIO_EVENT_READ|NETIO_EVENT_TIMEOUT;
    notify->handler.event_handler = notify_handle_zone;
    return notify;
}
Example #15
0
/**
 * Main. start interface tool.
 *
 */
int
main(int argc, char* argv[])
{
    char* cmd = NULL;
    int ret = 0;
    allocator_type* clialloc = allocator_create(malloc, free);
    if (!clialloc) {
        fprintf(stderr,"error, malloc failed for client\n");
        exit(1);
    }

	/*	argv[0] is always the executable name so 
		argc is always 1 or higher */
	ods_log_assert(argc >= 1);
	
	/*	concat arguments an add 1 extra char for 
		adding '\n' char later on, but only when argc > 1 */
    cmd = ods_str_join(clialloc,argc-1,&argv[1],' ');

    if (argc > 1 && !cmd) {
        fprintf(stderr, "memory allocation failed\n");
        exit(1);
    }

    /* main stuff */
    if (!cmd) {
        ret = interface_start(cmd);
    } else {
        if (ods_strcmp(cmd, "-h") == 0 || ods_strcmp(cmd, "--help") == 0) {
            usage(stdout);
            ret = 1;
        } else {
            strcat(cmd,"\n");
            ret = interface_start(cmd);
        }
    }

    /* done */
    allocator_deallocate(clialloc, (void*) cmd);
    allocator_cleanup(clialloc);
    return ret;
}
Example #16
0
/**
 * Create engine.
 *
 */
static engine_type*
engine_create(void)
{
    engine_type* engine;
    allocator_type* allocator = allocator_create(malloc, free);
    if (!allocator) {
        return NULL;
    }
    engine = (engine_type*) allocator_alloc(allocator, sizeof(engine_type));
    if (!engine) {
        allocator_cleanup(allocator);
        return NULL;
    }
    engine->allocator = allocator;
    engine->config = NULL;
    engine->workers = NULL;
    engine->drudgers = NULL;
    engine->cmdhandler = NULL;
    engine->cmdhandler_done = 0;
    engine->pid = -1;
    engine->uid = -1;
    engine->gid = -1;
    engine->daemonize = 0;
    engine->need_to_exit = 0;
    engine->need_to_reload = 0;

    engine->signal = SIGNAL_INIT;
    lock_basic_init(&engine->signal_lock);
    lock_basic_set(&engine->signal_cond);

    engine->taskq = schedule_create(engine->allocator);
    if (!engine->taskq) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->signq = fifoq_create(engine->allocator);
    if (!engine->signq) {
        engine_cleanup(engine);
        return NULL;
    }
    return engine;
}
/**
 * Cleanup notify structure.
 *
 */
void
notify_cleanup(notify_type* notify)
{
    allocator_type* allocator = NULL;
    if (!notify) {
        return;
    }
    allocator = notify->allocator;
    if (notify->handler.fd != -1) {
        close(notify->handler.fd);
        notify->handler.fd = -1;
    }
    if (notify->soa) {
        ldns_rr_free(notify->soa);
    }
    tsig_rr_cleanup(notify->tsig_rr);
    allocator_deallocate(allocator, (void*) notify);
    allocator_cleanup(allocator);
    return;
}
Example #18
0
/**
 * Clean up engine.
 *
 */
void
engine_cleanup(engine_type* engine)
{
    size_t i = 0;
    allocator_type* allocator;
    cond_basic_type signal_cond;
    lock_basic_type signal_lock;

    if (!engine) {
        return;
    }
    allocator = engine->allocator;
    signal_cond = engine->signal_cond;
    signal_lock = engine->signal_lock;

    if (engine->workers && engine->config) {
        for (i=0; i < (size_t) engine->config->num_worker_threads; i++) {
            worker_cleanup(engine->workers[i]);
        }
        allocator_deallocate(allocator, (void*) engine->workers);
    }
#if HAVE_DRUDGERS
    if (engine->drudgers && engine->config) {
       for (i=0; i < (size_t) engine->config->num_signer_threads; i++) {
           worker_cleanup(engine->drudgers[i]);
       }
        allocator_deallocate(allocator, (void*) engine->drudgers);
    }
#endif
    schedule_cleanup(engine->taskq);
    fifoq_cleanup(engine->signq);
    cmdhandler_cleanup(engine->cmdhandler);
    engine_config_cleanup(engine->config);
    allocator_deallocate(allocator, (void*) engine);

    lock_basic_destroy(&signal_lock);
    lock_basic_off(&signal_cond);
    allocator_cleanup(allocator);
    return;
}
Example #19
0
/**
 * Create DNS output adapter.
 *
 */
dnsout_type*
dnsout_create(void)
{
    dnsout_type* addns = NULL;
    allocator_type* allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] unable to create dnsout: allocator_create() "
                      " failed", adapter_str);
        return NULL;
    }
    addns = (dnsout_type*) allocator_alloc(allocator, sizeof(dnsout_type));
    if (!addns) {
        ods_log_error("[%s] unable to create dnsout: allocator_alloc() "
                      " failed", adapter_str);
        allocator_cleanup(allocator);
        return NULL;
    }
    addns->allocator = allocator;
    addns->provide_xfr = NULL;
    addns->do_notify = NULL;
    addns->tsig = NULL;
    return addns;
}
Example #20
0
/**
 * Create a new zone.
 *
 */
zone_type*
zone_create(char* name, ldns_rr_class klass)
{
    allocator_type* allocator = NULL;
    zone_type* zone = NULL;

    if (!name || !klass) {
        return NULL;
    }
    allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] unable to create zone %s: allocator_create() "
            "failed", zone_str, name);
        return NULL;
    }
    zone = (zone_type*) allocator_alloc(allocator, sizeof(zone_type));
    if (!zone) {
        ods_log_error("[%s] unable to create zone %s: allocator_alloc()",
            "failed", zone_str, name);
        allocator_cleanup(allocator);
        return NULL;
    }
    zone->allocator = allocator;
    /* [start] PS 9218653: Drop trailing dot in domain name */
    if (strlen(name) > 1 && name[strlen(name)-1] == '.') {
        name[strlen(name)-1] = '\0';
    }
    /* [end] PS 9218653 */
    zone->name = allocator_strdup(allocator, name);
    if (!zone->name) {
        ods_log_error("[%s] unable to create zone %s: allocator_strdup() "
            "failed", zone_str, name);
        zone_cleanup(zone);
        return NULL;
    }
    zone->klass = klass;
    zone->default_ttl = 3600; /* TODO: configure --default-ttl option? */
    zone->apex = ldns_dname_new_frm_str(name);
    /* check zone->apex? */
    zone->notify_command = NULL;
    zone->notify_ns = NULL;
    zone->notify_args = NULL;
    zone->policy_name = NULL;
    zone->signconf_filename = NULL;
    zone->adinbound = NULL;
    zone->adoutbound = NULL;
    zone->zl_status = ZONE_ZL_OK;
    zone->task = NULL;
    zone->xfrd = NULL;
    zone->notify = NULL;
    zone->db = namedb_create((void*)zone);
    if (!zone->db) {
        ods_log_error("[%s] unable to create zone %s: namedb_create() "
            "failed", zone_str, name);
        zone_cleanup(zone);
        return NULL;
    }
    zone->ixfr = ixfr_create((void*)zone);
    if (!zone->ixfr) {
        ods_log_error("[%s] unable to create zone %s: ixfr_create() "
            "failed", zone_str, name);
        zone_cleanup(zone);
        return NULL;
    }
    zone->signconf = signconf_create();
    if (!zone->signconf) {
        ods_log_error("[%s] unable to create zone %s: signconf_create() "
            "failed", zone_str, name);
        zone_cleanup(zone);
        return NULL;
    }
    zone->stats = stats_create();
    lock_basic_init(&zone->zone_lock);
    lock_basic_init(&zone->xfr_lock);
    return zone;
}