Пример #1
0
 def discovery(self, proto):
     '''
     Resolve generic netlink protocol -- takes a string
     as the only parameter, return protocol description
     '''
     msg = ctrlmsg()
     msg['cmd'] = CTRL_CMD_GETFAMILY
     msg['version'] = 1
     msg['attrs'].append(['CTRL_ATTR_FAMILY_NAME', proto])
     msg['header']['type'] = GENL_ID_CTRL
     msg['header']['flags'] = NLM_F_REQUEST
     msg['header']['pid'] = self.pid
     msg.encode()
     self.sendto(msg.data, (0, 0))
     msg = self.get()[0]
     err = msg['header'].get('error', None)
     if err is not None:
         if hasattr(err, 'code') and err.code == errno.ENOENT:
             err.extra_code = errno.ENOTSUP
             logger = getattr(logging, self.module_err_level)
             logger('Generic netlink protocol %s not found' % proto)
             logger('Please check if the protocol module is loaded')
             if self.module_err_message is not None:
                 logger(self.module_err_message)
         raise err
     return msg
Пример #2
0
 def discovery(self, proto):
     '''
     Resolve generic netlink protocol -- takes a string
     as the only parameter, return protocol description
     '''
     msg = ctrlmsg()
     msg['cmd'] = CTRL_CMD_GETFAMILY
     msg['version'] = 1
     msg['attrs'].append(['CTRL_ATTR_FAMILY_NAME', proto])
     msg['header']['type'] = GENL_ID_CTRL
     msg['header']['flags'] = NLM_F_REQUEST
     msg['header']['pid'] = self.pid
     msg.encode()
     self.sendto(msg.data, (0, 0))
     msg = self.get()[0]
     err = msg['header'].get('error', None)
     if err is not None:
         raise err
     return msg
 def get_protocol_id(self, proto):
     '''
     Resolve generic netlink protocol -- takes a string
     as the only parameter, return integer proto ID
     '''
     msg = ctrlmsg()
     msg['cmd'] = CTRL_CMD_GETFAMILY
     msg['version'] = 1
     msg['attrs'].append(['CTRL_ATTR_FAMILY_NAME', proto])
     msg['header']['type'] = GENL_ID_CTRL
     msg['header']['flags'] = NLM_F_REQUEST
     msg['header']['pid'] = self.pid
     msg.encode()
     self.sendto(msg.buf.getvalue(), (0, 0))
     msg = self.get()[0]
     err = msg['header'].get('error', None)
     if err is not None:
         raise err
     return msg.get_attr('CTRL_ATTR_FAMILY_ID')
Пример #4
0
 def discovery(self, proto):
     '''
     Resolve generic netlink protocol -- takes a string
     as the only parameter, return protocol description
     '''
     msg = ctrlmsg()
     msg['cmd'] = CTRL_CMD_GETFAMILY
     msg['version'] = 1
     msg['attrs'].append(['CTRL_ATTR_FAMILY_NAME', proto])
     msg['header']['type'] = GENL_ID_CTRL
     msg['header']['flags'] = NLM_F_REQUEST
     msg['header']['pid'] = self.pid
     msg.encode()
     self.sendto(msg.data, (0, 0))
     msg = self.get()[0]
     err = msg['header'].get('error', None)
     if err is not None:
         if hasattr(err, 'code') and err.code == errno.ENOENT:
             logging.error('Generic netlink protocol %s not found' % proto)
             logging.error('Please check if the protocol module is loaded')
         raise err
     return msg
Пример #5
0
 def discovery(self):
     '''
     Resolve gtp netlink protocol
     '''
     msg = ctrlmsg()
     msg['cmd'] = CTRL_CMD_GETFAMILY
     msg['version'] = 1
     #        msg['attrs'].append(['CTRL_ATTR_FAMILY_ID', GENL_ID_CTRL])
     msg['attrs'].append(['CTRL_ATTR_FAMILY_NAME', "gtp"])
     msg['header']['type'] = GENL_ID_CTRL
     msg['header']['flags'] = NLM_F_REQUEST
     msg['header']['pid'] = self.pid
     msg.encode()
     self.sendto(msg.data, (0, 0))
     msg = self.get()[0]
     err = msg['header'].get('error', None)
     if err is not None:
         if hasattr(err, 'code') and err.code == ENOENT:
             logger.error('gtp netlink protocol not found')
             logger.error(
                 'maybe the protocol module is loaded, (modprobe gtp)')
         exit(1)
     return msg