예제 #1
0
def process_slot_fast(r, s):
    s.flags |= netmap.NS_FORWARD
    buf_ptr = get_buf(r, s.buf_idx)
    ethhdr = ffi.cast('struct ethhdr*', buf_ptr)
    offset = Eth.struct.size
    port = 0
    if swap16(ethhdr.h_proto) == dpkt.ethernet.ETH_TYPE_IP:
        iphdr = ffi.cast('struct iphdr*', buf_ptr + offset)
        offset += Ip.struct.size
        if iphdr.protocol == dpkt.ip.IP_PROTO_UDP:
            udphdr = ffi.cast('struct udphdr*', buf_ptr + offset)
            sport, dport = swap16(udphdr.uh_sport), swap16(udphdr.uh_dport)
            if sport in PORTS:
                port = sport + dport
예제 #2
0
def get_buf(r, cur):
    base_ptr = ffi.cast('char*', r) + r.buf_ofs
    buf_ptr = base_ptr + r.slot[cur].buf_idx * r.nr_buf_size
    return buf_ptr
예제 #3
0
def get_buf(r, buf_idx):
    base_ptr = ffi.cast('char*', r) + r.buf_ofs
    buf_ptr = base_ptr + buf_idx * r.nr_buf_size
    return buf_ptr
예제 #4
0
def netmap_rxring(nifp, index):
    return ffi.cast(
        'char*',
        ffi.cast('char*', nifp) + nifp.ring_ofs[index + nifp.ni_tx_rings + 1])
예제 #5
0
def netmap_txring(nifp, index):
    return ffi.cast('char*', ffi.cast('char*', nifp) + nifp.ring_ofs[index])
예제 #6
0
def netmap_txring(nifp, index):
    return ffi.cast('char*', ffi.cast('char*', nifp) + nifp.ring_ofs[index])


def netmap_rxring(nifp, index):
    return ffi.cast(
        'char*',
        ffi.cast('char*', nifp) + nifp.ring_ofs[index + nifp.ni_tx_rings + 1])


ifname = ffi.new('char[]', IFNAME)
nm_desc = lib.nm_open(ifname, ffi.NULL, 0, ffi.NULL)
nifp = nm_desc.nifp
rxr = lib.netmap_rxring(nifp, 0)
txr = lib.netmap_txring(nifp, 0)
print 'nm_desc:'
pprint(insp(nm_desc))
print 'netmap_if:'
pprint(insp(nifp))
index = 0
base_ptr = ffi.cast('char*', nifp)
rx_ptr = ffi.cast('char*', rxr)
tx_ptr = ffi.cast('char*', txr)
idx = 0
print netmap_rxring(nifp, 0)
print 'rx:', rx_ptr, rx_ptr - base_ptr, insp(rxr)
print netmap_txring(nifp, 0)
print 'tx:', tx_ptr, tx_ptr - base_ptr, insp(txr)
print 'rx-tx:', tx_ptr - rx_ptr

lib.nm_close(nm_desc)