Let me put it this way, for clarity:
If all immigration is legal, then you have documentation of everyone who has entered the country.
The only "illegal" kind of immigration would be if someone on the FBI's most wanted list etc. tried to enter a country. They would be denied, and would have to "immigrate" "illegally." However everyone else, provided they have a reasonable criminal record, should be able to enter any country, so long as their presence is documented.
Meaning they are issued, say, a card that says their name and the name of the country issuing the card and their status. And if the cops pull them over they have to have the card. And it also means they can't vote and stuff. Issue them a kind of social security number (not because they'd get social security..... just in case you were about to freak out about that.)
This would allow you to prevent them from doing "things only citizens get to do" much more easily. It would also solve your "but what about TERRORISTS?????" problem. It would also solve the problem of all the terrible crimes that now result in human trafficking of immigrants as well as low (illegally low) wages. And statistics would be accurate. And Mexicans would hate us less. And the whole world would like us more. And fucking insular white people would start to realize that the world is 83% non-white people, and not only would they REALIZE it, they would have to DEAL with it. As in, learn to live side-by-side with these people.
If these types of laws were put into place, eventually, different kinds of people would live all over, and the idea of the nation-state would break down even more than it already has, and you would have a global government, and see the end of language barriers, race, and war.
But you know. That's not necessarily a worthy goal in everyone's eyes. Usually bigots' eyes.