clangllvmebpf

Could use memcpy or memset in ebpf prog ?


I have follow ebpf prog, but when compile with clang, it reported error: A call to built-in function 'memset' is not supported for ip4_str[m++] = temp[j];. In ebpf prog, we can't use a character copy?

    char ip4_str[sizeof("255.255.255.255")];
    u8 iparr[4];
    iparr[0] = (ip >> 24) & 0xFF;
    iparr[1] = (ip >> 16) & 0xFF;
    iparr[2] = (ip >> 8) & 0xFF;
    iparr[3] = (ip >> 0) & 0xFF;
    int ip_l = 0;
    int m = 0;
    for (int i = 0; i < 4; i++) {
        u8 r = iparr[i];
        char temp[4];
        int ret = convert(r, temp);
        ip_l += ret;
        int j = 0;
        // __builtin_memcpy(ip4_str, temp, ret);
        while (j < ret) {
            ip4_str[m++] = temp[j];
            j++;
        } 
        if (i < 3) {
            ip4_str[m++] = '.';
            ip_l++;
        }
    }
    ip4_str[m++] = '\0';

Solution

  • For clang/llvm, you can use __builtin_memcpy to do copy:

     __builtin_memcpy(&ip4_str, &temp, ret);