p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
682 stars 446 forks source link

[PSA eBPF] Invalid access to struct field using pointer #5031

Open marsontti opened 1 week ago

marsontti commented 1 week ago

Hi everyone. I'm trying to implement incremental checksum in P4 PSA eBPF. I'm using P4-eBPF backend to compile my code and error occurs during compilation:

make -f /home/marsontic/p4c-1.2.4.16/backends/ebpf/runtime/kernel.mk BPFOBJ=my_switch.o P4FILE=my_switch.p4 ARGS="-DPSA_PORT_RECIRCULATE=2" P4ARGS="--Wdisable=unused" psa

my_switch.c:1297:35: error: member reference type 'struct metadata *' is a pointer; did you mean to use '->'?
            ck_1_state = user_meta.fwd_metadata.checksum_state;

The P4 code which is related to this:

control EgressDeparserImpl(packet_out packet,
                           out empty_metadata_t clone_e2e_meta,
                           out empty_metadata_t recirculate_meta,
                           inout headers hdr,
                           in metadata user_meta,
                           in psa_egress_output_metadata_t istd,
                           in psa_egress_deparser_input_metadata_t edstd){
    InternetChecksum() ck;
    apply {
         if (hdr.ipv4.isValid()) {
            ck.clear();
            ck.add({
                    hdr.ipv4.version, hdr.ipv4.ihl, hdr.ipv4.diffserv,
                    hdr.ipv4.totalLen,
                    hdr.ipv4.identification,
                    hdr.ipv4.flags, hdr.ipv4.fragOffset,
                    hdr.ipv4.ttl, hdr.ipv4.protocol,
                    hdr.ipv4.srcAddr,
                    hdr.ipv4.dstAddr
                });
            hdr.ipv4.hdrChecksum = ck.get();
        }

        ck.set_state(user_meta.fwd_metadata.checksum_state);

I'm able to workaround this by just changing the line in generated C code and compile again, but I'm not sure if it's a good idea:

ck_1_state = user_meta->fwd_metadata.checksum_state;