<div dir="ltr"><div>On 03/11 03:48, Dmitry V. Levin wrote:</div><div>> On Sun, Mar 11, 2018 at 03:06:23AM +0300, Dmitry V. Levin wrote:</div><div>> > On Thu, Mar 08, 2018 at 10:53:47PM +0800, Chen Jingpiao wrote:</div><div>> > > * tests/netlink_netfilter.c(test_nfgenmsg): Add check for decoding</div><div>> > > of netfilter subsystem.</div><div>> > > ---</div><div>> > >  tests/netlink_netfilter.c | 34 ++++++++++++++++++++++++++++++++++</div><div>> > >  1 file changed, 34 insertions(+)</div><div>> > > </div><div>> > > diff --git a/tests/netlink_netfilter.c b/tests/netlink_netfilter.c</div><div>> > > index 2826017d1..149da5ac1 100644</div><div>> > > --- a/tests/netlink_netfilter.c</div><div>> > > +++ b/tests/netlink_netfilter.c</div><div>> > > @@ -149,9 +149,22 @@ test_nfgenmsg(const int fd)</div><div>> > >  <span style="white-space:pre">          </span>     printf("{nfgen_family=AF_UNIX");</div><div>> > >  <span style="white-space:pre">           </span>     printf(", version=NFNETLINK_V0");</div><div>> > >  <span style="white-space:pre">          </span>     printf(", res_id=htons(%d)", NFNL_SUBSYS_NFTABLES));</div><div>> > > +# endif /* NFNL_MSG_BATCH_BEGIN */</div><div>> > >  </div><div>> > >  <span style="white-space:pre">     </span>char str_buf[NLMSG_ALIGN(sizeof(msg)) + 4];</div><div>> > > +<span style="white-space:pre">   </span>msg.res_id = htons(0xefab);</div><div>> > > +<span style="white-space:pre">   </span>memcpy(str_buf, &msg, sizeof(msg));</div><div>> > > +<span style="white-space:pre">       </span>memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4);</div><div>> > > +<span style="white-space:pre">      </span>TEST_NETLINK_(fd, nlh0,</div><div>> > > +<span style="white-space:pre">               </span>      0xffff, "0xff /* NFNL_SUBSYS_??? */<<8|0xff",</div><div>> > > +<span style="white-space:pre">                </span>      NLM_F_REQUEST, "NLM_F_REQUEST",</div><div>> > > +<span style="white-space:pre">            </span>      sizeof(str_buf), str_buf, sizeof(str_buf),</div><div>> > > +<span style="white-space:pre">           </span>      printf("{nfgen_family=AF_UNIX");</div><div>> > > +<span style="white-space:pre">           </span>      printf(", version=NFNETLINK_V0");</div><div>> > > +<span style="white-space:pre">          </span>      printf(", res_id=htons(%d)"</div><div>> > > +<span style="white-space:pre">                        </span>     ", \"\\x31\\x32\\x33\\x34\"", 0xefab));</div><div>> > >  </div><div>> > > +# ifdef NFNL_MSG_BATCH_BEGIN</div><div>> > >  <span style="white-space:pre">      </span>msg.res_id = htons(0xabcd);</div><div>> > >  <span style="white-space:pre">  </span>memcpy(str_buf, &msg, sizeof(msg));</div><div>> > >  <span style="white-space:pre">      </span>memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4);</div><div>> > > @@ -164,6 +177,27 @@ test_nfgenmsg(const int fd)</div><div>> > >  <span style="white-space:pre">               </span>     printf(", res_id=htons(%d)"</div><div>> > >  <span style="white-space:pre">                        </span>    ", \"\\x31\\x32\\x33\\x34\"", 0xabcd));</div><div>> > >  # endif /* NFNL_MSG_BATCH_BEGIN */</div><div>> > > +</div><div>> > > +<span style="white-space:pre">    </span>static const struct nlattr nla = {</div><div>> > > +<span style="white-space:pre">            </span>.nla_len = sizeof(nla),</div><div>> > > +<span style="white-space:pre">               </span>.nla_type = 0x0bcd</div><div>> > > +<span style="white-space:pre">    </span>};</div><div>> > > +<span style="white-space:pre">    </span>char nla_buf[NLMSG_ALIGN(sizeof(msg)) + sizeof(nla)];</div><div>> > > +</div><div>> > > +<span style="white-space:pre">  </span>msg.res_id = htons(NFNL_SUBSYS_NFTABLES);</div><div>> > > +<span style="white-space:pre">     </span>memcpy(nla_buf, &msg, sizeof(msg));</div><div>> > > +<span style="white-space:pre">       </span>memcpy(nla_buf + NLMSG_ALIGN(sizeof(msg)), &nla, sizeof(nla));</div><div>> > > +</div><div>> > > +<span style="white-space:pre">     </span>TEST_NETLINK_(fd, nlh0,</div><div>> > > +<span style="white-space:pre">               </span>      NFNL_SUBSYS_NFTABLES << 8 | 0xff,</div><div>> > > +<span style="white-space:pre">              </span>      "NFNL_SUBSYS_NFTABLES<<8|0xff /* NFT_MSG_??? */",</div><div>> > > +<span style="white-space:pre">            </span>      NLM_F_REQUEST, "NLM_F_REQUEST",</div><div>> > > +<span style="white-space:pre">            </span>      sizeof(nla_buf), nla_buf, sizeof(nla_buf),</div><div>> > > +<span style="white-space:pre">           </span>      printf("{nfgen_family=AF_UNIX");</div><div>> > > +<span style="white-space:pre">           </span>      printf(", version=NFNETLINK_V0");</div><div>> > > +<span style="white-space:pre">          </span>      printf(", res_id=htons(NFNL_SUBSYS_NFTABLES)"</div><div>> > > +<span style="white-space:pre">                      </span>     ", {nla_len=%d, nla_type=%#x}",</div><div>> > > +<span style="white-space:pre">                     </span>     nla.nla_len, nla.nla_type));</div><div>> > </div><div>> > The last part of this test fails on one of systems where</div><div>> > I test changes before merging them into master:</div><div>> > </div><div>> > -sendto(3, {{len=24, type=NFNL_SUBSYS_NFTABLES<<8|0xff /* NFT_MSG_??? */, flags=NLM_F_REQUEST, seq=0, pid=0}, {nfgen_family=AF_UNIX, version=NFNETLINK_V0, res_id=htons(NFNL_SUBSYS_NFTABLES), {nla_len=4, nla_type=0xbcd}}, 24, MSG_DONTWAIT, NULL, 0) = 24</div><div>> > +sendto(3, {{len=24, type=NFNL_SUBSYS_NFTABLES<<8|0xff /* NFT_MSG_??? */, flags=NLM_F_REQUEST, seq=0, pid=0}, {nfgen_family=AF_UNIX, version=NFNETLINK_V0, res_id=htons(NFNL_SUBSYS_NFTABLES), "\x04\x00\xcd\x0b"}, 24, MSG_DONTWAIT, NULL, 0) = 24</div><div>> > </div><div>> > Looks like an alignment issue, but I haven't had a chance to look into this yet.</div><div>> </div><div>> No, the reason is completely different: the kernel headers installed on</div><div>> that system are old enough to have NFNL_SUBSYS_COUNT defined to older</div><div>> value than our fallback definition of NFNL_SUBSYS_NFTABLES provided by</div><div>> xlat/<a href="http://nl_netfilter_subsys_ids.in">nl_netfilter_subsys_ids.in</a> file.</div><div><br></div><div>Yes.</div><div><br></div><div>> </div><div>> In other words, NFNL_SUBSYS_COUNT provided by kernel headers is unreliable</div><div>> and shouldn't be used, I think it has to be removed from</div><div>> xlat/<a href="http://nl_netfilter_subsys_ids.in">nl_netfilter_subsys_ids.in</a> as well.</div><div><br></div><div>I can not find an existing way to remove the condition from xlat/*.h.</div><div>xlat/gen.sh only have print_xlat and cond_xlat to generate xlat array.</div><div>Should I add a directive?</div><div><br></div><div>ps: </div><div>Is the same problem exist in other counter symbols in xlat/*.in?</div><div>(I do the research, not found.)</div><div><br></div><div>> </div><div>> For netlink_netfilter.c purposes I'd recommend to use something like</div><div>> (subsys_id > nl_netfilter_subsys_ids[ARRAY_SIZE(nl_netfilter_subsys_ids) - 1].val)</div><div>> instead of subsys_id >= NFNL_SUBSYS_COUNT).</div><div><br></div><div>If I have removed kernel header's NFNL_SUBSYS_COUNT value from</div><div>xlat/<a href="http://nl_netfilter_subsys_ids.in">nl_netfilter_subsys_ids.in</a>.</div><div>Why can't we use subsys_id >= NFNL_SUBSYS_COUNT?</div><div><br></div><div>--</div><div>Chen Jingpiao</div></div>