Esempio n. 1
0
    def store_attrs(self, attrs):
        for aid in attrs.keys():
            try:
                pol = self._policy[aid]
                if pol.type == NLA_S8:
                    pol.type = nl.NLA_U8
                    pol.signed = True
                elif pol.type == NLA_S16:
                    pol.type = nl.NLA_U16
                    pol.signed = True
                elif pol.type == NLA_S32:
                    pol.type = nl.NLA_U32
                    pol.signed = True
                elif pol.type == NLA_S64:
                    pol.type = nl.NLA_U64
                    pol.signed = True

                if pol.type == NLA_NUL_STRING:
                    self._attrs[aid] = nl.nla_get_string(attrs[aid])
                elif pol.type == nl.NLA_U64:
                    self._attrs[aid] = nl.nla_get_u64(attrs[aid])
                elif pol.type == nl.NLA_U32:
                    self._attrs[aid] = nl.nla_get_u32(attrs[aid])
                elif pol.type == nl.NLA_U16:
                    self._attrs[aid] = nl.nla_get_u16(attrs[aid])
                elif pol.type == nl.NLA_U8:
                    self._attrs[aid] = nl.nla_get_u8(attrs[aid])
                elif pol.type == nl.NLA_FLAG:
                    self._attrs[aid] = True
                elif pol.type == nl.NLA_NESTED:
                    if hasattr(pol, 'single') and pol.single:
                        obj = self.create_nested(attrs[aid], aid)
                    elif hasattr(pol, 'map') and pol.map:
                        if not hasattr(pol, 'list_type'):
                            raise Exception(
                                'need to specify "list_type" for map')
                        obj = self.create_map(attrs[aid], pol)
                    elif hasattr(pol, 'list_type'):
                        obj = self.create_list(attrs[aid], pol)
                    else:
                        obj = self.create_nested_list(attrs[aid], aid)
                    self.merge_nested_attrs(aid, obj)
                elif pol.type in [NLA_BINARY, nl.NLA_UNSPEC]:
                    self._attrs[aid] = nl.nla_data(attrs[aid])
                if hasattr(pol, 'signed') and pol.signed:
                    self._attrs[aid] = self.convert_sign(self._attrs[aid], pol)
            except Exception as e:
                print e.message
                self._attrs[aid] = nl.nla_data(attrs[aid])
        self.post_store_attrs(attrs)
Esempio n. 2
0
	def store_attrs(self, attrs):
		for aid in attrs.keys():
			try:
				pol = self._policy[aid]
				if pol.type == NLA_S8:
					pol.type = NLA_U8
					pol.signed = True
				elif pol.type == NLA_S16:
					pol.type = NLA_U16
					pol.signed = True
				elif pol.type == NLA_S32:
					pol.type = NLA_U32
					pol.signed = True
				elif pol.type == NLA_S64:
					pol.type = NLA_U64
					pol.signed = True

				if pol.type == NLA_NUL_STRING:
					self._attrs[aid] = nla_get_string(attrs[aid])
				elif pol.type == NLA_U64:
					self._attrs[aid] = nla_get_u64(attrs[aid])
				elif pol.type == NLA_U32:
					self._attrs[aid] = nla_get_u32(attrs[aid])
				elif pol.type == NLA_U16:
					self._attrs[aid] = nla_get_u16(attrs[aid])
				elif pol.type == NLA_U8:
					self._attrs[aid] = nla_get_u8(attrs[aid])
				elif pol.type == NLA_FLAG:
					self._attrs[aid] = True
				elif pol.type == NLA_NESTED:
					if hasattr(pol, 'single') and pol.single:
						obj = self.create_nested(attrs[aid], aid)
					elif hasattr(pol, 'map') and pol.map:
						if not hasattr(pol, 'list_type'):
							raise Exception('need to specify "list_type" for map')
						obj = self.create_map(attrs[aid], pol)
					elif hasattr(pol, 'list_type'):
						obj = self.create_list(attrs[aid], pol)
					else:
						obj = self.create_nested_list(attrs[aid], aid)
					self.merge_nested_attrs(aid, obj)
				elif pol.type in [ NLA_BINARY, NLA_UNSPEC ]:
					self._attrs[aid] = nla_data(attrs[aid])
				if hasattr(pol, 'signed') and pol.signed:
					self._attrs[aid] = self.convert_sign(self._attrs[aid], pol)
			except Exception as e:
				print e.message
				self._attrs[aid] = nla_data(attrs[aid])
		self.post_store_attrs(attrs)
Esempio n. 3
0
 def create_list(self, attr_list, pol):
     nest_list = []
     item_type = pol.list_type
     for item in nl.nla_get_nested(attr_list):
         if item_type == NLA_NUL_STRING:
             nest_obj = nl.nla_get_string(item)
         elif item_type == nl.NLA_U64:
             nest_obj = nl.nla_get_u64(item)
         elif item_type == nl.NLA_U32:
             nest_obj = nl.nla_get_u32(item)
         elif item_type == nl.NLA_U16:
             nest_obj = nl.nla_get_u16(item)
         elif item_type == nl.NLA_U8:
             nest_obj = nl.nla_get_u8(item)
         else:
             raise Exception("type (%d) not supported for list" % item_type)
         nest_list.append(nest_obj)
     return nest_list
Esempio n. 4
0
	def create_list(self, attr_list, pol):
		nest_list = []
		item_type = pol.list_type
		for item in nla_get_nested(attr_list):
			if item_type == NLA_NUL_STRING:
				nest_obj = nla_get_string(item)
			elif item_type == NLA_U64:
				nest_obj = nla_get_u64(item)
			elif item_type == NLA_U32:
				nest_obj = nla_get_u32(item)
			elif item_type == NLA_U16:
				nest_obj = nla_get_u16(item)
			elif item_type == NLA_U8:
				nest_obj = nla_get_u8(item)
			else:
				raise Exception("type (%d) not supported for list" % item_type)
			nest_list.append(nest_obj)
		return nest_list
Esempio n. 5
0
	def store_attrs(self, attrs):
		for attr in attrs.keys():
			try:
				pol = self._policy[attr]
				if pol.type == NLA_NUL_STRING:
					self._attrs[attr] = nl.nla_get_string(attrs[attr])
				elif pol.type == nl.NLA_U64:
					self._attrs[attr] = nl.nla_get_u64(attrs[attr])
				elif pol.type == nl.NLA_U32:
					self._attrs[attr] = nl.nla_get_u32(attrs[attr])
				elif pol.type == nl.NLA_U16:
					self._attrs[attr] = nl.nla_get_u16(attrs[attr])
				elif pol.type == nl.NLA_U8:
					self._attrs[attr] = nl.nla_get_u8(attrs[attr])
				elif pol.type == nl.NLA_FLAG:
					self._attrs[attr] = True
				elif pol.type == nl.NLA_NESTED:
					self.store_nested(attrs[attr], attr)
				elif pol.type in [ NLA_BINARY, nl.NLA_UNSPEC ]:
					self._attrs[attr] = nl.nla_data(attrs[attr])
			except Exception as e:
				print e.message
				self._attrs[attr] = nl.nla_data(attrs[attr])
Esempio n. 6
0
 def store_attrs(self, attrs):
     for attr in attrs.keys():
         try:
             pol = self._policy[attr]
             if pol.type == NLA_NUL_STRING:
                 self._attrs[attr] = nl.nla_get_string(attrs[attr])
             elif pol.type == nl.NLA_U64:
                 self._attrs[attr] = nl.nla_get_u64(attrs[attr])
             elif pol.type == nl.NLA_U32:
                 self._attrs[attr] = nl.nla_get_u32(attrs[attr])
             elif pol.type == nl.NLA_U16:
                 self._attrs[attr] = nl.nla_get_u16(attrs[attr])
             elif pol.type == nl.NLA_U8:
                 self._attrs[attr] = nl.nla_get_u8(attrs[attr])
             elif pol.type == nl.NLA_FLAG:
                 self._attrs[attr] = True
             elif pol.type == nl.NLA_NESTED:
                 self.store_nested(attrs[attr], attr)
             elif pol.type in [NLA_BINARY, nl.NLA_UNSPEC]:
                 self._attrs[attr] = nl.nla_data(attrs[attr])
         except Exception as e:
             print e.message
             self._attrs[attr] = nl.nla_data(attrs[attr])