<div dir="ltr"><div>On 03/07 08:30, Eugene Syromyatnikov wrote:</div><div>> On Wed, Mar 7, 2018 at 4:34 AM, Chen Jingpiao <<a href="mailto:chenjingpiao@gmail.com">chenjingpiao@gmail.com</a>> wrote:</div><div>> > +# ifdef WORDS_BIGENDIAN</div><div>> > +                               printf("htons(NFNL_SUBSYS_NFTABLES)");</div><div>> > +# else</div><div>> > +                               printf("NFNL_SUBSYS_NFTABLES");</div><div>> > +# endif</div><div>> </div><div>> I thought that "network order" is big-endian (at least that is what</div><div>> byteorder(3) says), so htons() is no-op there.</div><div>> </div><div>> And I don't see a reason to print the value differently on</div><div>> little-endian and big-endian architectures.</div><div><br></div><div>because res_id in nftables using host byte order.</div><div><br></div><div>in Linux kernel source code: linux/net/netfilter/nfnetlink.c</div><div>(see linux commit v4.3-rc1~28^2~47^2~1)</div><div>static void nfnetlink_rcv_skb_batch(struct sk_buff *skb, struct nlmsghdr *nlh)</div><div>{</div><div><span style="white-space:pre">  </span>...</div><div><br></div><div><span style="white-space:pre">  </span>/* Work around old nft using host byte order */</div><div><span style="white-space:pre">       </span>if (nfgenmsg->res_id == NFNL_SUBSYS_NFTABLES)</div><div><span style="white-space:pre">              </span>res_id = NFNL_SUBSYS_NFTABLES;</div><div><span style="white-space:pre">        </span>else</div><div><span style="white-space:pre">          </span>res_id = ntohs(nfgenmsg->res_id);</div><div><span style="white-space:pre">  </span>...</div><div>}</div><div><br></div><div>in nftables source code: nftables/src/mnl.c</div><div>static void nft_mnl_batch_put(char *buf, uint16_t type, uint32_t seqnum)</div><div>{</div><div><span style="white-space:pre"> </span>...</div><div><span style="white-space:pre">   </span>nfg->res_id = NFNL_SUBSYS_NFTABLES;</div><div>}</div><div><br></div><div>And in big-endian can not distinguish</div><div><br></div><div><span style="white-space:pre">  </span>nfg->res_id = NFNL_SUBSYS_NFTABLES;</div><div><span style="white-space:pre">        </span>and</div><div><span style="white-space:pre">   </span>nfg->res_id = htons(NFNL_SUBSYS_NFTABLES);</div><div><br></div><div>So nfg->res_id = NFNL_SUBSYS_NFTABLES print as</div><div>"res_id=NFNL_SUBSYS_NFTABLES" in little-endian architecture</div><div>"res_id=htons(NFNL_SUBSYS_NFTABLES)" in big-endian architecture</div><div><br></div><div>> </div><div>> +#  ifdef NFNETLINK_V0</div><div>> +                    printf(", version=NFNETLINK_V0");</div><div>> +#  else</div><div>> +                    printf(", version=%#x /* NFNETLINK_??? */", msg.version);</div><div>> +#  endif</div><div>> </div><div>> NFNETLINK_V0 is not architecture-specific, so you can safely provide a</div><div>> fallback definition in xlat *.in file (and always decode it, as a</div><div>> result).</div><div><br></div><div>Ok, thank you.</div><div><br></div><div>--</div><div>Chen Jingpiao</div></div>