In preparation for using the struct_group() macro in struct sk_buff, move the conditional preprocessor directives out of the region of struct sk_buff that will be enclosed by struct_group(). While GCC and Clang are happy with conditional preprocessor directives here, sparse is not, even under -Wno-directive-within-macro[1], as would be seen under a C=1 build: net/core/filter.c: note: in included file (through include/linux/netlink.h, include/linux/sock_diag.h): ./include/linux/skbuff.h:820:1: warning: directive in macro's argument list ./include/linux/skbuff.h:822:1: warning: directive in macro's argument list ./include/linux/skbuff.h:846:1: warning: directive in macro's argument list ./include/linux/skbuff.h:848:1: warning: directive in macro's argument list Additionally remove empty macro argument definitions and usage. "objdump -d" shows no object code differences. [1] https://www.spinics.net/lists/linux-sparse/msg10857.html
Unified · Split
| @@ -795,7 +795,7 @@ struct sk_buff { · 794 unmodified lines | |||
| 795 | #else | 795 | #else |
| 796 | #define CLONED_MASK 1 | 796 | #define CLONED_MASK 1 |
| 797 | #endif | 797 | #endif |
| 798 | #define CLONED_OFFSET() offsetof(struct sk_buff, __cloned_offset) | 798 | #define CLONED_OFFSET offsetof(struct sk_buff, __cloned_offset) |
| 799 | 799 | ||
| 800 | /* private: */ | 800 | /* private: */ |
| 801 | __u8 __cloned_offset[0]; | 801 | __u8 __cloned_offset[0]; |
| @@ -818,18 +818,10 @@ struct sk_buff { · 16 unmodified lines | |||
| 818 | __u32 headers_start[0]; | 818 | __u32 headers_start[0]; |
| 819 | /* public: */ | 819 | /* public: */ |
| 820 | 820 | ||
| 821 | /* if you move pkt_type around you also must adapt those constants */ | ||
| 822 | #ifdef __BIG_ENDIAN_BITFIELD | ||
| 823 | #define PKT_TYPE_MAX (7 << 5) | ||
| 824 | #else | ||
| 825 | #define PKT_TYPE_MAX 7 | ||
| 826 | #endif | ||
| 827 | #define PKT_TYPE_OFFSET() offsetof(struct sk_buff, __pkt_type_offset) | ||
| 828 | |||
| 829 | /* private: */ | 821 | /* private: */ |
| 830 | __u8 __pkt_type_offset[0]; | 822 | __u8 __pkt_type_offset[0]; |
| 831 | /* public: */ | 823 | /* public: */ |
| 832 | __u8 pkt_type:3; | 824 | __u8 pkt_type:3; /* see PKT_TYPE_MAX */ |
| 833 | __u8 ignore_df:1; | 825 | __u8 ignore_df:1; |
| 834 | __u8 nf_trace:1; | 826 | __u8 nf_trace:1; |
| 835 | __u8 ip_summed:2; | 827 | __u8 ip_summed:2; |
| @@ -845,16 +837,10 @@ struct sk_buff { · 9 unmodified lines | |||
| 845 | __u8 encap_hdr_csum:1; | 837 | __u8 encap_hdr_csum:1; |
| 846 | __u8 csum_valid:1; | 838 | __u8 csum_valid:1; |
| 847 | 839 | ||
| 848 | #ifdef __BIG_ENDIAN_BITFIELD | ||
| 849 | #define PKT_VLAN_PRESENT_BIT 7 | ||
| 850 | #else | ||
| 851 | #define PKT_VLAN_PRESENT_BIT 0 | ||
| 852 | #endif | ||
| 853 | #define PKT_VLAN_PRESENT_OFFSET() offsetof(struct sk_buff, __pkt_vlan_present_offset) | ||
| 854 | /* private: */ | 840 | /* private: */ |
| 855 | __u8 __pkt_vlan_present_offset[0]; | 841 | __u8 __pkt_vlan_present_offset[0]; |
| 856 | /* public: */ | 842 | /* public: */ |
| 857 | __u8 vlan_present:1; | 843 | __u8 vlan_present:1; /* See PKT_VLAN_PRESENT_BIT */ |
| 858 | __u8 csum_complete_sw:1; | 844 | __u8 csum_complete_sw:1; |
| 859 | __u8 csum_level:2; | 845 | __u8 csum_level:2; |
| 860 | __u8 csum_not_inet:1; | 846 | __u8 csum_not_inet:1; |
| @@ -953,6 +939,22 @@ struct sk_buff { · 92 unmodified lines | |||
| 953 | #endif | 939 | #endif |
| 954 | }; | 940 | }; |
| 955 | 941 | ||
| 942 | /* if you move pkt_type around you also must adapt those constants */ | ||
| 943 | #ifdef __BIG_ENDIAN_BITFIELD | ||
| 944 | #define PKT_TYPE_MAX (7 << 5) | ||
| 945 | #else | ||
| 946 | #define PKT_TYPE_MAX 7 | ||
| 947 | #endif | ||
| 948 | #define PKT_TYPE_OFFSET offsetof(struct sk_buff, __pkt_type_offset) | ||
| 949 | |||
| 950 | /* if you move pkt_vlan_present around you also must adapt these constants */ | ||
| 951 | #ifdef __BIG_ENDIAN_BITFIELD | ||
| 952 | #define PKT_VLAN_PRESENT_BIT 7 | ||
| 953 | #else | ||
| 954 | #define PKT_VLAN_PRESENT_BIT 0 | ||
| 955 | #endif | ||
| 956 | #define PKT_VLAN_PRESENT_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset) | ||
| 957 | |||
| 956 | #ifdef __KERNEL__ | 958 | #ifdef __KERNEL__ |
| 957 | /* | 959 | /* |
| 958 | * Handling routines are only of interest to the kernel | 960 | * Handling routines are only of interest to the kernel |
| @@ -301,7 +301,7 @@ static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg, · 300 unmodified lines | |||
| 301 | break; | 301 | break; |
| 302 | 302 | ||
| 303 | case SKF_AD_PKTTYPE: | 303 | case SKF_AD_PKTTYPE: |
| 304 | *insn++ = BPF_LDX_MEM(BPF_B, dst_reg, src_reg, PKT_TYPE_OFFSET()); | 304 | *insn++ = BPF_LDX_MEM(BPF_B, dst_reg, src_reg, PKT_TYPE_OFFSET); |
| 305 | *insn++ = BPF_ALU32_IMM(BPF_AND, dst_reg, PKT_TYPE_MAX); | 305 | *insn++ = BPF_ALU32_IMM(BPF_AND, dst_reg, PKT_TYPE_MAX); |
| 306 | #ifdef __BIG_ENDIAN_BITFIELD | 306 | #ifdef __BIG_ENDIAN_BITFIELD |
| 307 | *insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, 5); | 307 | *insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, 5); |
| @@ -323,7 +323,7 @@ static u32 convert_skb_access(int skb_field, int dst_reg, int src_reg, · 15 unmodified lines | |||
| 323 | offsetof(struct sk_buff, vlan_tci)); | 323 | offsetof(struct sk_buff, vlan_tci)); |
| 324 | break; | 324 | break; |
| 325 | case SKF_AD_VLAN_TAG_PRESENT: | 325 | case SKF_AD_VLAN_TAG_PRESENT: |
| 326 | *insn++ = BPF_LDX_MEM(BPF_B, dst_reg, src_reg, PKT_VLAN_PRESENT_OFFSET()); | 326 | *insn++ = BPF_LDX_MEM(BPF_B, dst_reg, src_reg, PKT_VLAN_PRESENT_OFFSET); |
| 327 | if (PKT_VLAN_PRESENT_BIT) | 327 | if (PKT_VLAN_PRESENT_BIT) |
| 328 | *insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, PKT_VLAN_PRESENT_BIT); | 328 | *insn++ = BPF_ALU32_IMM(BPF_RSH, dst_reg, PKT_VLAN_PRESENT_BIT); |
| 329 | if (PKT_VLAN_PRESENT_BIT < 7) | 329 | if (PKT_VLAN_PRESENT_BIT < 7) |
| @@ -8029,7 +8029,7 @@ static int bpf_unclone_prologue(struct bpf_insn *insn_buf, bool direct_write, · 7699 unmodified lines | |||
| 8029 | * (Fast-path, otherwise approximation that we might be | 8029 | * (Fast-path, otherwise approximation that we might be |
| 8030 | * a clone, do the rest in helper.) | 8030 | * a clone, do the rest in helper.) |
| 8031 | */ | 8031 | */ |
| 8032 | *insn++ = BPF_LDX_MEM(BPF_B, BPF_REG_6, BPF_REG_1, CLONED_OFFSET()); | 8032 | *insn++ = BPF_LDX_MEM(BPF_B, BPF_REG_6, BPF_REG_1, CLONED_OFFSET); |
| 8033 | *insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_6, CLONED_MASK); | 8033 | *insn++ = BPF_ALU32_IMM(BPF_AND, BPF_REG_6, CLONED_MASK); |
| 8034 | *insn++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_6, 0, 7); | 8034 | *insn++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_6, 0, 7); |
| 8035 | 8035 | ||
| @@ -8617,7 +8617,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, · 581 unmodified lines | |||
| 8617 | case offsetof(struct __sk_buff, pkt_type): | 8617 | case offsetof(struct __sk_buff, pkt_type): |
| 8618 | *target_size = 1; | 8618 | *target_size = 1; |
| 8619 | *insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg, | 8619 | *insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg, |
| 8620 | PKT_TYPE_OFFSET()); | 8620 | PKT_TYPE_OFFSET); |
| 8621 | *insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, PKT_TYPE_MAX); | 8621 | *insn++ = BPF_ALU32_IMM(BPF_AND, si->dst_reg, PKT_TYPE_MAX); |
| 8622 | #ifdef __BIG_ENDIAN_BITFIELD | 8622 | #ifdef __BIG_ENDIAN_BITFIELD |
| 8623 | *insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, 5); | 8623 | *insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, 5); |
| @@ -8642,7 +8642,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, · 18 unmodified lines | |||
| 8642 | case offsetof(struct __sk_buff, vlan_present): | 8642 | case offsetof(struct __sk_buff, vlan_present): |
| 8643 | *target_size = 1; | 8643 | *target_size = 1; |
| 8644 | *insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg, | 8644 | *insn++ = BPF_LDX_MEM(BPF_B, si->dst_reg, si->src_reg, |
| 8645 | PKT_VLAN_PRESENT_OFFSET()); | 8645 | PKT_VLAN_PRESENT_OFFSET); |
| 8646 | if (PKT_VLAN_PRESENT_BIT) | 8646 | if (PKT_VLAN_PRESENT_BIT) |
| 8647 | *insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, PKT_VLAN_PRESENT_BIT); | 8647 | *insn++ = BPF_ALU32_IMM(BPF_RSH, si->dst_reg, PKT_VLAN_PRESENT_BIT); |
| 8648 | if (PKT_VLAN_PRESENT_BIT < 7) | 8648 | if (PKT_VLAN_PRESENT_BIT < 7) |