<div dir="ltr"><div class="gmail_extra"><div class="gmail_extra">On Fri, 5 Jan 2018 20:49:28 +0530 Harsha Sharma wrote:</div><div class="gmail_extra">> * netlink.c: decode family NETLINK_KOBJECT_UEVENT</div><div class="gmail_extra">> * netlink_kobject_uevent.h: New struct (udev_monitor_netlink_header)</div><div class="gmail_extra">> * netlink_kobject_uevent.c: New file</div><div class="gmail_extra">> * Makefile.am (strace_SOURCES): Add it</div><div class="gmail_extra">> * defs.h: Add decode_netlink_kobject_uevent func</div><div class="gmail_extra"><br></div><div class="gmail_extra">We are prefer:</div><div class="gmail_extra"><br></div><div class="gmail_extra">* defs.h (decode_netlink_kobject_uevent): ...</div><div class="gmail_extra">* netlink.c (decode_netlink): ...</div><div class="gmail_extra">* netlink_kobject_uevent.h: New file.</div><div class="gmail_extra">* netlink_kobject_uevent.c: Likewise.</div><div class="gmail_extra">* Makefile.am (strace_SOURCES): Add them.</div><div class="gmail_extra"><br></div><div class="gmail_extra">> </div><div class="gmail_extra">> Changes in v2:</div><div class="gmail_extra">> * New file netlink_kobject_uevent.c</div><div class="gmail_extra">> * change location of netlink_kobject_uevent.h</div><div class="gmail_extra">> * add comments in netlink_kobject_uevent.h</div><div class="gmail_extra">> * add new files in Makefile.am</div><div class="gmail_extra">> * add func decode_netlink_kobject_uevent in defs.h</div><div class="gmail_extra">> * Use macros from print_fields.h instead of tprintf</div><div class="gmail_extra">> * minor changes in decode_netlink_kobject_uevent (including name)</div><div class="gmail_extra"><br></div><div class="gmail_extra">Move patch changelog ...</div><div class="gmail_extra"><br></div><div class="gmail_extra">> </div><div class="gmail_extra">> Signed-off-by: Harsha Sharma <<a href="mailto:harshasharmaiitr@gmail.com">harshasharmaiitr@gmail.com</a>></div><div class="gmail_extra">> ---</div><div class="gmail_extra"><br></div><div class="gmail_extra">... here.</div><div class="gmail_extra"><br></div><div class="gmail_extra">>  Makefile.am              |  2 ++</div><div class="gmail_extra">>  defs.h                   |  3 +++</div><div class="gmail_extra">>  netlink.c                |  2 +-</div><div class="gmail_extra">>  netlink_kobject_uevent.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++</div><div class="gmail_extra">>  netlink_kobject_uevent.h | 29 ++++++++++++++++++++++++</div><div class="gmail_extra">>  5 files changed, 93 insertions(+), 1 deletion(-)</div><div class="gmail_extra">>  create mode 100644 netlink_kobject_uevent.c</div><div class="gmail_extra">>  create mode 100644 netlink_kobject_uevent.h</div><div class="gmail_extra">> </div><div class="gmail_extra">> diff --git a/Makefile.am b/Makefile.am</div><div class="gmail_extra">> index 34da3372..9dace776 100644</div><div class="gmail_extra">> --- a/Makefile.am</div><div class="gmail_extra">> +++ b/Makefile.am</div><div class="gmail_extra">> @@ -194,6 +194,8 @@ strace_SOURCES =<span style="white-space:pre">     </span>\</div><div class="gmail_extra">>  <span style="white-space:pre">        </span>netlink.c       \</div><div class="gmail_extra">>  <span style="white-space:pre">     </span>netlink.h<span style="white-space:pre">    </span>\</div><div class="gmail_extra">>  <span style="white-space:pre">        </span>netlink_crypto.c \</div><div class="gmail_extra">> +<span style="white-space:pre">        </span>netlink_kobject_uevent.c \</div><div class="gmail_extra">> +<span style="white-space:pre">        </span>netlink_kobject_uevent.h \</div><div class="gmail_extra">>  <span style="white-space:pre">       </span>netlink_sock_diag.h \</div><div class="gmail_extra">>  <span style="white-space:pre">    </span>netlink_inet_diag.c \</div><div class="gmail_extra">>  <span style="white-space:pre">    </span>netlink_netlink_diag.c \</div><div class="gmail_extra">> diff --git a/defs.h b/defs.h</div><div class="gmail_extra">> index bd4267b3..98d04dd5 100644</div><div class="gmail_extra">> --- a/defs.h</div><div class="gmail_extra">> +++ b/defs.h</div><div class="gmail_extra">> @@ -687,6 +687,9 @@ DECL_NETLINK(route);</div><div class="gmail_extra">>  DECL_NETLINK(selinux);</div><div class="gmail_extra">>  DECL_NETLINK(sock_diag);</div><div class="gmail_extra">>  </div><div class="gmail_extra">> +extern void</div><div class="gmail_extra">> +decode_netlink_kobject_uevent(struct tcb *, kernel_ulong_t addr,</div><div class="gmail_extra">> +<span style="white-space:pre">                  </span>      kernel_ulong_t len, const void *);</div><div class="gmail_extra">>  extern int tv_nz(const struct timeval *);</div><div class="gmail_extra">>  extern int tv_cmp(const struct timeval *, const struct timeval *);</div><div class="gmail_extra">>  extern double tv_float(const struct timeval *);</div><div class="gmail_extra">> diff --git a/netlink.c b/netlink.c</div><div class="gmail_extra">> index 6b9a1f5c..e62e37d9 100644</div><div class="gmail_extra">> --- a/netlink.c</div><div class="gmail_extra">> +++ b/netlink.c</div><div class="gmail_extra">> @@ -628,7 +628,7 @@ decode_netlink(struct tcb *const tcp,</div><div class="gmail_extra">>  <span style="white-space:pre">      </span>const int family = get_fd_nl_family(tcp, fd);</div><div class="gmail_extra">>  </div><div class="gmail_extra">>  <span style="white-space:pre">        </span>if (family == NETLINK_KOBJECT_UEVENT) {</div><div class="gmail_extra">> -<span style="white-space:pre">           </span>printstrn(tcp, addr, len);</div><div class="gmail_extra">> +<span style="white-space:pre">                </span>decode_netlink_kobject_uevent(tcp, addr, len, NULL);</div><div class="gmail_extra"><br></div><div class="gmail_extra">The last argument is useless.</div><div class="gmail_extra"><br></div><div class="gmail_extra">>  <span style="white-space:pre">             </span>return;</div><div class="gmail_extra">>  <span style="white-space:pre">  </span>}</div><div class="gmail_extra">>  </div><div class="gmail_extra">> diff --git a/netlink_kobject_uevent.c b/netlink_kobject_uevent.c</div><div class="gmail_extra">> new file mode 100644</div><div class="gmail_extra">> index 00000000..5b0e018d</div><div class="gmail_extra">> --- /dev/null</div><div class="gmail_extra">> +++ b/netlink_kobject_uevent.c</div><div class="gmail_extra">> @@ -0,0 +1,58 @@</div><div class="gmail_extra">> +/*</div><div class="gmail_extra">> + * Copyright (c) 2018 Harsha Sharma <<a href="mailto:harshasharmaiittr@gmail.com">harshasharmaiittr@gmail.com</a>></div><div class="gmail_extra">> + * Copyright (c) 2017 The strace developers.</div><div class="gmail_extra">> + * All rights reserved.</div><div class="gmail_extra">> + *</div><div class="gmail_extra">> + * Redistribution and use in source and binary forms, with or without</div><div class="gmail_extra">> + * modification, are permitted provided that the following conditions</div><div class="gmail_extra">> + * are met:</div><div class="gmail_extra">> + * 1. Redistributions of source code must retain the above copyright</div><div class="gmail_extra">> + *    notice, this list of conditions and the following disclaimer.</div><div class="gmail_extra">> + * 2. Redistributions in binary form must reproduce the above copyright</div><div class="gmail_extra">> + *    notice, this list of conditions and the following disclaimer in the</div><div class="gmail_extra">> + *    documentation and/or other materials provided with the distribution.</div><div class="gmail_extra">> + * 3. The name of the author may not be used to endorse or promote products</div><div class="gmail_extra">> + *    derived from this software without specific prior written permission.</div><div class="gmail_extra">> + *</div><div class="gmail_extra">> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR</div><div class="gmail_extra">> + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</div><div class="gmail_extra">> + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</div><div class="gmail_extra">> + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,</div><div class="gmail_extra">> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT</div><div class="gmail_extra">> + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</div><div class="gmail_extra">> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</div><div class="gmail_extra">> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</div><div class="gmail_extra">> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF</div><div class="gmail_extra">> + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</div><div class="gmail_extra">> + */</div><div class="gmail_extra">> +</div><div class="gmail_extra">> +#include "defs.h"</div><div class="gmail_extra">> +#include "netlink.h"</div><div class="gmail_extra"><br></div><div class="gmail_extra">No need include "netlink.h".</div><div class="gmail_extra"><br></div><div class="gmail_extra">> +#include "print_fields.h"</div><div class="gmail_extra">> +#include "netlink_kobject_uevent.h"</div><div class="gmail_extra">> +</div><div class="gmail_extra">> +</div><div class="gmail_extra"><br></div><div class="gmail_extra">To more empty line.</div><div class="gmail_extra"><br></div><div class="gmail_extra">> +void</div><div class="gmail_extra">> +decode_netlink_kobject_uevent(struct tcb *tcp, kernel_ulong_t addr,</div><div class="gmail_extra">> +<span style="white-space:pre">                     </span>      kernel_ulong_t len,</div><div class="gmail_extra">> +<span style="white-space:pre">                      </span>      const void *const opaque_data)</div><div class="gmail_extra">> +{</div><div class="gmail_extra">> +<span style="white-space:pre">       </span>struct udev_monitor_netlink_header uh;</div><div class="gmail_extra">> +<span style="white-space:pre">    </span>const char *prefix = "libudev";</div><div class="gmail_extra">> +</div><div class="gmail_extra">> +<span style="white-space:pre">      </span>if (!umove_or_printaddr(tcp, addr, &uh) &&</div><div class="gmail_extra">> +<span style="white-space:pre">    </span>    strcmp(uh.prefix, prefix) == 0) {</div><div class="gmail_extra">> +<span style="white-space:pre">           </span>PRINT_FIELD_CSTRING("{", uh, prefix);</div><div class="gmail_extra">> +<span style="white-space:pre">           </span>PRINT_FIELD_U(", ", uh, magic);</div><div class="gmail_extra">> +<span style="white-space:pre">         </span>PRINT_FIELD_U(", ", uh, header_size);</div><div class="gmail_extra">> +<span style="white-space:pre">           </span>PRINT_FIELD_U(", ", uh, properties_off);</div><div class="gmail_extra">> +<span style="white-space:pre">                </span>PRINT_FIELD_U(", ", uh, properties_len);</div><div class="gmail_extra">> +<span style="white-space:pre">                </span>PRINT_FIELD_U(", ", uh, filter_subsystem_hash);</div><div class="gmail_extra">> +<span style="white-space:pre">         </span>PRINT_FIELD_U(", ", uh, filter_devtype_hash);</div><div class="gmail_extra">> +<span style="white-space:pre">           </span>PRINT_FIELD_U(", ", uh, filter_tag_bloom_hi);</div><div class="gmail_extra">> +<span style="white-space:pre">           </span>PRINT_FIELD_U(", ", uh, filter_tag_bloom_lo);</div><div class="gmail_extra">> +<span style="white-space:pre">           </span>tprints("}");</div><div class="gmail_extra"><br></div><div class="gmail_extra">Do not ignore the messages after the header.</div><div class="gmail_extra"><br></div><div class="gmail_extra">> +<span style="white-space:pre">    </span>} else {</div><div class="gmail_extra">> +<span style="white-space:pre">          </span>printstrn(tcp, addr, len);</div><div class="gmail_extra">> +<span style="white-space:pre">        </span>}</div><div class="gmail_extra">> +}</div><div class="gmail_extra">> diff --git a/netlink_kobject_uevent.h b/netlink_kobject_uevent.h</div><div class="gmail_extra">> new file mode 100644</div><div class="gmail_extra">> index 00000000..8b7c5970</div><div class="gmail_extra">> --- /dev/null</div><div class="gmail_extra">> +++ b/netlink_kobject_uevent.h</div><div class="gmail_extra">> @@ -0,0 +1,29 @@</div><div class="gmail_extra">> +#ifndef STRACE_NETLINK_KOBJECT_UEVENT_H</div><div class="gmail_extra">> +#define STRACE_NETLINK_KOBJECT_UEVENT_H</div><div class="gmail_extra">> +</div><div class="gmail_extra">> +struct udev_monitor_netlink_header {</div><div class="gmail_extra">> +<span style="white-space:pre">    </span>/* "libudev" prefix to distinguish libudev and kernel messages */</div><div class="gmail_extra">> +<span style="white-space:pre">       </span>char prefix[8];</div><div class="gmail_extra">> +<span style="white-space:pre">   </span>/*</div><div class="gmail_extra">> +<span style="white-space:pre">        </span> * magic to protect against daemon <-> library message format mismatch</div><div class="gmail_extra">> +<span style="white-space:pre">      </span> * used in the kernel from socket filter rules;</div><div class="gmail_extra">> +<span style="white-space:pre">   </span> * needs to be stored in network order</div><div class="gmail_extra">> +<span style="white-space:pre">    </span> */</div><div class="gmail_extra">> +<span style="white-space:pre">       </span>unsigned int magic;</div><div class="gmail_extra">> +<span style="white-space:pre">       </span>/* total length of header structure known to the sender */</div><div class="gmail_extra">> +<span style="white-space:pre">        </span>unsigned int header_size;</div><div class="gmail_extra">> +<span style="white-space:pre"> </span>/* properties string buffer */</div><div class="gmail_extra">> +<span style="white-space:pre">    </span>unsigned int properties_off;</div><div class="gmail_extra">> +<span style="white-space:pre">      </span>unsigned int properties_len;</div><div class="gmail_extra">> +<span style="white-space:pre">      </span>/*</div><div class="gmail_extra">> +<span style="white-space:pre">        </span> * hashes of primary device properties strings,</div><div class="gmail_extra">> +<span style="white-space:pre">   </span> * to let libudev subscribers use in-kernel socket filters;</div><div class="gmail_extra">> +<span style="white-space:pre">       </span> * values need to be stored in network order</div><div class="gmail_extra">> +<span style="white-space:pre">      </span> */</div><div class="gmail_extra">> +<span style="white-space:pre">       </span>unsigned int filter_subsystem_hash;</div><div class="gmail_extra">> +<span style="white-space:pre">       </span>unsigned int filter_devtype_hash;</div><div class="gmail_extra">> +<span style="white-space:pre"> </span>unsigned int filter_tag_bloom_hi;</div><div class="gmail_extra">> +<span style="white-space:pre"> </span>unsigned int filter_tag_bloom_lo;</div><div class="gmail_extra">> +};</div><div class="gmail_extra"><br></div><div class="gmail_extra">I think only the comment of "prefix" is useful.</div><div class="gmail_extra"><br></div><div class="gmail_extra">> +</div><div class="gmail_extra">> +#endif /* !STRACE_NETLINK_KOBJECT_UEVENT_H */</div><div class="gmail_extra">> -- </div><div class="gmail_extra">> 2.11.0</div><div class="gmail_extra"><br></div><div class="gmail_extra">Without a test.</div><div class="gmail_extra"><br></div><div class="gmail_extra">--</div><div class="gmail_extra">Chen Jingpiao</div></div></div>