By Tamsin Smith
BBC reporter in Spain and Morocco
With the arrest of several Moroccans suspected of involvement with the Madrid blasts, people are asking how safe Spain's and Europe's frontiers are.
Spain's weakest border is its southern coast separated from Northern Africa by only the narrow straits of Gibraltar.
Spanish police use heat-seeking devices to detect migrants
At the maritime immigration headquarters in the port of Algeciras, Guardia Civil spokesman Salvadore Gomez proudly shows grainy footage of patrol boats intercepting immigrants destined for Europe along with computer animations of how heat-seeking technology works.
"Here on this border we know we have to prevent everything... not just immigration, but we can have terrorists trying to cross in a vessel, perhaps with the intention to plant bombs," he says.
"Here we have security systems and specialist teams who come from all over Spain just to work on this threat."
After the 11 September attacks on the US, securing Spain's sea borders became top priority.
Take the fast ferry from Algeciras to the Moroccan port of Tangier and you can see why.
No sooner is the ferry leaving the port and passing the Rock of Gibraltar, than the North African coast looms large on the horizon.
At Tangier, one of Morocco's major ports, thousands of freight containers line the dockside, most headed for Europe.
This is also the meeting point for an illegal cargo of people, desperate to cross illegally to Spain.
They congregate here from all over Morocco and from sub-Saharan Africa, sleeping rough in the port and in the town until they get their chance to leave.
One young Moroccan boy from Marrakech says he and his friends have been sleeping rough on the dockside for 2 months and will stay until they manage to smuggle themselves to Spain.
"I tried climbing up a ship's rigging last week, but they caught me... I'll try the lorries next time, that's how my friends got to Spain," he says.
Hi-tech Spanish maritime controls are having some success stopping small boatloads of immigrants arriving in Spain, but the number of stowaways hiding in lorries has increased dramatically.
"The situation is really getting worse and worse, it's desperate. We're finding people hidden in our lorries every single week now," says the director of the Tangier branch of British logistics company Tibbett and Britten, Laetitia Banzet.
Like many transport companies in Tangier she has little faith in the Moroccan police authorities and employs her own security staff to protect drivers and lorries from gangs of migrants.
"There are gangs of 25 or 50 people running after the lorries on the way to the port, they attack the drivers throwing stones to make them stop, then they climb into the trailer. It makes me really angry that nobody does anything about this."
In fact, Moroccan police do seem more interested in tracking foreign journalists than stopping illegal migrants.
Since arriving in Tangier we were followed constantly by plain-clothed policemen even through the bustling streets of the old town, or around our hotel.
They even detained us briefly for conducting interviews near the docks, but paid little attention to the stowaways we were talking to.
'No political will'
Jamiar Amyer, editor of one of Tangier leading daily newspapers says that the money Moroccan workers send home once they get to Europe, may explain the lack of government action when it comes to border security.
"Conditions haven't improved because there has been no political will to sort it out," he says
Every week, thousands of lorries converge in Tangiers
"Remember that these people leave and bring or send back money to their families. Wages of Moroccans living overseas are the first export resource of Morocco. In 2003 this amounted to over 3bn euros ($3.6bn)."
It is on the weekly export day at the port of Tangier that the size of the security challenge facing Europe is most apparent.
Once a week thousands of lorries converge here on the quayside waiting to board the ferries.
During night and early dawn hundreds of young men are seen jumping over walls, squeezing under trucks and lorries - there's little obvious police presence.
If the Moroccan authorities are reluctant to police illegal migrants leaving to find work abroad, can they be relied on to detect people who may be destined for Europe with more sinister intentions?
I was there two years ago, a place to mind your pockets and the shirt on your back. I wouldn't wish to return but with potential terrorism links we must be selective about the Moroccans that come to us. Since we're hanging on to Gibraltar maybe we could help the Spanish authorities.
I have heard a lot of noise about the illegal migration but from the numbers I have seen, the total is a pretty small figure. Given Europe's demographics, maybe the so-called leaders would stop playing to the base instincts of their people and pay more attention to bring in people legally. Like the drug problem in the US, all the money and effort thrown into policing this matter will be far better spent regulating this problem
Rubin Naidu, Toronto, Canada
I don't think Spain or the rest of Europe should be the solution to the problems of Morocco or any other country. After the train bombings in Madrid I feel threatened and less secure in my own city. I surely think that immigration should be much more rigid.
MGJ, Madrid, Spain
Having lived and worked in Gibraltar for the last 12 months, I can completely understand the temptation of want-to-be immigrants in Africa - to look out over the Straits of Gibraltar every day and see Europe so close, the land of opportunity when your own family is starving a mere 14km away, the journey is so small. But having been to Morocco, it is easy to understand why the authorities there turn a blind eye - it is an opportunity for income for them. Europe should be working closer with Morocco to prevent this; the free-trade agreement is not enough. We should be working not just from the Spanish border but with Morocco too, even in Tangier itself, to ensure that immigrants do not make it over so easily.
Clair A, Gibraltar
If the migrants were given a fair legal way of getting into the EU, then the Moroccan authorities could be persuaded to tighten up security in the illegal end of migration.
Chris Williams, Solihull, UK
I think it is a problem to look after the borders every minute of every day - just like the report says most of the migrants cross borders for a better life. It's only extremists that want to make things harder for more migrants in the future.
Coyreec Williams, Trinidad and Tobago
This situation is absolutely disgusting and must be stopped now! The number one priority for Europe should be keeping these people out. It is only a matter of time before right wing parties take control of the governments all over Europe. People have had enough. Blame the idiot politicians!
If Morocco, as it seems is unwilling to police her boarders correctly, then maybe considering a withdrawing of any financial support she may be receiving from Europe will be an incentive. Another idea may sound absurd, but if a monetary package can be decided upon, then maybe paying for an independent European and Moroccan security force to guard the Moroccan side of the straits will also serve to hinder those who would want to get across.