Example #1
0
 def put_setlink(self, msg, *argv, **kwarg):
     # is it a port setup?
     master = msg.get_attr('IFLA_MASTER')
     if self.ancient and master is not None:
         seq = kwarg.get('msg_seq', 0)
         response = ifinfmsg()
         response['header']['type'] = NLMSG_ERROR
         response['header']['sequence_number'] = seq
         ifname = self.name_by_id(msg['index'])
         if master == 0:
             # port delete
             # 1. get the current master
             m = self.name_by_id(compat_get_master(ifname))
             # 2. get the type of the master
             kind = compat_get_type(m)
             # 3. delete the port
             if kind == 'bridge':
                 compat_del_bridge_port(m, ifname)
             elif kind == 'bond':
                 compat_del_bond_port(m, ifname)
         else:
             # port add
             # 1. get the name of the master
             m = self.name_by_id(master)
             # 2. get the type of the master
             kind = compat_get_type(m)
             # 3. add the port
             if kind == 'bridge':
                 compat_add_bridge_port(m, ifname)
             elif kind == 'bond':
                 compat_add_bond_port(m, ifname)
         response.encode()
         self.backlog[seq] = [response]
     NetlinkSocket.put(self, msg, *argv, **kwarg)
Example #2
0
    def put_dellink(self, msg, *argv, **kwarg):
        if self.ancient:
            # get the interface kind
            kind = compat_get_type(msg.get_attr('IFLA_IFNAME'))

            # not covered types pass to the system
            if kind not in ('bridge', 'bond'):
                return NetlinkSocket.put(self, msg, *argv, **kwarg)
            ##
            # otherwise, create a valid answer --
            # NLMSG_ERROR with code 0 (no error)
            ##
            # FIXME: intercept and return valid RTM_NEWLINK
            ##
            seq = kwarg.get('msg_seq', 0)
            response = ifinfmsg()
            response['header']['type'] = NLMSG_ERROR
            response['header']['sequence_number'] = seq
            # route the request
            if kind == 'bridge':
                compat_del_bridge(msg.get_attr('IFLA_IFNAME'))
            elif kind == 'bond':
                compat_del_bond(msg.get_attr('IFLA_IFNAME'))
            # while RTM_NEWLINK is not intercepted -- sleep
            time.sleep(_ANCIENT_BARRIER)
            response.encode()
            self.backlog[seq] = [response]
        else:
            # else just send the packet
            NetlinkSocket.put(self, msg, *argv, **kwarg)
Example #3
0
 def put(self, *argv, **kwarg):
     '''
     Proxy `put()` request
     '''
     if argv[1] in self.put_map:
         self.put_map[argv[1]](*argv, **kwarg)
     else:
         NetlinkSocket.put(self, *argv, **kwarg)