def dump_table(self, family=AF_INET, event_type=NFCT_T_ALL): # Create a pointer to a 'uint8_t' of the address family family = byref(uint8_t(family)) def copyEntry(msgtype, ct, data): copyEntry.ctlist.append(ExpectEntry(self, ct, msgtype)) return NFCT_CB_STOLEN copyEntry.ctlist = [] # Install callback, do the query, remove callback self.register_callback(copyEntry, event_type) self.query(NFCT_Q_DUMP, family) self.unregister_callback() return copyEntry.ctlist
def dump_table(self, family=AF_INET, event_type=NFCT_T_ALL, filter=None): if not filter: filter = Filter() if HAS_CNETFILTER_CONNTRACK: if family != AF_INET: raise ValueError("cnetfilter_conntrack only supports IPv4") options = filter.createCNetfilterOptions() table, total = dump_table_ipv4(self.handle, **options) connections = [] for attr in table: handle = attr.pop('handle') for key, value in attr.iteritems(): if "ipv4" in key: attr[key] = IP(value) conn = ConntrackEntry(self, handle, attr=attr) connections.append(conn) return connections, total else: # Create a pointer to a 'uint8_t' of the address family family = byref(uint8_t(family)) def copyEntry(msgtype, conntrack, data): conn = ConntrackEntry(self, conntrack, msgtype) if not filter.filterConnection(conn): conn._destroy = False return NFCT_CB_CONTINUE copyEntry.ctlist.append(conn) return NFCT_CB_STOLEN copyEntry.ctlist = [] # Install callback, do the query, remove callback self.register_callback(copyEntry, event_type) self.query(NFCT_Q_DUMP, family) self.unregister_callback() connset = copyEntry.ctlist # Sort the list filter.sortTable(connset) # Truncated the list total = len(connset) connset = filter.truncate(connset) # Suppress unwanted entries return connset, total
def flush(self, family=AF_INET): family = byref(uint8_t(family)) self.query(NFCT_Q_FLUSH, family)