daemon: cgen: use float for meta.probability matcher#453
daemon: cgen: use float for meta.probability matcher#453qdeslandes wants to merge 1 commit intofacebook:mainfrom
Conversation
Unify meta.probability and meta.flow_probability to share the same floating-point parsing and printing logic, replacing the integer-only code path. This allows meta.probability to accept fractional percentages (e.g., "33.33%") and removes duplicate parser/printer functions.
| @@ -928,7 +898,7 @@ static struct bf_matcher_meta _bf_matcher_metas[_BF_MATCHER_TYPE_MAX] = { | |||
| .layer = BF_MATCHER_NO_LAYER, | |||
There was a problem hiding this comment.
Claude: The payload size for BF_MATCHER_META_PROBABILITY changes from sizeof(uint8_t) (1 byte) to sizeof(float) (4 bytes). Since bf_matcher_pack serializes the payload as raw binary and bf_matcher_new_from_pack → bf_matcher_new copies payload bytes without validating against ref_payload_size, any previously persisted matchers with the old 1-byte payload will be deserialized into a matcher struct with only 1 byte of payload. Subsequent *(float *)bf_matcher_payload(matcher) reads in both codegen and print would then read 3 bytes out of bounds.
Is there a version/migration mechanism for serialized state, or is this acceptable because the daemon always re-generates matchers from rules on restart?
bpfilter/src/libbpfilter/matcher.c
Line 898 in 47e22e8
| EMIT(program, BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32)); | ||
| EMIT_FIXUP_JMP_NEXT_RULE( | ||
| program, | ||
| BPF_JMP_IMM(BPF_JGT, BPF_REG_0, |
There was a problem hiding this comment.
Claude: _bf_matcher_generate_meta_probability uses BPF_JMP_IMM (64-bit comparison) while the analogous _bf_matcher_generate_meta_flow_probability at line 251 uses BPF_JMP32_IMM (32-bit comparison). Since bpf_get_prandom_u32() returns a 32-bit value, BPF_JMP32_IMM is the more precise match. This is a pre-existing inconsistency, but now that the two matchers share the same parsing/printing logic, aligning the codegen would be a natural follow-up.
bpfilter/src/bpfilter/cgen/matcher/meta.c
Line 75 in 47e22e8
|
Claude: review of facebook/bpfilter #453 (47e22e8) Suggestions
Nits
|
Unify meta.probability and meta.flow_probability to share the same floating-point parsing and printing logic, replacing the integer-only code path. This allows meta.probability to accept fractional percentages (e.g., "33.33%") and removes duplicate parser/printer functions.