<div dir="ltr"><div>On Wed, 3 Jan 2018 18:33:46 +0530, Harsha Sharma wrote:</div><div>> * netlink.c: decode family NETLINK_KOBJECT_UEVENT if prefix is libudev</div><div>> * linux/netlink_kobject_uevent.h: New struct (udev_monitor_netlink_header)</div><div><br></div><div>I think this header should not in linux directory.</div><div>When adding a new file, we should add it in Makefile.am.</div><div><br></div><div>> </div><div>> Signed-off-by: Harsha Sharma <<a href="mailto:harshasharmaiitr@gmail.com">harshasharmaiitr@gmail.com</a>></div><div>> ---</div><div>>  linux/netlink_kobject_uevent.h | 16 ++++++++++++++++</div><div>>  netlink.c                      | 27 ++++++++++++++++++++++++++-</div><div>>  2 files changed, 42 insertions(+), 1 deletion(-)</div><div>>  create mode 100644 linux/netlink_kobject_uevent.h</div><div>> </div><div>> diff --git a/linux/netlink_kobject_uevent.h b/linux/netlink_kobject_uevent.h</div><div>> new file mode 100644</div><div>> index 00000000..d83ccad5</div><div>> --- /dev/null</div><div>> +++ b/linux/netlink_kobject_uevent.h</div><div>> @@ -0,0 +1,16 @@</div><div>> +#ifndef STRACE_LINUX_NETLINK_KOBJECT_UEVENT_H</div><div>> +#define STRACE_LINUX_NETLINK_KOBJECT_UEVENT_H</div><div>> +</div><div>> +struct udev_monitor_netlink_header {</div><div>> +<span style="white-space:pre">      </span>char prefix[8];</div><div><br></div><div>Reserve useful comment.</div><div><br></div><div>> +<span style="white-space:pre"> </span>unsigned int magic;</div><div>> +<span style="white-space:pre">     </span>unsigned int header_size;</div><div>> +<span style="white-space:pre">       </span>unsigned int properties_off;</div><div>> +<span style="white-space:pre">    </span>unsigned int properties_len;</div><div>> +<span style="white-space:pre">    </span>unsigned int filter_subsystem_hash;</div><div>> +<span style="white-space:pre">     </span>unsigned int filter_devtype_hash;</div><div>> +<span style="white-space:pre">       </span>unsigned int filter_tag_bloom_hi;</div><div>> +<span style="white-space:pre">       </span>unsigned int filter_tag_bloom_lo;</div><div>> +};</div><div>> +</div><div>> +#endif /* !STRACE_LINUX_NETLINK_KOBJECT_UEVENT_H */</div><div>> diff --git a/netlink.c b/netlink.c</div><div>> index 6b9a1f5c..e991ed86 100644</div><div>> --- a/netlink.c</div><div>> +++ b/netlink.c</div><div>> @@ -32,6 +32,7 @@</div><div>>  #include "nlattr.h"</div><div>>  #include <linux/audit.h></div><div>>  #include <linux/rtnetlink.h></div><div>> +#include <linux/netlink_kobject_uevent.h></div><div>>  #include <linux/xfrm.h></div><div>>  #include "xlat/netlink_ack_flags.h"</div><div>>  #include "xlat/netlink_delete_flags.h"</div><div>> @@ -183,6 +184,29 @@ decode_nlmsg_type_netfilter(const struct xlat *const xlat,</div><div>>  <span style="white-space:pre">            </span>tprintf("%#x", msg_type);</div><div>>  }</div><div>>  </div><div>> +static bool</div><div>> +decode_nlmsg_type_kobject_uevent(struct tcb *tcp, kernel_ulong_t addr,</div><div>> +<span style="white-space:pre">                             </span> kernel_ulong_t len,</div><div>> +<span style="white-space:pre">                            </span> const void *const opaque_data)</div><div>> +{</div><div>> +<span style="white-space:pre">   </span>struct udev_monitor_netlink_header uh;</div><div>> +<span style="white-space:pre">  </span>const char *prefix = "libudev";</div><div>> +</div><div>> +<span style="white-space:pre">  </span>if (len < sizeof(uh))</div><div>> +<span style="white-space:pre">                </span>return false;</div><div>> +<span style="white-space:pre">   </span>if (!umove_or_printaddr(tcp, addr, &uh) &&</div><div>> +<span style="white-space:pre">  </span>    strcmp(uh.prefix, prefix) == 0) {</div><div>> +<span style="white-space:pre">         </span>tprintf("{prefix=%s, magic=%u, header_size=%u, properties_off=%u, properties_len=%u, filter_subsystem_hash=%u, filter_devtype_hash=%u, filter_tag_bloom_hi=%u, filter_tag_bloom_lo=%u}", uh.prefix,</div><div><br></div><div>More than 80 character.</div><div><br></div><div>> +<span style="white-space:pre">           </span>    uh.magic, uh.header_size, uh.properties_off,</div><div>> +<span style="white-space:pre">              </span>    uh.properties_len, uh.filter_subsystem_hash,</div><div>> +<span style="white-space:pre">              </span>    uh.filter_devtype_hash, uh.filter_tag_bloom_hi,</div><div>> +<span style="white-space:pre">           </span>    uh.filter_tag_bloom_lo);</div><div><br></div><div>We can use macros in print_fields.h.</div><div>I think magic, filter_tag_bloom_hi and filter_tag_bloom_lo sholud use other format.</div><div><br></div><div>After the header have other messages.</div><div><br></div><div>> +<span style="white-space:pre">              </span>return true;</div><div>> +<span style="white-space:pre">    </span>}</div><div>> +<span style="white-space:pre">       </span>return false;</div><div><br></div><div>If umove_or_printaddr return -1, you print address and string.</div><div>If prefix is not "libudev", address addr to (addr + sizeof(uh)) will call umove</div><div>again, we should reduce call syscall.</div><div><br></div><div>> +}</div><div><br></div><div>I think this function should separate into a single file.</div><div><br></div><div>> +</div><div>> +</div><div><br></div><div>To more empty line.</div><div><br></div><div>>  typedef void (*nlmsg_types_decoder_t)(const struct xlat *,</div><div>>  <span style="white-space:pre">                         </span>      uint16_t type,</div><div>>  <span style="white-space:pre">                                </span>      const char *dflt);</div><div>> @@ -628,7 +652,8 @@ decode_netlink(struct tcb *const tcp,</div><div>>  <span style="white-space:pre">       </span>const int family = get_fd_nl_family(tcp, fd);</div><div>>  </div><div>>  <span style="white-space:pre">    </span>if (family == NETLINK_KOBJECT_UEVENT) {</div><div>> -<span style="white-space:pre">         </span>printstrn(tcp, addr, len);</div><div>> +<span style="white-space:pre">              </span>if (!decode_nlmsg_type_kobject_uevent(tcp, addr, len, NULL))</div><div><br></div><div>I think this should be named decode_netlink_kobject_uevent, then ...</div><div><br></div><div>> +<span style="white-space:pre">                      </span>printstrn(tcp, addr, len);</div><div><br></div><div>... this problem handle in this function.</div><div><br></div><div><span style="white-space:pre">  </span>if (family == NETLINK_KOBJECT_UEVENT) {</div><div><span style="white-space:pre">               </span>decode_netlink_kobject_uevent(tcp, addr, len);</div><div><span style="white-space:pre">                </span>return;</div><div><span style="white-space:pre">       </span>}</div><div><br></div><div>>  <span style="white-space:pre">             </span>return;</div><div>>  <span style="white-space:pre">        </span>}</div><div>>  </div><div>> -- </div><div>> 2.11.0</div><div>> </div><div><br></div><div>Without a test.</div><div><br></div><div>--</div><div>Chen Jingpiao</div></div>