On 30/10/2023 13:48, Zachary Leaf wrote:
+static int check_attr(int cmd, void *vattr) +{
- switch (cmd) {
- case BPF_MAP_CREATE:
return CHECK_ATTR(BPF_MAP_CREATE);
- case BPF_MAP_LOOKUP_ELEM:
return CHECK_ATTR(BPF_MAP_LOOKUP_ELEM);
- case BPF_MAP_GET_NEXT_KEY:
return CHECK_ATTR(BPF_MAP_GET_NEXT_KEY);
- case BPF_MAP_FREEZE:
return CHECK_ATTR(BPF_MAP_FREEZE);
- case BPF_PROG_LOAD:
return CHECK_ATTR(BPF_PROG_LOAD);
- case BPF_OBJ_PIN:
return CHECK_ATTR(BPF_OBJ);
- case BPF_OBJ_GET:
return CHECK_ATTR(BPF_OBJ);
- case BPF_PROG_ATTACH:
return CHECK_ATTR(BPF_PROG_ATTACH);
- case BPF_PROG_DETACH:
return CHECK_ATTR(BPF_PROG_DETACH);
- case BPF_PROG_QUERY:
return CHECK_ATTR(BPF_PROG_QUERY);
- case BPF_PROG_TEST_RUN:
return CHECK_ATTR(BPF_PROG_TEST_RUN);
- case BPF_PROG_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_MAP_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_BTF_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_PROG_GET_FD_BY_ID:
return CHECK_ATTR(BPF_PROG_GET_FD_BY_ID);
- case BPF_MAP_GET_FD_BY_ID:
return CHECK_ATTR(BPF_MAP_GET_FD_BY_ID);
- case BPF_OBJ_GET_INFO_BY_FD:
return CHECK_ATTR(BPF_OBJ_GET_INFO_BY_FD);
- case BPF_RAW_TRACEPOINT_OPEN:
return CHECK_ATTR(BPF_RAW_TRACEPOINT_OPEN);
- case BPF_BTF_LOAD:
return CHECK_ATTR(BPF_BTF_LOAD);
- case BPF_BTF_GET_FD_BY_ID:
return CHECK_ATTR(BPF_BTF_GET_FD_BY_ID);
- case BPF_TASK_FD_QUERY:
return CHECK_ATTR(BPF_TASK_FD_QUERY);
- case BPF_MAP_LOOKUP_AND_DELETE_ELEM:
return CHECK_ATTR(BPF_MAP_LOOKUP_AND_DELETE_ELEM);
- case BPF_LINK_CREATE:
return CHECK_ATTR(BPF_LINK_CREATE);
- case BPF_LINK_UPDATE:
return CHECK_ATTR(BPF_LINK_UPDATE);
- case BPF_LINK_GET_FD_BY_ID:
return CHECK_ATTR(BPF_LINK_GET_FD_BY_ID);
- case BPF_LINK_GET_NEXT_ID:
return CHECK_ATTR(BPF_OBJ_GET_NEXT_ID);
- case BPF_ENABLE_STATS:
return CHECK_ATTR(BPF_ENABLE_STATS);
- case BPF_ITER_CREATE:
return CHECK_ATTR(BPF_ITER_CREATE);
- case BPF_LINK_DETACH:
return CHECK_ATTR(BPF_LINK_DETACH);
- case BPF_PROG_BIND_MAP:
return CHECK_ATTR(BPF_PROG_BIND_MAP);
- default:
return 0;
This gets me thinking: assuming we are supposed to handle all the bpf_cmd enum values (I think we do), it would actually be better not to have a default. This way, we would get a warning if a new value is added (I think -Wswitch is enabled but worth checking this actually works).
Kevin