Example #1
0
/**
 * @brief Feed a list packets into an eBPF program.
 * @details This is a mock function emulating the behavior of a running
 * eBPF program. It takes a list of input packets and iteratively parses them
 * using the given imported ebpf_filter function. The output defines whether
 * or not the packet is "dropped." If the packet is not dropped, its content is
 * copied and appended to an output packet list.
 *
 * @param pkt_list A list of input packets running through the filter.
 * @return The list of packets "surviving" the filter function
 */
pcap_list_t *feed_packets(packet_filter ebpf_filter, pcap_list_t *pkt_list, int debug) {
    pcap_list_t *output_pkts = allocate_pkt_list();
    uint32_t list_len = get_pkt_list_length(pkt_list);
    for (uint32_t i = 0; i < list_len; i++) {
        /* Parse each packet in the list and check the result */
        struct sk_buff skb;
        pcap_pkt *input_pkt = get_packet(pkt_list, i);
        skb.data = (void *) input_pkt->data;
        skb.len = input_pkt->pcap_hdr.len;
        int result = ebpf_filter(&skb);
        if (result != 0) {
            /* We copy the entire content to emulate an outgoing packet */
            pcap_pkt *out_pkt = copy_pkt(input_pkt);
            output_pkts = append_packet(output_pkts, out_pkt);
        }
        if (debug)
            printf("Result of the eBPF parsing is: %d\n", result);
    }
    return output_pkts;
}
Example #2
0
static void
on_ssdp_message (G_GNUC_UNUSED GSSDPClient *client,
                 G_GNUC_UNUSED const gchar *from_ip,
                 G_GNUC_UNUSED gushort      from_port,
                 _GSSDPMessageType          type,
                 SoupMessageHeaders        *headers,
                 G_GNUC_UNUSED gpointer     user_data)
{
        time_t arrival_time;
        
        arrival_time = time (NULL);
     
        if (type == _GSSDP_DISCOVERY_REQUEST)
                return;
        if (ip_filter != NULL && strcmp (ip_filter, from_ip) != 0)
                return;
        if (!capture_packets) 
                return;

        append_packet (from_ip, arrival_time, type, headers);
}