Example #1
0
def tunnel_listp(devname):
    s = NetlinkSocket()
    s.bind()

    msg = ifinfmsg()
    nonce = 123

    # fill the protocol-specific fields
    msg['index'] = 85  # index of the interface
    msg['family'] = 18  # address family

    # attach NLA -- it MUST be a list / mutable
    msg['attrs'] = [['CTRL_ATTR_FAMILY_NAME', "gtp0"]]

    # fill generic netlink fields
    msg['header']['sequence_number'] = nonce  # an unique seq number
    msg['header']['pid'] = os.getpid()
    msg['header']['type'] = GENL_ID_CTRL
    msg['header']['flags'] = NLM_F_REQUEST |\
                             NLM_F_ACK

    # encode the packet
    msg.encode()

    # send the buffer
    s.sendto(msg.data, (0, 0))
    s.get()
    s.close()

    l = 1
    print("tthis is a list; {}".format(l))
    return list
Example #2
0
 def get(self, *argv, **kwarg):
     '''
     Proxy `get()` request
     '''
     msgs = NetlinkSocket.get(self, *argv, **kwarg)
     for msg in msgs:
         mtype = msg['header']['type']
         if mtype in self.get_map:
             self.get_map[mtype](msg)
     return msgs