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.
Unified · Split
| @@ -97,4 +97,34 @@ asm( \ · 96 unmodified lines | ||
| 97 | 97 | |
| 98 | 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 | + | |
| 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 | + | |
| 100 | 130 | #endif |
| @@ -9421,39 +9421,13 @@ void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog) · 9420 unmodified lines | ||
| 9421 | 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 | − | |
| 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 | − | |
| 9450 | 9424 | #ifdef CONFIG_DEBUG_INFO_BTF |
| 9451 | −BTF_ID_LIST(btf_sock_ids) | |
| 9425 | +BTF_ID_LIST_GLOBAL(btf_sock_ids) | |
| 9452 | 9426 | #define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type) |
| 9453 | 9427 | BTF_SOCK_TYPE_xxx |
| 9454 | 9428 | #undef BTF_SOCK_TYPE |
| 9455 | 9429 | #else |
| 9456 | −static u32 btf_sock_ids[MAX_BTF_SOCK_TYPE]; | |
| 9430 | +u32 btf_sock_ids[MAX_BTF_SOCK_TYPE]; | |
| 9457 | 9431 | #endif |
| 9458 | 9432 | |
| 9459 | 9433 | static bool check_arg_btf_id(u32 btf_id, u32 arg) |
| @@ -97,4 +97,34 @@ asm( \ · 96 unmodified lines | ||
| 97 | 97 | |
| 98 | 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 | + | |
| 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 | + | |
| 100 | 130 | #endif |