コード例 #1
0
ファイル: iproute.py プロジェクト: Lh4cKg/pyroute2
 def get_neighbors(self, family=AF_UNSPEC):
     """
     Retrieve ARP cache records.
     """
     msg = ndmsg()
     msg["family"] = family
     return self.nlm_request(msg, RTM_GETNEIGH)
コード例 #2
0
ファイル: iproute.py プロジェクト: rgacogne/pyroute2
 def get_neighbors(self, family=AF_UNSPEC):
     '''
     Retrieve ARP cache records.
     '''
     msg = ndmsg()
     msg['family'] = family
     return self.nlm_request(msg, RTM_GETNEIGH)
コード例 #3
0
ファイル: iproute.py プロジェクト: welterde/pyroute2
 def get_neighbors(self, family=AF_UNSPEC):
     '''
     Retrieve ARP cache records.
     '''
     msg = ndmsg()
     msg['family'] = family
     return self.nlm_request(msg, RTM_GETNEIGH)
コード例 #4
0
ファイル: iproute.py プロジェクト: GateprotectGmbH/pyroute2
    def neigh(self, command, match=None, **kwarg):
        '''
        Neighbours operations, same as `ip neigh` or `bridge fdb`

        * command -- add, delete, change, replace
        * match -- match rules
        * ifindex -- device index
        * family -- family: AF_INET, AF_INET6, AF_BRIDGE
        * \*\*kwarg -- msg fields and NLA

        Example::

            pass
        '''
        # FIXME: this is only a draft; all definitions should
        # be generalized

        flags_base = NLM_F_REQUEST | NLM_F_ACK
        flags_make = flags_base | NLM_F_CREATE | NLM_F_EXCL
        flags_change = flags_base | NLM_F_REPLACE
        flags_replace = flags_change | NLM_F_CREATE

        commands = {'add': (RTM_NEWNEIGH, flags_make),
                    'set': (RTM_NEWNEIGH, flags_replace),
                    'replace': (RTM_NEWNEIGH, flags_replace),
                    'change': (RTM_NEWNEIGH, flags_change),
                    'del': (RTM_DELNEIGH, flags_make),
                    'remove': (RTM_DELNEIGH, flags_make),
                    'delete': (RTM_DELNEIGH, flags_make)}

        (command, flags) = commands.get(command, command)
        msg = ndmsg()
        for field in msg.fields:
            msg[field[0]] = kwarg.pop(field[0], 0)
        msg['family'] = msg['family'] or AF_INET
        msg['attrs'] = []
        # fix nud kwarg
        state = kwarg.pop('state', kwarg.pop('nud', 0))
        if isinstance(state, basestring):
            # parse state string
            states = state.split(',')
            state = 0
            for s in states:
                s = s.upper()
                if not s.startswith('NUD_'):
                    s = 'NUD_' + s
                state |= NUD_NAMES[s]
        msg['state'] = state

        for key in kwarg:
            nla = ndmsg.name2nla(key)
            if kwarg[key] is not None:
                msg['attrs'].append([nla, kwarg[key]])

        ret = self.nlm_request(msg, msg_type=command, msg_flags=flags)
        if match is not None:
            return self._match(match, ret)
        else:
            return ret
コード例 #5
0
 def get_neighbours(self, *argv, **kwarg):
     ifc = self._ifc.parse(self._ifc.run())
     arp = self._arp.parse(self._arp.run())
     ret = []
     for spec in arp:
         spec['ifindex'] = ifc['links'][spec['ifname']]['index']
         msg = ndmsg().load(spec)
         del msg['value']
         ret.append(msg)
     return ret
コード例 #6
0
 def get_neighbours(self, *argv, **kwarg):
     ifc = self._ifc.parse(self._ifc.run())
     arp = self._arp.parse(self._arp.run())
     ret = []
     for spec in arp:
         if spec['ifname'] not in ifc['links']:
             continue
         spec['ifindex'] = ifc['links'][spec['ifname']]['index']
         msg = ndmsg().load(spec)
         msg['header']['type'] = RTM_NEWNEIGH
         del msg['value']
         ret.append(msg)
     return ret
コード例 #7
0
ファイル: iproute.py プロジェクト: rgacogne/pyroute2
    def get_rules(self, family=AF_UNSPEC):
        '''
        Get all rules.
        You can specify inet family, by default return rules for all families.

        Example::
            ip.get_rules() # get all the rules for all families
            ip.get_routes(family=AF_INET6)  # get only IPv6 rules
        '''
        msg = ndmsg()
        msg['family'] = family
        msg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_ATOMIC
        return self.nlm_request(msg, RTM_GETRULE, msg_flags)
コード例 #8
0
ファイル: iproute.py プロジェクト: welterde/pyroute2
    def get_rules(self, family=AF_UNSPEC):
        '''
        Get all rules.
        You can specify inet family, by default return rules for all families.

        Example::
            ip.get_rules() # get all the rules for all families
            ip.get_routes(family=AF_INET6)  # get only IPv6 rules
        '''
        msg = ndmsg()
        msg['family'] = family
        msg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_ATOMIC
        return self.nlm_request(msg, RTM_GETRULE, msg_flags)
コード例 #9
0
ファイル: bsd.py プロジェクト: svinota/pyroute2
 def get_neighbours(self, *argv, **kwarg):
     ifc = self._ifc.parse(self._ifc.run())
     arp = self._arp.parse(self._arp.run())
     ret = []
     for spec in arp:
         if spec['ifname'] not in ifc['links']:
             continue
         spec['ifindex'] = ifc['links'][spec['ifname']]['index']
         msg = ndmsg().load(spec)
         msg['header']['type'] = RTM_NEWNEIGH
         del msg['value']
         ret.append(msg)
     return ret
コード例 #10
0
    def neigh(self, command, match=None, **kwarg):
        '''
        Neighbours operations, same as `ip neigh` or `bridge fdb`

        * command -- add, delete, change, replace
        * match -- match rules
        * ifindex -- device index
        * family -- family: AF_INET, AF_INET6, AF_BRIDGE
        * \*\*kwarg -- msg fields and NLA

        Example::

            pass
        '''
        # FIXME: this is only a draft; all definitions should
        # be generalized

        flags_base = NLM_F_REQUEST | NLM_F_ACK
        flags_make = flags_base | NLM_F_CREATE | NLM_F_EXCL
        flags_change = flags_base | NLM_F_REPLACE
        flags_replace = flags_change | NLM_F_CREATE

        commands = {
            'add': (RTM_NEWNEIGH, flags_make),
            'set': (RTM_NEWNEIGH, flags_replace),
            'replace': (RTM_NEWNEIGH, flags_replace),
            'change': (RTM_NEWNEIGH, flags_change),
            'del': (RTM_DELNEIGH, flags_make),
            'remove': (RTM_DELNEIGH, flags_make),
            'delete': (RTM_DELNEIGH, flags_make)
        }

        (command, flags) = commands.get(command, command)
        msg = ndmsg()
        for field in msg.fields:
            msg[field[0]] = kwarg.pop(field[0], 0)
        msg['family'] = msg['family'] or AF_INET
        msg['attrs'] = []

        for key in kwarg:
            nla = ndmsg.name2nla(key)
            if kwarg[key] is not None:
                msg['attrs'].append([nla, kwarg[key]])

        ret = self.nlm_request(msg, msg_type=command, msg_flags=flags)
        if match is not None:
            return self._match(match, ret)
        else:
            return ret