static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfa, void *data) { unsigned char *payload; int pay_len, match, rlen; u_int32_t id = display_pkt(nfa); pay_len = nfq_get_payload(nfa, &payload); #ifdef DEBUG printf("Content inspection...pay_len=%d\n", pay_len); #endif match = inspect_tcp(payload, pay_len); // return 1 if matched, 0 otherwise if (match && p_queue.count < QSIZE) { // if queue is full, let them pass //print_ip_pkt(payload, pay_len); // now lock the queue pthread_mutex_lock (&lock_queue); enqueue(&p_queue, payload, pay_len, id); #ifdef DEBUG printf("Matched packet. Queue size: %d\n", p_queue.count); #endif pthread_mutex_unlock (&lock_queue); sem_post(&sem_queue); // wake up sending threads return 0; } else { #ifdef DEBUG printf("No match found\n"); // should be ok for not locking the queue #endif pthread_mutex_lock (&lock_qh); rlen = nfq_set_verdict(qh, id, NF_ACCEPT, pay_len, payload); pthread_mutex_unlock (&lock_qh); return rlen; } }
UInt8 tal_write_packet(const UInt8 * data, const UInt8 len) { #ifdef UART BOOL uart_pause_needed = FALSE; #endif #ifdef DEBUGGING_TOOLS if(pause || ratchet || write_pause) { proceed = FALSE; synchronize_last_tick(); #if DEBUG_VERBOSE_LEVEL > 2 if(verbose_level > 2) { oncli_send_msg("\n\n%lu sending %u bytes:\n", TICK_TO_MS(get_tick_count()), len); } #endif #if DEBUG_VERBOSE_LEVEL > 5 if(verbose_level > 5) { display_pkt(data, len, NULL, 0, NULL, 0); } #endif #if DEBUG_VERBOSE_LEVEL > 2 if(verbose_level <= 5 && verbose_level > 2) { xdump(data, len); } #endif #if DEBUG_VERBOSE_LEVEL > 1 if(verbose_level == 2) { UInt16 raw_pid; if(get_raw_pid(&data[ON_ENCODED_PID_IDX], &raw_pid)) { oncli_send_msg("\n\nWrite Raw PID 0x%02X\n", raw_pid); } } #endif } while(pausing = (pause || (ratchet && !proceed))) { synchronize_last_tick(); oncli(); } proceed = FALSE; if(write_pause > 0) { pausing = TRUE; ont_set_timer(WRITE_PAUSE_TIMER, write_pause); while(!ont_inactive_or_expired(WRITE_PAUSE_TIMER)) { oncli(); // alow the user to enter commands while pausing } #if DEBUG_VERBOSE_LEVEL > 1 if(verbose_level > 1) { oncli_send_msg("Pause done\n"); } #endif pausing = FALSE; } #endif #ifdef WRITE_PAUSE #if WRITE_PAUSE_FACTOR > 0 { tick_t write_tick = get_tick_count() + MS_TO_TICK(WRITE_PAUSE_FACTOR); while(get_tick_count() < write_tick) { } } #endif #endif tx_rf_idx = 0; tx_rf_data = data; tx_rf_len = len; #ifdef UART while(cb_bytes_queued(&uart_tx_cb)) { uart_pause_needed = TRUE; } if(uart_pause_needed) { #ifdef DEBUGGING_TOOLS pausing = TRUE; #endif delay_ms(2); // slight pause to let the uart clear so nothing // gets garbled. #ifdef DEBUGGING_TOOLS pausing = FALSE; #endif } #endif // if UART is enabled // tal_turn_on_transmitter(); ENABLE_TX_BIT_INTERRUPTS(); return len; } // tal_write_packet //