Check address-plan membership
Join each assignment to its VLAN prefix and preserve missing policy as unknown.
String prefixes are not subnet tests
An address beginning with the characters 192.0.2 is not necessarily a member of the subnet you mean. Prefix lengths can end partway through an octet, so compare numeric boundaries. A /25 divides a /24 in half; an address on one side cannot be accepted merely because its first three octets match.
The address plan maps a VLAN to one validated prefix. Load it first, retaining inclusive first and last boundaries. Then join each device assignment by its VLAN. Because the reference input includes a header, even an otherwise empty plan has a well-defined first file.
Missing policy is a separate result
When a VLAN has no supplied prefix, classify its assignment as unknown. Calling it outside would imply that a policy had been checked and failed; calling it inside would invent permission. This distinction becomes especially useful when reports combine data from several collectors.
The membership check includes the first and last address because it asks whether an address belongs to a block, not whether a host should be configured with it. Input assignments and plan prefixes are already validated in this lesson. Validation and membership remain separate operations, which makes each one easier to test and reuse.
awk -F '\t' 'NR>1 {print $1 " uses VLAN " $2}' assignments.tsv
Put it into practice.
plan.tsv contains unique validated vlan<TAB>prefix entries with VLANs 1–4094; assignments.tsv contains validated unique device_id<TAB>vlan<TAB>address rows. Print device_id<TAB>vlan<TAB>address<TAB>membership sorted by device ID under LC_ALL=C. Membership is inside for an address within the VLAN prefix inclusive bounds, outside when a known prefix excludes it, or unknown when no prefix is supplied. Use lib/ipv4.awk; do not infer membership by text matching.
See an explained solution
export LC_ALL=C
printf 'device_id\tvlan\taddress\tmembership\n'
awk -F '\t' -f lib/ipv4.awk -f - plan.tsv assignments.tsv <<'AWK' | sort
FILENAME==ARGV[1] {if(FNR>1 && cidr($2)){lo[$1]=first;hi[$1]=last}next}
FNR>1 {state="unknown";if($2 in lo){v=ipv4($3);state=(v>=lo[$2] && v<=hi[$2])?"inside":"outside"}printf "%s\t%s\t%s\t%s\n",$1,$2,$3,state}
AWK
The join keeps every assignment, including devices with missing address-plan coverage. Numeric comparisons correctly handle prefixes between octet boundaries and retain the explicit distinction between outside and unknown.