Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net, uapi: remove inclusion of arpa/inet.h

In include/uapi/linux/tipc_config.h, there's a comment that it includes
arpa/inet.h for ntohs; but ntohs is not defined in any UAPI header. For
now, reuse the definitions from include/linux/byteorder/generic.h, since
the various conversion functions do exist in UAPI headers:
include/uapi/linux/byteorder/big_endian.h
include/uapi/linux/byteorder/little_endian.h

We would like to get to the point where we can build UAPI header tests
with -nostdinc, meaning that kernel UAPI headers should not have a
circular dependency on libc headers.

Link: https://android-review.googlesource.com/c/platform/bionic/+/2048127
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Nick Desaulniers and committed by
David S. Miller
1ee375d7 f4b41f06

+12 -16
+12 -16
include/uapi/linux/tipc_config.h
··· 43 43 #include <linux/tipc.h> 44 44 #include <asm/byteorder.h> 45 45 46 - #ifndef __KERNEL__ 47 - #include <arpa/inet.h> /* for ntohs etc. */ 48 - #endif 49 - 50 46 /* 51 47 * Configuration 52 48 * ··· 265 269 */ 266 270 267 271 return (space >= TLV_SPACE(0)) && 268 - (ntohs(((struct tlv_desc *)tlv)->tlv_len) <= space); 272 + (__be16_to_cpu(((struct tlv_desc *)tlv)->tlv_len) <= space); 269 273 } 270 274 271 275 static inline int TLV_CHECK(const void *tlv, __u16 space, __u16 exp_type) 272 276 { 273 277 return TLV_OK(tlv, space) && 274 - (ntohs(((struct tlv_desc *)tlv)->tlv_type) == exp_type); 278 + (__be16_to_cpu(((struct tlv_desc *)tlv)->tlv_type) == exp_type); 275 279 } 276 280 277 281 static inline int TLV_GET_LEN(struct tlv_desc *tlv) 278 282 { 279 - return ntohs(tlv->tlv_len); 283 + return __be16_to_cpu(tlv->tlv_len); 280 284 } 281 285 282 286 static inline void TLV_SET_LEN(struct tlv_desc *tlv, __u16 len) 283 287 { 284 - tlv->tlv_len = htons(len); 288 + tlv->tlv_len = __cpu_to_be16(len); 285 289 } 286 290 287 291 static inline int TLV_CHECK_TYPE(struct tlv_desc *tlv, __u16 type) 288 292 { 289 - return (ntohs(tlv->tlv_type) == type); 293 + return (__be16_to_cpu(tlv->tlv_type) == type); 290 294 } 291 295 292 296 static inline void TLV_SET_TYPE(struct tlv_desc *tlv, __u16 type) 293 297 { 294 - tlv->tlv_type = htons(type); 298 + tlv->tlv_type = __cpu_to_be16(type); 295 299 } 296 300 297 301 static inline int TLV_SET(void *tlv, __u16 type, void *data, __u16 len) ··· 301 305 302 306 tlv_len = TLV_LENGTH(len); 303 307 tlv_ptr = (struct tlv_desc *)tlv; 304 - tlv_ptr->tlv_type = htons(type); 305 - tlv_ptr->tlv_len = htons(tlv_len); 308 + tlv_ptr->tlv_type = __cpu_to_be16(type); 309 + tlv_ptr->tlv_len = __cpu_to_be16(tlv_len); 306 310 if (len && data) { 307 311 memcpy(TLV_DATA(tlv_ptr), data, len); 308 312 memset((char *)TLV_DATA(tlv_ptr) + len, 0, TLV_SPACE(len) - tlv_len); ··· 344 348 345 349 static inline void TLV_LIST_STEP(struct tlv_list_desc *list) 346 350 { 347 - __u16 tlv_space = TLV_ALIGN(ntohs(list->tlv_ptr->tlv_len)); 351 + __u16 tlv_space = TLV_ALIGN(__be16_to_cpu(list->tlv_ptr->tlv_len)); 348 352 349 353 list->tlv_ptr = (struct tlv_desc *)((char *)list->tlv_ptr + tlv_space); 350 354 list->tlv_space -= tlv_space; ··· 400 404 401 405 msg_len = TCM_LENGTH(data_len); 402 406 tcm_hdr = (struct tipc_cfg_msg_hdr *)msg; 403 - tcm_hdr->tcm_len = htonl(msg_len); 404 - tcm_hdr->tcm_type = htons(cmd); 405 - tcm_hdr->tcm_flags = htons(flags); 407 + tcm_hdr->tcm_len = __cpu_to_be32(msg_len); 408 + tcm_hdr->tcm_type = __cpu_to_be16(cmd); 409 + tcm_hdr->tcm_flags = __cpu_to_be16(flags); 406 410 if (data_len && data) { 407 411 memcpy(TCM_DATA(msg), data, data_len); 408 412 memset((char *)TCM_DATA(msg) + data_len, 0, TCM_SPACE(data_len) - msg_len);