History

bpf: Make btf_sock_ids global

tcp and udp bpf_iter can reuse some socket ids in btf_sock_ids, so make it global. I put the extern definition in btf_ids.h as a central place so it can be easily discovered by developers.

Yonghong Song committed 6 years ago

Commit fce557b1 parent 0f12e583 files · +62 −28Browse files

Unified · Split

3 files
  1. include/linux/btf_ids.h +30 −0
  2. net/core/filter.c +2 −28
  3. tools/include/linux/btf_ids.h +30 −0
include/linux/btf_ids.h+30−0
@@ -97,4 +97,34 @@ asm( \ · 96 unmodified lines
97 97
98#endif /* CONFIG_DEBUG_INFO_BTF */98#endif /* CONFIG_DEBUG_INFO_BTF */
99 99
100#ifdef CONFIG_NET
101/* Define a list of socket types which can be the argument for
102 * skc_to_*_sock() helpers. All these sockets should have
103 * sock_common as the first argument in its memory layout.
104 */
105#define BTF_SOCK_TYPE_xxx \
106 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
107 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
108 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
109 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
110 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
111 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
112 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
113 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
114 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
115 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
116 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
117 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
118 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
119
120enum {
121#define BTF_SOCK_TYPE(name, str) name,
122BTF_SOCK_TYPE_xxx
123#undef BTF_SOCK_TYPE
124MAX_BTF_SOCK_TYPE,
125};
126
127extern u32 btf_sock_ids[];
128#endif
129
100#endif130#endif
net/core/filter.c+2−28
@@ -9421,39 +9421,13 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog) · 9420 unmodified lines
9421 bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(xdp), prev_prog, prog);9421 bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(xdp), prev_prog, prog);
9422}9422}
9423 9423
9424/* Define a list of socket types which can be the argument for
9425 * skc_to_*_sock() helpers. All these sockets should have
9426 * sock_common as the first argument in its memory layout.
9427 */
9428#define BTF_SOCK_TYPE_xxx \
9429 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
9430 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
9431 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
9432 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
9433 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
9434 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
9435 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
9436 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
9437 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
9438 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
9439 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
9440 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
9441 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
9442
9443enum {
9444#define BTF_SOCK_TYPE(name, str) name,
9445BTF_SOCK_TYPE_xxx
9446#undef BTF_SOCK_TYPE
9447MAX_BTF_SOCK_TYPE,
9448};
9449
9450#ifdef CONFIG_DEBUG_INFO_BTF9424#ifdef CONFIG_DEBUG_INFO_BTF
9451BTF_ID_LIST(btf_sock_ids)9425BTF_ID_LIST_GLOBAL(btf_sock_ids)
9452#define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type)9426#define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type)
9453BTF_SOCK_TYPE_xxx9427BTF_SOCK_TYPE_xxx
9454#undef BTF_SOCK_TYPE9428#undef BTF_SOCK_TYPE
9455#else9429#else
9456static u32 btf_sock_ids[MAX_BTF_SOCK_TYPE];9430u32 btf_sock_ids[MAX_BTF_SOCK_TYPE];
9457#endif9431#endif
9458 9432
9459static bool check_arg_btf_id(u32 btf_id, u32 arg)9433static bool check_arg_btf_id(u32 btf_id, u32 arg)
tools/include/linux/btf_ids.h+30−0
@@ -97,4 +97,34 @@ asm( \ · 96 unmodified lines
97 97
98#endif /* CONFIG_DEBUG_INFO_BTF */98#endif /* CONFIG_DEBUG_INFO_BTF */
99 99
100#ifdef CONFIG_NET
101/* Define a list of socket types which can be the argument for
102 * skc_to_*_sock() helpers. All these sockets should have
103 * sock_common as the first argument in its memory layout.
104 */
105#define BTF_SOCK_TYPE_xxx \
106 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
107 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
108 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
109 BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
110 BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
111 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
112 BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
113 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
114 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
115 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
116 BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
117 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
118 BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
119
120enum {
121#define BTF_SOCK_TYPE(name, str) name,
122BTF_SOCK_TYPE_xxx
123#undef BTF_SOCK_TYPE
124MAX_BTF_SOCK_TYPE,
125};
126
127extern u32 btf_sock_ids[];
128#endif
129
100#endif130#endif