In segment routing protocol, we know that the routing process is source steered. I'm struck to know if any best (longest) prefix matching happens to route the data packets? If so any clue about the prefix be attached to the header of IP packet when forwarding to downstream router?
Subnet routing is usually by destination address (as opposed to policy-based routing where other parameters can be used).
The routing algorithm selects the most specific, longest subnet prefix from the routing table. Effectively, the routing table is sorted by prefix lengths and entries are tested from longest to shortest prefix until a match is found. If present, the null-length default entry 0.0.0.0/0 matches all destinations.
The packet itself doesn't carry any prefix length information, just the source and destination addresses. The length of the prefix is taken from the routing table of each forwarding hop.
This way, the routing entries can become more specific along the way, from hop to hop. For instance, a branch office using 10.11.22.0/24 locally can use a 10.0.0.0/8 "private default" route to headquarters. At HQ, 10.22.0.0/16 can point to another branch office and there, 10.22.33.0/24 can point to an actual subnet.