Skip to content

Commit fce557b

Browse files
yonghong-songAlexei Starovoitov
authored and
Alexei Starovoitov
committed
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. Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0f12e58 commit fce557b

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed

include/linux/btf_ids.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,34 @@ asm( \
9797

9898
#endif /* CONFIG_DEBUG_INFO_BTF */
9999

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+
120+
enum {
121+
#define BTF_SOCK_TYPE(name, str) name,
122+
BTF_SOCK_TYPE_xxx
123+
#undef BTF_SOCK_TYPE
124+
MAX_BTF_SOCK_TYPE,
125+
};
126+
127+
extern u32 btf_sock_ids[];
128+
#endif
129+
100130
#endif

net/core/filter.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9421,39 +9421,13 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog)
94219421
bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(xdp), prev_prog, prog);
94229422
}
94239423

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-
9443-
enum {
9444-
#define BTF_SOCK_TYPE(name, str) name,
9445-
BTF_SOCK_TYPE_xxx
9446-
#undef BTF_SOCK_TYPE
9447-
MAX_BTF_SOCK_TYPE,
9448-
};
9449-
94509424
#ifdef CONFIG_DEBUG_INFO_BTF
9451-
BTF_ID_LIST(btf_sock_ids)
9425+
BTF_ID_LIST_GLOBAL(btf_sock_ids)
94529426
#define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type)
94539427
BTF_SOCK_TYPE_xxx
94549428
#undef BTF_SOCK_TYPE
94559429
#else
9456-
static u32 btf_sock_ids[MAX_BTF_SOCK_TYPE];
9430+
u32 btf_sock_ids[MAX_BTF_SOCK_TYPE];
94579431
#endif
94589432

94599433
static bool check_arg_btf_id(u32 btf_id, u32 arg)

tools/include/linux/btf_ids.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,34 @@ asm( \
9797

9898
#endif /* CONFIG_DEBUG_INFO_BTF */
9999

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+
120+
enum {
121+
#define BTF_SOCK_TYPE(name, str) name,
122+
BTF_SOCK_TYPE_xxx
123+
#undef BTF_SOCK_TYPE
124+
MAX_BTF_SOCK_TYPE,
125+
};
126+
127+
extern u32 btf_sock_ids[];
128+
#endif
129+
100130
#endif

0 commit comments

Comments
 (0)