P4ELTE / t4p4s

Retargetable compiler for the P4 language
http://p4.elte.hu/
Apache License 2.0
119 stars 42 forks source link

Error when using concatinated bit-string in buffer #55

Open VogelIBR opened 1 year ago

VogelIBR commented 1 year ago

When trying to run a snippet with the following code:

    bit<256> hmac = hdr.four_bytes.hmac;
    bit<16> checksum = hdr.four_bytes.udp_checksum;
    bit<272> concat = hmac ++ checksum;
    verify_hmac({concat});

I get the following error:

FAILED: verify-hmac.p/srcgen_multi_actions.stage_0.c.o 
ccache gcc-11 -Iverify-hmac.p -I. -I.. -I../srcgen -I../srcgen/multi -I../../../src/testing/includes -I../../../src/hardware_dep/dpdk/includes -I../../../src/hardware_dep/shared/includes -I../../../src/hardware_dep/shared/ctrl_plane -I/usr/local/include -I/usr/include/libnl3 -fvisibility=hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -O2 -g -pthread -include rte_config.h -march=native -D__TARGET_V1__ -DT4P4S_INIT_CRYPTO -Wno-deprecated-declarations -DT4P4S_DEBUG=on -DT4P4S_DEBUG_LINENO -MD -MQ verify-hmac.p/srcgen_multi_actions.stage_0.c.o -MF verify-hmac.p/srcgen_multi_actions.stage_0.c.o.d -o verify-hmac.p/srcgen_multi_actions.stage_0.c.o -c ../srcgen/multi/actions.stage_0.c
In file included from ../srcgen/parser.h:9,
                 from ../../../src/hardware_dep/shared/includes/dataplane_hdr_fld_pkt.h:10,
                 from ../../../src/hardware_dep/shared/includes/dataplane.h:7,
                 from ../../../src/hardware_dep/shared/includes/backend.h:7,
                 from ../../../src/hardware_dep/dpdk/includes/dpdk_lib.h:35,
                 from ../srcgen/multi_actions.c:6,
                 from ../srcgen/multi/actions.stage_0.c:5:
../srcgen/multi_actions.c: In function ‘action_code_verifyhmac64’:
../srcgen/hdr_fld.h:8:21: error: ‘HDRT_None_t’ undeclared (first use in this function); did you mean ‘HDRT_bool_t’?
    8 | #define HDRT(hdrt)  HDRT_ ## hdrt
      |                     ^~~~~
../srcgen/multi_actions.c:44:31: note: in expansion of macro ‘HDRT’
   44 |  struct_tuple_0_461697.f0 = *(HDRT(None_t)*)pd->headers[HDR(None)].pointer;
      |                               ^~~~
../srcgen/hdr_fld.h:8:21: note: each undeclared identifier is reported only once for each function it appears in
    8 | #define HDRT(hdrt)  HDRT_ ## hdrt
      |                     ^~~~~
../srcgen/multi_actions.c:44:31: note: in expansion of macro ‘HDRT’
   44 |  struct_tuple_0_461697.f0 = *(HDRT(None_t)*)pd->headers[HDR(None)].pointer;
      |                               ^~~~
In file included from ../srcgen/multi/actions.stage_0.c:5:
../srcgen/multi_actions.c:44:44: error: expected expression before ‘)’ token
   44 |  struct_tuple_0_461697.f0 = *(HDRT(None_t)*)pd->headers[HDR(None)].pointer;
      |                                            ^
ninja: build stopped: subcommand failed.

verify_hmac is defined as follows:

// in p4:
extern void verify_hmac<T1>(in T1 data1);
// in c:
void EXTERNIMPL1(verify_hmac,u8s)(uint8_buffer_t data, SHORT_STDPARAMS) {

If I instead of using the concatinated value I use any of the headers or variables it works fine

    bit<256> hmac = hdr.four_bytes.hmac;
    bit<16> checksum = hdr.four_bytes.udp_checksum;
    bit<272> concat = hmac ++ checksum;
    verify_hmac({hmac}); // works
    verify_hmac({hdr.four_bytes.hmac}); // works