• Home
  • Raw
  • Download

Lines Matching full:self

80   def __init__(self, nl_msg):  argument
81 self.nl_msg = nl_msg
83 def __str__(self): argument
84 return f"Netlink error: {os.strerror(-self.nl_msg.error)}\n{self.nl_msg}"
100 def __init__(self, raw, offset): argument
101 self._len, self._type = struct.unpack("HH", raw[offset:offset + 4])
102 self.type = self._type & ~Netlink.NLA_TYPE_MASK
103 self.payload_len = self._len
104 self.full_len = (self.payload_len + 3) & ~3
105 self.raw = raw[offset + 4:offset + self.payload_len]
129 def as_scalar(self, attr_type, byte_order=None): argument
130 format = self.get_format(attr_type, byte_order)
131 return format.unpack(self.raw)[0]
133 def as_strz(self): argument
134 return self.raw.decode('ascii')[:-1]
136 def as_bin(self): argument
137 return self.raw
139 def as_c_array(self, type): argument
140 format = self.get_format(type)
141 return [ x[0] for x in format.iter_unpack(self.raw) ]
143 def as_struct(self, members): argument
149 decoded = self.raw[offset:offset+m['len']]
152 format = self.get_format(m.type, m.byte_order)
153 [ decoded ] = format.unpack_from(self.raw, offset)
156 decoded = self.formatted_string(decoded, m.display_hint)
160 def __repr__(self): argument
161 return f"[type:{self.type} len:{self._len}] {self.raw}"
165 def __init__(self, msg): argument
166 self.attrs = []
172 self.attrs.append(attr)
174 def __iter__(self): argument
175 yield from self.attrs
177 def __repr__(self): argument
179 for a in self.attrs:
187 def __init__(self, msg, offset, attr_space=None): argument
188 self.hdr = msg[offset:offset + 16]
190 self.nl_len, self.nl_type, self.nl_flags, self.nl_seq, self.nl_portid = \
191 struct.unpack("IHHII", self.hdr)
193 self.raw = msg[offset + 16:offset + self.nl_len]
195 self.error = 0
196 self.done = 0
199 if self.nl_type == Netlink.NLMSG_ERROR:
200 self.error = struct.unpack("i", self.raw[0:4])[0]
201 self.done = 1
203 elif self.nl_type == Netlink.NLMSG_DONE:
204 self.error = struct.unpack("i", self.raw[0:4])[0]
205 self.done = 1
208 self.extack = None
209 if self.nl_flags & Netlink.NLM_F_ACK_TLVS and extack_off:
210 self.extack = dict()
211 extack_attrs = NlAttrs(self.raw[extack_off:])
214 self.extack['msg'] = extack.as_strz()
216 self.extack['miss-type'] = extack.as_scalar('u32')
218 self.extack['miss-nest'] = extack.as_scalar('u32')
220 self.extack['bad-attr-offs'] = extack.as_scalar('u32')
222 if 'unknown' not in self.extack:
223 self.extack['unknown'] = []
224 self.extack['unknown'].append(extack)
228 if 'miss-type' in self.extack and 'miss-nest' not in self.extack:
229 miss_type = self.extack['miss-type']
235 self.extack['miss-type'] = desc
237 def cmd(self): argument
238 return self.nl_type
240 def __repr__(self): argument
241 …msg = f"nl_len = {self.nl_len} ({len(self.raw)}) nl_flags = 0x{self.nl_flags:x} nl_type = {self.nl…
242 if self.error:
243 msg += '\terror: ' + str(self.error)
244 if self.extack:
245 msg += '\textack: ' + repr(self.extack)
250 def __init__(self, data, attr_space=None): argument
251 self.msgs = []
257 self.msgs.append(msg)
259 def __iter__(self): argument
260 yield from self.msgs
329 def __init__(self, nl_msg): argument
330 self.nl = nl_msg
331 self.genl_cmd, self.genl_version, _ = struct.unpack_from("BBH", nl_msg.raw, 0)
332 self.raw = nl_msg.raw[4:]
334 def cmd(self): argument
335 return self.genl_cmd
337 def __repr__(self): argument
338 msg = repr(self.nl)
339 msg += f"\tgenl_cmd = {self.genl_cmd} genl_ver = {self.genl_version}\n"
340 for a in self.raw_attrs:
346 def __init__(self, family_name, proto_num): argument
347 self.family_name = family_name
348 self.proto_num = proto_num
350 def _message(self, nl_type, nl_flags, seq=None): argument
356 def message(self, flags, command, version, seq=None): argument
357 return self._message(command, flags, seq)
359 def _decode(self, nl_msg): argument
362 def decode(self, ynl, nl_msg): argument
363 msg = self._decode(nl_msg)
371 def get_mcast_id(self, mcast_name, mcast_groups): argument
378 def __init__(self, family_name): argument
385 self.genl_family = genl_family_name_to_id[family_name]
386 self.family_id = genl_family_name_to_id[family_name]['id']
388 def message(self, flags, command, version, seq=None): argument
389 nlmsg = self._message(self.family_id, flags, seq)
393 def _decode(self, nl_msg): argument
396 def get_mcast_id(self, mcast_name, mcast_groups): argument
397 if mcast_name not in self.genl_family['mcast']:
399 return self.genl_family['mcast'][mcast_name]
408 def __init__(self, def_path, schema=None): argument
411 self.include_raw = False
414 if self.proto == "netlink-raw":
415 self.nlproto = NetlinkProtocol(self.yaml['name'],
416 self.yaml['protonum'])
418 self.nlproto = GenlProtocol(self.yaml['name'])
420 raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel")
422 self.sock = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, self.nlproto.proto_num)
423 self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1)
424 self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1)
425 self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_GET_STRICT_CHK, 1)
427 self.async_msg_ids = set()
428 self.async_msg_queue = []
430 for msg in self.msgs.values():
432 self.async_msg_ids.add(msg.rsp_value)
434 for op_name, op in self.ops.items():
435 bound_f = functools.partial(self._op, op_name)
436 setattr(self, op.ident_name, bound_f)
439 def ntf_subscribe(self, mcast_name): argument
440 mcast_id = self.nlproto.get_mcast_id(mcast_name, self.mcast_groups)
441 self.sock.bind((0, 0))
442 self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_ADD_MEMBERSHIP,
445 def _add_attr(self, space, name, value): argument
447 attr = self.attr_sets[space][name]
455 attr_payload += self._add_attr(attr['nested-attributes'], subname, subvalue)
476 def _decode_enum(self, raw, attr_spec): argument
477 enum = self.consts[attr_spec['enum']]
490 def _decode_binary(self, attr, attr_spec): argument
492 members = self.consts[attr_spec.struct_name]
496 decoded[m.name] = self._decode_enum(decoded[m.name], m)
505 def _decode_array_nest(self, attr, attr_spec): argument
512 subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
516 def _decode(self, attrs, space): argument
517 attr_space = self.attr_sets[space]
525 subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'])
530 decoded = self._decode_binary(attr, attr_spec)
536 decoded = self._decode_array_nest(attr, attr_spec)
541 decoded = self._decode_enum(decoded, attr_spec)
552 def _decode_extack_path(self, attrs, attr_set, offset, target): argument
569 subpath = self._decode_extack_path(NlAttrs(attr.raw),
570 self.attr_sets[attr_spec['nested-attributes']],
578 def _decode_extack(self, request, op, extack): argument
582 msg = self.nlproto.decode(self, NlMsg(request, 0, op.attr_set))
583 offset = 20 + self._fixed_header_size(op)
584 path = self._decode_extack_path(msg.raw_attrs, op.attr_set, offset,
590 def _fixed_header_size(self, op): argument
592 fixed_header_members = self.consts[op.fixed_header].members
601 def _decode_fixed_header(self, msg, name): argument
602 fixed_header_members = self.consts[name].members
610 value = self._decode_enum(value, m)
614 def handle_ntf(self, decoded): argument
616 if self.include_raw:
618 op = self.rsp_by_value[decoded.cmd()]
619 attrs = self._decode(decoded.raw_attrs, op.attr_set.name)
621 attrs.update(self._decode_fixed_header(decoded, op.fixed_header))
625 self.async_msg_queue.append(msg)
627 def check_ntf(self): argument
630 reply = self.sock.recv(128 * 1024, socket.MSG_DONTWAIT)
644 decoded = self.nlproto.decode(self, nl_msg)
645 if decoded.cmd() not in self.async_msg_ids:
649 self.handle_ntf(decoded)
651 def operation_do_attributes(self, name): argument
656 op = self.find_operation(name)
662 def _op(self, method, vals, flags, dump=False): argument
663 op = self.ops[method]
672 msg = self.nlproto.message(nl_flags, op.req_value, 1, req_seq)
675 fixed_header_members = self.consts[op.fixed_header].members
681 msg += self._add_attr(op.attr_set.name, name, value)
684 self.sock.send(msg, 0)
689 reply = self.sock.recv(128 * 1024)
693 self._decode_extack(msg, op, nl_msg.extack)
704 decoded = self.nlproto.decode(self, nl_msg)
708 if decoded.cmd() in self.async_msg_ids:
709 self.handle_ntf(decoded)
715 rsp_msg = self._decode(decoded.raw_attrs, op.attr_set.name)
717 rsp_msg.update(self._decode_fixed_header(decoded, op.fixed_header))
726 def do(self, method, vals, flags): argument
727 return self._op(method, vals, flags)
729 def dump(self, method, vals): argument
730 return self._op(method, vals, [], dump=True)