Open imgrass opened 4 years ago
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#define __maybe_unused __attribute__((__unused__))
/* Header cursor to keep track of current parsing position */
struct hdr_cursor {
void *pos;
};
struct icmphdr_common {
__u8 type;
__u8 code;
};
/* Function prototypes with __maybe_unused attribute */
static __always_inline __maybe_unused int proto_is_vlan(__u16 h_proto);
static __always_inline __maybe_unused int parse_icmp6hdr(struct hdr_cursor *nh, void *data_end, struct icmphdr_common *icmphdr);
static __always_inline __maybe_unused int parse_icmphdr(struct hdr_cursor *nh, void *data_end, struct icmphdr_common *icmphdr);
static __always_inline __maybe_unused int parse_udphdr(struct hdr_cursor *nh, void *data_end, struct udphdr **udp);
static __always_inline __maybe_unused int parse_tcphdr(struct hdr_cursor *nh, void *data_end, struct tcphdr **tcp);
static __always_inline __maybe_unused int proto_is_vlan(__u16 h_proto) {
return h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD);
}
static __always_inline __maybe_unused int parse_icmp6hdr(struct hdr_cursor *nh, void *data_end, struct icmphdr_common *icmphdr) {
struct icmp6hdr *hdr = nh->pos;
if (hdr + 1 > data_end)
return -1;
icmphdr->type = hdr->icmp6_type;
icmphdr->code = hdr->icmp6_code;
nh->pos = hdr + 1;
return 0;
}
static __always_inline __maybe_unused int parse_icmphdr(struct hdr_cursor *nh, void *data_end, struct icmphdr_common *icmphdr) {
struct icmphdr *hdr = nh->pos;
if (hdr + 1 > data_end)
return -1;
icmphdr->type = hdr->type;
icmphdr->code = hdr->code;
nh->pos = hdr + 1;
return 0;
}
static __always_inline __maybe_unused int parse_udphdr(struct hdr_cursor *nh, void *data_end, struct udphdr **udp) {
struct udphdr *hdr = nh->pos;
if (hdr + 1 > data_end)
return -1;
*udp = hdr;
nh->pos = hdr + 1;
return 0;
}
static __always_inline __maybe_unused int parse_tcphdr(struct hdr_cursor *nh, void *data_end, struct tcphdr **tcp) {
struct tcphdr *hdr = nh->pos;
if (hdr + 1 > data_end)
return -1;
*tcp = hdr;
nh->pos = hdr + 1;
return 0;
}
In commit "dcdc6836f237c8a1a36b2d699c171475a7c4d07e" with branch "origin/master", the following compilation error would occur like that:
I added "__maybe_unused" marco to these function definitions shown as below, then these errors disappeared
This is my system info:
Is this a bug? Or there are other steps need to be done firstly?