static void tfw_bmb_report(unsigned long ts_start) { TFW_LOG("BOMBER SUMMARY:"); TFW_LOG(" total connections: %d\n", nconns * niters * nthreads); TFW_LOG(" attempted connections: %d\n", atomic_read(&bmb_conn_attempt)); TFW_LOG(" completed connections: %d\n", atomic_read(&bmb_conn_compl)); TFW_LOG(" error connections: %d\n", atomic_read(&bmb_conn_error)); TFW_LOG(" dropped connections: %d\n", atomic_read(&bmb_conn_drop)); TFW_LOG(" total requests: %d\n", atomic_read(&bmb_request_send)); TFW_LOG(" total time: %ldms\n", jiffies - ts_start); }
void tfw_close_listen_sockets(void) { down_read(&tfw_cfg.mtx); TFW_LOG("Close %u listening sockets\n", listen_socks_n); while (listen_socks_n) sock_release(protos[--listen_socks_n].listener); kfree(protos); up_read(&tfw_cfg.mtx); }
int tfw_open_listen_sockets(void) { struct sockaddr_in6 *addr; int r = -ENOMEM; __be16 ports[DEF_MAX_PORTS]; down_read(&tfw_cfg.mtx); TFW_LOG("Open %u listening sockets\n", tfw_cfg.listen->count); protos = kzalloc(sizeof(void *) * tfw_cfg.listen->count, GFP_KERNEL); if (!protos) goto out; for (listen_socks_n = 0; listen_socks_n < tfw_cfg.listen->count; ++listen_socks_n) { SsProto *proto; if (listen_socks_n > DEF_MAX_PORTS) { TFW_ERR("Too many listening sockets\n"); tfw_close_listen_sockets(); goto out; } /* * TODO If multiprotocol support is required, then here we must * have information for which protocol we're establishing * the new listener. So TfwAddrCfg must be extended with * protocol information (e.g. HTTP enum value). */ proto = protos + listen_socks_n; proto->type = TFW_FSM_HTTP; addr = (struct sockaddr_in6 *)(tfw_cfg.listen->addr + listen_socks_n); r = __open_listen_socket(proto, addr); if (r) { tfw_close_listen_sockets(); goto out; } ports[listen_socks_n] = addr->sin6_port; } tfw_filter_set_inports(ports, listen_socks_n); r = 0; out: up_read(&tfw_cfg.mtx); return r; }
static void tfw_bmb_release_sockets(int tn) { int i; TFW_LOG("Release connections.\n"); for (i = 0; i < nconns; i++) { if (bmb_task[tn].conn[i].sk) { tfw_connection_unlink_from_sk(bmb_task[tn].conn[i].sk); ss_close(bmb_task[tn].conn[i].sk); } } }
static int tfw_bmb_conn_recv(void *cdata, struct sk_buff *skb, unsigned int off) { if (verbose) { unsigned int data_off = 0; TFW_LOG("Server response:\n------------------------------\n"); ss_skb_process(skb, &data_off, tfw_bmb_print_msg, NULL); printk(KERN_INFO "\n------------------------------\n"); } __kfree_skb(skb); return TFW_PASS; }
static void tfw_bmb_msg_send(int tn, int cn) { TfwBmbTask *task = &bmb_task[tn]; int fz_tries = 0, r; TfwStr msg; TfwHttpMsg req; TfwMsgIter it; BUG_ON(!task->conn[cn].sk); do { if (++fz_tries > 10) { TFW_ERR("Too many fuzzer tries to generate request\n"); return; } r = fuzz_gen(&task->ctx, task->buf, task->buf + BUF_SIZE, 0, 1, FUZZ_REQ); if (r < 0) { TFW_ERR("Cannot generate HTTP request, r=%d\n", r); return; } if (r == FUZZ_END) fuzz_init(&task->ctx, true); } while (r != FUZZ_VALID); msg.ptr = task->buf; msg.skb = NULL; msg.len = strlen(msg.ptr); msg.flags = 0; if (!tfw_http_msg_create(&req, &it, Conn_Clnt, msg.len)) { TFW_WARN("Cannot create HTTP request.\n"); return; } if (verbose) TFW_LOG("Send request:\n" "------------------------------\n" "%s\n" "------------------------------\n", task->buf); tfw_http_msg_write(&it, &req, &msg); ss_send(task->conn[cn].sk, &req.msg.skb_list, true); atomic_inc(&bmb_request_send); }
static int __init tfw_bmb_init(void) { long i; volatile unsigned long ts_start; struct task_struct *task; int r = 0; if (tfw_addr_pton(&TFW_STR_FROM(server), &bmb_server_address)) { TFW_ERR("Unable to parse server's address: %s", server); return -EINVAL; } TFW_LOG("Started bomber module, server's address is %s\n", server); if (tfw_bmb_alloc()) return -ENOMEM; ts_start = jiffies; for (i = 0; i < nthreads; i++) { task = kthread_create(tfw_bmb_worker, (void *)i, "worker"); if (IS_ERR_OR_NULL(task)) { TFW_ERR("Unable to create worker\n"); r = -EINVAL; goto stop_threads; } bmb_task[i].task_struct = task; } atomic_set(&bmb_threads, nthreads); for (i = 0; i < nthreads; i++) wake_up_process(bmb_task[i].task_struct); wait_event_interruptible(bmb_task_wq, !atomic_read(&bmb_threads)); tfw_bmb_report(ts_start); stop_threads: tfw_bmb_stop_threads(); tfw_bmb_free(); return r; }