diff mbox series

[iproute2] Add missing headers to the project

Message ID a8892441-c0a7-68b2-169e-ae76af0027ad@gmail.com (mailing list archive)
State Changes Requested
Delegated to: David Ahern
Headers show
Series [iproute2] Add missing headers to the project | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Maxim Petrov Nov. 20, 2021, 2 p.m. UTC
The project's headers are not self-contained, as they use some types without
explicitly including the corresponding headers with definitions. That makes the
overall headers structure fragile: reordering/updating the headers may break the
compilation. IDEs also suffer and generate dozens of errors when jumping to some
random header file, distracting programmers from more serious code issues.

Some building issue caused by missing headers has arised just recently and it
required some local cleanup in a31e7b79 (mptcp: cleanup include section). In
this patch I tried to improve the situation for the whole project by adding
missing includes for virtually all the project headers, except uapi ones.

Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
---
 bridge/br_common.h    | 4 ++++
 include/cg_map.h      | 2 ++
 include/color.h       | 2 ++
 include/json_print.h  | 2 ++
 include/json_writer.h | 1 +
 include/ll_map.h      | 3 +++
 include/mnl_utils.h   | 3 +++
 include/rtm_map.h     | 2 ++
 include/xt-internal.h | 2 ++
 ip/ila_common.h       | 1 +
 ip/ip_common.h        | 7 +++++++
 ip/nh_common.h        | 6 ++++++
 ip/xfrm.h             | 3 +++
 misc/lnstat.h         | 1 +
 misc/ssfilter.h       | 1 +
 tc/tc_common.h        | 5 +++++
 tc/tc_red.h           | 2 ++
 tc/tc_util.h          | 3 +++
 tipc/bearer.h         | 1 +
 tipc/link.h           | 3 +++
 tipc/media.h          | 3 +++
 tipc/misc.h           | 2 ++
 tipc/msg.h            | 2 ++
 tipc/nametable.h      | 3 +++
 tipc/node.h           | 3 +++
 tipc/peer.h           | 3 +++
 tipc/socket.h         | 3 +++
 27 files changed, 73 insertions(+)

Comments

Stephen Hemminger Nov. 20, 2021, 5:26 p.m. UTC | #1
On Sat, 20 Nov 2021 17:00:45 +0300
Maxim Petrov <mmrmaximuzz@gmail.com> wrote:

> The project's headers are not self-contained, as they use some types without
> explicitly including the corresponding headers with definitions. That makes the
> overall headers structure fragile: reordering/updating the headers may break the
> compilation. IDEs also suffer and generate dozens of errors when jumping to some
> random header file, distracting programmers from more serious code issues.
> 
> Some building issue caused by missing headers has arised just recently and it
> required some local cleanup in a31e7b79 (mptcp: cleanup include section). In
> this patch I tried to improve the situation for the whole project by adding
> missing includes for virtually all the project headers, except uapi ones.
> 
> Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>

Would be better to do this with an existing tool like IncludeWhatYouUse
Is this what you did?

From 343062efbb3895f9afbff015d49df497b180f3d9 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen@networkplumber.org>
Date: Sat, 20 Nov 2021 09:21:22 -0800
Subject: [PATCH] lib: update headers using iwyu

This is a semi-automated patch generated by using the iwyu
tool: https://github.com/include-what-you-use/include-what-you-use

The result was manually corrected to remove unnecessary
references to <asm/int-ll64.h>
---
 lib/ax25_ntop.c       |  1 +
 lib/bpf_glue.c        |  3 ++-
 lib/bpf_legacy.c      | 21 +++++++++++++++------
 lib/cg_map.c          |  7 ++++---
 lib/color.c           |  3 ++-
 lib/inet_proto.c      |  5 +----
 lib/json_print.c      | 12 ++++++++++--
 lib/json_print_math.c |  2 +-
 lib/json_writer.c     |  6 +++---
 lib/libgenl.c         |  7 ++++++-
 lib/libnetlink.c      | 15 +++++++++++----
 lib/ll_addr.c         |  9 ---------
 lib/ll_map.c          | 10 ++++++----
 lib/ll_proto.c        | 13 ++-----------
 lib/ll_types.c        | 12 ------------
 lib/mnl_utils.c       |  9 ++++++++-
 lib/mpls_ntop.c       |  4 +++-
 lib/mpls_pton.c       |  4 +++-
 lib/names.c           |  5 ++---
 lib/netrom_ntop.c     |  1 +
 lib/rose_ntop.c       | 12 ------------
 lib/rt_names.c        | 11 +++--------
 lib/utils_math.c      |  2 +-
 23 files changed, 85 insertions(+), 89 deletions(-)

diff --git a/lib/ax25_ntop.c b/lib/ax25_ntop.c
index cfd0e04b06f9..c76cf781d95c 100644
--- a/lib/ax25_ntop.c
+++ b/lib/ax25_ntop.c
@@ -3,6 +3,7 @@
 #include <errno.h>
 #include <sys/socket.h>
 #include <netax25/ax25.h>
+#include <stddef.h>
 
 #include "utils.h"
 
diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c
index 70d001840f7b..b093031a0f9c 100644
--- a/lib/bpf_glue.c
+++ b/lib/bpf_glue.c
@@ -4,9 +4,10 @@
  * Authors:	Hangbin Liu <haliu@redhat.com>
  *
  */
-#include <limits.h>
+#include <stddef.h>
 
 #include "bpf_util.h"
+#include "linux/bpf.h"
 #ifdef HAVE_LIBBPF
 #include <bpf/bpf.h>
 #endif
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 6e3891c9f1f1..88ea5ade640f 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c
@@ -22,29 +22,38 @@
 #include <stdarg.h>
 #include <limits.h>
 #include <assert.h>
+#include <bsd/string.h>
+#include <elf.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/statfs.h>
+#include <syscall.h>
 
 #ifdef HAVE_ELF
 #include <libelf.h>
 #include <gelf.h>
 #endif
 
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/un.h>
-#include <sys/vfs.h>
 #include <sys/mount.h>
-#include <sys/syscall.h>
 #include <sys/sendfile.h>
 #include <sys/resource.h>
 
-#include <arpa/inet.h>
-
 #include "utils.h"
 #include "json_print.h"
-
 #include "bpf_util.h"
 #include "bpf_elf.h"
 #include "bpf_scm.h"
+#include "linux/bpf.h"
+#include "linux/bpf_common.h"
+#include "linux/btf.h"
+#include "linux/elf-em.h"
+#include "linux/filter.h"
+#include "linux/if_alg.h"
+#include "linux/limits.h"
+#include "linux/magic.h"
+#include "linux/rtnetlink.h"
 
 struct bpf_prog_meta {
 	const char *type;
diff --git a/lib/cg_map.c b/lib/cg_map.c
index 39f244dbc5bd..80d605d98663 100644
--- a/lib/cg_map.c
+++ b/lib/cg_map.c
@@ -9,18 +9,19 @@
  * Authors:	Dmitry Yakunin <zeil@yandex-team.ru>
  */
 
+#include "cg_map.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdbool.h>
-#include <linux/types.h>
-#include <linux/limits.h>
 #include <ftw.h>
 
-#include "cg_map.h"
 #include "list.h"
 #include "utils.h"
 
+struct stat;
+
 struct cg_cache {
 	struct hlist_node id_hash;
 	__u64	id;
diff --git a/lib/color.c b/lib/color.c
index 59976847295c..930cd5a9a59f 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -5,10 +5,11 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/socket.h>
-#include <sys/types.h>
+#include <stdbool.h>
 #include <linux/if.h>
 
 #include "color.h"
+
 #include "utils.h"
 
 static void set_color_palette(void);
diff --git a/lib/inet_proto.c b/lib/inet_proto.c
index 41e2e8b88d82..fe1333ce80dc 100644
--- a/lib/inet_proto.c
+++ b/lib/inet_proto.c
@@ -12,12 +12,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
 #include <netdb.h>
 #include <string.h>
+#include <bsd/string.h>
 
 #include "rt_names.h"
 #include "utils.h"
diff --git a/lib/json_print.c b/lib/json_print.c
index e3a88375fe7c..51c443e0123d 100644
--- a/lib/json_print.c
+++ b/lib/json_print.c
@@ -9,11 +9,19 @@
  * Authors:    Julien Fortin, <julien@cumulusnetworks.com>
  */
 
-#include <stdarg.h>
+#include "json_print.h"
+
 #include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/time.h>
 
 #include "utils.h"
-#include "json_print.h"
+#include "color.h"
+#include "json_writer.h"
+
+struct timeval;
 
 static json_writer_t *_jw;
 
diff --git a/lib/json_print_math.c b/lib/json_print_math.c
index f4d504995924..837b8dcd4a6f 100644
--- a/lib/json_print_math.c
+++ b/lib/json_print_math.c
@@ -1,11 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0+
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <math.h>
 
 #include "utils.h"
 #include "json_print.h"
+#include "color.h"
 
 char *sprint_size(__u32 sz, char *buf)
 {
diff --git a/lib/json_writer.c b/lib/json_writer.c
index 88c5eb888225..e2d410beb2dc 100644
--- a/lib/json_writer.c
+++ b/lib/json_writer.c
@@ -8,15 +8,15 @@
  * Authors:	Stephen Hemminger <stephen@networkplumber.org>
  */
 
+#include "json_writer.h"
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdarg.h>
 #include <assert.h>
-#include <malloc.h>
 #include <inttypes.h>
 #include <stdint.h>
-
-#include "json_writer.h"
+#include <stdlib.h>
 
 struct json_writer {
 	FILE		*out;	/* output file */
diff --git a/lib/libgenl.c b/lib/libgenl.c
index fca07f9fe768..288ccefcc449 100644
--- a/lib/libgenl.c
+++ b/lib/libgenl.c
@@ -6,9 +6,14 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
+#include <string.h>
 
 #include <linux/genetlink.h>
+
+#include "libnetlink.h"
+#include "linux/netlink.h"
+
+struct rtattr;
 #include "libgenl.h"
 
 static int genl_parse_getfamily(struct nlmsghdr *nlh)
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 7e977a6762f8..22977e005303 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -14,21 +14,28 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <unistd.h>
-#include <fcntl.h>
-#include <net/if_arp.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
 #include <string.h>
 #include <errno.h>
 #include <time.h>
-#include <sys/uio.h>
+#include <bits/types/struct_iovec.h>
+#include <bsd/sys/cdefs.h>
+#include <stdint.h>
+#include <sys/param.h>
 #include <linux/fib_rules.h>
 #include <linux/if_addrlabel.h>
 #include <linux/if_bridge.h>
 #include <linux/nexthop.h>
 
 #include "libnetlink.h"
+
 #include "utils.h"
+#include "linux/if_addr.h"
+#include "linux/if_link.h"
+#include "linux/neighbour.h"
+#include "linux/netconf.h"
+#include "linux/netlink.h"
+#include "linux/rtnetlink.h"
 
 #ifndef __aligned
 #define __aligned(x)		__attribute__((aligned(x)))
diff --git a/lib/ll_addr.c b/lib/ll_addr.c
index d6fd736b1e3a..9a5c45faf5dc 100644
--- a/lib/ll_addr.c
+++ b/lib/ll_addr.c
@@ -10,19 +10,10 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
-
-#include <linux/netdevice.h>
 #include <linux/if_arp.h>
-#include <linux/sockios.h>
-
 #include "rt_names.h"
 #include "utils.h"
 
diff --git a/lib/ll_map.c b/lib/ll_map.c
index 70ea3d499c8f..1ec94bdcd495 100644
--- a/lib/ll_map.c
+++ b/lib/ll_map.c
@@ -10,19 +10,21 @@
  *
  */
 
+#include "ll_map.h"
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
 #include <string.h>
 #include <net/if.h>
+#include <stdbool.h>
 
 #include "libnetlink.h"
-#include "ll_map.h"
 #include "list.h"
 #include "utils.h"
+#include "linux/if_link.h"
+#include "linux/netlink.h"
+#include "linux/rtnetlink.h"
 
 struct ll_cache {
 	struct hlist_node idx_hash;
diff --git a/lib/ll_proto.c b/lib/ll_proto.c
index 78179311c066..aa92fa939f9d 100644
--- a/lib/ll_proto.c
+++ b/lib/ll_proto.c
@@ -10,21 +10,12 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include <linux/netdevice.h>
-#include <linux/if_arp.h>
-#include <linux/sockios.h>
+#include <strings.h>
 
 #include "utils.h"
 #include "rt_names.h"
+#include "linux/if_ether.h"
 
 
 #define __PF(f,n) { ETH_P_##f, #n },
diff --git a/lib/ll_types.c b/lib/ll_types.c
index 49da15df911d..484956f91f7e 100644
--- a/lib/ll_types.c
+++ b/lib/ll_types.c
@@ -10,19 +10,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-
-#include <linux/netdevice.h>
 #include <linux/if_arp.h>
-#include <linux/sockios.h>
-
 #include "rt_names.h"
 #include "utils.h"
 
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index d5abff58d816..2ee1045731c9 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -7,11 +7,18 @@
 #include <string.h>
 #include <time.h>
 #include <libmnl/libmnl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <linux/genetlink.h>
 
-#include "libnetlink.h"
 #include "mnl_utils.h"
+
+#include "libnetlink.h"
 #include "utils.h"
+#include "linux/netlink.h"
+
+struct mnl_socket;
 
 struct mnl_socket *mnlu_socket_open(int bus)
 {
diff --git a/lib/mpls_ntop.c b/lib/mpls_ntop.c
index f8d89f421ecb..f11358956946 100644
--- a/lib/mpls_ntop.c
+++ b/lib/mpls_ntop.c
@@ -2,8 +2,10 @@
 
 #include <errno.h>
 #include <string.h>
-#include <sys/types.h>
 #include <netinet/in.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/socket.h>
 #include <linux/mpls.h>
 
 #include "utils.h"
diff --git a/lib/mpls_pton.c b/lib/mpls_pton.c
index 065374eb11bf..715f49b96dce 100644
--- a/lib/mpls_pton.c
+++ b/lib/mpls_pton.c
@@ -2,8 +2,10 @@
 
 #include <errno.h>
 #include <string.h>
-#include <sys/types.h>
 #include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/socket.h>
 #include <linux/mpls.h>
 
 #include "utils.h"
diff --git a/lib/names.c b/lib/names.c
index b46ea7910946..3f086bb5eb0e 100644
--- a/lib/names.c
+++ b/lib/names.c
@@ -8,14 +8,13 @@
  *
  */
 
+#include "names.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 
-#include "names.h"
-#include "utils.h"
-
 #define MAX_ENTRIES  256
 #define NAME_MAX_LEN 512
 
diff --git a/lib/netrom_ntop.c b/lib/netrom_ntop.c
index 3dd6cb0b3d23..e3e9a2dbb6f6 100644
--- a/lib/netrom_ntop.c
+++ b/lib/netrom_ntop.c
@@ -2,6 +2,7 @@
 
 #include <sys/socket.h>
 #include <errno.h>
+#include <stddef.h>
 #include <linux/ax25.h>
 
 #include "utils.h"
diff --git a/lib/rose_ntop.c b/lib/rose_ntop.c
index c9ba712c515c..9676fa0844c0 100644
--- a/lib/rose_ntop.c
+++ b/lib/rose_ntop.c
@@ -1,22 +1,10 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
 #include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
 #include <errno.h>
-
-#include <linux/netdevice.h>
-#include <linux/if_arp.h>
-#include <linux/sockios.h>
 #include <linux/rose.h>
 
-#include "rt_names.h"
 #include "utils.h"
 
 static const char *rose_ntop1(const rose_address *src, char *dst,
diff --git a/lib/rt_names.c b/lib/rt_names.c
index b976471d7979..a4ae0c7b7e96 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -11,19 +11,14 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
-#include <sys/time.h>
-#include <sys/socket.h>
 #include <dirent.h>
-#include <limits.h>
-
-#include <asm/types.h>
 #include <linux/rtnetlink.h>
 
+#include "linux/limits.h"
+#include "linux/netlink.h"
+
 #include "rt_names.h"
-#include "utils.h"
 
 #define NAME_MAX_LEN 512
 
diff --git a/lib/utils_math.c b/lib/utils_math.c
index 9ef3dd6ed93b..1c3780119649 100644
--- a/lib/utils_math.c
+++ b/lib/utils_math.c
@@ -4,7 +4,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#include <asm/types.h>
+#include <strings.h>
 
 #include "utils.h"
Maxim Petrov Nov. 20, 2021, 8:24 p.m. UTC | #2
Hello Stephen!

On 11/20/21 8:26 PM, Stephen Hemminger wrote:
> Would be better to do this with an existing tool like IncludeWhatYouUse
> Is this what you did?

This is my fault, I didn't even think about searching for any existing tools for
this task. :)

I just wrote a stupid loop over the header files like this:

```bash
for hdr in $(find . -name *.h)
do
	printf '#include "%s"' $hdr > headertest.c
	gcc headertest.c -c -I ./include -I ./include/uapi
done
```

and then manually patched the files until there are no compilation errors.

It seems like I reinvented the wheel and did it not so good. I targeted only
header files and fixed only compilation errors, possibly keeping some transitive
includes. IWYU looks much better as it targets usage, not just compilation
errors. If you can run this tool and fix the whole project automagically, then
it is better to ignore my patch. Anyway, thank you for the information, I will
definitely try IWYU soon.

Max
diff mbox series

Patch

diff --git a/bridge/br_common.h b/bridge/br_common.h
index 610e83f6..7b3c2961 100644
--- a/bridge/br_common.h
+++ b/bridge/br_common.h
@@ -1,5 +1,9 @@ 
 /* SPDX-License-Identifier: GPL-2.0 */
 
+#include <stdbool.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
 #define MDB_RTA(r) \
 		((struct rtattr *)(((char *)(r)) + RTA_ALIGN(sizeof(struct br_mdb_entry))))
 
diff --git a/include/cg_map.h b/include/cg_map.h
index d30517fd..c2fa4647 100644
--- a/include/cg_map.h
+++ b/include/cg_map.h
@@ -1,6 +1,8 @@ 
 #ifndef __CG_MAP_H__
 #define __CG_MAP_H__
 
+#include <linux/types.h>
+
 const char *cg_id_to_path(__u64 id);
 
 #endif /* __CG_MAP_H__ */
diff --git a/include/color.h b/include/color.h
index 17ec56f3..4ef03ecb 100644
--- a/include/color.h
+++ b/include/color.h
@@ -3,6 +3,8 @@ 
 #define __COLOR_H__ 1
 
 #include <stdbool.h>
+#include <stdio.h>
+#include <linux/types.h>
 
 enum color_attr {
 	COLOR_IFNAME,
diff --git a/include/json_print.h b/include/json_print.h
index 91b34571..6691afe1 100644
--- a/include/json_print.h
+++ b/include/json_print.h
@@ -12,6 +12,8 @@ 
 #ifndef _JSON_PRINT_H_
 #define _JSON_PRINT_H_
 
+#include <stdbool.h>
+#include <sys/time.h>
 #include "json_writer.h"
 #include "color.h"
 
diff --git a/include/json_writer.h b/include/json_writer.h
index b52dc2d0..22e1d418 100644
--- a/include/json_writer.h
+++ b/include/json_writer.h
@@ -13,6 +13,7 @@ 
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <stdio.h>
 
 /* Opaque class structure */
 typedef struct json_writer json_writer_t;
diff --git a/include/ll_map.h b/include/ll_map.h
index 4de1041e..5b1dae95 100644
--- a/include/ll_map.h
+++ b/include/ll_map.h
@@ -2,6 +2,9 @@ 
 #ifndef __LL_MAP_H__
 #define __LL_MAP_H__ 1
 
+#include <linux/netlink.h>
+#include "libnetlink.h"
+
 int ll_remember_index(struct nlmsghdr *n, void *arg);
 
 void ll_init_map(struct rtnl_handle *rth);
diff --git a/include/mnl_utils.h b/include/mnl_utils.h
index aa5f0a9b..e8710f40 100644
--- a/include/mnl_utils.h
+++ b/include/mnl_utils.h
@@ -2,6 +2,9 @@ 
 #ifndef __MNL_UTILS_H__
 #define __MNL_UTILS_H__ 1
 
+#include <stdint.h>
+#include <libmnl/libmnl.h>
+
 struct mnlu_gen_socket {
 	struct mnl_socket *nl;
 	char *buf;
diff --git a/include/rtm_map.h b/include/rtm_map.h
index f85e52c4..65f36c85 100644
--- a/include/rtm_map.h
+++ b/include/rtm_map.h
@@ -2,6 +2,8 @@ 
 #ifndef __RTM_MAP_H__
 #define __RTM_MAP_H__ 1
 
+#include <linux/types.h>
+
 char *rtnl_rtntype_n2a(int id, char *buf, int len);
 int rtnl_rtntype_a2n(int *id, char *arg);
 
diff --git a/include/xt-internal.h b/include/xt-internal.h
index 89c73e4f..684ec1b5 100644
--- a/include/xt-internal.h
+++ b/include/xt-internal.h
@@ -6,6 +6,8 @@ 
 #	define XT_LIB_DIR "/lib/xtables"
 #endif
 
+#include <stddef.h>
+
 /* protocol family dependent informations */
 struct afinfo {
 	/* protocol family */
diff --git a/ip/ila_common.h b/ip/ila_common.h
index f99c2672..1121be8c 100644
--- a/ip/ila_common.h
+++ b/ip/ila_common.h
@@ -3,6 +3,7 @@ 
 #define _ILA_COMMON_H_
 
 #include <linux/ila.h>
+#include <linux/types.h>
 #include <string.h>
 
 static inline char *ila_csum_mode2name(__u8 csum_mode)
diff --git a/ip/ip_common.h b/ip/ip_common.h
index ea04c8ff..4511d8f7 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -3,8 +3,15 @@ 
 #define _IP_COMMON_H_
 
 #include <stdbool.h>
+#include <stdio.h>
+
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/types.h>
 
 #include "json_print.h"
+#include "libnetlink.h"
+#include "utils.h"
 
 extern int use_iec;
 
diff --git a/ip/nh_common.h b/ip/nh_common.h
index 4d6677e6..eacf970b 100644
--- a/ip/nh_common.h
+++ b/ip/nh_common.h
@@ -2,7 +2,13 @@ 
 #ifndef __NH_COMMON_H__
 #define __NH_COMMON_H__ 1
 
+#include <stdbool.h>
+#include <stdio.h>
 #include <list.h>
+#include <netinet/in.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/types.h>
 
 #define NH_CACHE_SIZE		1024
 
diff --git a/ip/xfrm.h b/ip/xfrm.h
index 17dcf3fe..e6a00e45 100644
--- a/ip/xfrm.h
+++ b/ip/xfrm.h
@@ -24,9 +24,12 @@ 
 #ifndef __XFRM_H__
 #define __XFRM_H__ 1
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <sys/socket.h>
 #include <linux/in.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
 #include <linux/xfrm.h>
 #include <linux/ipsec.h>
 
diff --git a/misc/lnstat.h b/misc/lnstat.h
index 433599cc..58d5b48a 100644
--- a/misc/lnstat.h
+++ b/misc/lnstat.h
@@ -3,6 +3,7 @@ 
 #define _LNSTAT_H
 
 #include <limits.h>
+#include <stdio.h>
 #include <sys/select.h>
 
 #define PROC_NET_STAT	"/proc/net/stat"
diff --git a/misc/ssfilter.h b/misc/ssfilter.h
index 0be3b1e0..bf7ed58a 100644
--- a/misc/ssfilter.h
+++ b/misc/ssfilter.h
@@ -1,4 +1,5 @@ 
 #include <stdbool.h>
+#include <stdio.h>
 
 enum {
 	SSF_DCOND,
diff --git a/tc/tc_common.h b/tc/tc_common.h
index 58dc9d6a..e1a53400 100644
--- a/tc/tc_common.h
+++ b/tc/tc_common.h
@@ -1,5 +1,10 @@ 
 /* SPDX-License-Identifier: GPL-2.0 */
 
+#include <stdbool.h>
+#include <stdio.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
 #define TCA_BUF_MAX	(64*1024)
 
 extern struct rtnl_handle rth;
diff --git a/tc/tc_red.h b/tc/tc_red.h
index 3882c831..44d1024d 100644
--- a/tc/tc_red.h
+++ b/tc/tc_red.h
@@ -2,6 +2,8 @@ 
 #ifndef _TC_RED_H_
 #define _TC_RED_H_ 1
 
+#include <linux/types.h>
+
 int tc_red_eval_P(unsigned qmin, unsigned qmax, double prob);
 int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt);
 int tc_red_eval_idle_damping(int wlog, unsigned avpkt, unsigned bandwidth,
diff --git a/tc/tc_util.h b/tc/tc_util.h
index b197bcdd..90b2c688 100644
--- a/tc/tc_util.h
+++ b/tc/tc_util.h
@@ -6,10 +6,13 @@ 
 #include <limits.h>
 #include <linux/if.h>
 #include <stdbool.h>
+#include <stdio.h>
 
 #include <linux/pkt_sched.h>
 #include <linux/pkt_cls.h>
 #include <linux/gen_stats.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
 
 #include "tc_core.h"
 #include "json_print.h"
diff --git a/tipc/bearer.h b/tipc/bearer.h
index c0d09963..6b5b8faf 100644
--- a/tipc/bearer.h
+++ b/tipc/bearer.h
@@ -12,6 +12,7 @@ 
 #ifndef _TIPC_BEARER_H
 #define _TIPC_BEARER_H
 
+#include <linux/netlink.h>
 #include "cmdl.h"
 
 extern int help_flag;
diff --git a/tipc/link.h b/tipc/link.h
index 6dc95e5b..ba3803ca 100644
--- a/tipc/link.h
+++ b/tipc/link.h
@@ -12,6 +12,9 @@ 
 #ifndef _TIPC_LINK_H
 #define _TIPC_LINK_H
 
+#include <linux/netlink.h>
+#include "cmdl.h"
+
 extern int help_flag;
 
 int cmd_link(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
diff --git a/tipc/media.h b/tipc/media.h
index 8584af74..b43621f6 100644
--- a/tipc/media.h
+++ b/tipc/media.h
@@ -12,6 +12,9 @@ 
 #ifndef _TIPC_MEDIA_H
 #define _TIPC_MEDIA_H
 
+#include <linux/netlink.h>
+#include "cmdl.h"
+
 extern int help_flag;
 
 int cmd_media(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
diff --git a/tipc/misc.h b/tipc/misc.h
index 59309f68..5067e07a 100644
--- a/tipc/misc.h
+++ b/tipc/misc.h
@@ -14,6 +14,8 @@ 
 
 #include <stdint.h>
 
+#include <linux/tipc.h>
+
 uint32_t str2addr(char *str);
 int str2nodeid(char *str, uint8_t *id);
 void nodeid2str(uint8_t *id, char *str);
diff --git a/tipc/msg.h b/tipc/msg.h
index 56af5a70..46b3ed74 100644
--- a/tipc/msg.h
+++ b/tipc/msg.h
@@ -12,6 +12,8 @@ 
 #ifndef _TIPC_MSG_H
 #define _TIPC_MSG_H
 
+#include <libmnl/libmnl.h>
+
 struct nlmsghdr *msg_init(int cmd);
 int msg_doit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data);
 int msg_dumpit(struct nlmsghdr *nlh, mnl_cb_t callback, void *data);
diff --git a/tipc/nametable.h b/tipc/nametable.h
index e0473e18..bdf9515e 100644
--- a/tipc/nametable.h
+++ b/tipc/nametable.h
@@ -12,6 +12,9 @@ 
 #ifndef _TIPC_NAMETABLE_H
 #define _TIPC_NAMETABLE_H
 
+#include <linux/netlink.h>
+#include "cmdl.h"
+
 extern int help_flag;
 
 void cmd_nametable_help(struct cmdl *cmdl);
diff --git a/tipc/node.h b/tipc/node.h
index afee1fd0..57fd618e 100644
--- a/tipc/node.h
+++ b/tipc/node.h
@@ -12,6 +12,9 @@ 
 #ifndef _TIPC_NODE_H
 #define _TIPC_NODE_H
 
+#include <linux/netlink.h>
+#include "cmdl.h"
+
 extern int help_flag;
 
 int cmd_node(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
diff --git a/tipc/peer.h b/tipc/peer.h
index 89722616..d87b2970 100644
--- a/tipc/peer.h
+++ b/tipc/peer.h
@@ -12,6 +12,9 @@ 
 #ifndef _TIPC_PEER_H
 #define _TIPC_PEER_H
 
+#include <linux/netlink.h>
+#include "cmdl.h"
+
 extern int help_flag;
 
 int cmd_peer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
diff --git a/tipc/socket.h b/tipc/socket.h
index 9d1b6487..332760b7 100644
--- a/tipc/socket.h
+++ b/tipc/socket.h
@@ -12,6 +12,9 @@ 
 #ifndef _TIPC_SOCKET_H
 #define _TIPC_SOCKET_H
 
+#include <linux/netlink.h>
+#include "cmdl.h"
+
 extern int help_flag;
 
 void cmd_socket_help(struct cmdl *cmdl);