static retvalue addpackages(struct target *target, const char *packagename, const char *controlchunk, /*@null@*/const char *oldcontrolchunk, const char *version, /*@null@*/const char *oldversion, const struct strlist *files, /*@only@*//*@null@*/struct strlist *oldfiles, /*@null@*/struct logger *logger, /*@null@*/struct trackingdata *trackingdata, architecture_t architecture, /*@null@*/const char *oldsource, /*@null@*/const char *oldsversion, /*@null@*/const char *causingrule, /*@null@*/const char *suitefrom) { retvalue result, r; struct table *table = target->packages; enum filetype filetype; assert (atom_defined(architecture)); if (architecture == architecture_source) filetype = ft_SOURCE; else if (architecture == architecture_all) filetype = ft_ALL_BINARY; else filetype = ft_ARCH_BINARY; /* mark it as needed by this distribution */ r = references_insert(target->identifier, files, oldfiles); if (RET_WAS_ERROR(r)) { if (oldfiles != NULL) strlist_done(oldfiles); return r; } /* Add package to the distribution's database */ if (oldcontrolchunk != NULL) { result = table_replacerecord(table, packagename, controlchunk); } else { result = table_adduniqrecord(table, packagename, controlchunk); } if (RET_WAS_ERROR(result)) { if (oldfiles != NULL) strlist_done(oldfiles); return result; } if (logger != NULL) logger_log(logger, target, packagename, version, oldversion, controlchunk, oldcontrolchunk, files, oldfiles, causingrule, suitefrom); r = trackingdata_insert(trackingdata, filetype, files, oldsource, oldsversion, oldfiles); RET_UPDATE(result, r); /* remove old references to files */ if (oldfiles != NULL) { r = references_delete(target->identifier, oldfiles, files); RET_UPDATE(result, r); strlist_done(oldfiles); } return result; }
static void client_send_cb(uv_write_t *req, int status) { struct client_context *client = req->data; struct remote_context *remote = client->remote; if (status == 0) { if (client->stage == XSTAGE_REQUEST) { receive_from_client(client); } else if (client->stage == XSTAGE_FORWARD) { receive_from_remote(remote); } else if (client->stage == XSTAGE_TERMINATE) { close_client(client); close_remote(remote); } } else { char addrbuf[INET6_ADDRSTRLEN + 1] = {0}; int port = ip_name(&client->addr, addrbuf, sizeof addrbuf); logger_log(LOG_ERR, "%s -> %s:%d failed: %s", client->target_addr, addrbuf, port, uv_strerror(status)); } free(req); }
void client_accept_cb(uv_stream_t *server, int status) { struct client_context *client = new_client(); struct remote_context *remote = new_remote(idle_timeout); client->remote = remote; remote->client = client; uv_timer_init(server->loop, remote->timer); uv_tcp_init(server->loop, &client->handle.tcp); uv_tcp_init(server->loop, &remote->handle.tcp); int rc = uv_accept(server, &client->handle.stream); if (rc == 0) { int namelen = sizeof client->addr; uv_tcp_getpeername(&client->handle.tcp, &client->addr, &namelen); reset_timer(remote); // start timer connect_to_remote(remote); } else { logger_log(LOG_ERR, "accept error: %s", uv_strerror(rc)); close_client(client); close_remote(remote); } }
int config_load(luna_state *state, const char *filename) { lua_State *L = NULL; /* Create lua environment */ if ((L = lua_newstate(&mm_lalloc, NULL))) { int status = 0; if (luaL_dofile(L, filename) == 0) { /* Both user and server must be set (== 0) */ if (config_get_userinfo(state, L) || config_get_serverinfo(state, L)) status = 1; else config_get_netinfo(state, L); } else { logger_log(state->logger, LOGLEV_ERROR, "Lua error: %s", lua_tostring(L, -1)); status = 1; } /* Cleanup */ lua_close(L); return status; } return 1; }
static void * conn_init(void *opaque, unsigned char *local, int locallen, unsigned char *remote, int remotelen) { raop_conn_t *conn; conn = calloc(1, sizeof(raop_conn_t)); if (!conn) { return NULL; } conn->raop = opaque; conn->raop_rtp = NULL; if (locallen == 4) { logger_log(conn->raop->logger, LOGGER_INFO, "Local: %d.%d.%d.%d", local[0], local[1], local[2], local[3]); } else if (locallen == 16) { logger_log(conn->raop->logger, LOGGER_INFO, "Local: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", local[0], local[1], local[2], local[3], local[4], local[5], local[6], local[7], local[8], local[9], local[10], local[11], local[12], local[13], local[14], local[15]); } if (remotelen == 4) { logger_log(conn->raop->logger, LOGGER_INFO, "Remote: %d.%d.%d.%d", remote[0], remote[1], remote[2], remote[3]); } else if (remotelen == 16) { logger_log(conn->raop->logger, LOGGER_INFO, "Remote: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", remote[0], remote[1], remote[2], remote[3], remote[4], remote[5], remote[6], remote[7], remote[8], remote[9], remote[10], remote[11], remote[12], remote[13], remote[14], remote[15]); } conn->local = malloc(locallen); assert(conn->local); memcpy(conn->local, local, locallen); conn->remote = malloc(remotelen); assert(conn->remote); memcpy(conn->remote, remote, remotelen); conn->locallen = locallen; conn->remotelen = remotelen; digest_generate_nonce(conn->nonce, sizeof(conn->nonce)); return conn; }
static void idle_state_service_event_handler( sMGMT_VIDEO_MSG *msg ) { if((msg->event_data.service.nal_unit->nal_unit[0] & 0x1F) == 0x07) { // Cache SPS. logger_log("MGMT_VIDEO:: New SPS NAL unit"); // Lock mutex. pthread_mutex_lock(&f_cblk.sps_mutex); if(f_cblk.sps_nal_unit != NULL) { free(f_cblk.sps_nal_unit); } // Free mutex. f_cblk.sps_nal_unit = msg->event_data.service.nal_unit; logger_log("MGMT_VIDEO:: New SPS NAL unit len %d", f_cblk.sps_nal_unit->nal_unit_len); pthread_mutex_unlock(&f_cblk.sps_mutex); } else if((msg->event_data.service.nal_unit->nal_unit[0] & 0x1F) == 0x08) { // Cache PPS. logger_log("MGMT_VIDEO:: New PPS NAL unit"); pthread_mutex_lock(&f_cblk.pps_mutex); if(f_cblk.pps_nal_unit != NULL) { free(f_cblk.pps_nal_unit); } pthread_mutex_unlock(&f_cblk.pps_mutex); f_cblk.pps_nal_unit = msg->event_data.service.nal_unit; } else { // Free unit. free(msg->event_data.service.nal_unit); } }
static void poll_cb(uv_poll_t *watcher, int status, int events) { struct tundev *tun; struct tundev_context *ctx; uint8_t *tunbuf, *m; ctx = container_of(watcher, struct tundev_context, watcher); tun = ctx->tun; tunbuf = malloc(PRIMITIVE_BYTES + tun->mtu); m = tunbuf + PRIMITIVE_BYTES; int mlen = read(ctx->tunfd, m, tun->mtu); if (mlen <= 0) { logger_log(LOG_ERR, "tun read error"); free(tunbuf); return; } struct iphdr *iphdr = (struct iphdr *) m; in_addr_t client_network = iphdr->saddr & htonl(ctx->tun->netmask); if (client_network != ctx->tun->network) { char *a = inet_ntoa(*(struct in_addr *) &iphdr->saddr); logger_log(LOG_ERR, "Invalid Source Address: %s", a); free(tunbuf); return; } if (ctx->connect == CONNECTED) { crypto_encrypt(tunbuf, m, mlen); tun_to_tcp_server(ctx, tunbuf, PRIMITIVE_BYTES + mlen); } else { free(tunbuf); if (ctx->connect == DISCONNECTED) { connect_to_server(ctx); } } }
static void remote_timer_expire(uv_timer_t *handle) { struct remote_context *remote = handle->data; struct client_context *client = remote->client; if (verbose) { char addrbuf[INET6_ADDRSTRLEN + 1] = {0}; uint16_t port = ip_name(&client->addr, addrbuf, sizeof addrbuf); if (client->stage < XSTAGE_FORWARD) { logger_log(LOG_WARNING, "%s:%d connection timeout", addrbuf, port); } else { logger_log(LOG_WARNING, "%s:%d <-> %s connection timeout", addrbuf, port, client->target_addr); } } assert(client->stage != XSTAGE_TERMINATE); request_ack(client, S5_REP_TTL_EXPIRED); }
/* Starts the event loop attached to the controller thread. */ static void * event_loop(void *ctrl_loop_) { assert(ctrl_loop_ != NULL); struct ctrl_loop *ctrl_loop = (struct ctrl_loop *)ctrl_loop_; thread_id_set(); logger_log(ctrl_loop->logger, LOG_INFO, "Thread started for DP control."); ev_ref(ctrl_loop->loop); //makes sure an empty loop stays alive ev_run(ctrl_loop->loop, 0/*flags*/); logger_log(ctrl_loop->logger, LOG_ERR, "Loop exited."); pthread_exit(NULL); return NULL; }
void cache_log(uint8_t atyp, const struct sockaddr *src_addr, const struct sockaddr *dst_addr, const char *host, uint16_t port, int hit) { char src[INET6_ADDRSTRLEN + 1] = {0}; char dst[INET6_ADDRSTRLEN + 1] = {0}; uint16_t src_port = 0, dst_port = 0; char *hint = hit ? "hit" : "miss"; src_port = ip_name(src_addr, src, sizeof src); if (atyp == ATYP_HOST) { logger_log(hit ? LOG_INFO : LOG_WARNING, "[udp] cache %s: %s:%d -> %s:%d", hint, src, src_port, host, ntohs(port)); } else { dst_port = ip_name(dst_addr, dst, sizeof dst); logger_log(hit ? LOG_INFO : LOG_WARNING, "[udp] cache %s: %s:%d -> %s:%d", hint, src, src_port, dst, dst_port); } }
/* Static initializer for the driver. */ struct pcap_drv * MALLOC_ATTR pcap_drv_init(struct port_drv *drv) { struct pcap_drv *pcap_drv = malloc(sizeof(struct pcap_drv)); pcap_drv->drv = drv; pcap_drv->logger = logger_mgr_get(LOGGER_NAME_PORT_DRV_PCAP); pcap_drv->ports_map = NULL; size_t i; for (i=0; i<MAX_PORTS; i++) { pcap_drv->ports[i] = NULL; } pcap_drv->ports_num = 0; pcap_drv->ports_rwlock = malloc(sizeof(pthread_rwlock_t)); pthread_rwlock_init(pcap_drv->ports_rwlock, NULL); struct pcap_drv_loop *pcap_drv_loop = malloc(sizeof(struct pcap_drv_loop)); pcap_drv_loop->logger = logger_mgr_get(LOGGER_NAME_PORT_DRV_PCAP_IF); pcap_drv->pcap_drv_loop = pcap_drv_loop; pcap_drv_loop->pcap_drv = pcap_drv; pcap_drv->thread = malloc(sizeof(pthread_t)); pcap_drv->loop = ev_loop_new(0/*flags*/); pcap_drv_loop->loop = pcap_drv->loop; ev_set_userdata(pcap_drv->loop, (void *)pcap_drv_loop); pcap_drv->notifier = mbox_new(pcap_drv->loop, NULL, NULL); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); int rc; if ((rc = pthread_create(pcap_drv->thread, &attr, event_loop, (void *)pcap_drv_loop)) != 0) { logger_log(pcap_drv->logger, LOG_ERR, "Unable to create thread (%d).", rc); //TODO: free structures return NULL; } logger_log(pcap_drv->logger, LOG_INFO, "PCAP initialized."); return pcap_drv; }
static void remote_recv_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { struct remote_context *remote; struct client_context *client; remote = stream->data; client = remote->client; if (nread > 0) { reset_timer(remote); struct packet *packet = &remote->packet; int rc = packet_filter(packet, buf->base, nread); if (rc == PACKET_COMPLETED) { uint8_t *m = packet->buf; int mlen = packet->size - PRIMITIVE_BYTES; int err = crypto_decrypt(m, packet->buf, packet->size); if (err) { goto error; } uv_read_stop(&remote->handle.stream); forward_to_client(client, m, mlen); } else if (rc == PACKET_INVALID) { goto error; } } else if (nread < 0){ if (nread != UV_EOF && verbose) { char addrbuf[INET6_ADDRSTRLEN + 1]; int port = ip_name(&client->target_addr, addrbuf, sizeof(addrbuf)); logger_log(LOG_ERR, "receive from %s:%d failed: %s", addrbuf, port, uv_strerror(nread)); } close_client(client); close_remote(remote); } return; error: logger_log(LOG_ERR, "invalid tcp packet"); close_client(client); close_remote(remote); }
static void client_send_cb(uv_udp_send_t *req, int status) { if (status) { logger_log(LOG_ERR, "forward to client failed: %s", uv_strerror(status)); } uv_buf_t *buf = (uv_buf_t *)(req + 1); free(buf->base); free(req); }
static void handle_invalid_packet(struct client_context *client) { int port = 0; char remote[INET_ADDRSTRLEN + 1]; port = ip_name(&client->addr, remote, sizeof(remote)); logger_log(LOG_ERR, "Invalid tcp packet from %s:%d", remote, port); packet_reset(&client->packet); close_client(client); }
void connect_to_remote(struct remote_context *remote) { remote->stage = XSTAGE_CONNECT; remote->connect_req.data = remote; int rc = uv_tcp_connect(&remote->connect_req, &remote->handle.tcp, &server_addr, remote_connect_cb); if (rc) { logger_log(LOG_ERR, "connect to server error: %s", uv_strerror(rc)); request_ack(remote->client, S5_REP_NETWORK_UNREACHABLE); } }
/* Creates and spawns a new controller handler. */ struct ctrl * MALLOC_ATTR ctrl_new(struct dp *dp) { struct ctrl *ctrl = malloc(sizeof(struct ctrl)); ctrl->dp = dp; ctrl->logger = logger_mgr_get(LOGGER_NAME_CTRL, dp_get_uid(dp)); struct ctrl_loop *ctrl_loop = malloc(sizeof(struct ctrl_loop)); ctrl_loop->dp = dp; ctrl_loop->logger = logger_mgr_get(LOGGER_NAME_CTRL_IF, dp_get_uid(dp)); size_t i; for (i=0; i<MAX_CONNS; i++) { ctrl_loop->conns[i] = NULL; } ctrl_loop->conns_num = 1; // "0" is used for broadcast ctrl->ctrl_loop = ctrl_loop; ctrl_loop->ctrl = ctrl; ctrl->thread = malloc(sizeof(pthread_t)); ctrl->loop = ev_loop_new(0/*flags*/); ctrl_loop->loop = ctrl->loop; ctrl->cmd_mbox = mbox_new(ctrl->loop, ctrl_loop, process_cmd); ctrl->msg_mbox = mbox_new(ctrl->loop, ctrl_loop, process_msg); ev_set_userdata(ctrl->loop, (void *)ctrl_loop); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); int rc; if ((rc = pthread_create(ctrl->thread, &attr, event_loop, (void *)ctrl_loop)) != 0) { logger_log(ctrl->logger, LOG_ERR, "Unable to create thread (%d).", rc); //TODO free structures return NULL; } logger_log(ctrl->logger, LOG_INFO, "Initialized."); return ctrl; }
/* timeslot_initialize_test: */ int timeslot_initialize_test(MPI_Comm comm) { int commsize; /* Synchronize clocks */ double synctime = hpctimer_wtime(); mpigclock_sync(comm, mpiperf_master_rank, MPIGCLOCK_SYNC_LINEAR); synctime = hpctimer_wtime() - synctime; MPI_Comm_size(comm, &commsize); logger_log("Clock synchronization time (commsize: %d, root: %d): %.6f sec.", commsize, mpiperf_master_rank, synctime); logger_log("Local clock offset (commsize: %d, root: %d): %.6f sec.", commsize, mpiperf_master_rank, mpigclock_offset()); bcasttime = measure_bcast_double(comm) * TIMESLOT_BCAST_OVERHEAD; logger_log("MPI_Bcast time: %.6f sec.", bcasttime); return MPIPERF_SUCCESS; }
static void resolve_cb(struct sockaddr *addr, void *data) { struct remote_context *remote = data; if (addr == NULL) { logger_log(LOG_ERR, "resolve %s failed: %s", remote->client->target_addr, resolver_lasterror(remote->host_query)); remote->stage = XSTAGE_TERMINATE; close_client(remote->client); close_remote(remote); } else { if (verbose) { logger_log(LOG_INFO, "connect to %s", remote->client->target_addr); } remote->addr = *addr; connect_to_remote(remote); } }
void sx_mgmt_video_init( void ) { logger_log("(mgmt_video_init): Invoked."); // Initialize resources. resources_init(); }
int main(int argc, char **argv) { logger_t *lg_test; lg_test = logger_init(); logger_set_level (lg_test, LOGGER_DEBUG); logger_set_callback(lg_test, cb, NULL); logger_log(lg_test, LOGGER_DEBUG, "test %s", "Hello world\n" ); return 0; }
static void inet_send_cb(uv_udp_send_t *req, int status) { if (status) { logger_log(LOG_ERR, "[UDP] Tun to network failed: %s", uv_strerror(status)); } uv_buf_t *buf = (uv_buf_t *) (req + 1); free(buf->base); free(req); }
void dns_destroy() { int i; for (i = 0; i < black_list.elements; i++) { free(black_list.domains[i]); } free(black_list.domains); black_list.elements = 0; logger_log(LOG_WARNING, "DNS filter stoped."); }
/* Instructs the controller handler to send a message to the controller(s). * Can be called from any thread; will send an async message to the connection thread. */ void ctrl_send_msg(struct ctrl *ctrl, size_t conn_id, of_xid_t xid, struct ofl_msg_header *msg) { struct ctrl_msg *message = malloc(sizeof(struct ctrl_msg)); message->conn_id = conn_id; message->xid = xid; message->msg = msg; logger_log(ctrl->logger, LOG_DEBUG, "Sending request for message."); mbox_send(ctrl->msg_mbox, (struct list_node *)message); }
static void remote_send_cb(uv_write_t *req, int status) { struct remote_context *remote = (struct remote_context *)req->data; struct client_context *client = remote->client; if (status == 0) { receive_from_client(client); } else { logger_log(LOG_ERR, "forward to remote failed: %s", uv_strerror(status)); } }
void packetproc_add_flow_ref(struct packetproc *packetproc, uint32_t processor_id, uint32_t input_id, uint32_t flow_ref) { struct pp *pp; pthread_mutex_lock(packetproc->mutex); HASH_FIND(hh, packetproc->pp_map, &processor_id, sizeof(size_t), pp); if(pp == NULL) { //TODO:send error logger_log(packetproc->logger, LOG_ERR, "Cant add reference to non existing pp (proc_id: %d)", processor_id); pthread_mutex_unlock(packetproc->mutex); return; } //TODO: check if already added struct pp_refs *pp_refs = malloc(sizeof(struct pp_refs)); pp_refs->ref = flow_ref; pp_refs->input_id = input_id; DL_APPEND(pp->flow_refs, pp_refs); pthread_mutex_unlock(packetproc->mutex); logger_log(packetproc->logger, LOG_DEBUG, "Added new flow reference to pp: %d", processor_id); }
void connect_to_remote(struct remote_context *remote) { remote->stage = XSTAGE_CONNECT; remote->connect_req.data = remote; int rc = uv_tcp_connect(&remote->connect_req, &remote->handle.tcp, &remote->addr, remote_connect_cb); if (rc) { logger_log(LOG_ERR, "connect to %s error: %s", remote->client->target_addr, uv_strerror(rc)); close_client(remote->client); close_remote(remote); } }
static void remote_timer_expire(uv_timer_t *handle) { struct remote_context *remote = handle->data; struct client_context *client = remote->client; if (verbose) { char addrbuf[INET6_ADDRSTRLEN + 1] = {0}; uint16_t port = ip_name(&client->addr, addrbuf, sizeof addrbuf); logger_log(LOG_WARNING, "%s:%d <-> %s connection timeout", addrbuf, port, client->target_addr); } close_client(remote->client); close_remote(remote); }
static void signal_cb(uv_signal_t *handle, int signum) { if (signum == SIGINT || signum == SIGQUIT) { char *name = signum == SIGINT ? "SIGINT" : "SIGQUIT"; logger_log(LOG_INFO, "Received %s, scheduling shutdown...", name); signal_close(); struct tundev *tun = handle->data; tun_stop(tun); } }
void message_destroy(message_t *msg){ logger_log(LOG_DEBUG, "[charcoal message] freeing message"); if(msg->body != NULL){ free(msg->body); } if(msg != NULL){ free(msg); } }
void logger_init() { Logger *l = &logger; l->fname = get_logdir(); l->fd = open(l->fname, O_CREAT | O_APPEND | O_WRONLY, 0777); if (l->fd < 0) { fprintf(stderr, "could not open logger fh: %s", strerror(errno)); exit(1); } logger_log("logger initialized"); }