EtherateMT Notes

Packet MMAP Notes:

    /*
     PACKET_MMAP buffer size calculator
    ------------------------------------
    Definitions:

        : is the maximum size of allocable with kmalloc (see /proc/slabinfo)
    : depends on the architecture -- sizeof(void *)
       : depends on the architecture -- PAGE_SIZE or getpagesize (2)
       : is the value defined with MAX_ORDER
      : it's an upper bound of frame's capture size (more on this later)

     = 8096 bytes  from /proc/slabinfo
     = 8 bytes
     = 4096 bytes  from /usr/include/x86_64-linux-gnu/sys/user.h
     = 11
     = 1514 bytes

     = 8096/8 = 1012 blocks
     = 4096 << 11 = 8 MiB.
    128 blocks * 8 MBs == 1024MBs
    */

    psock_tpacket.c:
    struct block_desc {
        uint32_t version;
        uint32_t offset_to_priv;
        struct tpacket_hdr_v1 h1;
    };

    // if_packet.h:
    struct tpacket_hdr_v1 {
        __u32   block_status;
        __u32   num_pkts;
        __u32   offset_to_first_pkt;
        __u32   blk_len;
        __aligned_u64   seq_num;
        struct tpacket_bd_ts    ts_first_pkt, ts_last_pkt;
    };

// if_packet.h:
    struct tpacket_hdr {
        unsigned long   tp_status;
        unsigned int    tp_len;
        unsigned int    tp_snaplen;
        unsigned short  tp_mac;
        unsigned short  tp_net;
        unsigned int    tp_sec;
        unsigned int    tp_usec;
    }; // if_packet.h: struct tpacket2_hdr { __u32 tp_status; __u32 tp_len; __u32 tp_snaplen; __u16 tp_mac; __u16 tp_net; __u32 tp_sec; __u32 tp_nsec; __u16 tp_vlan_tci; __u16 tp_vlan_tpid; __u8 tp_padding[4]; }; // if_packet.h: struct tpacket3_hdr { __u32 tp_next_offset; __u32 tp_sec; __u32 tp_nsec; __u32 tp_snaplen; __u32 tp_len; __u32 tp_status; __u16 tp_mac; __u16 tp_net; // pkt_hdr variants union { struct tpacket_hdr_variant1 hv1; }; __u8 tp_padding[8]; }; // if_packet.h: struct tpacket_req { unsigned int tp_block_size; /* Minimal size of contiguous block */ unsigned int tp_block_nr; /* Number of blocks */ unsigned int tp_frame_size; /* Size of frame */ unsigned int tp_frame_nr; /* Total number of frames */ }; // if_packet.h: struct tpacket_req3 { unsigned int tp_block_size; /* Minimal size of contiguous block */ unsigned int tp_block_nr; /* Number of blocks */ unsigned int tp_frame_size; /* Size of frame */ unsigned int tp_frame_nr; /* Total number of frames */ unsigned int tp_retire_blk_tov; /* timeout in msecs */ unsigned int tp_sizeof_priv; /* offset to private data area */ unsigned int tp_feature_req_word; };